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