From 1ae02605f687697d71d4b0fdfd9193575d58f17f Mon Sep 17 00:00:00 2001 From: Cuyler36 <24523422+Cuyler36@users.noreply.github.com> Date: Mon, 3 Jun 2024 18:52:26 -0400 Subject: [PATCH] Implement & link jaudio_NES/dummyrom.c --- config/analysis_overrides.yml | 1 + config/dol_slices.yml | 5 ++ configure.py | 3 +- include/jaudio_NES/audiocommon.h | 3 + include/jaudio_NES/audiostruct.h | 12 +--- include/jaudio_NES/dummyrom.h | 23 ++++++++ include/jaudio_NES/dvdthread.h | 13 +++++ include/jaudio_NES/os.h | 9 +++ include/libultra/osMesg.h | 4 +- src/static/jaudio_NES/dummyrom.c | 94 ++++++++++++++++++++++++++++++++ 10 files changed, 153 insertions(+), 14 deletions(-) create mode 100644 include/jaudio_NES/dummyrom.h create mode 100644 include/jaudio_NES/dvdthread.h create mode 100644 include/jaudio_NES/os.h create mode 100644 src/static/jaudio_NES/dummyrom.c diff --git a/config/analysis_overrides.yml b/config/analysis_overrides.yml index 55996991..eb088a0b 100644 --- a/config/analysis_overrides.yml +++ b/config/analysis_overrides.yml @@ -5,6 +5,7 @@ blocked_targets: - 0x800A97E0 # boot.c local static const tbl, also start of .rodata - 0x80008000 - 0x80018800 + - 0x800189C0 - 0x801F6C7C # tcs_bad - 0x801F6C7D # ics_bad - 0x800a9a90 diff --git a/config/dol_slices.yml b/config/dol_slices.yml index 5136ef25..fa591fcf 100644 --- a/config/dol_slices.yml +++ b/config/dol_slices.yml @@ -38,6 +38,11 @@ jaudio_NES/aictrl.c: .sdata2: [0x80218da8, 0x80218db8] jaudio_NES/sample.c: .text: [0x80018640, 0x80018920] +jaudio_NES/dummyrom.c: + .text: [0x80018920, 0x80018bc0] + .rodata: [0x800aa518, 0x800aa528] +# .bss: [0x8020d78c, 0x8020d7a0] # placed in common bss + .sbss: [0x80218420, 0x80218440] # jaudio_NES/game64.c: # TODO: finish # .rodata: [0x800a9938, 0x800a9b98] #jaudio_NES/verysimple.c: diff --git a/configure.py b/configure.py index 04cc9feb..1440224d 100644 --- a/configure.py +++ b/configure.py @@ -626,7 +626,8 @@ class AsmSource(Source): JAUDIO_FUNC_ALIGN_32_TUS = [ "sample.c", - "aictrl.c" + "aictrl.c", + "dummyrom.c" ] class CSource(Source): diff --git a/include/jaudio_NES/audiocommon.h b/include/jaudio_NES/audiocommon.h index a72adf0d..6f3a7ce6 100644 --- a/include/jaudio_NES/audiocommon.h +++ b/include/jaudio_NES/audiocommon.h @@ -10,6 +10,9 @@ extern "C" { #define S16_MIN (-0x8000) #define S16_MAX (0x7FFF) +#define AUDIO_ARAM_SIZE 0x400000 /* 4MB */ +#define AUDIO_ARAM_HEAP_SIZE 0xC000 + #ifdef __cplusplus } #endif diff --git a/include/jaudio_NES/audiostruct.h b/include/jaudio_NES/audiostruct.h index 4e38a893..1cd1f149 100644 --- a/include/jaudio_NES/audiostruct.h +++ b/include/jaudio_NES/audiostruct.h @@ -3,6 +3,7 @@ #include "types.h" #include "jaudio_NES/audiocommon.h" +#include "PR/abi.h" #ifdef __cplusplus extern "C" { @@ -39,17 +40,6 @@ typedef struct AudioPort_ { /* 0x04 */ u32 param; } AudioPort; -/* sizeof(Acmd) == 0x4*/ -typedef union Acmd { - struct { - /* 0x00 */ u8 p0; - /* 0x01 */ u8 p1; - /* 0x02 */ u8 p2; - /* 0x03 */ u8 p3; - }; - /* 0x00 */ u32 uint32; -} Acmd; - /* sizeof(ALHeap) == 0x14 */ typedef struct ALHeap { /* 0x00 */ u8* base; diff --git a/include/jaudio_NES/dummyrom.h b/include/jaudio_NES/dummyrom.h new file mode 100644 index 00000000..76d8be69 --- /dev/null +++ b/include/jaudio_NES/dummyrom.h @@ -0,0 +1,23 @@ +#ifndef DUMMYROM_H +#define DUMMYROM_H + +#include "types.h" +#include "jaudio_NES/audiostruct.h" +#include "libultra/libultra.h" + +#define DUMMYROM_DRAM_TO_ARAM 0 +#define DUMMYROM_ARAM_TO_DRAM 1 + +extern u8* JAC_ARAM_DMA_BUFFER_TOP; +ALHeap aram_hp; /* placed in common bss */ + +extern u32 GetNeos_FileTop(void); +extern u32 GetNeosRomTop(void); +extern u32 GetNeosRom_PreLoaded(void); +extern void SetPreCopy_NeosRom(u8* load_addr, u32 load_size, BOOL cut_flag); +extern BOOL ARAMStartDMAmesg(u32 dir, u32 dramAddr, u32 aramAddr, u32 size, s32 unused, OSMesgQueue* mq); +extern void Jac_SetAudioARAMSize(u32 size); +extern void ARAllocFull(u32* outSize); +extern void Jac_InitARAM(u32 loadAudiorom); + +#endif diff --git a/include/jaudio_NES/dvdthread.h b/include/jaudio_NES/dvdthread.h new file mode 100644 index 00000000..2d0a4a64 --- /dev/null +++ b/include/jaudio_NES/dvdthread.h @@ -0,0 +1,13 @@ +#ifndef DVDTHREAD_H +#define DVDTHREAD_H + +#include "types.h" +#include "dolphin/dvd.h" + +typedef void (*Jac_DVDCallback)(u32); + +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); + +#endif diff --git a/include/jaudio_NES/os.h b/include/jaudio_NES/os.h new file mode 100644 index 00000000..6e9bd107 --- /dev/null +++ b/include/jaudio_NES/os.h @@ -0,0 +1,9 @@ +#ifndef OS_H +#define OS_H + +#include "types.h" +#include "libultra/libultra.h" + +extern int Z_osSendMesg(OSMesgQueue* mq, OSMesg msg, s32 block); + +#endif diff --git a/include/libultra/osMesg.h b/include/libultra/osMesg.h index c54948e1..7ffaff64 100644 --- a/include/libultra/osMesg.h +++ b/include/libultra/osMesg.h @@ -7,7 +7,7 @@ typedef void* OSMesg; -typedef struct OSMesgQueue { +typedef struct OSMesgQueue_s { /* 0x00 */ OSThread* mtqueue; /* 0x04 */ OSThread* fullqueue; /* 0x08 */ int validCount; @@ -16,7 +16,7 @@ typedef struct OSMesgQueue { /* 0x14 */ OSMesg* msg; } OSMesgQueue; // size = 0x18 -extern void osCreateMesgQueue(OSMessageQueue* mq ,OSMessage msg, int flags); +extern void osCreateMesgQueue(OSMessageQueue* mq, OSMessage msg, int flags); extern int osSendMesg(OSMessageQueue* mq, OSMessage msg, int flags); extern int osRecvMesg(OSMessageQueue* mq, OSMessage* msg, int flags); diff --git a/src/static/jaudio_NES/dummyrom.c b/src/static/jaudio_NES/dummyrom.c new file mode 100644 index 00000000..d02e3ce3 --- /dev/null +++ b/src/static/jaudio_NES/dummyrom.c @@ -0,0 +1,94 @@ +#include "jaudio_NES/dummyrom.h" + +#include "dolphin/ar.h" +#include "jaudio_NES/dvdthread.h" +#include "jaudio_NES/os.h" +#include "jaudio_NES/memory.h" + +u8* JAC_ARAM_DMA_BUFFER_TOP = nullptr; +static u32 AUDIO_ARAM_TOP = 0; +static u32 CARD_SECURITY_BUFFER = 0; +static u32 init_load_size = 0; +static u8* init_load_addr = nullptr; +static BOOL init_cut_flag = FALSE; +static u32 SELECTED_ARAM_SIZE = 0; + +extern u32 GetNeos_FileTop(void) { + if (init_cut_flag) { + return 0; + } + + return init_load_size; +} + +extern u32 GetNeosRomTop(void) { + return AUDIO_ARAM_TOP; +} + +extern u32 GetNeosRom_PreLoaded(void) { + DVDT_DRAMtoARAM(0, (u32)init_load_addr, AUDIO_ARAM_TOP, init_load_size, nullptr, nullptr); + return init_load_size; +} + +extern void SetPreCopy_NeosRom(u8* load_addr, u32 load_size, BOOL cut_flag) { + init_load_size = load_size; + init_load_addr = load_addr; + init_cut_flag = cut_flag; +} + +static void mesg_finishcall(u32 mq) { + Z_osSendMesg((OSMesgQueue*)mq, NULL, OS_MESSAGE_NOBLOCK); +} + +extern BOOL ARAMStartDMAmesg(u32 dir, u32 dramAddr, u32 aramAddr, u32 size, s32 unused, OSMesgQueue* mq) { + aramAddr += AUDIO_ARAM_TOP; + + if (dir == DUMMYROM_ARAM_TO_DRAM) { + DVDT_ARAMtoDRAM((u32)mq, dramAddr, aramAddr, size, nullptr, &mesg_finishcall); + } else { + DVDT_DRAMtoARAM((u32)mq, dramAddr, aramAddr, size, nullptr, &mesg_finishcall); + } + + return FALSE; +} + +extern void Jac_SetAudioARAMSize(u32 size) { + SELECTED_ARAM_SIZE = size; +} + +extern void ARAllocFull(u32* outSize) { + u32 freeSize = aram_hp.length - ((int)aram_hp.current - (int)aram_hp.base); + + Nas_HeapAlloc(&aram_hp, freeSize - 32); + *outSize = freeSize - 32; +} + +extern void Jac_InitARAM(u32 loadAudiorom) { + u32 aram_size = AUDIO_ARAM_SIZE; + volatile u32 audiorom_size; + + if (SELECTED_ARAM_SIZE != 0) { + aram_size = SELECTED_ARAM_SIZE; + } + + AUDIO_ARAM_TOP = ARGetBaseAddress(); + if (loadAudiorom) { + audiorom_size = Jac_CheckFile("/audiorom.img"); + if (audiorom_size != 0) { + audiorom_size = ALIGN_NEXT(audiorom_size, 32); + (void)audiorom_size; /* leftover from some debug print? */ + } + } else { + audiorom_size = 0; + } + + CARD_SECURITY_BUFFER = 0x40; + audiorom_size += AUDIO_ARAM_TOP; + JAC_ARAM_DMA_BUFFER_TOP = (u8*)audiorom_size; + audiorom_size += AUDIO_ARAM_HEAP_SIZE; + Nas_HeapInit(&aram_hp, (u8*)audiorom_size, aram_size - audiorom_size); + + /* Probably leftovers from some debug print statement */ + (void)audiorom_size; + (void)audiorom_size; +}