Implement score addition.
This commit is contained in:
parent
e84b9acc52
commit
313a97265f
|
@ -8,6 +8,8 @@ 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
|
||||
hCurrentDAS:: ds 1
|
||||
|
@ -64,14 +66,9 @@ LevelUp::
|
|||
cp a, $09
|
||||
ret z
|
||||
|
||||
; If we required a line clear, unset the flag and play the sfx.
|
||||
ldh a, [hRequiresLineClear]
|
||||
cp a, $FF
|
||||
jr nz, .doit
|
||||
ld a, SFX_LEVEL_UP
|
||||
call SFXEnqueue
|
||||
xor a, a
|
||||
ldh [hRequiresLineClear], a
|
||||
; Save the current hundred digit.
|
||||
ld a, [wCLevel+1]
|
||||
ld [wPrevHundreds], a
|
||||
|
||||
; Increment LSD.
|
||||
.doit
|
||||
|
@ -119,6 +116,8 @@ LevelUp::
|
|||
ld [hl-], a
|
||||
ld [hl], a
|
||||
call DoSpeedUp
|
||||
ld a, SFX_RANK_UP
|
||||
call SFXEnqueue
|
||||
ret
|
||||
|
||||
.checknlevel
|
||||
|
@ -149,7 +148,7 @@ LevelUp::
|
|||
ldh [hRequiresLineClear], a
|
||||
ld a, SFX_BELL
|
||||
call SFXEnqueue
|
||||
jr .checkspeedup
|
||||
jr .leveljinglemaybe
|
||||
|
||||
; Otherwise check the second digit of wCLevel.
|
||||
: ld hl, wCLevel+1
|
||||
|
@ -180,20 +179,27 @@ LevelUp::
|
|||
ld a, [hl+]
|
||||
and a, [hl]
|
||||
cp a, 9
|
||||
jr nz, .checkspeedup
|
||||
jr nz, .leveljinglemaybe
|
||||
ld a, $FF
|
||||
ldh [hRequiresLineClear], a
|
||||
ld a, SFX_BELL
|
||||
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
|
||||
ldh a, [hNextSpeedUp]
|
||||
and a, $F0
|
||||
jr z, :+
|
||||
rrc a
|
||||
rrc a
|
||||
rrc a
|
||||
rrc a
|
||||
swap a
|
||||
and a, $0F
|
||||
ld hl, wCLevel
|
||||
cp a, [hl]
|
||||
ret nc
|
||||
|
@ -209,10 +215,8 @@ LevelUp::
|
|||
: ldh a, [hNextSpeedUp+1]
|
||||
and a, $F0
|
||||
jr z, :+
|
||||
rrc a
|
||||
rrc a
|
||||
rrc a
|
||||
rrc a
|
||||
swap a
|
||||
and a, $0F
|
||||
ld hl, wCLevel+2
|
||||
cp a, [hl]
|
||||
jr z, :+
|
||||
|
|
|
@ -13,7 +13,7 @@ hGameState:: ds 1
|
|||
|
||||
SECTION "Stack", WRAM0
|
||||
wStack::
|
||||
ds STACK_SIZE
|
||||
ds STACK_SIZE + 1
|
||||
wStackEnd::
|
||||
|
||||
|
||||
|
@ -25,7 +25,7 @@ Main::
|
|||
ldh [rLCDC], a
|
||||
|
||||
; 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.
|
||||
ld de, Tiles
|
||||
|
|
155
src/score.asm
155
src/score.asm
|
@ -7,6 +7,9 @@ INCLUDE "globals.asm"
|
|||
|
||||
SECTION "Score Variables", WRAM0
|
||||
wScore:: ds 6
|
||||
wScoreIncrement:: ds 2
|
||||
wScoreIncrementBCD:: ds 6
|
||||
wScoreIncrementHead:: ds 1
|
||||
|
||||
|
||||
SECTION "Score Functions", ROM0
|
||||
|
@ -19,6 +22,158 @@ ScoreInit::
|
|||
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
|
||||
|
||||
|
||||
|
|
|
@ -166,6 +166,10 @@ spawnPieceMode:
|
|||
jr nz, :+
|
||||
ld e, 1
|
||||
call LevelUp
|
||||
ld a, $10
|
||||
ld hl, wScoreIncrement+1
|
||||
ld [hl], a
|
||||
call IncreaseScore
|
||||
|
||||
: ld a, [hUpState]
|
||||
cp a, 1
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
#Emulicious settings file
|
||||
#Wed Oct 18 09:16:29 CEST 2023
|
||||
#Wed Oct 18 11:58:40 CEST 2023
|
||||
WindowEventViewerWindowHeight=1416
|
||||
WindowEventViewerWindowDivider=876
|
||||
WindowMemoryTracerWindowY=631
|
||||
|
@ -99,7 +99,7 @@ Gamepad1Key30=-1
|
|||
BankSwapAtPCBreakpointEnabled=false
|
||||
DebuggerMemorySelectedTab=HRAM
|
||||
WindowVideoViewerOpen=true
|
||||
WindowMemoryEditorTabVisibleRect=0,0,583,128
|
||||
WindowMemoryEditorTabVisibleRect=0,336,583,384
|
||||
Gamepad1Key29=-1
|
||||
Gamepad1Key28=-1
|
||||
Gamepad1Key27=-1
|
||||
|
@ -136,7 +136,7 @@ Gamepad1Key13=-1
|
|||
Gamepad1Key12=-1
|
||||
Gamepad1Key11=-1
|
||||
Gamepad1Key10=-1
|
||||
WindowMemoryEditorSelectedAddress=16
|
||||
WindowMemoryEditorSelectedAddress=434
|
||||
WindowMemoryEditorWidth=665
|
||||
GameBoyErrorBreakpointCondition9=
|
||||
GameBoyErrorBreakpointCondition8=
|
||||
|
@ -155,7 +155,7 @@ Gamepad0Key35=-1
|
|||
Gamepad0Key34=-1
|
||||
Gamepad0Key33=-1
|
||||
Gamepad0Key32=-1
|
||||
WindowMemoryEditorSelectedTab=I/O
|
||||
WindowMemoryEditorSelectedTab=RAM
|
||||
Gamepad0Key31=-1
|
||||
Gamepad0Key30=-1
|
||||
SMSGamepadAThreshold=50
|
||||
|
@ -178,8 +178,8 @@ Gamepad0Key20=-1
|
|||
DebuggerSouthPanelSelectedTab=1
|
||||
WindowEmuliciousWidth=816
|
||||
WindowVideoViewerWidth=980
|
||||
WindowMemoryEditorY=827
|
||||
WindowMemoryEditorX=2697
|
||||
WindowMemoryEditorY=582
|
||||
WindowMemoryEditorX=1506
|
||||
Gamepad0Key19=-1
|
||||
Gamepad0Key18=-1
|
||||
Gamepad0Key17=-1
|
||||
|
@ -199,8 +199,8 @@ GameBoyErrorBreakpointMessage32=
|
|||
InterruptBreakpointCondition=
|
||||
Recent0=C\:\\workspace\\dmgtris\\bin\\out.gb
|
||||
GameBoyErrorBreakpointMessage20=
|
||||
WindowEmuliciousY=350
|
||||
WindowEmuliciousX=1544
|
||||
WindowEmuliciousY=461
|
||||
WindowEmuliciousX=1508
|
||||
GameBoyErrorBreakpointEnabled9=false
|
||||
GameBoyErrorBreakpointEnabled8=false
|
||||
GameBoyErrorBreakpointEnabled7=false
|
||||
|
@ -264,8 +264,8 @@ Gamepad0Key3=-1
|
|||
Gamepad0Key2=-1
|
||||
Gamepad0Key1=-1
|
||||
Gamepad0Key0=-1
|
||||
WindowDebuggerY=287
|
||||
WindowDebuggerX=-1
|
||||
WindowDebuggerY=103
|
||||
WindowDebuggerX=166
|
||||
InterruptBreakpointSuspend=true
|
||||
SMSGamepadAKeyboard=false
|
||||
GameBoyErrorBreakpointSuspend32=true
|
||||
|
|
|
@ -1,3 +1,6 @@
|
|||
wCLevel 4 Hexadecimal
|
||||
hPlayQueue 4 Hexadecimal
|
||||
hPlayhead 4 Hexadecimal
|
||||
wScoreIncrementBCD 6 Hexadecimal
|
||||
wScoreIncrement 2 Hexadecimal
|
||||
wScore 6 Hexadecimal
|
||||
|
|
Loading…
Reference in New Issue