From b1cf7ee021540732ab96b421124ecfa0d46b47e5 Mon Sep 17 00:00:00 2001 From: nmlgc Date: Sun, 18 Apr 2021 18:36:29 +0200 Subject: [PATCH] [Maintenance] [th02] .MPN: Update existing decompilations to current standards Part of P0138, funded by [Anonymous] and Blue Bolt. --- Makefile.mak | 2 +- th02/formats/mpn.hpp | 36 ++++++++++++++++--------- th02/formats/{mpn_i.cpp => mpn_l_i.cpp} | 18 ++++++++----- th02/main02_1.cpp | 9 ++++--- th02/mpn_l_i.cpp | 1 + th02_main.asm | 20 ++++++-------- 6 files changed, 51 insertions(+), 35 deletions(-) rename th02/formats/{mpn_i.cpp => mpn_l_i.cpp} (67%) create mode 100644 th02/mpn_l_i.cpp diff --git a/Makefile.mak b/Makefile.mak index d57c9d06..04dfb7ff 100644 --- a/Makefile.mak +++ b/Makefile.mak @@ -85,7 +85,7 @@ bin\th02\op.exe: th02\op_01.cpp bin\exit_dos.obj bin\th02\zunerror.obj bin\th02\ $** | -bin\th02\main.exe: bin\th02\main.obj 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\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_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 +bin\th02\main.exe: bin\th02\main.obj 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\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 $(CC) $(CFLAGS) $(LARGE_LFLAGS) -Z -DGAME=2 -nbin\th02\ -eMAIN.EXE @&&| $** | diff --git a/th02/formats/mpn.hpp b/th02/formats/mpn.hpp index dfee8cf7..21cb8d32 100644 --- a/th02/formats/mpn.hpp +++ b/th02/formats/mpn.hpp @@ -1,20 +1,30 @@ +/// Uncompressed 16-color 16×16 image format with palette, used for map tiles +/// ------------------------------------------------------------------------- + +typedef dot_rect_t(TILE_W, TILE_H) mpn_plane_t; +typedef Planar mpn_image_t; + typedef struct { char magic[4]; // = "MPTN" - char count; - char unused; + uint8_t count; + int8_t unused; } mpn_header_t; -#define MPN_SIZE (8 * 16) +#if (GAME == 2) + extern uint8_t mpn_count; + extern mpn_image_t *mpn_images; + extern Palette8 mpn_palette; -extern unsigned char mpn_count; -extern int *mpn_buffer; -extern Palette8 mpn_palette; + // Reads the .MPN file with the given [fn] into the newly reallocated + // [mpn_images], and sets [mpn_count] and [mpn_palette] accordingly. + // Returns 0 if allocation succeeded and the tiles were read into + // [mpn_images], -1 otherwise. + int pascal mpn_load(const char *fn); -// Reads the .MPN file with the given [fn] into the newly reallocated -// [mpn_buffer], and sets [mpn_count] and [mpn_palette] accordingly. -int pascal mpn_load(const char *fn); + // Like mpn_load(), but sets the hardware palette to the one in [fn]'s + // header. + int pascal mpn_load_palette_show(const char *fn); -// Like mpn_load(), but sets the hardware palette to the one in [fn]'s header. -int pascal mpn_load_palette_show(const char *fn); - -void mpn_free(void); + void mpn_free(void); +#endif +/// ------------------------------------------------------------------------- diff --git a/th02/formats/mpn_i.cpp b/th02/formats/mpn_l_i.cpp similarity index 67% rename from th02/formats/mpn_i.cpp rename to th02/formats/mpn_l_i.cpp index ae4dc263..9259f513 100644 --- a/th02/formats/mpn_i.cpp +++ b/th02/formats/mpn_l_i.cpp @@ -4,7 +4,10 @@ extern "C" { #include #include "platform.h" #include "pc98.h" +#include "planar.h" #include "master.hpp" +#include "th02/main/playfld.h" +#include "th02/main/tile.hpp" #include "th02/formats/mpn.hpp" void mpn_palette_show(void) @@ -21,21 +24,24 @@ int pascal mpn_load_palette_show(const char *fn) file_ropen(fn); file_read(&header, sizeof(header)); mpn_count = header.count; + file_read(&mpn_palette, sizeof(mpn_palette)); if(mpn_show_palette_on_load) { mpn_palette_show(); } - if(mpn_buffer) { + + if(mpn_images) { mpn_free(); } - mpn_buffer = reinterpret_cast( - hmem_allocbyte((mpn_count + 1) * MPN_SIZE) - ); - if(!mpn_buffer) { + mpn_images = reinterpret_cast(hmem_allocbyte( + (mpn_count + 1) * sizeof(mpn_image_t) + )); + if(!mpn_images) { file_close(); return -1; } - file_read(mpn_buffer, (mpn_count + 1) * MPN_SIZE); + file_read(mpn_images, (mpn_count + 1) * sizeof(mpn_image_t)); + file_close(); return 0; } diff --git a/th02/main02_1.cpp b/th02/main02_1.cpp index dd1ad154..01c050be 100644 --- a/th02/main02_1.cpp +++ b/th02/main02_1.cpp @@ -9,7 +9,10 @@ extern "C" { #include #include "platform.h" #include "pc98.h" +#include "planar.h" #include "master.hpp" +#include "th02/main/playfld.h" +#include "th02/main/tile.hpp" #include "th02/formats/mpn.hpp" int pascal mpn_load(const char *fn) @@ -25,10 +28,10 @@ int pascal mpn_load(const char *fn) void mpn_free(void) { - if(mpn_buffer) { - HMem::free(mpn_buffer); + if(mpn_images) { + HMem::free(mpn_images); } - mpn_buffer = 0; + mpn_images = NULL; } } diff --git a/th02/mpn_l_i.cpp b/th02/mpn_l_i.cpp new file mode 100644 index 00000000..2c77fff8 --- /dev/null +++ b/th02/mpn_l_i.cpp @@ -0,0 +1 @@ +#include "th02/formats/mpn_l_i.cpp" diff --git a/th02_main.asm b/th02_main.asm index 3f6f9766..cb9be4d7 100644 --- a/th02_main.asm +++ b/th02_main.asm @@ -162,8 +162,8 @@ arg_4 = word ptr 0Ah mov di, ax mov ax, [bp+arg_0] shl ax, 7 - mov dx, word ptr _mpn_buffer+2 - mov bx, word ptr _mpn_buffer + mov dx, word ptr _mpn_images+2 + mov bx, word ptr _mpn_images add bx, ax mov ds, dx mov si, bx @@ -2249,7 +2249,7 @@ loc_B4D7: lea ax, [bp+var_C] push ax call mpn_load - push 30h ; '0' ; n + push size palette_t ; n push ds push offset _mpn_palette ; src push ds @@ -2398,9 +2398,7 @@ loc_B8B5: graph_accesspage 0 call sub_4782 call _mpn_free - push ds - push offset aMiko_k_mpn ; "miko_k.mpn" - call mpn_load + call mpn_load pascal, ds, offset aMiko_k_mpn ; "miko_k.mpn" les bx, _resident cmp es:[bx+mikoconfig_t.demo_num], 0 jnz short loc_B922 @@ -33652,9 +33650,8 @@ include th02/formats/pfopen[data].asm public _snd_active _snd_active db 0 db 0 -public _mpn_show_palette_on_load +public _mpn_show_palette_on_load, _mpn_count _mpn_show_palette_on_load db 1 -public _mpn_count _mpn_count db 0 public _pf_fn _pf_fn db '“Œ•û••–‚.˜^',0 @@ -34651,10 +34648,9 @@ include libs/master.lib/pfint21[bss].asm include th02/hardware/input_sense[bss].asm include th02/snd/snd[bss].asm include th02/snd/load[bss].asm -public _mpn_buffer -_mpn_buffer dd ? -public _mpn_palette -_mpn_palette db 16 * 3 dup(?) +public _mpn_images, _mpn_palette +_mpn_images dd ? +_mpn_palette palette_t word_1FFF0 dw ? word_1FFF2 dw ? word_1FFF4 dw ?