diff --git a/decomp.h b/decomp.hpp similarity index 66% rename from decomp.h rename to decomp.hpp index 98a35d2d..4a863d24 100644 --- a/decomp.h +++ b/decomp.hpp @@ -1,6 +1,6 @@ /* ReC98 * ----- - * Macros to help decompiling the seemingly impossible + * Macros and inline functions to help decompiling the seemingly impossible */ // Flag comparisons @@ -55,48 +55,48 @@ // // Also, hey, no need for the MK_FP() macro if we directly return the correct // types. -#ifdef __cplusplus + +} // extern "C" was a mistake + +#if defined(__TURBOC__) && defined(__MSDOS__) + // Declared in in these compilers. + void __emit__(uint8_t __byte, ...); +#endif + +struct Decomp_ES { void __seg* value() { return (void __seg *)(_ES); } }; +struct Decomp_FS { void __seg* value() { return (void __seg *)(_FS); } }; +struct Decomp_GS { void __seg* value() { return (void __seg *)(_GS); } }; +struct Decomp_DI { void __near* value() { return (void __near *)(_DI); } }; + +// Removing [val] from the parameter lists of the template functions below +// perfects the inlining. +#define poked(sgm, off, val) \ + _EAX = val; \ + poked_eax((Decomp##sgm *)NULL, (Decomp##off *)NULL, (uint8_t)(0x89)); + +#define poke_or_d(sgm, off, val) \ + _EAX = val; \ + poked_eax((Decomp##sgm *)NULL, (Decomp##off *)NULL, (uint8_t)(0x09)); + +template inline void poked_eax( + Segment *sgm, Offset *off, uint8_t op +) { + if(op == 0x89) { + *(uint32_t far *)(sgm->value() + off->value()) = _EAX; + } else if(op == 0x09) { + *(uint32_t far *)(sgm->value() + off->value()) |= _EAX; + } } - #if defined(__TURBOC__) && defined(__MSDOS__) - // Declared in in these compilers. - void __emit__(uint8_t __byte, ...); - #endif - struct Decomp_ES { void __seg* value() { return (void __seg *)(_ES); } }; - struct Decomp_FS { void __seg* value() { return (void __seg *)(_FS); } }; - struct Decomp_GS { void __seg* value() { return (void __seg *)(_GS); } }; - struct Decomp_DI { void __near* value() { return (void __near *)(_DI); } }; +inline void poked_eax(Decomp_FS *sgm, Decomp_DI *off, uint8_t op) { + __emit__(0x66, 0x64, op, 0x05); // [op] FS:[DI], EAX +} - // Removing [val] from the parameter lists of the template functions below - // perfects the inlining. - #define poked(sgm, off, val) \ - _EAX = val; \ - poked_eax((Decomp##sgm *)NULL, (Decomp##off *)NULL, (uint8_t)(0x89)); - - #define poke_or_d(sgm, off, val) \ - _EAX = val; \ - poked_eax((Decomp##sgm *)NULL, (Decomp##off *)NULL, (uint8_t)(0x09)); - - template inline void poked_eax( - Segment *sgm, Offset *off, uint8_t op - ) { - if(op == 0x89) { - *(uint32_t far *)(sgm->value() + off->value()) = _EAX; - } else if(op == 0x09) { - *(uint32_t far *)(sgm->value() + off->value()) |= _EAX; - } - } - - inline void poked_eax(Decomp_FS *sgm, Decomp_DI *off, uint8_t op) { - __emit__(0x66, 0x64, op, 0x05); // [op] FS:[DI], EAX - } - - inline void poked_eax(Decomp_GS *sgm, Decomp_DI *off, uint8_t op) { - __emit__(0x66, 0x65, op, 0x05); // [op] GS:[DI], EAX - } +inline void poked_eax(Decomp_GS *sgm, Decomp_DI *off, uint8_t op) { + __emit__(0x66, 0x65, op, 0x05); // [op] GS:[DI], EAX +} extern "C" { -#endif // --------------------------------------------------------- // 32-bit ASM instructions not supported by Turbo C++ 4.0J's built-in diff --git a/th01/end/pic.cpp b/th01/end/pic.cpp index 2a100b08..f192d9e4 100644 --- a/th01/end/pic.cpp +++ b/th01/end/pic.cpp @@ -10,7 +10,7 @@ void pascal end_pics_load_palette_show(const char *fn) // Avoid symbol duplication... #define egc_start_copy egc_start_copy_1 -#include "th01/hardware/egcstart.c" +#include "th01/hardware/egcstart.cpp" static const pixel_t PIC_W = (RES_X / 2); static const pixel_t PIC_H = (RES_Y / 2); diff --git a/th01/hardware/egcrect.cpp b/th01/hardware/egcrect.cpp index 338fd007..44e859f9 100644 --- a/th01/hardware/egcrect.cpp +++ b/th01/hardware/egcrect.cpp @@ -1,4 +1,4 @@ -#include "th01/hardware/egcstart.c" +#include "th01/hardware/egcstart.cpp" void egc_copy_rect_1_to_0_16(screen_x_t x, vram_y_t y, pixel_t w, pixel_t h) { diff --git a/th01/hardware/egcstart.c b/th01/hardware/egcstart.cpp similarity index 81% rename from th01/hardware/egcstart.c rename to th01/hardware/egcstart.cpp index 69361fc8..c3fca280 100644 --- a/th01/hardware/egcstart.c +++ b/th01/hardware/egcstart.cpp @@ -1,5 +1,5 @@ +#include "decomp.hpp" #include "th01/hardware/egc.h" -#include "decomp.h" void pascal egc_start_copy(void) { diff --git a/th01/main_13.cpp b/th01/main_13.cpp index 2fcba9ef..507ed01d 100644 --- a/th01/main_13.cpp +++ b/th01/main_13.cpp @@ -10,7 +10,7 @@ extern "C" { #include "platform.h" #include "pc98.h" #include "planar.h" -#include "decomp.h" +#include "decomp.hpp" #include "master.hpp" #include "th01/hardware/egc.h" #include "th01/hardware/graph.h" diff --git a/th01/zunsoft.cpp b/th01/zunsoft.cpp index ab568789..a0bb747d 100644 --- a/th01/zunsoft.cpp +++ b/th01/zunsoft.cpp @@ -7,7 +7,7 @@ extern "C" { #include "platform.h" #include "x86real.h" #include "pc98.h" -#include "decomp.h" +#include "decomp.hpp" #include "master.hpp" #include "th01/hardware/egc.h" #include "th01/math/vector.hpp" diff --git a/th03/formats/mrs.cpp b/th03/formats/mrs.cpp index befd44df..0173ba7c 100644 --- a/th03/formats/mrs.cpp +++ b/th03/formats/mrs.cpp @@ -6,7 +6,7 @@ extern "C" { #include "platform.h" #include "pc98.h" #include "planar.h" -#include "decomp.h" +#include "decomp.hpp" #include "master.hpp" #include "th03/formats/hfliplut.h" } diff --git a/th03/sprite16.cpp b/th03/sprite16.cpp index 26a2374f..c7ccf063 100644 --- a/th03/sprite16.cpp +++ b/th03/sprite16.cpp @@ -11,7 +11,7 @@ extern "C" { #include "x86real.h" #include "pc98.h" #include "planar.h" -#include "decomp.h" +#include "decomp.hpp" #include "master.hpp" #include "libs/sprite16/sprite16.h" #include "th03/sprite16.hpp" diff --git a/th04/end/box.cpp b/th04/end/box.cpp index 8ccfa275..61c4884d 100644 --- a/th04/end/box.cpp +++ b/th04/end/box.cpp @@ -2,7 +2,7 @@ #include "x86real.h" #include "pc98.h" #include "planar.h" -#include "decomp.h" +#include "decomp.hpp" #include "twobyte.h" #include "master.hpp" diff --git a/th04/hardware/egcrect.cpp b/th04/hardware/egcrect.cpp index a3771ead..d3adb5c2 100644 --- a/th04/hardware/egcrect.cpp +++ b/th04/hardware/egcrect.cpp @@ -5,7 +5,7 @@ extern "C" { #include "x86real.h" #include "pc98.h" #include "planar.h" -#include "decomp.h" +#include "decomp.hpp" #include "master.hpp" #include "th01/hardware/egc.h" diff --git a/th05/formats/cdg_p_nc.cpp b/th05/formats/cdg_p_nc.cpp index 548c11cf..af6d7e96 100644 --- a/th05/formats/cdg_p_nc.cpp +++ b/th05/formats/cdg_p_nc.cpp @@ -6,7 +6,7 @@ extern "C" { #include "x86real.h" #include "pc98.h" #include "planar.h" -#include "decomp.h" +#include "decomp.hpp" #include "th04/formats/cdg.h" } diff --git a/th05/formats/pi_impl.hpp b/th05/formats/pi_impl.hpp index 2602e3e6..6c111485 100644 --- a/th05/formats/pi_impl.hpp +++ b/th05/formats/pi_impl.hpp @@ -1,6 +1,6 @@ // Shared parts of the pi_put_*() functions. -#include "decomp.h" +#include "decomp.hpp" inline void imul_di(int8_t factor) { __emit__(0x6B, 0xFF, factor); diff --git a/th05/hardware/inp_h_w.cpp b/th05/hardware/inp_h_w.cpp index 66f8c8ca..52511f4d 100644 --- a/th05/hardware/inp_h_w.cpp +++ b/th05/hardware/inp_h_w.cpp @@ -2,7 +2,7 @@ extern "C" { #include "platform.h" -#include "decomp.h" +#include "decomp.hpp" #include "master.hpp" #include "th05/hardware/input.h" } diff --git a/th05/music/piano_c.cpp b/th05/music/piano_c.cpp index 7bec50a9..0a497df0 100644 --- a/th05/music/piano_c.cpp +++ b/th05/music/piano_c.cpp @@ -6,7 +6,7 @@ extern "C" { #include "x86real.h" #include "pc98.h" #include "planar.h" -#include "decomp.h" +#include "decomp.hpp" #include "master.hpp" #include "libs/kaja/kaja.h" #include "th05/music/piano.h" diff --git a/th05/snd/load.cpp b/th05/snd/load.cpp index 1f4f57a4..b1214c7d 100644 --- a/th05/snd/load.cpp +++ b/th05/snd/load.cpp @@ -5,7 +5,7 @@ extern "C" { #include #include "platform.h" #include "x86real.h" -#include "decomp.h" +#include "decomp.hpp" #include "master.hpp" #include "libs/kaja/kaja.h" #include "th05/snd/snd.h"