Implement score addition.

This commit is contained in:
Randy Thiemann 2023-10-18 11:59:22 +02:00
parent e84b9acc52
commit 313a97265f
6 changed files with 196 additions and 30 deletions

View File

@ -8,6 +8,8 @@ INCLUDE "globals.asm"
SECTION "Level Variables", WRAM0 SECTION "Level Variables", WRAM0
wCLevel:: ds 4 wCLevel:: ds 4
wNLevel:: ds 6 ; The extra 2 bytes will be clobbered by the sprite drawing functions. wNLevel:: ds 6 ; The extra 2 bytes will be clobbered by the sprite drawing functions.
wPrevHundreds:: ds 1
SECTION "Critical Level Variables", HRAM SECTION "Critical Level Variables", HRAM
hCurrentDAS:: ds 1 hCurrentDAS:: ds 1
@ -64,14 +66,9 @@ LevelUp::
cp a, $09 cp a, $09
ret z ret z
; If we required a line clear, unset the flag and play the sfx. ; Save the current hundred digit.
ldh a, [hRequiresLineClear] ld a, [wCLevel+1]
cp a, $FF ld [wPrevHundreds], a
jr nz, .doit
ld a, SFX_LEVEL_UP
call SFXEnqueue
xor a, a
ldh [hRequiresLineClear], a
; Increment LSD. ; Increment LSD.
.doit .doit
@ -119,6 +116,8 @@ LevelUp::
ld [hl-], a ld [hl-], a
ld [hl], a ld [hl], a
call DoSpeedUp call DoSpeedUp
ld a, SFX_RANK_UP
call SFXEnqueue
ret ret
.checknlevel .checknlevel
@ -149,7 +148,7 @@ LevelUp::
ldh [hRequiresLineClear], a ldh [hRequiresLineClear], a
ld a, SFX_BELL ld a, SFX_BELL
call SFXEnqueue call SFXEnqueue
jr .checkspeedup jr .leveljinglemaybe
; Otherwise check the second digit of wCLevel. ; Otherwise check the second digit of wCLevel.
: ld hl, wCLevel+1 : ld hl, wCLevel+1
@ -180,20 +179,27 @@ LevelUp::
ld a, [hl+] ld a, [hl+]
and a, [hl] and a, [hl]
cp a, 9 cp a, 9
jr nz, .checkspeedup jr nz, .leveljinglemaybe
ld a, $FF ld a, $FF
ldh [hRequiresLineClear], a ldh [hRequiresLineClear], a
ld a, SFX_BELL ld a, SFX_BELL
call SFXEnqueue call SFXEnqueue
.leveljinglemaybe
ld a, [wPrevHundreds]
ld b, a
ld a, [wCLevel+1]
cp a, b
jr z, .checkspeedup
ld a, SFX_LEVEL_UP
call SFXEnqueue
.checkspeedup .checkspeedup
ldh a, [hNextSpeedUp] ldh a, [hNextSpeedUp]
and a, $F0 and a, $F0
jr z, :+ jr z, :+
rrc a swap a
rrc a and a, $0F
rrc a
rrc a
ld hl, wCLevel ld hl, wCLevel
cp a, [hl] cp a, [hl]
ret nc ret nc
@ -209,10 +215,8 @@ LevelUp::
: ldh a, [hNextSpeedUp+1] : ldh a, [hNextSpeedUp+1]
and a, $F0 and a, $F0
jr z, :+ jr z, :+
rrc a swap a
rrc a and a, $0F
rrc a
rrc a
ld hl, wCLevel+2 ld hl, wCLevel+2
cp a, [hl] cp a, [hl]
jr z, :+ jr z, :+

View File

@ -13,7 +13,7 @@ hGameState:: ds 1
SECTION "Stack", WRAM0 SECTION "Stack", WRAM0
wStack:: wStack::
ds STACK_SIZE ds STACK_SIZE + 1
wStackEnd:: wStackEnd::
@ -25,7 +25,7 @@ Main::
ldh [rLCDC], a ldh [rLCDC], a
; Set up stack ; Set up stack
ld sp, wStackEnd ld sp, wStackEnd-1
; We use a single set of tiles for the entire game, so we copy it at the start. ; We use a single set of tiles for the entire game, so we copy it at the start.
ld de, Tiles ld de, Tiles

