From d8770ad59a0f2b587631477fd7d1a19805302d8e Mon Sep 17 00:00:00 2001 From: Damian Yerrick Date: Thu, 26 May 2022 17:14:38 -0400 Subject: [PATCH] snes.inc: add symbols for high-byte 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. --- src/player.s | 16 +++++++++------- src/snes.inc | 18 +++++++++++++++++- 2 files changed, 26 insertions(+), 8 deletions(-) diff --git a/src/player.s b/src/player.s index 2b50b45..18c70f6 100644 --- a/src/player.s +++ b/src/player.s @@ -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 @@ -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 @@ -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 diff --git a/src/snes.inc b/src/snes.inc index f57e137..1864270 100644 --- a/src/snes.inc +++ b/src/snes.inc @@ -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 @@ -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