[Reverse-engineering] [th05] Number display using the bold gaiji font

Many thanks to http://bytepointer.com/tasm/index.htm for providing a
better searchable resource for TASM's default `LEA imm16` → `MOV imm16`
optimization, which we initially had to hack around here.

Funded by -Tom-.
This commit is contained in:
nmlgc 2019-03-05 01:24:06 +01:00
parent ba3a6f7158
commit fac879f8e6
9 changed files with 162 additions and 204 deletions

View File

@ -63,6 +63,8 @@ twobyte_t ends
RES_X = 640 RES_X = 640
RES_Y = 400 RES_Y = 400
GAIJI_TRAM_W = 2
PLAYFIELD_X = 32 PLAYFIELD_X = 32
PLAYFIELD_Y = 16 PLAYFIELD_Y = 16
PLAYFIELD_W = 384 PLAYFIELD_W = 384
@ -70,6 +72,9 @@ PLAYFIELD_H = 368
PLAYFIELD_VRAM_X = PLAYFIELD_X / 8 PLAYFIELD_VRAM_X = PLAYFIELD_X / 8
PLAYFIELD_VRAM_W = PLAYFIELD_W / 8 PLAYFIELD_VRAM_W = PLAYFIELD_W / 8
PLAYFIELD_TRAM_X = PLAYFIELD_X / 8
PLAYFIELD_TRAM_W = PLAYFIELD_W / 8
ROW_SIZE = (RES_X / 8) ROW_SIZE = (RES_X / 8)
TILE_W = 16 TILE_W = 16

12
th02/gaiji_boldfont.inc Normal file
View File

@ -0,0 +1,12 @@
; Bold font
GB_DIGITS = 0A0h
gb_0_ = GB_DIGITS + 0
gb_1_ = GB_DIGITS + 1
gb_2_ = GB_DIGITS + 2
gb_3_ = GB_DIGITS + 3
gb_4_ = GB_DIGITS + 4
gb_5_ = GB_DIGITS + 5
gb_6_ = GB_DIGITS + 6
gb_7_ = GB_DIGITS + 7
gb_8_ = GB_DIGITS + 8
gb_9_ = GB_DIGITS + 9

View File

@ -0,0 +1,9 @@
public _POWERS_OF_10_LONG
_POWERS_OF_10_LONG label dword
dd 1000000
dd 100000
dd 10000
dd 1000
dd 100
dd 10
dd 1

View File

@ -2,6 +2,7 @@ GAME = 2
include defconv_c.inc include defconv_c.inc
include th02/hardware/input.inc include th02/hardware/input.inc
include th02/math/randring_next.inc include th02/math/randring_next.inc
include th02/gaiji_boldfont.inc
kajacall macro func, param := <0> kajacall macro func, param := <0>
call _snd_kaja_interrupt pascal, (func shl 8) or (param and 0ffh) call _snd_kaja_interrupt pascal, (func shl 8) or (param and 0ffh)

View File

@ -6711,7 +6711,7 @@ arg_4 = word ptr 8
sub sp, 4 sub sp, 4
push si push si
push di push di
mov si, 0B4Ch mov si, offset _POWERS_OF_10_LONG
mov di, 38h ; '8' mov di, 38h ; '8'
jmp short loc_DC9A jmp short loc_DC9A
; --------------------------------------------------------------------------- ; ---------------------------------------------------------------------------
@ -6726,13 +6726,9 @@ loc_DC65:
sub [bp+arg_0], eax sub [bp+arg_0], eax
add si, 4 add si, 4
mov ax, [bp+var_4] mov ax, [bp+var_4]
add ax, 0A0h add ax, GB_DIGITS
mov [bp+var_2], ax mov [bp+var_2], ax
push di call gaiji_putca pascal, di, [bp+arg_4], ax, TX_WHITE
push [bp+arg_4]
push ax
push 0E1h
call gaiji_putca
add di, 2 add di, 2
loc_DC9A: loc_DC9A:
@ -34561,34 +34557,7 @@ bombs db 3
db 5 db 5
word_1E5B6 dw 0 word_1E5B6 dw 0
dword_1E5B8 dd 9C40h dword_1E5B8 dd 9C40h
db 40h include th02/hud/number_put[data].asm
db 42h ; B
db 0Fh
db 0
db 0A0h
db 86h
db 1
db 0
db 10h
db 27h ; '
db 0
db 0
db 0E8h
db 3
db 0
db 0
db 64h ; d
db 0
db 0
db 0
db 0Ah
db 0
db 0
db 0
db 1
db 0
db 0
db 0
word_1E5D8 dw 4140h word_1E5D8 dw 4140h
word_1E5DA dw 4342h word_1E5DA dw 4342h
word_1E5DC dw 44h word_1E5DC dw 44h

1
th04/gaiji.inc Normal file
View File

@ -0,0 +1 @@
g_EMPTY = 2

82
th05/hud/number_put.asm Normal file
View File

@ -0,0 +1,82 @@
; Prints [val] using the bold gaiji font, right-aligned at ([x+5], [y]), with
; the given attribute.
; void pascal far hud_int_put(unsigned int x, unsigned int y, unsigned int val, unsigned int atrb);
public hud_int_put
hud_int_put proc far
@@atrb = word ptr 6
@@val = word ptr 8
push bp
mov bp, sp
push di
; Avoid LEA being turned into MOV for immediate addresses
pushstate
nosmart
lea di, _hud_gaiji_row + (SCORE_DIGITS - 5)
movzx edx, [bp+@@val]
lea bx, _POWERS_OF_10_LONG + (2 * 4)
popstate
mov ax, [bp+@@atrb]
mov cx, 4
jmp short hud_digits_put
hud_int_put endp
nop
; Prints [points] using the bold gaiji font, right-aligned at ([x+8], [y]),
; in white, using up to 7 digits (8 if the "continue" digit is included).
; Larger numbers will overflow the most significant digit into the A-Z range.
; void pascal far hud_points_put(unsigned int x, unsigned int y, unsigned long points);
public hud_points_put
hud_points_put proc far
@@points = dword ptr 6
@@y = word ptr 0Ah
@@x = word ptr 0Ch
push bp
mov bp, sp
push di
mov edx, [bp+@@points]
mov di, offset _hud_gaiji_row
mov ax, TX_WHITE
mov _hud_gaiji_row[SCORE_DIGITS - 1], gb_0_ ; ("continues used" digit)
mov bx, offset _POWERS_OF_10_LONG
mov cx, SCORE_DIGITS - 2
hud_digits_put:
push [bp+@@x]
push [bp+@@y]
push ds
push di
push ax
mov ax, ds
mov es, ax
@@digit_loop:
mov eax, edx
xor edx, edx
div dword ptr [bx]
or ch, al
jz short @@omit_leading_zeroes
add al, GB_DIGITS
jmp short @@digit_next
; ---------------------------------------------------------------------------
@@omit_leading_zeroes:
mov al, g_EMPTY
@@digit_next:
stosb
add bx, 4
dec cl
jnz short @@digit_loop
add dl, gb_0_ ; (ones)
mov [di], dl
call gaiji_putsa
pop di
pop bp
retf 8
hud_points_put endp

View File

@ -8,3 +8,5 @@ include th04/hardware/input.inc
include th04/math/randring_next.inc include th04/math/randring_next.inc
include th04/math/motion.inc include th04/math/motion.inc
include th05/shot_types.inc include th05/shot_types.inc
include th02/gaiji_boldfont.inc
include th04/gaiji.inc

View File

@ -9697,14 +9697,8 @@ sub_104BB endp
sub_10574 proc far sub_10574 proc far
push bp push bp
mov bp, sp mov bp, sp
push 3E0010h call hud_int_put pascal, (62 shl 16) + 16, word_2CEC6, TX_WHITE
push word_2CEC6 call hud_int_put pascal, (62 shl 16) + 15, word_22648, TX_CYAN
push 0E1h
call sub_1F9F4
push 3E000Fh
push word_22648
push 0A1h
call sub_1F9F4
pop bp pop bp
retf retf
sub_10574 endp sub_10574 endp
@ -9775,10 +9769,7 @@ sub_1059D endp
sub_1060E proc far sub_1060E proc far
push bp push bp
mov bp, sp mov bp, sp
push 3E0012h call hud_int_put pascal, (62 shl 16) + 18, word_2C97A, TX_WHITE
push word_2C97A
push 0E1h
call sub_1F9F4
pop bp pop bp
retf retf
sub_1060E endp sub_1060E endp
@ -12981,9 +12972,7 @@ loc_11FA5:
call gaiji_putsa call gaiji_putsa
cmp byte_2CE72, 2 cmp byte_2CE72, 2
jnz short loc_11FD9 jnz short loc_11FD9
push 1C0002h call hud_points_put pascal, ((PLAYFIELD_TRAM_X + (PLAYFIELD_TRAM_W / 2)) shl 16) + 2, large [dword_2CE8E]
pushd [dword_2CE8E]
call sub_1FA0E
loc_11FD9: loc_11FD9:
inc byte_2288C inc byte_2288C
@ -20876,55 +20865,55 @@ loc_165F8:
mov si, ax mov si, ax
movzx eax, si movzx eax, si
mov [bp+var_4], eax mov [bp+var_4], eax
push 220008h push (34 shl 16) + 8
push eax push eax
nopcall sub_1FA0E nopcall hud_points_put
mov al, dream mov al, dream
mov ah, 0 mov ah, 0
imul ax, 0Ah imul ax, 0Ah
mov si, ax mov si, ax
movzx eax, si movzx eax, si
add [bp+var_4], eax add [bp+var_4], eax
push 22000Ah push (34 shl 16) + 10
push eax push eax
nopcall sub_1FA0E nopcall hud_points_put
mov ax, word_2C97A mov ax, word_2C97A
imul ax, 5 imul ax, 5
mov si, ax mov si, ax
movzx eax, si movzx eax, si
add [bp+var_4], eax add [bp+var_4], eax
push 22000Ch push (34 shl 16) + 12
push eax push eax
nopcall sub_1FA0E nopcall hud_points_put
mov si, word_2CEC6 mov si, word_2CEC6
movzx eax, si movzx eax, si
imul eax, [bp+var_4] imul eax, [bp+var_4]
mov [bp+var_4], eax mov [bp+var_4], eax
push 28000Eh push (40 shl 16) + 14
push si push si
push 0E1h push TX_WHITE
nopcall sub_1F9F4 nopcall hud_int_put
mov al, stage_id mov al, stage_id
mov ah, 0 mov ah, 0
imul ax, 1388h imul ax, 5000
add ax, 2710h add ax, 10000
mov si, ax mov si, ax
cmp [bp+var_5], 0 cmp [bp+var_5], 0
jz short loc_166B2 jz short loc_166B2
movzx eax, si movzx eax, si
add [bp+var_4], eax add [bp+var_4], eax
push 220010h push (34 shl 16) + 16
push eax push eax
nopcall sub_1FA0E nopcall hud_points_put
loc_166B2: loc_166B2:
cmp [bp+var_6], 0 cmp [bp+var_6], 0
jz short loc_166CD jz short loc_166CD
movzx eax, si movzx eax, si
add [bp+var_4], eax add [bp+var_4], eax
push 220011h push (34 shl 16) + 17
push eax push eax
nopcall sub_1FA0E nopcall hud_points_put
loc_166CD: loc_166CD:
cmp [bp+var_4], 124F80h cmp [bp+var_4], 124F80h
@ -20970,9 +20959,9 @@ loc_1671B:
lea ax, [bp+var_4] lea ax, [bp+var_4]
push ax push ax
call sub_16438 call sub_16438
push 220015h push (34 shl 16) + 21
pushd [bp+var_4] pushd [bp+var_4]
nopcall sub_1FA0E nopcall hud_points_put
mov eax, [bp+var_4] mov eax, [bp+var_4]
add _score_delta, eax add _score_delta, eax
pop si pop si
@ -21051,77 +21040,77 @@ loc_1683E:
mov si, 3E8h mov si, 3E8h
movzx eax, si movzx eax, si
mov [bp+var_4], eax mov [bp+var_4], eax
push 220006h push (34 shl 16) + 6
push eax push eax
nopcall sub_1FA0E nopcall hud_points_put
mov al, dream mov al, dream
mov ah, 0 mov ah, 0
imul ax, 0Ah imul ax, 0Ah
mov si, ax mov si, ax
movzx eax, si movzx eax, si
add [bp+var_4], eax add [bp+var_4], eax
push 220008h push (34 shl 16) + 8
push eax push eax
nopcall sub_1FA0E nopcall hud_points_put
mov ax, word_2C97A mov ax, word_2C97A
imul ax, 5 imul ax, 5
mov si, ax mov si, ax
movzx eax, si movzx eax, si
add [bp+var_4], eax add [bp+var_4], eax
push 22000Ah push (34 shl 16) + 10
push eax push eax
nopcall sub_1FA0E nopcall hud_points_put
mov al, lives mov al, lives
mov ah, 0 mov ah, 0
imul ax, 3E8h imul ax, 1000
add ax, 0FC18h add ax, 64536
mov si, ax mov si, ax
movzx eax, si movzx eax, si
add [bp+var_4], eax add [bp+var_4], eax
push 22000Ch push (34 shl 16) + 12
push eax push eax
nopcall sub_1FA0E nopcall hud_points_put
mov si, word_2CEC6 mov si, word_2CEC6
movzx eax, si movzx eax, si
imul eax, [bp+var_4] imul eax, [bp+var_4]
mov [bp+var_4], eax mov [bp+var_4], eax
push 28000Eh push (40 shl 16) + 14
push si push si
push 0E1h push TX_WHITE
nopcall sub_1F9F4 nopcall hud_int_put
mov [bp+var_8], 0C350h mov [bp+var_8], 50000
cmp [bp+var_9], 0 cmp [bp+var_9], 0
jz short loc_1691E jz short loc_1691E
mov eax, [bp+var_8] mov eax, [bp+var_8]
add [bp+var_4], eax add [bp+var_4], eax
push 220010h push (34 shl 16) + 16
push eax push eax
nopcall sub_1FA0E nopcall hud_points_put
loc_1691E: loc_1691E:
cmp [bp+var_A], 0 cmp [bp+var_A], 0
jz short loc_16939 jz short loc_16939
mov eax, [bp+var_8] mov eax, [bp+var_8]
add [bp+var_4], eax add [bp+var_4], eax
push 220011h push (34 shl 16) + 17
push eax push eax
nopcall sub_1FA0E nopcall hud_points_put
loc_16939: loc_16939:
movzx eax, word_22648 movzx eax, word_22648
imul eax, 0FAh imul eax, 250
mov [bp+var_8], eax mov [bp+var_8], eax
add [bp+var_4], eax add [bp+var_4], eax
push 220012h push (34 shl 16) + 18
push eax push eax
nopcall sub_1FA0E nopcall hud_points_put
push ss push ss
lea ax, [bp+var_4] lea ax, [bp+var_4]
push ax push ax
call sub_16438 call sub_16438
push 220015h push (34 shl 16) + 21
pushd [bp+var_4] pushd [bp+var_4]
nopcall sub_1FA0E nopcall hud_points_put
mov eax, [bp+var_4] mov eax, [bp+var_4]
add _score_delta, eax add _score_delta, eax
pop si pop si
@ -37483,92 +37472,7 @@ sub_1F9BA endp
; --------------------------------------------------------------------------- ; ---------------------------------------------------------------------------
nop nop
include th05/hud/number_put.asm
; =============== S U B R O U T I N E =======================================
; Attributes: bp-based frame
sub_1F9F4 proc far
arg_2 = word ptr 6
arg_4 = word ptr 8
push bp
mov bp, sp
push di
; Hack?!? What is this I don't even
db 08dh
db 03eh
db 0c9h
db 01fh
movzx edx, [bp+arg_4]
db 08dh
db 01eh
db 0a8h
db 01fh
mov ax, [bp+arg_2]
mov cx, 4
jmp short loc_1FA27
sub_1F9F4 endp
; ---------------------------------------------------------------------------
nop
; =============== S U B R O U T I N E =======================================
; Attributes: bp-based frame
sub_1FA0E proc far
arg_0 = dword ptr 6
arg_4 = word ptr 0Ah
arg_6 = word ptr 0Ch
push bp
mov bp, sp
push di
mov edx, [bp+arg_0]
mov di, offset _hud_gaiji_row
mov ax, TX_WHITE
mov _hud_gaiji_row[HUD_TRAM_W - 1], 0A0h
mov bx, 1FA0h
mov cx, 6
loc_1FA27:
push [bp+arg_6]
push [bp+arg_4]
push ds
push di
push ax
mov ax, ds
mov es, ax
loc_1FA34:
mov eax, edx
xor edx, edx
div dword ptr [bx]
or ch, al
jz short loc_1FA45
add al, 0A0h
jmp short loc_1FA47
; ---------------------------------------------------------------------------
loc_1FA45:
mov al, 2
loc_1FA47:
stosb
add bx, 4
dec cl
jnz short loc_1FA34
add dl, 0A0h
mov [di], dl
call gaiji_putsa
pop di
pop bp
retf 8
sub_1FA0E endp
; =============== S U B R O U T I N E ======================================= ; =============== S U B R O U T I N E =======================================
@ -38903,34 +38807,7 @@ SHOT_FUNCS label word
dw shot_yuuka_l9 dw shot_yuuka_l9
byte_2297E db 0 byte_2297E db 0
db 0 db 0
db 40h include th02/hud/number_put[data].asm
db 42h ; B
db 0Fh
db 0
db 0A0h
db 86h
db 1
db 0
unk_22988 db 10h
db 27h ; '
db 0
db 0
db 0E8h
db 3
db 0
db 0
db 64h ; d
db 0
db 0
db 0
db 0Ah
db 0
db 0
db 0
db 1
db 0
db 0
db 0
db 10h db 10h
db 27h ; ' db 27h ; '
db 0E8h db 0E8h