Skip to content

Commit

Permalink
[Decompilation] [th01] .GRP / .GRZ / .PTN: Move all data to C land
Browse files Browse the repository at this point in the history
Cross-executable ZUN bloat 🤮

Part of P0213, funded by Ember2528 and GhostRiderCog.
  • Loading branch information
nmlgc committed Aug 11, 2022
1 parent ce9f1ed commit e79f6c6
Show file tree
Hide file tree
Showing 20 changed files with 125 additions and 143 deletions.
8 changes: 4 additions & 4 deletions Makefile.mak
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ th05:: $(TH05:\=bin\th05\)
.obj.com:
tlink /t /3 $**

bin\Pipeline\grzview.com: Pipeline\grzview.cpp th01\formats\grz.cpp
bin\Pipeline\grzview.com: Pipeline\grzview.cpp th01\formats\grz.cpp bin\th01\f_imgd.obj
$(CC) $(CFLAGS) -Z -DGAME=1 -mt -lt -nbin\Pipeline\ @&&|
$**
| masters.lib
Expand All @@ -43,17 +43,17 @@ bin\th01\zunsoft.com: th01\zunsoft.cpp
{th01}.cpp{bin\th01}.obj:
$(CC) $(CFLAGS) -ml -3 -Z -d -DGAME=1 -n$(@D) -c $**

bin\th01\op.exe: bin\piloadc.obj bin\th01\op.obj th01\op_01.cpp bin\th01\frmdelay.obj bin\th01\vsync.obj bin\th01\ztext.obj bin\th01\initexit.obj bin\th01\graph.obj bin\th01\ptn_0to1.obj bin\th01\vplanset.obj th01\op_07.cpp bin\th01\grppffx.obj bin\th01\ptn.obj th01\op_09.cpp bin\th01\grz.obj bin\th01\opm.obj bin\th01\resstuff.obj bin\th01\mdrv2.obj bin\th01\pf.obj
bin\th01\op.exe: bin\piloadc.obj bin\th01\op.obj th01\op_01.cpp bin\th01\frmdelay.obj bin\th01\vsync.obj bin\th01\ztext.obj bin\th01\initexit.obj bin\th01\graph.obj bin\th01\ptn_0to1.obj bin\th01\vplanset.obj th01\op_07.cpp bin\th01\grppffx.obj bin\th01\ptn.obj th01\op_09.cpp bin\th01\f_imgd.obj bin\th01\grz.obj bin\th01\opm.obj bin\th01\resstuff.obj bin\th01\mdrv2.obj bin\th01\pf.obj
$(CC) $(CFLAGS) $(LARGE_LFLAGS) -3 -Z -DGAME=1 -DBINARY='O' -nbin\th01\ -eOP.EXE @&&|
$**
|

bin\th01\reiiden.exe: bin\piloadc.obj bin\th01\reiiden.obj th01\main_010.cpp th01\main_011.cpp th01\main_012.cpp bin\th01\frmdelay.obj bin\th01\vsync.obj bin\th01\ztext.obj bin\th01\initexit.obj bin\th01\graph.obj bin\th01\ptn_0to1.obj bin\th01\vplanset.obj th01\main_07.cpp bin\th01\ptn.obj th01\main_08.cpp bin\th01\grz.obj bin\th01\reiidenm.obj th01\main_09.cpp th01\bullet_l.cpp th01\grpinv32.cpp bin\th01\resstuff.obj th01\scrollup.cpp th01\egcrows.cpp th01\pgtrans.cpp th01\2x_main.cpp th01\egcwave.cpp th01\grph1to0.cpp th01\main_14.cpp th01\main_15.cpp bin\th01\mdrv2.obj th01\main_17.cpp th01\main_18.cpp th01\main_19.cpp th01\main_20.cpp th01\main_21.cpp bin\th01\pf.obj th01\main_23.cpp th01\main_24.cpp th01\main_25.cpp th01\main_26.cpp th01\main_27.cpp th01\main_28.cpp th01\main_29.cpp th01\main_30.cpp th01\main_31.cpp th01\main_32.cpp th01\main_33.cpp th01\main_34.cpp th01\main_35.cpp th01\main_36.cpp th01\main_37.cpp th01\main_38.cpp
bin\th01\reiiden.exe: bin\piloadc.obj bin\th01\reiiden.obj th01\main_010.cpp th01\main_011.cpp th01\main_012.cpp bin\th01\frmdelay.obj bin\th01\vsync.obj bin\th01\ztext.obj bin\th01\initexit.obj bin\th01\graph.obj bin\th01\ptn_0to1.obj bin\th01\vplanset.obj th01\main_07.cpp bin\th01\ptn.obj th01\main_08.cpp bin\th01\f_imgd.obj bin\th01\grz.obj bin\th01\reiidenm.obj th01\main_09.cpp th01\bullet_l.cpp th01\grpinv32.cpp bin\th01\resstuff.obj th01\scrollup.cpp th01\egcrows.cpp th01\pgtrans.cpp th01\2x_main.cpp th01\egcwave.cpp th01\grph1to0.cpp th01\main_14.cpp th01\main_15.cpp bin\th01\mdrv2.obj th01\main_17.cpp th01\main_18.cpp th01\main_19.cpp th01\main_20.cpp th01\main_21.cpp bin\th01\pf.obj th01\main_23.cpp th01\main_24.cpp th01\main_25.cpp th01\main_26.cpp th01\main_27.cpp th01\main_28.cpp th01\main_29.cpp th01\main_30.cpp th01\main_31.cpp th01\main_32.cpp th01\main_33.cpp th01\main_34.cpp th01\main_35.cpp th01\main_36.cpp th01\main_37.cpp th01\main_38.cpp
$(CC) $(CFLAGS) $(LARGE_LFLAGS) -3 -Z -d -DGAME=1 -DBINARY='M' -nbin\th01\ -eREIIDEN.EXE @&&|
$**
|

