diff --git a/src/include/input.asm b/src/include/input.asm index f94cb62..7911777 100644 --- a/src/include/input.asm +++ b/src/include/input.asm @@ -11,6 +11,7 @@ hAState:: ds 1 hBState:: ds 1 hStartState:: ds 1 hSelectState:: ds 1 +hDASCharge:: ds 1 @@ -25,10 +26,37 @@ InputInit:: ldh [hBState], a ldh [hStartState], a ldh [hSelectState], a + ldh [hDASCharge], a ret 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. .btns ld a, P1F_GET_BTN @@ -39,12 +67,13 @@ GetInput:: ldh a, [rP1] ld b, a + ; Read A button. .readA - bit 0, b ; A + bit 0, b jr nz, .clearA .setA ldh a, [hAState] - cp $FF + cp a, $FF jr z, .readB inc a ldh [hAState], a @@ -53,12 +82,13 @@ GetInput:: xor a, a ldh [hAState], a + ; Read B button. .readB - bit 1, b ; B + bit 1, b jr nz, .clearB .setB ldh a, [hBState] - cp $FF + cp a, $FF jr z, .readSelect inc a ldh [hBState], a @@ -67,12 +97,13 @@ GetInput:: xor a, a ldh [hBState], a + ; Read select button. .readSelect - bit 2, b ; Select + bit 2, b jr nz, .clearSelect .setSelect ldh a, [hSelectState] - cp $FF + cp a, $FF jr z, .readStart inc a ldh [hSelectState], a @@ -81,12 +112,13 @@ GetInput:: xor a, a ldh [hSelectState], a + ; Read start button. .readStart - bit 3, b ; Start + bit 3, b jr nz, .clearStart .setStart ldh a, [hStartState] - cp $FF + cp a, $FF jr z, .dpad inc a ldh [hStartState], a @@ -95,7 +127,6 @@ GetInput:: xor a, a ldh [hStartState], a - ; Get the dpad state. .dpad ld a, P1F_GET_DPAD @@ -106,12 +137,13 @@ GetInput:: ldh a, [rP1] ld b, a + ; Read up button. .readUp - bit 2, b ; Up + bit 2, b jr nz, .clearUp .setUp ldh a, [hUpState] - cp $FF + cp a, $FF jr z, .readDown inc a ldh [hUpState], a @@ -120,12 +152,13 @@ GetInput:: xor a, a ldh [hUpState], a + ; Read down button. .readDown - bit 3, b ; Down + bit 3, b jr nz, .clearDown .setDown ldh a, [hDownState] - cp $FF + cp a, $FF jr z, .readLeft inc a ldh [hDownState], a @@ -134,33 +167,50 @@ GetInput:: xor a, a ldh [hDownState], a + ; Read left button. If it's just been pressed, restore the held DAS charge. .readLeft - bit 1, b ; Left + bit 1, b jr nz, .clearLeft .setLeft ldh a, [hLeftState] - cp $FF + cp a, $FF jr z, .readRight - inc a + cp a, 0 + jr nz, :+ + ldh a, [hDASCharge] +: inc a ldh [hLeftState], a jr .readRight .clearLeft xor a, a ldh [hLeftState], a + ; Read right button. If it's just been pressed, restore the held DAS charge. .readRight - bit 0, b ; Right + bit 0, b jr nz, .clearRight .setRight ldh a, [hRightState] - cp $FF - ret z - inc a + cp a, $FF + jr z, .checkDAS + cp a, 0 + jr nz, :+ + ldh a, [hDASCharge] +: inc a ldh [hRightState], a - ret + jr .checkDAS .clearRight xor a, 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 diff --git a/tools/Emulicious.ini b/tools/Emulicious.ini index 95b1113..87e7857 100644 --- a/tools/Emulicious.ini +++ b/tools/Emulicious.ini @@ -1,5 +1,5 @@ #Emulicious settings file -#Fri Oct 13 11:30:41 CEST 2023 +#Mon Oct 16 05:45:08 CEST 2023 WindowEventViewerWindowHeight=861 WindowEventViewerWindowDivider=309 WindowMemoryTracerWindowY=631 @@ -125,9 +125,9 @@ Key1=75 Key0=74 Gamepad1Key19=-1 Gamepad1Key18=-1 -WindowEventViewerWindowY=489 +WindowEventViewerWindowY=673 Gamepad1Key17=-1 -WindowEventViewerWindowX=1472 +WindowEventViewerWindowX=1846 Gamepad1Key16=-1 Gamepad1Key15=-1 Gamepad1Key14=-1 @@ -135,7 +135,7 @@ Gamepad1Key13=-1 Gamepad1Key12=-1 Gamepad1Key11=-1 Gamepad1Key10=-1 -WindowMemoryEditorSelectedAddress=-1 +WindowMemoryEditorSelectedAddress=116 WindowMemoryEditorWidth=665 GameBoyErrorBreakpointCondition9= GameBoyErrorBreakpointCondition8=