Proper DAS charge holding.

This commit is contained in:
Randy Thiemann 2023-10-16 05:45:30 +02:00
parent 7efef9a042
commit 0f1d35ed51
2 changed files with 75 additions and 25 deletions

View File

@ -11,6 +11,7 @@ hAState:: ds 1
hBState:: ds 1 hBState:: ds 1
hStartState:: ds 1 hStartState:: ds 1
hSelectState:: ds 1 hSelectState:: ds 1
hDASCharge:: ds 1
@ -25,10 +26,37 @@ InputInit::
ldh [hBState], a ldh [hBState], a
ldh [hStartState], a ldh [hStartState], a
ldh [hSelectState], a ldh [hSelectState], a
ldh [hDASCharge], a
ret ret
GetInput:: GetInput::
; Check if the left state > DAS charge.
ldh a, [hLeftState]
ld b, a
ldh a, [hDASCharge]
cp a, b
; If so, save the new DAS charge.
jr nc, :+
ld a, b
ldh [hDASCharge], a
; Check if the right state > DAS charge.
: ldh a, [hRightState]
ld b, a
ldh a, [hDASCharge]
cp a, b
; If so, save the new DAS charge.
jr nc, :+
ld a, b
ldh [hDASCharge], a
; There's an overflow risk here if the DAS charge is 255.
: cp a, $FF
jr nz, .btns
dec a
ldh [hDASCharge], a
; Get the button state. ; Get the button state.
.btns .btns
ld a, P1F_GET_BTN ld a, P1F_GET_BTN
@ -39,12 +67,13 @@ GetInput::
ldh a, [rP1] ldh a, [rP1]
ld b, a ld b, a
; Read A button.
.readA .readA
bit 0, b ; A bit 0, b
jr nz, .clearA jr nz, .clearA
.setA .setA
ldh a, [hAState] ldh a, [hAState]
cp $FF cp a, $FF
jr z, .readB jr z, .readB
inc a inc a
ldh [hAState], a ldh [hAState], a
@ -53,12 +82,13 @@ GetInput::
xor a, a xor a, a
ldh [hAState], a ldh [hAState], a
; Read B button.
.readB .readB
bit 1, b ; B bit 1, b
jr nz, .clearB jr nz, .clearB
.setB .setB
ldh a, [hBState] ldh a, [hBState]
cp $FF cp a, $FF
jr z, .readSelect jr z, .readSelect
inc a inc a
ldh [hBState], a ldh [hBState], a
@ -67,12 +97,13 @@ GetInput::
xor a, a xor a, a
ldh [hBState], a ldh [hBState], a
; Read select button.
.readSelect .readSelect
bit 2, b ; Select bit 2, b
jr nz, .clearSelect jr nz, .clearSelect
.setSelect .setSelect
ldh a, [hSelectState] ldh a, [hSelectState]
cp $FF cp a, $FF
jr z, .readStart jr z, .readStart
inc a inc a
ldh [hSelectState], a ldh [hSelectState], a
@ -81,12 +112,13 @@ GetInput::
xor a, a xor a, a
ldh [hSelectState], a ldh [hSelectState], a
; Read start button.
.readStart .readStart
bit 3, b ; Start bit 3, b
jr nz, .clearStart jr nz, .clearStart
.setStart .setStart
ldh a, [hStartState] ldh a, [hStartState]
cp $FF cp a, $FF
jr z, .dpad jr z, .dpad
inc a inc a
ldh [hStartState], a ldh [hStartState], a
@ -95,7 +127,6 @@ GetInput::
xor a, a xor a, a
ldh [hStartState], a ldh [hStartState], a
; Get the dpad state. ; Get the dpad state.
.dpad .dpad
ld a, P1F_GET_DPAD ld a, P1F_GET_DPAD
@ -106,12 +137,13 @@ GetInput::
ldh a, [rP1] ldh a, [rP1]
ld b, a ld b, a
; Read up button.
.readUp .readUp
bit 2, b ; Up bit 2, b
jr nz, .clearUp jr nz, .clearUp
.setUp .setUp
ldh a, [hUpState] ldh a, [hUpState]
cp $FF cp a, $FF
jr z, .readDown jr z, .readDown
inc a inc a
ldh [hUpState], a ldh [hUpState], a
@ -120,12 +152,13 @@ GetInput::
xor a, a xor a, a
ldh [hUpState], a ldh [hUpState], a
; Read down button.
.readDown .readDown
bit 3, b ; Down bit 3, b
jr nz, .clearDown jr nz, .clearDown
.setDown .setDown
ldh a, [hDownState] ldh a, [hDownState]
cp $FF cp a, $FF
jr z, .readLeft jr z, .readLeft
inc a inc a
ldh [hDownState], a ldh [hDownState], a
@ -134,33 +167,50 @@ GetInput::
xor a, a xor a, a
ldh [hDownState], a ldh [hDownState], a
; Read left button. If it's just been pressed, restore the held DAS charge.
.readLeft .readLeft
bit 1, b ; Left bit 1, b
jr nz, .clearLeft jr nz, .clearLeft
.setLeft .setLeft
ldh a, [hLeftState] ldh a, [hLeftState]
cp $FF cp a, $FF
jr z, .readRight jr z, .readRight
inc a cp a, 0
jr nz, :+
ldh a, [hDASCharge]
: inc a
ldh [hLeftState], a ldh [hLeftState], a
jr .readRight jr .readRight
.clearLeft .clearLeft
xor a, a xor a, a
ldh [hLeftState], a ldh [hLeftState], a
; Read right button. If it's just been pressed, restore the held DAS charge.
.readRight .readRight
bit 0, b ; Right bit 0, b
jr nz, .clearRight jr nz, .clearRight
.setRight .setRight
ldh a, [hRightState] ldh a, [hRightState]
cp $FF cp a, $FF
ret z jr z, .checkDAS
inc a cp a, 0
jr nz, :+
ldh a, [hDASCharge]
: inc a
ldh [hRightState], a ldh [hRightState], a
ret jr .checkDAS
.clearRight .clearRight
xor a, a xor a, a
ldh [hRightState], a ldh [hRightState], a
; If none of the four directions are pressed, reset the DAS charge.
.checkDAS
ld a, b
or a, $F0
cp a, $FF
ret nz
xor a, a
ldh [hDASCharge], a
ret ret

