ソースコードで、モードを表す構造体メンバーの名前とコメントを修正
authorj8takagi <j8takagi@nifty.com>
Sun, 7 Feb 2010 01:21:39 +0000 (10:21 +0900)
committerj8takagi <j8takagi@nifty.com>
Sun, 7 Feb 2010 01:21:39 +0000 (10:21 +0900)
include/assemble.h
include/casl2.h
include/exec.h
src/assemble.c
src/casl2.c
src/comet2.c
src/dump.c
src/exec.c

index f6e081a..ae746fd 100644 (file)
@@ -12,11 +12,11 @@ enum {
 
 /* アセンブルモード */
 typedef struct {
 
 /* アセンブルモード */
 typedef struct {
-    bool srcmode;             /* ソースを表示する場合はtrue */
-    bool labelmode;           /* ラベル表を表示する場合はtrue */
-    bool onlylabelmode;       /* ラベル表を表示して終了する場合はtrue */
-    bool asdetailmode;        /* アセンブラ詳細結果を表示する場合はtrue */
-    bool onlyassemblemode;    /* アセンブルだけを行う場合はtrue */
+    bool src;             /* ソースを表示する場合はtrue */
+    bool label;           /* ラベル表を表示する場合はtrue */
+    bool onlylabel;       /* ラベル表を表示して終了する場合はtrue */
+    bool asdetail;        /* アセンブラ詳細結果を表示する場合はtrue */
+    bool onlyassemble;    /* アセンブルだけを行う場合はtrue */
 } ASMODE;
 extern ASMODE asmode;
 
 } ASMODE;
 extern ASMODE asmode;
 
@@ -101,9 +101,9 @@ OPD *opdtok(const char *str);
 /* 1行を解析する */
 CMDLINE *linetok(const char *line);
 
 /* 1行を解析する */
 CMDLINE *linetok(const char *line);
 
-/* æ±\8eç\94¨ã\83¬ã\82¸ã\82¹ã\82¿ã\82\92表ã\81\99æ\96\87å­\97å\88\97ã\80\8cGR[0-7]ã\80\8dã\82\92WORDå\80¤ã\81«å¤\89æ\8f\9b
-   is_xがTRUEの場合は、指標レジスタとして用いる汎用レジスタ
-   文字列が汎用レジスタを表さない場合は、0xFFFFを返す */
+/* æ±\8eç\94¨ã\83¬ã\82¸ã\82¹ã\82¿ã\82\92表ã\81\99æ\96\87å­\97å\88\97ã\80\8cGR[0-7]ã\80\8dã\81\8bã\82\89ã\80\81ã\83¬ã\82¸ã\82¹ã\82¿ç\95ªå\8f·[0-7]ã\82\92WORDå\80¤ã\81§è¿\94ã\81\99 */
+/* 文字列が汎用レジスタを表さない場合は、0xFFFFを返す */
+/* is_xがtrueの場合は指標レジスタ。GR0は、COMET IIの仕様により、エラー発生 */
 WORD getgr(const char *str, bool is_x);
 
 /* 10進定数をWORDに変換 */
 WORD getgr(const char *str, bool is_x);
 
 /* 10進定数をWORDに変換 */
@@ -162,4 +162,4 @@ bool writeRPUSH(PASS pass);
 /* マクロ命令「RPOP」をメモリに書込 */
 bool writeRPOP(PASS pass);
 
 /* マクロ命令「RPOP」をメモリに書込 */
 bool writeRPOP(PASS pass);
 
-#endif
+#endif            /* YACASL2_ASSEMBLE_INCLUDEDの終端 */
index fa4b0ae..42ed92d 100644 (file)
@@ -126,4 +126,4 @@ void free_code_type();
 /* 指定されたファイルにアセンブル結果を書込 */
 void outassemble(const char *file);
 
 /* 指定されたファイルにアセンブル結果を書込 */
 void outassemble(const char *file);
 
-#endif
+#endif            /* YACASL2_CASL2_INCLUDEDの終端 */
index 6841146..40230b4 100644 (file)
@@ -10,54 +10,12 @@ enum {
 
 /* 実行モード */
 typedef struct {
 
 /* 実行モード */
 typedef struct {
-    bool tracemode;           /* レジストリの内容を表示する場合はtrue */
-    bool logicalmode;         /* レジストリの内容を論理値(0〜65535)で表示する場合はtrue */
-    bool dumpmode;            /* メモリの内容を表示する場合はtrue */
+    bool trace;           /* レジストリの内容を表示する場合はtrue */
+    bool logical;         /* レジストリの内容を論理値(0〜65535)で表示する場合はtrue */
+    bool dump;            /* メモリの内容を表示する場合はtrue */
 } EXECMODE;
 extern EXECMODE execmode;
 
 } EXECMODE;
 extern EXECMODE execmode;
 
-/* 指定されたファイルからアセンブル結果を読込 */
-bool inassemble(char *file);
-
-/* 標準入力から文字データを読込(SVC 1) */
-void svcin();
-
-/* 標準出力へ文字データを書出(SVC 2) */
-void svcout();
-
-/* ロード/論理積/論理和/排他的論理和のフラグ設定。OFは常に0 */
-void setfr(WORD val);
-
-/* 算術加算。フラグを設定して値を返す */
-WORD adda(WORD val0, WORD val1);
-
-/* 算術減算。フラグを設定して値を返す */
-WORD suba(WORD val0, WORD val1);
-
-/* 論理加算。フラグを設定して値を返す */
-WORD addl(WORD val0, WORD val1);
-
-/* 論理減算。フラグを設定して値を返す */
-WORD subl(WORD val0, WORD val1);
-
-/* 算術比較のフラグ設定。OFは常に0 */
-void cpa(WORD val0, WORD val1);
-
-/* 論理比較のフラグ設定。OFは常に0 */
-void cpl(WORD val0, WORD val1);
-
-/* 算術左シフト。フラグを設定して値を返す */
-WORD sla(WORD val0, WORD val1);
-
-/* 算術右シフト。フラグを設定して値を返す */
-WORD sra(WORD val0, WORD val1);
-
-/* 論理左シフト。フラグを設定して値を返す */
-WORD sll(WORD val0, WORD val1);
-
-/* 論理右シフト。フラグを設定して値を返す */
-WORD srl(WORD val0, WORD val1);
-
 /* 仮想マシンのリセット */
 void reset();
 
 /* 仮想マシンのリセット */
 void reset();
 
@@ -70,4 +28,4 @@ void dumpmemory();
 /* COMET IIのレジスタを表示 */
 void dspregister();
 
 /* COMET IIのレジスタを表示 */
 void dspregister();
 
-#endif
+#endif            /* YACASL2_EXEC_INCLUDEDの終端 */
index 27ebfdb..811f670 100644 (file)
@@ -10,20 +10,21 @@ WORD lptr;
 /* 他のプログラムで参照する入口名 */
 char *prog;
 
 /* 他のプログラムで参照する入口名 */
 char *prog;
 
-/* 汎用レジスタを表す文字列「GR[0-7]」をWORD値に変換 */
-/* is_xがtrueの場合は、指標レジスタとして用いる汎用レジスタ */
+/* 汎用レジスタを表す文字列「GR[0-7]」から、レジスタ番号[0-7]をWORD値で返す */
 /* 文字列が汎用レジスタを表さない場合は、0xFFFFを返す */
 /* 文字列が汎用レジスタを表さない場合は、0xFFFFを返す */
+/* is_xがtrueの場合は指標レジスタ。GR0は、COMET IIの仕様により、エラー発生 */
 WORD getgr(const char *str, bool is_x)
 {
     assert(str != NULL);
     WORD r;
 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');
     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;
     if(is_x == true && r == 0x0) {
         setcerr(120, NULL);    /* GR0 in operand x */
         return 0x0;
@@ -61,7 +62,7 @@ bool writememory(WORD word, WORD adr, PASS pass)
     }
     if(cerrno == 0) {
         memory[adr] = word;
     }
     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;
             fprintf(stdout, "\t#%04X\t#%04X\n", adr, word);
         }
         status = true;
@@ -417,8 +418,8 @@ bool assemble(const char *file, PASS pass)
             break;
         }
         lineno++;
             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);
         }
         {
             fprintf(stdout, "%s:%5d:%s", file, lineno, line);
         }
