Skip to content

Commit

Permalink
More reverse/mapping around MidiDevice and MidiTimer
Browse files Browse the repository at this point in the history
  • Loading branch information
marysaka committed Oct 27, 2024
1 parent 577a4be commit cc3b53e
Show file tree
Hide file tree
Showing 8 changed files with 57 additions and 49 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

BOOL __thiscall th06::MidiDevice::FUN_00421b90(MidiDevice *this,LPMIDIHDR param_1)
BOOL __thiscall th06::MidiDevice::SendLongMsg(MidiDevice *this,LPMIDIHDR pmh)

{
BOOL uVar1;
Expand All @@ -9,9 +9,9 @@ BOOL __thiscall th06::MidiDevice::FUN_00421b90(MidiDevice *this,LPMIDIHDR param_
uVar1 = 0;
}
else {
MVar1 = midiOutPrepareHeader(this->handle,param_1,0x40);
MVar1 = midiOutPrepareHeader(this->handle,pmh,0x40);
if (MVar1 == 0) {
MVar1 = midiOutLongMsg(this->handle,param_1,0x40);
MVar1 = midiOutLongMsg(this->handle,pmh,0x40);
uVar1 = (BOOL)(MVar1 != 0);
}
else {
Expand Down
27 changes: 17 additions & 10 deletions src/th06_102h.exe/MidiDevice/SendShortMsg.c
Original file line number Diff line number Diff line change
@@ -1,21 +1,28 @@

bool __thiscall
th06::MidiDevice::SendShortMsg(MidiDevice *this,byte firstByte,byte secondByte,byte thirdByte)
th06::MidiDevice::SendShortMsg(MidiDevice *this,byte midiStatus,byte firstByte,byte secondByte)

{
DWORD DVar1;
MMRESULT MVar2;
bool bVar3;
DWORD local_8;
BYTE aBVar1 [4];
MMRESULT res;
bool hasError;
BYTE dwMsg [4];

DVar1 = local_8;
aBVar1 = dwMsg;
if (this->handle == (HMIDIOUT)0x0) {
bVar3 = false;
hasError = false;
}
else {
MVar2 = midiOutShortMsg(this->handle,local_8);
bVar3 = MVar2 != 0;
dwMsg[1] = firstByte;
dwMsg[0] = midiStatus;
/* Ghidra is drunk here:
- Order is wrong (should be 0, 1, 2)
- dwMsg[3] is never set. */
dwMsg[3] = aBVar1[3];
dwMsg[2] = secondByte;
res = midiOutShortMsg(this->handle,(DWORD)dwMsg);
hasError = res != 0;
}
return bVar3;
return hasError;
}

2 changes: 1 addition & 1 deletion src/th06_102h.exe/MidiOutput/Play.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ ZunResult __thiscall th06::MidiOutput::Play(MidiOutput *this)
else {
FUN_004223c0(this);
MidiDevice::OpenDevice(&this->midiOutDev,0xffffffff);
MidiTimer::FUN_00421c90(&this->timer,1,(LPTIMECALLBACK)0x0,0);
MidiTimer::StartTimer(&this->timer,1,(LPTIMECALLBACK)0x0,0);
ZVar1 = ZUN_SUCCESS;
}
return ZVar1;
Expand Down
22 changes: 11 additions & 11 deletions src/th06_102h.exe/MidiOutput/ProcessMsg.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ void __thiscall th06::MidiOutput::ProcessMsg(MidiOutput *this,MidiTrack *param_1

{
char cVar1;
LPMIDIHDR _Memory;
LPMIDIHDR pmh;
MIDIHDR *pMVar2;
LPSTR pCVar3;
BOOL BVar4;
Expand Down Expand Up @@ -56,32 +56,32 @@ void __thiscall th06::MidiOutput::ProcessMsg(MidiOutput *this,MidiTrack *param_1
}
pMVar2 = (MIDIHDR *)_malloc(0x40);
this->midiHeaders[this->midiHeadersCursor] = pMVar2;
_Memory = this->midiHeaders[this->midiHeadersCursor];
pmh = this->midiHeaders[this->midiHeadersCursor];
iVar7 = FUN_00421d90(&param_1->curTrackDataCursor);
pmVar9 = _Memory;
pmVar9 = pmh;
for (iVar8 = 0x10; iVar8 != 0; iVar8 = iVar8 + -1) {
pmVar9->lpData = (LPSTR)0x0;
pmVar9 = (LPMIDIHDR)&pmVar9->dwBufferLength;
}
pCVar3 = (LPSTR)_malloc(iVar7 + 1);
_Memory->lpData = pCVar3;
*_Memory->lpData = -0x10;
_Memory->dwFlags = 0;
_Memory->dwBufferLength = iVar7 + 1;
pmh->lpData = pCVar3;
*pmh->lpData = -0x10;
pmh->dwFlags = 0;
pmh->dwBufferLength = iVar7 + 1;
arg2 = arg2 & 0xff;
uStack_9 = 0;
while (CONCAT13(uStack_9,arg2._1_3_) < iVar7) {
/* WARNING: Load size is inaccurate */
_Memory->lpData[CONCAT13(uStack_9,arg2._1_3_) + 1] = *param_1->curTrackDataCursor;
pmh->lpData[CONCAT13(uStack_9,arg2._1_3_) + 1] = *param_1->curTrackDataCursor;
param_1->curTrackDataCursor = (void *)((int)param_1->curTrackDataCursor + 1);
iVar8 = CONCAT13(uStack_9,arg2._1_3_) + 1;
arg2._1_3_ = (undefined3)iVar8;
uStack_9 = (undefined)((uint)iVar8 >> 0x18);
}
BVar4 = MidiDevice::FUN_00421b90(&this->midiOutDev,_Memory);
BVar4 = MidiDevice::SendLongMsg(&this->midiOutDev,pmh);
if (BVar4 != 0) {
_free(_Memory->lpData);
_free(_Memory);
_free(pmh->lpData);
_free(pmh);
this->midiHeaders[this->midiHeadersCursor] = (MIDIHDR *)0x0;
}
this->midiHeadersCursor = this->midiHeadersCursor + 1;
Expand Down
5 changes: 3 additions & 2 deletions src/th06_102h.exe/MidiTimer/DefaultTimerCallback.c
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@

void th06::MidiTimer::DefaultTimerCallback(uint uTimerID,uint uMsg,MidiOutput *dwUser)
void th06::MidiTimer::DefaultTimerCallback
(uint uTimerID,uint uMsg,DWORD_PTR dwUser,DWORD_PTR dw1,DWORD_PTR dw2)

{
(**(code **)(dwUser->timer).vtbl)();
(***(code ***)dwUser)();
return;
}

21 changes: 0 additions & 21 deletions src/th06_102h.exe/MidiTimer/FUN_00421c90.c

This file was deleted.

21 changes: 21 additions & 0 deletions src/th06_102h.exe/MidiTimer/StartTimer.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@

UINT __thiscall
th06::MidiTimer::StartTimer(MidiTimer *this,UINT delay,LPTIMECALLBACK cb,DWORD_PTR data)

{
MMRESULT timer_id;

StopTimer(this);
timeBeginPeriod((this->timeCaps).wPeriodMin);
if (cb == (LPTIMECALLBACK)0x0) {
timer_id = timeSetEvent(delay,(this->timeCaps).wPeriodMin,DefaultTimerCallback,(DWORD_PTR)this,
TIME_PERIODIC);
this->timerId = timer_id;
}
else {
timer_id = timeSetEvent(delay,(this->timeCaps).wPeriodMin,cb,data,TIME_PERIODIC);
this->timerId = timer_id;
}
return this->timerId;
}

2 changes: 1 addition & 1 deletion th06_102h.exe.version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
272
273

0 comments on commit cc3b53e

Please sign in to comment.