From fd3e894915f43bffbd5fd40ff00d7f7463a08222 Mon Sep 17 00:00:00 2001 From: Cuyler36 <24523422+Cuyler36@users.noreply.github.com> Date: Tue, 4 Jun 2024 17:26:57 -0400 Subject: [PATCH] Implement & link jaudio_NES/neosthread.c --- config/disasm_overrides.yml | 1 + config/dol_slices.yml | 6 ++ configure.py | 3 +- include/jaudio_NES/audioconst.h | 17 ++++++ include/jaudio_NES/cpubuf.h | 1 + include/jaudio_NES/dvdthread.h | 1 + include/jaudio_NES/neosthread.h | 1 + include/jaudio_NES/rspsim.h | 8 +++ include/jaudio_NES/sub_sys.h | 9 +++ include/jaudio_NES/system.h | 8 +++ src/static/jaudio_NES/neosthread.c | 96 ++++++++++++++++++++++++++++++ 11 files changed, 150 insertions(+), 1 deletion(-) create mode 100644 include/jaudio_NES/audioconst.h create mode 100644 include/jaudio_NES/rspsim.h create mode 100644 include/jaudio_NES/sub_sys.h create mode 100644 include/jaudio_NES/system.h create mode 100644 src/static/jaudio_NES/neosthread.c diff --git a/config/disasm_overrides.yml b/config/disasm_overrides.yml index 064b20ec..0a450474 100644 --- a/config/disasm_overrides.yml +++ b/config/disasm_overrides.yml @@ -3,6 +3,7 @@ trim_ctors: true symbol_aligns: 0x80018920: 32 0x800190e0: 32 + 0x80019380: 32 0x80207458: 8 # align RunQueue to 0x001251d8 0x800b9140: 32 # align gam_win_moji1_tex to 32 bytes 0x801f71c0: 32 # align texture_buffer_data to 32 bytes diff --git a/config/dol_slices.yml b/config/dol_slices.yml index 9dbcf6f2..b05b1c10 100644 --- a/config/dol_slices.yml +++ b/config/dol_slices.yml @@ -49,6 +49,12 @@ jaudio_NES/audiothread.c: .bss: [0x8017cfc0, 0x80180020] .sbss: [0x80218440, 0x80218460] .sdata2: [0x80218db8, 0x80218dc0] +jaudio_NES/neosthread.c: + .text: [0x800190e0, 0x80019380] + .rodata: [0x800aa538, 0x800aa558] + .bss: [0x80180020, 0x80186440] + .sdata: [0x80217be0, 0x80217be8] + .sbss: [0x80218460, 0x80218478] # jaudio_NES/game64.c: # TODO: finish # .rodata: [0x800a9938, 0x800a9b98] #jaudio_NES/verysimple.c: diff --git a/configure.py b/configure.py index f1e6500f..74631980 100644 --- a/configure.py +++ b/configure.py @@ -628,7 +628,8 @@ JAUDIO_FUNC_ALIGN_32_TUS = [ "sample.c", "aictrl.c", "dummyrom.c", - "audiothread.c" + "audiothread.c", + "neosthread.c" ] class CSource(Source): diff --git a/include/jaudio_NES/audioconst.h b/include/jaudio_NES/audioconst.h new file mode 100644 index 00000000..d131aec1 --- /dev/null +++ b/include/jaudio_NES/audioconst.h @@ -0,0 +1,17 @@ +#ifndef AUDIOCONST_H +#define AUDIOCONST_H + +#include "types.h" +#include "jaudio_NES/audiostruct.h" + +typedef struct ALGlobalsConst_ { + s8 maxChan; + s16 timeBase; + s32 acmdBufSize; + s32 fixSize; + s32 ememSize; +} ALGlobalsConst; + +extern ALGlobalsConst AGC; + +#endif diff --git a/include/jaudio_NES/cpubuf.h b/include/jaudio_NES/cpubuf.h index eb222104..a90de7e4 100644 --- a/include/jaudio_NES/cpubuf.h +++ b/include/jaudio_NES/cpubuf.h @@ -6,5 +6,6 @@ extern u32 CpubufProcess(DSPBUF_EVENTS event); extern void CpuFrameEnd(void); +extern s16* MixCpu(s32 nSamples); #endif diff --git a/include/jaudio_NES/dvdthread.h b/include/jaudio_NES/dvdthread.h index 2cbe83ec..d5606c8a 100644 --- a/include/jaudio_NES/dvdthread.h +++ b/include/jaudio_NES/dvdthread.h @@ -6,6 +6,7 @@ typedef void (*Jac_DVDCallback)(u32); +extern s32 DVDT_LoadtoARAM(u32 owner, char* path, u32 dram, u32 aram, u32 len, u32* outLen, Jac_DVDCallback callback); extern s32 DVDT_DRAMtoARAM(u32 owner, u32 dram, u32 aram, u32 len, u32* outLen, Jac_DVDCallback callback); extern s32 DVDT_ARAMtoDRAM(u32 owner, u32 dram, u32 aram, u32 len, u32* outLen, Jac_DVDCallback callback); extern u32 Jac_CheckFile(char* path); diff --git a/include/jaudio_NES/neosthread.h b/include/jaudio_NES/neosthread.h index fe7ab696..17e552b3 100644 --- a/include/jaudio_NES/neosthread.h +++ b/include/jaudio_NES/neosthread.h @@ -2,6 +2,7 @@ #define NEOSTHREAD_H #include "types.h" +#include "jaudio_NES/audiostruct.h" extern void* neosproc(void* param); diff --git a/include/jaudio_NES/rspsim.h b/include/jaudio_NES/rspsim.h new file mode 100644 index 00000000..93e742a0 --- /dev/null +++ b/include/jaudio_NES/rspsim.h @@ -0,0 +1,8 @@ +#ifndef RSPSIM_H +#define RSPSIM_H + +#include "types.h" + +extern void RspStart2(u32* pTaskCmds, s32 allTasks, s32 param_3); + +#endif diff --git a/include/jaudio_NES/sub_sys.h b/include/jaudio_NES/sub_sys.h new file mode 100644 index 00000000..11b90af1 --- /dev/null +++ b/include/jaudio_NES/sub_sys.h @@ -0,0 +1,9 @@ +#ifndef SUB_SYS_H +#define SUB_SYS_H + +#include "types.h" +#include "jaudio_NES/audiostruct.h" + +extern s32 CreateAudioTask(Acmd* cmds, s16* pSamples, u32 nSamples, s32 param_4); + +#endif diff --git a/include/jaudio_NES/system.h b/include/jaudio_NES/system.h new file mode 100644 index 00000000..51594c22 --- /dev/null +++ b/include/jaudio_NES/system.h @@ -0,0 +1,8 @@ +#ifndef SYSTEM_H +#define SYSTEM_H + +#include "types.h" + +extern void Nas_InitAudio(u64* acmdBuf, s32 acmdBufSize); + +#endif diff --git a/src/static/jaudio_NES/neosthread.c b/src/static/jaudio_NES/neosthread.c new file mode 100644 index 00000000..73f93298 --- /dev/null +++ b/src/static/jaudio_NES/neosthread.c @@ -0,0 +1,96 @@ +#include "jaudio_NES/neosthread.h" + +#include "dolphin/os.h" +#include "jaudio_NES/dummyrom.h" +#include "jaudio_NES/dvdthread.h" +#include "jaudio_NES/aictrl.h" +#include "jaudio_NES/rate.h" +#include "jaudio_NES/audioconst.h" +#include "jaudio_NES/system.h" +#include "jaudio_NES/audiothread.h" +#include "jaudio_NES/cpubuf.h" +#include "jaudio_NES/dummyprobe.h" +#include "jaudio_NES/sub_sys.h" +#include "jaudio_NES/rspsim.h" +#include "jaudio_NES/sample.h" + +#define NEOSTHREAD_IMAGE_LOADED_MSG (0x12345678) +#define NEOSTHREAD_ACMD_BUF_NUM 1600 + +static OSMessageQueue neosproc_mq; +static u32 neosproc_mq_init = FALSE; +static s16* tmp_buf = nullptr; +static BOOL neos_ready = FALSE; + +extern BOOL Neos_Update(s16* dst) { + if (neosproc_mq_init) { + if (OSSendMessage(&neosproc_mq, (OSMessage)dst, OS_MESSAGE_NOBLOCK) == TRUE) { + return TRUE; + } else { + return FALSE; + } + } + + return FALSE; +} + +extern void ImageLoaded(u32 param) { + OSSendMessage(&neosproc_mq, (OSMessage)NEOSTHREAD_IMAGE_LOADED_MSG, OS_MESSAGE_BLOCK); +} + +extern BOOL Neos_CheckBoot(void) { + return neos_ready; +} + +extern void* neosproc(void* param) { + static OSMessage msgbuf[1]; + static u32 cur = 0; + + neos_ready = FALSE; + OSInitMessageQueue(&neosproc_mq, msgbuf, 1); + neosproc_mq_init = TRUE; + u32 neos_rom_top = GetNeosRomTop(); + u32 neos_rom_preloaded = GetNeosRom_PreLoaded(); + u32 neos_file_top = GetNeos_FileTop(); + + DVDT_LoadtoARAM(0, "/audiorom.img", neos_rom_top + neos_rom_preloaded, neos_file_top, 0, nullptr, &ImageLoaded); + + OSMessage msg; + do { + OSReceiveMessage(&neosproc_mq, &msg, 1); + } while (msg != (OSMessage)NEOSTHREAD_IMAGE_LOADED_MSG); + + tmp_buf = (s16*)OSAlloc2(DAC_SIZE * 2); + + /* Initialize neos */ + s32 tmp = AGC.acmdBufSize; + u64* acmdBuf = (u64*)OSAlloc2(tmp); + Nas_InitAudio(acmdBuf, tmp); + NeosSync(); + neos_ready = TRUE; + + Jac_RegisterMixcallback(&MixCpu, MixMode_Interleave); + + do { + static Acmd task_buf[2][NEOSTHREAD_ACMD_BUF_NUM]; + static u32 tasks[2] = { 0, 0 }; + + OSReceiveMessage(&neosproc_mq, &msg, OS_MESSAGE_BLOCK); + Probe_Start(8, "NEOS THREAD"); + s16* samples_dst = (s16*)msg; + tasks[cur] = CreateAudioTask(task_buf[cur], tmp_buf, JAC_FRAMESAMPLES, 0); + + tmp = (cur + 1) & 1; + if (tasks[tmp]) { + RspStart2((u32*)task_buf[tmp], tasks[tmp], 0); + tasks[tmp] = 0; + Jac_bcopy(tmp_buf, samples_dst, DAC_SIZE * 2); + } else { + Jac_bzero(samples_dst, DAC_SIZE * 2); + } + + Probe_Finish(8); + NeosSync(); + cur = tmp; + } while (TRUE); +}