bin\th01\fuuin.exe: bin\piloadc.obj bin\th01\fuuin.obj th01\fuuin_01.cpp th01\fuuin_02.cpp th01\fuuin_03.cpp th01\fuuin_04.cpp bin\th01\fuuin_2.obj bin\th01\vsync.obj bin\th01\ztext.obj bin\th01\initexit.obj bin\th01\graph.obj bin\th01\grppffx.obj th01\fuuin_10.cpp bin\th01\vplanset.obj th01\fuuin_11.cpp th01\2x_fuuin.cpp bin\th01\mdrv2.obj bin\th01\fuuinm.obj
bin\th01\fuuin.exe: bin\piloadc.obj bin\th01\fuuin.obj th01\fuuin_01.cpp th01\fuuin_02.cpp th01\fuuin_03.cpp th01\fuuin_04.cpp bin\th01\fuuin_2.obj bin\th01\vsync.obj bin\th01\ztext.obj bin\th01\initexit.obj bin\th01\graph.obj bin\th01\grppffx.obj th01\fuuin_10.cpp th01\f_imgd_f.cpp bin\th01\vplanset.obj th01\fuuin_11.cpp th01\2x_fuuin.cpp bin\th01\mdrv2.obj bin\th01\fuuinm.obj
$(CC) $(CFLAGS) $(LARGE_LFLAGS) -3 -Z -DGAME=1 -DBINARY='E' -nbin\th01\ -eFUUIN.EXE @&&|
$**
|
Expand Down
16 changes: 0 additions & 16 deletions Pipeline/grzview.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,22 +17,6 @@ extern "C" {
{
grcg_off();
}

// Temporary declarations for local GRZ data
// -----------------------------------------
// TODO: These will cause duplicate symbol errors once those are defined
// in th01/formats/grz.cpp; remove this section once that is the case.

// `const` would prevent them from being exported?!
char HGRZ_MAGIC[4] = "HGRZ";
char HGRX_MAGIC[4] = "HGRX";

char planar_stream_id;
char grx_col;
uint8_t* rle_streams[GRX_COUNT];
dots8_t* planar_streams[GRX_COUNT][PLANAR_STREAM_PER_GRX_COUNT];
unsigned char planar_stream_count[GRX_COUNT];
// -----------------------------------------
}

void z_palette_set_all_show(const Palette4& pal)
Expand Down
2 changes: 1 addition & 1 deletion planar.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,8 @@ extern dots8_t far *VRAM_PLANE[PLANE_COUNT];
// And no, expressing these as a struct won't generate the same ASM.
// Been there, tried that.
extern dots8_t far *VRAM_PLANE_B;
extern dots8_t far *VRAM_PLANE_G;
extern dots8_t far *VRAM_PLANE_R;
extern dots8_t far *VRAM_PLANE_G;
extern dots8_t far *VRAM_PLANE_E;

