Use hram constants for remaining joypad variables.

This commit is contained in:
yenatch 2014-08-30 19:48:49 -07:00
parent 365ae68d80
commit 8f49e37b82
8 changed files with 71 additions and 68 deletions

View file

@ -537,7 +537,7 @@ TradeCenter_SelectMon:
ld [wTileMap + $141], a ld [wTileMap + $141], a
.asm_574a .asm_574a
call JoypadLowSensitivity call JoypadLowSensitivity
ld a, [$ffb5] ld a, [hJoy5]
and a and a
jr z, .asm_574a ; 0x5750 $f8 jr z, .asm_574a ; 0x5750 $f8
bit 0, a bit 0, a
@ -896,7 +896,7 @@ Func_5a5f: ; 5a5f (1:5a5f)
ld [W_GRASSRATE], a ; W_GRASSRATE ld [W_GRASSRATE], a ; W_GRASSRATE
inc a inc a
ld [W_ISLINKBATTLE], a ; W_ISLINKBATTLE ld [W_ISLINKBATTLE], a ; W_ISLINKBATTLE
ld [$ffb5], a ld [hJoy5], a
ld a, $a ld a, $a
ld [wMusicHeaderPointer], a ld [wMusicHeaderPointer], a
ld a, BANK(Music_Celadon) ld a, BANK(Music_Celadon)

View file

@ -140,7 +140,7 @@ asm_7befa: ; 7befa (1e:7efa)
call DelayFrame call DelayFrame
push bc push bc
call JoypadLowSensitivity call JoypadLowSensitivity
ld a, [$ffb5] ld a, [hJoy5]
pop bc pop bc
and $2 and $2
jr nz, .asm_7bf0d jr nz, .asm_7bf0d

View file

@ -307,7 +307,7 @@ Func_5d5f: ; 5d5f (1:5d5f)
xor a xor a
ld [hJoyPressed], a ld [hJoyPressed], a
ld [hJoyHeld], a ld [hJoyHeld], a
ld [$ffb5], a ld [hJoy5], a
ld [wd72d], a ld [wd72d], a
ld hl, wd732 ld hl, wd732
set 0, [hl] set 0, [hl]
@ -461,7 +461,7 @@ DisplayOptionMenu: ; 5e8a (1:5e8a)
call SetOptionsFromCursorPositions call SetOptionsFromCursorPositions
.getJoypadStateLoop .getJoypadStateLoop
call JoypadLowSensitivity call JoypadLowSensitivity
ld a,[$ffb5] ld a,[hJoy5]
ld b,a ld b,a
and a,%11111011 ; any key besides select pressed? and a,%11111011 ; any key besides select pressed?
jr z,.getJoypadStateLoop jr z,.getJoypadStateLoop

View file

@ -10,7 +10,7 @@ ShowPokedexMenu: ; 40000 (10:4000)
ld [wLastMenuItem],a ld [wLastMenuItem],a
inc a inc a
ld [wd11e],a ld [wd11e],a
ld [$ffb7],a ld [hJoy7],a
.setUpGraphics .setUpGraphics
ld b,$08 ld b,$08
call GoPAL_SET call GoPAL_SET
@ -35,7 +35,7 @@ ShowPokedexMenu: ; 40000 (10:4000)
ld [wcc37],a ld [wcc37],a
ld [wCurrentMenuItem],a ld [wCurrentMenuItem],a
ld [wLastMenuItem],a ld [wLastMenuItem],a
ld [$ffb7],a ld [hJoy7],a
ld [wcd3a],a ld [wcd3a],a
ld [wcd3b],a ld [wcd3b],a
pop af pop af
@ -550,7 +550,7 @@ ShowPokedexDataInternal: ; 402e2 (10:42e2)
ld [$fff4],a ld [$fff4],a
.waitForButtonPress .waitForButtonPress
call JoypadLowSensitivity call JoypadLowSensitivity
ld a,[$ffb5] ld a,[hJoy5]
and a,%00000011 ; A button and B button and a,%00000011 ; A button and B button
jr z,.waitForButtonPress jr z,.waitForButtonPress
pop af pop af

