mirror of https://github.com/nmlgc/ReC98.git
[Maintenance] Add a template for stupid bytewise access to logical structures
For the cases where ZUN's code would always be cleaner without it. Part of P0157, funded by Yanga.
This commit is contained in:
parent
af2c0e14a4
commit
ab4c1a9bad
10
decomp.hpp
10
decomp.hpp
|
@ -1,6 +1,6 @@
|
|||
/* ReC98
|
||||
* -----
|
||||
* Macros and inline functions to help decompiling the seemingly impossible
|
||||
* Declarations to help decompiling the seemingly impossible
|
||||
*/
|
||||
|
||||
// Flag comparisons
|
||||
|
@ -29,6 +29,14 @@
|
|||
|
||||
} // extern "C" was a mistake
|
||||
|
||||
// Should just be unwrapped wherever it appears. Code that directly uses T
|
||||
// would be much cleaner.
|
||||
template <class T> union StupidBytewiseWrapperAround {
|
||||
T t;
|
||||
int8_t byte[sizeof(T)];
|
||||
uint8_t ubyte[sizeof(T)];
|
||||
};
|
||||
|
||||
// poke() versions that actually inline with pseudoregisters
|
||||
// ---------------------------------------------------------
|
||||
#define pokew(sgm, off, val) { *(uint16_t far *)(MK_FP(sgm, off)) = val; }
|
||||
|
|
|
@ -65,14 +65,11 @@ typedef enum {
|
|||
OT_BAR_RIGHT = 21,
|
||||
} obstacle_type_t;
|
||||
|
||||
union stagedat_stage_t {
|
||||
struct {
|
||||
// Stores the cards of [CARDS_PER_BYTE] horizontal tiles in the lower
|
||||
// [CARDS_PER_BYTE] bits. The other bits are unused.
|
||||
uint8_t cards[STAGEOBJS_Y][STAGEOBJS_X / CARDS_PER_BYTE];
|
||||
struct stagedat_stage_t {
|
||||
// Stores the cards of [CARDS_PER_BYTE] horizontal tiles in the lower
|
||||
// [CARDS_PER_BYTE] bits. The other bits are unused.
|
||||
uint8_t cards[STAGEOBJS_Y][STAGEOBJS_X / CARDS_PER_BYTE];
|
||||
|
||||
int8_t obstacles[STAGEOBJS_Y][STAGEOBJS_X]; // obstacle_type_t
|
||||
} type;
|
||||
int8_t byte[sizeof((stagedat_stage_t*)0)->type];
|
||||
int8_t obstacles[STAGEOBJS_Y][STAGEOBJS_X]; // obstacle_type_t
|
||||
};
|
||||
/// --------------------------------------------------------------------------
|
||||
|
|
|
@ -11,6 +11,7 @@ extern "C" {
|
|||
#include <string.h>
|
||||
#include "ReC98.h"
|
||||
#include "x86real.h"
|
||||
#include "decomp.hpp"
|
||||
#include "pc98kbd.h"
|
||||
#include "twobyte.h"
|
||||
#include "master.hpp"
|
||||
|
|
|
@ -13,13 +13,6 @@
|
|||
|
||||
#define SCOREDAT_NAME_KEY 0x9C
|
||||
|
||||
// Exclusively used to store full-width Shift-JIS code points.
|
||||
// Not null-terminated.
|
||||
union scoredat_name_t {
|
||||
int16_t codepoint[SCOREDAT_NAME_KANJI];
|
||||
int8_t byte[SCOREDAT_NAME_BYTES];
|
||||
};
|
||||
|
||||
// Encodes or decodes a single name byte.
|
||||
int8_t scoredat_name_byte_encode(int8_t byte);
|
||||
int8_t scoredat_name_byte_decode(int8_t byte);
|
||||
|
@ -29,7 +22,11 @@ int8_t scoredat_name_byte_decode(int8_t byte);
|
|||
struct scoredat_t {
|
||||
// Not null-terminated!
|
||||
char magic[sizeof(SCOREDAT_MAGIC) - 1];
|
||||
scoredat_name_t name[SCOREDAT_PLACES];
|
||||
|
||||
// Exclusively used to store full-width Shift-JIS code points.
|
||||
// Not null-terminated.
|
||||
int16_t name[SCOREDAT_PLACES][SCOREDAT_NAME_KANJI];
|
||||
|
||||
uint32_t points[SCOREDAT_PLACES];
|
||||
int16_t stage[SCOREDAT_PLACES];
|
||||
twobyte_t route[SCOREDAT_PLACES];
|
||||
|
@ -50,10 +47,9 @@ inline int8_t& scoredat_route_byte(int place, int byte)
|
|||
}
|
||||
|
||||
// Null-terminated version of scoredat_name_t, used internally.
|
||||
union scoredat_name_z_t {
|
||||
typedef StupidBytewiseWrapperAround<struct {
|
||||
int16_t codepoint[SCOREDAT_NAME_KANJI + 1];
|
||||
int8_t byte[SCOREDAT_NAME_BYTES + 1];
|
||||
};
|
||||
}> scoredat_name_z_t;
|
||||
|
||||
// Loads the score file for the current [rank], recreating it if necessary.
|
||||
// Returns 0 on success, 1 on failure.
|
||||
|
|
|
@ -3,6 +3,7 @@ extern "C" {
|
|||
#include <malloc.h>
|
||||
#include "platform.h"
|
||||
#include "pc98.h"
|
||||
#include "decomp.hpp"
|
||||
#include "planar.h"
|
||||
#include "master.hpp"
|
||||
#include "th01/common.h"
|
||||
|
@ -26,7 +27,7 @@ static const int TURRET_SLOW_INTERVAL = 200;
|
|||
// -------
|
||||
|
||||
struct stage_t {
|
||||
stagedat_stage_t dat;
|
||||
StupidBytewiseWrapperAround<stagedat_stage_t> dat;
|
||||
int8_t padding[5];
|
||||
};
|
||||
extern stage_t scene_stage[STAGES_PER_SCENE];
|
||||
|
@ -36,19 +37,19 @@ extern stage_t scene_stage[STAGES_PER_SCENE];
|
|||
// -----------------------------------------
|
||||
|
||||
inline int cards_begin() {
|
||||
return offsetof(stagedat_stage_t, type.cards);
|
||||
return offsetof(stagedat_stage_t, cards);
|
||||
}
|
||||
|
||||
inline int cards_end() {
|
||||
return (cards_begin() + sizeof(((stagedat_stage_t*)0)->type.cards));
|
||||
return (cards_begin() + sizeof(((stagedat_stage_t*)0)->cards));
|
||||
}
|
||||
|
||||
inline int obstacles_begin() {
|
||||
return offsetof(stagedat_stage_t, type.obstacles);
|
||||
return offsetof(stagedat_stage_t, obstacles);
|
||||
}
|
||||
|
||||
inline int obstacles_end() {
|
||||
return (obstacles_begin() + sizeof(((stagedat_stage_t*)0)->type.obstacles));
|
||||
return (obstacles_begin() + sizeof(((stagedat_stage_t*)0)->obstacles));
|
||||
}
|
||||
// -----------------------------------------
|
||||
|
||||
|
|
|
@ -11,6 +11,7 @@ extern "C" {
|
|||
#include <string.h>
|
||||
#include "ReC98.h"
|
||||
#include "x86real.h"
|
||||
#include "decomp.hpp"
|
||||
#include "twobyte.h"
|
||||
#include "master.hpp"
|
||||
#include "th01/ranks.h"
|
||||
|
|
Loading…
Reference in New Issue