--- 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:57:02 1.1.1.12 @@ -19,18 +19,67 @@ 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 #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 */ @@ -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 */ /********************************** @@ -90,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); @@ -224,7 +278,6 @@ static void dsp_add_x1_b(void); static void dsp_add_y1_a(void); static void dsp_add_y1_b(void); static void dsp_addl_b_a(void); -static void dsp_addl_b_a(void); static void dsp_addl_a_b(void); static void dsp_addr_b_a(void); static void dsp_addr_a_b(void); @@ -236,10 +289,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); @@ -466,7 +519,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, @@ -479,23 +532,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, @@ -519,23 +572,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] = { @@ -549,11 +602,11 @@ 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, 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, @@ -612,12 +665,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, @@ -660,11 +713,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; @@ -679,16 +732,16 @@ Uint32 dsp56k_execute_one_disasm_instruc dsp_core.pc = pc; /* Disasm instruction */ - instruction_length = dsp56k_disasm(DSP_DISASM_MODE) - 1; + instruction_length = dsp56k_disasm(DSP_DISASM_MODE, out) - 1; /* 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; @@ -701,26 +754,32 @@ 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; + + /* 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; - - /* Initialize instruction cycle counter */ 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); - + disasm_return = dsp56k_disasm(DSP_TRACE_MODE, TraceFile); + 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); @@ -730,25 +789,36 @@ 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 */ if (isDsp_in_disasm_mode == false) { if (disasm_return != 0) { - fprintf(stderr, "%s", dsp56k_getInstructionText()); - + fprintf(TraceFile, "%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(); + dsp56k_disasm_reg_compare(TraceFile); if (LOG_TRACE_LEVEL(TRACE_DSP_DISASM_MEM)) { /* 1 memory change to display ? */ if (disasm_memory_ptr == 1) - fprintf(stderr, "\t%s\n", str_disasm_memory[0]); + fprintf(TraceFile, "\t%s\n", str_disasm_memory[0]); /* 2 memory changes to display ? */ else if (disasm_memory_ptr == 2) { - fprintf(stderr, "\t%s\n", str_disasm_memory[0]); - fprintf(stderr, "\t%s\n", str_disasm_memory[1]); + fprintf(TraceFile, "\t%s\n", str_disasm_memory[0]); + fprintf(TraceFile, "\t%s\n", str_disasm_memory[1]); } } } @@ -783,13 +853,13 @@ 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); 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,20 +881,19 @@ 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; } } @@ -893,7 +962,7 @@ static void dsp_postexecute_interrupts(v instr = read_memory_p(dsp_core.interrupt_instr_fetch); if ( ((instr & 0xfff000) == 0x0d0000) || ((instr & 0xffc0ff) == 0x0bc080) ) { dsp_core.interrupt_state = DSP_INTERRUPT_LONG; - dsp_stack_push(dsp_core.interrupt_save_pc, dsp_core.registers[DSP_REG_SR], 0); + dsp_stack_push(dsp_core.interrupt_save_pc, dsp_core.registers[DSP_REG_SR], 0); dsp_core.registers[DSP_REG_SR] &= BITMASK(16)-((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: @@ -1067,7 +1138,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: @@ -1128,12 +1199,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); } @@ -1164,28 +1237,30 @@ 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(); } - 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); } @@ -1194,7 +1269,7 @@ static inline void write_memory(int spac { if (LOG_TRACE_LEVEL(TRACE_DSP_DISASM_MEM)) write_memory_disasm(space, address, value); - else + else write_memory_raw(space, address, value); } @@ -1244,16 +1319,14 @@ 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; } } - + /* Internal RAM ? */ if (address < 0x100) { dsp_core.ramint[space][address] = value; @@ -1275,16 +1348,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 +1403,79 @@ 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<modulo) { - while (modifier>bufsize) { - r_reg += bufsize; - modifier -= bufsize; - } - while (modifier<-bufsize) { - r_reg -= bufsize; - modifier += bufsize; - } + if (modifier<0) { + abs_modifier = -modifier; + } else { + abs_modifier = modifier; } - r_reg += modifier; - if (orig_modifier!=modulo) { + if (abs_modifier>modulo) { + if (abs_modifier&bufmask) { + fprintf(stderr,"Dsp: Modulo addressing result unpredictable\n"); + } else { + r_reg += modifier; + } + } else { + r_reg += modifier; + + if (r_reg>hibound) { r_reg -= modulo; } else if (r_reg> 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; @@ -1714,6 +1835,9 @@ static void opcode8h_0(void) case 0x00008c: dsp_enddo(); break; + default: + dsp_undefined(); + break; } } @@ -1726,13 +1850,16 @@ static void dsp_undefined(void) if (isDsp_in_disasm_mode == false) { cur_inst_len = 0; fprintf(stderr, "Dsp: 0x%04x: 0x%06x Illegal instruction\n",dsp_core.pc, cur_inst); - /* Add some CPU cycles to avoid being stuck in an infinite loop */ + /* Add some artificial CPU cycles to avoid being stuck in an infinite loop */ dsp_core.instr_cycle += 100; } else { cur_inst_len = 1; dsp_core.instr_cycle = 0; } + if (ExceptionDebugMask & EXCEPT_DSP) { + DebugUI(REASON_DSP_EXCEPTION); + } } static void dsp_andi(void) @@ -1760,7 +1887,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); @@ -1785,7 +1912,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); @@ -1805,15 +1932,12 @@ static void dsp_bchg_ea(void) dsp_core.registers[DSP_REG_SR] |= newcarry<=0x200) { - dsp_core.instr_cycle += XY_WAITSTATE; - } } 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); @@ -1833,17 +1957,12 @@ static void dsp_bchg_pp(void) dsp_core.registers[DSP_REG_SR] |= newcarry<>8) & BITMASK(6); numbit = cur_inst & BITMASK(5); @@ -1872,7 +1991,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); @@ -1892,7 +2011,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); @@ -1908,15 +2027,12 @@ static void dsp_bclr_ea(void) dsp_core.registers[DSP_REG_SR] |= newcarry<=0x200) { - dsp_core.instr_cycle += XY_WAITSTATE; - } } 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); @@ -1932,17 +2048,12 @@ static void dsp_bclr_pp(void) dsp_core.registers[DSP_REG_SR] |= newcarry<>8) & BITMASK(6); numbit = cur_inst & BITMASK(5); @@ -1967,7 +2078,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); @@ -1988,7 +2099,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); @@ -2004,15 +2115,12 @@ static void dsp_bset_ea(void) dsp_core.registers[DSP_REG_SR] |= newcarry<=0x200) { - dsp_core.instr_cycle += XY_WAITSTATE; - } } 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); @@ -2027,17 +2135,12 @@ static void dsp_bset_pp(void) dsp_core.registers[DSP_REG_SR] |= newcarry<>8) & BITMASK(6); numbit = cur_inst & BITMASK(5); @@ -2062,7 +2165,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); @@ -2081,7 +2184,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); @@ -2100,7 +2203,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); @@ -2119,7 +2222,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); @@ -2150,18 +2253,21 @@ static void dsp_div(void) case 2: srcreg = DSP_REG_X1; break; case 3: srcreg = DSP_REG_Y1; break; } - destreg = DSP_REG_A+((cur_inst>>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,9 +2281,16 @@ 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))<>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]; } @@ -2289,6 +2402,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) @@ -2303,9 +2419,6 @@ static void dsp_jcc_imm(void) } dsp_core.instr_cycle += 2; - if (newpc >= 0x200) { - dsp_core.instr_cycle += 2*P_WAITSTATE; - } } static void dsp_jcc_ea(void) @@ -2321,15 +2434,12 @@ 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) { Uint32 memspace, addr, value, numbit, newaddr; - + memspace = (cur_inst>>6) & 1; addr = (cur_inst>>8) & BITMASK(6); numbit = cur_inst & BITMASK(5); @@ -2337,47 +2447,41 @@ 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<>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); dsp_core.instr_cycle += 4; - if (newaddr >= 0x200) { - dsp_core.instr_cycle += 2*P_WAITSTATE; - } if ((value & (1<>6) & 1; value = (cur_inst>>8) & BITMASK(6); numbit = cur_inst & BITMASK(5); @@ -2386,22 +2490,19 @@ static void dsp_jclr_pp(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<>8) & BITMASK(6); numbit = cur_inst & BITMASK(5); newaddr = read_memory_p(dsp_core.pc+1); @@ -2413,15 +2514,12 @@ static void dsp_jclr_reg(void) } 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; - } } static void dsp_jmp_imm(void) @@ -2448,9 +2543,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) @@ -2464,12 +2556,9 @@ 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; - if (newpc >= 0x200) { - dsp_core.instr_cycle += 2*P_WAITSTATE; - } } static void dsp_jscc_imm(void) @@ -2482,43 +2571,37 @@ 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; - if (newpc >= 0x200) { - dsp_core.instr_cycle += 2*P_WAITSTATE; - } } 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 (newaddr >= 0x200) { - dsp_core.instr_cycle += 2*P_WAITSTATE; - } - + if ((value & (1<>6) & 1; value = (cur_inst>>8) & BITMASK(6); numbit = cur_inst & BITMASK(5); @@ -2527,24 +2610,21 @@ static void dsp_jsclr_ea(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<>6) & 1; value = (cur_inst>>8) & BITMASK(6); numbit = cur_inst & BITMASK(5); @@ -2553,24 +2633,21 @@ static void dsp_jsclr_pp(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<>8) & BITMASK(6); numbit = cur_inst & BITMASK(5); newaddr = read_memory_p(dsp_core.pc+1); @@ -2582,24 +2659,21 @@ static void dsp_jsclr_reg(void) } dsp_core.instr_cycle += 4; - if (newaddr >= 0x200) { - dsp_core.instr_cycle += 2*P_WAITSTATE; - } - + if ((value & (1<>6) & 1; addr = (cur_inst>>8) & BITMASK(6); numbit = cur_inst & BITMASK(5); @@ -2607,23 +2681,20 @@ static void dsp_jset_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<>6) & 1; value = (cur_inst>>8) & BITMASK(6); numbit = cur_inst & BITMASK(5); @@ -2632,23 +2703,20 @@ static void dsp_jset_ea(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<>6) & 1; value = (cur_inst>>8) & BITMASK(6); numbit = cur_inst & BITMASK(5); @@ -2657,27 +2725,24 @@ static void dsp_jset_pp(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<>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 { @@ -2685,16 +2750,13 @@ static void dsp_jset_reg(void) } 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; - } } static void dsp_jsr_ea(void) @@ -2737,25 +2796,19 @@ 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) { 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 (newaddr >= 0x200) { - dsp_core.instr_cycle += 2*P_WAITSTATE; - } 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 (newaddr >= 0x200) { - dsp_core.instr_cycle += 2*P_WAITSTATE; - } if (value & (1<>6) & 1; value = (cur_inst>>8) & BITMASK(6); numbit = cur_inst & BITMASK(5); @@ -2805,9 +2855,6 @@ static void dsp_jsset_pp(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<>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 { @@ -2834,9 +2881,6 @@ static void dsp_jsset_reg(void) } dsp_core.instr_cycle += 4; - if (newaddr >= 0x200) { - dsp_core.instr_cycle += 2*P_WAITSTATE; - } if (value & (1<>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) || (numreg2 == DSP_REG_B)) { - dsp_core.registers[DSP_REG_A2+(numreg2 & 1)] = 0; - if (value & (1<<23)) { - dsp_core.registers[DSP_REG_A2+(numreg2 & 1)] = 0xff; - } - dsp_core.registers[DSP_REG_A1+(numreg2 & 1)] = value & BITMASK(24); - dsp_core.registers[DSP_REG_A0+(numreg2 & 1)] = 0; - } else { - dsp_core.registers[numreg2] = value & BITMASK(registers_mask[numreg2]); - } + dsp_write_reg(numreg2, value); } } @@ -2928,13 +2963,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]; } @@ -2949,7 +2984,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); } @@ -2976,14 +3011,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]; } @@ -3001,16 +3036,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]; } @@ -3018,9 +3053,6 @@ static void dsp_movem_aa(void) } dsp_core.instr_cycle += 4; - if (addr>=0x200) { - dsp_core.instr_cycle += P_WAITSTATE; - } } static void dsp_movem_ea(void) @@ -3034,16 +3066,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]; } @@ -3051,9 +3083,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) @@ -3062,7 +3091,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)); @@ -3072,7 +3101,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); @@ -3084,7 +3113,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); } @@ -3112,7 +3141,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) @@ -3133,27 +3165,21 @@ 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 { - 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)); } @@ -3287,7 +3313,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]; } @@ -3312,9 +3338,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 +3349,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) @@ -3347,7 +3367,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)) { @@ -3355,30 +3375,41 @@ 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)) { 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]); } } } @@ -3391,7 +3422,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 */ @@ -3415,7 +3446,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; } @@ -3427,7 +3458,7 @@ static int dsp_pm_read_accu24(int numreg /* No limiting */ *dest=value; return 0; - } + } } if (dsp_core.registers[DSP_REG_A2+reg] == 0xff) { @@ -3435,7 +3466,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)) { @@ -3448,7 +3479,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 */ @@ -3473,31 +3504,28 @@ 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] */ 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) { 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; @@ -3532,7 +3560,7 @@ static void dsp_pm_1(void) else save_1 = dsp_core.registers[numreg1]; } - + /* S2 */ if (memspace) { /* Y: */ @@ -3540,9 +3568,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)](); @@ -3551,18 +3579,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); @@ -3575,7 +3592,7 @@ static void dsp_pm_1(void) } else { /* X: */ numreg2 = DSP_REG_Y0 + ((cur_inst>>16) & 1); - } + } dsp_core.registers[numreg2] = save_2; } @@ -3615,7 +3632,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); @@ -3629,19 +3646,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) @@ -3669,19 +3675,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) @@ -3721,7 +3716,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; } @@ -3729,11 +3724,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); @@ -3784,13 +3774,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; } } @@ -3872,7 +3862,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; @@ -3903,21 +3893,11 @@ 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 */ write_memory(memspace, xy_addr, value); } } @@ -3928,7 +3908,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 @@ -3951,11 +3931,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; @@ -3968,7 +3943,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); @@ -4083,7 +4058,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); @@ -4144,7 +4119,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); @@ -4250,7 +4225,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; } @@ -4330,13 +4305,10 @@ 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); - + if (curcarry) { source[0]=0; source[1]=0; source[2]=1; newsr |= dsp_add56(source, dest); @@ -4365,13 +4337,10 @@ 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); - + if (curcarry) { source[0]=0; source[1]=0; source[2]=1; newsr |= dsp_add56(source, dest); @@ -4400,13 +4369,10 @@ 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); - + if (curcarry) { source[0]=0; source[1]=0; source[2]=1; newsr |= dsp_add56(source, dest); @@ -4435,13 +4401,10 @@ 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); - + if (curcarry) { source[0]=0; source[1]=0; source[2]=1; newsr |= dsp_add56(source, dest); @@ -4518,10 +4481,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 +4506,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 +4531,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 +4556,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 +4581,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 +4606,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 +4631,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 +4656,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 +4681,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 +4706,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 +4731,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 +4756,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 +4942,7 @@ static void dsp_and_y1_b(void) dsp_core.registers[DSP_REG_SR] |= (dsp_core.registers[DSP_REG_B1]==0)<