バージョンを設定
[YACASL2.git] / src / struct.c
index 981409a..4e38f2e 100644 (file)
@@ -1,9 +1,4 @@
-#include <stdio.h>
-#include <assert.h>
-#include <string.h>
-#include "hash.h"
 #include "struct.h"
-#include "cmem.h"
 #include "exec.h"
 
 /**
@@ -19,7 +14,7 @@ EXECPTR *execptr;
 /**
  * システムCOMET IIの命令表
  */
-static COMET2CMD comet2cmd[] = {
+static const COMET2CMD comet2cmd[] = {
     { "NOP", NONE, 0x0, nop },
     { "LD", R_ADR_X, 0x1000, ld_r_adr_x },
     { "ST", R_ADR_X, 0x1100, st },
@@ -209,10 +204,27 @@ const void (*getcmdptr(WORD code))
     return ptr;
 }
 
+/**
+ * 命令コードから命令のタイプを返す
+ */
+CMDTYPE getcmdtype(WORD code)
+{
+    CMDTAB *t;
+    CMDTYPE type = NONE;
+
+    for(t = code_cmdtype[hash_code(code)]; t != NULL; t = t->next) {
+        if(code == t->cmd->code) {
+            type = t->cmd->type;
+            break;
+        }
+    }
+    return type;
+}
+
 /**
  * 命令コードから命令の名前を返す
  */
-char (*getcmdname(WORD code))
+char *getcmdname(WORD code)
 {
     CMDTAB *t;
     char *cmd = NULL;
@@ -226,6 +238,18 @@ char (*getcmdname(WORD code))
     return cmd;
 }
 
+/**
+ * 汎用レジスタの番号からレジスタを表す文字列を返す
+ */
+
+char *grstr(WORD word)
+{
+    assert(word <= 7);
+    char *str = malloc_chk(3 + 1, "grstr.str");
+    sprintf(str, "GR%d", word);
+    return str;
+}
+
 /**
  * コードがキーの命令ハッシュ表を解放する
  */