jaudio_NES: building from pik1

This commit is contained in:
Cuyler36
2025-06-21 04:26:24 -04:00
parent d5498f9b52
commit 46c688ea10
64 changed files with 12460 additions and 267 deletions
@@ -168,25 +168,25 @@ u8 NIN_WAVE[] ATTRIBUTE_ALIGN(32) = {
void __OK(u32 a) {
(void)a;
int r31 = Jaq_SetSeqData(0, NIN_SEQ, 0x60, 0);
int unused1 = Jaq_StartSeq(r31);
int unused1 = Jaq_StartSeq((u8)r31);
}
u32 bootsound_ptr;
u32 bootsound_size;
u32 dummy_callback(char* a, u32 b, u32 c, u32* d, JAHEAP* e) {
u32 dummy_callback(char* a, u32 b, u32 c, u32* d, jaheap_* e) {
(void)a;
(void)b;
(void)c;
JAHEAP* heap2;
JAHEAP* heap;
BOOL allocd;
jaheap_* heap;
Init_AramMotherHeap();
heap = Get_AramMotherHeap();
heap2 = Jac_AllocHeap(e, heap, bootsound_size);
if ((s32)heap2 == 0) {
allocd = Jac_AllocHeap(e, heap, bootsound_size);
if (allocd == 0) {
return 0;
}
u32 p = (u32)e->_08;
u32 p = (u32)e->startAddress;
int unused = DVDT_DRAMtoARAM(0, bootsound_ptr, p, bootsound_size, d, 0);
return p;
}
+1 -1
View File
@@ -4,7 +4,7 @@
#include "jaudio_NES/cmdstack.h"
#include "jaudio_NES/seqsetup.h"
#include "jaudio_NES/connect.h"
#include "jaudio_NES/jammain.h"
#include "jaudio_NES/jammain_2.h"
extern void Jac_Start(void* heap, u32 heap_size, u32 aram_size) {
StartAudioThread(heap, heap_size, aram_size, 7);
+178
View File
@@ -0,0 +1,178 @@
#include "jaudio_NES/aramcall.h"
#include "jaudio_NES/heapctrl.h"
#include "jaudio_NES/dummyrom.h"
#include "jaudio_NES/dvdthread.h"
#include "string.h"
jaheap_ aram_mother;
ARAMCallback ARCALL = &LoadAram_Default;
static char extdir[64] = "/Banks/";
/*
* --INFO--
* Address: ........
* Size: 000008
*/
void Jac_RegisterARAMCallback(ARAMCallback callback)
{
ARCALL = callback;
}
/*
* --INFO--
* Address: 8000D8A0
* Size: 000064
*/
u32 LoadAram(char* filepath, u32* status, u32 dst)
{
// GUH MUH BRUH
volatile char** filepathGuh = (volatile char**)&filepath;
volatile u32* dstGuh = &dst;
char* filepathMruh = (char*)*filepathGuh;
u32 dstMruh = *dstGuh;
if (DVDT_LoadtoARAM(0, filepathMruh, dstMruh, 0, 0, status, NULL) == -1) {
return 0;
}
return dst;
}
/*
* --INFO--
* Address: 8000D920
* Size: 000068
*/
u32 LoadAramSingle(char* filepath, u32 src, u32 length, u32* status, u32 dst)
{
// GUH MUH BRUH (this function is very stupidly written, why does this match?)
u32 pad[1];
volatile char** filepathGuh = (volatile char**)&filepath;
volatile u32* srcGuh = &src;
volatile u32* lengthGuh = &length;
char* filepathMruh = (char*)*filepathGuh;
u32 lengthMuh = *lengthGuh;
u32 srcMuh = *srcGuh;
// u32 dstMuh = *dstGuh;
// Why is normal dst passed into this function when everything else isn't???
if (DVDT_LoadtoARAM(0, filepathMruh, dst, srcMuh, lengthMuh, status, NULL) == -1) {
return 0;
}
return dst;
}
/*
* --INFO--
* Address: ........
* Size: 000030
*/
void Jac_WaveDirectorySet(char* directory)
{
strcpy(extdir, directory);
}
/*
* --INFO--
* Address: ........
* Size: 00000C
*/
jaheap_* Get_AramMotherHeap(void)
{
return &aram_mother;
}
/*
* --INFO--
* Address: 8000D9A0
* Size: 00002C
*/
void Show_AramMotherHeap(void)
{
Jac_ShowHeap(&aram_mother, 0);
}
/*
* --INFO--
* Address: 8000D9E0
* Size: 00002C
*/
void Collect_AramMotherHeap(void)
{
Jac_GarbageCollection_St(&aram_mother);
Show_AramMotherHeap();
}
/*
* --INFO--
* Address: 8000DA20
* Size: 00006C
*/
void Init_AramMotherHeap(void)
{
void* alloc;
u32 outSize;
static BOOL inited = FALSE;
if (!inited) {
inited = TRUE;
void* alloc = ARAllocFull(&outSize);
Jac_InitMotherHeap(&aram_mother, (u32)alloc, outSize, 0);
}
}
// Used only by `LoadAram_Default`.
static BOOL first = TRUE;
/*
* --INFO--
* Address: 8000DAA0
* Size: 0000F8
*/
u32 LoadAram_Default(char* filename, u32 src, u32 length, u32* status, jaheap_* heap)
{
char filepath[140];
if (first) {
Init_AramMotherHeap();
first = FALSE;
}
strcpy(filepath, extdir);
strcat(filepath, filename);
if (src == 0 && length == 0) {
if (!Jac_AllocHeap(heap, &aram_mother, DVDT_CheckFile(filepath))) {
return 0;
}
return LoadAram(filepath, status, heap->startAddress);
} else {
if (!Jac_AllocHeap(heap, &aram_mother, length)) {
return 0;
}
return LoadAramSingle(filepath, src, length, status, heap->startAddress);
}
}
/*
* --INFO--
* Address: 8000DBA0
* Size: 000038
*/
u32 LoadAram_All(char* filename, u32* status, jaheap_* heap)
{
return ARCALL(filename, 0, 0, status, heap);
}
/*
* --INFO--
* Address: 8000DBE0
* Size: 000028
*/
u32 LoadAram_One(char* filename, u32 src, u32 length, u32* status, jaheap_* heap)
{
return ARCALL(filename, src, length, status, heap);
}
+327
View File
@@ -0,0 +1,327 @@
#include "jaudio_NES/bankdrv.h"
#include "jaudio_NES/random.h"
#include "jaudio_NES/rate.h"
#include "jaudio_NES/bx.h"
#include "jaudio_NES/ja_calc.h"
static u32 FORCE_RELEASE_TABLE[3] = { 5, 15, 0 };
/*
* --INFO--
* Address: 8000CFC0
* Size: 000030
*/
Inst_* Bank_InstChange(Bank_* bank, volatile u32 VOLATILE_index)
{
u32 index;
index = VOLATILE_index;
if (!bank) {
return NULL;
}
return bank->mInstruments[index];
}
/*
* --INFO--
* Address: ........
* Size: 000030
*/
Voice_* Bank_VoiceChange(Bank_* bank, volatile u32 VOLATILE_index)
{
u32 index;
index = VOLATILE_index;
if (!bank) {
return NULL;
}
return bank->mVoices[index];
}
/*
* --INFO--
* Address: 8000D000
* Size: 000030
*/
Perc_* Bank_PercChange(Bank_* bank, volatile u32 VOLATILE_index)
{
u32 index;
index = VOLATILE_index;
if (!bank) {
return NULL;
}
return bank->mPercs[index];
}
/*
* --INFO--
* Address: 8000D040
* Size: 00005C
*/
int Bank_GetInstKeymap(Inst_* inst, u8 param_2)
{
if (!inst) {
return 0;
}
for (u32 i = 0; i < inst->mKeyRegionCount; i++) {
if (param_2 <= inst->mKeyRegions[i]->mBaseKey) {
return i; // Return the index of the keymap
}
}
return -1;
}
/*
* --INFO--
* Address: 8000D0A0
* Size: 000090
*/
int Bank_GetInstVmap(Inst_* inst, u8 param_2, u8 param_3)
{
if (!inst) {
return 0;
}
int instIndex = Bank_GetInstKeymap(inst, param_2);
if (instIndex != -1) {
u8* REF_p3 = &param_3;
InstKeymap_* key = inst->mKeyRegions[instIndex];
for (u32 i = 0; i < key->mVelocityCount; i++) {
Vmap_* vmap = key->mVelocities[i];
if (param_3 <= vmap->mBaseVelocity) {
return (int)vmap;
}
}
return 0;
}
return instIndex;
}
/*
* --INFO--
* Address: 8000D140
* Size: 000068
*/
Vmap_* Bank_GetPercVmap(Perc_* perc, u8 keyIdx, u8 vel)
{
if (!perc) {
return 0;
}
PercKeymap_* keymap = perc->mKeyRegions[keyIdx];
if (!keymap) {
return 0;
}
for (u32 i = 0; i < keymap->mVelocityCount; i++) {
Vmap_* vmap = keymap->mVelocities[i];
if (vel <= vmap->mBaseVelocity) {
return vmap;
}
}
return 0;
}
/*
* --INFO--
* Address: ........
* Size: 000010
*/
int Bank_GetVoiceMap(Voice_* voice, u16 id)
{
// UNUSED FUNCTION
}
/*
* --INFO--
* Address: 8000D1C0
* Size: 000104
*/
f32 Bank_SenseToOfs(Sense_* sensor, u8 p2)
{
if (!sensor) {
return 1.0f;
}
if (sensor->threshold == 127 || sensor->threshold == 0) {
return sensor->min + (f32)p2 * (sensor->max - sensor->min) / 127.0f;
}
if (p2 < sensor->threshold) {
return sensor->min + (1.0f - sensor->min) * ((f32)p2 / (f32)sensor->threshold);
}
int a = p2 - sensor->threshold;
int b = 127 - sensor->threshold;
return 1.0f + (sensor->max - 1.0f) * ((f32)a / (f32)b);
}
/*
* --INFO--
* Address: 8000D2E0
* Size: 000048
*/
f32 Bank_RandToOfs(Rand_* rand)
{
f32 value;
if (!rand) {
return 1.0f;
}
value = GetRandom_sf32();
value *= rand->range;
value += rand->value;
return value;
}
/*
* --INFO--
* Address: 8000D340
* Size: 0003F8
*/
f32 Bank_OscToOfs(Osc_* osc, Oscbuf_* buf)
{
f32 sub;
int offset;
s16 val0, val1, val2;
f32 calc;
s16* table;
if (osc == NULL) {
buf->value = 1.0f;
return 1.0f;
}
if (buf->state == 4) {
if (osc->attackVecOffset != osc->releaseVecOffset) {
buf->tableIndex = 0;
buf->timeCounter = 0.0f;
buf->targetValue = buf->value;
}
if (osc->releaseVecOffset == 0 && buf->releaseParam == 0) {
buf->releaseParam = 0x10;
}
if (buf->releaseParam) {
buf->state = 8;
buf->curveType = buf->releaseParam >> 14 & 3;
f32 x = buf->releaseParam & 0x3fff;
x *= (JAC_DAC_RATE / 80.0f) / 600.0f;
buf->timeCounter = x;
if (buf->timeCounter < 1.0f) {
buf->timeCounter = 1.0f;
}
buf->targetValue = 0.0f;
buf->deltaRate = (buf->targetValue - buf->value) / buf->timeCounter;
} else {
buf->state = 5;
}
}
if (buf->state == 6) {
buf->tableIndex = 0;
buf->timeCounter = 0.0f;
buf->targetValue = buf->value;
buf->state = 7;
}
if (buf->state == 5) {
table = osc->releaseVecOffset;
} else if (buf->state == 7) {
table = (s16*)FORCE_RELEASE_TABLE;
} else {
table = osc->attackVecOffset;
}
if (table == NULL && buf->state != 8) {
buf->value = 1.0f;
return 1.0f;
}
if (buf->state == 0) {
return 1.0f;
}
if (buf->state == 3) {
return buf->value * osc->width + osc->vertex;
}
if (buf->state == 1) {
buf->state = 2;
buf->tableIndex = 0;
buf->timeCounter = 0.0f;
buf->targetValue = 0.0f;
buf->releaseParam = 0;
sub = osc->rate;
} else {
sub = osc->rate;
}
if (buf->state == 7) {
sub = 1.0f;
}
buf->timeCounter -= sub;
while (buf->timeCounter <= 0.0f) {
offset = (buf->tableIndex * 3);
buf->value = buf->targetValue;
if (buf->state == 8) {
buf->state = 0;
break;
}
val0 = table[offset + 0];
val1 = table[offset + 1];
val2 = table[offset + 2];
if (val0 == 0xd) {
buf->tableIndex = val2;
continue;
} else if (val0 == 0xf) {
buf->state = 0;
break;
} else if (val0 == 0xe) {
buf->state = 3;
return buf->value * osc->width + osc->vertex;
}
buf->curveType = val0;
if (val1 == 0) {
buf->targetValue = val2 / 32768.0f;
buf->tableIndex++;
} else {
f32 x = (u16)val1;
x *= (JAC_DAC_RATE / 80.0f) / 600.0f;
buf->timeCounter = x;
buf->targetValue = val2 / 32768.0f;
buf->deltaRate = (buf->targetValue - buf->value) / buf->timeCounter;
buf->tableIndex++;
}
}
calc = -(buf->deltaRate * buf->timeCounter - buf->targetValue);
buf->value = calc;
switch (buf->curveType) {
case 0:
break;
case 1:
if (calc > 0.0f) {
calc = calc * calc;
} else {
calc = -calc * calc;
}
break;
case 2:
if (calc > 0.0f) {
calc = sqrtf2(calc);
} else {
calc = -sqrtf2(-calc);
}
break;
}
return calc * osc->width + osc->vertex;
}
+137 -109
View File
@@ -1,138 +1,166 @@
#include "jaudio_NES/audiostruct.h"
#include "jaudio_NES/bankread.h"
#include "jaudio_NES/connect.h"
#include "jaudio_NES/bx.h"
static void PTconvert(void** s, u32 ramaddr) {
u32 ofs = (u32)*s;
#define BANKP_SIZE (0x100)
static Bank_* bankp[BANKP_SIZE];
if (ofs >= ramaddr || ofs == 0) {
return;
}
*s = (void*)(ofs + ramaddr);
/*
* --INFO--
* Address: 8000BE00
* Size: 000024
*/
static void PTconvert(void** pointer, u32 base_address)
{
if (*pointer >= (void*)base_address || *pointer == NULL) {
return;
}
*pointer = *(char**)pointer + base_address;
}
// @nonmatching - regswaps (need to make structs for these)
static Bank* Bank_Test(u8* data) {
InstBank* ibnk = (InstBank*)data;
u32 ramaddr = (u32)data;
Bank* bank = &ibnk->bank;
u32 i;
u32 j;
void** unk_pp;
u32 k;
void* unk;
void** inst_p;
void* inst;
/*
* --INFO--
* Address: 8000BE40
* Size: 000270
*/
Bank_* Bank_Test(u8* ibnk_address)
{
u32 i, k, j;
u32 base_addr = (u32)ibnk_address;
Bank_* startBank = (Bank_*)(ibnk_address + 0x20);
if (startBank->mMagic != 'BANK') {
return NULL;
}
if (bank->magic != 'BANK') {
return NULL;
}
for (i = 0; i < BANK_TEST_INST_COUNT; ++i) {
PTconvert((void**)&startBank->mInstruments[i], base_addr);
for (i = 0; i < ARRAY_COUNT(bank->part0); i++) {
inst_p = (void**)&bank->part0[i];
PTconvert(inst_p, ramaddr);
Inst_* inst = (Inst_*)startBank->mInstruments[i];
if (!inst) {
continue;
}
inst = *inst_p;
if (inst != NULL) {
for (j = 0; j < 2; j++) {
unk_pp = (void**)((u32)inst + j * 4 + 0x10);
PTconvert((void**)(unk_pp), ramaddr);
PTconvert((void**)((u32)inst + j * 4 + 0x18), ramaddr);
PTconvert((void**)((u32)inst + j * 4 + 0x20), ramaddr);
if (*unk_pp != NULL) {
PTconvert((void**)((u32)*unk_pp + 0x08), ramaddr);
PTconvert((void**)((u32)*unk_pp + 0x0C), ramaddr);
}
}
// each instrument has two oscillators, effects, and sensors
for (j = 0; j < 2; j++) {
PTconvert((void**)&inst->mOscillators[j], base_addr);
PTconvert((void**)&inst->mEffects[j], base_addr);
PTconvert((void**)&inst->mSensors[j], base_addr);
for (j = 0; j < *((u32*)inst + 0x28); j++) {
unk_pp = (void**)((u32)inst + j * 4 + 0x2C);
PTconvert(unk_pp, ramaddr);
for (k = 0; k < *(u32*)((u32)*unk_pp + 4); k++) {
PTconvert((void**)((u32)*unk_pp + k * 4 + 8), ramaddr);
}
}
}
}
if (inst->mOscillators[j]) {
PTconvert((void**)&inst->mOscillators[j]->attackVecOffset, base_addr);
PTconvert((void**)&inst->mOscillators[j]->releaseVecOffset, base_addr);
}
}
for (i = 0; i < ARRAY_COUNT(bank->part1); i++) {
inst_p = (void**)&bank->part1[i];
// each instrument also has a certain number of key regions
for (j = 0; j < inst->mKeyRegionCount; j++) {
PTconvert((void**)&inst->mKeyRegions[j], base_addr);
PTconvert(inst_p, ramaddr);
inst = *inst_p;
for (k = 0; k < inst->mKeyRegions[j]->mVelocityCount; k++) {
PTconvert((void**)&inst->mKeyRegions[j]->mVelocities[k], base_addr);
}
}
}
if (inst != NULL) {
for (j = 0; j < *((u32*)inst + 0x08); j++) {
void** unk = (void**)((u32)inst + j * 4 + 0x0C);
PTconvert(unk, ramaddr);
}
}
}
// treat the next block of 100 as voices (for some reason)
for (i = 0; i < BANK_TEST_VOICE_COUNT; i++) {
PTconvert((void**)&(startBank->mInstruments + BANK_TEST_VOICE_OFFSET)[i], base_addr);
for (i = 0; i < ARRAY_COUNT(bank->part2); i++) {
inst_p = (void**)&bank->part2[i];
inst;
Voice_* voice = (Voice_*)(startBank->mInstruments + BANK_TEST_VOICE_OFFSET)[i];
if (!voice) {
continue;
}
PTconvert(inst_p, ramaddr);
for (j = 0; j < voice->size; j++) {
PTconvert(&voice->_0C[j], base_addr);
}
}
inst = *inst_p;
if (inst != NULL) {
for (j = 0; j < 128; j++) {
unk_pp = (void**)((u32)inst + j * 4 + 0x88);
// treat the next block of 12 as percussion (for some reason)
for (i = 0; i < BANK_TEST_PERC_COUNT; i++) {
PTconvert((void**)&(startBank->mInstruments + BANK_TEST_PERC_OFFSET)[i], base_addr);
PTconvert(unk_pp, ramaddr);
Perc_* perc = (Perc_*)(startBank->mInstruments + BANK_TEST_PERC_OFFSET)[i];
if (!perc) {
continue;
}
unk = *unk_pp;
if (unk != NULL) {
PTconvert((void**)((u32)unk + 0x08), ramaddr);
PTconvert((void**)((u32)unk + 0x0C), ramaddr);
for (j = 0; j < 128; j++) {
PTconvert((void**)&perc->mKeyRegions[j], base_addr);
for (k = 0; k < *(u32*)((u32)unk + 0x10); k++) {
PTconvert((void**)((u32)unk + k * 4 + 0x14), ramaddr);
}
}
}
}
}
PercKeymap_* key = perc->mKeyRegions[j];
if (!key) {
continue;
}
return bank;
PTconvert(&key->_08, base_addr);
PTconvert(&key->_0C, base_addr);
for (k = 0; k < key->mVelocityCount; k++) {
PTconvert((void**)&key->mVelocities[k], base_addr);
}
}
}
return startBank;
}
static Bank* bankp[256];
static BOOL __Bank_Regist_Inner(u8* bank, u32 pid, u32 vid) {
Jac_BnkConnectTableSet(vid, pid);
bankp[pid] = Bank_Test(bank);
if (bankp[pid] != NULL) {
return TRUE;
}
return FALSE;
/*
* --INFO--
* Address: 8000C0C0
* Size: 000068
*/
static BOOL __Bank_Regist_Inner(u8* ibnk, u32 param_2, u32 param_3)
{
Jac_BnkConnectTableSet(param_3, param_2);
bankp[param_2] = Bank_Test(ibnk);
if (!bankp[param_2])
return FALSE;
return TRUE;
}
BOOL Bank_Regist(void* bank, u32 pid) {
InstBank* ibnk = (InstBank*)bank;
return __Bank_Regist_Inner((u8*)bank, pid, ibnk->vid);
/*
* --INFO--
* Address: 8000C140
* Size: 000024
*/
BOOL Bank_Regist(void* ibnk, u32 param_2)
{
return __Bank_Regist_Inner((u8*)ibnk, param_2, ((Ibnk_*)ibnk)->_08);
}
void Bank_Init(void) {
int i;
for (i = 0; i < ARRAY_COUNT(bankp); i++) {
bankp[i] = NULL;
}
/*
* --INFO--
* Address: ........
* Size: 000020
*/
BOOL Bank_Regist_Direct(void* ibnk, u32 param_2, u32 param_3)
{
return __Bank_Regist_Inner((u8*)ibnk, param_2, param_3);
}
Bank* Bank_Get(u32 pid) {
if (pid >= ARRAY_COUNT(bankp)) {
return NULL;
}
return bankp[pid];
/*
* --INFO--
* Address: 8000C180
* Size: 00002C
*/
void Bank_Init()
{
for (int i = 0; i < BANKP_SIZE; ++i) {
bankp[i] = NULL;
}
}
/*
* --INFO--
* Address: 8000C1C0
* Size: 000028
*/
Bank_* Bank_Get(u32 index)
{
if (index >= BANKP_SIZE) {
return NULL;
}
return bankp[index];
}
+44
View File
@@ -0,0 +1,44 @@
#include "jaudio_NES/centcalc.h"
#include "jaudio_NES/tables.h"
// Calculated via powf(2.0f, x / 12.0f)
#define KEY_CURVE_RESOLUTION (64)
static f32 KEY_TABLE[KEY_CURVE_RESOLUTION] = {
1.0000000, 1.0009100, 1.0018210, 1.0027330, 1.0036449, 1.0045590, 1.0054730, 1.0063879, 1.0073040, 1.0082200, 1.0091380,
1.0100560, 1.0109750, 1.0118960, 1.0128160, 1.0137380, 1.0146610, 1.0155840, 1.0165080, 1.0174330, 1.0183589, 1.0192860,
1.0202140, 1.0211420, 1.0220710, 1.0230020, 1.0239330, 1.0248640, 1.0257970, 1.0267310, 1.0276650, 1.0286000, 1.0295360,
1.0304730, 1.0314110, 1.0323499, 1.0332890, 1.0342300, 1.0351710, 1.0361130, 1.0370560, 1.0380000, 1.0389440, 1.0398900,
1.0408360, 1.0417830, 1.0427310, 1.0436800, 1.0446300, 1.0455810, 1.0465320, 1.0474850, 1.0484380, 1.0493920, 1.0503470,
1.0513030, 1.0522600, 1.0532170, 1.0541760, 1.0551350, 1.0560950, 1.0570560, 1.0580180, 1.0589809,
};
/*
* --INFO--
* Address: 80014BC0
* Size: 0000CC
*/
f32 Jam_PitchToCent(f32 basePitch, f32 scaleFactor)
{
f32 scaledPitch;
f32 fractionalPart;
s16 tableIndex;
scaledPitch = 4.0f * basePitch * scaleFactor;
tableIndex = scaledPitch;
fractionalPart = scaledPitch - tableIndex;
// Handle negative input rounding
if (scaledPitch < 0.0f && fractionalPart != 0.0f) {
fractionalPart += 1.0f;
tableIndex -= 1;
}
if (fractionalPart >= 1.0f) {
fractionalPart -= 1.0f;
tableIndex += 1;
}
return C5BASE_PITCHTABLE[tableIndex + 60] * (KEY_TABLE)[(u16)(fractionalPart * KEY_CURVE_RESOLUTION)];
}
+211
View File
@@ -0,0 +1,211 @@
#include "jaudio_NES/cmdstack.h"
#include "jaudio_NES/playercall.h"
#include "dolphin/os.h"
JPorthead_ cmd_once;
JPorthead_ cmd_stay;
/*
* --INFO--
* Address: 8000E300
* Size: 000028
*/
void Add_PortcmdOnce(u32* a1)
{
Add_Portcmd(&cmd_once, a1);
}
/*
* --INFO--
* Address: ........
* Size: 000028
*/
void Add_PortcmdStay(void)
{
// UNUSED FUNCTION
}
/*
* --INFO--
* Address: 8000E340
* Size: 000018
*/
int Set_Portcmd(int* a1, int a2, int a3)
{
// Is this a struct? I have no idea
a1[5] = a2;
a1[6] = a3;
a1[3] = 0;
return 1;
}
/*
* --INFO--
* Address: 8000E360
* Size: 000078
*/
BOOL Add_Portcmd(JPorthead_* port, u32* a2)
{
BOOL interrupt = OSDisableInterrupts();
if (a2[3]) {
OSRestoreInterrupts(interrupt);
return FALSE;
}
if (port->_04) {
((int*)port->_04)[4] = (int)a2;
} else {
port->_00 = (int)a2;
}
port->_04 = (int)a2;
a2[4] = 0;
a2[3] = (int)port;
OSRestoreInterrupts(interrupt);
return TRUE;
}
/*
* --INFO--
* Address: 8000E3E0
* Size: 000040
*/
static int Get_Portcmd(JPorthead_* port)
{
u32 a = port->_00;
if (a) {
port->_00 = ((int*)port->_00)[4];
if (port->_00 == 0) {
port->_04 = 0;
}
((int*)a)[3] = 0;
} else {
a = 0;
}
return a;
}
/*
* --INFO--
* Address: ........
* Size: 000080
*/
void Cancel_Portcmd(void)
{
// UNUSED FUNCTION
}
/*
* --INFO--
* Address: ........
* Size: 000028
*/
void Cancel_PortcmdStay(void)
{
// UNUSED FUNCTION
}
/*
* --INFO--
* Address: 8000E420
* Size: 000050
*/
int Jac_Portcmd_Proc_Once(JPorthead_* port)
{
u32 p;
while (1) {
p = Get_Portcmd(port);
if (!p) {
break;
}
// Ckit ahh moment unless someone figures out what type Get_Portcmd actually returns
((int (*)(int)) * (int*)(p + 0x14))(((int*)p)[6]);
}
return 0;
}
/*
* --INFO--
* Address: 8000E480
* Size: 00004C
*/
int Jac_Portcmd_Proc_Stay(JPorthead_* port)
{
u32 p = port->_00;
while (1) {
if (!p) {
break;
}
((int (*)(int)) * (int*)(p + 0x14))(((int*)p)[6]);
p = ((u32*)p)[4];
}
return 0;
}
/*
* --INFO--
* Address: 8000E4E0
* Size: 000030
*/
static s32 Portcmd_Main(void* a)
{
Jac_Portcmd_Proc_Once(&cmd_once);
Jac_Portcmd_Proc_Stay(&cmd_stay);
return 0;
}
/*
* --INFO--
* Address: 8000E520
* Size: 000010
*/
void Jac_Porthead_Init(JPorthead_* port)
{
port->_00 = 0;
port->_04 = 0;
}
/*
* --INFO--
* Address: 8000E540
* Size: 00003C
*/
void Jac_Portcmd_Init(void)
{
Jac_Porthead_Init(&cmd_once);
Jac_Porthead_Init(&cmd_stay);
Jac_RegisterPlayerCallback(Portcmd_Main, 0);
}
/*
* --INFO--
* Address: ........
* Size: 00001C
*/
void JP_Pitch1Shot(void)
{
// UNUSED FUNCTION
}
/*
* --INFO--
* Address: ........
* Size: 00006C
*/
void JP_Start1Shot(void)
{
// UNUSED FUNCTION
}
/*
* --INFO--
* Address: ........
* Size: 00004C
*/
void JP_Stop1Shot(void)
{
// UNUSED FUNCTION
}
+308
View File
@@ -0,0 +1,308 @@
#include "jaudio_NES/connect.h"
#include "jaudio_NES/heapctrl.h"
#include "jaudio_NES/bx.h"
#include "jaudio_NES/aramcall.h"
static s16 WS_V2P_TABLE[0x100];
static s16 BNK_V2P_TABLE[0x100];
/*
* --INFO--
* Address: 8000C860
* Size: 0000A0
*/
static int UpdateWave(WaveArchive_* arc, Ctrl_* ctrl, u32 base)
{
u32 i = 0;
for (; i < ctrl->count; i++) {
WaveID_* wave = ctrl->waveIDs[i];
wave->data = arc->waves[i + base];
if (arc->heap.startAddress) {
Jac_SelfAllocHeap(&wave->heap, &arc->heap, wave->data->length + 0x1f & 0xffffffe0,
arc->heap.startAddress + wave->data->srcAddress);
}
}
return i + base;
}
/*
* --INFO--
* Address: 8000C900
* Size: 000174
*/
static BOOL UpdateWave_Extern(WaveArchiveBank_* bank, CtrlGroup_* group, Ctrl_* ctrl)
{
WaveID_* wave;
for (u32 i = 0; i < ctrl->count; i++) {
wave = ctrl->waveIDs[i];
u32 a = wave->id >> 16;
u32 b = wave->id & 0xffff;
if (wave->heap.startAddress) {
continue;
}
Ctrl_* cdf = group->scenes[a]->cdf;
u32 index = 0;
u32* ptr = &a;
u32* ptr2 = &index;
while (index < cdf->count) {
if ((cdf->waveIDs[index]->id & 0xffff) == b) {
break;
}
index++;
}
if (index != cdf->count) {
WaveID_** wave2 = &cdf->waveIDs[index];
if ((*wave2)->heap.startAddress) {
wave->data = (*wave2)->data;
Jac_SelfInitHeap(&wave->heap, (*wave2)->heap.startAddress, 0, (*wave2)->heap.memoryType);
Jac_SetGroupHeap(&wave->heap, &(*wave2)->heap);
} else {
WaveArchive_* wave3 = bank->waveGroups[a];
wave->data = wave3->waves[index];
wave->loadStatus = 0;
wave->data->fileLoadStatus = &wave->loadStatus;
LoadAram_One(wave3->filePath, wave->data->srcAddress, wave->data->length, &wave->loadStatus, &wave->heap);
Jac_SetGroupHeap(&wave->heap, &wave3->heap);
}
}
}
return TRUE;
}
/*
* --INFO--
* Address: 8000CA80
* Size: 00009C
*/
void Jac_SceneClose(WaveArchiveBank_* bank, CtrlGroup_* group, u32 id, BOOL set)
{
WaveArchive_* arc;
SCNE_* scene;
scene = group->scenes[id];
arc = bank->waveGroups[id];
Jac_DeleteHeap(&arc->heap);
arc->fileLoadStatus = 0;
if (set && scene->_08) {
for (u32 i = 0; i < scene->_08; i++) {
Jac_SceneClose(bank, group, scene->_18[i], TRUE);
}
}
}
/*
* --INFO--
* Address: 8000CB20
* Size: 00015C
*/
BOOL Jac_SceneSet(WaveArchiveBank_* bank, CtrlGroup_* group, u32 id, BOOL set)
{
WaveArchiveBank_** bankp = &bank;
u32* idp = &id;
WaveArchive_* arc;
int stat = 0;
SCNE_* scene;
Ctrl_* cdf;
u32 i;
arc = bank->waveGroups[id];
!arc;
if (arc->heap.startAddress && arc->fileLoadStatus) {
for (i = 0; i < arc->waveCount; i++) {
arc->waves[i]->fileLoadStatus = &arc->fileLoadStatus;
}
} else {
arc->fileLoadStatus = 0;
for (i = 0; i < arc->waveCount; i++) {
arc->waves[i]->fileLoadStatus = &arc->fileLoadStatus;
}
if (LoadAram_All(arc->filePath, &arc->fileLoadStatus, &arc->heap) == 0) {
return FALSE;
}
}
scene = group->scenes[id];
cdf = scene->cdf;
if (cdf) {
stat = UpdateWave(arc, cdf, 0);
}
if (scene->cex) {
if (scene->_04 == 0) {
UpdateWave(arc, scene->cex, stat);
} else {
UpdateWave_Extern(bank, group, scene->cex);
}
}
if (set) {
group->_04 = id;
}
return TRUE;
}
/*
* --INFO--
* Address: 8000CC80
* Size: 000044
*/
static WaveID_* SearchWave(Ctrl_* ctrl, u32 flag)
{
for (u32 i = 0; i < ctrl->count; i++) {
WaveID_* wave = ctrl->waveIDs[i];
if ((u16)wave->id == flag) {
return wave;
}
}
return NULL;
}
/*
* --INFO--
* Address: 8000CCE0
* Size: 00010C
*/
WaveID_* __GetSoundHandle(CtrlGroup_* group, u32 id, u32 id2)
{
u16 wId = id;
SCNE_* scene = group->scenes[id2];
Ctrl_* ctrl;
ctrl = scene->cdf;
if (ctrl) {
WaveID_* wave = SearchWave(ctrl, wId);
if (wave && wave->data && (int)wave->data != 0xffffffff) {
return wave;
}
}
ctrl = scene->cex;
if (ctrl) {
WaveID_* wave = SearchWave(ctrl, wId);
if (wave && wave->data && (int)wave->data != 0xffffffff) {
return wave;
}
}
for (u32 i = 0; i < scene->_08; i++) {
WaveID_* wave = __GetSoundHandle(group, id, scene->_18[i]);
if (wave && wave->data && (int)wave->data != 0xffffffff) {
return wave;
}
}
return NULL;
}
/*
* --INFO--
* Address: 8000CE00
* Size: 000074
*/
WaveID_* GetSoundHandle(CtrlGroup_* group, u32 flag)
{
u32* flagptr = &flag;
WaveID_* wave = __GetSoundHandle(group, flag, group->_04);
if (wave == NULL) {
return NULL;
}
if (wave->data == NULL) {
return NULL;
}
u32* ptr = wave->data->fileLoadStatus;
if (ptr == NULL) {
return NULL;
}
if (*ptr == 0) {
return NULL;
}
return wave;
}
/*
* --INFO--
* Address: 8000CE80
* Size: 000018
*/
u16 Jac_WsVirtualToPhysical(u16 vID)
{
return WS_V2P_TABLE[vID];
}
/*
* --INFO--
* Address: 8000CEA0
* Size: 000018
*/
u16 Jac_BnkVirtualToPhysical(u16 vID)
{
return BNK_V2P_TABLE[vID];
}
/*
* --INFO--
* Address: ........
* Size: 000040
*/
u16 Jac_BnkPhysicalToVirtual(u16 bnk)
{
// UNUSED FUNCTION
}
/*
* --INFO--
* Address: ........
* Size: 000040
*/
u16 Jac_WsPhysicalToVirtual(u16 ws)
{
// UNUSED FUNCTION
}
/*
* --INFO--
* Address: 8000CEC0
* Size: 000050
*/
void Jac_WsConnectTableSet(u32 id, u32 val)
{
u32* id2 = &id;
u32* bnk = &val;
if (id != 0xffff && id < 0x100 && WS_V2P_TABLE[id] == -1) {
WS_V2P_TABLE[id] = *bnk;
}
}
/*
* --INFO--
* Address: 8000CF20
* Size: 000050
*/
void Jac_BnkConnectTableSet(u32 id, u32 val)
{
u32* id2 = &id;
u32* bnk = &val;
if (id != 0xffff && id < 0x100 && BNK_V2P_TABLE[id] == -1) {
BNK_V2P_TABLE[id] = *bnk;
}
}
/*
* --INFO--
* Address: 8000CF80
* Size: 00003C
*/
void Jac_ConnectTableInit()
{
for (int i = 0; i < 0x100; i++) {
WS_V2P_TABLE[i] = -1;
BNK_V2P_TABLE[i] = -1;
}
}
File diff suppressed because it is too large Load Diff
@@ -0,0 +1,331 @@
#include "jaudio_NES/dsp_cardunlock.h"
#include "dolphin/os.h"
#include "dolphin/card.h"
#include "MSL_C/rand.h"
#include "jaudio_NES/ipldec.h"
#include "_mem.h"
#include "card/__card.h"
#define DATA_SCRAMBLE_R(data) (~(data ^ (data >> 7) ^ (data >> 15) ^ (data >> 23)))
#define DATA_SCRAMBLE_L(data) (~(data ^ (data << 7) ^ (data << 15) ^ (data << 23)))
/*
* --INFO--
* Address: 80008BE0
* Size: 000038
*/
static u32 exnor_1st(u32 data, u32 rshift)
{
for (u32 i = 0; i < rshift; ++i) {
data = (data >> 1) | (DATA_SCRAMBLE_R(data) << 30) & 0x40000000;
}
return data;
}
/*
* --INFO--
* Address: 80008C20
* Size: 000038
*/
static u32 exnor(u32 data, u32 lshift)
{
for (u32 i = 0; i < lshift; ++i) {
data = (data << 1) | (DATA_SCRAMBLE_L(data) >> 30) & 0x00000002;
}
return data;
}
/*
* --INFO--
* Address: 80008C60
* Size: 00007C
*/
static u32 bitrev(u32 data)
{
u32 wk;
u32 i;
u32 k = 0;
u32 j = 1;
wk = 0;
for (i = 0; i < 32; ++i) {
if (i > 0x0f) {
if (i == 31) {
wk |= (data & 1 << 31) >> 31;
} else {
wk |= (data & 1 << i) >> j;
j += 2;
}
} else {
wk |= (data & 1 << i) << (31 - i - k);
k += 1;
}
}
return wk;
}
/*
* --INFO--
* Address: 80008CE0
* Size: 00017C
*/
static s32 ReadArrayUnlock(s32 chan, u32 data, void* rbuf, s32 length, BOOL mode)
{
ASSERTLINE(216, 0 <= chan && chan < 2);
CARDControl* card = &__CARDBlock[chan];
if (!EXISelect(chan, 0, 4))
return CARD_RESULT_NOCARD;
data &= 0xFFFFF000;
u8 cmd[5];
memset(cmd, 0, sizeof(cmd));
cmd[0] = 0x52;
if (mode == FALSE) {
cmd[1] = data >> 29 & 0x03;
cmd[2] = data >> 21 & 0xff;
cmd[3] = data >> 19 & 0x03;
cmd[4] = data >> 12 & 0x7f;
} else {
cmd[1] = data >> 24 & 0xff;
cmd[2] = data >> 16 & 0xff;
}
BOOL err = FALSE;
err |= !EXIImmEx(chan, cmd, sizeof(cmd), EXI_WRITE);
err |= !EXIImmEx(chan, (void*)(((CARDID*)card->workArea)+1), card->latency, EXI_WRITE);
err |= !EXIImmEx(chan, rbuf, length, EXI_READ);
err |= !EXIDeselect(chan);
return err ? CARD_RESULT_NOCARD : CARD_RESULT_READY;
}
/*
* --INFO--
* Address: 80008E60
* Size: 000044
*/
static u32 GetInitVal()
{
srand(OSGetTick());
u32 val = 0x7fec8000;
val |= rand();
val &= 0xFFFFF000;
return val;
}
/*
* --INFO--
* Address: 80008EC0
* Size: 00008C
*/
static u32 DummyLen()
{
u32 lshift = 1;
u32 i = 0;
srand(OSGetTick());
int result = (rand() & 0x1f) + 1;
for (; result < 4 && i < 10; i++) {
result = OSGetTick() << lshift;
if (++lshift > 0x10)
lshift = 1;
srand(result);
result = (rand() & 0x1f) + 1;
}
return result < 4 ? 4 : result;
}
static void InitCallback(void* dspTask);
static void DoneCallback(void* dspTask);
struct CARDDecodeParameters {
u8* inputAddr; // _00
u32 inputLength; // _04
u32 aramAddr; // _08
u8* outputAddr; // _0C
};
/*
* --INFO--
* Address: 80008F60
* Size: 0002B0
*/
int __CARDUnlock(int chan, u8 flashID[12])
{
u32 Ans1, Ans2;
u8 rbuf[64];
// The nonsense
CARDControl* card = &__CARDBlock[chan];
DSPTaskInfo* task = &card->task;
CARDDecodeParameters* param = (CARDDecodeParameters*)card->workArea;
u8* input = (u8*)param + sizeof(CARDDecodeParameters);
input = (u8*)OSRoundUp32B(input);
u8* output = input + 32;
u32 data;
s32 dummy;
s32 rlen;
data = GetInitVal();
dummy = DummyLen();
rlen = dummy;
if (ReadArrayUnlock(chan, data, rbuf, rlen, FALSE) < CARD_RESULT_READY)
return CARD_RESULT_NOCARD;
// TODO: Pikmin uses `card->formatStep`, but every other
// decomp uses `card->scramble`. What's up with that?
u32 shift;
u32 wk;
shift = dummy * 8 + 1;
wk = exnor_1st(data, shift);
card->formatStep = wk | (DATA_SCRAMBLE_R(wk) << 31 & 0x80000000);
card->formatStep = bitrev(card->formatStep);
data = 0;
dummy = DummyLen();
rlen = dummy + 20;
if (ReadArrayUnlock(chan, data, rbuf, rlen, TRUE) < CARD_RESULT_READY)
return CARD_RESULT_NOCARD;
u32 para1A = *(u32*)(rbuf + 0);
u32 para1B = *(u32*)(rbuf + 4);
Ans1 = *(u32*)(rbuf + 8);
u32 para2A = *(u32*)(rbuf + 12);
u32 para2B = *(u32*)(rbuf + 16);
para1A ^= card->formatStep;
shift = 32;
wk = exnor(card->formatStep, shift);
card->formatStep = wk | (DATA_SCRAMBLE_L(wk) >> 31 & 0x00000001);
para1B ^= card->formatStep;
shift = 32;
wk = exnor(card->formatStep, shift);
card->formatStep = wk | (DATA_SCRAMBLE_L(wk) >> 31 & 0x00000001);
Ans1 ^= card->formatStep;
shift = 32;
wk = exnor(card->formatStep, shift);
card->formatStep = wk | (DATA_SCRAMBLE_L(wk) >> 31 & 0x00000001);
para2A ^= card->formatStep;
shift = 32;
wk = exnor(card->formatStep, shift);
card->formatStep = wk | (DATA_SCRAMBLE_L(wk) >> 31 & 0x00000001);
para2B ^= card->formatStep;
shift = dummy * 8;
wk = exnor(card->formatStep, shift);
card->formatStep = wk | (DATA_SCRAMBLE_L(wk) >> 31 & 0x00000001);
shift = 32 + 1;
wk = exnor(card->formatStep, shift);
card->formatStep = wk | (DATA_SCRAMBLE_L(wk) >> 31 & 0x00000001);
*(u32*)(input + 0) = para2A;
*(u32*)(input + 4) = para2B;
param->inputAddr = input;
param->inputLength = 8;
param->outputAddr = output;
param->aramAddr = 0;
DCFlushRange(input, 8);
DCInvalidateRange(output, 4);
DCFlushRange(param, sizeof(CARDDecodeParameters));
Jac_DSPcardDecodeAsync(task, param, DoneCallback);
*(u32*)(flashID + 0) = para1A;
*(u32*)(flashID + 4) = para1B;
*(u32*)(flashID + 8) = Ans1;
return CARD_RESULT_READY;
}
/*
* --INFO--
* Address: ........
* Size: 0000C4
*/
static void InitCallback(void* dspTask)
{
}
/*
* --INFO--
* Address: 80009220
* Size: 0001E0
*/
static void DoneCallback(void* dspTask)
{
DSPTaskInfo* task = (DSPTaskInfo*)dspTask;
u8 rbuf[64];
u32 Ans2;
u8 status;
s32 chan;
CARDControl* card;
for (chan = 0; chan < 2; ++chan) {
card = &__CARDBlock[chan];
if (&card->task == task) {
break;
}
}
ASSERTLINE(548, 0 <= chan && chan < 2);
// The nonsense
CARDDecodeParameters* param = (CARDDecodeParameters*)card->workArea;
u8* input = (u8*)param + sizeof(CARDDecodeParameters);
input = (u8*)OSRoundUp32B(input);
u8* output = input + 32;
Ans2 = *(u32*)output;
// TODO: Pikmin uses `card->formatStep`, but every other
// decomp uses `card->scramble`. What's up with that?
s32 dummy;
s32 rlen;
u32 data;
dummy = DummyLen();
rlen = dummy;
data = (Ans2 ^ card->formatStep) & 0xffff0000;
if (ReadArrayUnlock(chan, data, rbuf, rlen, TRUE) < CARD_RESULT_READY) {
EXIUnlock(chan);
__CARDMountCallback(chan, CARD_RESULT_NOCARD);
return;
}
u32 shift;
u32 wk, wk1;
shift = (rlen + 4 + card->latency) * 8 + 1;
wk = exnor(card->formatStep, shift);
card->formatStep = wk | ((DATA_SCRAMBLE_L(wk) >> 31) & 0x00000001);
dummy = DummyLen();
rlen = dummy;
data = ((Ans2 << 16) ^ card->formatStep) & 0xffff0000;
if (ReadArrayUnlock(chan, data, rbuf, rlen, TRUE) < CARD_RESULT_READY) {
EXIUnlock(chan);
__CARDMountCallback(chan, CARD_RESULT_NOCARD);
return;
}
s32 result = __CARDReadStatus(chan, &status);
if (!EXIProbe(chan)) {
EXIUnlock(chan);
__CARDMountCallback(chan, CARD_RESULT_NOCARD);
return;
}
if (result == CARD_RESULT_READY && !(status & 0x40)) {
EXIUnlock(chan);
result = CARD_RESULT_IOERROR;
}
__CARDMountCallback(chan, result);
}
+365
View File
@@ -0,0 +1,365 @@
#include "jaudio_NES/dspdriver.h"
#include "jaudio_NES/dspinterface.h"
#include "jaudio_NES/audiothread.h"
#include "jaudio_NES/driverinterface.h"
#include "jaudio_NES/rate.h"
#include <dolphin/PPCArch.h>
#define DSPCH_LENGTH (64)
static dspch_ DSPCH[DSPCH_LENGTH] ATTRIBUTE_ALIGN(32);
static int old_time;
static u32 history[10] = { 0xF4240 };
/*
* --INFO--
* Address: ........
* Size: 000014
*/
dspch_* GetDSPchannelHandle(u32 idx)
{
return &DSPCH[idx];
// UNUSED FUNCTION
}
/*
* --INFO--
* Address: 8000AD00
* Size: 000060
*/
void InitDSPchannel()
{
dspch_* chan;
int i;
for (i = 0; i < DSPCH_LENGTH; ++i) {
chan = &DSPCH[i];
chan->buffer_idx = i;
chan->_01 = 0;
chan->_08 = 0;
chan->_06 = 0;
chan->_0C = NULL;
chan->_03 = 0;
chan->_04 = 0;
}
}
/*
* --INFO--
* Address: 8000AD60
* Size: 000114
*/
dspch_* AllocDSPchannel(u32 param_1, u32 param_2)
{
s32 i;
u32* p2 = &param_2;
s32* ip = &i;
if (param_1 == 0) {
for (i = 0; i < DSPCH_LENGTH; ++i) {
if (DSPCH[i]._01 == 0) {
DSPCH[i]._01 = TRUE;
DSPCH[i]._08 = (jc_*)param_2;
DSPCH[i]._03 = 1;
DSP_AllocInit(i);
return &DSPCH[i];
}
}
return NULL;
}
for (i = 1; i < DSPCH_LENGTH; i += 2) {
if (DSPCH[i]._01 || DSPCH[i - 1]._01)
continue;
DSPCH[i]._01 = 3;
DSPCH[i - 1]._01 = 2;
DSPCH[i]._08 = (jc_*)param_2;
DSPCH[i - 1]._08 = (jc_*)param_2;
DSP_AllocInit(i);
DSP_AllocInit(i - 1);
return &DSPCH[i - 1];
}
return NULL;
}
/*
* --INFO--
* Address: 8000AE80
* Size: 0000DC
*/
int DeAllocDSPchannel(dspch_* chan, u32 id)
{
if (chan == NULL) {
return -1;
}
if (chan->_08 != (jc_*)id) {
return -2;
}
switch (chan->_01) {
case 1:
case 4:
chan->_01 = 0;
break;
case 2:
chan->_01 = 0;
DeAllocDSPchannel(&DSPCH[chan->buffer_idx + 1], id);
break;
case 3:
chan->_01 = 0;
DeAllocDSPchannel(&DSPCH[chan->buffer_idx - 1], id);
break;
}
chan->_03 = 0;
chan->_0C = nullptr;
chan->_08 = 0;
return 0;
}
/*
* --INFO--
* Address: 8000AF60
* Size: 000104
*/
dspch_* GetLowerDSPchannel()
{
u8 max = 255;
u32 id = 0;
u32 x = 0;
u32 i = 0;
u8* REF_max = &max;
u32* REF_id = &id;
u32* REF_x = &x;
u32* REF_i = &i;
for (i; i < DSPCH_LENGTH; i++) {
if (DSPCH[i]._01 != 4) {
if (DSPCH[i]._01 == 0) {
DSPCH[i]._03 = 0;
id = i;
break;
}
if (DSPCH[i]._0C) {
GetDspHandle(DSPCH[i].buffer_idx);
if (DSPCH[i]._03 <= max) {
DSPchannel_* buf = GetDspHandle(DSPCH[i].buffer_idx);
if (max != DSPCH[i]._03 || (x && (buf->_10C >= x || buf->_10C == 0))) {
x = buf->_10C;
id = i;
max = DSPCH[i]._03;
}
}
}
}
}
return &DSPCH[id];
}
/*
* --INFO--
* Address: 8000B080
* Size: 0000D8
*/
dspch_* GetLowerActiveDSPchannel()
{
u8 a = 0xFF;
u32 index = 0;
u32 c = 0;
u32 i;
DSPchannel_* buf;
u8* REF_a = &a;
u32* REF_index = &index;
u32* REF_c = &c;
for (i = 0; i < DSPCH_LENGTH; ++i) {
if (DSPCH[i]._01 == 4 || DSPCH[i]._01 == 0)
continue;
if (DSPCH[i]._03 > a)
continue;
buf = GetDspHandle(DSPCH[i].buffer_idx);
if (a == DSPCH[i]._03) {
if (c == 0)
continue;
if (buf->_10C < c && buf->_10C != 0)
continue;
}
c = buf->_10C;
index = i;
a = DSPCH[i]._03;
}
return &DSPCH[index];
}
/*
* --INFO--
* Address: 8000B160
* Size: 00007C
*/
BOOL ForceStopDSPchannel(dspch_* chan)
{
dspch_** REF_chan;
DSPchannel_* buf;
REF_chan = &chan;
if (chan->_01 == 4)
return FALSE;
buf = GetDspHandle(chan->buffer_idx);
if (!buf->enabled)
return FALSE;
buf->endRequested = DSP_TRUE;
chan->_01 = 4;
DSP_FlushChannel(chan->buffer_idx);
return TRUE;
}
/*
* --INFO--
* Address: 8000B1E0
* Size: 0000AC
*/
BOOL BreakLowerDSPchannel(u8 param_1)
{
u8* REF_param_1;
dspch_* chan;
DSPchannel_* buf;
chan = GetLowerDSPchannel();
REF_param_1 = &param_1;
if (chan->_03 > param_1)
return FALSE;
if (chan->_03 == param_1) {
buf = GetDspHandle(chan->buffer_idx); // UNUSED??
}
if (chan->_01) {
if (chan->_0C) {
chan->_06 = chan->_0C(chan, 3);
ForceStopDSPchannel(chan);
chan->_01 = 4;
}
ForceStopDSPchannel(chan);
} else {
return FALSE;
}
return TRUE;
}
/*
* --INFO--
* Address: 8000B2A0
* Size: 0000AC
*/
BOOL BreakLowerActiveDSPchannel(u8 id)
{
u8* id_ptr = &id;
dspch_* chan = GetLowerActiveDSPchannel();
if (chan->_03 > id) {
return FALSE;
}
if (chan->_03 == id) {
GetDspHandle(chan->buffer_idx);
}
if (chan->_01) {
if (chan->_0C) {
chan->_06 = chan->_0C(chan, 3);
ForceStopDSPchannel(chan);
chan->_01 = 4;
}
ForceStopDSPchannel(chan);
} else {
return FALSE;
}
return TRUE;
}
/*
* --INFO--
* Address: ........
* Size: 000008
*/
void UpdateDSPchannel(dspch_* chan)
{
// UNUSED FUNCTION
}
/*
* --INFO--
* Address: 8000B360
* Size: 0001F4
*/
void UpdateDSPchannelAll()
{
int tick = OSGetTick();
u32 old = tick - old_time;
old_time = tick;
int id = JAC_SUBFRAMES - DspSyncCountCheck();
history[id] = old;
if (id != 0 && (f32)history[0] / (f32)old < 1.1f) {
BreakLowerActiveDSPchannel(0x7e);
}
for (u32 i = 0; i < DSPCH_LENGTH; i++) {
dspch_* chan = &DSPCH[i];
dspch_** chanptr = &chan;
if (chan->_01 == FALSE) {
continue;
}
DSPchannel_* buf = GetDspHandle(chan->buffer_idx);
if (buf->done) {
if (chan->_0C) {
chan->_06 = chan->_0C(chan, 2);
}
buf->done = FALSE;
buf->enabled = FALSE;
DSP_FlushChannel(chan->buffer_idx);
if (chan->_01 == FALSE) {
continue;
}
}
if (!buf->endRequested) {
buf->_10C++;
if (buf->_10C == chan->_04 && chan->_0C) {
chan->_06 = chan->_0C(chan, 4);
}
}
if (chan->_0C) {
u16* ptr = &chan->_06;
u16 a = *ptr;
if (a) {
*ptr = a - 1;
}
if (*ptr == 0) {
*ptr = chan->_0C(chan, 0);
if (*ptr == 0) {
buf->done = FALSE;
buf->enabled = FALSE;
__Entry_WaitChannel(1);
DSP_FlushChannel(chan->buffer_idx);
}
}
}
}
EntryCheck_WaitDSPChannel();
PPCSync();
}
@@ -0,0 +1,479 @@
#include "jaudio_NES/dspinterface.h"
#include "dolphin/os.h"
#include "jaudio_NES/sample.h"
#include "jaudio_NES/dspproc.h"
#include "jaudio_NES/dspdriver.h"
#include "jaudio_NES/driverinterface.h"
#include "jaudio_NES/fxinterface.h"
#include "limits.h"
#define CH_BUF_LENGTH (64)
#define FX_BUF_LENGTH (4)
static DSPchannel_ CH_BUF[CH_BUF_LENGTH];
static FXBuffer FX_BUF[FX_BUF_LENGTH];
/*
* --INFO--
* Address: 8000B560
* Size: 000018
*/
DSPchannel_* GetDspHandle(u8 idx)
{
return &CH_BUF[idx];
}
/*
* --INFO--
* Address: ........
* Size: 000034
*/
DSPchannel_* GetDspHandleNc(u8)
{
// UNUSED FUNCTION
}
/*
* --INFO--
* Address: 8000B580
* Size: 000014
*/
FXBuffer* GetFxHandle(u8 idx)
{
return &FX_BUF[idx];
}
/*
* --INFO--
* Address: ........
* Size: 000030
*/
FXBuffer* GetFxHandleNc(u8 idx)
{
// UNUSED FUNCTION
}
/*
* --INFO--
* Address: 8000B5A0
* Size: 00002C
*/
void DSP_SetPitch(u8 idx, u16 pitch)
{
DSPchannel_* buf = &CH_BUF[idx];
if (pitch >= SHRT_MAX)
pitch = SHRT_MAX;
buf->resamplingRatio = pitch;
}
/*
* --INFO--
* Address: ........
* Size: 000050
*/
void DSP_SetPitch_Indirect(u8 idx, f32, f32)
{
// UNUSED FUNCTION
}
/*
* --INFO--
* Address: 8000B5E0
* Size: 000020
*/
void DSP_SetMixerInitDelayMax(u8 idx, u8 initDelayMax)
{
DSPchannel_* buf = &CH_BUF[idx];
buf->samplesToKeepCount = initDelayMax;
}
/*
* --INFO--
* Address: 8000B600
* Size: 00004C
*/
void DSP_SetMixerInitVolume(u8 idx, u8 mixer, s16 volume, u8 level)
{
u8* REF_idx;
u8* REF_mixer;
DSPchannel_* buf;
DSPMixerChannel* mixChan;
REF_idx = &idx;
REF_mixer = &mixer;
buf = &CH_BUF[idx];
mixChan = &buf->mixChannels[mixer];
mixChan->currentVolume = volume;
mixChan->targetVolume = volume;
mixChan->level = (level << 8) | (level);
}
/*
* --INFO--
* Address: 8000B660
* Size: 000044
*/
void DSP_SetMixerVolume(u8 idx, u8 mixer, s16 volume, u8 param_4)
{
DSPchannel_* buf = &CH_BUF[idx];
DSPMixerChannel* mixChan = &buf->mixChannels[mixer];
if (buf->endRequested)
return;
mixChan->targetVolume = volume;
mixChan->level = (param_4 << 8) | (mixChan->level & 0xff);
}
/*
* --INFO--
* Address: 8000B6C0
* Size: 00002C
*/
void DSP_SetOscInfo(u8 idx, u32 samplesSourceType)
{
DSPchannel_* buf = &CH_BUF[idx];
buf->baseAddress = 0;
buf->afcRemainingDecodedSamples = 16;
buf->samplesSourceType = samplesSourceType;
}
/*
* --INFO--
* Address: 8000B700
* Size: 000020
*/
void DSP_SetPauseFlag(u8 idx, u8 pauseFlag)
{
DSPchannel_* buf = &CH_BUF[idx];
buf->useConstantSample = pauseFlag;
}
/*
* --INFO--
* Address: 8000B720
* Size: 0000B0
*/
void DSP_SetWaveInfo(u8 idx, Wave_* wave, u32 baseAddress)
{
static u8 COMP_BLOCKSAMPLES[] = {
0x10, 0x10, 0x01, 0x01, 0x01, 0x10, 0x10, 0x01,
};
static u8 COMP_BLOCKBYTES[] = {
0x09, 0x05, 0x08, 0x10, 0x01, 0x01, 0x01, 0x01,
};
DSPchannel_* buf = &CH_BUF[idx];
buf->baseAddress = baseAddress;
buf->afcRemainingDecodedSamples = COMP_BLOCKSAMPLES[wave->compBlockIdx];
buf->samplesSourceType = COMP_BLOCKBYTES[wave->compBlockIdx];
if (buf->samplesSourceType < 4)
return;
buf->_11C = wave->_1C;
buf->isLooping = wave->isLooping;
if (buf->isLooping) {
buf->loopAddress = wave->loopAddress;
buf->loopStartPosition = wave->loopStartPosition;
buf->loopYN1 = wave->loopYN1;
buf->loopYN2 = wave->loopYN2;
} else {
buf->loopStartPosition = buf->_11C;
}
for (int i = 0; i < 16; ++i) {
buf->afcRemainingSamples[i] = 0;
}
}
/*
* --INFO--
* Address: 8000B7E0
* Size: 000038
*/
void DSP_SetBusConnect(u8 idx, u8 mixer, u8 busConnect)
{
static u16 connect_table[] = {
0x0000, 0x0D00, 0x0D60, 0x0DC0, 0x0E20, 0x0E80, 0x0EE0, 0x0CA0, 0x0F40, 0x0FA0, 0x0B00, 0x09A0,
};
DSPchannel_* buf = &CH_BUF[idx];
DSPMixerChannel* mixChan = &buf->mixChannels[mixer];
mixChan->id = connect_table[busConnect];
}
/*
* --INFO--
* Address: 8000B820
* Size: 000020
*/
void DSP_PlayStop(u8 idx)
{
DSPchannel_* buf = &CH_BUF[idx];
buf->enabled = DSP_FALSE;
}
/*
* --INFO--
* Address: 8000B840
* Size: 000060
*/
void DSP_AllocInit(u8 idx)
{
DSPchannel_* buf = &CH_BUF[idx];
buf->useConstantSample = DSP_FALSE;
buf->done = DSP_FALSE;
buf->endRequested = DSP_FALSE;
buf->enabled = DSP_FALSE;
DSP_InitFilter(idx);
DSP_FlushChannel(idx);
}
/*
* --INFO--
* Address: 8000B8A0
* Size: 00007C
*/
void DSP_PlayStart(u8 idx)
{
u32 i;
DSPchannel_* buf = &CH_BUF[idx];
buf->_10C = 0;
buf->currentPosition = 0;
buf->currentPosFrac = 0;
buf->resetVpb = DSP_TRUE;
buf->constantSample = 0;
for (i = 0; i < 4; ++i) {
buf->resampleBuffer[i] = 0;
buf->biquadHistory[i] = 0;
}
for (i = 0; i < 20; ++i) {
buf->variableFirHistory[i] = 0;
}
buf->enabled = DSP_TRUE;
}
/*
* --INFO--
* Address: 8000B920
* Size: 00001C
*/
void DSP_SetDistFilter(u8 idx, s16 distFilter)
{
DSPchannel_* buf = &CH_BUF[idx];
buf->lowPassCoeff = distFilter;
}
/*
* --INFO--
* Address: 8000B940
* Size: 000024
*/
void DSP_SetFilterTable(s16* dst, s16* src, u32 len)
{
for (int i = 0; i < len; ++i) {
*dst++ = *src++;
}
}
/*
* --INFO--
* Address: 8000B980
* Size: 00003C
*/
void DSP_SetIIRFilterParam(u8 idx, s16* param_2)
{
DSPchannel_* buf = &CH_BUF[idx];
DSP_SetFilterTable(buf->biquadFilterCoeffs, param_2, 4);
}
/*
* --INFO--
* Address: 8000B9C0
* Size: 00003C
*/
void DSP_SetFIR8FilterParam(u8 idx, s16* param_2)
{
DSPchannel_* buf = &CH_BUF[idx];
DSP_SetFilterTable(buf->variableFirCoeffs, param_2, 8);
}
/*
* --INFO--
* Address: 8000BA00
* Size: 000054
*/
void DSP_SetFilterMode(u8 idx, u16 filterMode)
{
DSPchannel_* buf = &CH_BUF[idx];
u8 enableBiquadFilter = filterMode & 0b100000;
u8 variableFirFilterSize = filterMode & 0b011111;
if (enableBiquadFilter) {
if (variableFirFilterSize > 20) {
variableFirFilterSize = 20;
}
} else {
if (variableFirFilterSize > 24) {
variableFirFilterSize = 24;
}
}
buf->filterMode = enableBiquadFilter + variableFirFilterSize;
}
/*
* --INFO--
* Address: 8000BA60
* Size: 000070
*/
void DSP_InitFilter(u8 idx)
{
int i;
DSPchannel_* buf = &CH_BUF[idx];
for (i = 0; i < 8; ++i) {
buf->variableFirCoeffs[i] = 0;
}
buf->variableFirCoeffs[0] = SHRT_MAX;
for (i = 0; i < 4; ++i) {
buf->biquadFilterCoeffs[i] = 0;
}
buf->biquadFilterCoeffs[0] = SHRT_MAX;
buf->lowPassCoeff = 0;
}
/*
* --INFO--
* Address: 8000BAE0
* Size: 00003C
*/
void DSP_FlushBuffer()
{
DCFlushRange(CH_BUF, sizeof(CH_BUF));
DCFlushRange(FX_BUF, sizeof(FX_BUF));
}
/*
* --INFO--
* Address: 8000BB20
* Size: 000038
*/
void DSP_FlushChannel(u8 idx)
{
DCFlushRangeNoSync(&CH_BUF[idx], sizeof(DSPchannel_));
}
/*
* --INFO--
* Address: ........
* Size: 000038
*/
void DSP_CacheChannel(u8 idx)
{
// UNUSED FUNCTION
}
/*
* --INFO--
* Address: ........
* Size: 00002C
*/
void DSP_FlushChannelAll()
{
// UNUSED FUNCTION
}
/*
* --INFO--
* Address: ........
* Size: 00002C
*/
void DSP_CacheChannelAll()
{
// UNUSED FUNCTION
}
/*
* --INFO--
* Address: 8000BB60
* Size: 00002C
*/
void DSP_InvalChannelAll()
{
DCInvalidateRange(CH_BUF, sizeof(CH_BUF));
}
/*
* --INFO--
* Address: 8000BBA0
* Size: 000050
*/
void DSP_ClearBuffer()
{
for (int i = 0; i < CH_BUF_LENGTH; ++i) {
Jac_bzero(&CH_BUF[i], sizeof(DSPchannel_));
}
}
static u32 DSPADPCM_FILTER[] ATTRIBUTE_ALIGN(32) = {
0x00000000, 0x08000000, 0x00000800, 0x04000400, 0x1000f800, 0x0e00fa00, 0x0c00fc00, 0x1200f600,
0x1068f738, 0x12c0f704, 0x1400f400, 0x0800f800, 0x0400fc00, 0xfc000400, 0xfc000000, 0xf8000000,
};
static u32 DSPRES_FILTER[] ATTRIBUTE_ALIGN(32) = {
0x0c3966ad, 0x0d46ffdf, 0x0b396696, 0x0e5fffd8, 0x0a446669, 0x0f83ffd0, 0x095a6626, 0x10b4ffc8, 0x087d65cd, 0x11f0ffbf, 0x07ab655e,
0x1338ffb6, 0x06e464d9, 0x148cffac, 0x0628643f, 0x15ebffa1, 0x0577638f, 0x1756ff96, 0x04d162cb, 0x18cbff8a, 0x043561f3, 0x1a4cff7e,
0x03a46106, 0x1bd7ff71, 0x031c6007, 0x1d6cff64, 0x029f5ef5, 0x1f0bff56, 0x022a5dd0, 0x20b3ff48, 0x01be5c9a, 0x2264ff3a, 0x015b5b53,
0x241eff2c, 0x010159fc, 0x25e0ff1e, 0x00ae5896, 0x27a9ff10, 0x00635720, 0x297aff02, 0x001f559d, 0x2b50fef4, 0xffe2540d, 0x2d2cfee8,
0xffac5270, 0x2f0dfedb, 0xff7c50c7, 0x30f3fed0, 0xff534f14, 0x32dcfec6, 0xff2e4d57, 0x34c8febd, 0xff0f4b91, 0x36b6feb6, 0xfef549c2,
0x38a5feb0, 0xfedf47ed, 0x3a95feac, 0xfece4611, 0x3c85feab, 0xfec04430, 0x3e74feac, 0xfeb6424a, 0x4060feaf, 0xfeaf4060, 0x424afeb6,
0xfeac3e74, 0x4430fec0, 0xfeab3c85, 0x4611fece, 0xfeac3a95, 0x47edfedf, 0xfeb038a5, 0x49c2fef5, 0xfeb636b6, 0x4b91ff0f, 0xfebd34c8,
0x4d57ff2e, 0xfec632dc, 0x4f14ff53, 0xfed030f3, 0x50c7ff7c, 0xfedb2f0d, 0x5270ffac, 0xfee82d2c, 0x540dffe2, 0xfef42b50, 0x559d001f,
0xff02297a, 0x57200063, 0xff1027a9, 0x589600ae, 0xff1e25e0, 0x59fc0101, 0xff2c241e, 0x5b53015b, 0xff3a2264, 0x5c9a01be, 0xff4820b3,
0x5dd0022a, 0xff561f0b, 0x5ef5029f, 0xff641d6c, 0x6007031c, 0xff711bd7, 0x610603a4, 0xff7e1a4c, 0x61f30435, 0xff8a18cb, 0x62cb04d1,
0xff961756, 0x638f0577, 0xffa115eb, 0x643f0628, 0xffac148c, 0x64d906e4, 0xffb61338, 0x655e07ab, 0xffbf11f0, 0x65cd087d, 0xffc810b4,
0x6626095a, 0xffd00f83, 0x66690a44, 0xffd80e5f, 0x66960b39, 0xffdf0d46, 0x66ad0c39, 0x00000c8b, 0x18f82527, 0x30fb3c56, 0x471c5133,
0x5a8262f1, 0x6a6d70e2, 0x76417a7c, 0x7d897f61, 0x7fff7f61, 0x7d897a7c, 0x764170e2, 0x6a6d62f1, 0x5a825133, 0x471c3c56, 0x30fb2527,
0x18f80c8b, 0x0000f375, 0xe708dad9, 0xcf05c3aa, 0xb8e4aecd, 0xa57e9d0f, 0x95938f1e, 0x89bf8584, 0x8277809f, 0x8001809f, 0x82778584,
0x89bf8f1e, 0x95939d0f, 0xa57eaecd, 0xb8e4c3aa, 0xcf05dad9, 0xe708f375, 0x000007ff, 0x0fff17ff, 0x1fff27ff, 0x2fff37ff, 0x3fff47ff,
0x4fff57ff, 0x5fff67ff, 0x6fff77ff, 0x7fff7800, 0x70006800, 0x60005800, 0x50004800, 0x40003800, 0x30002800, 0x20001800, 0x10000800,
0x0000f801, 0xf001e801, 0xe001d801, 0xd001c801, 0xc001b801, 0xb001a801, 0xa0019801, 0x90018801, 0x80018800, 0x90009800, 0xa000a800,
0xb000b800, 0xc000c800, 0xd000d800, 0xe000e800, 0xf000f800, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
0x00000000, 0x00000000, 0x00000000, 0x1fff3fff, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
0x00000000, 0x00000000, 0x1fffc001,
};
/*
* --INFO--
* Address: 8000BC00
* Size: 000044
*/
void DSP_SetupBuffer()
{
DsetupTable((u32)CH_BUF_LENGTH, (u32)CH_BUF, (u32)DSPRES_FILTER, (u32)DSPADPCM_FILTER, (u32)FX_BUF);
}
/*
* --INFO--
* Address: 8000BC60
* Size: 000058
*/
void DSP_InitBuffer()
{
for (int i = 0; i < 4; ++i)
DFX_SetFxLine(i, NULL, NULL);
DSP_ClearBuffer();
DSP_SetupBuffer();
InitDSPchannel();
InitGlobalChannel();
DSP_FlushBuffer();
}
+3 -3
View File
@@ -57,11 +57,11 @@ extern void Jac_SetAudioARAMSize(u32 size) {
SELECTED_ARAM_SIZE = size;
}
extern void ARAllocFull(u32* outSize) {
extern void* ARAllocFull(u32* outSize) {
u32 freeSize = aram_hp.length - ((int)aram_hp.current - (int)aram_hp.base);
Nas_HeapAlloc(&aram_hp, freeSize - 32);
void* alloc = Nas_HeapAlloc(&aram_hp, freeSize - 32);
*outSize = freeSize - 32;
return alloc;
}
extern void Jac_InitARAM(u32 loadAudiorom) {
+415
View File
@@ -0,0 +1,415 @@
#include "jaudio_NES/fat.h"
#include "jaudio_NES/aictrl.h"
#include "jaudio_NES/sample.h"
static int ACTIVE_FATS;
static int USEFAT_TAIL;
static u8* fatheapptr;
typedef struct FATEntry FATEntry;
struct FATEntry {
u16 ownerHandle; // _00
u16 blockSize; // _02
u8* addr; // _04
};
#define FAT_SIZE (256)
static struct FAT_info2 {
u16 startBlock; // _00
u16 blockCount; // _02
} FH_TO_FAT[FAT_SIZE];
static FATEntry FAT[FAT_SIZE];
// havent figured this out yet
static struct FATEntry fattmp[FAT_SIZE];
/*
* --INFO--
* Address: 8000DDE0
* Size: 000044
*/
void Jac_FatMemory_Init(u32 size)
{
fatheapptr = (u8*)OSAlloc2(size);
if (fatheapptr) {
FAT_InitSystem(fatheapptr, size);
}
}
/*
* --INFO--
* Address: 8000DE40
* Size: 0000BC
*/
void FAT_InitSystem(u8* heap, u32 size)
{
u32 i;
int fats = 0;
for (i = 0; i < FAT_SIZE; i++) {
if (size < 0x1000) {
break;
}
size -= 0x1000;
FAT[i].addr = heap;
fats++;
heap += 0x1000;
FAT[i].blockSize = 0x1000;
FAT[i].ownerHandle = 0xffff;
}
ACTIVE_FATS = fats;
USEFAT_TAIL = 0;
for (i = ACTIVE_FATS; i < FAT_SIZE; i++) {
FAT[i].ownerHandle = 0xffff;
FAT[i].blockSize = 0;
}
for (i = 0; i < FAT_SIZE; i++) {
FH_TO_FAT[i].startBlock = -1;
FH_TO_FAT[i].blockCount = 0;
}
}
/*
* --INFO--
* Address: 8000DF00
* Size: 0000D4
*/
int FAT_AllocateMemory(u32 size)
{
u32 a = 0;
for (int i = 0; i < FAT_SIZE; i++) {
if (FH_TO_FAT[i].blockCount == 0) {
break;
}
a++;
}
if (a == FAT_SIZE) {
return 0xffff;
}
u16 res = a;
if (size == 0) {
return 0xffff;
}
int b = size + 0xfff >> 0xc;
if (ACTIVE_FATS - USEFAT_TAIL < b) {
return 0xffff;
}
for (u32 i = USEFAT_TAIL; i < USEFAT_TAIL + b; i++) {
FAT[i].ownerHandle = res;
}
FH_TO_FAT[res].startBlock = USEFAT_TAIL;
FH_TO_FAT[res].blockCount = b;
USEFAT_TAIL += b;
return res;
}
/*
* --INFO--
* Address: 8000DFE0
* Size: 000190
*/
int FAT_FreeMemory(u16 size)
{
u16 temp;
u32 i;
u32 start;
u16 size2;
u32 count;
u16 tail;
count = FH_TO_FAT[size].blockCount;
start = FH_TO_FAT[size].startBlock;
FH_TO_FAT[size].blockCount = 0;
size2 = start + count;
tail = USEFAT_TAIL - size2;
if (tail == 0) {
USEFAT_TAIL -= count;
for (i = 0; i < count; i++) {
FAT[USEFAT_TAIL + i].ownerHandle = 0xffff;
}
return 0;
}
for (i = 0; i < count; i++) {
fattmp[i] = FAT[start + i];
fattmp[i].ownerHandle = 0xffff;
}
temp = 0xffff;
for (i = 0; i < tail; i++) {
FAT[start + i] = FAT[size2 + i];
if (FAT[size2 + i].ownerHandle != temp) {
FH_TO_FAT[FAT[size2 + i].ownerHandle].startBlock = start + i;
temp = FAT[size2 + i].ownerHandle;
}
}
USEFAT_TAIL -= count;
for (i = 0; i < count; i++) {
FAT[USEFAT_TAIL + i] = fattmp[i];
}
return 0;
/*
.loc_0x0:
stwu r1, -0x20(r1)
lis r4, 0x8031
subi r4, r4, 0x2118
rlwinm r0,r3,2,14,29
stmw r30, 0x18(r1)
add r3, r4, r0
li r11, 0
lhzx r0, r4, r0
lhz r5, 0x2(r3)
sth r11, 0x2(r3)
add r3, r0, r5
rlwinm r3,r3,0,16,31
lwz r6, 0x2BF4(r13)
sub r7, r6, r3
rlwinm. r30,r7,0,16,31
bne- .loc_0x84
sub r0, r6, r5
lis r3, 0x1
stw r0, 0x2BF4(r13)
subi r6, r3, 0x1
li r8, 0
lwz r7, 0x2BF4(r13)
mtctr r5
cmplwi r5, 0
ble- .loc_0x7C
.loc_0x64:
add r0, r7, r8
addi r8, r8, 0x1
rlwinm r0,r0,3,0,28
add r3, r4, r0
sth r6, 0x400(r3)
bdnz+ .loc_0x64
.loc_0x7C:
li r3, 0
b .loc_0x184
.loc_0x84:
lis r7, 0x1
addi r6, r11, 0
subi r7, r7, 0x1
mtctr r5
cmplwi r5, 0
ble- .loc_0xCC
.loc_0x9C:
add r8, r0, r11
add r10, r4, r6
rlwinm r8,r8,3,0,28
addi r11, r11, 0x1
add r8, r4, r8
addi r6, r6, 0x8
lwz r9, 0x400(r8)
lwz r8, 0x404(r8)
stw r9, 0xC00(r10)
stw r8, 0xC04(r10)
sth r7, 0xC00(r10)
bdnz+ .loc_0x9C
.loc_0xCC:
lis r6, 0x1
li r12, 0
subi r31, r6, 0x1
mtctr r30
cmplwi r30, 0
ble- .loc_0x130
.loc_0xE4:
add r6, r3, r12
add r11, r0, r12
rlwinm r7,r6,3,0,28
rlwinm r6,r11,3,0,28
add r10, r4, r7
add r9, r4, r6
lwz r8, 0x400(r10)
rlwinm r6,r31,0,16,31
lwz r7, 0x404(r10)
stw r8, 0x400(r9)
stw r7, 0x404(r9)
lhz r7, 0x400(r10)
cmplw r6, r7
beq- .loc_0x128
rlwinm r6,r7,2,0,29
mr r31, r7
sthx r11, r4, r6
.loc_0x128:
addi r12, r12, 0x1
bdnz+ .loc_0xE4
.loc_0x130:
lwz r0, 0x2BF4(r13)
li r9, 0
li r3, 0
sub r0, r0, r5
stw r0, 0x2BF4(r13)
lwz r8, 0x2BF4(r13)
mtctr r5
cmplwi r5, 0
ble- .loc_0x180
.loc_0x154:
add r7, r4, r3
add r0, r8, r9
rlwinm r6,r0,3,0,28
lwz r5, 0xC00(r7)
lwz r0, 0xC04(r7)
add r6, r4, r6
addi r9, r9, 0x1
addi r3, r3, 0x8
stw r5, 0x400(r6)
stw r0, 0x404(r6)
bdnz+ .loc_0x154
.loc_0x180:
li r3, 0
.loc_0x184:
lmw r30, 0x18(r1)
addi r1, r1, 0x20
blr
*/
}
/*
* --INFO--
* Address: 8000E180
* Size: 000048
*/
u8* FAT_GetPointer(u16 a, u32 b)
{
u32 c = b >> 12;
if (FH_TO_FAT[a].blockCount <= c) {
return 0;
}
b &= 0xFFF;
return FAT[c + FH_TO_FAT[a].startBlock].addr + b;
}
/*
* --INFO--
* Address: 8000E1E0
* Size: 000034
*/
u8 FAT_ReadByte(u16 a, u32 b)
{
u8* ptr = FAT_GetPointer(a, b);
if (ptr == NULL) {
return 0;
}
return *ptr;
}
/*
* --INFO--
* Address: ........
* Size: 000034
*/
u16 FAT_ReadWord(u16 a, u32 b)
{
// Guessing based on name/size
u16* ptr = (u16*)FAT_GetPointer(a, b);
if (ptr == NULL) {
return 0;
}
return *ptr;
// UNUSED FUNCTION
}
/*
* --INFO--
* Address: ........
* Size: 000050
*/
void FAT_ReadWordD(u16 a, u32 b)
{
// UNUSED FUNCTION
}
/*
* --INFO--
* Address: ........
* Size: 000024
*/
u32 FAT_ReadLong(u16 a, u32 b)
{
// UNUSED FUNCTION
// Guessing based on name/size
return *(u32*)FAT_GetPointer(a, b);
}
/*
* --INFO--
* Address: ........
* Size: 000080
*/
void FAT_ReadLongD(u16 a1, u32 a2)
{
// UNUSED FUNCTION
}
/*
* --INFO--
* Address: 8000E220
* Size: 0000E0
*/
int FAT_StoreBlock(u8* ptr, u16 a, u32 b, u32 c)
{
u8* ptr2 = FAT_GetPointer(a, b);
int size = b;
b &= 0xFFF;
size -= b;
// this whole thing is wrong
while (c != 0) {
b++;
*ptr2++ = *ptr++;
c--;
if (b == 0x1000) {
size += 0x1000;
ptr2 = FAT_GetPointer(a, size);
break;
}
}
for (; 0x1000 <= c;) {
Jac_bcopy(ptr, ptr2, 0x1000);
size += 0x1000;
c -= 0x1000;
ptr += 0x1000;
ptr2 = FAT_GetPointer(a, size);
}
if (c != 0) {
Jac_bcopy(ptr, ptr2, c);
}
return 0;
}
@@ -0,0 +1,62 @@
#include "jaudio_NES/fxinterface.h"
#include "dolphin/os.h"
#include "jaudio_NES/sample.h"
static u16 SEND_TABLE[] = {
0x0D00, 0x0D60, 0x0DC0, 0x0E20, 0x0E80, 0x0EE0, 0x0CA0, 0x0F40, 0x0FA0, 0x0B00, 0x09A0, 0x0000,
};
/*
* --INFO--
* Address: 8000BCC0
* Size: 000138
*/
BOOL DFX_SetFxLine(u8 idx, s16* circularBufferBase, FxlineConfig* config)
{
s16** REF_circularBufferBase;
FXBuffer* buf;
BOOL restoreInterrupts;
restoreInterrupts = OSDisableInterrupts();
buf = GetFxHandle(idx);
buf->enabled = DSP_FALSE;
if (config) {
buf->dest[0].volume = config->volume0;
buf->dest[0].bufferId = SEND_TABLE[config->sendIdx0];
buf->dest[1].volume = config->volume1;
buf->dest[1].bufferId = SEND_TABLE[config->sendIdx1];
buf->circularBufferSize = config->circularBufferSize;
DSP_SetFilterTable(buf->filterCoeffs, config->filterCoeffs, 8);
}
REF_circularBufferBase = &circularBufferBase;
if (circularBufferBase && config) {
int size = config->circularBufferSize * 0xa0; // TODO: What is 160 bytes large?
buf->circularBufferBase = circularBufferBase;
Jac_bzero(circularBufferBase, size);
DCFlushRange(circularBufferBase, size);
} else if (!config || circularBufferBase) {
buf->circularBufferBase = circularBufferBase;
}
if (buf->circularBufferBase) {
buf->enabled = config->enabled;
} else {
buf->enabled = DSP_FALSE;
}
DCFlushRange(buf, sizeof(FXBuffer));
OSRestoreInterrupts(restoreInterrupts);
return TRUE;
}
/*
* --INFO--
* Address: ........
* Size: 0000E0
*/
void DFX_ChangeFxLineParam(u8, u8, u32)
{
// UNUSED FUNCTION
}
+568
View File
@@ -0,0 +1,568 @@
#include "jaudio_NES/heapctrl.h"
#include "jaudio_NES/dummyrom.h"
#include "dolphin/os/OSMessage.h"
#include "dolphin/ar.h"
#include "dolphin/os/OSCache.h"
#define DMABUFFER_SIZE (0x10000)
static u8 dmabuffer[DMABUFFER_SIZE] ATTRIBUTE_ALIGN(32);
static u32 global_id = 0;
/*
* --INFO--
* Address: 8000E9C0
* Size: 000034
*/
static void ARAMFinish(u32 msg)
{
// STACK_PAD_VAR(1);
u32* REF_param_1;
REF_param_1 = &msg;
ARQRequest* request = (ARQRequest*)msg;
OSSendMessage((OSMessageQueue*)request->owner, (OSMessage)1, OS_MESSAGE_BLOCK);
}
/*
* --INFO--
* Address: 8000EA00
* Size: 0000E8
*/
static void ARAM_TO_ARAM_DMA(u32 src, u32 dst, u32 totalSize)
{
ARQRequest request;
OSMessageQueue msgQueue;
OSMessage msg;
u32 burstSize;
OSInitMessageQueue(&msgQueue, &msg, 1);
while (totalSize != 0) {
burstSize = totalSize >= DMABUFFER_SIZE ? DMABUFFER_SIZE : totalSize;
ARQPostRequest(&request, (u32)&msgQueue, ARQ_TYPE_ARAM_TO_MRAM, ARQ_PRIORITY_LOW, src, (u32)dmabuffer, burstSize, &ARAMFinish);
OSReceiveMessage(&msgQueue, NULL, OS_MESSAGE_BLOCK);
ARQPostRequest(&request, (u32)&msgQueue, ARQ_TYPE_MRAM_TO_ARAM, ARQ_PRIORITY_LOW, (u32)dmabuffer, dst, burstSize, &ARAMFinish);
OSReceiveMessage(&msgQueue, NULL, OS_MESSAGE_BLOCK);
totalSize -= burstSize;
src += burstSize;
dst += burstSize;
}
}
/*
* --INFO--
* Address: 8000EB00
* Size: 0000FC
*/
static void DRAM_TO_DRAM_DMA(u32 src, u32 dst, u32 totalSize)
{
ARQRequest request;
OSMessageQueue msgQueue;
OSMessage msg;
u32 dma_buffer_top;
u32 burstSize;
dma_buffer_top = (u32)JAC_ARAM_DMA_BUFFER_TOP;
OSInitMessageQueue(&msgQueue, &msg, 1);
DCFlushRange((void*)src, totalSize);
DCInvalidateRange((void*)dst, totalSize);
while (totalSize != 0) {
burstSize = totalSize >= DMABUFFER_SIZE ? DMABUFFER_SIZE : totalSize;
ARQPostRequest(&request, (u32)&msgQueue, ARQ_TYPE_MRAM_TO_ARAM, ARQ_PRIORITY_LOW, src, dma_buffer_top, burstSize, &ARAMFinish);
OSReceiveMessage(&msgQueue, NULL, OS_MESSAGE_BLOCK);
ARQPostRequest(&request, (u32)&msgQueue, ARQ_TYPE_ARAM_TO_MRAM, ARQ_PRIORITY_LOW, dma_buffer_top, dst, burstSize, &ARAMFinish);
OSReceiveMessage(&msgQueue, NULL, OS_MESSAGE_BLOCK);
totalSize -= burstSize;
src += burstSize;
dst += burstSize;
}
}
/*
* --INFO--
* Address: ........
* Size: 00002C
*/
void Jac_GetUnlockHeap(jaheap_*)
{
// UNUSED FUNCTION
}
/*
* --INFO--
* Address: ........
* Size: 00001C
*/
void Jac_CheckAlloc(jaheap_*)
{
// UNUSED FUNCTION
}
/*
* --INFO--
* Address: 8000EC00
* Size: 000044
*/
void Jac_InitHeap(jaheap_* heap)
{
heap->startAddress = 0;
heap->usedSize = 0;
heap->size = 0;
heap->heapId = global_id++;
heap->isRootHeap = 0;
heap->childCount = 0;
heap->firstChild = 0;
heap->parent = NULL;
heap->nextSibling = 0;
heap->groupOwner = 0;
heap->firstGroupedHeap = 0;
heap->nextGroupedHeap = 0;
}
/*
* --INFO--
* Address: 8000EC60
* Size: 000038
*/
void Jac_SelfInitHeap(jaheap_* heap, u32 startAddr, u32 size, u32 memType)
{
heap->startAddress = startAddr;
heap->size = size;
heap->usedSize = 0;
heap->isRootHeap = 0;
heap->memoryType = memType;
heap->childCount = 0;
heap->firstChild = NULL;
heap->parent = NULL;
heap->nextSibling = 0;
heap->groupOwner = 0;
heap->firstGroupedHeap = 0;
heap->nextGroupedHeap = 0;
}
/*
* --INFO--
* Address: 8000ECA0
* Size: 000100
*/
BOOL Jac_SelfAllocHeap(jaheap_* parent, jaheap_* heap, u32 size, u32 startAddr)
{
if (parent->startAddress && parent->startAddress != -1) {
return FALSE;
}
parent->startAddress = startAddr;
parent->size = size;
parent->usedSize = 0;
parent->isRootHeap = 0;
parent->memoryType = heap->memoryType;
parent->childCount = 0;
parent->firstChild = nullptr;
parent->parent = heap;
jaheap_* temp = heap->firstChild;
if (temp == NULL) {
heap->firstChild = parent;
parent->nextSibling = nullptr;
heap->usedSize = parent->startAddress - heap->startAddress + parent->size;
} else {
jaheap_* temp2 = heap->firstChild;
if (parent->startAddress < heap->firstChild->startAddress) {
parent->nextSibling = heap->firstChild;
heap->firstChild = parent;
} else {
while (TRUE) {
if (!(temp = temp2->nextSibling)) {
parent->nextSibling = NULL;
temp2->nextSibling = parent;
heap->usedSize = parent->startAddress - heap->startAddress + parent->size;
break;
}
if (parent->startAddress < temp->startAddress) {
parent->nextSibling = temp;
temp2->nextSibling = parent;
break;
}
temp2 = temp;
}
}
}
heap->childCount++;
return TRUE;
}
/*
* --INFO--
* Address: 8000EDA0
* Size: 000038
*/
BOOL Jac_SetGroupHeap(jaheap_* heapA, jaheap_* heapB)
{
if (heapA->groupOwner || heapA->nextGroupedHeap) {
return FALSE;
}
heapA->groupOwner = heapB;
heapA->nextGroupedHeap = heapB->firstGroupedHeap;
heapB->firstGroupedHeap = heapA;
return TRUE;
}
/*
* --INFO--
* Address: ........
* Size: 00000C
*/
void Jac_CutdownHeap(jaheap_*)
{
// UNUSED FUNCTION
}
/*
* --INFO--
* Address: 8000EDE0
* Size: 00005C
*/
void Jac_InitMotherHeap(jaheap_* heap, u32 startAddr, u32 size, u8 memType)
{
heap->startAddress = startAddr + 0x1f & 0xffffffe0;
heap->usedSize = 0;
heap->size = size - (startAddr & 0x1f);
heap->heapId = global_id++;
heap->isRootHeap = 1;
heap->memoryType = memType;
heap->childCount = 0;
heap->firstChild = NULL;
heap->parent = NULL;
heap->nextSibling = NULL;
heap->groupOwner = NULL;
heap->firstGroupedHeap = NULL;
heap->nextGroupedHeap = NULL;
}
/*
* --INFO--
* Address: 8000EE40
* Size: 0001B4
*/
BOOL Jac_AllocHeap(jaheap_* heap, jaheap_* parent, u32 size)
{
u32 y;
jaheap_* temp;
jaheap_* temp2;
jaheap_* temp3;
jaheap_* result;
u32 t;
u32 max;
u32 x;
u32 fixedSize = OSRoundUp32B(size);
if (parent->startAddress == 0) {
return FALSE;
}
if (heap->startAddress && heap->startAddress != -1) {
return FALSE;
}
if (parent->size - parent->usedSize < fixedSize) {
temp = parent->firstChild;
y = parent->startAddress;
result = NULL;
max = 0xfffffff;
while (TRUE) {
if (temp == NULL) {
break;
}
x = temp->startAddress - y;
if (x >= fixedSize) {
x -= fixedSize;
if (x < max) {
result = temp;
t = y;
max = x;
}
}
y = temp->startAddress + temp->size;
temp = temp->nextSibling;
}
if (result == 0) {
return FALSE;
}
if (result == parent->firstChild) {
heap->nextSibling = parent->firstChild;
parent->firstChild = heap;
} else {
temp3 = parent->firstChild;
while (TRUE) {
if (temp3->nextSibling == result) {
heap->nextSibling = temp3->nextSibling;
temp3->nextSibling = heap;
break;
}
temp3 = temp3->nextSibling;
}
}
heap->startAddress = t;
heap->size = fixedSize;
heap->usedSize = 0;
heap->isRootHeap = 0;
heap->memoryType = parent->memoryType;
heap->childCount = 0;
heap->firstChild = NULL;
heap->parent = parent;
parent->childCount++;
return TRUE;
}
heap->startAddress = parent->startAddress + parent->usedSize;
heap->size = fixedSize;
heap->usedSize = 0;
heap->isRootHeap = 0;
heap->memoryType = parent->memoryType;
heap->childCount = 0;
heap->firstChild = NULL;
heap->parent = parent;
temp2 = parent->firstChild;
!temp2;
if (temp2 == NULL) {
parent->firstChild = heap;
heap->nextSibling = NULL;
} else {
while (TRUE) {
if (temp2->nextSibling == NULL) {
temp2->nextSibling = heap;
break;
}
temp2 = temp2->nextSibling;
}
}
heap->nextSibling = NULL;
parent->usedSize += fixedSize;
parent->childCount++;
return TRUE;
}
/*
* --INFO--
* Address: 8000F000
* Size: 0001B0
*/
BOOL Jac_DeleteHeap(jaheap_* heap)
{
// STACK_PAD_VAR(4);
jaheap_** pt = &heap;
if (heap->startAddress == 0) {
return FALSE;
}
jaheap_* heap2 = heap->firstChild;
while (heap2) {
jaheap_* next = heap2->nextSibling;
Jac_DeleteHeap(heap2);
heap2 = next;
}
heap->firstChild = NULL;
heap2 = heap->firstGroupedHeap;
while (heap2) {
jaheap_* next = heap2->nextGroupedHeap;
Jac_DeleteHeap(heap2);
heap2 = next;
}
heap->firstGroupedHeap = NULL;
if (heap->parent) {
heap2 = heap->parent->firstChild;
if (heap2 == heap) {
heap->parent->firstChild = heap->nextSibling;
if (heap->nextSibling == NULL) {
heap->parent->usedSize = NULL;
}
} else {
while (TRUE) {
if (heap2 == NULL) {
heap->startAddress = 0;
return FALSE;
}
if (heap2->nextSibling == heap) {
heap2->nextSibling = heap->nextSibling;
if (heap->nextSibling == NULL) {
heap->parent->usedSize = heap2->startAddress + heap2->size - heap->parent->startAddress;
}
break;
}
heap2 = heap2->nextSibling;
}
}
heap->parent->childCount--;
}
if (heap->groupOwner) {
heap2 = heap->groupOwner->firstGroupedHeap;
if (heap2 == heap) {
heap->groupOwner->firstGroupedHeap = heap->nextGroupedHeap;
} else {
while (TRUE) {
if (heap2 == NULL) {
return FALSE;
}
if (heap2->nextGroupedHeap == heap) {
heap2->nextGroupedHeap = heap->nextGroupedHeap;
break;
}
heap2 = heap2->nextGroupedHeap;
}
}
heap->groupOwner = NULL;
heap->nextGroupedHeap = NULL;
}
heap->startAddress = 0;
return TRUE;
}
/*
* --INFO--
* Address: 8000F1C0
* Size: 000064
*/
static void Jac_Move_Children(jaheap_* heap, s32 flag)
{
if (flag == 0) {
return;
}
for (jaheap_* c = heap->firstChild;; c = c->nextSibling) {
if (c == NULL) {
break;
}
c->startAddress += flag;
if (c->firstChild) {
Jac_Move_Children(c, flag);
}
}
}
/*
* --INFO--
* Address: 8000F240
* Size: 0000C8
*/
void Jac_GarbageCollection_St(jaheap_* heap)
{
jaheap_* heap_00;
u32 src;
u32 dst;
dst = heap->startAddress;
heap_00 = heap->firstChild;
if (heap_00 == NULL) {
heap->usedSize = 0;
return;
}
do {
src = heap_00->startAddress;
if (dst != src) {
switch (heap->memoryType) {
case 0:
ARAM_TO_ARAM_DMA(src, dst, heap_00->size);
break;
case 1:
DRAM_TO_DRAM_DMA(src, dst, heap_00->size);
break;
}
Jac_Move_Children(heap_00, dst - heap_00->startAddress);
heap_00->startAddress = dst;
}
dst = heap_00->startAddress + heap_00->size;
} while (heap_00 = heap_00->nextSibling);
heap->usedSize = dst - heap->startAddress;
}
/*
* --INFO--
* Address: ........
* Size: 000058
*/
void Jac_CheckFreeHeap_Total(jaheap_*)
{
// UNUSED FUNCTION
}
/*
* --INFO--
* Address: ........
* Size: 00005C
*/
void Jac_CheckFreeHeap_Linear(jaheap_*)
{
// UNUSED FUNCTION
}
/*
* --INFO--
* Address: 8000F320
* Size: 0000C4
*/
void Jac_ShowHeap(jaheap_* heap, u32 flag)
{
jaheap_** REF_heap = &heap;
jaheap_* c;
jaheap_** REF_c;
// STACK_PAD_VAR(3);
char unused[] = " ";
(void*)unused[0];
c = heap->firstChild;
REF_c = &c;
// STACK_PAD_VAR(15);
if (c) {
do {
if (c->firstChild) {
Jac_ShowHeap(c, flag + 1);
}
c = c->nextSibling;
} while (c);
}
jaheap_* c2;
if (c2 = heap->firstGroupedHeap) {
do {
if (c2->firstGroupedHeap) {
Jac_ShowHeap(c2, flag + 1);
}
c2 = c2->nextGroupedHeap;
} while (c2);
}
}
+113
View File
@@ -0,0 +1,113 @@
#include "jaudio_NES/ipldec.h"
#include "jaudio_NES/audiostruct.h"
#include "jaudio_NES/dspproc.h"
DSPTask EX_DSPTASK[4];
static u8 TASK_READPTR;
static u8 TASK_WRITEPTR;
static u8 TASK_REMAIN;
/*
* --INFO--
* Address: 80008A00
* Size: 000070
*/
static DSPTask* WriteTask(u8 target, u32 cmd, void* task, DSPCallback callback)
{
if (TASK_REMAIN == 4) {
return NULL;
}
DSPTask* dspTask = &EX_DSPTASK[TASK_WRITEPTR];
dspTask->target = target;
dspTask->cmd = cmd;
dspTask->task = task;
dspTask->callback = callback;
TASK_WRITEPTR++;
if (TASK_WRITEPTR == 4) {
TASK_WRITEPTR = 0;
}
TASK_REMAIN++;
return EX_DSPTASK;
}
/*
* --INFO--
* Address: 80008A80
* Size: 0000C0
*/
static void DoTask()
{
while (TASK_REMAIN != 0) {
DSPTask* dspTask = &EX_DSPTASK[TASK_READPTR];
void* task = dspTask->task;
u32 cmd = dspTask->cmd;
DSPCallback cb = dspTask->callback;
switch (dspTask->target) {
case DSPTARGET_IPL:
DiplSec(cmd);
break;
case DSPTARGET_AGB:
DagbSec(cmd);
break;
}
if (cb) {
cb(task);
}
TASK_READPTR++;
if (TASK_READPTR == 4) {
TASK_READPTR = 0;
}
TASK_REMAIN--;
}
}
/*
* --INFO--
* Address: 80008B40
* Size: 000024
*/
BOOL DspExtraTaskCheck()
{
DoTask();
return TRUE;
}
/*
* --INFO--
* Address: ........
* Size: 0000A8
*/
void Jac_IPLDspSec(void)
{
// UNUSED FUNCTION
}
/*
* --INFO--
* Address: 80008B80
* Size: 00004C
*/
void Jac_DSPcardDecodeAsync(void* task, void* cmd, DSPCallback callback)
{
while (WriteTask(DSPTARGET_IPL, (u32)cmd, task, callback) == NULL) {
;
}
}
/*
* --INFO--
* Address: ........
* Size: 00004C
*/
void Jac_DSPagbDecodeAsync(void*, void*, void (*)(void*))
{
// UNUSED FUNCTION
}
+71
View File
@@ -0,0 +1,71 @@
#include "jaudio_NES/ja_calc.h"
#include "PowerPC_EABI_Support/msl/MSL_C/PPC_EABI/cmath_gcn.h"
// #include "std/Math.h"
// #include "dolphin/math.h"
// #include "stl/math.h"
#define SINTABLE_LENGTH (257)
static f32 SINTABLE[SINTABLE_LENGTH];
/*
* --INFO--
* Address: 8000DC20
* Size: 000020
*/
f32 sqrtf2(f32 x)
{
return std::sqrtf(x);
}
/*
* --INFO--
* Address: ........
* Size: 000020
*/
void cosf2(f32)
{
// UNUSED FUNCTION
}
/*
* --INFO--
* Address: 8000DCC0
* Size: 000024
*/
f32 atanf2(f32 x, f32 y)
{
return atan2(x, y);
}
/*
* --INFO--
* Address: ........
* Size: 000020
*/
void sinf2(f32)
{
// UNUSED FUNCTION
}
/*
* --INFO--
* Address: 8000DD00
* Size: 000088
*/
void Jac_InitSinTable()
{
for (u32 i = 0; i < SINTABLE_LENGTH; i++) {
SINTABLE[i] = std::sinf(i * HALF_PI / 256.0f);
}
}
/*
* --INFO--
* Address: 8000DDA0
* Size: 000034
*/
f32 sinf3(f32 x)
{
return SINTABLE[(int)(256.0f * x)];
}
File diff suppressed because it is too large Load Diff
+195
View File
@@ -0,0 +1,195 @@
#include "jaudio_NES/jamosc.h"
#include "jaudio_NES/jammain_2.h"
s16 VIB_TABLE[] = { 0, 0, 0, 0, 20, 0x7fff, 0, 20, 0, 0, 0x14, 0xc000, 0, 20, 0, 13, 0, 1 };
s16 TRE_TABLE[] = { 0, 0, 0x7fff, 0, 20, 0, 0, 20, 0x8001, 0, 0x14, 0, 0, 0x14, 0x7fff, 13, 0, 1 };
s16 REL_TABLE[] = { 0, 10, 0, 15, 1, 0 };
Osc_ VIBRATO_DEF = { 1, 0.8f, VIB_TABLE, VIB_TABLE, 0.0f, 1.0f };
Osc_ TREMOLO_DEF = { 0, 1.0f, TRE_TABLE, TRE_TABLE, 0.0f, 1.0f };
Osc_ ENVELOPE_DEF = { 0, 1.0f, NULL, REL_TABLE, 1.0f, 0.0f };
s16 ADS_TABLE[] = { 0, 0, 0x7fff, 0, 0, 0x7fff, 0, 0, 0, 14, 0, 0 };
Osc_ ADSR_DEF = { 0, 1.0f, NULL, NULL, 1.0f, 0.0f };
Osc_ OSC_DEF = { 0, 1.0f, NULL, REL_TABLE, 1.0f, 0.0f };
/*
* --INFO--
* Address: 80014CA0
* Size: 000090
* Note: Equivalent to `JASTrack::updateOscParam` in later JAudio.
*/
void Osc_Update_Param(seqp_* track, u8 id, f32 val)
{
u8* REF_id = &id;
f32* REF_val = &val;
switch (id) {
case 6:
track->oscillators[0].width = val;
break;
case 7:
track->oscillators[0].rate = val;
break;
case 8:
track->oscillators[0].vertex = val;
break;
case 9:
track->oscillators[1].width = val;
break;
case 10:
track->oscillators[1].rate = val;
break;
case 11:
track->oscillators[1].vertex = val;
break;
}
}
/*
* --INFO--
* Address: 80014D40
* Size: 00003C
*/
void Osc_Setup_Vibrato(seqp_* track, u8 id)
{
track->oscillators[id] = VIBRATO_DEF;
}
/*
* --INFO--
* Address: 80014D80
* Size: 00003C
*/
void Osc_Setup_Tremolo(seqp_* track, u8 id)
{
track->oscillators[id] = TREMOLO_DEF;
}
/*
* --INFO--
* Address: 80014DC0
* Size: 000064
* Note: Equivalent to `JASTrack::oscSetupSimple` in later JAudio.
*/
void Osc_Setup_Simple(seqp_* track, u8 id)
{
switch (id) {
case 0:
Osc_Setup_Vibrato(track, 1);
break;
case 1:
Osc_Setup_Tremolo(track, 0);
break;
case 2:
Osc_Setup_Tremolo(track, 1);
break;
}
}
/*
* --INFO--
* Address: 80014E40
* Size: 000010
*/
void Osc_Clear_Overwrite(seqp_* track)
{
track->oscillatorRouting[0] = 15;
track->oscillatorRouting[1] = 15;
}
/*
* --INFO--
* Address: 80014E60
* Size: 00004C
*/
void Osc_Init_Env(seqp_* track)
{
track->oscillators[0] = ENVELOPE_DEF;
Osc_Clear_Overwrite(track);
}
/*
* --INFO--
* Address: 80014EC0
* Size: 000094
*/
void Osc_Setup_SimpleEnv(seqp_* track, u8 id, u32 val)
{
switch (id) {
case 0:
track->oscillators[0] = ENVELOPE_DEF;
track->oscillators[0].attackVecOffset = (s16*)Jam_OfsToAddr(track, val);
break;
case 1:
track->oscillators[0].releaseVecOffset = (s16*)Jam_OfsToAddr(track, val);
break;
}
}
/*
* --INFO--
* Address: 80014F60
* Size: 0000B0
*/
void Osc_Setup_ADSR(seqp_* track, s16* addr)
{
track->oscillators[0] = ADSR_DEF;
track->oscillators[0].attackVecOffset = track->adsTable;
track->oscillators[0].releaseVecOffset = track->relTable;
for (int i = 0; i < 12; i++) {
track->adsTable[i] = ADS_TABLE[i];
}
for (int i = 0; i < 6; i++) {
track->relTable[i] = REL_TABLE[i];
}
track->adsTable[1] = addr[0];
track->adsTable[4] = addr[1];
track->adsTable[7] = addr[2];
track->adsTable[8] = addr[3];
track->relTable[1] = addr[4];
}
/*
* --INFO--
* Address: 80015020
* Size: 00010C
*/
void Osc_Setup_Full(seqp_* track, u8 flag, u32 offs1, u32 offs2)
{
u32 a = flag & 0xF;
u32 b = flag & 0x40;
u32 idx = (flag >> 4) & 0x1;
u32 c = flag & 0x20;
u32 d = flag & 0x80;
if (d) {
track->oscillators[idx] = ENVELOPE_DEF;
track->oscillators[idx].mode = a;
switch (a) {
case 1:
track->oscillators[idx].vertex = 1.0f;
break;
}
}
if (b) {
if (offs1 == 0) {
track->oscillators[idx].attackVecOffset = NULL;
}
track->oscillators[idx].attackVecOffset = (s16*)Jam_OfsToAddr(track, offs1);
}
if (c) {
if (offs2 == 0) {
track->oscillators[idx].releaseVecOffset = REL_TABLE;
}
track->oscillators[idx].releaseVecOffset = (s16*)Jam_OfsToAddr(track, offs2);
}
}
+604
View File
@@ -0,0 +1,604 @@
#include "jaudio_NES/memory.h"
/*
* --INFO--
* Address: ........
* Size: 00001C
*/
void __CalcRelf(f32)
{
// UNUSED FUNCTION
}
/*
* --INFO--
* Address: ........
* Size: 000170
*/
void MakeReleaseTable()
{
// UNUSED FUNCTION
}
/*
* --INFO--
* Address: ........
* Size: 0000A0
*/
void Nas_ResetIDtable()
{
// UNUSED FUNCTION
}
/*
* --INFO--
* Address: ........
* Size: 0000E0
*/
void Nas_ForceStopChannel(s32)
{
// UNUSED FUNCTION
}
/*
* --INFO--
* Address: ........
* Size: 00006C
*/
void Nas_ForceReleaseChannel(s32)
{
// UNUSED FUNCTION
}
/*
* --INFO--
* Address: ........
* Size: 000084
*/
void Nas_ForceStopSeq(s32)
{
// UNUSED FUNCTION
}
/*
* --INFO--
* Address: ........
* Size: 000030
*/
void* Nas_CacheOff(u8*, s32)
{
// UNUSED FUNCTION
}
/*
* --INFO--
* Address: ........
* Size: 00006C
*/
void Nas_2ndHeapAlloc_CL(ALHeap*, s32)
{
// UNUSED FUNCTION
}
/*
* --INFO--
* Address: ........
* Size: 00006C
*/
void* Nas_2ndHeapAlloc(ALHeap*, s32)
{
// UNUSED FUNCTION
}
/*
* --INFO--
* Address: ........
* Size: 00003C
*/
void Nas_NcHeapAlloc(ALHeap*, s32)
{
// UNUSED FUNCTION
}
/*
* --INFO--
* Address: ........
* Size: 00003C
*/
void Nas_NcHeapAlloc_CL(ALHeap*, s32)
{
// UNUSED FUNCTION
}
/*
* --INFO--
* Address: ........
* Size: 000054
*/
void* Nas_HeapAlloc_CL(ALHeap*, s32)
{
// UNUSED FUNCTION
}
/*
* --INFO--
* Address: ........
* Size: 000048
*/
void Nas_TmpAlloc(ALHeap*, s32)
{
// UNUSED FUNCTION
}
/*
* --INFO--
* Address: ........
* Size: 000034
*/
void Nas_HeapFree(ALHeap*)
{
// UNUSED FUNCTION
}
/*
* --INFO--
* Address: 80005640
* Size: 00006C
*/
void* Nas_HeapAlloc(ALHeap* heap, s32 size)
{
s32* REF_size;
REF_size = &size;
u32 roundedSize = ALIGN_NEXT(size, 32);
if (!heap->base) {
return NULL;
}
u8* prev = heap->current;
if (prev + roundedSize <= heap->base + heap->length) {
heap->current = prev + roundedSize;
} else {
return NULL;
}
heap->count++;
heap->last = prev;
return prev;
}
/*
* --INFO--
* Address: 800056C0
* Size: 000058
*/
void Nas_HeapInit(ALHeap* heap, u8* p2, s32 p3)
{
ALHeap** REF_heap;
int length;
REF_heap = &heap;
heap->count = 0;
if (!p2) {
heap->length = 0;
heap->current = NULL;
heap->last = NULL;
} else {
length = p3 - ((u32)p2 & 0x1F);
heap->base = (u8*)ALIGN_NEXT((u32)p2, 32);
heap->current = heap->base;
heap->length = length;
heap->last = NULL;
}
}
/*
* --INFO--
* Address: ........
* Size: 000018
*/
void Nas_SzStayClear(SZStay*)
{
// UNUSED FUNCTION
}
/*
* --INFO--
* Address: ........
* Size: 00003C
*/
void Nas_SzAutoClear(SZAuto*)
{
// UNUSED FUNCTION
}
/*
* --INFO--
* Address: ........
* Size: 000014
*/
// void Nas_SzCustomClear(SZCustom*)
// {
// // UNUSED FUNCTION
// }
/*
* --INFO--
* Address: ........
* Size: 00010C
*/
void Nas_SzStayDelete(s32)
{
// UNUSED FUNCTION
}
/*
* --INFO--
* Address: ........
* Size: 000068
*/
void Nas_SzHeapReset(u32)
{
// UNUSED FUNCTION
}
/*
* --INFO--
* Address: ........
* Size: 000058
*/
void Nas_SzHeapDivide(AudioHeapstrc*)
{
// UNUSED FUNCTION
}
/*
* --INFO--
* Address: ........
* Size: 000014
*/
void Nas_SzDataDivide(DataHeapstrc*)
{
// UNUSED FUNCTION
}
/*
* --INFO--
* Address: ........
* Size: 0000B4
*/
void Nas_SzStayDivide(StayHeapstrc*)
{
// UNUSED FUNCTION
}
/*
* --INFO--
* Address: ........
* Size: 0000B4
*/
void Nas_SzAutoDivide(AutoHeapstrc*)
{
// UNUSED FUNCTION
}
/*
* --INFO--
* Address: ........
* Size: 0006CC
*/
void* Nas_SzHeapAlloc(s32, s32, s32, s32)
{
// UNUSED FUNCTION
}
/*
* --INFO--
* Address: ........
* Size: 000064
*/
u32 Nas_SzCacheCheck(s32, s32, s32)
{
// UNUSED FUNCTION
}
/*
* --INFO--
* Address: ........
* Size: 000114
*/
void __Nas_SzCacheCheck_Inner(s32, s32, s32)
{
// UNUSED FUNCTION
}
/*
* --INFO--
* Address: ........
* Size: 0000D4
*/
void Nas_InitFilterCoef(f32, f32, u16*)
{
// UNUSED FUNCTION
}
/*
* --INFO--
* Address: ........
* Size: 000020
*/
void Nas_ClearFilter(s16*)
{
// UNUSED FUNCTION
}
/*
* --INFO--
* Address: ........
* Size: 000040
*/
void Nas_SetLPFilter(s16*, s32)
{
// UNUSED FUNCTION
}
/*
* --INFO--
* Address: ........
* Size: 000044
*/
void Nas_SetHPFilter(s16*, s32)
{
// UNUSED FUNCTION
}
/*
* --INFO--
* Address: ........
* Size: 000134
*/
void Nas_SetBPFilter(s16*, s32, s32)
{
// UNUSED FUNCTION
}
/*
* --INFO--
* Address: ........
* Size: 000004
*/
void __DownDelay(delay*)
{
// UNUSED FUNCTION
}
/*
* --INFO--
* Address: ........
* Size: 0000A0
*/
void __Nas_DelayDown()
{
// UNUSED FUNCTION
}
/*
* --INFO--
* Address: ........
* Size: 000048
*/
void __Nas_DacClear()
{
// UNUSED FUNCTION
}
/*
* --INFO--
* Address: ........
* Size: 000258
*/
s32 Nas_SpecChange()
{
// UNUSED FUNCTION
}
/*
* --INFO--
* Address: ........
* Size: 0006B4
*/
void __Nas_MemoryReconfig()
{
// UNUSED FUNCTION
}
/*
* --INFO--
* Address: ........
* Size: 00005C
*/
void* EmemOnCheck(s32, s32)
{
// UNUSED FUNCTION
}
/*
* --INFO--
* Address: ........
* Size: 00007C
*/
void* EmemAlloc(s32, s32, s32)
{
// UNUSED FUNCTION
}
/*
* --INFO--
* Address: ........
* Size: 000064
*/
void Nas_Alloc_Single(s32, s32, u8*, char, s32)
{
// UNUSED FUNCTION
}
/*
* --INFO--
* Address: ........
* Size: 0000C4
*/
void Nas_Init_Single(s32, s32)
{
// UNUSED FUNCTION
}
/*
* --INFO--
* Address: ........
* Size: 000200
*/
void __Nas_Alloc_Single_Auto_Inner(s32)
{
// UNUSED FUNCTION
}
/*
* --INFO--
* Address: ........
* Size: 00012C
*/
void __SearchBank(SwMember*, s32)
{
// UNUSED FUNCTION
}
/*
* --INFO--
* Address: ........
* Size: 0000EC
*/
void __KillSwMember(SwMember*)
{
// UNUSED FUNCTION
}
/*
* --INFO--
* Address: ........
* Size: 000034
*/
void __RomAddrSet(SwMember*, smzwavetable*)
{
// UNUSED FUNCTION
}
/*
* --INFO--
* Address: ........
* Size: 000094
*/
void __Nas_Alloc_Single_Stay_Inner(s32)
{
// UNUSED FUNCTION
}
/*
* --INFO--
* Address: ........
* Size: 000040
*/
void __Do_EmemKill(SwMember*, s32, s32, s32)
{
// UNUSED FUNCTION
}
/*
* --INFO--
* Address: ........
* Size: 000128
*/
void Emem_KillSwMember()
{
// UNUSED FUNCTION
}
/*
* --INFO--
* Address: ........
* Size: 0000A0
*/
void __RestoreAddr(Wavelookuptable*, smzwavetable*)
{
// UNUSED FUNCTION
}
/*
* --INFO--
* Address: ........
* Size: 000030
*/
void DirtyWave(s32)
{
// UNUSED FUNCTION
}
/*
* --INFO--
* Address: ........
* Size: 000030
*/
void EntryWave(s32)
{
// UNUSED FUNCTION
}
/*
* --INFO--
* Address: ........
* Size: 000238
*/
void __ExchangeWave(s32, s32)
{
// UNUSED FUNCTION
}
/*
* --INFO--
* Address: ........
* Size: 000088
*/
void Dirty_AllWave()
{
// UNUSED FUNCTION
}
/*
* --INFO--
* Address: ........
* Size: 0000AC
*/
void __Nas_GetCompressBuffer(delay*)
{
// UNUSED FUNCTION
}
/*
* --INFO--
* Address: ........
* Size: 00028C
*/
void Nas_SetDelayLineParam(s32, s32, s32, s32)
{
// UNUSED FUNCTION
}
/*
* --INFO--
* Address: ........
* Size: 0001E0
*/
void Nas_SetDelayLine(s32, fxconfig_*, s32)
{
// UNUSED FUNCTION
}
+47
View File
@@ -0,0 +1,47 @@
#include "types.h"
s16 CUTOFF_TO_IIR_TABLE[128][4] = {
{ 0x0f5c, 0x0a3d, 0x4665, 0x3999 }, { 0x103f, 0x0a28, 0x45d7, 0x3925 }, { 0x1122, 0x0a14, 0x454a, 0x38b0 },
{ 0x1205, 0x09ff, 0x44bc, 0x383c }, { 0x12e8, 0x09ea, 0x442e, 0x37c8 }, { 0x13cb, 0x09d6, 0x43a0, 0x3754 },
{ 0x14ae, 0x09c1, 0x4312, 0x36e0 }, { 0x1591, 0x09ac, 0x4284, 0x366c }, { 0x1674, 0x0998, 0x41f6, 0x35f8 },
{ 0x1757, 0x0983, 0x4168, 0x3584 }, { 0x183a, 0x096e, 0x40da, 0x3510 }, { 0x191d, 0x095a, 0x404c, 0x349c },
{ 0x1a00, 0x0945, 0x3fbe, 0x3427 }, { 0x1ae3, 0x0931, 0x3f31, 0x33b3 }, { 0x1bc6, 0x091c, 0x3ea3, 0x333f },
{ 0x1ca9, 0x0907, 0x3e15, 0x32cb }, { 0x1d8c, 0x08f3, 0x3d87, 0x3257 }, { 0x1e6f, 0x08de, 0x3cf9, 0x31e3 },
{ 0x1f52, 0x08c9, 0x3c6b, 0x316f }, { 0x2035, 0x08b5, 0x3bdd, 0x30fb }, { 0x2118, 0x08a0, 0x3b4f, 0x3087 },
{ 0x21fc, 0x088b, 0x3ac1, 0x3012 }, { 0x22df, 0x0877, 0x3a33, 0x2f9e }, { 0x23c2, 0x0862, 0x39a6, 0x2f2a },
{ 0x24a5, 0x084d, 0x3918, 0x2eb6 }, { 0x2588, 0x0839, 0x388a, 0x2e42 }, { 0x266b, 0x0824, 0x37fc, 0x2dce },
{ 0x274e, 0x0810, 0x376e, 0x2d5a }, { 0x2831, 0x07fb, 0x36e0, 0x2ce6 }, { 0x2914, 0x07e6, 0x3652, 0x2c72 },
{ 0x29f7, 0x07d2, 0x35c4, 0x2bfe }, { 0x2ada, 0x07bd, 0x3536, 0x2b89 }, { 0x2bbd, 0x07a8, 0x34a8, 0x2b15 },
{ 0x2ca0, 0x0794, 0x341b, 0x2aa1 }, { 0x2d83, 0x077f, 0x338d, 0x2a2d }, { 0x2e66, 0x076a, 0x32ff, 0x29b9 },
{ 0x2f49, 0x0756, 0x3271, 0x2945 }, { 0x302c, 0x0741, 0x31e3, 0x28d1 }, { 0x310f, 0x072d, 0x3155, 0x285d },
{ 0x31f2, 0x0718, 0x30c7, 0x27e9 }, { 0x32d5, 0x0703, 0x3039, 0x2775 }, { 0x33b8, 0x06ef, 0x2fab, 0x2700 },
{ 0x349c, 0x06da, 0x2f1d, 0x268c }, { 0x357f, 0x06c5, 0x2e8f, 0x2618 }, { 0x3662, 0x06b1, 0x2e02, 0x25a4 },
{ 0x3745, 0x069c, 0x2d74, 0x2530 }, { 0x3828, 0x0687, 0x2ce6, 0x24bc }, { 0x390b, 0x0673, 0x2c58, 0x2448 },
{ 0x39ee, 0x065e, 0x2bca, 0x23d4 }, { 0x3ad1, 0x0649, 0x2b3c, 0x2360 }, { 0x3bb4, 0x0635, 0x2aae, 0x22eb },
{ 0x3c97, 0x0620, 0x2a20, 0x2277 }, { 0x3d7a, 0x060c, 0x2992, 0x2203 }, { 0x3e5d, 0x05f7, 0x2904, 0x218f },
{ 0x3f40, 0x05e2, 0x2877, 0x211b }, { 0x4023, 0x05ce, 0x27e9, 0x20a7 }, { 0x4106, 0x05b9, 0x275b, 0x2033 },
{ 0x41e9, 0x05a4, 0x26cd, 0x1fbf }, { 0x42cc, 0x0590, 0x263f, 0x1f4b }, { 0x43af, 0x057b, 0x25b1, 0x1ed7 },
{ 0x4492, 0x0566, 0x2523, 0x1e62 }, { 0x4575, 0x0552, 0x2495, 0x1dee }, { 0x4658, 0x053d, 0x2407, 0x1d7a },
{ 0x473b, 0x0529, 0x2379, 0x1d06 }, { 0x481f, 0x0514, 0x22eb, 0x1c92 }, { 0x4902, 0x04ff, 0x225e, 0x1c1e },
{ 0x49e5, 0x04eb, 0x21d0, 0x1baa }, { 0x4ac8, 0x04d6, 0x2142, 0x1b36 }, { 0x4bab, 0x04c1, 0x20b4, 0x1ac2 },
{ 0x4c8e, 0x04ad, 0x2026, 0x1a4e }, { 0x4d71, 0x0498, 0x1f98, 0x19d9 }, { 0x4e54, 0x0483, 0x1f0a, 0x1965 },
{ 0x4f37, 0x046f, 0x1e7c, 0x18f1 }, { 0x501a, 0x045a, 0x1dee, 0x187d }, { 0x50fd, 0x0445, 0x1d60, 0x1809 },
{ 0x51e0, 0x0431, 0x1cd3, 0x1795 }, { 0x52c3, 0x041c, 0x1c45, 0x1721 }, { 0x53a6, 0x0408, 0x1bb7, 0x16ad },
{ 0x5489, 0x03f3, 0x1b29, 0x1639 }, { 0x556c, 0x03de, 0x1a9b, 0x15c4 }, { 0x564f, 0x03ca, 0x1a0d, 0x1550 },
{ 0x5732, 0x03b5, 0x197f, 0x14dc }, { 0x5815, 0x03a0, 0x18f1, 0x1468 }, { 0x58f8, 0x038c, 0x1863, 0x13f4 },
{ 0x59db, 0x0377, 0x17d5, 0x1380 }, { 0x5abf, 0x0362, 0x1747, 0x130c }, { 0x5ba2, 0x034e, 0x16ba, 0x1298 },
{ 0x5c85, 0x0339, 0x162c, 0x1224 }, { 0x5d68, 0x0324, 0x159e, 0x11b0 }, { 0x5e4b, 0x0310, 0x1510, 0x113b },
{ 0x5f2e, 0x02fb, 0x1482, 0x10c7 }, { 0x6011, 0x02e7, 0x13f4, 0x1053 }, { 0x60f4, 0x02d2, 0x1366, 0x0fdf },
{ 0x61d7, 0x02bd, 0x12d8, 0x0f6b }, { 0x62ba, 0x02a9, 0x124a, 0x0ef7 }, { 0x639d, 0x0294, 0x11bc, 0x0e83 },
{ 0x6480, 0x027f, 0x112f, 0x0e0f }, { 0x6563, 0x026b, 0x10a1, 0x0d9b }, { 0x6646, 0x0256, 0x1013, 0x0d27 },
{ 0x6729, 0x0241, 0x0f85, 0x0cb2 }, { 0x680c, 0x022d, 0x0ef7, 0x0c3e }, { 0x68ef, 0x0218, 0x0e69, 0x0bca },
{ 0x69d2, 0x0204, 0x0ddb, 0x0b56 }, { 0x6ab5, 0x01ef, 0x0d4d, 0x0ae2 }, { 0x6b98, 0x01da, 0x0cbf, 0x0a6e },
{ 0x6c7b, 0x01c6, 0x0c31, 0x09fa }, { 0x6d5f, 0x01b1, 0x0ba3, 0x0986 }, { 0x6e42, 0x019c, 0x0b16, 0x0912 },
{ 0x6f25, 0x0188, 0x0a88, 0x089d }, { 0x7008, 0x0173, 0x09fa, 0x0829 }, { 0x70eb, 0x015e, 0x096c, 0x07b5 },
{ 0x71ce, 0x014a, 0x08de, 0x0741 }, { 0x72b1, 0x0135, 0x0850, 0x06cd }, { 0x7394, 0x0120, 0x07c2, 0x0659 },
{ 0x7477, 0x010c, 0x0734, 0x05e5 }, { 0x755a, 0x00f7, 0x06a6, 0x0571 }, { 0x763d, 0x00e3, 0x0618, 0x04fd },
{ 0x7720, 0x00ce, 0x058b, 0x0489 }, { 0x7803, 0x00b9, 0x04fd, 0x0414 }, { 0x78e6, 0x00a5, 0x046f, 0x03a0 },
{ 0x79c9, 0x0090, 0x03e1, 0x032c }, { 0x7aac, 0x007b, 0x0353, 0x02b8 }, { 0x7b8f, 0x0067, 0x02c5, 0x0244 },
{ 0x7c72, 0x0052, 0x0237, 0x01d0 }, { 0x7d55, 0x003d, 0x01a9, 0x015c }, { 0x7e38, 0x0029, 0x011b, 0x00e8 },
{ 0x7f1b, 0x0014, 0x008d, 0x0074 }, { 0x7fff, 0x0000, 0x0000, 0x0000 },
};
+201
View File
@@ -0,0 +1,201 @@
#include "jaudio_NES/noteon.h"
#include "jaudio_NES/audiostruct.h"
#include "jaudio_NES/jammain_2.h"
#include "jaudio_NES/oneshot.h"
#include "jaudio_NES/connect.h"
#include "jaudio_NES/driverinterface.h"
/*
* --INFO--
* Address: 80013840
* Size: 000394
*/
s32 NoteON(seqp_* track, s32 channel, s32 flag1, s32 flag2, s32 playFlag)
{
if (track->isMuted && (track->pauseStatus & 0x40)) {
return -1;
}
if (track->channels[channel]) {
NoteOFF(track, channel);
}
seqp_* parent = track->parent;
jcs_* jcs = &track->parentController;
u32 reg;
seqp_* temp = parent;
while (jcs->chanCount == 0 || jcs->freeChannels == 0) {
if (temp == NULL) {
jcs = &track->parentController;
break;
}
jcs = &temp->parentController;
temp = temp->parent;
}
if (track->flags == 4) {
if (parent == NULL) {
return -1;
}
if (jcs != &parent->parentController) {
jc_* chan = List_GetChannel(&jcs->freeChannels);
if (chan) {
jcs->chanCount--;
List_AddChannel(&track->parentController.freeChannels, chan);
parent->parentController.chanCount++;
chan->mMgr = &parent->parentController;
}
jcs = &parent->parentController;
}
} else if (jcs != &track->parentController) {
jc_* chan = List_GetChannel(&jcs->freeChannels);
if (chan) {
jcs->chanCount--;
List_AddChannel(&track->parentController.freeChannels, chan);
track->parentController.chanCount++;
chan->mMgr = &track->parentController;
}
jcs = &track->parentController;
}
reg = Jam_ReadRegDirect(track, 6);
u16 phys = Jac_BnkVirtualToPhysical(reg >> 8);
u32 b = (phys & 0xff) << 8 | reg & 0xff;
u32 a = b << 16 | flag1 << 8 | flag2;
jc_* sound;
SOUNDID_ id;
id.value = a;
if ((u8)reg >= 0xf0) {
sound = Play_1shot_Osc(jcs, id, playFlag);
} else if ((u8)reg >= 0xe4) {
sound = Play_1shot_Perc(jcs, id, playFlag);
} else {
sound = Play_1shot(jcs, id, playFlag);
}
track->channels[channel] = sound;
if (sound == NULL) {
return -1;
}
track->activeSoundIds[channel] = sound->channelId;
UpdatePanPower_1Shot(sound, track->regParam.param.arguments[0], track->regParam.param.arguments[1], track->regParam.param.arguments[2],
track->regParam.param.arguments[3]);
for (u32 i = 0; i < 2; i++) {
u32 flag = track->oscillatorRouting[i];
if (flag == 15 || flag == 14) {
continue;
}
if (flag >= 8) {
flag -= 8;
if (sound->mOscillators[flag]) {
track->oscillators[i] = *sound->mOscillators[flag];
}
} else if (flag >= 4) {
flag -= 4;
s16* prev = track->oscillators[i].releaseVecOffset;
if (sound->mOscillators[flag]) {
track->oscillators[i] = *sound->mOscillators[flag];
track->oscillators[i].releaseVecOffset = prev;
}
}
Effecter_Overwrite_1ShotD(sound, &track->oscillators[i], flag);
}
Jam_UpdateTrack(track, 3);
ResetInitialVolume(sound);
return 0;
s32* REF_channel = &channel;
}
/*
* --INFO--
* Address: 80013BE0
* Size: 000090
*/
s32 NoteOFF_R(seqp_* track, u8 param_2, u16 param_3)
{
u8* REF_param_2;
jc_* jc;
REF_param_2 = &param_2;
if (jc = track->channels[param_2]) {
if (jc->channelId == track->activeSoundIds[param_2]) {
if (param_3 == 0) {
Stop_1Shot(jc);
} else {
Stop_1Shot_R(jc, param_3);
}
}
track->channels[param_2] = NULL;
track->activeSoundIds[param_2] = 0;
return 1;
}
return 0;
}
/*
* --INFO--
* Address: 80013C80
* Size: 000024
*/
s32 NoteOFF(seqp_* track, u8 param_2)
{
return NoteOFF_R(track, param_2, 0);
}
/*
* --INFO--
* Address: 80013CC0
* Size: 000058
*/
s32 GateON(seqp_* track, s32 param_2, s32 param_3, s32 param_4, s32 param_5)
{
s32* REF_param_3 = &param_3;
if (track->channels[param_2]) {
Gate_1Shot(track->channels[param_2], param_3, param_4, param_5);
} else {
return -1;
}
return 0;
}
/*
* --INFO--
* Address: ........
* Size: 000008
*/
void ProgramChange(s32 chan)
{
// UNUSED FUNCTION
}
/*
* --INFO--
* Address: 80013D20
* Size: 000064
*/
BOOL CheckNoteStop(seqp_* track, s32 param_2)
{
jc_* jc;
if (jc = track->channels[param_2]) {
if (jc->channelId != track->activeSoundIds[param_2]) {
track->channels[param_2] = NULL;
track->activeSoundIds[param_2] = 0;
return TRUE;
}
if (jc->note == 0xff) {
return TRUE;
}
return FALSE;
}
return TRUE;
}
File diff suppressed because it is too large Load Diff
+7
View File
@@ -0,0 +1,7 @@
#include "jaudio_NES/rate.h"
u32 JAC_AI_SETTING = 0;
f32 JAC_DAC_RATE = 32028.5f;
u32 JAC_SUBFRAMES = 7;
u32 JAC_FRAMESAMPLES = 560;
u32 DAC_SIZE = 1120;
+648
View File
@@ -0,0 +1,648 @@
#include "jaudio_NES/seqsetup.h"
#include "jaudio_NES/jammain_2.h"
#include "jaudio_NES/noteon.h"
#include "jaudio_NES/fat.h"
#include "jaudio_NES/playercall.h"
#include "jaudio_NES/jamosc.h"
#include "jaudio_NES/driverinterface.h"
#include "jaudio_NES/oneshot.h"
#include "jaudio_NES/fat.h"
#include "dolphin/os/OSInterrupt.h"
#define SEQ_SIZE (256)
#define ROOT_OUTER_SIZE (16)
#define ROOTSEQ_SIZE (16)
#define FREE_SEQP_QUEUE_SIZE (256)
static seqp_ seq[SEQ_SIZE];
static OuterParam_ ROOT_OUTER[ROOT_OUTER_SIZE];
static seqp_* rootseq[ROOTSEQ_SIZE];
static seqp_* FREE_SEQP_QUEUE[FREE_SEQP_QUEUE_SIZE];
static u32 BACK_P;
static u32 GET_P;
static u32 SEQ_REMAIN;
/*
* --INFO--
* Address: 80013DA0
* Size: 0000A0
*/
void Jaq_Reset(void)
{
int i;
for (i = 0; i < SEQ_SIZE; ++i) {
seq[i].trackState = 0;
seq[i].childMuteMask = 0;
seq[i].isMuted = 0;
FREE_SEQP_QUEUE[i] = &seq[i];
}
BACK_P = 0;
GET_P = 0;
SEQ_REMAIN = FREE_SEQP_QUEUE_SIZE;
for (i = 0; i < ROOTSEQ_SIZE; ++i) {
rootseq[i] = NULL;
}
Jam_InitRegistTrack();
}
/*
* --INFO--
* Address: ........
* Size: 000008
*/
void Jaq_GetRemainFreeTracks(void)
{
// UNUSED FUNCTION
}
/*
* --INFO--
* Address: 80013E40
* Size: 000088
*/
static BOOL BackTrack(seqp_* track)
{
seqp_** REF_track;
REF_track = &track;
track->trackState = 0;
if (track->_3E4 == 1) {
if (SEQ_REMAIN == FREE_SEQP_QUEUE_SIZE) {
return FALSE;
}
FREE_SEQP_QUEUE[BACK_P] = track;
++SEQ_REMAIN;
++BACK_P;
if (BACK_P == FREE_SEQP_QUEUE_SIZE) {
BACK_P = 0;
}
return TRUE;
}
return FALSE;
}
/*
* --INFO--
* Address: 80013EE0
* Size: 000064
*/
static seqp_* GetNewTrack()
{
seqp_* track;
if (SEQ_REMAIN == 0) {
return NULL;
}
track = FREE_SEQP_QUEUE[GET_P];
++GET_P;
--SEQ_REMAIN;
if (GET_P == FREE_SEQP_QUEUE_SIZE) {
GET_P = 0;
}
track->trackState = 2;
track->_3E4 = 1;
return track;
}
/*
* --INFO--
* Address: 80013F60
* Size: 000048
*/
int AllocNewRoot(seqp_* track)
{
int i;
for (i = 0; i < ROOTSEQ_SIZE; ++i) {
if (!rootseq[i]) {
rootseq[i] = track;
return i;
}
}
return -1;
}
/*
* --INFO--
* Address: 80013FC0
* Size: 00004C
*/
int DeAllocRoot(seqp_* track)
{
int i;
for (i = 0; i < ROOTSEQ_SIZE; ++i) {
if (rootseq[i] == track) {
rootseq[i] = NULL;
return i;
}
}
return -1;
}
/*
* --INFO--
* Address: 80014020
* Size: 000018
*/
seqp_* Jaq_HandleToSeq(u32 handle)
{
return rootseq[handle];
}
/*
* --INFO--
* Address: 80014040
* Size: 000368
*/
static void Init_Track(seqp_* track, u32 dataAddress, seqp_* parent)
{
int i;
if (!parent) {
track->baseData = (u8*)dataAddress;
track->programCounter = 0;
track->tempo = 120;
track->timeBase = 48;
track->timeRelationMode = 1;
track->isPaused = FALSE;
track->pauseStatus = 10;
track->childMuteMask = 0;
track->isMuted = 0;
} else {
track->baseData = parent->baseData;
track->programCounter = dataAddress;
track->fileHandle = parent->fileHandle;
track->tempo = parent->tempo;
track->doChangeTempo = FALSE;
track->tempoFactor = parent->tempoFactor;
track->timeBase = parent->timeBase;
track->timeRelationMode = parent->timeRelationMode;
track->isPaused = parent->isPaused;
track->pauseStatus = parent->pauseStatus;
track->childMuteMask = 0;
}
track->callStackDepth = 0;
track->_D0 = 0;
track->waitTimer = 0;
track->trackState = 1;
track->parent = parent;
track->interruptEnable = 0;
track->interruptActive = 0;
track->timer = 0;
// Initialize all MoveParams with default values.
for (i = 0; i < 18; ++i) {
track->timedParam.move[i].duration = 0.0f;
track->timedParam.move[i].currentValue = 1.0f;
track->timedParam.move[i].targetValue = 1.0f;
}
track->timedParam.inner.pitch.currentValue = 0.0f;
track->timedParam.inner.pitch.targetValue = 0.0f;
track->timedParam.inner.pitch.currentValue = 0.0f; // Just to be sure.
track->timedParam.inner.pitch.targetValue = 0.0f; // Just to be sure.
track->timedParam.inner.pan.currentValue = 0.5f;
track->timedParam.inner.pan.targetValue = 0.5f;
track->timedParam.inner._100.currentValue = 0.5f;
track->timedParam.inner._100.targetValue = 0.5f;
track->timedParam.inner._110.currentValue = 0.0f;
track->timedParam.inner._110.targetValue = 0.0f;
track->timedParam.inner.fxmix.currentValue = 0.0f;
track->timedParam.inner.fxmix.targetValue = 0.0f;
track->timedParam.inner.dolby.currentValue = 0.0f;
track->timedParam.inner.dolby.targetValue = 0.0f;
// Initialize IIRs (skipping the first one)
for (i = 1; i < 4; ++i) {
track->timedParam.inner.IIRs[i].currentValue = 0.0f;
track->timedParam.inner.IIRs[i].targetValue = 0.0f;
}
track->timedParam.inner.distFilter.currentValue = 0.0f;
track->timedParam.inner.distFilter.targetValue = 0.0f;
for (i = 0; i < 32; ++i) {
track->regParam.reg[i] = 0;
}
if ((track->flags & 2) || !track->parent) {
track->regParam.param.arguments[0] = 0;
track->regParam.param.arguments[1] = 1;
track->regParam.param.arguments[2] = 1;
track->regParam.param.arguments[3] = 0x7fff;
track->regParam.param.arguments[4] = 0x4000;
for (i = 0; i < 3; ++i) {
track->panCalcTypes[i] = 2;
track->parentPanCalcTypes[i] = 2;
track->parentController.panCalcTypes[i] = 26;
}
track->regParam.param.bankNumber = 0xf0;
track->regParam.param.pitchScale = 0x0c;
track->regParam.param.basePriority = 0x40;
} else {
for (i = 0; i < 5; ++i) {
track->regParam.param.arguments[i] = track->parent->regParam.param.arguments[i];
}
track->regParam.param.bankNumber = track->parent->regParam.param.bankNumber;
track->regParam.param.pitchScale = track->parent->regParam.param.pitchScale;
track->regParam.param.basePriority = track->parent->regParam.param.basePriority;
for (i = 0; i < 3; ++i) {
track->panCalcTypes[i] = track->parent->panCalcTypes[i];
track->parentPanCalcTypes[i] = track->parent->parentPanCalcTypes[i];
track->parentController.panCalcTypes[i] = track->parent->parentController.panCalcTypes[i];
}
}
for (i = 0; i < 16; ++i) {
track->childOuterParams[i] = NULL;
track->children[i] = 0;
}
for (i = 0; i < 8; ++i) {
track->_94[i] = -1;
track->channels[i] = NULL;
track->activeSoundIds[i] = 0;
}
track->_D4 = 0;
track->_D5 = 0;
track->_90 = 0;
track->_D6 = FALSE;
Osc_Init_Env(track);
track->transpose = 0;
track->finalTranspose = 0;
track->tickCounter = -1;
for (i = 0; i < 16; ++i) {
track->trackPort[i].importFlag = 0;
track->trackPort[i].exportFlag = 0;
}
track->isRegistered = 0;
}
/*
* --INFO--
* Address: 800143C0
* Size: 0000A0
*/
BOOL Jaq_StopSeq(s32 index)
{
seqp_* track;
if (index == -1) {
return FALSE;
}
track = rootseq[index];
if (!track) {
return FALSE;
}
switch (track->trackState) {
case 0:
break;
case 2:
BackTrack(track);
DeAllocRoot(track);
break;
default:
track->trackState = 3;
break;
}
return TRUE;
}
/*
* --INFO--
* Address: 80014460
* Size: 000054
*/
static void __StopSeq(seqp_* track)
{
SeqUpdate(track, 0);
Jaq_CloseTrack(track);
DeAllocRoot(track);
if (track->dataSourceMode == 1) {
FAT_FreeMemory(track->fileHandle);
}
}
/*
* --INFO--
* Address: 800144C0
* Size: 000024
*/
s32 Jaq_SetSeqData(seqp_* param_1, u8* param_2, u32 param_3, u32 param_4)
{
return Jaq_SetSeqData_Limit(param_1, param_2, param_3, param_4, 0);
}
/*
* --INFO--
* Address: 80014500
* Size: 000170
*/
s32 Jaq_SetSeqData_Limit(seqp_* track, u8* param_2, u32 param_3, u32 param_4, u8 param_5)
{
s32 root;
BOOL level;
u8* puVar2;
if (!track) {
level = OSDisableInterrupts();
track = GetNewTrack();
OSRestoreInterrupts(level);
if (!track) {
return -1;
}
} else {
track->_3E4 = 0;
}
root = AllocNewRoot(track);
if (root == -1) {
return -1;
}
track->dataSourceMode = param_4;
switch (param_4) {
case 0:
puVar2 = param_2;
break;
case 1:
track->fileHandle = FAT_AllocateMemory(param_3);
if (track->fileHandle == 0xffff) { // Isn't this literally impossible?
return -1;
}
FAT_StoreBlock(param_2, track->fileHandle, 0, param_3);
puVar2 = NULL;
break;
case 2:
track->fileHandle = (u8)param_2;
puVar2 = NULL;
break;
}
track->trackId = root;
track->flags = 3;
Init_Track(track, (u32)puVar2, NULL);
Jam_InitExtBuffer(&ROOT_OUTER[root]);
Jam_AssignExtBuffer(track, &ROOT_OUTER[root]);
Init_1shot(&track->parentController, param_5);
track->tempoAccumulator = 0.0f;
track->tempoFactor = 1.0f;
Jam_UpdateTrackAll(track);
track->trackState = 2;
return root;
}
/*
* --INFO--
* Address: 80014680
* Size: 00002C
*/
BOOL Jaq_SetBankNumber(seqp_* track, u8 bankNum)
{
u8 lo;
// Let's get ahead of ourselves here.
lo = track->regParam.param.bankNumber & 0xFF;
if (!track) {
return FALSE;
}
track->regParam.param.bankNumber = (bankNum << 8) | lo;
return TRUE;
}
static s32 Jaq_RootCallback(void* track);
/*
* --INFO--
* Address: 800146C0
* Size: 0000B4
*/
BOOL Jaq_StartSeq(u32 param_1)
{
seqp_* track;
u8* lbzu;
if (param_1 == -1) {
return FALSE;
}
track = rootseq[param_1];
if (!track) {
return FALSE;
};
// This feels like a fakematch, but oh well.
switch (*(lbzu = &track->trackState)) {
case 0:
return FALSE;
case 1:
return FALSE;
case 3:
return FALSE;
case 2:
*lbzu = 1;
}
Jac_RegisterDspPlayerCallback(&Jaq_RootCallback, rootseq[param_1]);
return TRUE;
}
/* Flags bit layout (u32):
* -----------------------
* Bits 0-3 : Index Selector (0 to 15)
* Bit 5 : Direct Register Read Flag
* - If set, index is read from hardware register
* - Forces mode to 4
* Bits 6-7 : Mode Flags (0 to 3)
*/
/*
* --INFO--
* Address: 80014780
* Size: 00014C
*/
s32 Jaq_OpenTrack(seqp_* track, u32 flags, u32 source)
{
seqp_* oldChildTrack;
seqp_* newChildTrack;
u8 childIndex;
u8 trackFlags;
u8* REF_index;
childIndex = (flags & 0b00001111);
trackFlags = (flags & 0b11000000) >> 6;
if ((flags & 0b00100000)) {
trackFlags = 4;
}
if ((u8)(flags & 0b00100000)) { // This u8 cast is a repeating pattern across JAudio... Mysterious.
childIndex = Jam_ReadRegDirect(track, childIndex);
}
REF_index = &childIndex;
if (childIndex >= 16) {
return -1;
}
oldChildTrack = track->children[childIndex];
if (oldChildTrack) {
Jaq_CloseTrack(oldChildTrack);
}
newChildTrack = GetNewTrack();
if (!newChildTrack) {
return -1;
}
track->children[childIndex] = newChildTrack;
newChildTrack->trackId = ((track->trackId << 4 | childIndex) & 0xFFFFFFF) | ((track->trackId & 0xF0000000) + 0x10000000);
newChildTrack->connectionId = 0;
newChildTrack->dataSourceMode = track->dataSourceMode;
newChildTrack->flags = trackFlags;
Init_Track(newChildTrack, source, track);
// Dev rolls "worst bit extraction method", asked to leave Nintendo EAD.
newChildTrack->isMuted = newChildTrack->parent->isMuted | ((newChildTrack->parent->childMuteMask & (1 << childIndex)) >> childIndex);
newChildTrack->outerParams = newChildTrack->parent->childOuterParams[childIndex];
if (newChildTrack->outerParams) {
++newChildTrack->outerParams->refCount;
}
Init_1shot(&newChildTrack->parentController, 0);
Jam_UpdateTrackAll(newChildTrack);
return 0;
}
/*
* --INFO--
* Address: 800148E0
* Size: 0000B4
*/
void __AllNoteOff(seqp_* track)
{
u32 i;
if (!track->parent) {
for (i = 0; i < 8; ++i) {
NoteOFF_R(track, i, 10);
track->_94[i] = -1;
track->channels[i] = NULL;
}
} else {
for (i = 0; i < 8; ++i) {
NoteOFF(track, i);
track->_94[i] = -1;
track->channels[i] = NULL;
}
}
}
/*
* --INFO--
* Address: 800149A0
* Size: 000120
*/
u32 Jaq_CloseTrack(seqp_* track)
{
size_t i;
// Specifically two separate conditional blocks, because why not.
if (!track) {
return 0;
}
if (track->trackState == 0) {
return 0;
}
__AllNoteOff(track);
BackTrack(track);
for (i = 0; i < 16; ++i) {
if (track->children[i]) {
Jaq_CloseTrack(track->children[i]);
track->children[i] = NULL;
}
}
if (track->outerParams) {
// This smells like refcounting.
track->outerParams->refCount -= 1;
track->outerParams = NULL;
}
for (i = 0; i < 16; ++i) {
if (track->childOuterParams[i]) {
track->childOuterParams[i]->isAssigned = FALSE;
track->childOuterParams[i] = NULL;
}
}
track->isMuted = 0;
track->childMuteMask = 0;
if (track->parent) {
FixMoveChannelAll(&track->parentController, &track->parent->parentController);
} else {
FixReleaseChannelAll(&track->parentController);
}
Jam_UnRegistTrack(track);
return 0;
}
/*
* --INFO--
* Address: 80014AC0
* Size: 0000E8
*
* Note: While this function accepts `void*`, it really expects `seqp_*`.
*/
static s32 Jaq_RootCallback(void* VOID_track)
{
seqp_* track;
track = (seqp_*)VOID_track;
if (track && track->trackState != 0) {
if (track->trackState == 3) {
__StopSeq(track);
return -1;
}
track->tempoAccumulator += track->tempoFactor;
if (track->tempoAccumulator < 1.0f) {
SeqUpdate(track, 0);
} else {
while (track->tempoAccumulator >= 1.0f) {
track->tempoAccumulator -= 1.0f;
if (Jam_SeqmainNote(track, 0) == -1) {
__StopSeq(track);
return -1;
}
}
SeqUpdate(track, 0);
}
} else {
return -1;
}
return 0;
}
+20
View File
@@ -0,0 +1,20 @@
#include "jaudio_NES/tables.h"
// TODO: This is probably some curve that can be expressed in better terms than a bunch of constant values copied from the DOL.
f32 C5BASE_PITCHTABLE[C5BASE_PITCHTABLE_LENGTH] = {
0.031250000f, 0.033108000f, 0.035076998f, 0.037161998f, 0.039372000f, 0.041712999f, 0.044194000f, 0.046822000f, 0.049605999f,
0.052556000f, 0.055681000f, 0.058991998f, 0.062500000f, 0.066215999f, 0.070153996f, 0.074325000f, 0.078745000f, 0.083426997f,
0.088388000f, 0.093644000f, 0.099212997f, 0.105112000f, 0.111362000f, 0.117984000f, 0.125000000f, 0.132433000f, 0.140307990f,
0.148651000f, 0.157490000f, 0.166855000f, 0.176777000f, 0.187288000f, 0.198424990f, 0.210224000f, 0.222725000f, 0.235969000f,
0.250000000f, 0.264865990f, 0.280615990f, 0.297302000f, 0.314980000f, 0.333710000f, 0.353553000f, 0.374576990f, 0.396849990f,
0.420448000f, 0.445448990f, 0.471937000f, 0.500000000f, 0.529731990f, 0.561231000f, 0.594604000f, 0.629961000f, 0.667420000f,
0.707107000f, 0.749153970f, 0.793700990f, 0.840897000f, 0.890899000f, 0.943875000f, 1.000000000f, 1.059463000f, 1.122462000f,
1.189207000f, 1.259921000f, 1.334840000f, 1.414214000f, 1.498307000f, 1.587401000f, 1.681793000f, 1.781798000f, 1.887749000f,
2.000000000f, 2.118926000f, 2.244924000f, 2.378413900f, 2.519841900f, 2.669680000f, 2.828428000f, 2.996614900f, 3.174803000f,
3.363585900f, 3.563596000f, 3.775497900f, 4.000000000f, 4.237853000f, 4.489849000f, 4.756828800f, 5.039684800f, 5.339360000f,
5.656855000f, 5.993228900f, 6.349606000f, 6.727172900f, 7.127192000f, 7.550995800f, 8.000000000f, 8.475705000f, 8.979697000f,
9.513657600f, 10.07937000f, 10.67872000f, 11.31371000f, 11.98645900f, 12.69921100f, 13.45434600f, 14.25438300f, 15.10199300f,
16.00000000f, 16.95141000f, 17.95939400f, 19.02731500f, 20.15873900f, 21.35744000f, 22.62742000f, 23.97291800f, 25.39842200f,
26.90869100f, 28.50876600f, 30.20398500f, 32.00000000f, 33.90282000f, 35.91878900f, 38.05463000f, 40.31747800f, 42.71488000f,
45.25484000f, 47.94583500f,
};
+261
View File
@@ -0,0 +1,261 @@
#include "jaudio_NES/waveread.h"
#include "jaudio_NES/connect.h"
#include "jaudio_NES/heapctrl.h"
#include "jaudio_NES/bx.h"
#define WAVEARC_SIZE (0x100)
#define WAVEGROUP_SIZE (0x100)
static WaveArchiveBank_* wavearc[WAVEARC_SIZE];
static CtrlGroup_* wavegroup[WAVEGROUP_SIZE];
CtrlGroup_* CGRP_ARRAY[16];
/*
* --INFO--
* Address: 8000C200
* Size: 000038
*/
static void PTconvert(void** pointer, u32 base_address)
{
if (*pointer == NULL) {
*pointer = NULL;
return;
}
if (*pointer >= (void*)base_address || *pointer == NULL) {
return;
}
*pointer = *(char**)pointer + base_address;
}
/*
* --INFO--
* Address: 8000C240
* Size: 0002A0
*/
CtrlGroup_* Wave_Test(u8* data)
{
u32 i, j;
u32 base_addr = (u32)data;
WaveArchiveBank_* arcBank;
CtrlGroup_* group;
WaveArchive_* arc;
WaveArchive_** REF_arc;
SCNE_* scene;
Ctrl_* cdf;
Ctrl_* cex;
Ctrl_* cst;
PTconvert((void**)&((Wsys_*)data)->waveArcBank, base_addr);
PTconvert((void**)&((Wsys_*)data)->ctrlGroup, base_addr);
arcBank = *(WaveArchiveBank_**)(data + 0x10);
group = *(CtrlGroup_**)(data + 0x14);
CGRP_ARRAY[0] = group;
if (arcBank->magic != 'WINF') {
return NULL;
}
if (group->magic != 'WBCT') {
return NULL;
}
for (i = 0; i < arcBank->count; i++) {
PTconvert((void**)&arcBank->waveGroups[i], base_addr);
arc = arcBank->waveGroups[i];
REF_arc = &arc;
Jac_InitHeap(&arc->heap);
arc->heap.startAddress = 0;
for (j = 0; j < arc->waveCount; j++) {
PTconvert((void**)&arc->waves[j], base_addr);
}
}
for (i = 0; i < group->count; i++) {
PTconvert((void**)&group->scenes[i], base_addr);
scene = group->scenes[i];
PTconvert((void**)&scene->cdf, base_addr);
PTconvert((void**)&scene->cex, base_addr);
PTconvert((void**)&scene->cst, base_addr);
cdf = scene->cdf;
if (cdf && cdf->magic == 'C-DF') {
for (j = 0; j < cdf->count; j++) {
PTconvert((void**)&cdf->waveIDs[j], base_addr);
Jac_InitHeap(&cdf->waveIDs[j]->heap);
cdf->waveIDs[j]->heap.startAddress = 0;
}
}
cex = scene->cex;
if (cex && cex->magic == 'C-EX') {
for (j = 0; j < cex->count; j++) {
PTconvert((void**)&cex->waveIDs[j], base_addr);
Jac_InitHeap(&cex->waveIDs[j]->heap);
cex->waveIDs[j]->heap.startAddress = 0;
}
}
cst = scene->cst;
if (cst && cst->magic == 'C-ST') {
for (j = 0; j < cst->count; j++) {
PTconvert((void**)&cst->waveIDs[j], base_addr);
Jac_InitHeap(&cst->waveIDs[j]->heap);
cst->waveIDs[j]->heap.startAddress = 0;
}
}
}
return CGRP_ARRAY[0];
}
/*
* --INFO--
* Address: ........
* Size: 000030
*/
void GetSound_Test(u32 id)
{
// UNUSED FUNCTION
}
/*
* --INFO--
* Address: 8000C4E0
* Size: 000084
*/
BOOL Wavegroup_Regist(void* wsysData, u32 id)
{
Wsys_* wsys = (Wsys_*)wsysData;
Jac_WsConnectTableSet(wsys->globalID, id);
wavegroup[id] = Wave_Test((u8*)wsys);
wavearc[id] = wsys->waveArcBank;
if (wavegroup[id] == NULL) {
return FALSE;
}
wavegroup[id]->_04 = 0;
return TRUE;
}
/*
* --INFO--
* Address: 8000C580
* Size: 00002C
*/
void Wavegroup_Init()
{
for (int i = 0; i < WAVEGROUP_SIZE; ++i) {
wavegroup[i] = NULL;
}
}
/*
* --INFO--
* Address: 8000C5C0
* Size: 000064
*/
CtrlGroup_* WaveidToWavegroup(u32 param_1, u32 param_2)
{
u16 virtID = param_1 >> 16;
u16 index;
u16* REF_virtID = &virtID;
if (virtID == 0xFFFF) {
index = param_2;
} else {
index = Jac_WsVirtualToPhysical(virtID);
}
return index >= WAVEGROUP_SIZE ? NULL : wavegroup[index];
}
/*
* --INFO--
* Address: 8000C640
* Size: 00008C
*/
static BOOL __WaveScene_Set(u32 waveIndex, u32 ctrlIndex, BOOL doSet)
{
u32* REF_param_1;
u32* REF_param_2;
CtrlGroup_* group;
REF_param_1 = &waveIndex;
if (waveIndex >= WAVEGROUP_SIZE) {
return FALSE;
}
if (!(group = wavegroup[waveIndex])) {
return FALSE;
}
REF_param_2 = &ctrlIndex;
if (ctrlIndex >= group->count) {
return FALSE;
}
return Jac_SceneSet(wavearc[waveIndex], group, ctrlIndex, doSet);
}
/*
* --INFO--
* Address: 8000C6E0
* Size: 000024
*/
BOOL WaveScene_Set(u32 waveIndex, u32 ctrlIndex)
{
return __WaveScene_Set(waveIndex, ctrlIndex, TRUE);
}
/*
* --INFO--
* Address: 8000C720
* Size: 000024
*/
BOOL WaveScene_Load(u32 waveIndex, u32 ctrlIndex)
{
return __WaveScene_Set(waveIndex, ctrlIndex, FALSE);
}
/*
* --INFO--
* Address: 8000C760
* Size: 000074
*/
static void __WaveScene_Close(u32 waveIndex, u32 ctrlIndex, BOOL param_3)
{
u32* REF_param_1;
u32* REF_param_2;
CtrlGroup_* group;
REF_param_1 = &waveIndex;
if (waveIndex >= WAVEGROUP_SIZE) {
return;
}
if (group = wavegroup[waveIndex]) {
REF_param_2 = &ctrlIndex;
if (ctrlIndex < group->count) {
Jac_SceneClose(wavearc[waveIndex], group, ctrlIndex, param_3);
}
}
}
/*
* --INFO--
* Address: 8000C7E0
* Size: 000024
*/
void WaveScene_Close(u32 waveIndex, u32 ctrlIndex)
{
__WaveScene_Close(waveIndex, ctrlIndex, TRUE);
}
/*
* --INFO--
* Address: 8000C820
* Size: 000024
*/
void WaveScene_Erase(u32 waveIndex, u32 ctrlIndex)
{
__WaveScene_Close(waveIndex, ctrlIndex, FALSE);
}
+1
View File
@@ -1,6 +1,7 @@
#include "libforest/emu64/emu64.hpp"
#include "libforest/emu64.h"
// #include "MSL_C/w_math.h"
#include "libultra/libultra.h"
#include "terminal.h"
#include "boot.h"