]> Shamusworld >> Repos - rmac/blob - rmac.h
Fixed missing error reporting on fixup stage.
[rmac] / rmac.h
1 //
2 // RMAC - Reboot's Macro Assembler for the Atari Jaguar Console System
3 // RMAC.H - Main Application Code
4 // Copyright (C) 199x Landon Dyer, 2011 Reboot & Friends
5 // RMAC derived from MADMAC v1.07 Written by Landon Dyer, 1986
6 // Source Utilised with the Kind Permission of Landon Dyer
7 //
8
9 #ifndef __RMAC_H__
10 #define __RMAC_H__
11
12 //
13 // TARGET SPECIFIC BUILD SETTINGS
14 //
15 #ifdef WIN32
16         #define PLATFORM        "Win32"                 // Release platform - windows
17         #define _OPEN_FLAGS     _O_TRUNC|_O_CREAT|_O_BINARY|_O_RDWR
18         #define _OPEN_INC       _O_RDONLY|_O_BINARY
19         #define _PERM_MODE      _S_IREAD|_S_IWRITE 
20         #ifdef _MSC_VER
21                 #if _MSC_VER > 1000
22                         #pragma warning(disable:4996)
23                 #endif
24         #endif
25         #include <io.h>
26         #include <fcntl.h>
27         #include <stdio.h>
28         #include <stdlib.h>
29         #include <string.h>
30         #include <ctype.h>
31         #include <sys/types.h>
32         #include <sys/stat.h>
33 #else 
34         #ifdef __GCCUNIX__
35         #define PLATFORM        "OSX/Linux"             // Release platform - mac OS-X or linux
36         #define _OPEN_FLAGS     O_TRUNC|O_CREAT|O_RDWR
37         #define _OPEN_INC       O_RDONLY
38         #define _PERM_MODE      S_IREAD|S_IWRITE 
39         #include <sys/fcntl.h>
40         #include <stdio.h>
41         #include <stdlib.h>
42         #include <string.h>
43         #include <ctype.h>
44         #include <sys/types.h>
45         #include <sys/stat.h>
46         #include <unistd.h>
47 #else
48         #define PLATFORM        "Unknown"               // Release platform - not specified 
49         #define _OPEN_FLAGS     O_TRUNC|O_CREAT|O_RDWR
50         #define _OPEN_INC       O_RDONLY
51         #define _PERM_MODE      S_IREAD|S_IWRITE 
52         #include <sys/fcntl.h>
53         #include <stdio.h>
54         #include <stdlib.h>
55         #include <string.h>
56         #include <ctype.h>
57         #include <sys/types.h>
58         #include <sys/stat.h>
59         #endif
60 #endif
61
62 //
63 // Non-target specific stuff
64 //
65 #include <inttypes.h>
66 #include "symbol.h"
67
68 #define BYTE         uint8_t
69 #define WORD         uint16_t
70 #define LONG         uint32_t
71 #define VOID         void
72
73 #define ERROR        (-1)                       // Generic error return
74 #define EOS          '\0'                       // End of string
75 #define SPACE        ' '                        // Ascii space 
76 #define SLASHCHAR    '/'
77 #define SLASHSTRING  "/"
78 #define VALUE        LONG                       // Assembler value
79 #define TOKEN        LONG                       // Assembler token
80 #define FNSIZ        128                        // Maximum size of a filename
81 #define OK           0                          // OK return
82 #define DEBUG        if (debug)         // Debug conditional
83 #define MAXARGV      100                        // Maximum number of commandline args
84 #define STDOUT       1                          // Standard output
85 #define ERROUT       2                          // Error output
86 #define CREATMASK    0
87
88 // (Normally) non-printable tokens
89 #define COLON        ':'                        // : (grumble: GNUmacs hates ':')
90 #define CONST        'a'                        // CONST <value>
91 #define ACONST       'A'                        // ACONST <value> <attrib>
92 #define STRING       'b'                        // STRING <address>
93 #define SYMBOL       'c'                        // SYMBOL <address>
94 #define EOL          'e'                        // End of line
95 #define TKEOF        'f'                        // End of file (or macro)
96 #define DEQUALS      'g'                        // ==
97 #define SET          149                        // set
98 #define REG          'R'                        // reg
99 #define EQUREG       148                        // equreg
100 #define CCDEF        183                        // ccdef
101 #define DCOLON       'h'                        // ::
102 #define GE           'i'                        // >=
103 #define LE           'j'                        // <=
104 #define NE           'k'                        // <> or !=
105 #define SHR          'l'                        // >>
106 #define SHL          'm'                        // <<
107 #define UNMINUS      'n'                        // Unary '-'
108 #define DOTB         'B'                        // .b or .B or .s or .S
109 #define DOTW         'W'                        // .w or .W
110 #define DOTL         'L'                        // .l or .L
111 #define DOTI         'I'                        // .i or .I
112 #define ENDEXPR      'E'                        // End of expression
113
114 // Object code formats
115 #define ALCYON       0                          // Alcyon/DRI C object format
116 #define MWC          1                          // Mark Williams object format
117 #define BSD          2                          // BSD object format
118
119 // Pointer type that can point to (almost) anything
120 #define PTR union _ptr
121 PTR
122 {
123    char * cp;                                           // Char
124    WORD * wp;                                           // WORD
125    LONG * lp;                                           // LONG
126    LONG lw;                                                     // LONG
127    SYM ** sy;                                           // SYM
128    TOKEN * tk;                                          // TOKEN
129 };
130
131 // Symbol spaces
132 #define LABEL        0                          // User-defined symbol
133 #define MACRO        1                          // Macro definition
134 #define MACARG       2                          // Macro argument
135 #define SY_UNDEF     -1                         // Undefined (lookup never matches it)
136
137 // Symbol and expression attributes
138 #define DEFINED      0x8000                     // Symbol has been defined
139 #define GLOBAL       0x4000                     // Symbol has been .GLOBL'd
140 #define COMMON       0x2000                     // Symbol has been .COMM'd
141 #define REFERENCED   0x1000                     // Symbol has been referenced
142 #define EQUATED      0x0800                     // Symbol was equated
143 #define SDECLLIST    0x0400                     // Symbol is on 'sdecl'-order list
144
145 // Expression spaces, ORed with symbol and expression attributes above
146 #define ABS          0x0000                     // In absolute space
147 #define TEXT         0x0001                     // Relative to text
148 #define DATA         0x0002                     // Relative to data
149 #define BSS          0x0004                     // Relative to BSS
150 //#define M6502        0x0008           // 6502/microprocessor (absolute)
151 #define TDB          (TEXT|DATA|BSS)    // Mask for text+data+bss
152
153 // Sizes 
154 #define SIZB         0x0001                     // .b 
155 #define SIZW         0x0002                     // .w 
156 #define SIZL         0x0004                     // .l 
157 #define SIZN         0x0008                     // no .(size) specifier
158
159 // RISC register bank definitions (used in extended symbol attributes also)
160 #define BANK_N       0x0000                     // No register bank specified
161 #define BANK_0       0x0001                     // Register bank zero specified
162 #define BANK_1       0x0002                     // Register bank one specified
163 #define EQUATEDREG   0x0008                     // Equated register symbol
164 #define UNDEF_EQUR   0x0010
165 #define EQUATEDCC    0x0020
166 #define UNDEF_CC     0x0040
167
168 #define RISCSYM      0x00010000
169
170 // Globals, externals etc
171 extern int verb_flag;
172 extern int debug;
173 extern int rgpu, rdsp;
174 extern int err_flag;
175 extern int err_fd;
176 extern int regbank;
177 extern char * firstfname;
178 extern int list_fd;
179 extern int as68_flag;
180 extern int list_flag;
181 extern int glob_flag;
182 extern int lsym_flag;
183 extern int sbra_flag;
184 extern int obj_format;
185 extern LONG amemtot;
186 extern int in_main;
187
188 // Prototypes
189 void init_sym(void);
190 SYM * newsym(char *, int, int);
191 char * fext(char *, char *, int);
192 void cantcreat(char *);
193 int kmatch(char *, int *, int *, int *, int *);
194 void autoeven(int);
195 int nthpath(char *, int, char *);
196 void clear(char *, LONG);
197 char * copy(char *, char *, LONG);
198 int rmac_qsort(char *, int, int, int (*)());
199 //char * amem(LONG);
200
201 #endif // __RMAC_H__