View File

@ -7,6 +7,9 @@ INCLUDE "globals.asm"
SECTION "Score Variables", WRAM0 SECTION "Score Variables", WRAM0
wScore:: ds 6 wScore:: ds 6
wScoreIncrement:: ds 2
wScoreIncrementBCD:: ds 6
wScoreIncrementHead:: ds 1
SECTION "Score Functions", ROM0 SECTION "Score Functions", ROM0
@ -19,6 +22,158 @@ ScoreInit::
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
ld a, $FF
ld hl, wScoreIncrementBCD
ld [hl+], a
ld [hl+], a
ld [hl+], a
ld [hl+], a
ld [hl+], a
ld [hl], 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
; First convert to BCD.
ld a, [wScoreIncrement]
ld l, a
ld a, [wScoreIncrement+1]
ld h, a
ld de, wScoreIncrementBCD
ld bc, -10000
call .doConvert
ld bc, -1000
call .doConvert
ld bc, -100
call .doConvert
ld c, -10
call .doConvert
ld c, b
call .doConvert
jr .postConvert
.doConvert
ld a, 255
: inc a
add hl, bc
jr c, :-
push bc ; sbc hl, bc
push af ;
ld a, b ;
cpl ;
ld b, a ;
ld a, c ;
cpl ;
ld c, a ;
inc bc ;
call c, .carry ;
pop af ;
add hl, bc ;
pop bc ;
ld [de], a
inc de
ret
.carry
dec bc
ret
.postConvert
ld hl, wScoreIncrement
xor a, a
ld [hl+], a
ld [hl], a
ld de, wScoreIncrementBCD+5
ld b, 0
ld a, $FF
: cp a, b
jr nz, .preAddDigit
inc b
dec de
jr :-
.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
xor a, a
ld [wScoreIncrementBCD], a
dec b
jr z, :-
ld hl, wScore+5
ld de, wScoreIncrementBCD+5
; DE is now pointing to the last digit of the BCD score.
; HL points at the last digit of the displayed score.
.addDigit
; Increment the digit count.
inc b
; Add the currently pointed to digits together.
ld a, [de]
ld c, a
ld a, [hl]
add a, c
ld [hl], a
; If they're too big, carry.
cp a, $0A
jr c, .nextDigit
; Except if this is the 6th digit.
ld a, 5
cp a, b
jr z, .nextDigit
; Do the carry.
ld a, [hl]
sub a, 10
ld [hl-], a
ld a, [hl]
inc a
ld [hl+], a
.nextDigit
; Update the pointers.
dec de
dec hl
; Check if we're out of numbers.
ld a, 5
cp a, b
jr nz, .addDigit
; Check if the score has rolled over.
ld a, [wScore]
cp a, $0A
ret c
; If it has, reset the score.
xor a, a
ld [wScore], a
ld a, SFX_RANK_UP
call SFXEnqueue
ret ret

View File

@ -166,6 +166,10 @@ spawnPieceMode:
jr nz, :+ jr nz, :+
ld e, 1 ld e, 1
call LevelUp call LevelUp
ld a, $10
ld hl, wScoreIncrement+1
ld [hl], a
call IncreaseScore
: ld a, [hUpState] : ld a, [hUpState]
cp a, 1 cp a, 1

View File

