From a3bc614e68d772048b1bb9dd56b4a0d813dd0fe9 Mon Sep 17 00:00:00 2001 From: nmlgc Date: Wed, 10 Aug 2022 17:04:08 +0200 Subject: [PATCH] [Decompilation] [th01] MDRV2: Move all data to C land Part of P0213, funded by Ember2528 and GhostRiderCog. --- th01/snd/mdrv2.cpp | 25 +++++++++++++++---------- th01/snd/mdrv2[data].asm | 5 ----- th01_fuuin_data.asm | 1 - th01_op.asm | 1 - th01_reiiden.asm | 1 - 5 files changed, 15 insertions(+), 18 deletions(-) delete mode 100644 th01/snd/mdrv2[data].asm diff --git a/th01/snd/mdrv2.cpp b/th01/snd/mdrv2.cpp index 85b68df5..559449f7 100644 --- a/th01/snd/mdrv2.cpp +++ b/th01/snd/mdrv2.cpp @@ -15,6 +15,8 @@ extern "C" { #include "th01/snd/mdrv2.h" } +#define MDRV2_MAGIC "Mdrv2System" + typedef enum { MDRV2_MPLAY = 0x00, MDRV2_MFADE_OUT_BLOCK = 0x01, @@ -29,29 +31,32 @@ typedef enum { static const uint8_t MDRV2 = 0xF2; +inline int16_t mdrv2_segment(void) { + // 0000:((0xF2 * 4) + 2) + return peek(0, ((MDRV2 * sizeof(void far *)) + sizeof(void near *))); +} + inline uint16_t mdrv2_call(mdrv2_func_t func) { _AH = func; geninterrupt(MDRV2); return _AX; } -extern char mdrv2_have_board; -struct hack { char x[12]; }; // XXX -extern const struct hack mdrv2_magic; +static int8_t mdrv2_have_board = false; // ACTUAL TYPE: bool +static int8_t mdrv2_unused = 0; // ZUN bloat bool16 mdrv2_resident(void) { - char s1[sizeof(mdrv2_magic)]; - const struct hack s2 = mdrv2_magic; - char far *magicp = (char far *)( - ((long)peek(0, MDRV2 * 4 + 2) << 16) + 0x102 + char s1[sizeof(MDRV2_MAGIC)]; + const char MAGIC[] = "Mdrv2System"; + char far *magicp = reinterpret_cast( + (static_cast(mdrv2_segment()) << 16) + 0x102 ); - int i; - for(i = 0; i < sizeof(s1); i++) { + for(int i = 0; i < sizeof(s1); i++) { s1[i] = magicp[i]; } - if(strcmp(s1, s2.x) != 0) { + if(strcmp(s1, MAGIC) != 0) { return false; } return true; diff --git a/th01/snd/mdrv2[data].asm b/th01/snd/mdrv2[data].asm deleted file mode 100644 index 9b8d64b9..00000000 --- a/th01/snd/mdrv2[data].asm +++ /dev/null @@ -1,5 +0,0 @@ -public _mdrv2_have_board -_mdrv2_have_board db 0 - db 0 -public _mdrv2_magic -_mdrv2_magic db 'Mdrv2System',0 diff --git a/th01_fuuin_data.asm b/th01_fuuin_data.asm index ebc9779f..be5a236a 100644 --- a/th01_fuuin_data.asm +++ b/th01_fuuin_data.asm @@ -16,6 +16,5 @@ include th01/hardware/palette[data].asm include th01/hardware/graph_r[data].asm include th01/hardware/respal[data].asm include th01/formats/grp_ptn[data].asm -include th01/snd/mdrv2[data].asm end diff --git a/th01_op.asm b/th01_op.asm index 0741c8e2..6bfa2f31 100644 --- a/th01_op.asm +++ b/th01_op.asm @@ -1612,7 +1612,6 @@ include libs/master.lib/clip[data].asm include libs/master.lib/rand[data].asm public _res_id _res_id db 'ReiidenConfig',0 -include th01/snd/mdrv2[data].asm .data? public _rand diff --git a/th01_reiiden.asm b/th01_reiiden.asm index ac7c47ec..455c2559 100644 --- a/th01_reiiden.asm +++ b/th01_reiiden.asm @@ -3343,7 +3343,6 @@ include th01/sprites/ileave_m.asp db 0 db 0FFh include th01/sprites/laser_s.asp -include th01/snd/mdrv2[data].asm extern _arc_key:byte extern _card_flip_cycle:byte