index 1b438e5..35f9a80 100644 (file)
@@ -4,6 +4,7 @@
 #define _GNU_SOURCE
 #include <getopt.h>
 
 #define _GNU_SOURCE
 #include <getopt.h>
 
+/* casl2コマンドのオプション */
 static struct option longopts[] = {
     {"source", no_argument, NULL, 's'},
     {"label", no_argument, NULL, 'l'},
 static struct option longopts[] = {
     {"source", no_argument, NULL, 's'},
     {"label", no_argument, NULL, 'l'},
@@ -22,7 +23,9 @@ static struct option longopts[] = {
     {0, 0, 0, 0},
 };
 
     {0, 0, 0, 0},
 };
 
+/* アセンブルモード: src, label, onlylabel, asdetail, onlyassemble */
 ASMODE asmode = {false, false, false, false, false};
 ASMODE asmode = {false, false, false, false, false};
+/* 実行モード: trace, logical, dump */
 EXECMODE execmode = {false, false, false};
 
 /* エラー番号とエラーメッセージ */
 EXECMODE execmode = {false, false, false};
 
 /* エラー番号とエラーメッセージ */
@@ -84,7 +87,7 @@ const char *objfile_name(const char *str)
     }
 }
 
     }
 }
 
-/* casl2コマンド */
+/* casl2コマンドのメイン */
 int main(int argc, char *argv[])
 {
     int opt, i;
 int main(int argc, char *argv[])
 {
     int opt, i;
@@ -98,38 +101,38 @@ int main(int argc, char *argv[])
     while((opt = getopt_long(argc, argv, "tTdslLao::O::AM:C:h", longopts, NULL)) != -1) {
         switch(opt) {
         case 's':
     while((opt = getopt_long(argc, argv, "tTdslLao::O::AM:C:h", longopts, NULL)) != -1) {
         switch(opt) {
         case 's':
-            (&asmode)->srcmode = true;
+            (&asmode)->src = true;
             break;
         case 'l':
             break;
         case 'l':
-            (&asmode)->labelmode = true;
+            (&asmode)->label = true;
             break;
         case 'L':
             break;
         case 'L':
-            (&asmode)->labelmode = true;
-            (&asmode)->onlylabelmode = true;
+            (&asmode)->label = true;
+            (&asmode)->onlylabel = true;
             break;
         case 'a':
             break;
         case 'a':
-            (&asmode)->asdetailmode = true;
+            (&asmode)->asdetail = true;
             break;
         case 'A':
             break;
         case 'A':
-            (&asmode)->asdetailmode = true;
-            (&asmode)->onlyassemblemode = true;
+            (&asmode)->asdetail = true;
+            (&asmode)->onlyassemble = true;
             break;
         case 'o':
             objfile = strdup(objfile_name(optarg));
             break;
         case 'O':
             break;
         case 'o':
             objfile = strdup(objfile_name(optarg));
             break;
         case 'O':
-            (&asmode)->onlyassemblemode = true;
+            (&asmode)->onlyassemble = true;
             objfile = strdup(objfile_name(optarg));
             break;
         case 't':
             objfile = strdup(objfile_name(optarg));
             break;
         case 't':
-            (&execmode)->tracemode = true;
+            (&execmode)->trace = true;
             break;
         case 'T':
             break;
         case 'T':
-            (&execmode)->tracemode = true;
-            (&execmode)->logicalmode = true;
+            (&execmode)->trace = true;
+            (&execmode)->logical = true;
             break;
         case 'd':
             break;
         case 'd':
-            (&execmode)->dumpmode = true;
+            (&execmode)->dump = true;
             break;
         case 'M':
             memsize = atoi(optarg);
             break;
         case 'M':
             memsize = atoi(optarg);
@@ -161,9 +164,9 @@ int main(int argc, char *argv[])
             } else if(pass == SECOND) {
                 ptr = beginptr[i];
             }
             } else if(pass == SECOND) {
                 ptr = beginptr[i];
             }
-            if((&execmode)->tracemode == true || (&execmode)->dumpmode == true ||
-               (&asmode)->srcmode == true || (&asmode)->labelmode == true ||
-               (&asmode)->asdetailmode == true)
+            if((&execmode)->trace == true || (&execmode)->dump == true ||
+               (&asmode)->src == true || (&asmode)->label == true ||
+               (&asmode)->asdetail == true)
             {
                 fprintf(stdout, "\nAssemble %s (%d)\n", argv[i], pass);
             }
             {
                 fprintf(stdout, "\nAssemble %s (%d)\n", argv[i], pass);
             }
@@ -175,10 +178,10 @@ int main(int argc, char *argv[])
                 exit(-1);
             }
         }
                 exit(-1);
             }
         }
