Move everything to HRAM.

This commit is contained in:
Randy Thiemann 2023-10-21 20:49:52 +02:00
parent 61ae2c524b
commit ac28205be4
10 changed files with 135 additions and 161 deletions

View File

@ -32,7 +32,7 @@ wField:: ds (10*24)
wShadowField:: ds (14*26)
SECTION "Field High Variables", HRAM
SECTION "High Field Variables", HRAM
hPieceDataBase: ds 2
hPieceDataBaseFast: ds 2
hPieceDataOffset: ds 1
@ -1435,9 +1435,9 @@ FieldDelay::
jr nz, :-
ld a, l
ld [wScoreIncrement], a
ldh [hScoreIncrement], a
ld a, h
ld [wScoreIncrement+1], a
ldh [hScoreIncrement+1], a
call IncreaseScore
ret

View File

@ -22,7 +22,7 @@ DEF INPUT_ASM EQU 1
INCLUDE "globals.asm"
SECTION "Input Variables", HRAM
SECTION "High Input Variables", HRAM
hUpState:: ds 1
hDownState:: ds 1
hLeftState:: ds 1

View File

@ -22,7 +22,7 @@ DEF INTERRUPTS_ASM EQU 1
INCLUDE "globals.asm"
SECTION "Interrupt Variables", HRAM
SECTION "High Interrupt Variables", HRAM
hLCDCCtr:: ds 1

View File