View file

@ -797,7 +797,7 @@ SlotMachine_3784e: ; 3784e (d:784e)
SlotMachine_37882: ; 37882 (d:7882) SlotMachine_37882: ; 37882 (d:7882)
call DelayFrame call DelayFrame
call JoypadLowSensitivity call JoypadLowSensitivity
ld a, [$ffb5] ld a, [hJoy5]
and $1 and $1
ret z ret z
ld hl, wTrainerSpriteOffset ld hl, wTrainerSpriteOffset

View file

@ -6,7 +6,7 @@ DisplayTownMap: ; 70e3e (1c:4e3e)
ld [hl], $ff ld [hl], $ff
push hl push hl
ld a, $1 ld a, $1
ld [$ffb7], a ld [hJoy7], a
ld a, [W_CURMAP] ; W_CURMAP ld a, [W_CURMAP] ; W_CURMAP
push af push af
ld b, $0 ld b, $0
@ -66,7 +66,7 @@ Func_70e92: ; 70e92 (1c:4e92)
.asm_70ec8 .asm_70ec8
call Func_716c6 call Func_716c6
call JoypadLowSensitivity call JoypadLowSensitivity
ld a, [$ffb5] ld a, [hJoy5]
ld b, a ld b, a
and $c3 and $c3
jr z, .asm_70ec8 jr z, .asm_70ec8
@ -78,7 +78,7 @@ Func_70e92: ; 70e92 (1c:4e92)
jr nz, .asm_70f01 jr nz, .asm_70f01
xor a xor a
ld [wd09b], a ld [wd09b], a
ld [$ffb7], a ld [hJoy7], a
ld [W_SUBANIMTRANSFORM], a ; W_SUBANIMTRANSFORM ld [W_SUBANIMTRANSFORM], a ; W_SUBANIMTRANSFORM
call Func_711ab call Func_711ab
pop hl pop hl
@ -188,7 +188,7 @@ LoadTownMap_Fly: ; 70f90 (1c:4f90)
push hl push hl
call DelayFrame call DelayFrame
call JoypadLowSensitivity call JoypadLowSensitivity
ld a, [$ffb5] ld a, [hJoy5]
ld b, a ld b, a
pop hl pop hl
and $c3 and $c3

View file

