1 #ifndef ASM_H
2 #define ASM_H
3 /* asm.h: token codes and macros for them. protos.
4  * $Id: asm.h,v 1.6 2002/10/01 21:55:00 rowan Exp $
5  */
6 
7 /* This file is part of `exhaust', a memory array redcode simulator.
8  * Author: M Joonas Pihlaja
9  * Public Domain.
10  */
11 
12 #include <stdio.h>
13 /* macros:
14  *	is_tok_opcode()		just what it says
15  *	is_tok_pseudoop()
16  *	is_tok_modifier()
17  *	is_tok_mode()		is a token an addressing mode
18  */
19 
20 /*
21  * asm_line() exit codes:
22  *
23  */
24 
25 #define ASMLINE_PIN  -3		/* PIN encountered */
26 #define ASMLINE_ORG  -2		/* ORG encountered */
27 #define ASMLINE_DONE -1		/* END encountered */
28 #define ASMLINE_NONE  0		/* nothing to assemble, or something ignored */
29 #define ASMLINE_OK    1		/* assembled instruction OK */
30 
31 /*
32  * Token codes for the lexer.
33  */
34 enum {
35   TOK_FIRST = 256,		/* not used */
36 
37   TOK_OPCODE_START,		/* opcodes */
38   TOK_DAT,			/* same order as insn.h opcodes. */
39   TOK_SPL,
40   TOK_MOV,
41   TOK_DJN,
42   TOK_ADD,
43   TOK_JMZ,
44   TOK_SUB,
45   TOK_SEQ,
46   TOK_SNE,
47   TOK_SLT,
48   TOK_JMN,
49   TOK_JMP,
50   TOK_NOP,
51   TOK_MUL,
52   TOK_MOD,
53   TOK_DIV,
54   TOK_LDP,
55   TOK_STP,			/* 18 */
56   TOK_OPCODE_STOP,
57 
58   TOK_PSEUDOOP_START,
59     TOK_ORG,			/* pseudo-ops and start label */
60     TOK_END,
61     TOK_PIN,
62   TOK_PSEUDOOP_STOP,
63 
64   TOK_MODIFIER_START,
65     TOK_mF, TOK_mA, TOK_mB,	/* modifiers */
66     TOK_mAB, TOK_mBA, TOK_mX, TOK_mI,
67   TOK_MODIFIER_STOP,
68 
69   TOK_MODE_START,
70     TOK_DIRECT, TOK_IMMEDIATE,	/* addressing modes */
71     TOK_BINDIRECT,  TOK_BPREDEC,
72     TOK_BPOSTINC,  TOK_AINDIRECT,
73     TOK_APREDEC,  TOK_APOSTINC,	/* 8 */
74   TOK_MODE_STOP,
75 
76   TOK_START,
77   TOK_STR, TOK_INT,		/* string token, int token  */
78 
79   TOK_LAST			/* sentinel */
80 };
81 
82 
83 #define TOK_ERR TOK_FIRST	/* unused */
84 
85 /*
86  * Macros to identify a token type from a token code.
87  */
88 #define is_tok_opcode(t)   ( t > TOK_OPCODE_START && t < TOK_OPCODE_STOP )
89 #define is_tok_pseudoop(t) ( t > TOK_PSEUDOOP_START && t < TOK_PSEUDOOP_STOP )
90 #define is_tok_modifier(t) ( t > TOK_MODIFIER_START && t < TOK_MODIFIER_STOP )
91 #define is_tok_mode(t)     ( t > TOK_MODE_START && t < TOK_MODE_STOP )
92 
93 
94 /*
95  * protos
96  */
97 int asm_line( const char *line, insn_t *in, unsigned int CORESIZE );
98 void asm_file( FILE *F, warrior_t *w, unsigned int CORESIZE );
99 void asm_fname( const char *fname, warrior_t *w, unsigned int CORESIZE );
100 void dis1( char *s, insn_t in, unsigned int CORESIZE );
101 void discore( const insn_t *core, int start, int end, unsigned int CORESIZE );
102 
103 
104 #endif /* ASM_H */
105