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