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
13 // TARGET SPECIFIC BUILD SETTINGS
17 #define PLATFORM "Win32" // Release platform - windows
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
23 #pragma warning(disable:4996)
32 #include <sys/types.h>
36 #define PLATFORM "OSX/Linux" // Release platform - mac OS-X or linux
37 #define _OPEN_FLAGS O_TRUNC|O_CREAT|O_RDWR
38 #define _OPEN_INC O_RDONLY
39 #define _PERM_MODE S_IREAD|S_IWRITE
40 #include <sys/fcntl.h>
45 #include <sys/types.h>
49 #define PLATFORM "Unknown" // Release platform - not specified
50 #define _OPEN_FLAGS O_TRUNC|O_CREAT|O_RDWR
51 #define _OPEN_INC O_RDONLY
52 #define _PERM_MODE S_IREAD|S_IWRITE
53 #include <sys/fcntl.h>
58 #include <sys/types.h>
70 #define ERROR (-1) // Generic error return
71 #define EOS '\0' // End of string
72 #define SPACE ' ' // Ascii space
74 #define SLASHSTRING "/"
75 #define VALUE LONG // Assembler value
76 #define TOKEN LONG // Assembler token
77 #define FNSIZ 128 // Maximum size of a filename
78 #define OK 0 // OK return
79 #define DEBUG if(debug) // Debug conditional
80 #define MAXARGV 100 // Maximum number of commandline args
81 #define STDOUT 1 // Standard output
82 #define ERROUT 2 // Error output
85 // (Normally) non-printable tokens
86 #define COLON ':' // : (grumble: GNUmacs hates ':')
87 #define CONST 'a' // CONST <value>
88 #define ACONST 'A' // ACONST <value> <attrib>
89 #define STRING 'b' // STRING <address>
90 #define SYMBOL 'c' // SYMBOL <address>
91 #define EOL 'e' // End of line
92 #define TKEOF 'f' // End of file (or macro)
93 #define DEQUALS 'g' // ==
94 #define SET 149 // set
95 #define REG 'R' // reg
96 #define EQUREG 148 // equreg
97 #define CCDEF 183 // ccdef
98 #define DCOLON 'h' // ::
101 #define NE 'k' // <> or !=
102 #define SHR 'l' // >>
103 #define SHL 'm' // <<
104 #define UNMINUS 'n' // Unary '-'
105 #define DOTB 'B' // .b or .B or .s or .S
106 #define DOTW 'W' // .w or .W
107 #define DOTL 'L' // .l or .L
108 #define DOTI 'I' // .i or .I
109 #define ENDEXPR 'E' // End of expression
111 // Object code formats
112 #define ALCYON 0 // Alcyon/DRI C object format
113 #define MWC 1 // Mark Williams object format
114 #define BSD 2 // BSD object format
117 #define SYM struct _sym
120 SYM * snext; // * -> Next symbol on hash-chain
121 SYM * sorder; // * -> Next sym in order of refrence
122 SYM * sdecl; // * -> Next sym in order of declaration
123 BYTE stype; // Symbol type
124 WORD sattr; // Attribute bits
125 LONG sattre; // Extended attribute bits
126 WORD senv; // Enviroment number
127 LONG svalue; // Symbol value
128 char * sname; // * -> Symbol's print-name
131 // Pointer type that can point to (almost) anything
132 #define PTR union _ptr
144 #define LABEL 0 // User-defined symbol
145 #define MACRO 1 // Macro definition
146 #define MACARG 2 // Macro argument
147 #define SY_UNDEF -1 // Undefined (lookup never matches it)
149 // Symbol and expression attributes
150 #define DEFINED 0x8000 // Symbol has been defined
151 #define GLOBAL 0x4000 // Symbol has been .GLOBL'd
152 #define COMMON 0x2000 // Symbol has been .COMM'd
153 #define REFERENCED 0x1000 // Symbol has been referenced
154 #define EQUATED 0x0800 // Symbol was equated
155 #define SDECLLIST 0x0400 // Symbol is on 'sdecl'-order list
157 // Expression spaces, ORed with symbol and expression attributes above
158 #define ABS 0x0000 // In absolute space
159 #define TEXT 0x0001 // Relative to text
160 #define DATA 0x0002 // Relative to data
161 #define BSS 0x0004 // Relative to BSS
162 //#define M6502 0x0008 // 6502/microprocessor (absolute)
163 #define TDB (TEXT|DATA|BSS) // Mask for text+data+bss
166 #define SIZB 0x0001 // .b
167 #define SIZW 0x0002 // .w
168 #define SIZL 0x0004 // .l
169 #define SIZN 0x0008 // no .(size) specifier
171 // RISC register bank definitions (used in extended symbol attributes also)
172 #define BANK_N 0x0000 // No register bank specified
173 #define BANK_0 0x0001 // Register bank zero specified
174 #define BANK_1 0x0002 // Register bank one specified
175 #define EQUATEDREG 0x0008 // Equated register symbol
176 #define UNDEF_EQUR 0x0010
177 #define EQUATEDCC 0x0020
178 #define UNDEF_CC 0x0040
180 #define RISCSYM 0x00010000
182 // Globals, externals etc
183 extern int verb_flag;
185 extern int rgpu, rdsp;
189 extern char * firstfname;
191 extern int as68_flag;
192 extern int list_flag;
193 extern int glob_flag;
194 extern int lsym_flag;
195 extern int sbra_flag;
196 extern int obj_format;
202 SYM * lookup(char *, int, int);
203 SYM * newsym(char *, int, int);
204 char * fext(char *, char *, int);
205 void cantcreat(char *);
206 int kmatch(char *, int *, int *, int *, int *);
208 int nthpath(char *, int, char *);
209 void clear(char *, LONG);
210 char * copy(char *, char *, LONG);
211 int rmac_qsort(char *, int, int, int (*)());