From 417ba80c0026f2c8d9b5f26e312d67501669691b Mon Sep 17 00:00:00 2001 From: nmlgc Date: Fri, 13 Dec 2019 19:17:02 +0100 Subject: [PATCH] [Decompilation] Add a separate segment type At least wherever Turbo C++ and master.lib want us to use a non-pointer, since both use uint16_t for segment values throughout their APIs instead of the more sensible void __seg*. Maybe, integer arithmetic on segment values was widely considered more important than dereferencing? --- platform.h | 6 ++++++ th01/mdrv2.c | 3 ++- th01/resstuff.c | 6 +++--- th02/maine_03.c | 2 +- th02/op_01.c | 2 +- th02/th02.h | 2 +- th02/zun_res1.c | 4 ++-- th04/ems.h | 2 +- th04/formats/bb_stage.c | 2 +- 9 files changed, 18 insertions(+), 11 deletions(-) diff --git a/platform.h b/platform.h index 82ae9369..3ca9f1fa 100644 --- a/platform.h +++ b/platform.h @@ -23,3 +23,9 @@ typedef unsigned long uint32_t; # error This code can currently only be compiled on Borland's 16-bit DOS compilers. Ideally, you'd only have to declare types for your compiler here though? #endif /// ---------- + +// Both Turbo C++ and master.lib use uint16_t for segment values throughout +// their APIs instead of the more sensible void __seg*. Maybe, integer +// arithmetic on segment values was widely considered more important than +// dereferencing? +typedef uint16_t seg_t; diff --git a/th01/mdrv2.c b/th01/mdrv2.c index 4d8e91ad..b7988b5b 100644 --- a/th01/mdrv2.c +++ b/th01/mdrv2.c @@ -8,6 +8,7 @@ #include #include #include +#include "platform.h" #define MDRV2 0xf2 #define MDRV2_CALL(func) { \ @@ -54,7 +55,7 @@ static void near pascal mdrv2_load(const char *fn, char func) if(mdrv2_have_board) { int handle = open(fn, O_BINARY | O_RDONLY); int length = filelength(handle); - int sgm; + seg_t sgm; int ofs; void far *block; diff --git a/th01/resstuff.c b/th01/resstuff.c index 7622f4f1..8bc888a1 100644 --- a/th01/resstuff.c +++ b/th01/resstuff.c @@ -14,7 +14,7 @@ void resident_stuff_set( char rank, char bgm_mode, char bombs, char start_lives_extra, long rand ) { - unsigned res = resdata_exist(res_id, RES_ID_STRLEN, RES_PARASIZE); + seg_t res = resdata_exist(res_id, RES_ID_STRLEN, RES_PARASIZE); if(!res) { res = resdata_create(res_id, RES_ID_STRLEN, RES_PARASIZE); reiidenconfig = MK_FP(res, 0); @@ -42,7 +42,7 @@ int resident_stuff_get( int *stage ) { - unsigned res = resdata_exist(res_id, RES_ID_STRLEN, RES_PARASIZE); + seg_t res = resdata_exist(res_id, RES_ID_STRLEN, RES_PARASIZE); if(res) { reiidenconfig = MK_FP(res, 0); *rank = reiidenconfig->rank; @@ -59,7 +59,7 @@ int resident_stuff_get( void resident_free(void) { - unsigned res = resdata_exist(res_id, RES_ID_STRLEN, RES_PARASIZE); + seg_t res = resdata_exist(res_id, RES_ID_STRLEN, RES_PARASIZE); if(res) { resdata_free(res); } diff --git a/th02/maine_03.c b/th02/maine_03.c index a2f7a7cf..96d8f3a9 100644 --- a/th02/maine_03.c +++ b/th02/maine_03.c @@ -20,7 +20,7 @@ int unused_6; int pascal cfg_load(void) { - int resident_sgm; + seg_t resident_sgm; file_ropen(CFG_FN); file_seek(offsetof(huuma_cfg_t, resident_sgm), 0); diff --git a/th02/op_01.c b/th02/op_01.c index fecf12ab..edb6611d 100644 --- a/th02/op_01.c +++ b/th02/op_01.c @@ -20,7 +20,7 @@ char snd_bgm_mode; static int unused_2; unsigned int idle_frames; unsigned char demo_num; -unsigned int mikoconfig_sgm; +void __seg *mikoconfig_sgm; putfunc_t near *putfunc; // No, we don't want to put these two into th02.h. Apparently, declaring diff --git a/th02/th02.h b/th02/th02.h index 7b9e110e..0d8ac3c6 100644 --- a/th02/th02.h +++ b/th02/th02.h @@ -215,7 +215,7 @@ typedef struct { typedef struct { huuma_options_t opts; - int resident_sgm; + void __seg *resident_sgm; int8_t debug; } huuma_cfg_t; #pragma option -a. diff --git a/th02/zun_res1.c b/th02/zun_res1.c index 6e9cba66..fcc6336d 100644 --- a/th02/zun_res1.c +++ b/th02/zun_res1.c @@ -13,7 +13,7 @@ char debug = 0; -void cfg_write(int mikoconfig_sgm) +void cfg_write(seg_t mikoconfig_sgm) { static const huuma_options_t opts_default = { RANK_NORMAL, SND_BGM_FM, 3, 2, 0 @@ -58,7 +58,7 @@ int main(int argc, const char **argv) static const char INITIALIZED[] = "それでは、よろしくお願いします\n\n"; - int sgm; + seg_t sgm; const char *res_id = MIKOConfig; int i; char far *mikoconfig; diff --git a/th04/ems.h b/th04/ems.h index eb0d010c..dc2a9c20 100644 --- a/th04/ems.h +++ b/th04/ems.h @@ -1 +1 @@ -extern unsigned int Ems; /* ZUN symbol [MAGNet2010] */ +extern seg_t Ems; /* ZUN symbol [MAGNet2010] */ diff --git a/th04/formats/bb_stage.c b/th04/formats/bb_stage.c index 9dc2f258..450a2ba1 100644 --- a/th04/formats/bb_stage.c +++ b/th04/formats/bb_stage.c @@ -19,7 +19,7 @@ void pascal far bb_stage_free(void) #endif { if(bb_stage_seg) { - hmem_free((unsigned int)bb_stage_seg); + hmem_free((seg_t)bb_stage_seg); bb_stage_seg = 0; } }