Normalized some source formatting.
parent
951b2e6c7c
commit
ab6f6ad568
|
@ -9,8 +9,7 @@
|
||||||
static const uint32_t AI_STATUS_BUSY = 0x40000000;
|
static const uint32_t AI_STATUS_BUSY = 0x40000000;
|
||||||
static const uint32_t AI_STATUS_FULL = 0x80000000;
|
static const uint32_t AI_STATUS_FULL = 0x80000000;
|
||||||
|
|
||||||
static uint32_t get_remaining_dma_length(usf_state_t *state)
|
static uint32_t get_remaining_dma_length(usf_state_t *state) {
|
||||||
{
|
|
||||||
unsigned int next_ai_event;
|
unsigned int next_ai_event;
|
||||||
unsigned int remaining_dma_duration;
|
unsigned int remaining_dma_duration;
|
||||||
|
|
||||||
|
@ -37,12 +36,12 @@ void AddBuffer(usf_state_t *state, unsigned char *buf, unsigned int length) {
|
||||||
return;
|
return;
|
||||||
|
|
||||||
do_max = length >> 2;
|
do_max = length >> 2;
|
||||||
|
|
||||||
if ( do_max > state->sample_buffer_count )
|
if ( do_max > state->sample_buffer_count )
|
||||||
do_max = (unsigned int) state->sample_buffer_count;
|
do_max = (unsigned int) state->sample_buffer_count;
|
||||||
|
|
||||||
if ( sample_buffer )
|
if ( sample_buffer )
|
||||||
for (i = 0; i < do_max; ++i)
|
for (i = 0; i < do_max; ++i) {
|
||||||
{
|
|
||||||
*sample_buffer++ = ((int16_t*)buf)[1];
|
*sample_buffer++ = ((int16_t*)buf)[1];
|
||||||
*sample_buffer++ = ((int16_t*)buf)[0];
|
*sample_buffer++ = ((int16_t*)buf)[0];
|
||||||
buf += 4;
|
buf += 4;
|
||||||
|
@ -55,12 +54,10 @@ void AddBuffer(usf_state_t *state, unsigned char *buf, unsigned int length) {
|
||||||
|
|
||||||
length -= do_max << 2;
|
length -= do_max << 2;
|
||||||
|
|
||||||
if ( length )
|
if ( length ) {
|
||||||
{
|
|
||||||
sample_buffer = state->samplebuf;
|
sample_buffer = state->samplebuf;
|
||||||
do_max = length >> 2;
|
do_max = length >> 2;
|
||||||
for (i = 0; i < do_max; ++i)
|
for (i = 0; i < do_max; ++i) {
|
||||||
{
|
|
||||||
*sample_buffer++ = ((int16_t*)buf)[1];
|
*sample_buffer++ = ((int16_t*)buf)[1];
|
||||||
*sample_buffer++ = ((int16_t*)buf)[0];
|
*sample_buffer++ = ((int16_t*)buf)[0];
|
||||||
buf += 4;
|
buf += 4;
|
||||||
|
@ -75,8 +72,7 @@ static unsigned int get_dma_duration(usf_state_t *state)
|
||||||
{
|
{
|
||||||
unsigned int samples_per_sec = state->ROM_PARAMS.aidacrate / (1 + AI_DACRATE_REG);
|
unsigned int samples_per_sec = state->ROM_PARAMS.aidacrate / (1 + AI_DACRATE_REG);
|
||||||
|
|
||||||
return (uint32_t)(((uint64_t)(AI_LEN_REG)*state->VI_INTR_TIME*state->ROM_PARAMS.vilimit)
|
return (uint32_t)(((uint64_t)(AI_LEN_REG)*state->VI_INTR_TIME*state->ROM_PARAMS.vilimit) / (4 * samples_per_sec));
|
||||||
/ (4 * samples_per_sec));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void do_dma(usf_state_t * state, const struct ai_dma * dma) {
|
void do_dma(usf_state_t * state, const struct ai_dma * dma) {
|
||||||
|
|
|
@ -474,15 +474,12 @@ void StartEmulationFromSave ( usf_state_t * state, void * savestate ) {
|
||||||
state->SampleRate = (state->ROM_PARAMS.aidacrate) / (AI_DACRATE_REG + 1);
|
state->SampleRate = (state->ROM_PARAMS.aidacrate) / (AI_DACRATE_REG + 1);
|
||||||
|
|
||||||
if(state->enableFIFOfull) {
|
if(state->enableFIFOfull) {
|
||||||
if (VI_V_SYNC_REG == 0)
|
if (VI_V_SYNC_REG == 0) {
|
||||||
{
|
|
||||||
state->VI_INTR_TIME = 500000;
|
state->VI_INTR_TIME = 500000;
|
||||||
}
|
}
|
||||||
else
|
else {
|
||||||
{
|
|
||||||
state->VI_INTR_TIME = (VI_V_SYNC_REG + 1) * 1500;
|
state->VI_INTR_TIME = (VI_V_SYNC_REG + 1) * 1500;
|
||||||
if ((VI_V_SYNC_REG & 1) != 0)
|
if ((VI_V_SYNC_REG & 1) != 0) {
|
||||||
{
|
|
||||||
state->VI_INTR_TIME -= 38;
|
state->VI_INTR_TIME -= 38;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -497,18 +494,14 @@ void StartEmulationFromSave ( usf_state_t * state, void * savestate ) {
|
||||||
|
|
||||||
|
|
||||||
void RefreshScreen (usf_state_t * state){
|
void RefreshScreen (usf_state_t * state){
|
||||||
if (state->OLD_VI_V_SYNC_REG != VI_V_SYNC_REG)
|
if (state->OLD_VI_V_SYNC_REG != VI_V_SYNC_REG) {
|
||||||
{
|
|
||||||
state->OLD_VI_V_SYNC_REG = VI_V_SYNC_REG;
|
state->OLD_VI_V_SYNC_REG = VI_V_SYNC_REG;
|
||||||
if (VI_V_SYNC_REG == 0)
|
if (VI_V_SYNC_REG == 0) {
|
||||||
{
|
|
||||||
state->VI_INTR_TIME = 500000;
|
state->VI_INTR_TIME = 500000;
|
||||||
}
|
}
|
||||||
else
|
else {
|
||||||
{
|
|
||||||
state->VI_INTR_TIME = (VI_V_SYNC_REG + 1) * 1500;
|
state->VI_INTR_TIME = (VI_V_SYNC_REG + 1) * 1500;
|
||||||
if ((VI_V_SYNC_REG & 1) != 0)
|
if ((VI_V_SYNC_REG & 1) != 0) {
|
||||||
{
|
|
||||||
state->VI_INTR_TIME -= 38;
|
state->VI_INTR_TIME -= 38;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -516,19 +509,15 @@ void RefreshScreen (usf_state_t * state){
|
||||||
|
|
||||||
ChangeTimer(state,ViTimer,state->Timers->Timer + state->Timers->NextTimer[ViTimer] + state->VI_INTR_TIME);
|
ChangeTimer(state,ViTimer,state->Timers->Timer + state->Timers->NextTimer[ViTimer] + state->VI_INTR_TIME);
|
||||||
|
|
||||||
if ((VI_STATUS_REG & 0x10) != 0)
|
if ((VI_STATUS_REG & 0x10) != 0) {
|
||||||
{
|
if (state->ViFieldNumber == 0) {
|
||||||
if (state->ViFieldNumber == 0)
|
|
||||||
{
|
|
||||||
state->ViFieldNumber = 1;
|
state->ViFieldNumber = 1;
|
||||||
}
|
}
|
||||||
else
|
else {
|
||||||
{
|
|
||||||
state->ViFieldNumber = 0;
|
state->ViFieldNumber = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else {
|
||||||
{
|
|
||||||
state->ViFieldNumber = 0;
|
state->ViFieldNumber = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -558,7 +547,6 @@ void RunRsp (usf_state_t * state) {
|
||||||
|
|
||||||
DPC_STATUS_REG &= ~0x0002;
|
DPC_STATUS_REG &= ~0x0002;
|
||||||
return;
|
return;
|
||||||
|
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 2: {
|
case 2: {
|
||||||
|
|
|
@ -781,7 +781,8 @@ void StartInterpreterCPU (usf_state_t * state) {
|
||||||
if (last_sample_buffer_count == state->sample_buffer_count) {
|
if (last_sample_buffer_count == state->sample_buffer_count) {
|
||||||
DisplayError( state, "Emulator core is not generating any samples after 20 million instructions" );
|
DisplayError( state, "Emulator core is not generating any samples after 20 million instructions" );
|
||||||
break;
|
break;
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
safety_count = safety_count_max;
|
safety_count = safety_count_max;
|
||||||
last_sample_buffer_count = state->sample_buffer_count;
|
last_sample_buffer_count = state->sample_buffer_count;
|
||||||
}
|
}
|
||||||
|
@ -789,7 +790,6 @@ void StartInterpreterCPU (usf_state_t * state) {
|
||||||
}
|
}
|
||||||
|
|
||||||
state->cpu_stopped = 1;
|
state->cpu_stopped = 1;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void TestInterpreterJump (usf_state_t * state, uint32_t PC, uint32_t TargetPC, int32_t Reg1, int32_t Reg2) {
|
void TestInterpreterJump (usf_state_t * state, uint32_t PC, uint32_t TargetPC, int32_t Reg1, int32_t Reg2) {
|
||||||
|
|
|
@ -206,8 +206,7 @@ uint32_t r4300i_LD_VAddr ( usf_state_t * state, uint32_t VAddr, uint64_t * Value
|
||||||
uintptr_t address;
|
uintptr_t address;
|
||||||
address = state->TLB_Map[VAddr >> 12];
|
address = state->TLB_Map[VAddr >> 12];
|
||||||
if (address == 0) { return 0; }
|
if (address == 0) { return 0; }
|
||||||
if (address + VAddr + 7 - (uintptr_t)state->N64MEM >= state->RdramSize)
|
if (address + VAddr + 7 - (uintptr_t)state->N64MEM >= state->RdramSize) {
|
||||||
{
|
|
||||||
*((uint32_t *)(Value) + 1) = 0;
|
*((uint32_t *)(Value) + 1) = 0;
|
||||||
*((uint32_t *)(Value)) = 0;
|
*((uint32_t *)(Value)) = 0;
|
||||||
return 1;
|
return 1;
|
||||||
|
@ -234,8 +233,7 @@ uint32_t r4300i_LH_VAddr ( usf_state_t * state, uint32_t VAddr, uint16_t * Value
|
||||||
address = state->TLB_Map[VAddr >> 12];
|
address = state->TLB_Map[VAddr >> 12];
|
||||||
if (address == 0)
|
if (address == 0)
|
||||||
return 0;
|
return 0;
|
||||||
if (address + (VAddr ^ 2) + 1 - (uintptr_t)state->N64MEM >= state->RdramSize)
|
if (address + (VAddr ^ 2) + 1 - (uintptr_t)state->N64MEM >= state->RdramSize) {
|
||||||
{
|
|
||||||
*Value = 0;
|
*Value = 0;
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
@ -476,8 +474,7 @@ uint32_t r4300i_SD_VAddr ( usf_state_t * state, uint32_t VAddr, uint64_t Value )
|
||||||
uintptr_t address;
|
uintptr_t address;
|
||||||
address = state->TLB_Map[VAddr >> 12];
|
address = state->TLB_Map[VAddr >> 12];
|
||||||
if (address == 0) { return 0; }
|
if (address == 0) { return 0; }
|
||||||
if (address + VAddr + 7 - (uintptr_t)state->N64MEM < state->RdramSize)
|
if (address + VAddr + 7 - (uintptr_t)state->N64MEM < state->RdramSize) {
|
||||||
{
|
|
||||||
*(uint32_t *)(address + VAddr) = *((uint32_t *)(&Value) + 1);
|
*(uint32_t *)(address + VAddr) = *((uint32_t *)(&Value) + 1);
|
||||||
*(uint32_t *)(address + VAddr + 4) = *((uint32_t *)(&Value));
|
*(uint32_t *)(address + VAddr + 4) = *((uint32_t *)(&Value));
|
||||||
}
|
}
|
||||||
|
@ -822,8 +819,7 @@ void memcpyn642n64(usf_state_t * state, uint32_t dest, uint32_t src, uint32_t le
|
||||||
uint32_t i;
|
uint32_t i;
|
||||||
uint32_t temp;
|
uint32_t temp;
|
||||||
|
|
||||||
for (i = 0; i < len; i += 4)
|
for (i = 0; i < len; i += 4) {
|
||||||
{
|
|
||||||
uintptr_t dstAddr = state->TLB_Map[(dest + i) >> 12];
|
uintptr_t dstAddr = state->TLB_Map[(dest + i) >> 12];
|
||||||
uintptr_t srcAddr = state->TLB_Map[(src + i) >> 12];
|
uintptr_t srcAddr = state->TLB_Map[(src + i) >> 12];
|
||||||
|
|
||||||
|
|
|
@ -16,8 +16,7 @@ enum { RESAMPLER_RESOLUTION = 1 << RESAMPLER_SHIFT };
|
||||||
|
|
||||||
enum { resampler_buffer_size = 64 * 4 };
|
enum { resampler_buffer_size = 64 * 4 };
|
||||||
|
|
||||||
typedef struct resampler
|
typedef struct resampler {
|
||||||
{
|
|
||||||
int write_pos, write_filled;
|
int write_pos, write_filled;
|
||||||
int read_pos, read_filled;
|
int read_pos, read_filled;
|
||||||
int phase;
|
int phase;
|
||||||
|
@ -28,8 +27,7 @@ typedef struct resampler
|
||||||
short buffer_out[resampler_buffer_size * 2];
|
short buffer_out[resampler_buffer_size * 2];
|
||||||
} resampler;
|
} resampler;
|
||||||
|
|
||||||
void * resampler_create(void)
|
void * resampler_create(void) {
|
||||||
{
|
|
||||||
resampler * r = ( resampler * ) malloc( sizeof(resampler) );
|
resampler * r = ( resampler * ) malloc( sizeof(resampler) );
|
||||||
if ( !r ) return 0;
|
if ( !r ) return 0;
|
||||||
|
|
||||||
|
@ -47,13 +45,11 @@ void * resampler_create(void)
|
||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
|
|
||||||
void resampler_delete(void * _r)
|
void resampler_delete(void * _r) {
|
||||||
{
|
|
||||||
free( _r );
|
free( _r );
|
||||||
}
|
}
|
||||||
|
|
||||||
void * resampler_dup(const void * _r)
|
void * resampler_dup(const void * _r) {
|
||||||
{
|
|
||||||
void * r_out = malloc( sizeof(resampler) );
|
void * r_out = malloc( sizeof(resampler) );
|
||||||
if ( !r_out ) return 0;
|
if ( !r_out ) return 0;
|
||||||
|
|
||||||
|
@ -62,8 +58,7 @@ void * resampler_dup(const void * _r)
|
||||||
return r_out;
|
return r_out;
|
||||||
}
|
}
|
||||||
|
|
||||||
void resampler_dup_inplace(void *_d, const void *_s)
|
void resampler_dup_inplace(void *_d, const void *_s) {
|
||||||
{
|
|
||||||
const resampler * r_in = ( const resampler * ) _s;
|
const resampler * r_in = ( const resampler * ) _s;
|
||||||
resampler * r_out = ( resampler * ) _d;
|
resampler * r_out = ( resampler * ) _d;
|
||||||
|
|
||||||
|
@ -79,35 +74,29 @@ void resampler_dup_inplace(void *_d, const void *_s)
|
||||||
memcpy( r_out->buffer_out, r_in->buffer_out, sizeof(r_in->buffer_out) );
|
memcpy( r_out->buffer_out, r_in->buffer_out, sizeof(r_in->buffer_out) );
|
||||||
}
|
}
|
||||||
|
|
||||||
int resampler_get_free_count(void *_r)
|
int resampler_get_free_count(void *_r) {
|
||||||
{
|
|
||||||
resampler * r = ( resampler * ) _r;
|
resampler * r = ( resampler * ) _r;
|
||||||
return resampler_buffer_size - r->write_filled;
|
return resampler_buffer_size - r->write_filled;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int resampler_min_filled(resampler *r)
|
static int resampler_min_filled(resampler *r) {
|
||||||
{
|
|
||||||
return 4;
|
return 4;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int resampler_input_delay(resampler *r)
|
static int resampler_input_delay(resampler *r) {
|
||||||
{
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int resampler_output_delay(resampler *r)
|
static int resampler_output_delay(resampler *r) {
|
||||||
{
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int resampler_ready(void *_r)
|
int resampler_ready(void *_r) {
|
||||||
{
|
|
||||||
resampler * r = ( resampler * ) _r;
|
resampler * r = ( resampler * ) _r;
|
||||||
return r->write_filled > resampler_min_filled(r);
|
return r->write_filled > resampler_min_filled(r);
|
||||||
}
|
}
|
||||||
|
|
||||||
void resampler_clear(void *_r)
|
void resampler_clear(void *_r) {
|
||||||
{
|
|
||||||
resampler * r = ( resampler * ) _r;
|
resampler * r = ( resampler * ) _r;
|
||||||
r->write_pos = 1;
|
r->write_pos = 1;
|
||||||
r->write_filled = 0;
|
r->write_filled = 0;
|
||||||
|
@ -118,24 +107,20 @@ void resampler_clear(void *_r)
|
||||||
r->delay_removed = -1;
|
r->delay_removed = -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
void resampler_set_rate(void *_r, double new_factor)
|
void resampler_set_rate(void *_r, double new_factor) {
|
||||||
{
|
|
||||||
resampler * r = ( resampler * ) _r;
|
resampler * r = ( resampler * ) _r;
|
||||||
r->phase_inc = new_factor * RESAMPLER_RESOLUTION;
|
r->phase_inc = new_factor * RESAMPLER_RESOLUTION;
|
||||||
}
|
}
|
||||||
|
|
||||||
void resampler_write_sample(void *_r, short ls, short rs)
|
void resampler_write_sample(void *_r, short ls, short rs) {
|
||||||
{
|
|
||||||
resampler * r = ( resampler * ) _r;
|
resampler * r = ( resampler * ) _r;
|
||||||
|
|
||||||
if ( r->delay_added < 0 )
|
if ( r->delay_added < 0 ) {
|
||||||
{
|
|
||||||
r->delay_added = 0;
|
r->delay_added = 0;
|
||||||
r->write_filled = resampler_input_delay( r );
|
r->write_filled = resampler_input_delay( r );
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( r->write_filled < resampler_buffer_size )
|
if ( r->write_filled < resampler_buffer_size ) {
|
||||||
{
|
|
||||||
r->buffer_in[ 0 ][ r->write_pos ] = ls;
|
r->buffer_in[ 0 ][ r->write_pos ] = ls;
|
||||||
r->buffer_in[ 0 ][ r->write_pos + resampler_buffer_size ] = ls;
|
r->buffer_in[ 0 ][ r->write_pos + resampler_buffer_size ] = ls;
|
||||||
|
|
||||||
|
@ -148,16 +133,14 @@ void resampler_write_sample(void *_r, short ls, short rs)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static int resampler_run_cubic(resampler * r, short ** out_, short * out_end)
|
static int resampler_run_cubic(resampler * r, short ** out_, short * out_end) {
|
||||||
{
|
|
||||||
int in_size = r->write_filled;
|
int in_size = r->write_filled;
|
||||||
int in_offset = resampler_buffer_size + r->write_pos - r->write_filled;
|
int in_offset = resampler_buffer_size + r->write_pos - r->write_filled;
|
||||||
short const* inl_ = r->buffer_in[0] + in_offset;
|
short const* inl_ = r->buffer_in[0] + in_offset;
|
||||||
short const* inr_ = r->buffer_in[1] + in_offset;
|
short const* inr_ = r->buffer_in[1] + in_offset;
|
||||||
int used = 0;
|
int used = 0;
|
||||||
in_size -= 4;
|
in_size -= 4;
|
||||||
if ( in_size > 0 )
|
if ( in_size > 0 ) {
|
||||||
{
|
|
||||||
short* out = *out_;
|
short* out = *out_;
|
||||||
short const* inl = inl_;
|
short const* inl = inl_;
|
||||||
short const* inr = inr_;
|
short const* inr = inr_;
|
||||||
|
@ -165,8 +148,7 @@ static int resampler_run_cubic(resampler * r, short ** out_, short * out_end)
|
||||||
int phase = r->phase;
|
int phase = r->phase;
|
||||||
int phase_inc = r->phase_inc;
|
int phase_inc = r->phase_inc;
|
||||||
|
|
||||||
do
|
do {
|
||||||
{
|
|
||||||
int samplel, sampler;
|
int samplel, sampler;
|
||||||
const int16_t* lut;
|
const int16_t* lut;
|
||||||
|
|
||||||
|
@ -206,12 +188,10 @@ static int resampler_run_cubic(resampler * r, short ** out_, short * out_end)
|
||||||
return used;
|
return used;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void resampler_fill(resampler * r)
|
static void resampler_fill(resampler * r) {
|
||||||
{
|
|
||||||
int min_filled = resampler_min_filled(r);
|
int min_filled = resampler_min_filled(r);
|
||||||
while ( r->write_filled > min_filled &&
|
while ( r->write_filled > min_filled &&
|
||||||
r->read_filled < resampler_buffer_size )
|
r->read_filled < resampler_buffer_size ) {
|
||||||
{
|
|
||||||
int write_pos = ( r->read_pos + r->read_filled ) % resampler_buffer_size;
|
int write_pos = ( r->read_pos + r->read_filled ) % resampler_buffer_size;
|
||||||
int write_size = resampler_buffer_size - write_pos;
|
int write_size = resampler_buffer_size - write_pos;
|
||||||
short * out = r->buffer_out + write_pos * 2;
|
short * out = r->buffer_out + write_pos * 2;
|
||||||
|
@ -222,11 +202,9 @@ static void resampler_fill(resampler * r)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void resampler_fill_and_remove_delay(resampler * r)
|
static void resampler_fill_and_remove_delay(resampler * r) {
|
||||||
{
|
|
||||||
resampler_fill( r );
|
resampler_fill( r );
|
||||||
if ( r->delay_removed < 0 )
|
if ( r->delay_removed < 0 ) {
|
||||||
{
|
|
||||||
int delay = resampler_output_delay( r );
|
int delay = resampler_output_delay( r );
|
||||||
r->delay_removed = 0;
|
r->delay_removed = 0;
|
||||||
while ( delay-- )
|
while ( delay-- )
|
||||||
|
@ -234,37 +212,32 @@ static void resampler_fill_and_remove_delay(resampler * r)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int resampler_get_sample_count(void *_r)
|
int resampler_get_sample_count(void *_r) {
|
||||||
{
|
|
||||||
resampler * r = ( resampler * ) _r;
|
resampler * r = ( resampler * ) _r;
|
||||||
if ( r->read_filled < 1 )
|
if ( r->read_filled < 1 )
|
||||||
resampler_fill_and_remove_delay( r );
|
resampler_fill_and_remove_delay( r );
|
||||||
return r->read_filled;
|
return r->read_filled;
|
||||||
}
|
}
|
||||||
|
|
||||||
void resampler_get_sample(void *_r, short * ls, short * rs)
|
void resampler_get_sample(void *_r, short * ls, short * rs) {
|
||||||
{
|
|
||||||
resampler * r = ( resampler * ) _r;
|
resampler * r = ( resampler * ) _r;
|
||||||
if ( r->read_filled < 1 && r->phase_inc )
|
if ( r->read_filled < 1 && r->phase_inc )
|
||||||
resampler_fill_and_remove_delay( r );
|
resampler_fill_and_remove_delay( r );
|
||||||
if ( r->read_filled < 1 )
|
if ( r->read_filled < 1 ) {
|
||||||
{
|
|
||||||
*ls = 0;
|
*ls = 0;
|
||||||
*rs = 0;
|
*rs = 0;
|
||||||
}
|
}
|
||||||
else
|
else {
|
||||||
{
|
|
||||||
*ls = r->buffer_out[ r->read_pos * 2 + 0 ];
|
*ls = r->buffer_out[ r->read_pos * 2 + 0 ];
|
||||||
*rs = r->buffer_out[ r->read_pos * 2 + 1 ];
|
*rs = r->buffer_out[ r->read_pos * 2 + 1 ];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void resampler_remove_sample(void *_r)
|
void resampler_remove_sample(void *_r) {
|
||||||
{
|
|
||||||
resampler * r = ( resampler * ) _r;
|
resampler * r = ( resampler * ) _r;
|
||||||
if ( r->read_filled > 0 )
|
if ( r->read_filled > 0 ) {
|
||||||
{
|
|
||||||
--r->read_filled;
|
--r->read_filled;
|
||||||
r->read_pos = ( r->read_pos + 1 ) % resampler_buffer_size;
|
r->read_pos = ( r->read_pos + 1 ) % resampler_buffer_size;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -16,13 +16,11 @@
|
||||||
|
|
||||||
#include "usf_internal.h"
|
#include "usf_internal.h"
|
||||||
|
|
||||||
size_t usf_get_state_size()
|
size_t usf_get_state_size() {
|
||||||
{
|
|
||||||
return sizeof(usf_state_t) + 8192;
|
return sizeof(usf_state_t) + 8192;
|
||||||
}
|
}
|
||||||
|
|
||||||
void usf_clear(void * state)
|
void usf_clear(void * state) {
|
||||||
{
|
|
||||||
size_t offset;
|
size_t offset;
|
||||||
memset(state, 0, usf_get_state_size());
|
memset(state, 0, usf_get_state_size());
|
||||||
offset = 4096 - (((uintptr_t)state) & 4095);
|
offset = 4096 - (((uintptr_t)state) & 4095);
|
||||||
|
@ -80,29 +78,24 @@ void usf_clear(void * state)
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
void usf_set_compare(void * state, int enable)
|
void usf_set_compare(void * state, int enable) {
|
||||||
{
|
|
||||||
USF_STATE->enablecompare = enable;
|
USF_STATE->enablecompare = enable;
|
||||||
}
|
}
|
||||||
|
|
||||||
void usf_set_fifo_full(void * state, int enable)
|
void usf_set_fifo_full(void * state, int enable) {
|
||||||
{
|
|
||||||
USF_STATE->enableFIFOfull = enable;
|
USF_STATE->enableFIFOfull = enable;
|
||||||
}
|
}
|
||||||
|
|
||||||
void usf_set_hle_audio(void * state, int enable)
|
void usf_set_hle_audio(void * state, int enable) {
|
||||||
{
|
|
||||||
USF_STATE->enable_hle_audio = enable;
|
USF_STATE->enable_hle_audio = enable;
|
||||||
}
|
}
|
||||||
|
|
||||||
static uint32_t get_le32( const void * _p )
|
static uint32_t get_le32( const void * _p ) {
|
||||||
{
|
|
||||||
const uint8_t * p = (const uint8_t *) _p;
|
const uint8_t * p = (const uint8_t *) _p;
|
||||||
return p[0] + p[1] * 0x100 + p[2] * 0x10000 + p[3] * 0x1000000;
|
return p[0] + p[1] * 0x100 + p[2] * 0x10000 + p[3] * 0x1000000;
|
||||||
}
|
}
|
||||||
|
|
||||||
int usf_upload_section(void * state, const uint8_t * data, size_t size)
|
int usf_upload_section(void * state, const uint8_t * data, size_t size) {
|
||||||
{
|
|
||||||
uint32_t temp;
|
uint32_t temp;
|
||||||
|
|
||||||
if ( size < 4 ) return -1;
|
if ( size < 4 ) return -1;
|
||||||
|
@ -170,8 +163,7 @@ int usf_upload_section(void * state, const uint8_t * data, size_t size)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int is_valid_rom(const unsigned char *buffer)
|
static int is_valid_rom(const unsigned char *buffer) {
|
||||||
{
|
|
||||||
/* Test if rom is a native .z64 image with header 0x80371240. [ABCD] */
|
/* Test if rom is a native .z64 image with header 0x80371240. [ABCD] */
|
||||||
if((buffer[0]==0x80)&&(buffer[1]==0x37)&&(buffer[2]==0x12)&&(buffer[3]==0x40))
|
if((buffer[0]==0x80)&&(buffer[1]==0x37)&&(buffer[2]==0x12)&&(buffer[3]==0x40))
|
||||||
return 1;
|
return 1;
|
||||||
|
@ -185,26 +177,21 @@ static int is_valid_rom(const unsigned char *buffer)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void swap_rom(const unsigned char* signature, unsigned char* localrom, int loadlength)
|
static void swap_rom(const unsigned char* signature, unsigned char* localrom, int loadlength) {
|
||||||
{
|
|
||||||
unsigned char temp;
|
unsigned char temp;
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
/* Btyeswap if .v64 image. */
|
/* Btyeswap if .v64 image. */
|
||||||
if(signature[0]==0x37)
|
if(signature[0]==0x37) {
|
||||||
{
|
for (i = 0; i < loadlength; i+=2) {
|
||||||
for (i = 0; i < loadlength; i+=2)
|
|
||||||
{
|
|
||||||
temp=localrom[i];
|
temp=localrom[i];
|
||||||
localrom[i]=localrom[i+1];
|
localrom[i]=localrom[i+1];
|
||||||
localrom[i+1]=temp;
|
localrom[i+1]=temp;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/* Wordswap if .n64 image. */
|
/* Wordswap if .n64 image. */
|
||||||
else if(signature[0]==0x40)
|
else if(signature[0]==0x40) {
|
||||||
{
|
for (i = 0; i < loadlength; i+=4) {
|
||||||
for (i = 0; i < loadlength; i+=4)
|
|
||||||
{
|
|
||||||
temp=localrom[i];
|
temp=localrom[i];
|
||||||
localrom[i]=localrom[i+3];
|
localrom[i]=localrom[i+3];
|
||||||
localrom[i+3]=temp;
|
localrom[i+3]=temp;
|
||||||
|
@ -215,10 +202,8 @@ static void swap_rom(const unsigned char* signature, unsigned char* localrom, in
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static _system_type rom_country_code_to_system_type(unsigned short country_code)
|
static _system_type rom_country_code_to_system_type(unsigned short country_code) {
|
||||||
{
|
switch (country_code & 0xFF) {
|
||||||
switch (country_code & 0xFF)
|
|
||||||
{
|
|
||||||
// PAL codes
|
// PAL codes
|
||||||
case 0x44:
|
case 0x44:
|
||||||
case 0x46:
|
case 0x46:
|
||||||
|
@ -241,10 +226,8 @@ static _system_type rom_country_code_to_system_type(unsigned short country_code)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get the VI (vertical interrupt) limit associated to a ROM system type.
|
// Get the VI (vertical interrupt) limit associated to a ROM system type.
|
||||||
static int rom_system_type_to_vi_limit(_system_type system_type)
|
static int rom_system_type_to_vi_limit(_system_type system_type) {
|
||||||
{
|
switch (system_type) {
|
||||||
switch (system_type)
|
|
||||||
{
|
|
||||||
case SYSTEM_PAL:
|
case SYSTEM_PAL:
|
||||||
case SYSTEM_MPAL:
|
case SYSTEM_MPAL:
|
||||||
return 50;
|
return 50;
|
||||||
|
@ -255,10 +238,8 @@ static int rom_system_type_to_vi_limit(_system_type system_type)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static int rom_system_type_to_ai_dac_rate(_system_type system_type)
|
static int rom_system_type_to_ai_dac_rate(_system_type system_type) {
|
||||||
{
|
switch (system_type) {
|
||||||
switch (system_type)
|
|
||||||
{
|
|
||||||
case SYSTEM_PAL:
|
case SYSTEM_PAL:
|
||||||
return 49656530;
|
return 49656530;
|
||||||
case SYSTEM_MPAL:
|
case SYSTEM_MPAL:
|
||||||
|
@ -269,8 +250,7 @@ static int rom_system_type_to_ai_dac_rate(_system_type system_type)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void open_rom_header(usf_state_t * state, unsigned char * header, int header_size)
|
void open_rom_header(usf_state_t * state, unsigned char * header, int header_size) {
|
||||||
{
|
|
||||||
if (header_size >= sizeof(_rom_header))
|
if (header_size >= sizeof(_rom_header))
|
||||||
memcpy(&state->ROM_HEADER, header, sizeof(_rom_header));
|
memcpy(&state->ROM_HEADER, header, sizeof(_rom_header));
|
||||||
|
|
||||||
|
@ -284,8 +264,7 @@ void open_rom_header(usf_state_t * state, unsigned char * header, int header_siz
|
||||||
state->ROM_PARAMS.countperop = COUNT_PER_OP_DEFAULT;
|
state->ROM_PARAMS.countperop = COUNT_PER_OP_DEFAULT;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int usf_startup(usf_state_t * state)
|
static int usf_startup(usf_state_t * state) {
|
||||||
{
|
|
||||||
// Detect region
|
// Detect region
|
||||||
|
|
||||||
open_rom_header(state, state->savestatespace + 8, sizeof(_rom_header));
|
open_rom_header(state, state->savestatespace + 8, sizeof(_rom_header));
|
||||||
|
@ -309,19 +288,16 @@ static int usf_startup(usf_state_t * state)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
const char * usf_render(void * state, int16_t * buffer, size_t count, int32_t * sample_rate)
|
const char * usf_render(void * state, int16_t * buffer, size_t count, int32_t * sample_rate) {
|
||||||
{
|
|
||||||
USF_STATE->last_error = 0;
|
USF_STATE->last_error = 0;
|
||||||
USF_STATE->error_message[0] = '\0';
|
USF_STATE->error_message[0] = '\0';
|
||||||
|
|
||||||
if ( !USF_STATE->MemoryState )
|
if ( !USF_STATE->MemoryState ) {
|
||||||
{
|
|
||||||
if ( usf_startup( USF_STATE ) < 0 )
|
if ( usf_startup( USF_STATE ) < 0 )
|
||||||
return USF_STATE->last_error;
|
return USF_STATE->last_error;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( USF_STATE->samples_in_buffer )
|
if ( USF_STATE->samples_in_buffer ) {
|
||||||
{
|
|
||||||
size_t do_max = USF_STATE->samples_in_buffer;
|
size_t do_max = USF_STATE->samples_in_buffer;
|
||||||
if ( do_max > count )
|
if ( do_max > count )
|
||||||
do_max = count;
|
do_max = count;
|
||||||
|
@ -334,8 +310,7 @@ const char * usf_render(void * state, int16_t * buffer, size_t count, int32_t *
|
||||||
if ( sample_rate )
|
if ( sample_rate )
|
||||||
*sample_rate = USF_STATE->SampleRate;
|
*sample_rate = USF_STATE->SampleRate;
|
||||||
|
|
||||||
if ( USF_STATE->samples_in_buffer )
|
if ( USF_STATE->samples_in_buffer ) {
|
||||||
{
|
|
||||||
memmove( USF_STATE->samplebuf, USF_STATE->samplebuf + do_max * 2, sizeof(int16_t) * 2 * USF_STATE->samples_in_buffer );
|
memmove( USF_STATE->samplebuf, USF_STATE->samplebuf + do_max * 2, sizeof(int16_t) * 2 * USF_STATE->samples_in_buffer );
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -359,14 +334,11 @@ const char * usf_render(void * state, int16_t * buffer, size_t count, int32_t *
|
||||||
return USF_STATE->last_error;
|
return USF_STATE->last_error;
|
||||||
}
|
}
|
||||||
|
|
||||||
const char * usf_render_resampled(void * state, int16_t * buffer, size_t count, int32_t sample_rate)
|
const char * usf_render_resampled(void * state, int16_t * buffer, size_t count, int32_t sample_rate) {
|
||||||
{
|
if ( !buffer ) {
|
||||||
if ( !buffer )
|
|
||||||
{
|
|
||||||
unsigned long samples_buffered = resampler_get_sample_count( USF_STATE->resampler );
|
unsigned long samples_buffered = resampler_get_sample_count( USF_STATE->resampler );
|
||||||
resampler_clear(USF_STATE->resampler);
|
resampler_clear(USF_STATE->resampler);
|
||||||
if (samples_buffered)
|
if (samples_buffered) {
|
||||||
{
|
|
||||||
unsigned long samples_to_remove = samples_buffered;
|
unsigned long samples_to_remove = samples_buffered;
|
||||||
if (samples_to_remove > count)
|
if (samples_to_remove > count)
|
||||||
samples_to_remove = count;
|
samples_to_remove = count;
|
||||||
|
@ -377,41 +349,34 @@ const char * usf_render_resampled(void * state, int16_t * buffer, size_t count,
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
count = (size_t)((uint64_t)count * USF_STATE->SampleRate / sample_rate);
|
count = (size_t)((uint64_t)count * USF_STATE->SampleRate / sample_rate);
|
||||||
if (count > USF_STATE->samples_in_buffer_2)
|
if (count > USF_STATE->samples_in_buffer_2) {
|
||||||
{
|
|
||||||
count -= USF_STATE->samples_in_buffer_2;
|
count -= USF_STATE->samples_in_buffer_2;
|
||||||
USF_STATE->samples_in_buffer_2 = 0;
|
USF_STATE->samples_in_buffer_2 = 0;
|
||||||
}
|
}
|
||||||
else if (count)
|
else if (count) {
|
||||||
{
|
|
||||||
USF_STATE->samples_in_buffer_2 -= count;
|
USF_STATE->samples_in_buffer_2 -= count;
|
||||||
memmove(USF_STATE->samplebuf2, USF_STATE->samplebuf2 + 8192 - USF_STATE->samples_in_buffer_2 * 2, USF_STATE->samples_in_buffer_2 * sizeof(short) * 2);
|
memmove(USF_STATE->samplebuf2, USF_STATE->samplebuf2 + 8192 - USF_STATE->samples_in_buffer_2 * 2, USF_STATE->samples_in_buffer_2 * sizeof(short) * 2);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
return usf_render(state, buffer, count, NULL);
|
return usf_render(state, buffer, count, NULL);
|
||||||
}
|
}
|
||||||
while ( count )
|
while ( count ) {
|
||||||
{
|
|
||||||
const char * err;
|
const char * err;
|
||||||
|
|
||||||
while ( USF_STATE->samples_in_buffer_2 && resampler_get_free_count(USF_STATE->resampler) )
|
while ( USF_STATE->samples_in_buffer_2 && resampler_get_free_count(USF_STATE->resampler) ) {
|
||||||
{
|
|
||||||
int i = 0, j = resampler_get_free_count(USF_STATE->resampler);
|
int i = 0, j = resampler_get_free_count(USF_STATE->resampler);
|
||||||
if (j > USF_STATE->samples_in_buffer_2)
|
if (j > USF_STATE->samples_in_buffer_2)
|
||||||
j = (int)USF_STATE->samples_in_buffer_2;
|
j = (int)USF_STATE->samples_in_buffer_2;
|
||||||
for (i = 0; i < j; ++i)
|
for (i = 0; i < j; ++i) {
|
||||||
{
|
|
||||||
resampler_write_sample(USF_STATE->resampler, USF_STATE->samplebuf2[i*2], USF_STATE->samplebuf2[i*2+1]);
|
resampler_write_sample(USF_STATE->resampler, USF_STATE->samplebuf2[i*2], USF_STATE->samplebuf2[i*2+1]);
|
||||||
}
|
}
|
||||||
if (i)
|
if (i) {
|
||||||
{
|
|
||||||
memmove(USF_STATE->samplebuf2, USF_STATE->samplebuf2 + i * 2, (USF_STATE->samples_in_buffer_2 - i) * sizeof(short) * 2);
|
memmove(USF_STATE->samplebuf2, USF_STATE->samplebuf2 + i * 2, (USF_STATE->samples_in_buffer_2 - i) * sizeof(short) * 2);
|
||||||
USF_STATE->samples_in_buffer_2 -= i;
|
USF_STATE->samples_in_buffer_2 -= i;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
while ( count && resampler_get_sample_count(USF_STATE->resampler) )
|
while ( count && resampler_get_sample_count(USF_STATE->resampler) ) {
|
||||||
{
|
|
||||||
resampler_get_sample(USF_STATE->resampler, buffer, buffer + 1);
|
resampler_get_sample(USF_STATE->resampler, buffer, buffer + 1);
|
||||||
resampler_remove_sample(USF_STATE->resampler);
|
resampler_remove_sample(USF_STATE->resampler);
|
||||||
buffer += 2;
|
buffer += 2;
|
||||||
|
@ -436,8 +401,7 @@ const char * usf_render_resampled(void * state, int16_t * buffer, size_t count,
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void usf_restart(void * state)
|
void usf_restart(void * state) {
|
||||||
{
|
|
||||||
if ( USF_STATE->MemoryState )
|
if ( USF_STATE->MemoryState )
|
||||||
StartEmulationFromSave(USF_STATE, USF_STATE->savestatespace);
|
StartEmulationFromSave(USF_STATE, USF_STATE->savestatespace);
|
||||||
|
|
||||||
|
@ -447,11 +411,11 @@ void usf_restart(void * state)
|
||||||
resampler_clear(USF_STATE->resampler);
|
resampler_clear(USF_STATE->resampler);
|
||||||
}
|
}
|
||||||
|
|
||||||
void usf_shutdown(void * state)
|
void usf_shutdown(void * state) {
|
||||||
{
|
|
||||||
Release_Memory(USF_STATE);
|
Release_Memory(USF_STATE);
|
||||||
resampler_delete(USF_STATE->resampler);
|
resampler_delete(USF_STATE->resampler);
|
||||||
#ifdef DEBUG_INFO
|
#ifdef DEBUG_INFO
|
||||||
fclose(USF_STATE->debug_log);
|
fclose(USF_STATE->debug_log);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -6,44 +6,13 @@
|
||||||
#include "rsp_hle/hle.h"
|
#include "rsp_hle/hle.h"
|
||||||
#include "cpu_hle.h"
|
#include "cpu_hle.h"
|
||||||
|
|
||||||
/* Supported rom image types. */
|
typedef enum {
|
||||||
enum
|
|
||||||
{
|
|
||||||
Z64IMAGE,
|
|
||||||
V64IMAGE,
|
|
||||||
N64IMAGE
|
|
||||||
};
|
|
||||||
|
|
||||||
/* Supported CIC chips. */
|
|
||||||
enum
|
|
||||||
{
|
|
||||||
CIC_NUS_6101,
|
|
||||||
CIC_NUS_6102,
|
|
||||||
CIC_NUS_6103,
|
|
||||||
CIC_NUS_6105,
|
|
||||||
CIC_NUS_6106
|
|
||||||
};
|
|
||||||
|
|
||||||
/* Supported save types. */
|
|
||||||
enum
|
|
||||||
{
|
|
||||||
EEPROM_4KB,
|
|
||||||
EEPROM_16KB,
|
|
||||||
SRAM,
|
|
||||||
FLASH_RAM,
|
|
||||||
CONTROLLER_PACK,
|
|
||||||
NONE
|
|
||||||
};
|
|
||||||
|
|
||||||
typedef enum
|
|
||||||
{
|
|
||||||
SYSTEM_NTSC = 0,
|
SYSTEM_NTSC = 0,
|
||||||
SYSTEM_PAL,
|
SYSTEM_PAL,
|
||||||
SYSTEM_MPAL
|
SYSTEM_MPAL
|
||||||
} _system_type;
|
} _system_type;
|
||||||
|
|
||||||
typedef struct
|
typedef struct {
|
||||||
{
|
|
||||||
unsigned char init_PI_BSB_DOM1_LAT_REG; /* 0x00 */
|
unsigned char init_PI_BSB_DOM1_LAT_REG; /* 0x00 */
|
||||||
unsigned char init_PI_BSB_DOM1_PGS_REG; /* 0x01 */
|
unsigned char init_PI_BSB_DOM1_PGS_REG; /* 0x01 */
|
||||||
unsigned char init_PI_BSB_DOM1_PWD_REG; /* 0x02 */
|
unsigned char init_PI_BSB_DOM1_PWD_REG; /* 0x02 */
|
||||||
|
@ -61,8 +30,7 @@ typedef struct
|
||||||
unsigned short Country_code; /* 0x3E */
|
unsigned short Country_code; /* 0x3E */
|
||||||
} _rom_header;
|
} _rom_header;
|
||||||
|
|
||||||
typedef struct _rom_params
|
typedef struct _rom_params {
|
||||||
{
|
|
||||||
_system_type systemtype;
|
_system_type systemtype;
|
||||||
int vilimit;
|
int vilimit;
|
||||||
int aidacrate;
|
int aidacrate;
|
||||||
|
@ -70,8 +38,7 @@ typedef struct _rom_params
|
||||||
unsigned char countperop;
|
unsigned char countperop;
|
||||||
} rom_params;
|
} rom_params;
|
||||||
|
|
||||||
struct usf_state_helper
|
struct usf_state_helper {
|
||||||
{
|
|
||||||
size_t offset_to_structure;
|
size_t offset_to_structure;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -84,8 +51,7 @@ typedef uint32_t RCPREG;
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
struct usf_state
|
struct usf_state {
|
||||||
{
|
|
||||||
// RSP vector registers, need to be aligned to 16 bytes
|
// RSP vector registers, need to be aligned to 16 bytes
|
||||||
// when SSE2 or SSSE3 is enabled, or for any hope of
|
// when SSE2 or SSSE3 is enabled, or for any hope of
|
||||||
// auto vectorization
|
// auto vectorization
|
||||||
|
@ -232,3 +198,4 @@ struct usf_state
|
||||||
#define USF_STATE ((usf_state_t *)(((uint8_t *)(state))+((usf_state_helper_t *)(state))->offset_to_structure))
|
#define USF_STATE ((usf_state_t *)(((uint8_t *)(state))+((usf_state_helper_t *)(state))->offset_to_structure))
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue