REDRIVER2/src_rebuild/EMULATOR/LIBSPU.C

287 lines
5.0 KiB
C++
Raw Normal View History

2020-03-31 18:55:57 +02:00
#include "LIBSPU.H"
#include "LIBETC.H"
#include <stdio.h>
#include "EMULATOR.H"
#include "LIBAPI.H"
#include <string.h>
#define SPU_CENTERNOTE (49152)
short _spu_voice_centerNote[24] =
{
SPU_CENTERNOTE, SPU_CENTERNOTE, SPU_CENTERNOTE, SPU_CENTERNOTE, SPU_CENTERNOTE, SPU_CENTERNOTE, SPU_CENTERNOTE, SPU_CENTERNOTE, SPU_CENTERNOTE, SPU_CENTERNOTE,
SPU_CENTERNOTE, SPU_CENTERNOTE, SPU_CENTERNOTE, SPU_CENTERNOTE, SPU_CENTERNOTE, SPU_CENTERNOTE, SPU_CENTERNOTE, SPU_CENTERNOTE, SPU_CENTERNOTE, SPU_CENTERNOTE,
SPU_CENTERNOTE, SPU_CENTERNOTE, SPU_CENTERNOTE, SPU_CENTERNOTE
};
SpuCommonAttr dword_424;//Might be wrong struct, need to check
int _spu_isCalled = 0;
int _spu_FiDMA = 0;///@TODO decl as extern find initial value
int _spu_EVdma = 0;
int _spu_rev_flag = 0;
int _spu_rev_reserve_wa = 0;
int _spu_rev_offsetaddr = 0;
int _spu_rev_startaddr = 0;
int _spu_AllocBlockNum = 0;
int _spu_AllocLastNum = 0;
int _spu_memList = 0;
int _spu_trans_mode = 0;
int _spu_transMode = 0;
int _spu_keystat = 0;
int _spu_RQmask = 0;
int _spu_RQvoice = 0;
int _spu_env = 0;
char spu[440];//0x1F801C00 is base address
short* _spu_RXX = (short*)&spu[0];
int _spu_mem_mode_plus = 3;
void* _spu_transferCallback = NULL;///@TODO initial value check
int _spu_inTransfer = 0;///@TODO initial value check
unsigned short _spu_tsa = 0;
void SpuGetAllKeysStatus(char* status)
{
UNIMPLEMENTED();
}
void SpuSetKeyOnWithAttr(SpuVoiceAttr* attr)
{
UNIMPLEMENTED();
}
void _spu_t(int mode, int flag)
{
UNIMPLEMENTED();
}
void _spu_Fw(unsigned char* addr, unsigned long size)
{
//v0 = _spu_transMode
//s1 = addr
//s0 = size
if (_spu_trans_mode == 0)
{
//v0 = _spu_tsa
//a1 = _spu_mem_mode_plus
//a0 = 2
_spu_t(2, _spu_tsa << _spu_mem_mode_plus);
///@TODO check if a1 is modified in spu_t
}
//loc_A84
#if 0
jal _spu_t
sllv $a1, $v0, $a1
jal _spu_t
li $a0, 1
li $a0, 3
move $a1, $s1
jal _spu_t
move $a2, $s0
j loc_A94
move $v0, $s0
loc_A84:
move $a0, $s1
jal sub_480
move $a1, $s0
move $v0, $s0
loc_A94:
lw $ra, 0x20+var_8($sp)
lw $s1, 0x20+var_C($sp)
lw $s0, 0x20+var_10($sp)
jr $ra
addiu $sp, 0x20
# End of function _spu_Fw
#endif
}
unsigned long SpuWrite(unsigned char* addr, unsigned long size)
{
if (0x7EFF0 < size)
{
size = 0x7EFF0;
}
//loc_228
_spu_Fw(addr, size);
if (_spu_transferCallback == NULL)
{
_spu_inTransfer = 0;
}
return size;
}
long SpuSetTransferMode(long mode)
{
long mode_fix = mode == 0 ? 0 : 1;
//trans_mode = mode;
//transMode = mode_fix;
return mode_fix;
}
unsigned long SpuSetTransferStartAddr(unsigned long addr)
{
UNIMPLEMENTED();
return 0;
}
long SpuIsTransferCompleted(long flag)
{
UNIMPLEMENTED();
return 0;
}
void _SpuDataCallback(int a0)
{
UNIMPLEMENTED();
}
void SpuStart()//(F)
{
long event = 0;
if (_spu_isCalled == 0)
{
_spu_isCalled = 1;
EnterCriticalSection();
_SpuDataCallback(_spu_FiDMA);
event = OpenEvent(HwSPU, EvSpCOMP, EvMdNOINTR, NULL);
_spu_EVdma = event;
EnableEvent(event);
ExitCriticalSection();
}
//loc_348
}
void _spu_init(int a0)
{
UNIMPLEMENTED();
}
void _spu_FsetRXX(int a0, int a1, int a2)//(F)
{
if (a2 == 0)
{
_spu_RXX[a0] = a1;
}
else
{
_spu_RXX[a0] = a1 >> _spu_mem_mode_plus;
}
}
void _SpuInit(int a0)
{
ResetCallback();
_spu_init(a0);
if (a0 == 0)
{
for (int i = 0; i < sizeof(_spu_voice_centerNote) / sizeof(short); i++)
{
_spu_voice_centerNote[i] = SPU_CENTERNOTE;
}
}
//loc_240
SpuStart();
_spu_rev_flag = 0;
_spu_rev_reserve_wa = 0;
dword_424.mask = 0;
dword_424.mvol.left = 0;
dword_424.mvol.right = 0;
dword_424.mvolmode.left = 0;
dword_424.mvolmode.right = 0;
dword_424.mvolx.left = 0;
dword_424.mvolx.right = 0;
_spu_rev_offsetaddr = _spu_rev_startaddr;
_spu_FsetRXX(209, _spu_rev_startaddr, 0);
_spu_AllocBlockNum = 0;
_spu_AllocLastNum = 0;
_spu_memList = 0;
_spu_trans_mode = 0;
_spu_transMode = 0;
_spu_keystat = 0;
_spu_RQmask = 0;
_spu_RQvoice = 0;
_spu_env = 0;
}
void SpuInit(void)
{
_SpuInit(0);
}
long SpuSetReverb(long on_off)
{
UNIMPLEMENTED();
return 0;
}
unsigned long SpuSetReverbVoice(long on_off, unsigned long voice_bit)
{
UNIMPLEMENTED();
return 0;
}
void SpuSetCommonAttr(SpuCommonAttr* attr)
{
UNIMPLEMENTED();
}
long SpuInitMalloc(long num, char* top)//(F)
{
if (num > 0)
{
//loc_214
((int*)top)[0] = 0x40001010;
_spu_memList = (uintptr_t)top;
_spu_AllocLastNum = 0;
_spu_AllocBlockNum = num;
((int*)top)[1] = (0x10000000 << _spu_mem_mode_plus) - 0x1010;
}
return num;
}
long SpuMalloc(long size)
{
return 0/*(long)(uintptr_t)malloc(size)*/;
}
long SpuMallocWithStartAddr(unsigned long addr, long size)
{
UNIMPLEMENTED();
return 0;
}
void SpuFree(unsigned long addr)
{
/*free((void*)(uintptr_t)addr)*/;
}
void SpuSetCommonMasterVolume(short mvol_left, short mvol_right)// (F)
{
//MasterVolume.VolumeLeft.Raw = mvol_left;
//MasterVolume.VolumeRight.Raw = mvol_right;
}
long SpuSetReverbModeType(long mode)
{
UNIMPLEMENTED();
return 0;
}
void SpuSetReverbModeDepth(short depth_left, short depth_right)
{
UNIMPLEMENTED();
}