1 #ifndef YACASL2_STRUCT_INCLUDED
2 #define YACASL2_STRUCT_INCLUDED
3
4 #include <stdio.h>
5 #include <assert.h>
6 #include <string.h>
7 #include <time.h>
8 #include "word.h"
9 #include "cmem.h"
10 #include "hash.h"
11 #include "exec.h"
12
13
14
15
16 enum {
17 CMDSIZE = 4,
18 GRSIZE = 8,
19 DEFAULT_MEMSIZE = 512,
20 DEFAULT_CLOCKS = 5000000,
21 };
22
23
24
25
26 enum {
27 OF = 0x4,
28 SF = 0x2,
29 ZF = 0x1,
30 };
31
32
33
34
35 typedef struct {
36 WORD gr[GRSIZE];
37 WORD sp;
38 WORD pr;
39 WORD fr;
40 } CPU;
41
42
43
44
45 typedef struct {
46 CPU *cpu;
47 WORD *memory;
48 int memsize;
49 clock_t clocks;
50 } SYSTEM;
51
52
53
54
55 extern SYSTEM *sys;
56
57
58
59
60 typedef enum {
61 HASH_CMDTYPE,
62 HASH_CODE,
63 HASH_MAX,
64 } CMDTAB_HASH;
65
66
67
68
69
70 typedef enum {
71
72
73
74
75
76
77 R_ADR_X = 01,
78
79
80
81
82
83 R1_R2 = 02,
84
85
86
87
88
89 ADR_X = 03,
90
91
92
93
94 R_ = 04,
95
96
97
98 NONE = 0,
99 } CMDTYPE;
100
101
102
103
104 typedef struct {
105 char *name;
106 const void (*ptr);
107 } CMD;
108
109
110
111
112 typedef struct {
113 char *name;
114 CMDTYPE type;
115 WORD code;
116 const void (*ptr);
117 } COMET2CMD;
118
119
120
121
122 typedef struct _CMDTAB {
123 struct _CMDTAB *next;
124 const COMET2CMD *cmd;
125 } CMDTAB;
126
127
128
129
130 typedef struct {
131 WORD start;
132 WORD end;
133 bool stop;
134 } EXECPTR;
135
136 extern EXECPTR *execptr;
137
138
139
140
141 typedef struct {
142 bool trace;
143 bool logical;
144 bool dump;
145 int dump_start;
146 int dump_end;
147 bool monitor;
148 bool step;
149 } EXECMODE;
150
151
152
153
154 extern EXECMODE execmode;
155
156
157
158
159
160
161
162
163 char *grstr(WORD word);
164
165
166
167
168 void reset(int memsize, int clocks);
169
170
171
172
173 void shutdown();
174
175
176
177
178
179
180
181
182 bool create_cmdtable(CMDTAB_HASH hash);
183
184
185
186
187 void free_cmdtable(CMDTAB_HASH hash);
188
189
190
191
192
193 WORD getcmdcode(const char *cmd, CMDTYPE type);
194
195
196
197
198 const void (*getcmdptr(WORD code));
199
200
201
202
203 CMDTYPE getcmdtype(WORD code);
204
205
206
207
208 char *getcmdname(WORD code);
209
210 #endif