-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
as09.h
148 lines (123 loc) · 3.11 KB
/
as09.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
//================================================================================
// as09 - an MC6809E cross-assember
//
// See LICENSE file for usage rights and obligations
//================================================================================
#ifndef __AS09_H
#define __AS09_H
//-----------------
// constant decls
//-----------------
#define APP_NAME "as09"
#define APP_VER "0.5.3"
#define DONE 0
#define ADDRESS_BITS 16
#define INSTRUCTION_BITS 8
#define MAX_CODE 0x7FFF
#define MAX_SYMBOLS 4096
#define MAX_FIXUPS 4096
#define BUF_SIZE 512
#define INB_SIZE 32
#define SA_UNDEF -1
#define FP_NONE -1
#ifdef _WIN32
# define strcasecmp _stricmp
# define strdup _strdup
#endif
#ifndef TRUE
# define TRUE 1
#endif
#ifndef FALSE
# define FALSE 0
#endif
// remove this later
#define YYDEBUG 1
#ifndef LOBYTE
# define LOBYTE(word) ((word) & 0xFF)
#endif
#ifndef HIBYTE
# define HIBYTE(word) (((word) & 0xFF00) >> 8)
#endif
// opcode indices
enum
{
OP_ADCA, OP_ADCB, OP_ADDA, OP_ADDB, OP_ADDD, OP_ANDA, OP_ANDB, OP_ASL,
OP_ASR, OP_BITA, OP_BITB, OP_CLR, OP_CMPA, OP_CMPB, OP_CMPD, OP_CMPS,
OP_COM, OP_DEC, OP_EORA, OP_EORB, OP_INC, OP_JMP, OP_JSR, OP_LDA, OP_LDB,
OP_LDD, OP_LDU, OP_LDX, OP_LEAX, OP_LEAY, OP_LEAS, OP_LEAU, OP_LSL, OP_LSR,
OP_NEG, OP_ORA, OP_ORB, OP_ROL, OP_ROR, OP_SBCB, OP_SBCA, OP_STA, OP_STB,
OP_STD, OP_STS, OP_STU, OP_STX, OP_STY, OP_SUBA, OP_SUBB, OP_SUBD, OP_TST,
};
// branch types
typedef enum { BR_SHORT, BR_LONG, BR_LONG_NOPREFIX } BRANCH_TYPE;
typedef struct
{
FILE *fptr;
int yylineno;
int column;
char *filename;
} FileNode;
// opcodes for addressing modes
typedef struct
{
uint8_t ops[4];
} Opcodes;
// symbol types
typedef enum
{
ST_UNDEF, // symbol is undefined
ST_EQU, // symbol is an EQUate
ST_SET, // symbol is a set value
ST_LABEL, // symbol is an address label
ST_STRING // symbol is a string literal
} SYMBOL_TYPE;
// fixup types
typedef enum
{
FIXUP_NOCHANGE,
FIXUP_IMM8,
FIXUP_IMM16,
FIXUP_REL8,
FIXUP_REL16,
FIXUP_MAX
} FIXUP_TYPE;
// Address mode types
typedef enum
{
AM_IMM,
AM_DIRECT,
AM_INDEXED,
AM_EXTENDED,
} ADDRESS_MODE_TYPE;
// symbol structure def'n
typedef struct
{
const char *name;
const char *filename; // file where symbols was defined
int type;
int value;
int lineno; // local file line number
int refd; // was symbol referenced?
} Symbol_t;
// fixup structure def'n
typedef struct
{
const char *filename; // file where fixup resides
int symbol; // reference to symbol not yet defined
int addr; // address where symbol address is to be patched
FIXUP_TYPE type; // type of fixup imm8/16 or rel8/16
int lineno; // line number where fixup resides
} Fixup_t;
// token structure def'n
typedef struct
{
const char *lexeme;
int token;
} Tokens;
//-----------------
// function decls
//-----------------
int yylex();
void yyerror(char*);
int add_fixup(int symbol, int addr, FIXUP_TYPE type);
#endif //__AS_H