From 5bf11d551e4be1c74433363f4701580a3c3626d8 Mon Sep 17 00:00:00 2001 From: Chris Moeller Date: Tue, 18 Feb 2014 00:05:23 -0800 Subject: [PATCH] Updated to latest LazyUSF --- Frameworks/lazyusf/lazyusf/audio.c | 17 ++++++++++------- Frameworks/lazyusf/lazyusf/interpreter_cpu.c | 1 + Frameworks/lazyusf/lazyusf/interpreter_ops.c | 2 ++ Frameworks/lazyusf/lazyusf/main.c | 1 + Frameworks/lazyusf/lazyusf/memory.c | 4 +++- Frameworks/lazyusf/lazyusf/pif.c | 2 ++ Frameworks/lazyusf/lazyusf/rsp/rsp.c | 2 ++ Frameworks/lazyusf/lazyusf/rsp/rsp.h | 3 +++ Frameworks/lazyusf/lazyusf/rsp/su.h | 19 +++++++++++++++++-- Frameworks/lazyusf/lazyusf/rsp/vu/vmacq.h | 1 + Frameworks/lazyusf/lazyusf/rsp/vu/vnop.h | 2 ++ Frameworks/lazyusf/lazyusf/usf.c | 14 +++++++++++--- Frameworks/lazyusf/lazyusf/usf.h | 2 ++ Frameworks/lazyusf/lazyusf/usf_internal.h | 18 +++++++++++++++--- 14 files changed, 72 insertions(+), 16 deletions(-) diff --git a/Frameworks/lazyusf/lazyusf/audio.c b/Frameworks/lazyusf/lazyusf/audio.c index 6f2164edb..1ce16813d 100644 --- a/Frameworks/lazyusf/lazyusf/audio.c +++ b/Frameworks/lazyusf/lazyusf/audio.c @@ -16,13 +16,16 @@ void AddBuffer(usf_state_t *state, unsigned char *buf, unsigned int length) { do_max = length >> 2; if ( do_max > state->sample_buffer_count ) do_max = (unsigned int) state->sample_buffer_count; - - for (i = 0; i < do_max; ++i) - { - *sample_buffer++ = ((int16_t*)buf)[1]; - *sample_buffer++ = ((int16_t*)buf)[0]; - buf += 4; - } + + if ( sample_buffer ) + for (i = 0; i < do_max; ++i) + { + *sample_buffer++ = ((int16_t*)buf)[1]; + *sample_buffer++ = ((int16_t*)buf)[0]; + buf += 4; + } + else + buf += 4 * do_max; state->sample_buffer_count -= do_max; state->sample_buffer = sample_buffer; diff --git a/Frameworks/lazyusf/lazyusf/interpreter_cpu.c b/Frameworks/lazyusf/lazyusf/interpreter_cpu.c index c0ad8f28d..4e103b56d 100644 --- a/Frameworks/lazyusf/lazyusf/interpreter_cpu.c +++ b/Frameworks/lazyusf/lazyusf/interpreter_cpu.c @@ -89,6 +89,7 @@ void R4300i_opcode_COP1_L (usf_state_t * state) { void BuildInterpreter (usf_state_t * state) { + (void)state; R4300i_Opcode[ 0] = R4300i_opcode_SPECIAL; R4300i_Opcode[ 1] = R4300i_opcode_REGIMM; R4300i_Opcode[ 2] = r4300i_J; diff --git a/Frameworks/lazyusf/lazyusf/interpreter_ops.c b/Frameworks/lazyusf/lazyusf/interpreter_ops.c index 8effbb762..452645a82 100644 --- a/Frameworks/lazyusf/lazyusf/interpreter_ops.c +++ b/Frameworks/lazyusf/lazyusf/interpreter_ops.c @@ -482,6 +482,7 @@ void r4300i_SWR (usf_state_t * state) { } void r4300i_CACHE (usf_state_t * state) { + (void)state; } void r4300i_LL (usf_state_t * state) { @@ -618,6 +619,7 @@ void r4300i_SPECIAL_BREAK (usf_state_t * state) { } void r4300i_SPECIAL_SYNC (usf_state_t * state) { + (void)state; } void r4300i_SPECIAL_MFHI (usf_state_t * state) { diff --git a/Frameworks/lazyusf/lazyusf/main.c b/Frameworks/lazyusf/lazyusf/main.c index 222a71b3a..33ecf9e60 100644 --- a/Frameworks/lazyusf/lazyusf/main.c +++ b/Frameworks/lazyusf/lazyusf/main.c @@ -19,6 +19,7 @@ void StopEmulation(usf_state_t * state) } void DisplayError (char * Message, ...) { + (void)Message; //char Msg[1000]; //va_list ap; diff --git a/Frameworks/lazyusf/lazyusf/memory.c b/Frameworks/lazyusf/lazyusf/memory.c index 0c41338ab..b24464542 100644 --- a/Frameworks/lazyusf/lazyusf/memory.c +++ b/Frameworks/lazyusf/lazyusf/memory.c @@ -63,7 +63,7 @@ void large_free(void * p, size_t size) void * large_alloc(size_t size) { - return mmap(NULL, size, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, 0, 0); + return mmap(NULL, size, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0); } void large_free(void * p, size_t size) @@ -204,6 +204,8 @@ uint32_t r4300i_LD_VAddr ( usf_state_t * state, uint32_t VAddr, uint64_t * Value } int32_t r4300i_LH_NonMemory ( usf_state_t * state, uint32_t PAddr, uint32_t * Value, int32_t SignExtend ) { + (void)state; + (void)SignExtend; switch (PAddr & 0xFFF00000) { default: * Value = 0; diff --git a/Frameworks/lazyusf/lazyusf/pif.c b/Frameworks/lazyusf/lazyusf/pif.c index c8e6dfce3..6f60210f3 100644 --- a/Frameworks/lazyusf/lazyusf/pif.c +++ b/Frameworks/lazyusf/lazyusf/pif.c @@ -93,5 +93,7 @@ void PifRamWrite (usf_state_t * state) { // always return failure void ProcessControllerCommand ( usf_state_t * state, int32_t Control, uint8_t * Command) { + (void)state; + (void)Control; Command[1] |= 0x80; } diff --git a/Frameworks/lazyusf/lazyusf/rsp/rsp.c b/Frameworks/lazyusf/lazyusf/rsp/rsp.c index 4e68de4a9..2aec78eeb 100644 --- a/Frameworks/lazyusf/lazyusf/rsp/rsp.c +++ b/Frameworks/lazyusf/lazyusf/rsp/rsp.c @@ -34,6 +34,8 @@ void real_run_rsp(usf_state_t * state, uint32_t cycles) { + (void)cycles; + if (SP_STATUS_REG & 0x00000003) { message("SP_STATUS_HALT", 3); diff --git a/Frameworks/lazyusf/lazyusf/rsp/rsp.h b/Frameworks/lazyusf/lazyusf/rsp/rsp.h index 61ae902fb..fc9041f28 100644 --- a/Frameworks/lazyusf/lazyusf/rsp/rsp.h +++ b/Frameworks/lazyusf/lazyusf/rsp/rsp.h @@ -44,6 +44,8 @@ typedef uint32_t RCPREG; NOINLINE void message(const char* body, int priority) { + (void)body; + (void)priority; } /* @@ -53,6 +55,7 @@ NOINLINE void message(const char* body, int priority) /* typical standard DOS text file limit per line */ NOINLINE void update_conf(const char* source) { + (void)source; } #include "su.h" diff --git a/Frameworks/lazyusf/lazyusf/rsp/su.h b/Frameworks/lazyusf/lazyusf/rsp/su.h index 2a0a810c1..48e79786a 100644 --- a/Frameworks/lazyusf/lazyusf/rsp/su.h +++ b/Frameworks/lazyusf/lazyusf/rsp/su.h @@ -32,6 +32,7 @@ NOINLINE static void res_S(usf_state_t * state) { + (void)state; return; } @@ -219,6 +220,8 @@ static void MT_CMD_CLOCK(usf_state_t * state, int rt) } static void MT_READ_ONLY(usf_state_t * state, int rt) { + (void)state; + (void)rt; //char text[64]; //sprintf(text, "MTC0\nInvalid write attempt.\nstate->SR[%i] = 0x%08X", rt, state->SR[rt]); @@ -1088,7 +1091,13 @@ static void LHV(usf_state_t * state, int vt, int element, int offset, int base) return; } NOINLINE static void LFV(usf_state_t * state, int vt, int element, int offset, int base) -{ /* Dummy implementation only: Do any games execute this? */ +{ + (void)state; + (void)vt; + (void)element; + (void)offset; + (void)base; + /* Dummy implementation only: Do any games execute this? */ /*char debugger[32]; sprintf(debugger, "%s $v%i[0x%X], 0x%03X($%i)", "LFV", @@ -1454,7 +1463,13 @@ INLINE static void LTV(usf_state_t * state, int vt, int element, int offset, int return; } NOINLINE static void SWV(usf_state_t * state, int vt, int element, int offset, int base) -{ /* Dummy implementation only: Do any games execute this? */ +{ + (void)state; + (void)vt; + (void)element; + (void)offset; + (void)base; + /* Dummy implementation only: Do any games execute this? */ /*char debugger[32]; sprintf(debugger, "%s $v%i[0x%X], 0x%03X($%i)", "SWV", diff --git a/Frameworks/lazyusf/lazyusf/rsp/vu/vmacq.h b/Frameworks/lazyusf/lazyusf/rsp/vu/vmacq.h index 9b53e69b4..abf08e8e6 100644 --- a/Frameworks/lazyusf/lazyusf/rsp/vu/vmacq.h +++ b/Frameworks/lazyusf/lazyusf/rsp/vu/vmacq.h @@ -15,6 +15,7 @@ static void VMACQ(usf_state_t * state, int vd, int vs, int vt, int e) { + (void)state; vd &= vs &= vt &= e &= 0; /* unused */ if (vd != vs || vt != e) return; diff --git a/Frameworks/lazyusf/lazyusf/rsp/vu/vnop.h b/Frameworks/lazyusf/lazyusf/rsp/vu/vnop.h index 73d32f380..2b9bd23e3 100644 --- a/Frameworks/lazyusf/lazyusf/rsp/vu/vnop.h +++ b/Frameworks/lazyusf/lazyusf/rsp/vu/vnop.h @@ -17,6 +17,8 @@ static void VNOP(usf_state_t * state, int vd, int vs, int vt, int e) { const int WB_inhibit = vd = vs = vt = e = 1; + (void)state; + if (WB_inhibit) return; /* message("VNOP", WB_inhibit); */ return; diff --git a/Frameworks/lazyusf/lazyusf/usf.c b/Frameworks/lazyusf/lazyusf/usf.c index 6b228fed7..5528fbd48 100644 --- a/Frameworks/lazyusf/lazyusf/usf.c +++ b/Frameworks/lazyusf/lazyusf/usf.c @@ -182,8 +182,9 @@ void usf_render(void * state, int16_t * buffer, size_t count, int32_t * sample_r size_t do_max = USF_STATE->samples_in_buffer; if ( do_max > count ) do_max = count; - - memcpy( buffer, USF_STATE->samplebuf, sizeof(int16_t) * 2 * do_max ); + + if ( buffer ) + memcpy( buffer, USF_STATE->samplebuf, sizeof(int16_t) * 2 * do_max ); USF_STATE->samples_in_buffer -= do_max; @@ -196,7 +197,8 @@ void usf_render(void * state, int16_t * buffer, size_t count, int32_t * sample_r return; } - buffer += 2 * do_max; + if ( buffer ) + buffer += 2 * do_max; count -= do_max; } @@ -212,6 +214,12 @@ void usf_render(void * state, int16_t * buffer, size_t count, int32_t * sample_r *sample_rate = USF_STATE->SampleRate; } +void usf_restart(void * state) +{ + if ( USF_STATE->MemoryState ) + StartEmulationFromSave(USF_STATE, USF_STATE->savestatespace); +} + void usf_shutdown(void * state) { Release_Memory(USF_STATE); diff --git a/Frameworks/lazyusf/lazyusf/usf.h b/Frameworks/lazyusf/lazyusf/usf.h index e4b32fb62..c227aa0bb 100644 --- a/Frameworks/lazyusf/lazyusf/usf.h +++ b/Frameworks/lazyusf/lazyusf/usf.h @@ -32,6 +32,8 @@ int usf_upload_section(void * state, const uint8_t * data, size_t size); void usf_render(void * state, int16_t * buffer, size_t count, int32_t * sample_rate); +void usf_restart(void * state); + void usf_shutdown(void * state); #ifdef __cplusplus diff --git a/Frameworks/lazyusf/lazyusf/usf_internal.h b/Frameworks/lazyusf/lazyusf/usf_internal.h index b2b8f214d..af6a54473 100644 --- a/Frameworks/lazyusf/lazyusf/usf_internal.h +++ b/Frameworks/lazyusf/lazyusf/usf_internal.h @@ -14,22 +14,34 @@ typedef uint32_t RCPREG; struct usf_state { // RSP vector registers, need to be aligned to 16 bytes + // when SSE2 or SSSE3 is enabled, or for any hope of + // auto vectorization + + // usf_clear takes care of aligning the structure within + // the memory block passed into it, treating the pointer + // as usf_state_helper, and storing an offset from the + // pointer to the actual usf_state structure. The size + // which is indicated for allocation accounts for this + // with two pages of padding. + short VR[32][8]; short VACC[3][8]; - // RSP virtual registers + // RSP virtual registers, also needs alignment int SR[32]; - // rsp/rsp.c + // rsp/rsp.c, not necessarily in need of alignment RCPREG* CR[16]; - // rsp/vu/cf.h + // rsp/vu/cf.h, all need alignment short ne[8]; /* $vco: high byte "NOTEQUAL" */ short co[8]; /* $vco: low byte "carry/borrow in/out" */ short clip[8]; /* $vcc: high byte (clip tests: VCL, VCH, VCR) */ short comp[8]; /* $vcc: low byte (VEQ, VNE, VLT, VGE, VCL, VCH, VCR) */ short vce[8]; /* $vce: vector compare extension register */ + // All further members of the structure need not be aligned + // rsp/vu/divrom.h int DivIn; /* buffered numerator of division read from vector file */ int DivOut; /* global division result set by VRCP/VRCPL/VRSQ/VRSQH */