diff --git a/config/splat.pspeu.main.yaml b/config/splat.pspeu.main.yaml index 0657293a96..5ac9096b09 100644 --- a/config/splat.pspeu.main.yaml +++ b/config/splat.pspeu.main.yaml @@ -330,6 +330,7 @@ segments: - [0x30F3C, asm, func_psp_0892F848] - [0x3104C, asm, func_psp_0892F958] - [0x31178, c, main_psp/31178] + - [0x35670, c, main_psp/35670] - [0x359F8, c, main_psp/vector4] - [0x36174, c, main_psp/36174] - [0x38EF0, asm, func_psp_089377FC] @@ -376,7 +377,6 @@ segments: - [0x3E3D0, .data, main_psp/10944] - [0x3E3F0, .data, main_psp/11320] - [0x3E414, .data, main_psp/138B0] - - [0x3E438, data] - [0x3E4D4, .data, main_psp/mpeg/display] - [0x3E540, .data, main_psp/mpeg/fileread] - [0x3E554, .data, main_psp/mpeg/sound] @@ -397,22 +397,22 @@ segments: - [0xAEBAC, data] - {start: 0xAEF24, type: bss, vram: 0x089AD830, name: bss0} - {start: 0xAEF24, type: .bss, vram: 0x089B6540, name: main_psp/11320} - - {start: 0xAEF24, type: bss, vram: 0x08B1FB50, name: bss1} + - {start: 0xAEF24, type: .bss, vram: 0x08B1FB50, name: main_psp/138B0} - {start: 0xAEF24, type: .bss, vram: 0x08B1FB90, name: main_psp/mpeg/avsync} - {start: 0xAEF24, type: .bss, vram: 0x08B1FB94, name: main_psp/mpeg/display} - {start: 0xAEF24, type: .bss, vram: 0x08B1FBBC, name: main_psp/mpeg/fileread} - {start: 0xAEF24, type: .bss, vram: 0x08B1FBDC, name: main_psp/mpeg/sound} - - {start: 0xAEF24, type: bss, vram: 0x08B1FBFC, name: bss2} + - {start: 0xAEF24, type: bss, vram: 0x08B1FBFC, name: bss1} - {start: 0xAEF24, type: .bss, vram: 0x08B21DE8, name: main_psp/1A794} - - {start: 0xAEF24, type: bss, vram: 0x08B41F30, name: bss3} + - {start: 0xAEF24, type: bss, vram: 0x08B41F30, name: bss2} - {start: 0xAEF24, type: .bss, vram: 0x08B41F40, name: main_psp/1B0F0} - {start: 0xAEF24, type: .bss, vram: 0x08B41FB4, name: main_psp/1B61C} - - {start: 0xAEF24, type: bss, vram: 0x08B41FC0, name: bss4} + - {start: 0xAEF24, type: bss, vram: 0x08B41FC0, name: bss3} - {start: 0xAEF24, type: .bss, vram: 0x08B42068, name: main_psp/1BCFC} - - {start: 0xAEF24, type: bss, vram: 0x08C63124, name: bss5} + - {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: bss6} + - {start: 0xAEF24, type: bss, vram: 0x08C6BC30, name: bss5} - {start: 0xAEF24, type: .bss, vram: 0x08DAF2C8, name: main_psp/31178} - - {start: 0xAEF24, type: bss, vram: 0x08E2E5F8, name: bss7} + - {start: 0xAEF24, type: bss, vram: 0x08E2E5F8, name: bss6} - [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 bc257a572a..ada5e9002a 100644 --- a/config/symbols.pspeu.main.txt +++ b/config/symbols.pspeu.main.txt @@ -281,7 +281,10 @@ func_psp_0890EF88 = 0x0890EF88; // ignore:true _write_r = 0x0890F0C8; __swsetup_r = 0x0890F130; func_psp_089123B8 = 0x089123B8; // ignore:false +startCheck = 0x08913314; playMovie = 0x089133D4; +pad_read = 0x08913B48; +avsync_startAudioVideo = 0x08913CA0; avsync_video_setPts = 0x08913D20; avsync_video_getPts = 0x08913DD4; dispbuf_getDrawbuf = 0x0891499C; @@ -672,8 +675,13 @@ top_pad = 0x089B61F0; max_sbrked_mem = 0x089B61F4; max_total_mem = 0x089B61F8; current_mallinfo = 0x089B61FC; +audioOn = 0x08B1FB7C; sce_newlib_heap_delayed_alloc = 0x08B41F30; g_frameBufIdx = 0x08B41FC0; +dispThread = 0x08B42010; +readThread = 0x08B42020; +soundThread = 0x08B42030; +power_cb = 0x08B42040; D_psp_08C63B28 = 0x08C63B28; // size:0x8 D_psp_08C63B30 = 0x08C63B30; // size:0x8 D_psp_08C63B38 = 0x08C63B38; // size:0x8 diff --git a/include/pspsdk/pspthreadman.h b/include/pspsdk/pspthreadman.h index d2e86177c1..a8d8404efd 100644 --- a/include/pspsdk/pspthreadman.h +++ b/include/pspsdk/pspthreadman.h @@ -506,14 +506,14 @@ typedef struct SceKernelSemaInfo { * @par Example: * @code * int semaid; - * semaid = sceKernelCreateSema("MyMutex", 0, 1, 1, 0); + * semaid = sceKernelCreateSema("MyMutex", 0, 1, 1, NULL); * @endcode * * @param name - Specifies the name of the sema * @param attr - Sema attribute flags (normally set to 0) * @param initVal - Sema initial value * @param maxVal - Sema maximum value - * @param option - Sema options (normally set to 0) + * @param option - Sema options (normally set to NULL) * @return A semaphore id */ SceUID sceKernelCreateSema(const char *name, SceUInt attr, int initVal, int maxVal, SceKernelSemaOptParam *option); diff --git a/src/dra_psp/23138.c b/src/dra_psp/23138.c index 4f8a2cce6c..ed17f1cc0a 100644 --- a/src/dra_psp/23138.c +++ b/src/dra_psp/23138.c @@ -5,22 +5,22 @@ extern s32 g_CurrentStream; void func_psp_090FFAB8(void) { - s32 var_a1 = 0; + s32 skipButton = PAD_NONE; switch (g_CurrentStream) { case 0: - var_a1 = 8; + skipButton = PAD_START; break; case 1: - var_a1 = 8; + skipButton = PAD_START; break; case 2: - var_a1 = 0x6008; + skipButton = PAD_CROSS | PAD_CIRCLE | PAD_START; break; case 3: - var_a1 = 0x6008; + skipButton = PAD_CROSS | PAD_CIRCLE | PAD_START; break; } - func_psp_08912820(g_CurrentStream, var_a1); + func_psp_08912820(g_CurrentStream, skipButton); D_8003C728 = 0; g_IsUsingCd = 0; } diff --git a/src/main_psp/138B0.c b/src/main_psp/138B0.c index d4da17e720..d63ea3ddf9 100644 --- a/src/main_psp/138B0.c +++ b/src/main_psp/138B0.c @@ -7,39 +7,41 @@ #include #include -typedef struct unkStruct { - char* unk0; - s32 unk4; -} unkStruct; +#define PLAY_NORMAL (0) +#define PLAY_SKIP (1) +#define PLAY_STOP (10) + +// BSS +static s32 D_psp_08B1FB8C; +static s32 D_psp_08B1FB88 UNUSED; +static s32 playMode; +static u32 D_psp_08B1FB80; +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 D_psp_08B1FB68; +static s32 D_psp_08B1FB64; +static bool D_psp_08B1FB60; +static s32 D_psp_08B1FB5C; +static s32 D_psp_08B1FB58; +static s32 D_psp_08B1FB54; +static s32 umd_cb; -char D_psp_0893CD20[] = "DVDUMD_SAMPLE"; -char D_psp_0893CD30[] = PSP_UMD_ALIAS_NAME; -char D_psp_0893CD38[] = "DVDUMD_CTRL"; extern s32 g_drawWallpaperBackground; -extern s32 D_psp_08B1FB54; -extern s32 D_psp_08B1FB58; -extern s32 D_psp_08B1FB5C; -extern s32 D_psp_08B1FB60; -extern s32 D_psp_08B1FB64; -extern s32 D_psp_08B1FB68; -extern s32 D_psp_08B1FB6C; -extern s32 D_psp_08B1FB70; extern s32 D_psp_08B41FF0; -extern volatile s32 D_psp_08B1FB50; -extern s32 D_psp_08B1FB7C; -extern char D_psp_0893CDB8[]; -extern char D_psp_0893CDC8[]; -extern char D_psp_0893CDD4[]; -extern u32 D_psp_08B1FB80; -extern s32 D_psp_08B1FB84; -extern s32 D_psp_08B42010; -extern s32 D_psp_08B42020; -extern s32 D_psp_08B42030; -extern unkStruct D_psp_0893CD98[]; - -void func_psp_089144BC(void); - -s32 func_psp_089121BC(s32 count, s32 arg, void* param) { +extern s32 dispThread; +extern s32 readThread; +extern s32 soundThread; +extern s32 power_cb; + +s32 dispbuf_func(s32 args, void* argp); +s32 read_func(s32 args, void* argp); +s32 soundbuf_func(s32 args, void* argp); +s32 ringbufferCallBack(void* pBuf, s32 iNum, void* CallbackData); + +s32 umd_func(s32 count, s32 arg, void* param) { D_psp_08B1FB58 = arg; if (arg & PSP_UMD_MEDIA_IN) { D_psp_08B1FB54 |= 1; @@ -60,18 +62,19 @@ s32 func_psp_089121BC(s32 count, s32 arg, void* param) { void func_psp_0891228C(void) { volatile s32 ret; - D_psp_08B1FB50 = - sceKernelCreateCallback(D_psp_0893CD20, func_psp_089121BC, NULL); - D_psp_08B1FB50; - ret = sceUmdRegisterUMDCallBack(D_psp_08B1FB50); + umd_cb = sceKernelCreateCallback("DVDUMD_SAMPLE", umd_func, NULL); + if (umd_cb < 0) { + umd_cb; + } + ret = sceUmdRegisterUMDCallBack(umd_cb); ret; if (sceUmdCheckMedium() == 0) { sceUmdWaitDriveStatCB(PSP_UMD_MEDIA_IN, 0); } - ret = sceUmdActivate(PSP_UMD_MODE_POWERON, D_psp_0893CD30); + ret = sceUmdActivate(PSP_UMD_MODE_POWERON, PSP_UMD_ALIAS_NAME); if (ret < 0) { - sceUmdUnRegisterUMDCallBack(D_psp_08B1FB50); - sceKernelDeleteCallback(D_psp_08B1FB50); + sceUmdUnRegisterUMDCallBack(umd_cb); + sceKernelDeleteCallback(umd_cb); } D_psp_08B1FB5C = 1; sceUmdWaitDriveStatCB(PSP_UMD_READABLE, 0); @@ -121,31 +124,31 @@ void func_psp_0891249C(void) { D_psp_08B1FB5C = 0; func_psp_0891228C(); sp18 = sceKernelCreateThread( - D_psp_0893CD38, func_psp_08912398, 0x32, 0x1000, 0, NULL); + "DVDUMD_CTRL", func_psp_08912398, 0x32, 0x1000, 0, NULL); sp18; D_psp_08B41FF0 = sp18; sp1C = sceKernelStartThread(D_psp_08B41FF0, 0, 0); sp1C; } -s32 func_psp_08912530(s32 count, s32 arg, void* param) { +s32 power_func(s32 count, s32 arg, void* param) { if (arg & PSP_POWER_CB_POWER_SWITCH) { - D_psp_08B1FB70 = 1; + D_psp_08B1FB70 = true; } if (arg & PSP_POWER_CB_HOLD_SWITCH) { } if (arg & PSP_POWER_CB_STANDBY) { } if (arg & PSP_POWER_CB_RESUME_COMPLETE) { - D_psp_08B1FB70 = 0; - D_psp_08B1FB60 = 0; + D_psp_08B1FB70 = false; + D_psp_08B1FB60 = false; D_psp_08B1FB64++; } if (arg & PSP_POWER_CB_RESUMING) { - D_psp_08B1FB60 = 1; + D_psp_08B1FB60 = true; } if (arg & PSP_POWER_CB_SUSPENDING) { - D_psp_08B1FB60 = 1; + D_psp_08B1FB60 = true; } return 0; } @@ -157,29 +160,63 @@ void func_psp_08912608(void) { D_psp_08B1FB6C++; } -INCLUDE_ASM("main_psp/nonmatchings/main_psp/138B0", func_psp_08912640); +void func_psp_08912640(void) { + volatile s32* var_s0; -INCLUDE_ASM("main_psp/nonmatchings/main_psp/138B0", func_psp_0891269C); + if (D_psp_08B1FB6C <= 0) { + var_s0 = &D_psp_08B1FB6C; + *var_s0; + } + D_psp_08B1FB6C--; + sceKernelPowerUnlock(0); +} + +void func_psp_0891269C(void) { + volatile s32 ret; + + D_psp_08B1FB60 = false; + D_psp_08B1FB64 = 0; + power_cb = sceKernelCreateCallback("DVDUMD_SAMPLE", power_func, NULL); + if (power_cb < 0) { + power_cb; + } + ret = scePowerRegisterCallback(0, power_cb); + ret; + D_psp_08B1FB6C = 0; + D_psp_08B1FB68 = sceKernelCreateSema("p_off_lock_sema", 0, 1, 1, NULL); +} -INCLUDE_ASM("main_psp/nonmatchings/main_psp/138B0", func_psp_0891273C); +void func_psp_0891273C(void) { D_psp_08B1FB74 = 0; } -INCLUDE_ASM("main_psp/nonmatchings/main_psp/138B0", func_psp_0891274C); +void func_psp_0891274C(void) { D_psp_08B1FB8C = 0; } -INCLUDE_ASM("main_psp/nonmatchings/main_psp/138B0", func_psp_0891275C); +s32 func_psp_0891275C(s32 arg0) { + s32 ret; + + ret = func_psp_08919C8C(D_psp_08B1FB8C); + D_psp_08B1FB8C += ((arg0 + 0x3FU) / 0x40) * 0x40; + if (func_psp_08919C8C(D_psp_08B1FB8C) == 0) { + } + return ret; +} void func_psp_089127D8(void* arg0) {} -INCLUDE_ASM("main_psp/nonmatchings/main_psp/138B0", func_psp_089127E8); +void func_psp_089127E8(void) { + dispThread = -1; + readThread = -1; + soundThread = -1; +} s32 func_psp_08912814(void) { return 0x5333; } -s32 func_psp_08912820(s32 arg0, s32 arg1) { - s32 temp_s0; +s32 func_psp_08912820(s32 movieIdx, s32 skipButton) { + s32 ret; func_psp_0892A8C0(); DrawSync(0); VSync(0); - temp_s0 = func_psp_089128C4(arg0, arg1); + ret = func_psp_089128C4(movieIdx, skipButton); g_drawWallpaperBackground = 2; func_psp_08910044(); func_psp_0891A800(); @@ -187,29 +224,36 @@ s32 func_psp_08912820(s32 arg0, s32 arg1) { func_psp_089144BC(); func_psp_089144BC(); func_psp_089144BC(); - return temp_s0; + return ret; } -s32 dispbuf_func(s32 args, void* argp); -s32 read_func(s32 args, void* argp); -s32 soundbuf_func(s32 args, void* argp); -s32 ringbufferCallBack(void* pBuf, s32 iNum, void* CallbackData); +typedef struct unkStruct { + char* unk0; + bool usesAudio; +} unkStruct; + +static unkStruct D_psp_0893CD98[] = { + {"MOVIE/logo.pmf;1", true}, + {"MOVIE/no2.pmf;1", true}, + {"MOVIE/no3.pmf;1", true}, + {"MOVIE/no4.pmf;1", true}, +}; -s32 func_psp_089128C4(s32 arg0, s32 arg1) { +s32 func_psp_089128C4(s32 movieIdx, s32 skipButton) { SceMpeg mpeg; SceMpegRingbuffer ringbuf; SceMpegStream* pStream[2]; SceMpegAu avcAu; SceMpegAu atracAu; char filename[0x200]; + StrFile strFile; - s32 bufferSize[1]; - s32 workSize[1]; - s32 fileSize; - s32 audioEsSize; - s32 audioOutSize; + + s32 bufferSize[1], workSize[1], fileSize; + s32 audioEsSize, audioOutSize; s32 streamOffset; s32 ret[1]; + t_displayBuffer pDisp; t_ringBuffer pRing; t_soundBuffer pSound; @@ -219,22 +263,22 @@ s32 func_psp_089128C4(s32 arg0, s32 arg1) { SceMpegAvcMode decodeMode; s32 var_s7; char* temp_s6; - unkStruct* temp_s4; + unkStruct* ptr; u8* avcEsBuf; u8* pPSPStream; u8* pWorkBuf; u8* pAudioBuf; - temp_s4 = &D_psp_0893CD98[arg0]; + ptr = &D_psp_0893CD98[movieIdx]; memset(&pRing, 0, sizeof(t_ringBuffer)); func_psp_0891274C(); avcEsBuf = NULL; pPSPStream = NULL; pWorkBuf = NULL; pAudioBuf = NULL; - temp_s6 = temp_s4->unk0; - D_psp_08B1FB7C = temp_s4->unk4; + temp_s6 = ptr->unk0; + audioOn = ptr->usesAudio; decodeMode.iUnk0 = -1; decodeMode.iPixelFormat = 3; ret[0] = sceMpegInit(); @@ -332,7 +376,7 @@ s32 func_psp_089128C4(s32 arg0, s32 arg1) { 0; goto label1; } - if (D_psp_08B1FB7C != 0) { + if (audioOn) { pStream[1] = sceMpegRegistStream(&mpeg, 1, 0); if (pStream[1] == NULL) { 0; @@ -349,7 +393,7 @@ s32 func_psp_089128C4(s32 arg0, s32 arg1) { 0; goto label1; } - if (D_psp_08B1FB7C != 0) { + if (audioOn) { ret[0] = sceMpegQueryAtracEsSize(&mpeg, &audioEsSize, &audioOutSize); if (ret[0] != 0) { 0; @@ -374,7 +418,7 @@ s32 func_psp_089128C4(s32 arg0, s32 arg1) { 0; goto label2; } - if (D_psp_08B1FB7C != 0) { + if (audioOn) { if (soundbuf_create(&pSound, audioOutSize, 4, func_psp_08912814()) < 0) { 0; @@ -385,7 +429,7 @@ s32 func_psp_089128C4(s32 arg0, s32 arg1) { 0; goto label4; } - if (D_psp_08B1FB7C != 0) { + if (audioOn) { if (avsync_create(&pAvSync, &pDisp, &pSound, 3) < 0) { 0; goto label5; @@ -397,77 +441,77 @@ s32 func_psp_089128C4(s32 arg0, s32 arg1) { } } sceKernelChangeThreadPriority(sceKernelGetThreadId(), 0x40); - D_psp_08B42010 = - sceKernelCreateThread(D_psp_0893CDB8, dispbuf_func, 0x3F, 0x2000, 0, 0); - D_psp_08B42020 = - sceKernelCreateThread(D_psp_0893CDC8, read_func, 0x41, 0x2000, 0, 0); - if (D_psp_08B1FB7C != 0) { - D_psp_08B42030 = sceKernelCreateThread( - D_psp_0893CDD4, soundbuf_func, 0x3D, 0x2000, 0, 0); - } - D_psp_08B1FB84 = 0; - if (D_psp_08B1FB7C != 0) { + dispThread = sceKernelCreateThread( + "displayThread", dispbuf_func, 0x3F, 0x2000, 0, 0); + readThread = + sceKernelCreateThread("readThread", read_func, 0x41, 0x2000, 0, 0); + if (audioOn) { + soundThread = sceKernelCreateThread( + "soundThread", soundbuf_func, 0x3D, 0x2000, 0, 0); + } + playMode = PLAY_NORMAL; + if (audioOn) { soundbuf_reset(&pSound); } dispbuf_reset(&pDisp); read_reset(&pRing, fileSize, streamOffset); avsync_reset(&pAvSync); - if (D_psp_08B1FB7C != 0) { - sceKernelStartThread(D_psp_08B42030, sizeof(t_avSyncControl), &pAvSync); - } - sceKernelStartThread(D_psp_08B42010, sizeof(t_avSyncControl), &pAvSync); - sceKernelStartThread(D_psp_08B42020, sizeof(t_ringBuffer), &pRing); - if ((ret[0] = playMovie( - &mpeg, &ringbuf, &pStreamData, &pRing, &pAvSync, arg1)) != 0) { - if (D_psp_08B1FB84 == 1) { + if (audioOn) { + sceKernelStartThread(soundThread, sizeof(t_avSyncControl), &pAvSync); + } + sceKernelStartThread(dispThread, sizeof(t_avSyncControl), &pAvSync); + sceKernelStartThread(readThread, sizeof(t_ringBuffer), &pRing); + if ((ret[0] = playMovie(&mpeg, &ringbuf, &pStreamData, &pRing, &pAvSync, + skipButton)) != 0) { + if (playMode == PLAY_SKIP) { if (sceMpegFlushAllStream(&mpeg) != 0) { 0; goto label6; } - D_psp_08B1FB84 = 0; + playMode = PLAY_NORMAL; } else { - if (D_psp_08B1FB84 == 0xA) { + if (playMode == PLAY_STOP) { 0; goto label6; } } } - if (D_psp_08B1FB7C != 0) { - sceKernelWaitThreadEnd(D_psp_08B42030, NULL); + if (audioOn) { + sceKernelWaitThreadEnd(soundThread, NULL); } - sceKernelWaitThreadEnd(D_psp_08B42010, NULL); - sceKernelWaitThreadEnd(D_psp_08B42020, NULL); + sceKernelWaitThreadEnd(dispThread, NULL); + sceKernelWaitThreadEnd(readThread, NULL); label6: - if (D_psp_08B1FB7C != 0) { - sceKernelWaitThreadEnd(D_psp_08B42030, NULL); - } - sceKernelWaitThreadEnd(D_psp_08B42010, NULL); - sceKernelWaitThreadEnd(D_psp_08B42020, NULL); - if (D_psp_08B1FB7C != 0) { - sceKernelTerminateDeleteThread(D_psp_08B42030); - D_psp_08B42030 = -1; - } - sceKernelTerminateDeleteThread(D_psp_08B42010); - D_psp_08B42010 = -1; - sceKernelTerminateDeleteThread(D_psp_08B42020); - D_psp_08B42020 = -1; + if (audioOn) { + sceKernelWaitThreadEnd(soundThread, NULL); + } + sceKernelWaitThreadEnd(dispThread, NULL); + sceKernelWaitThreadEnd(readThread, NULL); + if (audioOn) { + sceKernelTerminateDeleteThread(soundThread); + soundThread = -1; + } + sceKernelTerminateDeleteThread(dispThread); + dispThread = -1; + sceKernelTerminateDeleteThread(readThread); + readThread = -1; label5: avsync_delete(&pAvSync); label4: read_delete(&pRing); label3: - if (D_psp_08B1FB7C != 0) { + if (audioOn) { soundbuf_delete(&pSound); } label2: dispbuf_delete(&pDisp); label1: - if (D_psp_08B1FB7C != 0) { + if (audioOn) { pAudioBuf = NULL; } sceMpegFreeAvcEsBuf(&mpeg, avcEsBuf); sceMpegUnRegistStream(&mpeg, pStream[0]); - if (D_psp_08B1FB7C != 0) { + if (audioOn) { sceMpegUnRegistStream(&mpeg, pStream[1]); } label0: @@ -496,26 +540,26 @@ s32 func_psp_089132C8(t_avSyncControl* pAvSync, t_ringBuffer* pRing) { return ret; } -s32 func_psp_08913314(t_avSyncControl* pAvSync, t_ringBuffer* pRing) { - s32 var_s0; +s32 startCheck(t_avSyncControl* pAvSync, t_ringBuffer* pRing) { + s32 ret; - if (D_psp_08B1FB7C != 0) { + if (audioOn) { if (dispbuf_getCapacity(pAvSync->pDisp) == 0 && soundbuf_getCapacity(pAvSync->pSound) == 0) { - func_psp_08913CA0(pAvSync); - var_s0 = 1; + avsync_startAudioVideo(pAvSync); + ret = 1; } else { - var_s0 = -1; + ret = -1; } } else { if (dispbuf_getCapacity(pAvSync->pDisp) == 0) { - func_psp_08913CA0(pAvSync); - var_s0 = 0; + avsync_startAudioVideo(pAvSync); + ret = 0; } else { - var_s0 = -1; + ret = -1; } } - return var_s0; + return ret; } INCLUDE_ASM("main_psp/nonmatchings/main_psp/138B0", playMovie); @@ -552,9 +596,9 @@ s32 readHeader( return ret; } -s32 func_psp_08913B48(t_displayBuffer* pDisp, s32 arg1) { - if (arg1 & PadReadPSP()) { - D_psp_08B1FB84 = 1; +s32 pad_read(t_displayBuffer* pDisp, s32 skipButton) { + if (skipButton & PadReadPSP()) { + playMode = PLAY_SKIP; return 1; } return 0; diff --git a/src/main_psp/1B0F0.c b/src/main_psp/1B0F0.c index 852bc936d7..8e6cb4e993 100644 --- a/src/main_psp/1B0F0.c +++ b/src/main_psp/1B0F0.c @@ -30,59 +30,59 @@ static Picture wallpaper; static u8 D_psp_08B41F6C[0x30] UNUSED; static s32 D_psp_08B41F68; static u8* D_psp_08B41F64; -static u16 D_psp_08B41F60; -static SceCtrlData D_psp_08B41F50; -static SceCtrlData D_psp_08B41F40; +static u16 buttonsPressed; +static SceCtrlData prevPad; +static SceCtrlData thisPad; void* memalign(size_t, size_t); void func_psp_08919C4C(void); -s32 func_psp_08933F7C(u8, u8); +s32 MapJoystickToButtons(u8, u8); void func_psp_08919D98(Unk08919D98* arg0); void _init(void) {} void _fini(void) {} -void func_psp_08919A0C(void) { +void InitPad(void) { sceCtrlSetSamplingMode(PSP_CTRL_MODE_ANALOG); - sceCtrlReadBufferPositive(&D_psp_08B41F40, 1); - sceCtrlReadBufferPositive(&D_psp_08B41F50, 1); + sceCtrlReadBufferPositive(&thisPad, 1); + sceCtrlReadBufferPositive(&prevPad, 1); } static void UpdatePad(void) { u32 buttons = 0; - sceCtrlPeekBufferPositive(&D_psp_08B41F40, 1); - if (func_psp_08932790()) { - D_psp_08B41F40.Buttons &= + sceCtrlPeekBufferPositive(&thisPad, 1); + if (GetDxCUseAnalogStick()) { + thisPad.Buttons &= ~(PSP_CTRL_UP | PSP_CTRL_RIGHT | PSP_CTRL_DOWN | PSP_CTRL_LEFT); - if (!(D_psp_08B41F40.Buttons & PSP_CTRL_HOLD)) { - buttons = func_psp_08933F7C(D_psp_08B41F40.Lx, D_psp_08B41F40.Ly); + if (!(thisPad.Buttons & PSP_CTRL_HOLD)) { + buttons = MapJoystickToButtons(thisPad.Lx, thisPad.Ly); } if (buttons != 0) { sceKernelPowerTick(PSP_POWER_TICK_DISPLAY); } - D_psp_08B41F40.Buttons |= buttons; + thisPad.Buttons |= buttons; } - if (D_psp_08B41F40.TimeStamp != D_psp_08B41F50.TimeStamp) { - D_psp_08B41F60 = D_psp_08B41F40.Buttons & 0xFFFF; - D_psp_08B41F60 ^= D_psp_08B41F50.Buttons & 0xFFFF; - D_psp_08B41F60 &= D_psp_08B41F40.Buttons & 0xFFFF; - memcpy(&D_psp_08B41F50, &D_psp_08B41F40, sizeof(SceCtrlData)); + if (thisPad.TimeStamp != prevPad.TimeStamp) { + buttonsPressed = thisPad.Buttons & 0xFFFF; + buttonsPressed ^= prevPad.Buttons & 0xFFFF; + buttonsPressed &= thisPad.Buttons & 0xFFFF; + memcpy(&prevPad, &thisPad, sizeof(SceCtrlData)); } } u32 PadReadPSP(void) { u32 buttons; UpdatePad(); - buttons = D_psp_08B41F40.Buttons & 0xFFFF; + buttons = thisPad.Buttons & 0xFFFF; return buttons; } u32 PadRead_PSP(void) { return PadReadPSP(); } -void func_psp_08919C00(s32 arg0) { +void func_psp_08919C00(s32 size) { func_psp_08919C4C(); - D_psp_08B41F68 = arg0; + D_psp_08B41F68 = size; D_psp_08B41F64 = memalign(0x40, D_psp_08B41F68); } @@ -96,7 +96,7 @@ void func_psp_08919C4C(void) { u8* func_psp_08919C8C(s32 arg0) { s32 sp10 = arg0; if (func_psp_08919CE4() < sp10) { - return 0; + return NULL; } return D_psp_08B41F64 + arg0; } diff --git a/src/main_psp/1B61C.c b/src/main_psp/1B61C.c index 71c90d195a..10a16fa77c 100644 --- a/src/main_psp/1B61C.c +++ b/src/main_psp/1B61C.c @@ -173,7 +173,7 @@ int main(int argc, char* argv[]) { sceDisplaySetVblankCallback(0, &VBlankhandler, NULL); func_psp_08919C00(0x480000); func_psp_0891273C(); - func_psp_08919A0C(); + InitPad(); func_psp_0891ACBC(); func_psp_08930324(); SetScreenMode(SCREEN_MODE_FULL); diff --git a/src/main_psp/31178.c b/src/main_psp/31178.c index e99c808b4b..e74e33201c 100644 --- a/src/main_psp/31178.c +++ b/src/main_psp/31178.c @@ -1130,7 +1130,7 @@ s32 GetDxCWallpaperIndex(void) { return D_psp_08DED03C.wallpaperIndex; } s32 func_psp_0893277C(void) { return D_psp_08DED03C.unk5; } -s32 func_psp_08932790(void) { return D_psp_08DED03C.unk6; } +s32 GetDxCUseAnalogStick(void) { return D_psp_08DED03C.useAnalogStick; } INCLUDE_ASM("main_psp/nonmatchings/main_psp/31178", func_psp_089327A4); @@ -1301,5 +1301,3 @@ INCLUDE_ASM("main_psp/nonmatchings/main_psp/31178", func_psp_08933ED8); INCLUDE_ASM("main_psp/nonmatchings/main_psp/31178", func_psp_08933F5C); INCLUDE_ASM("main_psp/nonmatchings/main_psp/31178", func_psp_08933F6C); - -INCLUDE_ASM("main_psp/nonmatchings/main_psp/31178", func_psp_08933F7C); diff --git a/src/main_psp/35670.c b/src/main_psp/35670.c new file mode 100644 index 0000000000..d6542ddac4 --- /dev/null +++ b/src/main_psp/35670.c @@ -0,0 +1,89 @@ +// 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 + +float sceVfpuVector4InnerProductXYZ( + const ScePspFVector4* pv0, const ScePspFVector4* pv1); +ScePspFVector4* sceVfpuVector4NormalizeXYZ( + ScePspFVector4* pv0, const ScePspFVector4* pv1); + +s32 MapJoystickToButtons(u8 x, u8 y) { + ScePspFVector4 dir; + + float fx = (x - 0x80) / 128.0f; + float fy = -1.0f * ((y - 0x80) / 128.0f); + s32 pad = 0; + + if (-0.5f < fx && fx < 0.5f) { + fx = 0.0f; + } else { + sceKernelPowerTick(6); + } + if (-0.5f < fy && fy < 0.5f) { + fy = 0.0f; + } else { + sceKernelPowerTick(6); + } + dir.w = 1.0f; + dir.x = fx; + dir.y = fy; + dir.z = 0.0f; + if (sceVfpuVector4InnerProductXYZ(&dir, &dir) >= 0.48999998f) { + ScePspFVector4 padDir; + padDir.w = 1.0f; + padDir.z = 0.0f; + sceVfpuVector4NormalizeXYZ(&dir, &dir); + if (fx >= 0.5f) { + padDir.x = 1.0f; + padDir.y = 0.0f; + if (sceVfpuVector4InnerProductXYZ(&dir, &padDir) >= 0.9612617f) { + pad |= PSP_CTRL_RIGHT; + } + padDir.x = 0.70710677f; + padDir.y = 0.70710677f; + if (sceVfpuVector4InnerProductXYZ(&dir, &padDir) >= 0.9612617f) { + pad |= PSP_CTRL_RIGHT | PSP_CTRL_UP; + } + padDir.x = 0.70710677f; + padDir.y = -0.70710677f; + if (sceVfpuVector4InnerProductXYZ(&dir, &padDir) >= 0.9612617f) { + pad |= PSP_CTRL_RIGHT | PSP_CTRL_DOWN; + } + } else if (fx <= -0.5f) { + padDir.x = -1.0f; + padDir.y = 0.0f; + if (sceVfpuVector4InnerProductXYZ(&dir, &padDir) >= 0.9612617f) { + pad |= PSP_CTRL_LEFT; + } + padDir.x = -0.70710677f; + padDir.y = 0.70710677f; + if (sceVfpuVector4InnerProductXYZ(&dir, &padDir) >= 0.9612617f) { + pad |= PSP_CTRL_LEFT | PSP_CTRL_UP; + } + padDir.x = -0.70710677f; + padDir.y = -0.70710677f; + if (sceVfpuVector4InnerProductXYZ(&dir, &padDir) >= 0.9612617f) { + pad |= PSP_CTRL_LEFT | PSP_CTRL_DOWN; + } + } + if (fy >= 0.5f) { + padDir.y = 1.0f; + padDir.x = 0.0f; + if (sceVfpuVector4InnerProductXYZ(&dir, &padDir) >= 0.9612617f) { + pad |= PSP_CTRL_UP; + } + } else if (fy <= -0.5f) { + padDir.y = -1.0f; + padDir.x = 0.0f; + if (sceVfpuVector4InnerProductXYZ(&dir, &padDir) >= 0.9612617f) { + pad |= PSP_CTRL_DOWN; + } + } + } + return pad; +} diff --git a/src/main_psp/main_psp_private.h b/src/main_psp/main_psp_private.h index 5a9dbbc8a6..d7f4aa8655 100644 --- a/src/main_psp/main_psp_private.h +++ b/src/main_psp/main_psp_private.h @@ -41,7 +41,7 @@ typedef struct { u8 wallpaperIndex; u8 unk4[0x10]; u8 unk5; - u8 unk6; + u8 useAnalogStick; u8 unk7[0x969]; SoTNSaveData sotnSaveData; } DxCSaveData; // size: 0x20AD0 diff --git a/src/main_psp/mpeg/avsync.c b/src/main_psp/mpeg/avsync.c index dbb3e66c60..e69f4298fe 100644 --- a/src/main_psp/mpeg/avsync.c +++ b/src/main_psp/mpeg/avsync.c @@ -31,10 +31,10 @@ s32 avsync_delete(t_avSyncControl* pAvSync) { return 0; } -s32 func_psp_08913CA0(t_avSyncControl* pAvSync) { - func_psp_08914E44(pAvSync->pDisp); +s32 avsync_startAudioVideo(t_avSyncControl* pAvSync) { + dispbuf_startVideo(pAvSync->pDisp); if (pAvSync->pSound != NULL) { - func_psp_08916310(pAvSync->pSound); + soundbuf_startAudio(pAvSync->pSound); } return 0; } diff --git a/src/main_psp/mpeg/display.c b/src/main_psp/mpeg/display.c index 4577fece25..0ab0586729 100644 --- a/src/main_psp/mpeg/display.c +++ b/src/main_psp/mpeg/display.c @@ -321,7 +321,7 @@ s32 dispbuf_func(s32 size, void* argp) { return 0; } -void func_psp_08914E44(t_displayBuffer* pDisp) { +void dispbuf_startVideo(t_displayBuffer* pDisp) { sceKernelSignalSema(pDisp->startSema, 1); } @@ -337,7 +337,7 @@ s32 dispbuf_show(t_displayBuffer* pDisp) { return 0; } -void func_psp_08914EE0(s32 arg0, s32 arg1) { - D_psp_08B1FBB0.w = arg0; - D_psp_08B1FBB0.h = arg1; +void func_psp_08914EE0(s32 w, s32 h) { + D_psp_08B1FBB0.w = w; + D_psp_08B1FBB0.h = h; } diff --git a/src/main_psp/mpeg/sound.c b/src/main_psp/mpeg/sound.c index 4a921deea1..c258b25fa1 100644 --- a/src/main_psp/mpeg/sound.c +++ b/src/main_psp/mpeg/sound.c @@ -153,7 +153,7 @@ s32 func_psp_089162C8(t_soundBuffer* pSound) { s32 func_psp_089162F0(t_soundBuffer* pSound) { return *pSound->unk4; } -void func_psp_08916310(t_soundBuffer* pSound) { +void soundbuf_startAudio(t_soundBuffer* pSound) { sceKernelSignalSema(pSound->startSema, 1); }