From 0d0e0e87d38a3cbc9a22b0e07b21ecb186eee3aa Mon Sep 17 00:00:00 2001 From: Rangi42 Date: Sun, 21 Jul 2024 10:52:13 -0400 Subject: [PATCH] Refactor the Unown wall word data --- constants/charmap.asm | 10 ++++++ constants/script_constants.asm | 1 + data/events/unown_walls.asm | 59 +++++++++++----------------------- engine/events/unown_walls.asm | 31 ++++++++++-------- 4 files changed, 47 insertions(+), 54 deletions(-) diff --git a/constants/charmap.asm b/constants/charmap.asm index 3edce65ffa2..3b834dc3f38 100644 --- a/constants/charmap.asm +++ b/constants/charmap.asm @@ -418,6 +418,16 @@ charmap "8", $fe charmap "9", $ff +; Unown charmap, for Unown words (see gfx/tilesets/ruins_of_alph.png) +pushc + newcharmap unown + DEF PRINTABLE_UNOWN EQUS "ABCDEFGHIJKLMNOPQRSTUVWXYZ-" + for i, STRLEN("{PRINTABLE_UNOWN}") + charmap STRSUB("{PRINTABLE_UNOWN}", i + 1, 1), $10 * (i / 8) + 2 * i + endr + charmap "@", $ff ; end +popc + ; ASCII charmap, for mobile functions pushc newcharmap ascii diff --git a/constants/script_constants.asm b/constants/script_constants.asm index 29f9de8bf54..e747bf99807 100644 --- a/constants/script_constants.asm +++ b/constants/script_constants.asm @@ -320,6 +320,7 @@ DEF NUM_UNOWN_PUZZLES EQU const_value const UNOWNWORDS_LIGHT ; 1 const UNOWNWORDS_WATER ; 2 const UNOWNWORDS_HO_OH ; 3 +DEF NUM_UNOWN_WALLS EQU const_value ; MoveTutor setval arguments const_def 1 diff --git a/data/events/unown_walls.asm b/data/events/unown_walls.asm index 6e28b5f1c26..b3b637a1e00 100644 --- a/data/events/unown_walls.asm +++ b/data/events/unown_walls.asm @@ -1,45 +1,22 @@ -MACRO unownwall - for n, CHARLEN(\1) - DEF x = CHARSUB(\1, n + 1) - if x == "-" - db $64 - elif x >= "Y" - db 2 * (x - "Y") + $60 - elif x >= "Q" - db 2 * (x - "Q") + $40 - elif x >= "I" - db 2 * (x - "I") + $20 - else - db 2 * (x - "A") - endc - endr - db -1 ; end -ENDM +; strings correspond to UNOWNWORDS_* constants (see constants/script_constants.asm) +DEF UNOWNWORD_1 EQUS "ESCAPE" +DEF UNOWNWORD_2 EQUS "LIGHT" +DEF UNOWNWORD_3 EQUS "WATER" +DEF UNOWNWORD_4 EQUS "HO-OH" UnownWalls: -; UNOWNWORDS_ESCAPE - ; db $08, $44, $04, $00, $2e, $08, -1 - unownwall "ESCAPE" -; UNOWNWORDS_LIGHT - ; db $26, $20, $0c, $0e, $46, -1 - unownwall "LIGHT" -; UNOWNWORDS_WATER - ; db $4c, $00, $46, $08, $42, -1 - unownwall "WATER" -; UNOWNWORDS_HO_OH - ; db $0e, $2c, $64, $2c, $0e, -1 - unownwall "HO-OH" + list_start UnownWalls + for x, 1, NUM_UNOWN_WALLS + 1 + li "{UNOWNWORD_{d:x}}" + endr + assert_list_length NUM_UNOWN_WALLS MenuHeaders_UnownWalls: -; UNOWNWORDS_ESCAPE - db MENU_BACKUP_TILES ; flags - menu_coords 3, 4, 16, 9 -; UNOWNWORDS_LIGHT - db MENU_BACKUP_TILES ; flags - menu_coords 4, 4, 15, 9 -; UNOWNWORDS_WATER - db MENU_BACKUP_TILES ; flags - menu_coords 4, 4, 15, 9 -; UNOWNWORDS_HO_OH - db MENU_BACKUP_TILES ; flags - menu_coords 4, 4, 15, 9 +; entries correspond to UNOWNWORDS_* constants + table_width 5, MenuHeaders_UnownWalls + for x, 1, NUM_UNOWN_WALLS + 1 + db MENU_BACKUP_TILES ; flags + DEF n = CHARLEN("{UNOWNWORD_{d:x}}") + menu_coords 9 - n, 4, 10 + n, 9 + endr + assert_table_length NUM_UNOWN_WALLS diff --git a/engine/events/unown_walls.asm b/engine/events/unown_walls.asm index 3934943f4db..89ea8cd1bbb 100644 --- a/engine/events/unown_walls.asm +++ b/engine/events/unown_walls.asm @@ -105,8 +105,8 @@ DisplayUnownWords: and a jr z, .load - ld d, $0 - ld e, $5 + ld d, 0 + ld e, 5 .loop add hl, de dec a @@ -148,11 +148,14 @@ DisplayUnownWords: call CloseWindow ret +pushc +setcharmap unown + INCLUDE "data/events/unown_walls.asm" _DisplayUnownWords_FillAttr: ld a, [de] - cp $ff + cp "@" ret z cp $60 ld a, VRAM_BANK_1 | PAL_BG_BROWN @@ -183,7 +186,7 @@ _DisplayUnownWords_CopyWord: push de .word_loop ld a, [de] - cp $ff + cp "@" jr z, .word_done ld c, a call .ConvertChar @@ -200,12 +203,12 @@ _DisplayUnownWords_CopyWord: .ConvertChar: push hl ld a, c - cp $60 - jr z, .Tile60 - cp $62 - jr z, .Tile62 - cp $64 - jr z, .Tile64 + cp "Y" + jr z, .YChar + cp "Z" + jr z, .ZChar + cp "-" + jr z, .DashChar ld [hli], a inc a ld [hld], a @@ -221,7 +224,7 @@ _DisplayUnownWords_CopyWord: pop hl ret -.Tile60: +.YChar: ld [hl], $5b inc hl ld [hl], $5c @@ -233,7 +236,7 @@ _DisplayUnownWords_CopyWord: pop hl ret -.Tile62: +.ZChar: ld [hl], $4e inc hl ld [hl], $4f @@ -245,7 +248,7 @@ _DisplayUnownWords_CopyWord: pop hl ret -.Tile64: +.DashChar: ld [hl], $2 inc hl ld [hl], $3 @@ -256,3 +259,5 @@ _DisplayUnownWords_CopyWord: ld [hl], $2 pop hl ret + +popc