diff --git a/config/splat.pspeu.main.yaml b/config/splat.pspeu.main.yaml index 5ac9096b09..471852b1c6 100644 --- a/config/splat.pspeu.main.yaml +++ b/config/splat.pspeu.main.yaml @@ -325,7 +325,9 @@ segments: - [0x280FC, c, main_psp/280FC] - [0x28A90, c, main_psp/28A90] - [0x2B69C, c, main_psp/2B69C] - - [0x2D1D4, c, main_psp/dvdumd_io] + - [0x2B910, c, main_psp/sound/2B910] + - [0x2C0E0, c, main_psp/sound/at3plus] + - [0x2D1D4, c, main_psp/sound/dvdumd_io] - [0x2D608, c, main_psp/2D608] - [0x30F3C, asm, func_psp_0892F848] - [0x3104C, asm, func_psp_0892F958] @@ -389,9 +391,10 @@ segments: - [0x47BC4, .data, main_psp/1BCFC] - [0x47D7C, .data, main_psp/2758C] - [0x47DA0, .data, main_psp/280FC] - - [0x6348C, data] - - [0x647C0, .data, main_psp/2B69C] - - [0x649A4, .data, main_psp/dvdumd_io] + - [0x6348C, .data, main_psp/2B69C] + - [0x64538, .data, main_psp/sound/2B910] + - [0x64574, .data, main_psp/sound/at3plus] + - [0x649A4, .data, main_psp/sound/dvdumd_io] - [0x649BC, data] - [0x65808, .data, main_psp/31178] - [0xAEBAC, data] @@ -412,7 +415,9 @@ segments: - {start: 0xAEF24, type: bss, vram: 0x08C63124, name: bss4} - {start: 0xAEF24, type: .bss, vram: 0x08C63C28, name: main_psp/28A90} - {start: 0xAEF24, type: bss, vram: 0x08C6BC30, name: bss5} + - {start: 0xAEF24, type: .bss, vram: 0x08DADC40, name: main_psp/sound/2B910} + - {start: 0xAEF24, type: bss, vram: 0x08DADCB4, name: bss6} - {start: 0xAEF24, type: .bss, vram: 0x08DAF2C8, name: main_psp/31178} - - {start: 0xAEF24, type: bss, vram: 0x08E2E5F8, name: bss6} + - {start: 0xAEF24, type: bss, vram: 0x08E2E5F8, name: bss7} - [0xAEF24, bin, elf_footer] - [0xB3E1C] \ No newline at end of file diff --git a/config/symbols.pspeu.main.txt b/config/symbols.pspeu.main.txt index ada5e9002a..2288ffeab6 100644 --- a/config/symbols.pspeu.main.txt +++ b/config/symbols.pspeu.main.txt @@ -310,23 +310,6 @@ func_psp_08918338 = 0x08918338; // ignore:true _init = 0x089199FC; _fini = 0x08919A04; main = 0x0891A1CC; -strFileOpen = 0x0892A9EC; -strFileRead = 0x0892AB74; -strFileLseek = 0x0892ABE8; -play_bgm = 0x0892ABF0; -init_atrac3plus = 0x0892AC94; -play_atrac3plus = 0x0892AF44; -createPlayModeFlag = 0x0892B2D8; -setPlayMode = 0x0892B2E8; -checkPlayMode = 0x0892B31C; -waitPlayMode = 0x0892B384; -clearPlayMode = 0x0892B394; -release_arg = 0x0892B3C8; -at3plus_addData = 0x0892B440; -reset_position = 0x0892B5CC; -fadeoutOperation = 0x0892B760; -DvdUmdIoInit = 0x0892BAE0; -DvdUmdIoTerm = 0x0892BB60; func_psp_0892C860 = 0x0892C860; // ignore:false func_psp_0892CA28 = 0x0892CA28; // ignore:false func_psp_0892CA90 = 0x0892CA90; // ignore:false @@ -689,7 +672,8 @@ D_psp_08C63BA8 = 0x08C63BA8; // size:0x20 D_psp_08C63BC8 = 0x08C63BC8; // size:0x20 D_psp_08C63BE8 = 0x08C63BE8; // size:0x20 D_psp_08C6BC40 = 0x08C6BC40; -D_psp_08C6FC40 = 0x08C6FC40; +D_psp_08C6FC40 = 0x08C6FC40; // size:0x3E000 +D_psp_08CADC40 = 0x08CADC40; // size:0x3C000 D_psp_08CE9C48 = 0x08CE9C48; D_psp_08D2DC40 = 0x08D2DC40; D_psp_08D6DC40 = 0x08D6DC40; diff --git a/include/pspsdk/pspatrac3.h b/include/pspsdk/pspatrac3.h index 6efce23e26..2bacb89e62 100644 --- a/include/pspsdk/pspatrac3.h +++ b/include/pspsdk/pspatrac3.h @@ -82,9 +82,9 @@ int sceAtracSetDataAndGetID(void *buf, SceSize bufsize); * Decode a frame of data. * * @param atracID - the atrac ID - * @param outSamples - pointer to a buffer that receives the decoded data of the current frame - * @param outN - pointer to a integer that receives the number of audio samples of the decoded frame - * @param outEnd - pointer to a integer that receives a boolean value indicating if the decoded frame is the last one + * @param outAddr - pointer to a buffer that receives the decoded data of the current frame + * @param outSamples - pointer to a integer that receives the number of audio samples of the decoded frame + * @param outFinishFlag - pointer to a integer that receives a boolean value indicating if the decoded frame is the last one * @param outRemainFrame - pointer to a integer that receives either -1 if all at3 data is already on memory, * or the remaining (not decoded yet) frames at memory if not all at3 data is on memory * @@ -92,7 +92,7 @@ int sceAtracSetDataAndGetID(void *buf, SceSize bufsize); * @return < 0 on error, otherwise 0 * */ -int sceAtracDecodeData(int atracID, u16 *outSamples, int *outN, int *outEnd, int *outRemainFrame); +int sceAtracDecodeData(SceInt32 atracID, SceShort16 *outAddr, SceUInt32 *outSamples, SceUInt32 *outFinishFlag, SceInt32 *outRemainFrame); /** * Gets the remaining (not decoded) number of frames diff --git a/src/dra/7E4BC.c b/src/dra/7E4BC.c index 12a6083a8b..98aac94e11 100644 --- a/src/dra/7E4BC.c +++ b/src/dra/7E4BC.c @@ -2507,8 +2507,8 @@ void EntityTeleport(Entity* self) { case 6: PLAYER.palette = PAL_FLAG(PAL_PLAYER_HIDDEN); #ifdef VERSION_PSP - func_psp_0892A620(0, 1); - func_psp_0892A620(1, 1); + func_psp_0892A620(0, true); + func_psp_0892A620(1, true); #endif var_s5 = true; if (--self->ext.teleport.timer == 0) { diff --git a/src/dra/game_handlers.c b/src/dra/game_handlers.c index 777210b43e..9fecc8a60c 100644 --- a/src/dra/game_handlers.c +++ b/src/dra/game_handlers.c @@ -496,8 +496,8 @@ void HandlePlay(void) { PlaySfx(SET_UNK_0B); MuteSound(); #ifdef VERSION_PSP - func_psp_0892A620(0, 1); - func_psp_0892A620(1, 1); + func_psp_0892A620(0, true); + func_psp_0892A620(1, true); #endif if (D_80097C98 & 0x80000000) { func_800E4970(); @@ -532,8 +532,8 @@ void HandlePlay(void) { } if (D_80097C98 & 0x08000000) { #ifdef VERSION_PSP - func_psp_0892A620(0, 1); - func_psp_0892A620(1, 1); + func_psp_0892A620(0, true); + func_psp_0892A620(1, true); #endif func_800E4970(); return; diff --git a/src/dra/sound.c b/src/dra/sound.c index 319d6c0f7b..e394cad1c5 100644 --- a/src/dra/sound.c +++ b/src/dra/sound.c @@ -1419,8 +1419,8 @@ void ExecSoundCommands(void) { case SET_UNK_0B: AddCdSoundCommand(CD_SOUND_COMMAND_FADE_OUT_2); #ifdef VERSION_PSP - func_psp_0892A620(0, 0); - func_psp_0892A620(1, 0); + func_psp_0892A620(0, false); + func_psp_0892A620(1, false); #endif StopSeq(); SetReleaseRate2(); @@ -1429,8 +1429,8 @@ void ExecSoundCommands(void) { case SET_UNK_0C: AddCdSoundCommand(CD_SOUND_COMMAND_FADE_OUT_2); #ifdef VERSION_PSP - func_psp_0892A620(0, 0); - func_psp_0892A620(1, 0); + func_psp_0892A620(0, false); + func_psp_0892A620(1, false); #endif StopSeq(); SoundWait(); diff --git a/src/dra_psp/1DDC0.c b/src/dra_psp/1DDC0.c index c9d7aeaeb7..7f068d8308 100644 --- a/src/dra_psp/1DDC0.c +++ b/src/dra_psp/1DDC0.c @@ -536,7 +536,7 @@ s32 func_psp_090FAB30(s32 fileId, SimFileType type, bool arg2) { s32 var_a0; s32 i; - s32 var_s2; + s32 ovlIndex; s32 var_s1; s32 var_s0; s32 var_s6; @@ -545,163 +545,163 @@ s32 func_psp_090FAB30(s32 fileId, SimFileType type, bool arg2) { u32* dst; g_SimFile = &D_800A024C[fileId]; - var_s2 = -1; + ovlIndex = -1; if (type == SimFileType_StagePrg) { if (strcmp(g_StagesLba[g_StageId].ovlName, "SEL") == 0) { - var_s2 = 1; + ovlIndex = 1; } if (strcmp(g_StagesLba[g_StageId].ovlName, "ST0") == 0) { - var_s2 = 2; + ovlIndex = 2; } if (strcmp(g_StagesLba[g_StageId].ovlName, "ARE") == 0) { - var_s2 = 3; + ovlIndex = 3; } if (strcmp(g_StagesLba[g_StageId].ovlName, "CAT") == 0) { - var_s2 = 4; + ovlIndex = 4; } if (strcmp(g_StagesLba[g_StageId].ovlName, "CEN") == 0) { - var_s2 = 5; + ovlIndex = 5; } if (strcmp(g_StagesLba[g_StageId].ovlName, "CHI") == 0) { - var_s2 = 6; + ovlIndex = 6; } if (strcmp(g_StagesLba[g_StageId].ovlName, "DAI") == 0) { - var_s2 = 7; + ovlIndex = 7; } if (strcmp(g_StagesLba[g_StageId].ovlName, "DRE") == 0) { - var_s2 = 8; + ovlIndex = 8; } if (strcmp(g_StagesLba[g_StageId].ovlName, "LIB") == 0) { - var_s2 = 9; + ovlIndex = 9; } if (strcmp(g_StagesLba[g_StageId].ovlName, "NO0") == 0) { - var_s2 = 0xA; + ovlIndex = 0xA; } if (strcmp(g_StagesLba[g_StageId].ovlName, "NO1") == 0) { - var_s2 = 0xB; + ovlIndex = 0xB; } if (strcmp(g_StagesLba[g_StageId].ovlName, "NO2") == 0) { - var_s2 = 0xC; + ovlIndex = 0xC; } if (strcmp(g_StagesLba[g_StageId].ovlName, "NO3") == 0) { - var_s2 = 0xD; + ovlIndex = 0xD; } if (strcmp(g_StagesLba[g_StageId].ovlName, "NO4") == 0) { - var_s2 = 0xE; + ovlIndex = 0xE; } if (strcmp(g_StagesLba[g_StageId].ovlName, "NP3") == 0) { - var_s2 = 0xF; + ovlIndex = 0xF; } if (strcmp(g_StagesLba[g_StageId].ovlName, "NZ0") == 0) { - var_s2 = 0x10; + ovlIndex = 0x10; } if (strcmp(g_StagesLba[g_StageId].ovlName, "NZ1") == 0) { - var_s2 = 0x11; + ovlIndex = 0x11; } if (strcmp(g_StagesLba[g_StageId].ovlName, "TOP") == 0) { - var_s2 = 0x12; + ovlIndex = 0x12; } if (strcmp(g_StagesLba[g_StageId].ovlName, "WRP") == 0) { - var_s2 = 0x13; + ovlIndex = 0x13; } if (strcmp(g_StagesLba[g_StageId].ovlName, "RARE") == 0) { - var_s2 = 0x14; + ovlIndex = 0x14; } if (strcmp(g_StagesLba[g_StageId].ovlName, "RCAT") == 0) { - var_s2 = 0x15; + ovlIndex = 0x15; } if (strcmp(g_StagesLba[g_StageId].ovlName, "RCEN") == 0) { - var_s2 = 0x16; + ovlIndex = 0x16; } if (strcmp(g_StagesLba[g_StageId].ovlName, "RCHI") == 0) { - var_s2 = 0x17; + ovlIndex = 0x17; } if (strcmp(g_StagesLba[g_StageId].ovlName, "RDAI") == 0) { - var_s2 = 0x18; + ovlIndex = 0x18; } if (strcmp(g_StagesLba[g_StageId].ovlName, "RLIB") == 0) { - var_s2 = 0x19; + ovlIndex = 0x19; } if (strcmp(g_StagesLba[g_StageId].ovlName, "RNO0") == 0) { - var_s2 = 0x1A; + ovlIndex = 0x1A; } if (strcmp(g_StagesLba[g_StageId].ovlName, "RNO1") == 0) { - var_s2 = 0x1B; + ovlIndex = 0x1B; } if (strcmp(g_StagesLba[g_StageId].ovlName, "RNO2") == 0) { - var_s2 = 0x1C; + ovlIndex = 0x1C; } if (strcmp(g_StagesLba[g_StageId].ovlName, "RNO3") == 0) { - var_s2 = 0x1D; + ovlIndex = 0x1D; } if (strcmp(g_StagesLba[g_StageId].ovlName, "RNO4") == 0) { - var_s2 = 0x1E; + ovlIndex = 0x1E; } if (strcmp(g_StagesLba[g_StageId].ovlName, "RNZ0") == 0) { - var_s2 = 0x1F; + ovlIndex = 0x1F; } if (strcmp(g_StagesLba[g_StageId].ovlName, "RNZ1") == 0) { - var_s2 = 0x20; + ovlIndex = 0x20; } if (strcmp(g_StagesLba[g_StageId].ovlName, "RTOP") == 0) { - var_s2 = 0x21; + ovlIndex = 0x21; } if (strcmp(g_StagesLba[g_StageId].ovlName, "RWRP") == 0) { - var_s2 = 0x22; + ovlIndex = 0x22; } if (strcmp(g_StagesLba[g_StageId].ovlName, "MAR") == 0) { - var_s2 = 0x23; + ovlIndex = 0x23; } if (strcmp(g_StagesLba[g_StageId].ovlName, "BO0") == 0) { - var_s2 = 0x24; + ovlIndex = 0x24; } if (strcmp(g_StagesLba[g_StageId].ovlName, "BO1") == 0) { - var_s2 = 0x25; + ovlIndex = 0x25; } if (strcmp(g_StagesLba[g_StageId].ovlName, "BO2") == 0) { - var_s2 = 0x26; + ovlIndex = 0x26; } if (strcmp(g_StagesLba[g_StageId].ovlName, "BO3") == 0) { - var_s2 = 0x27; + ovlIndex = 0x27; } if (strcmp(g_StagesLba[g_StageId].ovlName, "BO4") == 0) { - var_s2 = 0x28; + ovlIndex = 0x28; } if (strcmp(g_StagesLba[g_StageId].ovlName, "BO5") == 0) { - var_s2 = 0x29; + ovlIndex = 0x29; } if (strcmp(g_StagesLba[g_StageId].ovlName, "BO6") == 0) { - var_s2 = 0x2A; + ovlIndex = 0x2A; } if (strcmp(g_StagesLba[g_StageId].ovlName, "BO7") == 0) { - var_s2 = 0x2B; + ovlIndex = 0x2B; } if (strcmp(g_StagesLba[g_StageId].ovlName, "RBO0") == 0) { - var_s2 = 0x2C; + ovlIndex = 0x2C; } if (strcmp(g_StagesLba[g_StageId].ovlName, "RBO1") == 0) { - var_s2 = 0x2D; + ovlIndex = 0x2D; } if (strcmp(g_StagesLba[g_StageId].ovlName, "RBO2") == 0) { - var_s2 = 0x2E; + ovlIndex = 0x2E; } if (strcmp(g_StagesLba[g_StageId].ovlName, "RBO3") == 0) { - var_s2 = 0x2F; + ovlIndex = 0x2F; } if (strcmp(g_StagesLba[g_StageId].ovlName, "RBO4") == 0) { - var_s2 = 0x30; + ovlIndex = 0x30; } if (strcmp(g_StagesLba[g_StageId].ovlName, "RBO5") == 0) { - var_s2 = 0x31; + ovlIndex = 0x31; } if (strcmp(g_StagesLba[g_StageId].ovlName, "RBO6") == 0) { - var_s2 = 0x32; + ovlIndex = 0x32; } if (strcmp(g_StagesLba[g_StageId].ovlName, "RBO7") == 0) { - var_s2 = 0x33; + ovlIndex = 0x33; } if (strcmp(g_StagesLba[g_StageId].ovlName, "RBO8") == 0) { - var_s2 = 0x34; + ovlIndex = 0x34; } g_SimFile = &D_80136450; strcpy(buf, "hdbin/"); @@ -807,7 +807,7 @@ s32 func_psp_090FAB30(s32 fileId, SimFileType type, bool arg2) { } if (type == SimFileType_Weapon0Prg) { g_SimFile = &D_80136450; - var_s2 = fileId + 0x3F; + ovlIndex = fileId + 0x3F; sprintf(buf, "hdbin/w0_%03d.bin;1", fileId); g_SimFile->path = buf; g_SimFile->addr = &D_8017A000; @@ -819,7 +819,7 @@ s32 func_psp_090FAB30(s32 fileId, SimFileType type, bool arg2) { } if (type == SimFileType_Weapon1Prg) { g_SimFile = &D_80136450; - var_s2 = fileId + 0x7A; + ovlIndex = fileId + 0x7A; sprintf(buf, "hdbin/w1_%03d.bin;1", fileId); g_SimFile->path = buf; g_SimFile->addr = WEAPON1_PTR; @@ -849,7 +849,7 @@ s32 func_psp_090FAB30(s32 fileId, SimFileType type, bool arg2) { } if (type == SimFileType_FamiliarPrg) { g_SimFile = &D_80136450; - var_s2 = fileId + 0x38; + ovlIndex = fileId + 0x38; sprintf(buf, "hdbin/tt_%03d.bin;1", fileId); g_SimFile->path = buf; g_SimFile->addr = &g_ServantDesc; @@ -950,13 +950,13 @@ s32 func_psp_090FAB30(s32 fileId, SimFileType type, bool arg2) { if (strcmp(g_SimFile->path, "hdbin/ric.bin;1") == 0) { if (g_PlayableCharacter != 2) { var_s1 = func_psp_089330C4(); - var_s2 = 0x35; + ovlIndex = 0x35; } else { var_s1 = func_psp_089330C4(); - var_s2 = 0x37; + ovlIndex = 0x37; } } else if (strcmp(g_SimFile->path, "hdbin/arc_f.bin;1") == 0) { - var_s2 = 0x36; + ovlIndex = 0x36; var_s1 = func_psp_089330C4(); } var_s0 = func_psp_0893310C(); @@ -972,11 +972,11 @@ s32 func_psp_090FAB30(s32 fileId, SimFileType type, bool arg2) { FntPrint("tr err\n"); return -1; } - if (var_s2 >= 0) { + if (ovlIndex >= 0) { if (arg2) { - func_psp_0892A0F0(var_s2, var_s6, var_s0); + LoadOverlay(ovlIndex, var_s6, var_s0); } else { - func_psp_0892A1EC(var_s2); + func_psp_0892A1EC(ovlIndex); } } return 0; diff --git a/src/dra_psp/63C08.c b/src/dra_psp/63C08.c index f261bd475c..34e82acde4 100644 --- a/src/dra_psp/63C08.c +++ b/src/dra_psp/63C08.c @@ -1049,7 +1049,7 @@ static void AdvanceCdSoundCommandQueue(void) { g_CdSoundCommandQueuePos--; } -static s32 func_psp_09141550(s32 arg0) { +static bool func_psp_09141550(s32 arg0) { if (arg0 == 2) { return true; } @@ -1103,10 +1103,11 @@ s32 func_psp_09141668(s32 arg0) { s32 sp1C; s32 sp18; s32 i; - s32 var_s0, var_s1; + u8* var_s0; + s32 var_s1; s8* fileName; - var_s0 = 0; + var_s0 = NULL; var_s1 = 0; i = func_psp_09141608(arg0); func_psp_09141570(i, &sp1C, &sp18); @@ -1120,11 +1121,11 @@ s32 func_psp_09141668(s32 arg0) { sprintf(D_psp_09236888, "disc0:/PSP_GAME/USRDIR/res/ps/%sPS_BGM/%s", D_psp_08B42060, at3FileNames[i]); if (func_psp_09141550(i)) { - var_s0 = func_psp_08933F5C(); + var_s0 = (u8*)func_psp_08933F5C(); var_s1 = func_psp_08933F6C(); } - func_psp_0892A620(~sp18 & 1, 1); - func_psp_0892A414(sp18, D_psp_09236888, 1, sp1C, var_s0, var_s1); + func_psp_0892A620(~sp18 & 1, true); + func_psp_0892A414(sp18, D_psp_09236888, true, sp1C, var_s0, var_s1); } else { sprintf(D_psp_09236888, "%sXA/%s", D_psp_08B42060, at3FileNames[i]); if (func_psp_0890FA7C(D_psp_09236888) < 0) { @@ -1133,7 +1134,7 @@ s32 func_psp_09141668(s32 arg0) { D_psp_09236880 = i; sprintf(D_psp_09236888, "disc0:/PSP_GAME/USRDIR/res/ps/%sXA/%s", D_psp_08B42060, at3FileNames[i]); - func_psp_0892A414(sp18, D_psp_09236888, 0, sp1C, 0, 0); + func_psp_0892A414(sp18, D_psp_09236888, false, sp1C, NULL, 0); } return sp1C; } @@ -1141,7 +1142,7 @@ s32 func_psp_09141668(s32 arg0) { char* GetAT3FileName(s32 at3Index) { return at3FileNames[at3Index]; } void func_psp_09141878(s32 at3Index) { - func_psp_0892A620(0, 0); + func_psp_0892A620(0, false); SetCdVolume(0, 0x7F, 0x7F); if (at3Index >= 0 && at3Index <= 0x230) { func_psp_09141668(at3Index); @@ -1253,7 +1254,7 @@ void CdFadeOut1(void) { break; case 1: - func_psp_0892A620(func_psp_091415E0(D_psp_092374B0), 0); + func_psp_0892A620(func_psp_091415E0(D_psp_092374B0), false); func_psp_09140588(0); SetMaxVolume(); D_801390A0 = g_CdSoundCommandStep = 0; @@ -1286,7 +1287,7 @@ void CdFadeOut2(void) { break; case 1: - func_psp_0892A620(func_psp_091415E0(D_psp_092374B8), 0); + func_psp_0892A620(func_psp_091415E0(D_psp_092374B8), false); func_psp_09140588(0); D_801390A0 = g_CdSoundCommandStep = 0; AdvanceCdSoundCommandQueue(); @@ -1318,8 +1319,8 @@ void func_psp_09141E30(void) { break; case 1: - func_psp_0892A620(0, 0); - func_psp_0892A620(1, 0); + func_psp_0892A620(0, false); + func_psp_0892A620(1, false); func_psp_09140588(0); D_801390A0 = g_CdSoundCommandStep = 0; AdvanceCdSoundCommandQueue(); @@ -2084,8 +2085,8 @@ void ExecSoundCommands(void) { case SET_UNK_0B: AddCdSoundCommand(CD_SOUND_COMMAND_FADE_OUT_2); #ifdef VERSION_PSP - func_psp_0892A620(0, 0); - func_psp_0892A620(1, 0); + func_psp_0892A620(0, false); + func_psp_0892A620(1, false); #endif StopSeq(); SetReleaseRate2(); @@ -2094,8 +2095,8 @@ void ExecSoundCommands(void) { case SET_UNK_0C: AddCdSoundCommand(CD_SOUND_COMMAND_FADE_OUT_2); #ifdef VERSION_PSP - func_psp_0892A620(0, 0); - func_psp_0892A620(1, 0); + func_psp_0892A620(0, false); + func_psp_0892A620(1, false); #endif StopSeq(); SoundWait(); diff --git a/src/main_psp/10944.c b/src/main_psp/10944.c index c5edf02fba..23af170055 100644 --- a/src/main_psp/10944.c +++ b/src/main_psp/10944.c @@ -30,10 +30,10 @@ s32 func_psp_0890F300(char* file, SceIoStat* stat) { s32 ret; sceKernelDelayThreadCB(1); - func_psp_08912608(); + LockPowerSwitch(); sceKernelDelayThreadCB(1); ret = sceIoGetstat(file, stat); - func_psp_08912640(); + UnlockPowerSwitch(); sceKernelDelayThreadCB(1); return ret; } @@ -42,10 +42,10 @@ s32 func_psp_0890F374(s32 fd) { s32 ret; sceKernelDelayThreadCB(1); - func_psp_08912608(); + LockPowerSwitch(); sceKernelDelayThreadCB(1); ret = sceIoClose(fd); - func_psp_08912640(); + UnlockPowerSwitch(); sceKernelDelayThreadCB(1); return ret; } @@ -54,10 +54,10 @@ s32 func_psp_0890F3E0(char* file, s32 flags, s32 mode) { s32 ret; sceKernelDelayThreadCB(1); - func_psp_08912608(); + LockPowerSwitch(); sceKernelDelayThreadCB(1); ret = sceIoOpenAsync(file, flags, mode); - func_psp_08912640(); + UnlockPowerSwitch(); sceKernelDelayThreadCB(1); return ret; } @@ -66,10 +66,10 @@ s32 func_psp_0890F45C(s32 fd, s64 offset, s32 whence) { s32 ret; sceKernelDelayThreadCB(1); - func_psp_08912608(); + LockPowerSwitch(); sceKernelDelayThreadCB(1); ret = sceIoLseekAsync(fd, offset, whence); - func_psp_08912640(); + UnlockPowerSwitch(); sceKernelDelayThreadCB(1); return ret; } @@ -78,10 +78,10 @@ s32 func_psp_0890F4E0(s32 fd, void* buf, u32 nbyte) { s32 ret; sceKernelDelayThreadCB(1); - func_psp_08912608(); + LockPowerSwitch(); sceKernelDelayThreadCB(1); ret = sceIoReadAsync(fd, buf, nbyte); - func_psp_08912640(); + UnlockPowerSwitch(); sceKernelDelayThreadCB(1); return ret; } @@ -90,10 +90,10 @@ s32 func_psp_0890F55C(s32 fd, s64* result) { s32 ret; sceKernelDelayThreadCB(1); - func_psp_08912608(); + LockPowerSwitch(); sceKernelDelayThreadCB(1); ret = sceIoPollAsync(fd, result); - func_psp_08912640(); + UnlockPowerSwitch(); sceKernelDelayThreadCB(1); return ret; } diff --git a/src/main_psp/138B0.c b/src/main_psp/138B0.c index d63ea3ddf9..999a10d4bb 100644 --- a/src/main_psp/138B0.c +++ b/src/main_psp/138B0.c @@ -20,7 +20,7 @@ static bool audioOn; static s32 D_psp_08B1FB78; static s32 D_psp_08B1FB74; static bool D_psp_08B1FB70; -static s32 D_psp_08B1FB6C; +static s32 powerLockCount; static s32 D_psp_08B1FB68; static s32 D_psp_08B1FB64; static bool D_psp_08B1FB60; @@ -155,19 +155,19 @@ s32 power_func(s32 count, s32 arg, void* param) { s32 func_psp_089125F8(void) { return D_psp_08B1FB64; } -void func_psp_08912608(void) { +void LockPowerSwitch(void) { sceKernelPowerLock(0); - D_psp_08B1FB6C++; + powerLockCount++; } -void func_psp_08912640(void) { +void UnlockPowerSwitch(void) { volatile s32* var_s0; - if (D_psp_08B1FB6C <= 0) { - var_s0 = &D_psp_08B1FB6C; + if (powerLockCount <= 0) { + var_s0 = &powerLockCount; *var_s0; } - D_psp_08B1FB6C--; + powerLockCount--; sceKernelPowerUnlock(0); } @@ -182,7 +182,7 @@ void func_psp_0891269C(void) { } ret = scePowerRegisterCallback(0, power_cb); ret; - D_psp_08B1FB6C = 0; + powerLockCount = 0; D_psp_08B1FB68 = sceKernelCreateSema("p_off_lock_sema", 0, 1, 1, NULL); } @@ -442,12 +442,12 @@ s32 func_psp_089128C4(s32 movieIdx, s32 skipButton) { } sceKernelChangeThreadPriority(sceKernelGetThreadId(), 0x40); dispThread = sceKernelCreateThread( - "displayThread", dispbuf_func, 0x3F, 0x2000, 0, 0); + "displayThread", dispbuf_func, 0x3F, 0x2000, 0, NULL); readThread = - sceKernelCreateThread("readThread", read_func, 0x41, 0x2000, 0, 0); + sceKernelCreateThread("readThread", read_func, 0x41, 0x2000, 0, NULL); if (audioOn) { soundThread = sceKernelCreateThread( - "soundThread", soundbuf_func, 0x3D, 0x2000, 0, 0); + "soundThread", soundbuf_func, 0x3D, 0x2000, 0, NULL); } playMode = PLAY_NORMAL; if (audioOn) { diff --git a/src/main_psp/2B69C.c b/src/main_psp/2B69C.c index 4b7036ed8a..d97aba2438 100644 --- a/src/main_psp/2B69C.c +++ b/src/main_psp/2B69C.c @@ -1,360 +1,255 @@ // SPDX-License-Identifier: AGPL-3.0-or-later -//! PSPO=4,p #include -// https://pspdev.github.io/pspsdk/ -#define PSP_LEGACY_TYPES_DEFINED // avoid processing psptypes.h -#include -#include -#include -#include - -extern char D_psp_08962E80[]; -extern char D_psp_08962E88[]; -extern char D_psp_08962E90[]; -extern char D_psp_08962E98[]; -extern char D_psp_08962EBC[]; -extern char D_psp_08962F50[]; -extern char D_psp_08962FCC[]; -extern char D_psp_08962EDC[]; -extern u32 D_psp_08DADCB4; - -typedef struct { - SceUID fd; - char assignName[10]; -} StrFile; +typedef void (*LoadFunc)(void); typedef struct { - s32 atracID; // ATRAC playback ID - StrFile strFile; // File structure - SceUID playFlag; // Event flag indicating status Used for cueing, playing, - // and ending - s32 outputChannel; // Channel when outputting to libwave - s32 iEndSample; - s32 iVol; - s32 unk24; - s32 unk28; -} SceAtracArg; - -typedef struct { - char* filename; // "ATRAC3plus" file - u8* pucFirstBuf; // FirstBuffer starting address - s32 iFirstBufSize; // FirstBuffer size - u8* pucSecondBuf; // SecondBuffer starting address - s32 iSecondBufSize; // SecondBuffer size - s32 iOutputChannel; // Output channel - SceUID playFlag; // Event flag for setting playback mode -} SceBGMArg; + s32 type; + char* ovlName; + void* dst; + LoadFunc load; +} unkStruct; // clang-format off -// Values for setting playback mode and EVENTFLAG -#define BGM_INIT_END (0x00000001U) // Status when playback initialization ended -#define BGM_PLAY_START (0x00000002U) // State when playback start instruction was received -#define BGM_RESET_POSITION (0x00000004U) // Status when playback position changes -#define BGM_PLAY_FINISH (0x00000008U) // Status when playback termination is specified -#define BGM_UNK_10 (0x00000010U) +static unkStruct D_psp_089622C8[] = { + {1, "dra", NULL, (LoadFunc)0x00000000}, + {2, "sel", NULL, (LoadFunc)0x09237868}, + {2, "st0", NULL, (LoadFunc)0x09246B10}, + {2, "are", NULL, (LoadFunc)0x092379E8}, + {2, "cat", NULL, (LoadFunc)0x0925E600}, + {2, "cen", NULL, (LoadFunc)0x09260988}, + {2, "chi", NULL, (LoadFunc)0x0924BCA8}, + {2, "dai", NULL, (LoadFunc)0x09251430}, + {2, "dre", NULL, (LoadFunc)0x09244A50}, + {2, "lib", NULL, (LoadFunc)0x09254120}, + {2, "no0", NULL, (LoadFunc)0x0925D048}, + {2, "no1", NULL, (LoadFunc)0x09255C38}, + {2, "no2", NULL, (LoadFunc)0x09256C90}, + {2, "no3", NULL, (LoadFunc)0x09238360}, + {2, "no4", NULL, (LoadFunc)0x09237FB0}, + {2, "np3", NULL, (LoadFunc)0x09237A90}, + {2, "nz0", NULL, (LoadFunc)0x09237AB0}, + {2, "nz1", NULL, (LoadFunc)0x09253460}, + {2, "top", NULL, (LoadFunc)0x09248480}, + {2, "wrp", NULL, (LoadFunc)0x092447C0}, + {2, "rare", NULL, (LoadFunc)0x09237840}, + {2, "rcat", NULL, (LoadFunc)0x0924C6D8}, + {2, "rcen", NULL, (LoadFunc)0x09244F30}, + {2, "rchi", NULL, (LoadFunc)0x0924A488}, + {2, "rdai", NULL, (LoadFunc)0x0924F318}, + {2, "rlib", NULL, (LoadFunc)0x09249828}, + {2, "rno0", NULL, (LoadFunc)0x0925D410}, + {2, "rno1", NULL, (LoadFunc)0x092497F8}, + {2, "rno2", NULL, (LoadFunc)0x09253588}, + {2, "rno3", NULL, (LoadFunc)0x09255FB0}, + {2, "rno4", NULL, (LoadFunc)0x09251F90}, + {2, "rnz0", NULL, (LoadFunc)0x09256B38}, + {2, "rnz1", NULL, (LoadFunc)0x09252CD8}, + {2, "rtop", NULL, (LoadFunc)0x09247898}, + {2, "rwrp", NULL, (LoadFunc)0x09244D08}, + {2, "mar", NULL, (LoadFunc)0x092465C8}, + {2, "bo0", NULL, (LoadFunc)0x09251368}, + {2, "bo1", NULL, (LoadFunc)0x09245870}, + {2, "bo2", NULL, (LoadFunc)0x09245D30}, + {2, "bo3", NULL, (LoadFunc)0x09246198}, + {2, "bo4", NULL, (LoadFunc)0x092478E8}, + {2, "bo5", NULL, (LoadFunc)0x092473A0}, + {2, "bo6", NULL, (LoadFunc)0x09244758}, + {2, "bo7", NULL, (LoadFunc)0x09245D08}, + {2, "rbo0", NULL, (LoadFunc)0x09237858}, + {2, "rbo1", NULL, (LoadFunc)0x09248780}, + {2, "rbo2", NULL, (LoadFunc)0x09245DF0}, + {2, "rbo3", NULL, (LoadFunc)0x09245800}, + {2, "rbo4", NULL, (LoadFunc)0x09245F70}, + {2, "rbo5", NULL, (LoadFunc)0x0925F690}, + {2, "rbo6", NULL, (LoadFunc)0x09244A00}, + {2, "rbo7", NULL, (LoadFunc)0x09245D40}, + {2, "rbo8", NULL, (LoadFunc)0x09245C58}, + {3, "ric", NULL, (LoadFunc)0x092C8D48}, + {3, "arc_f", NULL, (LoadFunc)0x092A6280}, + {3, "maria", NULL, (LoadFunc)0x092C0280}, + {4, "tt_000", NULL, (LoadFunc)0x092EC220}, + {4, "tt_001", NULL, (LoadFunc)0x092EA620}, + {4, "tt_002", NULL, (LoadFunc)0x092EF290}, + {4, "tt_003", NULL, (LoadFunc)0x092EF908}, + {4, "tt_004", NULL, (LoadFunc)0x092EF780}, + {4, "tt_005", NULL, (LoadFunc)0x092EF290}, + {4, "tt_006", NULL, (LoadFunc)0x092EF908}, + {5, "w0_000", NULL, (LoadFunc)0x092F3498}, + {5, "w0_001", NULL, (LoadFunc)0x092F48A0}, + {5, "w0_002", NULL, (LoadFunc)0x092F3490}, + {5, "w0_003", NULL, (LoadFunc)0x092F3498}, + {5, "w0_004", NULL, (LoadFunc)0x092F34A8}, + {5, "w0_005", NULL, (LoadFunc)0x092F3500}, + {5, "w0_006", NULL, (LoadFunc)0x092F40F8}, + {5, "w0_007", NULL, (LoadFunc)0x092F4020}, + {5, "w0_008", NULL, (LoadFunc)0x092F4B80}, + {5, "w0_009", NULL, (LoadFunc)0x092F4D98}, + {5, "w0_010", NULL, (LoadFunc)0x092F59D0}, + {5, "w0_011", NULL, (LoadFunc)0x092F5740}, + {5, "w0_012", NULL, (LoadFunc)0x092F4650}, + {5, "w0_013", NULL, (LoadFunc)0x092F4AB0}, + {5, "w0_014", NULL, (LoadFunc)0x092F4418}, + {5, "w0_015", NULL, (LoadFunc)0x092F4D88}, + {5, "w0_016", NULL, (LoadFunc)0x092F4E68}, + {5, "w0_017", NULL, (LoadFunc)0x092F3C30}, + {5, "w0_018", NULL, (LoadFunc)0x092F3900}, + {5, "w0_019", NULL, (LoadFunc)0x092F3818}, + {5, "w0_020", NULL, (LoadFunc)0x092F4E18}, + {5, "w0_021", NULL, (LoadFunc)0x092F4D08}, + {5, "w0_022", NULL, (LoadFunc)0x092F3740}, + {5, "w0_023", NULL, (LoadFunc)0x092F5798}, + {5, "w0_024", NULL, (LoadFunc)0x092F59F8}, + {5, "w0_025", NULL, (LoadFunc)0x092F5880}, + {5, "w0_026", NULL, (LoadFunc)0x092F5A70}, + {5, "w0_027", NULL, (LoadFunc)0x092F5140}, + {5, "w0_028", NULL, (LoadFunc)0x092F5A10}, + {5, "w0_029", NULL, (LoadFunc)0x092F5300}, + {5, "w0_030", NULL, (LoadFunc)0x092F6378}, + {5, "w0_031", NULL, (LoadFunc)0x092F3508}, + {5, "w0_032", NULL, (LoadFunc)0x092F35B8}, + {5, "w0_033", NULL, (LoadFunc)0x092F34E8}, + {5, "w0_034", NULL, (LoadFunc)0x092F3C28}, + {5, "w0_035", NULL, (LoadFunc)0x092F3498}, + {5, "w0_036", NULL, (LoadFunc)0x092F3498}, + {5, "w0_037", NULL, (LoadFunc)0x092F4670}, + {5, "w0_038", NULL, (LoadFunc)0x092F39F0}, + {5, "w0_039", NULL, (LoadFunc)0x092F3CC0}, + {5, "w0_040", NULL, (LoadFunc)0x092F3ED0}, + {5, "w0_041", NULL, (LoadFunc)0x092F3E18}, + {5, "w0_042", NULL, (LoadFunc)0x092F4010}, + {5, "w0_043", NULL, (LoadFunc)0x092F3F10}, + {5, "w0_044", NULL, (LoadFunc)0x092F3EE8}, + {5, "w0_045", NULL, (LoadFunc)0x092F4058}, + {5, "w0_046", NULL, (LoadFunc)0x092F4738}, + {5, "w0_047", NULL, (LoadFunc)0x092F4500}, + {5, "w0_048", NULL, (LoadFunc)0x092F47C8}, + {5, "w0_049", NULL, (LoadFunc)0x092F4E58}, + {5, "w0_050", NULL, (LoadFunc)0x092F5358}, + {5, "w0_051", NULL, (LoadFunc)0x092F47C0}, + {5, "w0_052", NULL, (LoadFunc)0x092F58C0}, + {5, "w0_053", NULL, (LoadFunc)0x092F4BC8}, + {5, "w0_054", NULL, (LoadFunc)0x092F39E8}, + {5, "w0_055", NULL, (LoadFunc)0x092F3AE0}, + {5, "w0_056", NULL, (LoadFunc)0x092F4368}, + {5, "w0_057", NULL, (LoadFunc)0x092F3498}, + {5, "w0_058", NULL, (LoadFunc)0x092F43C0}, + {6, "w1_000", NULL, (LoadFunc)0x092F7298}, + {6, "w1_001", NULL, (LoadFunc)0x092F86A0}, + {6, "w1_002", NULL, (LoadFunc)0x092F7290}, + {6, "w1_003", NULL, (LoadFunc)0x092F7298}, + {6, "w1_004", NULL, (LoadFunc)0x092F72A8}, + {6, "w1_005", NULL, (LoadFunc)0x092F7300}, + {6, "w1_006", NULL, (LoadFunc)0x092F7EF8}, + {6, "w1_007", NULL, (LoadFunc)0x092F7E20}, + {6, "w1_008", NULL, (LoadFunc)0x092F8980}, + {6, "w1_009", NULL, (LoadFunc)0x092F8B98}, + {6, "w1_010", NULL, (LoadFunc)0x092F97D0}, + {6, "w1_011", NULL, (LoadFunc)0x092F9540}, + {6, "w1_012", NULL, (LoadFunc)0x092F8450}, + {6, "w1_013", NULL, (LoadFunc)0x092F88B0}, + {6, "w1_014", NULL, (LoadFunc)0x092F8218}, + {6, "w1_015", NULL, (LoadFunc)0x092F8B88}, + {6, "w1_016", NULL, (LoadFunc)0x092F8C68}, + {6, "w1_017", NULL, (LoadFunc)0x092F7A30}, + {6, "w1_018", NULL, (LoadFunc)0x092F7700}, + {6, "w1_019", NULL, (LoadFunc)0x092F7618}, + {6, "w1_020", NULL, (LoadFunc)0x092F8C10}, + {6, "w1_021", NULL, (LoadFunc)0x092F8B08}, + {6, "w1_022", NULL, (LoadFunc)0x092F7540}, + {6, "w1_023", NULL, (LoadFunc)0x092F9598}, + {6, "w1_024", NULL, (LoadFunc)0x092F97F8}, + {6, "w1_025", NULL, (LoadFunc)0x092F9680}, + {6, "w1_026", NULL, (LoadFunc)0x092F9870}, + {6, "w1_027", NULL, (LoadFunc)0x092F8F40}, + {6, "w1_028", NULL, (LoadFunc)0x092F9810}, + {6, "w1_029", NULL, (LoadFunc)0x092F9100}, + {6, "w1_030", NULL, (LoadFunc)0x092FA178}, + {6, "w1_031", NULL, (LoadFunc)0x092F7308}, + {6, "w1_032", NULL, (LoadFunc)0x092F73B8}, + {6, "w1_033", NULL, (LoadFunc)0x092F72E8}, + {6, "w1_034", NULL, (LoadFunc)0x092F7A28}, + {6, "w1_035", NULL, (LoadFunc)0x092F7298}, + {6, "w1_036", NULL, (LoadFunc)0x092F7298}, + {6, "w1_037", NULL, (LoadFunc)0x092F8470}, + {6, "w1_038", NULL, (LoadFunc)0x092F77F0}, + {6, "w1_039", NULL, (LoadFunc)0x092F7AC0}, + {6, "w1_040", NULL, (LoadFunc)0x092F7CD0}, + {6, "w1_041", NULL, (LoadFunc)0x092F7C18}, + {6, "w1_042", NULL, (LoadFunc)0x092F7E10}, + {6, "w1_043", NULL, (LoadFunc)0x092F7D10}, + {6, "w1_044", NULL, (LoadFunc)0x092F7CE8}, + {6, "w1_045", NULL, (LoadFunc)0x092F7E58}, + {6, "w1_046", NULL, (LoadFunc)0x092F8538}, + {6, "w1_047", NULL, (LoadFunc)0x092F8300}, + {6, "w1_048", NULL, (LoadFunc)0x092F85C8}, + {6, "w1_049", NULL, (LoadFunc)0x092F8C58}, + {6, "w1_050", NULL, (LoadFunc)0x092F9158}, + {6, "w1_051", NULL, (LoadFunc)0x092F85C0}, + {6, "w1_052", NULL, (LoadFunc)0x092F96C0}, + {6, "w1_053", NULL, (LoadFunc)0x092F89C8}, + {6, "w1_054", NULL, (LoadFunc)0x092F77E8}, + {6, "w1_055", NULL, (LoadFunc)0x092F78E0}, + {6, "w1_056", NULL, (LoadFunc)0x092F8168}, + {6, "w1_057", NULL, (LoadFunc)0x092F7298}, + {6, "w1_058", NULL, (LoadFunc)0x092F81C0}, +}; // clang-format on -void setPlayMode(SceUID playFlag, u32 uiPlayMode); -void waitPlayMode(SceUID playFlag, u32 uiPlayMode); - -INCLUDE_ASM("main_psp/nonmatchings/main_psp/2B69C", func_psp_08929FA8); - -INCLUDE_ASM("main_psp/nonmatchings/main_psp/2B69C", func_psp_0892A018); - -INCLUDE_ASM("main_psp/nonmatchings/main_psp/2B69C", func_psp_0892A0C4); - -INCLUDE_ASM("main_psp/nonmatchings/main_psp/2B69C", func_psp_0892A0F0); - -INCLUDE_ASM("main_psp/nonmatchings/main_psp/2B69C", func_psp_0892A1EC); - -INCLUDE_ASM("main_psp/nonmatchings/main_psp/2B69C", func_psp_0892A21C); - -INCLUDE_ASM("main_psp/nonmatchings/main_psp/2B69C", func_psp_0892A28C); - -INCLUDE_ASM("main_psp/nonmatchings/main_psp/2B69C", func_psp_0892A2D8); - -INCLUDE_ASM("main_psp/nonmatchings/main_psp/2B69C", func_psp_0892A3D4); - -INCLUDE_ASM("main_psp/nonmatchings/main_psp/2B69C", func_psp_0892A414); - -INCLUDE_ASM("main_psp/nonmatchings/main_psp/2B69C", func_psp_0892A620); - -INCLUDE_ASM("main_psp/nonmatchings/main_psp/2B69C", func_psp_0892A70C); - -INCLUDE_ASM("main_psp/nonmatchings/main_psp/2B69C", func_psp_0892A76C); - -INCLUDE_ASM("main_psp/nonmatchings/main_psp/2B69C", func_psp_0892A7E0); - -INCLUDE_ASM("main_psp/nonmatchings/main_psp/2B69C", func_psp_0892A8C0); - -INCLUDE_ASM("main_psp/nonmatchings/main_psp/2B69C", func_psp_0892A8FC); - -INCLUDE_ASM("main_psp/nonmatchings/main_psp/2B69C", func_psp_0892A97C); - -INCLUDE_ASM("main_psp/nonmatchings/main_psp/2B69C", func_psp_0892A998); +extern s32* D_psp_089AD810[]; +extern u8 D_psp_08CADC40[]; +extern s32* g_pStObjLayoutHorizontal; +extern s32* g_pStObjLayoutVertical; -INCLUDE_ASM("main_psp/nonmatchings/main_psp/2B69C", func_psp_0892A9D4); +void func_psp_089375C0(s32*, u32); -INCLUDE_ASM("main_psp/nonmatchings/main_psp/2B69C", func_psp_0892A9E0); - -s32 strFileOpen(StrFile* file, const char* filename, s32 flags) { - if (memcmp(filename, D_psp_08962E80, 6) == 0) { - strcpy(file->assignName, D_psp_08962E80); - file->fd = sceIoOpen(filename, flags, 0); - } else if (memcmp(filename, D_psp_08962E88, 4) == 0) { - strcpy(file->assignName, D_psp_08962E88); - file->fd = sceIoOpen(filename, flags, 0); - } else if (memcmp(filename, D_psp_08962E90, 6) == 0) { - strcpy(file->assignName, D_psp_08962E90); - file->fd = DvdUmdRetryOpenCB(filename, flags, 0); - } else { - printf(D_psp_08962E98); - return -1; - } - if (file->fd < 0) { - printf(D_psp_08962EBC, file->fd); - return -1; - } - return 0; -} - -s32 strFileClose(StrFile* file) { - SceInt64 result; - s32 ret; - - if (file->fd >= 0) { - ret = sceIoClose(file->fd); - if (ret == SCE_KERNEL_ERROR_ASYNC_BUSY) { - sceIoWaitAsync(file->fd, &result); - ret = sceIoClose(file->fd); - } - } else { - return -1; - } - return ret; -} - -s32 strFileRead(StrFile* file, void* buff, SceSize size) { - s32 readsize; +void func_psp_08929FA8(s32* arg0, s32 count) { + s32 i; - if (strcmp(file->assignName, D_psp_08962E90) == 0) { - readsize = DvdUmdRetryRead(file->fd, buff, size); - } else { - readsize = sceIoRead(file->fd, buff, size); + for (i = 0; i < count; i++) { + *arg0 = (s32)&D_psp_08CADC40[*arg0 & 0x000FFFFF]; + arg0++; } - return readsize; } -SceOff strFileLseek(StrFile* file, SceOff offset, s32 whence) { - return sceIoLseek(file->fd, offset, whence); -} - -s32 play_bgm(u32 args, void* argp) { - s32 status; - SceBGMArg* pBGMArg; - SceAtracArg atracArg; - - pBGMArg = (SceBGMArg*)argp; +void func_psp_0892A018(void) { + s32 i; - sceKernelClearEventFlag(pBGMArg->playFlag, 0); - setPlayMode(pBGMArg->playFlag, BGM_UNK_10); - status = init_atrac3plus(pBGMArg, &atracArg); - if (status < 0) { - printf(D_psp_08962EDC, status); - setPlayMode(pBGMArg->playFlag, BGM_PLAY_FINISH); - goto TERM; + for (i = 0; i <= 52; i++) { + g_pStObjLayoutHorizontal[i] = + (s32)&D_psp_08CADC40[g_pStObjLayoutHorizontal[i] & 0x000FFFFF]; + g_pStObjLayoutVertical[i] = + (s32)&D_psp_08CADC40[g_pStObjLayoutVertical[i] & 0x000FFFFF]; } - setPlayMode(pBGMArg->playFlag, BGM_INIT_END); - waitPlayMode(pBGMArg->playFlag, BGM_PLAY_START | BGM_PLAY_FINISH); - play_atrac3plus(&atracArg); - -TERM: - setPlayMode(pBGMArg->playFlag, BGM_PLAY_FINISH); - sceKernelExitThread(0); - return 0; } -INCLUDE_ASM("main_psp/nonmatchings/main_psp/2B69C", init_atrac3plus); - -INCLUDE_ASM("main_psp/nonmatchings/main_psp/2B69C", play_atrac3plus); - -void createPlayModeFlag(const char* name) { - sceKernelCreateEventFlag(name, PSP_EVENT_WAITMULTIPLE, 0x00000000, NULL); -} +void* GetOverlayDst(s32 arg0) { return D_psp_089AD810[arg0]; } -void setPlayMode(SceUID playFlag, u32 uiPlayMode) { - s32 status; +void LoadOverlay(s32 ovlIndex, void* data, s32 size) { + char ovlPath[0x100]; + unkStruct* ptr; - status = sceKernelSetEventFlag(playFlag, uiPlayMode); - if (status < 0) { - printf("status = 0x%x(in sceKernelSetEventFlag)\n", status); + ptr = &D_psp_089622C8[ovlIndex]; + sprintf( + ovlPath, "disc0:/PSP_GAME/USRDIR/res/ps/PSPBIN/%s.bin", ptr->ovlName); + if (ptr->dst == NULL) { + ptr->dst = GetOverlayDst(ptr->type); } -} - -s32 checkPlayMode(SceUID playFlag, u32 uiPlayMode) { - s32 status; - s32 ret = 0; - - if ((status = sceKernelPollEventFlag(playFlag, uiPlayMode, 1, NULL)) == - SCE_KERNEL_ERROR_OK) { - ret = 1; + if (data != NULL) { + memcpy(ptr->dst, data, size); + func_psp_089375C0(ptr->dst, size); } else { - if (status < 0 && status != SCE_KERNEL_ERROR_EVF_COND) { - printf("status = 0x%x(in sceKernelPollEventFlag)\n", status); - } - } - return ret; -} - -void waitPlayMode(SceUID playFlag, u32 uiPlayMode) { - sceKernelWaitEventFlag(playFlag, uiPlayMode, PSP_EVENT_WAITOR, NULL, NULL); -} - -void clearPlayMode(SceUID playFlag, u32 uiPlayMode) { - s32 status; - - status = sceKernelClearEventFlag(playFlag, ~uiPlayMode); - if (status < 0) { - printf("status = 0x%x(in sceKernelClearEventFlag)\n", status); - } -} - -void release_arg(SceAtracArg* pPlayArg) { - s32 status; - - if (pPlayArg->atracID >= 0) { - status = sceAtracReleaseAtracID(pPlayArg->atracID); - if (status < 0) { - printf("status = 0x%x(in sceAtracReleaseAtracID)\n", status); - } - } - if (pPlayArg->strFile.fd >= 0) { - status = strFileClose(&pPlayArg->strFile); - if (status < 0) { - printf("status = 0x%x(in strFileClose)\n", status); - } - } -} - -void at3plus_addData(s32 atracId, StrFile* pstrFile, s32* arg2) { - u8* pucWritePointer; - u32 uiWritableByte, uiReadPosition; - s32 status, iAddByte; - - if (*arg2 == 0) { - status = sceAtracGetStreamDataInfo( - atracId, &pucWritePointer, &uiWritableByte, &uiReadPosition); - if (status < 0) { - printf("sceAtracGetStreamDataInfo = 0x%x\n", status); - goto READ_FAIL; - } - if (uiWritableByte > 0x2000) { - uiWritableByte = 0x2000; + while (true) { + bool done = func_psp_08937740(ovlPath, ptr->dst); + if (done) { + break; + } + sceKernelDelayThreadCB(166); } - status = strFileLseek(pstrFile, (SceOff)uiReadPosition, PSP_SEEK_SET); - if (status < 0) { - printf("strFileLseek Error = 0x%x\n", status); - goto READ_FAIL; - } - D_psp_08DADCB4 = uiWritableByte; - if (strcmp(pstrFile->assignName, D_psp_08962E90) == 0) { - sceIoReadAsync(pstrFile->fd, pucWritePointer, uiWritableByte); - *arg2 = 1; - } else { - iAddByte = sceIoRead(pstrFile->fd, pucWritePointer, uiWritableByte); - } - if (iAddByte <= 0) { - printf("strFileReadNoRetry Error = 0x%x\n", - iAddByte); // TODO: inlined function ? - goto READ_FAIL; - } - } - if (*arg2 == 1 && sceIoPollAsync(pstrFile->fd, (SceInt64*)&iAddByte) == 0) { - iAddByte = D_psp_08DADCB4; - *arg2 = -1; - } - if (*arg2 < 0) { - status = sceAtracAddStreamData(atracId, iAddByte); - *arg2 = 0; - if (status < 0) { - printf("sceAtracAddStreamData = 0x%x\n", status); - } - } -READ_FAIL: - return; -} - -void reset_position(SceAtracArg* pPlayArg) { - PspBufferInfo bufferInfo; - s32 status; - s32 firstBufRead = 0, secondBufRead = 0; - - status = - sceAtracGetBufferInfoForResetting(pPlayArg->atracID, 0, &bufferInfo); - if (status < 0) { - printf("status = 0x%x(in sceAtracGetBufferInfoForResetting)\n", status); - goto ERROR_OCCURED; - } - if (bufferInfo.uiMinWriteByteFirstBuf > 0) { - status = strFileLseek( - &pPlayArg->strFile, (SceOff)bufferInfo.uiReadPositionFirstBuf, - PSP_SEEK_SET); - if (status < 0) { - printf(D_psp_08962FCC, status); - goto ERROR_OCCURED; - } - firstBufRead = - strFileRead(&pPlayArg->strFile, bufferInfo.pucWritePositionFirstBuf, - bufferInfo.uiWritableByteFirstBuf); - if (firstBufRead < 0) { - status = firstBufRead; - printf(D_psp_08962F50, status); - goto ERROR_OCCURED; - } - } - if (bufferInfo.uiMinWriteByteSecondBuf > 0) { - status = strFileLseek( - &pPlayArg->strFile, (SceOff)bufferInfo.uiReadPositionSecondBuf, - PSP_SEEK_SET); - if (status < 0) { - printf(D_psp_08962FCC, status); - goto ERROR_OCCURED; - } - secondBufRead = strFileRead( - &pPlayArg->strFile, bufferInfo.pucWritePositionSecondBuf, - bufferInfo.uiWritableByteSecondBuf); - if (secondBufRead < 0) { - printf(D_psp_08962F50, secondBufRead); - goto ERROR_OCCURED; - } - } - status = sceAtracResetPlayPosition( - pPlayArg->atracID, 0, firstBufRead, secondBufRead); - if (status < 0) { - printf("status = 0x%x (in sceAtracResetPlayPosition)\n", status); } - status = sceAtracSetLoopNum(pPlayArg->atracID, -1); - if (status < 0) { - printf("status = 0x%x(in sceAtracSetLoopNum)\n", status); + if (ptr->load != NULL) { + ptr->load(); } -ERROR_OCCURED: - return; } -void fadeoutOperation( - s16* pusValue, s32 iFadeoutBorderSample, s32 iMuteBorderSample) { - float fadeoutratio = 1.0f / iFadeoutBorderSample; - float fadeout; - s32 i; - - for (i = 0; i < iFadeoutBorderSample; i++) { - fadeout = ((iFadeoutBorderSample - 1) - i) * fadeoutratio; - pusValue[2 * i] = pusValue[2 * i] * fadeout; - pusValue[2 * i + 1] = pusValue[2 * i + 1] * fadeout; - } - for (; i < iMuteBorderSample; i++) { - pusValue[2 * i] = 0; - pusValue[2 * i + 1] = 0; - } -} +void func_psp_0892A1EC(s32 ovlIndex) { LoadOverlay(ovlIndex, NULL, 0); } diff --git a/src/main_psp/2D608.c b/src/main_psp/2D608.c index 770d81aaff..549f15a9d0 100644 --- a/src/main_psp/2D608.c +++ b/src/main_psp/2D608.c @@ -153,7 +153,7 @@ void func_psp_0892BFD8(unkStruct2* arg0) { func_psp_0892CAD8(); D_psp_08DAE784 = 1; D_psp_089632C8 = sceKernelCreateThread( - D_psp_089632CC, func_psp_0892CB40, 0x10, 0x1000, 0, 0); + D_psp_089632CC, func_psp_0892CB40, 0x10, 0x1000, 0, NULL); sceKernelStartThread(D_psp_089632C8, 0, 0); } diff --git a/src/main_psp/36174.c b/src/main_psp/36174.c index 9a5e8475af..f010c74475 100644 --- a/src/main_psp/36174.c +++ b/src/main_psp/36174.c @@ -175,16 +175,16 @@ s32 func_psp_08937658(char* file, void* buf) { } s32 func_psp_08937740(char* file, void* buf) { - s32 ret = 0; - bool var_s1 = false; + s32 size = 0; + bool ret = false; - ret = func_psp_08937658(file, buf); - if (ret > 0) { + size = func_psp_08937658(file, buf); + if (size > 0) { func_psp_08937650(buf); - func_psp_089375C0(buf, ret); - var_s1 = true; + func_psp_089375C0(buf, size); + ret = true; } - return var_s1; + return ret; } INCLUDE_ASM("main_psp/nonmatchings/main_psp/36174", func_psp_089377B8); diff --git a/src/main_psp/mpeg/fileread.c b/src/main_psp/mpeg/fileread.c index a2e7fc1434..c12f3689a2 100644 --- a/src/main_psp/mpeg/fileread.c +++ b/src/main_psp/mpeg/fileread.c @@ -137,13 +137,13 @@ s32 ringbufferCallBack(void* pBuf, s32 iNum, void* CallbackData) { if (temp_s0->unk2C < func_psp_089125F8()) { return -3; } - func_psp_08912608(); + LockPowerSwitch(); if (func_psp_089123B8() == 0 || D_psp_08B1FBC8 != func_psp_089125F8()) { - func_psp_08912640(); + UnlockPowerSwitch(); return -3; } iReadSize = func_psp_0891689C(pStrFile, pBuf, iTypeSize * iNum); - func_psp_08912640(); + UnlockPowerSwitch(); if (iReadSize > 0) { func_psp_0891535C(temp_s0, iReadSize); temp_s0->unk24 = 0; @@ -195,23 +195,23 @@ s32 read_func(s32 args, void* argp) { pStrFile->unk4 = 1; } if (pStrFile->unk4 == 1 || pStrFile->fd == -1) { - func_psp_08912608(); + LockPowerSwitch(); if ((D_psp_08B1FBD8 = func_psp_08916724( pStrFile, &pStrFile->unk16, PSP_O_RDONLY)) >= 0) { pStrFile->unk4 = 2; } - func_psp_08912640(); + UnlockPowerSwitch(); continue; } if (pStrFile->unk4 == 2) { - func_psp_08912608(); + LockPowerSwitch(); if ((D_psp_08B1FBD8 = func_psp_089168E8( pStrFile, D_psp_08B1FBD4->unk8, PSP_SEEK_SET)) >= 0) { D_psp_08B1FBC8 = func_psp_089125F8(); pStrFile->unk4 = 0; } - func_psp_08912640(); + UnlockPowerSwitch(); continue; } } diff --git a/src/main_psp/sound/2B910.c b/src/main_psp/sound/2B910.c new file mode 100644 index 0000000000..ed9a7faab6 --- /dev/null +++ b/src/main_psp/sound/2B910.c @@ -0,0 +1,214 @@ +// SPDX-License-Identifier: AGPL-3.0-or-later +//! PSPO=4,p +#include "sound_private.h" + +#define STACKSIZE (1024 * 64) + +static u8* firstBuffers[2]; +static u8* secondBuffers[2]; +static s32 threadIDs[2]; +static SceBGMArg bgmArgs[2]; +static s32 playFlags[2]; +static s32 status; +static s32 thread_status; +static bool dvd_umdAssignFlag; + +s32 play_bgm(u32 args, void* argp); + +s32 strFileAssign(char* filename) { + if (memcmp(filename, PSP_UMD_ALIAS_NAME, 6) == 0 && !dvd_umdAssignFlag) { + dvd_umdAssignFlag = true; + if (sceUmdActivate(PSP_UMD_MODE_POWERON, PSP_UMD_ALIAS_NAME) < 0) { + return -1; + } + DvdUmdIoInit(); + } + return 0; +} + +s32 strFileUnassign(void) { + s32 ret; + + ret = 1; + if (dvd_umdAssignFlag) { + if (sceUmdDeactivate(2, PSP_UMD_ALIAS_NAME) >= 0) { + dvd_umdAssignFlag = false; + } + ret = DvdUmdIoTerm(); + } + return ret; +} + +s32 func_psp_0892A2D8(void) { + s32 i; + s32 var_s3; + + var_s3 = 0; + for (i = 0; i < 2; i++) { + firstBuffers[i] = (u8*)func_psp_08919C8C(var_s3); + secondBuffers[i] = (u8*)func_psp_08919C8C(var_s3 + 0x20040); + var_s3 += 0x30080; + threadIDs[i] = -1; + } + playFlags[0] = createPlayModeFlag("AT3plusBGMFlag0"); + if (playFlags[0] < 0) { + status = playFlags[0]; + return -3; + } + playFlags[1] = createPlayModeFlag("AT3plusBGMFlag1"); + if (playFlags[1] < 0) { + status = playFlags[1]; + return -3; + } + return 0; +} + +void func_psp_0892A3D4(void) { + if (func_psp_08917E4C() != 0) { + status = -1; + } + status = strFileUnassign(); +} + +s32 func_psp_0892A414( + s32 arg0, char* filename, bool loop, s32 arg3, u8* buf, s32 fileSize) { + if (arg0 < 0 || arg0 >= 2) { + return -1; + } + func_psp_0892A620(arg0, false); + status = strFileAssign(filename); + if (status < 0) { + return -1; + } + bgmArgs[arg0].filename = filename; + bgmArgs[arg0].pucFirstBuf = (buf != NULL) ? buf : firstBuffers[arg0]; + bgmArgs[arg0].iFirstBufSize = 0x20000; + bgmArgs[arg0].pucSecondBuf = secondBuffers[arg0]; + bgmArgs[arg0].iSecondBufSize = 0x10000; + bgmArgs[arg0].iOutputChannel = arg0 + 1; + bgmArgs[arg0].playFlag = playFlags[arg0]; + bgmArgs[arg0].loop = loop; + bgmArgs[arg0].fileSize = (buf != NULL) ? fileSize : 0; + threadIDs[arg0] = sceKernelCreateThread( + "at3 thread 0", play_bgm, KERNEL_USER_HIGHEST_PRIORITY, STACKSIZE, 0, + NULL); + if (threadIDs[arg0] < 0) { + status = threadIDs[arg0]; + threadIDs[arg0] = -1; + return -1; + } + status = sceKernelStartThread( + threadIDs[arg0], sizeof(SceBGMArg), &bgmArgs[arg0]); + if (status != 0) { + threadIDs[arg0] = -1; + return -2; + } + return 0; +} + +s32 func_psp_0892A620(s32 arg0, bool arg1) { + if (arg0 < 0 || arg0 >= 2) { + return -1; + } + if (threadIDs[arg0] >= 0) { + setPlayMode(playFlags[arg0], BGM_UNK_40); + setPlayMode(playFlags[arg0], BGM_PLAY_FINISH); + if (arg1) { + setPlayMode(playFlags[arg0], BGM_UNK_100); + } + sceKernelDelayThreadCB(1000); + thread_status = sceKernelWaitThreadEnd(threadIDs[arg0], NULL); + if (thread_status != SCE_KERNEL_ERROR_OK) { + status = thread_status; + } + thread_status = sceKernelDeleteThread(threadIDs[arg0]); + if (thread_status != SCE_KERNEL_ERROR_OK) { + status = thread_status; + } + threadIDs[arg0] = -1; + } + return 0; +} + +s32 func_psp_0892A70C(s32 arg0) { + if (arg0 < 0 || arg0 >= 2) { + return -1; + } + if (threadIDs[arg0] >= 0) { + setPlayMode(playFlags[arg0], BGM_UNK_20); + } + return 0; +} + +s32 func_psp_0892A76C(s32 arg0) { + if (arg0 < 0 || arg0 >= 2) { + return -1; + } + if (threadIDs[arg0] >= 0) { + setPlayMode(playFlags[arg0], BGM_PLAY_START); + setPlayMode(playFlags[arg0], BGM_UNK_40); + } + return 0; +} + +s32 func_psp_0892A7E0(s32 arg0) { + s32 ret = 0; + + if (arg0 < 0 || arg0 >= 2) { + return ret; + } + if (checkPlayMode(playFlags[arg0], BGM_UNK_80)) { + ret |= BGM_UNK_80; + } + if (checkPlayMode(playFlags[arg0], BGM_PLAY_FINISH)) { + ret |= BGM_PLAY_FINISH; + } + if (checkPlayMode(playFlags[arg0], BGM_UNK_20)) { + ret |= BGM_UNK_20; + } + if (checkPlayMode(playFlags[arg0], BGM_PLAY_START)) { + ret |= BGM_PLAY_START; + } + if (checkPlayMode(playFlags[arg0], BGM_INIT_END)) { + ret |= BGM_INIT_END; + } + if (checkPlayMode(playFlags[arg0], BGM_INIT_START)) { + ret |= BGM_INIT_START; + } + return ret; +} + +void func_psp_0892A8C0(void) { + s32 i; + + for (i = 0; i < 2; i++) { + func_psp_0892A620(i, false); + } +} + +void func_psp_0892A8FC(void) { + s32 i; + + for (i = 0; i < 2; i++) { + if (threadIDs[i] >= 0) { + if (checkPlayMode(playFlags[i], BGM_INIT_END)) { + setPlayMode(playFlags[i], BGM_PLAY_START); + } + } + } +} + +void func_psp_0892A97C(s32 arg0, s32 arg1) { + setPlayMode(playFlags[arg0], BGM_UNK_80); +} + +void func_psp_0892A998(void) { + setPlayMode(playFlags[0], 0x0FFFFFFF); + setPlayMode(playFlags[1], 0x0FFFFFFF); +} + +static s32 D_psp_08962E7C = 0x8000; + +void func_psp_0892A9D4(s32 arg0) { D_psp_08962E7C = arg0; } + +s32 func_psp_0892A9E0(void) { return D_psp_08962E7C; } diff --git a/src/main_psp/sound/at3plus.c b/src/main_psp/sound/at3plus.c new file mode 100644 index 0000000000..04790b2a95 --- /dev/null +++ b/src/main_psp/sound/at3plus.c @@ -0,0 +1,492 @@ +// SPDX-License-Identifier: AGPL-3.0-or-later +//! PSPO=4,p +#include "sound_private.h" + +#define BYTEALIGN (64) +#define MAX_SAMPLE (2048) +#define AUDIO_OUTPUT_SAMPLE MAX_SAMPLE +#define BUFFER_NUM (3) +#define WRITEBUF_SIZE (BUFFER_NUM * (MAX_SAMPLE)) + +#define SCE_WAVE_AUDIO_SMPL_MIN (64) +#define SCE_WAVE_AUDIO_VOL_MAX (0x8000) +#define FADEOUT_RATIO (SCE_WAVE_AUDIO_VOL_MAX / 128) + +extern u32 D_psp_08DADCB4; + +void setPlayMode(SceUID playFlag, u32 uiPlayMode); +static void play_atrac3plus(SceAtracArg* pPlayArg); +static void clearPlayMode(SceUID playFlag, u32 uiPlayMode); +static void waitPlayMode(SceUID playFlag, u32 uiPlayMode); +static void release_arg(SceAtracArg* pPlayArg); +static void at3plus_addData(s32 atracId, StrFile* pstrFile, s32* arg2); +static void reset_position(SceAtracArg* pPlayArg); +static void fadeoutOperation( + s16* pusValue, s32 iFadeoutBorderSample, s32 iMuteBorderSample); + +static s32 strFileOpen(StrFile* file, const char* filename, s32 flags) { + if (memcmp(filename, "host0:", 6) == 0) { + strcpy(file->assignName, "host0:"); + file->fd = sceIoOpen(filename, flags, 0); + } else if (memcmp(filename, "ms0:", 4) == 0) { + strcpy(file->assignName, "ms0:"); + file->fd = sceIoOpen(filename, flags, 0); + } else if (memcmp(filename, PSP_UMD_ALIAS_NAME, 6) == 0) { + strcpy(file->assignName, PSP_UMD_ALIAS_NAME); + file->fd = DvdUmdRetryOpenCB(filename, flags, 0); + } else { + printf("fatal error : not supported device\n"); + return -1; + } + if (file->fd < 0) { + printf("fatal error : file->fd = 0x%x\n", file->fd); + return -1; + } + return 0; +} + +static s32 strFileClose(StrFile* file) { + SceInt64 result; + s32 ret; + + if (file->fd >= 0) { + ret = sceIoClose(file->fd); + if (ret == SCE_KERNEL_ERROR_ASYNC_BUSY) { + sceIoWaitAsync(file->fd, &result); + ret = sceIoClose(file->fd); + } + } else { + return -1; + } + return ret; +} + +static s32 strFileRead(StrFile* file, void* buff, SceSize size) { + s32 readsize; + + if (strcmp(file->assignName, PSP_UMD_ALIAS_NAME) == 0) { + readsize = DvdUmdRetryRead(file->fd, buff, size); + } else { + readsize = sceIoRead(file->fd, buff, size); + } + return readsize; +} + +static SceOff strFileLseek(StrFile* file, SceOff offset, s32 whence) { + return sceIoLseek(file->fd, offset, whence); +} + +s32 play_bgm(u32 args, void* argp) { + s32 status; + SceBGMArg* pBGMArg; + SceAtracArg atracArg; + + pBGMArg = (SceBGMArg*)argp; + + sceKernelClearEventFlag(pBGMArg->playFlag, 0); + setPlayMode(pBGMArg->playFlag, BGM_INIT_START); + status = init_atrac3plus(pBGMArg, &atracArg); + if (status < 0) { + printf("status = 0x%x (in init_atrac3plus)\n", status); + setPlayMode(pBGMArg->playFlag, BGM_PLAY_FINISH); + goto TERM; + } + setPlayMode(pBGMArg->playFlag, BGM_INIT_END); + waitPlayMode(pBGMArg->playFlag, BGM_PLAY_START | BGM_PLAY_FINISH); + play_atrac3plus(&atracArg); + +TERM: + setPlayMode(pBGMArg->playFlag, BGM_PLAY_FINISH); + sceKernelExitThread(0); + return 0; +} + +static s32 init_atrac3plus(SceBGMArg* pBGMArg, SceAtracArg* pPlayArg) { + s32 filesize; + s32 status; + s32 iLoopStartSample, iLoopEndSample; + u32 uiSecondBufferPosition; + u32 uiDataByte; + + s32 sp3C; + s32 sp38; + s32 sp34; + s32 uiBitrate; + u32 uiOutputCh; + + char* filename = "disc0:/PSP_GAME/USRDIR/res/ps/sound/XA/011a.at3"; + + pPlayArg->strFile.fd = -1; + pPlayArg->atracID = -1; + pPlayArg->playFlag = pBGMArg->playFlag; + pPlayArg->outputChannel = pBGMArg->iOutputChannel; + pPlayArg->iVol = 0x8000; + filesize = pBGMArg->fileSize; + pPlayArg->fileSize = filesize; + if (pPlayArg->fileSize == 0) { + status = strFileOpen(&pPlayArg->strFile, pBGMArg->filename, 1); + if (status < 0) { + printf("status = 0x%x(in strFileOpen)\n", status); + do { + status = strFileOpen(&pPlayArg->strFile, filename, 1); + sceKernelDelayThreadCB(100000); + } while (status < 0); + } + filesize = strFileRead(&pPlayArg->strFile, pBGMArg->pucFirstBuf, + (u32)pBGMArg->iFirstBufSize >> 1); + if (filesize < 0) { + status = filesize; + printf("status = 0x%x(in strFileRead)\n", status); + goto RELEASE_ARG; + } + } + pPlayArg->atracID = sceAtracSetDataAndGetID(pBGMArg->pucFirstBuf, filesize); + if (pPlayArg->atracID < 0) { + status = pPlayArg->atracID; + printf("status = 0x%x(in sceAtracSetDataAndGetID)\n", status); + goto RELEASE_ARG; + } + status = sceAtracGetSecondBufferInfo( + pPlayArg->atracID, &uiSecondBufferPosition, &uiDataByte); + if (status != PSP_ATRAC_ERROR_NONEED_SECOND_BUFFER) { + s32 iReadSize; + + if (status < 0) { + printf("status = 0x%x(in sceAtracGetSecondBufferInfo)\n", status); + goto RELEASE_ARG; + } + status = + strFileLseek(&pPlayArg->strFile, (s64)uiSecondBufferPosition, 0); + if (status < 0) { + printf("status = 0x%x(in strFileLseek)\n", status); + goto RELEASE_ARG; + } + iReadSize = strFileRead( + &pPlayArg->strFile, pBGMArg->pucSecondBuf, pBGMArg->iSecondBufSize); + if (iReadSize < 0) { + status = iReadSize; + printf("status = 0x%x(in strFileRead)\n", iReadSize); + goto RELEASE_ARG; + } + status = sceAtracSetSecondBuffer( + pPlayArg->atracID, pBGMArg->pucSecondBuf, iReadSize); + if (status < 0) { + printf("status = 0x%x(in sceAtracSetSecondBuffer)\n", status); + goto RELEASE_ARG; + } + } + status = sceAtracGetSoundSample(pPlayArg->atracID, &pPlayArg->iEndSample, + &iLoopStartSample, &iLoopEndSample); + if (status < 0) { + printf("status = 0x%x(in sceAtracGetSoundSample)\n", status); + goto RELEASE_ARG; + } + if (pBGMArg->loop != 0) { + status = sceAtracSetLoopNum(pPlayArg->atracID, -1); + if (status < 0) { + printf("status = 0x%x(in sceAtracSetLoopNum) loop=%d\n", status, + pBGMArg->loop); + } + } + sceAtracGetSoundSample(pPlayArg->atracID, &sp3C, &sp38, &sp34); + sceAtracGetBitrate(pPlayArg->atracID, &uiBitrate); + sceAtracGetOutputChannel(pPlayArg->atracID, &uiOutputCh); + return 0; +RELEASE_ARG: + release_arg(pPlayArg); + return status; +} + +static void play_atrac3plus(SceAtracArg* pPlayArg) { + s32 status; + u32 finishflag, uiWritePosition = 0, uiPlayPosition = 0; + s32 iRemainFrame; + s32 iReadThreshold; + s32 iVol; + s32* outputBuf; + s32 aiOutputBuf[WRITEBUF_SIZE + (AUDIO_OUTPUT_SAMPLE - 1) + BYTEALIGN / 4 - + 1]; + + outputBuf = + (s32*)((u32)(aiOutputBuf + BYTEALIGN / 4 - 1) & ~(BYTEALIGN - 1)); + status = sceAtracGetRemainFrame(pPlayArg->atracID, &iRemainFrame); + if (status < 0) { + printf("sceAtracGetRemainFrame err 0x%x\n", status); + } + iReadThreshold = iRemainFrame / 2; + if (iReadThreshold < 1) { + iReadThreshold = 1; + } + pPlayArg->unk28 = 0; + do { + u32 sample; + s32 var_s6 = true; + s32 var_s0 = false; + if (checkPlayMode(pPlayArg->playFlag, BGM_UNK_20)) { + clearPlayMode(pPlayArg->playFlag, BGM_UNK_20); + waitPlayMode(pPlayArg->playFlag, BGM_UNK_40); + clearPlayMode(pPlayArg->playFlag, BGM_UNK_40); + sceKernelDelayThreadCB(83330); + var_s0 = true; + if (iRemainFrame != PSP_ATRAC_ALLDATA_IS_ON_MEMORY && + iRemainFrame != PSP_ATRAC_NONLOOP_STREAM_DATA_IS_ON_MEMORY) { + at3plus_addData( + pPlayArg->atracID, &pPlayArg->strFile, &pPlayArg->unk28); + } + if (checkPlayMode(pPlayArg->playFlag, BGM_PLAY_FINISH)) { + break; + } + } + if (!var_s0) { + status = sceAtracDecodeData( + pPlayArg->atracID, (s16*)&outputBuf[uiWritePosition], &sample, + &finishflag, &iRemainFrame); + if (status < 0 && status != PSP_ATRAC_ERROR_NODATA_IN_BUFFER) { + s32 innerInfo; + sceAtracGetInternalErrorInfo(pPlayArg->atracID, &innerInfo); + printf("innerInfo 0x%x\n", innerInfo); + printf( + "sceAtracDecodeData err 0x%x (%08x)\n", status, innerInfo); + sceKernelDelayThreadCB(100000); + break; + } + uiWritePosition += sample; + } + if (uiWritePosition - uiPlayPosition >= AUDIO_OUTPUT_SAMPLE) { + s32 output_samples = (uiWritePosition - uiPlayPosition) & + ~(SCE_WAVE_AUDIO_SMPL_MIN - 1); + + if (checkPlayMode(pPlayArg->playFlag, BGM_PLAY_FINISH)) { + setPlayMode(pPlayArg->playFlag, BGM_UNK_80); + if (pPlayArg->outputChannel == 2 || + checkPlayMode(pPlayArg->playFlag, BGM_UNK_100)) { + break; + } + iVol = pPlayArg->outputChannel == 1 ? func_psp_0892A9E0() + : pPlayArg->iVol; + iVol -= FADEOUT_RATIO * output_samples >> 10; + if (iVol < 0) { + break; + } + pPlayArg->iVol = iVol; + if (pPlayArg->outputChannel == 1) { + func_psp_0892A9D4(iVol); + } + } + if (checkPlayMode(pPlayArg->playFlag, BGM_RESET_POSITION)) { + fadeoutOperation( + (s16*)&outputBuf[uiPlayPosition], output_samples, + uiWritePosition - uiPlayPosition); + } + var_s6 = false; + sceWaveAudioSetSample(pPlayArg->outputChannel, output_samples); + sceWaveAudioWriteBlocking( + pPlayArg->outputChannel, pPlayArg->iVol, pPlayArg->iVol, + &outputBuf[uiPlayPosition]); + uiPlayPosition += output_samples; + if (checkPlayMode(pPlayArg->playFlag, BGM_RESET_POSITION)) { + reset_position(pPlayArg); + clearPlayMode(pPlayArg->playFlag, BGM_RESET_POSITION); + } + } + if (uiWritePosition >= WRITEBUF_SIZE) { + uiWritePosition -= uiPlayPosition; + memcpy(outputBuf, &outputBuf[uiPlayPosition], + sizeof(s32) * uiWritePosition); + uiPlayPosition = 0; + } + if (iRemainFrame <= iReadThreshold && + iRemainFrame != PSP_ATRAC_ALLDATA_IS_ON_MEMORY && + iRemainFrame != PSP_ATRAC_NONLOOP_STREAM_DATA_IS_ON_MEMORY) { + at3plus_addData( + pPlayArg->atracID, &pPlayArg->strFile, &pPlayArg->unk28); + } + if (var_s6) { + sceKernelDelayThreadCB(1000); + } + } while (!finishflag); + + sceWaveAudioWriteBlocking(pPlayArg->outputChannel, 0, 0, NULL); + release_arg(pPlayArg); +} + +s32 createPlayModeFlag(const char* name) { + return sceKernelCreateEventFlag( + name, PSP_EVENT_WAITMULTIPLE, 0x00000000, NULL); +} + +void setPlayMode(SceUID playFlag, u32 uiPlayMode) { + s32 status; + + status = sceKernelSetEventFlag(playFlag, uiPlayMode); + if (status < 0) { + printf("status = 0x%x(in sceKernelSetEventFlag)\n", status); + } +} + +s32 checkPlayMode(SceUID playFlag, u32 uiPlayMode) { + s32 status; + s32 ret = 0; + + if ((status = sceKernelPollEventFlag(playFlag, uiPlayMode, PSP_EVENT_WAITOR, + NULL)) == SCE_KERNEL_ERROR_OK) { + ret = 1; + } else { + if (status < 0 && status != SCE_KERNEL_ERROR_EVF_COND) { + printf("status = 0x%x(in sceKernelPollEventFlag)\n", status); + } + } + return ret; +} + +static void waitPlayMode(SceUID playFlag, u32 uiPlayMode) { + sceKernelWaitEventFlag(playFlag, uiPlayMode, PSP_EVENT_WAITOR, NULL, NULL); +} + +static void clearPlayMode(SceUID playFlag, u32 uiPlayMode) { + s32 status; + + status = sceKernelClearEventFlag(playFlag, ~uiPlayMode); + if (status < 0) { + printf("status = 0x%x(in sceKernelClearEventFlag)\n", status); + } +} + +static void release_arg(SceAtracArg* pPlayArg) { + s32 status; + + if (pPlayArg->atracID >= 0) { + status = sceAtracReleaseAtracID(pPlayArg->atracID); + if (status < 0) { + printf("status = 0x%x(in sceAtracReleaseAtracID)\n", status); + } + } + if (pPlayArg->strFile.fd >= 0) { + status = strFileClose(&pPlayArg->strFile); + if (status < 0) { + printf("status = 0x%x(in strFileClose)\n", status); + } + } +} + +static void at3plus_addData(s32 atracId, StrFile* pstrFile, s32* arg2) { + u8* pucWritePointer; + u32 uiWritableByte, uiReadPosition; + s32 status, iAddByte; + + if (*arg2 == 0) { + status = sceAtracGetStreamDataInfo( + atracId, &pucWritePointer, &uiWritableByte, &uiReadPosition); + if (status < 0) { + printf("sceAtracGetStreamDataInfo = 0x%x\n", status); + goto READ_FAIL; + } + if (uiWritableByte > 0x2000) { + uiWritableByte = 0x2000; + } + status = strFileLseek(pstrFile, (SceOff)uiReadPosition, PSP_SEEK_SET); + if (status < 0) { + printf("strFileLseek Error = 0x%x\n", status); + goto READ_FAIL; + } + D_psp_08DADCB4 = uiWritableByte; + if (strcmp(pstrFile->assignName, PSP_UMD_ALIAS_NAME) == 0) { + sceIoReadAsync(pstrFile->fd, pucWritePointer, uiWritableByte); + *arg2 = 1; + } else { + iAddByte = sceIoRead(pstrFile->fd, pucWritePointer, uiWritableByte); + } + if (iAddByte <= 0) { + printf("strFileReadNoRetry Error = 0x%x\n", + iAddByte); // TODO: inlined function ? + goto READ_FAIL; + } + } + if (*arg2 == 1 && sceIoPollAsync(pstrFile->fd, (SceInt64*)&iAddByte) == 0) { + iAddByte = D_psp_08DADCB4; + *arg2 = -1; + } + if (*arg2 < 0) { + status = sceAtracAddStreamData(atracId, iAddByte); + *arg2 = 0; + if (status < 0) { + printf("sceAtracAddStreamData = 0x%x\n", status); + } + } +READ_FAIL: + return; +} + +static void reset_position(SceAtracArg* pPlayArg) { + PspBufferInfo bufferInfo; + s32 status; + s32 firstBufRead = 0, secondBufRead = 0; + + status = + sceAtracGetBufferInfoForResetting(pPlayArg->atracID, 0, &bufferInfo); + if (status < 0) { + printf("status = 0x%x(in sceAtracGetBufferInfoForResetting)\n", status); + goto ERROR_OCCURED; + } + if (bufferInfo.uiMinWriteByteFirstBuf > 0) { + status = strFileLseek( + &pPlayArg->strFile, (SceOff)bufferInfo.uiReadPositionFirstBuf, + PSP_SEEK_SET); + if (status < 0) { + printf("status = 0x%x(in strFileLseek)\n", status); + goto ERROR_OCCURED; + } + firstBufRead = + strFileRead(&pPlayArg->strFile, bufferInfo.pucWritePositionFirstBuf, + bufferInfo.uiWritableByteFirstBuf); + if (firstBufRead < 0) { + status = firstBufRead; + printf("status = 0x%x(in strFileRead)\n", status); + goto ERROR_OCCURED; + } + } + if (bufferInfo.uiMinWriteByteSecondBuf > 0) { + status = strFileLseek( + &pPlayArg->strFile, (SceOff)bufferInfo.uiReadPositionSecondBuf, + PSP_SEEK_SET); + if (status < 0) { + printf("status = 0x%x(in strFileLseek)\n", status); + goto ERROR_OCCURED; + } + secondBufRead = strFileRead( + &pPlayArg->strFile, bufferInfo.pucWritePositionSecondBuf, + bufferInfo.uiWritableByteSecondBuf); + if (secondBufRead < 0) { + printf("status = 0x%x(in strFileRead)\n", secondBufRead); + goto ERROR_OCCURED; + } + } + status = sceAtracResetPlayPosition( + pPlayArg->atracID, 0, firstBufRead, secondBufRead); + if (status < 0) { + printf("status = 0x%x (in sceAtracResetPlayPosition)\n", status); + } + status = sceAtracSetLoopNum(pPlayArg->atracID, -1); + if (status < 0) { + printf("status = 0x%x(in sceAtracSetLoopNum)\n", status); + } +ERROR_OCCURED: + return; +} + +static void fadeoutOperation( + s16* pusValue, s32 iFadeoutBorderSample, s32 iMuteBorderSample) { + float fadeoutratio = 1.0f / iFadeoutBorderSample; + float fadeout; + s32 i; + + for (i = 0; i < iFadeoutBorderSample; i++) { + fadeout = ((iFadeoutBorderSample - 1) - i) * fadeoutratio; + pusValue[2 * i] = pusValue[2 * i] * fadeout; + pusValue[2 * i + 1] = pusValue[2 * i + 1] * fadeout; + } + for (; i < iMuteBorderSample; i++) { + pusValue[2 * i] = 0; + pusValue[2 * i + 1] = 0; + } +} diff --git a/src/main_psp/dvdumd_io.c b/src/main_psp/sound/dvdumd_io.c similarity index 98% rename from src/main_psp/dvdumd_io.c rename to src/main_psp/sound/dvdumd_io.c index 55bc3ec8df..184ffc1927 100644 --- a/src/main_psp/dvdumd_io.c +++ b/src/main_psp/sound/dvdumd_io.c @@ -1,7 +1,5 @@ // SPDX-License-Identifier: AGPL-3.0-or-later -#include -#include -#include +#include "sound_private.h" // clang-format off #define SCE_ERROR_ERRNO_ENOENT 0x80010002 // Associated file or directory does not exist diff --git a/src/main_psp/sound/sound_private.h b/src/main_psp/sound/sound_private.h new file mode 100644 index 0000000000..ff94bff6e1 --- /dev/null +++ b/src/main_psp/sound/sound_private.h @@ -0,0 +1,52 @@ +// SPDX-License-Identifier: AGPL-3.0-or-later +#include + +// https://pspdev.github.io/pspsdk/ +#define PSP_LEGACY_TYPES_DEFINED // avoid processing psptypes.h +#include +#include +#include +#include +#include + +typedef struct { + s32 fd; + char assignName[10]; +} StrFile; + +typedef struct { + s32 atracID; // ATRAC playback ID + StrFile strFile; // File structure + s32 playFlag; // Event flag indicating status Used for cueing, playing, and + // ending + s32 outputChannel; // Channel when outputting to libwave + s32 iEndSample; + s32 iVol; + s32 fileSize; + s32 unk28; +} SceAtracArg; + +typedef struct { + char* filename; // "ATRAC3plus" file + u8* pucFirstBuf; // FirstBuffer starting address + s32 iFirstBufSize; // FirstBuffer size + u8* pucSecondBuf; // SecondBuffer starting address + s32 iSecondBufSize; // SecondBuffer size + s32 iOutputChannel; // Output channel + SceUID playFlag; // Event flag for setting playback mode + s32 loop; + s32 fileSize; +} SceBGMArg; + +// clang-format off +// Values for setting playback mode and EVENTFLAG +#define BGM_INIT_END (0x00000001U) // Status when playback initialization ended +#define BGM_PLAY_START (0x00000002U) // Status when playback start instruction was received +#define BGM_RESET_POSITION (0x00000004U) // Status when playback position changes +#define BGM_PLAY_FINISH (0x00000008U) // Status when playback termination is specified +#define BGM_INIT_START (0x00000010U) // Status when playback initialization starts +#define BGM_UNK_20 (0x00000020U) +#define BGM_UNK_40 (0x00000040U) +#define BGM_UNK_80 (0x00000080U) +#define BGM_UNK_100 (0x00000100U) +// clang-format on diff --git a/src/st/dai/e_confessional.c b/src/st/dai/e_confessional.c index 0ec68e3d0f..ae9f8d2494 100644 --- a/src/st/dai/e_confessional.c +++ b/src/st/dai/e_confessional.c @@ -157,7 +157,7 @@ void EntityConfessionalGhost(Entity* self) { #ifdef VERSION_PSP self->ext.confessionalGhost.activateChime = false; if (self->params & CONFESSIONAL_GHOST_PARISHIONER) { - func_psp_0892A620(0, 1); + func_psp_0892A620(0, true); } break; // psx starts the chime in INIT, but pspeu starts it in READY diff --git a/src/st/lib/e_shop.c b/src/st/lib/e_shop.c index 034f9e9383..b2e7cb3dd0 100644 --- a/src/st/lib/e_shop.c +++ b/src/st/lib/e_shop.c @@ -5506,7 +5506,7 @@ void func_us_801B8A00(Entity* self) { #ifdef VERSION_PSP switch (self->step_s) { case 0: - func_psp_0892A620(1, 1); + func_psp_0892A620(1, true); g_api.PlaySfx(SET_STOP_MUSIC); self->ext.et_801B6F30.unk86 = 1; self->step_s++; diff --git a/src/st/lib_psp/e_shop.c b/src/st/lib_psp/e_shop.c index dd036fb118..6ec1596dd5 100644 --- a/src/st/lib_psp/e_shop.c +++ b/src/st/lib_psp/e_shop.c @@ -7297,7 +7297,7 @@ void func_psp_0926AED0(Entity* self) { #ifdef VERSION_PSP switch (self->step_s) { case 0: - func_psp_0892A620(1, 1); + func_psp_0892A620(1, true); g_api.PlaySfx(SET_STOP_MUSIC); self->ext.et_801B6F30.unk86 = 1; self->step_s++;