summaryrefslogtreecommitdiff
path: root/sux.c
diff options
context:
space:
mode:
Diffstat (limited to 'sux.c')
-rw-r--r--sux.c69
1 files changed, 44 insertions, 25 deletions
diff --git a/sux.c b/sux.c
index de88b92..59c2168 100644
--- a/sux.c
+++ b/sux.c
@@ -33,6 +33,7 @@ uint8_t step = 0;
uint8_t *addr;
uint8_t kbd_rdy;
+uint8_t dbg_print_per_inst = 0;
uint8_t end = 0;
@@ -107,6 +108,21 @@ uint8_t is_extop(uint8_t opcode, uint8_t dbg) {
return 1;
}
+int is_wait_kbd(struct sux *cpu, uint8_t opcode, uint8_t prefix, uint8_t ext_prefix, uint8_t prefix2, uint8_t *op_type, uint8_t *op_id, uint8_t op_len, uint8_t thread) {
+ uint64_t address = 0;
+ operand ortho_op[2];
+ uint64_t ortho_addr[2] = {0, 0};
+ uint64_t tmp_pc = cpu->pc;
+ cpu->pc += op_len;
+ if (ext_prefix != 0x1D) {
+ address = get_addr(cpu, opcode, prefix, ext_prefix, 0, 0, thread);
+ } else {
+ get_ortho_addr(cpu, prefix, cpu->pc, ortho_op, ortho_addr, op_type, op_id, 0, 0, thread);
+ }
+ cpu->pc = tmp_pc;
+ return (address == CTRL_ADDR || ortho_addr[0] == CTRL_ADDR || ortho_addr[1] == CTRL_ADDR);
+}
+
void *run(void *args) {
struct suxthr *thr = (void *)args;
struct sux *cpu = &thr->sx;
@@ -169,19 +185,6 @@ void *run(void *args) {
#endif
address.u64 = 0;
value.u64 = 0;
- #if debug && !bench
- if (lines > 24*(thread+1)) {
- lines = (24*thread)+2;
- }
- #if keypoll
- pthread_mutex_lock(&mutex);
- #endif
- print_info(cpu, inst_win, lines, thread);
- print_regs(cpu, regs);
- #if keypoll
- pthread_mutex_unlock(&mutex);
- #endif
- #endif
uint32_t inst = read_value(cpu, 0, cpu->pc, 4, 1, 0);
uint8_t *tmp_inst = (uint8_t *)&inst;
uint8_t inst_len = 0;
@@ -190,8 +193,6 @@ void *run(void *args) {
opcode = tmp_inst[inst_len++];
op_id = (ext_prefix == 0x1D) ? tmp_inst[inst_len++] : 0;
- cpu->pc += inst_len;
- address.u64 = cpu->pc;
uint8_t operand_type[2];
uint8_t am;
uint8_t ortho_id[2];
@@ -253,16 +254,34 @@ void *run(void *args) {
uint8_t rs = (prefix >> 4) & 3;
uint8_t size = (/***/1 << rs) - 1;
uint8_t check_io = (am != IMM);
- #if debug && !bench
- #if keypoll
- pthread_mutex_lock(&mutex);
- #endif
- disasm(cpu, inst_win, lines, opcode, prefix, ext_prefix, prefix2, operand_type, ortho_id, thread);
- lines+=1;
- #if keypoll
- pthread_mutex_unlock(&mutex);
+ cpu->pc += inst_len;
+ address.u64 = cpu->pc;
+ #if debug && !bench
+ cpu->pc -= inst_len;
+ if (!dbg_print_per_inst) {
+ kbd_rdy = is_wait_kbd(cpu, opcode, prefix, ext_prefix, prefix2, operand_type, ortho_id, inst_len, thread);
+ } else {
+ kbd_rdy = 0;
+ }
+ if (lines > 24*(thread+1)) {
+ lines = (24*thread)+2;
+ }
+ if (step | kbd_rdy | dbg_print_per_inst) {
+ #if keypoll
+ pthread_mutex_lock(&mutex);
+ #endif
+ print_info(cpu, inst_win, lines, thread);
+ print_regs(cpu, regs);
+ cpu->pc = address.u64;
+ disasm(cpu, inst_win, lines, opcode, prefix, ext_prefix, prefix2, operand_type, ortho_id, thread);
+ lines+=1;
+ #if keypoll
+ pthread_mutex_unlock(&mutex);
+ #endif
+ } else {
+ cpu->pc = address.u64;
+ }
#endif
- #endif
if (am != IMPL && am != BREG) {
address.u64 = get_addr(cpu, opcode, prefix, ext_prefix, 1, 1, thread);
/*if (address.u64 > mem_size-1) {
@@ -285,7 +304,7 @@ void *run(void *args) {
} else {
exec_base_inst(cpu, opcode, prefix, value.u64, address.u64, size, thread);
}
- //usleep(1);
+ /*usleep(1);*/
#if !IO
ins++;
#endif