The first commit

This commit is contained in:
Banjo Kazooie
2022-07-15 17:09:41 -05:00
commit dd13d34074
1087 changed files with 391897 additions and 0 deletions

View File

@@ -0,0 +1,7 @@
#include <ultra64.h>
#include "n_synth.h"
//see libultre src/audio/load.c
#pragma GLOBAL_ASM("asm/nonmatchings/core1/audio/n_adpcm/_n_decodeChunk.s")
#pragma GLOBAL_ASM("asm/nonmatchings/core1/audio/n_adpcm/n_alAdpcmPull.s")

View File

@@ -0,0 +1,20 @@
#include <ultra64.h>
#include "functions.h"
#include "variables.h"
#pragma GLOBAL_ASM("asm/nonmatchings/core1/audio/n_csplayer/func_8025D7C0.s")
#pragma GLOBAL_ASM("asm/nonmatchings/core1/audio/n_csplayer/func_8025D830.s")
#pragma GLOBAL_ASM("asm/nonmatchings/core1/audio/n_csplayer/func_8025D838.s")
#pragma GLOBAL_ASM("asm/nonmatchings/core1/audio/n_csplayer/func_8025D840.s")
#pragma GLOBAL_ASM("asm/nonmatchings/core1/audio/n_csplayer/func_8025DA30.s")
#pragma GLOBAL_ASM("asm/nonmatchings/core1/audio/n_csplayer/func_8025E430.s")
#pragma GLOBAL_ASM("asm/nonmatchings/core1/audio/n_csplayer/__n_CSPVoiceHandler.s")
#pragma GLOBAL_ASM("asm/nonmatchings/core1/audio/n_csplayer/n_alCSPNew.s")

224
src/core1/code_0.c Normal file
View File

@@ -0,0 +1,224 @@
#include <ultra64.h>
#include "functions.h"
#include "variables.h"
#include "gc/gctransition.h"
void func_8023E00C(s32);
void func_8023DFF0(s32);
extern s32 D_80275610;
extern u32 D_80275618;
/* .bss */
u32 D_8027A130;
u8 pad_8027A138[0x400];
u64 D_8027A538;
u8 pad_8027A540[0x17F8];
OSThread D_8027BD38;
s32 D_8027BEE8;
s32 D_8027BEEC;
u64 D_8027BEF0;
extern u8 D_80286F90;
extern u8 D_803A5D00[2][0x1ECC0];
void func_8023DA20(s32 arg0){
bzero(&D_8027A130, &D_80286F90 - (u8*)&D_8027A130);
osWriteBackDCacheAll();
sns_find_and_parse_payload();
osInitialize();
func_80240BE0();
}
void func_8023DA74(void){
func_8033BD6C();
func_80255198(); //heap_flush_free_queue
}
void func_8023DA9C(s32 arg0){
func_80254008();
func_8024C428();
if (D_8027A130 == 4){
func_802E3580();
}
if (D_8027A130 == 3){
func_802E4170();
}
func_8023DA74();
D_8027A130 = arg0;
if (D_8027A130 == 3){
func_802E4214(D_8027BEE8);
}
if (D_8027A130 == 4){
func_802E35D0();
}
func_80255CD8();
}
u32 func_8023DB4C(u32 arg0){
return D_80275618 & arg0;
}
s32 func_8023DB5C(void){
return D_80275618;
}
void func_8023DB68(void){
D_80275618 = 0;
}
s32 func_8023DB74(void){
return (DEBUG_use_special_bootmap())? MAP_80_GL_FF_ENTRANCE : MAP_91_FILE_SELECT;
}
s32 func_8023DBA4(void){
return MAP_1F_CS_START_RAREWARE;
}
void func_8023DBAC(void){
func_8023E00C(func_8023DBA4());
func_8023DFF0(3);
}
void func_8023DBDC(void){
func_8023E00C(func_8023DB74());
func_8023DFF0(3);
}
void func_8023DC0C(void){
func_80255C30();
func_8023E00C(func_8023DBA4());
rarezip_init(); //initialize decompressor's huft table
func_8024BE30();
func_80251308();
D_8027BEF0 = D_8027A538;
heap_init();
func_80254028();
func_8025AFB0();
func_8033EF58();
func_8033BB84();
func_8024F05C();
func_80250C84();
func_8023FB1C();
func_8025425C();
func_80257424();
gctransition_reset();
D_8027A130 = 0;
D_80275618 = 0;
func_8023DA9C(3);
}
void func_8023DCDC(void){
D_80275618++;
}
void func_8023DCF4(void){
D_80275618--;
}
#ifndef NOMATCHING
#pragma GLOBAL_ASM("asm/nonmatchings/core1/code_0/func_8023DD0C.s")
#else
void func_8023DD0C(void){
s32 x;
s32 y;
s32 r;
s32 g;
s32 b;
if((func_8023DB5C() & 0x7f) == 0x11)
sns_write_payload_over_heap();
func_8023DA74();
if(D_8027A130 != 3 || getGameMode() != GAME_MODE_4_PAUSED)
func_8023DCDC();
if(!D_8027BEEC)
func_8024E7C8();
D_8027BEEC = 0;
func_80250C08();
if(!mapSpecificFlags_validateCRC1()){
write_file_blocks(0, 0, 0x80397AD0, 0x40);
}
switch(D_8027A130){
case 4:
func_802E35D8();
break;
case 3:
func_80255524();
func_80255ACC();
func_802C3A18();
if(func_802E4424())
func_802E3F8C(0);
func_802C3A38();
break;
}//L8023DE34
if(D_80275610){
func_8023DA9C(D_80275610 - 1);
D_80275610 = 0;
}//L8023DE54
if( !func_8032056C()
|| !levelSpecificFlags_validateCRC1()
|| !func_80320240()
){
//render weird CRC failure image
for(x= 0x1e; x< D_8027658C - 0x1e; x++){//L8023DEB4
for(y = 0x14; y < 0xeb; y++){
b = ((func_8023DB5C() << 3) + y*y + x*x) >> 3;
g = x >> 3;
r = y >> 3;
*(u16*)&D_803A5D00[1][((D_80276588 - 0xff)/2 + y + x*D_80276588)*2] =
*(u16*)&D_803A5D00[0][((D_80276588 - 0xff)/2 + y + x*D_80276588)*2] =
_SHIFTL(b, 1, 5)
| _SHIFTL(g, 6, 5)
| _SHIFTL(r, 11, 5)
| _SHIFTL(1, 0, 1 )
;
}
}
}//L8023DF70
}
#endif
void func_8023DF9C(void *arg0){
func_8023DC0C();
sns_write_payload_over_heap();
while(1){ //main loop
func_8023DD0C();
}
}
void func_8023DFF0(s32 arg0){
D_80275610 = arg0 + 1;
}
s32 func_8023E000(void){
return D_8027A130;
}
void func_8023E00C(s32 arg0){
D_8027BEE8 = arg0;
}
void func_8023E018(void){
// 5th argument should be a pointer to the end of an array, but the start is unknown
// D_8027A538 is not the right symbol, but the end of the array is the important port and this is the closest symbol currently
osCreateThread(&D_8027BD38, 6, func_8023DF9C, NULL, ((u8*)&D_8027A538) + 0x1800, 0x14);
}
OSThread *func_8023E060(void){
return &D_8027BD38;
}
void func_8023E06C(void){
D_8027BEEC = 1;
}

498
src/core1/code_11AC0.c Normal file
View File

@@ -0,0 +1,498 @@
#include <ultra64.h>
#include "functions.h"
#include "variables.h"
#include "music.h"
extern void func_8025F570(ALCSPlayer *, u8);
extern void func_8025F510(ALCSPlayer *, u8, u8);
extern void func_8025F5C0(ALCSPlayer *, u8);
extern ALBankFile D_EA3EB0;
extern ALWaveTable D_EADE60;
/* dependent functions */
void func_8024FA98(u8, enum comusic_e);
void func_8024FD28(u8, s16);
int func_80250074(u8);
u8 func_8025F4A0(ALCSPlayer *, u8);
void func_8025F3F0(ALCSPlayer *, f32, f32);
u16 func_80250474(s32 arg0);
void func_8024AF48(void);
void func_8024FB8C(void);
/* .data */
extern MusicTrackMeta D_80275D40[0xB0];
extern s32 D_802762C0;
extern s32 D_802762C4;
/* .rodata */
extern f32 D_80278180;
extern f32 D_80278184;
/* .data */
MusicTrack D_80281720[6];
MusicTrack **D_802820E0;
ALSeqpConfig D_802820E8;
u16 D_80282104; //called as u16 someplaces and s16 others
ALBank * D_80282108;
structBs D_80282110[0x20];
/* .rodata */
/* .code */
void func_8024F4E0(void){
s32 size;
ALBankFile * bnk_f; //sp38
s32 i;
f32 tmpf1;
size = (u8*)&D_EADE60 - (u8*)&D_EA3EB0;
bnk_f = malloc(size);
osWriteBackDCacheAll();
osPiStartDma(func_802405D0(), 0, 0, &D_EA3EB0, bnk_f, size, func_802405C4());
osRecvMesg(func_802405C4(), 0, 1); //osRecvMesg
D_80282104 = 0xAD;
D_802820E0 = (MusicTrack **) malloc(D_80282104 * sizeof(MusicTrack *));
for(i = 0; i < D_80282104; i++){
D_802820E0[i] = NULL;
}
D_802820E8.maxVoices = 0x18;
D_802820E8.maxEvents = 0x55;
D_802820E8.maxChannels = 0x10;
D_802820E8.heap = func_802405B8();
D_802820E8.initOsc = NULL;
D_802820E8.updateOsc = NULL;
D_802820E8.stopOsc = NULL;
func_8023FA64(&D_802820E8);
for(i = 0; i < 6; i++){
n_alCSPNew(&D_80281720[i].cseqp, &D_802820E8); //alCSPNew
}
alBnkfNew(bnk_f, (u8 *)&D_EADE60);
D_80282108 = bnk_f->bankArray[0];
for(i = 0; i < 6; i++){
alCSPSetBank(&D_80281720[i].cseqp, D_80282108);
}
for(i = 0; i < 6; i++){
D_80281720[i].unk2 = 0;
D_80281720[i].unk3 = 0;
D_80281720[i].index_cpy = 0;
D_80281720[i].unk17C = 0.0f;
D_80281720[i].unk180 = 1.0f;
}
func_8024FB8C();
}
ALBank *func_8024F758(void){
return D_80282108;
}
void func_8024F764(s32 arg0){//music track load
if(D_802820E0[arg0] == NULL){
func_8033B788();
D_802820E0[arg0] = assetcache_get(arg0 + 0x1516);
}
}
void func_8024F7C4(s32 arg0){
s32 i;
if(D_802820E0[arg0] != NULL){
i = 0;
for(i = 0; i != 6; i++){
if(D_80281720[i].index == arg0)
return;
}
assetcache_release(D_802820E0[arg0]);
D_802820E0[arg0] = 0;
}
}
void func_8024F83C(void){
s32 i;
for(i = 0; i < D_80282104; i++){
func_8024F7C4(i);
}
}
void func_8024F890(u8 arg0, enum comusic_e arg1){
s32 i;
if(arg1 == -1){
if(arg1 != D_80281720[arg0].index)
alCSPStop(&D_80281720[arg0].cseqp);
D_80281720[arg0].index = arg1;
}
else{
if(-1 != D_80281720[arg0].index){
func_8024F890(arg0, -1);
}
D_80281720[arg0].unk2 = 0;
D_80281720[arg0].unk3 = 0;
D_80281720[arg0].index = arg1;
for(i = 0; i < 0xe; i++){
D_80281720[arg0].unk184[i] = 0;
D_80281720[arg0].unk192[i] = 0;
}
func_8024F764(D_80281720[arg0].index);
n_alCSeqNew(&D_80281720[arg0].cseq, D_802820E0[D_80281720[arg0].index]);
D_80281720[arg0].cseqp.chanMask = func_80250474(arg0);
alCSPSetSeq(&D_80281720[arg0].cseqp, &D_80281720[arg0].cseq);
alCSPPlay(&D_80281720[arg0].cseqp);
alCSPSetVol(&D_80281720[arg0].cseqp, D_80281720[arg0].unk0);
if(player_is_present() && func_8028EE84() == BSWATERGROUP_2_UNDERWATER){
func_8025F3F0(&D_80281720[arg0].cseqp, 0.0f, 1.0f);
}
else{
func_8025F3F0(&D_80281720[arg0].cseqp, D_80281720[arg0].unk17C, D_80281720[arg0].unk180);
}
}
}
s32 func_8024FA6C(u8 arg0){
return D_80281720[arg0].index;
}
void func_8024FA98(u8 arg0, enum comusic_e arg1){
s32 sp2C;
s32 sp24;
volatile s64 sp20;
sp2C = D_80281720[arg0].index;
if(arg1 == sp2C || sp2C == -1){
func_8024F890(arg0, arg1);
}else{
func_8024F890(arg0, -1);
sp20 = osGetTime();
while(D_80281720[arg0].cseqp.state != AL_STOPPED){
osGetTime();
};
func_8024F7C4(sp2C);
func_8024F890(arg0, arg1);
}
}
s32 func_8024FB60(u8 arg0){
return D_80281720[arg0].cseqp.state;
}
void func_8024FB8C(void){
s32 i, allStopped;
volatile s64 sp2C;
for(i = 0; i < 6; i++){
func_8024F890(i,-1);
}
sp2C = osGetTime();
do{
allStopped = 0;
for(i = 0; i < 6; i++){
if(func_8024FB60(i) != AL_STOPPED)
allStopped++;
}
osGetTime();
}while(allStopped);
}
void func_8024FC1C(u8 arg0, enum comusic_e arg1){
D_80281720[arg0].index_cpy = arg1;
D_80281720[arg0].unk2 = 1;
D_80281720[arg0].unk3 = 0;
D_80281720[arg0].unk0 = D_80275D40[arg1].unk4;
}
void func_8024FC6C(u8 arg0){
s32 indx;
indx = D_80281720[arg0].index;
if(indx == 0x2D || indx == 0x3D){
D_80281720[arg0].unk2 = 1;
D_80281720[arg0].unk3 = 0;
D_80281720[arg0].index_cpy = D_80281720[arg0].index;
}else{
D_80281720[arg0].index_cpy = -1;
D_80281720[arg0].unk3 = 1;
D_80281720[arg0].unk2 = 1;
D_80281720[arg0].unk0 = 0;
}
}
void func_8024FCE0(u8 arg0, s16 arg1){
D_80281720[arg0].unk3 = 1;
D_80281720[arg0].unk2 = 1;
D_80281720[arg0].unk0 = arg1;
D_80281720[arg0].index_cpy = D_80281720[arg0].index;
}
//musicTrack_setVolume
void func_8024FD28(u8 arg0, s16 arg1){
D_80281720[arg0].unk0 = arg1;
alCSPSetVol(&D_80281720[arg0].cseqp, arg1);
if(D_80281720[arg0].unk3 && arg1){
func_8024FCE0(arg0, arg1);
}
else if(!D_80281720[arg0].unk3 && arg1 == 0){
if(func_80250074(arg0) == 0)
func_8024FC6C(arg0);
}
}
//musicTrack_setTempo
void func_8024FDDC(u8 arg0, s32 tempo){
if(func_80250074(arg0) == 0){
if(!D_80281720[arg0].unk2){
alCSPSetTempo(&D_80281720[arg0].cseqp, tempo);
}
}
}
void func_8024FE44(u8 arg0, f32 arg1, f32 arg2){
D_80281720[arg0].unk17C = arg1;
D_80281720[arg0].unk180 = arg2;
if(func_80250074(arg0) == 0){
if(func_8028EE84() == BSWATERGROUP_2_UNDERWATER){
func_8025F3F0(&D_80281720[arg0].cseqp, 0.0f, 1.0f);
}else{
func_8025F3F0(&D_80281720[arg0].cseqp, arg1, arg2);
}
}
}
void func_8024FEEC(u8 arg0){
alCSeqGetTicks(&D_80281720[arg0].cseq);
}
void func_8024FF34(void){
s32 i;
for(i = 0; i < 6 ; i++){
switch(D_80281720[i].cseqp.state){
case AL_PLAYING://L8024FF94
if(D_80281720[i].unk2){
alCSPStop(&(D_80281720[i].cseqp));
if(D_80281720[i].unk3)
D_80281720[i].unk2 = 0;
}
break;
case AL_STOPPED: //L8024FFBC
if(D_80281720[i].unk2){
if(D_80281720[i].unk3){
alCSPPlay(&D_80281720[i].cseqp);
} else{
func_8024FA98(i, D_80281720[i].index_cpy);
}
D_80281720[i].unk3 = 0;
D_80281720[i].unk2 = 0;
func_8024FD28(i, D_80281720[i].unk0);
}
break;
case AL_STOPPING: //L80250008
break;
}
}
}
s32 func_80250034(enum comusic_e track_id){
return D_80275D40[track_id].unk4;
}
void func_80250048(enum comusic_e track_id, u16 arg1){
D_80275D40[track_id].unk4 = arg1;
}
//song_getName
char *func_80250060(enum comusic_e track_id){
return D_80275D40[track_id].name;
}
int func_80250074(u8 arg0){
return (D_80281720[arg0].cseqp.state == AL_STOPPED && D_80281720[arg0].unk3 == 0);
}
s32 func_802500C0(void){
return *(s16 *)&D_80282104;
}
ALCSPlayer *func_802500CC(s32 arg0){
return &D_80281720[arg0].cseqp;
}
void func_802500F4(s32 arg0){}
void func_802500FC(s32 arg0){}
void func_80250104(ALCSeq *arg0, s32 arg1, s32 arg2){
u8 i;
for(i = 0; i < 6; i++){
if(arg0 == &D_80281720[i].cseq){
D_80281720[i].unk184[arg1 - 0x6A] = 1;
D_80281720[i].unk192[arg1 - 0x6A] = arg2;
return;
}
}
}
void func_80250170(u8 arg0, s32 arg1, s32 arg2){
D_80281720[arg0].unk184[arg1 - 0x6A] = arg2;
}
s32 func_802501A0(u8 arg0, s32 arg1, s32 *arg2){
if(arg2 != 0){
*arg2 = D_80281720[arg0].unk192[arg1 - 0x6A];
}
return D_80281720[arg0].unk184[arg1 - 0x6A];
}
void func_80250200(s32 arg0, s16 chan, s16 arg2, f32 arg3){
s32 i;
ALCSPlayer *sp28;
f32 tmpf;
s32 mask;
sp28 = func_802500CC(arg0);
mask = osSetIntMask(OS_IM_NONE);
tmpf = (!func_80250074(arg0))? func_8025F4A0(sp28, chan) :127.0f;
if(arg3 < D_80278180){
arg3 = D_80278180;
}
for(i = 0; i< 0x20; i++){
if( (D_80282110[i].unk8 == D_80282110[i].unk10)
|| (D_80282110[i].unk0 == arg0 && chan ==D_80282110[i].chan)
){
D_80282110[i].unk0 = arg0;
D_80282110[i].chan = chan;
D_80282110[i].unk8 = tmpf;
D_80282110[i].unkC = (arg2 - tmpf)/((arg3 * 60.0f)/2);
D_80282110[i].unk10 = arg2;
osSetIntMask(mask);
return;
}
}
osSetIntMask(mask);
}
void func_80250360(s32 arg0, s32 arg1, f32 arg2){
ALCSPlayer * sp24;
s32 i;
s32 sp1C;
f32 tempo;
sp24 = func_802500CC(arg0);
sp1C = osSetIntMask(1);
tempo = alCSPGetTempo(sp24);
if( arg2 < D_80278184){
arg2 = D_80278184;
}
for(i = 0; i < 0x20; i++){
if(D_80282110[i].unk8 == D_80282110[i].unk10
|| (D_80282110[i].unk0 == arg0 && -1 ==D_80282110[i].chan)
){
D_80282110[i].unk0 = arg0;
D_80282110[i].chan = -1;
D_80282110[i].unk8 = tempo;
D_80282110[i].unkC = (arg1 - tempo)/((arg2 * 60.0f)/2);
D_80282110[i].unk10 = arg1;
osSetIntMask(sp1C);
return;
}
}
osSetIntMask(sp1C);
}
u16 func_80250474(s32 arg0){
ALCSPlayer * sp24;
s32 i;
s32 sp1C;
f32 tmpf;
if(arg0 != 0)
return ~0;
D_802762C0 = (D_802762C4 = -1);
sp1C = osSetIntMask(1);
for(i = 0; i < 0x20; i++){
D_80282110[i].unk8 = -1.0f;
D_80282110[i].unk10 = -1.0f;
}
osSetIntMask(sp1C);
func_8024AF48();
if(D_802762C0 == -1){
D_802762C0 = 0xFFFF;
}
return D_802762C0;
}
void func_80250530(s32 arg0, u16 chan_mask, f32 arg2){
s32 chan;
if(D_802762C0 != chan_mask){
if(D_802762C0 == -1){
arg2 = 0.0f;
}
D_802762C0 = chan_mask;
for(chan = 0; chan < 16; chan++){
if(chan_mask & (1 << chan)){
func_80250200(arg0, chan, 0x7F, arg2);
}
else{
func_80250200(arg0, chan, 0, arg2);
}
}
}//L802505E4
}
void func_80250604(s32 arg0, s32 arg1, f32 arg2){
if(arg1 != D_802762C4){
if(D_802762C4 == -1){
arg2 = 0.0f;
}
D_802762C4 = arg1;
func_80250360(arg0, arg1, arg2);
}
}
#ifndef NONMATCHING
#pragma GLOBAL_ASM("asm/nonmatchings/core1/code_11AC0/func_80250650.s")
#else
void func_80250650(void) {
ALCSPlayer *csplayer;
s32 i;
s32 mask;
for(i = 0; i < 0x20; i++){
csplayer = func_802500CC(D_80282110[i].unk0);
if ((D_80282110[i].unk8 != D_80282110[i].unk10) && (func_80250074((u8)D_80282110[i].unk0) == 0)) {
if (D_80282110[i].unkC >= 0.0f) {
D_80282110[i].unk8 = MIN(D_80282110[i].unk8 + D_80282110[i].unkC, D_80282110[i].unk10);
} else {
D_80282110[i].unk8 = MAX(D_80282110[i].unk8 + D_80282110[i].unkC, D_80282110[i].unk10);
}
if (D_80282110[i].chan == -1) {
alCSPSetTempo(csplayer, (s32) D_80282110[i].unk8);
} else {
func_8025F510(csplayer,D_80282110[i].chan, D_80282110[i].unk8);
if ((csplayer->chanMask) & (1U << D_80282110[i].chan)) {
if (D_80282110[i].unk8 == 0.0) {
func_8025F5C0(csplayer, D_80282110[i].chan);
}
} else {
if (D_80282110[i].unk8 != 0.0f) {
func_8025F570(csplayer, D_80282110[i].chan);
}
}
}
}
}
}
#endif

176
src/core1/code_12F10.c Normal file
View File

@@ -0,0 +1,176 @@
#include <ultra64.h>
#include "functions.h"
#include "variables.h"
void func_8024F35C(s32);
extern f64 D_80278190;
OSMesgQueue D_80282390;
OSMesg D_802823A8;
s32 D_802823AC;
s32 D_802823B0;
OSMesgQueue *D_802823B4;
OSPfs D_802823B8;
f32 D_80282420;
f32 D_80282424;
f32 D_80282428;
f32 D_8028242C;
OSThread D_80282430;
u8 pad_D_80282430[0x200];
/* .code */
void func_80250D94(f32, f32, f32);
void func_80250890(void){
u32 motor_status;
if(D_802823B0){
func_8024F35C(4);
motor_status = osMotorStart(&D_802823B8);
D_802823B0 = (motor_status == 0);
func_8024F35C(0);
}
}
void func_802508E0(void){
u32 motor_status;
if(D_802823B0){
func_8024F35C(4);
motor_status = osMotorStop(&D_802823B8);
D_802823B0 = (motor_status == 0);
func_8024F35C(0);
}
}
void func_80250930(void){
u32 motor_status;
if(!D_802823B0){
func_8024F35C(4);
motor_status = osMotorInit(D_802823B4, &D_802823B8, 0);
D_802823B0 = (motor_status == 0);
func_8024F35C(0);
}
}
void func_8025098C(void *arg0) {
static s32 D_802827E0;
static s32 D_802827E4;
f32 temp_f2;
f32 temp_f0;
f32 temp_f12;
f32 temp_f14;
s32 temp_a0;
s32 var_v0;
s32 var_v1;
do{
osRecvMesg(&D_80282390, NULL, 1);
D_802827E0++;
if (!D_802823B0 && ((D_802827E0 % 60) == 0)) {
func_80250930();
}
temp_a0 = D_802827E4;
if (D_80282424 != D_80282420) {
temp_f2 = D_80282428 + ((D_8028242C - D_80282428) * D_80282424 / D_80282420);
var_v0 = (s32) (((1.0 - temp_f2) * 8.0) + 1);
if (var_v0 < 2) {
D_802827E4 = var_v0;
} else {
D_802827E4 = (D_802827E0 % var_v0) == 0;
}
} else {
D_802827E4 = 0;
}
if (D_802827E4 != temp_a0) {
D_802827E4 = D_802827E4;
if (D_802827E4) {
func_80250890(); //start_motor
}
else{
func_802508E0(); //stop_motor
}
}
}while(1);
}
void func_80250BA4(s32 arg0, s32 arg1, s32 arg2){
f64 f0 = 524288.0;
func_80250D94(arg0/f0, arg1/f0, arg2/f0);
}
void func_80250C08(void) {
if (D_802823AC != 0) {
D_80282424 = MIN(D_80282420, D_80282424 + time_getDelta());
}
}
void func_80250C84(void){
extern s32 D_802827E0;
s32 pfs_status;
func_8024F35C(4);
D_802823B4 = func_8024F344();
pfs_status = osPfsInit(D_802823B4, &D_802823B8, 0);
if(pfs_status == PFS_ERR_ID_FATAL || pfs_status == PFS_ERR_DEVICE){
pfs_status = osMotorInit(D_802823B4, &D_802823B8, 0);
}
func_8024F35C(0);
D_802823AC = (pfs_status == 0);
D_802823B0 = D_802823AC;
if(D_802823AC){
osCreateMesgQueue(&D_80282390, &D_802823A8, 1);
osCreateThread(&D_80282430, 8, func_8025098C, NULL, &D_802827E0, 0x19);
osStartThread(&D_80282430);
func_8024BDAC(&D_80282390, 0);
}
}
void func_80250D8C(void){}
void func_80250D94(f32 arg0, f32 arg1, f32 arg2){
f32 f4;
if(arg2 != 0.0f && D_802823AC){
if(func_802E4A08() == 0){
if(!(D_80278190 < D_80282420 - D_80282424) || !(arg0 + arg1 < D_80282428 + D_8028242C)){
D_80282420 = arg2;
D_80282424 = 0.0f;
D_80282428 = arg0;
D_8028242C = arg1;
}
}
}
}
void func_80250E6C(f32 arg0, f32 arg1){
func_80250D94(arg0, arg0, arg1);
}
void func_80250E94(f32 arg0, f32 arg1, f32 arg2, f32 arg3, f32 arg4, f32 arg5){
if(D_802823AC){
timedFunc_set_3(0.0f, (TFQM3) func_80250BA4, 0, (s32) (arg0 * 524288.0f), (s32) (arg2*524288.0f));
timedFunc_set_3(arg2, (TFQM3) func_80250BA4, (s32) (arg0 * 524288.0f), (s32) (arg1 * 524288.0f), (s32) (arg3*524288.0f));
timedFunc_set_3(arg2 + arg3, (TFQM3) func_80250BA4, (s32) (arg1 * 524288.0f), (s32) (arg1 * 524288.0f), (s32) (arg4*524288.0f));
timedFunc_set_3(arg2 + arg3 + arg4, (TFQM3) func_80250BA4, (s32) (arg1 * 524288.0f), 0, (s32) (arg5*524288.0f));
}
}
void func_80250FC0(void){
int i;
u32 motor_status;
if(D_802823B0){
func_8024F35C(4);
motor_status = osMotorInit(D_802823B4, &D_802823B8, 0);
D_802823B0 = (motor_status == 0);
for(i=0; i < 3 && D_802823B0; i++){
motor_status = osMotorStop(&D_802823B8);
D_802823B0 = (motor_status == 0);
}
func_8024F35C(0);
}
}

21
src/core1/code_13640.c Normal file
View File

@@ -0,0 +1,21 @@
#include <ultra64.h>
#include "functions.h"
#include "variables.h"
void func_8025108C(s32 arg0);
/* .bss */
s32 D_802827F0;
/* .code */
s32 func_80251060(void){
return D_802827F0;
}
void func_8025106C(void){
func_8025108C(0);
}
void func_8025108C(s32 arg0){
D_802827F0 = arg0;
}

35
src/core1/code_13680.c Normal file
View File

@@ -0,0 +1,35 @@
#include <ultra64.h>
#include "functions.h"
#include "variables.h"
u32 func_802510A0(BKSprite *this){
return this->unk8;
}
u32 func_802510A8(BKSprite *this){
return this->unkA;
}
u32 func_802510B0(BKSprite *this){
return this->unk6;
}
u32 func_802510B8(BKSprite *this){
return this->unk4;
}
s32 spriteGetFrameCount(BKSprite *this){
return this->frameCnt;
}
#pragma GLOBAL_ASM("asm/nonmatchings/core1/code_13680/spriteGetFramePtr.s")
// //NONMATCHING bad RegAlloc
/*BKSpriteFrame *spriteGetFramePtr(BKSprite *this, u32 frame){
u32 f_data;
u32 *f_array = this + 1;
f_data = (u32)(f_array + this->frameCnt) + f_array[frame];
return f_data;
}//*/

153
src/core1/code_136D0.c Normal file
View File

@@ -0,0 +1,153 @@
#include <ultra64.h>
#include "functions.h"
#include "variables.h"
typedef struct struct_2a_s{
char *name;
u32 ram_start;
u32 ram_end;
u32 unkC; //uncompressed_rom_range_start
u32 unk10; //uncompressed_rom_range_end
u32 code_start;
u32 code_end;
u32 data_start;
u32 data_end;
u32 bss_start;
u32 bss_end;
} struct2As;
extern u8 D_80363590;
extern u8 D_80379B90;
extern u8 D_80286F90;
extern u8 D_803863F0;
extern u8 D_803A5D00;
extern u8 D_F55960;
extern u8 D_1048560;
extern struct2As D_802762D0[] = {
{"gs", 0x80286F90, 0x803863F0, 0x00F55960, 0x01048560, 0x80286F90, 0x80363590, 0x80363590, 0x80379B90, 0x80379B90, 0x803863F0},
{"coshow", 0x803863F0, 0x80386430, 0x010BCD00, 0x010BCD20, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000},
{"whale", 0x803863F0, 0x8038A000, 0x01048560, 0x0104C0E0, 0x803863F0, 0x80389AA0, 0x80389AA0, 0x80389F70, 0x80389F70, 0x8038A000},
{"haunted", 0x803863F0, 0x8038C530, 0x01057710, 0x0105D7E0, 0x803863F0, 0x8038B9E0, 0x8038B9E0, 0x8038C4C0, 0x8038C4C0, 0x8038C530},
{"desert", 0x803863F0, 0x80391B10, 0x0104C0E0, 0x01057710, 0x803863F0, 0x80390BD0, 0x80390BD0, 0x80391A20, 0x80391A20, 0x80391B10},
{"beach", 0x803863F0, 0x8038D740, 0x0105D7E0, 0x01064AE0, 0x803863F0, 0x8038C3B0, 0x8038C3B0, 0x8038D6F0, 0x8038D6F0, 0x8038D740},
{"jungle", 0x803863F0, 0x80389CA0, 0x01064AE0, 0x01068370, 0x803863F0, 0x80389890, 0x80389890, 0x80389C80, 0x80389C80, 0x80389CA0},
{"swamp", 0x803863F0, 0x80391250, 0x01068370, 0x010731B0, 0x803863F0, 0x80390690, 0x80390690, 0x80391230, 0x80391230, 0x80391250},
{"ship", 0x803863F0, 0x803912D0, 0x010731B0, 0x0107E030, 0x803863F0, 0x80390050, 0x80390050, 0x80391270, 0x80391270, 0x803912D0},
{"snow", 0x803863F0, 0x803935F0, 0x0107E030, 0x0108AB50, 0x803863F0, 0x803919F0, 0x803919F0, 0x80392F10, 0x80392F10, 0x803935F0},
{"tree", 0x803863F0, 0x8038FDF0, 0x010B3320, 0x010BCD00, 0x803863F0, 0x8038EB50, 0x8038EB50, 0x8038FDD0, 0x8038FDD0, 0x8038FDF0},
{"training", 0x803863F0, 0x8038B330, 0x0108AB50, 0x0108FA80, 0x803863F0, 0x8038AAC0, 0x8038AAC0, 0x8038B320, 0x8038B320, 0x8038B330},
{"intro", 0x803863F0, 0x8038E9F0, 0x0108FA80, 0x01098070, 0x803863F0, 0x8038D350, 0x8038D350, 0x8038E9E0, 0x8038E9E0, 0x8038E9F0},
{"witch", 0x803863F0, 0x80395470, 0x01098070, 0x010A6FD0, 0x803863F0, 0x80392CB0, 0x80392CB0, 0x80395350, 0x80395350, 0x80395470},
{"battle", 0x803863F0, 0x80392930, 0x010A6FD0, 0x010B3320, 0x803863F0, 0x80391380, 0x80391380, 0x80392740, 0x80392740, 0x80392930},
};
extern s32 D_80276564 = 15;
enum overlay_e D_80282800;
void func_802513A4(void);
/* .code */
struct2As *func_802510F0(void){
//returns struct2As ptr with largest RAM size
int i;
struct2As * v1;
v1 = &D_802762D0[1];
for(i = 1; i < D_80276564; i++){
if(v1->ram_end - v1->ram_start < D_802762D0[i].ram_end - D_802762D0[i].ram_start){
v1 = &D_802762D0[i];
}
}
return v1;
}
s32 func_80251170(void){
return 0;
}
s32 func_80251178(void){
int sp24;
struct2As *sp20;
s32 sp1C;
s32 sp18;
sp20 = func_802510F0();
sp18 = func_802546DC();
sp1C = func_80251170();
return ((sp1C + (u32)&D_803A5D00) - sp20->ram_end) + sp18;
}
void func_802511C4(void){
s32 sp24;
int sp20;
int sp1C;
int sp18;
u32 tmp_v0;
sp24 = func_80251178();
sp18 = heap_get_size();
sp20 = func_802546DC();
sp1C = sp18 - sp20;
if(sp24 < 0){
func_802513A4();
tmp_v0 = sp1C + sp24;
while( tmp_v0 & 0xF){tmp_v0--;}
}
}
int get_loaded_overlay_id(void){
return D_80282800;
}
int is_overlay_loaded(int overlay_id){
return D_80282800 == overlay_id;
}
//load_overlay
#ifndef NONMATCHING
#pragma GLOBAL_ASM("asm/nonmatchings/core1/code_136D0/load_overlay.s")
#else
bool load_overlay(enum overlay_e overlay_id){
struct2As *rom_info;
if(overlay_id == 0)
return FALSE;
if(overlay_id == D_80282800)
return FALSE;
D_80282800 = overlay_id;
rom_info = &D_802762D0[D_80282800];
func_80253050(
overlay_id,
rom_info->ram_start, rom_info->ram_end,
rom_info->unkC, rom_info->unk10,
rom_info->code_start, rom_info->code_end,
rom_info->data_start, rom_info->data_end,
rom_info->bss_start, rom_info->bss_end
);
return TRUE;
}
#endif
//clear_loaded_overlay_id
s32 func_802512FC(void){
D_80282800 = 0;
}
#ifdef NONMATCHING
void func_80251308(void){
func_802512FC();
func_80253050(0, &D_80286F90, &D_803863F0, &D_F55960, &D_1048560, &D_80286F90, &D_80363590, &D_80363590, &D_80379B90, &D_80379B90, &D_803863F0);
func_802511C4();
}
#else
#pragma GLOBAL_ASM("asm/nonmatchings/core1/code_136D0/func_80251308.s")
#endif
void func_802513A4(void){}

387
src/core1/code_13990.c Normal file
View File

@@ -0,0 +1,387 @@
#include <ultra64.h>
#include "functions.h"
#include "variables.h"
#include "ml/mtx.h"
extern Mtx *D_80282FD0;
extern Mtx_t D_80282810;
f32 func_80263FF0(f32);
f32 cosf(f32);
extern f64 D_80278220;
#ifndef NONMATCHING
#pragma GLOBAL_ASM("asm/nonmatchings/core1/code_13990/func_802513B0.s")
#else
void func_802513B0(f32 arg0[4][4]){
s32 i;
s32 j;
for(i = 0; i < 4; i++){
for(j = 0; j < 4; j++){
reinterpret_cast(f32, arg0[i][j]) = reinterpret_cast(f32, D_80282FD0->m[i][j]);
}
}
}
#endif
Mtx *func_80251488(void){
return D_80282FD0;
}
void mlMtxApply(Mtx *mPtr){
func_80245A7C(D_80282FD0, mPtr);
}
#pragma GLOBAL_ASM("asm/nonmatchings/core1/code_13990/func_802514BC.s")
#pragma GLOBAL_ASM("asm/nonmatchings/core1/code_13990/func_802515D4.s")
void mlMtxPop(void){
D_80282FD0--;
}
#pragma GLOBAL_ASM("asm/nonmatchings/core1/code_13990/func_802516E0.s")
void func_80251738(void){
s32 i;
f32 *v0 = ++D_80282FD0;
for(i = 0; i<3; i++){
v0[0] = 1.0f;
v0[1] = 0.0f;
v0[2] = 0.0f;
v0[3] = 0.0f;
v0[4] = 0.0f;
v0 += 5;
}
v0[0] = 1.0f;
}
#ifndef NONMATCHING
#pragma GLOBAL_ASM("asm/nonmatchings/core1/code_13990/func_80251788.s")
#else
f32 *func_80251788(f32 arg0, f32 arg1, f32 arg2){
f32 (* v0)[4][4] = (f32 *) ++D_80282FD0;
(*v0)[0][3] = 0.0f;
(*v0)[0][2] = 0.0f;
(*v0)[0][1] = 0.0f;
(*v0)[1][3] = 0.0f;
(*v0)[1][2] = 0.0f;
(*v0)[1][0] = 0.0f;
(*v0)[2][3] = 0.0f;
(*v0)[2][1] = 0.0f;
(*v0)[2][0] = 0.0f;
(*v0)[0][0] = 1.0f;
(*v0)[1][1] = 1.0f;
(*v0)[2][2] = 1.0f;
(*v0)[3][3] = 1.0f;
(*v0)[3][2] = arg2;
(*v0)[3][1] = arg1;
(*v0)[3][0] = arg0;
return &(*v0)[3][3];
}
#endif
#pragma GLOBAL_ASM("asm/nonmatchings/core1/code_13990/func_802517F8.s")
#pragma GLOBAL_ASM("asm/nonmatchings/core1/code_13990/func_80251878.s")
#pragma GLOBAL_ASM("asm/nonmatchings/core1/code_13990/func_802519C8.s")
//mlMtx
void mlMtxIdent(void){
s32 i;
f32 *v0 = D_80282FD0 = D_80282810;
for(i = 0; i<3; i++){
v0[0] = 1.0f;
v0[1] = 0.0f;
v0[2] = 0.0f;
v0[3] = 0.0f;
v0[4] = 0.0f;
v0 += 5;
}
v0[0] = 1.0f;
}
#pragma GLOBAL_ASM("asm/nonmatchings/core1/code_13990/func_80251B5C.s")
#pragma GLOBAL_ASM("asm/nonmatchings/core1/code_13990/func_80251BCC.s")
#pragma GLOBAL_ASM("asm/nonmatchings/core1/code_13990/func_80251C20.s")
#pragma GLOBAL_ASM("asm/nonmatchings/core1/code_13990/mlMtxRotPitch.s")
#pragma GLOBAL_ASM("asm/nonmatchings/core1/code_13990/mlMtxRotYaw.s")
/*void mlMtxRotYaw(f32 yaw) {
f32 sin;
f32 cos;
f32 phi_f12;
f32 phi_f10;
f32 phi_f8;
f32 phi_f4;
f32 *phi_v0;
s32 phi_v1;
if (yaw == 0.0f)
return;
sin = sinf(yaw*0.0174533);
cos = cosf(yaw*0.0174533);
phi_v0 = D_80282FD0;
for(phi_v1 = 0; phi_v1 < 0xC; phi_v1 += 4){
phi_v0 = (u32)D_80282FD0 + phi_v1;
phi_f12 = phi_v0[0] * cos;
phi_f10 = phi_v0[8] * sin;
phi_f8 = phi_v0[0] * sin;
phi_f4 = phi_v0[8] * cos;
phi_v0[0] = phi_f12 - phi_f10;
phi_v0 = (u32)D_80282FD0 + phi_v1;
phi_v0[8] = phi_f8 + phi_f4;
}
}//*/
#pragma GLOBAL_ASM("asm/nonmatchings/core1/code_13990/mlMtxRotRoll.s")
#pragma GLOBAL_ASM("asm/nonmatchings/core1/code_13990/func_80251F8C.s")
#pragma GLOBAL_ASM("asm/nonmatchings/core1/code_13990/func_8025208C.s")
void mlMtxRotate(f32 pitch, f32 yaw, f32 roll){
mlMtxRotYaw(yaw);
mlMtxRotPitch(pitch);
mlMtxRotRoll(roll);
}
void mlMtxScale_xyz(f32 x, f32 y, f32 z){
int i;
for(i = 0; i < 3; i++){
reinterpret_cast(f32, D_80282FD0->m[0][i]) *= x;
reinterpret_cast(f32, D_80282FD0->m[1][i]) *= y;
reinterpret_cast(f32, D_80282FD0->m[2][i]) *= z;
}
}
void mlMtxScale(f32 scale){
int i;
for(i = 0; i < 3; i++){
reinterpret_cast(f32, D_80282FD0->m[0][i]) *= scale;
reinterpret_cast(f32, D_80282FD0->m[1][i]) *= scale;
reinterpret_cast(f32, D_80282FD0->m[2][i]) *= scale;
}
}
void func_80252330(f32 x, f32 y, f32 z){
reinterpret_cast(f32, D_80282FD0->m[3][0]) = x;
reinterpret_cast(f32, D_80282FD0->m[3][1]) = y;
reinterpret_cast(f32, D_80282FD0->m[3][2]) = z;
}
#pragma GLOBAL_ASM("asm/nonmatchings/core1/code_13990/func_8025235C.s")
#pragma GLOBAL_ASM("asm/nonmatchings/core1/code_13990/func_80252434.s")
#pragma GLOBAL_ASM("asm/nonmatchings/core1/code_13990/func_802524F0.s")
#pragma GLOBAL_ASM("asm/nonmatchings/core1/code_13990/func_802525A4.s")
#pragma GLOBAL_ASM("asm/nonmatchings/core1/code_13990/func_8025276C.s")
void mlMtxTranslate(f32 x, f32 y, f32 z) {
f32 *temp_t6;
f32 *phi_v0;
f32 phi_f18;
f32 phi_f16;
f32 phi_f10;
s32 phi_v1;
phi_v0 = D_80282FD0;
for(phi_v1 = 0; phi_v1 < 0xC; phi_v1 +=4){
phi_v0 = (u32)D_80282FD0 + phi_v1;
phi_f18 = phi_v0[0] * x;
phi_f16 = phi_v0[4] * y;
phi_v0[0xC] += phi_f18 + phi_f16 + (phi_v0[8] * z);
}
}
void func_80252A38(f32 x, f32 y, f32 z) {
s32 var_v1;
for(var_v1 = 0; var_v1 != 3; var_v1++){
reinterpret_cast(f32, D_80282FD0->m[3][var_v1]) += reinterpret_cast(f32, D_80282FD0->m[0][var_v1])*x + reinterpret_cast(f32, D_80282FD0->m[1][var_v1])*y + reinterpret_cast(f32, D_80282FD0->m[2][var_v1])*z;
}
}
void func_80252AF0(f32 arg0[3], f32 arg1[3], f32 rotation[3], f32 scale, f32 arg4[3]) {
f32 sp1C[3];
if (arg1 != NULL) {
sp1C[0] = arg1[0] - arg0[0];
sp1C[1] = arg1[1] - arg0[1];
sp1C[2] = arg1[2] - arg0[2];
} else {
sp1C[0] = arg0[0] * -1.0f;
sp1C[1] = arg0[1] * -1.0f;
sp1C[2] = arg0[2] * -1.0f;
}
mlMtxTranslate(sp1C[0], sp1C[1], sp1C[2]);
if (rotation != NULL) {
mlMtxRotYaw(rotation[1]);
mlMtxRotPitch(rotation[0]);
mlMtxRotRoll(rotation[2]);
}
if (scale != 1.0f) {
mlMtxScale_xyz(scale, scale, scale);
}
if (arg4 != NULL) {
mlMtxTranslate(-arg4[0], -arg4[1], -arg4[2]);
}
}
void func_80252C08(f32 arg0[3], f32 arg1[3], f32 scale, f32 arg3[3]){
if(arg0 != NULL)
mlMtxTranslate(arg0[0], arg0[1], arg0[2]);
if(arg1 != NULL){
mlMtxRotYaw(arg1[1]);
mlMtxRotPitch(arg1[0]);
mlMtxRotRoll(arg1[2]);
}
if(scale != 1.0f){
mlMtxScale_xyz(scale, scale, scale);
}
if(arg3 != NULL)
mlMtxTranslate(-arg3[0], -arg3[1], -arg3[2]);
}
void func_80252CC4(f32 arg0[3], f32 arg1[3], f32 scale, f32 arg3[3]){
if(arg3 != NULL)
mlMtxTranslate(arg3[0], arg3[1], arg3[2]);
if(scale != 1.0f){
mlMtxScale_xyz(1.0f/scale, 1.0f/scale, 1.0f/scale);
}
if(arg1 != NULL){
mlMtxRotRoll(-arg1[2]);
mlMtxRotPitch(-arg1[0]);
mlMtxRotYaw(-arg1[1]);
}
if(arg0 != NULL)
mlMtxTranslate(-arg0[0], -arg0[1], -arg0[2]);
}
void func_80252D8C(f32 arg0[3], f32 arg1[3]){
mlMtxTranslate(arg0[0], arg0[1], arg0[2]);
mlMtxRotRoll(arg1[2]);
mlMtxRotPitch(arg1[0]);
mlMtxRotYaw(arg1[1]);
}
void func_80252DDC(f32 arg0[3], f32 arg1[3]){
mlMtxRotYaw(-arg1[1]);
mlMtxRotPitch(-arg1[0]);
mlMtxRotRoll(-arg1[2]);
mlMtxTranslate(-arg0[0], -arg0[1], -arg0[2]);
}
void func_80252E4C(f32 arg0[3], f32 arg1[3]){
mlMtxTranslate(arg0[0], arg0[1], arg0[2]);
mlMtxRotRoll(arg1[2]);
mlMtxRotPitch(arg1[0]);
mlMtxRotYaw(arg1[1]);
mlMtxTranslate(-arg0[0], -arg0[1], -arg0[2]);
}
void func_80252EC8(f32 arg0[3], f32 arg1[3]){
mlMtxTranslate(arg0[0], arg0[1], arg0[2]);
mlMtxRotYaw(-arg1[1]);
mlMtxRotPitch(-arg1[0]);
mlMtxRotRoll(-arg1[2]);
mlMtxTranslate(-arg0[0], -arg0[1], -arg0[2]);
}
void func_80252F50(f32 arg0[3]){
mlMtxRotYaw(arg0[1]);
mlMtxRotPitch(arg0[0]);
mlMtxRotRoll(arg0[2]);
}
void func_80252F8C(f32 arg0[3]){
mlMtxRotRoll(arg0[2]);
mlMtxRotPitch(arg0[0]);
mlMtxRotYaw(arg0[1]);
}
void func_80252FC8(f32 arg0[3]){
mlMtxRotYaw(-arg0[1]);
mlMtxRotPitch(-arg0[0]);
mlMtxRotRoll(-arg0[2]);
}
#pragma GLOBAL_ASM("asm/nonmatchings/core1/code_13990/func_80253010.s")
#pragma GLOBAL_ASM("asm/nonmatchings/core1/code_13990/func_80253034.s")
typedef struct{
u32 unk0;
u32 unk4;
}struct49s;
extern struct49s D_803FFE10[];
extern u8 D_8000E800;
extern u8 D_8002D500;
extern u32 D_8027BF2C;
extern u32 D_8027BF30;
void func_80253050(
s32 overlay_id, u32 ram_start, u32 ram_end, u32 rom_start, u32 rom_end,
u32 code_start, u32 code_end, u32 data_start, u32 data_end, u32 bss_start, u32 bss_end
){
u32 sp34;
u32 sp30;
u32 sp2C;
u32 *tmp;
osWriteBackDCacheAll();
osInvalDCache(ram_start, ram_end - ram_start);
osInvalICache(ram_start, ram_end - ram_start);
if(bss_start){
osInvalDCache(bss_start, bss_end - bss_start);
}
rom_start = D_803FFE10[overlay_id].unk0;
rom_end = D_803FFE10[overlay_id].unk4;
if(overlay_id){
func_80254008();
sp34 = &D_8000E800;
}
else{
sp34 = &D_8002D500;
}
func_802405F0(sp34, rom_start, rom_end - rom_start);
rarezip_uncompress(&sp34, &ram_start);
sp2C = D_8027BF2C;
sp30 = D_8027BF30;
rarezip_uncompress(&sp34, &ram_start);
if(bss_start){
bzero(bss_start, bss_end - bss_start);
osWriteBackDCacheAll();
tmp = (u32*) bss_start;
tmp[0] = sp2C;
tmp[1] = sp30;
tmp[2] = D_8027BF2C;
tmp[3] = D_8027BF30;
}
}

77
src/core1/code_15770.c Normal file
View File

@@ -0,0 +1,77 @@
#include <ultra64.h>
#include "functions.h"
#include "variables.h"
extern struct {
void *unk0;
int unk4;
} D_80282FE0;
extern u8 D_8000E800;
extern u8 D_803A5D00[2][0x1ecc0];
void func_80253208(Gfx **gdl, s32 x, s32 y, s32 w, s32 h, void *color_buffer);
void func_80253190(Gfx **gdl){
func_80253208(gdl, 0, 0, D_80276588, D_8027658C, D_803A5D00[func_8024BDA0()]);
}
void func_80253208(Gfx **gdl, s32 x, s32 y, s32 w, s32 h, void *color_buffer){
if( D_80282FE0.unk0 != NULL && (getGameMode() != GAME_MODE_4_PAUSED || func_80335134())){
//draw z_buffer
gDPPipeSync((*gdl)++);
gDPSetColorImage((*gdl)++, G_IM_FMT_RGBA, G_IM_SIZ_16b, D_80276588, OS_K0_TO_PHYSICAL(D_80282FE0.unk0));
gDPSetCycleType((*gdl)++, G_CYC_FILL);
gDPSetRenderMode((*gdl)++, G_RM_NOOP, G_RM_NOOP2);
gDPSetFillColor((*gdl)++, 0xFFFCFFFC);
gDPScisFillRectangle((*gdl)++, x, y, x + w - 1, y + h - 1);
//draw color_buffer
gDPPipeSync((*gdl)++);
gDPSetColorImage((*gdl)++, G_IM_FMT_RGBA, G_IM_SIZ_16b, D_80276588, OS_K0_TO_PHYSICAL(color_buffer));
}
}
int func_80253400(void){
return D_80282FE0.unk4;
}
int func_8025340C(void){
return D_80282FE0.unk0 != NULL;
}
void func_80253420(void){}
#ifdef NONMATCHING
s32 func_80253428(int arg0){
if(arg0){
D_80282FE0.unk0 = &D_8000E800;
while((s32)D_80282FE0.unk0 % 0x40){
D_80282FE0.unk0 = (s32)D_80282FE0.unk0 + 2;
}
}else{//L80253494
D_80282FE0.unk0 = NULL;
}//L802534A0
D_80282FE0.unk4 = 0;
}
#else
#pragma GLOBAL_ASM("asm/nonmatchings/core1/code_15770/func_80253428.s")
#endif
void func_802534A8(int arg0){
D_80282FE0.unk4 = (D_80282FE0.unk0 != NULL && arg0);
}
//zBuffer_set
void func_802534CC(Gfx **gdl){
if(D_80282FE0.unk0 && getGameMode() != GAME_MODE_4_PAUSED){
gDPPipeSync((*gdl)++);
gDPSetDepthImage((*gdl)++, D_80282FE0.unk0);
}
}
//zBuffer_get
void *func_80253540(void){
return D_80282FE0.unk0;
}

268
src/core1/code_15B30.c Normal file
View File

@@ -0,0 +1,268 @@
#include <ultra64.h>
#include "functions.h"
#include "variables.h"
typedef struct {
s32 unk0;
s32 unk4;
s32 unk8;
s32 unkC;
s32 unk10;
s32 unk14;
}Struct_Core1_15B30;
extern Gfx *D_80276580[2];
extern Mtx *D_80282FF0[2];
extern Vtx *D_80282FF8[2];
extern s32 D_80283000;
extern s32 D_80283004;
extern Struct_Core1_15B30 D_80283008[];
extern s32 D_802831E8;
extern OSMesgQueue D_802831F0;
extern OSMesg D_80283208;
extern u16 D_8028320C;
extern u16 D_8028320E;
extern u16 D_80283210;
extern u16 D_80283212;
extern Gfx *D_80283214;
extern u8 D_803A5D00[2][0x1ecc0];
void func_80254348(void);
void func_80254464(void);
/* .code */
void func_80253550(void){
osRecvMesg(&D_802831F0, NULL, OS_MESG_BLOCK);
}
void func_8025357C(void){
osSendMesg(&D_802831F0, NULL, OS_MESG_BLOCK);
}
void func_802535A8(UNK_TYPE(s32) arg0, UNK_TYPE(s32)arg1, UNK_TYPE(s32) arg2, UNK_TYPE(s32) arg3) {
Struct_Core1_15B30 *sp1C;
func_80253550();
sp1C = &D_80283008[D_802831E8];
D_802831E8 = (s32) (D_802831E8 + 1) % 20;
func_8025357C();
sp1C->unk0 = 0;
sp1C->unk8 = arg0;
sp1C->unkC = arg1;
sp1C->unk10 = arg2;
sp1C->unk14 = arg3;
func_80246670(sp1C);
}
void func_80253640(Gfx ** gdl, void *arg1){
D_80283214 = *gdl;
gSPSegment((*gdl)++, 0x00, 0x00000000);
gDPSetRenderMode((*gdl)++, G_RM_NOOP, G_RM_NOOP2);
gSPClearGeometryMode((*gdl)++, G_ZBUFFER | G_SHADE | G_CULL_BOTH | G_FOG | G_LIGHTING | G_TEXTURE_GEN | G_TEXTURE_GEN_LINEAR | G_LOD | G_SHADING_SMOOTH);
gDPPipeSync((*gdl)++);
gDPPipelineMode((*gdl)++, G_PM_NPRIMITIVE);
gDPSetAlphaCompare((*gdl)++, G_AC_NONE);
gDPSetColorDither((*gdl)++, G_CD_MAGICSQ);
gDPSetScissor((*gdl)++, G_SC_NON_INTERLACE, D_8028320C, D_8028320E, D_80283210, D_80283212);
func_80253208(gdl, 0, 0, D_80276588, D_8027658C, arg1);
gDPSetColorImage((*gdl)++, G_IM_FMT_RGBA, G_IM_SIZ_16b, D_80276588, OS_K0_TO_PHYSICAL(arg1));
gDPSetCycleType((*gdl)++, G_CYC_1CYCLE);
gDPSetTextureConvert((*gdl)++, G_TC_FILT);
gDPSetTextureDetail((*gdl)++, G_TD_CLAMP);
if(D_80283004){
gDPSetTextureFilter((*gdl)++, G_TF_POINT);
}else{
gDPSetTextureFilter((*gdl)++, G_TF_BILERP);
}
gDPSetTextureLOD((*gdl)++, G_TL_TILE);
gDPSetTextureLUT((*gdl)++, G_TT_NONE);
gDPSetTexturePersp((*gdl)++, G_TP_PERSP);
func_802534CC(gdl);
}
void func_802539AC(Gfx **gdl, s32 arg1){
if(getGameMode() == GAME_MODE_8_BOTTLES_BONUS || getGameMode() == GAME_MODE_A_SNS_PICTURE)
{
func_8030C710();
func_80253640(gdl, func_8030C704());
}
else{
func_80254348();
func_80253640(gdl, D_803A5D00[arg1]);
}
}
void func_80253A58(Gfx **gfx, s32 arg1){
gSPSegment((*gfx)++, 0x00, 0x00000000);
gDPSetColorImage((*gfx)++, G_IM_FMT_RGBA, G_IM_SIZ_16b, D_80276588, OS_PHYSICAL_TO_K0(arg1));
gSPClearGeometryMode((*gfx)++, G_ZBUFFER | G_SHADE | G_CULL_BOTH | G_FOG | G_LIGHTING | G_TEXTURE_GEN | G_TEXTURE_GEN_LINEAR | G_LOD | G_SHADING_SMOOTH);
gSPTexture((*gfx)++, 0, 0, 0, G_TX_RENDERTILE, G_OFF);
gSPSetGeometryMode((*gfx)++, G_ZBUFFER | G_SHADE | G_SHADING_SMOOTH);
gDPSetCycleType((*gfx)++, G_CYC_1CYCLE);
gDPPipelineMode((*gfx)++, G_PM_NPRIMITIVE);
gDPSetCombineMode((*gfx)++, G_CC_SHADE, G_CC_SHADE);
gDPSetAlphaCompare((*gfx)++, G_AC_NONE);
gDPSetColorDither((*gfx)++, G_CD_DISABLE);
gDPSetRenderMode((*gfx)++, G_RM_AA_ZB_XLU_LINE, G_RM_AA_ZB_XLU_LINE2);
gSPClipRatio((*gfx)++, FRUSTRATIO_1);
gDPSetScissor((*gfx)++, G_SC_NON_INTERLACE, D_8028320C, D_8028320E, D_80283210, D_80283212);
gDPPipeSync((*gfx)++);
}
void func_80253D60(Gfx **gfx, s32 arg1){
func_80254348();
func_80253A58(gfx, D_803A5D00[arg1]);
}
void func_80253DC0(Gfx **gfx){
func_802476EC(gfx);
}
void func_80253DE0(Gfx **gdl) {
gDPFullSync((*gdl)++);
gSPEndDisplayList((*gdl)++);
}
void func_80253E14(Gfx **arg0, Gfx **arg1, s32 arg2){
Struct_Core1_15B30 *sp1C;
func_80253550();
sp1C = D_80283008 + D_802831E8;
D_802831E8 = (D_802831E8 + 1) % 0x14;
func_8025357C();
sp1C->unk0 = 1;
sp1C->unk4 = arg2;
sp1C->unk8 = arg0;
sp1C->unkC = arg1;
func_80246670((OSMesg) sp1C);
}
void func_80253EA4(Gfx **arg0, Gfx **arg1){
func_80253E14(arg0, arg1, 0);
}
void func_80253EC4(Gfx **arg0, Gfx **arg1){
func_80253E14(arg0, arg1, 0x40000000);
}
void func_80253EE4(Gfx **arg0, Gfx **arg1, s32 arg2) {
Struct_Core1_15B30 *sp1C;
func_80253550();
sp1C = &D_80283008[D_802831E8];
D_802831E8 = (s32) (D_802831E8 + 1) % 20;
func_8025357C();
sp1C->unk0 = 2;
sp1C->unk4 = arg2;
sp1C->unk8 = arg0;
sp1C->unkC = arg1;
func_80246670(sp1C);
}
void func_80253F74(Gfx **arg0, Gfx **arg1){
func_80253EE4(arg0, arg1, 0);
}
void func_80253F94(Gfx **arg0, Gfx **arg1){
func_80253EE4(arg0, arg1, 0x40000000);
}
void func_80253FB4(u32 *arg0, u32 *arg1, u32 *arg2, u32 *arg3){
*arg0 = D_8028320C;
*arg1 = D_80283210;
*arg2 = D_8028320E;
*arg3 = D_80283212;
}
void func_80253FE8(void){
func_8024BFAC();
}
void func_80254008(void){
func_80246670(3);
}
void func_80254028(void){
D_802831E8 = 0;
osCreateMesgQueue(&D_802831F0, &D_80283208, 1);
osSendMesg(&D_802831F0, NULL, 1);
func_80247560();
func_80254348();
}
void func_80254084(Gfx **gfx, s32 x, s32 y, s32 w, s32 h, s32 r, s32 g, s32 b){
gDPPipeSync((*gfx)++);
gDPPipelineMode((*gfx)++, G_PM_NPRIMITIVE);
gDPSetCycleType((*gfx)++, G_CYC_FILL);
gDPSetFillColor((*gfx)++, GPACK_RGBA5551(r, g, b, 1) << 16 | GPACK_RGBA5551(r, g, b, 1));
gDPSetRenderMode((*gfx)++, G_RM_NOOP, G_RM_NOOP2);
gDPScisFillRectangle((*gfx)++, x, y, x + w -1, y + h -1);
}
void func_802541E8(void){
if(D_80276580[0]){
free(D_80276580[0]);
free(D_80276580[1]);
free(D_80282FF0[0]);
free(D_80282FF0[1]);
free(D_80282FF8[0]);
free(D_80282FF8[1]);
D_80276580[0] = NULL;
}
}
void func_8025425C(void){
if(D_80276580[0] == NULL){
D_80276580[0] = (Gfx *)malloc(29600);
D_80276580[1] = (Gfx *)malloc(29600);
D_80282FF0[0] = (Mtx *)malloc(44800);
D_80282FF0[1] = (Mtx *)malloc(44800);
D_80282FF8[0] = malloc(6880);
D_80282FF8[1] = malloc(6880);
func_80254464();
}
D_80283000 = 0;
D_80283004 = 0;
}
void func_802542F4(s32 arg0, s32 arg1, s32 arg2, s32 arg3) {
D_8028320C = arg0;
D_80283210 = arg1;
D_8028320E = arg2;
D_80283212 = arg3;
D_80276588 = arg1 - arg0;
D_8027658C = arg3 - arg2;
func_8024CC5C();
}
void func_80254348(void){
func_802542F4(0, 0x124, 0, 0xd8);
}
void func_80254374(s32 arg0) {
Struct_Core1_15B30 *sp1C;
func_80253550();
func_8024C2A0(arg0);
sp1C = &D_80283008[D_802831E8];
D_802831E8 = (s32) (D_802831E8 + 1) % 20;
func_8025357C();
sp1C->unk0 = 7;
func_80246670(sp1C);
}
void func_802543EC(void){
u32 ret_val = D_80283004;
D_80283004 = ret_val < 1;
}
void func_80254404(Gfx **gfx, Mtx **mtx, Vtx **vtx){
D_80283000 = (1 - D_80283000);
*gfx = D_80276580[D_80283000];
*mtx = D_80282FF0[D_80283000];
*vtx = D_80282FF8[D_80283000];
}
void func_80254464(void){}

28
src/core1/code_18110.c Normal file
View File

@@ -0,0 +1,28 @@
#include <ultra64.h>
#include "functions.h"
#include "variables.h"
#include "save.h"
#define ROUND_UP_DIVIDE(a, b) (((a) + (b) - 1) / (b))
// The round up divide is not technically needed, but will come in handy for modding
#define SAVEFILE_NUM_BLOCKS ROUND_UP_DIVIDE(sizeof(SaveFile),EEPROM_BLOCK_SIZE)
s32 write_file_blocks(s32 filenum, s32 blockOffset, u8 *buffer, s32 blockCount) {
s32 address = (filenum * SAVEFILE_NUM_BLOCKS) + blockOffset;
s32 ret;
func_8024F35C(3);
ret = osEepromLongWrite(func_8024F344(), address, buffer, blockCount * EEPROM_BLOCK_SIZE);
func_8024F35C(0);
return ret;
}
s32 load_file_blocks(s32 filenum, s32 blockOffset, u8 *buffer, s32 blockCount) {
s32 address = (filenum * SAVEFILE_NUM_BLOCKS) + blockOffset;
s32 ret;
func_8024F35C(3);
ret = osEepromLongRead(func_8024F344(), address, buffer, blockCount * EEPROM_BLOCK_SIZE);
func_8024F35C(0);
return ret;
}

32
src/core1/code_18210.c Normal file
View File

@@ -0,0 +1,32 @@
#include <ultra64.h>
#include "functions.h"
#include "variables.h"
extern u64 D_80283280[];
extern s32 D_80283380;
extern s32 D_80283384;
extern s32 D_80283388;
void func_80255C30(void) {
D_80283384 = *(s32 *)0xA4000000 ^ -1;
D_80283388 = (D_80283384) ? 1 :0;
D_80283380 = *(s32 *)0xA4001000 ^ 0x17D7;
D_80283388 |= (D_80283380) ? 2 :0;
if (D_80283388 == 0) {
func_802405F0(&D_80283280, 0xB0000B70, 0x100);
}
}
void func_80255CD8(void){}
void func_80255CE0(void){
osPiReadIo(0, NULL);
}
s32 func_80255D04(void){return 0;}
void func_80255D0C(u64 **ucode_ptr, u32 *ucode_size){
*ucode_ptr = &D_80283280;
*ucode_size = 0x100;
}

137
src/core1/code_18310.c Normal file
View File

@@ -0,0 +1,137 @@
#include <ultra64.h>
#include "functions.h"
#include "variables.h"
s16 D_802765C0[] ={
0x0001, 0x0002, 0x0003, 0x0004, 0x0005, 0x0006, 0x0007, 0x0008,
0x0009, 0x000A, 0x029E, 0x000C, 0x000D, 0x000E, 0x029F, 0x0010,
0x0011, 0x0012, 0x0013, 0x0014, 0x0015, 0x0016, 0x0017, 0x0018,
0x0019, 0x001A, 0x001B, 0x001C, 0x001D, 0x001E, 0x001F, 0x0020,
0x0021, 0x0022, 0x0023, 0x0291, 0x0292, 0x029B, 0x0024, 0x029D,
0x02B2, 0x0025, 0x0026, 0x0027, 0x02B8, 0x02B9, 0x002A, 0x002B,
0x002C, 0x002D, 0xFFFE, 0x002F, 0x0295, 0x0031, 0x0032, 0x0033,
0x0034, 0x0035, 0x0036, 0x0037, 0x0038, 0x0039, 0x003A, 0x003B,
0x003C, 0x003D, 0x003E, 0x003F, 0x0040, 0x0041, 0x0042, 0x0043,
0x0044, 0x0045, 0x0046, 0x0047, 0x0048, 0x0049, 0x004A, 0x004B,
0x004C, 0x004D, 0x004E, 0x004F, 0x0050, 0x0051, 0x0052, 0x0053,
0x0054, 0x0055, 0x0056, 0x0057, 0x0058, 0x0059, 0x005A, 0x005B,
0x005C, 0x005D, 0x005E, 0x005F, 0x0060, 0x0061, 0x0062, 0x0063,
0x0064, 0x0065, 0x020D, 0x020E, 0x020F, 0x0210, 0x006A, 0x006B,
0x006C, 0x006D, 0x006E, 0x006F, 0x0070, 0x0071, 0x0072, 0x0073,
0x0074, 0x0075, 0x0076, 0x0294, 0x008F, 0x0090, 0x0293, 0x0078,
0x0079, 0x007A, 0x007B, 0x007C, 0x007D, 0x007E, 0x007F, 0x0080,
0x0081, 0x0082, 0x0083, 0x0084, 0x0085, 0x008F, 0x008F, 0x008F,
0x008F, 0x008F, 0x008F, 0x008C, 0x008E, 0x008D, 0x0091, 0x0093,
0x0098, 0x0161, 0x015E, 0x00F9, 0x010E, 0x010F, 0x015F, 0x0110,
0x0163, 0x0160, 0x0296, 0x01B7, 0x00AE, 0x009D, 0x00AD, 0x01B8,
0x01B9, 0x01BA, 0x013A, 0x013B, 0x0139, 0x013D, 0x013C, 0x01BB,
0x01BC, 0x01BD, 0x01BE, 0x01BF, 0x01C0, 0xFFFE, 0x01C2, 0x01C3,
0x01C4, 0x01C5, 0x01C6, 0x01C7, 0x01C8, 0x01C9, 0x01CA, 0x01CB,
0x01CC, 0x01CD, 0x01CE, 0x01CF, 0x01D0, 0x01D1, 0x01D2, 0x01D3,
0x01D4, 0x01D5, 0x02A0, 0xFFFE, 0x01F8, 0x01F9, 0x01F7, 0x01F5,
0x01FA, 0x01FB, 0x01FC, 0x01FD, 0x01FE, 0x01FF, 0x0200, 0x0201,
0x0202, 0x0204, 0x0205, 0x0206, 0x0207, 0x0208, 0x0209, 0x020A,
0x020B, 0x020C, 0x01C1, 0x0297, 0x0298, 0x0299, 0x029A, 0x029C,
0x02AE, 0x02AF, 0x02B0, 0x02B1, 0x02B3, 0x02B4, 0x02B5, 0x02B6,
0x02B7, 0x02BA, 0x02BB, 0x02BC, 0xFFFE, 0xFFFE, 0xFFFE, 0xFFFE,
0xFFFE, 0xFFFE, 0xFFFE, 0xFFFE, 0xFFFE, 0xFFFE, 0xFFFE, 0xFFFE,
0xFFFE, 0xFFFE, 0xFFFE, 0xFFFE, 0xFFFE, 0xFFFE, 0xFFFE, 0xFFFE,
0xFFFE, 0xFFFE, 0xFFFE, 0xFFFE, 0xFFFE, 0xFFFE, 0xFFFE, 0xFFFE,
0xFFFE, 0xFFFE, 0xFFFE, 0xFFFE, 0xFFFE, 0xFFFE, 0xFFFE, 0xFFFE,
0xFFFE, 0xFFFE, 0xFFFE, 0xFFFE, 0xFFFE, 0xFFFE, 0xFFFE, 0xFFFE,
0xFFFE, 0xFFFE, 0xFFFE, 0xFFFE, 0xFFFE, 0xFFFE, 0xFFFE, 0xFFFE,
0xFFFE, 0xFFFE, 0xFFFE, 0xFFFE, 0xFFFE, 0xFFFE, 0xFFFE, 0xFFFE,
0xFFFE, 0xFFFE, 0xFFFE, 0xFFFE, 0xFFFE, 0xFFFE, 0xFFFE, 0xFFFE,
0xFFFE, 0xFFFE, 0xFFFE, 0xFFFE, 0xFFFE, 0xFFFE, 0xFFFE, 0xFFFE,
0xFFFE, 0xFFFE, 0xFFFE, 0xFFFE, 0xFFFE, 0xFFFE, 0xFFFE, 0xFFFE,
0xFFFE, 0xFFFE, 0xFFFE, 0xFFFE, 0xFFFE, 0xFFFE, 0xFFFE, 0xFFFE,
0xFFFE, 0xFFFE, 0xFFFE, 0xFFFE, 0xFFFE, 0xFFFE, 0xFFFE, 0x008F,
0x0090, 0x0092, 0x0094, 0x0095, 0x0096, 0x0097, 0x0099, 0x009A,
0x009B, 0x009C, 0x009D, 0x009E, 0x009F, 0x00A0, 0x00A1, 0x00A2,
0x00A3, 0x00A4, 0x00A5, 0x00A6, 0x00A7, 0x00A8, 0x00A9, 0x00AA,
0x00AB, 0x00AC, 0x00AD, 0x00AE, 0x00AF, 0x00B0, 0x00B1, 0x00B2,
0x00B3, 0x00B4, 0x00B5, 0x00B6, 0x00B7, 0x00B8, 0x00B9, 0x00BA,
0x00BB, 0x00BC, 0x00BD, 0x00BE, 0x00BF, 0x00C0, 0x00C1, 0x00C2,
0x00C3, 0x00C4, 0x00C5, 0x00C6, 0x00C7, 0x00C8, 0x00C9, 0x00CA,
0x00CB, 0x00CC, 0x00CD, 0x00CE, 0x00CF, 0x00D0, 0x00D1, 0x00D2,
0x00D3, 0x00D4, 0x00D5, 0xFFFE, 0x00D7, 0x00D8, 0x00D9, 0x00DA,
0x00DB, 0x00DC, 0x00DD, 0x00DE, 0x00DF, 0x00E0, 0x00E1, 0x00E2,
0x00E3, 0x00E4, 0x00E5, 0x00E6, 0x00E7, 0x00E8, 0x00E9, 0x00EA,
0x00EB, 0x00EC, 0x00ED, 0x00EE, 0x00EF, 0x00F0, 0x00F1, 0x00F2,
0x00F3, 0x00F4, 0x00F5, 0x00F6, 0x00F7, 0x00F8, 0x00F9, 0x00FA,
0x00FB, 0x00FC, 0x00FD, 0x00FE, 0x00FF, 0x0100, 0x0101, 0x0102,
0x0103, 0x0104, 0x0105, 0x0106, 0x0107, 0x0108, 0x0109, 0x010A,
0x010B, 0x010C, 0x010D, 0x010E, 0x010F, 0x0110, 0x0111, 0x0112,
0x0113, 0x0114, 0x0115, 0x0116, 0x0117, 0x0118, 0x0119, 0x011A,
0x011B, 0x011C, 0x011D, 0x011E, 0x011F, 0x0120, 0x0121, 0x0122,
0x0123, 0x0124, 0x0125, 0x0126, 0x0127, 0x0128, 0x0129, 0x012A,
0x012B, 0x012C, 0x012D, 0x012E, 0x012F, 0xFFFF
};
s16 D_802769AC[] = {
0x0000, 0x0001,
0x0002, 0x0003, 0x018F, 0x0005, 0x008C, 0x0007, 0x0008, 0xFFFE,
0x000A, 0x000B, 0x000C, 0x000D, 0x000E, 0x000F, 0x0010, 0x0063,
0x0064, 0x03F0, 0x0011, 0x0012, 0x0013, 0x0027, 0x0014, 0x0015,
0x0016, 0x0017, 0x0018, 0x0019, 0x001A, 0x001B, 0x0066, 0x001D,
0x001E, 0x001F, 0x0152, 0x0021, 0x0022, 0x0023, 0x0024, 0xFFFE,
0x0026, 0x03E9, 0x0028, 0xFFFE, 0xFFFE, 0x002B, 0x002C, 0x002D,
0x002E, 0x002F, 0x0030, 0x0031, 0x0032, 0x0033, 0x0034, 0x0035,
0x0036, 0x0037, 0x0038, 0x0039, 0x003A, 0x003B, 0x003C, 0x003D,
0x003E, 0x003F, 0x0040, 0x0041, 0x0042, 0x0043, 0x0044, 0x0045,
0x0046, 0x0047, 0x0048, 0x0049, 0xFFFE, 0x004B, 0x004C, 0x004D,
0x004E, 0x004F, 0x0050, 0x03EE, 0x0052, 0x0053, 0x0054, 0x0055,
0x0056, 0x0057, 0x0058, 0x0059, 0x005A, 0x005B, 0x005C, 0x005D,
0x005E, 0x005F, 0x0060, 0x0061, 0x0062, 0x03E9, 0x03EA, 0x03EB,
0x03EC, 0x03ED, 0x03EF, 0xFFFE, 0xFFFE, 0x0069, 0x006A, 0x006B,
0x006C, 0x006D, 0x00D0, 0x00C1, 0x03FA, 0x0066, 0x03FC, 0x03F2,
0x00C9, 0x00EA, 0x00EB, 0x00EC, 0x00ED, 0x0128, 0xFFFE, 0xFFFE,
0xFFFE, 0xFFFE, 0xFFFE, 0x03F9, 0x0405, 0x0190, 0xFFFE, 0x0131,
0x0133, 0xFFFE, 0xFFFE, 0xFFFE, 0xFFFE, 0xFFFE, 0xFFFE, 0xFFFE,
0xFFFE, 0xFFFE, 0xFFFE, 0xFFFE, 0xFFFE, 0xFFFE, 0xFFFE, 0xFFFE,
0xFFFE, 0xFFFE, 0xFFFE, 0xFFFE, 0xFFFE, 0xFFFE, 0xFFFE, 0xFFFE,
0xFFFE, 0xFFFE, 0xFFFE, 0xFFFE, 0xFFFE, 0xFFFE, 0xFFFE, 0xFFFE,
0xFFFE, 0xFFFE, 0xFFFE, 0xFFFE, 0xFFFE, 0xFFFE, 0xFFFE, 0xFFFE,
0xFFFE, 0xFFFE, 0xFFFE, 0xFFFE, 0x03F6, 0x007F, 0x006E, 0x006F,
0x0070, 0x0071, 0x0072, 0x0073, 0x0074, 0x0075, 0x0076, 0x0077,
0x0078, 0x0079, 0x0419, 0xFFFE, 0x007C, 0x007D, 0x007E, 0x007F,
0x0080, 0x0081, 0x0082, 0x0083, 0x0084, 0x0085, 0x0086, 0x0087,
0x0088, 0x0089, 0x008A, 0x008B, 0x008C, 0x008D, 0x008E, 0x008F,
0x0090, 0xFFFE, 0xFFFE, 0x0093, 0x0094, 0xFFFE, 0xFFFE, 0x0097,
0x0098, 0x0099, 0x009A, 0x009B, 0x009C, 0x009D, 0x009E, 0x009F,
0x00A0, 0x00A1, 0x00A2, 0x00A3, 0x00A4, 0x00A5, 0xFFFE, 0x00A7,
0x00A8, 0x00A9, 0xFFFF, 0x0000
};
s16 D_80276B98[] = {
0x002F, 0x0030, 0x0099, 0x005F,
0x0002, 0x0003, 0xFFFE, 0x0005, 0x0006, 0xFFFE, 0x0008, 0x0009,
0x000A, 0x000B, 0x000C, 0x000D, 0xFFFE, 0x000F, 0x0010, 0xFFFE,
0xFFFE, 0xFFFE, 0xFFFE, 0x0011, 0x0012, 0x0013, 0x0014, 0x0015,
0x0016, 0x0017, 0x0018, 0x0019, 0x001A, 0x001B, 0x001C, 0x001D,
0xFFFE, 0x001F, 0x0020, 0x0021, 0x0022, 0x0023, 0x0024, 0x0025,
0x0026, 0x0027, 0x0028, 0xFFFE, 0x0029, 0x002A, 0x0030, 0x0031,
0x0032, 0xFFFE, 0xFFFE, 0x002B, 0x002C, 0x003F, 0x0040, 0x0043,
0x000E, 0x0091, 0x00AB, 0xFFFE, 0xFFFE, 0xFFFE, 0xFFFE, 0xFFFE,
0xFFFE, 0xFFFE, 0xFFFE, 0xFFFE, 0xFFFE, 0xFFFE, 0xFFFE, 0xFFFE,
0xFFFE, 0xFFFE, 0xFFFE, 0xFFFE, 0xFFFE, 0xFFFE, 0xFFFE, 0xFFFE,
0xFFFE, 0xFFFE, 0xFFFE, 0xFFFE, 0xFFFE, 0xFFFE, 0xFFFE, 0xFFFE,
0xFFFE, 0xFFFE, 0xFFFE, 0xFFFE, 0xFFFE, 0xFFFE, 0xFFFE, 0xFFFE,
0xFFFE, 0xFFFE, 0xFFFE, 0xFFFE, 0xFFFE, 0xFFFE, 0xFFFE, 0xFFFE,
0xFFFE, 0xFFFE, 0xFFFE, 0xFFFE, 0xFFFE, 0xFFFE, 0xFFFE, 0xFFFE,
0xFFFE, 0xFFFE, 0xFFFE, 0xFFFE, 0xFFFE, 0xFFFE, 0xFFFE, 0xFFFE,
0xFFFE, 0xFFFE, 0xFFFE, 0xFFFE, 0xFFFE, 0xFFFE, 0xFFFE, 0xFFFE,
0xFFFE, 0xFFFE, 0xFFFE, 0x0044, 0xFFFF, 0x0000, 0x0000, 0x0000,
};
s32 func_80255D30(s32 arg0){
return D_80276B98[arg0];
}
s32 func_80255D44(s32 arg0){
return D_802769AC[arg0];
}
s32 func_80255D58(s32 arg0){
return D_802765C0[arg0];
}

1491
src/core1/code_18350.c Normal file

File diff suppressed because it is too large Load Diff

628
src/core1/code_1BE90.c Normal file
View File

@@ -0,0 +1,628 @@
#include <ultra64.h>
#include "functions.h"
#include "variables.h"
extern func_8024FDDC(u8, s32);
void func_8025AE50(s32, f32);
bool func_80250074(u8);
void func_8024FD28(u8, s32);
void func_8024FC1C(u8, s32);
void func_8025AC20(enum comusic_e, s32, s32, f32, char*, s32);
void func_8025AC7C(enum comusic_e, s32, s32, f32, s32, char*, s32);
void func_80259B14(void);
void func_8025A55C(s32, s32, s32);
void func_8025A7DC(enum comusic_e);
void func_8025ABB8(enum comusic_e, s32, s32, s32);
void *func_802EDAA4(SLA **, s32*);
/* .bss */
extern CoMusic *D_80276E30; //active track ptr
extern int D_80276E34;
/* .code */
CoMusic *func_802598B0(enum comusic_e track_id) {
CoMusic *iMusPtr;
CoMusic *freeSlotPtr;
freeSlotPtr = NULL;
for(iMusPtr = D_80276E30 + 1; iMusPtr < D_80276E30 + 5; iMusPtr++) {
if (track_id == iMusPtr->unk10) {
return iMusPtr;
}
if (freeSlotPtr == 0) {
if ((s32) iMusPtr->unk10 < 0) {
freeSlotPtr = iMusPtr;
}
}
}
return freeSlotPtr;
}
void func_80259914(CoMusic *this, s32 arg1, s32 arg2){
s32 sp2C;
s32 i;
struct12s *tmp;
array_clear(this->unk18);
for(i = 0; i < 0xE; i++){
this->unk1C[i] = 0;
}
tmp = (struct12s *)func_802EDAA4(&this->unk18, &sp2C);
tmp->unk0 = arg1;
tmp->unk1 = arg2;
}
void func_80259994(CoMusic *this, s32 arg1){
func_80259914(this, arg1, arg1);
}
void func_802599B4(CoMusic *this){
func_80259994(this, func_80250034(this->unk10));
this->unk10 = -1;
this->unk14 = 0;
this->unk15 = 0;
func_8024FC1C(this - D_80276E30, -1);
}
void func_80259A24(void){
CoMusic * iPtr;
s32 i;
if(D_80276E30 != NULL)
func_80259B14();
D_80276E30 = (CoMusic *) malloc(6*sizeof(CoMusic));
for(iPtr = D_80276E30; iPtr < D_80276E30 + 6; iPtr++){
iPtr->unk10 = -1;
iPtr->unk8 = 0;
iPtr->unk12 = 0;
iPtr->unkC = 0;
iPtr->unk4 = 0.0f;
iPtr->unk14 = 0;
iPtr->unk15 = 0;
iPtr->unk0 = 0.0f;
iPtr->unk18 = array_new(sizeof(struct12s),4);
for(i = 0; i < 0xE; i++){
iPtr->unk1C[i] = 0;
}
}
}
//comusic_freeAll
void func_80259B14(void){
CoMusic *iPtr;
func_8024FB8C();
func_8024F83C();
for(iPtr = D_80276E30; iPtr < D_80276E30 + 6; iPtr++){
array_free(iPtr->unk18);
}
free(D_80276E30);
D_80276E30 = NULL;
}
//comusic_count
s32 func_80259B8C(void){
CoMusic * iPtr;
s32 cnt = 0;
for(iPtr = D_80276E30; iPtr < D_80276E30 + 6; iPtr++){
if(iPtr->unk10 >= 0)
cnt++;
}
return cnt;
}
void func_80259BD0(void) {
s32 temp_lo;
CoMusic *var_s0;
f32 sp3C;
sp3C = time_getDelta();
for(var_s0 = D_80276E30; var_s0 < &D_80276E30[6]; var_s0++){
if (var_s0->unk10 >= 0) {
temp_lo = var_s0 - D_80276E30;
var_s0->unk4 = min_f(var_s0->unk4 + sp3C, 600.0f);
if ((var_s0->unk4 > 1.0f) && func_80250074(temp_lo)) {
func_8025A7DC(var_s0->unk10);
}
}
}
func_8024FF34();
if (!D_80276E34)
return;
D_80276E34 = FALSE;
for(var_s0 = D_80276E30; var_s0 < &D_80276E30[6]; var_s0++){
if (var_s0->unk10 >= 0) {
if (var_s0->unk12 != 0) {
temp_lo = var_s0 - D_80276E30;
if (var_s0->unk0 > 0.0f) {
var_s0->unk0 -= time_getDelta();
D_80276E34 = TRUE;
} else if (var_s0->unk12 < 0) {
var_s0->unk8 += var_s0->unk12;
if (var_s0->unk15 && (var_s0->unkC == 0) && (var_s0->unk8 <= 0)) {
func_802599B4(var_s0);
continue;
} else {
if (var_s0->unkC >= var_s0->unk8) {
var_s0->unk8 = var_s0->unkC;
var_s0->unk12 = 0;
} else {
D_80276E34 = TRUE;
}
func_8024FD28(temp_lo, (s16)var_s0->unk8);
}
} else if (var_s0->unk8 < var_s0->unkC) {
if (var_s0->unk8 == 0) {
var_s0->unk4 = 0.0f;
}
var_s0->unk8 += var_s0->unk12;
if (var_s0->unk8 >= var_s0->unkC) {
var_s0->unk8 = var_s0->unkC;
var_s0->unk12 = 0;
} else {
D_80276E34 = TRUE;
}
func_8024FD28(temp_lo, (s16)var_s0->unk8);
} else {
var_s0->unk12 = 0;
}
}
}
}
}
void func_80259EA8(CoMusic *this, s32 *arg1, s32 *arg2){
int i;
int cnt = array_size(this->unk18);
s32 tmp_s1 = 0x7FFF;
s32 tmp_s2 = 0x40000000;
struct12s *tmp_ptr;
for(i = 1; i < cnt; i++){
if(func_802EDC18(this->unk18, i)){
tmp_ptr = (struct12s*)array_at(this->unk18, i);
if(tmp_ptr->unk0 < tmp_s1 || (tmp_s1 == tmp_ptr->unk0 && tmp_ptr->unk1 < tmp_s2)){
tmp_s1 = tmp_ptr->unk0;
tmp_s2 = tmp_ptr->unk1;
}//L80259F40
}
}
*arg1 = tmp_s1;
*arg2 = tmp_s2;
}
void func_80259F7C(CoMusic *self, s32 *arg1, s32 *arg2, s32 *arg3) {
struct12s *temp_v0;
f32 pad;
s32 sp34;
s32 var_s2;
var_s2 = *arg1;
sp34 = *arg2;
if ((*arg3 != 0) && !func_802EDC18(self->unk18, *arg3)) {
*arg3 = 0;
}
if (var_s2 < 0) {
temp_v0 = (struct12s *)array_at(self->unk18, 1);
if (temp_v0->unk0 < func_80250034(self->unk10)) {
var_s2 = func_80250034(self->unk10);
}
else{
var_s2 = temp_v0->unk0;
}
if (*arg3 != 0) {
temp_v0 = (struct12s *)array_at(self->unk18, *arg3);
*arg2 = temp_v0->unk1;
func_802EDCDC(self->unk18, *arg3);
*arg3 = 0;
func_80259EA8(self, arg1, &sp34);
return;
}
}
if (*arg3 == 0) {
temp_v0 = (struct12s *)array_at(self->unk18, 1);
if ((temp_v0->unk0 < var_s2) || ((var_s2 == temp_v0->unk0) && (sp34 >= temp_v0->unk1))) {
func_80259914(self, var_s2, sp34);
} else {
func_802EDAA4(&self->unk18, arg3);
}
}
if (*arg3 != 0) {
temp_v0 = (struct12s *)array_at(self->unk18, *arg3);
temp_v0->unk0 = var_s2;
temp_v0->unk1 = sp34;
}
func_80259EA8(self, arg1, arg2);
}
void func_8025A104(enum comusic_e arg0, s32 arg1){
if (arg0 != D_80276E30[0].unk10){
func_8024FC1C(0, arg0);
}
func_8024FD28(0, (s16)arg1);
D_80276E30[0].unk10 = (s16) arg0;
D_80276E30[0].unk8 = arg1;
D_80276E30[0].unk0 = 0.0f;
D_80276E30[0].unk12 = 0;
D_80276E30[0].unk4 = 0.0f;
D_80276E30[0].unk15 = 0;
func_80259994(&D_80276E30[0], arg1);
}
void func_8025A1A8(enum comusic_e arg0){
if (arg0 != D_80276E30[0].unk10){
func_8024FC1C(0, arg0);
D_80276E30[0].unk10 = (s16) arg0;
D_80276E30[0].unk8 = func_80250034(arg0);
D_80276E30[0].unk0 = 0.0f;
D_80276E30[0].unk12 = 0;
D_80276E30[0].unk4 = 0.0f;
D_80276E30[0].unk15 = 0;
func_80259994(&D_80276E30[0], D_80276E30[0].unk8);
}
}
void func_8025A23C(s32 arg0){
CoMusic *music = &D_80276E30[5];
s32 temp_v0;
if (arg0 != music->unk10){
func_8024FC1C(5, arg0);
music->unk10 = (s16) arg0;
temp_v0 = func_80250034(arg0);
music->unk8 = temp_v0;
music->unk12 = 0;
music->unk15 = 0;
music->unk0 = 0.0f;
music->unk4 = 0.0f;
func_80259994(music, temp_v0);
}
}
void func_8025A2B0(void){
func_802599B4(&D_80276E30[5]);
}
void func_8025A2D8(void){
func_802599B4(&D_80276E30[0]);
}
void func_8025A2FC(s32 arg0, s32 arg1){
s32 i;
func_8025A55C(arg0, arg1, 1);
for (i = 1; i < 5; i++){
s16 val = (i + D_80276E30)->unk10; // Doesn't match with D_80276E30[i]
if (val >= 0){
func_8025ABB8(val, arg0, arg1, 1);
}
}
}
void func_8025A388(s32 arg0, s32 arg1) {
s32 i;
if (D_80276E30->unk14 == 0){
func_8025A55C(arg0, arg1, 1);
}
for (i = 1; i < 5; i++){
CoMusic *current = (i + D_80276E30); // Doesn't match with D_80276E30[i]
if (current->unk10 >= 0 && current->unk14 == 0){
func_8025ABB8(current->unk10, arg0, arg1, 1);
}
}
}
void func_8025A430(s32 arg0, s32 arg1, s32 arg2){
s32 i;
func_8025A55C(arg0, arg1, arg2);
for (i = 1; i < 5; i++){
s16 val = (i + D_80276E30)->unk10; // Doesn't match with D_80276E30[i]
if (val >= 0){
func_8025ABB8(val, arg0, arg1, arg2);
}
}
}
void func_8025A4C4(s32 arg0, s32 arg1, s32 *arg2){
if(D_80276E30[0].unk10 >= 0){
func_80259F7C(&D_80276E30[0], &arg0, &arg1, arg2);
if(arg0 != D_80276E30[0].unk8){
if(D_80276E30[0].unk8 < arg0){
D_80276E30[0].unk12 = arg1;
}
else{
D_80276E30[0].unk12 = -arg1;
}
D_80276E30[0].unkC = arg0;
D_80276E34 = 1;
}
}
}
void func_8025A55C(s32 arg0, s32 arg1, s32 arg2){
func_8025A4C4(arg0, arg1, &D_80276E30->unk1C[arg2]);
}
void func_8025A58C(s32 arg0, s32 arg1){
func_8025A55C(arg0, arg1, 0);
}
void func_8025A5AC(enum comusic_e comusic_id, s32 arg1, s32 arg2){
CoMusic *tmp_a2;
s32 sp20;
if(arg1 == -1){
arg1 = func_80250034(comusic_id);
}
tmp_a2 = func_802598B0(comusic_id);
if(tmp_a2 == NULL)
return;
sp20 = (tmp_a2 - D_80276E30);
if(tmp_a2->unk10 < 0 || arg2){
switch(comusic_id){
case COMUSIC_15_EXTRA_LIFE_COLLECTED:
if(map_get() != MAP_10_BGS_MR_VILE){
case COMUSIC_3B_MINIGAME_VICTORY:
case COMUSIC_3C_MINIGAME_LOSS:
func_8025AE50(4000, 2.0f);
}//L8025A668
}
tmp_a2->unk10 = comusic_id;
tmp_a2->unk12 = 0;
tmp_a2->unk15 = 0;
tmp_a2->unk4 = 0.0f;
func_80259994(tmp_a2, arg1);
func_8024FC1C(sp20, comusic_id);
}
func_8024FD28(sp20, (s16) arg1);
tmp_a2->unk8 = arg1;
}
void func_8025A6CC(enum comusic_e arg0, s32 arg1){
func_8025A5AC(arg0, arg1, 0);
}
void func_8025A6EC(enum comusic_e track_id, s32 arg1){
func_8025A5AC(track_id, arg1, 1);
}
//comusic_queueTrack
void func_8025A70C(enum comusic_e track_id){
CoMusic *trackPtr;
s32 indx;
trackPtr = func_802598B0(track_id);
if(trackPtr == NULL)
return;
indx = trackPtr - D_80276E30;
if(trackPtr->unk10 < 0){
trackPtr->unk10 = track_id;
trackPtr->unk12 = 0;
trackPtr->unk4 = 0.0f;
func_8024FC1C( indx, track_id);
func_80259994(trackPtr, trackPtr->unk8 = func_80250034(track_id));
}
}
void func_8025A788(enum comusic_e comusic_id, f32 delay1, f32 delay2){
timedFunc_set_1(delay1, (TFQM1) func_8025A70C, comusic_id);
timedFunc_set_1(delay1 + delay2, (TFQM1) func_8025A7DC, comusic_id);
}
void func_8025A7DC(enum comusic_e track_id){
CoMusic *trackPtr;
trackPtr = func_802598B0(track_id);
if (trackPtr != NULL && trackPtr->unk10 >= 0){
func_802599B4(trackPtr);
}
}
s32 func_8025A818(void){
if (D_80276E30[0].unkC == 0 && D_80276E30[0].unk8 <= 0){
func_802599B4(&D_80276E30[0]);
return 1;
}
return 0;
}
s32 func_8025A864(enum comusic_e track_id){
CoMusic *trackPtr;
trackPtr = func_802598B0(track_id);
if (trackPtr != NULL && trackPtr->unkC == 0 && trackPtr->unk8 <= 0){
func_802599B4(trackPtr);
return 1;
}
return 0;
}
void func_8025A8B8(enum comusic_e track_id, s32 arg1){
CoMusic *trackPtr;
trackPtr = func_802598B0(track_id);
if (trackPtr != NULL){
trackPtr->unk14 = arg1;
}
}
void func_8025A8E4(s32 arg0) {
if (D_80276E30[0].unk10 >= 0) {
D_80276E30[0].unk14 = arg0;
}
}
void func_8025A904(void){
CoMusic *trackPtr = &D_80276E30[0];
while (trackPtr < &D_80276E30[6]){
if (trackPtr->unk10 >= 0){
func_802599B4(trackPtr);
}
trackPtr++;
}
}
//dequeue_allTracks
void func_8025A96C(void){
CoMusic *iPtr;
for(iPtr = &D_80276E30[1]; iPtr < &D_80276E30[6]; iPtr++){
if(iPtr->unk10 >= 0){
func_802599B4(iPtr);
}
}
}
//dequeue_allTracks
void func_8025A9D4(void){
CoMusic *iPtr;
for(iPtr = &D_80276E30[0]; iPtr < &D_80276E30[6]; iPtr++){
if(iPtr->unk10 >= 0 && !iPtr->unk14){
func_802599B4(iPtr);
}
}
}
//dequeue_nonmainTracks
void func_8025AA48(void){
CoMusic *iPtr;
for(iPtr = &D_80276E30[1]; iPtr < &D_80276E30[6]; iPtr++){
if(iPtr->unk10 >= 0 && !iPtr->unk14){
func_802599B4(iPtr);
}
}
}
//dequeue_track?
void func_8025AABC(enum comusic_e track_id){
CoMusic *trackPtr;
if(trackPtr = func_802598B0(track_id)){
trackPtr->unk15 = 1;
if(!trackPtr->unk8)
func_802599B4(trackPtr);
}
}
void func_8025AB00(void){
D_80276E30[0].unk15 = 1;
if (!D_80276E30[0].unk8){
func_802599B4(&D_80276E30[0]);
}
}
void comusic_8025AB44(enum comusic_e comusic_id, s32 arg1, s32 arg2){
func_8025AC20(comusic_id, arg1, arg2, 0.0f, "comusic.c", 0x39e);
}
void comusic_8025AB78(enum comusic_e comusic_id, s32 arg1, s32 arg2, s32 arg3){
func_8025AC7C(comusic_id, arg1, arg2, 0.0f, arg3, "comusic.c", 0x3a3);
}
void func_8025ABB8(enum comusic_e comusic_id, s32 arg1, s32 arg2, s32 arg3){
func_8025AC7C(comusic_id, arg1, arg2, 0.0f, (s32)&(func_802598B0(comusic_id)->unk1C[arg3]), "comusic.c", 0x3aa);
}
void func_8025AC20(enum comusic_e comusic_id, s32 arg1, s32 arg2, f32 arg3, char* arg4, s32 char5){
func_8025AC7C(comusic_id, arg1, arg2, 0.0f, (s32) func_802598B0(comusic_id)->unk1C, "comusic.c", 0x3b1);
}
void func_8025AC7C(enum comusic_e comusic_id, s32 arg1, s32 arg2, f32 arg3, s32 arg4, char* arg5, s32 arg6){
CoMusic *trackPtr;
u32 sp24;
trackPtr = func_802598B0(comusic_id);
if(trackPtr == NULL)
return;
if(trackPtr->unk10 < 0){ //Track not ready
if(arg1 == 0)
return;
sp24 = (trackPtr - D_80276E30);
func_8024FC1C(sp24, comusic_id);
trackPtr->unk10 = comusic_id;
trackPtr->unk8 = 0;
trackPtr->unk15 = 0;
trackPtr->unk4 = 0.0f;
func_80259994(trackPtr, 0);
func_8024FD28(sp24, 0);
}
func_80259F7C(trackPtr,&arg1, &arg2, arg4);
trackPtr->unk0 = arg3;
trackPtr->unk12 = (trackPtr->unk8 < arg1)? arg2: -arg2;
trackPtr->unkC = arg1;
D_80276E34 = 1;
}
//comusic_trackQueued
int func_8025AD7C(enum comusic_e arg0){
CoMusic * trackPtr = func_802598B0(arg0);
return (trackPtr == NULL || trackPtr->unk10 == -1)? 0 : 1;
}
//comusic_isPrimaryTrack
int func_8025ADBC(enum comusic_e arg0){
return D_80276E30[0].unk10 == arg0;
}
s32 func_8025ADD4(enum comusic_e id){
CoMusic * ptr = func_802598B0(id);
return ptr - D_80276E30;
}
void func_8025AE0C(s32 arg0, f32 arg1){
func_8025A58C(0, arg0);
timedFunc_set_2(arg1, (TFQM2)func_8025A58C, -1, arg0);
}
void func_8025AE50(s32 arg0, f32 arg1){
func_8025A430(0, arg0, 6);
timedFunc_set_3(arg1, (TFQM3)func_8025A430, -1, arg0, 6);
}
void func_8025AEA0(enum comusic_e track_id, s32 arg1){
CoMusic *ptr = func_802598B0(track_id);
if(!ptr) return;
func_8024FDDC(ptr - D_80276E30, arg1);
}
int func_8025AEEC(void){
s32 out = func_802501A0(0, 0x6A, 0);
if(out)
func_80250170(0, 0x6A, 0);
return out;
}
void func_8025AF38(void){
CoMusic *iPtr;
if(!D_80276E30) return;
for(iPtr = &D_80276E30[0]; iPtr < &D_80276E30[6]; iPtr++){
iPtr->unk18 = array_defrag(iPtr->unk18);
}
D_80276E30 = defrag(D_80276E30);
}

577
src/core1/code_1D00.c Normal file
View File

@@ -0,0 +1,577 @@
#include <ultra64.h>
#include "functions.h"
#include "variables.h"
#include "2.0L/PR/sched.h"
#include "n_libaudio.h"
extern void func_8025C320(s32, ALSynConfig *);
typedef struct AudioInfo_s {
short *data; /* Output data pointer */
short frameSamples; /* # of samples synthesized in this frame */
u8 pad4[2];
s16 unk8;
u8 padA[2];
struct AudioInfo_s *unkC;
} AudioInfo;
typedef struct Struct_1D00_1_s{
void *unk0;
u8 pad4[4];
s16 unk8;
u8 pada[2];
struct Struct_1D00_1_s *unkC;
} Struct_1D00_1;
typedef struct {
u8 pad0[4];
AudioInfo *unk4;
} Struct_1D00_2;
typedef struct Struct_1D00_3_s{
ALLink unk0;
u32 unk8;
u32 unkC;
u32 unk10;
} Struct_1D00_3;
typedef struct{
u8 pad0[0x18];
}Struct_core1_1D00_4;
typedef struct struct_core1_1D00_5_s{
struct struct_core1_1D00_5_s * next;
u8 type;
// u8 pad5[1];
u16 unk6;
u16 unk8;
union{
struct{u8 unk0; u8 unk1;}type1;
struct{f32 unk0;}type80;
}unkC;
}OscState;
void func_8023FBB8(void);
void func_8023FE80(void *);
// void func_802403B8(void);
void amgrHandleDoneMsg(AudioInfo *info);
void *func_802403B8(void *state);
void func_802403F0(void);
void amgrStartThread(void);
extern s32 D_80000300;
s32 D_80275770 = 0;
s32 D_80275774 = 0;
u8 D_80275778 = 0;
s32 D_8027577C[] = {
6, /* number of sections in this effect */
0x1900, /* total allocated memory */
/* SECTION 1 */
0, /* input */
0xA0, /* output */
900, /* fbcoef */
-900, /* ffcoef */
500, /* out gain */
0x0, /* no chorus rate */
0x0, /* no chorus delay */
0x0, /* no low-pass filter */
/* SECTION 2 */
0xA0, /* input */
0x140, /* output */
900, /* fbcoef */
-900, /* ffcoef */
500, /* out gain */
0x0, /* no chorus rate */
0x0, /* no chorus delay */
0x2500, /* low-pass filter */
/* SECTION 3 */
0x320, /* input */
0xA00, /* output */
13000, /* fbcoef */
-13000, /* ffcoef */
0xE03, /* out gain */
0x0, /* no chorus rate */
0x0, /* no chorus delay */
0x3000, /* low-pass filter */
/* SECTION 4 */
0xC80, /* input */
0x15E0, /* output */
13000, /* fbcoef */
-13000, /* ffcoef */
0xE03, /* out gain */
0x0, /* no chorus rate */
0x0, /* no chorus delay */
0x3500, /* low-pass filter */
/* SECTION 5 */
0xD20, /* input */
0x12C0, /* output */
0x2000, /* fbcoef */
-0x2000, /* ffcoef */
0x0, /* no out gain */
0x0, /* no chorus rate */
0x0, /* no chorus delay */
0x4000, /* low-pass filter */
/* SECTION 6 */
0x0, /* input */
0x1720, /* output */
11000, /* fbcoef */
-11000, /* ffcoef */
0x0, /* no out gain */
0x17C, /* chorus rate */
0xA, /* chorus delay */
0x4500 /* low-pass filter */
};
Struct_1D00_2 *D_80275844 = NULL;
AudioInfo *D_80275848 = NULL;
// extern int D_8027584C;//static int D_8027584C = 0;
extern s32 osViClock; //0x80277128
extern f32 D_80277620;
extern f64 D_80277628;
extern f64 D_80277630;
extern f32 D_80277638;
struct {
Acmd* ACMDList[2];
AudioInfo *audioInfo[3];
OSThread thread;
OSMesgQueue audioFrameMsgQ;
OSMesg audioFrameMsgBuf[8];
OSMesgQueue audioReplyMsgQ;
OSMesg audioReplyMsgBuf[8];
} g_AudioManager;
u8 pad_8027C178[0xE78];
ALHeap D_8027CFF0;
u8 * D_8027D000;
s32 D_8027D004;
OSMesgQueue D_8027D008;
OSMesg D_8027D020;
OSIoMesg D_8027D0E8;
Struct_core1_1D00_4 D_8027D100[58];
struct {
u8 unk0;
Struct_1D00_3 *unk4;
Struct_1D00_3 *unk8;
u8 padC[0x4];
} D_8027D5B0;
Struct_1D00_3 D_8027D5C0[90];
s32 D_8027DCC8;
s32 D_8027DCCC;
s32 D_8027DCD0;
N_ALSynth D_8027DCD8;
ALSynConfig D_8027DD50;
s32 D_8027DD74;
s32 D_8027DD78;
s32 D_8027DD7C;
s32 D_8027DD80;
OscState *freeOscStateList;
OscState oscStates[48];
/* .code */
f32 _depth2Cents(u8 depth)
{
f32 x = /*1.0309929847717f*/ D_80277620;
f32 cents = 1.0f;
while (depth) {
if (depth & 1) {
cents *= x;
}
x *= x;
depth >>= 1;
}
return cents;
}
ALMicroTime initOsc(void **oscState, f32 *initVal, u8 oscType, u8 oscRate, u8 oscDepth, u8 oscDelay, u8 arg6)
{
OscState *state;
ALMicroTime result = 0;
if (freeOscStateList != NULL) {
state = freeOscStateList;
freeOscStateList = freeOscStateList->next;
state->type = oscType;
*oscState = state;
result = oscDelay << 14;
switch (oscType) {
case 1:
state->unk8 = 0;
state->unk6 = 259 - oscRate;
state->unkC.type1.unk0 = oscDepth >> 1;
state->unkC.type1.unk1 = 127 - state->unkC.type1.unk0;
*initVal = state->unkC.type1.unk1;
break;
case 0x80:
state->unkC.type80.unk0 = _depth2Cents(oscDepth);
state->unk8 = 0;
state->unk6 = 259 - oscRate;
*initVal = 1.0f;
break;
default:
break;
}
}
return result;
}
ALMicroTime updateOsc(void *oscState, f32 *updateVal)
{
f32 sp2c;
OscState *state = oscState;
ALMicroTime result = AL_USEC_PER_FRAME;
switch (state->type) {
case 0x01:
state->unk8++;
if (state->unk8 >= state->unk6) {
state->unk8 = 0;
}
sp2c = (f32)state->unk8 / (f32)state->unk6;
sp2c = sinf(sp2c * /*M_TAU*/D_80277628);
sp2c = sp2c * state->unkC.type1.unk0;
*updateVal = state->unkC.type1.unk1 + sp2c;
break;
case 0x80:
state->unk8++;
if (state->unk8 >= state->unk6) {
state->unk8 = 0;
}
sp2c = (f32)state->unk8 / (f32)state->unk6;
sp2c = sinf(sp2c * /*M_TAU*/D_80277630) * state->unkC.type80.unk0;
*updateVal = alCents2Ratio(sp2c);
break;
default:
break;
}
return result;
}
void stopOsc(OscState *oscState){
oscState->next = freeOscStateList;
freeOscStateList = oscState;
}
void func_8023FA64(ALSeqpConfig *arg0) {
OscState *item;
s32 i;
freeOscStateList = &oscStates[0];
item = &oscStates[0];
for(i = 0; i< 0x2F; i++){
item->next = &oscStates[i+1];
item = item->next;
}
item->next = NULL;
arg0->initOsc = initOsc;
arg0->updateOsc = updateOsc;
arg0->stopOsc = stopOsc;
}
void func_8023FB1C(void){
D_8027D000 = (u8 *) malloc(0x21000);
bzero(D_8027D000, 0x21000);
alHeapInit(&D_8027CFF0, D_8027D000, 0x21000);
if(D_80000300 != 1)
osViClock = 0x2e6025c;
func_8023FBB8();
func_80335220();
func_8024F4E0();
amgrStartThread();
}
//amgrCreate
void func_8023FBB8(void) {
int i;
osCreateMesgQueue(&D_8027D008, &D_8027D020, 0x32);
osCreateMesgQueue(&g_AudioManager.audioReplyMsgQ, g_AudioManager.audioReplyMsgBuf, 8); //audioReplyMesgQueue
osCreateMesgQueue(&g_AudioManager.audioFrameMsgQ, g_AudioManager.audioFrameMsgBuf, 8);
D_8027DD74 = (s32)D_80277638;
if ((f32) D_8027DD74 < D_80277638) {
D_8027DD74++;
}
D_8027DD74 = ((D_8027DD74 / 0xB8) * 0xB8) + 0xB8;
D_8027DD78 = D_8027DD74 - 0xB8;
D_8027DD7C = D_8027DD74;
D_8027DD50.maxVVoices = 0x18;
D_8027DD50.maxPVoices = 0x18;
D_8027DD50.maxUpdates = 0x80;
D_8027DD50.dmaproc = (void*)func_802403B8;
D_8027DD50.fxType = AL_FX_CUSTOM;
D_8027DD50.params = (void*) &D_8027577C;
D_8027DD50.heap = &D_8027CFF0;
D_8027DD50.outputRate = osAiSetFrequency(22000);
func_8025C320(&D_8027DCD8, &D_8027DD50);
D_8027D5C0[0].unk0.prev = NULL;
D_8027D5C0[0].unk0.next = NULL;
for(i = 0; i < 89; i++){
alLink((ALLink *)&D_8027D5C0[i+1], (ALLink *)&D_8027D5C0[i]);
D_8027D5C0[i].unk10 = alHeapDBAlloc(0, 0, D_8027DD50.heap, 1, 0x200);
}
D_8027D5C0[i].unk10 = alHeapDBAlloc(0, 0, D_8027DD50.heap, 1, 0x200);
for(i = 0; i < 2; i++){
g_AudioManager.ACMDList[i] = malloc(20000);
}
D_8027DD80 = 2500;
for(i = 0; i < 3; i++){
g_AudioManager.audioInfo[i] = alHeapDBAlloc(0, 0, D_8027DD50.heap, 1, 0x10);
g_AudioManager.audioInfo[i]->unk8 = 0;
g_AudioManager.audioInfo[i]->unkC = g_AudioManager.audioInfo[i];
g_AudioManager.audioInfo[i]->data = malloc(D_8027DD7C * 4);
}
osCreateThread(&g_AudioManager.thread, 4, &func_8023FE80, 0, &D_8027CFF0, 0x32);
}
void func_8023FE80(void *arg0) {
s32 phi_s1;
phi_s1 = 1;
while(1){
osRecvMesg(&g_AudioManager.audioFrameMsgQ, NULL, OS_MESG_BLOCK);
if (amgr_handleFrameMsg(g_AudioManager.audioInfo[D_8027DCC8 % 3], D_80275848)){
if(phi_s1 == 0){
osRecvMesg(&g_AudioManager.audioReplyMsgQ, &D_80275844, OS_MESG_BLOCK);
amgrHandleDoneMsg(D_80275844->unk4);
D_80275848 = D_80275844->unk4;
}else{
phi_s1 += -1;
}
}
}
}
void func_8023FFAC(void){
D_80275770 = osAiGetLength()/4;
}
void func_8023FFD4(s32 arg0, s32 arg1, s32 arg2){
return;
}
bool amgr_handleFrameMsg(AudioInfo *info, AudioInfo *prev_info){
s16 *outbuffer;
Acmd *sp38;
s32 sp34;
s32 sp30 = 0;
f32 pad;
outbuffer = (s16 *)osVirtualToPhysical(info->data);
func_802403F0();
func_8023FFAC();
if(prev_info){
sp30 = osAiSetNextBuf(prev_info->data, prev_info->frameSamples*4);
}//L8024003C
if(sp30 == -1){
func_80247F24(2, 0x7d2);
func_80247F9C(prev_info->frameSamples);
func_80247F9C(info->frameSamples);
func_802483D8();
}
if((D_80275770 >= 0x139) & !D_80275778){
info->frameSamples = D_8027DD78;
D_80275778 = 2;
}
else{
info->frameSamples = D_8027DD74;
if(D_80275778)
D_80275778--;
}
if(info->frameSamples < D_8027DD78){
info->frameSamples = D_8027DD78;
}
sp38 = n_alAudioFrame(g_AudioManager.ACMDList[D_8027DCD0], &sp34, outbuffer, info->frameSamples);
if(D_8027DD80 < sp34){
func_80247F24(2, 2000);
func_80247F9C(sp34);
func_80247F9C(D_8027DD80);
func_802483D8();
}
if(sp34 == 0){
return 0;
}else{
func_802535A8(g_AudioManager.ACMDList[D_8027DCD0], sp38, &g_AudioManager.audioReplyMsgQ, &info->unk8);
func_80250650();
D_8027DCD0 ^= 1;
return 1;
}
}
void amgrHandleDoneMsg(AudioInfo *info)
{
static int D_8027584C = TRUE;
if (osAiGetLength() >> 2 == 0 && D_8027584C == FALSE) {
D_8027584C = FALSE;
}
}
#ifndef NONMATCHING
s32 func_80240204(s32 addr, s32 len, void *state);
#pragma GLOBAL_ASM("asm/nonmatchings/core1/code_1D00/func_80240204.s")
#else
s32 func_80240204(s32 addr, s32 len, void *state){
void *sp44;
s32 sp40;
Struct_1D00_3 *sp30;
Struct_1D00_3 *temp_s0;
ALLink *temp_s0_2;
Struct_1D00_3 *temp_s0_3;
Struct_1D00_3 *temp_v0_2;
s32 temp_t4;
s32 temp_v0_3;
s32 temp_v1;
u32 temp_a3;
u32 temp_v0;
void *temp_t0;
Struct_1D00_3 *phi_s0;
Struct_1D00_3 *phi_a2;
phi_s0 = D_8027D5B0.unk4;
sp30 = NULL;
while (temp_s0 != NULL) {
temp_v0 = phi_s0->unk8;
if (addr >= temp_v0) {
sp30 = phi_s0;
if ((temp_v0 + 0x200) >= (addr + len)) {
phi_s0->unkC = (s32) D_8027DCC8;
return osVirtualToPhysical((phi_s0->unk10 + addr) - temp_v0);
}
phi_s0 = phi_s0->unk0.next;
}
}
temp_s0_3 = D_8027D5B0.unk8;
if (temp_s0_3 == NULL) {
func_80247F24(2, 0x7D1, sp30, addr);
func_802483D8();
return osVirtualToPhysical(D_8027D5B0.unk4);
}
D_8027D5B0.unk8 = temp_s0_3->unk0.next;
alUnlink(temp_s0_3);
if (sp30 != NULL) {
alLink(temp_s0_3, sp30);
} else {
temp_v0_2 = D_8027D5B0.unk4;
if (temp_v0_2 != NULL) {
D_8027D5B0.unk4 = temp_s0_3;
temp_s0_3->unk0.next = (ALLink *)temp_v0_2;
temp_s0_3->unk0.prev = NULL;
temp_v0_2->unk0.prev = (ALLink *)temp_s0_3;
} else {
D_8027D5B0.unk4 = temp_s0_3;
temp_s0_3->unk0.next = NULL;
temp_s0_3->unk0.prev = NULL;
}
}
sp40 = addr & 1;
sp44 = temp_s0_3->unk10;
sp40 = temp_v0_3;
temp_s0_3->unk8 = addr - sp40;
temp_s0_3->unkC = (s32) D_8027DCC8;
osPiStartDma(&D_8027D100[D_8027DCCC++], 1, 0, temp_a3, sp44, 0x200U, &D_8027D008);
return osVirtualToPhysical(sp44) + sp40;
}
#endif
void *func_802403B8(void *state) {
if (D_8027D5B0.unk0 == 0) {
D_8027D5B0.unk4 = NULL;
D_8027D5B0.unk8 = &D_8027D5C0;
D_8027D5B0.unk0 = 1;
}
*(void **)state = &D_8027D5B0;
return &func_80240204;
}
void func_802403F0(void) {
u32 phi_s0;
OSMesg sp40;
Struct_1D00_3 *phi_s1;
Struct_1D00_3 *phi_s0_2;
sp40 = NULL;
for(phi_s0 = 0; phi_s0 < D_8027DCCC; phi_s0++){
if (osRecvMesg(&D_8027D008, &sp40, 0) == -1) {
func_80247F24(2, 0x7D5);
func_80247F9C(D_8027DCCC);
func_80247F9C(phi_s0);
func_802483D8();
}
}
phi_s0_2 = D_8027D5B0.unk4;
while(phi_s0_2 != NULL){
phi_s1 = (Struct_1D00_3 *)phi_s0_2->unk0.next;
if (phi_s0_2->unkC + 1 < D_8027DCC8) {
if (phi_s0_2 == D_8027D5B0.unk4) {
D_8027D5B0.unk4 = phi_s0_2->unk0.next;
}
alUnlink(phi_s0_2);
if (D_8027D5B0.unk8 != NULL) {
alLink(&phi_s0_2->unk0, &D_8027D5B0.unk8->unk0);
} else {
D_8027D5B0.unk8 = phi_s0_2;
phi_s0_2->unk0.next = NULL;
phi_s0_2->unk0.prev = NULL;
}
}
phi_s0_2 = phi_s1;
}
D_8027DCCC = 0;
D_8027DCC8 += 1;
}
void amgrStopThread(void){
if(D_80275774){
D_80275774 = 0;
osStopThread(&g_AudioManager.thread);
}
}
void amgrStartThread(void){
if(D_80275774 == 0){
D_80275774 = 1;
osStartThread(&g_AudioManager.thread);
}
}
OSThread * amgrGetThread(void){
return &g_AudioManager.thread;
}
ALHeap * func_802405B8(void){
return &D_8027CFF0;
}
OSMesgQueue * func_802405C4(void){
return &D_8027D008;
}
OSIoMesg * func_802405D0(void){
return &D_8027D0E8;
}
OSMesgQueue * amgr_getFrameMesgQueue(void){
return &g_AudioManager.audioFrameMsgQ;
}

364
src/core1/code_1D5D0.c Normal file
View File

@@ -0,0 +1,364 @@
#include <ultra64.h>
#include "functions.h"
#include "variables.h"
#include "SnS.h"
#include "save.h"
void sns_init_parsing_params(s32 min, s32 max)
{
snsMinKeyToParse = min;
snsMaxKeyToParse = max;
snsParsedCurrPos = 0;
}
u32 sns_get_next_key_in_range(void)
{
while (snsParsedCurrPos < SNS_PAYLOAD_DATALEN)
{
if (snsParsedKeys[snsParsedCurrPos] >= snsMinKeyToParse
&& snsParsedKeys[snsParsedCurrPos] <= snsMaxKeyToParse)
return snsParsedKeys[snsParsedCurrPos++];
snsParsedCurrPos++;
}
return 0;
}
void sns_update_global_save_data_checksum(void)
{
s32 i;
/**
* Updates the save data checksum multiple times (?)
*
* Running this multiple times seems to achieve nothing.
* A debug leftover?
*/
for (i = 5; i != 0 && func_8033CD0C(&gSaveData); i--)
;
}
void sns_save_and_update_global_data(void)
{
s32 i;
/**
* Triggers a save of the global save data to EEPROM,
* and validates the checksum.
*/
if (func_8033CA9C(&gSaveData))
{
/**
* Failed, hide the evidence.
*
* Clears the entire global data area.
*/
gSaveData.sns.uEggYellow = FALSE;
gSaveData.sns.uEggRed = FALSE;
gSaveData.sns.uEggGreen = FALSE;
gSaveData.sns.uEggBlue = FALSE;
gSaveData.sns.uEggPink = FALSE;
gSaveData.sns.uEggCyan = FALSE;
gSaveData.sns.uIceKey = FALSE;
gSaveData.sns.cEggYellow = FALSE;
gSaveData.sns.cEggRed = FALSE;
gSaveData.sns.cEggGreen = FALSE;
gSaveData.sns.cEggBlue = FALSE;
gSaveData.sns.cEggPink = FALSE;
gSaveData.sns.cEggCyan = FALSE;
gSaveData.sns.cIceKey = FALSE;
gSaveData.snsw = gSaveData.snsw << SNS_NUM_FLAGS >> SNS_NUM_FLAGS ^ gSaveData.snsw;
for (i = 0; i < sizeof(gSaveData.UNUSED); i++)
gSaveData.UNUSED[i] = 0;
sns_update_global_save_data_checksum();
}
sns_unlock_parsed_items();
sns_update_global_save_data_checksum();
}
/**
* Scans N64 RDRAM for a valid payload, and if found,
* parses it for the key values and saves them internally.
*/
void sns_find_and_parse_payload(void)
{
struct SnsPayload *payload;
s32 i;
for (i = 0; i < SNS_PAYLOAD_DATALEN; i++)
snsParsedKeys[i] = 0;
payload = snspayload_find_payload_in_ram();
if (payload)
{
snspayload_rewind_incoming();
i = 0;
while (i < SNS_PAYLOAD_DATALEN)
{
u32 val = snspayload_get_next_key(payload);
snsParsedKeys[i] = val;
if (val)
i++;
else
i = SNS_PAYLOAD_DATALEN;
}
}
}
void sns_init_base_payloads(void)
{
snsBasePayloadPtr3 = snspayload_init_new_payload((struct SnsPayload *)0x803FFF00);
snsBasePayloadPtr4 = snspayload_init_new_payload((struct SnsPayload *)0x803A5C00);
snsBasePayloadPtr1 = snspayload_init_new_payload((struct SnsPayload *)func_8025484C(0x100));
snsBasePayloadPtr2 = snspayload_init_new_payload((struct SnsPayload *)func_80254898(0x100));
}
bool sns_get_or_set_key(bool state, struct SnsPayload *payload, s32 key, s32 mode)
{
if (mode == SNS_MODE_WRITE)
{
if (state)
snspayload_append_key_to_outgoing_payload(payload, key);
return state;
}
if (mode == SNS_MODE_READ)
{
/**
* A VERY roundabout way of simply searching through the
* parsed values to see if the given key is present.
*
* It feels like a leftover remnant from code written
* hastily during testing of SnS.
*/
sns_init_parsing_params(key, key);
return sns_get_next_key_in_range() ? TRUE : state;
}
return FALSE;
}
void sns_commit_collected_flags(s32 mode, struct SnsPayload *payload)
{
gSaveData.sns.cEggYellow = sns_get_or_set_key(gSaveData.sns.cEggYellow, payload, SNS_ITEM_COLLECTED_EggYellow, mode);
gSaveData.sns.cEggRed = sns_get_or_set_key(gSaveData.sns.cEggRed, payload, SNS_ITEM_COLLECTED_EggRed, mode);
gSaveData.sns.cEggGreen = sns_get_or_set_key(gSaveData.sns.cEggGreen, payload, SNS_ITEM_COLLECTED_EggGreen, mode);
gSaveData.sns.cEggBlue = sns_get_or_set_key(gSaveData.sns.cEggBlue, payload, SNS_ITEM_COLLECTED_EggBlue, mode);
gSaveData.sns.cEggPink = sns_get_or_set_key(gSaveData.sns.cEggPink, payload, SNS_ITEM_COLLECTED_EggPink, mode);
gSaveData.sns.cEggCyan = sns_get_or_set_key(gSaveData.sns.cEggCyan, payload, SNS_ITEM_COLLECTED_EggCyan, mode);
gSaveData.sns.cIceKey = sns_get_or_set_key(gSaveData.sns.cIceKey, payload, SNS_ITEM_COLLECTED_IceKey, mode);
}
void sns_commit_unlocked_flags(s32 mode, struct SnsPayload *payload)
{
gSaveData.sns.uEggYellow = sns_get_or_set_key(gSaveData.sns.uEggYellow, payload, SNS_ITEM_UNLOCKED_EggYellow, mode);
gSaveData.sns.uEggRed = sns_get_or_set_key(gSaveData.sns.uEggRed, payload, SNS_ITEM_UNLOCKED_EggRed, mode);
gSaveData.sns.uEggGreen = sns_get_or_set_key(gSaveData.sns.uEggGreen, payload, SNS_ITEM_UNLOCKED_EggGreen, mode);
gSaveData.sns.uEggBlue = sns_get_or_set_key(gSaveData.sns.uEggBlue, payload, SNS_ITEM_UNLOCKED_EggBlue, mode);
gSaveData.sns.uEggPink = sns_get_or_set_key(gSaveData.sns.uEggPink, payload, SNS_ITEM_UNLOCKED_EggPink, mode);
gSaveData.sns.uEggCyan = sns_get_or_set_key(gSaveData.sns.uEggCyan, payload, SNS_ITEM_UNLOCKED_EggCyan, mode);
gSaveData.sns.uIceKey = sns_get_or_set_key(gSaveData.sns.uIceKey, payload, SNS_ITEM_UNLOCKED_IceKey, mode);
}
void sns_unlock_parsed_items(void)
{
sns_commit_unlocked_flags(SNS_MODE_READ, NULL);
}
void sns_generate_payload(struct SnsPayload *payload)
{
snspayload_rewind_outgoing();
snspayload_append_key_to_outgoing_payload(payload, 1);
sns_commit_collected_flags(SNS_MODE_WRITE, payload);
snspayload_finalise_outgoing_payload(payload);
}
/**
* Writes payload to RAM for another Rareware game
* to read and parse after swapping cartridges.
*/
void sns_write_payload_over_heap(void)
{
s32 val2;
u32 i;
if (func_8023DB5C() <= 0x3B || snsToRestoreItems)
return;
sns_generate_payload(snsBasePayloadPtr2);
// memcpy
func_80254630(snsBasePayloadPtr3, snsBasePayloadPtr2, sizeof(*snsBasePayloadPtr2));
func_80254630(snsBasePayloadPtr4, snsBasePayloadPtr2, sizeof(*snsBasePayloadPtr2));
for (i = 1; i < 5; i++)
{
u32 val1 = func_80254BD0(&val2, i);
if (val1 && val2 > 0x4000)
{
s32 val3 = val1 - 0x400 + val2;
val1 -= val1 & 0x1FFF;
for (val1 += 0x2C00; val1 < val3; val1 += 0x2000)
// memcpy
func_80254630((void *)val1, snsBasePayloadPtr2, sizeof(*snsBasePayloadPtr2));
}
}
}
void sns_stub(void) {}
/**
* Dev flag: to boot straight to a specific map.
*
* This value is unused in the retail builds, but may have
* been used in debug builds.
*
* If TRUE, on boot, the game will start in the furnace fun
* portal room (used for testing furnace fun?)
*
* If FALSE, on boot, the game will start on the file select
* screen (skips all the logo cutscenes)
*/
bool DEBUG_use_special_bootmap(void)
{
return FALSE;
}
/**
* Dev flag: purpose unknown?
*/
bool func_8025B818(void)
{
return TRUE;
}
bool sns_get_item_state(enum StopNSwop_Item item, s32 set)
{
switch (item)
{
case SNS_ITEM_EGG_YELLOW: return set == SNS_COLLECTED ? gSaveData.sns.cEggYellow : gSaveData.sns.uEggYellow;
case SNS_ITEM_EGG_RED: return set == SNS_COLLECTED ? gSaveData.sns.cEggRed : gSaveData.sns.uEggRed;
case SNS_ITEM_EGG_GREEN: return set == SNS_COLLECTED ? gSaveData.sns.cEggGreen : gSaveData.sns.uEggGreen;
case SNS_ITEM_EGG_BLUE: return set == SNS_COLLECTED ? gSaveData.sns.cEggBlue : gSaveData.sns.uEggBlue;
case SNS_ITEM_EGG_PINK: return set == SNS_COLLECTED ? gSaveData.sns.cEggPink : gSaveData.sns.uEggPink;
case SNS_ITEM_EGG_CYAN: return set == SNS_COLLECTED ? gSaveData.sns.cEggCyan : gSaveData.sns.uEggCyan;
case SNS_ITEM_ICE_KEY: return set == SNS_COLLECTED ? gSaveData.sns.cIceKey : gSaveData.sns.uIceKey;
default:
return FALSE;
}
}
void sns_set_item_state(enum StopNSwop_Item item, s32 set, s32 state)
{
if (set == SNS_COLLECTED)
{
switch (item)
{
case SNS_ITEM_EGG_YELLOW: gSaveData.sns.cEggYellow = state; return;
case SNS_ITEM_EGG_RED: gSaveData.sns.cEggRed = state; return;
case SNS_ITEM_EGG_GREEN: gSaveData.sns.cEggGreen = state; return;
case SNS_ITEM_EGG_BLUE: gSaveData.sns.cEggBlue = state; return;
case SNS_ITEM_EGG_PINK: gSaveData.sns.cEggPink = state; return;
case SNS_ITEM_EGG_CYAN: gSaveData.sns.cEggCyan = state; return;
// debug string?
case SNS_ITEM_ICE_KEY: gSaveData.sns.cIceKey = state; if (0); return;
default:
return;
}
}
else // SNS_UNLOCKED
{
switch (item)
{
case SNS_ITEM_EGG_YELLOW: gSaveData.sns.uEggYellow = state; return;
case SNS_ITEM_EGG_RED: gSaveData.sns.uEggRed = state; return;
case SNS_ITEM_EGG_GREEN: gSaveData.sns.uEggGreen = state; return;
case SNS_ITEM_EGG_BLUE: gSaveData.sns.uEggBlue = state; return;
case SNS_ITEM_EGG_PINK: gSaveData.sns.uEggPink = state; return;
case SNS_ITEM_EGG_CYAN: gSaveData.sns.uEggCyan = state; return;
case SNS_ITEM_ICE_KEY: gSaveData.sns.uIceKey = state; return;
default:
return;
}
}
}
void sns_set_item_and_update_payload(enum StopNSwop_Item item, s32 set, s32 state)
{
sns_set_item_state(item, set, state);
sns_update_global_save_data_checksum();
sns_write_payload_over_heap();
}
/**
* Used for the cutscene at the end of the game where Mumbo shows
* you Stop 'n' Swop hints.
*
* Backs up your item flags, then forces them all to be unlocked
* and not collected, so they can be seen during the hint sequences.
*/
void sns_backup_items_and_unlock_all(void)
{
u32 i;
if (snsToRestoreItems)
return;
sns_write_payload_over_heap();
snsToRestoreItems = TRUE;
// statements on same line for match (why?)
snsBackedUpItems = 0; for (i = 1; i < SNS_ITEM_length; i++)
{
snsBackedUpItems = (sns_get_item_state(i, SNS_UNLOCKED) ? 1 : 0) + (snsBackedUpItems << 1);
snsBackedUpItems = (sns_get_item_state(i, SNS_COLLECTED) ? 1 : 0) + (snsBackedUpItems << 1);
sns_set_item_state(i, SNS_UNLOCKED, TRUE);
sns_set_item_state(i, SNS_COLLECTED, FALSE);
}
}
/**
* Used when ending the cutscene where Mumbo shows you Stop 'n'
* Swop hints.
*
* It restores whatever item flags you had before it was triggered.
*/
void sns_restore_backed_up_items(void)
{
u32 i;
if (!snsToRestoreItems)
return;
for (i = SNS_ITEM_length - 1; i > 0; i--)
{
sns_set_item_state(i, SNS_COLLECTED, snsBackedUpItems & 1);
snsBackedUpItems >>= 1;
sns_set_item_state(i, SNS_UNLOCKED, snsBackedUpItems & 1);
snsBackedUpItems >>= 1;
}
snsToRestoreItems = FALSE;
}

47
src/core1/code_1E6E0.c Normal file
View File

@@ -0,0 +1,47 @@
#include <ultra64.h>
#include "functions.h"
#include "variables.h"
// transform seed (in mips3 file)
u32 func_8025C29C(u32 *seed);
void glcrc_calc_checksum(void *start, void *end, u32 checksum[2])
{
u8 *p;
u32 shift = 0;
u64 seed = 0x8F809F473108B3C1;
u32 crc1 = 0;
u32 crc2 = 0;
u32 tmp;
// CRC1: Iterate forwards over bytes
for (p = start; (void *)p < end; p++)
{
seed += *p << (shift & 15);
tmp = func_8025C29C(&seed);
shift += 7;
crc1 ^= tmp;
}
// CRC2: Iterate backwards over bytes
for (p = (u8 *)end - 1; (void *)p >= start; p--)
{
seed += *p << (shift & 15);
tmp = func_8025C29C(&seed);
shift += 3;
crc2 ^= tmp;
}
checksum[0] = crc1;
checksum[1] = crc2;
}

12
src/core1/code_1E820.c Normal file
View File

@@ -0,0 +1,12 @@
#include <ultra64.h>
#include "functions.h"
#include "variables.h"
s64 D_80376E70;
#pragma GLOBAL_ASM("asm/nonmatchings/core1/code_1E820/func_8025C240.s")
#pragma GLOBAL_ASM("asm/nonmatchings/core1/code_1E820/func_8025C288.s")
#pragma GLOBAL_ASM("asm/nonmatchings/core1/code_1E820/func_8025C29C.s")

86
src/core1/code_22E40.c Normal file
View File

@@ -0,0 +1,86 @@
#include <ultra64.h>
#include "functions.h"
#include "variables.h"
#pragma GLOBAL_ASM("asm/nonmatchings/core1/code_22E40/func_80260860.s")
#pragma GLOBAL_ASM("asm/nonmatchings/core1/code_22E40/func_802609E0.s")
#pragma GLOBAL_ASM("asm/nonmatchings/core1/code_22E40/func_80260BD4.s")
#pragma GLOBAL_ASM("asm/nonmatchings/core1/code_22E40/n_alEnvmixerPull.s")
void __postNextSeqEvent(ALSeqPlayer *seqp)
{
ALEvent evt;
s32 deltaTicks;
ALSeq *seq = seqp->target;
/* sct 1/5/96 - Do nothing if we're not playing or don't have a target sequence. */
if ((seqp->state != AL_PLAYING) || (seq == NULL))
return;
/* Get the next event time in ticks. */
/* If false is returned, then there is no next delta (ie. end of sequence reached). */
if (!__alSeqNextDelta(seq, &deltaTicks))
return;
/* Handle loops. */
if (seqp->loopCount)
{
/* Assume that the loop end falls on a MIDI event. Delta time
will be correct even if we loop */
if (alSeqGetTicks(seq) + deltaTicks >= seqp->loopEnd->curTicks)
{
alSeqSetLoc(seq, seqp->loopStart);
if (seqp->loopCount != -1)
seqp->loopCount--;
}
}
evt.type = AL_SEQ_REF_EVT;
//alEvtqPostEvent(&seqp->evtq, &evt, deltaTicks * seqp->uspt);
alEvtqPostEvent(&seqp->evtq, &evt, deltaTicks * seqp->uspt);
}
#pragma GLOBAL_ASM("asm/nonmatchings/core1/code_22E40/__setInstChanState.s")
#pragma GLOBAL_ASM("asm/nonmatchings/core1/code_22E40/func_80261348.s")
#pragma GLOBAL_ASM("asm/nonmatchings/core1/code_22E40/__initFromBank.s")
#pragma GLOBAL_ASM("asm/nonmatchings/core1/code_22E40/func_80261490.s")
#pragma GLOBAL_ASM("asm/nonmatchings/core1/code_22E40/__vsDelta.s")
#pragma GLOBAL_ASM("asm/nonmatchings/core1/code_22E40/__vsVol.s")
#pragma GLOBAL_ASM("asm/nonmatchings/core1/code_22E40/__seqpReleaseVoice.s")
#pragma GLOBAL_ASM("asm/nonmatchings/core1/code_22E40/__voiceNeedsNoteKill.s")
#pragma GLOBAL_ASM("asm/nonmatchings/core1/code_22E40/__unmapVoice.s")
#pragma GLOBAL_ASM("asm/nonmatchings/core1/code_22E40/func_802617A0.s")
#pragma GLOBAL_ASM("asm/nonmatchings/core1/code_22E40/__vsPan.s")
#pragma GLOBAL_ASM("asm/nonmatchings/core1/code_22E40/__lookupVoice.s")
#pragma GLOBAL_ASM("asm/nonmatchings/core1/code_22E40/__mapVoice.s")
#pragma GLOBAL_ASM("asm/nonmatchings/core1/code_22E40/__lookupSoundQuick.s")
#pragma GLOBAL_ASM("asm/nonmatchings/core1/code_22E40/func_80261A94.s")
#pragma GLOBAL_ASM("asm/nonmatchings/core1/code_22E40/func_802623F4.s")
#pragma GLOBAL_ASM("asm/nonmatchings/core1/code_22E40/func_802623FC.s")
#pragma GLOBAL_ASM("asm/nonmatchings/core1/code_22E40/__seqpStopOsc.s")
#pragma GLOBAL_ASM("asm/nonmatchings/core1/code_22E40/__initChanState.s")
#pragma GLOBAL_ASM("asm/nonmatchings/core1/code_22E40/func_80262BFC.s")

16
src/core1/code_25E20.c Normal file
View File

@@ -0,0 +1,16 @@
#include <ultra64.h>
#include "functions.h"
#include "variables.h"
void func_80263840(void){}
void func_80263848(void){}
#pragma GLOBAL_ASM("asm/nonmatchings/core1/code_25E20/func_80263850.s")
#pragma GLOBAL_ASM("asm/nonmatchings/core1/code_25E20/func_802639FC.s")
void func_80263B1C(void){}
void func_80263B24(void){}

8
src/core1/code_26110.c Normal file
View File

@@ -0,0 +1,8 @@
#include <ultra64.h>
#include "functions.h"
#include "variables.h"
n_alSynSetPriority(ALVoice *voice, s16 priority){
voice->priority = priority;
}

42
src/core1/code_2BD0.c Normal file
View File

@@ -0,0 +1,42 @@
#include <ultra64.h>
#include "functions.h"
#include "variables.h"
OSIoMesg D_8027E090;
OSMesg D_8027E0A8;
OSMesgQueue D_8027E0AC;
OSMesg D_8027E0C8[16]; //g_PimgrMesgBuffer
OSMesgQueue D_8027E108; //g_PimgrMesgQueue
#ifndef NONMATCHING
#pragma GLOBAL_ASM("asm/nonmatchings/core1/code_2BD0/func_802405F0.s")
#else
void func_802405F0(u32 arg0, u32 arg1, s32 size){
int i;
s32 block_cnt;
s32 block_remainder;
s32 block_size = 0x20000;
osWritebackDCache(arg0, size);
block_cnt = size/block_size;
for(i = 0; i < block_cnt; i++){
osPiStartDma(&D_8027E090, OS_MESG_PRI_NORMAL, OS_READ, arg1, arg0, block_size, &D_8027E0AC);
osRecvMesg(&D_8027E0AC, NULL, 1);
arg0 += 0x20000;
arg1 += 0x20000;
}
block_remainder = size%0x20000;
osPiStartDma(&D_8027E090, OS_MESG_PRI_NORMAL, OS_READ, arg1, arg0, block_remainder, &D_8027E0AC);
osRecvMesg(&D_8027E0AC, NULL, 1);
osInvalDCache(arg0, size);
}
#endif
void func_80240754(void){
osCreateMesgQueue(&D_8027E0AC, &D_8027E0A8, 1);
osCreateMesgQueue(&D_8027E108, &D_8027E0C8[0], 16);
osCreatePiManager(OS_PRIORITY_PIMGR, &D_8027E108, &D_8027E0C8[0], 16);
}

57
src/core1/code_2DA0.c Normal file
View File

@@ -0,0 +1,57 @@
#include <ultra64.h>
#include "functions.h"
#include "variables.h"
void func_80240924(s32 arg0);
OSMesgQueue D_8027E120;
OSMesg D_8027E138;
OSMesgQueue D_8027E140;
OSMesg D_8027E158;
OSThread D_8027E160;
u8 pad_8027E310[0x800];
extern u8 D_8027EB10;
/* .code */
void func_802407C0(void){
osCreateMesgQueue(&D_8027E120, &D_8027E138, 1);
osCreateMesgQueue(&D_8027E140, &D_8027E158, 1);
osCreateThread(&D_8027E160, 2, func_80240924, NULL, &D_8027EB10, 10);
osStartThread(&D_8027E160);
}
void func_80240844(void){
osStopThread(&D_8027E160);
osDestroyThread(&D_8027E160);
}
void func_80240874(void){
if(func_8023E000() == 3){
osSendMesg(&D_8027E120, NULL, OS_MESG_BLOCK);
}
}
void func_802408B0(void){
if(func_8023E000() == 3){
osSendMesg(&D_8027E140, NULL, OS_MESG_BLOCK);
}
}
void func_802408EC(OSPri pri){
if(func_8023E000() == 3){
osSetThreadPri(&D_8027E160, pri);
}
}
void func_80240924(s32 arg0){
int tmp_v0;
do{
osRecvMesg(&D_8027E120, NULL, OS_MESG_BLOCK);
if(!D_8027E140.validCount){
do{
tmp_v0 = func_802E48D8();
}while(!D_8027E140.validCount && tmp_v0);
}
osRecvMesg(&D_8027E140, NULL, OS_MESG_BLOCK);
}while(1);
}

68
src/core1/code_2FA0.c Normal file
View File

@@ -0,0 +1,68 @@
#include <ultra64.h>
#include "functions.h"
#include "variables.h"
s32 D_80275860 = 0;
void func_802409C0(f32 arg0[3], f32 arg1){
f32 sp3C[3];
f32 sp30[3];
f32 sp28[2];
f32 sp24;
sp24 = time_getDelta()*arg1;
func_8024E71C(0, sp28);
sp30[0] = sp28[0] * sp24;
sp30[1] = 0.0f;
sp30[2] = -(sp28[1] * sp24);
func_8024C764(&sp3C);
ml_vec3f_yaw_rotate_copy(sp30, sp30, sp3C[1]);
arg0[0] = arg0[0] + sp30[0];
arg0[1] = arg0[1] + sp30[1];
arg0[2] = arg0[2] + sp30[2];
}
void func_80240A74(f32 arg0[3]){
func_802409C0(arg0, 400.0f);
}
f32 func_80240A94(s32 arg0, f32 arg1){
if(arg0 >= 0x29){
arg0 = 0x28;
}
return arg1 + (f32)arg0*(arg1)/16 ;
}
void func_80240AC8(f32 arg0[3], f32 arg1){
f32 sp3C[3];
f32 sp30[3];
f32 sp28[2];
f32 sp24;
sp24 = time_getDelta()*arg1;
func_8024E71C(0, sp28);
if(0.0f != sp28[0] || 0.0f != sp28[1]){
D_80275860++;
if(D_80275860 >= 0x12D)
D_80275860 = 0x12C;
}
else{
D_80275860 = 1;
}
sp24 = func_80240A94(D_80275860, sp24);
sp30[0] = sp28[0] * sp24;
sp30[1] = 0.0f;
sp30[2] = -(sp28[1] * sp24);
func_8024C764(&sp3C);
ml_vec3f_yaw_rotate_copy(sp30, sp30, sp3C[1]);
arg0[0] = arg0[0] + sp30[0];
arg0[1] = arg0[1] + sp30[1];
arg0[2] = arg0[2] + sp30[2];
}

123
src/core1/code_31C0.c Normal file
View File

@@ -0,0 +1,123 @@
#include <ultra64.h>
#include "functions.h"
#include "variables.h"
extern f64 D_80277640;
u8 D_8027EB10[0x200]; // Size based on the previous symbol's address
OSThread D_8027ED10;
void func_80240C30(void*);
void func_80240BE0(void){
osCreateThread(&D_8027ED10, 1, func_80240C30, NULL, &D_8027EB10[0x200], 0);
osStartThread(&D_8027ED10);
}
void func_80240754(void);
void func_8023E018(void);
OSThread *func_8023E060(void);
void func_80240C30(void *arg)
{
func_80240754();
func_8023E018();
osStartThread(func_8023E060());
while (1);
}
static void _guMtxF2L(float mf[4][4], Mtx *m)
{
int i, j;
int e1,e2;
int *ai,*af;
ai=(int *) &m->m[0][0];
af=(int *) &m->m[2][0];
for (i=0; i<4; i++)
for (j=0; j<2; j++) {
e1=FTOFIX32(mf[i][j*2]);
e2=FTOFIX32(mf[i][j*2+1]);
*(ai++) = ( e1 & 0xffff0000 ) | ((e2 >> 16)&0xffff);
*(af++) = ((e1 << 16) & 0xffff0000) | (e2 & 0xffff);
}
}
static void _guMtxIdentF(float mf[4][4])
{
int i, j;
for (i=0; i<4; i++)
for (j=0; j<4; j++)
if (i == j) mf[i][j] = 1.0;
else mf[i][j] = 0.0;
}
void guScaleF(float mf[4][4], float x, float y, float z)
{
_guMtxIdentF(mf);
mf[0][0] = x;
mf[1][1] = y;
mf[2][2] = z;
mf[3][3] = 1;
}
void func_80240E4C(f32 mf[4][4], LookAt *l, float xEye, float yEye, float zEye,
float xAt, float yAt, float zAt,
float xUp, float yUp, float zUp);
#pragma GLOBAL_ASM("asm/nonmatchings/core1/code_31C0/func_80240E4C.s")
void func_8024128C (Mtx *m, LookAt *l, float xEye, float yEye, float zEye,
float xAt, float yAt, float zAt,
float xUp, float yUp, float zUp)
{
float mf[4][4];
func_80240E4C(mf, l, xEye, yEye, zEye, xAt, yAt, zAt,
xUp, yUp, zUp);
guMtxF2L(mf, m);
}
void guScale(Mtx *m, float x, float y, float z)
{
float mf[4][4];
guScaleF(mf, x, y, z);
_guMtxF2L(mf, m);
}
void guRotateRPYF(f32 mf[4][4], f32 r, f32 p, f32 h) {
static f32 dtor = 3.1415926 / 180.0;
s32 pad;
f32 sinp, sinh, sinr;
f32 cosp, cosh, cosr;
r *= dtor;
p *= dtor;
h *= dtor;
sinr = sinf(r);
cosr = cosf(r);
sinp = sinf(p);
cosp = cosf(p);
sinh = sinf(h);
cosh = cosf(h);
guMtxIdentF(mf);
mf[0][0] = cosp * cosh;
mf[0][1] = cosp * sinh;
mf[0][2] = -sinp;
mf[1][0] = (sinr*sinp*cosh - cosr*sinh);
mf[1][1] = (sinr*sinp*sinh + cosr*cosh);
mf[1][2] = (sinr*cosp);
mf[2][0] = (cosr*sinp*cosh + sinr*sinh);
mf[2][1] = (cosr*sinp*sinh - sinr*cosh);
mf[2][2] = (cosr*cosp);
}

625
src/core1/code_3A70.c Normal file
View File

@@ -0,0 +1,625 @@
#include <ultra64.h>
#include "functions.h"
#include "variables.h"
#include "n_libaudio.h"
void func_802444C0(Struct81s *arg0);
void func_80244050(ALEventQueue *arg0, Struct81s *arg1, u16 arg2);
extern Gfx D_80275880[];
extern f64 D_80277650;
extern f64 D_80277658;
/* .code */
void func_80241490(Gfx **gfx, Vtx **vtx, s32 *arg2[3], s32 arg3[3], s32 arg4[3], s32 arg5[3], s32 arg6, s32 arg7) {
s32 spB4[3];
s32 var_a0;
s32 var_v0;
s32 var_v1;
s32 sp78[3][4];
s32 i;
func_8024C5F0(&spB4);
gSPDisplayList((*gfx)++, D_80275880);
if (arg6 != 0) {
gSPSetGeometryMode((*gfx)++, G_ZBUFFER | G_CULL_BACK);
} else {
gSPSetGeometryMode((*gfx)++, G_ZBUFFER | G_CULL_FRONT);
}
gSPVertex((*gfx)++, *vtx, 8, 0);
for(i = 0; i < 2; i++){
for(var_a0 = 0; var_a0 < 2; var_a0++){
for(var_v1 = 0; var_v1 < 2; var_v1++){
var_v0 = (var_v1 == 0) ? arg2[0] : arg3[0];
(*vtx)->v.ob[0] = (s16) (var_v0 - spB4[0]);
var_v0 = (i == 0) ? arg2[1] : arg3[1];
(*vtx)->v.ob[1] = (s16) (var_v0 - spB4[1]);
var_v0 = (var_a0 == 0) ? arg2[2] : arg3[2];
(*vtx)->v.ob[2] = (s16) (var_v0 - spB4[2]);
(*vtx)->v.flag = 0;
(*vtx)->v.tc[0] = 0;
(*vtx)->v.tc[1] = 0;
(*vtx)->v.cn[0] = 0;
(*vtx)->v.cn[1] = 0;
(*vtx)->v.cn[2] = 0;
(*vtx)->v.cn[3] = 0;
(*vtx)++;
}
}
}
if (arg7 != 0) {
for(i = 0; i < 3; i++){
for(var_v1 = 0; var_v1 < 3; var_v1++){
sp78[i][var_v1] = (arg4[var_v1] * arg5[i]) / 255;
}
sp78[i][3] = 0xFF;
}
} else {
for(i = 0; i < 3; i++){
for(var_v1 = 0; var_v1 < 3; var_v1++){
sp78[i][var_v1] = arg4[var_v1];
}
sp78[i][3] = arg5[i];
}
}
gDPPipeSync((*gfx)++);
gDPSetPrimColor((*gfx)++, 0, 0, sp78[0][0], sp78[0][1], sp78[0][2], sp78[0][3]);
gSP2Triangles((*gfx)++, 7, 3, 5, 0, 5, 3, 1, 0);
gSP1Quadrangle((*gfx)++, 6, 4, 0, 2, 0);
gDPPipeSync((*gfx)++);
gDPSetPrimColor((*gfx)++, 0, 0, sp78[1][0], sp78[1][1], sp78[1][2], sp78[1][3]);
gSP1Quadrangle((*gfx)++, 7, 6, 2, 3, 0);
gSP2Triangles((*gfx)++, 4, 5, 0, 0, 5, 1, 0, 0);
gDPPipeSync((*gfx)++);
gDPSetPrimColor((*gfx)++, 0, 0, sp78[2][0], sp78[2][1], sp78[2][2], sp78[2][3]);
gSP1Quadrangle((*gfx)++, 5, 4, 6, 7, 0);
gSP2Triangles((*gfx)++, 0, 1, 2, 0, 1, 3, 2, 0);
}
#pragma GLOBAL_ASM("asm/nonmatchings/core1/code_3A70/func_80241928.s")
void func_802424D4(Gfx **gfx, Mtx **mtx, Vtx **vtx, f32 arg3[3], f32 arg4[3], f32 arg5, s32 arg6[4]) {
s32 var_a0;
s32 var_v0;
s32 var_v1;
f32 sp80[3];
f32 sp74[3];
f32 sp68[3];
f32 sp5C[3];
f32 sp50[3];
f32 sp44[3];
sp50[0] = arg4[0];
sp50[1] = arg4[1];
sp50[2] = arg4[2];
if ((arg3[0] != sp50[0]) || (arg3[1] != sp50[1]) || (arg3[2] != sp50[2])) {
if ((arg3[0] == sp50[0]) && (arg3[2] == sp50[2])) {
sp50[0] += D_80277658;
}
sp80[0] = sp50[0] - arg3[0];
sp80[1] = sp50[1] - arg3[1];
sp80[2] = sp50[2] - arg3[2];
ml_vec3f_normalize_copy(sp44, sp80);
sp74[0] = -sp44[2];
sp74[1] = 0.0f;
sp74[2] = sp44[0];
ml_vec3f_normalize(sp74);
sp74[0] *= arg5;
sp74[1] *= arg5;
sp74[2] *= arg5;
sp68[0] = (sp44[1] * sp74[2]) - (sp44[2]*sp74[1]);
sp68[1] = (sp44[2] * sp74[0]) - (sp44[0]*sp74[2]);
sp68[2] = (sp44[0] * sp74[1]) - (sp44[1]*sp74[0]);
ml_vec3f_normalize(sp68);
sp68[0] *= arg5;
sp68[1] *= arg5;
sp68[2] *= arg5;
func_8024C5CC(sp5C);
gSPDisplayList((*gfx)++, D_80275880);
gSPSetGeometryMode((*gfx)++, G_ZBUFFER);
gSPVertex((*gfx)++, *vtx, 8, 0);
for( var_a0 = 0; var_a0 < 2; var_a0++){
for(var_v0 = -1; var_v0 < 3; var_v0+=2) {
(*vtx)->v.ob[0] = (arg3[0] + (var_a0 * sp80[0]) + (var_v0 * sp74[0])) - sp5C[0];
(*vtx)->v.ob[1] = (arg3[1] + (var_a0 * sp80[1]) + (var_v0 * sp74[1])) - sp5C[1];
(*vtx)->v.ob[2] = (arg3[2] + (var_a0 * sp80[2]) + (var_v0 * sp74[2])) - sp5C[2];
(*vtx)->v.tc[0] = 0;
(*vtx)->v.tc[1] = 0;
(*vtx)->v.cn[0] = 0;
(*vtx)->v.cn[1] = 0;
(*vtx)->v.cn[2] = 0;
(*vtx)->v.cn[3] = 0;
(*vtx)++;
}
}
for( var_a0 = 0; var_a0 < 2; var_a0++){
for(var_v0 = -1; var_v0 < 3; var_v0+=2) {
(*vtx)->v.ob[0] = (arg3[0] + (var_a0 * sp80[0]) + (var_v0 * sp68[0])) - sp5C[0];
(*vtx)->v.ob[1] = (arg3[1] + (var_a0 * sp80[1]) + (var_v0 * sp68[1])) - sp5C[1];
(*vtx)->v.ob[2] = (arg3[2] + (var_a0 * sp80[2]) + (var_v0 * sp68[2])) - sp5C[2];
(*vtx)->v.tc[0] = 0;
(*vtx)->v.tc[1] = 0;
(*vtx)->v.cn[0] = 0;
(*vtx)->v.cn[1] = 0;
(*vtx)->v.cn[2] = 0;
(*vtx)->v.cn[3] = 0;
(*vtx)++;
}
}
gDPPipeSync((*gfx)++);
gDPSetPrimColor((*gfx)++, 0, 0, arg6[0], arg6[1], arg6[2], arg6[3]);
gSP1Quadrangle((*gfx)++, 0, 1, 3, 2, 0);
gSP1Quadrangle((*gfx)++, 4, 5, 7, 6, 0);
}
}
#pragma GLOBAL_ASM("asm/nonmatchings/core1/code_3A70/func_80242BE8.s")
// BREAK???===
extern struct{
Struct81s *unk0;
Struct81s *unk4;
Struct81s *unk8;
}D_802758C0;
extern N_ALSndPlayer *D_802758CC;
extern s32 D_802758D0;
extern s16 D_802758D4;
extern ALEventUnknown;
u8 pad_8027EEC0[0x54];
u16 *D_8027EF14;
extern struct {
u8 pad0[4];
s32 volume[3];
}D_8027EF18;
#pragma GLOBAL_ASM("asm/nonmatchings/core1/code_3A70/func_80243070.s")
// void func_80243070(void *arg0) {
// s16 sp40;
// ALLink *temp_a0;
// s32 var_s1;
// s32 var_v0;
// u32 var_s0;
// u32 var_s0_2;
// void *temp_s0;
// void *temp_s0_2;
// void *temp_s0_3;
// D_802758CC->maxSounds = (s32) arg0->unk8;
// D_802758CC->target = NULL;
// D_802758CC->frameTime = 33000;
// ;
// D_802758CC->sndState = alHeapDBAlloc(NULL, 0, arg0->unkC, 1, arg0->unk0 * sizeof(Struct81s));
// alEvtqNew(&D_802758CC->evtq, alHeapDBAlloc(NULL, 0, arg0->unkC, 1, arg0->unk4 * 0x1C), arg0->unk4);
// // var_s0 = 1;
// // var_s1 = 0x50;
// D_802758C0.unk8 = D_802758CC->sndState;
// if ((u32) arg0->unk0 >= 2U) {
// do {
// temp_a0 = var_s1 + D_802758CC->unk40;
// alLink(temp_a0, temp_a0 - 0x50);
// var_s0 += 1;
// var_s1 += 0x50;
// } while (var_s0 < (u32) arg0->unk0);
// }
// D_8027EF14 = alHeapDBAlloc(NULL, 0, arg0->unkC, 2, (s32) arg0->unk10);
// var_v0 = 0;
// var_s0_2 = 0;
// if (arg0->unk10 != 0) {
// do {
// var_s0_2 += 1;
// *(D_8027EF14 + var_v0) = 0x7FFF;
// var_v0 += 2;
// } while (var_s0_2 < (u16) arg0->unk10);
// }
// D_802758CC->unk0 = 0;
// D_802758CC->unk8 = &func_8024324C;
// temp_s0 = D_802758CC;
// temp_s0->unk4 = temp_s0;
// n_alSynAddSndPlayer(D_802758CC);
// temp_s0_2 = D_802758CC;
// sp40 = 0x20;
// alEvtqPostEvent(temp_s0_2 + 0x14, (ALEvent *) &sp40, temp_s0_2->unk48);
// temp_s0_3 = D_802758CC;
// D_802758CC->unk4C = alEvtqNextEvent(temp_s0_3 + 0x14, temp_s0_3 + 0x28);
// }
#ifndef NONMATCHING
#pragma GLOBAL_ASM("asm/nonmatchings/core1/code_3A70/func_8024324C.s")
#else
void func_8024324C(N_ALSndPlayer *arg0) {
N_ALEvent sp3C;
do {
if (arg0->nextEvent.type == 0x20) {
sp3C.type = 0x20;
alEvtqPostEvent(&arg0->evtq, (ALEvent *) &sp3C, arg0->frameTime);
func_80244190(arg0);
} else {
func_802432F8(arg0, &arg0->nextEvent);
}
arg0->nextDelta = alEvtqNextEvent(&arg0->evtq, &arg0->nextEvent);
} while (arg0->nextDelta == 0);
arg0->curTime += arg0->nextDelta;
}
#endif
#pragma GLOBAL_ASM("asm/nonmatchings/core1/code_3A70/func_802432F8.s")
void func_80243F84(Struct81s *arg0) {
if (arg0->unk3F & 4) {
n_alSynStopVoice(&arg0->voice);
n_alSynFreeVoice(&arg0->voice);
}
func_802444C0(arg0);
func_80244050(&D_802758CC->evtq, arg0, 0xFFFF);
}
void func_80243FE4(Struct81s *arg0) {
ALEvent evt;
f32 sp1C;
sp1C = alCents2Ratio(arg0->unk8->keyMap->detune)* arg0->unk2C;
evt.type = 0x10;
evt.msg.unk3A70.unk0 = arg0;
evt.msg.unk3A70.unk4 = reinterpret_cast(s32, sp1C);
alEvtqPostEvent(&D_802758CC->evtq, &evt, 33333);
}
void func_80244050(ALEventQueue *arg0, Struct81s *arg1, u16 arg2) {
s32 pad[5];
u32 mask;
ALEventListItem *next_event_list;
ALEventListItem *event_list;
mask = osSetIntMask(OS_IM_NONE);
for(event_list = (ALEventListItem *)arg0->allocList.next; event_list != NULL; event_list = next_event_list) {
next_event_list = (ALEventListItem *)event_list->node.next;
if ((arg1 == event_list->evt.msg.unk3A70.unk0) && (reinterpret_cast(u16, event_list->evt.type) & arg2)) {
if (next_event_list != NULL) {
next_event_list->delta += event_list->delta;
}
alUnlink((ALLink *)event_list);
alLink((ALLink *)event_list, (ALLink *)arg0);
}
}
osSetIntMask(mask);
}
s32 func_80244110(u16 *arg0, u16 *arg1) {
Struct81s *var_v0;
Struct81s *var_v1_2;
Struct81s *var_a2;
u16 var_a0;
u16 var_a3;
u16 var_v1;
var_v0 = D_802758C0.unk0;
var_v1_2 = D_802758C0.unk8;
var_a2 = D_802758C0.unk4;
for(var_a3 = 0; var_v0 != NULL; var_a3++){
var_v0 = (Struct81s *) var_v0->node.next;
}
for(var_a0 = 0; var_v1_2 != NULL; var_a0++) {
var_v1_2 = (Struct81s *) var_v1_2->node.next;
}
for(var_v1 = 0; var_a2 != NULL; var_v1++) {
var_a2 = (Struct81s *) var_a2->node.prev;
}
*arg0 = var_a0;
*arg1 = var_a3;
return var_v1;
}
#ifndef NONMATCHING
#pragma GLOBAL_ASM("asm/nonmatchings/core1/code_3A70/func_80244190.s")
#else
void func_80244190(Struct81s *arg0) {
ALMicroTime *temp_a1;
s32 prev_volume;
s32 temp_t1;
s32 temp_t5;
s32 var_t0;
ALMicroTime var_t1;
u8 temp_t6;
u8 var_a2;
ALEnvelope *envelope;
Struct81s *var_v0;
Struct81s *var_v1;
for(var_v0 = D_802758C0.unk0; var_v0 != NULL; var_v0 = (Struct81s *)var_v0->node.next){
var_v1 = var_v0;
envelope = var_v0->unk8->envelope;
temp_a1 = &envelope->attackTime;
D_8027EF18.volume[AL_PHASE_ATTACK] = (s32) envelope->attackVolume;
D_8027EF18.volume[AL_PHASE_DECAY] = (s32) envelope->decayVolume;
while( var_v0->envPhase < AL_PHASE_RELEASE
&& var_v0->unk48 >= temp_a1[var_v0->envPhase]
&& temp_a1[var_v0->envPhase] != -1
){
var_v0->unk48 -= temp_a1[var_v0->envPhase];
var_v0->envPhase++;
}
if (var_v0->envPhase < AL_PHASE_RELEASE) {
if (temp_a1[var_v1->envPhase] != -1) {
var_v0->unk44 = D_8027EF18.volume[var_v0->envPhase - 1] + ((s32) ((D_8027EF18.volume[var_v0->envPhase] - D_8027EF18.volume[var_v0->envPhase - 1]) * var_v0->unk48) / temp_a1[var_v0->envPhase]);
} else {
var_v0->unk44 = D_8027EF18.volume[var_v0->envPhase - 1]; //
}
}
var_v0->unk48 += arg0->unk48;
}
}
#endif
#ifndef NONMATCHING
#pragma GLOBAL_ASM("asm/nonmatchings/core1/code_3A70/func_8024431C.s")
#else
Struct81s *func_8024431C(ALBank *bank, ALSound *sound) {
s32 pad;
ALKeyMap *sp30;
Struct81s *temp_s0;
OSIntMask mask;
s32 sp24;
temp_s0 = D_802758C0.unk8;
sp30 = sound->keyMap;
if (temp_s0 != NULL) {
mask = osSetIntMask(OS_IM_NONE);
D_802758C0.unk8 = (Struct81s *) temp_s0->unk0.next;
alUnlink((ALLink *)temp_s0);
if (D_802758C0.unk0 != NULL) {
temp_s0->unk0.next = D_802758C0.unk0;
temp_s0->unk0.prev = NULL;
D_802758C0.unk0->unk0.prev = temp_s0;
D_802758C0.unk0 = temp_s0;
} else {
temp_s0->unk0.prev = NULL;
temp_s0->unk0.next = NULL;
D_802758C0.unk0 = temp_s0;
D_802758C0.unk4 = temp_s0;
}
osSetIntMask(mask);
sp24 = ((sound->envelope->decayTime + 1) == 0) + 0x40;
temp_s0->unk36 = sp24;
temp_s0->unk40 = 5;
temp_s0->unk38 = 2;
temp_s0->unk8 = sound;
temp_s0->unk2C = 1.0f;
temp_s0->unk3F = sp30->keyMax & 0xF0;
temp_s0->unk30 = 0;
temp_s0->envPhase = AL_PHASE_ATTACK;
temp_s0->unk44 = 0.0f;
temp_s0->unk48 = 0;
if (temp_s0->unk3F & 0x20) {
temp_s0->unk28 = alCents2Ratio((sp30->keyBase * 0x64) - 0x1770);
} else {
temp_s0->unk28 = alCents2Ratio(((sp30->keyBase * 0x64) + sp30->detune) - 0x1770);
}
if (sp24 != 0x40) {
temp_s0->unk3F |= 2;
}
temp_s0->unk3E = 0;
temp_s0->unk3D = 0x40;
temp_s0->unk34 = 0x7FFF;
}
return temp_s0;
}
#endif
void func_802444C0(Struct81s *arg0){
Struct81s *var_v0;
sizeof(ALVoice);
var_v0 = D_802758C0.unk0;
if(arg0 == D_802758C0.unk0){
D_802758C0.unk0 = (Struct81s *)arg0->node.next;
}
if(arg0 == D_802758C0.unk4){
D_802758C0.unk4 = (Struct81s *)arg0->node.prev;
}
alUnlink((ALLink *)arg0);
if(D_802758C0.unk8 != NULL){
arg0->node.next = (ALLink *)D_802758C0.unk8;
arg0->node.prev = NULL;
D_802758C0.unk8->node.prev = (ALLink *)arg0;
D_802758C0.unk8 = arg0;
}
else{
arg0->node.prev = NULL;
arg0->node.next = NULL;
D_802758C0.unk8 = arg0;
}
if(arg0->unk3F & 0x4){
D_802758D4--;
}
arg0->unk40 = 0;
if(arg0->unk30 != NULL){
if(*arg0->unk30 == arg0){
*arg0->unk30 = NULL;
}
arg0->unk30 = NULL;
}
}
void func_80244594(Struct81s *arg0, u8 arg1){
if(arg0 != NULL)
arg0->unk36 = arg1;
}
s32 func_802445AC(Struct81s *arg0){
if(arg0 != NULL)
return arg0->unk40;
return 0;
}
bool func_802445C4(ALBank *bank, s16 arg1){
ALSound *snd = bank->instArray[0]->soundArray[arg1-1];
if (snd->envelope->decayTime == -1)
return TRUE;
else
return FALSE;
}
void *func_80244608(ALBank *bank, s16 arg1, struct46s *arg2) {
ALKeyMap *temp_v0_2;
ALSound *temp_s2;
Struct81s *temp_v0;
s32 var_s3;
s16 sp6E;
s32 sp68;
s32 var_s4;
Struct81s *var_fp;
ALEvent sp50;
ALEvent sp40;
var_fp = NULL;
sp6E = 0;
var_s3 = 0;
if (arg1 == 0) {
return NULL;
}
do{
temp_s2 = bank->instArray[0]->soundArray[arg1-1];
temp_v0 = func_8024431C(bank, temp_s2);
if (temp_v0 != NULL) {
temp_v0->unk4C = (s32) (arg1 - 1);
D_802758CC->target = temp_v0;
sp50.type = AL_SEQ_MIDI_EVT;
((s32 *)&sp50.msg)[0] = temp_v0;
var_s4 = temp_s2->keyMap->velocityMax * 0x8235;
if (temp_v0->unk3F & 0x10) {
temp_v0->unk3F &= ~(0x10);
alEvtqPostEvent(&D_802758CC->evtq, (ALEvent *) &sp50, var_s3 + 1);
sp68 = var_s4 + 1;
sp6E = arg1;
} else {
alEvtqPostEvent(&D_802758CC->evtq, (ALEvent *) &sp50, var_s4 + 1);
}
var_fp = temp_v0;
}
temp_v0_2 = temp_s2->keyMap;
var_s3 += var_s4;
arg1 = temp_v0_2->velocityMin + ((temp_v0_2->keyMin & 0xC0) * 4);
} while (arg1 != 0 && temp_v0 != NULL);
if (var_fp != NULL) {
var_fp->unk3F |= 1;
var_fp->unk30 = arg2;
if (sp6E != 0) {
var_fp->unk3F |= 0x10;
sp40.type = 0x200;
((s32 *)&sp40.msg)[0] = var_fp;
((s32 *)&sp40.msg)[1] = sp6E;
((s32 *)&sp40.msg)[2] = bank;
alEvtqPostEvent(&D_802758CC->evtq, &sp40, sp68);
}
}
if (arg2 != NULL) {
arg2->unk0 = (s32) var_fp;
}
return var_fp;
}
void func_80244814(Struct81s *arg0){
ALEvent evt;
evt.type = 0x400;
((s32 *)&evt.msg)[0] = arg0;
if(arg0 != NULL){
arg0->unk3F &= ~(0x10);
alEvtqPostEvent(&D_802758CC->evtq, &evt, 0);
}
}
void func_80244860(u8 arg0) {
OSIntMask mask;
ALEvent evt;
Struct81s *var_s0;
mask = osSetIntMask(1U);
for(var_s0 = D_802758C0.unk0; var_s0 != NULL; var_s0 = (Struct81s *)var_s0->node.next){
evt.type = 0x400;
((s32 *)&evt.msg)[0] = (s32)var_s0;
if ((var_s0->unk3F & arg0) == arg0) {
var_s0->unk3F &= ~(0x10);
alEvtqPostEvent(&D_802758CC->evtq, &evt, 0);
}
}
osSetIntMask(mask);
}
void func_80244918(void){
func_80244860(1);
}
void func_80244938(void){
func_80244860(0x11);
}
void func_80244958(void){
func_80244860(3);
}
void func_80244978(s32 arg0, s16 type, s32 arg2){
ALEvent sp18;
if(arg0){
sp18.type = type;
((s32 *)&sp18.msg)[0] = arg0;
((s32 *)&sp18.msg)[1] = arg2;
alEvtqPostEvent(&D_802758CC->evtq, &sp18, 0);
}
}
s32 func_802449C4(u8 arg0){
return D_8027EF14[arg0];
}
void func_802449E4(u8 arg0, u16 arg1) {
Struct81s *var_s0;
s32 pad30;
ALEvent evt;
var_s0 = D_802758C0.unk0;
D_8027EF14[arg0] = arg1;
while(var_s0 != NULL){
if ((var_s0->unk8->keyMap->keyMin & 0x3F) == arg0) {
evt.type = 0x800;
((s32 *)&evt.msg)[0] = var_s0;
alEvtqPostEvent(&D_802758CC->evtq, &evt, 0);
}
var_s0 = (Struct81s *)var_s0->node.next;
}
}
void func_80244A98(s32 arg0){
D_802758D0 = arg0;
}

109
src/core1/code_660.c Normal file
View File

@@ -0,0 +1,109 @@
#include <ultra64.h>
#include "functions.h"
#include "variables.h"
#include "core1/rarezip.h"
static int _rarezip_uncompress(u8 **arg0, u8 **arg1, struct huft * arg2);
#define COMP_HEADER_SIZE 6
//border[]= { /* Order of the bit length code lengths */
u8 D_80275670[] = {
16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15
};
// static ush cplens[] = { /* Copy lengths for literal codes 257..285 */
u16 D_80275684[] = {
3, 4, 5, 6, 7, 8, 9, 10, 11, 13, 15, 17, 19, 23, 27, 31,
35, 43, 51, 59, 67, 83, 99, 115, 131, 163, 195, 227, 258, 0, 0
};
// /* note: see note #13 above about the 258 in this list. */
// static uch cplext[] = { /* Extra bits for literal codes 257..285 */
u8 D_802756C4[] = {
0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 2, 2,
3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 0, 99, 99
}; /* 99==invalid */
// static ush cpdist[] = { /* Copy offsets for distance codes 0..29 */
u16 D_802756E4[] = {
1, 2, 3, 4, 5, 7, 9, 13, 17, 25, 33, 49, 65, 97, 129, 193,
257, 385, 513, 769, 1025, 1537, 2049, 3073, 4097, 6145,
8193, 12289, 16385, 24577
};
// static uch cpdext[] = { /* Extra bits for distance codes */
u8 D_80275720[] = {
0, 0, 0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6,
7, 7, 8, 8, 9, 9, 10, 10, 11, 11,
12, 12, 13, 13
};
// ush mask_bits[] = {
u16 D_80275740[] = {
0x0000,
0x0001, 0x0003, 0x0007, 0x000f, 0x001f, 0x003f, 0x007f, 0x00ff,
0x01ff, 0x03ff, 0x07ff, 0x0fff, 0x1fff, 0x3fff, 0x7fff, 0xffff
};
s32 D_80275764 = 9; //lbits
s32 D_80275768 = 6; //dbits
/* .data */
extern struct huft D_803FBE00;
struct huft *D_8027BF00;
u8 pad_8027BF00[0xC];
u8 *D_8027BF10; //inbuf
u8 *D_8027BF14; //slide
u32 D_8027BF18; //inptr
u32 D_8027BF1C; //wp
struct huft *D_8027BF20; //unk
u32 D_8027BF24; //bb
u32 D_8027BF28; //bk
u32 D_8027BF2C; //crc1
u32 D_8027BF30; //crc2
u32 D_8027BF34; //hufts
/* .code */
s32 rarezip_get_uncompressed_size(u8 *arg0) {
return *((s32*) (arg0 + 2));
}
void rarezip_init(void){
D_8027BF00 = &D_803FBE00;
}
void rarezip_inflate(u8 *src, u8 *dst){
_rarezip_inflate(src, dst, D_8027BF00);
}
void rarezip_uncompress(u8 **srcPtr, u8 **dstPtr){
//updates in and out buffer ptrs,
_rarezip_uncompress(srcPtr, dstPtr, D_8027BF00);
}
void func_8023E0E8(void){
return;
}
static int _rarezip_inflate(u8 * src, u8 * dst, struct huft * arg2){
D_8027BF10 = src;
D_8027BF14 = dst;
D_8027BF20 = arg2;
D_8027BF10 += COMP_HEADER_SIZE;
D_8027BF1C = 0;
D_8027BF18 = 0;
inflate();
return D_8027BF1C;
}
static int _rarezip_uncompress(u8 **srcPtr, u8 **dstPtr, struct huft * arg2){
int result;
result = _rarezip_inflate(*srcPtr, *dstPtr, arg2);
*dstPtr = *dstPtr + D_8027BF1C;
*dstPtr = ((u32)*dstPtr & 0xF) ? ((u32)*dstPtr & -0x10) + 0x10: *dstPtr;
*srcPtr = *srcPtr + D_8027BF18 + COMP_HEADER_SIZE;
return result;
}

70
src/core1/code_7090.c Normal file
View File

@@ -0,0 +1,70 @@
#include <ultra64.h>
#include "functions.h"
#include "variables.h"
extern void sfxsource_setSampleRate(u8, s32);
extern void func_8030E2C4(u8);
typedef struct struct_27_s{
s16 unk0;
u8 pad2[0x12];
}struct27s;
extern s16 * D_802758E0;
void func_80244C78(int arg0);
/* .code */
void func_80244AB0(void){
int i;
if(D_802758E0)
return;
D_802758E0 = (struct16s *) malloc(10*sizeof(s16));
for(i = 0; i < 10; i++){
D_802758E0[i] = 0;
}
}
void func_80244B3C(void){
int i;
if(!D_802758E0)
return;
for(i = 0; i < 10; i++){
if(D_802758E0[i])
func_8030E394((u8)D_802758E0[i]);
}
free(D_802758E0);
D_802758E0 = NULL;
}
void func_80244BB0(s32 arg0, s32 arg1, s32 arg2, f32 arg3){
s32 i;
u8 indx;
if(func_8030ED70(func_80255D44(arg1))){
i = func_8030D90C();
indx = i;
if(i){
sfxsource_setSfxId(indx, func_80255D44(arg1));
func_8030DBB4(indx, arg3);
sfxsource_setSampleRate(indx, arg2);
func_8030E2C4(indx);
func_80244C78(arg0);
D_802758E0[arg0] = indx;
}
}
else{
func_8030E6A4(func_80255D44(arg1), arg3, arg2);
}
}
void func_80244C78(int arg0){
if(D_802758E0[arg0]){
func_8030DA44(D_802758E0[arg0]);
}
D_802758E0[arg0] = 0;
}

228
src/core1/code_72B0.c Normal file
View File

@@ -0,0 +1,228 @@
#include <ultra64.h>
#include "functions.h"
#include "variables.h"
int func_802458E0(f32 arg0[3], Actor *arg1, s32 arg2);
extern bool func_80320DB0(f32[3], f32, f32[3], u32);
extern bool func_80323240(struct56s *, f32, f32[3]);
extern f32 ml_vec3f_dot_product(f32[3], f32[3]);
extern Struct66s *func_80320B98(f32[3], f32[3], f32[3], u32);
/* .rodata */
extern f64 D_802776C8;
/* .bss */
u8 pad_D_8027EF20[0x10];
f32 D_8027EF30;
/* .code */
void func_80244CD0(f32 arg0[3], u32 arg1) {
f32 sp34[3];
f32 sp28[3];
f32 sp1C[3];
Struct66s *temp_v0;
ml_vec3f_copy(sp28, arg0);
ml_vec3f_copy(sp1C, arg0);
sp28[1] += 100.0f;
sp1C[1] -= 500.0f;
temp_v0 = func_80320B98(sp28, sp1C, sp34, arg1);
if ((temp_v0 != NULL) && (!(sp34[1] < 0.0f) || (temp_v0->unk8 & 0x10000)) && (arg0[1] < sp1C[1])) {
arg0[1] = sp1C[1];
}
}
Struct66s *func_80244D94(f32 arg0[3], f32 arg1[3], f32 arg2[3], u32 arg3, f32 arg4) {
f32 sp2C[3];
f32 sp20[3];
Struct66s *sp1C;
ml_vec3f_copy(sp20, arg1);
ml_vec3f_diff_copy(sp2C, sp20, arg0);
ml_vec3f_set_length_copy(sp2C, sp2C, arg4);
sp20[0] += sp2C[0];
sp20[1] += sp2C[1];
sp20[2] += sp2C[2];
sp1C = func_80320B98(arg0, sp20, arg2, arg3);
if (sp1C == NULL) {
return 0;
}
ml_vec3f_diff(sp20, sp2C);
ml_vec3f_copy(arg1, sp20);
return sp1C;
}
#pragma GLOBAL_ASM("asm/nonmatchings/core1/code_72B0/func_80244E54.s")
#pragma GLOBAL_ASM("asm/nonmatchings/core1/code_72B0/func_80244F00.s")
void func_80244FC0(f32 arg0[3], f32 arg1[3], f32 arg2, f32 arg3, s32 arg4, u32 arg5) {
f32 sp44[3];
f32 sp38[3];
f32 sp2C[3];
f32 pad[2];
sp2C[0] = arg0[0];
sp2C[1] = arg0[1] + arg3;
sp2C[2] = arg0[2];
ml_vec3f_copy(arg1, arg0);
if (func_80320DB0(sp2C, arg2, sp38, arg5)) {
arg1[0] = arg0[0] + (sp38[0] * arg2);
arg1[1] = arg0[1] + (sp38[1] * arg2);
arg1[2] = arg0[2] + (sp38[2] * arg2);
sp44[0] = arg0[0] + (sp38[0] * arg2);
sp44[1] = arg0[1] + (sp38[1] * arg2);
sp44[2] = arg0[2] + (sp38[2] * arg2);
ml_vec3f_copy(arg0, sp44);
if (arg4 != 0) {
func_80244CD0(arg0, arg5);
}
}
}
void func_802450DC(f32 arg0[3], f32 arg1[3], f32 arg2[3], f32 arg3[3], f32 arg4[3]) {
f32 sp3C[3];
f32 sp30[3];
f32 sp24[3];
f32 phi_f12;
ml_vec3f_diff_copy(sp3C, arg1, arg0);
ml_vec3f_diff_copy(sp30, arg3, arg2);
ml_vec3f_diff_copy(sp24, sp3C, sp30);
phi_f12 = -ml_vec3f_dot_product(arg4, sp24);
phi_f12 = MAX(5.0f, phi_f12);
arg1[0] += phi_f12 * arg4[0];
arg1[1] += phi_f12 * arg4[1];
arg1[2] += phi_f12 * arg4[2];
}
void func_802451A4(f32 arg0[3], f32 arg1[3], f32 arg2[3], f32 arg3[3], f32 arg4[3], s32 arg5) {
f32 sp6C[3];
f32 sp60[3];
f32 sp54[3];
f32 sp48[3];
f32 sp3C[3];
f32 sp30[3];
s32 phi_v0;
f32 sp28;
f32 phi_f12;
ml_vec3f_diff_copy(sp6C, arg1, arg0);
ml_vec3f_diff_copy(sp60, arg3, arg2);
ml_vec3f_diff_copy(sp54, sp6C, sp60);
ml_vec3f_normalize_copy(sp3C, sp54);
ml_vec3f_yaw_rotate_copy(sp30, sp3C, 90.0f);
sp28 = ml_vec3f_dot_product(arg4, sp3C);
if (arg5 != 0) {
D_8027EF30 = ml_vec3f_dot_product(arg4, sp30);
}
phi_v0 = (D_8027EF30 < 0.0f) ? -1 : 1;
ml_vec3f_yaw_rotate_copy(sp48, arg4,(phi_v0 * sp28) * D_802776C8);
phi_f12 = -ml_vec3f_dot_product(&sp48, &sp54);
phi_f12 = MAX(5.0f, phi_f12);
arg1[0] += phi_f12 * sp48[0];
arg1[1] += phi_f12 * sp48[1];
arg1[2] += phi_f12 * sp48[2];
}
bool func_80245314(f32 arg0[3], f32 arg1[3], f32 arg2, f32 arg3, s32 arg4) {
f32 sp2C[3];
f32 sp20[3];
bool temp_v0;
ml_vec3f_copy(sp2C, arg0);
ml_vec3f_copy(sp20, arg0);
sp2C[1] += arg2;
sp20[1] += arg3;
temp_v0 = func_80320B98(sp2C, sp20, arg1, arg4);
if (temp_v0 != 0) {
arg0[1] = sp20[1];
}
return temp_v0;
}
bool func_802453A0(f32 arg0[3], f32 arg1[3], f32 arg2[3]){
f32 sp24[3];
f32 sp18[3];
ml_vec3f_copy(sp18, arg1);
return func_80320B98(arg0, sp18, sp24, arg2);
}
f32 func_802453DC(f32 arg0[3], f32 arg1, f32 arg2[3], s32 arg3) {
f32 sp24[3];
f32 phi_f0;
func_80323240(arg0, arg1, sp24);
if (!func_802453A0(arg2, sp24, arg3)) {
return arg1;
}
func_80323240(arg0, 1.0f, sp24);
if (!func_802453A0(arg2, sp24, arg3)) {
return 1.0f;
}
func_80323240(arg0, 0.0f, sp24);
if (!func_802453A0(arg2, sp24, arg3)) {
return 0.0f;
}
return arg1;
}
//over_water?
int func_8024549C(f32 arg0[3], f32 arg1){
f32 sp44[3];
f32 sp38[3];
f32 sp2C[3];
f32 sp20[3];
int sp1C;
sp20[0] = sp20[1] = sp20[2] = 0.0f;
sp20[1] = arg1;
ml_vec3f_diff_copy(sp2C, arg0, sp20);
ml_vec3f_add(sp38, arg0, sp20);
sp1C = func_80309B48(sp2C, sp38, sp44, 0xf800ff0f);
if(sp1C){
ml_vec3f_copy(arg0, sp38);
}
return sp1C;
}
#pragma GLOBAL_ASM("asm/nonmatchings/core1/code_72B0/func_80245524.s")
#pragma GLOBAL_ASM("asm/nonmatchings/core1/code_72B0/func_8024559C.s")
#pragma GLOBAL_ASM("asm/nonmatchings/core1/code_72B0/func_8024560C.s")
#pragma GLOBAL_ASM("asm/nonmatchings/core1/code_72B0/func_8024575C.s")
#pragma GLOBAL_ASM("asm/nonmatchings/core1/code_72B0/func_802457C4.s")
void func_8024587C(Struct60s *dst, Struct60s *src){
dst->unk0[0] = src->unk0[0];
dst->unk0[1] = src->unk0[1];
dst->unk0[2] = src->unk0[2];
dst->unk8 = src->unk8;
dst->unk6 = src->unk6;
}
int func_802458A8(f32 arg0[3], ActorMarker *arg1, s32 arg2){
return func_802458E0(arg0, marker_getActor(arg1), arg2);
}
int func_802458E0(f32 arg0[3], Actor *arg1, s32 arg2){
f32 sp34[3];
f32 sp28[3];
f32 sp1C[3];
ml_vec3f_copy(sp28, arg0);
ml_vec3f_copy(sp1C, arg1->position);
sp1C[1] += (f32)arg2;
if(sp1C[1] < sp28[1])
return FALSE;
if(func_80320B98(sp28, sp1C, sp34, 0x25e0000)){
return FALSE;
}
return TRUE;
}

58
src/core1/code_7F60.c Normal file
View File

@@ -0,0 +1,58 @@
#include <ultra64.h>
#include "functions.h"
#include "variables.h"
#pragma GLOBAL_ASM("asm/nonmatchings/core1/code_7F60/func_80245980.s")
#pragma GLOBAL_ASM("asm/nonmatchings/core1/code_7F60/func_802459A0.s")
#pragma GLOBAL_ASM("asm/nonmatchings/core1/code_7F60/func_80245A7C.s")
// void func_80245A7C(Mtx *m0, Mtx *m1){
// u32 *v0 = &m1->m[0][0];
// u32 *v1 = &m1->m[2][0];
// f32 *a2 = &m0->m[0][0];
// s32 a0;
// s32 a1;
// int i;
// for(i = 0; i < 8; i++){
// a0 = a2[2*i]*65536.0f;
// a1 = a2[2*i+1]*65536.0f;
// v0[i] = (a0 & 0xffff0000) | ((a1 >> 16) & 0xffff);
// v1[i] = ((a0 << 16) & 0xffff0000) | (a1 & 0xffff);
// }
// }
#pragma GLOBAL_ASM("asm/nonmatchings/core1/code_7F60/func_80245BE4.s")
void _guMtxIdentF_80245D44(float mf[4][4]) //static
{
int i, j;
for (i=0; i<4; i++)
for (j=0; j<4; j++)
if (i == j) mf[i][j] = 1.0;
else mf[i][j] = 0.0;
}
#pragma GLOBAL_ASM("asm/nonmatchings/core1/code_7F60/func_80245DCC.s")
#pragma GLOBAL_ASM("asm/nonmatchings/core1/code_7F60/func_80245F34.s")
#pragma GLOBAL_ASM("asm/nonmatchings/core1/code_7F60/func_80245FB8.s")
#pragma GLOBAL_ASM("asm/nonmatchings/core1/code_7F60/guPerspective.s")
#pragma GLOBAL_ASM("asm/nonmatchings/core1/code_7F60/func_8024632C.s")
#pragma GLOBAL_ASM("asm/nonmatchings/core1/code_7F60/func_802464B0.s")
#pragma GLOBAL_ASM("asm/nonmatchings/core1/code_7F60/func_80246510.s")
#pragma GLOBAL_ASM("asm/nonmatchings/core1/code_7F60/func_80246570.s")
#pragma GLOBAL_ASM("asm/nonmatchings/core1/code_7F60/func_802465D0.s")
#pragma GLOBAL_ASM("asm/nonmatchings/core1/code_7F60/func_80246624.s")

392
src/core1/code_8C50.c Normal file
View File

@@ -0,0 +1,392 @@
#include <ultra64.h>
#include "functions.h"
#include "variables.h"
extern s32 D_80000300;
typedef struct {
s32 unk0;
s32 unk4;
s32 unk8;
s32 unkC;
}Struct_Core1_8C50_s;
void func_80247224(void);
#define CORE1_8C50_EVENT_DP 4
#define CORE1_8C50_EVENT_SP 6
#define CORE1_8C50_EVENT_AUDIO_TIMER 8
#define CORE1_8C50_EVENT_FAULT 10
#define CORE1_8C50_EVENT_PRENMI 11
#define CORE1_8C50_EVENT_CONT_TIMER 13
/* .data */
extern u64 D_80272590[]; // ucode
extern u64 D_802731F0[];
extern u64 D_80274620[];
extern OSTask D_80275910;
extern OSTask D_80275950;
extern s32 D_80275990;
extern s32 D_80275994;
extern s32 D_80275998;
extern s32 D_8027599C;
extern s32 D_802759A0;
// static s32 D_802759A4;
extern OSViMode D_802759A8;
extern OSViMode D_802759F8;
extern u64 D_80278E80[]; //ucode_data
extern u64 D_80279130[];
extern u64 D_80279930[];
/* .bss */
s32 D_8027EF40;
u8 D_8027EF44[0xC20];
OSMesgQueue D_8027FB60;
OSMesg D_8027FB78[20];
OSMesgQueue D_8027FBC8;
OSMesg D_8027FBE0[10];
Struct_Core1_8C50_s *D_8027FC08;
s32 D_8027FC0C;
bool D_8027FC10;
s32 D_8027FC14;
s32 D_8027FC18;
s32 D_8027FC1C;
s32 D_8027FC20;
s32 D_8027FC24;
u8 pad_8027FC28[0x7F8];
OSThread D_80280428;
Struct_Core1_8C50_s * D_802805D8[20];
volatile s32 D_80280628;
volatile s32 D_8028062C;
Struct_Core1_8C50_s * D_80280630[20];
volatile s32 D_80280680;
volatile s32 D_80280684;
s32 D_80280688;
OSTimer D_80280690; //audio_timer
OSTimer D_802806B0; //controller_timer
s32 D_802806D0;
/* .code */
void func_80246670(OSMesg arg0){
sizeof(OSThread);
osSendMesg(&D_8027FB60, arg0, 1);
if((s32) arg0 == 3 ){
D_80275994 = 0x1e;
if(D_802759A0){
osDpSetStatus(DPC_CLR_FREEZE);
D_802759A0 = 0;
}
osRecvMesg(&D_8027FBC8, NULL, 1);
D_80275994 = 0;
}
}
void func_802466F4(OSMesg arg0){
s32 tmp = (D_80280680 + 1) % 0x14;
if(D_80280684 != tmp){
D_80280630[D_80280680] = arg0;
D_80280680 = tmp;
}
}
void func_80246744(OSMesg arg0){
s32 tmp = (D_80280628 + 1) % 0x14;
if(D_8028062C != tmp){
D_802805D8[D_80280628] = arg0;
D_80280628 = tmp;
}
}
void func_80246794(Struct_Core1_8C50_s * arg0){
func_80255D0C(&D_80275910.t.ucode_boot, &D_80275910.t.ucode_boot_size);
D_80275910.t.ucode = D_80272590;
D_80275910.t.ucode_data = D_80278E80;
D_80275910.t.data_ptr = (void*) arg0->unk8;
D_80275910.t.data_size = (arg0->unkC - arg0->unk8) >> 3 << 3;
osWritebackDCache(D_80275910.t.data_ptr , D_80275910.t.data_size);
osWritebackDCache(&D_80275910, sizeof(OSTask));
D_8027FC08 = arg0;
osSpTaskLoad(&D_80275910);
osSpTaskStartGo(&D_80275910);
D_8027FC1C = 4;
}
void func_80246844(Struct_Core1_8C50_s * arg0){
func_80255D0C(&D_80275950.t.ucode_boot, &D_80275950.t.ucode_boot_size);
D_80275950.t.ucode = D_802731F0;
D_80275950.t.ucode_data = D_80279130;
D_80275950.t.data_ptr = (void*) arg0->unk8;
D_80275950.t.data_size = (arg0->unkC - arg0->unk8) >> 3 << 3;
osWritebackDCache(D_80275950.t.data_ptr , D_80275950.t.data_size);
osWritebackDCache(&D_80275950, sizeof(OSTask));
osSpTaskLoad(&D_80275950);
osSpTaskStartGo(&D_80275950);
D_8027FC1C = arg0->unk4 | 0x8;
D_8027FC18 = arg0->unk4 | 0x1;
if(!(osDpGetStatus() & DPC_STATUS_FREEZE)){
D_8027FC14 = D_8027FC18;
D_80275998 = 0x1e;
}
}
void func_8024692C(Struct_Core1_8C50_s * arg0){
func_80255D0C(&D_80275950.t.ucode_boot, &D_80275950.t.ucode_boot_size);
D_80275950.t.ucode = D_80274620;
D_80275950.t.ucode_data = D_80279930;
D_80275950.t.data_ptr = (void*) arg0->unk8;
D_80275950.t.data_size = (arg0->unkC - arg0->unk8) >> 3 << 3;
osWritebackDCache(D_80275950.t.data_ptr , D_80275950.t.data_size);
osWritebackDCache(&D_80275950, sizeof(OSTask));
osSpTaskLoad(&D_80275950);
osSpTaskStartGo(&D_80275950);
D_8027FC1C = arg0->unk4 | 0x8;
D_8027FC18 = arg0->unk4 | 0x1;
if(!(osDpGetStatus() & DPC_STATUS_FREEZE)){
D_8027FC14 = D_8027FC18;
D_80275998 = 0x1e;
}
}
void func_80246A14(Struct_Core1_8C50_s *arg0){
switch(arg0->unk0){
case 1:
func_80246844(arg0);
break;
case 2:
func_8024692C(arg0);
break;
}
}
void func_80246A64(OSMesg msg){
func_802466F4(msg);
}
void func_80246A84(OSMesg msg){
func_80246744(msg);
if(D_8027FC1C == 0x10 && !D_8027FC10){
func_80246844(D_802805D8[D_8028062C]);
D_8028062C = (D_8028062C + 1) % 0x14;
}
}
void func_80246B0C(OSMesg msg){
func_80246744(msg);
if(D_8027FC1C == 0x10 && !D_8027FC10){
func_8024692C(D_802805D8[D_8028062C]);
D_8028062C = (D_8028062C + 1) % 0x14;
}
}
void func_80246B94(void){
if( D_8027FC1C == 0x10
&& D_8027FC14 == 2
&& D_8028062C == D_80280628
&& !(osDpGetStatus() & DPC_STATUS_FREEZE)
){
osSendMesg(&D_8027FBC8, NULL, OS_MESG_NOBLOCK);
}
else{
D_8027FC0C++;
}
}
void func_80246C2C(void){
if((D_8027FC14 << 1) < 0){
osDpSetStatus(DPC_SET_FREEZE);
D_80280688 = osViGetCurrFrameBuffer();
func_8024BFAC();
}
D_8027FC14 = D_8027FC18 = 2;
D_80275998 = 0;
if(D_8027FC1C == 0x10 && D_8028062C != D_80280628 && !D_8027FC10){
func_80246A14(D_802805D8[D_8028062C]);
D_8028062C = (D_8028062C + 1) % 0x14;
}
else{
if(D_8027FC0C && D_8028062C == D_80280628 && !(osDpGetStatus() & DPC_STATUS_FREEZE)){
osSendMesg(&D_8027FBC8, NULL, 0);
D_8027FC0C--;
}
}
}
#ifndef NONMATCHING //MATCHES but requires .data defined for local static variable
#pragma GLOBAL_ASM("asm/nonmatchings/core1/code_8C50/func_80246D78.s")
#else
static s32 D_802759A4;
void func_80246D78(void){
s32 sp2C = (D_8027FC0C != 0) && (D_8028062C == D_80280628) && (D_8027FC18 == 2) && (D_8027FC1C == 0x10);
volatile s32 sp30;
sp30 = FALSE;
if( osViGetCurrFrameBuffer() != D_80280688 || sp2C){
if(osDpGetStatus() & DPC_STATUS_FREEZE){
osDpSetStatus(DPC_CLR_FREEZE);
D_8027FC14 = D_8027FC18;
func_8025AFB8();
if(D_8027FC14 & 1){
D_80275998 = 0x1E;
}
}
if(sp2C){
osSendMesg(&D_8027FBC8, NULL, OS_MESG_NOBLOCK);
D_8027FC0C--;
}
}
D_80275990 = 0;
if(D_80275994 != 0){
D_80275994--;
}
if(D_8027599C != 0){
D_8027599C--;
}
if(D_80275998 != 0){
D_80275998--;
if(D_80275998 == 0){
sp30 = TRUE;
}
}
D_8027FC10 = 0;
D_802759A4++;
if(!(D_802759A4 & 1)){
osStopTimer(&D_80280690);
osSetTimer(&D_80280690, 280000, 0, &D_8027FB60, CORE1_8C50_EVENT_AUDIO_TIMER);
}
if(D_802806D0){
osStopTimer(&D_802806B0);
osSetTimer(&D_802806B0, ((osClockRate / 60)* 2) / 3, 0, &D_8027FB60, CORE1_8C50_EVENT_CONT_TIMER);
}
}
#endif
#pragma GLOBAL_ASM("asm/nonmatchings/core1/code_8C50/func_80247000.s")
void func_802471D8(OSMesg arg0){
D_8027FC10 = TRUE;
}
void func_802471EC(void){
osSendMesg(amgr_getFrameMesgQueue(), NULL, OS_MESG_NOBLOCK);
func_80247224();
}
void func_80247224(void){
Struct_Core1_8C50_s *ptr;
if((D_8027FC1C == 0x10) && (D_80280684 != D_80280680)){
ptr = D_80280630[D_80280684];
D_80280684 = (D_80280684 + 1) % 0x14;
func_80246794(ptr);
} else if((D_8027FC1C & 0x8) && (D_80280684 != D_80280680)){
osSpTaskYield();
D_8027FC20 = D_8027FC1C;
D_8027FC1C = 0x20;
D_8027599C = 0x1E;
}
}
void func_80247304(void){};
void func_8024730C(void){
static s32 D_802806D4;
if(!D_802806D4){
D_802806D4 = TRUE;
if(D_80000300 != TRUE){
osViSetMode(&D_802759A8);
} else {
osViSetMode(&D_802759F8);
}
func_80250FC0(); //stop controller motors
do{
osDpSetStatus(DPC_STATUS_FLUSH);
}while(1);
}
}
void func_80247380(void){
if(!(___osGetSR() & SR_IBIT5)){
func_8024730C();
}
}
void func_802473B4(void *arg0){
OSMesg msg = NULL;
do{
osRecvMesg(&D_8027FB60, &msg, OS_MESG_BLOCK);
func_80247380();
if((s32)msg == 3){ func_80246B94(); }
else if((u32)msg == 5) { func_80246D78(); }
else if((u32)msg == CORE1_8C50_EVENT_DP) { func_80246C2C(); }
else if((u32)msg == CORE1_8C50_EVENT_SP) { func_80247000(); }
else if((u32)msg == CORE1_8C50_EVENT_AUDIO_TIMER) { func_802471EC(); }
else if((u32)msg == CORE1_8C50_EVENT_FAULT) { do{}while(1); }
else if((u32)msg == CORE1_8C50_EVENT_PRENMI) { func_8024730C(); }
else if((u32)msg == 12) { }
else if((u32)msg == CORE1_8C50_EVENT_CONT_TIMER) { func_8024F1B0(); }
else if((u32)msg >= 100) {
if(*(u32*)msg == 0){ func_80246A64(msg); }
else if(*(u32*)msg == 1){ func_80246A84(msg); }
else if(*(u32*)msg == 2){ func_80246B0C(msg); }
else if(*(u32*)msg == 7){ func_802471D8(msg); }
}
}while(1);
}
#ifndef NONMATCHING
#pragma GLOBAL_ASM("asm/nonmatchings/core1/code_8C50/func_80247560.s")
#else
void func_80247560(void){
u32 tmp_v0;
osCreateMesgQueue(&D_8027FB60, &D_8027FB78, 20);
osCreateMesgQueue(&D_8027FBC8, &D_8027FBE0, 10);
osSetEventMesg(OS_EVENT_DP, &D_8027FB60, CORE1_8C50_EVENT_DP);
osSetEventMesg(OS_EVENT_SP, &D_8027FB60, CORE1_8C50_EVENT_SP);
osSetEventMesg(OS_EVENT_FAULT, &D_8027FB60, CORE1_8C50_EVENT_FAULT);
osSetEventMesg(OS_EVENT_PRENMI, &D_8027FB60, CORE1_8C50_EVENT_PRENMI);
func_8024BDAC(&D_8027FB60, 5);
D_8027FC0C = 0;
D_8027FC10 = 0;
D_8027FC14 = D_8027FC18 = 2;
D_8027FC1C = D_8027FC20 = 0x10;
D_8027FC24 = 0;
D_80280628 = D_8028062C = 0;
D_80280680 = D_80280684 = 0;
for(tmp_v0 = &D_8027EF40; tmp_v0 & 0xF; tmp_v0++){}
D_80275950.yield_data_size = tmp_v0;
osCreateThread(&D_80280428, 5, func_802473B4, NULL, &D_80280428, 60);
osStartThread(&D_80280428);
}
#endif
void func_802476DC(void){
D_802806D0 = 1;
}
void func_802476EC(Gfx **gfx){
gDPPipeSync((*gfx)++);
gSPEndDisplayList((*gfx)++);
}
s32 func_80247720(void){
return D_8027FC1C;
}
OSMesgQueue *func_8024772C(void){
return &D_8027FB60;
}
OSThread *func_80247738(void){
return &D_80280428;
}

173
src/core1/code_9D30.c Normal file
View File

@@ -0,0 +1,173 @@
#include <ultra64.h>
#include "functions.h"
#include "variables.h"
void func_8024A840(s32 arg0, s32 arg1, s32 arg2);
void func_8024A85C(s32 arg0);
extern s16 D_80275BBC;
extern s16 D_80275BC4;
extern s16 D_80275BCC;
extern s16 D_80275BD0;
extern s16 D_80275BD4;
/* .bss */
s32 D_802806E0;
s32 D_802806E4;
s32 D_802806E8;
s32 D_802806EC;
#pragma GLOBAL_ASM("asm/nonmatchings/core1/code_9D30/func_80247750.s")
#pragma GLOBAL_ASM("asm/nonmatchings/core1/code_9D30/func_8024776C.s")
#pragma GLOBAL_ASM("asm/nonmatchings/core1/code_9D30/func_80247818.s")
#pragma GLOBAL_ASM("asm/nonmatchings/core1/code_9D30/func_802478C0.s")
void func_8024792C(void){}
#pragma GLOBAL_ASM("asm/nonmatchings/core1/code_9D30/func_80247934.s")
#pragma GLOBAL_ASM("asm/nonmatchings/core1/code_9D30/func_80247978.s")
#pragma GLOBAL_ASM("asm/nonmatchings/core1/code_9D30/func_802479E4.s")
#pragma GLOBAL_ASM("asm/nonmatchings/core1/code_9D30/func_80247A40.s")
#pragma GLOBAL_ASM("asm/nonmatchings/core1/code_9D30/func_80247A7C.s")
#pragma GLOBAL_ASM("asm/nonmatchings/core1/code_9D30/func_80247C20.s")
#pragma GLOBAL_ASM("asm/nonmatchings/core1/code_9D30/func_80247CEC.s")
#pragma GLOBAL_ASM("asm/nonmatchings/core1/code_9D30/func_80247D80.s")
#pragma GLOBAL_ASM("asm/nonmatchings/core1/code_9D30/func_80247F24.s")
void func_80247F9C(s32 arg0){
func_80247D80(D_80275BCC, arg0, 2);
func_802484D0();
}
#pragma GLOBAL_ASM("asm/nonmatchings/core1/code_9D30/func_80247FD0.s")
#pragma GLOBAL_ASM("asm/nonmatchings/core1/code_9D30/func_80248098.s")
#pragma GLOBAL_ASM("asm/nonmatchings/core1/code_9D30/func_8024824C.s")
#ifndef NONMATCHING
#pragma GLOBAL_ASM("asm/nonmatchings/core1/code_9D30/func_80248330.s")
#else
void func_80248330(u8 *arg0){
s32 i;
s32 val;
D_80275BC4 = D_80275BBC;
D_80275BD4 = 2;
for(i = 0; arg0[i] != 0; i++){
func_8024824C(arg0[i]);
func_80247CEC(D_80275BCC, arg0[i], 2);
}
func_80248520();
}
#endif
void func_802483B8(void){
D_80275BD0 = 1;
do{}while(1);
}
void func_802483D8(void){
s32 i;
D_80275BD0 = 1;
for(i = 30000000; i != 0; i--){}
D_80275BD0 = 0;
}
void func_80248404(s32 arg0){
s32 i;
D_80275BD0 = 1;
while(arg0 != 0){
for(i = 30000000; i != 0; i--){}
arg0--;
}
D_80275BD0 = 0;
}
#pragma GLOBAL_ASM("asm/nonmatchings/core1/code_9D30/func_80248444.s")
#pragma GLOBAL_ASM("asm/nonmatchings/core1/code_9D30/func_802484D0.s")
#pragma GLOBAL_ASM("asm/nonmatchings/core1/code_9D30/func_80248500.s")
#pragma GLOBAL_ASM("asm/nonmatchings/core1/code_9D30/func_80248520.s")
#pragma GLOBAL_ASM("asm/nonmatchings/core1/code_9D30/func_8024856C.s")
s32 func_802485BC(void){
return D_80275BD0;
}
#pragma GLOBAL_ASM("asm/nonmatchings/core1/code_9D30/func_802485C8.s")
#pragma GLOBAL_ASM("asm/nonmatchings/core1/code_9D30/func_802485D0.s")
#pragma GLOBAL_ASM("asm/nonmatchings/core1/code_9D30/func_80248870.s")
#pragma GLOBAL_ASM("asm/nonmatchings/core1/code_9D30/func_80248B40.s")
#pragma GLOBAL_ASM("asm/nonmatchings/core1/code_9D30/func_80248D40.s")
#pragma GLOBAL_ASM("asm/nonmatchings/core1/code_9D30/func_80248F9C.s")
#pragma GLOBAL_ASM("asm/nonmatchings/core1/code_9D30/func_80249210.s")
#pragma GLOBAL_ASM("asm/nonmatchings/core1/code_9D30/func_80249428.s")
#pragma GLOBAL_ASM("asm/nonmatchings/core1/code_9D30/func_80249644.s")
#pragma GLOBAL_ASM("asm/nonmatchings/core1/code_9D30/func_802499BC.s")
#pragma GLOBAL_ASM("asm/nonmatchings/core1/code_9D30/func_802499D0.s")
#pragma GLOBAL_ASM("asm/nonmatchings/core1/code_9D30/func_802499E4.s")
#pragma GLOBAL_ASM("asm/nonmatchings/core1/code_9D30/func_80249CEC.s")
#pragma GLOBAL_ASM("asm/nonmatchings/core1/code_9D30/func_80249DE0.s")
#pragma GLOBAL_ASM("asm/nonmatchings/core1/code_9D30/func_80249F34.s")
#pragma GLOBAL_ASM("asm/nonmatchings/core1/code_9D30/func_8024A284.s")
#pragma GLOBAL_ASM("asm/nonmatchings/core1/code_9D30/func_8024A3C8.s")
#pragma GLOBAL_ASM("asm/nonmatchings/core1/code_9D30/func_8024A490.s")
#pragma GLOBAL_ASM("asm/nonmatchings/core1/code_9D30/func_8024A564.s")
#pragma GLOBAL_ASM("asm/nonmatchings/core1/code_9D30/func_8024A770.s")
void func_8024A810(void){
func_8024A840(0, 0x80, 0);
func_8024A85C(0);
}
void func_8024A840(s32 arg0, s32 arg1, s32 arg2){
D_802806E0 = arg0;
D_802806E4 = arg1;
D_802806E8 = arg2;
}
void func_8024A85C(s32 arg0){
D_802806EC = arg0;
}
s32 func_8024A868(void){
return D_802806EC;
}

196
src/core1/code_E360.c Normal file
View File

@@ -0,0 +1,196 @@
#include <ultra64.h>
#include "functions.h"
#include "variables.h"
void func_8024BF94(s32 arg0);
void func_8024C2F8(void *);
typedef struct struct_1_s{
OSMesgQueue *messageQueue;
OSMesg message;
} struct1;
extern u32 D_80000300;
extern OSViMode D_80275C80;
extern OSViMode D_80275CD0;
u32 D_80280720;
u32 D_80280724;
u32 D_80280728;
struct1 D_80280730[8];
OSMesgQueue D_80280770;
OSMesgQueue D_802807B0;
OSMesgQueue D_802807D0;
volatile s32 D_802808D8;
s32 D_802808DC;
OSThread D_802808E0;
u8 pad_80280970[0x520];
extern u8 D_803A5D00[2][0x1ECC0]; //framebuffer
void func_8024C428(void);
/* .code */
bool func_8024BD80(void){
sizeof(OSThread);
return NOT(D_80280720);
}
s32 func_8024BD94(void){
return D_80280724;
}
s32 func_8024BDA0(void){
return D_80280720;
}
void func_8024BDAC(OSMesgQueue *mq, OSMesg msg){
s32 i;
for(i = 0; i < 8; i++){
if(D_80280730[i].messageQueue == NULL){
D_80280730[i].messageQueue = mq;
D_80280730[i].message = msg;
return;
}
}
}
void func_8024BE30(void){
extern s32 D_80280E90;
s32 i;
func_8024C428();
osCreateViManager(0xfe);
if(D_80000300 != 1)
osViSetMode(&D_80275CD0); //PAL
else
osViSetMode(&D_80275C80); //NTSC
osViSetSpecialFeatures(OS_VI_DITHER_FILTER_ON);
osViSetSpecialFeatures(OS_VI_GAMMA_OFF);
osViSwapBuffer(&D_803A5D00);
osCreateMesgQueue(&D_80280770, (&D_80280770 + 1), 10);
osCreateMesgQueue(&D_802807B0, (&D_802807B0 + 1), 1);
osCreateMesgQueue(&D_802807D0, (&D_802807D0 + 1), 0x3C);
osViSetEvent(&D_80280770,NULL,1);
D_80280720 = 0;
D_80280724 = 1;
D_80280728 = 0;
for(i = 0; i<8; i++){
D_80280730[i].messageQueue = NULL;
}
D_802808D8 = 0;
func_8024BF94(2);
osCreateThread(&D_802808E0,0,func_8024C2F8,NULL,&D_80280E90,0x50);
osStartThread(&D_802808E0);
}
void func_8024BF94(s32 arg0){
D_802808DC = arg0;
}
s32 func_8024BFA0(void){
return D_802808DC;
}
void func_8024BFAC(void){
osSendMesg(&D_802807B0, 0, OS_MESG_NOBLOCK);
}
void func_8024BFD8(s32 arg0){
static s32 D_80280E90;
osSetThreadPri(NULL, 0x7f);
func_802408EC(0x1E);
func_80240874();
if(arg0){
osRecvMesg(&D_802807B0, NULL, OS_MESG_BLOCK);
}
while(D_802808D8 < func_8024BFA0() - D_80280E90){
osRecvMesg(&D_802807D0, NULL, OS_MESG_BLOCK);
}
while(D_802807D0.validCount){
osRecvMesg(&D_802807D0, NULL, OS_MESG_NOBLOCK);
}
osViSwapBuffer(D_803A5D00[D_80280720 = func_8024BD80()]);
D_80280E90 = 0;
while(!(osDpGetStatus() & 2) && osViGetCurrFrameBuffer() != osViGetNextFrameBuffer()){
osRecvMesg(&D_802807D0, NULL, OS_MESG_BLOCK);
D_80280E90++;
}//L8024C178
D_80280724 = D_802808D8;
D_802808D8 = 0;
func_802408B0();
osSetThreadPri(NULL, 0x14);
func_802408EC(0xA);
}
void func_8024C1B4(void){
func_8024BFD8(0);
func_8025AFB8();
}
void func_8024C1DC(void){
func_8024BFD8(1);
}
void func_8024C1FC(OSMesgQueue *mq, OSMesg msg){
s32 i;
for(i = 0; i < 8; i++){
if(D_80280730[i].messageQueue == mq && D_80280730[i].message == msg){
D_80280730[i].messageQueue = NULL;
return;
}
}
}
void func_8024C2A0(s32 arg0) {
D_80280720 = arg0;
osViSwapBuffer(D_803A5D00[D_80280720]);
}
void func_8024C2F8(void *arg0){
s32 i;
OSMesg sp48;
do{
osRecvMesg(&D_80280770, &sp48, OS_MESG_BLOCK);
func_80247380();
D_802808D8++;
if(D_802808D8 == 420){
func_802485BC();
}
osSendMesg(&D_802807D0, NULL, OS_MESG_NOBLOCK);
for(i = 0; i < 8; i++){
if(D_80280730[i].messageQueue != NULL){
osSendMesg(D_80280730[i].messageQueue, D_80280730[i].message, OS_MESG_NOBLOCK);
}
}
}while(1);
}
void func_8024C408(s32 arg0){
osViBlack(arg0);
}
void func_8024C428(void) {
//zeros all both framebuffers
func_80253034(&D_803A5D00, 0, (s32) ((f32)D_80276588*2*D_8027658C*2));
osWritebackDCache(&D_803A5D00, (s32) ((f32)D_80276588*2* D_8027658C*2));
}
s32 func_8024C4E8(void){
return D_802808D8;
}
void func_8024C4F8(s32 arg0){
D_802808D8 = arg0;
}

575
src/core1/code_EAF0.c Normal file
View File

@@ -0,0 +1,575 @@
#include <ultra64.h>
#include "functions.h"
#include "variables.h"
extern void guPerspective(Mtx *, u16*, f32, f32, f32, f32, f32);
extern s32 D_A00001D8;
/* .data */
extern f32 D_80275D20; //fovy
extern f32 D_80275D24; //aspect
extern f32 D_80275D28; //near
extern f32 D_80275D2C; //far
extern s32 D_80275D38;
/* .rodata */
extern f64 D_802779F0;
extern f32 D_80277A08;
extern f64 D_80277A30;
extern f32 D_80277A00;
extern f32 D_80277A04;
extern f32 D_80277A0C;
extern f32 D_80277A10;
extern f32 D_80277A14;
extern f32 D_80277A18;
extern f32 D_80277A1C;
extern f32 D_80277A20;
/* .data */
f32 D_80280EA0[3];
f32 D_80280EB0[3];
f32 D_80280EC0[3];
f32 D_80280ECC;
f32 D_80280ED0[4][4];
Vp D_80280F10[8];
int D_80280F90;
Mtx D_80280F98;
Mtx D_80280FD8;
s32 D_80281018; //viewport indx
u8 pad_D_8028101C[0x104];
u8 D_80281130[0x188];
OSMesg D_802812B0;
OSMesg D_802812B4;
OSContPad D_802812B8[4];
OSContPad D_802812D0;
OSMesgQueue D_802812D8;
OSMesgQueue D_802812F0;
u8 pad_D_80281308[0x10];
OSContStatus D_80281318;
u8 pad_D_80281320[0x8];
s32 D_80281328;
OSThread D_80281330;
u8 pad_D_802814E0[0x200];
f32 D_802816E0;
OSMesgQueue D_802816E8;
OSMesg D_80281700[4];
u8 pad_D_80281710[1];
void func_8024F450(void);
void func_8024F4AC(void);
void func_8024C964(Gfx **, Mtx **, f32, f32);
void func_8024CD7C(int);
void func_8024CDF8(f32, f32, f32);
void func_8024CE40(f32, f32, f32);
void func_8024CE60(f32, f32);
void func_8024CE74(s32 arg0, s32 arg1, s32 arg2, s32 arg3);
void func_8024DDB4(f32);
void func_80256E24(f32 [3], f32, f32, f32, f32, f32);
/* .code */
void func_8024C510(f32 arg0){
f32 sp24[3];
func_80256E24(sp24, D_80280EC0[0], D_80280EC0[1], 0.0f, 0.0f, arg0);
D_80280EB0[0] += sp24[0];
D_80280EB0[1] += sp24[1];
D_80280EB0[2] += sp24[2];
}
void func_8024C584(f32 arg0[3]){
ml_vec3f_distance(arg0, D_80280EB0);
}
void func_8024C5A8(f32 arg0[3]){
ml_vec3f_copy(arg0, D_80280EA0);
}
void func_8024C5CC(f32 arg0[3]){
ml_vec3f_copy(arg0, D_80280EB0);
}
void func_8024C5F0(s32 dst[3]){
dst[0] = ((f32)(s32)(D_80280EB0[0]*500.0))/500.0;
dst[1] = ((f32)(s32)(D_80280EB0[1]*500.0))/500.0;
dst[2] = ((f32)(s32)(D_80280EB0[2]*500.0))/500.0;
}
void func_8024C6A0(s16 dst[3]){
dst[0] = ((f32)(s32)(D_80280EB0[0]*500.0))/500.0;
dst[1] = ((f32)(s32)(D_80280EB0[1]*500.0))/500.0;
dst[2] = ((f32)(s32)(D_80280EB0[2]*500.0))/500.0;
}
void func_8024C764(f32 arg0[3]){
ml_vec3f_copy(arg0, D_80280EC0);
}
f32 func_8024C788(void){
return D_80280EC0[1];
}
void func_8024C794(f32 *arg0, f32 *arg1, f32 *arg2){
*arg0 = D_80280EC0[0];
*arg1 = D_80280EC0[1];
*arg2 = D_80280EC0[2];
}
#ifndef NONMATCHING
#pragma GLOBAL_ASM("asm/nonmatchings/core1/code_EAF0/func_8024C7B8.s")
#else
void func_8024C7B8(Gfx **gfx, Mtx **mtx){
f32 tmp_f0;
f32 tmp_f16;
f32 tmp_f2;
f32 tmp_f18;
gSPViewport((*gfx)++, &D_80280F10[D_80281018]);
tmp_f0 = 2*(f32)D_80276588;
tmp_f2 = 2*(f32)D_8027658C;
guOrtho(*mtx, -tmp_f0, tmp_f0, -tmp_f2, tmp_f2, 1.0f, 20.0f, 1.0f);
gSPMatrix((*gfx)++, OS_PHYSICAL_TO_K0((*mtx)++), G_MTX_NOPUSH | G_MTX_LOAD | G_MTX_PROJECTION);
guTranslate(*mtx, 0.0f, 0.0f, 0.0f);
gSPMatrix((*gfx)++, OS_PHYSICAL_TO_K0((*mtx)++), G_MTX_NOPUSH | G_MTX_LOAD | G_MTX_MODELVIEW);
}
#endif
void func_8024C904(Gfx **gfx, Mtx **mtx){
gSPViewport((*gfx)++, &D_80280F10[D_80281018]);
func_8024C964(gfx, mtx, D_80275D28, D_80275D2C);
}
#ifndef NONMATCHING
#pragma GLOBAL_ASM("asm/nonmatchings/core1/code_EAF0/func_8024C964.s")
#else
void func_8024C964(Gfx **gfx, Mtx **mtx, f32 near, f32 far){
u16 sp5e;
near = MAX(D_80275D28, near);
far = MIN(D_80275D2C, far);
if(D_A00001D8 + 0x53D4FFF0){
near = D_80277A00;
far = D_80277A04;
}
guPerspective(*mtx, &sp5e, D_80275D20, D_80275D24, near, far, 0.5f);
gSPPerspNormalize((*gfx)++, sp5e);
gSPMatrix((*gfx)++, OS_PHYSICAL_TO_K0((*mtx)++), G_MTX_NOPUSH | G_MTX_LOAD | G_MTX_PROJECTION);
guRotate(*mtx, -D_80280EC0[2], 0.0f, 0.0f, -1.0f);
gSPMatrix((*gfx)++, OS_PHYSICAL_TO_K0((*mtx)++), G_MTX_NOPUSH | G_MTX_MUL | G_MTX_PROJECTION);
guRotate(*mtx, -D_80280EC0[0], 1.0f, 0.0f, 0.0f);
gSPMatrix((*gfx)++, OS_PHYSICAL_TO_K0((*mtx)++), G_MTX_NOPUSH | G_MTX_MUL | G_MTX_PROJECTION);
guRotate(*mtx, -D_80280EC0[1], 0.0f, 1.0f, 0.0f);
gSPMatrix((*gfx)++, OS_PHYSICAL_TO_K0((*mtx)++), G_MTX_NOPUSH | G_MTX_MUL | G_MTX_PROJECTION);
guTranslate(*mtx, 0.0f, 0.0f, 0.0f);
gSPMatrix((*gfx)++, OS_PHYSICAL_TO_K0((*mtx)++), G_MTX_NOPUSH | G_MTX_LOAD | G_MTX_MODELVIEW);
}
#endif
void func_8024CBD4(Gfx **gfx, Mtx **mtx){
func_8024C964(gfx, mtx, D_80275D28, D_80275D2C);
}
void func_8024CC00(void){}
void func_8024CC08(f32 arg0){
if(90.0f < arg0) arg0 = 90.0f;
if(arg0 < 5.0f) arg0 = 10.0f;
D_80280ECC = arg0;
}
f32 func_8024CC50(void){
return D_80280ECC;
}
void func_8024CC5C(void){
func_8024CE74((s32) ((f32)D_80276588/2), (s32) ((f32)D_8027658C/2), (s32) ((f32)D_80276588/2), (s32) ((f32)D_8027658C/2));
}
void func_8024CCC4(void){
func_8024CD7C(1);
func_8024CDF8(0.0f, 0.0f, 0.0f);
func_8024CE40(0.0f, 0.0f, 0.0f);
func_8024CC08(40.0f);
func_8024CE60(1.0f, D_80277A08);
func_8024CC5C();
func_8024DDB4(40.0f);
mlMtxIdent();
mlMtxRotYaw(-60.0f);
mlMtxRotPitch(-90.0f);
func_802513B0(&D_80280FD8);
}
void func_8024CD7C(int arg0){
D_80280F90 = arg0;
}
void func_8024CD88(f32 src[3]){
ml_vec3f_copy(D_80280EB0, src);
}
void func_8024CDB0(s32 src[3]){
D_80280EB0[0] = (f32)src[0];
D_80280EB0[1] = (f32)src[1];
D_80280EB0[2] = (f32)src[2];
}
void func_8024CDF8(f32 arg0, f32 arg1, f32 arg2){
D_80280EB0[0] = arg0;
D_80280EB0[1] = arg1;
D_80280EB0[2] = arg2;
}
void func_8024CE18(f32 src[3]){
ml_vec3f_copy(D_80280EC0, src);
}
void func_8024CE40(f32 arg0, f32 arg1, f32 arg2){
D_80280EC0[0] = arg0;
D_80280EC0[1] = arg1;
D_80280EC0[2] = arg2;
}
void func_8024CE60(f32 near, f32 far){
D_80275D28 = near;
D_80275D2C = far;
}
void func_8024CE74(s32 arg0, s32 arg1, s32 arg2, s32 arg3){
D_80281018 = (D_80281018 + 1) % 8;
D_80280F10[D_80281018].vp.vscale[0] = arg0 << 2;
D_80280F10[D_80281018].vp.vscale[1] = arg1 << 2;
D_80280F10[D_80281018].vp.vscale[2] = 0x1ff;
D_80280F10[D_80281018].vp.vscale[3] = 0;
D_80280F10[D_80281018].vp.vtrans[0] = arg2 << 2;
D_80280F10[D_80281018].vp.vtrans[1] = arg3 << 2;
D_80280F10[D_80281018].vp.vtrans[2] = 0x1ff;
D_80280F10[D_80281018].vp.vtrans[3] = 0;
osWritebackDCache(&D_80280F10[D_80281018], sizeof(Vp)*8);
}
void func_8024CF10(f32 arg0, f32 arg1, f32 arg2, f32 arg3){
D_80281018 = (D_80281018 + 1) % 8;
D_80280F10[D_80281018].vp.vscale[0] = arg0*4;
D_80280F10[D_80281018].vp.vscale[1] = arg1*4;
D_80280F10[D_80281018].vp.vscale[2] = 0x1ff;
D_80280F10[D_80281018].vp.vscale[3] = 0;
D_80280F10[D_80281018].vp.vtrans[0] = arg2*4;
D_80280F10[D_80281018].vp.vtrans[1] = arg3*4;
D_80280F10[D_80281018].vp.vtrans[2] = 0x1ff;
D_80280F10[D_80281018].vp.vtrans[3] = 0;
osWritebackDCache(&D_80280F10[D_80281018], sizeof(Vp)*8);
}
void func_8024CFD4(void){
func_80256E24(D_80280ED0[0], D_80280EC0[0], D_80280EC0[1], -89.21774f, 0.0f, D_80277A0C);
func_80256E24(D_80280ED0[1], D_80280EC0[0], D_80280EC0[1], 89.21774f, 0.0f, D_80277A10);
func_80256E24(D_80280ED0[2], D_80280EC0[0], D_80280EC0[1], 0.0f, D_80277A14, D_80277A18);
func_80256E24(D_80280ED0[3], D_80280EC0[0], D_80280EC0[1], 0.0f, D_80277A1C, D_80277A20);
ml_vec3f_normalize(D_80280ED0[0]);
ml_vec3f_normalize(D_80280ED0[1]);
ml_vec3f_normalize(D_80280ED0[2]);
ml_vec3f_normalize(D_80280ED0[3]);
D_80280ED0[0][3] = -(D_80280EB0[0]*D_80280ED0[0][0] + D_80280EB0[1]*D_80280ED0[0][1] + D_80280EB0[2]*D_80280ED0[0][2]);
D_80280ED0[1][3] = -(D_80280EB0[0]*D_80280ED0[1][0] + D_80280EB0[1]*D_80280ED0[1][1] + D_80280EB0[2]*D_80280ED0[1][2]);
D_80280ED0[2][3] = -(D_80280EB0[0]*D_80280ED0[2][0] + D_80280EB0[1]*D_80280ED0[2][1] + D_80280EB0[2]*D_80280ED0[2][2]);
D_80280ED0[3][3] = -(D_80280EB0[0]*D_80280ED0[3][0] + D_80280EB0[1]*D_80280ED0[3][1] + D_80280EB0[2]*D_80280ED0[3][2]);
mlMtxIdent();
mlMtxRotYaw(D_80280EC0[1]);
mlMtxRotPitch(D_80280EC0[0]);
func_802513B0(&D_80280F98);
D_80280EA0[0] = 0.0f;
D_80280EA0[1] = 0.0f;
D_80280EA0[2] = -1.0f;
func_8025235C(D_80280EA0, D_80280EA0);
}
#ifndef NONMATCHING
#pragma GLOBAL_ASM("asm/nonmatchings/core1/code_EAF0/func_8024D1EC.s")
#else
void func_8024D1EC(f32 arg0[4], f32 arg1[4], f32 arg2[4], f32 arg3[4]){
arg0[0] = D_80280ED0[0][0];
arg1[0] = D_80280ED0[1][0];
arg2[0] = D_80280ED0[2][0];
arg3[0] = D_80280ED0[3][0];
arg0[1] = D_80280ED0[0][1];
arg1[1] = D_80280ED0[1][1];
arg2[1] = D_80280ED0[2][1];
arg3[1] = D_80280ED0[3][1];
arg0[2] = D_80280ED0[0][2];
arg1[2] = D_80280ED0[1][2];
arg2[2] = D_80280ED0[2][2];
arg3[2] = D_80280ED0[3][2];
arg0[3] = D_80280ED0[0][3];
arg1[3] = D_80280ED0[1][3];
arg2[3] = D_80280ED0[2][3];
arg3[3] = D_80280ED0[3][3];
}
#endif
#pragma GLOBAL_ASM("asm/nonmatchings/core1/code_EAF0/func_8024D2B0.s")
#pragma GLOBAL_ASM("asm/nonmatchings/core1/code_EAF0/func_8024D374.s")
#pragma GLOBAL_ASM("asm/nonmatchings/core1/code_EAF0/func_8024D8F4.s")
#pragma GLOBAL_ASM("asm/nonmatchings/core1/code_EAF0/func_8024D9B0.s")
#pragma GLOBAL_ASM("asm/nonmatchings/core1/code_EAF0/func_8024DB50.s")
#pragma GLOBAL_ASM("asm/nonmatchings/core1/code_EAF0/func_8024DC04.s")
#pragma GLOBAL_ASM("asm/nonmatchings/core1/code_EAF0/func_8024DD0C.s")
#pragma GLOBAL_ASM("asm/nonmatchings/core1/code_EAF0/func_8024DD34.s")
#pragma GLOBAL_ASM("asm/nonmatchings/core1/code_EAF0/func_8024DD90.s")
#pragma GLOBAL_ASM("asm/nonmatchings/core1/code_EAF0/func_8024DD9C.s")
#pragma GLOBAL_ASM("asm/nonmatchings/core1/code_EAF0/func_8024DDA8.s")
#pragma GLOBAL_ASM("asm/nonmatchings/core1/code_EAF0/func_8024DDB4.s")
#pragma GLOBAL_ASM("asm/nonmatchings/core1/code_EAF0/func_8024DDC0.s")
#pragma GLOBAL_ASM("asm/nonmatchings/core1/code_EAF0/func_8024DDCC.s")
f32 func_8024DDD8(s32 arg0, f32 arg1){
return mlNormalizeAngle((D_80280EC0[1] + arg1) + D_80277A30);
}
#pragma GLOBAL_ASM("asm/nonmatchings/core1/code_EAF0/func_8024DE1C.s")
#pragma GLOBAL_ASM("asm/nonmatchings/core1/code_EAF0/func_8024E030.s")
#pragma GLOBAL_ASM("asm/nonmatchings/core1/code_EAF0/func_8024E258.s")
#pragma GLOBAL_ASM("asm/nonmatchings/core1/code_EAF0/func_8024E2FC.s")
#pragma GLOBAL_ASM("asm/nonmatchings/core1/code_EAF0/func_8024E3A8.s")
#ifndef CORE2_DATA_CRC2
#define CORE2_DATA_CRC2 0
#endif
extern s32 D_803727F4 = CORE2_DATA_CRC2;
extern s32 D_80276574;
extern f32 D_80277A70;
extern f32 D_80277A74;
extern struct {
u8 pad0[4];
s32 unk4;
u8 pad8[4];
s32 unkC;
} D_80379B90;
f32 func_8024E420(s32 arg0, s32 arg1, s32 arg2) {
f32 phi_f2;
phi_f2 = D_80277A70;
if ((D_80379B90.unk4 != D_803727F4) || (D_80379B90.unkC != D_80276574)) {
phi_f2 = D_80277A74;
}
if (arg0 > 0) {
arg0 = (arg2 < arg0) ? arg2 : (arg0 < arg1) ? arg1 : arg0;
arg0 = (s32) ((arg0 - arg1) * 0x50) / (s32) (arg2 - arg1);
} else {
if (arg0 < 0) {
arg0 = (arg0 < -arg2) ? -arg2 : (-arg1 < arg0) ? -arg1 : arg0;
arg0 = (s32) ((arg0 + arg1) * 0x50) / (s32) (arg2 - arg1);
}
}
return phi_f2 *= arg0;
}
#pragma GLOBAL_ASM("asm/nonmatchings/core1/code_EAF0/func_8024E55C.s")
#pragma GLOBAL_ASM("asm/nonmatchings/core1/code_EAF0/func_8024E5A8.s")
#pragma GLOBAL_ASM("asm/nonmatchings/core1/code_EAF0/func_8024E5E8.s")
#pragma GLOBAL_ASM("asm/nonmatchings/core1/code_EAF0/func_8024E60C.s")
#pragma GLOBAL_ASM("asm/nonmatchings/core1/code_EAF0/func_8024E640.s")
#pragma GLOBAL_ASM("asm/nonmatchings/core1/code_EAF0/func_8024E668.s")
#pragma GLOBAL_ASM("asm/nonmatchings/core1/code_EAF0/func_8024E67C.s")
#pragma GLOBAL_ASM("asm/nonmatchings/core1/code_EAF0/func_8024E698.s")
#pragma GLOBAL_ASM("asm/nonmatchings/core1/code_EAF0/func_8024E6E0.s")
#pragma GLOBAL_ASM("asm/nonmatchings/core1/code_EAF0/func_8024E71C.s")
#ifndef NONMATCHING
#pragma GLOBAL_ASM("asm/nonmatchings/core1/code_EAF0/func_8024E7C8.s")
#else
void func_8024E7C8(void){
u32 s0;
s32 sp5C;
if(func_8023E000() == 3)
func_802E4384();
osSetThreadPri(NULL, 0x29);
D_802812D0.stick_x = D_802812B8[0].stick_x;
D_802812D0.stick_y = D_802812B8[0].stick_y;
D_802812D0.button = D_802812B8[0].button;
if( getGameMode() == GAME_MODE_6_FILE_PLAYBACK
|| getGameMode() == GAME_MODE_7_ATTRACT_DEMO
|| getGameMode() == GAME_MODE_8_BOTTLES_BONUS
|| getGameMode() == GAME_MODE_A_SNS_PICTURE
|| getGameMode() == GAME_MODE_9_BANJO_AND_KAZOOIE
){
s0 = START_BUTTON;
if(gctransition_8030BD98()){
D_802816E0 += time_getDelta();
}
if(D_802816E0 < 1.0 || getGameMode() == GAME_MODE_9_BANJO_AND_KAZOOIE){
s0 = 0;
}
if(D_802812D0.button & s0 || demo_readInput(D_802812B8, &sp5C) < 1){
if(D_802812D0.button & s0){
func_803204E4(0x64, 1);
}
else{
func_803204E4(0x63, 1);
}
func_8033DD90();
}//L8024E944
}//L8024E94C
}
#endif
void func_8024EF74(void){
func_8024F35C(0);
if(!D_80281318.errno)
osContGetReadData(D_802812B8);
}
#ifndef NONMATCHING
void func_8024EFB0(void *);
#pragma GLOBAL_ASM("asm/nonmatchings/core1/code_EAF0/func_8024EFB0.s")
#else
void func_8024EFB0(void *arg0){
while(1){
osRecvMesg(&D_802812D8, &D_802812F0, 1);
if(D_80281328 == TRUE){
func_8024EF74();
}
else{
osSendMesg(&D_802812D8, 0, 0);
}
}
}
#endif
void func_8024F05C(void){
osCreateMesgQueue(&D_802812D8, &D_802812B0, 1);
osCreateMesgQueue(&D_802812F0, &D_802812B4, 1);
osCreateThread(&D_80281330, 7, func_8024EFB0, NULL, &D_802816E0, 0x28);
osSetEventMesg(OS_EVENT_SI, &D_802812D8, &D_802812B0);
osContInit(&D_802812D8, &D_80281130, &D_80281318);
osContSetCh(1);
func_8024F224();
func_802476DC();
osStartThread(&D_80281330);
}
int func_8024F12C(void){
return D_80281318.errno ? 1 : 0;
}
void func_8024F150(void){
if(func_8024F12C())
func_802DD008(0,0);
}
void func_8024F180(void){
if(func_8024F12C())
func_802DD040(0,0);
}
#ifndef NONMATCHING
#pragma GLOBAL_ASM("asm/nonmatchings/core1/code_EAF0/func_8024F1B0.s")
#else
void func_8024F1B0(void){
if(D_80281328 == 0){
func_8024F35C(1);
osContStartReadData(&D_802812D8);
}
}
#endif
void func_8024F1F0(void){
osRecvMesg(&D_802812D8, NULL, 1);
func_8024E7C8();
}
#pragma GLOBAL_ASM("asm/nonmatchings/core1/code_EAF0/func_8024F224.s")
#pragma GLOBAL_ASM("asm/nonmatchings/core1/code_EAF0/func_8024F2E4.s")
#pragma GLOBAL_ASM("asm/nonmatchings/core1/code_EAF0/func_8024F328.s")
OSMesgQueue * func_8024F344(void){
return &D_802812F0;
}
#pragma GLOBAL_ASM("asm/nonmatchings/core1/code_EAF0/func_8024F350.s")
#ifndef NONMATCHING
#pragma GLOBAL_ASM("asm/nonmatchings/core1/code_EAF0/func_8024F35C.s")
#else
void func_8024F35C(int arg0){
if(!arg0)
func_8024F4AC();
else
func_8024F450();
if(arg0 || D_802816E8.validCount == 1)
D_80281328[0] = arg0;
}
#endif
#pragma GLOBAL_ASM("asm/nonmatchings/core1/code_EAF0/func_8024F3B4.s")
int func_8024F3C4(int arg0){
return D_802812B8[arg0].button + D_802812B8[arg0].stick_x + D_802812B8[arg0].stick_y;
}
OSContPad *func_8024F3F4(void){
return &D_802812D0;
}
/* initilizes D_802816E8 message queue */
void func_8024F400(void){
D_80275D38 = TRUE;
osCreateMesgQueue(&D_802816E8, &D_80281700, 5);
osSendMesg(&D_802816E8, 0, 0);
}
void func_8024F450(void){
if(!D_80275D38)
func_8024F400();
osRecvMesg(&D_802816E8, 0, 1);
osSetEventMesg(OS_EVENT_SI, &D_802812D8, &D_802812B0);
}
void func_8024F4AC(void){
osSendMesg(&D_802816E8, 0, 0);
}

View File

@@ -0,0 +1,42 @@
#include <ultra64.h>
#include "synthInternals.h"
Acmd *alAuxBusPull(void *filter, s16 *outp, s32 outCount, s32 sampleOffset, Acmd *p)
{
Acmd *ptr = p;
ALAuxBus *m = (ALAuxBus *)filter;
ALFilter **sources = m->sources;
s32 i;
/*
* clear the output buffers here
*/
aClearBuffer(ptr++, AL_AUX_L_OUT, outCount<<1);
aClearBuffer(ptr++, AL_AUX_R_OUT, outCount<<1);
for (i = 0; i < m->sourceCount; i++) {
ptr = (sources[i]->handler)(sources[i], outp, outCount, sampleOffset,
ptr);
}
return ptr;
}
s32 alAuxBusParam(void *filter, s32 paramID, void *param)
{
ALAuxBus *m = (ALAuxBus *) filter;
ALFilter **sources = m->sources;
switch (paramID) {
case (AL_FILTER_ADD_SOURCE):
sources[m->sourceCount++] = (ALFilter *) param;
break;
default:
/* ??? */
break;
}
return 0;
}

118
src/core1/done/audio/bnkf.c Normal file
View File

@@ -0,0 +1,118 @@
#include <ultra64.h>
#include "functions.h"
#include "variables.h"
/* copt used??? */
void alSeqFileNew(ALSeqFile *file, u8 *base)
{
s32 offset = (s32) base;
s32 i;
/*
* patch the file so that offsets are pointers
*/
for (i = 0; i < file->seqCount; i++) {
file->seqArray[i].offset = (u8 *)((u8 *)file->seqArray[i].offset + offset);
}
}
static void _bnkfPatchWaveTable(ALWaveTable *w, s32 offset, s32 table)
{
if (w->flags)
return;
w->flags = 1;
w->base += table;
/* sct 2/14/96 - patch wavetable loop info based on type. */
if (w->type == AL_ADPCM_WAVE)
{
w->waveInfo.adpcmWave.book = (ALADPCMBook *)((u8 *)w->waveInfo.adpcmWave.book + offset);
if (w->waveInfo.adpcmWave.loop)
w->waveInfo.adpcmWave.loop = (ALADPCMloop *)((u8 *)w->waveInfo.adpcmWave.loop + offset);
}
else if (w->type == AL_RAW16_WAVE)
{
if (w->waveInfo.rawWave.loop)
w->waveInfo.rawWave.loop = (ALRawLoop *)((u8 *)w->waveInfo.rawWave.loop + offset);
}
}
static void _bnkfPatchSound(ALSound *s, s32 offset, s32 table)
{
if (s->flags)
return;
s->flags = 1;
s->envelope = (ALEnvelope *)((u8 *)s->envelope + offset);
s->keyMap = (ALKeyMap *)((u8 *)s->keyMap + offset);
s->wavetable = (ALWaveTable *)((u8 *)s->wavetable + offset);
_bnkfPatchWaveTable(s->wavetable, offset, table);
}
static void _bnkfPatchInst(ALInstrument *inst, s32 offset, s32 table)
{
s32 i;
if (inst->flags)
return;
inst->flags = 1;
for (i = 0; i < inst->soundCount; i++) {
inst->soundArray[i] = (ALSound *)((u8 *)inst->soundArray[i] +
offset);
_bnkfPatchSound(inst->soundArray[i], offset, table);
}
}
static void _bnkfPatchBank(ALBank *bank, s32 offset, s32 table)
{
s32 i;
if (bank->flags)
return;
bank->flags = 1;
if (bank->percussion) {
bank->percussion = (ALInstrument *)((u8 *)bank->percussion + offset);
_bnkfPatchInst(bank->percussion, offset, table);
}
for (i = 0; i < bank->instCount; i++) {
bank->instArray[i] = (ALInstrument *)((u8 *)bank->instArray[i] +
offset);
if(bank->instArray[i])
_bnkfPatchInst(bank->instArray[i], offset, table);
}
}
void alBnkfNew(ALBankFile *file, u8 *table)
{
s32 offset = (s32) file;
s32 woffset = (s32) table;
s32 i;
/*
* check the file format revision in debug libraries
*/
ALFailIf(file->revision != AL_BANK_VERSION, ERR_ALBNKFNEW);
/*
* patch the file so that offsets are pointers
*/
for (i = 0; i < file->bankCount; i++) {
file->bankArray[i] = (ALBank *)((u8 *)file->bankArray[i] + offset);
if(file->bankArray[i])
_bnkfPatchBank(file->bankArray[i], offset, woffset);
}
}

View File

@@ -0,0 +1,23 @@
#include <libaudio.h>
f32 alCents2Ratio(s32 cents)
{
f32 x;
f32 ratio = 1.0f;
if (cents >= 0) {
x = 1.00057779f; /* 2^(1/1200) */
} else {
x = 0.9994225441f; /* 2^(-1/1200) */
cents = -cents;
}
while (cents) {
if (cents & 1)
ratio *= x;
x *= x;
cents >>= 1;
}
return ratio;
}

View File

@@ -0,0 +1,14 @@
#include <ultra64.h>
#include "functions.h"
#include "variables.h"
void func_8025F3F0(ALCSPlayer *seqp, f32 arg1, f32 arg2)
{
ALEvent evt;
evt.type = AL_UNK18_EVT; //event type not listed;
evt.msg.unk18.unk0 = arg1;
evt.msg.unk18.unk4 = arg2;
alEvtqPostEvent(&seqp->evtq, &evt, 0);
}

View File

@@ -0,0 +1,9 @@
#include <ultra64.h>
#include "functions.h"
#include "variables.h"
#include "n_synth.h"
u8 func_8025F4A0(N_ALCSPlayer *seqp, u8 chan)
{
return seqp->chanState[chan].unk9;
}

View File

@@ -0,0 +1,16 @@
#include <ultra64.h>
#include "functions.h"
#include "variables.h"
void func_8025F510(ALCSPlayer *seqp, u8 chan, u8 arg2)
{
ALEvent evt;
evt.type = AL_SEQP_MIDI_EVT;
evt.msg.midi.ticks = 0;
evt.msg.midi.status = AL_MIDI_ControlChange | chan;
evt.msg.midi.byte1 = 0x7D;
evt.msg.midi.byte2 = arg2;
alEvtqPostEvent(&seqp->evtq, &evt, 0);
}

View File

@@ -0,0 +1,40 @@
#include <ultra64.h>
#include "functions.h"
#include "variables.h"
#include "n_synth.h"
void func_8025F610(void){
n_syn->head = NULL;
n_syn->n_seqp1 = NULL;
n_syn->n_seqp2 = NULL;
n_syn->unk5C = NULL;
n_syn->unk60 = NULL;
n_syn->unk64 = NULL;
n_syn->unk68 = NULL;
n_syn->unk6C = NULL;
n_syn->unk70 = NULL;
n_syn->n_sndp = NULL;
}
void func_8025F5C0(N_ALSeqPlayer *arg0, u8 arg1){
ALEvent evt;
evt.type = AL_SEQP_MIDI_EVT;
evt.msg.midi.ticks = 0;
evt.msg.midi.status = AL_MIDI_ChannelModeSelect;
evt.msg.midi.byte1 = 0x7E;
evt.msg.midi.byte2 = arg1;
alEvtqPostEvent(&arg0->evtq, &evt, 0);
}
void func_8025F570(N_ALSeqPlayer *arg0, u8 arg1){
ALEvent evt;
evt.type = AL_SEQP_MIDI_EVT;
evt.msg.midi.ticks = 0;
evt.msg.midi.status = AL_MIDI_ChannelModeSelect;
evt.msg.midi.byte1 = 0x7F;
evt.msg.midi.byte2 = arg1;
alEvtqPostEvent(&arg0->evtq, &evt, 0);
}

View File

@@ -0,0 +1,14 @@
#include <ultra64.h>
#include "functions.h"
#include "variables.h"
void alCopy(void *src, void *dest, s32 len)
{
s32 i;
u8 *s = (u8 *)src;
u8 *d = (u8 *)dest;
for (i = 0; i < len; i++){
*d++ = *s++;
}
}

375
src/core1/done/audio/cseq.c Normal file
View File

@@ -0,0 +1,375 @@
#include <ultra64.h>
static u32 __readVarLen(ALCSeq *s,u32 track);
static u8 __getTrackByte(ALCSeq *s,u32 track);
static u32 __alCSeqGetTrackEvent(ALCSeq *seq, u32 track, ALEvent *event);
void alCSeqNew(ALCSeq *seq, u8 *ptr)
{
u32 i,tmpOff,flagTmp;
/* load the seqence pointed to by ptr */
seq->base = (ALCMidiHdr*)ptr;
seq->validTracks = 0;
seq->lastDeltaTicks = 0;
seq->lastTicks = 0;
seq->deltaFlag = 1;
for(i = 0; i < 16; i++)
{
seq->lastStatus[i] = 0;
seq->curBUPtr[i] = 0;
seq->curBULen[i] = 0;
tmpOff = seq->base->trackOffset[i];
if(tmpOff) /* if the track is valid */
{
flagTmp = 1 << i;
seq->validTracks |= flagTmp;
seq->curLoc[i] = (u8*)((u32)ptr + tmpOff);
seq->evtDeltaTicks[i] = __readVarLen(seq,i);
/*__alCSeqGetTrackEvent(seq,i); prime the event buffers */
}
else
seq->curLoc[i] = 0;
}
seq->qnpt = 1.0/(f32)seq->base->division;
}
void alCSeqNextEvent(ALCSeq *seq,ALEvent *evt)
{
u32 i;
u32 firstTime = 0xFFFFFFFF;
u32 firstTrack;
u32 lastTicks = seq->lastDeltaTicks;
#ifdef _DEBUG
/* sct 1/17/96 - Warn if we are beyond the end of sequence. */
if (!seq->validTracks)
__osError(ERR_ALSEQOVERRUN, 0);
#endif
for(i = 0; i < 16 ; i++)
{
if((seq->validTracks >> i) & 1)
{
if(seq->deltaFlag)
seq->evtDeltaTicks[i] -= lastTicks;
if(seq->evtDeltaTicks[i] < firstTime)
{
firstTime = seq->evtDeltaTicks[i];
firstTrack = i;
}
}
}
__alCSeqGetTrackEvent(seq,firstTrack,evt);
evt->msg.midi.ticks = firstTime;
seq->lastTicks += firstTime;
seq->lastDeltaTicks = firstTime;
if(evt->type != AL_TRACK_END)
seq->evtDeltaTicks[firstTrack] += __readVarLen(seq,firstTrack);
seq->deltaFlag = 1;
}
/*
Note: If there are no valid tracks (ie. all tracks have
reached the end of their data stream), then return FALSE
to indicate that there is no next event.
*/
char __alCSeqNextDelta(ALCSeq *seq, s32 *pDeltaTicks)
{
u32 i;
u32 firstTime = 0xFFFFFFFF;
u32 lastTicks = seq->lastDeltaTicks;
if (!seq->validTracks)
return FALSE;
for(i = 0; i < 16 ; i++)
{
if((seq->validTracks >> i) & 1)
{
if(seq->deltaFlag)
seq->evtDeltaTicks[i] -= lastTicks;
if(seq->evtDeltaTicks[i] < firstTime)
firstTime = seq->evtDeltaTicks[i];
}
}
seq->deltaFlag = 0;
*pDeltaTicks = firstTime;
return TRUE;
}
/* only call alCSeqGetTrackEvent with a valid track !! */
static u32 __alCSeqGetTrackEvent(ALCSeq *seq, u32 track, ALEvent *event)
{
u32 offset;
u8 status, loopCt, curLpCt, *tmpPtr;
status = __getTrackByte(seq,track); /* read the status byte */
if (status == AL_MIDI_Meta) /* running status not allowed on meta events!! */
{
u8 type = __getTrackByte(seq,track);
if (type == AL_MIDI_META_TEMPO)
{
event->type = AL_TEMPO_EVT;
event->msg.tempo.status = status;
event->msg.tempo.type = type;
event->msg.tempo.byte1 = __getTrackByte(seq,track);
event->msg.tempo.byte2 = __getTrackByte(seq,track);
event->msg.tempo.byte3 = __getTrackByte(seq,track);
seq->lastStatus[track] = 0; /* lastStatus not supported after meta */
}
else if (type == AL_MIDI_META_EOT)
{
u32 flagMask;
flagMask = 0x01 << track;
seq->validTracks = seq->validTracks ^ flagMask;
if(seq->validTracks) /* there is music left don't end */
event->type = AL_TRACK_END;
else /* no more music send AL_SEQ_END_EVT msg */
event->type = AL_SEQ_END_EVT;
}
else if (type == AL_CMIDI_LOOPSTART_CODE)
{
status = __getTrackByte(seq,track); /* get next two bytes, ignore them */
status = __getTrackByte(seq,track);
seq->lastStatus[track] = 0;
event->type = AL_CSP_LOOPSTART;
}
else if (type == AL_CMIDI_LOOPEND_CODE)
{
tmpPtr = seq->curLoc[track];
loopCt = *tmpPtr++;
curLpCt = *tmpPtr;
if(curLpCt == 0) /* done looping */
{
*tmpPtr = loopCt; /* reset current loop count */
seq->curLoc[track] = tmpPtr + 5; /* move pointer to end of event */
}
else
{
if(curLpCt != 0xFF) /* not a loop forever */
*tmpPtr = curLpCt - 1; /* decrement current loop count */
tmpPtr++; /* get offset from end of event */
offset = (*tmpPtr++) << 24;
offset += (*tmpPtr++) << 16;
offset += (*tmpPtr++) << 8;
offset += *tmpPtr++;
seq->curLoc[track] = tmpPtr - offset;
}
seq->lastStatus[track] = 0;
event->type = AL_CSP_LOOPEND;
}
#ifdef _DEBUG
else
__osError(ERR_ALSEQMETA, 1, type);
#endif
}
else
{
event->type = AL_SEQ_MIDI_EVT;
if (status & 0x80) /* if high bit is set, then new status */
{
event->msg.midi.status = status;
event->msg.midi.byte1 = __getTrackByte(seq,track);
seq->lastStatus[track] = status;
}
else /* running status */
{
#ifdef _DEBUG
if(seq->lastStatus[track] == 0)
__osError(ERR_ALCSEQZEROSTATUS, 1, track);
#endif
event->msg.midi.status = seq->lastStatus[track];
event->msg.midi.byte1 = status;
}
if (((event->msg.midi.status & 0xf0) != AL_MIDI_ProgramChange) &&
((event->msg.midi.status & 0xf0) != AL_MIDI_ChannelPressure))
{
event->msg.midi.byte2 = __getTrackByte(seq,track);
if((event->msg.midi.status & 0xf0) == AL_MIDI_NoteOn)
{
event->msg.midi.duration = __readVarLen(seq,track);
#ifdef _DEBUG
if(event->msg.midi.byte2 == 0)
__osError( ERR_ALCSEQZEROVEL, 1, track);
#endif
}
}
else
event->msg.midi.byte2 = 0;
}
return TRUE;
}
f32 alCSeqTicksToSec(ALCSeq *seq, s32 ticks, u32 tempo)
{
return ((f32) (((f32)(ticks) * (f32)(tempo)) /
((f32)(seq->base->division) * 1000000.0)));
}
u32 alCSeqSecToTicks(ALCSeq *seq, f32 sec, u32 tempo)
{
return (u32)(((sec * 1000000.0) * seq->base->division) / tempo);
}
s32 alCSeqGetTicks(ALCSeq *seq)
{
return seq->lastTicks;
}
void alCSeqNewMarker(ALCSeq *seq, ALCSeqMarker *m, u32 ticks)
{
ALEvent evt;
ALCSeq tempSeq;
s32 i;
alCSeqNew(&tempSeq, (u8*)seq->base);
do {
m->validTracks = tempSeq.validTracks;
m->lastTicks = tempSeq.lastTicks;
m->lastDeltaTicks = tempSeq.lastDeltaTicks;
for(i=0;i<16;i++)
{
m->curLoc[i] = tempSeq.curLoc[i];
m->curBUPtr[i] = tempSeq.curBUPtr[i];
m->curBULen[i] = tempSeq.curBULen[i];
m->lastStatus[i] = tempSeq.lastStatus[i];
m->evtDeltaTicks[i] = tempSeq.evtDeltaTicks[i];
}
alCSeqNextEvent(&tempSeq, &evt);
if (evt.type == AL_SEQ_END_EVT)
break;
} while (tempSeq.lastTicks < ticks);
}
void alCSeqSetLoc(ALCSeq *seq, ALCSeqMarker *m)
{
s32 i;
seq->validTracks = m->validTracks;
seq->lastTicks = m->lastTicks;
seq->lastDeltaTicks = m->lastDeltaTicks;
for(i=0;i<16;i++)
{
seq->curLoc[i] = m->curLoc[i];
seq->curBUPtr[i] = m->curBUPtr[i];
seq->curBULen[i] = m->curBULen[i];
seq->lastStatus[i] = m->lastStatus[i];
seq->evtDeltaTicks[i] = m->evtDeltaTicks[i];
}
}
void alCSeqGetLoc(ALCSeq *seq, ALCSeqMarker *m)
{
s32 i;
m->validTracks = seq->validTracks;
m->lastTicks = seq->lastTicks;
m->lastDeltaTicks = seq->lastDeltaTicks;
for(i=0;i<16;i++)
{
m->curLoc[i] = seq->curLoc[i];
m->curBUPtr[i] = seq->curBUPtr[i];
m->curBULen[i] = seq->curBULen[i];
m->lastStatus[i] = seq->lastStatus[i];
m->evtDeltaTicks[i] = seq->evtDeltaTicks[i];
}
}
/* non-aligned byte reading routines */
static u8 __getTrackByte(ALCSeq *seq,u32 track)
{
u8 theByte;
if(seq->curBULen[track])
{
theByte = *seq->curBUPtr[track];
seq->curBUPtr[track]++;
seq->curBULen[track]--;
}
else /* need to handle backup mode */
{
theByte = *seq->curLoc[track];
seq->curLoc[track]++;
if(theByte == AL_CMIDI_BLOCK_CODE)
{
u8 loBackUp,hiBackUp,theLen,nextByte;
u32 backup;
nextByte = *seq->curLoc[track];
seq->curLoc[track]++;
if(nextByte != AL_CMIDI_BLOCK_CODE)
{
/* if here, then got a backup section. get the amount of
backup, and the len of the section. Subtract the amount of
backup from the curLoc ptr, and subtract four more, since
curLoc has been advanced by four while reading the codes. */
hiBackUp = nextByte;
loBackUp = *seq->curLoc[track];
seq->curLoc[track]++;
theLen = *seq->curLoc[track];
seq->curLoc[track]++;
backup = (u32)hiBackUp;
backup = backup << 8;
backup += loBackUp;
seq->curBUPtr[track] = seq->curLoc[track] - (backup + 4);
seq->curBULen[track] = (u32)theLen;
/* now get the byte */
theByte = *seq->curBUPtr[track];
seq->curBUPtr[track]++;
seq->curBULen[track]--;
}
}
}
return theByte;
}
static u32 __readVarLen(ALCSeq *seq,u32 track)
{
u32 value;
u32 c;
value = (u32)__getTrackByte(seq,track);
if ( value & 0x00000080 )
{
value &= 0x7f;
do
{
c = (u32)__getTrackByte(seq,track);
value = (value << 7) + (c & 0x7f);
} while (c & 0x80);
}
return (value);
}

View File

@@ -0,0 +1,10 @@
#include <ultra64.h>
#include "functions.h"
#include "variables.h"
s32 alCSPGetTempo(ALCSPlayer *seqp){
if(seqp->target == NULL)
return 0;
return seqp->uspt / seqp->target->qnpt;
}

View File

@@ -0,0 +1,12 @@
#include <ultra64.h>
#include "functions.h"
#include "variables.h"
void alCSPPlay(ALCSPlayer *seqp)
{
ALEvent evt;
evt.type = AL_SEQP_PLAY_EVT;
alEvtqPostEvent(&seqp->evtq, &evt, 0);
}

View File

@@ -0,0 +1,13 @@
#include <ultra64.h>
#include "functions.h"
#include "variables.h"
void alCSPSetBank(ALCSPlayer *seqp, ALBank *b)
{
ALEvent evt;
evt.type = AL_SEQP_BANK_EVT;
evt.msg.spbank.bank = b;
alEvtqPostEvent(&seqp->evtq, &evt, 0);
}

View File

@@ -0,0 +1,11 @@
#include <ultra64.h>
void alCSPSetSeq(ALCSPlayer *seqp, ALCSeq *seq)
{
ALEvent evt;
evt.type = AL_SEQP_SEQ_EVT;
evt.msg.spseq.seq = seq;
alEvtqPostEvent(&seqp->evtq, &evt, 0);
}

View File

@@ -0,0 +1,17 @@
#include <ultra64.h>
#include "functions.h"
#include "variables.h"
void alCSPSetTempo(ALCSPlayer *seqp, s32 tempo)
{
ALEvent evt;
evt.type = AL_SEQP_META_EVT;
evt.msg.tempo.status = AL_MIDI_Meta;
evt.msg.tempo.type = AL_MIDI_META_TEMPO;
evt.msg.tempo.byte1 = (tempo & 0xff0000)>>16;
evt.msg.tempo.byte2 = (tempo & 0xff00)>>8;
evt.msg.tempo.byte3 = tempo & 0xff;
alEvtqPostEvent(&seqp->evtq, &evt, 0);
}

View File

@@ -0,0 +1,15 @@
#include <ultra64.h>
#include "functions.h"
#include "variables.h"
void alCSPSetVol(ALCSPlayer *seqp, s16 vol)
{
ALEvent evt;
evt.type = AL_SEQP_VOL_EVT;
evt.msg.spvol.vol = vol;
alEvtqPostEvent(&seqp->evtq, &evt, 0);
}

View File

@@ -0,0 +1,10 @@
#include <ultra64.h>
void alCSPStop(ALCSPlayer *seqp)
{
ALEvent evt;
evt.type = AL_SEQP_STOPPING_EVT;
alEvtqPostEvent(&seqp->evtq, &evt, 0);
}

View File

@@ -0,0 +1,280 @@
#include <ultra64.h>
#include "functions.h"
#include "variables.h"
#include "synthInternals.h"
/*
* WARNING: THE FOLLOWING CONSTANT MUST BE KEPT IN SYNC
* WITH SCALING IN MICROCODE!!!
*/
#define SCALE 16384
/*
* the following arrays contain default parameters for
* a few hopefully useful effects.
*/
#define ms *(((s32)((f32)44.1))&~0x7)
static s32 SMALLROOM_PARAMS[26] = {
/* sections length */
3, 100 ms,
/* chorus chorus filter
input output fbcoef ffcoef gain rate depth coef */
0, 54 ms, 9830, -9830, 0, 0, 0, 0,
19 ms, 38 ms, 3276, -3276, 0x3fff, 0, 0, 0,
0, 60 ms, 5000, 0, 0, 0, 0, 0x5000
};
static s32 BIGROOM_PARAMS[34] = {
/* sections length */
4, 100 ms,
/* chorus chorus filter
input output fbcoef ffcoef gain rate depth coef */
0, 66 ms, 9830, -9830, 0, 0, 0, 0,
22 ms, 54 ms, 3276, -3276, 0x3fff, 0, 0, 0,
66 ms, 91 ms, 3276, -3276, 0x3fff, 0, 0, 0,
0, 94 ms, 8000, 0, 0, 0, 0, 0x5000
};
static s32 ECHO_PARAMS[10] = {
/* sections length */
1, 200 ms,
/* chorus chorus filter
input output fbcoef ffcoef gain rate depth coef */
0, 179 ms, 12000, 0, 0x7fff, 0, 0, 0
};
static s32 CHORUS_PARAMS[10] = {
/* sections length */
1, 20 ms,
/* chorus chorus filter
input output fbcoef ffcoef gain rate depth coef */
0, 5 ms, 0x4000, 0, 0x7fff, 7600, 700, 0
};
static s32 FLANGE_PARAMS[10] = {
/* sections length */
1, 20 ms,
/* chorus chorus filter
input output fbcoef ffcoef gain rate depth coef */
0, 5 ms, 0, 0x5fff, 0x7fff, 380, 500, 0
};
static s32 NULL_PARAMS[10] = {
0, 0,
0, 0, 0, 0, 0, 0, 0, 0
};
void init_lpfilter(ALLowPass *lp)
{
s32 i, temp;
s16 fc;
f64 ffc, fcoef;
temp = lp->fc * SCALE;
fc = temp >> 15;
lp->fgain = SCALE - fc;
lp->first = 1;
for (i=0; i<8; i++)
lp->fcvec.fccoef[i] = 0;
lp->fcvec.fccoef[i++] = fc;
fcoef = ffc = (f64)fc/SCALE;
for (; i<16; i++){
fcoef *= ffc;
lp->fcvec.fccoef[i] = (s16)(fcoef * SCALE);
}
}
void alFxNew(ALFx *r, ALSynConfig *c, ALHeap *hp)
{
u16 i, j, k;
s32 *param = 0;
ALFilter *f = (ALFilter *) r;
ALDelay *d;
alFilterNew(f, 0, alFxParam, AL_FX);
f->handler = alFxPull;
r->paramHdl = (ALSetFXParam)alFxParamHdl;
switch (c->fxType) {
case AL_FX_SMALLROOM: param = SMALLROOM_PARAMS; break;
case AL_FX_BIGROOM: param = BIGROOM_PARAMS; break;
case AL_FX_ECHO: param = ECHO_PARAMS; break;
case AL_FX_CHORUS: param = CHORUS_PARAMS; break;
case AL_FX_FLANGE: param = FLANGE_PARAMS; break;
case AL_FX_CUSTOM: param = c->params; break;
default: param = NULL_PARAMS; break;
}
j = 0;
r->section_count = param[j++];
r->length = param[j++];
r->delay = alHeapAlloc(hp, r->section_count, sizeof(ALDelay));
r->base = alHeapAlloc(hp, r->length, sizeof(s16));
r->input = r->base;
for ( k=0; k < r->length; k++)
r->base[k] = 0;
for ( i=0; i<r->section_count; i++ ){
d = &r->delay[i];
d->input = param[j++];
d->output = param[j++];
d->fbcoef = param[j++];
d->ffcoef = param[j++];
d->gain = param[j++];
if (param[j]) {
#define RANGE 2.0
/* d->rsinc = ((f32) param[j++])/0xffffff; */
d->rsinc = ((((f32)param[j++])/1000) * RANGE)/c->outputRate;
/*
* the following constant is derived from:
*
* ratio = 2^(cents/1200)
*
* and therefore for hundredths of a cent
* x
* ln(ratio) = ---------------
* (120,000)/ln(2)
* where
* 120,000/ln(2) = 173123.40...
*/
#define CONVERT 173123.404906676
#define LENGTH (d->output - d->input)
d->rsgain = (((f32) param[j++])/CONVERT) * LENGTH;
d->rsval = 1.0;
d->rsdelta = 0.0;
d->rs = alHeapAlloc(hp, 1, sizeof(ALResampler));
d->rs->state = alHeapAlloc(hp, 1, sizeof(RESAMPLE_STATE));
d->rs->delta = 0.0;
d->rs->first = 1;
} else {
d->rs = 0;
j++;
j++;
}
if (param[j]) {
d->lp = alHeapAlloc(hp, 1, sizeof(ALLowPass));
d->lp->fstate = alHeapAlloc(hp, 1, sizeof(POLEF_STATE));
d->lp->fc = param[j++];
init_lpfilter(d->lp);
} else {
d->lp = 0;
j++;
}
}
}
void alEnvmixerNew(ALEnvMixer *e, ALHeap *hp)
{
alFilterNew((ALFilter *) e, alEnvmixerPull, alEnvmixerParam, AL_ENVMIX);
e->state = alHeapAlloc(hp, 1, sizeof(ENVMIX_STATE));
e->first = 1;
e->motion = AL_STOPPED;
e->volume = 1;
e->ltgt = 1;
e->rtgt = 1;
e->cvolL = 1;
e->cvolR = 1;
e->dryamt = 0;
e->wetamt = 0;
e->lratm = 1;
e->lratl = 0;
e->lratm = 1;
e->lratl = 0;
e->delta = 0;
e->segEnd = 0;
e->pan = 0;
e->ctrlList = 0;
e->ctrlTail = 0;
e->sources = 0;
}
void alLoadNew(ALLoadFilter *f, ALDMANew dmaNew, ALHeap *hp)
{
s32
i;
/*
* init filter superclass
*/
alFilterNew((ALFilter *) f, alAdpcmPull, alLoadParam, AL_ADPCM);
f->state = alHeapAlloc(hp, 1, sizeof(ADPCM_STATE));
f->lstate = alHeapAlloc(hp, 1, sizeof(ADPCM_STATE));
f->dma = dmaNew(&f->dmaState);
/*
* init the adpcm state
*/
f->lastsam = 0;
f->first = 1;
f->memin = 0;
}
void alResampleNew(ALResampler *r, ALHeap *hp)
{
alFilterNew((ALFilter *) r, alResamplePull, alResampleParam, AL_RESAMPLE);
/*
* Init resampler state
*/
r->state = alHeapAlloc(hp, 1, sizeof(RESAMPLE_STATE));
r->delta = 0.0;
r->first = 1;
r->motion = AL_STOPPED;
r->ratio = 1.0;
r->upitch = 0;
r->ctrlList = 0;
r->ctrlTail = 0;
/* state in the ucode is initialized by the A_INIT flag */
}
void alAuxBusNew(ALAuxBus *m, void *sources, s32 maxSources)
{
alFilterNew((ALFilter *) m, alAuxBusPull, alAuxBusParam, AL_AUXBUS);
m->sourceCount = 0;
m->maxSources = maxSources;
m->sources = (ALFilter **)sources;
}
void alMainBusNew(ALMainBus *m, void *sources, s32 maxSources)
{
alFilterNew((ALFilter *) m, alMainBusPull, alMainBusParam, AL_MAINBUS);
m->sourceCount = 0;
m->maxSources = maxSources;
m->sources = (ALFilter **)sources;
}
void alSaveNew(ALSave *f)
{
/*
* init filter superclass
*/
alFilterNew((ALFilter *) f, alSavePull, alSaveParam, AL_SAVE);
/*
* init the save state, which is a virtual dram address
*/
f->dramout = 0;
f->first = 1;
}

495
src/core1/done/audio/env.c Normal file
View File

@@ -0,0 +1,495 @@
#include <ultra64.h>
#include "synthInternals.h"
#ifndef assert
#define assert(s)
#endif
#ifdef AUD_PROFILE
extern u32 cnt_index, env_num, env_cnt, env_max, env_min, lastCnt[];
extern u32 rate_num, rate_cnt, rate_max, rate_min;
extern u32 vol_num, vol_cnt, vol_max, vol_min;
#endif
#define EQPOWER_LENGTH 128
static s16 eqpower[ EQPOWER_LENGTH ] = {
32767, 32764, 32757, 32744, 32727, 32704,
32677, 32644, 32607, 32564, 32517, 32464,
32407, 32344, 32277, 32205, 32127, 32045,
31958, 31866, 31770, 31668, 31561, 31450,
31334, 31213, 31087, 30957, 30822, 30682,
30537, 30388, 30234, 30075, 29912, 29744,
29572, 29395, 29214, 29028, 28838, 28643,
28444, 28241, 28033, 27821, 27605, 27385,
27160, 26931, 26698, 26461, 26220, 25975,
25726, 25473, 25216, 24956, 24691, 24423,
24151, 23875, 23596, 23313, 23026, 22736,
22442, 22145, 21845, 21541, 21234, 20924,
20610, 20294, 19974, 19651, 19325, 18997,
18665, 18331, 17993, 17653, 17310, 16965,
16617, 16266, 15913, 15558, 15200, 14840,
14477, 14113, 13746, 13377, 13006, 12633,
12258, 11881, 11503, 11122, 10740, 10357,
9971, 9584, 9196, 8806, 8415, 8023,
7630, 7235, 6839, 6442, 6044, 5646,
5246, 4845, 4444, 4042, 3640, 3237,
2833, 2429, 2025, 1620, 1216, 810,
405, 0
};
extern f64 __pow(f64, f64);
/*
* prototypes for private enveloper functions
*/
static Acmd *_pullSubFrame(void *filter, s16 *inp, s16 *outp, s32 outCount,
s32 sampleOffset, Acmd *p) ;
static s16 _getRate(f64 vol, f64 tgt, s32 count, u16* ratel);
static f32 _getVol(f32 ivol, s32 samples, s16 ratem, u16 ratel);
/***********************************************************************
* Enveloper filter public interfaces
***********************************************************************/
Acmd *alEnvmixerPull(void *filter, s16 *outp, s32 outCount, s32 sampleOffset,
Acmd *p)
{
Acmd *ptr = p;
ALEnvMixer *e = (ALEnvMixer *)filter;
s16 inp;
s32 lastOffset;
s32 thisOffset = sampleOffset;
s32 samples;
s16 loutp = 0;
s32 fVol;
ALParam *thisParam;
#ifdef AUD_PROFILE
lastCnt[++cnt_index] = osGetCount();
#endif
/*
* Force the input to be the resampler output
*/
inp = AL_RESAMPLER_OUT;
while (e->ctrlList != 0) {
lastOffset = thisOffset;
thisOffset = e->ctrlList->delta;
samples = thisOffset - lastOffset;
if (samples > outCount)
break;
assert(samples >= 0);
assert(samples <= AL_MAX_RSP_SAMPLES);
switch (e->ctrlList->type) {
case (AL_FILTER_START_VOICE_ALT):
{
ALStartParamAlt *param = (ALStartParamAlt *)e->ctrlList;
ALFilter *f = (ALFilter *) e;
s32 tmp;
if (param->unity) {
(*e->filter.setParam)(&e->filter,
AL_FILTER_SET_UNITY_PITCH, 0);
}
(*e->filter.setParam)(&e->filter, AL_FILTER_SET_WAVETABLE,
param->wave);
(*e->filter.setParam)(&e->filter, AL_FILTER_START, 0);
e->first = 1;
e->delta = 0;
e->segEnd = param->samples;
tmp = ((s32)param->volume + (s32)param->volume) /2;
//tmp = ((s32)param->volume * (s32)param->volume) >> 15;
e->volume = (s16) tmp;
e->pan = param->pan;
e->dryamt = eqpower[param->fxMix];
e->wetamt = eqpower[EQPOWER_LENGTH - param->fxMix - 1];
if (param->samples) {
e->cvolL = 1;
e->cvolR = 1;
} else {
/*
* Attack time is zero. Simply set the
* volume. We don't want an attack segment.
*/
e->cvolL = (e->volume * eqpower[e->pan]) >> 15;
e->cvolR = (e->volume *
eqpower[EQPOWER_LENGTH - e->pan - 1]) >> 15;
}
if (f->source) {
union {
f32 f;
s32 i;
} data;
data.f = param->pitch;
(*f->source->setParam)(f->source, AL_FILTER_SET_PITCH,
(void *)data.i);
}
}
break;
case (AL_FILTER_SET_FXAMT):
case (AL_FILTER_SET_PAN):
case (AL_FILTER_SET_VOLUME):
ptr = _pullSubFrame(e, &inp, &loutp, samples, sampleOffset, ptr);
e->delta += samples;
if (e->delta >= e->segEnd){
/*
* We should have reached our target, calculate
* target in case e->segEnd was 0
*/
e->ltgt = (e->volume * eqpower[e->pan]) >> 15;
e->rtgt = (e->volume *
eqpower[EQPOWER_LENGTH - e->pan - 1]) >> 15;
e->delta = e->segEnd; /* To prevent overflow */
e->cvolL = e->ltgt;
e->cvolR = e->rtgt;
} else {
/*
* Estimate the current volume
*/
e->cvolL = _getVol(e->cvolL, e->delta, e->lratm, e->lratl);
e->cvolR = _getVol(e->cvolR, e->delta, e->rratm, e->rratl);
}
/*
* We can't have volume of zero, because the envelope
* would never go anywhere from there
*/
if( e->cvolL == 0 ) e->cvolL = 1;
if( e->cvolR == 0 ) e->cvolR = 1;
if (e->ctrlList->type == AL_FILTER_SET_PAN)
/*
* This should result in a change to the current
* segment rate and target
*/
e->pan = (s16) e->ctrlList->data.i;
if (e->ctrlList->type == AL_FILTER_SET_VOLUME){
/*
* Switching to a new segment
*/
e->delta = 0;
/*
* Map volume non-linearly to give something close to
* loudness
*/
fVol = (e->ctrlList->data.i);
//fVol = (fVol*fVol)>>15;
fVol = (fVol+fVol)/2;
e->volume = (s16) fVol;
e->segEnd = e->ctrlList->moredata.i;
}
if (e->ctrlList->type == AL_FILTER_SET_FXAMT){
e->dryamt = eqpower[e->ctrlList->data.i];
e->wetamt = eqpower[EQPOWER_LENGTH - e->ctrlList->data.i - 1];
}
/*
* Force a volume update
*/
e->first = 1;
break;
case (AL_FILTER_START_VOICE):
{
ALStartParam *p = (ALStartParam *)e->ctrlList;
/*
* Changing to PLAYING (since the previous state was
* persumable STOPPED, we'll just bump the output
* pointer rather than pull a subframe of zeros).
*/
if (p->unity) {
(*e->filter.setParam)(&e->filter,
AL_FILTER_SET_UNITY_PITCH, 0);
}
(*e->filter.setParam)(&e->filter, AL_FILTER_SET_WAVETABLE,
p->wave);
(*e->filter.setParam)(&e->filter, AL_FILTER_START, 0);
}
break;
case (AL_FILTER_STOP_VOICE):
{
/*
* Changing to STOPPED and reset the filter
*/
ptr = _pullSubFrame(e, &inp, &loutp, samples, sampleOffset, ptr);
(*e->filter.setParam)(&e->filter, AL_FILTER_RESET, 0);
}
break;
case (AL_FILTER_FREE_VOICE):
{
ALSynth *drvr = &alGlobals->drvr;
ALFreeParam *param = (ALFreeParam *)e->ctrlList;
param->pvoice->offset = 0;
_freePVoice(drvr, (PVoice *)param->pvoice);
}
break;
default:
/*
* Pull the reuired number of samples and then pass the message
* on down the chain
*/
ptr = _pullSubFrame(e, &inp, &loutp, samples, sampleOffset, ptr);
e->delta += samples;
(*e->filter.setParam)(&e->filter, e->ctrlList->type,
(void *) e->ctrlList->data.i);
break;
}
loutp += (samples<<1);
outCount -= samples;
/*
* put the param record back on the free list
*/
thisParam = e->ctrlList;
e->ctrlList = e->ctrlList->next;
if (e->ctrlList == 0)
e->ctrlTail = 0;
__freeParam(thisParam);
}
if(e->motion == 1){
ptr = _pullSubFrame(e, &inp, &loutp, outCount, sampleOffset, ptr);
e->delta += outCount;
}
/*
* Prevent overflow in e->delta
*/
if (e->delta > e->segEnd)
e->delta = e->segEnd;
#ifdef AUD_PROFILE
PROFILE_AUD(env_num, env_cnt, env_max, env_min);
#endif
return ptr;
}
s32
alEnvmixerParam(void *filter, s32 paramID, void *param)
{
ALFilter *f = (ALFilter *) filter;
ALEnvMixer *e = (ALEnvMixer *) filter;
switch (paramID) {
case (AL_FILTER_ADD_UPDATE):
if (e->ctrlTail) {
e->ctrlTail->next = (ALParam *)param;
} else {
e->ctrlList = (ALParam *)param;
}
e->ctrlTail = (ALParam *)param;
break;
case (AL_FILTER_RESET):
e->first = 1;
e->motion = AL_STOPPED;
e->volume = 1;
if (f->source)
(*f->source->setParam)(f->source, AL_FILTER_RESET, param);
break;
case (AL_FILTER_START):
e->motion = AL_PLAYING;
if (f->source)
(*f->source->setParam)(f->source, AL_FILTER_START, param);
break;
case (AL_FILTER_SET_SOURCE):
f->source = (ALFilter *) param;
break;
default:
if (f->source)
(*f->source->setParam)(f->source, paramID, param);
}
return 0;
}
static
Acmd* _pullSubFrame(void *filter, s16 *inp, s16 *outp, s32 outCount, s32 sampleOffset, Acmd *p)
{
Acmd *ptr = p;
ALEnvMixer *e = (ALEnvMixer *)filter;
ALFilter *source= e->filter.source;
/* filter must be playing and request non-zero output samples to pull. */
//if (e->motion != AL_PLAYING || !outCount)
// return ptr;
if(!outCount)
return ptr;
/*
* ask all filters upstream from us to build their command
* lists.
*/
assert(source);
ptr = (*source->handler)(source, inp, outCount, sampleOffset, p);
/*
* construct our portion of the command list
*/
aSetBuffer(ptr++, A_MAIN, *inp, AL_MAIN_L_OUT + *outp, outCount<<1);
aSetBuffer(ptr++, A_AUX, AL_MAIN_R_OUT + *outp, AL_AUX_L_OUT + *outp,
AL_AUX_R_OUT + *outp);
if (e->first){
e->first = 0;
/*
* Calculate derived parameters
*/
e->ltgt = (e->volume * eqpower[e->pan]) >> 15;
e->lratm = _getRate((f64)e->cvolL, (f64)e->ltgt,
e->segEnd, &(e->lratl));
e->rtgt = (e->volume *
eqpower[EQPOWER_LENGTH - e->pan - 1]) >> 15;
e->rratm = _getRate((f64)e->cvolR, (f64)e->rtgt, e->segEnd,
&(e->rratl));
aSetVolume(ptr++, A_LEFT | A_VOL, e->cvolL, 0, 0);
aSetVolume(ptr++, A_RIGHT | A_VOL, e->cvolR, 0, 0);
aSetVolume(ptr++, A_LEFT | A_RATE, e->ltgt, e->lratm, e->lratl);
aSetVolume(ptr++, A_RIGHT | A_RATE, e->rtgt, e->rratm, e->rratl);
aSetVolume(ptr++, A_AUX, e->dryamt, 0, e->wetamt);
aEnvMixer (ptr++, A_INIT | A_AUX, osVirtualToPhysical(e->state));
}
else
aEnvMixer(ptr++, A_CONTINUE | A_AUX, osVirtualToPhysical(e->state));
/*
* bump the input buffer pointer
*/
*inp += (outCount<<1);
//e->delta += outCount;
return ptr;
}
#define EXP_MASK 0x7f800000
#define MANT_MASK 0x807fffff
f64
_frexpf(f64 value, s32 *eptr)
{
f64 absvalue;
*eptr = 0;
if (value == 0.0) /* nothing to do for zero */
return (value);
absvalue = (value > 0.0) ? value : -value;
for ( ; absvalue >= 1.0; absvalue *= 0.5)
++*eptr;
for ( ; absvalue < 0.5; absvalue += absvalue)
--*eptr;
return (value > 0.0 ? absvalue : -absvalue);
}
f64
_ldexpf(f64 in, s32 ex)
{
s32 exp;
if ( ex ) {
exp = 1 << ex;
in *= (f64)exp;
}
return ( in );
}
/*
_getRate() -- This function determines how to go from the
current volume level (vol) to the target
volume level (tgt) in some number of steps
(count). Two values are returned that are
used as multipliers to incrementally scale
the volume. Some tricky math is used and
is explained below.
RWW 28jun95
*/
static
s16 _getRate(f64 vol, f64 tgt, s32 count, u16* ratel)
{
s16 s;
f64 a;
#ifdef AUD_PROFILE
lastCnt[++cnt_index] = osGetCount();
#endif
if (count == 0){
if (tgt >= vol){
*ratel = 0xffff;
return 0x7fff;
}
else{
*ratel = 0;
return -0x8000;
}
}
a = ((tgt - vol)/(f32)count) * 8.0;
if(a < 0.0)
a = a - 1.0;
s = (s16) a;
*ratel = (s16)(0xffff * (a - (f32) s));
#ifdef AUD_PROFILE
PROFILE_AUD(rate_num, rate_cnt, rate_max, rate_min);
#endif
return (s16)a;
}
static
f32 _getVol(f32 ivol, s32 samples, s16 ratem, u16 ratel)
{
f32 r;
#ifdef AUD_PROFILE
lastCnt[++cnt_index] = osGetCount();
#endif
r = ((f32) (ratem<<16) + (f32) ratel)/65536.0;
ivol += r* samples * 0.125;
#ifdef AUD_PROFILE
PROFILE_AUD(vol_num, vol_cnt, vol_max, vol_min);
#endif
return ivol;
}

View File

@@ -0,0 +1,137 @@
#include <ultra64.h>
#include "functions.h"
#include "variables.h"
void alEvtqNew(ALEventQueue *evtq, ALEventListItem *items, s32 itemCount)
{
s32 i;
evtq->eventCount = 0;
evtq->allocList.next = 0;
evtq->allocList.prev = 0;
evtq->freeList.next = 0;
evtq->freeList.prev = 0;
if(itemCount > 0){
i = 0;
do{
alLink(&items[i].node, &evtq->freeList);
i++;
} while (i != itemCount);
}
}
ALMicroTime alEvtqNextEvent(ALEventQueue *evtq, ALEvent *evt)
{
ALEventListItem *item;
ALMicroTime delta;
OSIntMask mask;
mask = osSetIntMask(OS_IM_NONE);
item = (ALEventListItem *)evtq->allocList.next;
if (item)
{
alUnlink((ALLink *)item);
alCopy(&item->evt, evt, sizeof(*evt));
alLink((ALLink *)item, &evtq->freeList);
delta = item->delta;
}
else
{
/* sct 11/28/95 - If we get here, most like we overflowed the event queue */
/* with non-self-perpetuating events. Eg. if we filled the evtq with volume */
/* events, then when the seqp is told to play it will handle all the events */
/* at once completely emptying out the queue. At this point this problem */
/* must be treated as an out of resource error and the evtq should be increased. */
evt->type = -1;
delta = 0;
}
osSetIntMask(mask);
return delta;
}
void alEvtqPostEvent(ALEventQueue *evtq, ALEvent *evt, ALMicroTime delta)
{
ALEventListItem *item;
ALEventListItem *nextItem;
ALLink *node;
s32 postAtEnd=0;
OSIntMask mask;
mask = osSetIntMask(OS_IM_NONE);
item = (ALEventListItem *)evtq->freeList.next;
if (!item) {
osSetIntMask(mask);
return;
}
alUnlink(&item->node);
alCopy(evt, &item->evt, sizeof(item->evt));
if (delta == AL_EVTQ_END)
postAtEnd = -1;
for (node = &evtq->allocList; node != 0; node = node->next) {
if (!node->next) { /* end of the list */
if (postAtEnd)
item->delta = 0;
else
item->delta = delta;
alLink(&item->node, node);
break;
} else {
nextItem = (ALEventListItem *)node->next;
if (delta < nextItem->delta) {
item->delta = delta;
nextItem->delta -= delta;
alLink(&item->node, node);
break;
}
delta -= nextItem->delta;
}
}
osSetIntMask(mask);
}
void alEvtqFlushType(ALEventQueue *evtq, s16 type)
{
ALLink *thisNode;
ALLink *nextNode;
ALEventListItem *thisItem, *nextItem;
OSIntMask mask;
mask = osSetIntMask(OS_IM_NONE);
thisNode = evtq->allocList.next;
while( thisNode != 0 )
{
nextNode = thisNode->next;
thisItem = (ALEventListItem *)thisNode;
nextItem = (ALEventListItem *)nextNode;
if (thisItem->evt.type == type)
{
if (nextItem)
nextItem->delta += thisItem->delta;
alUnlink(thisNode);
alLink(thisNode, &evtq->freeList);
}
thisNode = nextNode;
}
osSetIntMask(mask);
}

View File

@@ -0,0 +1,12 @@
#include <ultra64.h>
#include "synthInternals.h"
void alFilterNew(ALFilter *f, ALCmdHandler h, ALSetParam s, s32 type)
{
f->source = 0;
f->handler = h;
f->setParam = s;
f->inp = 0;
f->outp = 0;
f->type = type;
}

View File

@@ -0,0 +1,43 @@
#include <ultra64.h>
#include "synthInternals.h"
void *alHeapDBAlloc(u8 *file, s32 line, ALHeap *hp, s32 num, s32 size)
{
s32 bytes;
u8 *ptr = 0;
bytes = (num*size + AL_CACHE_ALIGN) & ~AL_CACHE_ALIGN;
#ifdef _DEBUG
hp->count++;
bytes += sizeof(HeapInfo);
#endif
if ((hp->cur + bytes) <= (hp->base + hp->len)) {
ptr = hp->cur;
hp->cur += bytes;
#ifdef _DEBUG
((HeapInfo *)ptr)->magic = AL_HEAP_MAGIC;
((HeapInfo *)ptr)->size = bytes;
((HeapInfo *)ptr)->count = hp->count;
if (file) {
((HeapInfo *)ptr)->file = file;
((HeapInfo *)ptr)->line = line;
} else {
((HeapInfo *)ptr)->file = (u8 *) "unknown";
((HeapInfo *)ptr)->line = 0;
}
ptr += sizeof(HeapInfo);
#endif
} else {
#ifdef _DEBUG
__osError(ERR_ALHEAPNOFREE, 1, size);
#endif
}
return ptr;
}

View File

@@ -0,0 +1,16 @@
#include "synthInternals.h"
#include <libaudio.h>
void alHeapInit(ALHeap *hp, u8 *base, s32 len)
{
s32 extraAlign = (AL_CACHE_ALIGN+1) - ((s32) base & AL_CACHE_ALIGN);
if (extraAlign != AL_CACHE_ALIGN+1)
hp->base = base + extraAlign;
else
hp->base = base;
hp->len = len;
hp->cur = hp->base;
hp->count = 0;
}

446
src/core1/done/audio/load.c Normal file
View File

@@ -0,0 +1,446 @@
#include <ultra64.h>
#include "synthInternals.h"
#ifndef MIN
# define MIN(a,b) (((a)<(b))?(a):(b))
#endif
#ifdef AUD_PROFILE
extern u32 cnt_index, adpcm_num, adpcm_cnt, adpcm_max, adpcm_min, lastCnt[];
#endif
#define ADPCMFBYTES 9
#define LFSAMPLES 4
static
Acmd *_decodeChunk(Acmd *ptr, ALLoadFilter *f, s32 tsam, s32 nbytes, s16 outp, s16 inp, u32 flags);
Acmd *alAdpcmPull(void *filter, s16 *outp, s32 outCount, s32 sampleOffset, Acmd *p)
{
Acmd *ptr = p;
s16 inp;
s32 tsam;
s32 nframes;
s32 nbytes;
s32 overFlow;
s32 startZero;
s32 nOver;
s32 nSam;
s32 op;
s32 nLeft;
s32 bEnd;
s32 decoded = 0;
s32 looped = 0;
ALLoadFilter *f = (ALLoadFilter *)filter;
#ifdef AUD_PROFILE
lastCnt[++cnt_index] = osGetCount();
#endif
if (outCount == 0)
return ptr;
inp = AL_DECODER_IN;
aLoadADPCM(ptr++, f->bookSize,
K0_TO_PHYS(f->table->waveInfo.adpcmWave.book->book));
looped = (outCount + f->sample > f->loop.end) && (f->loop.count != 0);
if (looped)
nSam = f->loop.end - f->sample;
else
nSam = outCount;
if (f->lastsam)
nLeft = ADPCMFSIZE - f->lastsam;
else
nLeft = 0;
tsam = nSam - nLeft;
if (tsam<0) tsam = 0;
nframes = (tsam+ADPCMFSIZE-1)>>LFSAMPLES;
nbytes = nframes*ADPCMFBYTES;
if (looped){
ptr = _decodeChunk(ptr, f, tsam, nbytes, *outp, inp, f->first);
/*
* Fix up output pointer, which will be used as the input pointer
* by the following module.
*/
if (f->lastsam)
*outp += (f->lastsam<<1);
else
*outp += (ADPCMFSIZE<<1);
/*
* Now fix up state info to reflect the loop start point
*/
f->lastsam = f->loop.start &0xf;
f->memin = (s32) f->table->base + ADPCMFBYTES *
((s32) (f->loop.start>>LFSAMPLES) + 1);
f->sample = f->loop.start;
bEnd = *outp;
while (outCount > nSam){
outCount -= nSam;
/*
* Put next one after the end of the last lot - on the
* frame boundary (32 byte) after the end.
*/
op = (bEnd + ((nframes+1)<<(LFSAMPLES+1))) & ~0x1f;
/*
* The actual end of data
*/
bEnd += (nSam<<1);
/*
* -1 is loop forever - the loop count is not exact now
* for small loops!
*/
if ((f->loop.count != -1) && (f->loop.count != 0))
f->loop.count--;
/*
* What's left to compute.
*/
nSam = MIN(outCount, f->loop.end - f->loop.start);
tsam = nSam - ADPCMFSIZE + f->lastsam;
if (tsam<0) tsam = 0;
nframes = (tsam+ADPCMFSIZE-1)>>LFSAMPLES;
nbytes = nframes*ADPCMFBYTES;
ptr = _decodeChunk(ptr, f, tsam, nbytes, op, inp, f->first | A_LOOP);
/*
* Merge the two sections in DMEM.
*/
aDMEMMove(ptr++, op+(f->lastsam<<1), bEnd, nSam<<1);
}
f->lastsam = (outCount + f->lastsam) & 0xf;
f->sample += outCount;
f->memin += ADPCMFBYTES*nframes;
#ifdef AUD_PROFILE
PROFILE_AUD(adpcm_num, adpcm_cnt, adpcm_max, adpcm_min);
#endif
return ptr;
}
/*
* The unlooped case, which is executed most of the time
*/
nSam = nframes<<LFSAMPLES;
/*
* overFlow is the number of bytes past the end
* of the bitstream I try to generate
*/
overFlow = f->memin + nbytes - ((s32) f->table->base + f->table->len);
if (overFlow < 0)
overFlow = 0;
nOver = (overFlow/ADPCMFBYTES)<<LFSAMPLES;
if (nOver > nSam + nLeft)
nOver = nSam + nLeft;
nbytes -= overFlow;
if ((nOver - (nOver & 0xf))< outCount){
decoded = 1;
ptr = _decodeChunk(ptr, f, nSam - nOver, nbytes, *outp, inp, f->first);
if (f->lastsam)
*outp += (f->lastsam<<1);
else
*outp += (ADPCMFSIZE<<1);
f->lastsam = (outCount + f->lastsam) & 0xf;
f->sample += outCount;
f->memin += ADPCMFBYTES*nframes;
} else {
f->lastsam = 0;
f->memin += ADPCMFBYTES*nframes;
}
/*
* Put zeros in if necessary
*/
if (nOver){
f->lastsam = 0;
if (decoded)
startZero = (nLeft + nSam - nOver)<<1;
else
startZero = 0;
aClearBuffer(ptr++, startZero + *outp, nOver<<1);
}
#ifdef AUD_PROFILE
PROFILE_AUD(adpcm_num, adpcm_cnt, adpcm_max, adpcm_min);
#endif
return ptr;
}
Acmd *alRaw16Pull(void *filter, s16 *outp, s32 outCount, s32 sampleOffset, Acmd *p)
{
Acmd *ptr = p;
s32 nbytes;
s32 dramLoc;
s32 dramAlign;
s32 dmemAlign;
s32 overFlow;
s32 startZero;
s32 nSam;
s32 op;
ALLoadFilter *f = (ALLoadFilter *)filter;
ALFilter *a = (ALFilter *) filter;
if (outCount == 0)
return ptr;
if ((outCount + f->sample > f->loop.end) && (f->loop.count != 0)){
nSam = f->loop.end - f->sample;
nbytes = nSam<<1;
if (nSam > 0){
dramLoc = (f->dma)(f->memin, nbytes, f->dmaState);
/*
* Make sure enough is loaded into DMEM to take care
* of 8 byte alignment
*/
dramAlign = dramLoc & 0x7;
nbytes += dramAlign;
aSetBuffer(ptr++, 0, *outp, 0, nbytes + 8 - (nbytes & 0x7));
aLoadBuffer(ptr++, dramLoc - dramAlign);
} else
dramAlign = 0;
/*
* Fix up output pointer to allow for dram alignment
*/
*outp += dramAlign;
f->memin = (s32) f->table->base + (f->loop.start<<1);
f->sample = f->loop.start;
op = *outp;
while (outCount > nSam){
op += (nSam<<1);
outCount -= nSam;
/*
* -1 is loop forever
*/
if ((f->loop.count != -1) && (f->loop.count != 0))
f->loop.count--;
/*
* What to compute.
*/
nSam = MIN(outCount, f->loop.end - f->loop.start);
nbytes = nSam<<1;
/*
* Do the next section, same as last.
*/
dramLoc = (f->dma)(f->memin, nbytes, f->dmaState);
/*
* Make sure enough is loaded into DMEM to take care
* of 8 byte alignment
*/
dramAlign = dramLoc & 0x7;
nbytes += dramAlign;
if (op & 0x7)
dmemAlign = 8 - (op & 0x7);
else
dmemAlign = 0;
aSetBuffer(ptr++, 0, op + dmemAlign, 0, nbytes + 8 - (nbytes & 0x7));
aLoadBuffer(ptr++, dramLoc - dramAlign);
/*
* Merge the two sections in DMEM.
*/
if (dramAlign || dmemAlign)
aDMEMMove(ptr++, op+dramAlign+dmemAlign, op, nSam<<1);
}
f->sample += outCount;
f->memin += (outCount<<1);
return ptr;
}
/*
* The unlooped case, which is executed most of the time
*
* overFlow is the number of bytes past the end
* of the bitstream I try to generate
*/
nbytes = outCount<<1;
overFlow = f->memin + nbytes - ((s32) f->table->base + f->table->len);
if (overFlow < 0)
overFlow = 0;
if (overFlow > nbytes)
overFlow = nbytes;
if (overFlow < nbytes){
if (outCount > 0){
nbytes -= overFlow;
dramLoc = (f->dma)(f->memin, nbytes, f->dmaState);
/*
* Make sure enough is loaded into DMEM to take care
* of 8 byte alignment
*/
dramAlign = dramLoc & 0x7;
nbytes += dramAlign;
aSetBuffer(ptr++, 0, *outp, 0, nbytes + 8 - (nbytes & 0x7));
aLoadBuffer(ptr++, dramLoc - dramAlign);
} else
dramAlign = 0;
*outp += dramAlign;
f->sample += outCount;
f->memin += outCount<<1;
} else {
f->memin += outCount<<1;
}
/*
* Put zeros in if necessary
*/
if (overFlow){
startZero = (outCount<<1) - overFlow;
if (startZero < 0)
startZero = 0;
aClearBuffer(ptr++, startZero + *outp, overFlow);
}
return ptr;
}
s32
alLoadParam(void *filter, s32 paramID, void *param)
{
ALLoadFilter *a = (ALLoadFilter *) filter;
ALFilter *f = (ALFilter *) filter;
switch (paramID) {
case (AL_FILTER_SET_WAVETABLE):
a->table = (ALWaveTable *) param;
a->memin = (s32) a->table->base;
a->sample = 0;
switch (a->table->type){
case (AL_ADPCM_WAVE):
/*
* Set up the correct handler
*/
f->handler = alAdpcmPull;
/*
* Make sure the table length is an integer number of
* frames
*/
a->table->len = ADPCMFBYTES *
((s32) (a->table->len/ADPCMFBYTES));
a->bookSize = 2*a->table->waveInfo.adpcmWave.book->order*
a->table->waveInfo.adpcmWave.book->npredictors*ADPCMVSIZE;
if (a->table->waveInfo.adpcmWave.loop) {
a->loop.start = a->table->waveInfo.adpcmWave.loop->start;
a->loop.end = a->table->waveInfo.adpcmWave.loop->end;
a->loop.count = a->table->waveInfo.adpcmWave.loop->count;
alCopy(a->table->waveInfo.adpcmWave.loop->state,
a->lstate, sizeof(ADPCM_STATE));
} else {
a->loop.start = a->loop.end = a->loop.count = 0;
}
break;
case (AL_RAW16_WAVE):
f->handler = alRaw16Pull;
if (a->table->waveInfo.rawWave.loop) {
a->loop.start = a->table->waveInfo.rawWave.loop->start;
a->loop.end = a->table->waveInfo.rawWave.loop->end;
a->loop.count = a->table->waveInfo.rawWave.loop->count;
} else {
a->loop.start = a->loop.end = a->loop.count = 0;
}
break;
default:
break;
}
break;
case (AL_FILTER_RESET):
a->lastsam = 0;
a->first = 1;
a->sample = 0;
/* sct 2/14/96 - Check table since it is initialized to null and */
/* Get loop info according to table type. */
if (a->table)
{
a->memin = (s32) a->table->base;
if (a->table->type == AL_ADPCM_WAVE)
{
if (a->table->waveInfo.adpcmWave.loop)
a->loop.count = a->table->waveInfo.adpcmWave.loop->count;
}
else if (a->table->type == AL_RAW16_WAVE)
{
if (a->table->waveInfo.rawWave.loop)
a->loop.count = a->table->waveInfo.rawWave.loop->count;
}
}
break;
default:
break;
}
}
Acmd *_decodeChunk(Acmd *ptr, ALLoadFilter *f, s32 tsam, s32 nbytes, s16 outp, s16 inp, u32 flags)
{
s32
dramAlign,
dramLoc;
if (nbytes > 0){
dramLoc = (f->dma)(f->memin, nbytes, f->dmaState);
/*
* Make sure enough is loaded into DMEM to take care
* of 8 byte alignment
*/
dramAlign = dramLoc & 0x7;
nbytes += dramAlign;
aSetBuffer(ptr++, 0, inp, 0, nbytes + 8 - (nbytes & 0x7));
aLoadBuffer(ptr++, dramLoc - dramAlign);
} else
dramAlign = 0;
if (flags & A_LOOP){
aSetLoop(ptr++, K0_TO_PHYS(f->lstate));
}
aSetBuffer(ptr++, 0, inp + dramAlign, outp, tsam<<1);
aADPCMdec(ptr++, flags, K0_TO_PHYS(f->state));
f->first = 0;
return ptr;
}

View File

@@ -0,0 +1,46 @@
#include <ultra64.h>
#include "synthInternals.h"
Acmd *alMainBusPull(void *filter, s16 *outp, s32 outCount, s32 sampleOffset, Acmd *p)
{
Acmd *ptr = p;
ALMainBus *m = (ALMainBus *)filter;
ALFilter **sources = m->sources;
s32 i;
/*
* clear the output buffers here
*/
aClearBuffer(ptr++, AL_MAIN_L_OUT, outCount<<1);
aClearBuffer(ptr++, AL_MAIN_R_OUT, outCount<<1);
for (i = 0; i < m->sourceCount; i++) {
ptr = (sources[i]->handler)(sources[i], outp, outCount, sampleOffset,
ptr);
aSetBuffer(ptr++, 0, 0, 0, outCount<<1);
aMix(ptr++, 0, 0x7fff, AL_AUX_L_OUT, AL_MAIN_L_OUT);
aMix(ptr++, 0, 0x7fff, AL_AUX_R_OUT, AL_MAIN_R_OUT);
}
return ptr;
}
s32 alMainBusParam(void *filter, s32 paramID, void *param)
{
ALMainBus *m = (ALMainBus *) filter;
ALFilter **sources = m->sources;
switch (paramID) {
case (AL_FILTER_ADD_SOURCE):
sources[m->sourceCount++] = (ALFilter *) param;
break;
default:
/* ??? */
break;
}
return 0;
}

View File

@@ -0,0 +1,23 @@
#include <ultra64.h>
#include "functions.h"
#include "variables.h"
#include "n_synth.h"
Acmd *n_alAuxBusPull(s32 sampleOffset, Acmd *p)
{
Acmd *ptr = p;
N_ALAuxBus *m = (N_ALAuxBus *)n_syn->auxBus;
N_PVoice **sources = m->sources;
s32 i;
#ifndef N_MICRO
aClearBuffer(ptr++, AL_AUX_L_OUT, FIXED_SAMPLE<<1);
aClearBuffer(ptr++, AL_AUX_R_OUT, FIXED_SAMPLE<<1);
#else
aClearBuffer(ptr++, N_AL_AUX_L_OUT, N_AL_DIVIDED<<1);
#endif
for (i = 0; i < m->sourceCount; i++)
ptr = n_alEnvmixerPull(sources[i],sampleOffset,ptr);
return ptr;
}

View File

@@ -0,0 +1,870 @@
#include <ultra64.h>
#include "n_synth.h"
#include <assert.h>
#include "seqp.h"
#include "n_cseqp.h"
#include "cseq.h"
#ifndef assert
#define assert(s)
#endif
static ALMicroTime __n_CSPVoiceHandler(void *node);
static void __n_CSPHandleNextSeqEvent(N_ALCSPlayer *seqp);
static void __n_CSPHandleMIDIMsg(N_ALCSPlayer *seqp, N_ALEvent *event);
static void __n_CSPHandleMetaMsg(N_ALCSPlayer *seqp, N_ALEvent *event);
static void __n_CSPRepostEvent(ALEventQueue *evtq, N_ALEventListItem *item);
static void __n_setUsptFromTempo(N_ALCSPlayer *seqp, ALCSeq *target, f32 tempo); /* sct 1/8/96 */
/*
* Sequence Player public functions
*/
/*done*/
void n_alCSPNew(N_ALCSPlayer *seqp, ALSeqpConfig *c)
{
s32 i;
N_ALEventListItem *items;
N_ALVoiceState *vs;
N_ALVoiceState *voices;
ALHeap *hp = c->heap;
/*
* initialize member variables
*/
seqp->bank = 0;
seqp->target = NULL;
seqp->drvr = n_syn;
seqp->chanMask = 0xffff;
seqp->uspt = 488;
seqp->nextDelta = 0;
seqp->state = AL_STOPPED;
seqp->vol = 0x7FFF; /* full volume */
seqp->debugFlags = c->debugFlags;
seqp->frameTime = AL_USEC_PER_FRAME; /* should get this from driver */
seqp->curTime = 0;
seqp->initOsc = c->initOsc;
seqp->updateOsc = c->updateOsc;
seqp->stopOsc = c->stopOsc;
seqp->nextEvent.type = AL_SEQP_API_EVT; /* this will start the voice handler "spinning" */
/*
* init the channel state
*/
seqp->maxChannels = c->maxChannels;
seqp->chanState = alHeapAlloc(hp, c->maxChannels, sizeof(ALChanState) );
__initChanState((ALSeqPlayer*)seqp); /* sct 11/6/95 */
/*
* init the voice state array
*/
voices = alHeapAlloc(hp, c->maxVoices, sizeof(ALVoiceState));
seqp->vFreeList = 0;
for (i = 0; i < c->maxVoices; i++) {
vs = &voices[i];
vs->next = seqp->vFreeList;
seqp->vFreeList = vs;
}
seqp->vAllocHead = 0;
seqp->vAllocTail = 0;
/*
* init the event queue
*/
items = alHeapAlloc(hp, c->maxEvents, sizeof(ALEventListItem));
alEvtqNew(&seqp->evtq, items, c->maxEvents);
/*
* add ourselves to the driver
*/
seqp->node.next = NULL;
seqp->node.handler = __n_CSPVoiceHandler;
seqp->node.clientData = seqp;
n_alSynAddSeqPlayer(&seqp->node);
}
/*************************************************************
* private routines or driver callback routines
*************************************************************/
static ALMicroTime __n_CSPVoiceHandler(void *node)
{
N_ALCSPlayer *seqp = (N_ALCSPlayer *) node;
N_ALEvent evt;
ALVoice *voice;
ALMicroTime delta;
ALVoiceState *vs;
void *oscState;
f32 oscValue;
u8 chan;
do {
switch (seqp->nextEvent.type)
{
case (AL_SEQ_REF_EVT):
__n_CSPHandleNextSeqEvent(seqp);
break;
case (AL_SEQP_API_EVT):
evt.type = AL_SEQP_API_EVT;
alEvtqPostEvent(&seqp->evtq, (ALEvent *)&evt, seqp->frameTime);
break;
case (AL_NOTE_END_EVT):
voice = seqp->nextEvent.msg.note.voice;
n_alSynStopVoice(voice);
n_alSynFreeVoice(voice);
vs = (ALVoiceState *)voice->clientPrivate;
if(vs->flags)
__seqpStopOsc((ALSeqPlayer*)seqp,vs);
__unmapVoice((ALSeqPlayer*)seqp, voice);
break;
case (AL_SEQP_ENV_EVT):
voice = seqp->nextEvent.msg.vol.voice;
vs = (ALVoiceState *)voice->clientPrivate;
if(vs->envPhase == AL_PHASE_ATTACK)
vs->envPhase = AL_PHASE_DECAY;
delta = seqp->nextEvent.msg.vol.delta;
vs->envEndTime = seqp->curTime + delta;
vs->envGain = seqp->nextEvent.msg.vol.vol;
n_alSynSetVol(voice, __vsVol(vs, (ALSeqPlayer*)seqp), delta);
break;
case (AL_TREM_OSC_EVT):
vs = seqp->nextEvent.msg.osc.vs;
oscState = seqp->nextEvent.msg.osc.oscState;
delta = (*seqp->updateOsc)(oscState,&oscValue);
vs->tremelo = (u8)oscValue;
n_alSynSetVol(&vs->voice, __vsVol(vs,(ALSeqPlayer*)seqp),
__vsDelta(vs,seqp->curTime));
evt.type = AL_TREM_OSC_EVT;
evt.msg.osc.vs = vs;
evt.msg.osc.oscState = oscState;
alEvtqPostEvent(&seqp->evtq, &evt, delta);
break;
case (AL_VIB_OSC_EVT):
vs = seqp->nextEvent.msg.osc.vs;
oscState = seqp->nextEvent.msg.osc.oscState;
chan = seqp->nextEvent.msg.osc.chan;
delta = (*seqp->updateOsc)(oscState,&oscValue);
vs->vibrato = oscValue;
n_alSynSetPitch(&vs->voice, vs->pitch * vs->vibrato
* seqp->chanState[chan].pitchBend);
evt.type = AL_VIB_OSC_EVT;
evt.msg.osc.vs = vs;
evt.msg.osc.oscState = oscState;
evt.msg.osc.chan = chan;
alEvtqPostEvent(&seqp->evtq, &evt, delta);
break;
case (AL_SEQP_MIDI_EVT):
case (AL_CSP_NOTEOFF_EVT): /* nextEvent is a note off midi message */
__n_CSPHandleMIDIMsg(seqp, &seqp->nextEvent);
break;
case (AL_SEQP_META_EVT):
__n_CSPHandleMetaMsg(seqp, &seqp->nextEvent);
break;
case (AL_SEQP_VOL_EVT):
seqp->vol = seqp->nextEvent.msg.spvol.vol;
for (vs = seqp->vAllocHead; vs != 0; vs = vs->next)
{
n_alSynSetVol(&vs->voice,
__vsVol(vs, (ALSeqPlayer*)seqp),
__vsDelta(vs, seqp->curTime));
}
break;
case (AL_SEQP_PLAY_EVT):
if (seqp->state != AL_PLAYING)
{
seqp->state = AL_PLAYING;
func_80250650();
__n_CSPPostNextSeqEvent(seqp); /* seqp must be AL_PLAYING before we call this routine. */
}
break;
case (AL_SEQP_STOP_EVT):
if ( seqp->state == AL_STOPPING )
{
for (vs = seqp->vAllocHead; vs != 0; vs = seqp->vAllocHead)
{
#ifdef _DEBUG
__osError(ERR_ALCSPVNOTFREE, 2, vs->channel, vs->key);
#endif
n_alSynStopVoice(&vs->voice);
n_alSynFreeVoice(&vs->voice);
if(vs->flags)
__seqpStopOsc((ALSeqPlayer*)seqp,vs);
__unmapVoice((ALSeqPlayer*)seqp, &vs->voice);
}
seqp->state = AL_STOPPED;
/* alEvtqFlush(&seqp->evtq); - Don't flush event queue
anymore. */
/* sct 1/3/96 - Don't overwrite nextEvent with
AL_SEQP_API_EVT or set nextDelta to
AL_USEC_PER_FRAME since we're not stopping event
processing. */
/* sct 1/3/96 - Don't return here since we keep
processing events as usual. */
}
break;
case (AL_SEQP_STOPPING_EVT):
if (seqp->state == AL_PLAYING)
{
/* sct 12/29/95 - Remove events associated with the
* stopping sequence. For compact sequence player,
* also remove all queued note off events since they
* are not contained in a compact sequence but are
* generated in response to note ons. Note that
* flushing AL_SEQP_MIDI_EVTs may flush events that
* were posted after the call to alSeqpStop, so the
* application must queue these events either when
* the player is fully stopped, or when it is
* playing. */
alEvtqFlushType(&seqp->evtq, AL_SEQ_REF_EVT);
alEvtqFlushType(&seqp->evtq, AL_CSP_NOTEOFF_EVT);
alEvtqFlushType(&seqp->evtq, AL_SEQP_MIDI_EVT);
/* sct 1/3/96 - Check to see which voices need to be
killed and release them. */
/* Unkilled voices should have note end events
occurring prior to KILL_TIME. */
for (vs = seqp->vAllocHead; vs != 0; vs = vs->next)
{
if (__voiceNeedsNoteKill ((ALSeqPlayer*)seqp, &vs->voice, KILL_TIME))
__seqpReleaseVoice((ALSeqPlayer*)seqp, &vs->voice, KILL_TIME);
}
seqp->state = AL_STOPPING;
evt.type = AL_SEQP_STOP_EVT;
alEvtqPostEvent(&seqp->evtq, &evt, AL_EVTQ_END);
}
break;
case (AL_SEQP_PRIORITY_EVT):
chan = seqp->nextEvent.msg.sppriority.chan;
seqp->chanState[chan].priority = seqp->nextEvent.msg.sppriority.priority;
break;
case (AL_SEQP_SEQ_EVT):
//assert(seqp->state != AL_PLAYING); /* Must be done playing to change sequences. */
((seqp->state != AL_PLAYING)?((void)0):func_8033F000("seqp->state != AL_PLAYING","n_csplayer.c", 272));
seqp->target = seqp->nextEvent.msg.spseq.seq;
seqp->chanMask = 0xFFFF;
if (seqp->bank)
__initFromBank((ALSeqPlayer *)seqp, seqp->bank);
break;
case (AL_SEQP_BANK_EVT):
//assert(seqp->state == AL_STOPPED); /* Must be fully stopped to change banks. */
((seqp->state == AL_STOPPED)?((void)0):func_8033F000("seqp->state == AL_STOPPED","n_csplayer.c", 283));
seqp->bank = seqp->nextEvent.msg.spbank.bank;
__initFromBank((ALSeqPlayer *)seqp, seqp->bank);
break;
/* sct 11/6/95 - these events should now be handled by __n_CSPHandleNextSeqEvent */
case (AL_SEQ_END_EVT):
case (AL_TEMPO_EVT):
case (AL_SEQ_MIDI_EVT):
//assert(FALSE);
((FALSE)?((void)0):func_8033F000("FALSE","n_csplayer.c", 296));
break;
}
seqp->nextDelta = alEvtqNextEvent(&seqp->evtq, &seqp->nextEvent);
} while (seqp->nextDelta == 0);
/*
* assume that next callback won't be more than half an
* hour away
*/
seqp->curTime += seqp->nextDelta; /* sct 11/7/95 */
return seqp->nextDelta;
}
/*
Calculates the delta time in ticks until the next sequence
event and posts a sequence reference event with the time in usecs.
Loops are handled automatically by the compact sequence.
Does nothing if the sequence player is not playing or if there
is no target sequence.
sct 11/7/95
*/
/*DONE*/
void __n_CSPPostNextSeqEvent(N_ALCSPlayer *seqp)
{
ALEvent evt;
s32 deltaTicks;
if (seqp->state != AL_PLAYING || seqp->target == NULL)
return;
/* Get the next event time in ticks. */
/* If false is returned, then there is no next delta (ie. end of sequence reached). */
if (!__alCSeqNextDelta(seqp->target, &deltaTicks))
return;
evt.type = AL_SEQ_REF_EVT;
alEvtqPostEvent(&seqp->evtq, &evt, deltaTicks * seqp->uspt);
}
/*
Call this routine to handle the next event in the sequence.
Assumes that the next sequence event is scheduled to be processed
immediately since it does not check the event's tick time.
sct 11/7/95
*/
static void
__n_CSPHandleNextSeqEvent(N_ALCSPlayer *seqp)
{
ALEvent evt;
/* sct 1/5/96 - Do nothing if we don't have a target sequence. */
if (seqp->target == NULL)
return;
alCSeqNextEvent(seqp->target, &evt);
switch (evt.type)
{
case AL_SEQ_MIDI_EVT:
__n_CSPHandleMIDIMsg(seqp, &evt);
__n_CSPPostNextSeqEvent(seqp);
break;
case AL_TEMPO_EVT:
__n_CSPHandleMetaMsg(seqp, &evt);
__n_CSPPostNextSeqEvent(seqp);
break;
case AL_SEQ_END_EVT:
seqp->state = AL_STOPPING;
evt.type = AL_SEQP_STOP_EVT;
alEvtqPostEvent(&seqp->evtq, &evt, AL_EVTQ_END);
break;
case AL_TRACK_END:
case AL_CSP_LOOPSTART:
case AL_CSP_LOOPEND:
__n_CSPPostNextSeqEvent(seqp);
break;
default:
//assert(FALSE); /* Sequence event type not supported. */
((FALSE)?((void)0):func_8033F000("FALSE","n_csplayer.c", 353));
break;
}
}
static void __n_CSPHandleMIDIMsg(N_ALCSPlayer *seqp, N_ALEvent *event)
{
N_ALVoice *voice;
N_ALVoiceState *vs;
s32 status;
u8 chan;
u8 key;
u8 vel;
u8 byte1;
u8 byte2;
ALMIDIEvent *midi = &event->msg.midi;
s16 vol;
N_ALEvent evt;
ALMicroTime deltaTime;
N_ALVoiceState *vstate;
ALPan pan;
ALFxRef fxref;
status = midi->status & AL_MIDI_StatusMask;
chan = midi->status & AL_MIDI_ChannelMask;
byte1 = key = midi->byte1;
byte2 = vel = midi->byte2;
if(status == AL_MIDI_ChannelModeSelect){
if(byte1 == 0x7E){
seqp->chanMask &= ~(1 << byte2);
vstate = seqp->vAllocHead;
while(vs){
if(vstate->channel == byte2){
__seqpReleaseVoice(seqp, &vstate->voice.node.next, vstate->sound->envelope->releaseTime);
}
vs = vs->next;
}
return;
}else if(byte1 == 0x7F){
seqp->chanMask |= (1 << byte2);
return;
}
}
if(!((seqp->chanMask & (1 << chan)) || status != AL_MIDI_NoteOn))
return;
//L8025DB08
switch (status)
{
case (AL_MIDI_NoteOn):
if (vel != 0) /* a real note on */
{
ALVoiceConfig config;
ALSound *sound;
s16 cents;
f32 pitch,oscValue;
u8 fxmix;
void *oscState;
ALInstrument *inst;
/* If we're not playing, don't process note ons. */
if (seqp->state != AL_PLAYING)
break;
sound = __lookupSoundQuick((ALSeqPlayer*)seqp, key, vel, chan);
ALFlagFailIf(!sound, seqp->debugFlags & NO_SOUND_ERR_MASK,
ERR_ALSEQP_NO_SOUND);
config.priority = seqp->chanState[chan].priority;
config.fxBus = 0;
config.unityPitch = 0;
vstate = __mapVoice((ALSeqPlayer*)seqp, key, vel, chan);
ALFlagFailIf(!vstate, seqp->debugFlags & NO_VOICE_ERR_MASK,
ERR_ALSEQP_NO_VOICE );
voice = &vstate->voice;
n_alSynAllocVoice(voice, &config);
/*
* set up the voice state structure
*/
vstate->sound = sound;
vstate->envPhase = AL_PHASE_ATTACK;
if (seqp->chanState[chan].sustain > AL_SUSTAIN)
vstate->phase = AL_PHASE_SUSTAIN;
else
vstate->phase = AL_PHASE_NOTEON;
cents = (key - sound->keyMap->keyBase) * 100
+ sound->keyMap->detune;
vstate->pitch = alCents2Ratio(cents);
vstate->envGain = sound->envelope->attackVolume;
vstate->envEndTime = seqp->curTime +
sound->envelope->attackTime;
/*
* setup tremelo and vibrato if active
*/
vstate->flags = 0;
inst = seqp->chanState[chan].instrument;
oscValue = (f32)AL_VOL_FULL; /* set this as a default */
if(inst->tremType)
{
if(seqp->initOsc)
{
deltaTime = (*seqp->initOsc)(&oscState,&oscValue,inst->tremType,
inst->tremRate,inst->tremDepth,inst->tremDelay);
if(deltaTime) /* a deltaTime of zero means don't run osc */
{
evt.type = AL_TREM_OSC_EVT;
evt.msg.osc.vs = vstate;
evt.msg.osc.oscState = oscState;
alEvtqPostEvent(&seqp->evtq, &evt, deltaTime);
vstate->flags |= 0x01; /* set tremelo flag bit */
}
}
}
vstate->tremelo = (u8)oscValue; /* will default if not changed by initOsc */
oscValue = 1.0f; /* set this as a default */
if(inst->vibType)
{
if(seqp->initOsc)
{
deltaTime = (*seqp->initOsc)(&oscState,&oscValue,inst->vibType,
inst->vibRate,inst->vibDepth,inst->vibDelay);
if(deltaTime) /* a deltaTime of zero means don't run osc. */
{
evt.type = AL_VIB_OSC_EVT;
evt.msg.osc.vs = vstate;
evt.msg.osc.oscState = oscState;
evt.msg.osc.chan = chan;
alEvtqPostEvent(&seqp->evtq, &evt, deltaTime);
vstate->flags |= 0x02; /* set the vibrato flag bit */
}
}
}
vstate->vibrato = oscValue; /* will default if not changed by initOsc */
/*
* calculate the note on parameters
*/
pitch = vstate->pitch * seqp->chanState[chan].pitchBend *
vstate->vibrato;
fxmix = seqp->chanState[chan].fxmix;
pan = __vsPan(vstate, (ALSeqPlayer*)seqp);
vol = __vsVol(vstate, (ALSeqPlayer*)seqp);
deltaTime = sound->envelope->attackTime;
n_alSynStartVoiceParams(voice, sound->wavetable,
pitch, vol, pan, fxmix, deltaTime);
/*
* set up callbacks for envelope
*/
evt.type = AL_SEQP_ENV_EVT;
evt.msg.vol.voice = voice;
evt.msg.vol.vol = sound->envelope->decayVolume;
evt.msg.vol.delta = sound->envelope->decayTime;
alEvtqPostEvent(&seqp->evtq, &evt, deltaTime);
if(midi->duration)
{
/*
* set up note off evt. if no duration don't do this
*/
evt.type = AL_CSP_NOTEOFF_EVT;
evt.msg.midi.status = chan | AL_MIDI_NoteOff;
evt.msg.midi.byte1 = key;
evt.msg.midi.byte2 = 0; /* not needed ? */
deltaTime = seqp->uspt * midi->duration;
/* max time would be about one hour ten minutes */
alEvtqPostEvent(&seqp->evtq, &evt, deltaTime);
}
break;
}
/*
* NOTE: intentional fall-through for note on with zero
* velocity (Should never happen with compact midi sequence,
* but could happen with real time midi.)
*/
case (AL_MIDI_NoteOff):
vstate = __lookupVoice((ALSeqPlayer*)seqp, key, chan);
ALFlagFailIf(!vstate, seqp->debugFlags & NOTE_OFF_ERR_MASK,
ERR_ALSEQP_OFF_VOICE );
if (vstate->phase == AL_PHASE_SUSTAIN)
vstate->phase = AL_PHASE_SUSTREL;
else
{
vstate->phase = AL_PHASE_RELEASE;
__seqpReleaseVoice((ALSeqPlayer*)seqp, &vstate->voice,
vstate->sound->envelope->releaseTime);
}
break;
case (AL_MIDI_PolyKeyPressure):
/*
* Aftertouch per key (hardwired to volume). Note that
* aftertouch affects only notes that are already
* sounding.
*/
vstate = __lookupVoice((ALSeqPlayer*)seqp, key, chan);
ALFailIf(!vstate, ERR_ALSEQP_POLY_VOICE );
vstate->velocity = byte2;
n_alSynSetVol(&vstate->voice,
__vsVol(vstate, (ALSeqPlayer*)seqp),
__vsDelta(vstate,seqp->curTime));
break;
case (AL_MIDI_ChannelPressure):
/*
* Aftertouch per channel (hardwired to volume). Note that
* aftertouch affects only notes that are already
* sounding.
*/
for (vs = seqp->vAllocHead; vs != 0; vs = vs->next) {
if (vs->channel == chan) {
vs->velocity = byte1;
n_alSynSetVol(&vs->voice,
__vsVol(vs, (ALSeqPlayer*)seqp),
__vsDelta(vs,seqp->curTime));
}
}
break;
case (AL_MIDI_ControlChange):
switch (byte1)
{
case (AL_MIDI_PAN_CTRL):
seqp->chanState[chan].pan = byte2;
for (vs = seqp->vAllocHead; vs != 0; vs = vs->next)
{
if (vs->channel == chan)
{
pan = __vsPan(vs, (ALSeqPlayer*)seqp);
n_alSynSetPan(&vs->voice, pan);
}
}
break;
case (AL_MIDI_VOLUME_CTRL):
seqp->chanState[chan].vol = byte2;
for (vs = seqp->vAllocHead; vs != 0; vs = vs->next)
{
if ((vs->channel == chan) && (vs->envPhase != AL_PHASE_RELEASE))
{
vol = __vsVol(vs, (ALSeqPlayer*)seqp);
n_alSynSetVol(&vs->voice, vol,
__vsDelta(vs,seqp->curTime));
}
}
break;
case (0x7D):
seqp->chanState[chan].unk9 = byte2;
for (vs = seqp->vAllocHead; vs != 0; vs = vs->next)
{
if ((vs->channel == chan) && (vs->envPhase != AL_PHASE_RELEASE))
{
vol = __vsVol(vs, (ALSeqPlayer*)seqp);
n_alSynSetVol(&vs->voice, vol,
__vsDelta(vs,seqp->curTime));
}
}
break;
case (AL_MIDI_PRIORITY_CTRL):
/* leave current voices where they are */
seqp->chanState[chan].priority = byte2;
break;
case (AL_MIDI_SUSTAIN_CTRL):
seqp->chanState[chan].sustain = byte2;
for (vs = seqp->vAllocHead; vs != 0; vs = vs->next)
{
if ((vs->channel == chan) && (vs->phase != AL_PHASE_RELEASE))
{
if ( byte2 > AL_SUSTAIN )
{
/*
* sustain pedal down
*/
if (vs->phase == AL_PHASE_NOTEON)
vs->phase = AL_PHASE_SUSTAIN;
}
else
{
/*
* sustain pedal up
*/
if (vs->phase == AL_PHASE_SUSTAIN)
vs->phase = AL_PHASE_NOTEON;
else if(vs->phase == AL_PHASE_SUSTREL)
{
vs->phase = AL_PHASE_RELEASE;
__seqpReleaseVoice((ALSeqPlayer*)seqp,
&vs->voice,
vs->sound->envelope->releaseTime);
}
}
}
}
break;
case (AL_MIDI_FX1_CTRL):
seqp->chanState[chan].fxmix = byte2;
for (vs = seqp->vAllocHead; vs != 0; vs = vs->next)
{
if (vs->channel == chan)
n_alSynSetFXMix(&vs->voice, byte2);
}
break;
case (0x6A):
case (0x6B):
case (0x6C):
case (0x6D):
case (0x6E):
case (0x6F):
case (0x70):
case (0x71):
case (0x72):
case (0x73):
case (0x74):
case (0x75):
case (0x76):
case (0x77):
func_80250104(seqp->target,key, chan);
break;
default:
break;
}
break;
case (AL_MIDI_ProgramChange):
/* sct 1/16/96 - We must have a valid bank in order to process the program change. */
//assert(seqp->bank != NULL);
((seqp->bank != NULL)?((void)0):func_8033F000("seqp->bank != NULL", "n_csplayer.c", 715));
if (key < seqp->bank->instCount)
{
ALInstrument *inst = seqp->bank->instArray[key];
__setInstChanState((ALSeqPlayer*)seqp, inst, chan); /* sct 11/6/95 */
}
else
{
#ifdef _DEBUG
__osError(ERR_ALSEQPINVALIDPROG, 2, key, seqp->bank->instCount);
#endif
}
break;
case (AL_MIDI_PitchBendChange):
{
s32 bendVal;
f32 bendRatio;
s32 cents;
/* get 14-bit unsigned midi value */
bendVal = ( (byte2 << 7) + byte1) - 8192;
/* calculate pitch bend in cents */
cents = (seqp->chanState[chan].bendRange * bendVal)/8192;
/* calculate the corresponding ratio */
bendRatio = alCents2Ratio(cents);
seqp->chanState[chan].pitchBend = bendRatio;
for (vs = seqp->vAllocHead; vs != 0; vs = vs->next)
if (vs->channel == chan)
n_alSynSetPitch(&vs->voice,
vs->pitch * bendRatio * vs->vibrato);
}
break;
default:
#ifdef _DEBUG
__osError(ERR_ALSEQPUNKNOWNMIDI, 1, status);
#endif
break;
}
}
/*Done*/
static void __n_CSPHandleMetaMsg(N_ALCSPlayer *seqp, N_ALEvent *event)
{
ALTempoEvent *tevt = &event->msg.tempo;
ALEvent evt;
s32 tempo;
s32 oldUspt;
u32 ticks;
ALMicroTime tempDelta,curDelta = 0;
ALEventListItem *thisNode,*nextNode,*firstTemp = 0;
if (event->msg.tempo.status == AL_MIDI_Meta)
{
if (event->msg.tempo.type == AL_MIDI_META_TEMPO)
{
oldUspt = seqp->uspt;
tempo = (tevt->byte1 << 16) | (tevt->byte2 << 8) | (tevt->byte3 << 0);
__n_setUsptFromTempo (seqp, seqp->target, (f32)tempo); /* sct 1/8/96 */
thisNode = (ALEventListItem*)seqp->evtq.allocList.next;
while(thisNode)
{
curDelta += thisNode->delta;
nextNode = (ALEventListItem*)thisNode->node.next;
if(thisNode->evt.type == AL_CSP_NOTEOFF_EVT)
{
alUnlink((ALLink*)thisNode);
if(firstTemp)
alLink((ALLink*)thisNode,(ALLink*)firstTemp);
else
{
thisNode->node.next = 0;
thisNode->node.prev = 0;
firstTemp = thisNode;
}
tempDelta = curDelta; /* record the current delta */
if(nextNode) /* don't do this if no nextNode */
{
curDelta -= thisNode->delta; /* subtract out this delta */
nextNode->delta += thisNode->delta; /* add it to next event */
}
thisNode->delta = tempDelta; /* set this event delta from current */
}
thisNode = nextNode;
}
thisNode = firstTemp;
while(thisNode)
{
nextNode = (ALEventListItem*)thisNode->node.next;
ticks = thisNode->delta/oldUspt;
thisNode->delta = ticks * seqp->uspt;
__n_CSPRepostEvent(&seqp->evtq,thisNode);
thisNode = nextNode;
}
}
}
}
/*Done*/
static void __n_CSPRepostEvent(ALEventQueue *evtq, N_ALEventListItem *item)
{
OSIntMask mask;
ALLink *node;
N_ALEventListItem *nextItem;
mask = osSetIntMask(OS_IM_NONE);
for (node = &evtq->allocList; node != 0; node = node->next)
{
if (!node->next) /* end of the list */
{
alLink((ALLink *)item, node);
break;
}
else
{
nextItem = (N_ALEventListItem *)node->next;
if (item->delta < nextItem->delta)
{
nextItem->delta -= item->delta;
alLink((ALLink *)item, node);
break;
}
item->delta -= nextItem->delta;
}
}
osSetIntMask(mask);
}
/*
This routine safely calculates the sequence player's
uspt value based on the given tempo. It does this safely
by making sure that the player has a target sequence and
therefore a qnpt value which is needed for the calculation.
Compact sequence player needs its own version of this routine
since the ALCSeq's qnpt field is at a different offset.
*/
/* DONE */
static void __n_setUsptFromTempo(N_ALCSPlayer *seqp, ALCSeq *target, f32 tempo)
{
if (target)
seqp->uspt = (s32)((f32)tempo * target->qnpt);
else
seqp->uspt = 488; /* This is the initial value set by alSeqpNew. */
}

View File

@@ -0,0 +1,292 @@
#include <ultra64.h>
#include "n_libaudio.h"
static u32 __readVarLen(ALCSeq *s,u32 track);
static u8 __getTrackByte(ALCSeq *s,u32 track);
static u32 __n_alCSeqGetTrackEvent(ALCSeq *seq, u32 track, N_ALEvent *event);
void n_alCSeqNew(ALCSeq *seq, u8 *ptr)
{
u32 i,tmpOff,flagTmp;
/* load the seqence pointed to by ptr */
seq->base = (ALCMidiHdr*)ptr;
seq->validTracks = 0;
seq->lastDeltaTicks = 0;
seq->lastTicks = 0;
seq->deltaFlag = 1;
for(i = 0; i < 16; i++)
{
seq->lastStatus[i] = 0;
seq->curBUPtr[i] = 0;
seq->curBULen[i] = 0;
tmpOff = seq->base->trackOffset[i];
if(tmpOff) /* if the track is valid */
{
flagTmp = 1 << i;
seq->validTracks |= flagTmp;
seq->curLoc[i] = (u8*)((u32)ptr + tmpOff);
seq->evtDeltaTicks[i] = __readVarLen(seq,i);
/*__n_alCSeqGetTrackEvent(seq,i); prime the event buffers */
}
else
seq->curLoc[i] = 0;
}
seq->qnpt = 1.0/(f32)seq->base->division;
}
void n_alCSeqNextEvent(ALCSeq *seq,N_ALEvent *evt)
{
u32 i;
u32 firstTime = 0xFFFFFFFF;
u32 firstTrack;
u32 lastTicks = seq->lastDeltaTicks;
#ifdef _DEBUG
/* sct 1/17/96 - Warn if we are beyond the end of sequence. */
if (!seq->validTracks)
__osError(ERR_ALSEQOVERRUN, 0);
#endif
for(i = 0; i < 16 ; i++)
{
if((seq->validTracks >> i) & 1)
{
if(seq->deltaFlag)
seq->evtDeltaTicks[i] -= lastTicks;
if(seq->evtDeltaTicks[i] < firstTime)
{
firstTime = seq->evtDeltaTicks[i];
firstTrack = i;
}
}
}
__n_alCSeqGetTrackEvent(seq,firstTrack,evt);
evt->msg.midi.ticks = firstTime;
seq->lastTicks += firstTime;
seq->lastDeltaTicks = firstTime;
if(evt->type != AL_TRACK_END)
seq->evtDeltaTicks[firstTrack] += __readVarLen(seq,firstTrack);
seq->deltaFlag = 1;
}
/* only call n_alCSeqGetTrackEvent with a valid track !! */
static u32 __n_alCSeqGetTrackEvent(ALCSeq *seq, u32 track, N_ALEvent *event)
{
u32 offset;
u8 status, loopCt, curLpCt, *tmpPtr;
status = __getTrackByte(seq,track); /* read the status byte */
if (status == AL_MIDI_Meta) /* running status not allowed on meta events!! */
{
u8 type = __getTrackByte(seq,track);
if (type == AL_MIDI_META_TEMPO)
{
event->type = AL_TEMPO_EVT;
event->msg.tempo.status = status;
event->msg.tempo.type = type;
event->msg.tempo.byte1 = __getTrackByte(seq,track);
event->msg.tempo.byte2 = __getTrackByte(seq,track);
event->msg.tempo.byte3 = __getTrackByte(seq,track);
seq->lastStatus[track] = 0; /* lastStatus not supported after meta */
}
else if (type == AL_MIDI_META_EOT)
{
u32 flagMask;
flagMask = 0x01 << track;
seq->validTracks = seq->validTracks ^ flagMask;
if(seq->validTracks) /* there is music left don't end */
event->type = AL_TRACK_END;
else /* no more music send AL_SEQ_END_EVT msg */
event->type = AL_SEQ_END_EVT;
}
else if (type == AL_CMIDI_LOOPSTART_CODE)
{
status = __getTrackByte(seq,track); /* get next two bytes, ignore them */
status = __getTrackByte(seq,track);
seq->lastStatus[track] = 0;
event->type = AL_CSP_LOOPSTART;
}
else if (type == AL_CMIDI_LOOPEND_CODE)
{
tmpPtr = seq->curLoc[track];
loopCt = *tmpPtr++;
curLpCt = *tmpPtr;
if(curLpCt == 0) /* done looping */
{
*tmpPtr = loopCt; /* reset current loop count */
seq->curLoc[track] = tmpPtr + 5; /* move pointer to end of event */
}
else
{
if(curLpCt != 0xFF) /* not a loop forever */
*tmpPtr = curLpCt - 1; /* decrement current loop count */
tmpPtr++; /* get offset from end of event */
offset = (*tmpPtr++) << 24;
offset += (*tmpPtr++) << 16;
offset += (*tmpPtr++) << 8;
offset += *tmpPtr++;
seq->curLoc[track] = tmpPtr - offset;
}
seq->lastStatus[track] = 0;
event->type = AL_CSP_LOOPEND;
}
#ifdef _DEBUG
else
__osError(ERR_ALSEQMETA, 1, type);
#endif
}
else
{
event->type = AL_SEQ_MIDI_EVT;
if (status & 0x80) /* if high bit is set, then new status */
{
event->msg.midi.status = status;
event->msg.midi.byte1 = __getTrackByte(seq,track);
seq->lastStatus[track] = status;
}
else /* running status */
{
#ifdef _DEBUG
if(seq->lastStatus[track] == 0)
__osError(ERR_ALCSEQZEROSTATUS, 1, track);
#endif
event->msg.midi.status = seq->lastStatus[track];
event->msg.midi.byte1 = status;
}
if (((event->msg.midi.status & 0xf0) != AL_MIDI_ProgramChange) &&
((event->msg.midi.status & 0xf0) != AL_MIDI_ChannelPressure))
{
event->msg.midi.byte2 = __getTrackByte(seq,track);
if((event->msg.midi.status & 0xf0) == AL_MIDI_NoteOn)
{
event->msg.midi.duration = __readVarLen(seq,track);
#ifdef _DEBUG
if(event->msg.midi.byte2 == 0)
__osError( ERR_ALCSEQZEROVEL, 1, track);
#endif
}
}
else
event->msg.midi.byte2 = 0;
}
return TRUE;
}
void n_alCSeqNewMarker(ALCSeq *seq, ALCSeqMarker *m, u32 ticks)
{
N_ALEvent evt;
ALCSeq tempSeq;
s32 i;
n_alCSeqNew(&tempSeq, (u8*)seq->base);
do {
m->validTracks = tempSeq.validTracks;
m->lastTicks = tempSeq.lastTicks;
m->lastDeltaTicks = tempSeq.lastDeltaTicks;
for(i=0;i<16;i++)
{
m->curLoc[i] = tempSeq.curLoc[i];
m->curBUPtr[i] = tempSeq.curBUPtr[i];
m->curBULen[i] = tempSeq.curBULen[i];
m->lastStatus[i] = tempSeq.lastStatus[i];
m->evtDeltaTicks[i] = tempSeq.evtDeltaTicks[i];
}
n_alCSeqNextEvent(&tempSeq, &evt);
if (evt.type == AL_SEQ_END_EVT)
break;
} while (tempSeq.lastTicks < ticks);
}
/* non-aligned byte reading routines */
static u8 __getTrackByte(ALCSeq *seq,u32 track)
{
u8 theByte;
if(seq->curBULen[track])
{
theByte = *seq->curBUPtr[track];
seq->curBUPtr[track]++;
seq->curBULen[track]--;
}
else /* need to handle backup mode */
{
theByte = *seq->curLoc[track];
seq->curLoc[track]++;
if(theByte == AL_CMIDI_BLOCK_CODE)
{
u8 loBackUp,hiBackUp,theLen,nextByte;
u32 backup;
nextByte = *seq->curLoc[track];
seq->curLoc[track]++;
if(nextByte != AL_CMIDI_BLOCK_CODE)
{
/* if here, then got a backup section. get the amount of
backup, and the len of the section. Subtract the amount of
backup from the curLoc ptr, and subtract four more, since
curLoc has been advanced by four while reading the codes. */
hiBackUp = nextByte;
loBackUp = *seq->curLoc[track];
seq->curLoc[track]++;
theLen = *seq->curLoc[track];
seq->curLoc[track]++;
backup = (u32)hiBackUp;
backup = backup << 8;
backup += loBackUp;
seq->curBUPtr[track] = seq->curLoc[track] - (backup + 4);
seq->curBULen[track] = (u32)theLen;
/* now get the byte */
theByte = *seq->curBUPtr[track];
seq->curBUPtr[track]++;
seq->curBULen[track]--;
}
}
}
return theByte;
}
static u32 __readVarLen(ALCSeq *seq,u32 track)
{
u32 value;
u32 c;
value = (u32)__getTrackByte(seq,track);
if ( value & 0x00000080 )
{
value &= 0x7f;
do
{
c = (u32)__getTrackByte(seq,track);
value = (value << 7) + (c & 0x7f);
} while (c & 0x80);
}
return (value);
}

View File

@@ -0,0 +1,188 @@
#include <ultra64.h>
#include "functions.h"
#include "variables.h"
#include "n_synth.h"
/*
* WARNING: THE FOLLOWING CONSTANT MUST BE KEPT IN SYNC
* WITH SCALING IN MICROCODE!!!
*/
#define SCALE 16384
/*
* the following arrays contain default parameters for
* a few hopefully useful effects.
*/
#define ms *(((s32)((f32)44.1))&~0x7)
s32 SMALLROOM_PARAMS_N[26] = {
/* sections length */
3, 100 ms,
/* chorus chorus filter
input output fbcoef ffcoef gain rate depth coef */
0, 54 ms, 9830, -9830, 0, 0, 0, 0,
19 ms, 38 ms, 3276, -3276, 0x3fff, 0, 0, 0,
0, 60 ms, 5000, 0, 0, 0, 0, 0x5000
};
s32 BIGROOM_PARAMS_N[34] = {
/* sections length */
4, 100 ms,
/* chorus chorus filter
input output fbcoef ffcoef gain rate depth coef */
0, 66 ms, 9830, -9830, 0, 0, 0, 0,
22 ms, 54 ms, 3276, -3276, 0x3fff, 0, 0, 0,
66 ms, 91 ms, 3276, -3276, 0x3fff, 0, 0, 0,
0, 94 ms, 8000, 0, 0, 0, 0, 0x5000
};
s32 ECHO_PARAMS_N[10] = {
/* sections length */
1, 200 ms,
/* chorus chorus filter
input output fbcoef ffcoef gain rate depth coef */
0, 179 ms, 12000, 0, 0x7fff, 0, 0, 0
};
s32 CHORUS_PARAMS_N[10] = {
/* sections length */
1, 20 ms,
/* chorus chorus filter
input output fbcoef ffcoef gain rate depth coef */
0, 5 ms, 0x4000, 0, 0x7fff, 7600, 700, 0
};
s32 FLANGE_PARAMS_N[10] = {
/* sections length */
1, 20 ms,
/* chorus chorus filter
input output fbcoef ffcoef gain rate depth coef */
0, 5 ms, 0, 0x5fff, 0x7fff, 380, 500, 0
};
s32 NULL_PARAMS_N[10] = {
0, 0,
0, 0, 0, 0, 0, 0, 0, 0
};
void n_alFxNew(ALFx **fx_ar, ALSynConfig *c, ALHeap *hp)
{
u16 i, j, k;
s32 *param = 0;
ALDelay *d;
ALFx *r;
*fx_ar = r = (ALFx *)alHeapAlloc(hp, 1, sizeof(ALFx));
switch (c->fxType) {
case AL_FX_SMALLROOM: param = SMALLROOM_PARAMS_N; break;
case AL_FX_BIGROOM: param = BIGROOM_PARAMS_N; break;
case AL_FX_ECHO: param = ECHO_PARAMS_N; break;
case AL_FX_CHORUS: param = CHORUS_PARAMS_N; break;
case AL_FX_FLANGE: param = FLANGE_PARAMS_N; break;
case AL_FX_CUSTOM: param = c->params; break;
default: param = NULL_PARAMS_N; break;
}
j = 0;
r->section_count = param[j++];
r->length = param[j++];
r->delay = alHeapAlloc(hp, r->section_count, sizeof(ALDelay));
r->base = alHeapAlloc(hp, r->length, sizeof(s16));
r->input = r->base;
for ( k=0; k < r->length; k++)
r->base[k] = 0;
for ( i=0; i<r->section_count; i++ ){
d = &r->delay[i];
d->input = param[j++];
d->output = param[j++];
d->fbcoef = param[j++];
d->ffcoef = param[j++];
d->gain = param[j++];
if (param[j]) {
#define RANGE 2.0
/* d->rsinc = ((f32) param[j++])/0xffffff; */
d->rsinc = ((((f32)param[j++])/1000) * RANGE)/c->outputRate;
/*
* the following constant is derived from:
*
* ratio = 2^(cents/1200)
*
* and therefore for hundredths of a cent
* x
* ln(ratio) = ---------------
* (120,000)/ln(2)
* where
* 120,000/ln(2) = 173123.40...
*/
#define CONVERT 173123.404906676
#define LENGTH (d->output - d->input)
d->rsgain = (((f32) param[j++])/CONVERT) * LENGTH;
d->rsval = 1.0;
d->rsdelta = 0.0;
d->rs = alHeapAlloc(hp, 1, sizeof(ALResampler));
d->rs->state = alHeapAlloc(hp, 1, sizeof(RESAMPLE_STATE));
d->rs->delta = 0.0;
d->rs->first = 1;
} else {
d->rs = 0;
j++;
j++;
}
if (param[j]) {
d->lp = alHeapAlloc(hp, 1, sizeof(ALLowPass));
d->lp->fstate = alHeapAlloc(hp, 1, sizeof(POLEF_STATE));
d->lp->fc = param[j++];
_init_lpfilter(d->lp);
} else {
d->lp = 0;
j++;
}
}
}
void alN_PVoiceNew(N_PVoice *mv, ALDMANew dmaNew, ALHeap *hp)
{
mv->dc_state = alHeapAlloc(hp, 1, sizeof(ADPCM_STATE));
mv->dc_lstate = alHeapAlloc(hp, 1, sizeof(ADPCM_STATE));
mv->dc_dma = dmaNew(&mv->dc_dmaState);
mv->dc_lastsam = 0;
mv->dc_first = 1;
mv->dc_memin = 0;
mv->rs_state = alHeapAlloc(hp, 1, sizeof(RESAMPLE_STATE));
mv->rs_delta = 0.0;
mv->rs_first = 1;
mv->rs_ratio = 1.0;
mv->rs_upitch = 0;
mv->em_state = alHeapAlloc(hp, 1, sizeof(ENVMIX_STATE));
mv->em_first = 1;
mv->em_motion = AL_STOPPED;
mv->em_volume = 1;
mv->em_ltgt = 1;
mv->em_rtgt = 1;
mv->em_cvolL = 1;
mv->em_cvolR = 1;
mv->em_dryamt = 0;
mv->em_wetamt = 0;
mv->em_lratm = 1;
mv->em_lratl = 0;
mv->em_lratm = 1;
mv->em_lratl = 0;
mv->em_delta = 0;
mv->em_segEnd = 0;
mv->em_pan = 0;
mv->em_ctrlList = 0;
mv->em_ctrlTail = 0;
}

View File

@@ -0,0 +1,40 @@
#include <ultra64.h>
#include "n_synth.h"
s32
n_alEnvmixerParam(N_PVoice *filter, s32 paramID, void *param)
{
N_PVoice *e = filter;
switch (paramID) {
case (AL_FILTER_ADD_UPDATE):
if (e->em_ctrlTail) {
e->em_ctrlTail->next = (ALParam *)param;
} else {
e->em_ctrlList = (ALParam *)param;
}
e->em_ctrlTail = (ALParam *)param;
break;
case (AL_FILTER_RESET):
e->em_first = 1;
e->em_motion = AL_STOPPED;
e->em_volume = 1;
e->rs_delta = 0.0;
e->rs_first = 1;
e->rs_upitch = 0;
n_alLoadParam(e, AL_FILTER_RESET, param);
break;
case (AL_FILTER_START):
e->em_motion = AL_PLAYING;
break;
default:
#if 1
n_alLoadParam(e, paramID, param);
#else
n_alResampleParam(e, paramID, param);
#endif
break;
}
return 0;
}

View File

@@ -0,0 +1,87 @@
#include <ultra64.h>
#include "n_synth.h"
#define ADPCMFBYTES 9
int
n_alLoadParam(N_PVoice *v, s32 paramID, void *param)
{
ALLoadFilter *a = (ALLoadFilter *) v;
switch (paramID) {
case (AL_FILTER_SET_WAVETABLE):
v->dc_table = (ALWaveTable *) param;
v->dc_memin = (s32) v->dc_table->base;
v->dc_sample = 0;
switch (v->dc_table->type){
case (AL_ADPCM_WAVE):
/*
* Set up the correct handler
*/
/*
* Make sure the table length is an integer number of
* frames
*/
v->dc_table->len = ADPCMFBYTES *
((s32) (v->dc_table->len/ADPCMFBYTES));
v->dc_bookSize = 2*v->dc_table->waveInfo.adpcmWave.book->order*
v->dc_table->waveInfo.adpcmWave.book->npredictors*ADPCMVSIZE;
if (v->dc_table->waveInfo.adpcmWave.loop) {
v->dc_loop.start = v->dc_table->waveInfo.adpcmWave.loop->start;
v->dc_loop.end = v->dc_table->waveInfo.adpcmWave.loop->end;
v->dc_loop.count = v->dc_table->waveInfo.adpcmWave.loop->count;
alCopy(v->dc_table->waveInfo.adpcmWave.loop->state,
v->dc_lstate, sizeof(ADPCM_STATE));
} else {
v->dc_loop.start = v->dc_loop.end = v->dc_loop.count = 0;
}
break;
case (AL_RAW16_WAVE):
//f->handler = alRaw16Pull;
if (v->dc_table->waveInfo.rawWave.loop) {
v->dc_loop.start = v->dc_table->waveInfo.rawWave.loop->start;
v->dc_loop.end = v->dc_table->waveInfo.rawWave.loop->end;
v->dc_loop.count = v->dc_table->waveInfo.rawWave.loop->count;
} else {
v->dc_loop.start = v->dc_loop.end = v->dc_loop.count = 0;
}
break;
default:
break;
}
break;
case (AL_FILTER_RESET):
v->dc_lastsam = 0;
v->dc_first = 1;
v->dc_sample = 0;
/* sct 2/14/96 - Check table since it is initialized to null and */
/* Get loop info according to table type. */
if (v->dc_table)
{
v->dc_memin = (s32) v->dc_table->base;
if (v->dc_table->type == AL_ADPCM_WAVE)
{
if (v->dc_table->waveInfo.adpcmWave.loop)
v->dc_loop.count = v->dc_table->waveInfo.adpcmWave.loop->count;
}
else if (v->dc_table->type == AL_RAW16_WAVE)
{
if (v->dc_table->waveInfo.rawWave.loop)
v->dc_loop.count = v->dc_table->waveInfo.rawWave.loop->count;
}
}
break;
default:
break;
}
}

View File

@@ -0,0 +1,28 @@
#include <ultra64.h>
#include "n_synth.h"
Acmd *n_alMainBusPull( s32 sampleOffset, Acmd *p)
{
Acmd *ptr = p;
#ifndef N_MICRO
aClearBuffer(ptr++, AL_MAIN_L_OUT, FIXED_SAMPLE<<1);
aClearBuffer(ptr++, AL_MAIN_R_OUT, FIXED_SAMPLE<<1);
#else
aClearBuffer(ptr++, N_AL_MAIN_L_OUT, N_AL_DIVIDED<<1);
#endif
ptr = (n_syn->mainBus->filter.handler)(sampleOffset,ptr);
#ifndef N_MICRO
aSetBuffer(ptr++, 0, 0, 0, FIXED_SAMPLE<<1);
aMix(ptr++, 0, 0x7fff, AL_AUX_L_OUT, AL_MAIN_L_OUT);
aMix(ptr++, 0, 0x7fff, AL_AUX_R_OUT, AL_MAIN_R_OUT);
#else
aMix(ptr++, 0, 0x7fff, N_AL_AUX_L_OUT, N_AL_MAIN_L_OUT);
aMix(ptr++, 0, 0x7fff, N_AL_AUX_R_OUT, N_AL_MAIN_R_OUT);
#endif
return ptr;
}

View File

@@ -0,0 +1,116 @@
#include <ultra64.h>
#include "n_synth.h"
#ifdef AUD_PROFILE
extern u32 cnt_index, resampler_num, resampler_cnt, resampler_max, resampler_min, lastCnt[];
#endif
/***********************************************************************
* Resampler filter public interfaces
***********************************************************************/
Acmd *n_alResamplePull(N_PVoice *e, s16 *outp, Acmd *p)
{
Acmd *ptr = p;
s16 inp;
s32 inCount;
s32 incr;
f32 finCount;
#ifdef AUD_PROFILE
lastCnt[++cnt_index] = osGetCount();
#endif
#ifndef N_MICRO
inp = AL_DECODER_OUT;
#else
inp = N_AL_DECODER_OUT;
#endif
/*
* check if resampler is required
*/
if (e->rs_upitch) {
ptr = n_alAdpcmPull(e, &inp, FIXED_SAMPLE, p);
aDMEMMove(ptr++, inp, *outp , FIXED_SAMPLE<<1);
} else {
/*
* clip to maximum allowable pitch
* FIXME: should we check for some minimum as well?
*/
if (e->rs_ratio > MAX_RATIO) e->rs_ratio = MAX_RATIO;
/*
* quantize the pitch
*/
e->rs_ratio = (s32)(e->rs_ratio * UNITY_PITCH);
e->rs_ratio = e->rs_ratio / UNITY_PITCH;
/*
* determine how many samples to generate
*/
finCount = e->rs_delta + (e->rs_ratio * (f32)FIXED_SAMPLE);
inCount = (s32) finCount;
e->rs_delta = finCount - (f32)inCount;
/*
* ask all filters upstream from us to build their command
* lists.
*/
ptr = n_alAdpcmPull(e, &inp, inCount, p);
/*
* construct our portion of the command list
*/
incr = (s32)(e->rs_ratio * UNITY_PITCH);
#ifndef N_MICRO
aSetBuffer(ptr++, 0, inp , *outp, FIXED_SAMPLE<<1);
aResample(ptr++, e->rs_first, incr, osVirtualToPhysical(e->rs_state));
#else
#include "n_resample_add01.c_"
#endif
e->rs_first = 0;
}
#ifdef AUD_PROFILE
PROFILE_AUD(resampler_num, resampler_cnt, resampler_max, resampler_min);
#endif
return ptr;
}
s32 n_alResampleParam(N_PVoice *filter, s32 paramID, void *param)
{
N_PVoice *r = filter;
union {
f32 f;
s32 i;
} data;
switch (paramID) {
#if 0
case (AL_FILTER_RESET):
r->rs_delta = 0.0;
r->rs_first = 1;
r->rs_upitch = 0;
n_alLoadParam(filter, AL_FILTER_RESET, 0);
break;
case (AL_FILTER_START):
n_alLoadParam(filter, AL_FILTER_START, 0);
break;
case (AL_FILTER_SET_PITCH):
data.i = (s32) param;
r->rs_ratio = data.f;
break;
case (AL_FILTER_SET_UNITY_PITCH):
r->rs_upitch = 1;
break;
#endif
default:
n_alLoadParam(filter, paramID, param);
break;
}
return 0;
}

View File

@@ -0,0 +1,2 @@
n_aResample(ptr++, osVirtualToPhysical(e->rs_state), e->rs_first, incr, inp, 0);

View File

@@ -0,0 +1,19 @@
#include <ultra64.h>
#include "n_synth.h"
Acmd *n_alSavePull( s32 sampleOffset, Acmd *p)
{
Acmd *ptr = p;
ptr = n_alMainBusPull(sampleOffset, ptr);
#ifndef N_MICRO
aSetBuffer (ptr++, 0, 0, 0, FIXED_SAMPLE<<1);
aInterleave(ptr++, AL_MAIN_L_OUT, AL_MAIN_R_OUT);
aSetBuffer (ptr++, 0, 0, 0, FIXED_SAMPLE<<2);
aSaveBuffer(ptr++, n_syn->sv_dramout);
#else
#include "n_save_add01.c_"
#endif
return ptr;
}

View File

@@ -0,0 +1,2 @@
n_aInterleave(ptr++);
n_aSaveBuffer(ptr++, FIXED_SAMPLE<<2, 0, n_syn->sv_dramout);

View File

@@ -0,0 +1,68 @@
#include <ultra64.h>
#include "synthInternals.h"
#include "n_synth.h"
void n_alSynAddPlayer( ALPlayer *client)
{
OSIntMask mask = osSetIntMask(OS_IM_NONE);
client->samplesLeft = n_syn->curSamples;
client->next = n_syn->head;
n_syn->head = client;
osSetIntMask(mask);
}
void n_alSynAddSndPlayer( ALPlayer *client)
{
OSIntMask mask = osSetIntMask(OS_IM_NONE);
client->samplesLeft = n_syn->curSamples;
#if 1
client->next = n_syn->head;
n_syn->head = client;
#endif
if( !(n_syn->n_sndp) )
n_syn->n_sndp = client;
osSetIntMask(mask);
}
void n_alSynAddSeqPlayer(ALPlayer *client)
{
OSIntMask mask = osSetIntMask(OS_IM_NONE);
client->samplesLeft = n_syn->curSamples;
client->next = n_syn->head;
n_syn->head = client;
if(n_syn->n_seqp1 == 0){
n_syn->n_seqp1 = client;
}
else if(n_syn->n_seqp2 == 0){
n_syn->n_seqp2 = client;
}
else if(n_syn->unk5C == 0){
n_syn->unk5C = client;
}
else if(n_syn->unk60 == 0){
n_syn->unk60 = client;
}
else if(n_syn->unk64 == 0){
n_syn->unk64 = client;
}
else if(n_syn->unk68 == 0){
n_syn->unk68 = client;
}
else if(n_syn->unk6C == 0){
n_syn->unk6C = client;
}
else if(n_syn->unk70 == 0){
n_syn->unk70 = client;
}
osSetIntMask(mask);
}

View File

@@ -0,0 +1,10 @@
#include <ultra64.h>
#include "functions.h"
#include "variables.h"
#include "n_synth.h"
ALFxRef n_alSynAllocFX( s16 bus, ALSynConfig *c, ALHeap *hp)
{
n_alFxNew(&n_syn->auxBus->fx_array[bus], c, hp);
return(n_syn->auxBus->fx_array[bus]);
}

View File

@@ -0,0 +1,107 @@
#include <ultra64.h>
#include "n_synth.h"
static s32 _n_allocatePVoice(N_PVoice **pvoice, s16 priority);
s32 n_alSynAllocVoice( N_ALVoice *voice, ALVoiceConfig *vc)
{
N_PVoice *pvoice = 0;
ALParam *update;
s32 stolen;
#ifdef _DEBUG
/* need two updates if voice is stolen */
if (drvr->paramList == 0) {
__osError(ERR_ALSYN_NO_UPDATE, 0);
return 0;
} else if (drvr->paramList->next == 0) {
__osError(ERR_ALSYN_NO_UPDATE, 0);
return 0;
}
#endif
voice->priority = vc->priority;
voice->unityPitch = vc->unityPitch;
voice->table = 0;
voice->fxBus = vc->fxBus;
voice->state = AL_STOPPED;
voice->pvoice = 0;
stolen = _n_allocatePVoice(&pvoice, vc->priority);
if (pvoice) { /* if we were able to allocate a voice */
if (stolen) {
pvoice->offset = 512;
pvoice->vvoice->pvoice = 0; /* zero stolen voice */
pvoice->vvoice = voice;
voice->pvoice = pvoice;
/*
* ramp down stolen voice
*/
update = __n_allocParam();
update->delta = n_syn->paramSamples;
update->type = AL_FILTER_SET_VOLUME;
update->data.i = 0;
update->moredata.i = pvoice->offset - 64;
n_alEnvmixerResampleParam(voice->pvoice, AL_FILTER_ADD_UPDATE, update);
/*
* stop stolen voice
*/
update = __n_allocParam();
if (update) {
update->delta = n_syn->paramSamples + pvoice->offset;
update->type = AL_FILTER_STOP_VOICE;
update->next = 0;
n_alEnvmixerResampleParam(voice->pvoice, AL_FILTER_ADD_UPDATE, update);
} else {
#ifdef _DEBUG
__osError(ERR_ALSYN_NO_UPDATE, 0);
#endif
}
} else {
pvoice->offset = 0;
pvoice->vvoice = voice; /* assign new voice */
voice->pvoice = pvoice;
}
}
return (pvoice != 0);
}
static
s32 _n_allocatePVoice(N_PVoice **pvoice, s16 priority)
{
ALLink *dl;
N_PVoice *pv;
s32 stolen = 0;
if ((dl = n_syn->pLameList.next) != 0) { /* check the lame list first */
*pvoice = (N_PVoice *) dl;
alUnlink(dl);
alLink(dl, &n_syn->pAllocList);
} else if ((dl = n_syn->pFreeList.next) != 0) { /* from the free list */
*pvoice = (N_PVoice *) dl;
alUnlink(dl);
alLink(dl, &n_syn->pAllocList);
} else { /* steal one */
for (dl = n_syn->pAllocList.next; dl != 0; dl = dl->next) {
pv = (N_PVoice *)dl;
/*
* if it is lower priority and not already stolen, keep it
* as a candidate for stealing
*/
if ((pv->vvoice->priority <= priority) && (pv->offset == 0)) {
*pvoice = pv;
priority = pv->vvoice->priority;
stolen = 1;
}
}
}
return stolen;
}

View File

@@ -0,0 +1,30 @@
#include <ultra64.h>
#include "n_synth.h"
void n_alSynFreeVoice(N_ALVoice *voice)
{
ALFilter *f;
ALFreeParam *update;
if (voice->pvoice) {
if (voice->pvoice->offset) { /* if voice was stolen */
update = (ALFreeParam *)__n_allocParam();
ALFailIf(update == 0, ERR_ALSYN_NO_UPDATE);
/*
* set voice data
*/
update->delta = n_syn->paramSamples + voice->pvoice->offset;
update->type = AL_FILTER_FREE_VOICE;
update->pvoice = (PVoice *)voice->pvoice;
n_alEnvmixerResampleParam(voice->pvoice, AL_FILTER_ADD_UPDATE, update);
} else {
_n_freePVoice(voice->pvoice);
}
voice->pvoice = 0;
}
}

View File

@@ -0,0 +1,29 @@
#include <ultra64.h>
#include "n_synth.h"
void n_alSynSetFXMix(N_ALVoice *v, u8 fxmix)
{
ALParam *update;
if (v->pvoice) {
/*
* get new update struct from the free list
*/
update = __n_allocParam();
ALFailIf(update == 0, ERR_ALSYN_NO_UPDATE);
/*
* set offset and fxmix data
*/
update->delta = n_syn->paramSamples + v->pvoice->offset;
update->type = AL_FILTER_SET_FXAMT;
if (fxmix < 0)
update->data.i = -fxmix;
else
update->data.i = fxmix;
update->next = 0;
n_alEnvmixerResampleParam(v->pvoice, AL_FILTER_ADD_UPDATE, update);
}
}

View File

@@ -0,0 +1,27 @@
#include <ultra64.h>
#include "n_synth.h"
void n_alSynSetPan(N_ALVoice *v, u8 pan)
{
ALParam *update;
ALFilter *f;
if (v->pvoice) {
/*
* get new update struct from the free list
*/
update = __n_allocParam();
ALFailIf(update == 0, ERR_ALSYN_NO_UPDATE);
/*
* set offset and pan data
*/
update->delta = n_syn->paramSamples + v->pvoice->offset;
update->type = AL_FILTER_SET_PAN;
update->data.i = pan;
update->next = 0;
n_alEnvmixerResampleParam(v->pvoice, AL_FILTER_ADD_UPDATE, update);
}
}

View File

@@ -0,0 +1,27 @@
#include <ultra64.h>
#include "n_synth.h"
void n_alSynSetPitch( N_ALVoice *v, f32 pitch)
{
ALParam *update;
ALFilter *f;
if (v->pvoice) {
/*
* get new update struct from the free list
*/
update = __n_allocParam();
ALFailIf(update == 0, ERR_ALSYN_NO_UPDATE);
/*
* set offset and pitch data
*/
update->delta = n_syn->paramSamples + v->pvoice->offset;
update->type = AL_FILTER_SET_PITCH;
update->data.f = pitch;
update->next = 0;
n_alEnvmixerResampleParam(v->pvoice, AL_FILTER_ADD_UPDATE, update);
}
}

View File

@@ -0,0 +1,30 @@
#include <ultra64.h>
#include "n_synth.h"
void n_alSynSetVol( N_ALVoice *v, s16 volume, ALMicroTime t)
{
ALParam *update;
ALFilter *f;
if (v->pvoice) {
/*
* get new update struct from the free list
*/
update = __n_allocParam();
ALFailIf(update == 0, ERR_ALSYN_NO_UPDATE);
/*
* set offset and volume data
*/
update->delta = n_syn->paramSamples + v->pvoice->offset;
update->type = AL_FILTER_SET_VOLUME;
update->data.i = volume;
update->moredata.i = _n_timeToSamples( t);
update->next = 0;
//f = v->pvoice->channelKnob;
//(*f->setParam)(f, AL_FILTER_ADD_UPDATE, update);
n_alEnvmixerResampleParam(v->pvoice, AL_FILTER_ADD_UPDATE, update);
}
}

View File

@@ -0,0 +1,49 @@
/*====================================================================
*
* Copyright 1993, Silicon Graphics, Inc.
* All Rights Reserved.
*
* This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics,
* Inc.; the contents of this file may not be disclosed to third
* parties, copied or duplicated in any form, in whole or in part,
* without the prior written permission of Silicon Graphics, Inc.
*
* RESTRICTED RIGHTS LEGEND:
* Use, duplication or disclosure by the Government is subject to
* restrictions as set forth in subdivision (c)(1)(ii) of the Rights
* in Technical Data and Computer Software clause at DFARS
* 252.227-7013, and/or in similar or successor clauses in the FAR,
* DOD or NASA FAR Supplement. Unpublished - rights reserved under the
* Copyright Laws of the United States.
*====================================================================*/
#include <os_internal.h>
#include <ultraerror.h>
#include "n_synth.h"
void n_alSynStartVoice( N_ALVoice *v, ALWaveTable *table)
{
ALStartParam *update;
if (v->pvoice) {
update = (ALStartParam *)__n_allocParam();
ALFailIf(update == 0, ERR_ALSYN_NO_UPDATE);
/*
* send the start message to the motion control filter
*/
#ifdef SAMPLE_ROUND
update->delta = SAMPLE184( n_syn->paramSamples + v->pvoice->offset);
#else
update->delta = n_syn->paramSamples + v->pvoice->offset;
#endif
update->type = AL_FILTER_START_VOICE;
update->wave = table;
update->next = 0;
update->unity = v->unityPitch;
n_alEnvmixerResampleParam(v->pvoice, AL_FILTER_ADD_UPDATE, update);
}
}

View File

@@ -0,0 +1,42 @@
#include <ultra64.h>
#include "synthInternals.h"
#include "n_synth.h"
void n_alSynStartVoiceParams(N_ALVoice *v, ALWaveTable *w,
f32 pitch, s16 vol, ALPan pan, u8 fxmix,
ALMicroTime t)
{
ALStartParamAlt *update;
if ( v->pvoice) {
/*
* get new update struct from the free list
*/
update = (ALStartParamAlt *)__n_allocParam();
ALFailIf(update == 0, ERR_ALSYN_NO_UPDATE);
if (fxmix < 0)
fxmix = -fxmix;
/*
* set offset and fxmix data
*/
update->delta = n_syn->paramSamples + v->pvoice->offset;
update->next = 0;
update->type = AL_FILTER_START_VOICE_ALT;
update->unity = v->unityPitch;
update->pan = pan;
update->volume = vol;
update->fxMix = fxmix;
update->pitch = pitch;
update->samples = _n_timeToSamples( t);
update->wave = w;
n_alEnvmixerResampleParam(v->pvoice, AL_FILTER_ADD_UPDATE, update);
}
}

View File

@@ -0,0 +1,20 @@
#include <ultra64.h>
#include "n_synth.h"
void n_alSynStopVoice( N_ALVoice *v)
{
ALParam *update;
if (v->pvoice) {
update = __n_allocParam();
ALFailIf(update == 0, ERR_ALSYN_NO_UPDATE);
update->delta = n_syn->paramSamples + v->pvoice->offset;
update->type = AL_FILTER_STOP_VOICE;
update->next = 0;
n_alEnvmixerResampleParam(v->pvoice, AL_FILTER_ADD_UPDATE, update);
}
}

View File

@@ -0,0 +1,359 @@
#include <ultra64.h>
#include "functions.h"
#include "variables.h"
#include "n_synth.h"
#ifndef assert
#define assert(s)
#endif
extern ALCmdHandler n_alAuxBusPull;
extern ALCmdHandler func_8025FE6C;
extern void alN_PVoiceNew(N_PVoice *mv, ALDMANew dmaNew, ALHeap *hp);
#ifdef AUD_PROFILE
#include <os.h>
extern u32 cnt_index, drvr_num, drvr_cnt, drvr_max, drvr_min, lastCnt[];
extern u32 client_num, client_cnt, client_max, client_min;
#endif
#ifndef MIN
# define MIN(a,b) (((a)<(b))?(a):(b))
#endif
static s32 func_8025C370(ALPlayer **client);
static s32 _n_timeToSamplesNoRound(s32 micros);
/***********************************************************************
* Synthesis driver public interfaces
***********************************************************************/
void n_alSynNew(ALSynConfig *c)
{
s32 i;
N_PVoice *pv;
N_PVoice *pvoices;
ALHeap *hp = c->heap;
ALFilter *sources;
ALParam *params;
ALParam *paramPtr;
n_syn->head = NULL;
n_syn->n_seqp1 = NULL;
n_syn->n_seqp2 = NULL;
n_syn->unk5C = NULL;
n_syn->unk60 = NULL;
n_syn->unk64 = NULL;
n_syn->unk68 = NULL;
n_syn->unk6C = NULL;
n_syn->unk70 = NULL;
n_syn->n_sndp = NULL;
n_syn->numPVoices = c->maxPVoices;
n_syn->curSamples = 0;
n_syn->paramSamples = 0;
n_syn->outputRate = c->outputRate;
n_syn->maxOutSamples = N_AL_MAX_RSP_SAMPLES;
n_syn->dma = (ALDMANew) c->dmaproc;
n_syn->sv_dramout = 0;
n_syn->sv_first = 1;
/*
* allocate and initialize the auxilliary effects bus. at present
* we only support 1 effects bus.
*/
n_syn->auxBus = alHeapAlloc(hp, 1, sizeof(N_ALAuxBus));
n_syn->auxBus->sourceCount = 0;
n_syn->auxBus->maxSources = c->maxPVoices;
n_syn->auxBus->sources = alHeapAlloc(hp, c->maxPVoices, sizeof(ALFilter *));
/*
* allocate and initialize the main bus.
*/
n_syn->mainBus = alHeapAlloc(hp, 1, sizeof(N_ALMainBus));
if (c->fxType != AL_FX_NONE){
/*
* Allocate an effect and set parameters
*/
n_syn->auxBus->fx = n_alSynAllocFX(0, c, hp);
n_syn->mainBus->filter.handler = &func_8025FE6C;
} else{
/*
* Connect the aux bus to the main bus
*/
n_syn->mainBus->filter.handler = &n_alAuxBusPull;
}
/*
* Build the physical voice lists
*/
n_syn->pFreeList.next = 0;
n_syn->pFreeList.prev = 0;
n_syn->pLameList.next = 0;
n_syn->pLameList.prev = 0;
n_syn->pAllocList.next = 0;
n_syn->pAllocList.prev = 0;
pvoices = alHeapAlloc(hp, c->maxPVoices, sizeof(N_PVoice));
for (i = 0; i < c->maxPVoices; i++) {
pv = &pvoices[i];
alLink((ALLink *)pv, &n_syn->pFreeList);
pv->vvoice = 0;
alN_PVoiceNew(pv, n_syn->dma, hp);
n_syn->auxBus->sources[n_syn->auxBus->sourceCount] = pv;
n_syn->auxBus->sourceCount++;
}
/*
* build the parameter update list
*/
params = alHeapAlloc(hp, c->maxUpdates, sizeof(ALParam));
n_syn->paramList = 0;
for (i = 0; i < c->maxUpdates; i++) {
paramPtr= &params[i];
paramPtr->next = n_syn->paramList;
n_syn->paramList = paramPtr;
}
n_syn->heap = hp;
}
/*
* slAudioFrame() is called every video frame, and is based on the video
* frame interrupt. It is assumed to be an accurate time source for the
* clients.
*/
Acmd *n_alAudioFrame(Acmd *cmdList, s32 *cmdLen, s16 *outBuf, s32 outLen)
{
ALPlayer *client;
ALFilter *output;
s16 tmp; /* Starting buffer in DMEM */
Acmd *cmdlEnd = cmdList;
s32 nOut;
s16 *lOutBuf = outBuf;
#ifdef AUD_PROFILE
lastCnt[++cnt_index] = osGetCount();
#endif
if (n_syn->head == 0) {
*cmdLen = 0;
return cmdList; /* nothing to do */
}
/*
* run down list of clients and execute callback if needed this
* subframe. Here we do all the work for the frame at the
* start. Time offsets that occur before the next frame are
* executed "early".
*/
#ifdef AUD_PROFILE
lastCnt[++cnt_index] = osGetCount();
#endif
/*
* paramSamples = time of next parameter change.
* curSamples = current sample time.
* so paramSamples - curSamples is the time until the next parameter change.
* if the next parameter change occurs within this frame time (outLen),
* then call back the client that contains the parameter change.
* Note, paramSamples must be rounded down to 16 sample boundary for use
* during the client handler.
*/
for (n_syn->paramSamples = func_8025C370(&client);
n_syn->paramSamples - n_syn->curSamples < outLen;
n_syn->paramSamples = func_8025C370(&client))
{
n_syn->paramSamples &= ~0xf;
client->samplesLeft += _n_timeToSamplesNoRound((*client->handler)(client));
}
/* for safety's sake, always store paramSamples aligned to 16 sample boundary.
* this way, if an voice handler routine gets called outside the ALVoiceHandler
* routine (alSynAllocVoice) it will get timestamped with an aligned value and
* will be processed immediately next audio frame.
*/
n_syn->paramSamples &= ~0xf;
#ifdef AUD_PROFILE
PROFILE_AUD(client_num, client_cnt, client_max, client_min);
#endif
/*
* Now build the command list in small chunks
*/
while (outLen > 0){
nOut = MIN(n_syn->maxOutSamples, outLen);
/*
* construct the command list for each physical voice by calling
* the head of the filter chain.
*/
n_syn->sv_dramout = (s32) lOutBuf;
cmdlEnd = n_alSavePull(n_syn->curSamples, cmdlEnd);
outLen -= nOut;
lOutBuf += nOut<<1; /* For Stereo */
n_syn->curSamples += nOut;
}
*cmdLen = (s32) (cmdlEnd - cmdList);
_n_collectPVoices(); /* collect free physical voices */
#ifdef AUD_PROFILE
PROFILE_AUD(drvr_num, drvr_cnt, drvr_max, drvr_min);
#endif
return cmdlEnd;
}
/***********************************************************************
* Synthesis driver private interfaces
***********************************************************************/
ALParam *__allocParam()
{
ALParam *update = 0;
if (n_syn->paramList) {
update = n_syn->paramList;
n_syn->paramList =n_syn->paramList->next;
update->next = 0;
}
return update;
}
void __n_freeParam(ALParam *param)
{
param->next = n_syn->paramList;
n_syn->paramList = param;
}
void _n_collectPVoices()
{
ALLink *dl;
N_PVoice *pv;
while ((dl = n_syn->pLameList.next) != 0) {
pv = (N_PVoice *)dl;
/* ### remove from mixer */
alUnlink(dl);
alLink(dl, &n_syn->pFreeList);
}
}
void _n_freePVoice(N_PVoice *pvoice)
{
/*
* move the voice from the allocated list to the lame list
*/
alUnlink((ALLink *)pvoice);
alLink((ALLink *)pvoice, &n_syn->pLameList);
}
/*
Add 0.5 to adjust the average affect of
the truncation error produced by casting
a float to an int.
*/
s32 _n_timeToSamplesNoRound(s32 micros)
{
f32 tmp = ((f32)micros) * n_syn->outputRate / 1000000.0 + 0.5;
return (s32)tmp;
}
s32 _n_timeToSamples(s32 micros)
{
return _n_timeToSamplesNoRound(micros) & ~0xf;
}
static s32 func_8025C370(ALPlayer **client)
{
ALMicroTime idelta;
ALMicroTime delta = 0x7fffffff; /* max delta for s32 */
ALPlayer *cl;
*client = 0;
if(n_syn->n_sndp != NULL){
idelta = (n_syn->n_sndp->samplesLeft - n_syn->curSamples);
if (idelta < delta) {
*client = n_syn->n_sndp;
delta = idelta;
}
}
cl = n_syn->n_seqp1;
if(cl != NULL){
idelta = (cl->samplesLeft - n_syn->curSamples);
if (idelta < delta) {
*client = cl;
delta = idelta;
}
}
cl = n_syn->n_seqp2;
if(cl != NULL){
if ((cl->samplesLeft - n_syn->curSamples) < delta) {
*client = cl;
delta = idelta;
}
}
cl = n_syn->unk5C;
if(cl != NULL){
if ((cl->samplesLeft - n_syn->curSamples) < delta) {
*client = cl;
delta = idelta;
}
}
cl = n_syn->unk60;
if(cl != NULL){
if ((cl->samplesLeft - n_syn->curSamples) < delta) {
*client = cl;
delta = idelta;
}
}
cl = n_syn->unk64;
if(cl != NULL){
if ((cl->samplesLeft - n_syn->curSamples) < delta) {
*client = cl;
delta = idelta;
}
}
cl = n_syn->unk68;
if(cl != NULL){
if ((cl->samplesLeft - n_syn->curSamples) < delta) {
*client = cl;
delta = idelta;
}
}
cl = n_syn->unk6C;
if(cl != NULL){
if ((cl->samplesLeft - n_syn->curSamples) < delta) {
*client = cl;
delta = idelta;
}
}
cl = n_syn->unk70;
if(cl != NULL){
if ((cl->samplesLeft - n_syn->curSamples) < delta) {
*client = cl;
delta = idelta;
}
}
return (*client)->samplesLeft;
}

View File

@@ -0,0 +1,125 @@
#include <ultra64.h>
#include "synthInternals.h"
#ifdef AUD_PROFILE
extern u32 cnt_index, resampler_num, resampler_cnt, resampler_max, resampler_min, lastCnt[];
#endif
/***********************************************************************
* Resampler filter public interfaces
***********************************************************************/
Acmd *alResamplePull(void *filter, s16 *outp, s32 outCnt, s32 sampleOffset, Acmd *p)
{
ALResampler *f = (ALResampler *)filter;
Acmd *ptr = p;
s16 inp;
s32 inCount;
ALFilter *source = f->filter.source;
s32 incr;
f32 finCount;
#ifdef AUD_PROFILE
lastCnt[++cnt_index] = osGetCount();
#endif
inp = AL_DECODER_OUT;
if (!outCnt)
return ptr;
/*
* check if resampler is required
*/
if (f->upitch) {
ptr = (*source->handler)(source, &inp, outCnt, sampleOffset, p);
aDMEMMove(ptr++, inp, *outp, outCnt<<1);
} else {
/*
* clip to maximum allowable pitch
* FIXME: should we check for some minimum as well?
*/
if (f->ratio > MAX_RATIO) f->ratio = MAX_RATIO;
/*
* quantize the pitch
*/
f->ratio = (s32)(f->ratio * UNITY_PITCH);
f->ratio = f->ratio / UNITY_PITCH;
/*
* determine how many samples to generate
*/
finCount = f->delta + (f->ratio * (f32) outCnt);
inCount = (s32) finCount;
f->delta = finCount - (f32)inCount;
/*
* ask all filters upstream from us to build their command
* lists.
*/
ptr = (*source->handler)(source, &inp, inCount, sampleOffset, p);
/*
* construct our portion of the command list
*/
incr = (s32)(f->ratio * UNITY_PITCH);
aSetBuffer(ptr++, 0, inp, *outp, outCnt<<1);
aResample(ptr++, f->first, incr, osVirtualToPhysical(f->state));
f->first = 0;
}
#ifdef AUD_PROFILE
PROFILE_AUD(resampler_num, resampler_cnt, resampler_max, resampler_min);
#endif
return ptr;
}
s32 alResampleParam(void *filter, s32 paramID, void *param)
{
ALFilter *f = (ALFilter *) filter;
ALResampler *r = (ALResampler *) filter;
union {
f32 f;
s32 i;
} data;
switch (paramID) {
case (AL_FILTER_SET_SOURCE):
f->source = (ALFilter *) param;
break;
case (AL_FILTER_RESET):
r->delta = 0.0;
r->first = 1;
r->motion = AL_STOPPED;
r->upitch = 0;
if (f->source)
(*f->source->setParam)(f->source, AL_FILTER_RESET, 0);
break;
case (AL_FILTER_START):
r->motion = AL_PLAYING;
if (f->source)
(*f->source->setParam)(f->source, AL_FILTER_START, 0);
break;
case (AL_FILTER_SET_PITCH):
data.i = (s32) param;
r->ratio = data.f;
break;
case (AL_FILTER_SET_UNITY_PITCH):
r->upitch = 1;
break;
default:
if (f->source)
(*f->source->setParam)(f->source, paramID, param);
break;
}
return 0;
}

View File

@@ -0,0 +1,431 @@
#include <ultra64.h>
#include "functions.h"
#include "variables.h"
#include "synthInternals.h"
#include "initfx.h"
#ifndef assert
#define assert(s)
#endif
#define RANGE 2.0
extern ALGlobals *alGlobals;
#ifdef AUD_PROFILE
extern u32 cnt_index, reverb_num, reverb_cnt, reverb_max, reverb_min, lastCnt[];
extern u32 load_num, load_cnt, load_max, load_min, save_num, save_cnt, save_max, save_min;
#endif
/*
* macros
*/
#define SWAP(in, out) \
{ \
s16 t = out; \
out = in; \
in = t; \
}
Acmd *_loadOutputBuffer(ALFx *r, ALDelay *d, s32 buff, s32 incount, Acmd *p);
Acmd *_loadBuffer(ALFx *r, s16 *curr_ptr, s32 buff, s32 count, Acmd *p);
Acmd *_saveBuffer(ALFx *r, s16 *curr_ptr, s32 buff, s32 count, Acmd *p);
Acmd *_filterBuffer(ALLowPass *lp, s32 buff, s32 count, Acmd *p);
f32 _doModFunc(ALDelay *d, s32 count);
static s32 L_INC[] = { L0_INC, L1_INC, L2_INC };
/***********************************************************************
* Reverb filter public interfaces
***********************************************************************/
Acmd *alFxPull(void *filter, s16 *outp, s32 outCount, s32 sampleOffset,
Acmd *p)
{
Acmd *ptr = p;
ALFx *r = (ALFx *)filter;
ALFilter *source = r->filter.source;
s16 i, buff1, buff2, input, output;
s16 *in_ptr, *out_ptr, gain, *prev_out_ptr = 0;
ALDelay *d, *pd;
#ifdef AUD_PROFILE
lastCnt[++cnt_index] = osGetCount();
#endif
assert(source);
/*
* pull channels going into this effect first
*/
ptr = (*source->handler)(source, outp, outCount, sampleOffset, p);
input = AL_AUX_L_OUT;
output = AL_AUX_R_OUT;
buff1 = AL_TEMP_0;
buff2 = AL_TEMP_1;
aSetBuffer(ptr++, 0, 0, 0, outCount<<1); /* set the buffer size */
aMix(ptr++, 0, 0xda83, AL_AUX_L_OUT, input); /* .707L = L - .293L */
aMix(ptr++, 0, 0x5a82, AL_AUX_R_OUT, input); /* mix the AuxL and AuxR into the AuxL */
/* and write the mixed value to the delay line at r->input */
ptr = _saveBuffer(r, r->input, input, outCount, ptr);
aClearBuffer(ptr++, output, outCount<<1); /* clear the AL_AUX_R_OUT */
for (i = 0; i < r->section_count; i++) {
d = &r->delay[i]; /* get the ALDelay structure */
in_ptr = &r->input[-d->input];
out_ptr = &r->input[-d->output];
if (in_ptr == prev_out_ptr) {
SWAP(buff1, buff2);
} else { /* load data at in_ptr into buff1 */
ptr = _loadBuffer(r, in_ptr, buff1, outCount, ptr);
}
ptr = _loadOutputBuffer(r, d, buff2, outCount, ptr);
if (d->ffcoef) {
aMix(ptr++, 0, (u16)d->ffcoef, buff1, buff2);
if (!d->rs && !d->lp) {
ptr = _saveBuffer(r, out_ptr, buff2, outCount, ptr);
}
}
if (d->fbcoef) {
aMix(ptr++, 0, (u16)d->fbcoef, buff2, buff1);
ptr = _saveBuffer(r, in_ptr, buff1, outCount, ptr);
}
if (d->lp)
ptr = _filterBuffer(d->lp, buff2, outCount, ptr);
if (!d->rs)
ptr = _saveBuffer(r, out_ptr, buff2, outCount, ptr);
if (d->gain)
aMix(ptr++, 0, (u16)d->gain, buff2, output);
prev_out_ptr = &r->input[d->output];
}
/*
* bump the master delay line input pointer
* modulo the length
*/
r->input += outCount;
if (r->input > &r->base[r->length])
r->input -= r->length;
/*
* output already in AL_AUX_R_OUT
* just copy to AL_AUX_L_OUT
*/
aDMEMMove(ptr++, output, AL_AUX_L_OUT, outCount<<1);
#ifdef AUD_PROFILE
PROFILE_AUD(reverb_num, reverb_cnt, reverb_max, reverb_min);
#endif
return ptr;
}
s32 alFxParam(void *filter, s32 paramID, void *param)
{
if(paramID == AL_FILTER_SET_SOURCE)
{
ALFilter *f = (ALFilter *) filter;
f->source = (ALFilter*) param;
}
return 0;
}
/*
* This routine gets called by alSynSetFXParam. No checking takes place to
* verify the validity of the paramID or the param value. input and output
* values must be 8 byte aligned, so round down any param passed.
*/
s32 alFxParamHdl(void *filter, s32 paramID, void *param)
{
ALFx *f = (ALFx *) filter;
s32 p = (paramID - 2) % 8;
s32 s = (paramID - 2) / 8;
s32 val = *(s32*)param;
#define INPUT_PARAM 0
#define OUTPUT_PARAM 1
#define FBCOEF_PARAM 2
#define FFCOEF_PARAM 3
#define GAIN_PARAM 4
#define CHORUSRATE_PARAM 5
#define CHORUSDEPTH_PARAM 6
#define LPFILT_PARAM 7
switch(p)
{
case INPUT_PARAM:
f->delay[s].input = (u32)val & 0xFFFFFFF8;
break;
case OUTPUT_PARAM:
f->delay[s].output = (u32)val & 0xFFFFFFF8;
break;
case FFCOEF_PARAM:
f->delay[s].ffcoef = (s16)val;
break;
case FBCOEF_PARAM:
f->delay[s].fbcoef = (s16)val;
break;
case GAIN_PARAM:
f->delay[s].gain = (s16)val;
break;
case CHORUSRATE_PARAM:
/* f->delay[s].rsinc = ((f32)val)/0xffffff; */
f->delay[s].rsinc = ((((f32)val)/1000) * RANGE)/alGlobals->drvr.outputRate;
break;
/*
* the following constant is derived from:
*
* ratio = 2^(cents/1200)
*
* and therefore for hundredths of a cent
* x
* ln(ratio) = ---------------
* (120,000)/ln(2)
* where
* 120,000/ln(2) = 173123.40...
*/
#define CONVERT 173123.404906676
#define LENGTH (f->delay[s].output - f->delay[s].input)
case CHORUSDEPTH_PARAM:
/*f->delay[s].rsgain = (((f32)val) / CONVERT) * LENGTH; */
f->delay[s].rsgain = (((f32)val) / CONVERT) * LENGTH;
break;
case LPFILT_PARAM:
if(f->delay[s].lp)
{
f->delay[s].lp->fc = (s16)val;
init_lpfilter(f->delay[s].lp);
}
break;
}
return 0;
}
Acmd *_loadOutputBuffer(ALFx *r, ALDelay *d, s32 buff, s32 incount, Acmd *p)
{
Acmd *ptr = p;
s32 ratio, count, rbuff = AL_TEMP_2;
s16 *out_ptr;
f32 fincount, fratio, delta;
s32 ramalign = 0, length;
static f32 val=0.0, lastval=-10.0;
static f32 blob=0;
/*
* The following section implements the chorus resampling. Modulate where you pull
* the samples from, since you need varying amounts of samples.
*/
if (d->rs) {
length = d->output - d->input;
delta = _doModFunc(d, incount); /* get the number of samples to modulate by */
/*
* find ratio of delta to delay length and quantize
* to same resolution as resampler
*/
delta /= length; /* convert delta from number of samples to a pitch ratio */
delta = (s32)(delta * UNITY_PITCH); /* quantize to value microcode will use */
delta = delta / UNITY_PITCH;
fratio = 1.0 - delta; /* pitch ratio needs to be centered around 1, not zero */
/* d->rs->delta is the difference between the fractional and integer value
* of the samples needed. fratio * incount + rs->delta gives the number of samples
* needed for this frame.
*/
fincount = d->rs->delta + (fratio * (f32)incount);
count = (s32) fincount; /* quantize to s32 */
d->rs->delta = fincount - (f32)count; /* calculate the round off and store */
/*
* d->rsdelta is amount the out_ptr has deviated from its starting position.
* You calc the out_ptr by taking d->output - d->rsdelta, and then using the
* negative of that as an index into the delay buffer. loadBuffer that uses this
* value then bumps it up if it is below the delay buffer.
*/
out_ptr = &r->input[-(d->output - d->rsdelta)];
ramalign = ((s32)out_ptr & 0x7) >> 1; /* calculate the number of samples needed
to align the buffer*/
#ifdef _DEBUG
#if 0
if(length > 0) {
if (length - d->rsdelta > (s32)r->length) {
__osError(ERR_ALMODDELAYOVERFLOW, 1, length - d->rsdelta - r->length);
}
}
else if(length < 0) {
if ((-length) - d->rsdelta > (s32)r->length) {
__osError(ERR_ALMODDELAYOVERFLOW, 1, (-length) - d->rsdelta - r->length);
}
}
#endif
#endif
/* load the rbuff with samples, note that there will be ramalign worth of
* samples at the begining which you don't care about. */
ptr = _loadBuffer(r, out_ptr - ramalign, rbuff, count + ramalign, ptr);
/* convert fratio to 16 bit fraction for microcode use */
ratio = (s32)(fratio * UNITY_PITCH);
/* set the buffers, and do the resample */
aSetBuffer(ptr++, 0, rbuff + (ramalign<<1), buff, incount<<1);
aResample(ptr++, d->rs->first, ratio, osVirtualToPhysical(d->rs->state));
d->rs->first = 0; /* turn off first time flag */
d->rsdelta += count - incount; /* add the number of samples to d->rsdelta */
} else {
out_ptr = &r->input[-d->output];
ptr = _loadBuffer(r, out_ptr, buff, incount, ptr);
}
return ptr;
}
/*
* This routine is for loading data from the delay line buff. If the
* address of curr_ptr < r->base, it will force it to be within r->base
* space, If the load goes past the end of r->base it will wrap around.
* Cause count bytes of data at curr_ptr (within the delay line) to be
* loaded into buff. (Buff is a dmem buffer)
*/
Acmd *_loadBuffer(ALFx *r, s16 *curr_ptr, s32 buff, s32 count, Acmd *p)
{
Acmd *ptr = p;
s32 after_end, before_end;
s16 *updated_ptr, *delay_end;
#ifdef AUD_PROFILE
lastCnt[++cnt_index] = osGetCount();
#endif
delay_end = &r->base[r->length];
#ifdef _DEBUG
if(curr_ptr > delay_end)
__osError(ERR_ALMODDELAYOVERFLOW, 1, delay_end - curr_ptr);
#endif
if (curr_ptr < r->base)
curr_ptr += r->length;
updated_ptr = curr_ptr + count;
if (updated_ptr > delay_end) {
after_end = updated_ptr - delay_end;
before_end = delay_end - curr_ptr;
aSetBuffer(ptr++, 0, buff, 0, before_end<<1);
aLoadBuffer(ptr++, osVirtualToPhysical(curr_ptr));
aSetBuffer(ptr++, 0, buff+(before_end<<1), 0, after_end<<1);
aLoadBuffer(ptr++, osVirtualToPhysical(r->base));
} else {
aSetBuffer(ptr++, 0, buff, 0, count<<1);
aLoadBuffer(ptr++, osVirtualToPhysical(curr_ptr));
}
aSetBuffer(ptr++, 0, 0, 0, count<<1);
#ifdef AUD_PROFILE
PROFILE_AUD(load_num, load_cnt, load_max, load_min);
#endif
return ptr;
}
/*
* This routine is for writing data to the delay line buff. If the
* address of curr_ptr < r->base, it will force it to be within r->base
* space. If the write goes past the end of r->base, it will wrap around
* Cause count bytes of data at buff to be written to delay line, curr_ptr.
*/
Acmd *_saveBuffer(ALFx *r, s16 *curr_ptr, s32 buff, s32 count, Acmd *p)
{
Acmd *ptr = p;
s32 after_end, before_end;
s16 *updated_ptr, *delay_end;
#ifdef AUD_PROFILE
lastCnt[++cnt_index] = osGetCount();
#endif
delay_end = &r->base[r->length];
if (curr_ptr < r->base) /* probably just security */
curr_ptr += r->length; /* shouldn't occur */
updated_ptr = curr_ptr + count;
if (updated_ptr > delay_end) { /* if the data wraps past end of r->base */
after_end = updated_ptr - delay_end;
before_end = delay_end - curr_ptr;
aSetBuffer(ptr++, 0, 0, buff, before_end<<1);
aSaveBuffer(ptr++, osVirtualToPhysical(curr_ptr));
aSetBuffer(ptr++, 0, 0, buff+(before_end<<1), after_end<<1);
aSaveBuffer(ptr++, osVirtualToPhysical(r->base));
aSetBuffer(ptr++, 0, 0, 0, count<<1);
} else {
aSetBuffer(ptr++, 0, 0, buff, count<<1);
aSaveBuffer(ptr++, osVirtualToPhysical(curr_ptr));
}
#ifdef AUD_PROFILE
PROFILE_AUD(save_num, save_cnt, save_max, save_min);
#endif
return ptr;
}
Acmd *_filterBuffer(ALLowPass *lp, s32 buff, s32 count, Acmd *p)
{
Acmd *ptr = p;
aSetBuffer(ptr++, 0, buff, buff, count<<1);
aLoadADPCM(ptr++, 32, osVirtualToPhysical(lp->fcvec.fccoef));
aPoleFilter(ptr++, lp->first, lp->fgain, osVirtualToPhysical(lp->fstate));
lp->first = 0;
return ptr;
}
/*
* Generate a triangle wave from -1 to 1, and find the current position
* in the wave. (Rate of the wave is controlled by d->rsinc, which is chorus
* rate) Multiply the current triangle wave value by d->rsgain, (chorus depth)
* which is expressed in number of samples back from output pointer the chorus
* should go at it's full chorus. In otherwords, this function returns a number
* of samples the output pointer should modulate backwards.
*/
f32 _doModFunc(ALDelay *d, s32 count)
{
f32 val;
/*
* generate bipolar sawtooth
* from -RANGE to +RANGE
*/
d->rsval += d->rsinc * count;
d->rsval = (d->rsval > RANGE) ? d->rsval-(RANGE*2) : d->rsval;
/*
* convert to monopolar triangle
* from 0 to RANGE
*/
val = d->rsval;
val = (val < 0) ? -val : val;
/*
* convert to bipolar triangle
* from -1 to 1
*/
val -= RANGE/2;
return(d->rsgain * val);
}

View File

@@ -0,0 +1,41 @@
#include <ultra64.h>
#include "synthInternals.h"
Acmd *alSavePull(void *filter, s16 *outp, s32 outCount, s32 sampleOffset,
Acmd *p)
{
Acmd *ptr = p;
ALSave *f = (ALSave *)filter;
ALFilter *source = f->filter.source;
ptr = (*source->handler)(source, outp, outCount, sampleOffset, ptr);
aSetBuffer (ptr++, 0, 0, 0, outCount<<1);
aInterleave(ptr++, AL_MAIN_L_OUT, AL_MAIN_R_OUT);
aSetBuffer (ptr++, 0, 0, 0, outCount<<2);
aSaveBuffer(ptr++, f->dramout);
return ptr;
}
s32 alSaveParam(void *filter, s32 paramID, void *param)
{
ALSave *a = (ALSave *) filter;
ALFilter *f = (ALFilter *) filter;
s32 pp = (s32) param;
switch (paramID) {
case (AL_FILTER_SET_SOURCE):
f->source = (ALFilter *) param;
break;
case (AL_FILTER_SET_DRAM):
a->dramout = pp;
break;
default:
break;
}
return 0;
}

309
src/core1/done/audio/seq.c Normal file
View File

@@ -0,0 +1,309 @@
#include <ultra64.h>
#include "functions.h"
#include "variables.h"
extern f64 D_80278D50;
extern f64 D_80278D58;
#define IFF_FILE_HDR 0x4d546864 /* 'MThd' */
#define IFF_TRACK_HDR 0x4d54726b /* 'MTrk' */
static s32 readVarLen(ALSeq *s);
static u8 read8(ALSeq *s);
static s16 read16(ALSeq *s);
static s32 read32(ALSeq *s);
void alSeqNew(ALSeq *seq, u8 *ptr, s32 len)
{
/*
* load the seqence pointed to by ptr
*/
seq->base = ptr;
seq->len = len;
seq->lastStatus = 0;
seq->lastTicks = 0;
seq->curPtr = ptr;
if (read32(seq) != IFF_FILE_HDR) {
#ifdef _DEBUG
__osError(ERR_ALSEQNOTMIDI, 1, ptr);
#endif
return;
}
read32(seq); /* skip the length field */
if (read16(seq) != 0) {
#ifdef _DEBUG
__osError(ERR_ALSEQNOTMIDI0, 1, ptr);
#endif
return;
}
if (read16(seq) != 1) {
#ifdef _DEBUG
__osError(ERR_ALSEQNUMTRACKS, 1, ptr);
#endif
return;
}
seq->division = read16(seq);
if (seq->division & 0x8000) {
#ifdef _DEBUG
__osError(ERR_ALSEQTIME, 1, ptr);
#endif
return;
}
seq->qnpt = 1.0/(f32)seq->division;
if (read32(seq) != IFF_TRACK_HDR) {
#ifdef _DEBUG
__osError(ERR_ALSEQTRACKHDR, 1, ptr);
#endif
return;
}
read32(seq); /* skip the length field */
seq->trackStart = seq->curPtr;
}
void alSeqNextEvent(ALSeq *seq, ALEvent *event)
{
u8 status;
s16 delta;
s32 len;
s32 deltaTicks;
s32 i;
#ifdef _DEBUG
/* sct 1/17/96 - Warn if curPtr is beyond the end of sequence. */
if (seq->curPtr >= seq->base + seq->len)
__osError(ERR_ALSEQOVERRUN, 0);
#endif
deltaTicks = readVarLen(seq); /* read the delta time */
seq->lastTicks += deltaTicks;
status = read8(seq);
#if _DEBUG
/*
* System exclusives are not supported, so just skip them and read
* the next event
*/
if ((status == 0xf0) || (status == 0xf7)) {
__osError(ERR_ALSEQSYSEX, 0);
len = readVarLen(seq);
for (i = 0; i < len; i++) {
read8(seq);
}
alSeqNextEvent(seq,event);
return;
}
#endif
if (status == AL_MIDI_Meta) {
u8 type = read8(seq);
if (type == AL_MIDI_META_TEMPO) {
event->type = AL_TEMPO_EVT;
event->msg.tempo.ticks = deltaTicks;
event->msg.tempo.status = status;
event->msg.tempo.type = type;
event->msg.tempo.len = read8(seq);
event->msg.tempo.byte1 = read8(seq);
event->msg.tempo.byte2 = read8(seq);
event->msg.tempo.byte3 = read8(seq);
} else if (type == AL_MIDI_META_EOT) {
event->type = AL_SEQ_END_EVT;
event->msg.end.ticks = deltaTicks;
event->msg.end.status = status;
event->msg.end.type = type;
event->msg.end.len = read8(seq);
} else {
#ifdef _DEBUG
__osError(ERR_ALSEQMETA, 1, type);
len = readVarLen(seq);
for (i = 0; i < len; i++) {
read8(seq);
}
alSeqNextEvent(seq,event);
return;
#endif
}
seq->lastStatus = 0;
} else {
event->type = AL_SEQ_MIDI_EVT;
event->msg.midi.ticks = deltaTicks;
if (status & 0x80) {
event->msg.midi.status = status;
event->msg.midi.byte1 = read8(seq);
seq->lastStatus = status;
} else {
/* running status */
event->msg.midi.status = seq->lastStatus;
event->msg.midi.byte1 = status;
}
if (((event->msg.midi.status & 0xf0) != AL_MIDI_ProgramChange) &&
((event->msg.midi.status & 0xf0) != AL_MIDI_ChannelPressure)) {
event->msg.midi.byte2 = read8(seq);
} else {
event->msg.midi.byte2 = 0;
}
}
}
/*
Returns the delta time in ticks for the next event in the sequence.
Assumes that the sequence data pointer is pointing to the delta time.
If the curPtr is at or beyond the end of the sequence, then return FALSE
to indicate no next event.
sct 11/6/95
*/
char __alSeqNextDelta (ALSeq *seq, s32 *pDeltaTicks)
{
u8 * savedPtr;
/* sct 1/16/96 - Put in safety check here to make sure we don't read past sequence data. */
if (seq->curPtr >= seq->base + seq->len)
return FALSE;
savedPtr = seq->curPtr;
*pDeltaTicks = readVarLen(seq); /* read the delta time */
seq->curPtr = savedPtr;
return TRUE;
}
f32 alSeqTicksToSec(ALSeq *seq, s32 ticks, u32 tempo)
{
return ((f32) (((f32)(ticks) * (f32)(tempo)) /
((f32)(seq->division) * 1000000.0)));
}
u32 alSeqSecToTicks(ALSeq *seq, f32 sec, u32 tempo)
{
return (u32)(((sec * 1000000.0) * seq->division) / tempo);
}
void alSeqNewMarker(ALSeq *seq, ALSeqMarker *m, u32 ticks)
{
ALEvent evt;
u8 *savePtr, *lastPtr;
s32 saveTicks, lastTicks;
s16 saveStatus, lastStatus;
/* does not check that ticks is within bounds */
if (ticks == 0) { /* common case */
m->curPtr = seq->trackStart;
m->lastStatus = 0;
m->lastTicks = 0;
m->curTicks = 0;
return;
} else {
savePtr = seq->curPtr;
saveStatus = seq->lastStatus;
saveTicks = seq->lastTicks;
seq->curPtr = seq->trackStart;
seq->lastStatus = 0;
seq->lastTicks = 0;
do {
lastPtr = seq->curPtr;
lastStatus = seq->lastStatus;
lastTicks = seq->lastTicks;
alSeqNextEvent(seq, &evt);
if (evt.type == AL_SEQ_END_EVT)
{
lastPtr = seq->curPtr;
lastStatus = seq->lastStatus;
lastTicks = seq->lastTicks;
break;
}
} while (seq->lastTicks < ticks);
m->curPtr = lastPtr;
m->lastStatus = lastStatus;
m->lastTicks = lastTicks;
m->curTicks = seq->lastTicks; /* Used by test loop condition. */
seq->curPtr = savePtr;
seq->lastStatus = saveStatus;
seq->lastTicks = saveTicks;
}
}
s32 alSeqGetTicks(ALSeq *seq){
return seq->lastTicks;
}
void alSeqSetLoc(ALSeq *seq, ALSeqMarker *m){
seq->curPtr = m->curPtr;
seq->lastStatus = m->lastStatus;
seq->lastTicks = m->lastTicks;
}
void alSeqGetLoc(ALSeq *seq, ALSeqMarker *m){
m->curPtr = seq->curPtr;
m->lastStatus = seq->lastStatus;
m->lastTicks = seq->lastTicks;
}
/* non-aligned byte reading routines */
static u8 read8(ALSeq *seq)
{
return *seq->curPtr++;
}
static s16 read16(ALSeq *seq)
{
s16 tmp;
tmp = *seq->curPtr++ << 8;
tmp |= *seq->curPtr++;
return tmp;
}
static s32 read32(ALSeq *seq)
{
s32 tmp;
tmp = *seq->curPtr++ << 24;
tmp |= *seq->curPtr++ << 16;
tmp |= *seq->curPtr++ << 8;
tmp |= *seq->curPtr++;
return tmp;
}
static s32 readVarLen(ALSeq *seq)
{
s32 value;
s32 c;
c = *seq->curPtr++;
value = c;
if ( c & 0x80 ) {
value &= 0x7f;
do {
c = *seq->curPtr++;
value = (value << 7) + (c & 0x7f);
} while (c & 0x80);
}
return (value);
}

38
src/core1/done/audio/sl.c Normal file
View File

@@ -0,0 +1,38 @@
#include <ultra64.h>
#include "functions.h"
#include "variables.h"
void alInit(ALGlobals *g, ALSynConfig *c){
if (!alGlobals) { /* already initialized? */
alGlobals = g;
alSynNew(&alGlobals->drvr, c);
}
}
void alClose(ALGlobals *glob)
{
if (alGlobals) {
alSynDelete(&glob->drvr);
alGlobals = 0;
}
}
void alLink(ALLink *ln, ALLink *to){
ln->next = to->next;
ln->prev = to;
if (to->next)
to->next->prev = ln;
to->next = ln;
}
void alUnlink(ALLink *ln){
if (ln->next)
ln->next->prev = ln->prev;
if (ln->prev)
ln->prev->next = ln->next;
}

View File

@@ -0,0 +1,12 @@
#include <ultra64.h>
#include "synthInternals.h"
ALFxRef *alSynAllocFX(ALSynth *s, s16 bus, ALSynConfig *c, ALHeap *hp)
{
alFxNew(&s->auxBus[bus].fx[0], c, hp);
alFxParam(&s->auxBus[bus].fx[0], AL_FILTER_SET_SOURCE,
&s->auxBus[bus]);
alMainBusParam(s->mainBus, AL_FILTER_ADD_SOURCE,&s->auxBus[bus].fx[0]);
return (ALFxRef)(&s->auxBus[bus].fx[0]);
}

View File

@@ -0,0 +1,6 @@
#include <ultra64.h>
void alSynDelete(ALSynth *drvr)
{
drvr->head = 0;
}

View File

@@ -0,0 +1,303 @@
#include <ultra64.h>
#include "synthInternals.h"
#ifdef AUD_PROFILE
#include <os.h>
extern u32 cnt_index, drvr_num, drvr_cnt, drvr_max, drvr_min, lastCnt[];
extern u32 client_num, client_cnt, client_max, client_min;
#endif
#ifndef MIN
# define MIN(a,b) (((a)<(b))?(a):(b))
#endif
#ifndef assert
#define assert(s)
#endif
static s32 __nextSampleTime(ALSynth *drvr, ALPlayer **client);
static s32 _timeToSamplesNoRound(ALSynth *ALSynth, s32 micros);
/***********************************************************************
* Synthesis driver public interfaces
***********************************************************************/
void alSynNew(ALSynth *drvr, ALSynConfig *c)
{
s32 i;
ALVoice *vv;
PVoice *pv;
ALVoice *vvoices;
PVoice *pvoices;
ALHeap *hp = c->heap;
ALSave *save;
ALFilter *sources;
ALParam *params;
ALParam *paramPtr;
drvr->head = NULL;
drvr->numPVoices = c->maxPVoices;
drvr->curSamples = 0;
drvr->paramSamples = 0;
drvr->outputRate = c->outputRate;
drvr->maxOutSamples = AL_MAX_RSP_SAMPLES;
drvr->dma = (ALDMANew) c->dmaproc;
save = alHeapAlloc(hp, 1, sizeof(ALSave));
alSaveNew(save);
drvr->outputFilter = (ALFilter *)save;
/*
* allocate and initialize the auxilliary effects bus. at present
* we only support 1 effects bus.
*/
drvr->auxBus = alHeapAlloc(hp, 1, sizeof(ALAuxBus));
drvr->maxAuxBusses = 1;
sources = alHeapAlloc(hp, c->maxPVoices, sizeof(ALFilter *));
alAuxBusNew(drvr->auxBus, sources, c->maxPVoices);
/*
* allocate and initialize the main bus.
*/
drvr->mainBus = alHeapAlloc(hp, 1, sizeof(ALMainBus));
sources = alHeapAlloc(hp, c->maxPVoices, sizeof(ALFilter *));
alMainBusNew(drvr->mainBus, sources, c->maxPVoices);
if (c->fxType != AL_FX_NONE){
/*
* Allocate an effect and set parameters
*/
alSynAllocFX(drvr, 0, c, hp);
} else
/*
* Connect the aux bus to the main bus
*/
alMainBusParam(drvr->mainBus, AL_FILTER_ADD_SOURCE, &drvr->auxBus[0]);
/*
* Build the physical voice lists
*/
drvr->pFreeList.next = 0;
drvr->pFreeList.prev = 0;
drvr->pLameList.next = 0;
drvr->pLameList.prev = 0;
drvr->pAllocList.next = 0;
drvr->pAllocList.prev = 0;
pvoices = alHeapAlloc(hp, c->maxPVoices, sizeof(PVoice));
for (i = 0; i < c->maxPVoices; i++) {
pv = &pvoices[i];
alLink((ALLink *)pv, &drvr->pFreeList);
pv->vvoice = 0;
alLoadNew(&pv->decoder, drvr->dma, hp);
alLoadParam(&pv->decoder, AL_FILTER_SET_SOURCE, 0);
alResampleNew(&pv->resampler, hp);
alResampleParam(&pv->resampler, AL_FILTER_SET_SOURCE, &pv->decoder);
alEnvmixerNew(&pv->envmixer, hp);
alEnvmixerParam(&pv->envmixer, AL_FILTER_SET_SOURCE, &pv->resampler);
alAuxBusParam(drvr->auxBus, AL_FILTER_ADD_SOURCE, &pv->envmixer);
pv->channelKnob = (ALFilter *)&pv->envmixer;
}
alSaveParam(save, AL_FILTER_SET_SOURCE, drvr->mainBus);
/*
* build the parameter update list
*/
params = alHeapAlloc(hp, c->maxUpdates, sizeof(ALParam));
drvr->paramList = 0;
for (i = 0; i < c->maxUpdates; i++) {
paramPtr= &params[i];
paramPtr->next = drvr->paramList;
drvr->paramList = paramPtr;
}
drvr->heap = hp;
}
/*
* slAudioFrame() is called every video frame, and is based on the video
* frame interrupt. It is assumed to be an accurate time source for the
* clients.
*/
Acmd *alAudioFrame(Acmd *cmdList, s32 *cmdLen, s16 *outBuf, s32 outLen)
{
ALPlayer *client;
ALFilter *output;
ALSynth *drvr = &alGlobals->drvr;
s16 tmp = 0; /* Starting buffer in DMEM */
Acmd *cmdlEnd = cmdList;
Acmd *cmdPtr;
s32 nOut;
s16 *lOutBuf = outBuf;
#ifdef AUD_PROFILE
lastCnt[++cnt_index] = osGetCount();
#endif
if (drvr->head == 0) {
*cmdLen = 0;
return cmdList; /* nothing to do */
}
/*
* run down list of clients and execute callback if needed this
* subframe. Here we do all the work for the frame at the
* start. Time offsets that occur before the next frame are
* executed "early".
*/
#ifdef AUD_PROFILE
lastCnt[++cnt_index] = osGetCount();
#endif
/*
* paramSamples = time of next parameter change.
* curSamples = current sample time.
* so paramSamples - curSamples is the time until the next parameter change.
* if the next parameter change occurs within this frame time (outLen),
* then call back the client that contains the parameter change.
* Note, paramSamples must be rounded down to 16 sample boundary for use
* during the client handler.
*/
for (drvr->paramSamples = __nextSampleTime(drvr, &client);
drvr->paramSamples - drvr->curSamples < outLen;
drvr->paramSamples = __nextSampleTime(drvr, &client))
{
drvr->paramSamples &= ~0xf;
client->samplesLeft += _timeToSamplesNoRound(drvr, (*client->handler)(client));
}
/* for safety's sake, always store paramSamples aligned to 16 sample boundary.
* this way, if an voice handler routine gets called outside the ALVoiceHandler
* routine (alSynAllocVoice) it will get timestamped with an aligned value and
* will be processed immediately next audio frame.
*/
drvr->paramSamples &= ~0xf;
#ifdef AUD_PROFILE
PROFILE_AUD(client_num, client_cnt, client_max, client_min);
#endif
/*
* Now build the command list in small chunks
*/
while (outLen > 0){
nOut = MIN(drvr->maxOutSamples, outLen);
/*
* construct the command list for each physical voice by calling
* the head of the filter chain.
*/
cmdPtr = cmdlEnd;
aSegment(cmdPtr++, 0, 0);
output = drvr->outputFilter;
(*output->setParam)(output, AL_FILTER_SET_DRAM, lOutBuf);
cmdlEnd = (*output->handler)(output, &tmp, nOut, drvr->curSamples,
cmdPtr);
outLen -= nOut;
lOutBuf += nOut<<1; /* For Stereo */
drvr->curSamples += nOut;
}
*cmdLen = (s32) (cmdlEnd - cmdList);
_collectPVoices(drvr); /* collect free physical voices */
#ifdef AUD_PROFILE
PROFILE_AUD(drvr_num, drvr_cnt, drvr_max, drvr_min);
#endif
return cmdlEnd;
}
/***********************************************************************
* Synthesis driver private interfaces
***********************************************************************/
ALParam *__allocParam()
{
ALParam *update = 0;
ALSynth *drvr = &alGlobals->drvr;
if (drvr->paramList) {
update = drvr->paramList;
drvr->paramList = drvr->paramList->next;
update->next = 0;
}
return update;
}
void __freeParam(ALParam *param)
{
ALSynth *drvr = &alGlobals->drvr;
param->next = drvr->paramList;
drvr->paramList = param;
}
void _collectPVoices(ALSynth *drvr)
{
ALLink *dl;
PVoice *pv;
while ((dl = drvr->pLameList.next) != 0) {
pv = (PVoice *)dl;
/* ### remove from mixer */
alUnlink(dl);
alLink(dl, &drvr->pFreeList);
}
}
void _freePVoice(ALSynth *drvr, PVoice *pvoice)
{
/*
* move the voice from the allocated list to the lame list
*/
alUnlink((ALLink *)pvoice);
alLink((ALLink *)pvoice, &drvr->pLameList);
}
/*
Add 0.5 to adjust the average affect of
the truncation error produced by casting
a float to an int.
*/
s32 _timeToSamplesNoRound(ALSynth *synth, s32 micros)
{
f32 tmp = ((f32)micros) * synth->outputRate / 1000000.0 + 0.5;
return (s32)tmp;
}
s32 _timeToSamples(ALSynth *synth, s32 micros)
{
return _timeToSamplesNoRound(synth, micros) & ~0xf;
}
static s32 __nextSampleTime(ALSynth *drvr, ALPlayer **client)
{
ALMicroTime delta = 0x7fffffff; /* max delta for s32 */
ALPlayer *cl;
assert(drvr->head);
*client = 0;
for (cl = drvr->head; cl != 0; cl = cl->next) {
if ((cl->samplesLeft - drvr->curSamples) < delta) {
*client = cl;
delta = cl->samplesLeft - drvr->curSamples;
}
}
return (*client)->samplesLeft;
}

View File

@@ -0,0 +1,15 @@
#include <ultra64.h>
#include "functions.h"
#include "variables.h"
void func_8025AFB0(void) {}
void func_8025AFB8(void) {}
void func_8025AFC0(Gfx **arg0, Mtx **arg1, Vtx **arg2) {}
s32 func_8025AFD0(void)
{
return 0;
}

133
src/core1/done/code_1E360.c Normal file
View File

@@ -0,0 +1,133 @@
#include <ultra64.h>
#include "functions.h"
#include "variables.h"
#include "SnS.h"
/**
* An index used to track the position in the incoming payload
* we should read the next key from.
*/
extern s32 snsPayloadInCurrPos;
/**
* An index used to track the position in the outgoing payload
* it should write the next key to.
*/
extern s32 snsPayloadOutCurrPos;
struct SnsPayload *snspayload_init_new_payload(struct SnsPayload *payload)
{
u32 i;
payload->magic = SNS_HEADER_MAGIC;
for (i = 0; i < SNS_PAYLOAD_DATALEN; i++)
payload->data[i] = 0;
payload->pad = 0;
snspayload_calc_checksum(payload);
return payload;
}
void snspayload_set_key_at_idx(struct SnsPayload *payload, s32 idx, s32 key)
{
payload->data[idx] = key;
snspayload_calc_checksum(payload);
}
void snspayload_calc_checksum(struct SnsPayload *payload)
{
glcrc_calc_checksum(payload, &payload->checksum, payload->checksum);
}
bool snspayload_validate(struct SnsPayload *payload)
{
u32 checksum[2];
glcrc_calc_checksum(payload, payload->checksum, checksum);
if ((payload->checksum[0] == checksum[0]) && (payload->checksum[1] == checksum[1]))
return TRUE;
return FALSE;
}
struct SnsPayload *snspayload_find_payload_in_ram(void)
{
struct SnsPayload *payload;
for (payload = (struct SnsPayload *)0x80000000; payload < (struct SnsPayload *)0x80400080; payload++)
if (payload->magic == SNS_HEADER_MAGIC && snspayload_validate(payload))
return payload;
return NULL;
}
s32 snspayload_contains_key(struct SnsPayload *payload, s32 key)
{
u32 i;
for (i = 0; i < SNS_PAYLOAD_DATALEN; i++)
if (payload->data[i] == key)
return key;
return 0;
}
s32 snspayload_get_key_in_range(struct SnsPayload *payload, s32 min, s32 max)
{
s32 i;
for (i = 0; i < SNS_PAYLOAD_DATALEN; i++)
{
if (payload->data[i] < min)
continue;
if (payload->data[i] > max)
continue;
return payload->data[i];
}
return 0;
}
void snspayload_rewind_incoming(void)
{
snsPayloadInCurrPos = 0;
}
u32 snspayload_get_next_key(struct SnsPayload *payload)
{
while (snsPayloadInCurrPos < SNS_PAYLOAD_DATALEN)
{
if (payload->data[snsPayloadInCurrPos])
return payload->data[snsPayloadInCurrPos++];
snsPayloadInCurrPos++;
}
return 0;
}
void snspayload_rewind_outgoing(void)
{
snsPayloadOutCurrPos = 0;
}
void snspayload_append_key_to_outgoing_payload(struct SnsPayload *payload, s32 key)
{
payload->data[snsPayloadOutCurrPos++] = key;
}
void snspayload_finalise_outgoing_payload(struct SnsPayload *payload)
{
while (snsPayloadOutCurrPos < SNS_PAYLOAD_DATALEN)
payload->data[snsPayloadOutCurrPos++] = 0;
snspayload_calc_checksum(payload);
}

View File

@@ -0,0 +1,36 @@
#include <ultra64.h>
#include "functions.h"
#include "variables.h"
#include "n_libaudio.h"
extern N_ALSynth *D_80276E80;
extern N_ALSynth *D_80276E84;
void func_8025C2E0(s32 a0)
{
if (D_80276E80)
{
func_8025F610();
D_80276E80 = NULL;
D_80276E84 = NULL;
}
}
void func_8025C320(N_ALSynth *synth, ALSynConfig *config)
{
if (D_80276E80 != NULL)
return;
D_80276E80 = synth;
if (D_80276E84 != NULL)
return;
D_80276E84 = synth;
n_alSynNew(config);
}

651
src/core1/done/code_CE60.c Normal file
View File

@@ -0,0 +1,651 @@
#include <ultra64.h>
#include "functions.h"
#include "variables.h"
#include "SnS.h"
typedef struct {
s16 x_min;
s16 x_max;
s16 y_min;
s16 y_max;
s16 z_min;
s16 z_max;
} Struct_Core1_CE60_0s;
void func_80250530(s32, u16 chan_mask, f32);
/* .data */
extern s32 D_80275C10;
extern s32 D_80275C14;
extern u8 D_80275C18;
extern u8 D_80275C1C;
extern Struct_Core1_CE60_0s D_80275C20[];
/* .bss */
s32 D_802806F0;
int D_802806F4;
s32 D_802806F8[4];
s32 D_80280708[4];
/* .code */
void func_8024A880(s32 chan_mask){
func_80250530(0, chan_mask, 3.0f);
}
void func_8024A8AC(s32 chan_mask, f32 arg1){
func_80250530(0, chan_mask, arg1);
}
int func_8024A8DC(s32 arg0, s32 arg1, s32 arg2){
return (arg0 - D_802806F8[0])*(arg0 - D_802806F8[0]) + (arg1 - D_802806F8[2])*(arg1 - D_802806F8[2]) < arg2*arg2;
}
f32 func_8024A928(f32 arg0, f32 arg1){
return gu_sqrtf((arg0 - D_802806F8[0])*(arg0 - D_802806F8[0]) + (arg1 - D_802806F8[2])*(arg1 - D_802806F8[2]));
}
int func_8024A984(s32 arg0){
func_802585E0(D_802806F8, D_80275C20[arg0].x_min, D_80275C20[arg0].y_min, D_80275C20[arg0].z_min, D_80275C20[arg0].x_max, D_80275C20[arg0].y_max, D_80275C20[arg0].z_max);
}
void func_8024A9EC(s32 arg0){
if(!func_8025ADBC(D_80280708[0]) && D_80280708[2]){
func_8025A104(D_80280708[0], 0);
}
func_8025A55C(D_80280708[2], arg0 ? arg0 : 0x1f4, 4 );
if(func_8025AD7C(D_80280708[1]) || D_80280708[3]){
func_8025ABB8(D_80280708[1], D_80280708[3], arg0 ? arg0 : 0x1f4, 4 );
}//L8024AA94
func_8025A864(D_80280708[1]);
}
void func_8024AAB0(void){
f32 plyr_pos[3]; //sp34
f32 sp30;
func_8028EB3C(&D_802806F8);
player_getPosition(plyr_pos);
D_80280708[0] = func_8032274C();
D_80280708[1] = func_80322758();
D_80280708[2] = D_80280708[3] = 0;
if(0 <= D_80280708[0])
D_80280708[2] = func_80250034(D_80280708[0]);
if(0 <= D_80280708[1])
D_80280708[3] = func_80250034(D_80280708[1]);
switch(map_get()){
case MAP_7_TTC_TREASURE_TROVE_COVE: //L8024ABA8
D_80280708[2] = ml_map_f(4700 - D_802806F8[1], 0.0f, 900.0f, 0.0f, D_80280708[2]);
D_80280708[3] = ml_map_f(4700 - D_802806F8[1], 0.0f, 900.0f, D_80280708[3], 0.0f);
break;
case MAP_B_CC_CLANKERS_CAVERN: //
sp30 = func_8024A928(13909.0f, -26.0f);
D_80280708[2] = ml_map_f(sp30, 1500.0f, 1800.0f, 0.0f, D_80280708[2]);
D_80280708[3] = ml_map_f(sp30, 1500.0f, 1800.0f, D_80280708[3], 0.0f);
break;
case MAP_1_SM_SPIRAL_MOUNTAIN: //L8024ACC4
if(func_8024A984(4))
D_80280708[2] = 0;
else
D_80280708[3] = 0;
break;
case MAP_1B_MMM_MAD_MONSTER_MANSION: //L8024ACE4
if(func_80309D58(plyr_pos, 1)){
D_80280708[2] = 0;
}
else{
D_80280708[3] = 0;
}
break;
case MAP_41_FP_BOGGYS_IGLOO: //L8024AD08
if( jiggyscore_isCollected(JIGGY_2E_FP_PRESENTS)
|| (levelSpecificFlags_get(0x11) && levelSpecificFlags_get(0x12) && levelSpecificFlags_get(0x13))
){
D_80280708[2] = 0;
}
else{
D_80280708[3] = 0;
}
break;
case MAP_1D_MMM_CELLAR: //L8024AD58
if(sns_get_item_state(SNS_ITEM_EGG_CYAN, 1) && D_802806F8[0] >= 0x23A){
D_80280708[2] = 0;
}
else{
D_80280708[3] = 0;
}
break;
case MAP_7F_FP_WOZZAS_CAVE: //L8024AD8C
if(sns_get_item_state(SNS_ITEM_ICE_KEY, 1) && func_8024A8DC(0x619, 0x97a, 0x69a)){
D_80280708[2] = 0;
}
else{
D_80280708[3] = 0;
}
break;
case MAP_45_CCW_AUTUMN: //L8024ADC0
case MAP_46_CCW_WINTER: //L8024ADC0
if(func_8024A984(5)){
D_80280708[2] = 0;
}
else{
D_80280708[3] = 0;
}
break;
}//L8024ADE0
}
void func_8024ADF0(s32 arg0){
func_8024AAB0();
if(arg0)
func_8025A9D4();
if(0 < D_80280708[0] && 0 < D_80280708[2])
func_8025A104(D_80280708[0], D_80280708[2]);
if(0 < D_80280708[1] && 0 < D_80280708[3])
func_8025A6CC(D_80280708[1], D_80280708[3]);
}
void func_8024AE74(void){
D_802806F0 = 0;
D_80275C10 = -1;
D_80275C14 = 0;
D_80275C1C = D_80275C18 = func_8024A8DC(0xb43, -0x2918, 0x1950) ? 1 : 0;
}
void func_8024AED8(void){
D_80275C10 = -1;
D_80275C14 = 0;
D_80275C18 = 0;
D_80275C1C = 0;
}
void func_8024AF00(s32 arg0, s32 arg1){
if(func_8028EE84() == BSWATERGROUP_2_UNDERWATER){
func_8024A880(arg0);
}
else{
func_8024A880(arg1);
}
}
void func_8024AF48(void){
if(!D_802806F4) return;
if(func_803203FC(1)) return;
if(func_803203FC(0x1f)) return;
if(func_802D686C()) return;
if(func_8028F22C()) return;
if(gctransition_8030BDC0()) return;
if(getGameMode() == GAME_MODE_A_SNS_PICTURE) return;
func_8028EB3C(D_802806F8);
func_8024AAB0();
switch(map_get()){
case MAP_2_MM_MUMBOS_MOUNTAIN: // L8024B000
if(func_8024A8DC(-4450, 4550, 1900) ||func_8024A8DC(-0x1777, 0x1820, 0x26c)){
func_8024A880(0x1cc0);
}
else if(func_8024A8DC(0x119F, -0x760, 0x7d0)){
func_8024A880(0xb0c0);
}
else if(func_8024A8DC(0x12c, -0x35a, 0x898)){
func_8024A880(0x513f);
}
else{
func_8024AF00(0x200, 0x103f);
}
break;
case MAP_7_TTC_TREASURE_TROVE_COVE: // L8024B094
func_8024A9EC(0);
if(func_8028EE84() == BSWATERGROUP_2_UNDERWATER){
func_8024A880(0x600);
}
else if(func_8024A8DC(-0x12C, 0x58c, 0x866)
|| (func_8024A8DC(-0x12c, 0x58c, 0xc1c)
&& D_802806F8[1] < 0x514
&& !func_8024A8DC(-0x49, 0x2c43, 0x1c0c)
&& !func_8024A8DC(0x6c8, 0xe04, 0x1c7)
&& !func_8024A8DC(0x564, 0xf9a, 0x190)
)
){
func_8024A880(0x7800);
}
else{
func_8024A880(0x60ff);
}
break;
case MAP_B_CC_CLANKERS_CAVERN: // L8024B158
func_8024A9EC(0);
if(func_8028EE84() == BSWATERGROUP_2_UNDERWATER){
if(!(D_802806F8[1] < 0x28b)){
func_8024A8AC(0x8180, 5.0f);
}
else{
func_8024A8AC(0x3e00, 5.0f);
}
}
else{
func_8024A880(0x407f);
}
break;
case MAP_12_GV_GOBIS_VALLEY:// L8024B1BC
if(func_8028EE84() == BSWATERGROUP_2_UNDERWATER){
func_8024A880(0x8020);
}
else if(func_8024A8DC(-0xf96, 0x1626, 0xe74)){
func_8024A880(0x797f);
}
else{
func_8024A880(0x67fe);
}
break;
case MAP_3_UNUSED: // L8024B214
func_8024AF00(0x1800, 0x67fe);
break;
case MAP_5_TTC_BLUBBERS_SHIP: // L8024B228
func_8024AF00(0x600, 0x7800);
break;
case MAP_1_SM_SPIRAL_MOUNTAIN: // L8024B23C
if(func_8028EE84() == BSWATERGROUP_2_UNDERWATER){
func_8024A880(0x9000);
}
else{
if(func_802DA498())
func_8024A9EC(0);
func_8024A880(0x6fff);
}
break;
case MAP_21_CC_WITCH_SWITCH_ROOM:// L8024B288
case MAP_22_CC_INSIDE_CLANKER:// L8024B288
case MAP_23_CC_GOLDFEATHER_ROOM:// L8024B288
func_8024AF00(0x3c00, 0x61ff);
break;
case MAP_25_MMM_WELL:// L8024B29C
case MAP_2F_MMM_WATERDRAIN_BARREL:// L8024B29C
func_8024AF00(0x1000, 0xcfff);
break;
case MAP_13_GV_MEMORY_GAME:// L8024B2B0
case MAP_14_GV_SANDYBUTTS_MAZE:// L8024B2B0
case MAP_15_GV_WATER_PYRAMID:// L8024B2B0
case MAP_16_GV_RUBEES_CHAMBER:// L8024B2B0
case MAP_1A_GV_INSIDE_JINXY:// L8024B2B0
func_8024AF00(0x3ffe, 0x4ffe);
break;
case MAP_1B_MMM_MAD_MONSTER_MANSION:// L8024B2C4
if( !mapSpecificFlags_get(1)
&& !func_8025AD7C(COMUSIC_4_MMM_CLOCK_VERSION)
&& !func_8025AD7C(COMUSIC_3C_MINIGAME_LOSS)
){
func_8024A9EC(0);
}
func_8024A880((mapSpecificFlags_get(1) ? 0x2000: 0) + 0xcfff);
break;
case MAP_D_BGS_BUBBLEGLOOP_SWAMP: // L8024B328
if( func_8024A8DC(0x762, -0x542, 0x578)
|| func_8024A8DC(-0x85, 0x7d8, 0x384)
|| func_8024A8DC(-0xe2d, -0x217, 0x578)
){
func_8024A8AC(0x2f4f, 2.0f);
}
else{
func_8024A8AC(0x6f4f, 2.0f);
}
break;
case MAP_31_RBB_RUSTY_BUCKET_BAY:// L8024B38C
if( (-4200 <= D_802806F8[0] && D_802806F8[0] < -3700)
&& (-900 <= D_802806F8[2] && D_802806F8[2] < 900)
){
func_8024A880(0x51ff);
}
else{
func_8024AF00(0x800, 0x71bf);
}
break;
case MAP_35_RBB_WAREHOUSE:// L8024B3E8
case MAP_36_RBB_BOATHOUSE:// L8024B3E8
case MAP_37_RBB_CONTAINER_1:// L8024B3E8
case MAP_38_RBB_CONTAINER_3:// L8024B3E8
case MAP_3E_RBB_CONTAINER_2:// L8024B3E8
func_8024AF00(0x800, 0xfe);
break;
case MAP_40_CCW_HUB:// L8024B3FC
if(func_8024A8DC(0, 0, 0x802)){
func_8024A8AC(7, 2.0f);
}
else if(0x5aa <= D_802806F8[2]){
func_8024A8AC(0x407, 2.0f);
}
else if(D_802806F8[0] < -0x5a9){
func_8024A8AC(0x707, 2.0f);
}
else if(D_802806F8[2] < -0x5a9){
func_8024A8AC(0x1067, 2.0f);
}
else if(0x5aa <= D_802806F8[0]) {
func_8024A8AC(0x7007, 2.0f);
}
break;
case MAP_A_TTC_SANDCASTLE: // L8024B4AC
func_8024AF00(0xCE, 0x3C);
break;
case MAP_43_CCW_SPRING:// L8024B4C0
func_8024AF00(0x400, 0x7bbf);
break;
case MAP_45_CCW_AUTUMN:// L8024B4D4
if(func_8028EE84() == BSWATERGROUP_2_UNDERWATER){
func_8024A880(0x600);
}
else{
func_8024A9EC(0);
func_8024A880(0x7BEF);
}
break;
case MAP_54_UNUSED:// L8024B510
case MAP_55_UNUSED:// L8024B510
case MAP_57_UNUSED:// L8024B510
case MAP_58_UNUSED:// L8024B510
case MAP_59_UNUSED:// L8024B510
func_8024AF00(0xc, 0x307b);
break;
case MAP_56_UNUSED:// L8024B524
func_8024AF00(0x10, 0x4f6f);
break;
case MAP_27_FP_FREEZEEZY_PEAK:// L8024B538
if(func_8028EE84() == BSWATERGROUP_2_UNDERWATER){
func_8024A880(0x400);
}
else if( mapSpecificFlags_get(0) && !jiggyscore_isCollected(JIGGY_2F_FP_XMAS_TREE)){
func_8024A880(0x4bff);
}
else{
func_8024A880(0x43ff);
}
break;
case MAP_65_CCW_SPRING_WHIPCRACK_ROOM:// L8024B59C
func_8024A880(0x107);
break;
case MAP_66_CCW_SUMMER_WHIPCRACK_ROOM:// L8024B5AC
func_8024A880(0x1C7);
break;
case MAP_67_CCW_AUTUMN_WHIPCRACK_ROOM:// L8024B5BC
func_8024A880(0xC07);
break;
case MAP_68_CCW_WINTER_WHIPCRACK_ROOM:// L8024B5CC
func_8024A880(0x1407);
break;
case MAP_5E_CCW_SPRING_NABNUTS_HOUSE:// L8024B5DC
func_8024A880(0x41fe);
break;
case MAP_5F_CCW_SUMMER_NABNUTS_HOUSE:// L8024B5EC
func_8024A880(0x71fe);
break;
case MAP_60_CCW_AUTUMN_NABNUTS_HOUSE:// L8024B5FC
func_8024A880(0x7fe);
break;
case MAP_61_CCW_WINTER_NABNUTS_HOUSE:// L8024B60C
func_8024A880(0xbfe);
break;
case MAP_63_CCW_AUTUMN_NABNUTS_WATER_SUPPLY:// L8024B61C
func_8024AF00(1, 0x7fe);
break;
case MAP_64_CCW_WINTER_NABNUTS_WATER_SUPPLY:// L8024B630
func_8024AF00(1, 0xbfe);
break;
case MAP_69_GL_MM_LOBBY:// L8024B644
if(func_8024A8DC(0xdb6, -0x65e, 0x4e2))
func_8024A880(0x7c00);
else
func_8024A880(0x41ff);
break;
case MAP_6A_GL_TTC_AND_CC_PUZZLE:// L8024B67C
if(0x2b8 <= D_802806F8[1] && func_8024A8DC(-0x615, -0x389, 0x1dd)){
func_8024A880(0x8e40);
}
else if(func_8024A8DC(0x5dc, -0x37a, 0x226) || func_8024A8DC(0x754, -0x453, 0x172)){
func_8024A880(0xf040);
}
else{
func_8024A880(0x81ff);
}
break;
case MAP_6B_GL_180_NOTE_DOOR:// L8024B704
if(func_8028EE84() == BSWATERGROUP_2_UNDERWATER){
func_8024A880(0x8800);
}
else if(func_8024A8DC(0x10eb, 0x4f5, 0x730)) {
func_8024A880(0x8640);
}
else if(func_8024A8DC(-0x526, 0x777, 0x125) || func_8024A8DC(-0x515, 0x878, 0xea)){
func_8024A880(0xf000);
}else{
func_8024A880(0x81bf);
}
break;
case MAP_6C_GL_RED_CAULDRON_ROOM:// L8024B794
func_8024A880(0x81bf);
break;
case MAP_6D_GL_TTC_LOBBY:// L8024B7A4
func_8024A880(0xf000);
break;
case MAP_70_GL_CC_LOBBY:// L8024B7B4
if(func_8028EE84() == BSWATERGROUP_2_UNDERWATER){
func_8024A880(0x8100);
}
else if(func_8024A8DC(-0x19d6, -0x1d3, 0x71e)){
func_8024A880(0xf047);
}
else{
func_8024A880(0x8e41);
}
break;
case MAP_6E_GL_GV_LOBBY:// L8024B80C
if(func_8024A8DC(0, -0x1996, 0xe42)){
func_8024A880(0xfe00);
}
else{
func_8024A880(0x81ff);
}
break;
case MAP_6F_GL_FP_LOBBY:// L8024B844
if(0xe75 <= D_802806F8[2]){
func_8024A880(0xe040);
}
else{
func_8024A880(0x81bf);
}
break;
case MAP_74_GL_GV_PUZZLE:// L8024B878
if(func_8024A8DC(-0xa49, -0x1f, 0x203)){
func_8024A880(0xe600);
}
else{
func_8024A880(0x81ff);
}
break;
case MAP_75_GL_MMM_LOBBY:// L8024B8B0
case MAP_7A_GL_CRYPT:// L8024B8B0
func_8024A880(0xd800);
break;
case MAP_71_GL_STATUE_ROOM:// L8024B8C0
if(func_8028EE84() == BSWATERGROUP_2_UNDERWATER){
func_8024A880(0x200);
}
else if(func_8024A8DC(-0xf0e, -0x15a, 0x302)){
func_8024A880(0x9c00);
}
else{
func_8024A880(0x81bf);
}
break;
case MAP_72_GL_BGS_LOBBY:// L8024B918
if(D_80275C10 == -1 && D_80275C18 == 0){
D_80275C10 = func_802F9AA8(0x410);
func_802F9F80(D_80275C10, 3.0f, 16777216.0f, 0.0f);
func_802FA060(D_80275C10, 3500, 3500, 0.0f);
D_80275C14 = func_802F9AA8(0x411);
func_802F9F80(D_80275C14, 3.0f, 16777216.0f, 0.0f);
func_802FA060(D_80275C14, 3500, 3500, 0.0f);
}//L8024B9BC
if(D_80275C1C != D_80275C18){
D_80275C1C = D_80275C18;
if(D_80275C18){
func_802F9FD0(D_80275C10, 0.0f, 0.0f, 3.0f);
func_802F9FD0(D_80275C14, 0.0f, 0.0f, 3.0f);
D_80275C10 = -1;
D_80275C14 = 0;
}
}//L8024BA2C
if(func_8024A8DC(0xb43, -0x2918, 0x1950)){
D_80275C18 = 1;
func_8024A880(0xe040);
}
else{
D_80275C18 = 0;
func_8024A880(0x9c00);
}
break;
case MAP_76_GL_640_NOTE_DOOR:// L8024BA70
func_8024AF00(0x8200, 0x81bf);
break;
case MAP_77_GL_RBB_LOBBY:// L8024BA84
func_8024AF00(0x8200, 0xf000);
break;
case MAP_78_GL_RBB_AND_MMM_PUZZLE:// L8024BA98
if(func_8028EE84() == BSWATERGROUP_2_UNDERWATER){
func_8024A880(0x8200);
}
else if(0x15a <= D_802806F8[1] && func_8024A8DC(-0x89a, 0x21a, 0x368)){
func_8024A880(0x8C00);
}
else if(func_8024A8DC(-0x36, 0x14, 0xa5c)){
func_8024A880(0x81bf);
}
else{
func_8024A880(0xf000);
}
break;
case MAP_79_GL_CCW_LOBBY:// L8024BB2C
if(0x31c <= D_802806F8[1] && D_802806F8[1] < 0x44c && func_8024A8DC(0x1c, 0x11c9, 0x431))
func_8024A880(0x81bf);
else if(-4 <= D_802806F8[1] && D_802806F8[1] < 0x168 && func_8024A8DC(0x87, 0x1373, 0x86c))
func_8024A880(0x81bf);
else
func_8024A880(0x9e00);
break;
case MAP_80_GL_FF_ENTRANCE:// L8024BBBC
if(D_802806F8[2] < 0x4e2)
func_8024A880(0xe040);
else
func_8024A880(0x9e00);
break;
case MAP_7F_FP_WOZZAS_CAVE:// L8024BBF0
func_8024A9EC((sns_get_item_state(SNS_ITEM_ICE_KEY, 1) && func_8024A8DC(0x619, 0x97a, 0x69a))? 0x7ff8 : 0);
func_8024AF00(0x20, 0x1f);
break;
case MAP_8B_RBB_ANCHOR_ROOM:// L8024BC40
func_8024AF00(0x800, 0x51ff);
break;
case MAP_34_RBB_ENGINE_ROOM:// L8024BC54
func_8024AF00(0x800, 0x43fe);
break;
case MAP_91_FILE_SELECT:// L8024BC68
if(!func_802C5A30()){
func_8024A8AC(0x200, 0.5f);
}
else{
func_8024A8AC(0x1ff, 0.5f);
}
break;
case MAP_8C_SM_BANJOS_HOUSE:// L8024BC9C
func_8024A8AC(0x1ff, 0.5f);
break;
case MAP_1D_MMM_CELLAR:// L8024BCB0
func_8024A9EC((sns_get_item_state(SNS_ITEM_EGG_CYAN, 1) && !(D_802806F8[0] < 0x23a))? 0x7ff8 : 0);
break;
case MAP_46_CCW_WINTER:// L8024BCF0
func_8024A9EC(0);
break;
}//L8024BCF8
}
void func_8024BD08(s32 arg0){
if(arg0){
D_802806F0++;
}
else{
D_802806F0--;
}
}
void func_8024BD40(s32 arg0, s32 arg1){
if(arg1 == 3){
}
else{
if(arg1 == 2){
D_802806F4 = TRUE;
}
else{
D_802806F4 = FALSE;
}
}
}

42
src/core1/done/gu/guint.h Normal file
View File

@@ -0,0 +1,42 @@
/**************************************************************************
* *
* Copyright (C) 1994, Silicon Graphics, Inc. *
* *
* These coded instructions, statements, and computer programs contain *
* unpublished proprietary information of Silicon Graphics, Inc., and *
* are protected by Federal copyright law. They may not be disclosed *
* to third parties or copied or duplicated in any form, in whole or *
* in part, without the prior written consent of Silicon Graphics, Inc. *
* *
**************************************************************************/
#include "mbi.h"
#include "gu.h"
typedef union
{
struct
{
unsigned int hi;
unsigned int lo;
} word;
double d;
} du;
typedef union
{
unsigned int i;
float f;
} fu;
#ifndef __GL_GL_H__
typedef float Matrix[4][4];
#endif
#define ROUND(d) (int)(((d) >= 0.0) ? ((d) + 0.5) : ((d) - 0.5))
#define ABS(d) ((d) > 0) ? (d) : -(d)
extern float __libm_qnan_f;

View File

@@ -0,0 +1,15 @@
#include <ultra64.h>
#include "functions.h"
#include "variables.h"
void guNormalize(float *x, float *y, float *z)
{
float m;
m = gu_sqrtf((*x)*(*x) + (*y)*(*y) + (*z)*(*z));
m = (f32)1.0/ m;
*x *= m;
*y *= m;
*z *= m;
}

31
src/core1/done/gu/ortho.c Normal file
View File

@@ -0,0 +1,31 @@
#include <ultra64.h>
#include "functions.h"
#include "variables.h"
void guOrthoF(float mf[4][4], float l, float r, float b, float t, float n, float f, float scale)
{
int i, j;
guMtxIdentF(mf);
mf[0][0] = 2/(r-l);
mf[1][1] = 2/(t-b);
mf[2][2] = -2/(f-n);
mf[3][0] = -(r+l)/(r-l);
mf[3][1] = -(t+b)/(t-b);
mf[3][2] = -(f+n)/(f-n);
mf[3][3] = 1;
for (i=0; i<4; i++)
for (j=0; j<4; j++)
mf[i][j] *= scale;
}
void guOrtho(Mtx *m, float l, float r, float b, float t, float n, float f, float scale)
{
float mf[4][4];
guOrthoF(mf, l, r, b, t, n, f, scale);
guMtxF2L(mf, m);
}

157
src/core1/done/gu/sinf.c Normal file
View File

@@ -0,0 +1,157 @@
/**************************************************************************
* *
* Copyright (C) 1994, Silicon Graphics, Inc. *
* *
* These coded instructions, statements, and computer programs contain *
* unpublished proprietary information of Silicon Graphics, Inc., and *
* are protected by Federal copyright law. They may not be disclosed *
* to third parties or copied or duplicated in any form, in whole or *
* in part, without the prior written consent of Silicon Graphics, Inc. *
* *
**************************************************************************/
#include "guint.h"
/* ====================================================================
* ====================================================================
*
* Module: fsin.c
* $Revision: 1.2 $
* $Date: 1995/07/12 17:48:01 $
* $Author: jeffd $
* $Source: /disk6/Master/cvsmdev2/PR/libultra/gu/sinf.c,v $
*
* Revision history:
* 09-Jun-93 - Original Version
*
* Description: source code for fsin function
*
* ====================================================================
* ====================================================================
*/
#pragma weak fsin = __sinf
#pragma weak sinf = __sinf
#define fsin __sinf
/* coefficients for polynomial approximation of sin on +/- pi/2 */
static const du P[] =
{
{0x3ff00000, 0x00000000},
{0xbfc55554, 0xbc83656d},
{0x3f8110ed, 0x3804c2a0},
{0xbf29f6ff, 0xeea56814},
{0x3ec5dbdf, 0x0e314bfe},
};
static const du rpi =
{0x3fd45f30, 0x6dc9c883};
static const du pihi =
{0x400921fb, 0x50000000};
static const du pilo =
{0x3e6110b4, 0x611a6263};
static const fu zero = {0x00000000};
/* ====================================================================
*
* FunctionName fsin
*
* Description computes sine of arg
*
* ====================================================================
*/
float
sinf( float x )
{
double dx, xsq, poly;
double dn;
int n;
double result;
int ix, xpt;
ix = *(int *)&x;
xpt = (ix >> 22);
xpt &= 0x1ff;
/* xpt is exponent(x) + 1 bit of mantissa */
if ( xpt < 0xff )
{
/* |x| < 1.5 */
dx = x;
if ( xpt >= 0xe6 )
{
/* |x| >= 2^(-12) */
/* compute sin(x) with a standard polynomial approximation */
xsq = dx*dx;
poly = ((P[4].d*xsq + P[3].d)*xsq + P[2].d)*xsq + P[1].d;
result = dx + (dx*xsq)*poly;
return ( (float)result );
}
return ( x );
}
if ( xpt < 0x136 )
{
/* |x| < 2^28 */
dx = x;
/* reduce argument to +/- pi/2 */
dn = dx*rpi.d;
n = ROUND(dn);
dn = n;
dx = dx - dn*pihi.d;
dx = dx - dn*pilo.d; /* dx = x - n*pi */
/* compute sin(dx) as before, negating result if n is odd
*/
xsq = dx*dx;
poly = ((P[4].d*xsq + P[3].d)*xsq + P[2].d)*xsq + P[1].d;
result = dx + (dx*xsq)*poly;
if ( (n & 1) == 0 )
return ( (float)result );
return ( -(float)result );
}
if ( x != x )
{
/* x is a NaN; return a quiet NaN */
#ifdef _IP_NAN_SETS_ERRNO
*__errnoaddr = EDOM;
#endif
return ( __libm_qnan_f );
}
/* just give up and return 0.0 */
return ( zero.f );
}

View File

@@ -0,0 +1,8 @@
#include <ultra64.h>
#include "functions.h"
#include "variables.h"
float gu_sqrtf(float val){
return sqrtf(val);
}

Some files were not shown because too many files have changed in this diff Show More