From 9d121c7ccef61ba1cb6e3b0712c2f0327dda103e Mon Sep 17 00:00:00 2001 From: nmlgc Date: Sun, 15 Sep 2019 19:36:17 +0200 Subject: [PATCH] [Decompilation] [th04/th05] Handle subpixels at the C++ type level MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit I've had the idea to hide this implementation detail and improve code readability for some time now, but it obviously must still all inline, to be indistinguishable from a direct assignment of the correct value… … which, amazingly, it does! Even the static_cast from float to int. The latter allows us to exclusively implement this for float, since we do have to express the occasional value smaller than 16. Who needs macros anyway. Yay, C++ in TH04 and TH05 after all! Part of P0030, funded by zorg. --- Makefile.mak | 2 +- th04/shared.h | 14 --------- th04/shared.hpp | 53 +++++++++++++++++++++++++++++++++ th05/{main_01.c => main_01.cpp} | 5 +++- th05/{th05.h => th05.hpp} | 3 +- 5 files changed, 60 insertions(+), 17 deletions(-) delete mode 100644 th04/shared.h create mode 100644 th04/shared.hpp rename th05/{main_01.c => main_01.cpp} (84%) rename th05/{th05.h => th05.hpp} (59%) diff --git a/Makefile.mak b/Makefile.mak index 97c7f400..2fd6dee7 100644 --- a/Makefile.mak +++ b/Makefile.mak @@ -73,7 +73,7 @@ bin\th04\op.exe: bin\th04\op.obj th04\op_02.c $** | -bin\th05\main.exe: bin\th05\main.obj th05\main_01.c +bin\th05\main.exe: bin\th05\main.obj th05\main_01.cpp $(CC) $(CFLAGS) -ml -3 -DGAME=5 -nbin\th05\ -eMAIN.EXE @&&| $** | diff --git a/th04/shared.h b/th04/shared.h deleted file mode 100644 index 08ddebef..00000000 --- a/th04/shared.h +++ /dev/null @@ -1,14 +0,0 @@ -/* ReC98 - * ----- - * Types shared between TH04 and TH05 - */ - -/// Score -/// ----- -extern unsigned long score_delta; - -void pascal near score_update_and_render(void); - -// Adds the entire score delta at once to the current score. -void pascal score_delta_commit(void); -/// ----- diff --git a/th04/shared.hpp b/th04/shared.hpp new file mode 100644 index 00000000..2794f58e --- /dev/null +++ b/th04/shared.hpp @@ -0,0 +1,53 @@ +/* ReC98 + * ----- + * Types shared between TH04 and TH05 + */ + +/// Math +/// ---- +class Subpixel { +private: + int v; + +public: + Subpixel() {} + Subpixel(float screen_v) { *this = screen_v; } + + Subpixel& operator =(float screen_v) { + v = static_cast(screen_v * 16.0f); + return *this; + } +}; + +struct SPPoint { + Subpixel x, y; + + void set(float screen_x, float screen_y) { + x = screen_x; + y = screen_y; + } +}; + +typedef struct { + SPPoint cur; + SPPoint prev; + SPPoint velocity; + + void init(float screen_x, float screen_y) { + cur.x = screen_x; + prev.x = screen_x; + cur.y = screen_y; + prev.y = screen_y; + } +} motion_t; +/// ---- + +/// Score +/// ----- +extern unsigned long score_delta; + +void pascal near score_update_and_render(void); + +// Adds the entire score delta at once to the current score. +void pascal score_delta_commit(void); +/// ----- diff --git a/th05/main_01.c b/th05/main_01.cpp similarity index 84% rename from th05/main_01.c rename to th05/main_01.cpp index 93d5b48b..eed86542 100644 --- a/th05/main_01.c +++ b/th05/main_01.cpp @@ -3,7 +3,8 @@ * Code segment #1 of TH05's MAIN.EXE */ -#include "th05/th05.h" +extern "C" { +#include "th05/th05.hpp" // Adds the entire score delta at once to the current score. void pascal score_delta_commit(void) @@ -12,3 +13,5 @@ void pascal score_delta_commit(void) score_update_and_render(); } } + +} diff --git a/th05/th05.h b/th05/th05.hpp similarity index 59% rename from th05/th05.h rename to th05/th05.hpp index 960fbd61..ff8c1cbc 100644 --- a/th05/th05.h +++ b/th05/th05.hpp @@ -4,4 +4,5 @@ */ #include "ReC98.h" -#include "th04/shared.h" +#include "th04/shared.hpp" +/// ------