Before I go on with my program, I'd like to be sure that all the NES-specific initialization and low level stuff is correct. Therefore, could you please have a look at the below code and tell me if there's still something wrong with it? (I removed all the custom code. This is just the bare bone initialization.)
Code:
.segment "HEADER"
.byte "NES", $1A
.byte $02
.byte $01
.byte $01
.byte $00
.segment "STARTUP"
.segment "ZEROPAGE"
PointerLowByte: .res 1
PointerHighByte: .res 1
.segment "CODE"
Reset:
SEI
CLD
LDX #$40
STX $4017
LDX #$FF
TXS
INX
STX $2000
STX $2001
STX $4010
WaitForVBlank1:
BIT $2002
BPL WaitForVBlank1
; Set RAM memory to 0
LDA #$00
STA PointerLowByte
STA PointerHighByte
LDX #$00
LDY #$00
@outerLoop:
@innerLoop:
STA (PointerLowByte), Y
INY
CPY #$00
BNE @innerLoop
INC PointerHighByte
INX
; The Sprite values are skipped
CPX #$02
BNE @notAtSpriteAddress
INC PointerHighByte
INX
@notAtSpriteAddress:
CPX #$08
BNE @outerLoop
; Set sprite RAM memory to outside the screen
LDA #$F4
LDX #$00
@loop:
STA $0200, X
INX
BNE @loop
WaitForVBlank2:
BIT $2002
BPL WaitForVBlank2
LDA #%10010000
STA $2000
LDA #%00011110
STA $2001
GameLogic:
; Custom code:
; Checking if game logic may be run.
; Constoller reading.
; General algorithms.
; Then jump back.
JMP GameLogic
Nmi:
PHA
TYA
PHA
TXA
PHA
; Check if NMI may be accessed in the moment, otherwise jump to NmiEnd
; ...
; Sprites
LDA #$00
STA $2003
LDA #$02
STA $4014
; Background, palettes, scrolling updates
; ...
NmiEnd:
PLA
TAX
PLA
TAY
PLA
RTI
.segment "VECTORS"
; These three bytes put the next values to address $FFFA
.word $00, $00, $00
.word Nmi
.word Reset
.word 0
.segment "CHARS"
.incbin "Graphics.chr"
.byte "NES", $1A
.byte $02
.byte $01
.byte $01
.byte $00
.segment "STARTUP"
.segment "ZEROPAGE"
PointerLowByte: .res 1
PointerHighByte: .res 1
.segment "CODE"
Reset:
SEI
CLD
LDX #$40
STX $4017
LDX #$FF
TXS
INX
STX $2000
STX $2001
STX $4010
WaitForVBlank1:
BIT $2002
BPL WaitForVBlank1
; Set RAM memory to 0
LDA #$00
STA PointerLowByte
STA PointerHighByte
LDX #$00
LDY #$00
@outerLoop:
@innerLoop:
STA (PointerLowByte), Y
INY
CPY #$00
BNE @innerLoop
INC PointerHighByte
INX
; The Sprite values are skipped
CPX #$02
BNE @notAtSpriteAddress
INC PointerHighByte
INX
@notAtSpriteAddress:
CPX #$08
BNE @outerLoop
; Set sprite RAM memory to outside the screen
LDA #$F4
LDX #$00
@loop:
STA $0200, X
INX
BNE @loop
WaitForVBlank2:
BIT $2002
BPL WaitForVBlank2
LDA #%10010000
STA $2000
LDA #%00011110
STA $2001
GameLogic:
; Custom code:
; Checking if game logic may be run.
; Constoller reading.
; General algorithms.
; Then jump back.
JMP GameLogic
Nmi:
PHA
TYA
PHA
TXA
PHA
; Check if NMI may be accessed in the moment, otherwise jump to NmiEnd
; ...
; Sprites
LDA #$00
STA $2003
LDA #$02
STA $4014
; Background, palettes, scrolling updates
; ...
NmiEnd:
PLA
TAX
PLA
TAY
PLA
RTI
.segment "VECTORS"
; These three bytes put the next values to address $FFFA
.word $00, $00, $00
.word Nmi
.word Reset
.word 0
.segment "CHARS"
.incbin "Graphics.chr"