@ -22,13 +22,7 @@ DEF LEVEL_ASM EQU 1
INCLUDE "globals.asm"
SECTION "Level Variables", WRAM0
wCLevel:: ds 4
wNLevel:: ds 6 ; The extra 2 bytes will be clobbered by the sprite drawing functions.
wPrevHundreds:: ds 1
SECTION "Critical Level Variables", HRAM
SECTION "High Level Variables", HRAM
hCurrentDAS:: ds 1
hCurrentARE:: ds 1
hCurrentLockDelay:: ds 1
@ -40,6 +34,9 @@ hSpeedCurvePtr:: ds 2
hStartSpeed:: ds 2
hRequiresLineClear:: ds 1
hLevel:: ds 2
hCLevel:: ds 4
hNLevel:: ds 6 ; The extra 2 bytes will be clobbered by the sprite drawing functions.
hPrevHundreds:: ds 1
SECTION "Level Functions", ROM0
@ -47,20 +44,18 @@ LevelInit::
xor a, a
ldh [hLevel], a
ldh [hLevel+1], a
ld hl, wCLevel
ld [hl+], a
ld [hl+], a
ld [hl+], a
ld [hl], a
ld hl, wNLevel
ld [hl+], a
inc a
ld [hl+], a
dec a
ld [hl+], a
ld [hl], a
ldh [hCLevel], a
ldh [hCLevel+1], a
ldh [hCLevel+2], a
ldh [hCLevel+3], a
ldh [hNLevel], a
ldh [hNLevel+2], a ; Note +1 is inited later.
ldh [hNLevel+3], a
ldh [hRequiresLineClear], a
ld a, 1
ldh [hNLevel+1], a
ldh a, [hStartSpeed]
ld l, a
ldh a, [hStartSpeed+1]
@ -70,19 +65,19 @@ LevelInit::
ld a, [hl+]
ld b, a
and a, $0F
ld [wCLevel+3], a
ldh [hCLevel+3], a
ld a, b
swap a
and a, $0F
ld [wCLevel+2], a
ldh [hCLevel+2], a
ld a, [hl+]
ld b, a
and a, $0F
ld [wCLevel+1], a
ldh [hCLevel+1], a
ld a, b
swap a
and a, $0F
ld [wCLevel], a
ldh [hCLevel], a
ld a, l
ldh [hSpeedCurvePtr], a
@ -99,19 +94,19 @@ LevelInit::
ld a, [hl+]
ld b, a
and a, $0F
ld [wNLevel+3], a
ldh [hNLevel+3], a
ld a, b
swap a
and a, $0F
ld [wNLevel+2], a
ldh [hNLevel+2], a
ld a, [hl+]
ld b, a
and a, $0F
ld [wNLevel+1], a
ldh [hNLevel+1], a
ld a, b
swap a
and a, $0F
ld [wNLevel], a
ldh [hNLevel], a
call DoSpeedUp
ret
@ -120,7 +115,7 @@ LevelInit::
; Levels may only increment by single digits.
LevelUp::
; Return if we're maxed out.
ld hl, wCLevel
ld hl, hCLevel
ld a, $09
and a, [hl]
inc hl
@ -148,12 +143,12 @@ LevelUp::
ldh [hLevel], a
; Save the current hundred digit.
ld a, [wCLevel+1]
ld [wPrevHundreds], a
ldh a, [hCLevel+1]
ldh [hPrevHundreds], a
; Increment LSD.
.doit
ld hl, wCLevel+3
ld hl, hCLevel+3
ld a, [hl]
add a, e
ld [hl], a
@ -192,10 +187,10 @@ LevelUp::
; 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
ldh [hCLevel], a
ldh [hCLevel+1], a
ldh [hCLevel+2], a
ldh [hCLevel+3], a
call DoSpeedUp
ld a, SFX_RANK_UP
call SFXEnqueue
@ -203,7 +198,7 @@ LevelUp::
.checknlevel
; Make wNLevel make sense.
ld hl, wCLevel
ld hl, hCLevel
ld a, $09
and a, [hl]
inc hl
@ -212,13 +207,12 @@ LevelUp::
; 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
ldh [hNLevel], a
ldh [hNLevel+1], a
ldh [hNLevel+2], a
ldh [hNLevel+3], a
; If the last two digits of wCLevel are 98, play the bell.
ld hl, wCLevel+2
ld hl, hCLevel+2
ld a, [hl+]
cp a, 9
jr nz, .checkspeedup
@ -232,31 +226,31 @@ LevelUp::
jr .leveljinglemaybe
; Otherwise check the second digit of wCLevel.
: ld hl, wCLevel+1
: ld hl, hCLevel+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
ld hl, hNLevel+1
xor a, a
ld [hl], a
ld hl, wCLevel
ld hl, hCLevel
ld a, [hl]
inc a
ld hl, wNLevel
ld hl, hNLevel
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 hl, hCLevel+1
ld a, [hl]
inc a
ld hl, wNLevel+1
ld hl, hNLevel+1
ld [hl], a
.bellmaybe
; If the last two digits of wCLevel are 99, play the bell.
ld hl, wCLevel+2
ld hl, hCLevel+2
ld a, [hl+]
and a, [hl]
cp a, 9
@ -267,9 +261,9 @@ LevelUp::
call SFXEnqueue
.leveljinglemaybe
ld a, [wPrevHundreds]
ldh a, [hPrevHundreds]
ld b, a
ld a, [wCLevel+1]
ld a, [hCLevel+1]
cp a, b
jr z, .checkspeedup
ld a, SFX_LEVEL_UP
@ -281,14 +275,14 @@ LevelUp::
jr z, :+
swap a
and a, $0F
ld hl, wCLevel
ld hl, hCLevel
cp a, [hl]
ret nc
: ldh a, [hNextSpeedUp]
and a, $0F
jr z, :+
ld hl, wCLevel+1
ld hl, hCLevel+1
cp a, [hl]
jr z, :+
ret nc
@ -298,7 +292,7 @@ LevelUp::
jr z, :+
swap a
and a, $0F
ld hl, wCLevel+2
ld hl, hCLevel+2
cp a, [hl]
jr z, :+
ret nc
@ -306,19 +300,11 @@ LevelUp::
: ldh a, [hNextSpeedUp+1]
and a, $0F
jr z, :+
ld hl, wCLevel+3
ld hl, hCLevel+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

View File

@ -25,7 +25,7 @@ INCLUDE "res/gameplay_map.inc"
INCLUDE "res/title_map.inc"
SECTION "Globals", HRAM
SECTION "High Globals", HRAM
hGameState:: ds 1
hSwapAB:: ds 1

View File

