7 static struct option longopts[] = {
8 {"trace", no_argument, NULL, 't'},
9 {"tracearithmetic", no_argument, NULL, 't'},
10 {"tracelogical", no_argument, NULL, 'T'},
11 {"dump", no_argument, NULL, 'd'},
12 {"memorysize", required_argument, NULL, 'M'},
13 {"clocks", required_argument, NULL, 'C'},
14 {"help", no_argument, NULL, 'h'},
19 CERRARRAY cerr_comet2[] = {
20 { 201, "Load object file - full of COMET II memory" },
21 { 202, "SVC input - out of Input memory" },
22 { 203, "SVC output - out of COMET II memory" },
23 { 204, "Program Register (PR) - out of COMET II memory" },
24 { 205, "Stack Pointer (SP) - cannot allocate stack buffer" },
25 { 206, "Address - out of COMET II memory" },
26 { 207, "Stack Pointer (SP) - out of COMET II memory" },
29 /* 指定されたファイルからアセンブル結果を読込 */
30 bool loadassemble(char *file) {
32 if((fp = fopen(file, "r")) == NULL) {
36 if((endptr = startptr + fread(memory, sizeof(WORD), memsize-startptr, fp)) == memsize) {
37 setcerr(201, NULL); /* Load object file - full of COMET II memory */
38 fprintf(stderr, "Execute error - %d: %s\n", cerrno, cerrmsg);
46 int main(int argc, char *argv[])
49 const char *usage = "Usage: %s [-tTdh] [-M <memorysize>] [-C <clocks>] FILE\n";
51 while((opt = getopt_long(argc, argv, "tTdM:C:h", longopts, NULL)) != -1) {
54 execmode.trace = true;
57 execmode.trace = true;
58 execmode.logical = true;
64 memsize = atoi(optarg);
67 clocks = atoi(optarg);
70 fprintf(stdout, usage, argv[0]);
73 fprintf(stderr, usage, argv[0]);
77 /* エラーリストにerr_comet2を追加 */
78 addcerrlist(ARRAYSIZE(cerr_comet2), cerr_comet2);
81 if(loadassemble(argv[optind]) == true) {