Added debug build logging to lazyusf

CQTexperiment
Chris Moeller 2015-02-26 18:51:44 -08:00
parent 83772785f8
commit 8c360b4555
6 changed files with 38 additions and 22 deletions

View File

@ -55,7 +55,7 @@ void AiLenChanged(usf_state_t * state) {
length = AI_LEN_REG & 0x3FFF8; length = AI_LEN_REG & 0x3FFF8;
#ifdef DEBUG_INFO #ifdef DEBUG_INFO
fprintf(stderr, "Audio buffer queued from %08x for %d bytes\n", AI_DRAM_ADDR_REG, length); fprintf(state->debug_log, "Audio DMA push: %d %d\n", AI_DRAM_ADDR_REG, length);
#endif #endif
AddBuffer(state, state->RDRAM+address, length); AddBuffer(state, state->RDRAM+address, length);

View File

@ -525,7 +525,7 @@ void RefreshScreen (usf_state_t * state){
void RunRsp (usf_state_t * state) { void RunRsp (usf_state_t * state) {
#ifdef DEBUG_INFO #ifdef DEBUG_INFO
fprintf(stderr, "RSP Task:"); fprintf(state->debug_log, "RSP Task:");
#endif #endif
if ( ( SP_STATUS_REG & SP_STATUS_HALT ) == 0) { if ( ( SP_STATUS_REG & SP_STATUS_HALT ) == 0) {
if ( ( SP_STATUS_REG & SP_STATUS_BROKE ) == 0 ) { if ( ( SP_STATUS_REG & SP_STATUS_BROKE ) == 0 ) {
@ -541,7 +541,7 @@ void RunRsp (usf_state_t * state) {
MI_INTR_REG |= 1; MI_INTR_REG |= 1;
#ifdef DEBUG_INFO #ifdef DEBUG_INFO
fprintf(stderr, " DList - interrupts %d\n", MI_INTR_REG); fprintf(state->debug_log, " DList - interrupts %d\n", MI_INTR_REG);
#endif #endif
CheckInterrupts(state); CheckInterrupts(state);
@ -552,7 +552,9 @@ void RunRsp (usf_state_t * state) {
} }
break; break;
case 2: { case 2: {
fprintf(stderr, " AList"); #ifdef DEBUG_INFO
fprintf(state->debug_log, " AList");
#endif
break; break;
} }
break; break;
@ -565,7 +567,7 @@ void RunRsp (usf_state_t * state) {
SP_STATUS_REG |= (0x0203 ); SP_STATUS_REG |= (0x0203 );
if ((SP_STATUS_REG & SP_STATUS_INTR_BREAK) != 0 ) { if ((SP_STATUS_REG & SP_STATUS_INTR_BREAK) != 0 ) {
#ifdef DEBUG_INFO #ifdef DEBUG_INFO
fprintf(stderr, " - interrupt"); fprintf(state->debug_log, " - interrupt");
#endif #endif
MI_INTR_REG |= 1; MI_INTR_REG |= 1;
CheckInterrupts(state); CheckInterrupts(state);
@ -573,7 +575,7 @@ void RunRsp (usf_state_t * state) {
} }
} }
#ifdef DEBUG_INFO #ifdef DEBUG_INFO
fprintf(stderr, "\n"); fprintf(state->debug_log, "\n");
#endif #endif
} }

View File

@ -35,17 +35,17 @@ void CheckInterrupts ( usf_state_t * state ) {
MI_INTR_REG |= (state->AudioIntrReg & MI_INTR_AI); MI_INTR_REG |= (state->AudioIntrReg & MI_INTR_AI);
#ifdef DEBUG_INFO #ifdef DEBUG_INFO
if (MI_INTR_REG) if (MI_INTR_REG)
fprintf(stderr, "Interrupt %d - ", MI_INTR_REG); fprintf(state->debug_log, "Interrupt %d - ", MI_INTR_REG);
#endif #endif
if ((MI_INTR_MASK_REG & MI_INTR_REG) != 0) { if ((MI_INTR_MASK_REG & MI_INTR_REG) != 0) {
#ifdef DEBUG_INFO #ifdef DEBUG_INFO
fprintf(stderr, "triggered\n"); fprintf(state->debug_log, "triggered\n");
#endif #endif
FAKE_CAUSE_REGISTER |= CAUSE_IP2; FAKE_CAUSE_REGISTER |= CAUSE_IP2;
} else { } else {
#ifdef DEBUG_INFO #ifdef DEBUG_INFO
if (MI_INTR_REG) if (MI_INTR_REG)
fprintf(stderr, "masked\n"); fprintf(state->debug_log, "masked\n");
#endif #endif
FAKE_CAUSE_REGISTER &= ~CAUSE_IP2; FAKE_CAUSE_REGISTER &= ~CAUSE_IP2;
} }

View File

@ -720,13 +720,10 @@ void ExecuteInterpreterOpCode (usf_state_t * state) {
#ifdef DEBUG_INFO #ifdef DEBUG_INFO
{ {
static const char filler[] = " ";
char opcode[256]; char opcode[256];
char arguments[256]; char arguments[256];
r4300_decode_op(state->Opcode.u.Hex, opcode, arguments, state->PROGRAM_COUNTER); r4300_decode_op(state->Opcode.u.Hex, opcode, arguments, state->PROGRAM_COUNTER);
strcat(opcode, filler); fprintf(state->debug_log, "%08x: %-16s %s\n", state->PROGRAM_COUNTER, opcode, arguments);
opcode[16] = '\0';
fprintf(stderr, "%08x: %s %s\n", state->PROGRAM_COUNTER, opcode, arguments);
} }
#endif #endif
@ -753,7 +750,11 @@ void ExecuteInterpreterOpCode (usf_state_t * state) {
state->PROGRAM_COUNTER += 4; state->PROGRAM_COUNTER += 4;
break; break;
case JUMP: case JUMP:
if (0 && state->cpu_hle_entry_count && if (
#ifdef DEBUG_INFO
0 &&
#endif
state->cpu_hle_entry_count &&
DoCPUHLE(state, state->JumpToLocation)) { DoCPUHLE(state, state->JumpToLocation)) {
state->PROGRAM_COUNTER = state->GPR[31].UW[0]; state->PROGRAM_COUNTER = state->GPR[31].UW[0];
state->NextInstruction = NORMAL; state->NextInstruction = NORMAL;

View File

@ -70,6 +70,10 @@ void usf_clear(void * state)
//USF_STATE->PIF_Ram = 0; //USF_STATE->PIF_Ram = 0;
PreAllocate_Memory(USF_STATE); PreAllocate_Memory(USF_STATE);
#ifdef DEBUG_INFO
USF_STATE->debug_log = fopen("/tmp/lazyusf.log", "w");
#endif
} }
void usf_set_compare(void * state, int enable) void usf_set_compare(void * state, int enable)
@ -162,23 +166,23 @@ int usf_upload_section(void * state, const uint8_t * data, size_t size)
return 0; return 0;
} }
static int usf_startup(void * state) static int usf_startup(usf_state_t * state)
{ {
// Detect the Ramsize before the memory allocation // Detect the Ramsize before the memory allocation
if(*(uint32_t*)(USF_STATE->savestatespace + 4) == 0x400000) { if(get_le32(state->savestatespace + 4) == 0x400000) {
void * savestate; void * savestate;
USF_STATE->RdramSize = 0x400000; state->RdramSize = 0x400000;
savestate = realloc(USF_STATE->savestatespace, 0x40275c); savestate = realloc(state->savestatespace, 0x40275c);
if ( savestate ) if ( savestate )
USF_STATE->savestatespace = savestate; state->savestatespace = savestate;
} else if(*(uint32_t*)(USF_STATE->savestatespace + 4) == 0x800000) } else if(get_le32(USF_STATE->savestatespace + 4) == 0x800000)
USF_STATE->RdramSize = 0x800000; state->RdramSize = 0x800000;
if ( !Allocate_Memory(state) ) if ( !Allocate_Memory(state) )
return -1; return -1;
StartEmulationFromSave(USF_STATE, USF_STATE->savestatespace); StartEmulationFromSave(state, USF_STATE->savestatespace);
return 0; return 0;
} }
@ -244,4 +248,7 @@ void usf_restart(void * state)
void usf_shutdown(void * state) void usf_shutdown(void * state)
{ {
Release_Memory(USF_STATE); Release_Memory(USF_STATE);
#ifdef DEBUG_INFO
fclose(USF_STATE->debug_log);
#endif
} }

View File

@ -15,7 +15,9 @@ struct usf_state_helper
typedef uint32_t RCPREG; typedef uint32_t RCPREG;
#endif #endif
#ifdef DEBUG_INFO
#include <stdio.h> #include <stdio.h>
#endif
struct usf_state struct usf_state
{ {
@ -140,6 +142,10 @@ struct usf_state
uint32_t cpu_hle_entry_count; uint32_t cpu_hle_entry_count;
_HLE_Entry * cpu_hle_entries; _HLE_Entry * cpu_hle_entries;
#ifdef DEBUG_INFO
FILE * debug_log;
#endif
}; };
#define USF_STATE_HELPER ((usf_state_helper_t *)(state)) #define USF_STATE_HELPER ((usf_state_helper_t *)(state))