From 9cb6cc527a95a51cdc4f607610fa1a15d729b3c4 Mon Sep 17 00:00:00 2001 From: nmlgc Date: Wed, 11 Dec 2019 21:42:27 +0100 Subject: [PATCH] [Decompilation] Finally declare types *Finally*. We already used `(unsigned) int` in quite a few places where we actually want a 16-bit value, which was bound to annoy future port developers. --- ReC98.h | 5 +++-- platform.h | 25 +++++++++++++++++++++++++ th01/pf.cpp | 16 ++++++++-------- th01/ztext.c | 12 ++++++------ th02/hardware/grppsafx.c | 2 +- th02/snd/kajaint.c | 2 +- th02/th02.h | 22 +++++++++++----------- th03/math/randring.h | 4 ++-- th04/mem.h | 2 +- th05/mem.h | 2 +- 10 files changed, 59 insertions(+), 33 deletions(-) create mode 100644 platform.h diff --git a/ReC98.h b/ReC98.h index aad94080..a83782f6 100644 --- a/ReC98.h +++ b/ReC98.h @@ -5,6 +5,7 @@ #include #include +#include "platform.h" #include "pc98.h" // master.lib extensions @@ -60,9 +61,9 @@ typedef struct { typedef union { struct { - char lo, hi; + int8_t lo, hi; } byte; - int v; + int16_t v; } twobyte_t; /// Typedefs diff --git a/platform.h b/platform.h new file mode 100644 index 00000000..82ae9369 --- /dev/null +++ b/platform.h @@ -0,0 +1,25 @@ +/* ReC98 + * ----- + * Platform- and compiler-specific types. + */ + +/// +/// ---------- +// __TURBOC__ is #define'd on both "Borland" and "Turbo" editions, unlike +// __BORLANDC__, which is only #define'd on the former. +#if defined(__TURBOC__) && defined(__MSDOS__) +# ifdef __cplusplus +typedef char bool; +# define false 0 +# define true 1 +#endif +typedef char int8_t; +typedef short int16_t; +typedef long int32_t; +typedef unsigned char uint8_t; +typedef unsigned short uint16_t; +typedef unsigned long uint32_t; +#else +# 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 +/// ---------- diff --git a/th01/pf.cpp b/th01/pf.cpp index b001ec24..412fc1ed 100644 --- a/th01/pf.cpp +++ b/th01/pf.cpp @@ -15,10 +15,10 @@ typedef struct { char type[2]; // •• if RLE-compressed char aux; // Always 3, unused char fn[FN_LEN]; - long packsize; - long orgsize; - long offset; // of the file data within the entire archive - long reserved; // Always zero + int32_t packsize; + int32_t orgsize; + int32_t offset; // of the file data within the entire archive + int32_t reserved; // Always zero } pf_header_t; #pragma option -Z -a1 @@ -84,9 +84,9 @@ int pascal near at_pos_of(const char *fn) } // Get it? En*crap*tion? -void pascal near crapt(char *buf, unsigned int size) +void pascal near crapt(char *buf, size_t size) { - unsigned int i; + size_t i; for(i = 0; i < size; i++) { buf[i] ^= arc_key; } @@ -178,10 +178,10 @@ void pascal arc_file_load(const char *fn) file_close(); } -void pascal arc_file_get(char *buf, unsigned int size) +void pascal arc_file_get(char *buf, size_t size) { char *p = buf; - unsigned int i; + size_t i; for(i = 0; i < size; i++) { if(file_pos >= file_pf->orgsize) { break; diff --git a/th01/ztext.c b/th01/ztext.c index 3d9c3fa5..db0ea14a 100644 --- a/th01/ztext.c +++ b/th01/ztext.c @@ -111,13 +111,13 @@ void z_text_locate(char x, char y) void z_text_putsa(int x, int y, int z_atrb, const char *str) { - unsigned int codepoint; + uint16_t codepoint; int p = ((y * text_width()) + x) * 2; int hw_atrb = 1; - #define tx_chars(byte) ((char*)MK_FP(0xA000, 0) + p + byte) - #define tx_chars(byte) ((char*)MK_FP(0xA000, 0) + p + byte) - #define tx_atrbs(byte) (int*)((char*)MK_FP(0xA200, 0) + p + byte) + #define tx_chars(byte) ((char*)MK_FP(0xA000, p + byte)) + #define tx_chars(byte) ((char*)MK_FP(0xA000, p + byte)) + #define tx_atrbs(byte) ((int16_t*)MK_FP(0xA200, p + byte)) if(z_atrb & 1) { hw_atrb += 0x20; @@ -152,7 +152,7 @@ void z_text_putsa(int x, int y, int z_atrb, const char *str) *tx_chars(1) = codepoint; *tx_atrbs(0) = hw_atrb; } else if(x == text_width() - 1) { - *(int*)tx_chars(0) = ' '; + *(int16_t*)tx_chars(0) = ' '; *tx_atrbs(0) = hw_atrb; } else { *tx_chars(0) = (codepoint >> 8) + 0xE0; @@ -166,7 +166,7 @@ void z_text_putsa(int x, int y, int z_atrb, const char *str) x++; } } else { - *(int*)tx_chars(0) = *(unsigned char*)(str++); + *(int16_t*)tx_chars(0) = *(unsigned char*)(str++); *tx_atrbs(0) = hw_atrb; } p += 2; diff --git a/th02/hardware/grppsafx.c b/th02/hardware/grppsafx.c index 6f8bf7b6..2116d496 100644 --- a/th02/hardware/grppsafx.c +++ b/th02/hardware/grppsafx.c @@ -3,7 +3,7 @@ void graph_putsa_fx(int x, int y, int fx, const unsigned char *str) { - unsigned int codepoint; + uint16_t codepoint; unsigned int glyph_row; unsigned char far *vram; int fullwidth; diff --git a/th02/snd/kajaint.c b/th02/snd/kajaint.c index abe32eae..2fe3c6ef 100644 --- a/th02/snd/kajaint.c +++ b/th02/snd/kajaint.c @@ -1,4 +1,4 @@ -int snd_kaja_interrupt(int ax) +int16_t snd_kaja_interrupt(int16_t ax) { if(snd_active) { _AX = ax; diff --git a/th02/th02.h b/th02/th02.h index 40b235d9..7b9e110e 100644 --- a/th02/th02.h +++ b/th02/th02.h @@ -183,7 +183,7 @@ int snd_pmd_resident(void); int snd_mmd_resident(void); int snd_determine_mode(void); -int snd_kaja_interrupt(int ax); +int16_t snd_kaja_interrupt(int16_t ax); #define snd_kaja_func(func, param) snd_kaja_interrupt((func) << 8 | (param)) #define SND_LOAD_SONG (KAJA_GET_SONG_ADDRESS << 8) @@ -206,17 +206,17 @@ void snd_se_update(void); #define CFG_FN "huuma.cfg" #pragma option -a1 typedef struct { - char rank; - char bgm_mode; - char bombs; - char lives; - char perf; + int8_t rank; + int8_t bgm_mode; + int8_t bombs; + int8_t lives; + int8_t perf; } huuma_options_t; typedef struct { huuma_options_t opts; int resident_sgm; - char debug; + int8_t debug; } huuma_cfg_t; #pragma option -a. // ------------------ @@ -283,10 +283,10 @@ typedef struct { * * For rank #4, this field is unused. */ - int cleared; + int16_t cleared; - long points[SCORE_PLACES]; - long points_sum; + int32_t points[SCORE_PLACES]; + int32_t points_sum; unsigned char g_name[SCORE_PLACES][SCORE_NAME_LEN + 1]; unsigned char g_name_first_sum; unsigned char stage[SCORE_PLACES]; @@ -297,7 +297,7 @@ typedef struct { typedef struct { score_t score; - long score_sum; // Sum of all bytes in score, pre-encraption + int32_t score_sum; // Sum of all bytes in score, pre-encraption } score_file_t; extern char cleared_game_with[SHOTTYPE_COUNT]; diff --git a/th03/math/randring.h b/th03/math/randring.h index 44ef1ff2..41a588d5 100644 --- a/th03/math/randring.h +++ b/th03/math/randring.h @@ -1,2 +1,2 @@ -unsigned short pascal near randring1_next16(void); -unsigned short pascal near randring1_next16_and(unsigned short mask); +uint16_t pascal near randring1_next16(void); +uint16_t pascal near randring1_next16_and(uint16_t mask); diff --git a/th04/mem.h b/th04/mem.h index 52bc1f61..fb266d2a 100644 --- a/th04/mem.h +++ b/th04/mem.h @@ -2,7 +2,7 @@ #define MEM_ASSIGN_PARAS_OP (336000 >> 4) #define MEM_ASSIGN_PARAS_MAIN (320000 >> 4) #define MEM_ASSIGN_PARAS_MAINE (336000 >> 4) -extern unsigned int mem_assign_paras; +extern size_t mem_assign_paras; #define EMSSIZE (180000) /* ZUN symbol [MAGNet2010] */ diff --git a/th05/mem.h b/th05/mem.h index d5cd0a15..034809c1 100644 --- a/th05/mem.h +++ b/th05/mem.h @@ -2,7 +2,7 @@ #define MEM_ASSIGN_PARAS_OP (336000 >> 4) #define MEM_ASSIGN_PARAS_MAIN (291200 >> 4) #define MEM_ASSIGN_PARAS_MAINE (336000 >> 4) -extern unsigned int mem_assign_paras; +extern size_t mem_assign_paras; #define EMSSIZE (320000) /* ZUN symbol [MAGNet2010] */