Files
tp/libs/dolphin/dvd/dvdlow.c
T

401 lines
11 KiB
C

//
// Generated By: dol2asm
// Translation Unit: dvdlow
//
#include "dolphin/dvd/dvdlow.h"
#include "dol2asm.h"
#include "dolphin/types.h"
#include "dolphin/os/OSAlarm.h"
#include "dolphin/os/OSTime.h"
//
// Forward References:
//
void __DVDInitWA();
void __DVDInterruptHandler();
static void AlarmHandler();
static void AlarmHandlerForTimeout();
static void Read(u32 arg0, u32 arg1, u32 arg2, DVDLowCallback cb);
static void SeekTwiceBeforeRead();
void DVDLowRead();
BOOL DVDLowSeek(u32 arg0, DVDLowCallback cb);
BOOL DVDLowWaitCoverClose(DVDLowCallback cb);
BOOL DVDLowReadDiskID(u32 arg0, DVDLowCallback cb);
BOOL DVDLowStopMotor(DVDLowCallback cb);
BOOL DVDLowRequestError(DVDLowCallback cb);
BOOL DVDLowInquiry(u32 arg0, DVDLowCallback cb);
BOOL DVDLowAudioStream(u32 arg0, u32 arg1, u32 arg2, DVDLowCallback cb);
BOOL DVDLowRequestAudioStatus(u32 arg0, DVDLowCallback cb);
BOOL DVDLowAudioBufferConfig(s32 arg0, u32 arg1, DVDLowCallback cb);
void DVDLowReset();
BOOL DVDLowBreak();
DVDLowCallback DVDLowClearCallback();
void __DVDLowSetWAType(u32 arg0, u32 arg1);
BOOL __DVDLowTestAlarm(OSAlarm* alarm);
//
// External References:
//
void OSInitAlarm();
void OSCreateAlarm();
void OSSetAlarm();
void OSCancelAlarm();
void OSSetCurrentContext();
void OSClearContext();
BOOL OSDisableInterrupts();
void OSRestoreInterrupts(BOOL enabled);
void __OSMaskInterrupts();
OSTime __OSGetSystemTime();
void DVDGetCurrentDiskID();
//
// Declarations:
//
typedef struct DVDCommand {
s32 _0;
u32 _4;
u32 _8;
u32 _c;
DVDLowCallback callback;
} DVDCommand;
/* ############################################################################################## */
/* 8044C830-8044C870 079550 003C+04 6/6 0/0 0/0 .bss CommandList */
static u8 CommandList[60 + 4 /* padding */];
/* 80451710-80451714 000C10 0004+00 12/12 0/0 0/0 .sbss StopAtNextInt */
static volatile BOOL StopAtNextInt;
/* 80451714-80451718 000C14 0004+00 1/1 0/0 0/0 .sbss LastLength */
static u32 LastLength;
/* 80451718-8045171C 000C18 0004+00 13/13 0/0 0/0 .sbss Callback */
static DVDLowCallback Callback;
/* 8045171C-80451720 000C1C 0004+00 1/1 0/0 0/0 .sbss ResetCoverCallback */
static u8 ResetCoverCallback[4];
/* 80451720-80451724 000C20 0004+00 2/2 0/0 0/0 .sbss LastResetEnd */
static u8 LastResetEnd[4];
/* 80451724-80451728 000C24 0004+00 2/2 0/0 0/0 .sbss None */
static u8 data_80451724[4];
/* 80451728-8045172C 000C28 0004+00 2/2 0/0 0/0 .sbss ResetOccurred */
static u8 ResetOccurred[4];
/* 8045172C-80451730 000C2C 0004+00 3/3 0/0 0/0 .sbss WaitingCoverClose */
static volatile BOOL WaitingCoverClose;
/* 80451730-80451734 000C30 0004+00 2/2 0/0 0/0 .sbss Breaking */
static BOOL Breaking;
/* 80451734-80451738 000C34 0004+00 2/2 0/0 0/0 .sbss WorkAroundType */
static u32 WorkAroundType;
/* 80451738-80451740 000C38 0004+04 2/2 0/0 0/0 .sbss WorkAroundSeekLocation */
static u32 WorkAroundSeekLocation[2];
/* 80451740-80451744 000C40 0004+00 2/2 0/0 0/0 .sbss LastReadFinished */
static BOOL LastReadFinished;
/* 80451744-80451748 000C44 0004+00 2/2 0/0 0/0 .sbss None */
static u8 data_80451744[4];
/* 80451748-8045174C 000C48 0004+00 1/1 0/0 0/0 .sbss LastReadIssued */
static OSTime LastReadIssued;
/* 80451750-80451754 000C50 0004+00 2/2 0/0 0/0 .sbss LastCommandWasRead */
static volatile BOOL LastCommandWasRead;
/* 80451754-80451758 000C54 0004+00 5/5 0/0 0/0 .sbss NextCommandNumber */
static u32 NextCommandNumber;
/* 80347674-803476B4 341FB4 0040+00 0/0 1/1 0/0 .text __DVDInitWA */
void __DVDInitWA() {
NextCommandNumber = 0;
((DVDCommand*)CommandList)[0]._0 = -1;
__DVDLowSetWAType(0, 0);
OSInitAlarm();
}
/* ############################################################################################## */
/* 8044C870-8044C898 079590 0028+00 0/1 0/0 0/0 .bss AlarmForWA */
#pragma push
#pragma force_active on
static u8 AlarmForWA[40];
#pragma pop
/* 8044C898-8044C8C0 0795B8 0028+00 9/11 0/0 0/0 .bss AlarmForTimeout */
static OSAlarm AlarmForTimeout;
/* 8044C8C0-8044C8E8 0795E0 0028+00 1/1 0/0 0/0 .bss AlarmForBreak */
static OSAlarm AlarmForBreak;
/* 8044C8E8-8044C8F4 079608 000C+00 0/1 0/0 0/0 .bss Prev */
#pragma push
#pragma force_active on
static u8 Prev[12];
#pragma pop
/* 8044C8F4-8044C900 079614 000C+00 0/2 0/0 0/0 .bss Curr */
#pragma push
#pragma force_active on
static u8 Curr[12];
#pragma pop
/* 804509D8-804509E0 000458 0004+04 2/2 0/0 0/0 .sdata FirstRead */
SECTION_SDATA static u32 FirstRead[1 + 1 /* padding */] = {
0x00000001,
/* padding */
0x00000000,
};
/* 803476B4-80347994 341FF4 02E0+00 0/0 1/1 0/0 .text __DVDInterruptHandler */
#pragma push
#pragma optimization_level 0
#pragma optimizewithasm off
asm void __DVDInterruptHandler() {
nofralloc
#include "asm/dolphin/dvd/dvdlow/__DVDInterruptHandler.s"
}
#pragma pop
/* 80347994-80347A18 3422D4 0084+00 1/1 0/0 0/0 .text AlarmHandler */
#ifdef NONMATCHING
static void AlarmHandler(OSAlarm* alarm, OSContext* context) {
DVDCommand* cmd;
cmd = &CommandList[NextCommandNumber];
if (cmd->_0 == 1) {
++NextCommandNumber;
Read(cmd->_4, cmd->_8, cmd->_c, cmd->callback);
} else if (cmd->_0 == 2) {
++NextCommandNumber;
DVDLowSeek(cmd->_c, cmd->callback);
}
}
#else
#pragma push
#pragma optimization_level 0
#pragma optimizewithasm off
static asm void AlarmHandler() {
nofralloc
#include "asm/dolphin/dvd/dvdlow/AlarmHandler.s"
}
#pragma pop
#endif
/* 80347A18-80347A88 342358 0070+00 9/9 0/0 0/0 .text AlarmHandlerForTimeout */
static void AlarmHandlerForTimeout(OSAlarm* alarm, OSContext* context) {
OSContext tmpContext;
DVDLowCallback callback;
__OSMaskInterrupts(0x400);
OSClearContext(&tmpContext);
OSSetCurrentContext(&tmpContext);
callback = Callback;
Callback = NULL;
if (callback != NULL) {
callback(0x10);
}
OSClearContext(&tmpContext);
OSSetCurrentContext(context);
}
static void __setAlarm(u32 seconds) {
u32 temp = OSSecondsToTicks(seconds);
OSCreateAlarm(&AlarmForTimeout);
OSSetAlarm(&AlarmForTimeout, (OSTime) temp, AlarmHandlerForTimeout);
}
/* 80347A88-80347B98 3423C8 0110+00 3/3 0/0 0/0 .text Read */
void Read(u32 arg0, u32 arg1, u32 arg2, DVDLowCallback cb) {
StopAtNextInt = FALSE;
Callback = cb;
LastCommandWasRead = TRUE;
LastReadIssued = __OSGetSystemTime();
__DIRegs[2] = 0xA8000000;
__DIRegs[3] = arg2 >> 2;
__DIRegs[4] = arg1;
__DIRegs[5] = arg0;
__DIRegs[6] = arg1;
LastLength = arg1;
__DIRegs[7] = 3;
if (arg1 > 0xa00000) {
__setAlarm(20);
} else {
__setAlarm(10);
}
}
/* 80347B98-80347C18 3424D8 0080+00 1/1 0/0 0/0 .text SeekTwiceBeforeRead */
#pragma push
#pragma optimization_level 0
#pragma optimizewithasm off
static asm void SeekTwiceBeforeRead() {
nofralloc
#include "asm/dolphin/dvd/dvdlow/SeekTwiceBeforeRead.s"
}
#pragma pop
/* 80347C18-80347EB0 342558 0298+00 0/0 4/4 0/0 .text DVDLowRead */
#pragma push
#pragma optimization_level 0
#pragma optimizewithasm off
asm void DVDLowRead() {
nofralloc
#include "asm/dolphin/dvd/dvdlow/DVDLowRead.s"
}
#pragma pop
/* 80347EB0-80347F44 3427F0 0094+00 3/3 2/2 0/0 .text DVDLowSeek */
BOOL DVDLowSeek(u32 arg0, DVDLowCallback cb) {
Callback = cb;
StopAtNextInt = FALSE;
__DIRegs[2] = 0xAB000000;
__DIRegs[3] = arg0 >> 2;
__DIRegs[7] = 1;
__setAlarm(10);
return TRUE;
}
/* 80347F44-80347F70 342884 002C+00 0/0 3/3 0/0 .text DVDLowWaitCoverClose */
BOOL DVDLowWaitCoverClose(DVDLowCallback cb) {
Callback = cb;
WaitingCoverClose = TRUE;
StopAtNextInt = FALSE;
__DIRegs[1] = 2;
return TRUE;
}
/* 80347F70-80348014 3428B0 00A4+00 0/0 2/2 0/0 .text DVDLowReadDiskID */
BOOL DVDLowReadDiskID(u32 arg0, DVDLowCallback cb) {
Callback = cb;
StopAtNextInt = FALSE;
__DIRegs[2] = 0xA8000040;
__DIRegs[3] = 0;
__DIRegs[4] = 0x20;
__DIRegs[5] = arg0;
__DIRegs[6] = 0x20;
__DIRegs[7] = 3;
__setAlarm(10);
return 1;
}
/* 80348014-803480A0 342954 008C+00 0/0 9/9 0/0 .text DVDLowStopMotor */
BOOL DVDLowStopMotor(DVDLowCallback cb) {
Callback = cb;
StopAtNextInt = FALSE;
__DIRegs[2] = 0xE3000000;
__DIRegs[7] = 1;
__setAlarm(10);
return 1;
}
/* 803480A0-8034812C 3429E0 008C+00 0/0 7/7 0/0 .text DVDLowRequestError */
BOOL DVDLowRequestError(DVDLowCallback cb) {
Callback = cb;
StopAtNextInt = FALSE;
__DIRegs[2] = 0xE0000000;
__DIRegs[7] = 1;
__setAlarm(10);
return 1;
}
/* 8034812C-803481C8 342A6C 009C+00 0/0 1/1 0/0 .text DVDLowInquiry */
BOOL DVDLowInquiry(u32 arg0, DVDLowCallback cb) {
Callback = cb;
StopAtNextInt = FALSE;
__DIRegs[2] = 0x12000000;
__DIRegs[4] = 0x20;
__DIRegs[5] = arg0;
__DIRegs[6] = 0x20;
__DIRegs[7] = 3;
__setAlarm(10);
return 1;
}
/* 803481C8-80348260 342B08 0098+00 0/0 2/2 0/0 .text DVDLowAudioStream */
BOOL DVDLowAudioStream(u32 arg0, u32 arg1, u32 arg2, DVDLowCallback cb) {
Callback = cb;
StopAtNextInt = FALSE;
__DIRegs[2] = arg0 | 0xe1000000;
__DIRegs[3] = arg2 >> 2;
__DIRegs[4] = arg1;
__DIRegs[7] = 1;
__setAlarm(10);
return 1;
}
/* 80348260-803482EC 342BA0 008C+00 0/0 1/1 0/0 .text DVDLowRequestAudioStatus */
BOOL DVDLowRequestAudioStatus(u32 arg0, DVDLowCallback cb) {
Callback = cb;
StopAtNextInt = FALSE;
__DIRegs[2] = arg0 | 0xe2000000;
__DIRegs[7] = 1;
__setAlarm(10);
return 1;
}
/* 803482EC-80348388 342C2C 009C+00 0/0 3/3 0/0 .text DVDLowAudioBufferConfig */
BOOL DVDLowAudioBufferConfig(s32 arg0, u32 arg1, DVDLowCallback cb) {
Callback = cb;
StopAtNextInt = FALSE;
__DIRegs[2] = arg1 | ((arg0 ? 0x10000 : 0) | 0xe4000000);
__DIRegs[7] = 1;
__setAlarm(10);
return 1;
}
/* 80348388-80348444 342CC8 00BC+00 0/0 1/1 0/0 .text DVDLowReset */
#pragma push
#pragma optimization_level 0
#pragma optimizewithasm off
asm void DVDLowReset() {
nofralloc
#include "asm/dolphin/dvd/dvdlow/DVDLowReset.s"
}
#pragma pop
/* 80348444-80348458 342D84 0014+00 0/0 1/1 0/0 .text DVDLowBreak */
BOOL DVDLowBreak() {
StopAtNextInt = TRUE;
Breaking = TRUE;
return TRUE;
}
/* 80348458-80348474 342D98 001C+00 0/0 1/1 0/0 .text DVDLowClearCallback */
DVDLowCallback DVDLowClearCallback() {
DVDLowCallback rv;
__DIRegs[1] = 0;
rv = Callback;
WaitingCoverClose = FALSE;
Callback = NULL;
return rv;
}
/* 80348474-803484B8 342DB4 0044+00 1/1 0/0 0/0 .text __DVDLowSetWAType */
void __DVDLowSetWAType(u32 arg0, u32 arg1) {
BOOL enabled = OSDisableInterrupts();
WorkAroundType = arg0;
WorkAroundSeekLocation[0] = arg1;
OSRestoreInterrupts(enabled);
}
/* 803484B8-803484F0 342DF8 0038+00 0/0 1/1 0/0 .text __DVDLowTestAlarm */
BOOL __DVDLowTestAlarm(OSAlarm* alarm) {
if (alarm == &AlarmForBreak) {
return TRUE;
}
if (alarm == &AlarmForTimeout) {
return TRUE;
}
return FALSE;
}