Skip to content

Commit

Permalink
Refactor the Unown wall word data (#1131)
Browse files Browse the repository at this point in the history
  • Loading branch information
Rangi42 authored Jul 24, 2024
1 parent 024c874 commit fed587f
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 56 deletions.
10 changes: 10 additions & 0 deletions constants/charmap.asm
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions constants/script_constants.asm
Original file line number Diff line number Diff line change
Expand Up @@ -320,6 +320,8 @@ 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
DEF UNOWN_WALL_MENU_HEADER_SIZE EQU 5

; MoveTutor setval arguments
const_def 1
Expand Down
60 changes: 19 additions & 41 deletions data/events/unown_walls.asm
Original file line number Diff line number Diff line change
@@ -1,45 +1,23 @@
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_{d:UNOWNWORDS_ESCAPE} EQUS "ESCAPE"
DEF UNOWNWORD_{d:UNOWNWORDS_LIGHT} EQUS "LIGHT"
DEF UNOWNWORD_{d:UNOWNWORDS_WATER} EQUS "WATER"
DEF UNOWNWORD_{d:UNOWNWORDS_HO_OH} 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"
; entries correspond to UNOWNWORDS_* constants
list_start UnownWalls
for x, NUM_UNOWN_WALLS
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 UNOWN_WALL_MENU_HEADER_SIZE, MenuHeaders_UnownWalls
for x, NUM_UNOWN_WALLS
DEF n = CHARLEN("{UNOWNWORD_{d:x}}")
db MENU_BACKUP_TILES ; flags
menu_coords 9 - n, 4, 10 + n, 9
endr
assert_table_length NUM_UNOWN_WALLS
34 changes: 19 additions & 15 deletions engine/events/unown_walls.asm
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,8 @@ DisplayUnownWords:
and a
jr z, .load

ld d, $0
ld e, $5
ld d, 0
ld e, UNOWN_WALL_MENU_HEADER_SIZE
.loop
add hl, de
dec a
Expand Down Expand Up @@ -148,17 +148,19 @@ 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
cp "Y"
ld a, VRAM_BANK_1 | PAL_BG_BROWN
jr c, .got_pal
ld a, PAL_BG_BROWN

.got_pal
call .PlaceSquare
inc hl
Expand All @@ -183,7 +185,7 @@ _DisplayUnownWords_CopyWord:
push de
.word_loop
ld a, [de]
cp $ff
cp "@"
jr z, .word_done
ld c, a
call .ConvertChar
Expand All @@ -200,12 +202,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
Expand All @@ -221,7 +223,7 @@ _DisplayUnownWords_CopyWord:
pop hl
ret

.Tile60:
.YChar:
ld [hl], $5b
inc hl
ld [hl], $5c
Expand All @@ -233,7 +235,7 @@ _DisplayUnownWords_CopyWord:
pop hl
ret

.Tile62:
.ZChar:
ld [hl], $4e
inc hl
ld [hl], $4f
Expand All @@ -245,7 +247,7 @@ _DisplayUnownWords_CopyWord:
pop hl
ret

.Tile64:
.DashChar:
ld [hl], $2
inc hl
ld [hl], $3
Expand All @@ -256,3 +258,5 @@ _DisplayUnownWords_CopyWord:
ld [hl], $2
pop hl
ret

popc

0 comments on commit fed587f

Please sign in to comment.