Hello.
I tried to restructure my program using:
http://wiki.nesdev.com/w/index.php/The_ ... age_of_NMI
It doesn't seem to work correctly, it is supposed to draw the title screen (works OK), then draw the game screen when start is pressed, then the title again when start is pressed and so on. Switching between the screens basically.
When should I use buffered reg writes, and when direct? Do I need to enable NMI each frame?
The code below just shows the main program, the drawing routines etc seem to be OK, but I can post those too.
Thanks!
I tried to restructure my program using:
http://wiki.nesdev.com/w/index.php/The_ ... age_of_NMI
It doesn't seem to work correctly, it is supposed to draw the title screen (works OK), then draw the game screen when start is pressed, then the title again when start is pressed and so on. Switching between the screens basically.
When should I use buffered reg writes, and when direct? Do I need to enable NMI each frame?
The code below just shows the main program, the drawing routines etc seem to be OK, but I can post those too.
Thanks!
Code:
.include "variables.asm"
.db "NES",$1a
.db $01
.db $01
.db $00
.dsb 9,$00
.base $c000
.include "initialise.asm"
jsr load_palette
load_title:
ldx #<title_bg
ldy #>title_bg
jsr draw_nametable
lda #%00011110
sta reg_2001
title_loop:
jsr read_joypad
lda joypad_pressed
and #START
beq title_loop
lda #$00
sta reg_2001
ldx #<game_bg
ldy #>game_bg
jsr draw_nametable
lda #%10001000
sta $2000
; main game code
main_loop:
jsr read_joypad
lda joypad_pressed
and #START
beq exec_frame
lda $00
sta $2001
jmp load_title
exec_frame:
lda #$01
sta draw_pending
sta oam_pending
sta ppu_pending
jsr wait_vblank
lda #%10001000
sta $2001
jmp main_loop
wait_vblank:
inc sleep
- lda sleep
bne -
rts
.include "palette.asm"
.include "joypad.asm"
.include "interrupts.asm"
.include "nametables.asm"
; interrupt vectors
.org $fffa
.dw nmi
.dw reset
.dw irq
; chr-rom
.incbin "tiles.chr"
.db "NES",$1a
.db $01
.db $01
.db $00
.dsb 9,$00
.base $c000
.include "initialise.asm"
jsr load_palette
load_title:
ldx #<title_bg
ldy #>title_bg
jsr draw_nametable
lda #%00011110
sta reg_2001
title_loop:
jsr read_joypad
lda joypad_pressed
and #START
beq title_loop
lda #$00
sta reg_2001
ldx #<game_bg
ldy #>game_bg
jsr draw_nametable
lda #%10001000
sta $2000
; main game code
main_loop:
jsr read_joypad
lda joypad_pressed
and #START
beq exec_frame
lda $00
sta $2001
jmp load_title
exec_frame:
lda #$01
sta draw_pending
sta oam_pending
sta ppu_pending
jsr wait_vblank
lda #%10001000
sta $2001
jmp main_loop
wait_vblank:
inc sleep
- lda sleep
bne -
rts
.include "palette.asm"
.include "joypad.asm"
.include "interrupts.asm"
.include "nametables.asm"
; interrupt vectors
.org $fffa
.dw nmi
.dw reset
.dw irq
; chr-rom
.incbin "tiles.chr"