Skip to content

Commit

Permalink
[Decompilation] [th01] HUD: Inter-page row-sized rectangle blitting
Browse files Browse the repository at this point in the history
Both inlined and non-inlined page switching within the same function,
together with an approach that doesn't correspond to our other planar
access macros? That code must have been written during a very
experimental phase very early in the development of this game.

Part of P0104, funded by Ember2528.
  • Loading branch information
nmlgc committed Jul 27, 2020
1 parent edd9a14 commit f3093a8
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 118 deletions.
5 changes: 5 additions & 0 deletions planar.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,11 @@ static inline unsigned int vram_offset_muldiv(int x, int y)
{
return (y * ROW_SIZE) + (x / 8);
}

static inline unsigned int vram_offset_divmul(int x, int y)
{
return (x / 8) + (y * ROW_SIZE);
}
#endif

#define VRAM_CHUNK(plane, offset, bit_count) \
Expand Down
48 changes: 33 additions & 15 deletions th01/main/hud/hud.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,11 @@ static const int CUR_FX = FX(7, 3, 0);
#if (PTN_QUARTER_W < GLYPH_FULL_W)
#error Original code assumes PTN_QUARTER_W >= GLYPH_FULL_W
#endif
#if (PTN_QUARTER_H < GLYPH_H)
#error Original code assumes PTN_QUARTER_H >= GLYPH_H
#endif
static const int COL_W = PTN_QUARTER_W;
static const int ROW_H = PTN_QUARTER_H;

static const int SCORE_W = (SCORE_DIGITS * COL_W);

Expand Down Expand Up @@ -235,21 +239,8 @@ void score_and_cardcombo_put_initial(bool16 first_run)
}
cardcombo_put_initial(MAX_TOP, MAX_FX);

/* TODO: Replace with the decompiled calls
* graph_copy_hud_row_0_to_1_8(SCORE_LEFT, MAX_TOP, SCORE_AND_CARDCOMBO_W);
* graph_copy_hud_row_0_to_1_8(SCORE_LEFT, CUR_TOP, SCORE_AND_CARDCOMBO_W);
* once that function is part of this translation unit */
#define call(top) __asm { \
db 0x66, 0x68, top, 0x00, SCORE_AND_CARDCOMBO_W, 0x00; \
push SCORE_LEFT; \
nop; \
push cs; \
call near ptr graph_copy_hud_row_0_to_1_8; \
add sp, 6; \
}
call(MAX_TOP);
call(CUR_TOP);

graph_copy_hud_row_0_to_1_8(SCORE_LEFT, MAX_TOP, SCORE_AND_CARDCOMBO_W);
graph_copy_hud_row_0_to_1_8(SCORE_LEFT, CUR_TOP, SCORE_AND_CARDCOMBO_W);
hud_cardcombo_max = 0;
}

Expand Down Expand Up @@ -312,3 +303,30 @@ int hud_bg_load(const char *fn)
return 0;
}
/// ----------

void graph_copy_hud_row_0_to_1_8(int left, int top, int w)
{
uint16_t vram_offset;
dots16_t dots;
int y;
uint16_t vram_offset_row = vram_offset_divmul(left, top);
int x;

vram_offset = vram_offset_row;
for(y = 0; y < ROW_H; y++) {
vram_offset = vram_offset_row;
for(x = 0; x < (w / 16); x++) {
#define copy_plane(plane) \
OUTW(0xA6, 0); VRAM_SNAP(dots, plane, vram_offset, 16); \
OUTW(0xA6, 1); VRAM_PUT(plane, vram_offset, dots, 16);
copy_plane(B);
copy_plane(R);
copy_plane(G);
copy_plane(E);
vram_offset += sizeof(dots);
#undef copy_plane
}
vram_offset_row += ROW_SIZE;
}
graph_accesspage_func(0);
}
104 changes: 1 addition & 103 deletions th01_reiiden.asm
Original file line number Diff line number Diff line change
Expand Up @@ -14356,116 +14356,14 @@ main_25_TEXT segment byte public 'CODE' use16
extern _score_and_cardcombo_put_initial:proc
extern _hud_bg_put:proc
extern _hud_bg_load:proc
extern _graph_copy_hud_row_0_to_1_8:proc
main_25_TEXT ends

main_25__TEXT segment byte public 'CODE' use16
assume cs:main_25
;org 9
assume es:nothing, ss:nothing, ds:_DATA, fs:nothing, gs:nothing

; =============== S U B R O U T I N E =======================================

; Attributes: bp-based frame
public _graph_copy_hud_row_0_to_1_8
_graph_copy_hud_row_0_to_1_8 proc far

var_6 = word ptr -6
var_4 = word ptr -4
var_2 = word ptr -2
arg_0 = word ptr 6
arg_2 = word ptr 8
arg_4 = word ptr 0Ah

enter 6, 0
push si
push di
mov ax, [bp+arg_0]
mov bx, 8
cwd
idiv bx
mov dx, [bp+arg_2]
imul dx, 50h
add ax, dx
mov [bp+var_4], ax
mov si, [bp+var_4]
mov [bp+var_2], 0
jmp loc_18D84
; ---------------------------------------------------------------------------

loc_18CF8:
mov si, [bp+var_4]
mov [bp+var_6], 0
jmp short loc_18D6F
; ---------------------------------------------------------------------------

loc_18D02:
mov dx, 0A6h
xor ax, ax
out dx, ax
les bx, _VRAM_PLANE_B
add bx, si
mov di, es:[bx]
mov ax, 1
out dx, ax
mov bx, word ptr _VRAM_PLANE_B
add bx, si
mov es:[bx], di
xor ax, ax
out dx, ax
les bx, _VRAM_PLANE_R
add bx, si
mov di, es:[bx]
mov ax, 1
out dx, ax
mov bx, word ptr _VRAM_PLANE_R
add bx, si
mov es:[bx], di
xor ax, ax
out dx, ax
les bx, _VRAM_PLANE_G
add bx, si
mov di, es:[bx]
mov ax, 1
out dx, ax
mov bx, word ptr _VRAM_PLANE_G
add bx, si
mov es:[bx], di
xor ax, ax
out dx, ax
les bx, _VRAM_PLANE_E
add bx, si
mov di, es:[bx]
mov ax, 1
out dx, ax
mov bx, word ptr _VRAM_PLANE_E
add bx, si
mov es:[bx], di
add si, 2
inc [bp+var_6]

loc_18D6F:
mov ax, [bp+arg_4]
mov bx, 16
cwd
idiv bx
cmp ax, [bp+var_6]
jg short loc_18D02
add [bp+var_4], ROW_SIZE
inc [bp+var_2]

loc_18D84:
cmp [bp+var_2], GLYPH_H
jl loc_18CF8
push 0
call _graph_accesspage_func
pop cx
pop di
pop si
leave
retf
_graph_copy_hud_row_0_to_1_8 endp


; =============== S U B R O U T I N E =======================================

; Attributes: bp-based frame
Expand Down

0 comments on commit f3093a8

Please sign in to comment.