Various cleanups to fix compiler warnings.
[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
16 #ifdef WIN32
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 
21 #ifdef _MSC_VER
22    #if _MSC_VER > 1000
23       #pragma warning(disable:4996)
24    #endif
25 #endif
26 #include <io.h>
27 #include <fcntl.h>
28 #include <stdio.h>
29 #include <stdlib.h>
30 #include <string.h>
31 #include <ctype.h>
32 #include <sys/types.h>
33 #include <sys/stat.h>
34 #else 
35 #ifdef __GCCUNIX__
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>
41 #include <stdio.h>
42 #include <stdlib.h>
43 #include <string.h>
44 #include <ctype.h>
45 #include <sys/types.h>
46 #include <sys/stat.h>
47 #include <unistd.h>
48 #else
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>
54 #include <stdio.h>
55 #include <stdlib.h>
56 #include <string.h>
57 #include <ctype.h>
58 #include <sys/types.h>
59 #include <sys/stat.h>
60 #endif
61 #endif
62
63
64
65 #define BYTE         unsigned char
66 #define WORD         unsigned short
67 #define LONG         unsigned long
68 #define VOID         void
69
70 #define ERROR        (-1)                                   // Generic error return
71 #define EOS          '\0'                                   // End of string
72 #define SPACE        ' '                                    // Ascii space 
73 #define SLASHCHAR    '/'
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
83 #define CREATMASK    0
84
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'                                    // ::
99 #define GE           'i'                                    // >=
100 #define LE           'j'                                    // <=
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
110
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
115
116 // Symbols
117 #define  SYM         struct _sym
118 SYM
119 {
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
129 };
130
131 // Pointer type that can point to (almost) anything
132 #define PTR union _ptr
133 PTR
134 {
135    char * cp;                                               // Char
136    WORD * wp;                                               // WORD
137    LONG * lp;                                               // LONG
138    LONG lw;                                                 // LONG
139    SYM ** sy;                                               // SYM
140    TOKEN * tk;                                              // TOKEN
141 };
142
143 // Symbol spaces
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)
148
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
156
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
164
165 // Sizes 
166 #define SIZB         0x0001                                 // .b 
167 #define SIZW         0x0002                                 // .w 
168 #define SIZL         0x0004                                 // .l 
169 #define SIZN         0x0008                                 // no .(size) specifier
170
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
179
180 #define RISCSYM      0x00010000
181
182 // Globals, externals etc
183 extern int verb_flag;
184 extern int debug;
185 extern int rgpu, rdsp;
186 extern int err_flag;
187 extern int err_fd;
188 extern int regbank;
189 extern char * firstfname;
190 extern int list_fd;
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;
197 extern LONG amemtot;
198 extern int in_main;
199
200 // Prototypes
201 void init_sym(void);
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 *);
207 void autoeven(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 (*)());
212 char * amem(LONG);
213
214 #endif // __RMAC_H__