@ -102,34 +102,34 @@ Start::
INCLUDE "home/joypad.asm" INCLUDE "home/joypad.asm"
INCLUDE "data/map_header_pointers.asm" INCLUDE "data/map_header_pointers.asm"
INCLUDE "home/overworld.asm" INCLUDE "home/overworld.asm"
; this is used to check if the player wants to interrupt the opening sequence at several points
; XXX is this used anywhere else?
; INPUT:
; c = number of frames to wait
; sets carry if Up+Select+B, Start, or A is pressed within c frames
; unsets carry otherwise
CheckForUserInterruption:: ; 12f8 (0:12f8) CheckForUserInterruption:: ; 12f8 (0:12f8)
; Return carry if Up+Select+B, Start or A are pressed in c frames.
; Used only in the intro and title screen.
call DelayFrame call DelayFrame
push bc push bc
call JoypadLowSensitivity call JoypadLowSensitivity
pop bc pop bc
ld a,[hJoyHeld] ; currently pressed buttons
cp a,%01000110 ; Up, Select button, B button ld a, [hJoyHeld]
jr z,.setCarry ; if all three keys are pressed cp D_UP + SELECT + B_BUTTON
ld a,[$ffb5] ; either newly pressed buttons or currently pressed buttons at low sampling rate jr z, .input
and a,%00001001 ; Start button, A button
jr nz,.setCarry ; if either key is pressed ld a, [hJoy5]
and START | A_BUTTON
jr nz, .input
dec c dec c
jr nz,CheckForUserInterruption jr nz, CheckForUserInterruption
.unsetCarry
and a and a
ret ret
.setCarry
.input
scf scf
ret ret
@ -1347,7 +1347,7 @@ DisplayListMenuID:: ; 2be6 (0:2be6)
xor a xor a
ld [H_AUTOBGTRANSFERENABLED],a ; disable auto-transfer ld [H_AUTOBGTRANSFERENABLED],a ; disable auto-transfer
ld a,1 ld a,1
ld [$ffb7],a ; joypad state update flag ld [hJoy7],a ; joypad state update flag
ld a,[W_BATTLETYPE] ld a,[W_BATTLETYPE]
and a ; is it the Old Man battle? and a ; is it the Old Man battle?
jr nz,.specialBattleType jr nz,.specialBattleType
@ -1501,7 +1501,7 @@ DisplayListMenuIDLoop:: ; 2c53 (0:2c53)
ld a,[wCurrentMenuItem] ld a,[wCurrentMenuItem]
ld [wd12d],a ld [wd12d],a
xor a xor a
ld [$ffb7],a ; joypad state update flag ld [hJoy7],a ; joypad state update flag
ld hl,wd730 ld hl,wd730
res 6,[hl] ; turn on letter printing delay res 6,[hl] ; turn on letter printing delay
jp BankswitchBack jp BankswitchBack
@ -1662,7 +1662,7 @@ ExitListMenu:: ; 2e3b (0:2e3b)
ld [wd12e],a ld [wd12e],a
ld [wcc37],a ld [wcc37],a
xor a xor a
ld [$ffb7],a ld [hJoy7],a
ld hl,wd730 ld hl,wd730
res 6,[hl] res 6,[hl]
call BankswitchBack call BankswitchBack
@ -3347,29 +3347,29 @@ CopyString:: ; 3829 (0:3829)
ret ret
; this function is used when lower button sensitivity is wanted (e.g. menus) ; this function is used when lower button sensitivity is wanted (e.g. menus)
; OUTPUT: [$ffb5] = pressed buttons in usual format ; OUTPUT: [hJoy5] = pressed buttons in usual format
; there are two flags that control its functionality, [$ffb6] and [$ffb7] ; there are two flags that control its functionality, [hJoy6] and [hJoy7]
; there are esentially three modes of operation ; there are esentially three modes of operation
; 1. Get newly pressed buttons only ; 1. Get newly pressed buttons only
; ([$ffb7] == 0, [$ffb6] == any) ; ([hJoy7] == 0, [hJoy6] == any)
; Just copies [hJoyPressed] to [$ffb5]. ; Just copies [hJoyPressed] to [hJoy5].
; 2. Get currently pressed buttons at low sample rate with delay ; 2. Get currently pressed buttons at low sample rate with delay
; ([$ffb7] == 1, [$ffb6] != 0) ; ([hJoy7] == 1, [hJoy6] != 0)
; If the user holds down buttons for more than half a second, ; If the user holds down buttons for more than half a second,
; report buttons as being pressed up to 12 times per second thereafter. ; report buttons as being pressed up to 12 times per second thereafter.
; If the user holds down buttons for less than half a second, ; If the user holds down buttons for less than half a second,
; report only one button press. ; report only one button press.
; 3. Same as 2, but report no buttons as pressed if A or B is held down. ; 3. Same as 2, but report no buttons as pressed if A or B is held down.
; ([$ffb7] == 1, [$ffb6] == 0) ; ([hJoy7] == 1, [hJoy6] == 0)
JoypadLowSensitivity:: ; 3831 (0:3831) JoypadLowSensitivity:: ; 3831 (0:3831)
call Joypad call Joypad
ld a,[$ffb7] ; flag ld a,[hJoy7] ; flag
and a ; get all currently pressed buttons or only newly pressed buttons? and a ; get all currently pressed buttons or only newly pressed buttons?
ld a,[hJoyPressed] ; newly pressed buttons ld a,[hJoyPressed] ; newly pressed buttons
jr z,.storeButtonState jr z,.storeButtonState
ld a,[hJoyHeld] ; all currently pressed buttons ld a,[hJoyHeld] ; all currently pressed buttons
.storeButtonState .storeButtonState
ld [$ffb5],a ld [hJoy5],a
ld a,[hJoyPressed] ; newly pressed buttons ld a,[hJoyPressed] ; newly pressed buttons
and a ; have any buttons been newly pressed since last check? and a ; have any buttons been newly pressed since last check?
jr z,.noNewlyPressedButtons jr z,.noNewlyPressedButtons
@ -3383,18 +3383,18 @@ JoypadLowSensitivity:: ; 3831 (0:3831)
jr z,.delayOver jr z,.delayOver
.delayNotOver .delayNotOver
xor a xor a
ld [$ffb5],a ; report no buttons as pressed ld [hJoy5],a ; report no buttons as pressed
ret ret
.delayOver .delayOver
; if [$ffb6] = 0 and A or B is pressed, report no buttons as pressed ; if [hJoy6] = 0 and A or B is pressed, report no buttons as pressed
ld a,[hJoyHeld] ld a,[hJoyHeld]
and a,%00000011 ; A and B buttons and a,%00000011 ; A and B buttons
jr z,.setShortDelay jr z,.setShortDelay
ld a,[$ffb6] ; flag ld a,[hJoy6] ; flag
and a and a
jr nz,.setShortDelay jr nz,.setShortDelay
xor a xor a
ld [$ffb5],a ld [hJoy5],a
.setShortDelay .setShortDelay
ld a,5 ; 1/12 of a second delay ld a,5 ; 1/12 of a second delay
ld [H_FRAMECOUNTER],a ld [H_FRAMECOUNTER],a
@ -3421,7 +3421,7 @@ WaitForTextScrollButtonPress:: ; 3865 (0:3865)
pop hl pop hl
call JoypadLowSensitivity call JoypadLowSensitivity
predef Func_5a5f predef Func_5a5f
ld a, [$ffb5] ld a, [hJoy5]
and A_BUTTON | B_BUTTON and A_BUTTON | B_BUTTON
jr z, .asm_3872 jr z, .asm_3872
pop af pop af
@ -3888,7 +3888,7 @@ HandleMenuInputPokemonSelection:: ; 3ac2 (0:3ac2)
.getJoypadState .getJoypadState
pop hl pop hl
call JoypadLowSensitivity call JoypadLowSensitivity
ld a,[$ffb5] ld a,[hJoy5]
and a ; was a key pressed? and a ; was a key pressed?
jr nz,.keyPressed jr nz,.keyPressed
push hl push hl
@ -3911,7 +3911,7 @@ HandleMenuInputPokemonSelection:: ; 3ac2 (0:3ac2)
.keyPressed .keyPressed
xor a xor a
ld [wcc4b],a ld [wcc4b],a
ld a,[$ffb5] ld a,[hJoy5]
ld b,a ld b,a
bit 6,a ; pressed Up key? bit 6,a ; pressed Up key?
jr z,.checkIfDownPressed jr z,.checkIfDownPressed
@ -3953,7 +3953,7 @@ HandleMenuInputPokemonSelection:: ; 3ac2 (0:3ac2)
and b ; does the menu care about any of the pressed keys? and b ; does the menu care about any of the pressed keys?
jp z,.loop1 jp z,.loop1
.checkIfAButtonOrBButtonPressed .checkIfAButtonOrBButtonPressed
ld a,[$ffb5] ld a,[hJoy5]
and a,%00000011 ; pressed A button or B button? and a,%00000011 ; pressed A button or B button?
jr z,.skipPlayingSound jr z,.skipPlayingSound
.AButtonOrBButtonPressed .AButtonOrBButtonPressed
@ -3971,7 +3971,7 @@ HandleMenuInputPokemonSelection:: ; 3ac2 (0:3ac2)
ld [H_DOWNARROWBLINKCNT1],a ; restore previous values ld [H_DOWNARROWBLINKCNT1],a ; restore previous values
xor a xor a
ld [wMenuWrappingEnabled],a ; disable menu wrapping ld [wMenuWrappingEnabled],a ; disable menu wrapping
ld a,[$ffb5] ld a,[hJoy5]
ret ret
.noWrappingAround .noWrappingAround
ld a,[wcc37] ld a,[wcc37]

