From 3dd432577e3dbca911d968f3d3af5a78ad79626e Mon Sep 17 00:00:00 2001 From: Jesse Luehrs Date: Mon, 6 Oct 2014 04:11:45 -0400 Subject: better structure for the game code shouldn't do everything in the NMI interrupt - only drawing should happen there in order to make sure that gets done during vblank, everything else should happen in the main loop --- main.s | 29 +++++++++++++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-) diff --git a/main.s b/main.s index aa4d596..d59c52a 100644 --- a/main.s +++ b/main.s @@ -17,6 +17,7 @@ BANKS 1 .ENUM $0000 buttons_pressed DB +sleeping DB .ENDE @@ -66,6 +67,7 @@ clrmem: ; initialize variables in ram LDA #$00 STA buttons_pressed + STA sleeping vblankwait2: ; Second wait for vblank, PPU is ready after this BIT $2002 @@ -93,11 +95,34 @@ LoadPalettesLoop: STA $2000 loop: + INC sleeping +sleep: + LDA sleeping + BNE sleep + + JSR read_controller1 + + ; game logic + JMP loop NMI: - JSR read_controller1 - ; ... + PHA + TXA + PHA + TYA + PHA + + ; drawing code + + LDA #$00 + STA sleeping + + PLA + TAY + PLA + TAX + PLA RTI read_controller1: -- cgit v1.2.3