summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMike Pavone <pavone@retrodev.com>2012-12-19 21:25:39 -0800
committerMike Pavone <pavone@retrodev.com>2012-12-19 21:25:39 -0800
commitb0f3220f3ce75fe7103a7e01527bbf71e7f44d4c (patch)
treed40b9cf6691543c9cbbf421194d05fa2abdea304
parent5061934613fc7cd633ef0ab1551f3bec0491227a (diff)
Cleanup 68K timing code. Temporarily omment out fFPS counter as it was causing segfaults
-rw-r--r--m68k_to_x86.c48
-rw-r--r--render_sdl.c4
-rw-r--r--runtime.S51
3 files changed, 37 insertions, 66 deletions
diff --git a/m68k_to_x86.c b/m68k_to_x86.c
index 262dfab..d566b3a 100644
--- a/m68k_to_x86.c
+++ b/m68k_to_x86.c
@@ -44,13 +44,6 @@ uint8_t * cycles(uint8_t * dst, uint32_t num)
dst = add_ir(dst, num, CYCLES, SZ_D);
}
-uint8_t * check_cycles(uint8_t * dst)
-{
- dst = cmp_rr(dst, CYCLES, LIMIT, SZ_D);
- dst = jcc(dst, CC_G, dst+7);
- dst = call(dst, (char *)handle_cycle_limit);
-}
-
int8_t native_reg(m68k_op_info * op, x86_68k_options * opts)
{
if (op->addr_mode == MODE_REG) {
@@ -119,7 +112,6 @@ uint8_t * translate_m68k_src(m68kinst * inst, x86_ea * ea, uint8_t * out, x86_68
} else {
out = sub_irdisp8(out, inc_amount, CONTEXT, reg_offset(&(inst->src)), SZ_D);
}
- out = check_cycles(out);
case MODE_AREG_INDIRECT:
case MODE_AREG_POSTINC:
if (opts->aregs[inst->src.params.regs.pri] >= 0) {
@@ -177,12 +169,7 @@ uint8_t * translate_m68k_src(m68kinst * inst, x86_ea * ea, uint8_t * out, x86_68
case MODE_IMMEDIATE:
case MODE_IMMEDIATE_WORD:
if (inst->variant != VAR_QUICK) {
- if (inst->extra.size == OPSIZE_LONG && inst->src.addr_mode == MODE_IMMEDIATE) {
- out = cycles(out, BUS);
- out = check_cycles(out);
- }
- out = cycles(out, BUS);
- out = check_cycles(out);
+ out = cycles(out, (inst->extra.size == OPSIZE_LONG && inst->src.addr_mode == MODE_IMMEDIATE) ? BUS*2 : BUS);
}
ea->mode = MODE_IMMED;
ea->disp = inst->src.params.immed;
@@ -507,7 +494,6 @@ uint8_t * translate_m68k_move(uint8_t * dst, m68kinst * inst, x86_68k_options *
//add cycles for prefetch
dst = cycles(dst, BUS);
- dst = check_cycles(dst);
return dst;
}
@@ -519,8 +505,8 @@ uint8_t * translate_m68k_clr(uint8_t * dst, m68kinst * inst, x86_68k_options * o
dst = mov_ir(dst, 1, FLAG_Z, SZ_B);
uint8_t reg = native_reg(&(inst->dst), opts);
if (reg >= 0) {
- dst = xor_rr(dst, reg, reg, inst->extra.size);
- return check_cycles(dst);
+ dst = cycles(dst, (inst->extra.size == OPSIZE_LONG ? 6 : 4));
+ return xor_rr(dst, reg, reg, inst->extra.size);
}
int32_t dec_amount,inc_amount;
switch (inst->dst.addr_mode)
@@ -529,7 +515,6 @@ uint8_t * translate_m68k_clr(uint8_t * dst, m68kinst * inst, x86_68k_options * o
case MODE_AREG:
dst = cycles(dst, (inst->extra.size == OPSIZE_LONG ? 6 : 4));
dst = mov_irdisp8(dst, 0, CONTEXT, reg_offset(&(inst->dst)), inst->extra.size);
- dst = check_cycles(dst);
break;
case MODE_AREG_PREDEC:
dst = cycles(dst, PREDEC_PENALTY);
@@ -543,7 +528,6 @@ uint8_t * translate_m68k_clr(uint8_t * dst, m68kinst * inst, x86_68k_options * o
case MODE_AREG_POSTINC:
//add cycles for prefetch and wasted read
dst = cycles(dst, (inst->extra.size == OPSIZE_LONG ? 12 : 8));
- dst = check_cycles(dst);
if (opts->aregs[inst->dst.params.regs.pri] >= 0) {
dst = mov_rr(dst, opts->aregs[inst->dst.params.regs.pri], SCRATCH2, SZ_D);
} else {
@@ -596,21 +580,15 @@ uint8_t * translate_m68k_lea(uint8_t * dst, m68kinst * inst, x86_68k_options * o
dst = mov_rrdisp8(dst, SCRATCH1, CONTEXT, offsetof(m68k_context, aregs) + 4 * inst->dst.params.regs.pri, SZ_D);
}
}
- dst = check_cycles(dst);
break;
case MODE_ABSOLUTE:
- dst = cycles(dst, BUS);
- dst = check_cycles(dst);
case MODE_ABSOLUTE_SHORT:
- dst = cycles(dst, BUS);
- dst = check_cycles(dst);
- dst = cycles(dst, BUS);
+ dst = cycles(dst, (inst->src.addr_mode == MODE_ABSOLUTE) ? BUS * 3 : BUS * 2);
if (dst_reg >= 0) {
dst = mov_ir(dst, inst->src.params.immed, dst_reg, SZ_D);
} else {
dst = mov_irdisp8(dst, inst->src.params.immed, CONTEXT, offsetof(m68k_context, aregs) + 4 * inst->dst.params.regs.pri, SZ_D);
}
- dst = check_cycles(dst);
break;
}
return dst;
@@ -718,7 +696,6 @@ uint8_t * translate_m68k_jmp(uint8_t * dst, m68kinst * inst, x86_68k_options * o
} else {
dst = mov_rdisp8r(dst, CONTEXT, offsetof(m68k_context, aregs) + 4 * inst->src.params.regs.pri, SCRATCH1, SZ_D);
}
- dst = check_cycles(dst);
dst = call(dst, (uint8_t *)m68k_native_addr);
//TODO: Finish me
//TODO: Fix timing
@@ -726,7 +703,6 @@ uint8_t * translate_m68k_jmp(uint8_t * dst, m68kinst * inst, x86_68k_options * o
case MODE_ABSOLUTE:
case MODE_ABSOLUTE_SHORT:
dst = cycles(dst, inst->src.addr_mode == MODE_ABSOLUTE ? 12 : 10);
- dst = check_cycles(dst);
dest_addr = get_native_address(opts->native_code_map, inst->src.params.immed);
if (!dest_addr) {
opts->deferred = defer_address(opts->deferred, inst->src.params.immed, dst + 1);
@@ -756,7 +732,6 @@ uint8_t * translate_m68k_dbcc(uint8_t * dst, m68kinst * inst, x86_68k_options *
{
//best case duration
dst = cycles(dst, 10);
- dst = check_cycles(dst);
uint8_t * skip_loc = NULL;
//TODO: Check if COND_TRUE technically valid here even though
//it's basically a slow NOP
@@ -831,7 +806,6 @@ uint8_t * translate_m68k_dbcc(uint8_t * dst, m68kinst * inst, x86_68k_options *
} else {
dst = cycles(dst, 4);
}
- dst = check_cycles(dst);
return dst;
}
@@ -845,12 +819,10 @@ uint8_t * translate_shift(uint8_t * dst, m68kinst * inst, x86_ea *src_op, x86_ea
uint8_t * end_off = NULL;
if (inst->src.addr_mode == MODE_UNUSED) {
dst = cycles(dst, BUS);
- dst = check_cycles(dst);
//Memory shift
dst = shift_ir(dst, 1, dst_op->base, SZ_W);
} else {
dst = cycles(dst, inst->extra.size == OPSIZE_LONG ? 8 : 6);
- dst = check_cycles(dst);
if (src_op->mode == MODE_IMMED) {
if (dst_op->mode == MODE_REG_DIRECT) {
dst = shift_ir(dst, src_op->disp, dst_op->base, inst->extra.size);
@@ -933,8 +905,6 @@ uint8_t * translate_shift(uint8_t * dst, m68kinst * inst, x86_ea *src_op, x86_ea
dst = mov_rrind(dst, FLAG_C, CONTEXT, SZ_B);
if (inst->src.addr_mode == MODE_UNUSED) {
dst = m68k_save_result(inst, dst, opts);
- } else {
- dst = check_cycles(dst);
}
}
@@ -992,7 +962,6 @@ uint8_t * translate_m68k(uint8_t * dst, m68kinst * inst, x86_68k_options * opts)
dst = setcc_r(dst, CC_S, FLAG_N);
dst = setcc_r(dst, CC_O, FLAG_V);
dst = mov_rrind(dst, FLAG_C, CONTEXT, SZ_B);
- dst = check_cycles(dst);
dst = m68k_save_result(inst, dst, opts);
break;
case M68K_ADDX:
@@ -1018,7 +987,6 @@ uint8_t * translate_m68k(uint8_t * dst, m68kinst * inst, x86_68k_options * opts)
dst = setcc_r(dst, CC_Z, FLAG_Z);
dst = setcc_r(dst, CC_S, FLAG_N);
dst = mov_ir(dst, 0, FLAG_V, SZ_B);
- dst = check_cycles(dst);
dst = m68k_save_result(inst, dst, opts);
break;
case M68K_ANDI_CCR:
@@ -1100,7 +1068,6 @@ uint8_t * translate_m68k(uint8_t * dst, m68kinst * inst, x86_68k_options * opts)
dst = setcc_r(dst, CC_Z, FLAG_Z);
dst = setcc_r(dst, CC_S, FLAG_N);
dst = setcc_r(dst, CC_O, FLAG_V);
- dst = check_cycles(dst);
break;
case M68K_DIVS:
case M68K_DIVU:
@@ -1126,7 +1093,6 @@ uint8_t * translate_m68k(uint8_t * dst, m68kinst * inst, x86_68k_options * opts)
dst = setcc_r(dst, CC_Z, FLAG_Z);
dst = setcc_r(dst, CC_S, FLAG_N);
dst = mov_ir(dst, 0, FLAG_V, SZ_B);
- dst = check_cycles(dst);
dst = m68k_save_result(inst, dst, opts);
break;
case M68K_EORI_CCR:
@@ -1153,7 +1119,6 @@ uint8_t * translate_m68k(uint8_t * dst, m68kinst * inst, x86_68k_options * opts)
dst = mov_rrdisp8(dst, SCRATCH2, src_op.base, src_op.disp, SZ_D);
}
}
- dst = check_cycles(dst);
break;
case M68K_EXT:
break;
@@ -1179,7 +1144,6 @@ uint8_t * translate_m68k(uint8_t * dst, m68kinst * inst, x86_68k_options * opts)
break;
case M68K_NOP:
dst = cycles(dst, BUS);
- dst = check_cycles(dst);
break;
case M68K_NOT:
break;
@@ -1204,7 +1168,6 @@ uint8_t * translate_m68k(uint8_t * dst, m68kinst * inst, x86_68k_options * opts)
dst = setcc_r(dst, CC_Z, FLAG_Z);
dst = setcc_r(dst, CC_S, FLAG_N);
dst = mov_ir(dst, 0, FLAG_V, SZ_B);
- dst = check_cycles(dst);
dst = m68k_save_result(inst, dst, opts);
break;
case M68K_ORI_CCR:
@@ -1243,7 +1206,6 @@ uint8_t * translate_m68k(uint8_t * dst, m68kinst * inst, x86_68k_options * opts)
dst = setcc_r(dst, CC_S, FLAG_N);
dst = setcc_r(dst, CC_O, FLAG_V);
dst = mov_rrind(dst, FLAG_C, CONTEXT, SZ_B);
- dst = check_cycles(dst);
dst = m68k_save_result(inst, dst, opts);
break;
case M68K_SUBX:
@@ -1259,7 +1221,6 @@ uint8_t * translate_m68k(uint8_t * dst, m68kinst * inst, x86_68k_options * opts)
dst = setcc_r(dst, CC_Z, FLAG_Z);
dst = setcc_r(dst, CC_S, FLAG_N);
dst = mov_ir(dst, 0, FLAG_V, SZ_B);
- dst = check_cycles(dst);
break;
case M68K_TAS:
case M68K_TRAP:
@@ -1275,7 +1236,6 @@ uint8_t * translate_m68k(uint8_t * dst, m68kinst * inst, x86_68k_options * opts)
dst = setcc_r(dst, CC_Z, FLAG_Z);
dst = setcc_r(dst, CC_S, FLAG_N);
dst = setcc_r(dst, CC_O, FLAG_V);
- dst = check_cycles(dst);
break;
case M68K_UNLK:
case M68K_INVALID:
diff --git a/render_sdl.c b/render_sdl.c
index 2c82cd1..4e0b01e 100644
--- a/render_sdl.c
+++ b/render_sdl.c
@@ -202,6 +202,8 @@ void wait_render_frame(vdp_context * context)
}
}
render_context(context);
+ /*
+ //TODO: Figure out why this causes segfaults
frame_counter++;
if ((last_frame - start) > 1000) {
if (start) {
@@ -210,7 +212,7 @@ void wait_render_frame(vdp_context * context)
}
start = last_frame;
frame_counter = 0;
- }
+ }*/
}
diff --git a/runtime.S b/runtime.S
index b117b77..2d355a3 100644
--- a/runtime.S
+++ b/runtime.S
@@ -31,6 +31,7 @@ bad_access_msg:
.global m68k_write_word
.global try_fifo_write
m68k_write_word:
+ call inccycles
and $0xFFFFFF, %rdi
cmp $0x400000, %edi
jle cart_w
@@ -38,14 +39,14 @@ m68k_write_word:
jge workram_w
cmp $0xC00000, %edi
jge vdp_psg_w
- jmp inccycles
+ ret
workram_w:
and $0xFFFF, %rdi
mov %cx, (%r9, %rdi)
- jmp inccycles
+ ret
cart_w:
mov %cx, (%r8, %rdi)
- jmp inccycles
+ ret
vdp_psg_w:
test $0x2700E0, %edi
jnz crash
@@ -77,7 +78,7 @@ try_fifo_write:
andb $0xEF, 19(%rdx)
pop %rbx
pop %rdx
- jmp inccycles
+ ret
fifo_fallback:
pop %rbx
pop %rdx
@@ -91,6 +92,7 @@ crash:
.global m68k_write_byte
m68k_write_byte:
+ call inccycles
and $0xFFFFFF, %rdi
/* deal with byte swapping */
xor $1, %edi
@@ -98,14 +100,14 @@ m68k_write_byte:
jle cart_wb
cmp $0xE00000, %edi
jge workram_wb
- jmp inccycles
+ ret
workram_wb:
and $0xFFFF, %rdi
mov %cl, (%r9, %rdi)
- jmp inccycles
+ ret
cart_wb:
mov %cl, (%r8, %rdi)
- jmp inccycles
+ ret
.global m68k_write_long_lowfirst
m68k_write_long_lowfirst:
@@ -126,9 +128,24 @@ m68k_write_long_highfirst:
pop %rdi
add $2, %rdi
jmp m68k_write_word
+
+inccycles:
+ cmp %rbp, %rax
+ jge do_limit
+ add $4, %rax
+ ret
+do_limit:
+ push %rcx
+ push %rdi
+ call handle_cycle_limit
+ pop %rdi
+ pop %rcx
+ add $4, %rax
+ ret
.global m68k_read_word_scratch1
m68k_read_word_scratch1:
+ call inccycles
and $0xFFFFFF, %rcx
cmp $0x400000, %ecx
jle cart
@@ -138,11 +155,11 @@ m68k_read_word_scratch1:
jge vdp_psg
xor %cx, %cx
dec %cx
- jmp inccycles
+ ret
workram:
and $0xFFFF, %rcx
mov (%r9, %rcx), %cx
- jmp inccycles
+ ret
vdp_psg:
test $0x2700E0, %ecx
jnz crash
@@ -150,15 +167,6 @@ vdp_psg:
jmp do_vdp_port_read
cart:
mov (%r8, %rcx), %cx
-inccycles:
- add $4, %rax
- cmp %rbp, %rax
- jge do_limit
- ret
-do_limit:
- push %rcx
- call handle_cycle_limit
- pop %rcx
ret
.global m68k_read_long_scratch1
@@ -176,6 +184,7 @@ m68k_read_long_scratch1:
.global m68k_read_byte_scratch1
m68k_read_byte_scratch1:
+ call inccycles
and $0xFFFFFF, %rcx
/* deal with byte swapping */
xor $1, %ecx
@@ -185,14 +194,14 @@ m68k_read_byte_scratch1:
jge workram_b
xor %cl, %cl
dec %cl
- jmp inccycles
+ ret
workram_b:
and $0xFFFF, %rcx
mov (%r9, %rcx), %cl
- jmp inccycles
+ ret
cart_b:
mov (%r8, %rcx), %cl
- jmp inccycles
+ ret
ret_addr_msg:
.asciz "Program modified return address on stack: found %X, expected %X\n"