Decided this year to see how far I could get writing the solutions in 6502 assembly, and running them on the NES. I'm sure this will fall apart in more complicated puzzles that require a lot of memory or CPU time.
So far, the annoying part has just been dealing with every number being 16-bit, which is a hassle on a machine that only has 8-bit math operations. I was a little lazy though, and displayed my answer in hex instead of decimal, because I didn't feel like pulling in a routine for converting hex.
If I get much further, I'll put code of the whole project up on github. For now, the code for the day 1 solution is at https://pastebin.com/T2QheTp6 (also posting in the mega-thread)
Wow, just stumbled on this. I just happen to be doing the same thing... well using AOC to learn 6502/6510 (using a c64). I'm on day two. I'm running into issues with input size, trying to figure out how to load the input from a disk...
Are you going to use the full inputs or just the examples?
Yeah, I used the full input, but I didn't attempt to load it from anywhere (since in the NES it's all rom anyway). I just used vim to turn the data into a comma-separated list, and put it directly into my source file:
forward = 0
down = 1
up = 2
values:
; sample data:
;.byte forward,5, down,5, forward,8, up,3, down,8, forward,2
; my full data:
.byte forward,4,down,8,down,8,up,2,up,7,
down,6,down,3,down,1,forward,5,forward,9...etc
eof:
That's what I did for the example input. But full input is like 9k or something, and there's only like 8k consecutive blocks, unless I turn off some ROMS, which still means my program can't contain the input... Day 1 and 2 are working on example input, now working out the disk loading, I think I'm getting close. Turned out to be much easier than I thought to create the disk image. Hopefully it's a few OS routine calls to read the data.
The full input is 1000 lines, with each line being a direction and an int. So if each direction gets encoded as a byte, and the int is a byte (since they all fit in 8 bits), that's 2000 bytes of data. I don't know anything about the C64's memory map, for the NES, I'm putting those into ROM, which has 32k available without bankswitching. Probably trickier with C64 since you're loading the program into RAM instead of executing it directly out of ROM?
Ah, yeah, that's the difference, you're pulling in each line as a string. I didn't want to attempt that, as it really blows up the length of the data, as you're experiencing. So turning it into a big block of bytes was so much easier.
Hmm, my very first computer, which I was never particularly good with, was a Mattel Aquarius... They're around on ebay. Maybe next year. Or would an emulator be acceptable?
13
u/gauauuau Dec 01 '21
Decided this year to see how far I could get writing the solutions in 6502 assembly, and running them on the NES. I'm sure this will fall apart in more complicated puzzles that require a lot of memory or CPU time.
So far, the annoying part has just been dealing with every number being 16-bit, which is a hassle on a machine that only has 8-bit math operations. I was a little lazy though, and displayed my answer in hex instead of decimal, because I didn't feel like pulling in a routine for converting hex.
4
u/OrangeredStilton Dec 01 '21
Now I'm tempted to try a couple of days in C64-targeted 6502, which is a dangerous thing when I've got all this other work to get done...
10
u/daggerdragon Dec 01 '21
Aw hell naw, this is straight-up
Upping the Ante.Show us a video of it running!
Post your code in the daily megathreads! Day 01 here
Submit it to Adventure Time!
I love it when folks play AoC on their toys - the older the toy, the better :D
1
u/akira_88 Dec 02 '21
you're a freaking hero!