Compare commits

..

3 Commits

Author SHA1 Message Date
Randy Thiemann 9b347b9e76 Improve gameplay sequencing. 2023-10-23 06:17:50 +02:00
Randy Thiemann 6474d431a4 Clear up a byte of memory. 2023-10-23 06:17:34 +02:00
Randy Thiemann 6ca137d41b Fix hold + IRS bug. 2023-10-23 06:16:55 +02:00
4 changed files with 191 additions and 140 deletions

View File

@ -53,6 +53,7 @@ hComboCt: ds 1
hLockDelayForce: ds 1 hLockDelayForce: ds 1
hHighestStack: ds 1 hHighestStack: ds 1
hDownFrames: ds 1 hDownFrames: ds 1
hStalePiece: ds 1
SECTION "Field Functions", ROM0 SECTION "Field Functions", ROM0
@ -502,6 +503,7 @@ ForceSpawnPiece::
TrySpawnPiece:: TrySpawnPiece::
; Always reset these for a new piece. ; Always reset these for a new piece.
xor a, a xor a, a
ldh [hStalePiece], a
ldh [hDownFrames], a ldh [hDownFrames], a
ldh [hLockDelayForce], a ldh [hLockDelayForce], a
ldh a, [hCurrentLockDelay] ldh a, [hCurrentLockDelay]
@ -660,7 +662,7 @@ FindMaxG:
ldh a, [hCurrentPieceX] ldh a, [hCurrentPieceX]
call XYToSFieldPtr call XYToSFieldPtr
DEF EXPERIMENTAL_OPTIMIZATION EQU 1 ;DEF EXPERIMENTAL_OPTIMIZATION EQU 1
IF DEF(EXPERIMENTAL_OPTIMIZATION) IF DEF(EXPERIMENTAL_OPTIMIZATION)
; The stack height marker gives a lower bound to how far the piece can fall. ; The stack height marker gives a lower bound to how far the piece can fall.
ldh a, [hHighestStack] ldh a, [hHighestStack]
@ -686,7 +688,6 @@ IF DEF(EXPERIMENTAL_OPTIMIZATION)
jr .try jr .try
ENDC ENDC
.unoptimized .unoptimized
push hl push hl
ld a, 1 ld a, 1
@ -723,128 +724,30 @@ FieldProcess::
ldh [hYPosAtStartOfFrame], a ldh [hYPosAtStartOfFrame], a
call FromShadowField call FromShadowField
; Cleanup from last frame.
; Check if we're about to hold. Return if so.
ldh a, [hSelectState]
cp a, 1
jr nz, :+
ldh a, [hHoldSpent]
cp a, $FF
ret nz
; How deep can we go?
: call FindMaxG
; **************************************************************
; HANDLE UP
; Is a hard/sonic drop requested?
ldh a, [hUpState]
cp a, 1
jr nz, .postdrop
; What kind, if any?
ldh a, [hSimulationMode]
cp a, MODE_TGM1
jr z, .postdrop
cp a, MODE_HELL
jr z, .postdrop
cp a, MODE_TGW2
jr z, .harddrop
cp a, MODE_TGW3
jr z, .harddrop
cp a, MODE_EAWY
jr z, .harddrop
; Sonic drop.
.sonicdrop
ldh a, [hDownFrames]
add a, 10
ldh [hDownFrames], a
ld a, 20
ldh [hWantedG], a
ldh a, [hTicksUntilG]
dec a
ldh [hTicksUntilG], a
jr nz, .grav
ldh a, [hCurrentFramesPerGravityTick]
ldh [hTicksUntilG], a
jr .grav
; Hard drop.
.harddrop
ldh a, [hDownFrames]
add a, 10
ldh [hDownFrames], a
ld a, 20
ld b, a
ldh a, [hActualG]
cp a, b
jr nc, :+
ld b, a
: ldh a, [hCurrentPieceY]
add a, b
ldh [hCurrentPieceY], a
xor a, a
ldh [hCurrentLockDelayRemaining], a
call SFXKill
ld a, SFX_LOCK
call SFXEnqueue
jp .draw
; If we press down, we want to do a soft drop.
.postdrop
ldh a, [hDownState]
cp a, 0
jr z, :+
ldh a, [hDownFrames]
inc a
ldh [hDownFrames], a
ld a, 1
ldh [hTicksUntilG], a
; Gravity?
: ldh a, [hTicksUntilG]
dec a
ldh [hTicksUntilG], a
jr nz, .nograv
ldh a, [hCurrentFramesPerGravityTick]
ldh [hTicksUntilG], a
ldh a, [hCurrentGravityPerTick]
ldh [hWantedG], a
; Can we drop the full requested distance?
.grav
ldh a, [hWantedG]
ld b, a
ldh a, [hActualG]
cp a, b
jr c, .smallg
; Yes. Do it.
.bigg
ldh a, [hWantedG]
ld b, a
ldh a, [hCurrentPieceY]
add a, b
ldh [hCurrentPieceY], a
jr .nograv
; No. Smaller distance.
.smallg
ldh a, [hActualG]
ld b, a
ldh a, [hCurrentPieceY]
add a, b
ldh [hCurrentPieceY], a
; No gravity, or post gravity.
.nograv
ldh a, [hCurrentPieceX] ldh a, [hCurrentPieceX]
ldh [hWantX], a ldh [hWantX], a
ldh a, [hCurrentPieceRotationState] ldh a, [hCurrentPieceRotationState]
ldh [hWantRotation], a ldh [hWantRotation], a
; Is this the first frame of the piece?
ldh a, [hStalePiece]
cp a, 0
ld a, $FF
ldh [hStalePiece], a
jp z, .skipmovement
; **************************************************************
; HANDLE SELECT
; Check if we're about to hold. Return if so.
ldh a, [hSelectState]
cp a, 1
jr nz, .wantrotccw
ldh a, [hHoldSpent]
cp a, $FF
ret nz
; ************************************************************** ; **************************************************************
; HANDLE ROTATION ; HANDLE ROTATION
@ -1232,10 +1135,122 @@ FieldProcess::
ldh [hCurrentPieceX], a ldh [hCurrentPieceX], a
; **************************************************************
; HANDLE MAXIMUM FALL
; This little maneuver is going to cost us 51 years.
.skipmovement
.donemanipulating
: call FindMaxG
; **************************************************************
; HANDLE UP
; Is a hard/sonic drop requested?
ldh a, [hUpState]
cp a, 0
jr z, .postdrop
; What kind, if any?
ldh a, [hSimulationMode]
cp a, MODE_TGM1
jr z, .postdrop
cp a, MODE_HELL
jr z, .postdrop
cp a, MODE_TGW2
jr z, .harddrop
cp a, MODE_TGW3
jr z, .harddrop
cp a, MODE_EAWY
jr z, .harddrop
; Sonic drop.
.sonicdrop
ldh a, [hDownFrames]
add a, 10
ldh [hDownFrames], a
ld a, 20
ldh [hWantedG], a
ldh a, [hTicksUntilG]
dec a
ldh [hTicksUntilG], a
jr nz, .grav
ldh a, [hCurrentFramesPerGravityTick]
ldh [hTicksUntilG], a
jr .grav
; Hard drop.
.harddrop
ldh a, [hDownFrames]
add a, 10
ldh [hDownFrames], a
ld a, 20
ld b, a
ldh a, [hActualG]
cp a, b
jr nc, :+
ld b, a
: ldh a, [hCurrentPieceY]
add a, b
ldh [hCurrentPieceY], a
xor a, a
ldh [hCurrentLockDelayRemaining], a
call SFXKill
ld a, SFX_LOCK
call SFXEnqueue
jp .draw
; If we press down, we want to do a soft drop.
.postdrop
ldh a, [hDownState]
cp a, 0
jr z, :+
ldh a, [hDownFrames]
inc a
ldh [hDownFrames], a
ld a, 1
ldh [hTicksUntilG], a
; Gravity?
: ldh a, [hTicksUntilG]
dec a
ldh [hTicksUntilG], a
jr nz, .nograv
ldh a, [hCurrentFramesPerGravityTick]
ldh [hTicksUntilG], a
ldh a, [hCurrentGravityPerTick]
ldh [hWantedG], a
; Can we drop the full requested distance?
.grav
ldh a, [hWantedG]
ld b, a
ldh a, [hActualG]
cp a, b
jr c, .smallg
; Yes. Do it.
.bigg
ldh a, [hWantedG]
ld b, a
ldh a, [hCurrentPieceY]
add a, b
ldh [hCurrentPieceY], a
jr .postgrav
; No. Smaller distance.
.smallg
ldh a, [hActualG]
ld b, a
ldh a, [hCurrentPieceY]
add a, b
ldh [hCurrentPieceY], a
; ************************************************************** ; **************************************************************
; HANDLE LOCKING ; HANDLE LOCKING
; Are we grounded? ; Are we grounded?
.donemanipulating .postgrav
.nograv
ldh a, [hCurrentPieceY] ldh a, [hCurrentPieceY]
inc a inc a
ld b, a ld b, a
@ -1249,42 +1264,57 @@ FieldProcess::
jr z, .notgrounded jr z, .notgrounded
; We're grounded. ; We're grounded.
; If the y position changed, play a sound. .grounded
ldh a, [hCurrentPieceY] ldh a, [hCurrentPieceY]
ld b, a ld b, a
ldh a, [hYPosAtStartOfFrame] ldh a, [hYPosAtStartOfFrame]
cp a, b cp a, b
jr z, :+ jr z, .postcheckforfirmdropsound ; Never play the sound if we didn't change rows.
ldh a, [hDownState] ldh a, [hDownState]
cp a, 0 cp a, 0
jr nz, :+ jr nz, .postcheckforfirmdropsound ; Don't play the sound if we're holding down.
; Play the firm drop sound.
.playfirmdropsound
call SFXKill call SFXKill
ld a, SFX_MOVE ld a, SFX_MOVE
call SFXEnqueue call SFXEnqueue
; If the down button is held, lock. ; If the down button is held, lock.
: ldh a, [hDownState] .postcheckforfirmdropsound
ldh a, [hDownState]
cp a, 0 cp a, 0
jr z, :+ jr z, .dontforcelock
ld a, 1
; Set the lock delay to 0 and save it.
.forcelock
ld a, 0
ldh [hCurrentLockDelayRemaining], a ldh [hCurrentLockDelayRemaining], a
: ldh a, [hCurrentLockDelayRemaining] jr .checklockdelay
; Load the lock delay.
; Decrement it by one and save it.
.dontforcelock
ldh a, [hCurrentLockDelayRemaining]
dec a dec a
ldh [hCurrentLockDelayRemaining], a ldh [hCurrentLockDelayRemaining], a
; If we're out of lock delay, play a sound.
; Are we out of lock delay?
.checklockdelay
cp a, 0 cp a, 0
jr nz, .forcelockmaybe jr nz, .checkfortgm3lockexception ; If not, check if the TGM3 exception applies.
call SFXKill jr .dolock ; Otherwise, lock!
ld a, SFX_LOCK
call SFXEnqueue
jr .draw
; TGM3 sometimes forces a piece to immediately lock. ; TGM3 sometimes forces a piece to immediately lock.
.forcelockmaybe .checkfortgm3lockexception
ldh a, [hLockDelayForce] ldh a, [hLockDelayForce]
cp a, $FF cp a, $FF
jr nz, .draw jr nz, .draw ; It's not forced, so go to drawing.
xor a, a xor a, a ; It is forced, so force it!
ldh [hCurrentLockDelayRemaining], a ldh [hCurrentLockDelayRemaining], a
; Play the locking sound and draw the piece.
.dolock
call SFXKill call SFXKill
ld a, SFX_LOCK ld a, SFX_LOCK
call SFXEnqueue call SFXEnqueue

