]> Shamusworld >> Repos - rmac/blob - rmac.h
Version bump. :-)
[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 #include <stdio.h>
13 #include <stdlib.h>
14 #include <string.h>
15 #include <ctype.h>
16 #include <sys/types.h>
17 #include <sys/stat.h>
18
19 //
20 // TARGET SPECIFIC BUILD SETTINGS
21 //
22 #if defined(WIN32) || defined (WIN64)
23         #include <io.h>
24         #include <fcntl.h>
25         // Release platform - windows
26         #define PLATFORM        "Win32"
27         #define _OPEN_FLAGS     _O_TRUNC|_O_CREAT|_O_BINARY|_O_RDWR
28         #define _OPEN_INC       _O_RDONLY|_O_BINARY
29         #define _PERM_MODE      _S_IREAD|_S_IWRITE 
30         #ifdef _MSC_VER
31                 #if _MSC_VER > 1000
32                         #pragma warning(disable:4996)
33                 #endif
34
35         // Makes warnings double clickable on visual studio (ggn)
36         #define STRINGIZE_HELPER(x) #x
37         #define STRINGIZE(x) STRINGIZE_HELPER(x)
38         #define WARNING(desc) __pragma(message(__FILE__ "(" STRINGIZE(__LINE__) ") : Warning: " #desc))
39
40         // usage:
41         // WARNING(FIXME: Code removed because...)
42
43         #else
44         // If we're not compiling for Visual Studio let's assume that we're using
45         // some flavour of gcc instead. So let's use the gcc compliant macro
46         // instead. If some weirdo uses something else (I dunno, Intel compiler or
47         // something?) this is probably going to explode spectacularly. Let's wait
48         // for the fireworks!
49         #define DO_PRAGMA(x) _Pragma (#x)
50         #define WARNING(desc) DO_PRAGMA(message (#desc))
51         #define inline __inline
52
53         #endif
54
55 #else 
56         #ifdef __GCCUNIX__
57         #include <sys/fcntl.h>
58         #include <unistd.h>
59         // Release platform - mac OS-X or linux
60         #define PLATFORM        "OSX/Linux"
61         #define _OPEN_FLAGS     O_TRUNC|O_CREAT|O_RDWR
62         #define _OPEN_INC       O_RDONLY
63         #define _PERM_MODE      S_IRUSR|S_IWUSR
64         // WARNING WARNING WARNING
65         #define DO_PRAGMA(x) _Pragma (#x)
66         #define WARNING(desc) DO_PRAGMA(message (#desc))
67 #else
68         // Release platform - not specified 
69         #include <sys/fcntl.h>
70         #define PLATFORM        "Unknown"
71         #define _OPEN_FLAGS     O_TRUNC|O_CREAT|O_RDWR
72         #define _OPEN_INC       O_RDONLY
73         #define _PERM_MODE      S_IREAD|S_IWRITE
74         // Defined here, even though the platform may not support it...
75         #define DO_PRAGMA(x) _Pragma (#x)
76         #define WARNING(desc) DO_PRAGMA(message (#desc))
77         #endif
78 #endif
79
80 //
81 // Non-target specific stuff
82 //
83 #include <inttypes.h>
84 #include "symbol.h"
85
86 #define BYTE         uint8_t
87 #define WORD         uint16_t
88 #define LONG         uint32_t
89 #define VOID         void
90
91 #define ERROR        (-1)                       // Generic error return
92 #define EOS          '\0'                       // End of string
93 #define SPACE        ' '                        // ASCII space 
94 #define SLASHCHAR    '/'
95 #define SLASHSTRING  "/"
96 #define VALUE        LONG                       // Assembler value
97 #define TOKEN        LONG                       // Assembler token
98 #define FNSIZ        128                        // Maximum size of a filename
99 #define OK           0                          // OK return
100 #define DEBUG        if (debug)         // Debug conditional
101 #define MAXARGV      100                        // Maximum number of commandline args
102 #define STDOUT       1                          // Standard output
103 #define ERROUT       2                          // Error output
104 #define CREATMASK    0
105
106 // (Normally) non-printable tokens
107 #define COLON        ':'                        // : (grumble: GNUmacs hates ':')
108 #define CONST        'a'                        // CONST <value>
109 #define ACONST       'A'                        // ACONST <value> <attrib>
110 #define STRING       'b'                        // STRING <address>
111 #define SYMBOL       'c'                        // SYMBOL <address>
112 #define EOL          'e'                        // End of line
113 #define TKEOF        'f'                        // End of file (or macro)
114 #define DEQUALS      'g'                        // ==
115 #define SET          149                        // set
116 #define REG          'R'                        // reg
117 #define EQUREG       148                        // equreg
118 #define CCDEF        183                        // ccdef
119 #define DCOLON       'h'                        // ::
120 #define GE           'i'                        // >=
121 #define LE           'j'                        // <=
122 #define NE           'k'                        // <> or !=
123 #define SHR          'l'                        // >>
124 #define SHL          'm'                        // <<
125 #define UNMINUS      'n'                        // Unary '-'
126 #define DOTB         'B'                        // .b or .B or .s or .S
127 #define DOTW         'W'                        // .w or .W
128 #define DOTL         'L'                        // .l or .L
129 #define DOTI         'I'                        // .i or .I
130 #define ENDEXPR      'E'                        // End of expression
131
132 // Object code formats
133 #define ALCYON       0                          // Alcyon/DRI C object format
134 #define MWC          1                          // Mark Williams object format
135 #define BSD          2                          // BSD object format
136
137 // Pointer type that can point to (almost) anything
138 #define PTR union _ptr
139 PTR
140 {
141    char * cp;                                           // Char
142    WORD * wp;                                           // WORD
143    LONG * lp;                                           // LONG
144    LONG lw;                                                     // LONG
145    SYM ** sy;                                           // SYM
146    TOKEN * tk;                                          // TOKEN
147 };
148
149 // Symbol spaces
150 #define LABEL        0                          // User-defined symbol
151 #define MACRO        1                          // Macro definition
152 #define MACARG       2                          // Macro argument
153 #define SY_UNDEF     -1                         // Undefined (lookup never matches it)
154
155 // Symbol and expression attributes
156 #define DEFINED      0x8000                     // Symbol has been defined
157 #define GLOBAL       0x4000                     // Symbol has been .GLOBL'd
158 #define COMMON       0x2000                     // Symbol has been .COMM'd
159 #define REFERENCED   0x1000                     // Symbol has been referenced
160 #define EQUATED      0x0800                     // Symbol was equated
161 #define SDECLLIST    0x0400                     // Symbol is on 'sdecl'-order list
162
163 // Expression spaces, ORed with symbol and expression attributes above
164 #define ABS          0x0000                     // In absolute space
165 #define TEXT         0x0001                     // Relative to text
166 #define DATA         0x0002                     // Relative to data
167 #define BSS          0x0004                     // Relative to BSS
168 //#define M6502        0x0008           // 6502/microprocessor (absolute)
169 #define TDB          (TEXT|DATA|BSS)    // Mask for text+data+bss
170
171 // Sizes 
172 #define SIZB         0x0001                     // .b 
173 #define SIZW         0x0002                     // .w 
174 #define SIZL         0x0004                     // .l 
175 #define SIZN         0x0008                     // no .(size) specifier
176
177 // RISC register bank definitions (used in extended symbol attributes also)
178 #define BANK_N       0x0000                     // No register bank specified
179 #define BANK_0       0x0001                     // Register bank zero specified
180 #define BANK_1       0x0002                     // Register bank one specified
181 #define EQUATEDREG   0x0008                     // Equated register symbol
182 #define UNDEF_EQUR   0x0010
183 #define EQUATEDCC    0x0020
184 #define UNDEF_CC     0x0040
185
186 //#define RISCSYM      0x00010000
187
188 // Optimisation defines
189 enum
190 {
191         OPT_ABS_SHORT       = 0,
192         OPT_MOVEL_MOVEQ     = 1,
193         OPT_BSR_BCC_S       = 2,
194         OPT_INDIRECT_DISP   = 3,
195         OPT_COUNT   // Dummy, used to count number of optimisation switches
196 };
197
198 // Globals, externals, etc.
199 extern int verb_flag;
200 extern int debug;
201 extern int rgpu, rdsp;
202 extern int err_flag;
203 extern int err_fd;
204 extern int regbank;
205 extern char * firstfname;
206 extern int list_fd;
207 extern int as68_flag;
208 extern int list_flag;
209 extern int glob_flag;
210 extern int lsym_flag;
211 extern int sbra_flag;
212 extern int obj_format;
213 extern int legacy_flag;
214 extern LONG PRGFLAGS;
215 extern int optim_flags[OPT_COUNT];
216
217 // Exported functions
218 char * fext(char *, char *, int);
219 int nthpath(char *, int, char *);
220 int ParseOptimization(char * optstring);
221
222 #endif // __RMAC_H__
223