I started a homebrew NES game to learn NES assembly programming back in April or May, though I haven't worked on it much this summer but really want to get back into it. I had asked this question over on the NESDev subreddit, but was directed here by the users there.
My question is regarding a problem I can't seem to solve with separating the game logic from the NMI. I know it is best practice to keep PPU and APU update code in the NMI, and all of the game engine code in its own loop. The problem is, I haven't gotten this to work--it is just fine when the logic is in the NMI, but when I try to move the logic to the game loop, the loop never executes or updates. I followed the Nerdy Nights tutorials when writing this code, but he kept the logic inside NMI...and disch's tutorial didn't help me much with this problem. Essentially, my problem is that when I put code in the main game loop (which, in the working version, just loops forever while we wait for an NMI, and the NMI handles all of the game code like in Super Mario Bros), none of this code actually executes. Specifically, controllers aren't read, the game engine doesn't do anything, and test tones don't play. The screen still scrolls, but that happens during NMI. I set my "gamestate" variable to "playing" in the reset file (which, in theory, should let me run the logic), but despite my attempts, this does not seem to help me execute my game engine code in my game loop.
For reference, here is my game loop:
Code: Select all
MainGameLoop: ;; put game logic here. Use a "sleep" flag to prevent us from doing too much per frame ;; "sleep" flag should only be set if we need to wait for an NMI MainGameLoop_Wait: lda sleep_flag bne MainGameLoop_Wait jsr ReadController jsr GameEngine inc sleep_flag ; set sleep flag after running the game engine JMP MainGameLoop
Rather than write all the code out here, I'll give you the pastebin links--here is a link to the init/reset file, and here is a link to the main file.
Thank you so much for your help, I hope someone can help me figure this out/point me in the right direction!