From ff777a099e2c9b36bb8ca2479403b0d7ce72c044 Mon Sep 17 00:00:00 2001 From: nmlgc Date: Wed, 19 Feb 2020 15:53:51 +0100 Subject: [PATCH] [Decompilation] [th03] Add a type for the paletted playchar IDs Much better than the previous incorrect comment, since the char_id() method now easily generates the correct sequence of conversion instructions, seen all throughout the ASM. Even within array subscripts! Part of P0076, funded by [Anonymous] and -Tom-. --- Research/Borland C++ decompilation.md | 1 + th03/chars/{chars.h => chars.hpp} | 17 +++++++++++++++++ th03/player/player.hpp | 5 +---- 3 files changed, 19 insertions(+), 4 deletions(-) rename th03/chars/{chars.h => chars.hpp} (57%) diff --git a/Research/Borland C++ decompilation.md b/Research/Borland C++ decompilation.md index 1642bd48..8aa7ad19 100644 --- a/Research/Borland C++ decompilation.md +++ b/Research/Borland C++ decompilation.md @@ -39,6 +39,7 @@ where the scalar-type variable is declared in relation to them. |-|-| | `ADD [m8], imm8` | Only achievable through a C++ method operating on a member? | | `MOV AL, [m8]`
`ADD AL, imm8`
`MOV [m8], AL` | Opposite; *not* an inlined function | +| `CWD`
`SUB AX, DX`
`SAR AX, 1` | `AX / 2`, `AX` is *int* | ### Arithmetic on a register *after* assigning it to a variable? diff --git a/th03/chars/chars.h b/th03/chars/chars.hpp similarity index 57% rename from th03/chars/chars.h rename to th03/chars/chars.hpp index 8b61c5f8..18a3cc95 100644 --- a/th03/chars/chars.h +++ b/th03/chars/chars.hpp @@ -11,6 +11,23 @@ typedef enum { PLAYCHAR_COUNT = 9, } playchars_t; +// Encodes a playchars_t together with its alternate palette flag. +#pragma option -a1 +struct playchar_paletted_t { + unsigned char v; + + int filename_id() const { + return (v - 1); + } + + playchars_t char_id() const { + return static_cast(filename_id() / 2); + } +}; +#pragma option -a. + +#define TO_PALETTED(playchar) ((playchar << 1) + 1) + typedef struct { SPPoint8 aligned; SPPoint8 diagonal; diff --git a/th03/player/player.hpp b/th03/player/player.hpp index dee0d8de..c6685c83 100644 --- a/th03/player/player.hpp +++ b/th03/player/player.hpp @@ -37,10 +37,7 @@ typedef struct { uint8_t unused_1; unsigned char invincibility_time; char halfhearts; - - // ( + 1) << 1 | - unsigned char playchar_paletted; - + playchar_paletted_t playchar_paletted; speed_t speed; shot_mode_t shot_mode; unsigned char patnum_movement;