From fa998af4caaba137e76f9cf4005bedaef4160cf9 Mon Sep 17 00:00:00 2001 From: nmlgc Date: Sat, 12 Feb 2022 19:55:36 +0100 Subject: [PATCH] [Maintenance] [th01] Update the MDRV2 functions to current coding standards Part of P0183, funded by Yanga and [Anonymous]. --- th01/mdrv2.c | 1 - th01/mdrv2.cpp | 1 + th01/snd/{mdrv2.c => mdrv2.cpp} | 56 ++++++++++++++++++--------------- th01/snd/mdrv2.h | 6 ++++ 4 files changed, 37 insertions(+), 27 deletions(-) delete mode 100644 th01/mdrv2.c create mode 100644 th01/mdrv2.cpp rename th01/snd/{mdrv2.c => mdrv2.cpp} (69%) diff --git a/th01/mdrv2.c b/th01/mdrv2.c deleted file mode 100644 index 1776230c..00000000 --- a/th01/mdrv2.c +++ /dev/null @@ -1 +0,0 @@ -#include "th01/snd/mdrv2.c" diff --git a/th01/mdrv2.cpp b/th01/mdrv2.cpp new file mode 100644 index 00000000..a363e4fb --- /dev/null +++ b/th01/mdrv2.cpp @@ -0,0 +1 @@ +#include "th01/snd/mdrv2.cpp" diff --git a/th01/snd/mdrv2.c b/th01/snd/mdrv2.cpp similarity index 69% rename from th01/snd/mdrv2.c rename to th01/snd/mdrv2.cpp index b7acb708..dcdcb0de 100644 --- a/th01/snd/mdrv2.c +++ b/th01/snd/mdrv2.cpp @@ -11,11 +11,8 @@ #include #include "platform.h" #include "x86real.h" - -#define MDRV2 0xf2 -#define MDRV2_CALL(func) __asm { \ - mov ah, func; \ - int MDRV2; \ +extern "C" { +#include "th01/snd/mdrv2.h" } typedef enum { @@ -30,11 +27,19 @@ typedef enum { MDRV2_MFADE_IN = 0x0F, } mdrv2_func_t; +static const uint8_t MDRV2 = 0xF2; + +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; -int far mdrv2_resident(void) +bool16 mdrv2_resident(void) { char s1[sizeof(mdrv2_magic)]; const struct hack s2 = mdrv2_magic; @@ -47,15 +52,15 @@ int far mdrv2_resident(void) s1[i] = magicp[i]; } if(strcmp(s1, s2.x) != 0) { - return 0; + return false; } - return 1; + return true; } -static void near pascal mdrv2_load(const char *fn, char func) +void near pascal mdrv2_load(const char *fn, char func) { if(mdrv2_have_board) { - int handle = open(fn, O_BINARY | O_RDONLY); + int handle = open(fn, (O_BINARY | O_RDONLY)); // opens a DOS handle int length = filelength(handle); seg_t sgm; int ofs; @@ -72,18 +77,20 @@ static void near pascal mdrv2_load(const char *fn, char func) mov cx, length mov ds, sgm mov dx, ofs - int 0x21 - pop ds } + geninterrupt(0x21); + __asm { pop ds; } + close(handle); __asm { push ds mov ah, func mov ds, sgm mov si, ofs - int MDRV2 - pop ds } + geninterrupt(MDRV2); + __asm { pop ds; } + farfree(block); } } @@ -101,52 +108,49 @@ void mdrv2_se_load(const char *fn) void mdrv2_bgm_play(void) { if(mdrv2_have_board) { - MDRV2_CALL(MDRV2_MPLAY); + mdrv2_call(MDRV2_MPLAY); } } void mdrv2_bgm_stop(void) { if(mdrv2_have_board) { - MDRV2_CALL(MDRV2_MSTOP); + mdrv2_call(MDRV2_MSTOP); } } void mdrv2_bgm_fade_out_nonblock(void) { if(mdrv2_have_board) { - MDRV2_CALL(MDRV2_MFADE_OUT_NONBLOCK); + mdrv2_call(MDRV2_MFADE_OUT_NONBLOCK); } } void mdrv2_bgm_fade_out_block(void) { if(mdrv2_have_board) { - MDRV2_CALL(MDRV2_MFADE_OUT_BLOCK); + mdrv2_call(MDRV2_MFADE_OUT_BLOCK); } } void mdrv2_bgm_fade_in(void) { if(mdrv2_have_board) { - MDRV2_CALL(MDRV2_MFADE_IN); + mdrv2_call(MDRV2_MFADE_IN); } } int mdrv2_check_board(void) { - MDRV2_CALL(MDRV2_CHECK_BOARD); - __asm { mov mdrv2_have_board, al } + mdrv2_have_board = mdrv2_call(MDRV2_CHECK_BOARD); return mdrv2_have_board; } void mdrv2_se_play(int se) { if(se && mdrv2_have_board) { - se += MDRV2_EPLAY << 8; - __asm { - mov ax, se - int MDRV2 - } + se += (MDRV2_EPLAY << 8); + __asm { mov ax, se; } // Prevent [se] from being put into a register + geninterrupt(MDRV2); } } diff --git a/th01/snd/mdrv2.h b/th01/snd/mdrv2.h index 74d3b3c5..e7b639f1 100644 --- a/th01/snd/mdrv2.h +++ b/th01/snd/mdrv2.h @@ -1,3 +1,9 @@ +// Returns `true` if the MDRV2 driver is resident. +bool16 mdrv2_resident(void); + +// Returns `true` if an FM sound source is installed. +int mdrv2_check_board(void); + void mdrv2_bgm_load(const char *fn); void mdrv2_se_load(const char *fn);