View file

@ -1,8 +1,8 @@
H_SPRITEWIDTH EQU $FF8B ; in bytes H_SPRITEWIDTH EQU $FF8B ; in tiles
H_SPRITEINTERLACECOUNTER EQU $FF8B H_SPRITEINTERLACECOUNTER EQU $FF8B
H_SPRITEHEIGHT EQU $FF8C ; in bytes H_SPRITEHEIGHT EQU $FF8C ; in tiles
H_SPRITEOFFSET EQU $FF8D H_SPRITEOFFSET EQU $FF8D
hSoftReset EQU $FF8A hSoftReset EQU $FF8A
; Initialized to 16. ; Initialized to 16.
@ -14,28 +14,31 @@ hSoftReset EQU $FF8A
H_DOWNARROWBLINKCNT1 EQU $FF8B H_DOWNARROWBLINKCNT1 EQU $FF8B
H_DOWNARROWBLINKCNT2 EQU $FF8C H_DOWNARROWBLINKCNT2 EQU $FF8C
; Note: the following multiplication and division addresses are used for multiple purposes ; Multiplcation and division variables are meant
; and so they overlap with each other ; to overlap for back-to-back usage. Big endian.
H_MULTIPLICAND EQU $FF96 ; 3 bytes, big endian order H_MULTIPLICAND EQU $FF96 ; 3 bytes
H_MULTIPLIER EQU $FF99 ; 1 byte H_MULTIPLIER EQU $FF99 ; 1 byte
H_PRODUCT EQU $FF95 ; 4 bytes, big endian order H_PRODUCT EQU $FF95 ; 4 bytes
H_DIVIDEND EQU $FF95 ; 4 bytes, big endian order H_DIVIDEND EQU $FF95 ; 4 bytes
H_DIVISOR EQU $FF99 ; 1 byte H_DIVISOR EQU $FF99 ; 1 byte
H_QUOTIENT EQU $FF95 ; 4 bytes, big endian order H_QUOTIENT EQU $FF95 ; 4 bytes
H_REMAINDER EQU $FF99 ; 1 byte H_REMAINDER EQU $FF99 ; 1 byte
; used to convert numbers to decimal ; PrintNumber (big endian).
H_PASTLEADINGZEROES EQU $FF95 ; flag to indicate that a nonzero digit has been printed H_PASTLEADINGZEROES EQU $FF95 ; last char printed
H_NUMTOPRINT EQU $FF96 ; 3 bytes, big endian order H_NUMTOPRINT EQU $FF96 ; 3 bytes
H_POWEROFTEN EQU $FF99 ; 3 bytes, big endian order H_POWEROFTEN EQU $FF99 ; 3 bytes
H_SAVEDNUMTOPRINT EQU $FF9C ; 3 bytes, big endian order (to back out of a subtraction) H_SAVEDNUMTOPRINT EQU $FF9C ; 3 bytes
hJoyHeldLast EQU $FFB1 hJoyHeldLast EQU $FFB1
hJoyReleased EQU $FFB2 hJoyReleased EQU $FFB2
hJoyPressed EQU $FFB3 hJoyPressed EQU $FFB3
hJoyHeld EQU $FFB4 hJoyHeld EQU $FFB4
hJoy5 EQU $FFB5
hJoy6 EQU $FFB6
hJoy7 EQU $FFB7
H_LOADEDROMBANK EQU $FFB8 H_LOADEDROMBANK EQU $FFB8