Debugging 1802 “load mode”

I threw together a testbench for the Elf, with the switch debouncing disabled.  The testbench tries to use load mode to load a program that has an infinite loop setting and clearing the Q flag, which is available as an output.

The GHDL simulator can dump the state of all the signals as a VCD file, and I’m using GTKwave to view that.

The most obvious bug I found is that the PC was being reset in state_clear_2 rather than state_clear, so after every load, the PC was reset to zero.  Load mode sits in state_clear_2, going to state_dma_input when the dma_in_req changes, so every load was to location zero.  In looking at my 1802 core design, there’s no obvious reason why the PC reset couldn’t be done in state_clear rather than state_clear_2, so I changed it to do that instead, and that seems to work.

My logic in the Elf wrapper for only asserting dma_in_req from the leading edge of the synchronized pushbutton input until the 1802 state code indicates that a DMA cycle is being done does not work correctly, so I’m getting memory writes to two consecutive locations for each button press.  The necessary logic is trickier than I would have expected, and I haven’t quite figured out the best way to fix it.

The good news is that the code actually is getting written to the RAM, and once the run switch is enabled, the code is actually being run.  It’s the wrong code due to the problem described above, but it seems that I’m getting very close to having it working.

This entry was posted in FPGA, RetroChallenge. Bookmark the permalink.

Leave a Reply