@ -1,5 +1,5 @@
#Emulicious settings file #Emulicious settings file
#Wed Oct 18 09:16:29 CEST 2023 #Wed Oct 18 11:58:40 CEST 2023
WindowEventViewerWindowHeight=1416 WindowEventViewerWindowHeight=1416
WindowEventViewerWindowDivider=876 WindowEventViewerWindowDivider=876
WindowMemoryTracerWindowY=631 WindowMemoryTracerWindowY=631
@ -99,7 +99,7 @@ Gamepad1Key30=-1
BankSwapAtPCBreakpointEnabled=false BankSwapAtPCBreakpointEnabled=false
DebuggerMemorySelectedTab=HRAM DebuggerMemorySelectedTab=HRAM
WindowVideoViewerOpen=true WindowVideoViewerOpen=true
WindowMemoryEditorTabVisibleRect=0,0,583,128 WindowMemoryEditorTabVisibleRect=0,336,583,384
Gamepad1Key29=-1 Gamepad1Key29=-1
Gamepad1Key28=-1 Gamepad1Key28=-1
Gamepad1Key27=-1 Gamepad1Key27=-1
@ -136,7 +136,7 @@ Gamepad1Key13=-1
Gamepad1Key12=-1 Gamepad1Key12=-1
Gamepad1Key11=-1 Gamepad1Key11=-1
Gamepad1Key10=-1 Gamepad1Key10=-1
WindowMemoryEditorSelectedAddress=16 WindowMemoryEditorSelectedAddress=434
WindowMemoryEditorWidth=665 WindowMemoryEditorWidth=665
GameBoyErrorBreakpointCondition9= GameBoyErrorBreakpointCondition9=
GameBoyErrorBreakpointCondition8= GameBoyErrorBreakpointCondition8=
@ -155,7 +155,7 @@ Gamepad0Key35=-1
Gamepad0Key34=-1 Gamepad0Key34=-1
Gamepad0Key33=-1 Gamepad0Key33=-1
Gamepad0Key32=-1 Gamepad0Key32=-1
WindowMemoryEditorSelectedTab=I/O WindowMemoryEditorSelectedTab=RAM
Gamepad0Key31=-1 Gamepad0Key31=-1
Gamepad0Key30=-1 Gamepad0Key30=-1
SMSGamepadAThreshold=50 SMSGamepadAThreshold=50
@ -178,8 +178,8 @@ Gamepad0Key20=-1
DebuggerSouthPanelSelectedTab=1 DebuggerSouthPanelSelectedTab=1
WindowEmuliciousWidth=816 WindowEmuliciousWidth=816
WindowVideoViewerWidth=980 WindowVideoViewerWidth=980
WindowMemoryEditorY=827 WindowMemoryEditorY=582
WindowMemoryEditorX=2697 WindowMemoryEditorX=1506
Gamepad0Key19=-1 Gamepad0Key19=-1
Gamepad0Key18=-1 Gamepad0Key18=-1
Gamepad0Key17=-1 Gamepad0Key17=-1
@ -199,8 +199,8 @@ GameBoyErrorBreakpointMessage32=
InterruptBreakpointCondition= InterruptBreakpointCondition=
Recent0=C\:\\workspace\\dmgtris\\bin\\out.gb Recent0=C\:\\workspace\\dmgtris\\bin\\out.gb
GameBoyErrorBreakpointMessage20= GameBoyErrorBreakpointMessage20=
WindowEmuliciousY=350 WindowEmuliciousY=461
WindowEmuliciousX=1544 WindowEmuliciousX=1508
GameBoyErrorBreakpointEnabled9=false GameBoyErrorBreakpointEnabled9=false
GameBoyErrorBreakpointEnabled8=false GameBoyErrorBreakpointEnabled8=false
GameBoyErrorBreakpointEnabled7=false GameBoyErrorBreakpointEnabled7=false
@ -264,8 +264,8 @@ Gamepad0Key3=-1
Gamepad0Key2=-1 Gamepad0Key2=-1
Gamepad0Key1=-1 Gamepad0Key1=-1
Gamepad0Key0=-1 Gamepad0Key0=-1
WindowDebuggerY=287 WindowDebuggerY=103
WindowDebuggerX=-1 WindowDebuggerX=166
InterruptBreakpointSuspend=true InterruptBreakpointSuspend=true
SMSGamepadAKeyboard=false SMSGamepadAKeyboard=false
GameBoyErrorBreakpointSuspend32=true GameBoyErrorBreakpointSuspend32=true

View File

@ -1,3 +1,6 @@
wCLevel 4 Hexadecimal wCLevel 4 Hexadecimal
hPlayQueue 4 Hexadecimal hPlayQueue 4 Hexadecimal
hPlayhead 4 Hexadecimal hPlayhead 4 Hexadecimal
wScoreIncrementBCD 6 Hexadecimal
wScoreIncrement 2 Hexadecimal
wScore 6 Hexadecimal