--- hatari/src/falcon/dsp_cpu.c 2019/04/09 08:51:18 1.1.1.7 +++ hatari/src/falcon/dsp_cpu.c 2019/04/09 08:55:50 1.1.1.11 @@ -22,18 +22,19 @@ /* DSP memory mapping ------------------ - + The memory map is configured as follows : Program space P is one contiguous block of 32K dsp Words - X and Y data space are each separate 16K dsp Word blocks. + X and Y data space are each separate 16K dsp Word blocks. Both X and Y can be accessed as blocks starting at 0 or 16K. Program space physically overlaps both X and Y data spaces. Y: memory is mapped at address $0 in P memory - X: memory is mapped at address $4000 in P memory + X: memory is mapped at address $4000 in P memory The DSP external RAM is zero waitstate, but there is a penalty for - accessing it twice in a single instruction, because there is only - one external data bus. + accessing it twice or more in a single instruction, because there is only + one external data bus. The extra access costs 2 cycles penalty. + The internal buses are all separate (0 waitstate) @@ -73,12 +74,12 @@ #include +#include "main.h" #include "dsp_core.h" #include "dsp_cpu.h" #include "dsp_disasm.h" #include "log.h" -# include "main.h" - +#include "debugui.h" #define DSP_COUNT_IPS 0 /* Count instruction per seconds */ @@ -90,6 +91,14 @@ #define SIGN_PLUS 0 #define SIGN_MINUS 1 +/* Defines some bits values for access to external memory (X, Y, P) */ +/* These values will set/unset the corresponding bits in the variable access_to_ext_memory */ +/* to detect how many access to the external memory were done for a single instruction */ +#define EXT_X_MEMORY 0 +#define EXT_Y_MEMORY 1 +#define EXT_P_MEMORY 2 + + /********************************** * Variables **********************************/ @@ -105,7 +114,7 @@ static Uint32 cur_inst_len; /* =0:jump, static Uint32 cur_inst; /* Counts the number of access to the external memory for one instruction */ -static Uint16 nb_access_to_extMemory; +static Uint16 access_to_ext_memory; /* DSP is in disasm mode ? */ /* If yes, stack overflow, underflow and illegal instructions messages are not displayed */ @@ -135,7 +144,7 @@ static inline void write_memory(int spac static void write_memory_raw(int space, Uint16 address, Uint32 value); static void write_memory_disasm(int space, Uint16 address, Uint32 value); -static void dsp_write_reg(Uint32 numreg, Uint32 value); +static void dsp_write_reg(Uint32 numreg, Uint32 value); static void dsp_stack_push(Uint32 curpc, Uint32 cursr, Uint16 sshOnly); static void dsp_stack_pop(Uint32 *curpc, Uint32 *cursr); @@ -511,7 +520,7 @@ static const dsp_emul_t opcodes8h[512] = dsp_undefined, dsp_undefined, dsp_undefined, dsp_undefined, dsp_undefined, dsp_undefined, dsp_undefined, dsp_undefined, dsp_undefined, dsp_undefined, dsp_div, dsp_div, dsp_undefined, dsp_undefined, dsp_undefined, dsp_undefined, dsp_norm, dsp_undefined, dsp_undefined, dsp_undefined, dsp_undefined, dsp_undefined, dsp_undefined, dsp_undefined, - + /* 0x40 - 0x7f */ dsp_tcc, dsp_tcc, dsp_tcc, dsp_tcc, dsp_undefined, dsp_undefined, dsp_undefined, dsp_undefined, dsp_tcc, dsp_tcc, dsp_tcc, dsp_tcc, dsp_undefined, dsp_undefined, dsp_undefined, dsp_undefined, @@ -524,23 +533,23 @@ static const dsp_emul_t opcodes8h[512] = /* 0x80 - 0xbf */ dsp_undefined, dsp_undefined, dsp_undefined, dsp_undefined, dsp_undefined, dsp_undefined, dsp_undefined, dsp_undefined, - dsp_lua, dsp_undefined, dsp_undefined, dsp_undefined, dsp_undefined, dsp_movec_reg, dsp_undefined, dsp_undefined, + dsp_lua, dsp_undefined, dsp_undefined, dsp_undefined, dsp_undefined, dsp_movec_reg, dsp_undefined, dsp_undefined, dsp_undefined, dsp_undefined, dsp_undefined, dsp_undefined, dsp_undefined, dsp_undefined, dsp_undefined, dsp_undefined, - dsp_undefined, dsp_undefined, dsp_undefined, dsp_undefined, dsp_undefined, dsp_movec_reg, dsp_undefined, dsp_undefined, + dsp_undefined, dsp_undefined, dsp_undefined, dsp_undefined, dsp_undefined, dsp_movec_reg, dsp_undefined, dsp_undefined, dsp_undefined, dsp_movec_aa, dsp_undefined, dsp_movec_aa, dsp_undefined, dsp_movec_imm, dsp_undefined, dsp_undefined, dsp_undefined, dsp_movec_ea, dsp_undefined, dsp_movec_ea, dsp_undefined, dsp_movec_imm, dsp_undefined, dsp_undefined, dsp_undefined, dsp_movec_aa, dsp_undefined, dsp_movec_aa, dsp_undefined, dsp_movec_imm, dsp_undefined, dsp_undefined, dsp_undefined, dsp_movec_ea, dsp_undefined, dsp_movec_ea, dsp_undefined, dsp_movec_imm, dsp_undefined, dsp_undefined, - + /* 0xc0 - 0xff */ - dsp_do_aa, dsp_rep_aa, dsp_do_aa, dsp_rep_aa, dsp_do_imm, dsp_rep_imm, dsp_undefined, dsp_undefined, - dsp_do_ea, dsp_rep_ea, dsp_do_ea, dsp_rep_ea, dsp_do_imm, dsp_rep_imm, dsp_undefined, dsp_undefined, - dsp_undefined, dsp_undefined, dsp_undefined, dsp_undefined, dsp_do_imm, dsp_rep_imm, dsp_undefined, dsp_undefined, - dsp_do_reg, dsp_rep_reg, dsp_undefined, dsp_undefined, dsp_do_imm, dsp_rep_imm, dsp_undefined, dsp_undefined, - dsp_movem_aa, dsp_movem_aa, dsp_undefined, dsp_undefined, dsp_undefined, dsp_undefined, dsp_undefined, dsp_undefined, - dsp_undefined, dsp_undefined, dsp_undefined, dsp_undefined, dsp_movem_ea, dsp_movem_ea, dsp_undefined, dsp_undefined, - dsp_movem_aa, dsp_movem_aa, dsp_undefined, dsp_undefined, dsp_undefined, dsp_undefined, dsp_undefined, dsp_undefined, - dsp_undefined, dsp_undefined, dsp_undefined, dsp_undefined, dsp_movem_ea, dsp_movem_ea, dsp_undefined, dsp_undefined, + dsp_do_aa, dsp_rep_aa, dsp_do_aa, dsp_rep_aa, dsp_do_imm, dsp_rep_imm, dsp_undefined, dsp_undefined, + dsp_do_ea, dsp_rep_ea, dsp_do_ea, dsp_rep_ea, dsp_do_imm, dsp_rep_imm, dsp_undefined, dsp_undefined, + dsp_undefined, dsp_undefined, dsp_undefined, dsp_undefined, dsp_do_imm, dsp_rep_imm, dsp_undefined, dsp_undefined, + dsp_do_reg, dsp_rep_reg, dsp_undefined, dsp_undefined, dsp_do_imm, dsp_rep_imm, dsp_undefined, dsp_undefined, + dsp_movem_aa, dsp_movem_aa, dsp_undefined, dsp_undefined, dsp_undefined, dsp_undefined, dsp_undefined, dsp_undefined, + dsp_undefined, dsp_undefined, dsp_undefined, dsp_undefined, dsp_movem_ea, dsp_movem_ea, dsp_undefined, dsp_undefined, + dsp_movem_aa, dsp_movem_aa, dsp_undefined, dsp_undefined, dsp_undefined, dsp_undefined, dsp_undefined, dsp_undefined, + dsp_undefined, dsp_undefined, dsp_undefined, dsp_undefined, dsp_movem_ea, dsp_movem_ea, dsp_undefined, dsp_undefined, /* 0x100 - 0x13f */ dsp_pm_0, dsp_pm_0, dsp_pm_0, dsp_pm_0, dsp_pm_0, dsp_pm_0, dsp_pm_0, dsp_pm_0, @@ -564,23 +573,23 @@ static const dsp_emul_t opcodes8h[512] = /* 0x180 - 0x1bf */ dsp_jmp_imm, dsp_jmp_imm, dsp_jmp_imm, dsp_jmp_imm, dsp_jmp_imm, dsp_jmp_imm, dsp_jmp_imm, dsp_jmp_imm, - dsp_undefined, dsp_undefined, dsp_undefined, dsp_undefined, dsp_undefined, dsp_undefined, dsp_undefined, dsp_undefined, - dsp_undefined, dsp_undefined, dsp_undefined, dsp_undefined, dsp_undefined, dsp_undefined, dsp_undefined, dsp_undefined, - dsp_undefined, dsp_undefined, dsp_undefined, dsp_undefined, dsp_undefined, dsp_undefined, dsp_undefined, dsp_undefined, - dsp_jsr_imm, dsp_jsr_imm, dsp_jsr_imm, dsp_jsr_imm, dsp_jsr_imm, dsp_jsr_imm, dsp_jsr_imm, dsp_jsr_imm, - dsp_undefined, dsp_undefined, dsp_undefined, dsp_undefined, dsp_undefined, dsp_undefined, dsp_undefined, dsp_undefined, - dsp_undefined, dsp_undefined, dsp_undefined, dsp_undefined, dsp_undefined, dsp_undefined, dsp_undefined, dsp_undefined, - dsp_undefined, dsp_undefined, dsp_undefined, dsp_undefined, dsp_undefined, dsp_undefined, dsp_undefined, dsp_undefined, + dsp_undefined, dsp_undefined, dsp_undefined, dsp_undefined, dsp_undefined, dsp_undefined, dsp_undefined, dsp_undefined, + dsp_undefined, dsp_undefined, dsp_undefined, dsp_undefined, dsp_undefined, dsp_undefined, dsp_undefined, dsp_undefined, + dsp_undefined, dsp_undefined, dsp_undefined, dsp_undefined, dsp_undefined, dsp_undefined, dsp_undefined, dsp_undefined, + dsp_jsr_imm, dsp_jsr_imm, dsp_jsr_imm, dsp_jsr_imm, dsp_jsr_imm, dsp_jsr_imm, dsp_jsr_imm, dsp_jsr_imm, + dsp_undefined, dsp_undefined, dsp_undefined, dsp_undefined, dsp_undefined, dsp_undefined, dsp_undefined, dsp_undefined, + dsp_undefined, dsp_undefined, dsp_undefined, dsp_undefined, dsp_undefined, dsp_undefined, dsp_undefined, dsp_undefined, + dsp_undefined, dsp_undefined, dsp_undefined, dsp_undefined, dsp_undefined, dsp_undefined, dsp_undefined, dsp_undefined, /* 0x1c0 - 0x1ff */ - dsp_jcc_imm, dsp_jcc_imm, dsp_jcc_imm, dsp_jcc_imm, dsp_jcc_imm, dsp_jcc_imm, dsp_jcc_imm, dsp_jcc_imm, - dsp_jcc_imm, dsp_jcc_imm, dsp_jcc_imm, dsp_jcc_imm, dsp_jcc_imm, dsp_jcc_imm, dsp_jcc_imm, dsp_jcc_imm, - dsp_jcc_imm, dsp_jcc_imm, dsp_jcc_imm, dsp_jcc_imm, dsp_jcc_imm, dsp_jcc_imm, dsp_jcc_imm, dsp_jcc_imm, - dsp_jcc_imm, dsp_jcc_imm, dsp_jcc_imm, dsp_jcc_imm, dsp_jcc_imm, dsp_jcc_imm, dsp_jcc_imm, dsp_jcc_imm, - dsp_jscc_imm, dsp_jscc_imm, dsp_jscc_imm, dsp_jscc_imm, dsp_jscc_imm, dsp_jscc_imm, dsp_jscc_imm, dsp_jscc_imm, - dsp_jscc_imm, dsp_jscc_imm, dsp_jscc_imm, dsp_jscc_imm, dsp_jscc_imm, dsp_jscc_imm, dsp_jscc_imm, dsp_jscc_imm, - dsp_jscc_imm, dsp_jscc_imm, dsp_jscc_imm, dsp_jscc_imm, dsp_jscc_imm, dsp_jscc_imm, dsp_jscc_imm, dsp_jscc_imm, - dsp_jscc_imm, dsp_jscc_imm, dsp_jscc_imm, dsp_jscc_imm, dsp_jscc_imm, dsp_jscc_imm, dsp_jscc_imm, dsp_jscc_imm, + dsp_jcc_imm, dsp_jcc_imm, dsp_jcc_imm, dsp_jcc_imm, dsp_jcc_imm, dsp_jcc_imm, dsp_jcc_imm, dsp_jcc_imm, + dsp_jcc_imm, dsp_jcc_imm, dsp_jcc_imm, dsp_jcc_imm, dsp_jcc_imm, dsp_jcc_imm, dsp_jcc_imm, dsp_jcc_imm, + dsp_jcc_imm, dsp_jcc_imm, dsp_jcc_imm, dsp_jcc_imm, dsp_jcc_imm, dsp_jcc_imm, dsp_jcc_imm, dsp_jcc_imm, + dsp_jcc_imm, dsp_jcc_imm, dsp_jcc_imm, dsp_jcc_imm, dsp_jcc_imm, dsp_jcc_imm, dsp_jcc_imm, dsp_jcc_imm, + dsp_jscc_imm, dsp_jscc_imm, dsp_jscc_imm, dsp_jscc_imm, dsp_jscc_imm, dsp_jscc_imm, dsp_jscc_imm, dsp_jscc_imm, + dsp_jscc_imm, dsp_jscc_imm, dsp_jscc_imm, dsp_jscc_imm, dsp_jscc_imm, dsp_jscc_imm, dsp_jscc_imm, dsp_jscc_imm, + dsp_jscc_imm, dsp_jscc_imm, dsp_jscc_imm, dsp_jscc_imm, dsp_jscc_imm, dsp_jscc_imm, dsp_jscc_imm, dsp_jscc_imm, + dsp_jscc_imm, dsp_jscc_imm, dsp_jscc_imm, dsp_jscc_imm, dsp_jscc_imm, dsp_jscc_imm, dsp_jscc_imm, dsp_jscc_imm, }; static const dsp_emul_t opcodes_parmove[16] = { @@ -598,7 +607,7 @@ static const dsp_emul_t opcodes_alu[256] dsp_add_x_b, dsp_adc_x_b, dsp_asr_b, dsp_lsr_b, dsp_sub_x_b, dsp_sbc_x_b, dsp_abs_b, dsp_ror_b, dsp_add_y_a, dsp_adc_y_a, dsp_asl_a, dsp_lsl_a, dsp_sub_y_a, dsp_sbc_y_a, dsp_neg_a, dsp_rol_a, dsp_add_y_b, dsp_adc_y_b, dsp_asl_b, dsp_lsl_b, dsp_sub_y_b, dsp_sbc_y_b, dsp_neg_b, dsp_rol_b, - + /* 0x40 - 0x7f */ dsp_add_x0_a, dsp_tfr_x0_a, dsp_or_x0_a, dsp_eor_x0_a, dsp_sub_x0_a, dsp_cmp_x0_a, dsp_and_x0_a, dsp_cmpm_x0_a, dsp_add_x0_b, dsp_tfr_x0_b, dsp_or_x0_b, dsp_eor_x0_b, dsp_sub_x0_b, dsp_cmp_x0_b, dsp_and_x0_b, dsp_cmpm_x0_b, @@ -657,12 +666,12 @@ static const int registers_mask[64] = { 24, 24, 24, 24, 24, 24, 8, 8, 24, 24, 24, 24, - + 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, - + 16, 16, 16, 16, 16, 16, 16, 16, 0, 0, 0, 0, @@ -705,11 +714,11 @@ void dsp56k_init_cpu(void) /** * Execute one instruction in trace mode at a given PC address. * */ -Uint32 dsp56k_execute_one_disasm_instruction(Uint32 pc) +Uint16 dsp56k_execute_one_disasm_instruction(FILE *out, Uint16 pc) { dsp_core_t *ptr1, *ptr2; static dsp_core_t dsp_core_save; - Uint32 instruction_length; + Uint16 instruction_length; ptr1 = &dsp_core; ptr2 = &dsp_core_save; @@ -729,11 +738,11 @@ Uint32 dsp56k_execute_one_disasm_instruc /* Execute instruction at address given in parameter to get the number of cycles it takes */ dsp56k_execute_instruction(); - fprintf(stderr, "%s", dsp56k_getInstructionText()); + fprintf(out, "%s", dsp56k_getInstructionText()); /* Restore DSP context after executing instruction */ memcpy(ptr1, ptr2, sizeof(dsp_core)); - + /* Unset DSP in disasm mode */ isDsp_in_disasm_mode = false; @@ -747,28 +756,31 @@ void dsp56k_execute_instruction(void) disasm_memory_ptr = 0; /* Initialise the number of access to the external memory for this instruction */ - nb_access_to_extMemory = 0; - + access_to_ext_memory = 0; + + /* Init the indirect AGU move instruction flag */ + dsp_core.agu_move_indirect_instr = 0; + /* Decode and execute current instruction */ cur_inst = read_memory_p(dsp_core.pc); - + /* Initialize instruction size and cycle counter */ cur_inst_len = 1; dsp_core.instr_cycle = 2; /* Disasm current instruction ? (trace mode only) */ - if (LOG_TRACE_LEVEL(TRACE_DSP_DISASM)) { + if (LOG_TRACE_LEVEL(TRACE_DSP_DISASM)) { /* Call dsp56k_disasm only when DSP is called in trace mode */ if (isDsp_in_disasm_mode == false) { disasm_return = dsp56k_disasm(DSP_TRACE_MODE); - + if (disasm_return != 0 && LOG_TRACE_LEVEL(TRACE_DSP_DISASM_REG)) { /* DSP regs trace enabled only if DSP DISASM is enabled */ dsp56k_disasm_reg_save(); } } } - + if (cur_inst < 0x100000) { value = (cur_inst >> 11) & (BITMASK(6) << 3); value += (cur_inst >> 5) & BITMASK(3); @@ -779,16 +791,23 @@ void dsp56k_execute_instruction(void) } /* Add the waitstate due to external memory access */ - if (nb_access_to_extMemory > 1) - dsp_core.instr_cycle += nb_access_to_extMemory - 1; - + /* (2 extra cycles per extra access to the external memory after the first one */ + if (access_to_ext_memory != 0) { + value = access_to_ext_memory & 1; + value += (access_to_ext_memory & 2) >> 1; + value += (access_to_ext_memory & 4) >> 2; + + if (value > 1) + dsp_core.instr_cycle += (value - 1) * 2; + } + /* Disasm current instruction ? (trace mode only) */ if (LOG_TRACE_LEVEL(TRACE_DSP_DISASM)) { /* Display only when DSP is called in trace mode */ if (isDsp_in_disasm_mode == false) { if (disasm_return != 0) { fprintf(stderr, "%s", dsp56k_getInstructionText()); - + /* DSP regs trace enabled only if DSP DISASM is enabled */ if (LOG_TRACE_LEVEL(TRACE_DSP_DISASM_REG)) dsp56k_disasm_reg_compare(); @@ -835,7 +854,7 @@ static void dsp_postexecute_update_pc(vo { /* When running a REP, PC must stay on the current instruction */ if (dsp_core.loop_rep) { - /* Is PC on the instruction to repeat ? */ + /* Is PC on the instruction to repeat ? */ if (dsp_core.pc_on_rep==0) { --dsp_core.registers[DSP_REG_LC]; dsp_core.registers[DSP_REG_LC] &= BITMASK(16); @@ -863,20 +882,19 @@ static void dsp_postexecute_update_pc(vo if (dsp_core.registers[DSP_REG_SR] & (1<>23)) & 3; - if (value_u == 0 || value_u == 3) + if (value_u == 0 || value_u == 3) dsp_core.registers[DSP_REG_SR] |= 1 << DSP_SR_U; break; case 2: @@ -1119,7 +1139,7 @@ static void dsp_ccr_update_e_u_n_z(Uint3 dsp_core.registers[DSP_REG_SR] |= 1 << DSP_SR_E; /* Unnormalized bit (U) */ - if ((reg1 & 0x600000) == 0 || (reg1 & 0x600000) == 0x600000) + if ((reg1 & 0x600000) == 0 || (reg1 & 0x600000) == 0x600000) dsp_core.registers[DSP_REG_SR] |= 1 << DSP_SR_U; break; default: @@ -1184,8 +1204,8 @@ static inline Uint32 read_memory_p(Uint1 return dsp_core.ramint[DSP_SPACE_P][address] & BITMASK(24); } - /* Access to the external memory */ - nb_access_to_extMemory ++; + /* Access to the external P memory */ + access_to_ext_memory |= 1 << EXT_P_MEMORY; /* External RAM, mask address to available ram size */ return dsp_core.ramext[address & (DSP_RAMSIZE-1)] & BITMASK(24); @@ -1218,7 +1238,7 @@ static Uint32 read_memory(int space, Uin if (address == 0xffc0+DSP_HOST_HRX) { value = dsp_core.dsp_host_rtx; dsp_core_hostport_dspread(); - } + } else if (address == 0xffc0+DSP_SSI_RX) { value = dsp_core_ssi_readRX(); } @@ -1226,16 +1246,22 @@ static Uint32 read_memory(int space, Uin return value; } - /* Access to the external memory */ - nb_access_to_extMemory ++; - - /* Falcon: External RAM, map X to upper 16K of matching space in Y,P */ + /* Falcon: External X or Y RAM access */ address &= (DSP_RAMSIZE>>1) - 1; if (space == DSP_SPACE_X) { + /* Map X to upper 16K of matching space in Y,P */ address += DSP_RAMSIZE>>1; + + /* Set one access to the X external memory */ + access_to_ext_memory |= 1 << EXT_X_MEMORY; + } + else { + /* Access to the Y external memory */ + access_to_ext_memory |= 1 << EXT_Y_MEMORY; } + /* Falcon: External RAM, finally map X,Y to P */ return dsp_core.ramext[address & (DSP_RAMSIZE-1)] & BITMASK(24); } @@ -1244,7 +1270,7 @@ static inline void write_memory(int spac { if (unlikely(LOG_TRACE_LEVEL(TRACE_DSP_DISASM_MEM))) write_memory_disasm(space, address, value); - else + else write_memory_raw(space, address, value); } @@ -1295,13 +1321,13 @@ static void write_memory_raw(int space, break; } return; - } + } else if (space == DSP_SPACE_Y) { dsp_core.periph[DSP_SPACE_Y][address-0xffc0] = value; return; } } - + /* Internal RAM ? */ if (address < 0x100) { dsp_core.ramint[space][address] = value; @@ -1323,16 +1349,25 @@ static void write_memory_raw(int space, } } - /* Access to the external memory */ - nb_access_to_extMemory ++; + /* Access to X, Y or P external RAM */ - /* Falcon: External RAM, map X to upper 16K of matching space in Y,P */ - if (space != DSP_SPACE_P) { + if (space == DSP_SPACE_P) { + /* Access to the P external RAM */ + access_to_ext_memory |= 1 << EXT_P_MEMORY; + } + else { address &= (DSP_RAMSIZE>>1) - 1; - } - if (space == DSP_SPACE_X) { - address += DSP_RAMSIZE>>1; + if (space == DSP_SPACE_X) { + /* Access to the X external RAM */ + /* map X to upper 16K of matching space in Y,P */ + address += DSP_RAMSIZE>>1; + access_to_ext_memory |= 1; + } + else { + /* Access to the Y external RAM */ + access_to_ext_memory |= 1 << EXT_Y_MEMORY; + } } /* Falcon: External RAM, map X,Y to P */ @@ -1372,14 +1407,40 @@ static void dsp_write_reg(Uint32 numreg, switch (numreg) { case DSP_REG_A: dsp_core.registers[DSP_REG_A0] = 0; - dsp_core.registers[DSP_REG_A1] = value; + dsp_core.registers[DSP_REG_A1] = value & BITMASK(24); dsp_core.registers[DSP_REG_A2] = value & (1<<23) ? 0xff : 0x0; break; case DSP_REG_B: dsp_core.registers[DSP_REG_B0] = 0; - dsp_core.registers[DSP_REG_B1] = value; + dsp_core.registers[DSP_REG_B1] = value & BITMASK(24); dsp_core.registers[DSP_REG_B2] = value & (1<<23) ? 0xff : 0x0; break; + case DSP_REG_R0: + case DSP_REG_R1: + case DSP_REG_R2: + case DSP_REG_R3: + case DSP_REG_R4: + case DSP_REG_R5: + case DSP_REG_R6: + case DSP_REG_R7: + case DSP_REG_N0: + case DSP_REG_N1: + case DSP_REG_N2: + case DSP_REG_N3: + case DSP_REG_N4: + case DSP_REG_N5: + case DSP_REG_N6: + case DSP_REG_N7: + case DSP_REG_M0: + case DSP_REG_M1: + case DSP_REG_M2: + case DSP_REG_M3: + case DSP_REG_M4: + case DSP_REG_M5: + case DSP_REG_M6: + case DSP_REG_M7: + dsp_core.registers[numreg] = value & BITMASK(16); + break; case DSP_REG_OMR: dsp_core.registers[DSP_REG_OMR] = value & 0xc7; break; @@ -1387,14 +1448,18 @@ static void dsp_write_reg(Uint32 numreg, dsp_core.registers[DSP_REG_SR] = value & 0xaf7f; break; case DSP_REG_SP: - stack_error = dsp_core.registers[DSP_REG_SP] & (1<> DSP_SR_N) & 1; value2 = (dsp_core.registers[DSP_REG_SR] >> DSP_SR_V) & 1; value3 = (dsp_core.registers[DSP_REG_SR] >> DSP_SR_Z) & 1; @@ -1762,6 +1831,9 @@ static void opcode8h_0(void) case 0x00008c: dsp_enddo(); break; + default: + dsp_undefined(); + break; } } @@ -1781,6 +1853,9 @@ static void dsp_undefined(void) cur_inst_len = 1; dsp_core.instr_cycle = 0; } + if (ExceptionDebugMask & EXCEPT_DSP) { + DebugUI(REASON_DSP_EXCEPTION); + } } static void dsp_andi(void) @@ -1808,7 +1883,7 @@ static void dsp_andi(void) static void dsp_bchg_aa(void) { Uint32 memspace, addr, value, newcarry, numbit; - + memspace = (cur_inst>>6) & 1; value = (cur_inst>>8) & BITMASK(6); numbit = cur_inst & BITMASK(5); @@ -1833,7 +1908,7 @@ static void dsp_bchg_aa(void) static void dsp_bchg_ea(void) { Uint32 memspace, addr, value, newcarry, numbit; - + memspace = (cur_inst>>6) & 1; value = (cur_inst>>8) & BITMASK(6); numbit = cur_inst & BITMASK(5); @@ -1858,7 +1933,7 @@ static void dsp_bchg_ea(void) static void dsp_bchg_pp(void) { Uint32 memspace, addr, value, newcarry, numbit; - + memspace = (cur_inst>>6) & 1; value = (cur_inst>>8) & BITMASK(6); numbit = cur_inst & BITMASK(5); @@ -1883,7 +1958,7 @@ static void dsp_bchg_pp(void) static void dsp_bchg_reg(void) { Uint32 value, numreg, newcarry, numbit; - + numreg = (cur_inst>>8) & BITMASK(6); numbit = cur_inst & BITMASK(5); @@ -1912,7 +1987,7 @@ static void dsp_bchg_reg(void) static void dsp_bclr_aa(void) { Uint32 memspace, addr, value, newcarry, numbit; - + memspace = (cur_inst>>6) & 1; addr = (cur_inst>>8) & BITMASK(6); numbit = cur_inst & BITMASK(5); @@ -1932,7 +2007,7 @@ static void dsp_bclr_aa(void) static void dsp_bclr_ea(void) { Uint32 memspace, addr, value, newcarry, numbit; - + memspace = (cur_inst>>6) & 1; value = (cur_inst>>8) & BITMASK(6); numbit = cur_inst & BITMASK(5); @@ -1953,7 +2028,7 @@ static void dsp_bclr_ea(void) static void dsp_bclr_pp(void) { Uint32 memspace, addr, value, newcarry, numbit; - + memspace = (cur_inst>>6) & 1; value = (cur_inst>>8) & BITMASK(6); numbit = cur_inst & BITMASK(5); @@ -1974,7 +2049,7 @@ static void dsp_bclr_pp(void) static void dsp_bclr_reg(void) { Uint32 value, numreg, newcarry, numbit; - + numreg = (cur_inst>>8) & BITMASK(6); numbit = cur_inst & BITMASK(5); @@ -1999,7 +2074,7 @@ static void dsp_bclr_reg(void) static void dsp_bset_aa(void) { Uint32 memspace, addr, value, newcarry, numbit; - + memspace = (cur_inst>>6) & 1; value = (cur_inst>>8) & BITMASK(6); numbit = cur_inst & BITMASK(5); @@ -2020,7 +2095,7 @@ static void dsp_bset_aa(void) static void dsp_bset_ea(void) { Uint32 memspace, addr, value, newcarry, numbit; - + memspace = (cur_inst>>6) & 1; value = (cur_inst>>8) & BITMASK(6); numbit = cur_inst & BITMASK(5); @@ -2041,7 +2116,7 @@ static void dsp_bset_ea(void) static void dsp_bset_pp(void) { Uint32 memspace, addr, value, newcarry, numbit; - + memspace = (cur_inst>>6) & 1; value = (cur_inst>>8) & BITMASK(6); numbit = cur_inst & BITMASK(5); @@ -2061,7 +2136,7 @@ static void dsp_bset_pp(void) static void dsp_bset_reg(void) { Uint32 value, numreg, newcarry, numbit; - + numreg = (cur_inst>>8) & BITMASK(6); numbit = cur_inst & BITMASK(5); @@ -2086,7 +2161,7 @@ static void dsp_bset_reg(void) static void dsp_btst_aa(void) { Uint32 memspace, addr, value, newcarry, numbit; - + memspace = (cur_inst>>6) & 1; value = (cur_inst>>8) & BITMASK(6); numbit = cur_inst & BITMASK(5); @@ -2105,7 +2180,7 @@ static void dsp_btst_aa(void) static void dsp_btst_ea(void) { Uint32 memspace, addr, value, newcarry, numbit; - + memspace = (cur_inst>>6) & 1; value = (cur_inst>>8) & BITMASK(6); numbit = cur_inst & BITMASK(5); @@ -2124,7 +2199,7 @@ static void dsp_btst_ea(void) static void dsp_btst_pp(void) { Uint32 memspace, addr, value, newcarry, numbit; - + memspace = (cur_inst>>6) & 1; value = (cur_inst>>8) & BITMASK(6); numbit = cur_inst & BITMASK(5); @@ -2143,7 +2218,7 @@ static void dsp_btst_pp(void) static void dsp_btst_reg(void) { Uint32 value, numreg, newcarry, numbit; - + numreg = (cur_inst>>8) & BITMASK(6); numbit = cur_inst & BITMASK(5); @@ -2212,7 +2287,7 @@ static void dsp_div(void) dsp_core.registers[DSP_REG_B1] = dest[1]; dsp_core.registers[DSP_REG_B0] = dest[2]; } - + dsp_core.registers[DSP_REG_SR] &= BITMASK(16)-((1<>7) & 1))<>8) & BITMASK(6); if ((numreg == DSP_REG_A) || (numreg == DSP_REG_B)) { - dsp_pm_read_accu24(numreg, &dsp_core.registers[DSP_REG_LC]); + dsp_pm_read_accu24(numreg, &dsp_core.registers[DSP_REG_LC]); } else { dsp_core.registers[DSP_REG_LC] = dsp_core.registers[numreg]; } @@ -2323,6 +2398,9 @@ static void dsp_illegal(void) { /* Raise interrupt p:0x003e */ dsp_add_interrupt(DSP_INTER_ILLEGAL); + if (ExceptionDebugMask & EXCEPT_DSP) { + DebugUI(REASON_DSP_EXCEPTION); + } } static void dsp_jcc_imm(void) @@ -2357,7 +2435,7 @@ static void dsp_jcc_ea(void) static void dsp_jclr_aa(void) { Uint32 memspace, addr, value, numbit, newaddr; - + memspace = (cur_inst>>6) & 1; addr = (cur_inst>>8) & BITMASK(6); numbit = cur_inst & BITMASK(5); @@ -2370,19 +2448,19 @@ static void dsp_jclr_aa(void) dsp_core.pc = newaddr; cur_inst_len = 0; return; - } + } ++cur_inst_len; } static void dsp_jclr_ea(void) { Uint32 memspace, addr, value, numbit, newaddr; - + memspace = (cur_inst>>6) & 1; value = (cur_inst>>8) & BITMASK(6); numbit = cur_inst & BITMASK(5); newaddr = read_memory_p(dsp_core.pc+1); - + dsp_calc_ea(value, &addr); value = read_memory(memspace, addr); @@ -2392,14 +2470,14 @@ static void dsp_jclr_ea(void) dsp_core.pc = newaddr; cur_inst_len = 0; return; - } + } ++cur_inst_len; } static void dsp_jclr_pp(void) { Uint32 memspace, addr, value, numbit, newaddr; - + memspace = (cur_inst>>6) & 1; value = (cur_inst>>8) & BITMASK(6); numbit = cur_inst & BITMASK(5); @@ -2413,14 +2491,14 @@ static void dsp_jclr_pp(void) dsp_core.pc = newaddr; cur_inst_len = 0; return; - } + } ++cur_inst_len; } static void dsp_jclr_reg(void) { Uint32 value, numreg, numbit, newaddr; - + numreg = (cur_inst>>8) & BITMASK(6); numbit = cur_inst & BITMASK(5); newaddr = read_memory_p(dsp_core.pc+1); @@ -2437,7 +2515,7 @@ static void dsp_jclr_reg(void) dsp_core.pc = newaddr; cur_inst_len = 0; return; - } + } ++cur_inst_len; } @@ -2474,7 +2552,7 @@ static void dsp_jscc_ea(void) dsp_stack_push(dsp_core.pc+cur_inst_len, dsp_core.registers[DSP_REG_SR], 0); dsp_core.pc = newpc; cur_inst_len = 0; - } + } dsp_core.instr_cycle += 2; } @@ -2489,7 +2567,7 @@ static void dsp_jscc_imm(void) dsp_stack_push(dsp_core.pc+cur_inst_len, dsp_core.registers[DSP_REG_SR], 0); dsp_core.pc = newpc; cur_inst_len = 0; - } + } dsp_core.instr_cycle += 2; } @@ -2497,29 +2575,29 @@ static void dsp_jscc_imm(void) static void dsp_jsclr_aa(void) { Uint32 memspace, addr, value, newpc, numbit, newaddr; - + memspace = (cur_inst>>6) & 1; addr = (cur_inst>>8) & BITMASK(6); numbit = cur_inst & BITMASK(5); value = read_memory(memspace, addr); newaddr = read_memory_p(dsp_core.pc+1); - + dsp_core.instr_cycle += 4; - + if ((value & (1<>6) & 1; value = (cur_inst>>8) & BITMASK(6); numbit = cur_inst & BITMASK(5); @@ -2528,21 +2606,21 @@ static void dsp_jsclr_ea(void) newaddr = read_memory_p(dsp_core.pc+1); dsp_core.instr_cycle += 4; - + if ((value & (1<>6) & 1; value = (cur_inst>>8) & BITMASK(6); numbit = cur_inst & BITMASK(5); @@ -2551,21 +2629,21 @@ static void dsp_jsclr_pp(void) newaddr = read_memory_p(dsp_core.pc+1); dsp_core.instr_cycle += 4; - + if ((value & (1<>8) & BITMASK(6); numbit = cur_inst & BITMASK(5); newaddr = read_memory_p(dsp_core.pc+1); @@ -2577,21 +2655,21 @@ static void dsp_jsclr_reg(void) } dsp_core.instr_cycle += 4; - + if ((value & (1<>6) & 1; addr = (cur_inst>>8) & BITMASK(6); numbit = cur_inst & BITMASK(5); @@ -2599,20 +2677,20 @@ static void dsp_jset_aa(void) newaddr = read_memory_p(dsp_core.pc+1); dsp_core.instr_cycle += 4; - + if (value & (1<>6) & 1; value = (cur_inst>>8) & BITMASK(6); numbit = cur_inst & BITMASK(5); @@ -2627,14 +2705,14 @@ static void dsp_jset_ea(void) dsp_core.pc = newpc; cur_inst_len=0; return; - } + } ++cur_inst_len; } static void dsp_jset_pp(void) { Uint32 memspace, addr, value, numbit, newpc, newaddr; - + memspace = (cur_inst>>6) & 1; value = (cur_inst>>8) & BITMASK(6); numbit = cur_inst & BITMASK(5); @@ -2643,24 +2721,24 @@ static void dsp_jset_pp(void) newaddr = read_memory_p(dsp_core.pc+1); dsp_core.instr_cycle += 4; - + if (value & (1<>8) & BITMASK(6); numbit = cur_inst & BITMASK(5); newaddr = read_memory_p(dsp_core.pc+1); - + if ((numreg==DSP_REG_A) || (numreg==DSP_REG_B)) { dsp_pm_read_accu24(numreg, &value); } else { @@ -2668,13 +2746,13 @@ static void dsp_jset_reg(void) } dsp_core.instr_cycle += 4; - + if (value & (1<>6) & 1; addr = (cur_inst>>8) & BITMASK(6); numbit = cur_inst & BITMASK(5); value = read_memory(memspace, addr); newaddr = read_memory_p(dsp_core.pc+1); - + dsp_core.instr_cycle += 4; if (value & (1<>6) & 1; value = (cur_inst>>8) & BITMASK(6); numbit = cur_inst & BITMASK(5); dsp_calc_ea(value, &addr); value = read_memory(memspace, addr); newaddr = read_memory_p(dsp_core.pc+1); - + dsp_core.instr_cycle += 4; if (value & (1<>6) & 1; value = (cur_inst>>8) & BITMASK(6); numbit = cur_inst & BITMASK(5); @@ -2780,18 +2858,18 @@ static void dsp_jsset_pp(void) dsp_core.pc = newpc; cur_inst_len = 0; return; - } + } ++cur_inst_len; } static void dsp_jsset_reg(void) { Uint32 value, numreg, newpc, numbit, newaddr; - + numreg = (cur_inst>>8) & BITMASK(6); numbit = cur_inst & BITMASK(5); newaddr = read_memory_p(dsp_core.pc+1); - + if ((numreg==DSP_REG_A) || (numreg==DSP_REG_B)) { dsp_pm_read_accu24(numreg, &value); } else { @@ -2806,7 +2884,7 @@ static void dsp_jsset_reg(void) dsp_core.pc = newpc; cur_inst_len = 0; return; - } + } ++cur_inst_len; } @@ -2821,14 +2899,13 @@ static void dsp_lua(void) srcnew = dsp_core.registers[DSP_REG_R0+srcreg]; dsp_core.registers[DSP_REG_R0+srcreg] = srcsave; - dstreg = cur_inst & BITMASK(3); - - if (cur_inst & (1<<3)) { - dsp_core.registers[DSP_REG_N0+dstreg] = srcnew; - } else { - dsp_core.registers[DSP_REG_R0+dstreg] = srcnew; - } + if (cur_inst & (1<<3)) + dstreg = DSP_REG_N0 + (cur_inst & BITMASK(3)); + else + dstreg = DSP_REG_R0 + (cur_inst & BITMASK(3)); + dsp_core.agu_move_indirect_instr = 1; + dsp_write_reg(dstreg, srcnew); dsp_core.instr_cycle += 2; } @@ -2842,38 +2919,27 @@ static void dsp_movec_reg(void) numreg2 = (cur_inst>>8) & BITMASK(6); numreg1 = cur_inst & BITMASK(6); + dsp_core.agu_move_indirect_instr = 1; + if (cur_inst & (1<<15)) { /* Write D1 */ if ((numreg2 == DSP_REG_A) || (numreg2 == DSP_REG_B)) { - dsp_pm_read_accu24(numreg2, &value); + dsp_pm_read_accu24(numreg2, &value); } else { value = dsp_core.registers[numreg2]; } - value &= BITMASK(registers_mask[numreg1]); dsp_write_reg(numreg1, value); } else { /* Read S1 */ if (numreg1 == DSP_REG_SSH) { dsp_stack_pop(&value, &dummy); - } + } else { value = dsp_core.registers[numreg1]; } - if (numreg2 == DSP_REG_A) { - dsp_core.registers[DSP_REG_A0] = 0; - dsp_core.registers[DSP_REG_A1] = value & BITMASK(24); - dsp_core.registers[DSP_REG_A2] = value & (1<<23) ? 0xff : 0x0; - } - else if (numreg2 == DSP_REG_B) { - dsp_core.registers[DSP_REG_B0] = 0; - dsp_core.registers[DSP_REG_B1] = value & BITMASK(24); - dsp_core.registers[DSP_REG_B2] = value & (1<<23) ? 0xff : 0x0; - } - else { - dsp_core.registers[numreg2] = value & BITMASK(registers_mask[numreg2]); - } + dsp_write_reg(numreg2, value); } } @@ -2893,13 +2959,13 @@ static void dsp_movec_aa(void) if (cur_inst & (1<<15)) { /* Write D1 */ value = read_memory(memspace, addr); - value &= BITMASK(registers_mask[numreg]); + dsp_core.agu_move_indirect_instr = 1; dsp_write_reg(numreg, value); } else { /* Read S1 */ if (numreg == DSP_REG_SSH) { dsp_stack_pop(&value, &dummy); - } + } else { value = dsp_core.registers[numreg]; } @@ -2914,7 +2980,7 @@ static void dsp_movec_imm(void) /* #xx,D1 */ numreg = cur_inst & BITMASK(6); value = (cur_inst>>8) & BITMASK(8); - value &= BITMASK(registers_mask[numreg]); + dsp_core.agu_move_indirect_instr = 1; dsp_write_reg(numreg, value); } @@ -2941,14 +3007,14 @@ static void dsp_movec_ea(void) } else { value = read_memory(memspace, addr); } - value &= BITMASK(registers_mask[numreg]); + dsp_core.agu_move_indirect_instr = 1; dsp_write_reg(numreg, value); } else { /* Read S1 */ dsp_calc_ea(ea_mode, &addr); if (numreg == DSP_REG_SSH) { dsp_stack_pop(&value, &dummy); - } + } else { value = dsp_core.registers[numreg]; } @@ -2966,16 +3032,16 @@ static void dsp_movem_aa(void) if (cur_inst & (1<<15)) { /* Write D */ value = read_memory_p(addr); - value &= BITMASK(registers_mask[numreg]); + dsp_core.agu_move_indirect_instr = 1; dsp_write_reg(numreg, value); } else { /* Read S */ if (numreg == DSP_REG_SSH) { dsp_stack_pop(&value, &dummy); - } + } else if ((numreg == DSP_REG_A) || (numreg == DSP_REG_B)) { - dsp_pm_read_accu24(numreg, &value); - } + dsp_pm_read_accu24(numreg, &value); + } else { value = dsp_core.registers[numreg]; } @@ -2996,16 +3062,16 @@ static void dsp_movem_ea(void) if (cur_inst & (1<<15)) { /* Write D */ value = read_memory_p(addr); - value &= BITMASK(registers_mask[numreg]); + dsp_core.agu_move_indirect_instr = 1; dsp_write_reg(numreg, value); } else { /* Read S */ if (numreg == DSP_REG_SSH) { dsp_stack_pop(&value, &dummy); - } + } else if ((numreg == DSP_REG_A) || (numreg == DSP_REG_B)) { - dsp_pm_read_accu24(numreg, &value); - } + dsp_pm_read_accu24(numreg, &value); + } else { value = dsp_core.registers[numreg]; } @@ -3021,7 +3087,7 @@ static void dsp_movep_0(void) /* x:pp,D */ /* S,y:pp */ /* y:pp,D */ - + Uint32 addr, memspace, numreg, value, dummy; addr = 0xffc0 + (cur_inst & BITMASK(6)); @@ -3031,7 +3097,7 @@ static void dsp_movep_0(void) if (cur_inst & (1<<15)) { /* Write pp */ if ((numreg == DSP_REG_A) || (numreg == DSP_REG_B)) { - dsp_pm_read_accu24(numreg, &value); + dsp_pm_read_accu24(numreg, &value); } else if (numreg == DSP_REG_SSH) { dsp_stack_pop(&value, &dummy); @@ -3043,7 +3109,7 @@ static void dsp_movep_0(void) } else { /* Read pp */ value = read_memory(memspace, addr); - value &= BITMASK(registers_mask[numreg]); + dsp_core.agu_move_indirect_instr = 1; dsp_write_reg(numreg, value); } @@ -3095,14 +3161,14 @@ static void dsp_movep_23(void) peraddr = 0xffc0 + (cur_inst & BITMASK(6)); perspace = (cur_inst>>16) & 1; - + ea_mode = (cur_inst>>8) & BITMASK(6); easpace = (cur_inst>>6) & 1; retour = dsp_calc_ea(ea_mode, &addr); if (cur_inst & (1<<15)) { /* Write pp */ - + if (retour) { write_memory(perspace, peraddr, addr); } else { @@ -3243,7 +3309,7 @@ static void dsp_rep_reg(void) numreg = (cur_inst>>8) & BITMASK(6); if ((numreg == DSP_REG_A) || (numreg == DSP_REG_B)) { - dsp_pm_read_accu24(numreg, &dsp_core.registers[DSP_REG_LC]); + dsp_pm_read_accu24(numreg, &dsp_core.registers[DSP_REG_LC]); } else { dsp_core.registers[DSP_REG_LC] = dsp_core.registers[numreg]; } @@ -3297,7 +3363,7 @@ static void dsp_tcc(void) Uint32 cc_code, regsrc1, regdest1; Uint32 regsrc2, regdest2; Uint32 val0, val1, val2; - + cc_code = (cur_inst>>12) & BITMASK(4); if (dsp_calc_cc(cc_code)) { @@ -3320,7 +3386,7 @@ static void dsp_tcc(void) val1 = dsp_core.registers[regsrc1]; val2 = val1 & (1<<23) ? 0xff : 0x0; } - + /* Write D1 */ if (regdest1 == DSP_REG_A) { dsp_core.registers[DSP_REG_A2] = val2; @@ -3338,7 +3404,8 @@ static void dsp_tcc(void) regsrc2 = DSP_REG_R0+((cur_inst>>8) & BITMASK(3)); regdest2 = DSP_REG_R0+(cur_inst & BITMASK(3)); - dsp_core.registers[regdest2] = dsp_core.registers[regsrc2]; + dsp_core.agu_move_indirect_instr = 1; + dsp_write_reg(regdest2, dsp_core.registers[regsrc2]); } } } @@ -3375,7 +3442,7 @@ static int dsp_pm_read_accu24(int numreg value |= (dsp_core.registers[DSP_REG_A0+reg]>>23) & 1; break; /* indeterminate */ - case 3: + case 3: break; } @@ -3387,7 +3454,7 @@ static int dsp_pm_read_accu24(int numreg /* No limiting */ *dest=value; return 0; - } + } } if (dsp_core.registers[DSP_REG_A2+reg] == 0xff) { @@ -3395,7 +3462,7 @@ static int dsp_pm_read_accu24(int numreg /* No limiting */ *dest=value; return 0; - } + } } if (dsp_core.registers[DSP_REG_A2+reg] & (1<<7)) { @@ -3408,7 +3475,7 @@ static int dsp_pm_read_accu24(int numreg *dest=0x007fffff; dsp_core.registers[DSP_REG_SR] |= (1<>16) & 1; dsp_calc_ea((cur_inst>>8) & BITMASK(6), &addr); - /* Save A or B */ + /* Save A or B */ dsp_pm_read_accu24(numreg, &save_accu); /* Save X0 or Y0 */ @@ -3433,7 +3500,7 @@ static void dsp_pm_0(void) /* Execute parallel instruction */ opcodes_alu[cur_inst & BITMASK(8)](); - /* Move [A|B] to [x|y]:ea */ + /* Move [A|B] to [x|y]:ea */ write_memory(memspace, addr, save_accu); /* Move [x|y]0 to [A|B] */ @@ -3446,15 +3513,15 @@ static void dsp_pm_1(void) { Uint32 memspace, numreg1, numreg2, value, xy_addr, retour, save_1, save_2; /* - 0001 ffdf w0mm mrrr x:ea,D1 S2,D2 + 0001 ffdf w0mm mrrr x:ea,D1 S2,D2 S1,x:ea S2,D2 #xxxxxx,D1 S2,D2 - 0001 deff w1mm mrrr S1,D1 y:ea,D2 + 0001 deff w1mm mrrr S1,D1 y:ea,D2 S1,D1 S2,y:ea S1,D1 #xxxxxx,D2 */ value = (cur_inst>>8) & BITMASK(6); - retour = dsp_calc_ea(value, &xy_addr); + retour = dsp_calc_ea(value, &xy_addr); memspace = (cur_inst>>14) & 1; numreg1 = numreg2 = DSP_REG_NULL; @@ -3489,7 +3556,7 @@ static void dsp_pm_1(void) else save_1 = dsp_core.registers[numreg1]; } - + /* S2 */ if (memspace) { /* Y: */ @@ -3497,9 +3564,9 @@ static void dsp_pm_1(void) } else { /* X: */ numreg2 = DSP_REG_A + ((cur_inst>>17) & 1); - } + } dsp_pm_read_accu24(numreg2, &save_2); - + /* Execute parallel instruction */ opcodes_alu[cur_inst & BITMASK(8)](); @@ -3508,18 +3575,7 @@ static void dsp_pm_1(void) /* Write parallel move values */ if (cur_inst & (1<<15)) { /* Write D1 */ - if (numreg1 == DSP_REG_A) { - dsp_core.registers[DSP_REG_A0] = 0x0; - dsp_core.registers[DSP_REG_A1] = save_1; - dsp_core.registers[DSP_REG_A2] = save_1 & (1<<23) ? 0xff : 0x0; - } - else if (numreg1 == DSP_REG_B) { - dsp_core.registers[DSP_REG_B0] = 0x0; - dsp_core.registers[DSP_REG_B1] = save_1; - dsp_core.registers[DSP_REG_B2] = save_1 & (1<<23) ? 0xff : 0x0; - } - else { - } dsp_core.registers[numreg1] = save_1; + dsp_write_reg(numreg1, save_1); } else { /* Read S1 */ write_memory(memspace, xy_addr, save_1); @@ -3532,7 +3588,7 @@ static void dsp_pm_1(void) } else { /* X: */ numreg2 = DSP_REG_Y0 + ((cur_inst>>16) & 1); - } + } dsp_core.registers[numreg2] = save_2; } @@ -3572,7 +3628,7 @@ static void dsp_pm_2_2(void) 0010 00ee eeed dddd S,D */ Uint32 srcreg, dstreg, save_reg; - + srcreg = (cur_inst >> 13) & BITMASK(5); dstreg = (cur_inst >> 8) & BITMASK(5); @@ -3586,19 +3642,8 @@ static void dsp_pm_2_2(void) opcodes_alu[cur_inst & BITMASK(8)](); /* Write reg */ - if (dstreg == DSP_REG_A) { - dsp_core.registers[DSP_REG_A0] = 0x0; - dsp_core.registers[DSP_REG_A1] = save_reg; - dsp_core.registers[DSP_REG_A2] = save_reg & (1<<23) ? 0xff : 0x0; - } - else if (dstreg == DSP_REG_B) { - dsp_core.registers[DSP_REG_B0] = 0x0; - dsp_core.registers[DSP_REG_B1] = save_reg; - dsp_core.registers[DSP_REG_B2] = save_reg & (1<<23) ? 0xff : 0x0; - } - else { - dsp_core.registers[dstreg] = save_reg & BITMASK(registers_mask[dstreg]); - } + dsp_core.agu_move_indirect_instr = 1; + dsp_write_reg(dstreg, save_reg); } static void dsp_pm_3(void) @@ -3626,19 +3671,8 @@ static void dsp_pm_3(void) break; } - if (dstreg == DSP_REG_A) { - dsp_core.registers[DSP_REG_A0] = 0x0; - dsp_core.registers[DSP_REG_A1] = srcvalue; - dsp_core.registers[DSP_REG_A2] = srcvalue & (1<<23) ? 0xff : 0x0; - } - else if (dstreg == DSP_REG_B) { - dsp_core.registers[DSP_REG_B0] = 0x0; - dsp_core.registers[DSP_REG_B1] = srcvalue; - dsp_core.registers[DSP_REG_B2] = srcvalue & (1<<23) ? 0xff : 0x0; - } - else { - dsp_core.registers[dstreg] = srcvalue & BITMASK(registers_mask[dstreg]); - } + dsp_core.agu_move_indirect_instr = 1; + dsp_write_reg(dstreg, srcvalue); } static void dsp_pm_4(void) @@ -3678,7 +3712,7 @@ static void dsp_pm_4x(void) */ value = (cur_inst>>8) & BITMASK(6); if (cur_inst & (1<<14)) { - dsp_calc_ea(value, &l_addr); + dsp_calc_ea(value, &l_addr); } else { l_addr = value; } @@ -3686,11 +3720,6 @@ static void dsp_pm_4x(void) numreg = (cur_inst>>16) & BITMASK(2); numreg |= (cur_inst>>17) & (1<<2); - /* 2 more cycles are needed if address is in external memory */ - if (l_addr>=0x200) { - dsp_core.instr_cycle += 2; - } - if (cur_inst & (1<<15)) { /* Write D */ save_lx = read_memory(DSP_SPACE_X,l_addr); @@ -3741,13 +3770,13 @@ static void dsp_pm_4x(void) break; case 6: /* AB */ - dsp_pm_read_accu24(DSP_REG_A, &save_lx); - dsp_pm_read_accu24(DSP_REG_B, &save_ly); + dsp_pm_read_accu24(DSP_REG_A, &save_lx); + dsp_pm_read_accu24(DSP_REG_B, &save_ly); break; case 7: /* BA */ - dsp_pm_read_accu24(DSP_REG_B, &save_lx); - dsp_pm_read_accu24(DSP_REG_A, &save_ly); + dsp_pm_read_accu24(DSP_REG_B, &save_lx); + dsp_pm_read_accu24(DSP_REG_A, &save_ly); break; } } @@ -3829,7 +3858,7 @@ static void dsp_pm_5(void) value = (cur_inst>>8) & BITMASK(6); if (cur_inst & (1<<14)) { - retour = dsp_calc_ea(value, &xy_addr); + retour = dsp_calc_ea(value, &xy_addr); } else { xy_addr = value; retour = 0; @@ -3860,19 +3889,8 @@ static void dsp_pm_5(void) if (cur_inst & (1<<15)) { /* Write D */ - if (numreg == DSP_REG_A) { - dsp_core.registers[DSP_REG_A0] = 0x0; - dsp_core.registers[DSP_REG_A1] = value; - dsp_core.registers[DSP_REG_A2] = value & (1<<23) ? 0xff : 0x0; - } - else if (numreg == DSP_REG_B) { - dsp_core.registers[DSP_REG_B0] = 0x0; - dsp_core.registers[DSP_REG_B1] = value; - dsp_core.registers[DSP_REG_B2] = value & (1<<23) ? 0xff : 0x0; - } - else { - dsp_core.registers[numreg] = value & BITMASK(registers_mask[numreg]); - } + dsp_core.agu_move_indirect_instr = 1; + dsp_write_reg(numreg, value); } else { /* Read S */ @@ -3886,7 +3904,7 @@ static void dsp_pm_8(void) Uint32 numreg1, numreg2; Uint32 save_reg1, save_reg2, x_addr, y_addr; /* - 1wmm eeff WrrM MRRR x:ea,D1 y:ea,D2 + 1wmm eeff WrrM MRRR x:ea,D1 y:ea,D2 x:ea,D1 S2,y:ea S1,x:ea y:ea,D2 S1,x:ea S2,y:ea @@ -3909,11 +3927,6 @@ static void dsp_pm_8(void) dsp_calc_ea(ea1, &x_addr); dsp_calc_ea(ea2, &y_addr); - /* 2 more cycles are needed if X:address1 and Y:address2 are both in external memory */ - if ((x_addr>=0x200) && (y_addr>=0x200)) { - dsp_core.instr_cycle += 2; - } - switch((cur_inst>>18) & BITMASK(2)) { case 0: numreg1=DSP_REG_X0; break; case 1: numreg1=DSP_REG_X1; break; @@ -3926,7 +3939,7 @@ static void dsp_pm_8(void) case 2: numreg2=DSP_REG_A; break; case 3: numreg2=DSP_REG_B; break; } - + if (cur_inst & (1<<15)) { /* Write D1 */ save_reg1 = read_memory(DSP_SPACE_X, x_addr); @@ -4041,7 +4054,7 @@ static Uint16 dsp_asl56(Uint32 *dest) dest[1] <<= 1; dest[1] |= (dest[2]>>23) & 1; dest[1] &= BITMASK(24); - + dest[2] <<= 1; dest[2] &= BITMASK(24); @@ -4102,7 +4115,7 @@ static Uint16 dsp_sub56(Uint32 *source, dest_save = dest[0]; - /* Substract source from dest: D = D-S */ + /* Subtract source from dest: D = D-S */ dest[2] -= source[2]; dest[1] -= source[1]+((dest[2]>>24) & 1); dest[0] -= source[0]+((dest[1]>>24) & 1); @@ -4208,7 +4221,7 @@ static void dsp_rnd56(Uint32 *dest) rnd_const[1] = 0; rnd_const[2] = (1<<22); dsp_add56(rnd_const, dest); - + if ((dest[2] & 0x7fffff) == 0){ dest[2] = 0; } @@ -4291,7 +4304,7 @@ static void dsp_adc_x_a(void) source[0] = source[1] & (1<<23) ? 0xff : 0x0; newsr = dsp_add56(source, dest); - + if (curcarry) { source[0]=0; source[1]=0; source[2]=1; newsr |= dsp_add56(source, dest); @@ -4323,7 +4336,7 @@ static void dsp_adc_x_b(void) source[0] = source[1] & (1<<23) ? 0xff : 0x0; newsr = dsp_add56(source, dest); - + if (curcarry) { source[0]=0; source[1]=0; source[2]=1; newsr |= dsp_add56(source, dest); @@ -4355,7 +4368,7 @@ static void dsp_adc_y_a(void) source[0] = source[1] & (1<<23) ? 0xff : 0x0; newsr = dsp_add56(source, dest); - + if (curcarry) { source[0]=0; source[1]=0; source[2]=1; newsr |= dsp_add56(source, dest); @@ -4387,7 +4400,7 @@ static void dsp_adc_y_b(void) source[0] = source[1] & (1<<23) ? 0xff : 0x0; newsr = dsp_add56(source, dest); - + if (curcarry) { source[0]=0; source[1]=0; source[2]=1; newsr |= dsp_add56(source, dest); @@ -6925,13 +6938,13 @@ static void dsp_macr_p_x1_y0_b(void) dsp_mul56(dsp_core.registers[DSP_REG_X1], dsp_core.registers[DSP_REG_Y0], source, SIGN_PLUS); - dsp_rnd56(dest); - dest[0] = dsp_core.registers[DSP_REG_B2]; dest[1] = dsp_core.registers[DSP_REG_B1]; dest[2] = dsp_core.registers[DSP_REG_B0]; newsr = dsp_add56(source, dest); + dsp_rnd56(dest); + dsp_core.registers[DSP_REG_B2] = dest[0]; dsp_core.registers[DSP_REG_B1] = dest[1]; dsp_core.registers[DSP_REG_B0] = dest[2]; @@ -8263,7 +8276,7 @@ static void dsp_sbc_x_a(void) source[0] = source[1] & (1<<23) ? 0xff : 0x0; newsr = dsp_sub56(source, dest); - + if (curcarry) { source[0]=0; source[1]=0; source[2]=1; newsr |= dsp_sub56(source, dest); @@ -8295,7 +8308,7 @@ static void dsp_sbc_x_b(void) source[0] = source[1] & (1<<23) ? 0xff : 0x0; newsr = dsp_sub56(source, dest); - + if (curcarry) { source[0]=0; source[1]=0; source[2]=1; newsr |= dsp_sub56(source, dest); @@ -8327,7 +8340,7 @@ static void dsp_sbc_y_a(void) source[0] = source[1] & (1<<23) ? 0xff : 0x0; newsr = dsp_sub56(source, dest); - + if (curcarry) { source[0]=0; source[1]=0; source[2]=1; newsr |= dsp_sub56(source, dest); @@ -8359,7 +8372,7 @@ static void dsp_sbc_y_b(void) source[0] = source[1] & (1<<23) ? 0xff : 0x0; newsr = dsp_sub56(source, dest); - + if (curcarry) { source[0]=0; source[1]=0; source[2]=1; newsr |= dsp_sub56(source, dest); @@ -8783,13 +8796,13 @@ static void dsp_subr_a(void) dest[0] = dsp_core.registers[DSP_REG_A2]; dest[1] = dsp_core.registers[DSP_REG_A1]; dest[2] = dsp_core.registers[DSP_REG_A0]; - + newsr = dsp_asr56(dest); source[0] = dsp_core.registers[DSP_REG_B2]; source[1] = dsp_core.registers[DSP_REG_B1]; source[2] = dsp_core.registers[DSP_REG_B0]; - + newsr |= dsp_sub56(source, dest); dsp_core.registers[DSP_REG_A2] = dest[0]; @@ -8810,13 +8823,13 @@ static void dsp_subr_b(void) dest[0] = dsp_core.registers[DSP_REG_B2]; dest[1] = dsp_core.registers[DSP_REG_B1]; dest[2] = dsp_core.registers[DSP_REG_B0]; - + newsr = dsp_asr56(dest); source[0] = dsp_core.registers[DSP_REG_A2]; source[1] = dsp_core.registers[DSP_REG_A1]; source[2] = dsp_core.registers[DSP_REG_A0]; - + newsr |= dsp_sub56(source, dest); dsp_core.registers[DSP_REG_B2] = dest[0]; @@ -8845,82 +8858,42 @@ static void dsp_tfr_a_b(void) static void dsp_tfr_x0_a(void) { - dsp_core.registers[DSP_REG_A0] = 0; - dsp_core.registers[DSP_REG_A1] = dsp_core.registers[DSP_REG_X0]; - if (dsp_core.registers[DSP_REG_A1] & (1<<23)) - dsp_core.registers[DSP_REG_A2] = 0xff; - else - dsp_core.registers[DSP_REG_A2] = 0x0; + dsp_write_reg(DSP_REG_A, dsp_core.registers[DSP_REG_X0]); } static void dsp_tfr_x0_b(void) { - dsp_core.registers[DSP_REG_B0] = 0; - dsp_core.registers[DSP_REG_B1] = dsp_core.registers[DSP_REG_X0]; - if (dsp_core.registers[DSP_REG_B1] & (1<<23)) - dsp_core.registers[DSP_REG_B2] = 0xff; - else - dsp_core.registers[DSP_REG_B2] = 0x0; + dsp_write_reg(DSP_REG_B, dsp_core.registers[DSP_REG_X0]); } static void dsp_tfr_y0_a(void) { - dsp_core.registers[DSP_REG_A0] = 0; - dsp_core.registers[DSP_REG_A1] = dsp_core.registers[DSP_REG_Y0]; - if (dsp_core.registers[DSP_REG_A1] & (1<<23)) - dsp_core.registers[DSP_REG_A2] = 0xff; - else - dsp_core.registers[DSP_REG_A2] = 0x0; + dsp_write_reg(DSP_REG_A, dsp_core.registers[DSP_REG_Y0]); } static void dsp_tfr_y0_b(void) { - dsp_core.registers[DSP_REG_B0] = 0; - dsp_core.registers[DSP_REG_B1] = dsp_core.registers[DSP_REG_Y0]; - if (dsp_core.registers[DSP_REG_B1] & (1<<23)) - dsp_core.registers[DSP_REG_B2] = 0xff; - else - dsp_core.registers[DSP_REG_B2] = 0x0; + dsp_write_reg(DSP_REG_B, dsp_core.registers[DSP_REG_Y0]); } static void dsp_tfr_x1_a(void) { - dsp_core.registers[DSP_REG_A0] = 0; - dsp_core.registers[DSP_REG_A1] = dsp_core.registers[DSP_REG_X1]; - if (dsp_core.registers[DSP_REG_A1] & (1<<23)) - dsp_core.registers[DSP_REG_A2] = 0xff; - else - dsp_core.registers[DSP_REG_A2] = 0x0; + dsp_write_reg(DSP_REG_A, dsp_core.registers[DSP_REG_X1]); } static void dsp_tfr_x1_b(void) { - dsp_core.registers[DSP_REG_B0] = 0; - dsp_core.registers[DSP_REG_B1] = dsp_core.registers[DSP_REG_X1]; - if (dsp_core.registers[DSP_REG_B1] & (1<<23)) - dsp_core.registers[DSP_REG_B2] = 0xff; - else - dsp_core.registers[DSP_REG_B2] = 0x0; + dsp_write_reg(DSP_REG_B, dsp_core.registers[DSP_REG_X1]); } static void dsp_tfr_y1_a(void) { - dsp_core.registers[DSP_REG_A0] = 0; - dsp_core.registers[DSP_REG_A1] = dsp_core.registers[DSP_REG_Y1]; - if (dsp_core.registers[DSP_REG_A1] & (1<<23)) - dsp_core.registers[DSP_REG_A2] = 0xff; - else - dsp_core.registers[DSP_REG_A2] = 0x0; + dsp_write_reg(DSP_REG_A, dsp_core.registers[DSP_REG_Y1]); } static void dsp_tfr_y1_b(void) { - dsp_core.registers[DSP_REG_B0] = 0; - dsp_core.registers[DSP_REG_B1] = dsp_core.registers[DSP_REG_Y1]; - if (dsp_core.registers[DSP_REG_B1] & (1<<23)) - dsp_core.registers[DSP_REG_B2] = 0xff; - else - dsp_core.registers[DSP_REG_B2] = 0x0; + dsp_write_reg(DSP_REG_B, dsp_core.registers[DSP_REG_Y1]); } static void dsp_tst_a(void)