エラーをリストで格納し、分散して追加するように修正
[YACASL2.git] / src / comet2.c
index ba26cf6..be09f10 100644 (file)
@@ -15,26 +15,28 @@ static struct option longopts[] = {
     {0, 0, 0, 0}
 };
 
-/* エラー番号とエラーメッセージ */
-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 },
+/* comet2のエラー定義 */
+CERRARRAY cerr_comet2[] = {
+    { 201, "Load object file - full of COMET II memory" },
 };
+bool addcerrlist_comet2()
+{
+    return addcerrlist(ARRAYSIZE(cerr_comet2), cerr_comet2);
+}
 
 /* 指定されたファイルからアセンブル結果を読込 */
 bool loadassemble(char *file) {
     FILE *fp;
+
     if((fp = fopen(file, "r")) == NULL) {
         perror(file);
         return false;
     }
-    endptr = startptr + 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;
 }
@@ -45,17 +47,18 @@ int main(int argc, char *argv[])
     int opt;
     const char *usage = "Usage: %s [-tTdh] [-M <memorysize>] [-C <clocks>] FILE\n";
 
+    addcerrlist_comet2();
     while((opt = getopt_long(argc, argv, "tTdM:C:h", longopts, NULL)) != -1) {
         switch(opt) {
         case 't':
-            (&execmode)->trace = true;
+            execmode.trace = true;
             break;
         case 'T':
-            (&execmode)->trace = true;
-            (&execmode)->logical = true;
+            execmode.trace = true;
+            execmode.logical = true;
             break;
         case 'd':
-            (&execmode)->dump = true;
+            execmode.dump = true;
             break;
         case 'M':
             memsize = atoi(optarg);