// Byte offset of an 8-pixel-aligned X/Y position on a VRAM bitplane,
Expand Down
1 change: 1 addition & 0 deletions th01/f_imgd.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
#include "th01/formats/img_data.cpp"
1 change: 1 addition & 0 deletions th01/f_imgd_f.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
#include "th01/formats/img_data.cpp"
8 changes: 4 additions & 4 deletions th01/formats/grp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,9 @@ extern "C" {
// *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 bool flag_grp_colorkey; // = false
extern bool16 flag_palette_show;
extern bool16 flag_grp_put;
extern bool flag_grp_colorkey;

int grp_palette_load_show_sane(const char *fn)
{
Expand Down Expand Up @@ -66,6 +65,7 @@ void grp_palette_set_all(const Palette4& pal)

int grp_put_palette_show(const char *fn)
{
extern int8_t* grp_buf;
int option = 0;
char ret;

Expand Down
2 changes: 0 additions & 2 deletions th01/formats/grp_buf[bss].asm

This file was deleted.

2 changes: 0 additions & 2 deletions th01/formats/grp_palette[bss].asm

This file was deleted.

14 changes: 0 additions & 14 deletions th01/formats/grp_ptn[data].asm

This file was deleted.

33 changes: 5 additions & 28 deletions th01/formats/grz.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,34 +11,11 @@ extern "C" {
#include "th01/hardware/graph.h"
#include "th01/formats/grz.h"

extern const char HGRZ_MAGIC[4];
extern const char HGRX_MAGIC[4];

extern char planar_stream_id;
extern char grx_col;
static int8_t planar_stream_id = 0;
static int8_t grx_col = 0;
extern uint8_t* rle_streams[GRX_COUNT];
// Actually a Planar<dots8_t*>, but used like a dots8_t* everywhere.
extern dots8_t* planar_streams[GRX_COUNT][PLANAR_STREAM_PER_GRX_COUNT];
extern unsigned char planar_stream_count[GRX_COUNT];

struct grz_header_t {
char magic[sizeof(HGRZ_MAGIC)];
uint8_t image_count;
int8_t padding[3];
int32_t offsets[GRZ_IMAGE_COUNT];
int32_t total_size; // including this header
int8_t unknown[20];
};

struct grx_header_t {
char magic[sizeof(HGRX_MAGIC)];
uint8_t planar_stream_count;
int8_t unused_1[3];
uint16_t rle_stream_size;
uint16_t planar_stream_size;
int8_t unused_2[4];
Palette4 palette;
};
extern uint8_t planar_stream_count[GRX_COUNT];

void grx_put_stream(unsigned int slot, int planar_stream)
{
Expand Down Expand Up @@ -119,7 +96,7 @@ void grx_put(unsigned int slot)

#define grx_header_read(grx, slot) \
file_read(&grx, sizeof(grx)); \
fail_if(memcmp(grx.magic, HGRX_MAGIC, sizeof(HGRX_MAGIC))); \
fail_if(memcmp(grx.magic, HGRX_MAGIC, (sizeof(HGRX_MAGIC) - 1))); \
fail_if(grx.planar_stream_count < 1); \
planar_stream_count[slot] = grx.planar_stream_count; \

Expand Down Expand Up @@ -220,7 +197,7 @@ int grz_load_single(unsigned int slot, const char *fn, int n)
headers_t* h = new headers_t[1];

file_read(&h->grz, sizeof(h->grz));
fail_if(memcmp(h->grz.magic, HGRZ_MAGIC, sizeof(HGRZ_MAGIC)));
fail_if(memcmp(h->grz.magic, HGRZ_MAGIC, (sizeof(HGRZ_MAGIC) - 1)));

uint8_t image_count = h->grz.image_count;
if(image_count > n) {
Expand Down
36 changes: 29 additions & 7 deletions th01/formats/grz.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,35 @@
/// format) to be used with the same RLE stream, or the RLE stream to be used
/// on its own for a monochrome byte-aligned pattern.

// Static arrays
#define GRX_COUNT 16
#define PLANAR_STREAM_PER_GRX_COUNT 16

// File format limit
#define GRZ_IMAGE_COUNT 16

#define HGRZ_MAGIC "HGRZ"
#define HGRX_MAGIC "HGRX"

struct grz_header_t {
char magic[sizeof(HGRZ_MAGIC) - 1];
uint8_t image_count;
int8_t padding[3];
int32_t offsets[GRZ_IMAGE_COUNT];
int32_t total_size; // including this header
int8_t unknown[20];
};

struct grx_header_t {
char magic[sizeof(HGRX_MAGIC) - 1];
uint8_t planar_stream_count;
int8_t unused_1[3];
uint16_t rle_stream_size;
uint16_t planar_stream_size;
int8_t unused_2[4];
Palette4 palette;
};

// RLE stream format
enum grx_rle_t {
// Puts the next byte from the pixel data source. No parameters.
Expand All @@ -16,13 +45,6 @@ enum grx_rle_t {
GC_RUN = 1,
};

// Static arrays
#define GRX_COUNT 16
#define PLANAR_STREAM_PER_GRX_COUNT 16

// File format limit
#define GRZ_IMAGE_COUNT 16

// Loading
// -------
// All of these load the file with the given [fn] into the given [slot],
Expand Down
5 changes: 0 additions & 5 deletions th01/formats/grz[data].asm

This file was deleted.

70 changes: 70 additions & 0 deletions th01/formats/img_data.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
// ZUN bloat: This file should not exist, as it causes the data for the .PTN
// and .GRZ formats to be needlessly linked into OP.EXE and FUUIN.EXE. Just
// declare the data local to the respective translation unit.

#include "platform.h"
#include "pc98.h"
#include "planar.h"
#include "th01/formats/grz.h"
#include "th01/formats/ptn.hpp"

#if (BINARY != 'E')
// TODO: Move into vplanset.cpp once we're close to done with TH02-TH04.
dots8_t far *VRAM_PLANE_B;
dots8_t far *VRAM_PLANE_R;
dots8_t far *VRAM_PLANE_G;
dots8_t far *VRAM_PLANE_E;
#endif


static int8_t unused[80]; // ZUN bloat

// .GRP and .PTN
// -------------

bool16 flag_palette_show = true;
// -------------

// .GRP
// ----

Palette4 grp_palette;
bool16 flag_grp_put = true;
static bool flag_grp_unused[3] = { false }; // ZUN bloat
// ----

// .PTN
// ----

ptn_t* ptn_images[PTN_SLOT_COUNT];
int8_t ptn_image_count[PTN_SLOT_COUNT] = { 0 };
// ----

// .GRZ
// ----

uint8_t* rle_streams[GRX_COUNT];

// Actually a Planar<dots8_t*>, but used like a dots8_t* everywhere.
dots8_t* planar_streams[GRX_COUNT][PLANAR_STREAM_PER_GRX_COUNT];

uint8_t planar_stream_count[GRX_COUNT];
// ----

// .GRP again
// ----------

#if (BINARY == 'E')
int grp_palette_tone = 100;
#endif
bool flag_grp_colorkey = false;
int8_t* grp_buf;
// ----------

#if (BINARY == 'E')
// TODO: Move into vplanset.cpp once we're close to done with TH02-TH04.
dots8_t far *VRAM_PLANE_B;
dots8_t far *VRAM_PLANE_R;
dots8_t far *VRAM_PLANE_G;
dots8_t far *VRAM_PLANE_E;
#endif
5 changes: 3 additions & 2 deletions th01/formats/ptn.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@ extern "C" {
#include "th01/formats/pf.hpp"
}

extern int flag_palette_show;

// On-disk .PTN slot file header
// -----------------------------
#define PTN_MAGIC "HPTN"
Expand All @@ -26,6 +24,9 @@ typedef struct {
} ptn_header_t;
// -----------------------------

extern int8_t ptn_image_count[PTN_SLOT_COUNT];
extern bool16 flag_palette_show;

ptn_error_t ptn_load_palette_show(main_ptn_slot_t slot, const char *fn)
{
union {
Expand Down
1 change: 0 additions & 1 deletion th01/formats/ptn.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ struct ptn_t : public ptn_file_image_t {
};

extern ptn_t* ptn_images[PTN_SLOT_COUNT];
extern int8_t ptn_image_count[PTN_SLOT_COUNT];

// MODDERS: Make [id] unsigned
static inline ptn_t* ptn_with_id(int id) {
Expand Down
35 changes: 0 additions & 35 deletions th01/formats/ptn_grz[bss].asm

This file was deleted.

5 changes: 0 additions & 5 deletions th01_fuuin.asm
Original file line number Diff line number Diff line change
Expand Up @@ -289,11 +289,6 @@ include th01/hardware/vsync[bss].asm
db 256 dup(?)
include th01/core/initexit[bss].asm
include th01/hardware/graph[bss].asm
db 80 dup(?)
include th01/formats/grp_palette[bss].asm
db 1136 dup(?)
include th01/formats/grp_buf[bss].asm
include th01/hardware/vram_planes[bss].asm

; libs/master.lib/pal[bss].asm
extern Palettes:rgb_t:COLOR_COUNT
Expand Down
3 changes: 0 additions & 3 deletions th01_fuuin_data.asm
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
.386
.model use16 large

BINARY = 'E'

include pc98.inc

.data
Expand All @@ -15,6 +13,5 @@ include th01/core/initexit[data].asm
include th01/hardware/palette[data].asm
include th01/hardware/graph_r[data].asm
include th01/hardware/respal[data].asm
include th01/formats/grp_ptn[data].asm

end
Loading

0 comments on commit e79f6c6

Please sign in to comment.