-
Notifications
You must be signed in to change notification settings - Fork 3
/
asmreal.h
466 lines (364 loc) · 11.7 KB
/
asmreal.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
#ifndef INCLUDE_ASMREAL_H
#define INCLUDE_ASMREAL_H
// asmreal.h
// Revision 10-jan-2007
#include "asmimpl.h"
#include "asmfile.h"
#include "var.h"
#include "macro.h"
#include "macroframe.h"
#include "module.h"
#include "local.h"
#include <iostream>
namespace pasmo {
namespace impl {
class AsmReal : public AsmImpl, public AsmFile,
public Vars, public MacroStore
{
public:
AsmReal (const AsmOptions & options_n);
// This is not a copy constructor, it creates a new
// instance copying the options and the AsmFile.
explicit AsmReal (const AsmReal & in);
~AsmReal ();
static Asm * create (const AsmOptions & options_n);
ValueType getinitialsegment ();
void setbase (unsigned int addr);
void addincludedir (const string & dirname);
void addpredef (const string & predef);
void setfilelisting (ostream & out_n);
AsmMode getasmmode () const;
bool getnocase () const;
void loadfile (const string & filename);
void link_modules (vector <Module *> & vpmod);
void loadmodules (vector <Module> & mod);
void link ();
void processfile ();
int currentpass () const;
//address getcurrentinstruction () const;
Value getcurrentinstruction () const;
// Variable access for local classes.
VarData getvar (const string & varname);
VarData rawgetvar (const string & varname);
string genlocalname (const string & varname);
// Object file generation.
address getminused () const;
address getmaxused () const;
size_t getcodesize () const;
void message_emit (const string & type);
void writebincode (ostream & out);
void emitobject (ostream & out);
void emitdump (std::ostream & out);
void emitplus3dos (ostream & out);
void emittap (ostream & out);
void writetzxcode (ostream & out);
void emittzx (ostream & out);
void writecdtcode (ostream & out);
void emitcdt (ostream & out);
string cpcbasicloader ();
void emitcdtbas (ostream & out);
string spectrumbasicloader ();
void emittapbas (ostream & out);
void emittzxbas (ostream & out);
void emithex (ostream & out);
void emitamsdos (ostream & out);
void emitprl (ostream & out);
void emitrel (ostream & out);
void emitcmd (ostream & out);
void emitcom (ostream & out);
void emitmsx (ostream & out);
void emitcode (ostream & out);
void dumppublic (ostream & out);
void dumpsymbol (ostream & out);
private:
void operator = (const AsmReal &); // Forbidden.
static std::streambuf * pnullbuf ();
void setentrypoint (address addr);
void checkendline (const Token & tok);
void checkendline (Tokenizer & tz);
//address currentpos () const;
Value currentpos () const;
void clearphase ();
//address phased (address addr) const;
//address phasedpos () const;
Value phased (Value addr) const;
Value phasedpos () const;
void genbyte (byte abyte);
void genword (address dataword);
void gencode (byte code);
void gencode (const VarData & vd);
void gencode (byte code1, byte code2);
void gencode (byte code1, byte code2, byte code3);
void gencode (byte code1, byte code2, byte code3, byte code4);
void gencodeED (byte code);
void gencodeword (address value);
void gencodeword (const Value & v);
void gencodeword (const VarData & vd);
void showcode (const string & instruction);
void showdebnocodeline (const Tokenizer & tz);
public:
void warningUglyInstruction ();
void parse_error (const string & errmsg);
void doEmpty ();
void doLabel (const string & varname);
void doExpandMacro (const string & name,
const MacroArgList & params);
void doASEG ();
void doCSEG ();
void doDEFBliteral (const string & s);
void doDEFBnum (byte b);
//void doDEFBnum (const VarData & vd);
void doDEFBend ();
void doDEFL (const string & label, address value);
void doDEFS (address count, byte value);
//void doDEFWnum (address num);
void doDEFWnum (const VarData & num);
void doDEFWend ();
void doDSEG ();
void doELSE ();
//void doEND (address end, bool hasentry);
void doEND ();
void doEND (const VarData & vd);
void doENDIF ();
void doENDM ();
void doENDP ();
void doEQU (const string & label, const VarData & vdata);
void doEXITM ();
void doEXTRN (const VarnameList & varnamelist);
void doIF (address v);
void doIF1 ();
void doIF2 ();
void doIFDEF (const string & varname);
void doIFNDEF (const string & varname);
void doINCBIN (const string & includefile);
void doINCLUDE ();
void doEndOfINCLUDE ();
void doIRP (const string & varname, const MacroArgList & params);
void doIRPC (const string & varname, const string & charlist);
void doLOCAL (const VarnameList & varnamelist);
void doMACRO (const string & name, const vector <string> & param);
void doPROC ();
void doORG (address neworg);
void doPUBLIC (const VarnameList & varnamelist);
void doREPT (address counter, const string & varcounter,
address valuecounter, address step);
void do_8080 ();
void do_DEPHASE ();
void do_ERROR (const string & msg);
void do_PHASE (address value);
void do_SHIFT ();
void do_WARNING (const string & msg);
void do_Z80 ();
void doByteInst (TypeByteInst ti, regbCode reg,
byte prefix= prefixNone, bool hasdesp= false, byte desp= 0);
void doByteInmediate (TypeByteInst ti, byte bvalue);
void doByteInstCB (byte codereg, regbCode reg,
byte prefix= prefixNone, bool hasdesp= false, byte desp= 0);
void doNoargInst (TypeToken tt);
void doADDADCSBC_HL (byte basecode, regwCode reg, byte prefix);
void doDJNZ (const VarData & vd);
//void doCALL (address addr);
void doCALL (const VarData & addr);
//void doCALL_flag (flagCode fcode, address addr);
void doCALL_flag (flagCode fcode, const VarData & vd);
void doEX_indSP_HL ();
void doEX_indSP_IX ();
void doEX_indSP_IY ();
void doEX_AF_AFP ();
void doEX_DE_HL ();
void doIN_A_indC ();
void doIN_A_indn (byte n);
void doINr_c_ (regbCode reg);
void doIM (address v);
//void doJP (address addr);
void doJP (const VarData & addr);
void doJP_indHL ();
void doJP_indIX ();
void doJP_indIY ();
//void doJP_flag (flagCode fcode, address addr);
void doJP_flag (flagCode fcode, const VarData & addr);
void doRelative (byte code, address addr, const string instrname);
void doRelative (byte code, const VarData & vd,
const string instrname);
void doJR (const VarData & vd);
void doJR_flag (flagCode fcode, const VarData & vd);
void doLDir (byte type);
void doLD_r_r (regbCode reg1, regbCode reg2);
void doLD_r_n (regbCode reg, byte n);
void doLD_r_undoc (regbCode reg1, regbCode reg2, byte prefix);
void doLD_r_idesp (regbCode reg1, byte prefix, byte desp);
void doLD_undoc_r (regbCode reg1, byte prefix, regbCode reg2);
void doLD_undoc_n (regbCode reg, byte prefix, byte n);
void doLD_idesp_r (byte prefix, byte desp, regbCode reg2);
void doLD_A_indexp (const VarData & vd);
void doLD_A_indBC ();
void doLD_A_indDE ();
void doLD_indBC_A ();
void doLD_indDE_A ();
void doLD_indexp_A (const VarData & vd);
void doLD_indexp_BC (const VarData & vd);
void doLD_indexp_DE (const VarData & vd);
void doLD_indexp_HL (const VarData & vd);
void doLD_indexp_SP (const VarData & vd);
void doLD_indexp_IX (const VarData & vd);
void doLD_indexp_IY (const VarData & vd);
void doLD_idesp_n (byte prefix, byte desp, byte n);
void doPUSHPOP (regwCode reg, byte prefix, bool isPUSH);
void doLD_SP_HL ();
void doLD_SP_IX ();
void doLD_SP_IY ();
void doLD_SP_nn (const VarData & value);
void doLD_SP_indexp (const VarData & value);
void doLD_HL_nn (const VarData & value);
void doLD_HL_indexp (const VarData & vd);
//void doLD_rr_nn (regwCode regcode, byte prefix, address value);
void doLD_rr_nn (regwCode regcode,
const VarData & addr);
//void doLD_rr_indexp (regwCode regcode, byte prefix, address value);
void doLD_rr_indexp (regwCode regcode,
const VarData & addr);
void doLD_IXY_nn (byte prefix, const VarData & addr);
void doLD_IXY_indexp (byte prefix, const VarData & addr);
void doINC_r (bool isINC, byte prefix, regbCode reg);
void doINC_IX (bool isINC, address adesp);
void doINC_IY (bool isINC, address adesp);
void doINC_rr (bool isINC, regwCode reg, byte prefix);
void doOUT_C_ (regbCode rcode);
void doOUT_n_ (byte b);
void doRET ();
void doRETflag (flagCode fcode);
void doRST (address addr);
private:
void showlistingblank (const string & txt);
void showlisting ();
void showlistingsymbols ();
void showlistingequ (address value);
void showlistingheader ();
string getlistingstatus () const;
string getcurrentlistingtext ();
address getvalue (const string & var, bool required, bool ignored);
bool setvardef (const string & varname,
address value, Defined defined);
bool setvardef (const string & varname,
const VarData & vdata, Defined defined);
public:
bool isdefined (const string & varname);
private:
Tokenizer getcurrenttz ();
void parseinstruction (Tokenizer & tz);
void do_iftrue (TypeToken ttif);
void do_iffalse (TypeToken ttif);
void do_if (TypeToken ttif, bool valueif);
void parseline (Tokenizer & tz);
//void link_rel_module (const string & relname);
//void link_modules ();
void dopass ();
bool setequorlabel (const string & varname, address value);
bool setlabel (const string & varname, const Value & v);
bool setequ (const string & varname, const VarData & vdata);
bool setdefl (const string & varname, address value);
// Aux error and warning functions.
public:
void emitwarning (const string & text);
private:
void no8080 ();
void no86 ();
// Z80 instructions.
//void genCALL (byte code, address addr);
void genCALL (byte code, const VarData & addr);
//void genJP (byte code, address addr);
void genJP (byte code, const VarData & addr);
// Variables.
const AsmOptions opt;
AsmMode asmmode;
GenCodeMode genmode;
// ********* Information streams ********
bool debout_flag;
bool listing_file;
bool listing_flag;
ostream debout;
ostream errout;
ostream verbout;
ostream warnout;
ostream listout;
size_t counterr;
Module mainmodule;
Segment mainseg;
address link_base;
address base;
//address current;
bool phase_active;
address phasing;
//address currentinstruction;
Value currentinstruction;
//address minused;
//address maxused;
address entrypoint;
bool hasentrypoint;
int pass;
bool end_reached;
vector <size_t> ifline;
size_t iflevel;
public:
size_t getiflevel () const;
void setiflevel (size_t newlevel);
void deciflevel ();
private:
size_t includelevel;
size_t macrolevel;
int listingpagelen;
int listinglines;
int listingspage;
int listingstep;
vector <string> hexlisting;
// ********* Local **********
size_t localcount;
vector <string> localnames;
void initlocal ();
LocalStack localstack;
public:
void pushlocal (LocalLevel * plevel);
LocalLevel * toplocal () const;
void poplocal ();
private:
bool isautolocalname (const string & varname);
AutoLevel * enterautolocal ();
void finishautolocal ();
void checkautolocal (const string & varname);
void verifynoautolocal (const string & varname);
void enterorfinishautolocal (const string & varname);
void checkafterprocess ();
// ********* Macro **********
//MapMacro mapmacro;
public:
const Macro & getmacro (const string & name);
bool ismacro (const string & name) const;
private:
bool gotoENDM ();
void domacroexpansion (MacroFrameMacro & mframe);
void expandIRP (MacroFrameIRPbase & macroirp,
const MacroArgList & params);
MacroFrameBase * pcurrentmframe;
public:
MacroFrameBase * getmframe () const;
void setmframe (MacroFrameBase * pnew);
// ********** Extern references **********
private:
typedef map <address, string> ChainExtern;
ChainExtern chainextern;
typedef map <address, address> ExternOffset;
ExternOffset externoffset;
public:
typedef map <address, Value> Relative;
//typedef map <address, string> RefToExtern;
typedef map <string, address> RefToExtern;
typedef map <address, Value> Offset;
private:
Relative relative;
RefToExtern reftoextern;
Offset offset;
};
} // namespace impl
} // namespace pasmo
#endif
// End of asmreal.h