-
Notifications
You must be signed in to change notification settings - Fork 33
Part 03 OpCodes
Go Home
Now, let's implement our first opcode, NOP (0x00). In the PDF referenced above, you can find the instruction for the NOP. It basically does nothing and uses 4 clock cycles. So, read from the PC (0x0000), to get the OpCode (0x00/NOP), then read for an array of function pointers. This should map to one for NOP. All that function does is increase the total cycles by 4 and increment the PC by 1.
Since the memory is all zeros, it'll run through the entire stack of memory (64k) running NOP, advancing the clock cycles by 4 every step. So, now would be a good time to make the CPU track the cycles and return once it gets to 70,244, or one frame. It is important to make sure you don't drop cycles, and you don't want to have to worry about the cycles overflowing, so every time you get to 70244 or higher, then subtract 70244 from the total cycles.
If my math is correct, then after running StepFrame() once, the Program Counter (PC) register should be 17562.