Make macros for setting 16bit/8bit registers.
Also disable NMI while processing, and start refactoring joypad handler.
This commit is contained in:
parent
8c5b4232c1
commit
5c45dfa834
68
pewpew.asm
68
pewpew.asm
@ -43,6 +43,29 @@
|
|||||||
.define spriteTableSize $220
|
.define spriteTableSize $220
|
||||||
.define spriteTableScratchStart $320
|
.define spriteTableScratchStart $320
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
; Sets A to 8-bit (& enables 8-bit "B" register).
|
||||||
|
.MACRO SetA8Bit
|
||||||
|
sep #%00100000 ; 8-bit A/B.
|
||||||
|
.ENDM
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
; Sets A to 16-bit.
|
||||||
|
.MACRO SetA16Bit
|
||||||
|
rep #%00100000 ; 16-bit A.
|
||||||
|
.ENDM
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
; Sets X/Y to 16-bit.
|
||||||
|
.MACRO SetXY16Bit
|
||||||
|
rep #%00010000 ; 16-bit X/Y.
|
||||||
|
.ENDM
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
; Stores result to A.
|
; Stores result to A.
|
||||||
; Assumes 16-bit X & 8-bit A.
|
; Assumes 16-bit X & 8-bit A.
|
||||||
; Modifies X.
|
; Modifies X.
|
||||||
@ -72,14 +95,14 @@ Start:
|
|||||||
; By default we assume 16-bit X/Y and 8-bit A.
|
; By default we assume 16-bit X/Y and 8-bit A.
|
||||||
; If any code wants to change this, it's expected to do so itself,
|
; If any code wants to change this, it's expected to do so itself,
|
||||||
; and to change them back to the defaults before returning.
|
; and to change them back to the defaults before returning.
|
||||||
rep #%00010000 ; 16-bit X/Y.
|
SetXY16Bit
|
||||||
sep #%00100000 ; 8-bit A/B.
|
SetA8Bit
|
||||||
|
|
||||||
; Store zeroes to the controller status registers.
|
; Store zeroes to the controller status registers.
|
||||||
; TODO(mcmillen): is this needed? I think the system will overwrite these
|
; TODO(mcmillen): is this needed? I think the system will overwrite these
|
||||||
; automatically.
|
; automatically.
|
||||||
stz JOY1H
|
stz joy1
|
||||||
stz JOY1L
|
stz joy1 + 1
|
||||||
|
|
||||||
jsr LoadPaletteAndTileData
|
jsr LoadPaletteAndTileData
|
||||||
jsr InitializeSpriteTables
|
jsr InitializeSpriteTables
|
||||||
@ -103,12 +126,6 @@ Start:
|
|||||||
lda #%00001111
|
lda #%00001111
|
||||||
sta INIDISP
|
sta INIDISP
|
||||||
|
|
||||||
; Enable NMI interrupt & joypad.
|
|
||||||
; n-vh---j n: NMI interrupt enable v: vertical counter enable
|
|
||||||
; h: horizontal counter enable j: joypad enable
|
|
||||||
lda #%10000001
|
|
||||||
sta NMITIMEN
|
|
||||||
|
|
||||||
jmp MainLoop
|
jmp MainLoop
|
||||||
|
|
||||||
|
|
||||||
@ -245,7 +262,7 @@ InitializeSpriteTables:
|
|||||||
; It uses the same approach we're using, in which we keep a buffer of the
|
; It uses the same approach we're using, in which we keep a buffer of the
|
||||||
; sprite tables in RAM, and DMA the sprite tables to the system's OAM
|
; sprite tables in RAM, and DMA the sprite tables to the system's OAM
|
||||||
; during VBlank.
|
; during VBlank.
|
||||||
rep #%00100000 ; 16-bit A.
|
SetA16Bit
|
||||||
|
|
||||||
ldx #$0000
|
ldx #$0000
|
||||||
; Fill sprite table 1. 4 bytes per sprite, laid out as follows:
|
; Fill sprite table 1. 4 bytes per sprite, laid out as follows:
|
||||||
@ -275,7 +292,7 @@ InitializeSpriteTables:
|
|||||||
cpx #spriteTableSize
|
cpx #spriteTableSize
|
||||||
bne -
|
bne -
|
||||||
|
|
||||||
sep #%00100000 ; 8-bit A.
|
SetA8Bit
|
||||||
rts
|
rts
|
||||||
|
|
||||||
|
|
||||||
@ -299,7 +316,12 @@ InitializeWorld:
|
|||||||
|
|
||||||
|
|
||||||
MainLoop:
|
MainLoop:
|
||||||
|
lda #%10000001 ; Enable NMI interrupt & auto joypad read.
|
||||||
|
sta NMITIMEN
|
||||||
wai ; Wait for interrupt.
|
wai ; Wait for interrupt.
|
||||||
|
lda #%00000001 ; Disable NMI interrupt while processing.
|
||||||
|
sta NMITIMEN
|
||||||
|
|
||||||
jsr JoypadDebug
|
jsr JoypadDebug
|
||||||
jsr JoypadHandler
|
jsr JoypadHandler
|
||||||
jsr UpdateWorld
|
jsr UpdateWorld
|
||||||
@ -322,7 +344,7 @@ JoypadDebug:
|
|||||||
JoypadHandler:
|
JoypadHandler:
|
||||||
; TODO(mcmillen): handle joystick using 16-bit loads?
|
; TODO(mcmillen): handle joystick using 16-bit loads?
|
||||||
JoypadUp:
|
JoypadUp:
|
||||||
lda JOY1H
|
lda joy1 + 1
|
||||||
bit #$08 ; Up
|
bit #$08 ; Up
|
||||||
beq JoypadDown ; Button not pressed.
|
beq JoypadDown ; Button not pressed.
|
||||||
lda playerY
|
lda playerY
|
||||||
@ -332,7 +354,7 @@ JoypadUp:
|
|||||||
dec playerY
|
dec playerY
|
||||||
|
|
||||||
JoypadDown:
|
JoypadDown:
|
||||||
lda JOY1H
|
lda joy1 + 1
|
||||||
bit #$04 ; Down
|
bit #$04 ; Down
|
||||||
beq JoypadLeft ; Button not pressed.
|
beq JoypadLeft ; Button not pressed.
|
||||||
lda playerY
|
lda playerY
|
||||||
@ -342,7 +364,7 @@ JoypadDown:
|
|||||||
inc playerY
|
inc playerY
|
||||||
|
|
||||||
JoypadLeft:
|
JoypadLeft:
|
||||||
lda JOY1H
|
lda joy1 + 1
|
||||||
bit #$02 ; Left
|
bit #$02 ; Left
|
||||||
beq JoypadRight ; Button not pressed.
|
beq JoypadRight ; Button not pressed.
|
||||||
lda playerX
|
lda playerX
|
||||||
@ -352,7 +374,7 @@ JoypadLeft:
|
|||||||
dec playerX
|
dec playerX
|
||||||
|
|
||||||
JoypadRight:
|
JoypadRight:
|
||||||
lda JOY1H
|
lda joy1 + 1
|
||||||
bit #$01 ; Right
|
bit #$01 ; Right
|
||||||
beq JoypadStart ; Button not pressed.
|
beq JoypadStart ; Button not pressed.
|
||||||
lda playerX
|
lda playerX
|
||||||
@ -362,7 +384,7 @@ JoypadRight:
|
|||||||
inc playerX
|
inc playerX
|
||||||
|
|
||||||
JoypadStart:
|
JoypadStart:
|
||||||
lda JOY1H
|
lda joy1 + 1
|
||||||
bit #$10 ; Start
|
bit #$10 ; Start
|
||||||
beq JoypadSelect ; Button not pressed.
|
beq JoypadSelect ; Button not pressed.
|
||||||
lda backgroundRed
|
lda backgroundRed
|
||||||
@ -371,7 +393,7 @@ JoypadStart:
|
|||||||
inc backgroundRed
|
inc backgroundRed
|
||||||
|
|
||||||
JoypadSelect:
|
JoypadSelect:
|
||||||
lda JOY1H
|
lda joy1 + 1
|
||||||
bit #$20 ; Select
|
bit #$20 ; Select
|
||||||
beq JoypadY ; Button not pressed.
|
beq JoypadY ; Button not pressed.
|
||||||
lda backgroundRed
|
lda backgroundRed
|
||||||
@ -380,7 +402,7 @@ JoypadSelect:
|
|||||||
dec backgroundRed
|
dec backgroundRed
|
||||||
|
|
||||||
JoypadY:
|
JoypadY:
|
||||||
lda JOY1H
|
lda joy1 + 1
|
||||||
bit #$40 ; Y
|
bit #$40 ; Y
|
||||||
beq JoypadX ; Button not pressed.
|
beq JoypadX ; Button not pressed.
|
||||||
lda backgroundGreen
|
lda backgroundGreen
|
||||||
@ -389,7 +411,7 @@ JoypadY:
|
|||||||
dec backgroundGreen
|
dec backgroundGreen
|
||||||
|
|
||||||
JoypadX:
|
JoypadX:
|
||||||
lda JOY1L
|
lda joy1
|
||||||
bit #$40 ; X
|
bit #$40 ; X
|
||||||
beq JoypadL ; Button not pressed.
|
beq JoypadL ; Button not pressed.
|
||||||
lda backgroundGreen
|
lda backgroundGreen
|
||||||
@ -398,7 +420,7 @@ JoypadX:
|
|||||||
inc backgroundGreen
|
inc backgroundGreen
|
||||||
|
|
||||||
JoypadL:
|
JoypadL:
|
||||||
lda JOY1L
|
lda joy1
|
||||||
bit #$20 ; L
|
bit #$20 ; L
|
||||||
beq JoypadR ; Button not pressed.
|
beq JoypadR ; Button not pressed.
|
||||||
lda backgroundBlue
|
lda backgroundBlue
|
||||||
@ -407,7 +429,7 @@ JoypadL:
|
|||||||
dec backgroundBlue
|
dec backgroundBlue
|
||||||
|
|
||||||
JoypadR:
|
JoypadR:
|
||||||
lda JOY1L
|
lda joy1
|
||||||
bit #$10 ; R
|
bit #$10 ; R
|
||||||
beq JoypadB ; Button not pressed.
|
beq JoypadB ; Button not pressed.
|
||||||
lda backgroundBlue
|
lda backgroundBlue
|
||||||
@ -416,7 +438,7 @@ JoypadR:
|
|||||||
inc backgroundBlue
|
inc backgroundBlue
|
||||||
|
|
||||||
JoypadB:
|
JoypadB:
|
||||||
lda JOY1H
|
lda joy1 + 1
|
||||||
bit #$80 ; B
|
bit #$80 ; B
|
||||||
beq JoypadDone
|
beq JoypadDone
|
||||||
jsr MaybeShoot
|
jsr MaybeShoot
|
||||||
|
Loading…
Reference in New Issue
Block a user