オブジェクトファイルの読込時、領域が足りない場合はすぐエラー201を発生
[YACASL2.git] / src / comet2.c
index bfe1634..e2a9e3c 100644 (file)
@@ -3,6 +3,7 @@
 #define _GNU_SOURCE
 #include <getopt.h>
 
+/* comet2コマンドのオプション */
 static struct option longopts[] = {
     {"trace", no_argument, NULL, 't'},
     {"tracearithmetic", no_argument, NULL, 't'},
@@ -14,11 +15,9 @@ static struct option longopts[] = {
     {0, 0, 0, 0}
 };
 
-EXECMODE execmode = {false, false, false};
-
 /* エラー番号とエラーメッセージ */
 CERRARRAY cerr[] = {
-    { 201, "execute - out of COMET II memory" },
+    { 201, "Load object file - full 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" },
@@ -29,14 +28,17 @@ CERRARRAY cerr[] = {
 };
 
 /* 指定されたファイルからアセンブル結果を読込 */
-bool inassemble(char *file) {
+bool loadassemble(char *file) {
     FILE *fp;
-    reset();
     if((fp = fopen(file, "r")) == NULL) {
         perror(file);
         return false;
     }
-    fread(memory, sizeof(WORD), memsize, fp);
+    if((endptr = startptr + fread(memory, sizeof(WORD), memsize-startptr, fp)) == memsize) {
+        setcerr(201, NULL);    /* Load object file - full of COMET II memory */
+        fprintf(stderr, "Execute error - %d: %s\n", cerrno, cerrmsg);
+        return false;
+    }
     fclose(fp);
     return true;
 }
@@ -50,14 +52,14 @@ int main(int argc, char *argv[])
     while((opt = getopt_long(argc, argv, "tTdM:C:h", longopts, NULL)) != -1) {
         switch(opt) {
         case 't':
-            (&execmode)->tracemode = true;
+            (&execmode)->trace = true;
             break;
         case 'T':
-            (&execmode)->tracemode = true;
-            (&execmode)->logicalmode = true;
+            (&execmode)->trace = true;
+            (&execmode)->logical = true;
             break;
         case 'd':
-            (&execmode)->dumpmode = true;
+            (&execmode)->dump = true;
             break;
         case 'M':
             memsize = atoi(optarg);
@@ -73,7 +75,9 @@ int main(int argc, char *argv[])
             exit(-1);
         }
     }
-    if(inassemble(argv[optind]) == true) {
+    reset();
+    startptr = 0;
+    if(loadassemble(argv[optind]) == true) {
         exec();    /* プログラム実行 */
     }
     if(cerrno > 0) {