X-Git-Url: http://j8takagi.net/cgi-bin/gitweb.cgi?p=YACASL2.git;a=blobdiff_plain;f=include%2Fcasl2.h;h=49f4c8c6e14552417660d1918e95bc00b8467c1c;hp=a293b13515e7091b20731b8a812c1d7659ee451c;hb=373540e9b114c01712121c36b40f47a98e12d263;hpb=712486afe58b10ef37c5fa915de889ab8d1dd6cd diff --git a/include/casl2.h b/include/casl2.h index a293b13..49f4c8c 100644 --- a/include/casl2.h +++ b/include/casl2.h @@ -11,26 +11,17 @@ #include "word.h" #include "hash.h" +#include "cmem.h" #include "cerr.h" -#ifndef ARRAYSIZE -#define ARRAYSIZE(array) (sizeof(array)/sizeof(array[0])) -#endif - /* COMET IIの規格 */ enum { - CMDSIZE = 4, /* 命令の最大文字数 */ - REGSIZE = 8, /* 汎用レジスタの数 */ + CMDSIZE = 4, /* 命令の最大文字数 */ + GRSIZE = 8, /* 汎用レジスタの数。COMET II規格で、7 */ DEFAULT_MEMSIZE = 512, /* デフォルトのメモリ容量。COMET II規格では、65536語 */ DEFAULT_CLOCKS = 5000000, /* デフォルトのクロック周波数。COMET II規格では、未定義 */ }; -/* COMET IIのメモリ */ -extern WORD *memory; - -/* COMET IIのCPUレジスタ */ -extern WORD GR[REGSIZE], SP, PR, FR; - /* COMET II フラグのマスク値 */ enum { OF = 0x4, /* Overflow Flag */ @@ -38,17 +29,23 @@ enum { ZF = 0x1, /* Zero Flag */ }; -/* メモリーサイズ */ -extern int memsize; - -/* クロック周波数 */ -extern int clocks; +/* COMET IIのCPU */ +typedef struct { + WORD gr[GRSIZE]; /* 汎用レジスタ */ + WORD sp; /* スタックポインタ */ + WORD pr; /* プログラムレジスタ */ + WORD fr; /* フラグレジスタ */ +} CPU; -/* 実行開始番地 */ -extern WORD startptr; +/* COMET IIの仮装実行マシンシステム */ +typedef struct { + CPU *cpu; /* CPU */ + WORD *memory; /* メモリ */ + int memsize; /* メモリサイズ */ + int clocks; /* クロック周波数 */ +} SYSTEM; -/* 実行終了番地 */ -extern WORD endptr; +extern SYSTEM *sys; /* COMET II 命令 */ /* 命令タイプは、オペランドにより6種類に分類 */ @@ -78,18 +75,39 @@ typedef enum { NONE = 0, } CMDTYPE; -/* 命令コードの配列 */ +/* 命令コード配列 */ typedef struct { - char *cmd; + char *name; CMDTYPE type; WORD code; -} CMDCODEARRAY; +} CMD; + +/* 命令コード配列のサイズ */ +extern int comet2cmdsize; /* 命令コードのハッシュ表 */ -typedef struct _CMDCODETAB { - struct _CMDCODETAB *next; - CMDCODEARRAY *cca; -} CMDCODETAB; +typedef struct _CMDTAB { + struct _CMDTAB *next; + CMD *cmd; +} CMDTAB; + +extern CMDTAB **cmdtype_code; +extern CMDTAB **code_type; +extern int cmdtabsize; + +/* CASL2プログラムのプロパティ */ +typedef struct { + WORD start; /* プログラムの開始番地 */ + WORD end; /* プログラムの終了番地 */ +} PROGPROP; + +extern PROGPROP *prog; + +/* COMET II仮想マシンのリセット */ +void reset(int memsize, int clocks); + +/* COMET II仮想マシンのシャットダウン */ +void shutdown(); /* 命令と命令タイプがキーのハッシュ表を作成する */ bool create_cmdtype_code(); @@ -98,9 +116,6 @@ bool create_cmdtype_code(); /* 無効な場合は0xFFFFを返す */ WORD getcmdcode(const char *cmd, CMDTYPE type); -/* 命令と命令タイプからハッシュ値を生成する */ -unsigned hash_cmdtype(const char *cmd, CMDTYPE type); - /* 命令と命令タイプがキーのハッシュ表を表示する */ void print_cmdtype_code(); @@ -110,9 +125,6 @@ void free_cmdtype_code(); /* 命令コードがキーのハッシュ表を作成する */ bool create_code_type(); -/* 命令コードからハッシュ値を生成する */ -unsigned hash_code(WORD code); - /* 命令コードから命令タイプを取得する */ /* 無効な場合はNONEを返す */ CMDTYPE getcmdtype(WORD code); @@ -124,6 +136,6 @@ void print_code_type(); void free_code_type(); /* 指定されたファイルにアセンブル結果を書込 */ -void outassemble(char *file); +void outassemble(const char *file); -#endif +#endif /* YACASL2_CASL2_INCLUDEDの終端 */