Redo high score sorting.

This commit is contained in:
Randy Thiemann 2023-11-12 01:12:39 +01:00
parent 8b1e0c2995
commit 1695175cb1
9 changed files with 1519 additions and 1250 deletions

Binary file not shown.

File diff suppressed because it is too large Load Diff

Binary file not shown.

File diff suppressed because it is too large Load Diff

View File

@ -25,25 +25,25 @@ INCLUDE "globals.asm"
SECTION "Hi Score Data", ROM0 SECTION "Hi Score Data", ROM0
sHiscoreDefaultData:: sHiscoreDefaultData::
db 0, 0, 0, 0, 0, 0, 0, 0, "DMG", GRADE_NONE, RNG_MODE_TGM3, ROT_MODE_ARSTI, DROP_MODE_FIRM, HIG_MODE_OFF db 0, 0, 0, 0, 0, 0, 0, 0, "DMG", GRADE_NONE, RNG_MODE_TGM3, ROT_MODE_ARSTI, DROP_MODE_FIRM, HIG_MODE_OFF
db 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 db 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
db 0, 0, 0, 0, 0, 0, 0, 0, "TRI", GRADE_NONE, RNG_MODE_TGM3, ROT_MODE_ARSTI, DROP_MODE_FIRM, HIG_MODE_OFF db 0, 0, 0, 0, 0, 0, 0, 0, "TRI", GRADE_NONE, RNG_MODE_TGM3, ROT_MODE_ARSTI, DROP_MODE_FIRM, HIG_MODE_OFF
db 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 db 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
db 0, 0, 0, 0, 0, 0, 0, 0, "SDM", GRADE_NONE, RNG_MODE_TGM3, ROT_MODE_ARSTI, DROP_MODE_FIRM, HIG_MODE_OFF db 0, 0, 0, 0, 0, 0, 0, 0, "SDM", GRADE_NONE, RNG_MODE_TGM3, ROT_MODE_ARSTI, DROP_MODE_FIRM, HIG_MODE_OFF
db 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 db 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
db 0, 0, 0, 0, 0, 0, 0, 0, "GTR", GRADE_NONE, RNG_MODE_TGM3, ROT_MODE_ARSTI, DROP_MODE_FIRM, HIG_MODE_OFF db 0, 0, 0, 0, 0, 0, 0, 0, "GTR", GRADE_NONE, RNG_MODE_TGM3, ROT_MODE_ARSTI, DROP_MODE_FIRM, HIG_MODE_OFF
db 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 db 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
db 0, 0, 0, 0, 0, 0, 0, 0, "ISD", GRADE_NONE, RNG_MODE_TGM3, ROT_MODE_ARSTI, DROP_MODE_FIRM, HIG_MODE_OFF db 0, 0, 0, 0, 0, 0, 0, 0, "ISD", GRADE_NONE, RNG_MODE_TGM3, ROT_MODE_ARSTI, DROP_MODE_FIRM, HIG_MODE_OFF
db 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 db 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
db 0, 0, 0, 0, 0, 0, 0, 0, "MGT", GRADE_NONE, RNG_MODE_TGM3, ROT_MODE_ARSTI, DROP_MODE_FIRM, HIG_MODE_OFF db 0, 0, 0, 0, 0, 0, 0, 0, "MGT", GRADE_NONE, RNG_MODE_TGM3, ROT_MODE_ARSTI, DROP_MODE_FIRM, HIG_MODE_OFF
db 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 db 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
db 0, 0, 0, 0, 0, 0, 0, 0, "RIS", GRADE_NONE, RNG_MODE_TGM3, ROT_MODE_ARSTI, DROP_MODE_FIRM, HIG_MODE_OFF db 0, 0, 0, 0, 0, 0, 0, 0, "RIS", GRADE_NONE, RNG_MODE_TGM3, ROT_MODE_ARSTI, DROP_MODE_FIRM, HIG_MODE_OFF
db 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 db 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
db 0, 0, 0, 0, 0, 0, 0, 0, "DMG", GRADE_NONE, RNG_MODE_TGM3, ROT_MODE_ARSTI, DROP_MODE_FIRM, HIG_MODE_OFF db 0, 0, 0, 0, 0, 0, 0, 0, "DMG", GRADE_NONE, RNG_MODE_TGM3, ROT_MODE_ARSTI, DROP_MODE_FIRM, HIG_MODE_OFF
db 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 db 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
db 0, 0, 0, 0, 0, 0, 0, 0, "TRI", GRADE_NONE, RNG_MODE_TGM3, ROT_MODE_ARSTI, DROP_MODE_FIRM, HIG_MODE_OFF db 0, 0, 0, 0, 0, 0, 0, 0, "TRI", GRADE_NONE, RNG_MODE_TGM3, ROT_MODE_ARSTI, DROP_MODE_FIRM, HIG_MODE_OFF
db 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 db 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
db 0, 0, 0, 0, 0, 0, 0, 0, "SDM", GRADE_NONE, RNG_MODE_TGM3, ROT_MODE_ARSTI, DROP_MODE_FIRM, HIG_MODE_OFF db 0, 0, 0, 0, 0, 0, 0, 0, "SDM", GRADE_NONE, RNG_MODE_TGM3, ROT_MODE_ARSTI, DROP_MODE_FIRM, HIG_MODE_OFF
db 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 db 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
SECTION "Hi Score Variables", WRAM0 SECTION "Hi Score Variables", WRAM0
@ -68,6 +68,86 @@ CheckAndAddHiscore::
; Load the score at position a. ; Load the score at position a.
call GetHiScoreEntry call GetHiScoreEntry
; Backup HL to DE for later.
ld d, h
ld e, l
; Compare grades, HL needs to forwarded 11 bytes.
.checkgrade
ld bc, 11
add hl, bc
; HL is now pointing to the grade in this high score.
; The handling depends on whether or not the old score had a grade.
ld a, [hl]
cp a, GRADE_NONE
jr z, .oldungraded
; The old score had a grade, so compare ours to theirs.
.oldgraded
ld b, a
ld a, [wDisplayedGrade]
cp a, b
jr c, .notbetter ; If we're less, we're not better.
jr nz, .better ; If we're higher, we're better.
jr .checklevel ; Equal, so check level.
; The old score did NOT have a grade. So check if we do.
.oldungraded
ld a, [wDisplayedGrade]
cp a, GRADE_NONE
jr nz, .better ; We do have a grade, so we win.
; We don't have a grade either, so continue as equals.
; Our grade is equal.
; Compare levels. HL needs to be forwarded 5 bytes.
.checklevel
ld bc, 5
add hl, bc
; HL is now pointing to the level in this high score.
; Make BC point to our level.
ld bc, hCLevel
; And compare the first digit...
ld a, [bc]
cp a, [hl]
jr c, .notbetter ; Lower? Not better.
jr nz, .better ; Higher? Better.
inc bc ; Equal? Keep checking...
inc hl
; Second...
ld a, [bc]
cp a, [hl]
jr c, .notbetter
jr nz, .better
inc bc
inc hl
; Third...
ld a, [bc]
cp a, [hl]
jr c, .notbetter
jr nz, .better
inc bc
inc hl
; Fourth...
ld a, [bc]
cp a, [hl]
jr c, .notbetter
jr nz, .better
; Our level is equal.
; So now also check the score. Restore the DE from earlier.
.checkscore
ld h, d
ld l, e
; HL is pointing to that score, make BC point to our current score. ; HL is pointing to that score, make BC point to our current score.
ld bc, hScore ld bc, hScore
@ -133,6 +213,8 @@ CheckAndAddHiscore::
jr c, .notbetter jr c, .notbetter
jr nz, .better jr nz, .better
; If we fell through all the way to here, we are completely equal. Oldest score has priority.
; Loop or return if we didn't make the scores. ; Loop or return if we didn't make the scores.
.notbetter .notbetter
ld a, [wInsertTarget] ld a, [wInsertTarget]
@ -140,7 +222,7 @@ CheckAndAddHiscore::
ld [wInsertTarget], a ld [wInsertTarget], a
cp a, 10 cp a, 10
ret z ret z
jr .checkloop jp .checkloop
.better .better
jr InsertHiScore jr InsertHiScore
@ -223,10 +305,26 @@ InsertHiScore::
ld [hl+], a ld [hl+], a
ld a, [wAlways20GState] ld a, [wAlways20GState]
ld [hl+], a ld [hl+], a
ldh a, [hCLevel+0]
ld [hl+], a
ldh a, [hCLevel+1]
ld [hl+], a
ldh a, [hCLevel+2]
ld [hl+], a
ldh a, [hCLevel+3]
ld [hl+], a
ldh a, [hNLevel+0]
ld [hl+], a
ldh a, [hNLevel+1]
ld [hl+], a
ldh a, [hNLevel+2]
ld [hl+], a
ldh a, [hNLevel+3]
ld [hl+], a
; 16 filler bytes. ; 8 filler bytes.
xor a, a xor a, a
REPT 16 REPT 8
ld [hl+], a ld [hl+], a
ENDR ENDR

