X-Git-Url: http://j8takagi.net/cgi-bin/gitweb.cgi?p=YACASL2.git;a=blobdiff_plain;f=src%2Fcomet2.c;h=1adf4266580c3ad8b36ac8a15a063e2f542315df;hp=03120350a9d9e8af2483d2a671ee41db26c097df;hb=4fe8479d27f535a0ff44c9f6ce270249934e980f;hpb=1e636c95bf237645b6c9117e3eb64aa2d8aa4c90 diff --git a/src/comet2.c b/src/comet2.c index 0312035..1adf426 100644 --- a/src/comet2.c +++ b/src/comet2.c @@ -3,53 +3,79 @@ #define _GNU_SOURCE #include -/* 指定されたファイルからCOMET II仮想メモリ(アセンブル結果)を読込 */ -bool inassemble(char *file) { - FILE *fp; - if((fp = fopen(file, "r")) == NULL) { - perror(file); - return false; - } - fread(memory, sizeof(WORD), MEMSIZE, fp); - fclose(fp); - return true; -} - +/* comet2コマンドのオプション */ static struct option longopts[] = { {"trace", no_argument, NULL, 't'}, {"tracearithmetic", no_argument, NULL, 't'}, {"tracelogical", no_argument, NULL, 'T'}, {"dump", no_argument, NULL, 'd'}, + {"memorysize", required_argument, NULL, 'M'}, + {"clocks", required_argument, NULL, 'C'}, {"help", no_argument, NULL, 'h'}, {0, 0, 0, 0} }; +/* 実行モード: trace, logical, dump */ +EXECMODE execmode = {false, false, false}; + +/* エラー番号とエラーメッセージ */ +CERRARRAY cerr[] = { + { 201, "execute - out of COMET II memory" }, + { 202, "SVC input - out of Input memory" }, + { 203, "SVC output - out of COMET II memory" }, + { 204, "Program Register (PR) - out of COMET II memory" }, + { 205, "Stack Pointer (SP) - cannot allocate stack buffer" }, + { 206, "Address - out of COMET II memory" }, + { 207, "Stack Pointer (SP) - out of COMET II memory" }, + { 0, NULL }, +}; + +/* 指定されたファイルからアセンブル結果を読込 */ +bool loadassemble(char *file) { + FILE *fp; + if((fp = fopen(file, "r")) == NULL) { + perror(file); + return false; + } + fread(memory, sizeof(WORD), memsize, fp); + fclose(fp); + return true; +} + +/* comet2コマンド */ int main(int argc, char *argv[]) { int opt; - const char *usage = "Usage: %s [-tTdh] FILE\n"; + const char *usage = "Usage: %s [-tTdh] [-M ] [-C ] FILE\n"; - while((opt = getopt_long(argc, argv, "tTdh", longopts, NULL)) != -1) { + while((opt = getopt_long(argc, argv, "tTdM:C:h", longopts, NULL)) != -1) { switch(opt) { case 't': - tracemode = true; + (&execmode)->trace = true; break; case 'T': - tracemode = true; - logicalmode = true; + (&execmode)->trace = true; + (&execmode)->logical = true; break; case 'd': - dumpmode = true; + (&execmode)->dump = true; + break; + case 'M': + memsize = atoi(optarg); + break; + case 'C': + clocks = atoi(optarg); break; case 'h': fprintf(stdout, usage, argv[0]); - exit(-1); + return 0; case '?': fprintf(stderr, usage, argv[0]); exit(-1); } } - if(inassemble(argv[optind]) == true) { + reset(); + if(loadassemble(argv[optind]) == true) { exec(); /* プログラム実行 */ } if(cerrno > 0) {