--- hatari/src/falcon/dsp.c 2019/04/09 08:55:48 1.1.1.11 +++ hatari/src/falcon/dsp.c 2019/04/09 08:59:31 1.1.1.14 @@ -16,8 +16,8 @@ GNU General Public License for more details. You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + along with this program; if not, write to the Free Software Foundation, + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335 USA */ #include @@ -67,6 +67,8 @@ static bool bDspDebugging; bool bDspEnabled = false; bool bDspHostInterruptPending = false; +Uint64 DSP_CyclesGlobalClockCounter = 0; /* Value of CyclesGlobalClockCounter when DSP_Run was last called */ + /** * Trigger HREQ interrupt at the host CPU. @@ -187,6 +189,7 @@ void DSP_Enable(void) { #if ENABLE_DSP_EMU bDspEnabled = true; + DSP_CyclesGlobalClockCounter = CyclesGlobalClockCounter; #endif } @@ -225,29 +228,37 @@ void DSP_MemorySnapShot_Capture(bool bSa void DSP_Run(int nHostCycles) { #if ENABLE_DSP_EMU - save_cycles += nHostCycles * 2; + if ( nHostCycles == 0 ) + return; + + DSP_CyclesGlobalClockCounter = CyclesGlobalClockCounter; + + save_cycles += nHostCycles * 2; - if (dsp_core.running == 0) - return; + if (dsp_core.running == 0) + return; - if (save_cycles <= 0) - return; + if (save_cycles <= 0) + return; - if (unlikely(bDspDebugging)) { - while (save_cycles > 0) - { - dsp56k_execute_instruction(); - save_cycles -= dsp_core.instr_cycle; - DebugDsp_Check(); - } - } else { - // fprintf(stderr, "--> %d\n", save_cycles); - while (save_cycles > 0) - { - dsp56k_execute_instruction(); - save_cycles -= dsp_core.instr_cycle; - } - } + if (unlikely(bDspDebugging)) + { + while (save_cycles > 0) + { + dsp56k_execute_instruction(); + save_cycles -= dsp_core.instr_cycle; + DebugDsp_Check(); + } + } + else + { + // fprintf(stderr, "--> %d\n", save_cycles); + while (save_cycles > 0) + { + dsp56k_execute_instruction(); + save_cycles -= dsp_core.instr_cycle; + } + } #endif } @@ -294,7 +305,7 @@ Uint16 DSP_GetNextPC(Uint16 pc) /* why dsp56k_execute_one_disasm_instruction() does "-1" * for this value, that doesn't seem right??? */ - instruction_length = dsp56k_disasm(DSP_DISASM_MODE); + instruction_length = dsp56k_disasm(DSP_DISASM_MODE, stderr); /* Restore DSP context */ memcpy(&dsp_core, &dsp_core_save, sizeof(dsp_core)); @@ -427,7 +438,7 @@ Uint32 DSP_ReadMemory(Uint16 address, ch * Output memory values between given addresses in given DSP address space. * Return next DSP address value. */ -Uint16 DSP_DisasmMemory(Uint16 dsp_memdump_addr, Uint16 dsp_memdump_upper, char space) +Uint16 DSP_DisasmMemory(FILE *fp, Uint16 dsp_memdump_addr, Uint16 dsp_memdump_upper, char space) { #if ENABLE_DSP_EMU Uint32 mem, mem2, value; @@ -437,16 +448,16 @@ Uint16 DSP_DisasmMemory(Uint16 dsp_memdu /* special printing of host communication/transmit registers */ if (space == 'X' && mem >= 0xffc0) { if (mem == 0xffeb) { - fprintf(stderr,"X periph:%04x HTX : %06x RTX:%06x\n", + fprintf(fp, "X periph:%04x HTX : %06x RTX:%06x\n", mem, dsp_core.dsp_host_htx, dsp_core.dsp_host_rtx); } else if (mem == 0xffef) { - fprintf(stderr,"X periph:%04x SSI TX : %06x SSI RX:%06x\n", + fprintf(fp, "X periph:%04x SSI TX : %06x SSI RX:%06x\n", mem, dsp_core.ssi.transmit_value, dsp_core.ssi.received_value); } else { value = DSP_ReadMemory(mem, space, &mem_str); - fprintf(stderr,"%s:%04x %06x\t%s\n", mem_str, mem, value, x_ext_memory_addr_name[mem-0xffc0]); + fprintf(fp, "%s:%04x %06x\t%s\n", mem_str, mem, value, x_ext_memory_addr_name[mem-0xffc0]); } continue; } @@ -457,12 +468,12 @@ Uint16 DSP_DisasmMemory(Uint16 dsp_memdu if (space == 'X') { mem2 += (DSP_RAMSIZE>>1); } - fprintf(stderr,"%c:%04x (P:%04x): %06x\n", space, + fprintf(fp, "%c:%04x (P:%04x): %06x\n", space, mem, mem2, dsp_core.ramext[mem2 & (DSP_RAMSIZE-1)]); continue; } value = DSP_ReadMemory(mem, space, &mem_str); - fprintf(stderr,"%s:%04x %06x\n", mem_str, mem, value); + fprintf(fp, "%s:%04x %06x\n", mem_str, mem, value); } #endif return dsp_memdump_upper+1; @@ -480,28 +491,28 @@ void DSP_Info(FILE *fp, Uint32 dummy) fputs("DSP core information:\n", fp); - for (i = 0; i < ARRAYSIZE(stackname); i++) { + for (i = 0; i < ARRAY_SIZE(stackname); i++) { fprintf(fp, "- %s stack:", stackname[i]); - for (j = 0; j < ARRAYSIZE(dsp_core.stack[0]); j++) { + for (j = 0; j < ARRAY_SIZE(dsp_core.stack[0]); j++) { fprintf(fp, " %04hx", dsp_core.stack[i][j]); } fputs("\n", fp); } fprintf(fp, "- Interrupt IPL:"); - for (i = 0; i < ARRAYSIZE(dsp_core.interrupt_ipl); i++) { + for (i = 0; i < ARRAY_SIZE(dsp_core.interrupt_ipl); i++) { fprintf(fp, " %04hx", dsp_core.interrupt_ipl[i]); } fputs("\n", fp); fprintf(fp, "- Pending ints: "); - for (i = 0; i < ARRAYSIZE(dsp_core.interrupt_isPending); i++) { + for (i = 0; i < ARRAY_SIZE(dsp_core.interrupt_isPending); i++) { fprintf(fp, " %04hx", dsp_core.interrupt_isPending[i]); } fputs("\n", fp); fprintf(fp, "- Hostport:"); - for (i = 0; i < ARRAYSIZE(dsp_core.hostport); i++) { + for (i = 0; i < ARRAY_SIZE(dsp_core.hostport); i++) { fprintf(fp, " %02x", dsp_core.hostport[i]); } fputs("\n", fp); @@ -511,29 +522,29 @@ void DSP_Info(FILE *fp, Uint32 dummy) /** * Show DSP register contents */ -void DSP_DisasmRegisters(void) +void DSP_DisasmRegisters(FILE *fp) { #if ENABLE_DSP_EMU Uint32 i; - fprintf(stderr,"A: A2: %02x A1: %06x A0: %06x\n", + fprintf(fp, "A: A2: %02x A1: %06x A0: %06x\n", dsp_core.registers[DSP_REG_A2], dsp_core.registers[DSP_REG_A1], dsp_core.registers[DSP_REG_A0]); - fprintf(stderr,"B: B2: %02x B1: %06x B0: %06x\n", + fprintf(fp, "B: B2: %02x B1: %06x B0: %06x\n", dsp_core.registers[DSP_REG_B2], dsp_core.registers[DSP_REG_B1], dsp_core.registers[DSP_REG_B0]); - fprintf(stderr,"X: X1: %06x X0: %06x\n", dsp_core.registers[DSP_REG_X1], dsp_core.registers[DSP_REG_X0]); - fprintf(stderr,"Y: Y1: %06x Y0: %06x\n", dsp_core.registers[DSP_REG_Y1], dsp_core.registers[DSP_REG_Y0]); + fprintf(fp, "X: X1: %06x X0: %06x\n", dsp_core.registers[DSP_REG_X1], dsp_core.registers[DSP_REG_X0]); + fprintf(fp, "Y: Y1: %06x Y0: %06x\n", dsp_core.registers[DSP_REG_Y1], dsp_core.registers[DSP_REG_Y0]); for (i=0; i<8; i++) { - fprintf(stderr,"R%01x: %04x N%01x: %04x M%01x: %04x\n", + fprintf(fp, "R%01x: %04x N%01x: %04x M%01x: %04x\n", i, dsp_core.registers[DSP_REG_R0+i], i, dsp_core.registers[DSP_REG_N0+i], i, dsp_core.registers[DSP_REG_M0+i]); } - fprintf(stderr,"LA: %04x LC: %04x PC: %04x\n", dsp_core.registers[DSP_REG_LA], dsp_core.registers[DSP_REG_LC], dsp_core.pc); - fprintf(stderr,"SR: %04x OMR: %02x\n", dsp_core.registers[DSP_REG_SR], dsp_core.registers[DSP_REG_OMR]); - fprintf(stderr,"SP: %02x SSH: %04x SSL: %04x\n", + fprintf(fp, "LA: %04x LC: %04x PC: %04x\n", dsp_core.registers[DSP_REG_LA], dsp_core.registers[DSP_REG_LC], dsp_core.pc); + fprintf(fp, "SR: %04x OMR: %02x\n", dsp_core.registers[DSP_REG_SR], dsp_core.registers[DSP_REG_OMR]); + fprintf(fp, "SP: %02x SSH: %04x SSL: %04x\n", dsp_core.registers[DSP_REG_SP], dsp_core.registers[DSP_REG_SSH], dsp_core.registers[DSP_REG_SSL]); #endif } @@ -644,7 +655,7 @@ int DSP_GetRegisterAddress(const char *r /* bisect */ l = 0; - r = ARRAYSIZE(registers) - 1; + r = ARRAY_SIZE(registers) - 1; do { m = (l+r) >> 1; for (i = 0; i < len; i++) { @@ -827,7 +838,7 @@ void DSP_HandleReadAccess(void) value = 0xff; #endif if (multi_access == true) - M68000_AddCycles(4); + M68000_WaitState(4); multi_access = true; Dprintf(("HWget_b(0x%08x)=0x%02x at 0x%08x\n", addr, value, m68k_getpc())); @@ -853,7 +864,7 @@ void DSP_HandleWriteAccess(void) dsp_core_write_host(addr-DSP_HW_OFFSET, value); #endif if (multi_access == true) - M68000_AddCycles(4); + M68000_WaitState(4); multi_access = true; } }