Implement & mostly match jaudio_NES/system.c

This commit is contained in:
Cuyler36
2025-04-16 20:18:49 -04:00
parent d271a4d9e0
commit 1602a2a056
8 changed files with 2194 additions and 44 deletions
+1 -1
View File
@@ -776,7 +776,7 @@ config.libs = [
Object(NonMatching, "jaudio_NES/internal/rate.c"),
Object(NonMatching, "jaudio_NES/internal/rspsim.c"),
Object(NonMatching, "jaudio_NES/internal/seqsetup.c"),
Object(NonMatching, "jaudio_NES/internal/system.c"),
Object(Equivalent, "jaudio_NES/internal/system.c"),
Object(NonMatching, "jaudio_NES/internal/tables.c"),
Object(NonMatching, "jaudio_NES/internal/waveread.c"),
],
+34 -1
View File
@@ -10,6 +10,9 @@ extern "C" {
#define S16_MIN (-0x8000)
#define S16_MAX (0x7FFF)
#define AUDIO_PRELOAD_SEQ (1 << 0)
#define AUDIO_PRELOAD_BANK (1 << 1)
#define AUDIO_ARAM_SIZE 0x400000 /* 4MB */
#define AUDIO_ARAM_HEAP_SIZE 0xC000
@@ -38,7 +41,7 @@ typedef enum DSPBUF_EVENTS {
typedef enum SampleMedium {
/* 0 */ MEDIUM_RAM,
/* 1 */ MEDIUM_UNK,
/* 1 */ MEDIUM_DISK,
/* 2 */ MEDIUM_CART,
/* 3 */ MEDIUM_DISK_DRIVE,
/* 5 */ MEDIUM_RAM_UNLOADED = 5
@@ -98,6 +101,36 @@ typedef enum SampleBankTableType {
/* 2 */ WAVE_TABLE
} SampleBankTableType;
typedef enum ExtDataType {
EXT_TYPE_DATA,
EXT_TYPE_SIZE,
EXT_TYPE_NUM
} ExtDataType;
typedef enum SoundOutputMode {
/* 0 */ SOUND_OUTPUT_STEREO,
/* 1 */ SOUND_OUTPUT_HEADSET,
/* 2 */ SOUND_OUTPUT_SURROUND,
/* 3 */ SOUND_OUTPUT_MONO
} SoundOutputMode;
typedef enum SampleCodec {
/* 0 */ CODEC_ADPCM, // 16 2-byte samples (32 bytes) compressed into 4-bit samples (8 bytes) + 1 header byte
/* 1 */ CODEC_S8, // 16 2-byte samples (32 bytes) compressed into 8-bit samples (16 bytes)
/* 2 */ CODEC_S16_INMEMORY,
/* 3 */ CODEC_SMALL_ADPCM, // 16 2-byte samples (32 bytes) compressed into 2-bit samples (4 bytes) + 1 header byte
/* 4 */ CODEC_REVERB,
/* 5 */ CODEC_S16
} SampleCodec;
typedef enum LpsCacheState {
/* 0 */ LPS_CACHE_STATE_WAITING,
/* 1 */ LPS_CACHE_STATE_START,
/* 2 */ LPS_CACHE_STATE_LOADING,
/* 3 */ LPS_CACHE_STATE_DONE
} LpsCacheState;
#define VOICE_TYPE_PERCUSSION 0
#define VOICE_TYPE_SOUND_EFF 1
#define VOICE_TYPE_INSTRUMENT_START 2
+16 -6
View File
@@ -65,14 +65,14 @@ typedef struct ALHeap {
/* 0x00 */ u8* base;
/* 0x04 */ u8* current;
/* 0x08 */ int length;
/* 0x0C */ u32 count;
/* 0x0C */ s32 count;
/* 0x10 */ u8* last;
} ALHeap;
/* sizeof(ArcEntry) == 0x10 */
typedef struct ArcEntry_ {
/* 0x00 */ u32 addr;
/* 0x04 */ size_t size;
/* 0x04 */ s32 size;
/* 0x08 */ s8 medium;
/* 0x09 */ s8 cacheType;
/* 0x0A */ s16 param0;
@@ -83,7 +83,7 @@ typedef struct ArcEntry_ {
/* sizeof(ArcHeader) == [0x10, 0x10+entries*0x10] */
typedef struct ArcHeader_ {
/* 0x00 */ s16 numEntries;
/* 0x02 */ s16 _02;
/* 0x02 */ s16 medium;
/* 0x04 */ u8* pData;
/* 0x08 */ u8 copy;
/* 0x09 */ u8 pad[7];
@@ -660,7 +660,7 @@ typedef struct lpscache_ {
/* 0x0C */ u8* current_ram_addr;
/* 0x10 */ u8* ram_addr;
/* 0x14 */ s32 status;
/* 0x18 */ size_t bytes_remaining;
/* 0x18 */ s32 bytes_remaining;
/* 0x1C */ s8* is_done;
/* 0x20 */ smzwavetable sample;
/* 0x30 */ OSMesgQueue mq;
@@ -679,6 +679,16 @@ typedef struct WaveLoad_ {
/* 0x0E */ u8 time_to_live;
} WaveLoad;
/* sizeof(WaveMedia) == 0x18 */
typedef struct WaveMedia_ {
/* 0x00 */ u32 wave0_bank_id;
/* 0x04 */ u32 wave1_bank_id;
/* 0x08 */ void* wave0_p;
/* 0x0C */ void* wave1_p;
/* 0x10 */ u32 wave0_media;
/* 0x14 */ u32 wave1_media;
} WaveMedia;
/* sizeof(audioparams) == 0x28 */
typedef struct audioparams_ {
/* 0x00 */ s16 spec;
@@ -883,8 +893,8 @@ typedef struct AudioGlobals {
/* 0x3771 */ u8 spec_id;
/* 0x3774 */ s32 audio_reset_fadeout_frames_left;
/* 0x3778 */ f32* adsr_decay_table;
/* 0x377C */ u8* audio_heap_p;
/* 0x3780 */ size_t audio_heap_size;
/* 0x377C */ u64* audio_heap_p;
/* 0x3780 */ s32 audio_heap_size;
/* 0x3784 */ channel* channels;
/* 0x3788 */ struct group_ groups[AUDIO_GROUP_MAX];
/* 0x3E68 */ note notes[AUDIO_NOTE_MAX];
+13 -1
View File
@@ -6,10 +6,16 @@
extern void Nas_HeapInit(ALHeap* heap, u8* base, s32 len);
extern void* Nas_HeapAlloc(ALHeap* heap, s32 size);
extern void* Nas_HeapAlloc_CL(ALHeap*, s32 size);
extern void* Nas_HeapAlloc_CL(ALHeap* heap, s32 size);
extern void* Nas_2ndHeapAlloc(ALHeap* heap, s32 size);
extern void* Nas_Alloc_Single(s32 size, s32 bank_id, u8* wave_addr, s8 medium, s32 cache);
extern void* Nas_CacheOff(u8* addr, s32 size);
extern void* Nas_SzHeapAlloc(s32 table_type, s32 size, s32 cache_type, s32 id);
extern u32 Nas_SzCacheCheck(s32 type, s32 cache_type, s32 id);
extern void Nas_SzStayDelete(s32 type);
extern void Nas_SzHeapReset(u32 fix_size);
extern void Nas_SetDelayLineParam(s32 delayIdx, s32 param_type, s32 param_value, s32 init);
@@ -17,4 +23,10 @@ extern void Nas_SetBPFilter(s16* filter, s32 lowpass_cutoff, s32 highpass_cutoff
extern s32 Nas_SpecChange(void);
extern void EntryWave(s32 id);
extern void* EmemOnCheck(s32 table_type, s32 id);
extern void* EmemAlloc(s32 table_type, s32 id, s32 size);
extern void Nas_ForceStopChannel(s32 bank_id);
#endif
+5 -6
View File
@@ -7,11 +7,10 @@
extern void Z_osWritebackDCacheAll();
extern void osInvalDCache2(void* src, s32 size);
extern void osWritebackDCache2(void* src, s32 size);
extern void Z_osCreateMesgQueue (OSMesgQueue* mq, OSMesg* msg, s32 count );
extern s32 Z_osSendMesg(OSMesgQueue* mq, OSMesg msg, s32 flags );
extern s32 Z_osRecvMesg(OSMesgQueue* mq, OSMesg* msg, s32 flags );
extern s32 Z_osEPiStartDma (OSPiHandle * handler, OSIoMesg* msg, s32 dir);
extern void Z_bcopy (void* dst, void* src, size_t size);
extern void Z_osCreateMesgQueue(OSMesgQueue* mq, OSMesg* msg, s32 count);
extern s32 Z_osSendMesg(OSMesgQueue* mq, OSMesg msg, s32 flags);
extern s32 Z_osRecvMesg(OSMesgQueue* mq, OSMesg* msg, s32 flags);
extern s32 Z_osEPiStartDma(OSPiHandle* handler, OSIoMesg* msg, s32 dir);
extern void Z_bcopy(void* src, void* dst, size_t size);
#endif
+20 -3
View File
@@ -4,6 +4,9 @@
#include "types.h"
#include "libultra/libultra.h"
#define REFRESH_RATE_DEVIATION_NTSC 1.00278f
#define REFRESH_RATE_NTSC 60
typedef enum SET_EXT_POINTER_TYPE {
EXT_POINTER_TYPE_ADDR,
EXT_POINTER_TYPE_SIZE,
@@ -11,10 +14,14 @@ typedef enum SET_EXT_POINTER_TYPE {
EXT_POINTER_TYPE_NUM
} SET_EXT_POINTER_TYPE;
typedef s32 (*Na_DmaProc)(OSPiHandle* handle, OSIoMesg* mb, s32 direction);
typedef s32 (*Na_SyncProc)(u8* param0, s32 param1);
extern void Nas_InitAudio(u64* acmdBuf, s32 acmdBufSize);
extern void Nas_FastCopy(u8* SrcAddr, u8* DestAdd, size_t size, s32 medium);
extern void Nas_StartMySeq(s32 group, s32 seq, s32 arg);
extern void Nas_StartSeq_Skip(s32 group, s32 seq, s32 skip_ticks);
extern void Nas_FastCopy(u8* SrcAddr, u8* DestAdd, size_t Length, s32 medium);
extern void Nas_FastDiskCopy(u8* SrcAddr, u8* DestAdd, size_t Length, s32 medium);
extern s32 Nas_StartMySeq(s32 group, s32 seq, s32 arg);
extern s32 Nas_StartSeq_Skip(s32 group, s32 seq, s32 skip_ticks);
extern s32 Nas_LoadVoice(s32 progId, s32 instId, s32 percId);
@@ -42,6 +49,16 @@ extern s32 VoiceLoad(s32 bank_id, u32 inst_id, s8* done_p);
extern s32 SeqLoad(s32 seq_id, u8* ram_addr, s8* done_p);
extern void MK_load(s32 type, s32 id, u8* done_p);
extern void LpsInit(void);
extern void LpsDma(s32 reset_status);
extern s32 Nas_CheckBgWave(s32 reset_status);
extern void Nas_BgCopyMain(s32 reset_status);
extern BOOL AUDIO_SYSTEM_READY;
extern Na_DmaProc NA_DMA_PROC;
extern OSMesgQueue MK_QUEUE;
extern OSMesg MK_QBUF[];
extern u8* MK_RMES[];
#endif
+21 -26
View File
@@ -3,36 +3,34 @@
#include "jaudio_NES/dummyrom.h"
#include "jaudio_NES/sample.h"
extern void Z_osWritebackDCacheAll(){
extern void Z_osWritebackDCacheAll() {
}
extern void osInvalDCache2(void* src, s32 size){
DCInvalidateRange(src,size);
extern void osInvalDCache2(void* src, s32 size) {
DCInvalidateRange(src, size);
}
extern void osWritebackDCache2(void* src, s32 size){
DCStoreRange(src,size);
extern void osWritebackDCache2(void* src, s32 size) {
DCStoreRange(src, size);
}
extern void Z_osCreateMesgQueue (OSMesgQueue* mq, OSMesg* msg, s32 count ){
extern void Z_osCreateMesgQueue(OSMesgQueue* mq, OSMesg* msg, s32 count) {
mq->msg = msg;
mq->msgCount = count;
mq->validCount = 0;
mq->first = 0;
}
extern s32 Z_osSendMesg(OSMesgQueue* mq, OSMesg msg, s32 flags ){
extern s32 Z_osSendMesg(OSMesgQueue* mq, OSMesg msg, s32 flags) {
int msgCount = mq->msgCount;
if (mq->validCount == mq->msgCount) {
return -1;
}
int count = mq->first + mq->validCount;
int count = mq->first + mq->validCount;
if(count >= mq->msgCount){
count -= mq->msgCount;
if (count >= mq->msgCount) {
count -= mq->msgCount;
}
mq->msg[count] = msg;
@@ -42,15 +40,13 @@ extern s32 Z_osSendMesg(OSMesgQueue* mq, OSMesg msg, s32 flags ){
return 0;
}
extern s32 Z_osRecvMesg(OSMesgQueue* mq, OSMesg* msg, s32 flags ){
if(flags == OS_MESG_BLOCK){
while(!mq->validCount){
};
extern s32 Z_osRecvMesg(OSMesgQueue* mq, OSMesg* msg, s32 flags) {
if (flags == OS_MESG_BLOCK) {
while (!mq->validCount) {};
}
if(mq->validCount == 0){
if(msg != NULL){
if (mq->validCount == 0) {
if (msg != NULL) {
*msg = NULL;
}
return -1;
@@ -58,25 +54,24 @@ extern s32 Z_osRecvMesg(OSMesgQueue* mq, OSMesg* msg, s32 flags ){
mq->validCount -= 1;
if(msg != NULL){
if (msg != NULL) {
*msg = mq->msg[mq->first];
}
mq->first++;
if(mq->first == mq->msgCount){
if (mq->first == mq->msgCount) {
mq->first = 0;
}
return 0;
}
extern s32 Z_osEPiStartDma (OSPiHandle * handler, OSIoMesg* msg, s32 dir){
extern s32 Z_osEPiStartDma(OSPiHandle* handler, OSIoMesg* msg, s32 dir) {
ARAMStartDMAmesg(1, (uintptr_t)msg->dramAddr, msg->devAddr, msg->size, 0, msg->hdr.retQueue);
return 0;
}
void Z_bcopy (void* dst, void* src, size_t size){
Jac_bcopy(dst,src,size);
}
void Z_bcopy(void* src, void* dst, size_t size) {
Jac_bcopy(src, dst, size);
}
File diff suppressed because it is too large Load Diff