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