From cd6982e5da1f5facdc1e0154b3a27c01e8b076c9 Mon Sep 17 00:00:00 2001 From: mrb0nk500 Date: Wed, 27 Jan 2021 13:42:57 -0500 Subject: - Fixed some bugs in the emulator. - Started work on implementing the Super VIA emulation. - Added support for disabling disassembly per instruction, when in debug mode. - Did some more work on rewriting the SuB Suite to work with the new calling convention. - Rewrote the symbol handling code in the emulator's assembler, to make it both simpler, and to add support for arbitrarily deep symbol scopes. - Added support for arbitrarily deep local symbol scopes. For example, to declare a symbol of depth 2, you add two '@' characters to the start of the symbol name. In other words, the number of '@' characters before the symbol name is what determines the scope of that symbol. And to use a symbol thats outside the current scope, you would use the same syntax as using a struct member, so you would do `global.local`. --- sux.c | 69 +++++++++++++++++++++++++++++++++++++++++++------------------------ 1 file changed, 44 insertions(+), 25 deletions(-) (limited to 'sux.c') 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 -- cgit v1.2.3-13-gbd6f