View File

@ -1338,8 +1338,8 @@ sTitleTiles::
DB $50,$50,$20,$20,$24,$24,$00,$00 DB $50,$50,$20,$20,$24,$24,$00,$00
DB $40,$40,$C0,$C0,$40,$40,$40,$40 DB $40,$40,$C0,$C0,$40,$40,$40,$40
DB $40,$40,$40,$40,$E4,$E4,$00,$00 DB $40,$40,$40,$40,$E4,$E4,$00,$00
DB $44,$44,$AC,$AC,$A4,$A4,$A4,$A4 DB $4C,$4C,$A2,$A2,$A2,$A2,$A4,$A4
DB $A4,$A4,$A4,$A4,$4E,$4E,$00,$00 DB $A8,$A8,$A8,$A8,$4E,$4E,$00,$00
sTitleTilesEnd:: sTitleTilesEnd::
sGameplayTilesM:: sGameplayTilesM::

Binary file not shown.

View File

@ -98,7 +98,7 @@ RestoreSRAM::
cp a, 0 cp a, 0
jp nz, InitializeSRAM jp nz, InitializeSRAM
ld a, [rCheck+5] ld a, [rCheck+5]
cp a, 3 cp a, 4
jp nz, InitializeSRAM jp nz, InitializeSRAM
; SRAM is initialized and for this build, so we can load the data. ; SRAM is initialized and for this build, so we can load the data.
@ -228,7 +228,7 @@ InitializeSRAM:
ld [rCheck+3], a ld [rCheck+3], a
ld a, 0 ld a, 0
ld [rCheck+4], a ld [rCheck+4], a
ld a, 3 ld a, 4
ld [rCheck+5], a ld [rCheck+5], a
xor a, a xor a, a
@ -340,6 +340,27 @@ InitializeSRAM:
ld a, "9" ld a, "9"
ld [rProfileName9+2], a ld [rProfileName9+2], a
ld a, 6
ld [wSelected], a
call ResetScores
ld a, 5
ld [wSelected], a
call ResetScores
ld a, 4
ld [wSelected], a
call ResetScores
ld a, 3
ld [wSelected], a
call ResetScores
ld a, 2
ld [wSelected], a
call ResetScores
ld a, 1
ld [wSelected], a
call ResetScores
xor a, a
ld [wSelected], a
; Set the default scores. ; Set the default scores.
ResetScores:: ResetScores::
ld a, [wSelected] ld a, [wSelected]

