Mostly match dvd.c

This commit is contained in:
gamemasterplc 2023-11-23 23:54:10 -06:00
parent 40f2ed3759
commit c831b27965
3 changed files with 184 additions and 6 deletions

View file

@ -534,7 +534,7 @@ fn_8002FB40 = .text:0x8002FB40; // type:function size:0x2F8
fn_8002FE38 = .text:0x8002FE38; // type:function size:0xE0
fn_8002FF18 = .text:0x8002FF18; // type:function size:0x2C
fn_8002FF44 = .text:0x8002FF44; // type:function size:0x8
fn_8002FF4C = .text:0x8002FF4C; // type:function size:0x150
OSPanic = .text:0x8002FF4C; // type:function size:0x150
fn_8003009C = .text:0x8003009C; // type:function size:0x118
fn_800301B4 = .text:0x800301B4; // type:function size:0x34
fn_800301E8 = .text:0x800301E8; // type:function size:0x98
@ -2260,12 +2260,12 @@ fn_800BD7E0 = .text:0x800BD7E0; // type:function size:0x18
__DVDLowSetWAType = .text:0x800BD7F8; // type:function size:0x44 scope:global
__DVDFSInit = .text:0x800BD83C; // type:function size:0x38 scope:global
fn_800BD874 = .text:0x800BD874; // type:function size:0x2F4
fn_800BDB68 = .text:0x800BDB68; // type:function size:0x74
fn_800BDBDC = .text:0x800BDBDC; // type:function size:0xC8
fn_800BDCA4 = .text:0x800BDCA4; // type:function size:0x24
DVDFastOpen = .text:0x800BDB68; // type:function size:0x74
DVDOpen = .text:0x800BDBDC; // type:function size:0xC8
DVDClose = .text:0x800BDCA4; // type:function size:0x24
fn_800BDCC8 = .text:0x800BDCC8; // type:function size:0x160
fn_800BDE28 = .text:0x800BDE28; // type:function size:0xC4
fn_800BDEEC = .text:0x800BDEEC; // type:function size:0xC0
DVDReadAsyncPrio = .text:0x800BDEEC; // type:function size:0xC0
fn_800BDFAC = .text:0x800BDFAC; // type:function size:0x30
fn_800BDFDC = .text:0x800BDFDC; // type:function size:0x118
fn_800BE0F4 = .text:0x800BE0F4; // type:function size:0x24

View file

