aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJesse Luehrs <doy@tozt.net>2014-10-06 04:11:45 -0400
committerJesse Luehrs <doy@tozt.net>2014-10-06 04:11:45 -0400
commit3dd432577e3dbca911d968f3d3af5a78ad79626e (patch)
treeee501a7a725a1902a127ab3cc91f65776bb378a4
parentcc3a1fb8164c606d29480f990275b553c96543c9 (diff)
downloadnes-project-skeleton-3dd432577e3dbca911d968f3d3af5a78ad79626e.tar.gz
nes-project-skeleton-3dd432577e3dbca911d968f3d3af5a78ad79626e.zip
better structure for the game codeHEADmaster
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
-rw-r--r--main.s29
1 files 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: