[Decompilation] [th02] HUD: Power bar rendering

Which also commits power changes to the shot level…

Part of P0242, funded by Yanga.
This commit is contained in:
nmlgc 2023-05-30 19:55:56 +02:00
parent 7bd0ac3f17
commit 0d28c116c0
11 changed files with 117 additions and 120 deletions

View File

@ -99,7 +99,7 @@ bin\th02\op.exe: th02\op_01.cpp bin\th02\exit_dos.obj bin\th02\zunerror.obj bin\
$**
|
bin\th02\main.exe: bin\th02\main.obj bin\th02\tile.obj th02\pointnum.cpp th02\player_b.cpp bin\th02\zunerror.obj bin\th02\keydelay.obj th02\main02_1.cpp bin\th01\vplanset.obj bin\th02\pi_load.obj bin\th02\vector2.obj bin\th02\frmdely1.obj bin\th02\input_s.obj bin\th02\exit.obj bin\th02\snd_mmdr.obj bin\th02\snd_mode.obj bin\th02\snd_pmdr.obj bin\th02\snd_dlyv.obj bin\th02\snd_load.obj th02\mpn_l_i.cpp bin\th02\initmain.obj bin\th02\pi_put.obj bin\th02\snd_kaja.obj bin\th02\snd_dlym.obj bin\th02\snd_se_r.obj bin\th02\snd_se.obj th02\main_03.cpp th02\hud_ovrl.cpp
bin\th02\main.exe: bin\th02\main.obj bin\th02\tile.obj th02\pointnum.cpp th02\hud.cpp th02\player_b.cpp bin\th02\zunerror.obj bin\th02\keydelay.obj th02\main02_1.cpp bin\th01\vplanset.obj bin\th02\pi_load.obj bin\th02\vector2.obj bin\th02\frmdely1.obj bin\th02\input_s.obj bin\th02\exit.obj bin\th02\snd_mmdr.obj bin\th02\snd_mode.obj bin\th02\snd_pmdr.obj bin\th02\snd_dlyv.obj bin\th02\snd_load.obj th02\mpn_l_i.cpp bin\th02\initmain.obj bin\th02\pi_put.obj bin\th02\snd_kaja.obj bin\th02\snd_dlym.obj bin\th02\snd_se_r.obj bin\th02\snd_se.obj th02\main_03.cpp th02\hud_ovrl.cpp
$(CC) $(CFLAGS) $(LARGE_LFLAGS) -3 -Z -DGAME=2 -nbin\th02\ -eMAIN.EXE @&&|
$**
|

3
pc98.h
View File

@ -27,6 +27,9 @@ typedef int vram_dword_amount_t;
typedef unsigned int uvram_byte_amount_t;
typedef unsigned int uvram_word_amount_t;
typedef unsigned int uvram_dword_amount_t;
// TRAM widths
typedef int tram_cell_amount_t;
/// ------
/// Coordinate systems

View File

@ -8,6 +8,16 @@ typedef enum {
gs_YINYANG = 0x02, // ☯
gs_BOMB, // ◉? ⦿? 🎯? 🖸? Or simply 💣?
gaiji_bar(0x30),
// A completely filled, 80-pixel bar with MAX drawn on top, stored in 5
// consecutive gaiji characters.
g_BAR_MAX_0,
g_BAR_MAX_1,
g_BAR_MAX_2,
g_BAR_MAX_3,
g_BAR_MAX_4,
gaiji_boldfont(0xA0),
gb_SP = 0xCF,

View File

@ -3,6 +3,12 @@ gs_BOMB = 003h
include th02/gaiji/boldfont.inc
g_BAR_MAX_0 = 040h
g_BAR_MAX_1 = 041h
g_BAR_MAX_2 = 042h
g_BAR_MAX_3 = 043h
g_BAR_MAX_4 = 044h
gs_NOTES = 0D8h
gb_SP = 0CFh
gs_ALL = 0F0h

1
th02/hud.cpp Normal file
View File

@ -0,0 +1 @@
#include "th02/main/hud/hud.cpp"

View File

@ -1,4 +1,55 @@
#pragma option -G
#include "platform.h"
#include "pc98.h"
#include "master.hpp"
#include "th02/gaiji/gaiji.h"
#include "th02/main/player/player.hpp"
#include "th02/main/hud/hud.hpp"
static const uint8_t SHOT_LEVEL_INTERVAL_BITS = 2;
extern uint8_t POWER_TO_SHOT_LEVEL[POWER_MAX >> SHOT_LEVEL_INTERVAL_BITS];
#include "th02/main/score.cpp"
void near player_shot_level_update_and_hud_power_put(void)
{
struct hack_bar {
char x[(POWER_MAX / BAR_GAIJI_MAX) + 1]; // ACTUAL TYPE: gaiji_th02_t
};
struct hack_colors {
uint8_t x[SHOT_LEVEL_MAX];
};
extern struct hack_bar gHUD_BAR_MAX;
extern struct hack_colors HUD_POWER_COLORS;
extern struct hack_bar gHUD_BAR_BLANK;
int i = 0;
int value_rem;
const struct hack_bar G_MAX = gHUD_BAR_MAX;
const struct hack_colors COLORS = HUD_POWER_COLORS;
struct hack_bar g_buf = gHUD_BAR_BLANK;
shot_level = POWER_TO_SHOT_LEVEL[power >> SHOT_LEVEL_INTERVAL_BITS];
if(shot_level == SHOT_LEVEL_MAX) {
gaiji_putsa(HUD_LABELED_LEFT, HUD_POWER_Y, G_MAX.x, TX_WHITE);
return;
}
value_rem = power;
value_rem -= BAR_GAIJI_MAX;
while(value_rem > 0) {
g_buf.x[i] = g_BAR_16W;
value_rem -= BAR_GAIJI_MAX;
i++;
}
// ZUN landmine: This causes a [power] of 0 to be rendered as 16 power
// instead. Probably the reason why TH02, TH04, and TH05 treat 1 as the
// lowest possible [power].
value_rem = ((power - 1) & (BAR_GAIJI_MAX - 1));
g_buf.x[i] = (g_BAR_01W + value_rem);
gaiji_putsa(HUD_LABELED_LEFT, HUD_POWER_Y, g_buf.x, COLORS.x[shot_level]);
}

View File

@ -1,2 +0,0 @@
#define HUD_LEFT 56
#define BAR_MAX 128

19
th02/main/hud/hud.hpp Normal file
View File

@ -0,0 +1,19 @@
// Coordinates
// -----------
static const tram_x_t HUD_LEFT = 56;
static const tram_y_t HUD_POWER_Y = 20;
static const tram_cell_amount_t HUD_LABEL_PADDING = 1;
static const tram_cell_amount_t HUD_LABEL_W = (2 * GAIJI_TRAM_W);
static const tram_cell_amount_t HUD_LABEL_PADDED_W = (
HUD_LABEL_PADDING + HUD_LABEL_W + HUD_LABEL_PADDING
);
static const tram_x_t HUD_LABELED_LEFT = (HUD_LEFT + HUD_LABEL_PADDED_W);
// -----------
// Yup, this also commits changes to [power] to the [shot_level], which
// absolutely doesn't belong here.
void near player_shot_level_update_and_hud_power_put(void);

View File

@ -39,7 +39,7 @@ MAP_LENGTH_MAX = 320
LIVES_MAX = 5
BOMBS_MAX = 5
main_01 group main_01_TEXT, POINTNUM_TEXT, main_01__TEXT, PLAYER_B_TEXT, main_01___TEXT
main_01 group main_01_TEXT, POINTNUM_TEXT, main_01__TEXT, HUD_TEXT, main_01___TEXT, PLAYER_B_TEXT, main_01____TEXT
main_03 group main_03_TEXT, main_03__TEXT
; ===========================================================================
@ -5022,7 +5022,7 @@ loc_D949:
cmp _power, POWER_MAX
jnb short loc_D964
inc _power
call hud_power_put
call @player_shot_level_update_and_hud$qv
mov _power_overflow, 0
inc dword_218A4
jmp short loc_D984
@ -5151,7 +5151,7 @@ loc_DA85:
add bx, bx
push _POWER_OVERFLOW_BONUS[bx] ; points
call @pointnums_add$qiiui
call hud_power_put
call @player_shot_level_update_and_hud$qv
jmp short loc_DAB6
; ---------------------------------------------------------------------------
@ -5543,110 +5543,13 @@ loc_DEAB:
pop bp
retf
sub_DE4E endp
main_01__TEXT ends
HUD_TEXT segment byte public 'CODE' use16
@player_shot_level_update_and_hud$qv procdesc near
HUD_TEXT ends
; =============== S U B R O U T I N E =======================================
; Attributes: bp-based frame
public HUD_POWER_PUT
hud_power_put proc near
var_18 = word ptr -18h
var_16 = word ptr -16h
var_14 = word ptr -14h
@@bar_colors = byte ptr -12h
var_8 = word ptr -8
var_6 = word ptr -6
var_4 = word ptr -4
var_2 = word ptr -2
push bp
mov bp, sp
sub sp, 18h
push si
xor si, si
mov ax, word_1E5D8
mov [bp+var_8], ax
mov ax, word_1E5DA
mov [bp+var_6], ax
mov ax, word_1E5DC
mov [bp+var_4], ax
mov ax, word ptr _HUD_POWER_COLORS + 0
mov word ptr [bp+@@bar_colors], ax
mov ax, word ptr _HUD_POWER_COLORS + 2
mov word ptr [bp+@@bar_colors + 2], ax
mov ax, word ptr _HUD_POWER_COLORS + 4
mov word ptr [bp+@@bar_colors + 4], ax
mov ax, word ptr _HUD_POWER_COLORS + 6
mov word ptr [bp+@@bar_colors + 6], ax
mov al, _HUD_POWER_COLORS + 8
mov [bp+@@bar_colors + 8], al
mov ax, word_1E5E7
mov [bp+var_18], ax
mov ax, word_1E5E9
mov [bp+var_16], ax
mov ax, word_1E5EB
mov [bp+var_14], ax
mov al, _power
mov ah, 0
sar ax, 2
mov bx, ax
mov al, _POWER_TO_SHOT_LEVEL[bx]
mov _shot_level, al
cmp _shot_level, SHOT_LEVEL_MAX
jnz short loc_DF20
push (62 shl 16) + 20
push ss
lea ax, [bp+var_8]
push ax
push TX_WHITE
jmp short loc_DF6E
; ---------------------------------------------------------------------------
loc_DF20:
mov al, _power
mov ah, 0
mov [bp+var_2], ax
sub [bp+var_2], 10h
jmp short loc_DF37
; ---------------------------------------------------------------------------
loc_DF2E:
mov byte ptr [bp+si+var_18], 3Fh ; '?'
sub [bp+var_2], 10h
inc si
loc_DF37:
cmp [bp+var_2], 0
jg short loc_DF2E
mov al, _power
mov ah, 0
dec ax
and ax, 0Fh
mov [bp+var_2], ax
mov al, byte ptr [bp+var_2]
add al, 30h ; '0'
mov byte ptr [bp+si+var_18], al
push (62 shl 16) + 20
push ss
lea ax, [bp+var_18]
push ax
mov al, _shot_level
mov ah, 0
lea dx, [bp+@@bar_colors]
add ax, dx
mov bx, ax
mov al, ss:[bx]
mov ah, 0
push ax
loc_DF6E:
call gaiji_putsa
pop si
leave
retn
hud_power_put endp
main_01___TEXT segment word public 'CODE' use16
; =============== S U B R O U T I N E =======================================
@ -5766,7 +5669,7 @@ hud_put proc near
call gaiji_putsa pascal, (57 shl 16) + 15, ds, offset gsREIGEKI, TX_YELLOW
call hud_bombs_put
call gaiji_putsa pascal, (57 shl 16) + 20, ds, offset gsREIRYOKU, TX_YELLOW
call hud_power_put
call @player_shot_level_update_and_hud$qv
push (57 shl 16) + 22
push ds
mov al, _rank
@ -7077,7 +6980,7 @@ loc_ECA9:
pop bp
retn
bomb_reimu_b endp
main_01__TEXT ends
main_01___TEXT ends
PLAYER_B_TEXT segment byte public 'CODE' use16
@bomb_update_and_render$qv procdesc near
@ -7091,7 +6994,7 @@ PLAYER_B_TEXT segment byte public 'CODE' use16
left:word, top:word, eight_tiles:byte
PLAYER_B_TEXT ends
main_01___TEXT segment byte public 'CODE' use16
main_01____TEXT segment byte public 'CODE' use16
; =============== S U B R O U T I N E =======================================
@ -7340,7 +7243,7 @@ loc_F107:
mov bx, ax
mov al, [bx+109Fh]
mov _power, al
call hud_power_put
call @player_shot_level_update_and_hud$qv
mov bx, word_205EE
push word ptr [bx]
mov bx, word_205F0
@ -7740,7 +7643,7 @@ off_F443 dw offset loc_F238
dw offset loc_F260
dw offset loc_F288
dw offset loc_F2A4
main_01___TEXT ends
main_01____TEXT ends
; ===========================================================================
@ -32049,13 +31952,15 @@ _EXTEND_SCORES dd 100000, 200000, 300000, 500000, 800000, 99999999
_extends_gained dw 0
dword_1E5B8 dd 40000
include th02/main/hud/score_put[data].asm
word_1E5D8 dw 4140h
word_1E5DA dw 4342h
word_1E5DC dw 44h
public _gHUD_BAR_MAX, _HUD_POWER_COLORS, _gHUD_BAR_BLANK
_gHUD_BAR_MAX label byte
db g_BAR_MAX_0, g_BAR_MAX_1, g_BAR_MAX_2, g_BAR_MAX_3, g_BAR_MAX_4, 0
include th02/main/hud/power[data].asm
word_1E5E7 dw 0CFCFh
word_1E5E9 dw 0CFCFh
word_1E5EB dw 0CFh
_gHUD_BAR_BLANK db gb_SP, gb_SP, gb_SP, gb_SP, gb_SP, 0
include th02/gaiji/ranks_left[data].asm
gsSCORE db 0C4h, 0C5h, 0C6h, 0, 0
gsHISCORE db 0CEh, 0C4h, 0C5h, 0C6h, 0

View File

@ -1,5 +1,7 @@
#pragma option -3
#include "platform.h"
#include "pc98.h"
#include "th04/main/hud/hud.hpp"
void pascal near hud_hp_update_and_render(int hp_cur, int hp_max)

View File

@ -1,4 +1,6 @@
#include "th02/main/hud/hud.h"
#include "th02/main/hud/hud.hpp"
#define BAR_MAX 128
// Low-level
// ---------