-/*
-MOV #imm,Rn 1110nnnniiiiiiii
-MOV.W @(disp,PC),Rn 1001nnnndddddddd
-MOV.L @(disp,PC),Rn 1101nnnndddddddd
-MOV Rm,Rn 0110nnnnmmmm0011
-MOV.B @Rm,Rn 0110nnnnmmmm0000
-MOV.W @Rm,Rn 0110nnnnmmmm0001
-MOV.L @Rm,Rn 0110nnnnmmmm0010
-MOV.B @Rm+,Rn 0110nnnnmmmm0100
-MOV.W @Rm+,Rn 0110nnnnmmmm0101
-MOV.L @Rm+,Rn 0110nnnnmmmm0110
-MOV.B R0,@(disp,Rn) 10000000nnnndddd
-MOV.W R0,@(disp,Rn) 10000001nnnndddd
-MOV.B @(disp,Rm),R0 10000100mmmmdddd
-MOV.W @(disp,Rm),R0 10000101mmmmdddd
-MOV.L @(disp,Rm),Rn 0101nnnnmmmmdddd
-MOV.B R0,@(disp,GBR) 11000000dddddddd
-MOV.W R0,@(disp,GBR) 11000001dddddddd
-MOV.L R0,@(disp,GBR) 11000010dddddddd
-MOV.B @(disp,GBR),R0 11000100dddddddd
-MOV.W @(disp,GBR),R0 11000101dddddddd
-MOV.L @(disp,GBR),R0 11000110dddddddd
-MOVA @(disp,PC),R0 11000111dddddddd
-SWAP.B Rm,Rn 0110nnnnmmmm1000
-SWAP.W Rm,Rn 0110nnnnmmmm1001
-XTRCT Rm,Rn 0010nnnnmmmm1101
-ADD Rm,Rn 0011nnnnmmmm1100
-ADD #imm,Rn 0111nnnniiiiiiii
-ADDC Rm,Rn 0011nnnnmmmm1110
-ADDV Rm,Rn 0011nnnnmmmm1111
-CMP/EQ #imm,R0 10001000iiiiiiii
-CMP/EQ Rm,Rn 0011nnnnmmmm0000
-CMP/HS Rm,Rn 0011nnnnmmmm0010
-CMP/GE Rm,Rn 0011nnnnmmmm0011
-CMP/HI Rm,Rn 0011nnnnmmmm0110
-CMP/GT Rm,Rn 0011nnnnmmmm0111
-CMP/PZ Rn 0100nnnn00010001
-CMP/PL Rn 0100nnnn00010101
-CMP/ST Rm,Rn 0010nnnnmmmm1100
-DIV1 Rm,Rn 0011nnnnmmmm0100
-DMULS. Rm,Rn 0011nnnnmmmm1101
-DMULU.L Rm,Rn 0011nnnnmmmm0101
-EXTS.B Rm,Rn 0110nnnnmmmm1110
-EXTS.W Rm,Rn 0110nnnnmmmm1111
-EXTU.B Rm,Rn 0110nnnnmmmm1100
-EXTU.W Rm,Rn 0110nnnnmmmm1101
-MAC @Rm+,@Rn+ 0100nnnnmmmm1111
-MULS.W Rm,Rn 0010nnnnmmmm1111
-MULU.W Rm,Rn 0010nnnnmmmm1110
-NEG Rm,Rn 0110nnnnmmmm1011
-NEGC Rm,Rn 0110nnnnmmmm1010
-SUB Rm,Rn 0011nnnnmmmm1000
-SUBC Rm,Rn 0011nnnnmmmm1010
-SUBV Rm,Rn 0011nnnnmmmm1011
-AND Rm,Rn 0010nnnnmmmm1001
-AND #imm,R0 11001001iiiiiiii
-AND.B #imm,@(R0,GBR) 11001101iiiiiiii
-NOT Rm,Rn 0110nnnnmmmm0111
-OR Rm,Rn 0010nnnnmmmm1011
-OR #imm,R0 11001011iiiiiiii
-OR.B #imm,@(R0,GBR) 11001111iiiiiiii
-TAS.B @Rn 0100nnnn00011011
-TST Rm,Rn 0010nnnnmmmm1000
-TST #imm,R0 11001000iiiiiiii
-TST.B #imm,@(R0,GBR) 11001100iiiiiiii
-XOR Rm,Rn 0010nnnnmmmm1010
-XOR #imm,R0 11001010iiiiiiii
-XOR.B #imm,@(R0,GBR) 11001110iiiiiiii
-ROTL Rn 0100nnnn00000100
-ROTR Rn 0100nnnn00000101
-ROTCL Rn 0100nnnn00100100
-ROTCR Rn 0100nnnn00100101
-SHAL Rn 0100nnnn00100000
-SHAR Rn 0100nnnn00100001
-SHLL Rn 0100nnnn00000000
-SHLR Rn 0100nnnn00000001
-SHLL2 Rn 0100nnnn00001000
-SHLR2 Rn 0100nnnn00001001
-SHLL8 Rn 0100nnnn00011000
-SHLR8 Rn 0100nnnn00011001
-SHLL16 Rn 0100nnnn00101000
-SHLR16 Rn 0100nnnn00101001
-LDC Rm,GBR 0100mmmm00011110
-LDC Rm,VBR 0100mmmm00101110
-LDC.L @Rm+,GBR 0100mmmm00010111
-LDC.L @Rm+,VBR 0100mmmm00100111
-LDS Rm,MACH 0100mmmm00001010
-LDS Rm,MACL 0100mmmm00011010
-LDS Rm,PR 0100mmmm00101010
-LDS.L @Rm+,MACH 0100mmmm00000110
-LDS.L @Rm+,MACL 0100mmmm00010110
-LDS.L @Rm+,PR 0100mmmm00100110
-STC.L SR,@–Rn 0100nnnn00000011
-STC.L GBR,@–Rn 0100nnnn00010011
-STC.L VBR,@–Rn 0100nnnn00100011
-STS.L MACH,@–Rn 0100nnnn00000010
-STS.L MACL,@–Rn 0100nnnn00010010
-STS.L PR,@–Rn 0100nnnn00100010
-TRAPA #imm 11000011iiiiiiii
-*/
+// @(Rx,Ry)
+static int emit_indirect_indexed_read(int rx, int ry, int size)
+{
+ int a0, t;
+ a0 = rcache_get_reg_arg(0, rx);
+ t = rcache_get_reg(ry, RC_GR_READ);
+ emith_add_r_r(a0, t);
+ return emit_memhandler_read(size);
+}
+
+// read @Rn, @rm
+static void emit_indirect_read_double(u32 *rnr, u32 *rmr, int rn, int rm, int size)
+{
+ int tmp;
+
+ rcache_get_reg_arg(0, rn);
+ tmp = emit_memhandler_read(size);
+ emith_ctx_write(tmp, offsetof(SH2, drc_tmp));
+ rcache_free_tmp(tmp);
+ tmp = rcache_get_reg(rn, RC_GR_RMW);
+ emith_add_r_imm(tmp, 1 << size);
+ rcache_unlock(tmp);
+
+ rcache_get_reg_arg(0, rm);
+ *rmr = emit_memhandler_read(size);
+ *rnr = rcache_get_tmp();
+ emith_ctx_read(*rnr, offsetof(SH2, drc_tmp));
+ tmp = rcache_get_reg(rm, RC_GR_RMW);
+ emith_add_r_imm(tmp, 1 << size);
+ rcache_unlock(tmp);
+}
+
+static void emit_do_static_regs(int is_write, int tmpr)
+{
+ int i, r, count;
+
+ for (i = 0; i < ARRAY_SIZE(reg_map_g2h); i++) {
+ r = reg_map_g2h[i];
+ if (r == -1)
+ continue;
+
+ for (count = 1; i < ARRAY_SIZE(reg_map_g2h) - 1; i++, r++) {
+ if (reg_map_g2h[i + 1] != r + 1)
+ break;
+ count++;
+ }
+
+ if (count > 1) {
+ // i, r point to last item
+ if (is_write)
+ emith_ctx_write_multiple(r - count + 1, (i - count + 1) * 4, count, tmpr);
+ else
+ emith_ctx_read_multiple(r - count + 1, (i - count + 1) * 4, count, tmpr);
+ } else {
+ if (is_write)
+ emith_ctx_write(r, i * 4);
+ else
+ emith_ctx_read(r, i * 4);
+ }
+ }
+}
+
+static void emit_block_entry(void)
+{
+ int arg0, arg1, arg2;
+
+ host_arg2reg(arg0, 0);
+ host_arg2reg(arg1, 1);
+ host_arg2reg(arg2, 2);
+
+#if (DRC_DEBUG & 8) || defined(PDB)
+ emit_do_static_regs(1, arg2);
+ emith_move_r_r(arg1, CONTEXT_REG);
+ emith_move_r_r(arg2, rcache_get_reg(SHR_SR, RC_GR_READ));
+ emith_call(sh2_drc_log_entry);
+ rcache_invalidate();
+#endif
+ emith_tst_r_r(arg0, arg0);
+ EMITH_SJMP_START(DCOND_EQ);
+ emith_jump_reg_c(DCOND_NE, arg0);
+ EMITH_SJMP_END(DCOND_EQ);
+}