アセンブルモードと実行モードの初期化位置を修正
[YACASL2.git] / src / assemble.c
index 27ebfdb..f2f5978 100644 (file)
@@ -10,20 +10,24 @@ WORD lptr;
 /* 他のプログラムで参照する入口名 */
 char *prog;
 
-/* 汎用レジスタを表す文字列「GR[0-7]」をWORD値に変換 */
-/* is_xがtrueの場合は、指標レジスタとして用いる汎用レジスタ */
+/* アセンブルモード: src, label, onlylabel, asdetail, onlyassemble */
+ASMODE asmode = {false, false, false, false, false};
+
+/* 汎用レジスタを表す文字列「GR[0-7]」から、レジスタ番号[0-7]をWORD値で返す */
 /* 文字列が汎用レジスタを表さない場合は、0xFFFFを返す */
+/* is_xがtrueの場合は指標レジスタ。GR0は、COMET IIの仕様により、エラー発生 */
 WORD getgr(const char *str, bool is_x)
 {
     assert(str != NULL);
     WORD r;
+    /* 「GR[0-7]」以外の文字列では、0xFFFFを返して終了 */
     if(!(strlen(str) == 3 && strncmp(str, "GR", 2) == 0 &&
          (*(str+2) >= '0' && *(str+2) <= '7')))
     {
         return 0xFFFF;
     }
     r = (WORD)(*(str+2) - '0');
-    /* COMET IIの仕様により、GR0は指標レジスタとして用いることはできない */
+    /* 指標レジスタとして用いることはできない */
     if(is_x == true && r == 0x0) {
         setcerr(120, NULL);    /* GR0 in operand x */
         return 0x0;
@@ -61,7 +65,7 @@ bool writememory(WORD word, WORD adr, PASS pass)
     }
     if(cerrno == 0) {
         memory[adr] = word;
-        if(pass == SECOND && (&asmode)->asdetailmode == true) {
+        if(pass == SECOND && (&asmode)->asdetail == true) {
             fprintf(stdout, "\t#%04X\t#%04X\n", adr, word);
         }
         status = true;
@@ -142,7 +146,7 @@ bool assemblecmd(const CMDLINE *cmdl, PASS pass)
     CMDARRAY ascmd[] = {
         { START, 0, 1, "START" },
         { END, 0, 0, "END" },
-        { DC, 0, OPDSIZE, "DC" },
+        { DC, 1, OPDSIZE, "DC" },
         { DS, 1, 1, "DS" },
         { 0, 0, 0, NULL }
     };
@@ -313,6 +317,7 @@ bool cometcmd(const CMDLINE *cmdl, PASS pass)
             /* オペランド数3 */
             if(cmdl->opd->opdc == 3) {
                 if((x = getgr(cmdl->opd->opdv[2], true)) == 0xFFFF) {
+                    setcerr(125, cmdl->cmd);    /* not GR in operand x */
                     return false;
                 }
                 cmd |= x;
@@ -417,8 +422,8 @@ bool assemble(const char *file, PASS pass)
             break;
         }
         lineno++;
-        if((pass == FIRST && (&asmode)->srcmode == true) ||
-           (pass == SECOND && (&asmode)->asdetailmode == true))
+        if((pass == FIRST && (&asmode)->src == true) ||
+           (pass == SECOND && (&asmode)->asdetail == true))
         {
             fprintf(stdout, "%s:%5d:%s", file, lineno, line);
         }