diff --git a/debug.c b/debug.c index 4e1d37a..7b823cd 100644 --- a/debug.c +++ b/debug.c @@ -161,7 +161,7 @@ void translate_args(uint16_t a1, uint16_t a2, uint16_t a3, char *arg1, char *arg } else { - sprintf(arg1,"%d",a1); + sprintf(arg1,"%02X",a1); } if(a2 > MAX_INT) @@ -170,7 +170,7 @@ void translate_args(uint16_t a1, uint16_t a2, uint16_t a3, char *arg1, char *arg } else { - sprintf(arg2,"%d",a2); + sprintf(arg2,"%02X",a2); } if(a3 > MAX_INT) @@ -179,7 +179,7 @@ void translate_args(uint16_t a1, uint16_t a2, uint16_t a3, char *arg1, char *arg } else { - sprintf(arg3,"%d",a3); + sprintf(arg3,"%02X",a3); } } @@ -193,64 +193,71 @@ void print_instruction(uint16_t opcode, uint16_t a1, uint16_t a2, uint16_t a3) switch(opcode) { case HALT: - fprintf(stderr,"HALT\n"); + fprintf(stderr, "HALT\n"); break; case MOV: - fprintf(stderr,"MOV %s %s\n",arg1,arg2); + fprintf(stderr, "MOV %s %s\n", arg1, arg2); break; case PUSH: - fprintf(stderr,"PUSH %s\n",arg1); + fprintf(stderr, "PUSH %s\n", arg1); break; case POP: - fprintf(stderr,"POP %s\n",arg1); + fprintf(stderr, "POP %s\n", arg1); break; case TEQ: - fprintf(stderr,"TEQ %s %s %s\n",arg1,arg2,arg3); + fprintf(stderr, "TEQ %s %s %s\n", arg1, arg2, arg3); break; case TGT: - fprintf(stderr,"TGT %s %s %s\n",arg1,arg2,arg3); + fprintf(stderr, "TGT %s %s %s\n", arg1, arg2, arg3); break; case JMP: - fprintf(stderr,"JMP %s\n",arg1); + fprintf(stderr, "JMP %s\n", arg1); break; case JNZ: - fprintf(stderr,"JNZ %s %s\n",arg1,arg2); + fprintf(stderr, "JNZ %s %s\n", arg1, arg2); break; case JZ: - fprintf(stderr,"JZ %s %s\n",arg1,arg2); + fprintf(stderr, "JZ %s %s\n", arg1, arg2); break; case ADD: - fprintf(stderr,"ADD %s %s %s\n",arg1,arg2,arg3); + fprintf(stderr, "ADD %s %s %s\n", arg1, arg2, arg3); break; case MUL: - fprintf(stderr,"MUL %s %s %s\n",arg1,arg2,arg3); + fprintf(stderr, "MUL %s %s %s\n", arg1, arg2, arg3); break; case MOD: - fprintf(stderr,"MOD %s %s %s\n",arg1,arg2,arg3); + fprintf(stderr, "MOD %s %s %s\n", arg1, arg2, arg3); break; case AND: - fprintf(stderr,"AND %s %s %s\n",arg1,arg2,arg3); + fprintf(stderr, "AND %s %s %s\n", arg1, arg2, arg3); break; case OR: - fprintf(stderr,"OR %s %s %s\n",arg1,arg2,arg3); + fprintf(stderr, "OR %s %s %s\n", arg1, arg2, arg3); break; case NOT: - fprintf(stderr,"NOT %s %s\n",arg1,arg2); + fprintf(stderr, "NOT %s %s\n", arg1, arg2); break; case LOAD: - fprintf(stderr,"LOAD %s %s\n",arg1,arg2); + fprintf(stderr, "LOAD %s %s\n", arg1, arg2); break; case STOR: - fprintf(stderr,"STOR %s %s\n",arg1,arg2); + fprintf(stderr, "STOR %s %s\n", arg1, arg2); break; case CALL: - fprintf(stderr,"CALL %s\n",arg1); + fprintf(stderr, "CALL %s\n", arg1); break; case RET: - fprintf(stderr,"RET\n"); + fprintf(stderr, "RET\n"); break; case OUT: - fprintf(stderr,"OUT %s\n",arg1); + if (a1 <= MAX_INT) + { + fprintf(stderr, "OUT '%c'\n",a1); + } + else + { + fprintf(stderr, "OUT %s\n", arg1); + } break; case IN: fprintf(stderr,"IN %s\n",arg1); @@ -259,7 +266,7 @@ void print_instruction(uint16_t opcode, uint16_t a1, uint16_t a2, uint16_t a3) fprintf(stderr,"NOP\n"); break; default: - fprintf(stderr,"UNK %d\n", opcode); + fprintf(stderr,"UNK %02X\n", opcode); break; } } @@ -273,10 +280,15 @@ void debug_program() uint16_t arg3; for(;;) { + if(in_breakpoint(pc)) + { + breakpoint = 1; + fprintf(stderr,"Breakpoint hit @ pc=%02X",pc); + } if(in_breakpoint(pc) || breakpoint) { breakpoint = 1; - fprintf(stderr, "%d: ", pc); + fprintf(stderr, "%02X: ", pc); print_instruction(mem[pc], mem[pc+1], mem[pc+2], mem[pc+3]); query(); } diff --git a/disasm.c b/disasm.c index 03b255d..c389c51 100644 --- a/disasm.c +++ b/disasm.c @@ -11,7 +11,7 @@ void disassemble_program(uint32_t length) { break; } - fprintf(stderr,"%d: ",pc); + fprintf(stderr,"%02X: ",pc); uint16_t opcode = fetch(); decode_instruction(opcode,&arg1,&arg2,&arg3); print_instruction(opcode,arg1,arg2,arg3); diff --git a/registers.c b/registers.c index fc6a595..71d972b 100644 --- a/registers.c +++ b/registers.c @@ -11,15 +11,15 @@ uint16_t pc = 0; void print_regs() { - fprintf(stderr,"r0: %2x\n",regs[0]); - fprintf(stderr,"r1: %2x\n",regs[1]); - fprintf(stderr,"r2: %2x\n",regs[2]); - fprintf(stderr,"r3: %2x\n",regs[3]); - fprintf(stderr,"r4: %2x\n",regs[4]); - fprintf(stderr,"r5: %2x\n",regs[5]); - fprintf(stderr,"r6: %2x\n",regs[6]); - fprintf(stderr,"r7: %2x\n",regs[7]); - fprintf(stderr,"pc: %2x\n",pc); + fprintf(stderr,"r0: %02X\n",regs[0]); + fprintf(stderr,"r1: %02X\n",regs[1]); + fprintf(stderr,"r2: %02X\n",regs[2]); + fprintf(stderr,"r3: %02X\n",regs[3]); + fprintf(stderr,"r4: %02X\n",regs[4]); + fprintf(stderr,"r5: %02X\n",regs[5]); + fprintf(stderr,"r6: %02X\n",regs[6]); + fprintf(stderr,"r7: %02X\n",regs[7]); + fprintf(stderr,"pc: %02X\n",pc); } void dump_regs(uint16_t *dump)