-        if(pass == FIRST && (&asmode)->labelmode == true) {
+        if(pass == FIRST && (&asmode)->label == true) {
             fprintf(stdout, "\nLabel::::\n");
             printlabel();
             fprintf(stdout, "\nLabel::::\n");
             printlabel();
-            if((&asmode)->onlylabelmode == true) {
+            if((&asmode)->onlylabel == true) {
                 return 0;
             }
         }
                 return 0;
             }
         }
@@ -188,7 +191,7 @@ int main(int argc, char *argv[])
         if(objfile != NULL) {
             outassemble(objfile);
         }
         if(objfile != NULL) {
             outassemble(objfile);
         }
-        if((&asmode)->onlyassemblemode == false) {
+        if((&asmode)->onlyassemble == false) {
             exec();    /* プログラム実行 */
         }
     }
             exec();    /* プログラム実行 */
         }
     }
index bfe1634..7fa8d29 100644 (file)
@@ -3,6 +3,7 @@
 #define _GNU_SOURCE
 #include <getopt.h>
 
 #define _GNU_SOURCE
 #include <getopt.h>
 
+/* comet2コマンドのオプション */
 static struct option longopts[] = {
     {"trace", no_argument, NULL, 't'},
     {"tracearithmetic", no_argument, NULL, 't'},
 static struct option longopts[] = {
     {"trace", no_argument, NULL, 't'},
     {"tracearithmetic", no_argument, NULL, 't'},
@@ -14,6 +15,7 @@ static struct option longopts[] = {
     {0, 0, 0, 0}
 };
 
     {0, 0, 0, 0}
 };
 
+/* 実行モード: trace, logical, dump */
 EXECMODE execmode = {false, false, false};
 
 /* エラー番号とエラーメッセージ */
 EXECMODE execmode = {false, false, false};
 
 /* エラー番号とエラーメッセージ */
@@ -29,7 +31,7 @@ CERRARRAY cerr[] = {
 };
 
 /* 指定されたファイルからアセンブル結果を読込 */
 };
 
 /* 指定されたファイルからアセンブル結果を読込 */
