diff --git a/include/disk.h b/include/disk.h index 36ee521..b5a0268 100644 --- a/include/disk.h +++ b/include/disk.h @@ -1,18 +1,33 @@ +#ifndef DISK_H +#define DISK_H + #include "common.h" typedef char* (*XWhat)(void); typedef s32 (*XHuh)(s32); +typedef void (*XWho)(s32); typedef struct DiskManager { /* 0x00 */ XWhat unk_00; - /* 0x04 */ XWhat unk_04; - /* 0x04 */ XWhat unk_08; - /* 0x04 */ XWhat unk_0C; + /* 0x04 */ XWhat getGamecode; + /* 0x08 */ XWhat unk_08; + /* 0x0C */ XWhat unk_0C; /* 0x10 */ b32 isMounted; - /* 0x14 */ XWhat unk_14; + /* 0x14 */ XWhat getImgName; /* 0x18 */ XHuh unk_18; /* 0x1C */ XWhat unk_1C; - /* 0x20 */ XWhat unk_20; -} DiskManager; + /* 0x20 */ XWho unk_20; +} DiskManager; // size = 0x24 -DiskManager disk_Mgr; +extern DiskManager disk_Mgr; + +char* func_0024A368(void); +char* disk_GetGamecode(void); +char* func_0024A388(void); +char* func_0024A398(void); +char* disk_GetImgName(void); +s32 func_0024A8B0(s32); +s32 func_0024AA88(); +void func_0024AA98(s32); + +#endif // DISK_H diff --git a/kh.jp.yaml b/kh.jp.yaml index cc65b64..75d7cf1 100644 --- a/kh.jp.yaml +++ b/kh.jp.yaml @@ -29,8 +29,7 @@ segments: vram: 0x100000 bss_size: 0x1E1500 subsegments: - - [0x80, asm] - - [0x88, asm] + - [0x80, asm, crt0] - [0x168, c, xbeginning] - [0x1260, c, xporcupine] - [0x15A8, asm] @@ -47,6 +46,9 @@ segments: - [0x3BD28, asm] - [0x49D68, c, xsquash] - [0x4A098, asm] + #################### + # Particle Effects # + #################### - [0x85220, c, ppp/pppKeThLz] - [0x85238, c, ppp/pppKeThCp] - [0x85250, c, ppp/pppKeThCpSft] @@ -475,6 +477,8 @@ segments: - [0x16F360, data] - [0x2DE638, data, xquack] - [0x2DE670, data] + - [0x364368, .data, disk] + - [0x364408, data] - [0x364430, data, libc/impure] - [0x364728, data, libc/malloc_r] - [0x364B80, data, libc/mlock] diff --git a/src/disk.c b/src/disk.c index 152c390..7f2d1a3 100644 --- a/src/disk.c +++ b/src/disk.c @@ -5,7 +5,6 @@ #include "eekernel.h" s32 func_0024A010(void); -char* disk_GetImgName(void); s32 disk_Mount(void); s32 disk_Unmount(void); s32 func_0024A4A8(void); @@ -16,24 +15,37 @@ s32 disk_SetBlock(s32*); extern vu8 D_002C1EB8; -s32 disk_BlockSize; // file length +s32 disk_BlockSize = 0; // file length -s32 D_004642EC; -s32 D_004642F0; -s32 D_004642F4; -s32 D_004642F8; -char D_00464300[]; -char D_00464308[]; -char D_00464320[]; -char D_00464330[]; -char D_00464340[]; -s32 D_00464354; -s32 D_00464358; -extern s32 D_0046435C; -s32 D_00464384; +s32 D_004642EC = 0; +s32 D_004642F0 = 0; +s32 D_004642F4 = 0; +s32 disk_Timer = 0; +char disk_SectorSize[] = "128M"; +char disk_Gamecode[] = "PP.SLPS-25105.0.KINGDOM"; +char D_00464320[] = "haneman0"; +char D_00464330[] = "mangan01"; +char disk_ImgName[] = "pfs0:kingdom.img"; +s32 D_00464354 = 0; +s32 D_00464358 = 0; +s32 D_0046435C = 0; + +struct DiskManager disk_Mgr = { + .unk_00 = func_0024A368, + .getGamecode = disk_GetGamecode, + .unk_08 = func_0024A388, + .unk_0C = func_0024A398, + .isMounted = FALSE, + .getImgName = disk_GetImgName, + .unk_18 = func_0024A8B0, + .unk_1C = func_0024AA88, + .unk_20 = func_0024AA98, +}; + +s32 D_00464384 = 0; extern s32 D_0048DB00; // gp0 value -char D_00663A90[0x1000]; +char disk_ThreadStack[0x1000]; s32 func_0024A010() { return D_004642EC; @@ -41,17 +53,17 @@ s32 func_0024A010() { INCLUDE_ASM(const s32, "disk", func_0024A020); -void func_0024A140(s32 arg0) { - if (0 < arg0) { +void disk_Timeout(s32 time) { + if (0 < time) { do { - D_004642F8++; - arg0--; - } while (arg0 != 0); + disk_Timer++; + time--; + } while (time != 0); } } -s32 func_0024A178() { - return D_004642F8; +s32 disk_GetTimer() { + return disk_Timer; } void func_0024A188(void* sema) { @@ -59,17 +71,18 @@ void func_0024A188(void* sema) { int stat[4]; do { - WaitSema(sema); + WaitSema((s32)sema); D_002C1EB8 = D_002C1EB8 & 0xE7 | 0x10; iVar1 = func_0024A010(); if (iVar1 != 0) { + /* close all files */ sceDevctl("pfs:", PDIOC_CLOSEALL, NULL, 0, NULL, 0); } while (sceDevctl("hdd:", HDIOC_DEV9OFF, NULL, 0, NULL, 0) < 0) { - func_0024A140(100000); + disk_Timeout(100000); } while (sceCdPowerOff(stat) == 0) { - func_0024A140(100000); + disk_Timeout(100000); } D_002C1EB8 |= 0x10 | 0x8; D_004642F0++; @@ -79,13 +92,13 @@ void func_0024A188(void* sema) { void func_0024A278(void* sema) { D_002C1EB8 = D_002C1EB8 & ~(0x10 | 0x8) | 0x8; if (func_0024A010() != 0) { - iSignalSema(sema); + iSignalSema((s32)sema); } } s32* disk_StartThread() { struct ThreadParam threadParam; - void* sema; + s32 sema; struct SemaParam semaParam; int thread; @@ -94,49 +107,40 @@ s32* disk_StartThread() { semaParam.option = 0; sema = CreateSema(&semaParam); threadParam.initPriority = 1; - threadParam.stackSize = sizeof(D_00663A90); + threadParam.stackSize = sizeof(disk_ThreadStack); threadParam.gpReg = &D_0048DB00; threadParam.entry = func_0024A188; - threadParam.stack = D_00663A90; + threadParam.stack = disk_ThreadStack; thread = CreateThread(&threadParam); - StartThread(thread, sema); - return sceCdPOffCallback(func_0024A278, sema); + StartThread(thread, (void*)sema); + return sceCdPOffCallback(func_0024A278, (void*)sema); } char* func_0024A368() { - // return "128M"; - return D_00464300; + return disk_SectorSize; } char* disk_GetGamecode(void) { - // return "PP.SLPS-25105.0.KINGDOM"; - return D_00464308; + return disk_Gamecode; } char* func_0024A388(void) { - // return "haneman0"; return D_00464320; } char* func_0024A398(void) { - // return "mangan01"; return D_00464330; } char* disk_GetImgName() { - // return "pfs0:kingdom.img"; - return D_00464340; + return disk_ImgName; } b32 disk_Mount() { - char* pcVar1; - char* pcVar2; char blkdevname[128]; if (disk_Mgr.isMounted == FALSE) { - pcVar1 = disk_Mgr.unk_04(); - pcVar2 = disk_Mgr.unk_08(); - sprintf(blkdevname, "hdd0:%s,%s", pcVar1, pcVar2); + sprintf(blkdevname, "hdd0:%s,%s", disk_Mgr.getGamecode(), disk_Mgr.unk_08()); if (sceMount("pfs0:", blkdevname, SCE_MT_RDWR, NULL, 0) < 0) { return TRUE; } @@ -184,19 +188,22 @@ s32 disk_GetStatus(void) { return sceDevctl("hdd0:", HDIOC_STATUS, NULL, 0, NULL, 0); } -b32 func_0024A588(char* devname, s32 arg1) { - s32 bufp; +b32 disk_IsSpaceAvailable(char* devname, s32 filesize) { + u32 bufp; // installable size, in number of 256kB sectors + // get total number of sectors on the disk sceDevctl(devname, HDIOC_TOTALSECTOR, NULL, 0, NULL, 0); + D_004642F4 = 60; bufp = NULL; + // return installable size into bufp if space is available if (sceDevctl(devname, HDIOC_FREESECTOR, NULL, 0, &bufp, 4) != 0) { return FALSE; } D_004642F4 = 70; - if ((s32)((u32)bufp >> 0x12) < arg1) { + if ((s32)((u32)bufp >> 0x12) < filesize) { return FALSE; } return TRUE; @@ -206,7 +213,7 @@ s32 func_0024A620(void) { return D_00464354; } -s32 func_0024A630(s32 arg0) { +s32 func_0024A630(s32 blocksize) { char filename[0x40]; s32 fd; int val; @@ -219,7 +226,7 @@ s32 func_0024A630(s32 arg0) { disk_Unmount(); } D_004642F4 = 40; - sprintf(filename, "hdd0:%s,,%s", disk_Mgr.unk_04(), &D_00464330); + sprintf(filename, "hdd0:%s,,%s", disk_Mgr.getGamecode(), &D_00464330); fd = sceOpen(filename, SCE_RDONLY); if (fd >= 0) { temp = sceIoctl2(fd, HIOCNSUB, NULL, 0, NULL, 0); @@ -230,8 +237,8 @@ s32 func_0024A630(s32 arg0) { sceDclose(fd); } D_004642F4 = 50; - val = (((((u32)(arg0 + 0xFFFFF)) >> 20) + 0x7F) >> 7) + 1; - if (func_0024A588("hdd0:", val - temp) == 0) { + val = (((((u32)(blocksize + 0xFFFFF)) >> 20) + 0x7F) >> 7) + 1; + if (disk_IsSpaceAvailable("hdd0:", val - temp) == FALSE) { D_00464354 = -1; } if (mounted != FALSE) { @@ -294,7 +301,7 @@ s32 disk_SetBlock(s32* isoBlock) { return length; } -s32 func_0024A8B0(void) { +s32 func_0024A8B0(s32 arg0) { s32 cond; s32 diskStatus; @@ -307,7 +314,7 @@ s32 func_0024A8B0(void) { D_004642F4 = 10; disk_Unmount(); - if (disk_Seek("hdd0:", D_00464308) != 0) { + if (disk_Seek("hdd0:", disk_Gamecode)) { cond = TRUE; D_00464384 = 1; } else { diff --git a/src/xarcade.c b/src/xarcade.c index e5cd256..a7e801c 100644 --- a/src/xarcade.c +++ b/src/xarcade.c @@ -7,39 +7,40 @@ typedef struct { /* 0x04 */ f32 unk_04; } XArcade; -char D_002B29B0[]; // "host:./kingdom.cnf" -char* D_002B29C8; -s32 D_002B2CB0; -s32 D_002B2CC0; -s32 D_002B2CC4; -u_long128* D_002B2CC8; -u_long128* D_002B2CCC; +extern char D_002B29B0[]; // "host:./kingdom.cnf" +extern char* D_002B29C8; +extern s32 D_002B2CB0; +extern s32 D_002B2CC0; +extern s32 D_002B2CC4; +extern u_long128* D_002B2CC8; +extern u_long128* D_002B2CCC; +extern s32** D_002B8690; +extern s32** D_002B8694; +extern s32 D_002B85C0[4]; +extern sceGsLoadImage D_002B8700; +extern s32 D_002B8870; +extern s32 D_002B8C70; +extern s32 D_002B8C8C; +extern s32* D_002DEC60; +extern s32* D_002DECA0; -s32 D_002B8690; -s32 D_002B8694; -s32 D_002B85C0[4]; -sceGsLoadImage D_002B8700; -s32 D_002B8870; -s32 D_002B8C70; -s32 D_002B8C8C; -s32* D_002DEC60; -s32* D_002DECA0; +extern s32 D_00358BE0; -s32 D_00358BE0; - -char D_004869E0[]; // "host:./kingdom.log" -char D_004869F8[]; // "kingdom.img" -s32 D_0048EBE0; -f32 D_0048EBE4; -f32 D_0048EBFC; -XArcade D_0048EC00; -s32 D_0048EC08; +extern char D_004869E0[]; // "host:./kingdom.log" +extern char D_004869F8[]; // "kingdom.img" +extern s32 D_0048EBE0; +extern f32 D_0048EBE4; +extern f32 D_0048EBFC; +extern XArcade D_0048EC00; +extern s32 D_0048EC08; extern void func_F20000(s32, s32); extern void func_00100240(); // in xbeginning extern void func_00110230(s32); extern void func_0011EDD0(s32*, s32*, s32, s32); +extern u_long128* func_00121C98(s32, u_long128**); extern void func_00122518(); +extern s32* func_00155ED8(s32, s32); extern void func_001600B8(); extern void func_001C20B8(); extern void func_00233968(); diff --git a/src/xbeginning.c b/src/xbeginning.c index 761acdb..f5a86ac 100644 --- a/src/xbeginning.c +++ b/src/xbeginning.c @@ -202,7 +202,7 @@ s32 func_00100328(void) { return 0; } -void main() { +int main() { func_001090D8(); do { func_00109580(); diff --git a/src/xkingdom.c b/src/xkingdom.c index 25a5c4f..ba38d01 100644 --- a/src/xkingdom.c +++ b/src/xkingdom.c @@ -1,6 +1,6 @@ #include "common.h" #include "io.h" - +#include "disk.h" #include "sdk/libcdvd.h" #include "sdk/ee/eekernel.h" #include "sdk/ee/sifdev.h" @@ -213,7 +213,7 @@ void func_00120108(XCrown* arg0) { } if (cond) { - D_00464380(4); + disk_Mgr.unk_20(4); D_002C1EB8 |= 4; do { func_0010BEE8(); diff --git a/src/xpancake.c b/src/xpancake.c index 1fcb87e..8d473e6 100644 --- a/src/xpancake.c +++ b/src/xpancake.c @@ -18,6 +18,10 @@ extern u16 D_002B8C70; f32 D_0048E508; +void func_00106718(void); +void func_00106728(void); +XFlapjack* func_0011EEB8(u16*, s32, s32 (*)(XFlapjack*)); + s32 func_001061D8() { if (((D_002B85C0[0] == 0) || (D_002B860C == 128)) & 0xFFFF) { return 1; @@ -124,12 +128,8 @@ void func_00106790(s32 arg0) { } s32 func_00106828(XFlapjack* arg0) { - f32 new_var = 0.0f; - arg0->unk_10 -= D_002B8340[1]; - if (new_var >= arg0->unk_10) { - if (((arg0->unk_14 == 0) && (!(new_var = arg0->unk_14))) && (new_var == 0)) { - } + if (arg0->unk_10 <= 0.0f) { D_002B860C = 0; return 4; } @@ -142,7 +142,7 @@ void func_00106880(s32 arg0) { f32 f0; s32 val; - if ((D_002B29CC == 1) || (D_002B29D0 == 1)) { + if (D_002B29CC == 1 || D_002B29D0 == 1) { func_00106578(arg0); func_00106718(); func_00106728(); diff --git a/symbol_addrs.txt b/symbol_addrs.txt index 69ad4c8..bc1258b 100644 --- a/symbol_addrs.txt +++ b/symbol_addrs.txt @@ -860,7 +860,10 @@ pppMatrixLoopZYXCalc = 0x0018D5C8; // type:func //============================= // disk.c //============================= +disk_Timeout = 0x0024A140; // type:func +disk_GetTimer = 0x0024A178; // type:func func_0024A278 = 0x0024A278; // type:func +disk_IsSpaceAvailable = 0x0024A588; // type:func disk_StartThread = 0x0024A2D0; // type:func disk_GetGamecode = 0x0024A378; // type:func disk_GetImgName = 0x0024A3A8; // type:func @@ -1985,7 +1988,11 @@ D_004885C0 = 0x004885C0; // type:s32 // disk.c //============================= disk_BlockSize = 0x004642E8; // type:s32 -disk_Mgr = 0x00464360; +disk_Timer = 0x004642F8; // type:s32 +disk_SectorSize = 0x00464300; // type:char +disk_Gamecode = 0x00464308; // type:char +disk_ImgName = 0x00464340; // type:char +disk_Mgr = 0x00464360; // size:0x24 //============================= // lib/libkernl/filestub.c @@ -2002,6 +2009,11 @@ ppvMng = 0x006105A0; ppvUserStopPartF = 0x0061095C; // type:s32 //============================= +// disk.c +//============================= +disk_ThreadStack = 0x00663A90; //size:0x1000 + // lib/libkernl/filestub.c //============================= -_fsversion = 0x00667A68; +_fsversion = 0x00667A68; +//=============================