From f6cbff0bf910252d5f8a9e248b74e648ce0466ad Mon Sep 17 00:00:00 2001 From: nmlgc Date: Fri, 13 Mar 2020 00:54:35 +0100 Subject: [PATCH] [Decompilation] [th01] .GRP file loading and display MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit All the weird double returns in FUUIN.EXE just magically appear with -O-! 😮 And yeah, it's a bowl of global state spaghetti once again. 🍝 Named the functions in a way that would make sense to a user of the API, who should be aware of typical side effects, like, y'know, a changed hardware palette… That's how you end up with the supposed "main" function getting a "_palette_show" suffix. Completes P0082, funded by Ember2528. --- Makefile.mak | 2 +- libs/piloadc/piloadc.h | 19 ++ th01/formats/grp.cpp | 112 +++++++ th01/formats/grp.h | 26 ++ th01/formats/grp_buf[bss].asm | 2 + th01/formats/grp_put_palette_show_1.asm | 13 + th01/formats/grz.cpp | 2 - th01/fuuin_10.cpp | 8 + th01/main_08.cpp | 3 + th01/op_09.cpp | 3 + th01_fuuin.asm | 421 +----------------------- th01_op.asm | 280 +--------------- th01_reiiden.asm | 321 +----------------- th01_reiiden_2.inc | 76 +---- 14 files changed, 239 insertions(+), 1049 deletions(-) create mode 100644 libs/piloadc/piloadc.h create mode 100644 th01/formats/grp_buf[bss].asm create mode 100644 th01/formats/grp_put_palette_show_1.asm create mode 100644 th01/fuuin_10.cpp diff --git a/Makefile.mak b/Makefile.mak index 7f0e97b9..b3ceaf8b 100644 --- a/Makefile.mak +++ b/Makefile.mak @@ -57,7 +57,7 @@ bin\th01\reiiden.exe: bin\th01\reiiden.obj th01\main_02.c th01\main_03.c th01\ma $** | -bin\th01\fuuin.exe: bin\th01\fuuin.obj th01\fuuin_04.cpp th01\fuuin_05.c th01\fuuin_06.c th01\fuuin_07.c th01\fuuin_08.cpp th01\fuuin_09.c th01\fuuin_11.c th01\fuuin_12.c th01\fuuin_13.c +bin\th01\fuuin.exe: bin\th01\fuuin.obj th01\fuuin_04.cpp th01\fuuin_05.c th01\fuuin_06.c th01\fuuin_07.c th01\fuuin_08.cpp th01\fuuin_09.c th01\fuuin_10.cpp th01\fuuin_11.c th01\fuuin_12.c th01\fuuin_13.c $(CC) $(CFLAGS) -ml -3 -DGAME=1 -DBINARY='E' -nbin\th01\ -eFUUIN.EXE @&&| $** | diff --git a/libs/piloadc/piloadc.h b/libs/piloadc/piloadc.h new file mode 100644 index 00000000..4b66d18d --- /dev/null +++ b/libs/piloadc/piloadc.h @@ -0,0 +1,19 @@ +// Option and error constants, according to PILOADC.DOC. + +#define PILOAD_OPT_COLORKEY(col) ((col << 8) | 0x40) + +// PiLoad also returns values >0 indicate DOS file I/O errors. +#define PILOAD_ERR_OK 0 +#define PILOAD_ERR_BUFFER_TOO_SMALL -8 +#define PILOAD_ERR_NO_PI -31 +#define PILOAD_ERR_NOT_SUPPORTED -32 + +#if defined(__LARGE__) || defined(__HUGE__) +# define PiLoad PiLoadL +#elif defined(__COMPACT__) +# define PiLoad PiLoadC +#endif + +int PiLoad( + const char *name, char *buff, int Size, int X, int Y, int tone, int option +); diff --git a/th01/formats/grp.cpp b/th01/formats/grp.cpp index 746dcd99..580aed09 100644 --- a/th01/formats/grp.cpp +++ b/th01/formats/grp.cpp @@ -1,7 +1,119 @@ extern "C" { +#include + +#include "ReC98.h" +#include "libs/piloadc/piloadc.h" +#include "th01/hardware/palette.h" +#include "th01/formats/grp.h" + +// The same size that master.lib uses in graph_pi_load_pack(), with no +// explanation for it given in either master.lib or PILOADC.DOC... +#define GRP_BUFFER_SIZE 0x4000 + +// *Not* offsetof(PiHeader, palette)! +#define PI_PALETTE_OFFSET 0x12 + +extern int8_t* grp_buf; extern int flag_palette_show; // = true extern int flag_grp_put; // = true extern unsigned char flag_grp_colorkey; // = false +int grp_palette_load_show_sane(const char *fn) +{ + if(!file_ropen(fn)) { + return 1; + } + file_seek(PI_PALETTE_OFFSET, 0); + file_read(&grp_palette, sizeof(grp_palette)); +#if (BINARY == 'E') + grp_palette_settone(grp_palette_tone); +#else + z_palette_set_all_show(grp_palette); +#endif + file_close(); + return 0; +} + +int grp_palette_load(const char *fn) +{ + if(!file_ropen(fn)) { + return 1; + } + file_seek(PI_PALETTE_OFFSET, 0); + file_read(&grp_palette, sizeof(grp_palette)); + file_close(); + return 0; +} + +// Random unused function is random +int getkanji(FILE *fp) +{ + int low = getc(fp); + low += (getc(fp) << 8); + return low; +} + +void grp_palette_set_all(const Palette4& pal) +{ + for(int col = 0; col < COLOR_COUNT; col++) { + for(int comp = 0; comp < sizeof(RGB4); comp++) { + grp_palette[col].v[comp] = pal[col].v[comp]; + } + } +} + +int grp_put_palette_show(const char *fn) +{ + int option = 0; + char ret; + + grp_buf = new int8_t[GRP_BUFFER_SIZE]; + if(flag_palette_show == true) { + // Setting bit 1 should set a resident palette of sorts, but this is + // not actually supported by the PC-98 version of piloadc... + option |= 2; + } + if(flag_grp_colorkey == true) { + option = PILOAD_OPT_COLORKEY(15); + } + if(flag_grp_put == true) { + ret = PiLoad(fn, grp_buf, GRP_BUFFER_SIZE, 0, 0, 100, option); + } + if(flag_palette_show == true) { + grp_palette_load_show_sane(fn); + } else { + grp_palette_load(fn); + } + + delete[] grp_buf; + return ret; +} + +int grp_put(const char *fn) +{ + flag_palette_show = false; + int ret = grp_put_palette_show(fn); + flag_palette_show = true; + return ret; +} + +int grp_palette_load_show(const char *fn) +{ + flag_grp_put = false; + int ret = grp_put_palette_show(fn); + flag_grp_put = true; + return ret; +} + +int grp_put_colorkey(const char *fn) +{ + flag_grp_colorkey = true; + flag_palette_show = false; + int ret = grp_put_palette_show(fn); + flag_palette_show = true; + flag_grp_colorkey = false; + return ret; +} + } diff --git a/th01/formats/grp.h b/th01/formats/grp.h index eb721061..7d4d6b1a 100644 --- a/th01/formats/grp.h +++ b/th01/formats/grp.h @@ -1,4 +1,27 @@ extern Palette4 grp_palette; + +// Overwrites [grp_palette] with [pal]. +void grp_palette_set_all(const Palette4& pal); + +// Loads [grp_palette] from the .GRP file with the given [fn], and updates the +// hardware palette with it. Returns garbage. +int grp_palette_load_show(const char *fn); + +// Sane version of grp_palette_load_show(). Returns 0 on success, 1 on file +// opening failure. +int grp_palette_load_show_sane(const char *fn); + +// Displays the .GRP image loaded from [fn] on the currently accessed VRAM +// page, using the current hardware palette. Returns the return value from +// PiLoad. +int grp_put(const char *fn); + +// Like grp_put(), but sets the hardware palette to the one in [fn]'s header. +int grp_put_palette_show(const char *fn); + +// Like grp_put(), but treats color #15 as transparent. +int grp_put_colorkey(const char *fn); + #if (BINARY == 'E') extern int grp_palette_tone; @@ -12,4 +35,7 @@ extern Palette4 grp_palette; void pascal grp_palette_black_in(unsigned int frames); void pascal grp_palette_white_out(unsigned int frames); void pascal grp_palette_white_in(unsigned int frames); + + // Like grp_put(), but always switches to page 1 first. + int pascal grp_put_palette_show_1(const char *fn); #endif diff --git a/th01/formats/grp_buf[bss].asm b/th01/formats/grp_buf[bss].asm new file mode 100644 index 00000000..81a3013c --- /dev/null +++ b/th01/formats/grp_buf[bss].asm @@ -0,0 +1,2 @@ +public _grp_buf +_grp_buf dd ? diff --git a/th01/formats/grp_put_palette_show_1.asm b/th01/formats/grp_put_palette_show_1.asm new file mode 100644 index 00000000..d2c35f43 --- /dev/null +++ b/th01/formats/grp_put_palette_show_1.asm @@ -0,0 +1,13 @@ +public GRP_PUT_PALETTE_SHOW_1 +grp_put_palette_show_1 proc far + +@@fn = dword ptr 6 + + push bp + mov bp, sp + call _graph_accesspage_func stdcall, 1 + pop cx + call _grp_put_palette_show c, word ptr [bp+@@fn], word ptr [bp+@@fn+2] + pop bp + retf 4 +grp_put_palette_show_1 endp diff --git a/th01/formats/grz.cpp b/th01/formats/grz.cpp index eddb0981..68a54a76 100644 --- a/th01/formats/grz.cpp +++ b/th01/formats/grz.cpp @@ -1,5 +1,3 @@ -#pragma option -Z - extern "C" { #include diff --git a/th01/fuuin_10.cpp b/th01/fuuin_10.cpp new file mode 100644 index 00000000..10829e05 --- /dev/null +++ b/th01/fuuin_10.cpp @@ -0,0 +1,8 @@ +/* ReC98 + * ----- + * Code segment #10 of TH01's FUIIN.EXE + */ + +#pragma option -1 -O- + +#include "th01/formats/grp.cpp" diff --git a/th01/main_08.cpp b/th01/main_08.cpp index 6ea61d30..0537f093 100644 --- a/th01/main_08.cpp +++ b/th01/main_08.cpp @@ -3,4 +3,7 @@ * Code segment #8 of TH01's REIIDEN.EXE */ +#pragma option -Z + +#include "th01/formats/grp.cpp" #include "th01/formats/grz.cpp" diff --git a/th01/op_09.cpp b/th01/op_09.cpp index 54a752de..f1a7ea4d 100644 --- a/th01/op_09.cpp +++ b/th01/op_09.cpp @@ -3,4 +3,7 @@ * Code segment #9 of TH01's OP.EXE */ +#pragma option -Z + +#include "th01/formats/grp.cpp" #include "th01/formats/grz.cpp" diff --git a/th01_fuuin.asm b/th01_fuuin.asm index f12a5616..b9ba15a0 100644 --- a/th01_fuuin.asm +++ b/th01_fuuin.asm @@ -33,7 +33,6 @@ include th01/th01.inc extern LXLSH@:proc extern LXMUL@:proc extern SCOPY@:proc - extern __fgetc:proc extern __mbcjmstojis:proc extern __mbctype:byte extern __setargv__:proc ; main() needs both to be set @@ -45,7 +44,6 @@ include th01/th01.inc extern _farfree:proc extern _farmalloc:proc extern _fclose:proc - extern _fgetc:proc extern _filelength:proc extern _fopen:proc extern _int86:proc @@ -3475,9 +3473,7 @@ sub_B945 proc far add sp, 4 call _mdrv2_bgm_play call grp_palette_settone pascal, 0 - push ds - push offset aEd1a_grp ; "ED1A.grp" - call sub_C73A + call grp_put_palette_show_1 pascal, ds, offset aEd1a_grp ; "ED1A.grp" push 0 call sub_C78B pop cx @@ -3503,9 +3499,7 @@ sub_B945 proc far pop cx call _frame_delay stdcall, 50 pop cx - push ds - push offset aEd1b_grp ; "ED1B.grp" - call sub_C73A + call grp_put_palette_show_1 pascal, ds, offset aEd1b_grp ; "ED1B.grp" push 0 call sub_C78B pop cx @@ -3527,9 +3521,7 @@ sub_B945 proc far pop cx call _z_graph_clear call grp_palette_settone pascal, 100 - push ds - push offset aEd1c_grp ; "ED1C.GRP" - call sub_C73A + call grp_put_palette_show_1 pascal, ds, offset aEd1c_grp ; "ED1C.GRP" xor si, si jmp short loc_BA49 ; --------------------------------------------------------------------------- @@ -3560,9 +3552,7 @@ loc_BA49: pop cx call _frame_delay stdcall, 40 pop cx - push ds - push offset aEd1d_grp ; "ED1D.GRP" - call sub_C73A + call grp_put_palette_show_1 pascal, ds, offset aEd1d_grp ; "ED1D.GRP" push 3 call sub_C78B pop cx @@ -3668,9 +3658,7 @@ loc_BB1E: call sub_C78B pop cx call grp_palette_settone pascal, 105 - push ds - push offset aEd1e_grp ; "ED1E.GRP" - call sub_C73A + call grp_put_palette_show_1 pascal, ds, offset aEd1e_grp ; "ED1E.GRP" push 0 call sub_C78B pop cx @@ -3843,9 +3831,7 @@ sub_BC7C proc near push bp mov bp, sp push si - push ds - push offset aEd2a_grp ; "ed2a.grp" - call sub_C73A + call grp_put_palette_show_1 pascal, ds, offset aEd2a_grp ; "ed2a.grp" call grp_palette_settone pascal, 200 push 0 call sub_C78B @@ -3879,9 +3865,7 @@ sub_BC7C proc near ; --------------------------------------------------------------------------- loc_BCFC: - push ds - push offset aEd4a_grp ; "ed4a.grp" - call sub_C73A + call grp_put_palette_show_1 pascal, ds, offset aEd4a_grp ; "ed4a.grp" xor si, si jmp short loc_BD2A ; --------------------------------------------------------------------------- @@ -3962,9 +3946,7 @@ sub_BDBD proc near push bp mov bp, sp push si - push ds - push offset aEd3a_grp ; "ed3a.grp" - call sub_C73A + call grp_put_palette_show_1 pascal, ds, offset aEd3a_grp ; "ed3a.grp" call grp_palette_settone pascal, 200 xor si, si jmp short loc_BE07 @@ -4057,9 +4039,7 @@ sub_BDBD endp sub_BE83 proc near push bp mov bp, sp - push ds - push offset aEd3b_grp ; "ed3b.grp" - call sub_C73A + call grp_put_palette_show_1 pascal, ds, offset aEd3b_grp ; "ed3b.grp" push 0 call sub_C78B pop cx @@ -4098,9 +4078,7 @@ sub_BF07 proc near push bp mov bp, sp push si - push ds - push offset aEd5a_grp ; "ed5a.grp" - call sub_C73A + call grp_put_palette_show_1 pascal, ds, offset aEd5a_grp ; "ed5a.grp" push 0 call sub_C78B pop cx @@ -4127,9 +4105,7 @@ loc_BF30: loc_BF51: cmp si, 0Fh jl short loc_BF30 - push ds - push offset aEd5b_grp ; "ed5b.grp" - call sub_C73A + call grp_put_palette_show_1 pascal, ds, offset aEd5b_grp ; "ed5b.grp" push 0 call sub_C78B pop cx @@ -4150,9 +4126,7 @@ loc_BF51: pop cx call _frame_delay stdcall, 100 pop cx - push ds - push offset aEd5c_grp ; "ed5c.grp" - call sub_C73A + call grp_put_palette_show_1 pascal, ds, offset aEd5c_grp ; "ed5c.grp" push 0 call sub_C78B pop cx @@ -4231,7 +4205,7 @@ loc_C074: push offset aEndb_b_grp ; "endb_b.grp" loc_C078: - call sub_C73A + call grp_put_palette_show_1 push 0 call sub_C78B pop cx @@ -4722,10 +4696,7 @@ var_10 = byte ptr -10h push 1 call _graph_accesspage_func pop cx - push ds - push offset aEndm_a_grp ; "endm_a.grp" - call sub_EB39 - add sp, 4 + call _grp_put_palette_show c, offset aEndm_a_grp, ds ; "endm_a.grp" call _graph_copy_page_back_to_front push 0 call _graph_accesspage_func @@ -4972,28 +4943,7 @@ fuuin_04_TEXT segment byte public 'CODE' use16 ;org 0Ah 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 - -sub_C73A proc far - -arg_0 = word ptr 6 -arg_2 = word ptr 8 - - push bp - mov bp, sp - push 1 - call _graph_accesspage_func - pop cx - push [bp+arg_2] - push [bp+arg_0] - call sub_EB39 - add sp, 4 - pop bp - retf 4 -sub_C73A endp - +include th01/formats/grp_put_palette_show_1.asm EGC_START_COPY_DEF 1, far ; =============== S U B R O U T I N E ======================================= @@ -5148,347 +5098,12 @@ fuuin_09_TEXT ends ; Segment type: Pure code fuuin_10_TEXT segment byte public 'CODE' use16 - assume cs:fuuin_10_TEXT - ;org 0Dh - 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 - -sub_EA1D proc far - -arg_0 = word ptr 6 -arg_2 = word ptr 8 - - push bp - mov bp, sp - push [bp+arg_2] - push [bp+arg_0] - call file_ropen - or ax, ax - jnz short loc_EA34 - mov ax, 1 - pop bp - retf -; --------------------------------------------------------------------------- - -loc_EA34: - call file_seek pascal, 0, 12h, 0 - call file_read pascal, ds, offset _grp_palette, size palette_t - call grp_palette_settone pascal, _grp_palette_tone - call file_close - xor ax, ax - pop bp - retf -sub_EA1D endp - -; --------------------------------------------------------------------------- - pop bp - retf - -; =============== S U B R O U T I N E ======================================= - -; Attributes: bp-based frame - -sub_EA5E proc far - -arg_0 = word ptr 6 -arg_2 = word ptr 8 - - push bp - mov bp, sp - push [bp+arg_2] - push [bp+arg_0] - call file_ropen - or ax, ax - jnz short loc_EA75 - mov ax, 1 - pop bp - retf -; --------------------------------------------------------------------------- - -loc_EA75: - call file_seek pascal, 0, 12h, 0 - call file_read pascal, ds, offset _grp_palette, size palette_t - call file_close - xor ax, ax - pop bp - retf -sub_EA5E endp - -; --------------------------------------------------------------------------- - pop bp - retf - -; =============== S U B R O U T I N E ======================================= - -; Attributes: bp-based frame - -sub_EA96 proc far - -stream = dword ptr 6 - - push bp - mov bp, sp - push si - push di - les bx, [bp+stream] - dec word ptr es:[bx] - jl short loc_EABB - les bx, [bp+stream] - mov dx, es:[bx+0Eh] - mov si, es:[bx+0Ch] - inc word ptr es:[bx+0Ch] - mov es, dx - mov al, es:[si] - mov ah, 0 - jmp short loc_EAC9 -; --------------------------------------------------------------------------- - -loc_EABB: - push word ptr [bp+stream+2] - push word ptr [bp+stream] ; stream - call __fgetc - add sp, 4 - -loc_EAC9: - mov di, ax - les bx, [bp+stream] - dec word ptr es:[bx] - jl short loc_EAEB - les bx, [bp+stream] - mov dx, es:[bx+0Eh] - mov si, es:[bx+0Ch] - inc word ptr es:[bx+0Ch] - mov es, dx - mov al, es:[si] - mov ah, 0 - jmp short loc_EAF9 -; --------------------------------------------------------------------------- - -loc_EAEB: - push word ptr [bp+stream+2] - push word ptr [bp+stream] ; stream - call __fgetc - add sp, 4 - -loc_EAF9: - shl ax, 8 - add di, ax - mov ax, di - jmp short $+2 - pop di - pop si - pop bp - retf -sub_EA96 endp - - -; =============== S U B R O U T I N E ======================================= - -; Attributes: bp-based frame - -sub_EB06 proc far - -arg_0 = dword ptr 6 - - push bp - mov bp, sp - xor dx, dx - jmp short loc_EB32 -; --------------------------------------------------------------------------- - -loc_EB0D: - xor cx, cx - jmp short loc_EB2C -; --------------------------------------------------------------------------- - -loc_EB11: - mov ax, dx - imul ax, size rgb_t - les bx, [bp+arg_0] - add bx, ax - add bx, cx - mov al, es:[bx] - mov bx, dx - imul bx, size rgb_t - add bx, cx - mov byte ptr _grp_palette[bx], al - inc cx - -loc_EB2C: - cmp cx, size rgb_t - jl short loc_EB11 - inc dx - -loc_EB32: - cmp dx, COLOR_COUNT - jl short loc_EB0D - pop bp - retf -sub_EB06 endp - - -; =============== S U B R O U T I N E ======================================= - -; Attributes: bp-based frame - -sub_EB39 proc far - -var_1 = byte ptr -1 -arg_0 = word ptr 6 -arg_2 = word ptr 8 - - enter 2, 0 - push si - xor si, si - push 4000h - call @$bnwa$qui - pop cx - mov word_1464C, dx - mov off_1464A, ax - cmp _flag_palette_show, 1 - jnz short loc_EB5A - or si, 2 - -loc_EB5A: - cmp _flag_grp_colorkey, 1 - jnz short loc_EB64 - mov si, 0F40h - -loc_EB64: - cmp _flag_grp_put, 1 - jnz short loc_EB8E - push si - push 64h ; 'd' - push 0 - push 0 - push 4000h - push word_1464C - push off_1464A - push [bp+arg_2] - push [bp+arg_0] - call _PiLoadL - add sp, 12h - mov [bp+var_1], al - -loc_EB8E: - cmp _flag_palette_show, 1 - jnz short loc_EBA1 - push [bp+arg_2] - push [bp+arg_0] - call sub_EA1D - jmp short loc_EBAB -; --------------------------------------------------------------------------- - -loc_EBA1: - push [bp+arg_2] - push [bp+arg_0] - call sub_EA5E - -loc_EBAB: - add sp, 4 - push word_1464C - push off_1464A ; font - call @$bdla$qnv - add sp, 4 - mov al, [bp+var_1] - cbw - jmp short $+2 - pop si - leave - retf -sub_EB39 endp - - -; =============== S U B R O U T I N E ======================================= - -; Attributes: bp-based frame - -sub_EBC7 proc far - -var_2 = word ptr -2 -arg_0 = word ptr 6 -arg_2 = word ptr 8 - - enter 2, 0 - mov _flag_palette_show, 0 - push [bp+arg_2] - push [bp+arg_0] - call sub_EB39 - add sp, 4 - mov [bp+var_2], ax - mov _flag_palette_show, 1 - mov ax, [bp+var_2] - leave - retf -sub_EBC7 endp - -; --------------------------------------------------------------------------- - leave - retf - -; =============== S U B R O U T I N E ======================================= - -; Attributes: bp-based frame - -sub_EBEE proc far - -var_2 = word ptr -2 -arg_0 = word ptr 6 -arg_2 = word ptr 8 - - enter 2, 0 - mov _flag_grp_put, 0 - push [bp+arg_2] - push [bp+arg_0] - call sub_EB39 - add sp, 4 - mov [bp+var_2], ax - mov _flag_grp_put, 1 - mov ax, [bp+var_2] - leave - retf -sub_EBEE endp - -; --------------------------------------------------------------------------- - leave - retf - -; =============== S U B R O U T I N E ======================================= - -; Attributes: bp-based frame - -sub_EC15 proc far - -var_2 = word ptr -2 -arg_0 = word ptr 6 -arg_2 = word ptr 8 - - enter 2, 0 - mov _flag_grp_colorkey, 1 - mov _flag_palette_show, 0 - push [bp+arg_2] - push [bp+arg_0] - call sub_EB39 - add sp, 4 - mov [bp+var_2], ax - mov _flag_palette_show, 1 - mov _flag_grp_colorkey, 0 - mov ax, [bp+var_2] - leave - retf -sub_EC15 endp - + extern _grp_put_palette_show:proc fuuin_10_TEXT ends -; --------------------------------------------------------------------------- ; =========================================================================== fuuin_11_TEXT segment byte public 'CODE' use16 - leave - retf extern VRAM_PLANES_SET:proc extern _egc_copy_rect_1_to_0:proc fuuin_11_TEXT ends @@ -6312,9 +5927,7 @@ include th01/formats/grp_palette[bss].asm dd ? dd ? dd ? -; void (*off_1464A)(void) -off_1464A dw ? -word_1464C dw ? +include th01/formats/grp_buf[bss].asm include th01/hardware/vram_planes[bss].asm include libs/master.lib/pal[bss].asm include libs/master.lib/fil[bss].asm diff --git a/th01_op.asm b/th01_op.asm index dc980d11..2142b4f8 100644 --- a/th01_op.asm +++ b/th01_op.asm @@ -29,7 +29,6 @@ include th01/th01.inc extern @$bnwa$qui:proc extern FTOL@:proc extern SCOPY@:proc - extern __fgetc:proc extern __mbcjmstojis:proc extern __mbctype:byte extern __mscjmstojis:proc @@ -794,16 +793,10 @@ sub_A719 proc far push 1 call _graph_accesspage_func pop cx - push ds - push offset aReiiden2_grp ; "REIIDEN2.grp" - call sub_DAEC - add sp, 4 + call _grp_put_palette_show c, offset aReiiden2_grp, ds ; "REIIDEN2.grp" call _z_palette_black call _graph_copy_page_back_to_front - push ds - push offset aReiiden3_grp ; "REIIDEN3.grp" - call sub_DB6F - add sp, 4 + call _grp_put c, offset aReiiden3_grp, ds ; "REIIDEN3.grp" push 0 call _graph_accesspage_func pop cx @@ -831,10 +824,7 @@ sub_A772 proc far push 0 call _graph_accesspage_func pop cx - push ds - push offset aOp_win_grp ; "op_win.grp" - call sub_DBAF - add sp, 4 + call _grp_put_colorkey c, offset aOp_win_grp, ds ; "op_win.grp" call _graph_copy_page_back_to_front pop bp retf @@ -2956,264 +2946,9 @@ loc_D9D5: leave retf -; =============== S U B R O U T I N E ======================================= - -; Attributes: bp-based frame - -sub_D9E3 proc far - -arg_0 = dword ptr 6 - - push bp - mov bp, sp - pushd [bp+arg_0] - call file_ropen - or ax, ax - jnz short loc_D9F8 - mov ax, 1 - pop bp - retf -; --------------------------------------------------------------------------- - -loc_D9F8: - call file_seek pascal, large 12h, 0 - call file_read pascal, ds, offset _grp_palette, size palette_t - call _z_palette_set_all_show c, offset _grp_palette, ds - call file_close - xor ax, ax - pop bp - retf -sub_D9E3 endp - - -; =============== S U B R O U T I N E ======================================= - -; Attributes: bp-based frame - -sub_DA22 proc far - -arg_0 = dword ptr 6 - - push bp - mov bp, sp - pushd [bp+arg_0] - call file_ropen - or ax, ax - jnz short loc_DA37 - mov ax, 1 - pop bp - retf -; --------------------------------------------------------------------------- - -loc_DA37: - call file_seek pascal, large 12h, 0 - call file_read pascal, ds, offset _grp_palette, size palette_t - call file_close - xor ax, ax - pop bp - retf -sub_DA22 endp - -; --------------------------------------------------------------------------- - push bp - mov bp, sp - push si - push di - les bx, [bp+6] - dec word ptr es:[bx] - jl short loc_DA77 - mov ax, es:[bx+0Eh] - mov si, es:[bx+0Ch] - inc word ptr es:[bx+0Ch] - mov es, ax - mov al, es:[si] - mov ah, 0 - jmp short loc_DA83 -; --------------------------------------------------------------------------- - -loc_DA77: - pushd dword ptr [bp+6] - call __fgetc - add sp, 4 - -loc_DA83: - mov di, ax - les bx, [bp+6] - dec word ptr es:[bx] - jl short loc_DAA2 - mov ax, es:[bx+0Eh] - mov si, es:[bx+0Ch] - inc word ptr es:[bx+0Ch] - mov es, ax - mov al, es:[si] - mov ah, 0 - jmp short loc_DAAE -; --------------------------------------------------------------------------- - -loc_DAA2: - pushd dword ptr [bp+6] - call __fgetc - add sp, 4 - -loc_DAAE: - shl ax, 8 - add di, ax - mov ax, di - pop di - pop si - pop bp - retf -; --------------------------------------------------------------------------- - push bp - mov bp, sp - xor dx, dx - jmp short loc_DAE5 -; --------------------------------------------------------------------------- - -loc_DAC0: - xor cx, cx - jmp short loc_DADF -; --------------------------------------------------------------------------- - -loc_DAC4: - mov ax, dx - imul ax, size rgb_t - les bx, [bp+6] - add bx, ax - add bx, cx - mov al, es:[bx] - mov bx, dx - imul bx, size rgb_t - add bx, cx - mov byte ptr _grp_palette[bx], al - inc cx - -loc_DADF: - cmp cx, size rgb_t - jl short loc_DAC4 - inc dx - -loc_DAE5: - cmp dx, COLOR_COUNT - jl short loc_DAC0 - pop bp - retf - -; =============== S U B R O U T I N E ======================================= - -; Attributes: bp-based frame - -sub_DAEC proc far - -var_1 = byte ptr -1 -arg_0 = dword ptr 6 - - enter 2, 0 - push si - xor si, si - push 4000h - call @$bnwa$qui - pop cx - mov word ptr font+2, dx - mov word ptr font, ax - cmp _flag_palette_show, 1 - jnz short loc_DB0D - or si, 2 - -loc_DB0D: - cmp _flag_grp_colorkey, 1 - jnz short loc_DB17 - mov si, 0F40h - -loc_DB17: - cmp _flag_grp_put, 1 - jnz short loc_DB3F - push si - push 640000h - pushd 4000h - pushd [font] - pushd [bp+arg_0] - call _PiLoadL - add sp, 12h - mov [bp+var_1], al - -loc_DB3F: - cmp _flag_palette_show, 1 - jnz short loc_DB50 - pushd [bp+arg_0] - call sub_D9E3 - jmp short loc_DB58 -; --------------------------------------------------------------------------- - -loc_DB50: - pushd [bp+arg_0] - call sub_DA22 - -loc_DB58: - add sp, 4 - pushd [font] ; font - call @$bdla$qnv - add sp, 4 - mov al, [bp+var_1] - cbw - pop si - leave - retf -sub_DAEC endp - - -; =============== S U B R O U T I N E ======================================= - -; Attributes: bp-based frame - -sub_DB6F proc far - -var_2 = word ptr -2 -arg_0 = dword ptr 6 - - enter 2, 0 - mov _flag_palette_show, 0 - pushd [bp+arg_0] - call sub_DAEC - add sp, 4 - mov [bp+var_2], ax - mov _flag_palette_show, 1 - leave - retf -sub_DB6F endp - -; --------------------------------------------------------------------------- - enter 2, 0 - mov _flag_grp_put, 0 - pushd dword ptr [bp+6] - call sub_DAEC - add sp, 4 - mov [bp-2], ax - mov _flag_grp_put, 1 - leave - retf - -; =============== S U B R O U T I N E ======================================= - -; Attributes: bp-based frame - -sub_DBAF proc far - -var_2 = word ptr -2 -arg_0 = dword ptr 6 - - enter 2, 0 - mov _flag_grp_colorkey, 1 - mov _flag_palette_show, 0 - pushd [bp+arg_0] - call sub_DAEC - add sp, 4 - mov [bp+var_2], ax - mov _flag_palette_show, 1 - mov _flag_grp_colorkey, 0 - leave - retf -sub_DBAF endp + extern _grp_put_palette_show:proc + extern _grp_put:proc + extern _grp_put_colorkey:proc op_09_TEXT ends ; =========================================================================== @@ -3736,8 +3471,7 @@ include th01/formats/grp_palette[bss].asm dd ? dd ? include th01/formats/grz[bss].asm -; void (*font)(void) -font dd ? +include th01/formats/grp_buf[bss].asm include libs/master.lib/pal[bss].asm include libs/master.lib/fil[bss].asm include libs/master.lib/keystart[bss].asm diff --git a/th01_reiiden.asm b/th01_reiiden.asm index ebb335f9..80036c93 100644 --- a/th01_reiiden.asm +++ b/th01_reiiden.asm @@ -35,7 +35,6 @@ include th01/th01.inc extern LXMUL@:proc extern SCOPY@:proc extern __control87:proc - extern __fgetc:proc extern __lrotl:proc extern __lrotr:proc extern __mbcjmstojis:proc @@ -1207,9 +1206,7 @@ loc_BD43: add sp, 8 or ax, ax jz short loc_BD75 - pushd [bp+s1] - call sub_10BAE - add sp, 4 + call _grp_put_palette_show c, large [bp+s1] loc_BD75: push ds @@ -6227,302 +6224,11 @@ loc_10A97: retf sub_109B2 endp - -; =============== S U B R O U T I N E ======================================= - -; Attributes: bp-based frame - -sub_10AA5 proc far - -arg_0 = dword ptr 6 - - push bp - mov bp, sp - pushd [bp+arg_0] - call file_ropen - or ax, ax - jnz short loc_10ABA - mov ax, 1 - pop bp - retf -; --------------------------------------------------------------------------- - -loc_10ABA: - call file_seek pascal, large 18, 0 - call file_read pascal, ds, offset _grp_palette, size palette_t - call _z_palette_set_all_show c, offset _grp_palette, ds - call file_close - xor ax, ax - pop bp - retf -sub_10AA5 endp - - -; =============== S U B R O U T I N E ======================================= - -; Attributes: bp-based frame - -sub_10AE4 proc far - -arg_0 = dword ptr 6 - - push bp - mov bp, sp - pushd [bp+arg_0] - call file_ropen - or ax, ax - jnz short loc_10AF9 - mov ax, 1 - pop bp - retf -; --------------------------------------------------------------------------- - -loc_10AF9: - pushd 12h - push 0 - call file_seek - push ds - push offset _grp_palette - push 30h ; '0' - call file_read - call file_close - xor ax, ax - pop bp - retf -sub_10AE4 endp - - -; =============== S U B R O U T I N E ======================================= - -; Attributes: bp-based frame - -sub_10B17 proc far - -stream = dword ptr 6 - - push bp - mov bp, sp - push si - push di - les bx, [bp+stream] - dec word ptr es:[bx] - jl short loc_10B39 - mov ax, es:[bx+0Eh] - mov si, es:[bx+0Ch] - inc word ptr es:[bx+0Ch] - mov es, ax - mov al, es:[si] - mov ah, 0 - jmp short loc_10B45 -; --------------------------------------------------------------------------- - -loc_10B39: - pushd [bp+stream] ; stream - call __fgetc - add sp, 4 - -loc_10B45: - mov di, ax - les bx, [bp+stream] - dec word ptr es:[bx] - jl short loc_10B64 - mov ax, es:[bx+0Eh] - mov si, es:[bx+0Ch] - inc word ptr es:[bx+0Ch] - mov es, ax - mov al, es:[si] - mov ah, 0 - jmp short loc_10B70 -; --------------------------------------------------------------------------- - -loc_10B64: - pushd [bp+stream] ; stream - call __fgetc - add sp, 4 - -loc_10B70: - shl ax, 8 - add di, ax - mov ax, di - pop di - pop si - pop bp - retf -sub_10B17 endp - - -; =============== S U B R O U T I N E ======================================= - -; Attributes: bp-based frame - -sub_10B7B proc far - -arg_0 = dword ptr 6 - - push bp - mov bp, sp - xor dx, dx - jmp short loc_10BA7 -; --------------------------------------------------------------------------- - -loc_10B82: - xor cx, cx - jmp short loc_10BA1 -; --------------------------------------------------------------------------- - -loc_10B86: - mov ax, dx - imul ax, size rgb_t - les bx, [bp+arg_0] - add bx, ax - add bx, cx - mov al, es:[bx] - mov bx, dx - imul bx, size rgb_t - add bx, cx - mov byte ptr _grp_palette[bx], al - inc cx - -loc_10BA1: - cmp cx, size rgb_t - jl short loc_10B86 - inc dx - -loc_10BA7: - cmp dx, COLOR_COUNT - jl short loc_10B82 - pop bp - retf -sub_10B7B endp - - -; =============== S U B R O U T I N E ======================================= - -; Attributes: bp-based frame - -sub_10BAE proc far - -var_1 = byte ptr -1 -arg_0 = dword ptr 6 - - enter 2, 0 - push si - xor si, si - push 4000h - call @$bnwa$qui - pop cx - mov word ptr off_38E28+2, dx - mov word ptr off_38E28, ax - cmp _flag_palette_show, 1 - jnz short loc_10BCF - or si, 2 - -loc_10BCF: - cmp _flag_grp_colorkey, 1 - jnz short loc_10BD9 - mov si, 0F40h - -loc_10BD9: - cmp _flag_grp_put, 1 - jnz short loc_10C01 - push si - push 640000h - pushd 4000h - pushd [off_38E28] - pushd [bp+arg_0] - call _PiLoadL - add sp, 12h - mov [bp+var_1], al - -loc_10C01: - cmp _flag_palette_show, 1 - jnz short loc_10C12 - pushd [bp+arg_0] - call sub_10AA5 - jmp short loc_10C1A -; --------------------------------------------------------------------------- - -loc_10C12: - pushd [bp+arg_0] - call sub_10AE4 - -loc_10C1A: - add sp, 4 - pushd [off_38E28] ; font - call @$bdla$qnv - add sp, 4 - mov al, [bp+var_1] - cbw - pop si - leave - retf -sub_10BAE endp - - -; =============== S U B R O U T I N E ======================================= - -; Attributes: bp-based frame - -sub_10C31 proc far - -var_2 = word ptr -2 -arg_0 = dword ptr 6 - - enter 2, 0 - mov _flag_palette_show, 0 - pushd [bp+arg_0] - call sub_10BAE - add sp, 4 - mov [bp+var_2], ax - mov _flag_palette_show, 1 - leave - retf -sub_10C31 endp - - -; =============== S U B R O U T I N E ======================================= - -; Attributes: bp-based frame - -sub_10C51 proc far - -var_2 = word ptr -2 -arg_0 = dword ptr 6 - - enter 2, 0 - mov _flag_grp_put, 0 - pushd [bp+arg_0] - call sub_10BAE - add sp, 4 - mov [bp+var_2], ax - mov _flag_grp_put, 1 - leave - retf -sub_10C51 endp - - -; =============== S U B R O U T I N E ======================================= - -; Attributes: bp-based frame - -sub_10C71 proc far - -var_2 = word ptr -2 -arg_0 = dword ptr 6 - - enter 2, 0 - mov _flag_grp_colorkey, 1 - mov _flag_palette_show, 0 - pushd [bp+arg_0] - call sub_10BAE - add sp, 4 - mov [bp+var_2], ax - mov _flag_palette_show, 1 - mov _flag_grp_colorkey, 0 - leave - retf -sub_10C71 endp - + extern _grp_palette_load_show_sane:proc + extern _grp_palette_load_show:proc + extern _grp_put_palette_show:proc + extern _grp_put:proc + extern _grp_put_colorkey:proc extern _grx_put:proc extern _grx_free:proc extern _grz_load_single:proc @@ -9095,9 +8801,7 @@ sub_12F62 proc near mov bp, sp push 1 call _graph_accesspage_func - push ds - push offset aClear3_grp ; "CLEAR3.grp" - call sub_10C31 + call _grp_put stdcall, offset aClear3_grp, ds ; "CLEAR3.grp" push ds push offset aNumb_ptn ; "numb.ptn" push 7 @@ -12096,16 +11800,12 @@ arg_6 = dword ptr 0Ch pop cx cmp di, 1Eh jge short loc_148F0 - push ds - push offset aGame_o_grp ; "game_o.grp" - call sub_10BAE + call _grp_put_palette_show stdcall, offset aGame_o_grp, ds ; "game_o.grp" jmp short loc_148F9 ; --------------------------------------------------------------------------- loc_148F0: - push ds - push offset aEndm_a_grp ; "endm_a.grp" - call sub_10C31 + call _grp_put stdcall, offset aEndm_a_grp, ds ; "endm_a.grp" loc_148F9: add sp, 4 @@ -27789,8 +27489,7 @@ include th01/formats/grp_palette[bss].asm dd ? dd ? include th01/formats/grz[bss].asm -; void (*off_38E28)(void) -off_38E28 dd ? +include th01/formats/grp_buf[bss].asm include libs/master.lib/pal[bss].asm include libs/master.lib/fil[bss].asm include libs/master.lib/keystart[bss].asm diff --git a/th01_reiiden_2.inc b/th01_reiiden_2.inc index 23825c1e..0488cd4c 100644 --- a/th01_reiiden_2.inc +++ b/th01_reiiden_2.inc @@ -409,10 +409,7 @@ sub_1B383 proc far mov bp, sp push si push di - push ds - push offset aBoss2_grp_0 ; "boss2.grp" - call sub_10C51 - add sp, 4 + call _grp_palette_load_show c, offset aBoss2_grp_0, ds ; "boss2.grp" call sub_232A4 mov word_3984E, 0 mov word_39880, 0 @@ -5026,9 +5023,7 @@ sub_1E33A proc far push offset point_3985C call sub_1568F mov word_39886, 0 - push ds - push offset aBoss3_grp_0 ; "boss3.grp" - call sub_10C51 + call _grp_palette_load_show stdcall, offset aBoss3_grp_0, ds ; "boss3.grp" add sp, 18h xor si, si jmp short loc_1E3A2 @@ -13087,9 +13082,7 @@ sub_22694 proc far push offset point_3988E call sub_1568F mov word_398B8, 0 - push ds - push offset aBoss1_grp_0 ; "boss1.grp" - call sub_10AA5 + call _grp_palette_load_show_sane stdcall, offset aBoss1_grp_0, ds ; "boss1.grp" add sp, 22h xor si, si jmp short loc_22717 @@ -23739,14 +23732,10 @@ sub_2869E proc far push si mov byte_360CC, 1 call text_fillca pascal, (' ' shl 16) + TX_BLACK + TX_REVERSE - push ds - push offset aBoss6_l_grp ; "boss6_l.grp" - call sub_10BAE + call _grp_put_palette_show stdcall, offset aBoss6_l_grp, ds ; "boss6_l.grp" push 1 call _graph_accesspage_func - push ds - push offset aBoss6_h_grp ; "boss6_h.grp" - call sub_10BAE + call _grp_put_palette_show stdcall, offset aBoss6_h_grp, ds ; "boss6_h.grp" push 0 call _graph_accesspage_func push 4 @@ -23782,8 +23771,7 @@ loc_2871C: call sub_11738 push 1 call _graph_accesspage_func - pushd [off_35DAB] - call sub_10BAE + call _grp_put_palette_show stdcall, large [off_35DAB] push 0 call _graph_accesspage_func push 28h ; '(' @@ -26271,8 +26259,7 @@ loc_29D0E: call _graph_accesspage_func mov bx, [bp+arg_0] shl bx, 2 - pushd dword ptr [bx+140Bh] - call sub_10BAE + call _grp_put_palette_show stdcall, large off_35DAB[bx] call _graph_copy_page_back_to_front push ds push offset _z_Palettes @@ -30716,20 +30703,14 @@ loc_2C8AE: push 1 call _graph_accesspage_func pop cx - push ds - push offset aBoss6_grp ; "boss6.grp" - call sub_10BAE - add sp, 4 + call _grp_put_palette_show c, offset aBoss6_grp, ds ; "boss6.grp" call _z_palette_set_show c, large (0 shl 16) or 0Fh, large (0 shl 16) or 0 call sub_232A4 call _graph_copy_page_back_to_front push 1 call _graph_accesspage_func pop cx - push ds - push offset aBoss6_a5_grp ; "boss6_a5.grp" - call sub_10C31 - add sp, 4 + call _grp_put c, offset aBoss6_a5_grp, ds ; "boss6_a5.grp" push 0 call _graph_accesspage_func @@ -30809,10 +30790,7 @@ loc_2C9DA: call _mdrv2_bgm_load add sp, 4 call _mdrv2_bgm_play - push ds - push offset aBoss6_a6_grp ; "boss6_a6.grp" - call sub_10BAE - add sp, 4 + call _grp_put_palette_show c, offset aBoss6_a6_grp, ds ; "boss6_a6.grp" call _z_palette_set_show c, large (0 shl 16) or 6, large (0 shl 16) or 0 call _graph_copy_page_back_to_front mov byte_34A49, 1 @@ -31077,10 +31055,7 @@ loc_2CC9E: push 1 call _graph_accesspage_func pop cx - push ds - push offset aBoss6_a6_grp ; "boss6_a6.grp" - call sub_10BAE - add sp, 4 + call _grp_put_palette_show c, offset aBoss6_a6_grp, ds ; "boss6_a6.grp" call _z_palette_set_show c, large (0 shl 16) or 6, large (0 shl 16) or 0 call sub_232A4 call _graph_copy_page_back_to_front @@ -31367,9 +31342,7 @@ var_2 = word ptr -2 push di mov byte_360CC, 1 call text_fillca pascal, (' ' shl 16) + TX_BLACK + TX_REVERSE - push ds - push offset aBoss7_d1_grp ; "boss7_d1.grp" - call sub_10BAE + call _grp_put_palette_show stdcall, offset aBoss7_d1_grp, ds ; "boss7_d1.grp" push ds push offset _z_Palettes call sub_C433 @@ -31377,9 +31350,7 @@ var_2 = word ptr -2 call sub_2091E push 1 call _graph_accesspage_func - push ds - push offset aBoss8_a1_grp ; "boss8_a1.grp" - call sub_10BAE + call _grp_put_palette_show stdcall, offset aBoss8_a1_grp, ds ; "boss8_a1.grp" push 0 call _graph_accesspage_func push ds @@ -31639,18 +31610,10 @@ loc_2D16E: push (0Fh shl 16) or 0Fh push (0Fh shl 16) or 09h call _z_palette_set_show - push ds - push offset aBoss8_d1_grp ; "boss8_d1.grp" - call sub_10C71 - push ds - push offset aBoss8_d2_grp ; "boss8_d2.grp" - call sub_10C71 - push ds - push offset aBoss8_d3_grp ; "boss8_d3.grp" - call sub_10C71 - push ds - push offset aBoss8_d4_grp ; "boss8_d4.grp" - call sub_10C71 + call _grp_put_colorkey stdcall, offset aBoss8_d1_grp, ds ; "boss8_d1.grp" + call _grp_put_colorkey stdcall, offset aBoss8_d2_grp, ds ; "boss8_d2.grp" + call _grp_put_colorkey stdcall, offset aBoss8_d3_grp, ds ; "boss8_d3.grp" + call _grp_put_colorkey stdcall, offset aBoss8_d4_grp, ds ; "boss8_d4.grp" add sp, 1Ah xor di, di jmp short loc_2D1F0 @@ -35817,10 +35780,7 @@ loc_2FA5C: loc_2FA62: cmp di, 19h jl short loc_2FA4B - push ds - push offset aBoss7_d1_grp ; "boss7_d1.grp" - call sub_10BAE - add sp, 4 + call _grp_put_palette_show c, offset aBoss7_d1_grp, ds ; "boss7_d1.grp" xor si, si jmp short loc_2FA8C ; ---------------------------------------------------------------------------