aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJesse Luehrs <doy@tozt.net>2014-10-11 23:25:28 -0400
committerJesse Luehrs <doy@tozt.net>2014-10-11 23:25:28 -0400
commitbb2990f82f5aa901f0aa83e0bec4658d68548663 (patch)
treea3420e9548cbed0c31f6a7fa89a70dc28f146189
parent33d3f4266229687d7d48fcaf90da51957bf99859 (diff)
downloadnes-snake-bb2990f82f5aa901f0aa83e0bec4658d68548663.tar.gz
nes-snake-bb2990f82f5aa901f0aa83e0bec4658d68548663.zip
move all game logic out of the nmi interrupt
drawing is now done in the main game code, by writing into the $07 page, and the nmi interrupt now just steps through that page and does the drawing actions described there
-rw-r--r--main.s82
1 files changed, 57 insertions, 25 deletions
diff --git a/main.s b/main.s
index ce612bb..4d8604c 100644
--- a/main.s
+++ b/main.s
@@ -48,6 +48,7 @@ vram_addr_low DB
vram_addr_high DB
body_test_x DB
body_test_y DB
+num_draws DB
.ENDE
; }}}
; }}}
@@ -169,34 +170,33 @@ NMI:
JMP end_nmi
draw_game:
- LDX #$00
- JSR draw_sprite_at_head
- LDA head_x
- SEC
- SBC length
- STA head_x
- LDA head_y
- SEC
- SBC length
- STA head_y
- LDX #$20
- JSR draw_sprite_at_head
- LDA head_x
- CLC
- ADC length
- STA head_x
- LDA head_y
+- LDA #$00
CLC
- ADC length
- STA head_y
+ ADC num_draws
+ ADC num_draws
+ ADC num_draws
+ SEC
+ SBC #$03
+ TAX
+ LDA $0700, x
+ STA $2006
+ INX
+ LDA $0700, x
+ STA $2006
+ INX
+ LDA $0700, x
+ STA $2007
+ LDX num_draws
+ DEX
+ STX num_draws
+ CPX #$00
+ BNE -
LDA #$20
STA $2006
LDA #$00
STA $2006
- JMP do_dma
-
do_dma:
LDA #$00
STA $2003
@@ -366,6 +366,26 @@ eat_apple:
+ JSR new_apple
end_game_loop:
+ LDX #$00
+ JSR draw_sprite_at_head
+ LDA head_x
+ SEC
+ SBC length
+ STA head_x
+ LDA head_y
+ SEC
+ SBC length
+ STA head_y
+ LDX #$20
+ JSR draw_sprite_at_head
+ LDA head_x
+ CLC
+ ADC length
+ STA head_x
+ LDA head_y
+ CLC
+ ADC length
+ STA head_y
RTS ; }}}
read_controller1: ; {{{
; latch
@@ -588,13 +608,25 @@ draw_sprite_at_head: ; {{{
ADC #$00
STA vram_addr_high
+ TXA
+ TAY
+ LDA #$00
+ ADC num_draws
+ ADC num_draws
+ ADC num_draws
+ TAX
LDA vram_addr_high
- STA $2006
+ STA $0700, x
+ INX
LDA vram_addr_low
- STA $2006
+ STA $0700, x
+ INX
+ TYA
+ STA $0700, x
- TXA
- STA $2007
+ LDX num_draws
+ INX
+ STX num_draws
RTS ; }}}
test_body_collision ; {{{