From: j8takagi Date: Tue, 3 Jul 2018 14:54:15 +0000 (+0900) Subject: COMET IIモニターに、コマンドQUITとREVERSEを追加 X-Git-Tag: v0.5p1~12 X-Git-Url: https://j8takagi.net/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=2a1b2ba47ff6596864ab38c8d9419e3c1372ef6e;p=YACASL2.git COMET IIモニターに、コマンドQUITとREVERSEを追加 --- diff --git a/include/exec.h b/include/exec.h index fb8e6b3..3e36e4b 100644 --- a/include/exec.h +++ b/include/exec.h @@ -396,11 +396,15 @@ void dspregister(); */ bool disassemble_file(const char *file); + /** - * @brief COMET IIモニターを起動する + * @brief COMET IIのメモリーを逆アセンブルし、標準出力へ出力する * * @return なし + * + * @param *start 逆アセンブルの開始位置 + * @param *end 逆アセンブルの終了位置 */ -void monitor(); +void disassemble_memory(WORD start, WORD end); #endif /* YACASL2_EXEC_INCLUDEDの終端 */ diff --git a/include/monitor.h b/include/monitor.h index 3530061..4b8c1fe 100644 --- a/include/monitor.h +++ b/include/monitor.h @@ -130,4 +130,11 @@ bool delbps(WORD adr); */ void freebps(); +/** + * @brief COMET IIモニターを起動する + * + * @return なし + */ +void monitor(); + #endif /* end of MONITOR_INCLUDE */ diff --git a/src/exec.c b/src/exec.c index 7329776..2bca011 100644 --- a/src/exec.c +++ b/src/exec.c @@ -851,13 +851,48 @@ execfin: } } +void disassemble_cmd_adr_x(CMDTYPE cmdtype, const char *cmdname, WORD word, WORD adr, WORD loc) +{ + WORD x; + char *g; + fprintf(stdout, "\t%s\t", cmdname); + if(cmdtype == R_ADR_X) { + fprintf(stdout, "%s,", g = grstr((word & 0x00F0) >> 4)); + FREE(g); + } + fprintf(stdout, "#%04X", adr); + if((x = (word & 0x000F)) != 0) { + fprintf(stdout, ",%s", g = grstr(x)); + FREE(g); + } + fprintf(stdout, "\t\t\t\t; #%04X: #%04X #%04X", loc, word, adr); +} + +void disassemble_cmd_r(CMDTYPE cmdtype, const char *cmdname, WORD word, WORD loc) +{ + char *g, *g1, *g2; + fprintf(stdout, "\t%s", cmdname); + if(cmdtype == R1_R2) { + g1 = grstr((word & 0x00F0) >> 4); + g2 = grstr(word & 0x000F); + fprintf(stdout, "\t%s,%s", g1, g2); + FREE(g1); + FREE(g2); + } else if(cmdtype == R_) { + g = grstr((word & 0x00F0) >> 4); + fprintf(stdout, "\t%s", g); + FREE(g); + } + fprintf(stdout, "\t\t\t\t; #%04X: #%04X", loc, word); +} + bool disassemble_file(const char *file) { bool stat = true; FILE *fp; - WORD i = 0, w, cmd, x, adr; + WORD i = 0, w, cmd, adr; CMDTYPE cmdtype = 0; - char *cmdname, *g, *g1, *g2; + char *cmdname; assert(file != NULL); if((fp = fopen(file, "rb")) == NULL) { @@ -868,46 +903,19 @@ bool disassemble_file(const char *file) create_code_cmdtype(); /* 命令のコードとタイプがキーのハッシュ表を作成 */ fprintf(stdout, "MAIN\tSTART\n"); - for(; ;) { - fread(&w, sizeof(WORD), 1, fp); - if(feof(fp)) { - break; - } + for(fread(&w, sizeof(WORD), 1, fp); !feof(fp); fread(&w, sizeof(WORD), 1, fp)) { cmd = w & 0xFF00; cmdname = getcmdname(cmd); cmdtype = getcmdtype(cmd); - if(cmd == 0xFF00 || (w != 0 && cmd == 0x0000)) { + if(cmd == 0xFF00 || (w != 0 && cmd == 0)) { fprintf(stdout, "\tDC\t%d\t\t\t\t; #%04X: #%04X :: ", w, i++, w); print_dumpword(w, true); } else if(cmdtype == R_ADR_X || cmdtype == ADR_X) { fread(&adr, sizeof(WORD), 1, fp); - fprintf(stdout, "\t%s\t", cmdname); - if(cmdtype == R_ADR_X) { - g = grstr((w & 0x00F0) >> 4); - fprintf(stdout, "%s,", g); - FREE(g); - } - fprintf(stdout, "#%04X", adr); - if((x = w & 0x000F) != 0) { - fprintf(stdout, ",%s", g = grstr(x)); - FREE(g); - } - fprintf(stdout, "\t\t\t\t; #%04X: #%04X #%04X", i, w, adr); + disassemble_cmd_adr_x(cmdtype, cmdname, w, adr, i); i += 2; } else { - fprintf(stdout, "\t%s", cmdname); - if(cmdtype == R1_R2) { - g1 = grstr((w & 0x00F0) >> 4); - g2 = grstr(w & 0x000F); - fprintf(stdout, "\t%s,%s", g1, g2); - FREE(g1); - FREE(g2); - } else if(cmdtype == R_) { - g = grstr((w & 0x00F0) >> 4); - fprintf(stdout, "\t%s", g); - FREE(g); - } - fprintf(stdout, "\t\t\t\t; #%04X: #%04X", i++, w); + disassemble_cmd_r(cmdtype, cmdname, w, i++); } fprintf(stdout, "\n"); } @@ -916,3 +924,27 @@ bool disassemble_file(const char *file) fclose(fp); return stat; } + +void disassemble_memory(WORD start, WORD end) +{ + WORD i, w, cmd, adr; + CMDTYPE cmdtype = 0; + char *cmdname; + + for(i = start; i <= end; i++) { + w = sys->memory[i]; + cmd = w & 0xFF00; + cmdname = getcmdname(cmd); + cmdtype = getcmdtype(cmd); + if(cmd == 0xFF00 || (w != 0 && cmd == 0)) { + fprintf(stdout, "\tDC\t%d\t\t\t\t; #%04X: #%04X :: ", w, i, w); + print_dumpword(w, true); + } else if(cmdtype == R_ADR_X || cmdtype == ADR_X) { + adr = sys->memory[i+1]; + disassemble_cmd_adr_x(cmdtype, cmdname, w, adr, i++); + } else { + disassemble_cmd_r(cmdtype, cmdname, w, i); + } + fprintf(stdout, "\n"); + } +} diff --git a/src/monitor.c b/src/monitor.c index e0c7dc4..d4189fa 100644 --- a/src/monitor.c +++ b/src/monitor.c @@ -222,17 +222,17 @@ void mon_break(int argc, char *argv[]) } } -bool monitorcmd(char *cmd, MONARGS *args) +MONCMDTYPE monitorcmd(char *cmd, MONARGS *args) { - bool next = false; + MONCMDTYPE cmdtype = MONREPEAT; if(stracmp(cmd, 2, (char* []){"s", "step"})) { execmode.step = true; - next = true; + cmdtype = MONNEXT; } else if(stracmp(cmd, 2, (char* []){"b", "break"})) { mon_break(args->argc, args->argv); } else if(stracmp(cmd, 2, (char* []){"c", "continue"})) { execmode.step = false; - next = true; + cmdtype = MONNEXT; } else if(stracmp(cmd, 2, (char* []){"t", "trace"})) { if(args->argc > 0 && stracmp(args->argv[0], 2, (char* []){"a", "auto"})) { execmode.logical = false; @@ -258,9 +258,18 @@ bool monitorcmd(char *cmd, MONARGS *args) execmode.dump = true; } else if(args->argc > 0 && stracmp(args->argv[0], 2, (char* []){"no", "noauto"})) { execmode.dump = false; - } else { - dumpmemory(); + } else if(args->argc == 1) { + dumpmemory(nh2word(args->argv[0]), 0xFFFF); + } else if(args->argc > 1) { + dumpmemory(nh2word(args->argv[0]), nh2word(args->argv[1])); + } + } else if(stracmp(cmd, 2, (char* []){"r", "reverse"})) { + if(args->argc == 2) { + disassemble_memory(nh2word(args->argv[0]), nh2word(args->argv[1])); } + } else if(stracmp(cmd, 2, (char* []){"q", "quit"})) { + fprintf(stdout, "Quit: COMET II monitor\n"); + cmdtype = MONQUIT; } else if(stracmp(cmd, 3, (char* []){"?", "h", "help"})) { fprintf(stdout, "b[reak] -- Manipulate Breakpoints. Details in `b ?'.\n"); fprintf(stdout, "s[tep] -- Step by step running your program until next interaction.\n"); @@ -269,7 +278,7 @@ bool monitorcmd(char *cmd, MONARGS *args) fprintf(stdout, "d[ump] -- Display memory dump. `d[ump] a[uto]/n[oauto]' set auto/noauto display.\n"); fprintf(stdout, "?/h[elp] -- Display this help.\n"); } - return next; + return cmdtype; } void free_moncmdline(MONCMDLINE *moncmdl) @@ -294,7 +303,7 @@ void monitor() { char *buf, *p; MONCMDLINE *moncmdl; - bool next = false; + MONCMDTYPE cmdtype = MONREPEAT; do { fprintf(stdout, "COMET II (Type ? for help) > "); buf = malloc_chk(MONINSIZE + 1, "monitor.buf"); @@ -303,9 +312,16 @@ void monitor() *p = '\0'; } if((moncmdl = monlinetok(buf)) != NULL) { - next = monitorcmd(moncmdl->cmd, moncmdl->args); + cmdtype = monitorcmd(moncmdl->cmd, moncmdl->args); free_moncmdline(moncmdl); } FREE(buf); - } while(next == false); + if(cmdtype == MONQUIT) { + shutdown(); + freebps(); + free_code_cmdtype(); + freecerr(); + exit(0); + } + } while(cmdtype == MONREPEAT); }