\doxysection{struct.\+c}
\label{struct_8c_source}\index{src/struct.c@{src/struct.c}}
\textbf{ Go to the documentation of this file.}
\begin{DoxyCode}{0}
\DoxyCodeLine{00001\ \textcolor{preprocessor}{\#include\ <errno.h>}}
\DoxyCodeLine{00002\ \textcolor{preprocessor}{\#include\ "{}struct.h"{}}}
\DoxyCodeLine{00003\ \textcolor{preprocessor}{\#include\ "{}exec.h"{}}}
\DoxyCodeLine{00004\ }
\DoxyCodeLine{00008\ SYSTEM\ *sys\ =\ NULL;}
\DoxyCodeLine{00009\ }
\DoxyCodeLine{00013\ EXECPTR\ *execptr\ =\ NULL;}
\DoxyCodeLine{00014\ }
\DoxyCodeLine{00018\ \textcolor{keyword}{static}\ \textcolor{keyword}{const}\ COMET2CMD\ comet2cmd[]\ =\ \{}
\DoxyCodeLine{00019\ \ \ \ \ \{\ \textcolor{stringliteral}{"{}NOP"{}},\ NONE,\ 0x0,\ nop\ \},}
\DoxyCodeLine{00020\ \ \ \ \ \{\ \textcolor{stringliteral}{"{}LD"{}},\ R\_ADR\_X,\ 0x1000,\ ld\_r\_adr\_x\ \},}
\DoxyCodeLine{00021\ \ \ \ \ \{\ \textcolor{stringliteral}{"{}ST"{}},\ R\_ADR\_X,\ 0x1100,\ st\ \},}
\DoxyCodeLine{00022\ \ \ \ \ \{\ \textcolor{stringliteral}{"{}LAD"{}},\ R\_ADR\_X,\ 0x1200,\ lad\ \},}
\DoxyCodeLine{00023\ \ \ \ \ \{\ \textcolor{stringliteral}{"{}LD"{}},\ R1\_R2,\ 0x1400,\ ld\_r1\_r2\ \},}
\DoxyCodeLine{00024\ \ \ \ \ \{\ \textcolor{stringliteral}{"{}ADDA"{}},\ R\_ADR\_X,\ 0x2000,\ adda\_r\_adr\_x\ \},}
\DoxyCodeLine{00025\ \ \ \ \ \{\ \textcolor{stringliteral}{"{}SUBA"{}},\ R\_ADR\_X,\ 0x2100,\ suba\_r\_adr\_x\ \},}
\DoxyCodeLine{00026\ \ \ \ \ \{\ \textcolor{stringliteral}{"{}ADDL"{}},\ R\_ADR\_X,\ 0x2200,\ addl\_r\_adr\_x\ \},}
\DoxyCodeLine{00027\ \ \ \ \ \{\ \textcolor{stringliteral}{"{}SUBL"{}},\ R\_ADR\_X,\ 0x2300,\ subl\_r\_adr\_x\ \},}
\DoxyCodeLine{00028\ \ \ \ \ \{\ \textcolor{stringliteral}{"{}ADDA"{}},\ R1\_R2,\ 0x2400,\ adda\_r1\_r2\ \},}
\DoxyCodeLine{00029\ \ \ \ \ \{\ \textcolor{stringliteral}{"{}SUBA"{}},\ R1\_R2,\ 0x2500,\ suba\_r1\_r2\ \},}
\DoxyCodeLine{00030\ \ \ \ \ \{\ \textcolor{stringliteral}{"{}ADDL"{}},\ R1\_R2,\ 0x2600,\ addl\_r1\_r2\ \},}
\DoxyCodeLine{00031\ \ \ \ \ \{\ \textcolor{stringliteral}{"{}SUBL"{}},\ R1\_R2,\ 0x2700,\ subl\_r1\_r2\ \},}
\DoxyCodeLine{00032\ \ \ \ \ \{\ \textcolor{stringliteral}{"{}AND"{}},\ R\_ADR\_X,\ 0x3000,\ and\_r\_adr\_x\ \},}
\DoxyCodeLine{00033\ \ \ \ \ \{\ \textcolor{stringliteral}{"{}OR"{}},\ R\_ADR\_X,\ 0x3100,\ or\_r\_adr\_x\ \},}
\DoxyCodeLine{00034\ \ \ \ \ \{\ \textcolor{stringliteral}{"{}XOR"{}},\ R\_ADR\_X,\ 0x3200,\ xor\_r\_adr\_x\ \},}
\DoxyCodeLine{00035\ \ \ \ \ \{\ \textcolor{stringliteral}{"{}AND"{}},\ R1\_R2,\ 0x3400,\ and\_r1\_r2\ \},}
\DoxyCodeLine{00036\ \ \ \ \ \{\ \textcolor{stringliteral}{"{}OR"{}},\ R1\_R2,\ 0x3500,\ or\_r1\_r2\ \},}
\DoxyCodeLine{00037\ \ \ \ \ \{\ \textcolor{stringliteral}{"{}XOR"{}},\ R1\_R2,\ 0x3600,\ xor\_r1\_r2\ \},}
\DoxyCodeLine{00038\ \ \ \ \ \{\ \textcolor{stringliteral}{"{}CPA"{}},\ R\_ADR\_X,\ 0x4000,\ cpa\_r\_adr\_x\ \},}
\DoxyCodeLine{00039\ \ \ \ \ \{\ \textcolor{stringliteral}{"{}CPL"{}},\ R\_ADR\_X,\ 0x4100,\ cpl\_r\_adr\_x\ \},}
\DoxyCodeLine{00040\ \ \ \ \ \{\ \textcolor{stringliteral}{"{}CPA"{}},\ R1\_R2,\ 0x4400,\ cpa\_r1\_r2\ \},}
\DoxyCodeLine{00041\ \ \ \ \ \{\ \textcolor{stringliteral}{"{}CPL"{}},\ R1\_R2,\ 0x4500,\ cpl\_r1\_r2\ \},}
\DoxyCodeLine{00042\ \ \ \ \ \{\ \textcolor{stringliteral}{"{}SLA"{}},\ R\_ADR\_X,\ 0x5000,\ sla\ \},}
\DoxyCodeLine{00043\ \ \ \ \ \{\ \textcolor{stringliteral}{"{}SRA"{}},\ R\_ADR\_X,\ 0x5100,\ sra\ \},}
\DoxyCodeLine{00044\ \ \ \ \ \{\ \textcolor{stringliteral}{"{}SLL"{}},\ R\_ADR\_X,\ 0x5200,\ sll\ \},}
\DoxyCodeLine{00045\ \ \ \ \ \{\ \textcolor{stringliteral}{"{}SRL"{}},\ R\_ADR\_X,\ 0x5300,\ srl\ \},}
\DoxyCodeLine{00046\ \ \ \ \ \{\ \textcolor{stringliteral}{"{}JMI"{}},\ ADR\_X,\ 0x6100,\ jmi\ \},}
\DoxyCodeLine{00047\ \ \ \ \ \{\ \textcolor{stringliteral}{"{}JNZ"{}},\ ADR\_X,\ 0x6200,\ jnz\ \},}
\DoxyCodeLine{00048\ \ \ \ \ \{\ \textcolor{stringliteral}{"{}JZE"{}},\ ADR\_X,\ 0x6300,\ jze\ \},}
\DoxyCodeLine{00049\ \ \ \ \ \{\ \textcolor{stringliteral}{"{}JUMP"{}},\ ADR\_X,\ 0x6400,\ jump\ \},}
\DoxyCodeLine{00050\ \ \ \ \ \{\ \textcolor{stringliteral}{"{}JPL"{}},\ ADR\_X,\ 0x6500,\ jpl\ \},}
\DoxyCodeLine{00051\ \ \ \ \ \{\ \textcolor{stringliteral}{"{}JOV"{}},\ ADR\_X,\ 0x6600,\ jov\ \},}
\DoxyCodeLine{00052\ \ \ \ \ \{\ \textcolor{stringliteral}{"{}PUSH"{}},\ ADR\_X,\ 0x7000,\ push\ \},}
\DoxyCodeLine{00053\ \ \ \ \ \{\ \textcolor{stringliteral}{"{}POP"{}},\ R\_,\ 0x7100,\ pop\ \},}
\DoxyCodeLine{00054\ \ \ \ \ \{\ \textcolor{stringliteral}{"{}CALL"{}},\ ADR\_X,\ 0x8000,\ call\ \},}
\DoxyCodeLine{00055\ \ \ \ \ \{\ \textcolor{stringliteral}{"{}SVC"{}},\ ADR\_X,\ 0xF000,\ svc\ \},}
\DoxyCodeLine{00056\ \ \ \ \ \{\ \textcolor{stringliteral}{"{}RET"{}},\ NONE,\ 0x8100,\ ret\ \},}
\DoxyCodeLine{00057\ \};}
\DoxyCodeLine{00058\ }
\DoxyCodeLine{00062\ \textcolor{keyword}{static}\ \textcolor{keywordtype}{int}\ comet2cmdsize\ =\ ARRAYSIZE(comet2cmd);}
\DoxyCodeLine{00063\ }
\DoxyCodeLine{00067\ \textcolor{keyword}{enum}\ \{}
\DoxyCodeLine{00068\ \ \ \ \ CMDTABSIZE\ =\ 41,}
\DoxyCodeLine{00069\ \};}
\DoxyCodeLine{00070\ }
\DoxyCodeLine{00074\ \textcolor{keyword}{static}\ CMDTAB\ *cmdtab[HASH\_MAX][CMDTABSIZE]\ =\ \{\{NULL\}\};}
\DoxyCodeLine{00075\ }
\DoxyCodeLine{00079\ \textcolor{keywordtype}{unsigned}\ hash\_cmdtype(\textcolor{keyword}{const}\ \textcolor{keywordtype}{char}\ *cmd,\ CMDTYPE\ type);}
\DoxyCodeLine{00080\ }
\DoxyCodeLine{00084\ \textcolor{keywordtype}{unsigned}\ hash\_code(WORD\ code);}
\DoxyCodeLine{00085\ }
\DoxyCodeLine{00089\ \textcolor{keywordtype}{void}\ cpu\_reset();}
\DoxyCodeLine{00090\ }
\DoxyCodeLine{00094\ \textcolor{keywordtype}{void}\ memory\_reset();}
\DoxyCodeLine{00095\ }
\DoxyCodeLine{00099\ \textcolor{keywordtype}{unsigned}\ hash\_cmdtype(\textcolor{keyword}{const}\ \textcolor{keywordtype}{char}\ *cmd,\ CMDTYPE\ type)}
\DoxyCodeLine{00100\ \{}
\DoxyCodeLine{00101\ \ \ \ \ HKEY\ *keys[2]\ =\ \{NULL\};}
\DoxyCodeLine{00102\ \ \ \ \ \textcolor{keywordtype}{unsigned}\ hashval\ =\ 0;}
\DoxyCodeLine{00103\ }
\DoxyCodeLine{00104\ \ \ \ \ \textcolor{comment}{/*\ 命令名を設定\ */}}
\DoxyCodeLine{00105\ \ \ \ \ keys[0]\ =\ malloc\_chk(\textcolor{keyword}{sizeof}(HKEY),\ \textcolor{stringliteral}{"{}hash\_cmdtype.keys[0]"{}});}
\DoxyCodeLine{00106\ \ \ \ \ keys[0]-\/>type\ =\ CHARS;}
\DoxyCodeLine{00107\ \ \ \ \ keys[0]-\/>val.s\ =\ strdup\_chk(cmd,\ \textcolor{stringliteral}{"{}keys[0].val.s"{}});}
\DoxyCodeLine{00108\ \ \ \ \ \textcolor{comment}{/*\ 命令タイプを設定\ */}}
\DoxyCodeLine{00109\ \ \ \ \ keys[1]\ =\ malloc\_chk(\textcolor{keyword}{sizeof}(HKEY),\ \textcolor{stringliteral}{"{}hash\_cmdtype.keys[1]"{}});}
\DoxyCodeLine{00110\ \ \ \ \ keys[1]-\/>type\ =\ INT;}
\DoxyCodeLine{00111\ \ \ \ \ keys[1]-\/>val.i\ =\ (int)(type\ \&\ 070);}
\DoxyCodeLine{00112\ \ \ \ \ \textcolor{comment}{/*\ ハッシュ値の計算\ */}}
\DoxyCodeLine{00113\ \ \ \ \ hashval\ =\ hash(2,\ keys,\ CMDTABSIZE);}
\DoxyCodeLine{00114\ \ \ \ \ FREE(keys[0]-\/>val.s);}
\DoxyCodeLine{00115\ \ \ \ \ FREE(keys[0]);}
\DoxyCodeLine{00116\ \ \ \ \ FREE(keys[1]);}
\DoxyCodeLine{00117\ \ \ \ \ \textcolor{comment}{/*\ ハッシュ値を返す\ */}}
\DoxyCodeLine{00118\ \ \ \ \ \textcolor{keywordflow}{return}\ hashval;}
\DoxyCodeLine{00119\ \}}
\DoxyCodeLine{00120\ }
\DoxyCodeLine{00124\ \textcolor{keywordtype}{bool}\ create\_cmdtable(CMDTAB\_HASH\ hash)}
\DoxyCodeLine{00125\ \{}
\DoxyCodeLine{00126\ \ \ \ \ CMDTAB\ *p\ =\ NULL;}
\DoxyCodeLine{00127\ \ \ \ \ \textcolor{keywordtype}{unsigned}\ hashval;}
\DoxyCodeLine{00128\ }
\DoxyCodeLine{00129\ \ \ \ \ \textcolor{keywordflow}{for}(\textcolor{keywordtype}{int}\ i\ =\ 0;\ i\ <\ comet2cmdsize;\ i++)\ \{}
\DoxyCodeLine{00130\ \ \ \ \ \ \ \ \ p\ =\ malloc\_chk(\textcolor{keyword}{sizeof}(CMDTAB),\ \textcolor{stringliteral}{"{}create\_cmdtable.p"{}});}
\DoxyCodeLine{00131\ \ \ \ \ \ \ \ \ p-\/>cmd\ =\ \&comet2cmd[i];}
\DoxyCodeLine{00132\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{if}(hash\ ==\ HASH\_CMDTYPE)\ \{}
\DoxyCodeLine{00133\ \ \ \ \ \ \ \ \ \ \ \ \ hashval\ =\ hash\_cmdtype(comet2cmd[i].name,\ comet2cmd[i].type);}
\DoxyCodeLine{00134\ \ \ \ \ \ \ \ \ \}\ \textcolor{keywordflow}{else}\ \textcolor{keywordflow}{if}(hash\ ==\ HASH\_CODE)\ \{}
\DoxyCodeLine{00135\ \ \ \ \ \ \ \ \ \ \ \ \ hashval\ =\ hash\_code(comet2cmd[i].code);}
\DoxyCodeLine{00136\ \ \ \ \ \ \ \ \ \}}
\DoxyCodeLine{00137\ \ \ \ \ \ \ \ \ p-\/>next\ =\ cmdtab[hash][hashval];}
\DoxyCodeLine{00138\ \ \ \ \ \ \ \ \ cmdtab[hash][hashval]\ =\ p;}
\DoxyCodeLine{00139\ \ \ \ \ \}}
\DoxyCodeLine{00140\ \ \ \ \ \textcolor{keywordflow}{return}\ \textcolor{keyword}{true};}
\DoxyCodeLine{00141\ \}}
\DoxyCodeLine{00142\ }
\DoxyCodeLine{00146\ \textcolor{keywordtype}{void}\ free\_cmdtable(CMDTAB\_HASH\ hash)}
\DoxyCodeLine{00147\ \{}
\DoxyCodeLine{00148\ \ \ \ \ CMDTAB\ *p\ =\ NULL;}
\DoxyCodeLine{00149\ \ \ \ \ CMDTAB\ *q\ =\ NULL;}
\DoxyCodeLine{00150\ }
\DoxyCodeLine{00151\ \ \ \ \ \textcolor{keywordflow}{for}(\textcolor{keywordtype}{int}\ i\ =\ 0;\ i\ <\ CMDTABSIZE;\ i++)\ \{}
\DoxyCodeLine{00152\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{for}(p\ =\ cmdtab[hash][i];\ p\ !=\ NULL;\ p\ =\ q)\ \{}
\DoxyCodeLine{00153\ \ \ \ \ \ \ \ \ \ \ \ \ q\ =\ p-\/>next;}
\DoxyCodeLine{00154\ \ \ \ \ \ \ \ \ \ \ \ \ FREE(p);}
\DoxyCodeLine{00155\ \ \ \ \ \ \ \ \ \}}
\DoxyCodeLine{00156\ \ \ \ \ \ \ \ \ cmdtab[hash][i]\ =\ NULL;}
\DoxyCodeLine{00157\ \ \ \ \ \}}
\DoxyCodeLine{00158\ \}}
\DoxyCodeLine{00159\ }
\DoxyCodeLine{00164\ WORD\ getcmdcode(\textcolor{keyword}{const}\ \textcolor{keywordtype}{char}\ *cmd,\ CMDTYPE\ type)}
\DoxyCodeLine{00165\ \{}
\DoxyCodeLine{00166\ \ \ \ \ CMDTAB\ *p\ =\ NULL;}
\DoxyCodeLine{00167\ \ \ \ \ WORD\ w\ =\ 0xFFFF;}
\DoxyCodeLine{00168\ }
\DoxyCodeLine{00169\ \ \ \ \ assert(cmd\ !=\ NULL);}
\DoxyCodeLine{00170\ \ \ \ \ \textcolor{keywordflow}{for}(p\ =\ cmdtab[HASH\_CMDTYPE][hash\_cmdtype(cmd,\ type)];\ p\ !=\ NULL;\ p\ =\ p-\/>next)\ \{}
\DoxyCodeLine{00171\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{if}(strcmp(cmd,\ p-\/>cmd-\/>name)\ ==\ 0\ \&\&\ type\ ==\ p-\/>cmd-\/>type)\ \{}
\DoxyCodeLine{00172\ \ \ \ \ \ \ \ \ \ \ \ \ w\ =\ p-\/>cmd-\/>code;}
\DoxyCodeLine{00173\ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{break};}
\DoxyCodeLine{00174\ \ \ \ \ \ \ \ \ \}}
\DoxyCodeLine{00175\ \ \ \ \ \}}
\DoxyCodeLine{00176\ \ \ \ \ \textcolor{keywordflow}{return}\ w;}
\DoxyCodeLine{00177\ \}}
\DoxyCodeLine{00178\ }
\DoxyCodeLine{00182\ \textcolor{keywordtype}{unsigned}\ hash\_code(WORD\ code)}
\DoxyCodeLine{00183\ \{}
\DoxyCodeLine{00184\ \ \ \ \ HKEY\ *keys[1]\ =\ \{NULL\};}
\DoxyCodeLine{00185\ \ \ \ \ \textcolor{keywordtype}{unsigned}\ h\ =\ 0;}
\DoxyCodeLine{00186\ }
\DoxyCodeLine{00187\ \ \ \ \ \textcolor{comment}{/*\ 命令コードを設定\ */}}
\DoxyCodeLine{00188\ \ \ \ \ keys[0]\ =\ malloc\_chk(\textcolor{keyword}{sizeof}(HKEY),\ \textcolor{stringliteral}{"{}hash\_code.key"{}});}
\DoxyCodeLine{00189\ \ \ \ \ keys[0]-\/>type\ =\ INT;}
\DoxyCodeLine{00190\ \ \ \ \ keys[0]-\/>val.i\ =\ (int)(code\ >>\ 8);}
\DoxyCodeLine{00191\ \ \ \ \ h\ =\ hash(1,\ keys,\ CMDTABSIZE);}
\DoxyCodeLine{00192\ \ \ \ \ FREE(keys[0]);}
\DoxyCodeLine{00193\ \ \ \ \ \textcolor{keywordflow}{return}\ h;}
\DoxyCodeLine{00194\ \}}
\DoxyCodeLine{00195\ }
\DoxyCodeLine{00199\ \textcolor{keyword}{const}\ void\ (*getcmdptr(WORD\ code))}
\DoxyCodeLine{00200\ \{}
\DoxyCodeLine{00201\ \ \ \ \ CMDTAB\ *t\ =\ NULL;}
\DoxyCodeLine{00202\ \ \ \ \ \textcolor{keyword}{const}\ \textcolor{keywordtype}{void}\ *ptr\ =\ NULL;}
\DoxyCodeLine{00203\ }
\DoxyCodeLine{00204\ \ \ \ \ \textcolor{keywordflow}{for}(t\ =\ cmdtab[HASH\_CODE][hash\_code(code)];\ t\ !=\ NULL;\ t\ =\ t-\/>next)\ \{}
\DoxyCodeLine{00205\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{if}(code\ ==\ t-\/>cmd-\/>code)\ \{}
\DoxyCodeLine{00206\ \ \ \ \ \ \ \ \ \ \ \ \ ptr\ =\ t-\/>cmd-\/>ptr;}
\DoxyCodeLine{00207\ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{break};}
\DoxyCodeLine{00208\ \ \ \ \ \ \ \ \ \}}
\DoxyCodeLine{00209\ \ \ \ \ \}}
\DoxyCodeLine{00210\ \ \ \ \ \textcolor{keywordflow}{return}\ ptr;}
\DoxyCodeLine{00211\ \}}
\DoxyCodeLine{00212\ }
\DoxyCodeLine{00216\ CMDTYPE\ getcmdtype(WORD\ code)}
\DoxyCodeLine{00217\ \{}
\DoxyCodeLine{00218\ \ \ \ \ CMDTAB\ *t\ =\ NULL;}
\DoxyCodeLine{00219\ \ \ \ \ CMDTYPE\ type\ =\ NONE;}
\DoxyCodeLine{00220\ }
\DoxyCodeLine{00221\ \ \ \ \ \textcolor{keywordflow}{for}(t\ =\ cmdtab[HASH\_CODE][hash\_code(code)];\ t\ !=\ NULL;\ t\ =\ t-\/>next)\ \{}
\DoxyCodeLine{00222\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{if}(code\ ==\ t-\/>cmd-\/>code)\ \{}
\DoxyCodeLine{00223\ \ \ \ \ \ \ \ \ \ \ \ \ type\ =\ t-\/>cmd-\/>type;}
\DoxyCodeLine{00224\ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{break};}
\DoxyCodeLine{00225\ \ \ \ \ \ \ \ \ \}}
\DoxyCodeLine{00226\ \ \ \ \ \}}
\DoxyCodeLine{00227\ \ \ \ \ \textcolor{keywordflow}{return}\ type;}
\DoxyCodeLine{00228\ \}}
\DoxyCodeLine{00229\ }
\DoxyCodeLine{00233\ \textcolor{keywordtype}{char}\ *getcmdname(WORD\ code)}
\DoxyCodeLine{00234\ \{}
\DoxyCodeLine{00235\ \ \ \ \ CMDTAB\ *t\ =\ NULL;}
\DoxyCodeLine{00236\ \ \ \ \ \textcolor{keywordtype}{char}\ *cmd\ =\ NULL;}
\DoxyCodeLine{00237\ }
\DoxyCodeLine{00238\ \ \ \ \ \textcolor{keywordflow}{for}(t\ =\ cmdtab[HASH\_CODE][hash\_code(code)];\ t\ !=\ NULL;\ t\ =\ t-\/>next)\ \{}
\DoxyCodeLine{00239\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{if}(code\ ==\ t-\/>cmd-\/>code)\ \{}
\DoxyCodeLine{00240\ \ \ \ \ \ \ \ \ \ \ \ \ cmd\ =\ t-\/>cmd-\/>name;}
\DoxyCodeLine{00241\ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{break};}
\DoxyCodeLine{00242\ \ \ \ \ \ \ \ \ \}}
\DoxyCodeLine{00243\ \ \ \ \ \}}
\DoxyCodeLine{00244\ \ \ \ \ \textcolor{keywordflow}{return}\ cmd;}
\DoxyCodeLine{00245\ \}}
\DoxyCodeLine{00246\ }
\DoxyCodeLine{00250\ }
\DoxyCodeLine{00251\ \textcolor{keywordtype}{char}\ *grstr(WORD\ word)}
\DoxyCodeLine{00252\ \{}
\DoxyCodeLine{00253\ \ \ \ \ assert(word\ <=\ 7);}
\DoxyCodeLine{00254\ \ \ \ \ \textcolor{keywordtype}{char}\ *str\ =\ NULL;}
\DoxyCodeLine{00255\ }
\DoxyCodeLine{00256\ \ \ \ \ str\ =\ malloc\_chk(3\ +\ 1,\ \textcolor{stringliteral}{"{}grstr.str"{}});}
\DoxyCodeLine{00257\ \ \ \ \ sprintf(str,\ \textcolor{stringliteral}{"{}GR\%d"{}},\ word);}
\DoxyCodeLine{00258\ \ \ \ \ \textcolor{keywordflow}{return}\ str;}
\DoxyCodeLine{00259\ \}}
\DoxyCodeLine{00260\ }
\DoxyCodeLine{00261\ WORD\ memsize\_str2word(\textcolor{keyword}{const}\ \textcolor{keywordtype}{char}\ *str)\ \{}
\DoxyCodeLine{00262\ \ \ \ \ \textcolor{keywordflow}{return}\ (WORD)str2l\_range(str,\ 1,\ MAX\_MEMSIZE,\ \textcolor{stringliteral}{"{}Memory\ Size"{}});}
\DoxyCodeLine{00263\ \}}
\DoxyCodeLine{00264\ }
\DoxyCodeLine{00268\ \textcolor{keywordtype}{void}\ comet2\_init(WORD\ memsize,\ CLOCK\ clocks)}
\DoxyCodeLine{00269\ \{}
\DoxyCodeLine{00270\ \ \ \ \ sys\ =\ malloc\_chk(\textcolor{keyword}{sizeof}(SYSTEM),\ \textcolor{stringliteral}{"{}sys"{}});}
\DoxyCodeLine{00271\ \ \ \ \ \textcolor{comment}{/*\ メモリサイズを設定\ */}}
\DoxyCodeLine{00272\ \ \ \ \ assert(0\ <\ memsize\ \&\&\ memsize\ <=\ MAX\_MEMSIZE-\/1);}
\DoxyCodeLine{00273\ \ \ \ \ sys-\/>memsize\ =\ memsize;}
\DoxyCodeLine{00274\ \ \ \ \ \textcolor{comment}{/*\ クロック周波数を設定\ */}}
\DoxyCodeLine{00275\ \ \ \ \ assert(0\ <\ clocks\ \&\&\ clocks\ <=\ MAX\_CLOCKS);}
\DoxyCodeLine{00276\ \ \ \ \ sys-\/>clocks\ =\ clocks;}
\DoxyCodeLine{00277\ \ \ \ \ \textcolor{comment}{/*\ CPU領域の確保\ */}}
\DoxyCodeLine{00278\ \ \ \ \ sys-\/>cpu\ =\ malloc\_chk(\textcolor{keyword}{sizeof}(CPU),\ \textcolor{stringliteral}{"{}comet2\_init.cpu"{}});}
\DoxyCodeLine{00279\ \ \ \ \ \textcolor{comment}{/*\ CPUをリセット\ */}}
\DoxyCodeLine{00280\ \ \ \ \ cpu\_reset();}
\DoxyCodeLine{00281\ \ \ \ \ \textcolor{comment}{/*\ メモリ領域の確保\ */}}
\DoxyCodeLine{00282\ \ \ \ \ sys-\/>memory\ =\ calloc\_chk(sys-\/>memsize,\ \textcolor{keyword}{sizeof}(WORD),\ \textcolor{stringliteral}{"{}comet2\_init.memory"{}});}
\DoxyCodeLine{00283\ \ \ \ \ \textcolor{comment}{/*\ メモリをリセット\ */}}
\DoxyCodeLine{00284\ \ \ \ \ memory\_reset();}
\DoxyCodeLine{00285\ \ \ \ \ \textcolor{comment}{/*\ CASL2プログラムの開始と終了のアドレスを初期化\ */}}
\DoxyCodeLine{00286\ \ \ \ \ execptr\ =\ malloc\_chk(\textcolor{keyword}{sizeof}(EXECPTR),\ \textcolor{stringliteral}{"{}execptr"{}});}
\DoxyCodeLine{00287\ \ \ \ \ execptr-\/>stop\ =\ \textcolor{keyword}{false};}
\DoxyCodeLine{00288\ \}}
\DoxyCodeLine{00289\ }
\DoxyCodeLine{00290\ }
\DoxyCodeLine{00291\ \textcolor{keywordtype}{void}\ cpu\_reset()\ \{}
\DoxyCodeLine{00292\ \ \ \ \ \textcolor{comment}{/*\ 汎用レジスタ\ \ */}}
\DoxyCodeLine{00293\ \ \ \ \ \textcolor{keywordflow}{for}(\textcolor{keywordtype}{int}\ i\ =\ 0;\ i\ <\ GRSIZE;\ i++)\ \{}
\DoxyCodeLine{00294\ \ \ \ \ \ \ \ \ sys-\/>cpu-\/>gr[i]\ =\ 0x0;}
\DoxyCodeLine{00295\ \ \ \ \ \}}
\DoxyCodeLine{00296\ \ \ \ \ sys-\/>cpu-\/>sp\ =\ sys-\/>memsize;\ \ \ \textcolor{comment}{/*\ スタックポインタ\ */}}
\DoxyCodeLine{00297\ \ \ \ \ sys-\/>cpu-\/>pr\ =\ 0x0;\ \ \ \ \ \ \ \ \ \ \ \ \textcolor{comment}{/*\ プログラムレジスタ\ */}}
\DoxyCodeLine{00298\ \ \ \ \ sys-\/>cpu-\/>fr\ =\ 0x0;\ \ \ \ \ \ \ \ \ \ \ \ \textcolor{comment}{/*\ フラグレジスタ\ */}}
\DoxyCodeLine{00299\ \}}
\DoxyCodeLine{00300\ }
\DoxyCodeLine{00304\ \textcolor{keywordtype}{void}\ memory\_reset()\ \{}
\DoxyCodeLine{00305\ \ \ \ \ memset(sys-\/>memory,\ 0,\ sys-\/>memsize\ *\ \textcolor{keyword}{sizeof}(WORD));}
\DoxyCodeLine{00306\ \}}
\DoxyCodeLine{00307\ }
\DoxyCodeLine{00311\ \textcolor{keywordtype}{void}\ comet2\_reset()}
\DoxyCodeLine{00312\ \{}
\DoxyCodeLine{00313\ \ \ \ \ \textcolor{comment}{/*\ CPUをリセット\ */}}
\DoxyCodeLine{00314\ \ \ \ \ cpu\_reset();}
\DoxyCodeLine{00315\ \}}
\DoxyCodeLine{00316\ }
\DoxyCodeLine{00320\ \textcolor{keywordtype}{void}\ comet2\_resetall()}
\DoxyCodeLine{00321\ \{}
\DoxyCodeLine{00322\ \ \ \ \ \textcolor{comment}{/*\ CPUをリセット\ */}}
\DoxyCodeLine{00323\ \ \ \ \ cpu\_reset();}
\DoxyCodeLine{00324\ \ \ \ \ \textcolor{comment}{/*\ メモリをリセット\ */}}
\DoxyCodeLine{00325\ \ \ \ \ memory\_reset();}
\DoxyCodeLine{00326\ \}}
\DoxyCodeLine{00327\ }
\DoxyCodeLine{00331\ \textcolor{keywordtype}{void}\ comet2\_shutdown()}
\DoxyCodeLine{00332\ \{}
\DoxyCodeLine{00333\ \ \ \ \ FREE(execptr);}
\DoxyCodeLine{00334\ \ \ \ \ FREE(sys-\/>memory);}
\DoxyCodeLine{00335\ \ \ \ \ FREE(sys-\/>cpu);}
\DoxyCodeLine{00336\ \ \ \ \ FREE(sys);}
\DoxyCodeLine{00337\ \}}
\end{DoxyCode}