From ed0437f80e0d007d9e13dfe948f566297b45e797 Mon Sep 17 00:00:00 2001 From: nmlgc Date: Wed, 4 Mar 2015 02:39:36 +0100 Subject: [PATCH] [C decompilation] [th02] First set of sound driver calls --- Makefile.mak | 7 +++- libs/kaja/kaja.h | 1 + th02/main_02.c | 15 +++++++++ th02/maine_02.c | 13 ++++++++ th02/op_02.c | 10 ++++++ th02/snd/delaymea.c | 17 ++++++++++ th02/snd/kajafunc.c | 12 +++++++ th02/snd/se.c | 45 ++++++++++++++++++++++++++ th02/snd/se_data.c | 10 ++++++ th02/th02.h | 4 +-- th02_main.asm | 44 +++---------------------- th02_maine.asm | 79 +++++++++++---------------------------------- th02_op.asm | 46 +++----------------------- 13 files changed, 160 insertions(+), 143 deletions(-) create mode 100644 th02/main_02.c create mode 100644 th02/maine_02.c create mode 100644 th02/snd/delaymea.c create mode 100644 th02/snd/kajafunc.c create mode 100644 th02/snd/se.c create mode 100644 th02/snd/se_data.c diff --git a/Makefile.mak b/Makefile.mak index f7d27575..db3ff16c 100644 --- a/Makefile.mak +++ b/Makefile.mak @@ -44,7 +44,12 @@ bin\th02\op.exe: bin\th02\op.obj th02\op_02.c th02\op_03.c th02\op_04.c th02\op_ $** | -bin\th02\maine.exe: bin\th02\maine.obj th02\maine_03.c th02\maine_04.c th02\maine_05.c +bin\th02\main.exe: bin\th02\main.obj th02\main_02.c + $(CC) $(CFLAGS) -ml -DGAME=2 -nbin\th02\ -eMAIN.EXE @&&| +$** +| + +bin\th02\maine.exe: bin\th02\maine.obj th02\maine_02.c th02\maine_03.c th02\maine_04.c th02\maine_05.c $(CC) $(CFLAGS) -ml -3 -Z -DGAME=2 -nbin\th02\ -eMAINE.EXE @&&| $** | diff --git a/libs/kaja/kaja.h b/libs/kaja/kaja.h index 286b42e3..63f85824 100644 --- a/libs/kaja/kaja.h +++ b/libs/kaja/kaja.h @@ -19,3 +19,4 @@ typedef enum { } kaja_func_t; #define PMD 0x60 +#define MMD 0x61 diff --git a/th02/main_02.c b/th02/main_02.c new file mode 100644 index 00000000..2c423aa9 --- /dev/null +++ b/th02/main_02.c @@ -0,0 +1,15 @@ +/* ReC98 + * ----- + * Code segment #2 of TH02's MAIN.EXE + */ + +#include "th02/th02.h" + +extern char snd_active; + +#define frame_delay_2 frame_delay + +#include "th02/snd/kajafunc.c" +#include "th02/snd/delaymea.c" +#pragma codestring "\x00" +#include "th02/snd/se.c" diff --git a/th02/maine_02.c b/th02/maine_02.c new file mode 100644 index 00000000..4be4c3f2 --- /dev/null +++ b/th02/maine_02.c @@ -0,0 +1,13 @@ +/* ReC98 + * ----- + * Code segment #2 of TH02's MAINE.EXE + */ + +#include "th02/th02.h" + +extern char snd_active; + +#define frame_delay_2 frame_delay + +#include "th02/snd/kajafunc.c" +#include "th02/snd/delaymea.c" diff --git a/th02/op_02.c b/th02/op_02.c index 3df7ab70..3fb3d923 100644 --- a/th02/op_02.c +++ b/th02/op_02.c @@ -5,4 +5,14 @@ #include "th02/th02.h" +char snd_active = 0; +char snd_unused = 0; + +extern char snd_midi_active; + +#include "th02/snd/se_data.c" + +#include "th02/snd/kajafunc.c" +#include "th02/snd/delaymea.c" +#include "th02/snd/se.c" #include "th02/hardware/frmdely1.c" diff --git a/th02/snd/delaymea.c b/th02/snd/delaymea.c new file mode 100644 index 00000000..fc5777b7 --- /dev/null +++ b/th02/snd/delaymea.c @@ -0,0 +1,17 @@ +void snd_delay_until_measure(int measure) +{ + if(!snd_active) { + frame_delay_2(100); + return; + } + do { + frame_delay_2(1); + _AH = KAJA_GET_SONG_MEASURE; + if(snd_midi_active != 1) { + geninterrupt(PMD); + } else { + _DX = 192; + geninterrupt(MMD); + } + } while(_AX < measure); +} diff --git a/th02/snd/kajafunc.c b/th02/snd/kajafunc.c new file mode 100644 index 00000000..094d5919 --- /dev/null +++ b/th02/snd/kajafunc.c @@ -0,0 +1,12 @@ +int snd_kaja_func(kaja_func_t ax) +{ + if(snd_active) { + _AX = ax; + if(snd_midi_active != 1) { + geninterrupt(PMD); + } else { + geninterrupt(MMD); + } + } + return _AX; +} diff --git a/th02/snd/se.c b/th02/snd/se.c new file mode 100644 index 00000000..8ebe5f41 --- /dev/null +++ b/th02/snd/se.c @@ -0,0 +1,45 @@ +extern char snd_fm_possible; + +extern unsigned char snd_se_playing; +extern unsigned char snd_se_priorities[]; +extern unsigned char snd_se_priority_frames[]; +extern unsigned char snd_se_frame; + +#pragma option -k- + +void snd_se_reset(void) +{ + snd_se_frame = 0; + snd_se_playing = 0xFF; +} + +#pragma codestring "\x90" + +void snd_se_play(int new_se) +{ + if(!snd_fm_possible) { + return; + } + if(snd_se_playing == 0xFF) { + snd_se_playing = new_se; + } else if(snd_se_priorities[snd_se_playing] <= snd_se_priorities[new_se]) { + snd_se_playing = new_se; + snd_se_frame = 0; + } +} + +void snd_se_update(void) +{ + if(snd_fm_possible && snd_se_playing != 0xFF) { + if(snd_se_frame == 0) __asm { + mov ah, PMD_SE_PLAY + mov al, snd_se_playing + int PMD + } + snd_se_frame++; + if(snd_se_priority_frames[snd_se_playing] < snd_se_frame) { + snd_se_frame = 0; + snd_se_playing = -1; + } + } +} diff --git a/th02/snd/se_data.c b/th02/snd/se_data.c new file mode 100644 index 00000000..ab7e3cf2 --- /dev/null +++ b/th02/snd/se_data.c @@ -0,0 +1,10 @@ +#define SE_COUNT 33 + +unsigned char snd_se_playing = -1; +unsigned char snd_se_priorities[SE_COUNT] = { + 0, 0, 32, 9, 2, 16, 5, 6, 48, 8, 9, 5, 16, 10, 17, 12, 32, 32, 16 +}; +unsigned char snd_se_priority_frames[SE_COUNT] = { + 0, 0, 36, 16, 4, 16, 8, 10, 48, 80, 24, 17, 11, 4, 80, 16, 48, 74, 32 +}; +unsigned char snd_se_frame = 0; diff --git a/th02/th02.h b/th02/th02.h index e1cb6bfc..2bd7a2bd 100644 --- a/th02/th02.h +++ b/th02/th02.h @@ -123,14 +123,14 @@ void pascal frame_delay_2(int frames); extern char snd_midi_active; extern char snd_midi_possible; -void snd_kaja_func(kaja_func_t func); +int snd_kaja_func(kaja_func_t func); #define SND_LOAD_SONG (KAJA_GET_SONG_ADDRESS << 8) void snd_load(const char *fn, int func); void snd_se_reset(void); -void snd_se_play(unsigned char se); +void snd_se_play(int new_se); void snd_se_update(void); // Music Room diff --git a/th02_main.asm b/th02_main.asm index 4442a37c..0bc8dfa5 100644 --- a/th02_main.asm +++ b/th02_main.asm @@ -10127,45 +10127,10 @@ sub_F913 endp include th02/formats/pi_slot_palette_apply.asm include th02/formats/pi_slot_put.asm -include th02/hardware/snd_kaja_func.asm - -; --------------------------------------------------------------------------- - push bp - mov bp, sp - cmp _snd_active, 0 - jnz short loc_FA25 - push 64h ; 'd' - nopcall frame_delay - pop bp - retf -; --------------------------------------------------------------------------- - -loc_FA25: - push 1 - nopcall frame_delay - mov ah, KAJA_GET_SONG_MEASURE - cmp _snd_midi_active, 1 - jz short loc_FA39 - int 60h ; - FTP Packet Driver - BASIC FUNC - TERMINATE DRIVER FOR HANDLE - ; BX = handle - ; Return: CF set on error, DH = error code - ; CF clear if successful - jmp short loc_FA3E -; --------------------------------------------------------------------------- - -loc_FA39: - mov dx, 0C0h - int 61h ; reserved for user interrupt - -loc_FA3E: - cmp ax, [bp+6] - jb short loc_FA25 - pop bp - retf -; --------------------------------------------------------------------------- - db 0 - -include th02/hardware/snd_se.asm + extern _snd_kaja_func:proc + extern _snd_se_reset:proc + extern _snd_se_play:proc + extern _snd_se_update:proc main_02_TEXT ends ; =========================================================================== @@ -35015,6 +34980,7 @@ byte_1E301 db 3 byte_1E302 db 0 db 0 include th02/formats/pfopen[data].asm +public _snd_active _snd_active db 0 db 0 byte_1E30C db 1 diff --git a/th02_maine.asm b/th02_maine.asm index b3bf3606..876f33b9 100644 --- a/th02_maine.asm +++ b/th02_maine.asm @@ -927,7 +927,7 @@ sub_9AD4 proc near push 4 call palette_white_in push 5 - call sub_B855 + call _snd_delay_until_measure pop cx mov si, 0A0h jmp short loc_9B5C @@ -2314,7 +2314,7 @@ var_4 = byte ptr -4 push si push di push 6 - call sub_B855 + call _snd_delay_until_measure pop cx xor si, si jmp short loc_A920 @@ -2338,7 +2338,7 @@ loc_A920: call sub_B200 add sp, 0Ah push 8 - call sub_B855 + call _snd_delay_until_measure pop cx mov si, 0B8h jmp short loc_A992 @@ -2374,7 +2374,7 @@ loc_A992: cmp si, 170h jl short loc_A947 push 9 - call sub_B855 + call _snd_delay_until_measure pop cx mov byte_F02A, 2Fh ; '/' push 1B000C0h @@ -2384,7 +2384,7 @@ loc_A992: push 0Ch call sub_9643 push 0Dh - call sub_B855 + call _snd_delay_until_measure pop cx mov dx, 0A6h ; '¦' mov al, 1 @@ -2409,7 +2409,7 @@ loc_A992: call sub_B200 add sp, 0Ah push 11h - call sub_B855 + call _snd_delay_until_measure pop cx push ds push offset aEd06b_rgb ; "ed06b.rgb" @@ -2420,7 +2420,7 @@ loc_A992: push 29h ; ')' call rotrect push 15h - call sub_B855 + call _snd_delay_until_measure pop cx push 200064h push 3 @@ -2443,7 +2443,7 @@ loc_A992: mov al, 0 out dx, al push 19h - call sub_B855 + call _snd_delay_until_measure pop cx call sub_A8A4 push ds @@ -2473,7 +2473,7 @@ loc_A992: push 29h ; ')' call rotrect push 1Dh - call sub_B855 + call _snd_delay_until_measure pop cx push ds push offset aEd07b_rgb ; "ed07b.rgb" @@ -2484,7 +2484,7 @@ loc_A992: push 0E9h call rotrect push 21h ; '!' - call sub_B855 + call _snd_delay_until_measure pop cx push 200064h push 2 @@ -2494,7 +2494,7 @@ loc_A992: push 0E9h call rotrect push 25h ; '%' - call sub_B855 + call _snd_delay_until_measure pop cx call sub_A8A4 push ds @@ -2520,7 +2520,7 @@ loc_A992: mov al, 0 out dx, al push 29h ; ')' - call sub_B855 + call _snd_delay_until_measure pop cx call _pi_slot_palette_apply stdcall, 0 pop cx @@ -2530,7 +2530,7 @@ loc_A992: push 0E9h call rotrect push 2Dh ; '-' - call sub_B855 + call _snd_delay_until_measure pop cx push ds push offset aEd08a_rgb ; "ed08a.rgb" @@ -2541,7 +2541,7 @@ loc_A992: push 29h ; ')' call rotrect push 31h ; '1' - call sub_B855 + call _snd_delay_until_measure pop cx call sub_A8A4 push ds @@ -2583,7 +2583,7 @@ loc_A992: push 29h ; ')' call rotrect push 35h ; '5' - call sub_B855 + call _snd_delay_until_measure pop cx push ds push offset aEd08c_rgb ; "ed08c.rgb" @@ -2594,7 +2594,7 @@ loc_A992: push 29h ; ')' call rotrect push 39h ; '9' - call sub_B855 + call _snd_delay_until_measure pop cx push 4 call palette_black_out @@ -3548,50 +3548,8 @@ sub_B756 endp include th02/formats/pi_slot_palette_apply.asm include th02/formats/pi_slot_put.asm -include th02/hardware/snd_kaja_func.asm - -; =============== S U B R O U T I N E ======================================= - -; Attributes: bp-based frame - -sub_B855 proc far - -arg_0 = word ptr 6 - - push bp - mov bp, sp - cmp _snd_active, 0 - jnz short loc_B868 - push 64h ; 'd' - nopcall frame_delay - pop bp - retf -; --------------------------------------------------------------------------- - -loc_B868: - push 1 - nopcall frame_delay - mov ah, KAJA_GET_SONG_MEASURE - cmp _snd_midi_active, 1 - jz short loc_B87C - int 60h ; - FTP Packet Driver - BASIC FUNC - TERMINATE DRIVER FOR HANDLE - ; BX = handle - ; Return: CF set on error, DH = error code - ; CF clear if successful - jmp short loc_B881 -; --------------------------------------------------------------------------- - -loc_B87C: - mov dx, 0C0h - int 61h ; reserved for user interrupt - -loc_B881: - cmp ax, [bp+arg_0] - jb short loc_B868 - pop bp - retf -sub_B855 endp - + extern _snd_kaja_func:proc + extern _snd_delay_until_measure:proc maine_02_TEXT ends ; =========================================================================== @@ -3772,6 +3730,7 @@ byte_D70B db 3 byte_D70C db 0 db 0 include th02/formats/pfopen[data].asm +public _snd_active _snd_active db 0 db 0 aUmx db '“Œ•û••–‚.˜^',0 diff --git a/th02_op.asm b/th02_op.asm index 9eabecdf..96e549b2 100644 --- a/th02_op.asm +++ b/th02_op.asm @@ -2339,44 +2339,10 @@ include th02/hardware/snd_pmd_resident.asm include th02/hardware/snd_load.asm include th02/formats/pi_slot_palette_apply.asm include th02/formats/pi_slot_put.asm -include th02/hardware/snd_kaja_func.asm - -; --------------------------------------------------------------------------- - push bp - mov bp, sp - cmp _snd_active, 0 - jnz short loc_B232 - push 64h ; 'd' - nopcall frame_delay_2 - pop bp - retf -; --------------------------------------------------------------------------- - -loc_B232: - push 1 - nopcall frame_delay_2 - mov ah, KAJA_GET_SONG_MEASURE - cmp _snd_midi_active, 1 - jz short loc_B246 - int 60h ; - FTP Packet Driver - BASIC FUNC - TERMINATE DRIVER FOR HANDLE - ; BX = handle - ; Return: CF set on error, DH = error code - ; CF clear if successful - jmp short loc_B24B -; --------------------------------------------------------------------------- - -loc_B246: - mov dx, 0C0h - int 61h ; reserved for user interrupt - -loc_B24B: - cmp ax, [bp+6] - jb short loc_B232 - pop bp - retf -; --------------------------------------------------------------------------- - -include th02/hardware/snd_se.asm + extern _snd_kaja_func:proc + extern _snd_se_reset:proc + extern _snd_se_play:proc + extern _snd_se_update:proc extern FRAME_DELAY:proc op_02_TEXT ends @@ -2482,9 +2448,7 @@ include libs/master.lib/super_entry_bfnt[data].asm include libs/master.lib/superpa[data].asm include th02/formats/pfopen[data].asm aUmx db '“Œ•û••–‚.˜^',0 -_snd_active db 0 - db 0 -include th02/hardware/snd_se[data].asm +extern _snd_active:byte extern _rank:byte .data?