@ -231,7 +231,7 @@ config.libs = [
"objects": [
Object(NonMatching, "game/main.c"),
Object(NonMatching, "game/pad.c"),
Object(NonMatching, "game/dvd.c"),
Object(Matching, "game/dvd.c"),
Object(NonMatching, "game/data.c"),
Object(Matching, "game/decode.c"),
Object(NonMatching, "game/font.c"),

178
src/game/dvd.c Normal file
View file

@ -0,0 +1,178 @@
#include "common.h"
#include "dolphin/dvd.h"
#include "dolphin/os.h"
extern u32 DirDataSize;
static DVDDiskID correctDiskID = {
{ 'M', 'P', 'G', 'C' }, //gameName
{ 'H', 'U' }, //company
1, //diskNumber
1, //gameVersion
1, //streaming
0, //streamingBufSize
};
void HuDvdErrorWatch();
static s32 beforeDvdStatus;
static int CallBackStatus;
static void HuDVDReadAsyncCallBack()
{
CallBackStatus = 1;
}
static void *HuDvdDataReadWait(DVDFileInfo *file, int heap, int mode, int num, DVDCallback cb, BOOL skip_wait)
{
u32 len;
void *buf;
if(mode != 0 && mode != 1 && mode != 2) {
OSReport("dvd.c: HuDvdDataReadWait Mode Error");
}
len = file->length;
DirDataSize = len;
if(mode == 1) {
buf = HuMemDirectMallocNum(heap, OSRoundUp32B(len), num);
} else {
buf = HuMemDirectMalloc(heap, OSRoundUp32B(len));
}
if(!buf) {
OSReport("dvd.c: Memory Allocation Error (Length %x) (mode %d)\n", len, mode);
OSReport("Rest Memory %x\n", HuMemHeapSizeGet(3)-HuMemUsedMallocSizeGet(3));
OSPanic("dvd.c", 75, "\n");
return NULL;
}
DCInvalidateRange(buf, OSRoundUp32B(len));
OSReport("Rest Memory %x\n", HuMemHeapSizeGet(3)-HuMemUsedMallocSizeGet(3));
CallBackStatus = 0;
DVDReadAsync(file, buf, OSRoundUp32B(len), 0, cb);
if(!skip_wait) {
while(!CallBackStatus) {
HuDvdErrorWatch();
}
HuDvdErrorWatch();
}
return buf;
}
void *HuDvdDataRead(char *path)
{
DVDFileInfo file;
void *data = NULL;
if(!DVDOpen(path, &file)) {
OSPanic("dvd.c", 146, "dvd.c: File Open Error");
} else {
data = HuDvdDataReadWait(&file, 3, 0, 0, HuDVDReadAsyncCallBack, FALSE);
DVDClose(&file);
}
return data;
}
void **HuDvdDataReadMulti(char **paths)
{
DVDFileInfo file;
u32 count;
int i;
void **file_ptrs;
count = 0;
while(paths[count]) {
count++;
}
file_ptrs = HuMemDirectMalloc(0, count*4);
for(i=0; i<count; i++) {
if(!DVDOpen(paths[i], &file)) {
OSPanic("dvd.c", 183, "dvd.c: File Open Error");
return NULL;
} else {
file_ptrs[i] = HuDvdDataReadWait(&file, 3, 0, 0, HuDVDReadAsyncCallBack, FALSE);
DVDClose(&file);
}
}
return file_ptrs;
}
void *HuDvdDataReadDirect(char *path, int heap)
{
DVDFileInfo file;
void *data = NULL;
if(!DVDOpen(path, &file)) {
OSPanic("dvd.c", 202, "dvd.c: File Open Error");
} else {
data = HuDvdDataReadWait(&file, heap, 2, 0, HuDVDReadAsyncCallBack, FALSE);
DVDClose(&file);
}
return data;
}
void *HuDvdDataFastRead(s32 entrynum)
{
DVDFileInfo file;
void *data = NULL;
if(!DVDFastOpen(entrynum, &file)) {
OSPanic("dvd.c", 243, "dvd.c: File Open Error");
} else {
data = HuDvdDataReadWait(&file, 3, 0, 0, HuDVDReadAsyncCallBack, FALSE);
DVDClose(&file);
}
return data;
}
void *HuDvdDataFastReadNum(s32 entrynum, s32 num)
{
DVDFileInfo file;
void *data = NULL;
if(!DVDFastOpen(entrynum, &file)) {
OSPanic("dvd.c", 258, "dvd.c: File Open Error");
(void)num;
(void)data;
} else {
data = HuDvdDataReadWait(&file, 3, 1, num, HuDVDReadAsyncCallBack, FALSE);
DVDClose(&file);
}
return data;
}
void HuDvdDataClose(void *ptr)
{
if(ptr) {
HuMemDirectFree(ptr);
}
}
void HuDvdErrorWatch()
{
int status = DVDGetDriveStatus();
if(status == beforeDvdStatus) {
return;
}
beforeDvdStatus = status;
switch(status+1) {
case 0:
OSReport("DVD ERROR:Fatal error occurred\n***HALT***");
while(1);
break;
case 6:
OSReport("DVD ERROR:No disk\n");
break;
case 7:
OSReport("DVD ERROR:Cover open\n");
break;
case 8:
OSReport("DVD ERROR:Wrong disk\n");
break;
case 12:
OSReport("DVD ERROR:Please retry\n");
break;
default:
break;
}
}