-bool inassemble(char *file) {
+bool loadassemble(char *file) {
     FILE *fp;
     reset();
     if((fp = fopen(file, "r")) == NULL) {
     FILE *fp;
     reset();
     if((fp = fopen(file, "r")) == NULL) {
@@ -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':
     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':
             break;
         case 'T':
-            (&execmode)->tracemode = true;
-            (&execmode)->logicalmode = true;
+            (&execmode)->trace = true;
+            (&execmode)->logical = true;
             break;
         case 'd':
             break;
         case 'd':
-            (&execmode)->dumpmode = true;
+            (&execmode)->dump = true;
             break;
         case 'M':
             memsize = atoi(optarg);
             break;
         case 'M':
             memsize = atoi(optarg);
@@ -73,7 +75,7 @@ int main(int argc, char *argv[])
             exit(-1);
         }
     }
             exit(-1);
         }
     }
-    if(inassemble(argv[optind]) == true) {
+    if(loadassemble(argv[optind]) == true) {
         exec();    /* プログラム実行 */
     }
     if(cerrno > 0) {
         exec();    /* プログラム実行 */
     }
     if(cerrno > 0) {
index c1184be..f1b575f 100644 (file)
@@ -32,7 +32,7 @@ void dspregister()
     int i;
     for(i = 0; i < REGSIZE; i++ ) {
         fprintf(stdout, "#%04X: GR%d: ", PR, i);
     int i;
     for(i = 0; i < REGSIZE; i++ ) {
         fprintf(stdout, "#%04X: GR%d: ", PR, i);
-        print_dumpword(GR[i], (&execmode)->logicalmode);
+        print_dumpword(GR[i], (&execmode)->logical);
     }
     fprintf(stdout, "#%04X: SP:  %6d = #%04X = %s\n", PR, SP, SP, word2bit(SP));
     fprintf(stdout, "#%04X: PR:  %6d = #%04X = %s\n", PR, PR, PR, word2bit(PR));
     }
     fprintf(stdout, "#%04X: SP:  %6d = #%04X = %s\n", PR, SP, SP, word2bit(SP));
     fprintf(stdout, "#%04X: PR:  %6d = #%04X = %s\n", PR, PR, PR, word2bit(PR));
index 29b1afc..00cee8d 100644 (file)
@@ -273,7 +273,7 @@ void exec()
     char *errpr = malloc(8);
     clock_t clock_begin, clock_end;
 
     char *errpr = malloc(8);
     clock_t clock_begin, clock_end;
 
-    if((&execmode)->tracemode) {
+    if((&execmode)->trace) {
         fprintf(stdout, "\nExecuting machine codes\n");
     }
     /* フラグレジスタの初期値設定 */
         fprintf(stdout, "\nExecuting machine codes\n");
     }
     /* フラグレジスタの初期値設定 */
@@ -309,15 +309,15 @@ void exec()
         if(cerrno > 0) {
             goto execerr;
         }
         if(cerrno > 0) {
             goto execerr;
         }
-        if((&execmode)->tracemode){
+        if((&execmode)->trace){
             fprintf(stdout, "#%04X: Register::::\n", PR);
             dspregister();
         }
             fprintf(stdout, "#%04X: Register::::\n", PR);
             dspregister();
         }
-        if((&execmode)->dumpmode){
+        if((&execmode)->dump){
             fprintf(stdout, "#%04X: Memory::::\n", PR);
             dumpmemory();
         }
             fprintf(stdout, "#%04X: Memory::::\n", PR);
             dumpmemory();
         }
-        if((&execmode)->dumpmode || (&execmode)->tracemode) {
+        if((&execmode)->dump || (&execmode)->trace) {
             fprintf(stdout, "\n");
         }
         PR++;
             fprintf(stdout, "\n");
         }
         PR++;