View File

@ -28,9 +28,17 @@ INCLUDE "res/title_map.inc"
SECTION "High Globals", HRAM SECTION "High Globals", HRAM
hGameState:: ds 1 hGameState:: ds 1
hSwapAB:: ds 1 hSwapAB:: ds 1
hInitialA:: ds 1
hSimulationMode:: ds 1 hSimulationMode:: ds 1
SECTION "Globals", WRAM0
wInitialA:: ds 1
wInitialB:: ds 1
wInitialC:: ds 1
wInitialD:: ds 1
wInitialE:: ds 1
wInitialH:: ds 1
wInitialL:: ds 1
SECTION "Stack", WRAM0 SECTION "Stack", WRAM0
wStack:: wStack::
@ -40,8 +48,20 @@ wStackEnd::
SECTION "Code Entry Point", ROM0 SECTION "Code Entry Point", ROM0
Main:: Main::
; Load the initial A register. For reasons. ; Load the initial registers. For reasons.
ldh [hInitialA], a ld [wInitialA], a
ld a, b
ld [wInitialB], a
ld a, c
ld [wInitialC], a
ld a, d
ld [wInitialD], a
ld a, e
ld [wInitialE], a
ld a, h
ld [wInitialH], a
ld a, l
ld [wInitialL], a
; Turn off LCD during initialization. ; Turn off LCD during initialization.
wait_vram wait_vram

View File

@ -555,6 +555,7 @@ DoHold:
ldh [hCurrentPieceRotationState], a ldh [hCurrentPieceRotationState], a
ld a, SFX_IRS ld a, SFX_IRS
call SFXEnqueue call SFXEnqueue
jr .doHoldOperation
.checkIRSHB .checkIRSHB
ldh a, [hSwapAB] ldh a, [hSwapAB]

View File

@ -39,7 +39,7 @@ SwitchToTitle::
call UnsafeMemCopy call UnsafeMemCopy
; Little easter egg. ; Little easter egg.
ldh a, [hInitialA] ld a, [wInitialA]
cp a, $FF cp a, $FF
jr nz, :+ jr nz, :+
ld de, sEaster0 ld de, sEaster0