aisetnextbuf.c OK (code_80194790.c) (#982)

* aisetnextbuf OK

* format

* Function headers

* Add comment
This commit is contained in:
engineer124 2022-08-09 20:49:20 -04:00 committed by GitHub
parent f4f0ce7523
commit d9a10948d3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 113 additions and 25 deletions

View File

@ -3149,9 +3149,7 @@ u32 Audio_NextRandom(void);
void Audio_InitMesgQueues(void);
void Audio_InvalDCache(void* buf, size_t size);
void Audio_WritebackDCache(void* buf, size_t size);
// void func_80194790(void);
// void func_80194840(void);
// void func_801948B0(void);
s32 osAiSetNextBuffer(void* buf, u32 size);
void AudioPlayback_NoteDisable(Note* note);
void AudioPlayback_ProcessNotes(void);
SoundFontSound* AudioPlayback_InstrumentGetSound(Instrument* instrument, s32 semitone);

View File

@ -1582,13 +1582,6 @@ extern s32 gAudioContextInitalized;
// extern UNK_TYPE1 D_801D5FF8;
// extern UNK_TYPE4 D_801D5FFC;
extern UNK_PTR D_801D6000;
// extern UNK_TYPE1 D_801D6010;
// extern UNK_TYPE1 D_801D6014;
// extern UNK_TYPE1 D_801D6028;
// extern UNK_TYPE1 D_801D6098;
// extern UNK_TYPE1 D_801D6100;
extern UNK_PTR D_801D6188;
extern UNK_PTR D_801D618C;
// extern UNK_TYPE4 D_801D6190;
// extern UNK_TYPE4 D_801D6194;
// extern UNK_TYPE1 D_801D6200;

3
spec
View File

@ -614,8 +614,7 @@ beginseg
include "build/src/code/audio/code_80192BE0.o"
include "build/data/code/code_80192BE0.data.o"
include "build/src/code/audio/audio_dcache.o"
include "build/src/code/audio/code_80194790.o"
include "build/data/code/code_80194790.data.o"
include "build/src/code/audio/aisetnextbuf.o"
include "build/src/code/audio/audio_playback.o"
include "build/src/code/audio/audio_effects.o"
include "build/src/code/audio/audio_seqplayer.o"

View File

@ -0,0 +1,107 @@
#include "global.h"
//! Note that this is not the same as the original libultra
//! osAiSetNextBuffer, see comments in the function
s32 osAiSetNextBuffer(void* buf, u32 size) {
static u8 D_801D6010 = false;
u32 bufAdjusted = (u32)buf;
s32 status;
if (D_801D6010) {
bufAdjusted = (u32)buf - 0x2000;
}
if ((((u32)buf + size) & 0x1FFF) == 0) {
D_801D6010 = true;
} else {
D_801D6010 = false;
}
// Originally a call to __osAiDeviceBusy
status = HW_REG(AI_STATUS_REG, s32);
if (status & AI_STATUS_AI_FULL) {
return -1;
}
// OS_K0_TO_PHYSICAL replaces osVirtualToPhysical, this replacement
// assumes that only KSEG0 addresses are given
HW_REG(AI_DRAM_ADDR_REG, u32) = OS_K0_TO_PHYSICAL(bufAdjusted);
HW_REG(AI_LEN_REG, u32) = size;
return 0;
}
//! Note that the remaining data and functions are unused and not part of the
//! original libultra osAiSetNextBuffer
s16 D_801D6014[] = {
19720, 18360, 17680, 16320, 14960, 13600, 12240, 10880, 9520, 0,
};
s8 D_801D6028[7][16] = {
{ 0, 1, 2, 2, 1, 3, 4, 5, 6, 7, 8, 7, 6, 5, 4, 3 }, { 0, 1, 2, 3, 3, 2, 1, 4, 5, 6, 7, 8, 7, 6, 5, 4 },
{ 0, 1, 2, 3, 4, 4, 3, 2, 1, 5, 6, 7, 8, 7, 6, 5 }, { 0, 1, 2, 3, 4, 5, 5, 4, 3, 2, 1, 6, 7, 8, 7, 6 },
{ 0, 1, 2, 3, 4, 5, 6, 6, 5, 4, 3, 2, 1, 7, 8, 7 }, { 0, 1, 2, 3, 4, 5, 6, 7, 7, 6, 5, 4, 3, 2, 1, 8 },
{ 0, 1, 2, 3, 4, 5, 6, 7, 8, 7, 6, 5, 4, 3, 2, 1 },
};
s16 D_801D6098[7][17] = {
{ 0, 268, 560, 834, 1126, 1418, 1692, 1966, 2240, 2514, 2718, 2922, 3196, 3470, 3744, 4018, 4292 },
{ 0, 268, 560, 834, 1108, 1382, 1674, 1966, 2240, 2514, 2788, 2992, 3196, 3470, 3744, 4018, 4292 },
{ 0, 268, 560, 834, 1108, 1382, 1656, 1930, 2222, 2514, 2788, 3062, 3266, 3470, 3744, 4018, 4292 },
{ 0, 268, 560, 834, 1108, 1382, 1656, 1930, 2204, 2478, 2770, 3062, 3336, 3540, 3744, 4018, 4292 },
{ 0, 268, 560, 834, 1108, 1382, 1656, 1930, 2222, 2514, 2752, 3026, 3318, 3610, 3814, 4018, 4292 },
{ 0, 268, 560, 834, 1108, 1382, 1656, 1930, 2134, 2408, 2682, 2956, 3230, 3504, 3796, 4088, 4292 },
{ 0, 268, 560, 834, 1108, 1382, 1656, 1930, 2134, 2338, 2612, 2886, 3163, 3434, 3708, 4000, 4292 },
};
s16* D_801D6188 = D_801D6098[0];
s8* D_801D618C = D_801D6028[0];
// Unused
void func_80194804(s32 index) {
D_801D6188 = D_801D6098[index];
D_801D618C = D_801D6028[index];
}
// Only used below
s16 func_80194840(s32 arg0) {
s32 i;
s32 j = 0;
for (i = 1; i < 16; i++) {
if (arg0 < D_801D6188[i]) {
break;
}
j++;
}
if (i == 16) {
return 0;
} else {
j = D_801D618C[j];
return D_801D6014[j];
}
}
// Unused
s32 func_801948B0(s32* arg0, s32* arg1) {
s32 temp_v0;
s32 phi_s0 = *arg0;
s32 phi_s1 = *arg1;
while (true) {
temp_v0 = func_80194840(phi_s0);
if (temp_v0 == 0) {
return -1;
}
if (phi_s1 < temp_v0) {
break;
}
phi_s1 -= temp_v0;
phi_s0++;
}
*arg0 = phi_s0;
*arg1 = phi_s1;
return 0;
}

View File

@ -1,9 +0,0 @@
#include "global.h"
#pragma GLOBAL_ASM("asm/non_matchings/code/code_80194790/func_80194790.s")
#pragma GLOBAL_ASM("asm/non_matchings/code/code_80194790/func_80194804.s")
#pragma GLOBAL_ASM("asm/non_matchings/code/code_80194790/func_80194840.s")
#pragma GLOBAL_ASM("asm/non_matchings/code/code_80194790/func_801948B0.s")

View File

@ -484,7 +484,7 @@
0x8018EB60 : "audio_load",
0x80192BE0 : "code_80192BE0",
0x80194710 : "audio_dcache",
0x80194790 : "code_80194790",
0x80194790 : "aisetnextbuf",
0x80194930 : "audio_playback",
0x80196A00 : "audio_effects",
0x801974D0 : "audio_seqplayer",
@ -587,7 +587,7 @@
0x801D5FB0 : "audio_synthesis",
0x801D5FE0 : "audio_load",
0x801D5FF0 : "code_80192BE0",
0x801D6010 : "code_80194790",
0x801D6010 : "aisetnextbuf",
0x801D6190 : "audio_effects",
0x801D61A0 : "audio_seqplayer",
0x801D6200 : "audio_dramStack",

View File

@ -3722,7 +3722,7 @@
0x801946E4:("Audio_InitMesgQueues",),
0x80194710:("Audio_InvalDCache",),
0x80194750:("Audio_WritebackDCache",),
0x80194790:("func_80194790",),
0x80194790:("osAiSetNextBuffer",),
0x80194804:("func_80194804",),
0x80194840:("func_80194840",),
0x801948B0:("func_801948B0",),

View File

@ -3238,7 +3238,7 @@ asm/non_matchings/code/code_80192BE0/Audio_NextRandom.s,Audio_NextRandom,0x80194
asm/non_matchings/code/code_80192BE0/Audio_InitMesgQueues.s,Audio_InitMesgQueues,0x801946E4,0xB
asm/non_matchings/code/code_80194710/Audio_InvalDCache.s,Audio_InvalDCache,0x80194710,0x10
asm/non_matchings/code/code_80194710/Audio_WritebackDCache.s,Audio_WritebackDCache,0x80194750,0x10
asm/non_matchings/code/code_80194710/func_80194790.s,func_80194790,0x80194790,0x1D
asm/non_matchings/code/code_80194710/osAiSetNextBuffer.s,osAiSetNextBuffer,0x80194790,0x1D
asm/non_matchings/code/code_80194710/func_80194804.s,func_80194804,0x80194804,0xF
asm/non_matchings/code/code_80194710/func_80194840.s,func_80194840,0x80194840,0x1C
asm/non_matchings/code/code_80194710/func_801948B0.s,func_801948B0,0x801948B0,0x20

1 asm/non_matchings/code/z_en_a_keep/EnAObj_Init.s EnAObj_Init 0x800A5AC0 0x2B
3238 asm/non_matchings/code/code_80192BE0/Audio_InitMesgQueues.s Audio_InitMesgQueues 0x801946E4 0xB
3239 asm/non_matchings/code/code_80194710/Audio_InvalDCache.s Audio_InvalDCache 0x80194710 0x10
3240 asm/non_matchings/code/code_80194710/Audio_WritebackDCache.s Audio_WritebackDCache 0x80194750 0x10
3241 asm/non_matchings/code/code_80194710/func_80194790.s asm/non_matchings/code/code_80194710/osAiSetNextBuffer.s func_80194790 osAiSetNextBuffer 0x80194790 0x1D
3242 asm/non_matchings/code/code_80194710/func_80194804.s func_80194804 0x80194804 0xF
3243 asm/non_matchings/code/code_80194710/func_80194840.s func_80194840 0x80194840 0x1C
3244 asm/non_matchings/code/code_80194710/func_801948B0.s func_801948B0 0x801948B0 0x20