View File

@ -27,6 +27,8 @@ SECTION "Title Variables", WRAM0
wSelected:: ds 1 wSelected:: ds 1
wTitleMode:: ds 1 wTitleMode:: ds 1
wProfileName:: ds 3 wProfileName:: ds 3
wDisplayingScoreMode:: ds 1
wScoreFlipTimer:: ds 1
SECTION "Title Function Trampolines", ROM0 SECTION "Title Function Trampolines", ROM0
@ -351,6 +353,8 @@ SwitchTitleMode:
call GBCTitleInit call GBCTitleInit
xor a, a xor a, a
ldh [hSelectState], a ldh [hSelectState], a
ld [wDisplayingScoreMode], a
ld [wScoreFlipTimer], a
jp RenderScores jp RenderScores
.switchCredits .switchCredits
@ -556,8 +560,19 @@ TitleEventLoopHandlerB:
; Select ; Select
ldh a, [hSelectState] ldh a, [hSelectState]
cp a, 255 ; Max hold duraction cp a, 255 ; Max hold duraction
jp z, RecordsHandleSelect
ld a, [wScoreFlipTimer]
inc a
ld [wScoreFlipTimer], a
cp a, 180
ret nz ret nz
jp RecordsHandleSelect xor a, a
ld [wScoreFlipTimer], a
ld a, [wDisplayingScoreMode]
cpl
ld [wDisplayingScoreMode], a
jp RenderScores
.eventLoopCredits .eventLoopCredits
ldh a, [hAState] ldh a, [hAState]
@ -1522,6 +1537,8 @@ CheckLevelRange:
RecordsHandleLeft: RecordsHandleLeft:
xor a, a xor a, a
ldh [hSelectState], a ldh [hSelectState], a
ld [wDisplayingScoreMode], a
ld [wScoreFlipTimer], a
ld a, [wSelected] ld a, [wSelected]
cp a, 0 cp a, 0
jr z, :+ jr z, :+
@ -1535,6 +1552,8 @@ RecordsHandleLeft:
RecordsHandleRight: RecordsHandleRight:
xor a, a xor a, a
ldh [hSelectState], a ldh [hSelectState], a
ld [wDisplayingScoreMode], a
ld [wScoreFlipTimer], a
ld a, [wSelected] ld a, [wSelected]
cp a, SCURVE_COUNT-1 cp a, SCURVE_COUNT-1
jr z, :+ jr z, :+
@ -1585,7 +1604,12 @@ RenderScores:
ld hl, TITLE_RECORDS_SCORE_BASE+4 ld hl, TITLE_RECORDS_SCORE_BASE+4
REPT 10 REPT 10
ld a, [wDisplayingScoreMode]
cp a, $FF
jr z, .level\@
; Render score. ; Render score.
.score\@
ld a, [de] ld a, [de]
inc de inc de
add a, "0" add a, "0"
@ -1619,11 +1643,63 @@ RenderScores:
add a, "0" add a, "0"
ld [hl+], a ld [hl+], a
; Go render the name.
jr .name\@
; Jump forward to level in the score.
.level\@
push hl
ld h, d
ld l, e
ld bc, 16
add hl, bc
ld d, h
ld e, l
pop hl
; Render it.
ld a, "L"
ld [hl+], a
ld a, "V"
ld [hl+], a
ld a, "L"
ld [hl+], a
ld a, 115
ld [hl+], a
ld a, [de]
inc de
add a, "0"
ld [hl+], a
ld a, [de]
inc de
add a, "0"
ld [hl+], a
ld a, [de]
inc de
add a, "0"
ld [hl+], a
ld a, [de]
inc de
add a, "0"
ld [hl+], a
; And jump back to the name.
push hl
ld h, d
ld l, e
ld bc, -12
add hl, bc
ld d, h
ld e, l
pop hl
.name\@
; Jump back to Name. ; Jump back to Name.
ld bc, -12 ld bc, -12
add hl, bc add hl, bc
; Render it. ; Render name.
ld a, [de] ld a, [de]
inc de inc de
ld [hl+], a ld [hl+], a
@ -1644,7 +1720,7 @@ RenderScores:
cp a, GRADE_NONE cp a, GRADE_NONE
jr nz, .grade\@ jr nz, .grade\@
.nograde\@ .nograde\@
ld a, TILE_BLANK ld a, 197
ld [hl+], a ld [hl+], a
jr .postgrade\@ jr .postgrade\@
.grade\@ .grade\@