Merge pull request #11 from gamemasterplc/main

Match dvd.c
This commit is contained in:
gamemasterplc 2023-11-24 08:17:22 -06:00 committed by GitHub
commit 00cf61b27c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 211 additions and 7 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
@ -5942,7 +5942,7 @@ beforeDvdStatus = .sbss:0x801D3AE0; // type:object size:0x4 scope:local data:4by
CallBackStatus = .sbss:0x801D3AE4; // type:object size:0x4 scope:local data:4byte
shortAccessSleep = .sbss:0x801D3AE8; // type:object size:0x4 scope:local data:4byte
DataDirMax = .sbss:0x801D3AEC; // type:object size:0x4 scope:local data:4byte
DirDataSize = .sbss:0x801D3AF0; // type:object size:0x8 scope:local data:4byte
DirDataSize = .sbss:0x801D3AF0; // type:object size:0x8 data:4byte
lbl_801D3AF8 = .sbss:0x801D3AF8; // type:object size:0x4 data:4byte
lbl_801D3AFC = .sbss:0x801D3AFC; // type:object size:0x4 data:4byte
lbl_801D3B00 = .sbss:0x801D3B00; // type:object size:0x4 data:float

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"),

View file

@ -2,6 +2,7 @@
#define _COMMON_STRUCTS_H
#include "types.h"
#include "dolphin/dvd.h"
typedef struct UnkOvl {
s32 unk0;
@ -62,4 +63,16 @@ typedef struct file_list_entry {
s32 file_id;
} FileListEntry;
typedef struct data_stat {
s32 dir_id;
void *dir;
void *data;
u32 raw_len;
u32 comp_type;
BOOL used;
s32 num;
u32 status;
DVDFileInfo file_info;
} DataStat;
#endif

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

@ -0,0 +1,191 @@
#include "common.h"
#include "dolphin/dvd.h"
#include "dolphin/os.h"
extern u32 DirDataSize;
extern void HuDataDirReadAsyncCallBack(s32 result, DVDFileInfo* fileInfo);
static DVDDiskID correctDiskID = {
{ 'M', 'P', 'G', 'C' }, //gameName
{ 'H', 'U' }, //company
1, //diskNumber
1, //gameVersion
1, //streaming
0, //streamingBufSize
};
void HuDvdErrorWatch();
static int CallBackStatus;
static s32 beforeDvdStatus;
static void HuDVDReadAsyncCallBack(s32 result, DVDFileInfo* fileInfo)
{
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");
buf = NULL;
len = 0;
}
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;
int i;
u32 count;
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)) {
(void)num;
OSPanic("dvd.c", 258, "dvd.c: File Open Error");
} else {
data = HuDvdDataReadWait(&file, 3, 1, num, HuDVDReadAsyncCallBack, FALSE);
DVDClose(&file);
}
return data;
}
void *HuDvdDataFastReadAsync(s32 entrynum, DataStat *stat)
{
DVDFileInfo file;
void *data = NULL;
if(!DVDFastOpen(entrynum, &stat->file_info)) {
OSPanic("dvd.c", 274, "dvd.c: File Open Error");
} else {
data = HuDvdDataReadWait(&stat->file_info, 3, 0, 0, HuDataDirReadAsyncCallBack, TRUE);
}
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 5:
OSReport("DVD ERROR:No disk\n");
break;
case 6:
OSReport("DVD ERROR:Cover open\n");
break;
case 7:
OSReport("DVD ERROR:Wrong disk\n");
break;
case 12:
OSReport("DVD ERROR:Please retry\n");
break;
default:
break;
}
}