Devlog 4 - Memory mapping and instruction stepping
-
The next thing I worked on was getting a basic function set up for stepping through instructions and calling the execute function. To do this, I also had to make a program counter, which is a 16 bit register storing the address of the next instruction. Currently, the step function is pretty barebones, but it simply calls the execute function, passes it the PC as a parameter, and then sets the program counter to be the returned address. The execute function has also been modified, meaning it reads the instruction from memory (more on that later) rather than being passed it directly, and return the address plus 1 to 3 bytes, depending on the instruction that was executed.
-
The next bit I made was the Game Boy’s memory. This is simply an char array with 64K values, equivalent to 64KiB of memory. Then, any address can be accessed simply by accessing the array value at an address.
-
After working on the other parts of the CPU, I went back to working on some instructions, implementing the rest of the disassembly tables, including the condition call table, which checks the flags register before executing an instruction. I also implemented some of the instructions that require inputting an address in memory to use instead of a number or register.
-
Finally, I also worked on some quality of life features. First, I made a function to replace missing functions, which simply sends an error message with the function name, and quits with an error code.
-
Secondly, I made / edited some functions to actually move the loaded ROM file into the main GB memory rather than the program memory. I had a little trouble troubleshooting this, as I didn’t at first have a reliable way to verify that the data had been copied successfully, and after I did, I still had trouble with pointers, as I am still pretty new to C’s manual memory management (I usually just keep things in the stack, or have global variables that will persist throughout the program’s lifetime.). I also added basic functionality for loading a ROM on desktop rather than the web, but it doesn’t use the system dialog yet, only loading a rom.gb file in the executable directory. After everything was working, I added a debug message to send the ROM’s header title, showing that it actually works. You can see this in the screenshot. It sends the message twice, once when the file is loaded, and once when it’s moved to GB memory, which I did to make sure that the transfer didn’t mess up the data accidentally.
Comments 0
No comments yet. Be the first!
Sign in to join the conversation.