diff --git a/Docs/DSP/Crazy Taxi.txt b/Docs/DSP/Crazy Taxi.txt index a5e8469038..2db9cb7284 100644 --- a/Docs/DSP/Crazy Taxi.txt +++ b/Docs/DSP/Crazy Taxi.txt @@ -87,7 +87,7 @@ Init-Code() 0021 00fe 0e31 SR @0x0e31, $30 0023 16fc dcd1 SI @DMBH, #0xdcd1 0025 16fd 0000 SI @DMBL, #0x0000 -0027 16fb 0001 SI @DIRQ, #0x0001 +0027 16fb 0001 SI @DIRQ, #0x0001 // write mail: DSP_TASK_STATE_RUN(0xDCD10000) and calls initCB of the task // wait for mail 0029 26fc LRS $30, @DMBH @@ -109,7 +109,9 @@ Init-Code() 0038 0092 00ff LRI $18, #0x00ff 003a 16fc dcd1 SI @DMBH, #0xdcd1 003c 16fd 0001 SI @DMBL, #0x0001 -003e 16fb 0001 SI @DIRQ, #0x0001 +003e 16fb 0001 SI @DIRQ, #0x0001 // write mail: DSP_TASK_STATE_RUN(0xDCD10001) and calls resCB of the task + + 0040 26fc LRS $30, @DMBH 0041 02a0 8000 ANDCF $30, #0x8000 0043 029c 0040 JZR 0x0040 @@ -121,9 +123,15 @@ Main() 0046 8100 CLR $30 0047 8900 CLR $31 0048 009f babe LRI $31, #0xbabe + + +// wait for dma timewasting :D 004a 26fe LRS $30, @CMBH 004b 02c0 8000 ANDF $30, #0x8000 004d 029c 004a JZR 0x004a + + + 004f 8200 CMP 0050 0294 004a JNE 0x004a 0052 23ff LRS $27, @CMBL @@ -727,6 +735,8 @@ Main() 033b 1c03 MRR $0, $3 033c 1ff5 MRR $31, $21 033d 191a LRRI $26, @$0 + + 033e f858 ADDPAXZ.L $30, $26 : $27, @$0 033f fba0 ADDPAXZ.LS $31, $27 : $26, $30 0340 f8b1 ADDPAXZ.LS $30, $26 : $27, $31 @@ -736,6 +746,10 @@ Main() 0344 f8b1 ADDPAXZ.LS $30, $26 : $27, $31 0345 fba0 ADDPAXZ.LS $31, $27 : $26, $30 0346 f83b ADDPAXZ.S $30, $26 : @$3, $31 + + + + 0347 1b7e SRRI @$3, $30 0348 0083 0e04 LRI $3, #0x0e04 034a 8100 CLR $30 @@ -818,6 +832,11 @@ Main() 03b3 16cd 03c0 SI @DSPA, #0x03c0 03b5 16c9 0000 SI @DSCR, #0x0000 03b7 16cb 0080 SI @DSBL, #0x0080 // Don't know w.at this dma xfer is + + + + + 03b9 8100 CLR $30 03ba 8900 CLR $31 03bb 00de 0b84 LR $30, @0x0b84 @@ -2598,11 +2617,11 @@ Main() 0c90 0cdd LRIS $28, #0xdd // normal case to return to the main-loop -// Mix and write back to RAM??? It is called by AXLIST_END command only +// Wait for new message from the CPU 0c91 8e00 S40 0c92 8100 CLR $30 0c93 8900 CLR $31 -0c94 02bf 0ce0 CALL 0x0ce0 // wait for CMBH +0c94 02bf 0ce0 CALL 0x0ce0 // wait for answer for our "0xDCD10002"-message... and we have to wait really long :( 0c96 27ff LRS $31, @CMBL 0c97 009e 0c8d LRI $30, #0x0c8d 0c99 4c00 ADD $30, $31 @@ -2612,6 +2631,8 @@ Main() 0c9d 176f JMPR $3 0c9e 0021 HALT +//////////////////////////////////////////////////////////////////////////7 + // case 0x00: 0c9f 029f 0030 JMP 0x0030 0ca1 0021 HALT diff --git a/Source/Plugins/Plugin_DSP_LLE/Src/Globals.cpp b/Source/Plugins/Plugin_DSP_LLE/Src/Globals.cpp index edfbd6a491..23f9e4f90d 100644 --- a/Source/Plugins/Plugin_DSP_LLE/Src/Globals.cpp +++ b/Source/Plugins/Plugin_DSP_LLE/Src/Globals.cpp @@ -88,4 +88,48 @@ u32 Memory_Read_U32(u32 _uAddress) _uAddress &= RAM_MASK; return Common::swap32(*(u32*)&g_dsp.cpu_ram[_uAddress]); } -// ============= \ No newline at end of file + +#if PROFILE + +#define PROFILE_MAP_SIZE 0x10000 + +u64 g_profileMap[PROFILE_MAP_SIZE]; +bool g_profile = false; + +void ProfilerStart() +{ + g_profile = true; +} + +void ProfilerAddDelta(int _addr, int _delta) +{ + if (g_profile) + { + g_profileMap[_addr] += _delta; + } +} + +void ProfilerInit() +{ + memset(g_profileMap, 0, sizeof(g_profileMap)); +} + +void ProfilerDump(uint64 count) +{ + FILE* pFile = fopen("c:\\_\\DSP_Prof.txt", "wt"); + if (pFile != NULL) + { + fprintf(pFile, "Number of DSP steps: %i\n\n", count); + for (int i=0; i 0) + { + fprintf(pFile, "0x%04X: %u\n", i, g_profileMap[i]); + } + } + + fclose(pFile); + } +} + +#endif diff --git a/Source/Plugins/Plugin_DSP_LLE/Src/Globals.h b/Source/Plugins/Plugin_DSP_LLE/Src/Globals.h index 42edd2d0ac..42287e3857 100644 --- a/Source/Plugins/Plugin_DSP_LLE/Src/Globals.h +++ b/Source/Plugins/Plugin_DSP_LLE/Src/Globals.h @@ -65,5 +65,13 @@ typedef const uint32 cuint32; u16 Memory_Read_U16(u32 _uAddress); // For PB address detection u32 Memory_Read_U32(u32 _uAddress); +#if PROFILE + void ProfilerDump(uint64 _count); + void ProfilerInit(); + void ProfilerAddDelta(int _addr, int _delta); + void ProfilerStart(); +#endif + + #endif diff --git a/Source/Plugins/Plugin_DSP_LLE/Src/gdsp_interpreter.cpp b/Source/Plugins/Plugin_DSP_LLE/Src/gdsp_interpreter.cpp index c67005066a..f609298237 100644 --- a/Source/Plugins/Plugin_DSP_LLE/Src/gdsp_interpreter.cpp +++ b/Source/Plugins/Plugin_DSP_LLE/Src/gdsp_interpreter.cpp @@ -228,11 +228,25 @@ void gdsp_step() if (g_dsp.pc == 0x80e7) { - g_dsp.pc = HLE_ROM_80E7_81F8(); + //g_dsp.pc = HLE_ROM_80E7_81F8(); } g_dsp.err_pc = g_dsp.pc; +#if PROFILE + ProfilerAddDelta(g_dsp.err_pc, 1); + if (g_dsp.step_counter == 1) + { + ProfilerInit(); + } + + if ((g_dsp.step_counter & 0xFFFFF) == 0) + { + ProfilerDump(g_dsp.step_counter); + } + +#endif + uint16 opc = dsp_fetch_code(); dsp_op[opc >> 12](opc); diff --git a/Source/Plugins/Plugin_DSP_LLE/Src/gdsp_interpreter.h b/Source/Plugins/Plugin_DSP_LLE/Src/gdsp_interpreter.h index 22af0bc81d..1ba0d685f8 100644 --- a/Source/Plugins/Plugin_DSP_LLE/Src/gdsp_interpreter.h +++ b/Source/Plugins/Plugin_DSP_LLE/Src/gdsp_interpreter.h @@ -91,5 +91,4 @@ uint16* gdsp_get_irom(void); uint16* gdsp_get_dram(void); uint16* gdsp_get_drom(void); - #endif diff --git a/Source/Plugins/Plugin_DSP_LLE/Src/gdsp_opcodes_helper.h b/Source/Plugins/Plugin_DSP_LLE/Src/gdsp_opcodes_helper.h index 774fbd5eb6..62cf8a8a76 100644 --- a/Source/Plugins/Plugin_DSP_LLE/Src/gdsp_opcodes_helper.h +++ b/Source/Plugins/Plugin_DSP_LLE/Src/gdsp_opcodes_helper.h @@ -107,6 +107,10 @@ inline void dsp_op_write_reg(uint8 reg, uint16 val) inline sint64 dsp_get_long_prod() { +#if PROFILE + ProfilerAddDelta(g_dsp.err_pc, 1); +#endif + sint64 val; sint64 low_prod; val = (sint8)g_dsp.r[0x16]; @@ -122,6 +126,10 @@ inline sint64 dsp_get_long_prod() inline void dsp_set_long_prod(sint64 val) { +#if PROFILE + ProfilerAddDelta(g_dsp.err_pc, 1); +#endif + g_dsp.r[0x14] = (uint16)val; val >>= 16; g_dsp.r[0x15] = (uint16)val; @@ -139,6 +147,10 @@ inline void dsp_set_long_prod(sint64 val) inline sint64 dsp_get_long_acc(uint8 reg) { +#if PROFILE + ProfilerAddDelta(g_dsp.err_pc, 1); +#endif + _dbg_assert_(reg < 2); sint64 val; sint64 low_acc; @@ -154,6 +166,10 @@ inline sint64 dsp_get_long_acc(uint8 reg) inline uint64 dsp_get_ulong_acc(uint8 reg) { +#if PROFILE + ProfilerAddDelta(g_dsp.err_pc, 1); +#endif + _dbg_assert_(reg < 2); uint64 val; uint64 low_acc; @@ -169,6 +185,10 @@ inline uint64 dsp_get_ulong_acc(uint8 reg) inline void dsp_set_long_acc(uint8 _reg, sint64 val) { +#if PROFILE + ProfilerAddDelta(g_dsp.err_pc, 1); +#endif + _dbg_assert_(_reg < 2); g_dsp.r[0x1c + _reg] = (uint16)val; val >>= 16; @@ -208,6 +228,10 @@ inline sint16 dsp_get_acc_h(uint8 _reg) inline sint64 dsp_get_long_acx(uint8 _reg) { +#if PROFILE + ProfilerAddDelta(g_dsp.err_pc, 1); +#endif + _dbg_assert_(_reg < 2); sint64 val = (sint16)g_dsp.r[0x1a + _reg]; val <<= 16; diff --git a/Source/Plugins/Plugin_DSP_LLE/Src/main.cpp b/Source/Plugins/Plugin_DSP_LLE/Src/main.cpp index 26d41c3547..1c89f9d712 100644 --- a/Source/Plugins/Plugin_DSP_LLE/Src/main.cpp +++ b/Source/Plugins/Plugin_DSP_LLE/Src/main.cpp @@ -66,7 +66,7 @@ bool AXTask(u32& _uMail); bool bCanWork = false; // Set this if you want to log audio. search for log_ai in this file to see the filename. -static bool log_ai = false; +static bool log_ai = true; WaveFileWriter g_wave_writer; // ============== @@ -258,11 +258,12 @@ void DSP_Initialize(DSPInitialize _dspInitialize) // -------------- // Dump UCode to file... - FILE* t = fopen("DSP_UC_09CD143F.txt", "wb"); - if(t) { + FILE* t = fopen("C:\\_\\DSP_UC_09CD143F.txt", "wb"); + if (t != NULL) + { gd_globals_t gdg; - gd_dis_file(&gdg, "DSP_UC_09CD143F.bin", t); - fclose(t); + gd_dis_file(&gdg, "C:\\_\\DSP_UC_09CD143F.bin", t); + fclose(t); } // -------------- @@ -353,6 +354,13 @@ void DSP_WriteMailboxHigh(bool _CPUMailbox, u16 _uHighMail) ErrorLog("Mailbox isnt empty ... strange"); } +#if PROFILE + if ((_uHighMail) == 0xBABE) + { + ProfilerStart(); + } +#endif + gdsp_mbox_write_h(GDSP_MBOX_CPU, _uHighMail); } else