@ -22,40 +22,38 @@ DEF RNG_ASM EQU 1
INCLUDE "globals.asm"
SECTION "RNG Variables", WRAM0
wRNGSeed: ds 4
wPieceHistory: ds 4
wNextPiece:: ds 1
SECTION "High RNG Variables", HRAM
hRNGSeed: ds 4
hPieceHistory: ds 4
hNextPiece:: ds 1
section "RNG Functions", ROM0
RNGInit::
; Do some bit fuckery on the seed using the gameboy's free-running timers.
ld hl, wRNGSeed
ldh a, [rDIV]
xor a, [hl]
ld [hl+], a
ldh [hRNGSeed], a
ldh a, [rTIMA]
xor a, [hl]
ld [hl+], a
ldh [hRNGSeed+1], a
ldh a, [rDIV]
xor a, [hl]
ld [hl+], a
ldh [hRNGSeed+2], a
ldh a, [rTIMA]
xor a, [hl]
ld [hl], a
ldh [hRNGSeed+3], a
; Initialize the next history.
ld hl, wPieceHistory
ld a, PIECE_Z
ld [hl+], a
ld [hl+], a
ld [hPieceHistory], a
ld [hPieceHistory+1], a
ld a, PIECE_S
ld [hl+], a
ld [hl], a
ld [hPieceHistory+2], a
ld [hPieceHistory+3], a
; Get the first piece and make sure it's not Z, S or O.
: call NextPiece
@ -67,10 +65,8 @@ RNGInit::
jr z, :-
; Store it.
ld hl, wPieceHistory
ld [hl], a
ld hl, wNextPiece
ld [hl], a
ldh [hPieceHistory], a
ld [hNextPiece], a
ret
@ -80,7 +76,7 @@ GetNextPiece::
jr z, :+
call NextPiece
ld hl, wPieceHistory
ld hl, hPieceHistory
cp a, [hl]
jr z, :-
inc hl
@ -93,20 +89,16 @@ GetNextPiece::
cp a, [hl]
jr z, :-
: ld hl, wNextPiece
ld [hl], a
: ldh [hNextPiece], a
ld b, a
ld hl, wPieceHistory+2
ld a, [hl+]
ld [hl], a
ld hl, wPieceHistory+1
ld a, [hl+]
ld [hl], a
ld hl, wPieceHistory
ld a, [hl+]
ld [hl-], a
ldh a, [hPieceHistory+2]
ldh [hPieceHistory+3], a
ldh a, [hPieceHistory+1]
ldh [hPieceHistory+2], a
ldh a, [hPieceHistory]
ldh [hPieceHistory+1], a
ld a, b
ld [hl], a
ldh [hPieceHistory], a
ret
@ -120,7 +112,7 @@ NextPiece:
NextByte:
; Load seed
ld hl,wRNGSeed+3
ld hl, hRNGSeed+3
ld a, [hl-]
ld b, a
ld a, [hl-]

View File

@ -22,54 +22,50 @@ DEF SCORE_ASM EQU 1
INCLUDE "globals.asm"
SECTION "Score Variables", WRAM0
wScore:: ds 6
wScoreIncrement:: ds 2
wScoreIncrementBCD:: ds 6
wScoreIncrementHead:: ds 1
SECTION "Score Variables", HRAM
hScore:: ds 6
hScoreIncrement:: ds 2
hScoreIncrementBCD:: ds 6
hScoreIncrementHead:: ds 1
SECTION "Score Functions", ROM0
ScoreInit::
xor a, a
ld hl, wScore
ld [hl+], a
ld [hl+], a
ld [hl+], a
ld [hl+], a
ld [hl+], a
ld [hl], a
ld hl, wScoreIncrement
ld [hl+], a
ld [hl], a
ldh [hScore], a
ldh [hScore+1], a
ldh [hScore+2], a
ldh [hScore+3], a
ldh [hScore+4], a
ldh [hScore+5], a
ldh [hScoreIncrement], a
ldh [hScoreIncrement+1], a
ld a, $FF
ld hl, wScoreIncrementBCD
ld [hl+], a
ld [hl+], a
ld [hl+], a
ld [hl+], a
ld [hl+], a
ld [hl], a
ldh [hScoreIncrementBCD], a
ldh [hScoreIncrementBCD+1], a
ldh [hScoreIncrementBCD+2], a
ldh [hScoreIncrementBCD+3], a
ldh [hScoreIncrementBCD+4], a
ldh [hScoreIncrementBCD+5], a
ret
; Increases the current score by the amount in wScoreIncrement.
IncreaseScore::
; Wipe the old BCD score.
ld a, $FF
ld hl, wScoreIncrementBCD
ld [hl+], a
ld [hl+], a
ld [hl+], a
ld [hl+], a
ld [hl+], a
ld [hl], a
ldh [hScoreIncrementBCD], a
ldh [hScoreIncrementBCD+1], a
ldh [hScoreIncrementBCD+2], a
ldh [hScoreIncrementBCD+3], a
ldh [hScoreIncrementBCD+4], a
ldh [hScoreIncrementBCD+5], a
; First convert to BCD.
ld a, [wScoreIncrement]
ldh a, [hScoreIncrement]
ld l, a
ld a, [wScoreIncrement+1]
ldh a, [hScoreIncrement+1]
ld h, a
ld de, wScoreIncrementBCD
ld de, hScoreIncrementBCD
ld bc, -10000
call .doConvert
ld bc, -1000
@ -109,12 +105,12 @@ IncreaseScore::
ret
.postConvert
ld hl, wScoreIncrement
ld hl, hScoreIncrement
xor a, a
ld [hl+], a
ld [hl], a
ld de, wScoreIncrementBCD+5
ld de, hScoreIncrementBCD+5
ld b, 0
ld a, $FF
: cp a, b
@ -125,22 +121,22 @@ IncreaseScore::
.preAddDigit
; B contains the amount of times we need to shift the BCD score to the right.
ld a, [wScoreIncrementBCD+4]
ld [wScoreIncrementBCD+5], a
ld a, [wScoreIncrementBCD+3]
ld [wScoreIncrementBCD+4], a
ld a, [wScoreIncrementBCD+2]
ld [wScoreIncrementBCD+3], a
ld a, [wScoreIncrementBCD+1]
ld [wScoreIncrementBCD+2], a
ld a, [wScoreIncrementBCD]
ld [wScoreIncrementBCD+1], a
ldh a, [hScoreIncrementBCD+4]
ldh [hScoreIncrementBCD+5], a
ldh a, [hScoreIncrementBCD+3]
ldh [hScoreIncrementBCD+4], a
ldh a, [hScoreIncrementBCD+2]
ldh [hScoreIncrementBCD+3], a
ldh a, [hScoreIncrementBCD+1]
ldh [hScoreIncrementBCD+2], a
ldh a, [hScoreIncrementBCD]
ldh [hScoreIncrementBCD+1], a
xor a, a
ld [wScoreIncrementBCD], a
ldh [hScoreIncrementBCD], a
dec b
jr z, :-
ld hl, wScore+5
ld de, wScoreIncrementBCD+5
ld hl, hScore+5
ld de, hScoreIncrementBCD+5
; DE is now pointing to the last digit of the BCD score.
; HL points at the last digit of the displayed score.
@ -182,13 +178,13 @@ IncreaseScore::
jr nz, .addDigit
; Check if the score has rolled over.
ld a, [wScore]
ldh a, [hScore]
cp a, $0A
ret c
; If it has, reset the score.
xor a, a
ld [wScore], a
ldh [hScore], a
ld a, SFX_RANK_UP
call SFXEnqueue
ret

View File

@ -1279,7 +1279,7 @@ sSFXReadyGo::
sSFXReadyGoEnd::
SECTION "SFX Variables", HRAM
SECTION "High SFX Variables", HRAM
hPlayhead:: ds 2
hPlayQueue:: ds 4

View File

@ -34,7 +34,7 @@ DEF MODE_PRE_GAME_OVER EQU 8
DEF MODE_PAUSED EQU 9
SECTION "Critical Gameplay Variables", HRAM
SECTION "High Gameplay Variables", HRAM
hCurrentPiece:: ds 1
hCurrentPieceX:: ds 1
hCurrentPieceY:: ds 1
@ -180,7 +180,7 @@ postGoMode:
; Fetch the next piece.
fetchPieceMode:
ld a, [wNextPiece]
ldh a, [hNextPiece]
ldh [hCurrentPiece], a
call GetNextPiece
@ -257,7 +257,7 @@ fetchPieceMode:
cp a, 0
jr nz, .skipJingle
.playNextJingle
ld a, [wNextPiece]
ldh a, [hNextPiece]
call SFXEnqueue
.skipJingle
ld a, MODE_SPAWN_PIECE
@ -462,7 +462,7 @@ gameOverMode:
; Quit
: ldh a, [hBState]
cp a, 1
jr nz, :+
jp nz, drawStaticInfo
call SwitchToTitle
jp EventLoopPostHandler
@ -524,22 +524,22 @@ pauseMode:
; Always draw the score, level, next piece, and held piece.
drawStaticInfo:
: ld a, [wNextPiece]
: ldh a, [hNextPiece]
call ApplyNext
ldh a, [hHeldPiece]
call ApplyHold
ld hl, wSPRScore1
ld de, wScore
ld de, hScore
call ApplyNumbers
ld hl, wSPRCLevel1
ld de, wCLevel
ld de, hCLevel
call ApplyNumbers
ld hl, wSPRNLevel1
ld de, wNLevel
ld de, hNLevel
call ApplyNumbers
jp EventLoopPostHandler
@ -612,7 +612,7 @@ DoHold:
jr nz, :+
ldh a, [hCurrentPiece]
ldh [hHeldPiece], a
ld a, [wNextPiece]
ldh a, [hNextPiece]
ldh [hCurrentPiece], a
call GetNextPiece
ret

View File

@ -22,7 +22,7 @@ DEF TIME_ASM EQU 1
INCLUDE "globals.asm"
SECTION "Time Variables", HRAM
SECTION "High Time Variables", HRAM
hFrameCtr:: ds 1
hEvenFrame:: ds 1