From 42e6eb03c2a177b8dcc8c3f036c8e78117b949cf Mon Sep 17 00:00:00 2001 From: Chris Moeller Date: Wed, 3 Dec 2014 21:38:28 -0800 Subject: [PATCH] Updated lazyusf --- Frameworks/lazyusf/lazyusf/cpu_hle.c | 15 ++++++++++++++- Frameworks/lazyusf/lazyusf/interpreter_cpu.c | 13 +++++++------ Frameworks/lazyusf/lazyusf/memory.h | 4 ++-- Frameworks/lazyusf/lazyusf/usf_internal.h | 1 + 4 files changed, 24 insertions(+), 9 deletions(-) diff --git a/Frameworks/lazyusf/lazyusf/cpu_hle.c b/Frameworks/lazyusf/lazyusf/cpu_hle.c index e08c4c71d..6b04cedc5 100644 --- a/Frameworks/lazyusf/lazyusf/cpu_hle.c +++ b/Frameworks/lazyusf/lazyusf/cpu_hle.c @@ -55,6 +55,13 @@ _HLE_Entry entrys[] = { //char foundlist[2048]; +int sort_entrys(void * a, void * b) +{ + _HLE_Entry * _a = (_HLE_Entry *)a; + _HLE_Entry * _b = (_HLE_Entry *)b; + return _b->used - _a->used; +} + int CPUHLE_Scan(usf_state_t * state) { int i = 0, j = 0; @@ -65,6 +72,7 @@ int CPUHLE_Scan(usf_state_t * state) void * address = 0; int good = 1; //, needcomma = 0; _HLE_Entry * entries; + unsigned entries_used = 0; numEntries = sizeof(entrys) / sizeof(_HLE_Entry); @@ -111,12 +119,16 @@ int CPUHLE_Scan(usf_state_t * state) entries[entry].used = 1; entries[entry].phys = i; + ++entries_used; break; } } } + qsort(entries, numEntries, sizeof(*entries), sort_entrys); + state->cpu_hle_entry_count = entries_used; + //printf("<--------------HLE Functions Found--------------->\n%s<------------------------------------------------>\n", foundlist); //printf("HLE Functions found: %s\n", foundlist); @@ -128,10 +140,11 @@ int DoCPUHLE(usf_state_t * state, unsigned long loc) int i = 0; uintptr_t real_addr = PageVRAM2(loc); _HLE_Entry * entries = state->cpu_hle_entries; + unsigned numEntries = state->cpu_hle_entry_count; for(i = 0; i < numEntries; i++) { - if(entries[i].used && (entries[i].phys == real_addr)) { + if(entries[i].phys == real_addr) { //printf("CPU HLEing using %d at %08x (phys: %08x) \"%s\"\n", entries[i].name, loc, entries[i].phys, entries[i].name); if(entries[i].location(state, entries[i].phys)) { diff --git a/Frameworks/lazyusf/lazyusf/interpreter_cpu.c b/Frameworks/lazyusf/lazyusf/interpreter_cpu.c index 65b1d82f0..3f7ee2990 100644 --- a/Frameworks/lazyusf/lazyusf/interpreter_cpu.c +++ b/Frameworks/lazyusf/lazyusf/interpreter_cpu.c @@ -737,16 +737,17 @@ void ExecuteInterpreterOpCode (usf_state_t * state) { state->PROGRAM_COUNTER += 4; break; case JUMP: - if(!DoCPUHLE(state, state->JumpToLocation)) { - state->PROGRAM_COUNTER = state->JumpToLocation; - state->NextInstruction = NORMAL; - } else { + if (state->cpu_hle_entry_count && + DoCPUHLE(state, state->JumpToLocation)) { state->PROGRAM_COUNTER = state->GPR[31].UW[0]; state->NextInstruction = NORMAL; } - if ((int32_t)state->Timers->Timer < 0) { TimerDone(state); } + else { + state->PROGRAM_COUNTER = state->JumpToLocation; + state->NextInstruction = NORMAL; + } + if ((int32_t)state->Timers->Timer < 0) { TimerDone(state); } if (state->CPU_Action->DoSomething) { DoSomething(state); } - } } diff --git a/Frameworks/lazyusf/lazyusf/memory.h b/Frameworks/lazyusf/lazyusf/memory.h index 294a509aa..5a2afdebb 100644 --- a/Frameworks/lazyusf/lazyusf/memory.h +++ b/Frameworks/lazyusf/lazyusf/memory.h @@ -31,8 +31,8 @@ #define ROM_IN_MAPSPACE -#define PageRAM2(x) (state->N64MEM+(x)) -#define PageVRAM(x) (state->TLB_Map[((x)&0xFFFFFFFF)>>12]+(x)) +#define PageRAM2(x) (state->N64MEM+(uint32_t)(x)) +#define PageVRAM(x) (state->TLB_Map[((uint32_t)(x))>>12]+(uint32_t)(x)) #define PageVRAM2(x) (uint32_t)(PageVRAM(x)-(uintptr_t)state->N64MEM) /* Memory Control */ diff --git a/Frameworks/lazyusf/lazyusf/usf_internal.h b/Frameworks/lazyusf/lazyusf/usf_internal.h index 0281f400f..9664f54e7 100644 --- a/Frameworks/lazyusf/lazyusf/usf_internal.h +++ b/Frameworks/lazyusf/lazyusf/usf_internal.h @@ -138,6 +138,7 @@ struct usf_state uint32_t OLD_VI_V_SYNC_REG/* = 0*/, VI_INTR_TIME/* = 500000*/; + uint32_t cpu_hle_entry_count; _HLE_Entry * cpu_hle_entries; };