Add registers.asm file. Refer to registers by name.
This commit is contained in:
parent
6d94f5d032
commit
1925869fb6
49
pewpew.asm
49
pewpew.asm
@ -1,6 +1,6 @@
|
|||||||
.INCLUDE "header.asm"
|
.INCLUDE "header.asm"
|
||||||
.INCLUDE "InitSNES.asm"
|
.INCLUDE "InitSNES.asm"
|
||||||
|
.INCLUDE "registers.asm"
|
||||||
|
|
||||||
.BANK 0 SLOT 0
|
.BANK 0 SLOT 0
|
||||||
.ORG 0
|
.ORG 0
|
||||||
@ -11,31 +11,29 @@
|
|||||||
; 00-0F: scratch space for functions.
|
; 00-0F: scratch space for functions.
|
||||||
; 10-13: controller state.
|
; 10-13: controller state.
|
||||||
; 14-17: 32-bit counter of vblanks.
|
; 14-17: 32-bit counter of vblanks.
|
||||||
; 20-22: [rgb] color values to use for background color.
|
; 20-22: RGB color values to use for background color, from [0-31].
|
||||||
|
|
||||||
|
|
||||||
Start:
|
Start:
|
||||||
InitSNES ; Initialize SNES.
|
InitSNES ; Initialize SNES.
|
||||||
|
|
||||||
; Turn on the screen.
|
; Turn on the screen.
|
||||||
; $2100: Screen display register [INIDISP]
|
|
||||||
;
|
|
||||||
; Format: x000bbbb
|
; Format: x000bbbb
|
||||||
; x: 0 = screen on, 1 = screen off, bbbb: Brightness ($0-$F)
|
; x: 0 = screen on, 1 = screen off, bbbb: Brightness ($0-$F)
|
||||||
lda #%00001111
|
lda #%00001111
|
||||||
sta $2100
|
sta INIDISP
|
||||||
|
|
||||||
; Enable NMI interrupt & joypad.
|
; Enable NMI interrupt & joypad.
|
||||||
; Register $4200: Counter enable [NMITIMEN]
|
|
||||||
; n-vh---j n: NMI interrupt enable v: vertical counter enable
|
; n-vh---j n: NMI interrupt enable v: vertical counter enable
|
||||||
; h: horizontal counter enable j: joypad enable
|
; h: horizontal counter enable j: joypad enable
|
||||||
lda #$81
|
lda #$81
|
||||||
sta $4200
|
sta NMITIMEN
|
||||||
|
|
||||||
; Store zeroes to the controller status registers.
|
; Store zeroes to the controller status registers.
|
||||||
; TODO(mcmillen): is this needed? I think the system should do this.
|
; TODO(mcmillen): is this needed? I think the system will overwrite these
|
||||||
stz $4218
|
; automatically.
|
||||||
stz $4219
|
stz JOY1H
|
||||||
|
stz JOY1L
|
||||||
|
|
||||||
; Write something recognizable into our scratch space.
|
; Write something recognizable into our scratch space.
|
||||||
jsr FillScratch
|
jsr FillScratch
|
||||||
@ -82,12 +80,11 @@ JoypadHandler:
|
|||||||
; Format: AXLR0000
|
; Format: AXLR0000
|
||||||
; $4219: Joypad #1 status [JOY1H]
|
; $4219: Joypad #1 status [JOY1H]
|
||||||
; Format: BYsSudlr (s=select, S=start, udlr = joypad)
|
; Format: BYsSudlr (s=select, S=start, udlr = joypad)
|
||||||
; Joypad #2 status would be $421A [JOY2L] and $421B [JOY2H].
|
|
||||||
jsr JoypadDebug ; DEBUG
|
jsr JoypadDebug ; DEBUG
|
||||||
|
|
||||||
; TODO(mcmillen): read joypad from local memory instead of registers?
|
; TODO(mcmillen): read joypad from local memory instead of registers?
|
||||||
JoypadUp:
|
JoypadUp:
|
||||||
lda $4219
|
lda JOY1H
|
||||||
and #$08 ; Up
|
and #$08 ; Up
|
||||||
cmp #$08
|
cmp #$08
|
||||||
bne JoypadDown ; Button not pressed.
|
bne JoypadDown ; Button not pressed.
|
||||||
@ -97,8 +94,8 @@ JoypadUp:
|
|||||||
inc $20
|
inc $20
|
||||||
|
|
||||||
JoypadDown:
|
JoypadDown:
|
||||||
lda $4219
|
lda JOY1H
|
||||||
and #$04 ; Down
|
and #$04
|
||||||
cmp #$04
|
cmp #$04
|
||||||
bne JoypadLeft ; Button not pressed.
|
bne JoypadLeft ; Button not pressed.
|
||||||
lda $20
|
lda $20
|
||||||
@ -107,7 +104,7 @@ JoypadDown:
|
|||||||
dec $20
|
dec $20
|
||||||
|
|
||||||
JoypadLeft:
|
JoypadLeft:
|
||||||
lda $4219
|
lda JOY1H
|
||||||
and #$02 ; Left
|
and #$02 ; Left
|
||||||
cmp #$02
|
cmp #$02
|
||||||
bne JoypadRight ; Button not pressed.
|
bne JoypadRight ; Button not pressed.
|
||||||
@ -117,7 +114,7 @@ JoypadLeft:
|
|||||||
dec $22
|
dec $22
|
||||||
|
|
||||||
JoypadRight:
|
JoypadRight:
|
||||||
lda $4219
|
lda JOY1H
|
||||||
and #$01
|
and #$01
|
||||||
cmp #$01 ; Right
|
cmp #$01 ; Right
|
||||||
bne JoypadB ; Button not pressed.
|
bne JoypadB ; Button not pressed.
|
||||||
@ -127,7 +124,7 @@ JoypadRight:
|
|||||||
inc $22
|
inc $22
|
||||||
|
|
||||||
JoypadB:
|
JoypadB:
|
||||||
lda $4219
|
lda JOY1H
|
||||||
and #$80 ; B
|
and #$80 ; B
|
||||||
cmp #$80
|
cmp #$80
|
||||||
bne JoypadY ; Button not pressed.
|
bne JoypadY ; Button not pressed.
|
||||||
@ -137,7 +134,7 @@ JoypadB:
|
|||||||
inc $21
|
inc $21
|
||||||
|
|
||||||
JoypadY:
|
JoypadY:
|
||||||
lda $4219
|
lda JOY1H
|
||||||
and #$40 ; Y
|
and #$40 ; Y
|
||||||
cmp #$40
|
cmp #$40
|
||||||
bne JoypadDone ; Button not pressed.
|
bne JoypadDone ; Button not pressed.
|
||||||
@ -153,13 +150,13 @@ JoypadDone:
|
|||||||
|
|
||||||
JoypadDebug:
|
JoypadDebug:
|
||||||
; Load joypad registers into RAM for easier inspection.
|
; Load joypad registers into RAM for easier inspection.
|
||||||
lda $4218
|
lda JOY1L
|
||||||
sta $10
|
sta $10
|
||||||
lda $4219
|
lda JOY1H
|
||||||
sta $11
|
sta $11
|
||||||
lda $421A
|
lda JOY2L
|
||||||
sta $12
|
sta $12
|
||||||
lda $421B
|
lda JOY2H
|
||||||
sta $13
|
sta $13
|
||||||
rts
|
rts
|
||||||
|
|
||||||
@ -175,7 +172,7 @@ SetBackgroundColor:
|
|||||||
asl
|
asl
|
||||||
.endr
|
.endr
|
||||||
ora $20 ; Red.
|
ora $20 ; Red.
|
||||||
sta $2122
|
sta CGDATA
|
||||||
|
|
||||||
; Compute the high-order byte and store it in CGDATA.
|
; Compute the high-order byte and store it in CGDATA.
|
||||||
lda $22 ; Blue.
|
lda $22 ; Blue.
|
||||||
@ -188,12 +185,12 @@ SetBackgroundColor:
|
|||||||
lsr
|
lsr
|
||||||
.endr
|
.endr
|
||||||
ora $00
|
ora $00
|
||||||
sta $2122
|
sta CGDATA
|
||||||
|
|
||||||
; Set the background color.
|
; Set the background color.
|
||||||
; $2121 is the color palette selection register [CGADD].
|
; $2121 is the color palette selection register [CGADD].
|
||||||
; Entry 0 corresponds to the SNES background color.
|
; Entry 0 corresponds to the SNES background color.
|
||||||
stz $2121
|
stz CGADD
|
||||||
rts
|
rts
|
||||||
|
|
||||||
|
|
||||||
|
46
registers.asm
Normal file
46
registers.asm
Normal file
@ -0,0 +1,46 @@
|
|||||||
|
; Definitions of commonly-used special memory addresses.
|
||||||
|
;
|
||||||
|
; These are commonly called "registers" in online documentation, even though
|
||||||
|
; that feels like a misnomer; these aren't necessarily hardware registers in
|
||||||
|
; the same sense as PC, A, X, Y, and so on. Despite that, I call them
|
||||||
|
; "registers" too, since that's what everyone else calls them.
|
||||||
|
;
|
||||||
|
; Where possible, I have named these register definitions in the same way that
|
||||||
|
; they're named in Yoshi's venerable snes.txt document.
|
||||||
|
|
||||||
|
; $2100: Screen display register [INIDISP]
|
||||||
|
; Format: x000bbbb
|
||||||
|
; x: 0 = screen on, 1 = screen off, bbbb: Brightness ($0-$F)
|
||||||
|
.define INIDISP $2100
|
||||||
|
|
||||||
|
; $2121: Color palette selection register [CGADD]
|
||||||
|
; Entry 0 corresponds to the SNES background color.
|
||||||
|
.define CGADD $2121
|
||||||
|
|
||||||
|
; $2122: Color data register [CGDATA]
|
||||||
|
; The palette color format is 15-bit: [0bbbbbgg][gggrrrrr].
|
||||||
|
; You will typically write to this register twice in a row: first for the
|
||||||
|
; low-order byte (containing green and red) and then for the high-order byte
|
||||||
|
; (containing blue and green).
|
||||||
|
.define CGDATA $2122
|
||||||
|
|
||||||
|
; $4200: Counter enable [NMITIMEN]
|
||||||
|
; n-vh---j n: NMI interrupt enable v: vertical counter enable
|
||||||
|
; h: horizontal counter enable j: joypad enable
|
||||||
|
.define NMITIMEN $4200
|
||||||
|
|
||||||
|
; $4218: Joypad #1 status [JOY1L]
|
||||||
|
; Format: AXLR0000
|
||||||
|
.define JOY1L $4218
|
||||||
|
|
||||||
|
; $4219: Joypad #1 status [JOY1H]
|
||||||
|
; Format: BYsSudlr (s=select, S=start, udlr = joypad)
|
||||||
|
.define JOY1H $4219
|
||||||
|
|
||||||
|
; $421A: Joypad #2 status [JOY2L]
|
||||||
|
; Format: AXLR0000
|
||||||
|
.define JOY2L $421A
|
||||||
|
|
||||||
|
; $421B: Joypad #2 status [JOY2H]
|
||||||
|
; Format: BYsSudlr (s=select, S=start, udlr = joypad)
|
||||||
|
.define JOY2H $421B
|
Loading…
Reference in New Issue
Block a user