--- hatari/src/falcon/dsp_cpu.c 2019/04/09 08:49:40 1.1.1.6 +++ hatari/src/falcon/dsp_cpu.c 2019/04/09 08:53:24 1.1.1.9 @@ -19,6 +19,55 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ +/* + 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. + 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 + + The DSP external RAM is zero waitstate, but there is a penalty for + 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) + + + X: Y: P: + $ffff |--------------+--------------+--------------| + | Int. I/O | Ext. I/O | | + $ffc0 |--------------+--------------+ | + | | | | + | Reserved | Reserved | Reserved | + | | | | + | | | | + | | | | + $8000 |--------------+--------------+--------------| + | | | | + | 16k Shadow | 16k Shadow | | + | | | 32K | + $4000 |--------------+--------------| Program | + | 16K | 16K | RAM | + | External | External | | + | RAM | RAM | | + $0200 |--------------+--------------+--------------| + | Log table or | Sin table or | | + | external mem | external mem | Internal | + $0100 |--------------+--------------+ program | + | Internal X | Internal Y | memory | + | memory | memory | | + $0000 |--------------+--------------+--------------| + + + Special Note : As the Falcon DSP is a 0 waitstate access memory, I've simplified a little the cycle counting. + If this DSP emulator code is used in another project, one should take into account the bus control register (BCR) waitstates. +*/ + #ifdef HAVE_CONFIG_H #include "config.h" #endif @@ -29,8 +78,8 @@ #include "dsp_cpu.h" #include "dsp_disasm.h" #include "log.h" -# include "main.h" - +#include "main.h" +#include "debugui.h" #define DSP_COUNT_IPS 0 /* Count instruction per seconds */ @@ -39,15 +88,17 @@ * Defines **********************************/ -/* cycle counter wait state time when access to external memory */ -#define XY_WAITSTATE 0 -#define P_WAITSTATE 0 -#define XP_WAITSTATE 0 /* X Peripheral WaitState */ -#define YP_WAITSTATE 0 /* Y Peripheral WaitState */ - #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 **********************************/ @@ -62,11 +113,14 @@ static Uint32 cur_inst_len; /* =0:jump, /* Current instruction */ static Uint32 cur_inst; +/* Counts the number of access to the external memory for one instruction */ +static Uint16 access_to_ext_memory; + /* DSP is in disasm mode ? */ /* If yes, stack overflow, underflow and illegal instructions messages are not displayed */ static bool isDsp_in_disasm_mode; -static char str_disasm_memory[2][50]; /* Buffer for memory change text in disasm mode */ +static char str_disasm_memory[2][50]; /* Buffer for memory change text in disasm mode */ static Uint16 disasm_memory_ptr; /* Pointer for memory change in disasm mode */ /********************************** @@ -236,10 +290,10 @@ static void dsp_and_x1_a(void); static void dsp_and_x1_b(void); static void dsp_and_y1_a(void); static void dsp_and_y1_b(void); -static void dsp_asl_b_a(void); -static void dsp_asl_a_b(void); -static void dsp_asr_b_a(void); -static void dsp_asr_a_b(void); +static void dsp_asl_a(void); +static void dsp_asl_b(void); +static void dsp_asr_a(void); +static void dsp_asr_b(void); static void dsp_clr_a(void); static void dsp_clr_b(void); static void dsp_cmp_b_a(void); @@ -549,10 +603,10 @@ static const dsp_emul_t opcodes_alu[256] dsp_undefined, dsp_tfr_a_b, dsp_addr_a_b, dsp_tst_b, dsp_undefined, dsp_cmp_a_b, dsp_subr_b, dsp_cmpm_a_b, dsp_add_b_a, dsp_rnd_a, dsp_addl_b_a, dsp_clr_a, dsp_sub_b_a, dsp_undefined, dsp_subl_a, dsp_not_a, dsp_add_a_b, dsp_rnd_b, dsp_addl_a_b, dsp_clr_b, dsp_sub_a_b, dsp_undefined, dsp_subl_b, dsp_not_b, - dsp_add_x_a, dsp_adc_x_a, dsp_asr_b_a, dsp_lsr_a, dsp_sub_x_a, dsp_sbc_x_a, dsp_abs_a, dsp_ror_a, - dsp_add_x_b, dsp_adc_x_b, dsp_asr_a_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_b_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_a_b, dsp_lsl_b, dsp_sub_y_b, dsp_sbc_y_b, dsp_neg_b, dsp_rol_b, + dsp_add_x_a, dsp_adc_x_a, dsp_asr_a, dsp_lsr_a, dsp_sub_x_a, dsp_sbc_x_a, dsp_abs_a, dsp_ror_a, + 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, @@ -660,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; @@ -684,7 +738,7 @@ 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)); @@ -701,11 +755,14 @@ void dsp56k_execute_instruction(void) Uint32 disasm_return = 0; disasm_memory_ptr = 0; + /* Initialise the number of access to the external memory for this instruction */ + access_to_ext_memory = 0; + /* Decode and execute current instruction */ cur_inst = read_memory_p(dsp_core.pc); - cur_inst_len = 1; - /* Initialize instruction cycle counter */ + /* Initialize instruction size and cycle counter */ + cur_inst_len = 1; dsp_core.instr_cycle = 2; /* Disasm current instruction ? (trace mode only) */ @@ -730,6 +787,17 @@ void dsp56k_execute_instruction(void) opcodes_parmove[(cur_inst>>20) & BITMASK(4)](); } + /* Add the waitstate due to external memory access */ + /* (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 */ @@ -789,7 +857,7 @@ static void dsp_postexecute_update_pc(vo dsp_core.registers[DSP_REG_LC] &= BITMASK(16); if (dsp_core.registers[DSP_REG_LC] > 0) { - cur_inst_len=0; /* Stay on this instruction */ + cur_inst_len = 0; /* Stay on this instruction */ } else { dsp_core.loop_rep = 0; dsp_core.registers[DSP_REG_LC] = dsp_core.registers[DSP_REG_LCSAVE]; @@ -811,11 +879,11 @@ static void dsp_postexecute_update_pc(vo if (dsp_core.registers[DSP_REG_SR] & (1<> 10) & 3) - 1; /* set IPL_HI */ - for (i=5;i<8;i++) { + for (i=5; i<8; i++) { dsp_core.interrupt_ipl[i] = ipl_hi; } /* set IPL_SSI */ - for (i=8;i<12;i++) { + for (i=8; i<12; i++) { dsp_core.interrupt_ipl[i] = ipl_ssi; } } @@ -1128,12 +1196,14 @@ static Uint32 read_memory_disasm(int spa static inline Uint32 read_memory_p(Uint16 address) { /* Internal RAM ? */ - if (address<0x200) { + if (address < 0x200) { return dsp_core.ramint[DSP_SPACE_P][address] & BITMASK(24); } + /* Access to the external P memory */ + access_to_ext_memory |= 1 << EXT_P_MEMORY; + /* External RAM, mask address to available ram size */ -// dsp_core.instr_cycle += P_WAITSTATE; return dsp_core.ramext[address & (DSP_RAMSIZE-1)] & BITMASK(24); } @@ -1168,31 +1238,33 @@ static Uint32 read_memory(int space, Uin else if (address == 0xffc0+DSP_SSI_RX) { value = dsp_core_ssi_readRX(); } - dsp_core.instr_cycle += XP_WAITSTATE; - } - else { - dsp_core.instr_cycle += YP_WAITSTATE; } return value; } - /* 1 more cycle for external RAM access */ - dsp_core.instr_cycle += XY_WAITSTATE; - - /* 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); } static inline void write_memory(int space, Uint16 address, Uint32 value) { - if (LOG_TRACE_LEVEL(TRACE_DSP_DISASM_MEM)) + if (unlikely(LOG_TRACE_LEVEL(TRACE_DSP_DISASM_MEM))) write_memory_disasm(space, address, value); else write_memory_raw(space, address, value); @@ -1244,12 +1316,10 @@ static void write_memory_raw(int space, dsp_core.periph[DSP_SPACE_X][address-0xffc0] = value; break; } - dsp_core.instr_cycle += XP_WAITSTATE; return; } else if (space == DSP_SPACE_Y) { dsp_core.periph[DSP_SPACE_Y][address-0xffc0] = value; - dsp_core.instr_cycle += YP_WAITSTATE; return; } } @@ -1275,16 +1345,25 @@ static void write_memory_raw(int space, } } - /* 1 more cycle for external RAM access */ - dsp_core.instr_cycle += XY_WAITSTATE; + /* 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 */ @@ -1321,49 +1400,53 @@ static void dsp_write_reg(Uint32 numreg, { Uint32 stack_error; - if ((numreg==DSP_REG_A) || (numreg==DSP_REG_B)) { - numreg &= 1; - dsp_core.registers[DSP_REG_A0+numreg]= 0; - dsp_core.registers[DSP_REG_A1+numreg]= value; - dsp_core.registers[DSP_REG_A2+numreg]= 0; - if (value & (1<<23)) { - dsp_core.registers[DSP_REG_A2+numreg]= 0xff; - } - } else { - switch (numreg) { - case DSP_REG_OMR: - dsp_core.registers[DSP_REG_OMR] = value & 0xc7; - break; - case DSP_REG_SR: - dsp_core.registers[DSP_REG_SR] = value & 0xaf7f; - break; - case DSP_REG_SP: - stack_error = dsp_core.registers[DSP_REG_SP] & (1<=0x200) { - dsp_core.instr_cycle += XY_WAITSTATE; - } } static void dsp_bchg_pp(void) @@ -1833,11 +1920,6 @@ static void dsp_bchg_pp(void) dsp_core.registers[DSP_REG_SR] |= newcarry<=0x200) { - dsp_core.instr_cycle += XY_WAITSTATE; - } } static void dsp_bclr_pp(void) @@ -1932,11 +2011,6 @@ static void dsp_bclr_pp(void) dsp_core.registers[DSP_REG_SR] |= newcarry<=0x200) { - dsp_core.instr_cycle += XY_WAITSTATE; - } } static void dsp_bset_pp(void) @@ -2027,11 +2098,6 @@ static void dsp_bset_pp(void) dsp_core.registers[DSP_REG_SR] |= newcarry<>3) & 1); + source[2] = 0; + source[1] = dsp_core.registers[srcreg]; + source[0] = source[1] & (1<<23) ? 0xff : 0x0; - source[0] = 0; - source[1] = dsp_core.registers[srcreg]; - if (source[1] & (1<<23)) { - source[0] = 0xff; - } - source[2] = 0; - - dest[0] = dsp_core.registers[DSP_REG_A2+(destreg & 1)]; - dest[1] = dsp_core.registers[DSP_REG_A1+(destreg & 1)]; - dest[2] = dsp_core.registers[DSP_REG_A0+(destreg & 1)]; + destreg = DSP_REG_A + ((cur_inst>>3) & 1); + if (destreg == DSP_REG_A) { + dest[0] = dsp_core.registers[DSP_REG_A2]; + dest[1] = dsp_core.registers[DSP_REG_A1]; + dest[2] = dsp_core.registers[DSP_REG_A0]; + } + else { + dest[0] = dsp_core.registers[DSP_REG_B2]; + dest[1] = dsp_core.registers[DSP_REG_B1]; + dest[2] = dsp_core.registers[DSP_REG_B0]; + } if (((dest[0]>>7) & 1) ^ ((source[1]>>23) & 1)) { /* D += S */ @@ -2175,10 +2244,17 @@ static void dsp_div(void) dest[2] |= (dsp_core.registers[DSP_REG_SR]>>DSP_SR_C) & 1; - dsp_core.registers[DSP_REG_A2+(destreg & 1)] = dest[0]; - dsp_core.registers[DSP_REG_A1+(destreg & 1)] = dest[1]; - dsp_core.registers[DSP_REG_A0+(destreg & 1)] = dest[2]; - + if (destreg == DSP_REG_A) { + dsp_core.registers[DSP_REG_A2] = dest[0]; + dsp_core.registers[DSP_REG_A1] = dest[1]; + dsp_core.registers[DSP_REG_A0] = dest[2]; + } + else { + dsp_core.registers[DSP_REG_B2] = dest[0]; + 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))<= 0x200) { - dsp_core.instr_cycle += 2*P_WAITSTATE; - } } static void dsp_jcc_ea(void) @@ -2321,9 +2397,6 @@ static void dsp_jcc_ea(void) } dsp_core.instr_cycle += 2; - if (newpc >= 0x200) { - dsp_core.instr_cycle += 2*P_WAITSTATE; - } } static void dsp_jclr_aa(void) @@ -2337,9 +2410,6 @@ static void dsp_jclr_aa(void) newaddr = read_memory_p(dsp_core.pc+1); dsp_core.instr_cycle += 4; - if (newaddr >= 0x200) { - dsp_core.instr_cycle += 2*P_WAITSTATE; - } if ((value & (1<= 0x200) { - dsp_core.instr_cycle += 2*P_WAITSTATE; - } if ((value & (1<= 0x200) { - dsp_core.instr_cycle += 2*P_WAITSTATE; - } if ((value & (1<= 0x200) { - dsp_core.instr_cycle += 2*P_WAITSTATE; - } if ((value & (1<= 0x200) { - dsp_core.instr_cycle += 2*P_WAITSTATE; - } } static void dsp_jmp_imm(void) @@ -2448,9 +2506,6 @@ static void dsp_jmp_imm(void) dsp_core.pc = newpc; dsp_core.instr_cycle += 2; - if (newpc >= 0x200) { - dsp_core.instr_cycle += 2*P_WAITSTATE; - } } static void dsp_jscc_ea(void) @@ -2467,9 +2522,6 @@ static void dsp_jscc_ea(void) } dsp_core.instr_cycle += 2; - if (newpc >= 0x200) { - dsp_core.instr_cycle += 2*P_WAITSTATE; - } } static void dsp_jscc_imm(void) @@ -2485,9 +2537,6 @@ static void dsp_jscc_imm(void) } dsp_core.instr_cycle += 2; - if (newpc >= 0x200) { - dsp_core.instr_cycle += 2*P_WAITSTATE; - } } static void dsp_jsclr_aa(void) @@ -2501,9 +2550,6 @@ static void dsp_jsclr_aa(void) newaddr = read_memory_p(dsp_core.pc+1); dsp_core.instr_cycle += 4; - if (newaddr >= 0x200) { - dsp_core.instr_cycle += 2*P_WAITSTATE; - } if ((value & (1<= 0x200) { - dsp_core.instr_cycle += 2*P_WAITSTATE; - } if ((value & (1<= 0x200) { - dsp_core.instr_cycle += 2*P_WAITSTATE; - } if ((value & (1<= 0x200) { - dsp_core.instr_cycle += 2*P_WAITSTATE; - } if ((value & (1<= 0x200) { - dsp_core.instr_cycle += 2*P_WAITSTATE; - } if (value & (1<= 0x200) { - dsp_core.instr_cycle += 2*P_WAITSTATE; - } - + if (value & (1<= 0x200) { - dsp_core.instr_cycle += 2*P_WAITSTATE; - } if (value & (1<= 0x200) { - dsp_core.instr_cycle += 2*P_WAITSTATE; - } if (value & (1<= 0x200) { - dsp_core.instr_cycle += 2*P_WAITSTATE; - } } static void dsp_jsr_ea(void) @@ -2737,9 +2759,6 @@ static void dsp_jsr_ea(void) cur_inst_len = 0; dsp_core.instr_cycle += 2; - if (newpc >= 0x200) { - dsp_core.instr_cycle += 2*P_WAITSTATE; - } } static void dsp_jsset_aa(void) @@ -2753,9 +2772,6 @@ static void dsp_jsset_aa(void) newaddr = read_memory_p(dsp_core.pc+1); dsp_core.instr_cycle += 4; - if (newaddr >= 0x200) { - dsp_core.instr_cycle += 2*P_WAITSTATE; - } if (value & (1<= 0x200) { - dsp_core.instr_cycle += 2*P_WAITSTATE; - } if (value & (1<= 0x200) { - dsp_core.instr_cycle += 2*P_WAITSTATE; - } if (value & (1<= 0x200) { - dsp_core.instr_cycle += 2*P_WAITSTATE; - } if (value & (1<=0x200) { - dsp_core.instr_cycle += P_WAITSTATE; - } } static void dsp_movem_ea(void) @@ -3051,9 +3058,6 @@ static void dsp_movem_ea(void) } dsp_core.instr_cycle += 4; - if (addr>=0x200) { - dsp_core.instr_cycle += P_WAITSTATE; - } } static void dsp_movep_0(void) @@ -3112,7 +3116,10 @@ static void dsp_movep_1(void) write_memory(DSP_SPACE_P, paddr, read_memory(memspace, xyaddr)); } - dsp_core.instr_cycle += 2; + /* Movep is 4 cycles, but according to the motorola doc, */ + /* movep from p memory to x or y peripheral memory takes */ + /* 2 more cycles, so +4 cycles at total */ + dsp_core.instr_cycle += 4; } static void dsp_movep_23(void) @@ -3144,16 +3151,10 @@ static void dsp_movep_23(void) if (retour) { write_memory(perspace, peraddr, addr); } else { - if (peraddr>=0x200) { - dsp_core.instr_cycle += P_WAITSTATE; - } write_memory(perspace, peraddr, read_memory(easpace, addr)); } } else { /* Read pp */ - if (peraddr>=0x200) { - dsp_core.instr_cycle += P_WAITSTATE; - } write_memory(easpace, addr, read_memory(perspace, peraddr)); } @@ -3312,9 +3313,6 @@ static void dsp_rti(void) cur_inst_len = 0; dsp_core.instr_cycle += 2; - if (newpc >= 0x200) { - dsp_core.instr_cycle += 2*P_WAITSTATE; - } } static void dsp_rts(void) @@ -3326,9 +3324,6 @@ static void dsp_rts(void) cur_inst_len = 0; dsp_core.instr_cycle += 2; - if (newpc >= 0x200) { - dsp_core.instr_cycle += 2*P_WAITSTATE; - } } static void dsp_stop(void) @@ -3355,23 +3350,33 @@ static void dsp_tcc(void) regdest1 = registers_tcc[(cur_inst>>3) & BITMASK(4)][1]; /* Read S1 */ - if ((regsrc1 == DSP_REG_A) || (regsrc1 == DSP_REG_B)) { - val0 = dsp_core.registers[DSP_REG_A0+(regsrc1 & 1)]; - val1 = dsp_core.registers[DSP_REG_A1+(regsrc1 & 1)]; - val2 = dsp_core.registers[DSP_REG_A2+(regsrc1 & 1)]; - } else { + if (regsrc1 == DSP_REG_A) { + val0 = dsp_core.registers[DSP_REG_A0]; + val1 = dsp_core.registers[DSP_REG_A1]; + val2 = dsp_core.registers[DSP_REG_A2]; + } + else if (regsrc1 == DSP_REG_B) { + val0 = dsp_core.registers[DSP_REG_B0]; + val1 = dsp_core.registers[DSP_REG_B1]; + val2 = dsp_core.registers[DSP_REG_B2]; + } + else { val0 = 0; val1 = dsp_core.registers[regsrc1]; - if (val1 & (1<<23)) - val2 = 0xff; - else - val2 = 0x0; + val2 = val1 & (1<<23) ? 0xff : 0x0; } /* Write D1 */ - dsp_core.registers[DSP_REG_A2+(regdest1 & 1)] = val2; - dsp_core.registers[DSP_REG_A1+(regdest1 & 1)] = val1; - dsp_core.registers[DSP_REG_A0+(regdest1 & 1)] = val0; + if (regdest1 == DSP_REG_A) { + dsp_core.registers[DSP_REG_A2] = val2; + dsp_core.registers[DSP_REG_A1] = val1; + dsp_core.registers[DSP_REG_A0] = val0; + } + else { + dsp_core.registers[DSP_REG_B2] = val2; + dsp_core.registers[DSP_REG_B1] = val1; + dsp_core.registers[DSP_REG_B0] = val0; + } /* S2,D2 transfer */ if (cur_inst & (1<<16)) { @@ -3391,7 +3396,7 @@ static void dsp_wait(void) static int dsp_pm_read_accu24(int numreg, Uint32 *dest) { Uint32 scaling, value, reg; - int got_limited=0; + int got_limited = 0; /* Read an accumulator, stores it limited */ @@ -3479,10 +3484,7 @@ static void dsp_pm_0(void) /* Move [x|y]0 to [A|B] */ dsp_core.registers[DSP_REG_A0+numreg] = 0; dsp_core.registers[DSP_REG_A1+numreg] = save_xy0; - if (save_xy0 & (1<<23)) - dsp_core.registers[DSP_REG_A2+numreg] = 0xff; - else - dsp_core.registers[DSP_REG_A2+numreg] = 0x0; + dsp_core.registers[DSP_REG_A2+numreg] = save_xy0 & (1<<23) ? 0xff : 0x0; } static void dsp_pm_1(void) @@ -3729,11 +3731,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); @@ -3918,6 +3915,7 @@ static void dsp_pm_5(void) } } else { + /* Read S */ write_memory(memspace, xy_addr, value); } } @@ -3951,11 +3949,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; @@ -4144,7 +4137,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); @@ -4330,10 +4323,7 @@ static void dsp_adc_x_a(void) source[2] = dsp_core.registers[DSP_REG_X0]; source[1] = dsp_core.registers[DSP_REG_X1]; - if (source[1] & (1<<23)) - source[0] = 0xff; - else - source[0] = 0x0; + source[0] = source[1] & (1<<23) ? 0xff : 0x0; newsr = dsp_add56(source, dest); @@ -4365,10 +4355,7 @@ static void dsp_adc_x_b(void) source[2] = dsp_core.registers[DSP_REG_X0]; source[1] = dsp_core.registers[DSP_REG_X1]; - if (source[1] & (1<<23)) - source[0] = 0xff; - else - source[0] = 0x0; + source[0] = source[1] & (1<<23) ? 0xff : 0x0; newsr = dsp_add56(source, dest); @@ -4400,10 +4387,7 @@ static void dsp_adc_y_a(void) source[2] = dsp_core.registers[DSP_REG_Y0]; source[1] = dsp_core.registers[DSP_REG_Y1]; - if (source[1] & (1<<23)) - source[0] = 0xff; - else - source[0] = 0x0; + source[0] = source[1] & (1<<23) ? 0xff : 0x0; newsr = dsp_add56(source, dest); @@ -4435,10 +4419,7 @@ static void dsp_adc_y_b(void) source[2] = dsp_core.registers[DSP_REG_Y0]; source[1] = dsp_core.registers[DSP_REG_Y1]; - if (source[1] & (1<<23)) - source[0] = 0xff; - else - source[0] = 0x0; + source[0] = source[1] & (1<<23) ? 0xff : 0x0; newsr = dsp_add56(source, dest); @@ -4518,10 +4499,7 @@ static void dsp_add_x_a(void) source[1] = dsp_core.registers[DSP_REG_X1]; source[2] = dsp_core.registers[DSP_REG_X0]; - if (source[1] & (1<<23)) - source[0] = 0xff; - else - source[0] = 0x0; + source[0] = source[1] & (1<<23) ? 0xff : 0x0; newsr = dsp_add56(source, dest); @@ -4546,10 +4524,7 @@ static void dsp_add_x_b(void) source[1] = dsp_core.registers[DSP_REG_X1]; source[2] = dsp_core.registers[DSP_REG_X0]; - if (source[1] & (1<<23)) - source[0] = 0xff; - else - source[0] = 0x0; + source[0] = source[1] & (1<<23) ? 0xff : 0x0; newsr = dsp_add56(source, dest); @@ -4574,10 +4549,7 @@ static void dsp_add_y_a(void) source[1] = dsp_core.registers[DSP_REG_Y1]; source[2] = dsp_core.registers[DSP_REG_Y0]; - if (source[1] & (1<<23)) - source[0] = 0xff; - else - source[0] = 0x0; + source[0] = source[1] & (1<<23) ? 0xff : 0x0; newsr = dsp_add56(source, dest); @@ -4602,10 +4574,7 @@ static void dsp_add_y_b(void) source[1] = dsp_core.registers[DSP_REG_Y1]; source[2] = dsp_core.registers[DSP_REG_Y0]; - if (source[1] & (1<<23)) - source[0] = 0xff; - else - source[0] = 0x0; + source[0] = source[1] & (1<<23) ? 0xff : 0x0; newsr = dsp_add56(source, dest); @@ -4630,10 +4599,7 @@ static void dsp_add_x0_a(void) source[2] = 0; source[1] = dsp_core.registers[DSP_REG_X0]; - if (source[1] & (1<<23)) - source[0] = 0xff; - else - source[0] = 0x0; + source[0] = source[1] & (1<<23) ? 0xff : 0x0; newsr = dsp_add56(source, dest); @@ -4658,10 +4624,7 @@ static void dsp_add_x0_b(void) source[2] = 0; source[1] = dsp_core.registers[DSP_REG_X0]; - if (source[1] & (1<<23)) - source[0] = 0xff; - else - source[0] = 0x0; + source[0] = source[1] & (1<<23) ? 0xff : 0x0; newsr = dsp_add56(source, dest); @@ -4686,10 +4649,7 @@ static void dsp_add_y0_a(void) source[2] = 0; source[1] = dsp_core.registers[DSP_REG_Y0]; - if (source[1] & (1<<23)) - source[0] = 0xff; - else - source[0] = 0x0; + source[0] = source[1] & (1<<23) ? 0xff : 0x0; newsr = dsp_add56(source, dest); @@ -4714,10 +4674,7 @@ static void dsp_add_y0_b(void) source[2] = 0; source[1] = dsp_core.registers[DSP_REG_Y0]; - if (source[1] & (1<<23)) - source[0] = 0xff; - else - source[0] = 0x0; + source[0] = source[1] & (1<<23) ? 0xff : 0x0; newsr = dsp_add56(source, dest); @@ -4742,10 +4699,7 @@ static void dsp_add_x1_a(void) source[2] = 0; source[1] = dsp_core.registers[DSP_REG_X1]; - if (source[1] & (1<<23)) - source[0] = 0xff; - else - source[0] = 0x0; + source[0] = source[1] & (1<<23) ? 0xff : 0x0; newsr = dsp_add56(source, dest); @@ -4770,10 +4724,7 @@ static void dsp_add_x1_b(void) source[2] = 0; source[1] = dsp_core.registers[DSP_REG_X1]; - if (source[1] & (1<<23)) - source[0] = 0xff; - else - source[0] = 0x0; + source[0] = source[1] & (1<<23) ? 0xff : 0x0; newsr = dsp_add56(source, dest); @@ -4798,10 +4749,7 @@ static void dsp_add_y1_a(void) source[2] = 0; source[1] = dsp_core.registers[DSP_REG_Y1]; - if (source[1] & (1<<23)) - source[0] = 0xff; - else - source[0] = 0x0; + source[0] = source[1] & (1<<23) ? 0xff : 0x0; newsr = dsp_add56(source, dest); @@ -4826,10 +4774,7 @@ static void dsp_add_y1_b(void) source[2] = 0; source[1] = dsp_core.registers[DSP_REG_Y1]; - if (source[1] & (1<<23)) - source[0] = 0xff; - else - source[0] = 0x0; + source[0] = source[1] & (1<<23) ? 0xff : 0x0; newsr = dsp_add56(source, dest); @@ -5015,7 +4960,7 @@ static void dsp_and_y1_b(void) dsp_core.registers[DSP_REG_SR] |= (dsp_core.registers[DSP_REG_B1]==0)<