diff --git a/src/constants.asm b/src/constants.asm index 110056a..090ecfe 100644 --- a/src/constants.asm +++ b/src/constants.asm @@ -191,6 +191,8 @@ sSpeedCurve:: ; Speed curve of the game. db 20, 1 ; 20G db 1, 1, 1, 1 ; ARE, DAS, LOCK, LINECLEAR + dw $FFFF ; End. + sPieceRotationStates:: ; How each piece is rotated. ; I db %0000 diff --git a/src/level.asm b/src/level.asm index 07c2c2c..a0660d2 100644 --- a/src/level.asm +++ b/src/level.asm @@ -9,6 +9,17 @@ SECTION "Level Variables", WRAM0 wCLevel:: ds 4 wNLevel:: ds 6 ; The extra 2 bytes will be clobbered by the sprite drawing functions. +SECTION "Critical Level Variables", HRAM +hCurrentDAS:: ds 1 +hCurrentARE:: ds 1 +hCurrentLockDelay:: ds 1 +hCurrentLineClearDelay:: ds 1 +hCurrentGravityPerTick:: ds 1 +hCurrentFramesPerGravityTick:: ds 1 +hNextSpeedUp:: ds 2 +hSpeedCurvePtr:: ds 2 +hRequiresLineClear:: ds 1 + SECTION "Level Functions", ROM0 LevelInit:: @@ -20,9 +31,228 @@ LevelInit:: ld [hl], a ld hl, wNLevel ld [hl+], a + inc a + ld [hl+], a + dec a + ld [hl+], a + ld [hl], a + ldh [hRequiresLineClear], a + + ld hl, sSpeedCurve+2 + ld a, l + ldh [hSpeedCurvePtr], a + ld a, h + ldh [hSpeedCurvePtr+1], a + + call DoSpeedUp + ret + + ; Increment level and speed up if necessary. Level increment in E. + ; Levels may only increment by single digits. +LevelUp:: + ; Return if we're maxed out. + ld hl, wCLevel + ld a, $09 + and a, [hl] + inc hl + and a, [hl] + inc hl + and a, [hl] + inc hl + and a, [hl] + ld c, [hl] + cp a, $09 + ret z + + ; Increment LSD. + ld a, [hl] + add a, e + ld [hl], a + cp a, $0A + jr c, .checknlevel + sub a, 10 + ld [hl], a + + ; Carry the one... + dec hl + ld a, [hl] + inc a + ld [hl], a + cp a, $0A + jr c, .checknlevel + xor a, a + ld [hl], a + + ; Again... + dec hl + ld a, [hl] + inc a + ld [hl], a + cp a, $0A + jr c, .checknlevel + xor a, a + ld [hl], a + + ; Once more... + dec hl + ld a, [hl] + inc a + ld [hl], a + cp a, $0A + jr c, .checknlevel + + ; We're maxed out. Both levels should be set to 9999. + ld a, 9 + ld [hl-], a + ld [hl-], a + ld [hl-], a + ld [hl], a + call DoSpeedUp + ret + +.checknlevel + ; Make wNLevel make sense. + ld hl, wCLevel + ld a, $09 + and a, [hl] + inc hl + and a, [hl] + cp a, $09 + ; If wCLevel begins 99, wNLevel should be 9999. + jr nz, :+ + ld a, 9 + ld hl, wNLevel + ld [hl+], a ld [hl+], a ld [hl+], a ld [hl], a + ; If the last two digits of wCLevel are 98, play the bell. + ld hl, wCLevel+2 + ld a, [hl+] + cp a, 9 + jr nz, .checkspeedup + ld a, [hl] + cp a, 8 + jr nz, .checkspeedup + ld a, SFX_BELL + call SFXEnqueue + jr .checkspeedup + + ; Otherwise check the second digit of wCLevel. +: ld hl, wCLevel+1 + ld a, [hl] + ; If it's 9, wNLevel should be y0xx. With y being the first digit of wCLevel+1 + cp a, 9 + jr nz, :+ + ld hl, wNLevel+1 + xor a, a + ld [hl], a + ld hl, wCLevel + ld a, [hl] + inc a + ld hl, wNLevel + ld [hl], a + jr .bellmaybe + + ; Otherwise just set the second digit of wNLevel to the second digit of wCLevel + 1. +: ld hl, wCLevel+1 + ld a, [hl] + inc a + ld hl, wNLevel+1 + ld [hl], a + +.bellmaybe + ; If the last two digits of wCLevel are 99, play the bell. + ld hl, wCLevel+2 + ld a, [hl+] + and a, [hl] + cp a, 9 + jr nz, .checkspeedup + ld a, SFX_BELL + call SFXEnqueue + +.checkspeedup + ldh a, [hNextSpeedUp] + and a, $F0 + jr z, :+ + rrc a + rrc a + rrc a + rrc a + ld hl, wCLevel + cp a, [hl] + ret nc + +: ldh a, [hNextSpeedUp] + and a, $0F + jr z, :+ + ld hl, wCLevel+1 + cp a, [hl] + jr z, :+ + ret nc + +: ldh a, [hNextSpeedUp+1] + and a, $F0 + jr z, :+ + rrc a + rrc a + rrc a + rrc a + ld hl, wCLevel+2 + cp a, [hl] + jr z, :+ + ret nc + +: ldh a, [hNextSpeedUp+1] + and a, $0F + jr z, :+ + ld hl, wCLevel+3 + cp a, [hl] + jr z, :+ + ret nc + + ldh a, [hNextSpeedUp+0] + ldh a, [hNextSpeedUp+1] + + ld a, [wCLevel+0] + ld a, [wCLevel+1] + ld a, [wCLevel+2] + ld a, [wCLevel+3] + +: call DoSpeedUp + ret + + +DoSpeedUp: + ; Load curve ptr. + ldh a, [hSpeedCurvePtr] + ld l, a + ldh a, [hSpeedCurvePtr+1] + ld h, a + + ; Get all the new data. + ld a, [hl+] + ldh [hCurrentGravityPerTick], a + ld a, [hl+] + ldh [hCurrentFramesPerGravityTick], a + ld a, [hl+] + ldh [hCurrentARE], a + ld a, [hl+] + ldh [hCurrentDAS], a + ld a, [hl+] + ldh [hCurrentLockDelay], a + ld a, [hl+] + ldh [hCurrentLineClearDelay], a + ld a, [hl+] + ldh [hNextSpeedUp+1], a + ld a, [hl+] + ldh [hNextSpeedUp], a + + ; Save the new pointer. + ld a, l + ldh [hSpeedCurvePtr], a + ld a, h + ldh [hSpeedCurvePtr+1], a ret diff --git a/src/res/sources/sfx.fur b/src/res/sources/sfx.fur index d78959d..fc92a0f 100644 Binary files a/src/res/sources/sfx.fur and b/src/res/sources/sfx.fur differ diff --git a/src/state_gameplay.asm b/src/state_gameplay.asm index e4a864e..dc3e3b4 100644 --- a/src/state_gameplay.asm +++ b/src/state_gameplay.asm @@ -15,8 +15,13 @@ DEF MODE_SPAWN_PIECE EQU 4 SECTION "Gameplay Variables", WRAM0 wMode: ds 1 wModeCounter: ds 1 -wCurrentPiece: ds 1 -wHeldPiece: ds 1 + +SECTION "Critical Gameplay Variables", HRAM +hCurrentPiece: ds 1 +hCurrentPieceX: ds 1 +hCurrentPieceY: ds 1 +hCurrentPieceRotationState: ds 1 +hHeldPiece: ds 1 SECTION "Gameplay Functions", ROM0 @@ -47,13 +52,9 @@ SwitchToGameplay:: call LevelInit call FieldInit - ; Next level is 0100. - ld a, 1 - ld [wNLevel+1], a - ; We don't start with a held piece. ld a, PIECE_NONE - ld [wHeldPiece], a + ldh [hHeldPiece], a ; Leady mode. ld a, MODE_LEADY @@ -138,7 +139,7 @@ postGoMode: ; Fetch the next piece. fetchPieceMode: ld a, [wNextPiece] - ld [wCurrentPiece], a + ldh [hCurrentPiece], a call GetNextPiece ; Check if IRS is charged. @@ -160,6 +161,9 @@ fetchPieceMode: spawnPieceMode: ; todo + ld e, 1 + call LevelUp + ld a, [hUpState] cp a, 1 jr nz, :+ @@ -192,7 +196,7 @@ drawStaticInfo: : ld a, [wNextPiece] call ApplyNext - ld a, [wHeldPiece] + ldh a, [hHeldPiece] call ApplyHold ld hl, wSPRScore1 diff --git a/tools/Emulicious.ini b/tools/Emulicious.ini index fbc3259..57b6acc 100644 --- a/tools/Emulicious.ini +++ b/tools/Emulicious.ini @@ -1,5 +1,5 @@ #Emulicious settings file -#Tue Oct 17 07:59:30 CEST 2023 +#Tue Oct 17 13:52:17 CEST 2023 WindowEventViewerWindowHeight=861 WindowEventViewerWindowDivider=309 WindowMemoryTracerWindowY=631 @@ -52,7 +52,7 @@ Key20=-1 MemoryTracer=true Key19=72 Key18=71 -DebuggerMemorySelectedAddress=4 +DebuggerMemorySelectedAddress=7 SMSGamepadBKeyboard=false Key17=76 Key16=74 @@ -117,6 +117,7 @@ Key9=40 Key8=38 Key7=83 Key6=87 +HighlightingPreference=-1 Key5=65 Key4=68 Key3=10 @@ -174,7 +175,7 @@ DebuggerHideToolbar=false Gamepad0Key21=-1 WindowDebuggerWidth=1481 Gamepad0Key20=-1 -DebuggerSouthPanelSelectedTab=0 +DebuggerSouthPanelSelectedTab=1 WindowEmuliciousWidth=816 WindowVideoViewerWidth=980 WindowMemoryEditorY=827 @@ -198,8 +199,8 @@ GameBoyErrorBreakpointMessage32= InterruptBreakpointCondition= Recent0=C\:\\workspace\\dmgtris\\bin\\out.gb GameBoyErrorBreakpointMessage20= -WindowEmuliciousY=316 -WindowEmuliciousX=619 +WindowEmuliciousY=513 +WindowEmuliciousX=97 GameBoyErrorBreakpointEnabled9=false GameBoyErrorBreakpointEnabled8=false GameBoyErrorBreakpointEnabled7=false @@ -263,8 +264,8 @@ Gamepad0Key3=-1 Gamepad0Key2=-1 Gamepad0Key1=-1 Gamepad0Key0=-1 -WindowDebuggerY=170 -WindowDebuggerX=1172 +WindowDebuggerY=369 +WindowDebuggerX=830 InterruptBreakpointSuspend=true SMSGamepadAKeyboard=false GameBoyErrorBreakpointSuspend32=true diff --git a/tools/projects/out.exp b/tools/projects/out.exp new file mode 100644 index 0000000..e81807f --- /dev/null +++ b/tools/projects/out.exp @@ -0,0 +1 @@ +wCLevel 4 Hexadecimal