View File

@ -1,5 +1,5 @@
#Emulicious settings file #Emulicious settings file
#Fri Oct 13 11:30:41 CEST 2023 #Mon Oct 16 05:45:08 CEST 2023
WindowEventViewerWindowHeight=861 WindowEventViewerWindowHeight=861
WindowEventViewerWindowDivider=309 WindowEventViewerWindowDivider=309
WindowMemoryTracerWindowY=631 WindowMemoryTracerWindowY=631
@ -125,9 +125,9 @@ Key1=75
Key0=74 Key0=74
Gamepad1Key19=-1 Gamepad1Key19=-1
Gamepad1Key18=-1 Gamepad1Key18=-1
WindowEventViewerWindowY=489 WindowEventViewerWindowY=673
Gamepad1Key17=-1 Gamepad1Key17=-1
WindowEventViewerWindowX=1472 WindowEventViewerWindowX=1846
Gamepad1Key16=-1 Gamepad1Key16=-1
Gamepad1Key15=-1 Gamepad1Key15=-1
Gamepad1Key14=-1 Gamepad1Key14=-1
@ -135,7 +135,7 @@ Gamepad1Key13=-1
Gamepad1Key12=-1 Gamepad1Key12=-1
Gamepad1Key11=-1 Gamepad1Key11=-1
Gamepad1Key10=-1 Gamepad1Key10=-1
WindowMemoryEditorSelectedAddress=-1 WindowMemoryEditorSelectedAddress=116
WindowMemoryEditorWidth=665 WindowMemoryEditorWidth=665
GameBoyErrorBreakpointCondition9= GameBoyErrorBreakpointCondition9=
GameBoyErrorBreakpointCondition8= GameBoyErrorBreakpointCondition8=