Skip to content

Commit

Permalink
snes.inc: add symbols for high-byte
Browse files Browse the repository at this point in the history
In #3, a user of the template reported confusion between reading
the controller's entire report as a 16-bit unit and reading only
the high byte as an 8-bit unit.  To make this confusion less
likely going forward, add a set of labels and constants for
reading the high byte for convenience in porting NES code.
  • Loading branch information
pinobatch committed May 26, 2022
1 parent c3a0d21 commit d8770ad
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 8 deletions.
16 changes: 9 additions & 7 deletions src/player.s
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,11 @@ player_facing: .res 1
rtl
.endproc

; except for STZs and BRAs, the following subroutine is
; direct copypasta from the NES template code
cur_keys := JOY1CUR+1
; Except for STZs and BRAs, the following subroutine is copied and
; pasted from the NES template code. We use JOY1CUR_HI for this
; particular routine because that most directly corresponds to the
; bit layout of the NES controller. When using JOYxCUR_HI, we also
; use the matching set of KEY_HI_* constants.

; constants used by move_player
; PAL frames are about 20% longer than NTSC frames. So if you make
Expand All @@ -81,8 +83,8 @@ RIGHT_WALL = 224
; Acceleration to right: Do it only if the player is holding right
; on the Control Pad and has a nonnegative velocity.
setaxy8
lda cur_keys
and #>KEY_RIGHT
lda JOY1CUR_HI
and #KEY_HI_RIGHT
beq notRight
lda player_dxlo
bmi notRight
Expand Down Expand Up @@ -115,8 +117,8 @@ RIGHT_WALL = 224

; Acceleration to left: Do it only if the player is holding left
; on the Control Pad and has a nonpositive velocity.
lda cur_keys
and #>KEY_LEFT
lda JOY1CUR_HI
and #KEY_HI_LEFT
beq notLeft
lda player_dxlo
beq isLeft
Expand Down
18 changes: 17 additions & 1 deletion src/snes.inc
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,7 @@ JOYOUT := $4201
; +-------- Controller 2 pin 6 output
; Results of the autoreader
JOY1CUR := $4218 ; Bit 0: used by standard controllers
JOY1CUR := $4218 ; Bit 0: used by standard controllers
JOY2CUR := $421A
JOY1B1CUR := $421C ; Bit 1: used by multitap and a few oddball
JOY2B1CUR := $421E ; input devices
Expand All @@ -334,6 +334,22 @@ KEY_X = $0040
KEY_L = $0020
KEY_R = $0010
; It is also possible to read the controller by reading only the
; upper 8 bits in 8-bit mode (m=1). This may be the path of least
; resistance for porting NES software to the Super NES. Be careful
; not to mix _HI addresses with non-_HI constants or vice versa.
; A, X, L, and R cannot be read this way.
JOY1CUR_HI := JOY1CUR + 1
JOY2CUR_HI := JOY2CUR + 1
KEY_HI_B = .hibyte(KEY_B)
KEY_HI_Y = .hibyte(KEY_Y)
KEY_HI_SELECT = .hibyte(KEY_SELECT)
KEY_HI_START = .hibyte(KEY_START)
KEY_HI_UP = .hibyte(KEY_UP)
KEY_HI_DOWN = .hibyte(KEY_DOWN)
KEY_HI_LEFT = .hibyte(KEY_LEFT)
KEY_HI_RIGHT = .hibyte(KEY_RIGHT)
; S-CPU multiply and divide ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; Multiply unit. Also good for shifting pixels when drawing
Expand Down

0 comments on commit d8770ad

Please sign in to comment.