]> git.sur5r.net Git - cc65/blob - src/ca65/macpack.c
Revised symbol scoping
[cc65] / src / ca65 / macpack.c
1 /*****************************************************************************/
2 /*                                                                           */
3 /*                                 macpack.c                                 */
4 /*                                                                           */
5 /*           Predefined macro packages for the ca65 macroassembler           */
6 /*                                                                           */
7 /*                                                                           */
8 /*                                                                           */
9 /* (C) 1998-2003 Ullrich von Bassewitz                                       */
10 /*               Römerstrasse 52                                             */
11 /*               D-70794 Filderstadt                                         */
12 /* EMail:        uz@cc65.org                                                 */
13 /*                                                                           */
14 /*                                                                           */
15 /* This software is provided 'as-is', without any expressed or implied       */
16 /* warranty.  In no event will the authors be held liable for any damages    */
17 /* arising from the use of this software.                                    */
18 /*                                                                           */
19 /* Permission is granted to anyone to use this software for any purpose,     */
20 /* including commercial applications, and to alter it and redistribute it    */
21 /* freely, subject to the following restrictions:                            */
22 /*                                                                           */
23 /* 1. The origin of this software must not be misrepresented; you must not   */
24 /*    claim that you wrote the original software. If you use this software   */
25 /*    in a product, an acknowledgment in the product documentation would be  */
26 /*    appreciated but is not required.                                       */
27 /* 2. Altered source versions must be plainly marked as such, and must not   */
28 /*    be misrepresented as being the original software.                      */
29 /* 3. This notice may not be removed or altered from any source              */
30 /*    distribution.                                                          */
31 /*                                                                           */
32 /*****************************************************************************/
33
34
35
36 /* common */
37 #include "check.h"
38
39 /* ca65 */
40 #include "error.h"
41 #include "scanner.h"
42 #include "macpack.h"
43
44
45
46 /*****************************************************************************/
47 /*                                   Data                                    */
48 /*****************************************************************************/
49
50
51
52 /* Predefined packages */
53
54 /* Generic macros */
55 static char MacGeneric[] =
56     ".macro  add     Arg1, Arg2\n"
57     "        clc\n"
58     "        .if .paramcount = 2\n"
59     "        adc     Arg1, Arg2\n"
60     "        .else\n"
61     "        adc     Arg1\n"
62     "        .endif\n"
63     ".endmacro\n"
64     ".macro  sub     Arg1, Arg2\n"
65     "        sec\n"
66     "        .if .paramcount = 2\n"
67     "        sbc     Arg1, Arg2\n"
68     "        .else\n"
69     "        sbc     Arg1\n"
70     "        .endif\n"
71     ".endmacro\n";
72
73 /* Long branch macros */
74 static char MacLongBranch[] =
75     ".macro  jeq     Target\n"
76     "        .if     .match(Target, 0)\n"
77     "        bne     *+5\n"
78     "        jmp     Target\n"
79     "        .elseif .def(Target) .and ((*+2)-(Target) <= 127)\n"
80     "        beq     Target\n"
81     "        .else\n"
82     "        bne     *+5\n"
83     "        jmp     Target\n"
84     "        .endif\n"
85     ".endmacro\n"
86     ".macro  jne     Target\n"
87     "        .if     .match(Target, 0)\n"
88     "        beq     *+5\n"
89     "        jmp     Target\n"
90     "        .elseif .def(Target) .and ((*+2)-(Target) <= 127)\n"
91     "        bne     Target\n"
92     "        .else\n"
93     "        beq     *+5\n"
94     "        jmp     Target\n"
95     "        .endif\n"
96     ".endmacro\n"
97     ".macro  jmi     Target\n"
98     "        .if     .match(Target, 0)\n"
99     "        bpl     *+5\n"
100     "        jmp     Target\n"
101     "        .elseif .def(Target) .and ((*+2)-(Target) <= 127)\n"
102     "        bmi     Target\n"
103     "        .else\n"
104     "        bpl     *+5\n"
105     "        jmp     Target\n"
106     "        .endif\n"
107     ".endmacro\n"
108     ".macro  jpl     Target\n"
109     "        .if     .match(Target, 0)\n"
110     "        bmi     *+5\n"
111     "        jmp     Target\n"
112     "        .elseif .def(Target) .and ((*+2)-(Target) <= 127)\n"
113     "        bpl     Target\n"
114     "        .else\n"
115     "        bmi     *+5\n"
116     "        jmp     Target\n"
117     "        .endif\n"
118     ".endmacro\n"
119     ".macro  jcs     Target\n"
120     "        .if     .match(Target, 0)\n"
121     "        bcc     *+5\n"
122     "        jmp     Target\n"
123     "        .elseif .def(Target) .and ((*+2)-(Target) <= 127)\n"
124     "        bcs     Target\n"
125     "        .else\n"
126     "        bcc     *+5\n"
127     "        jmp     Target\n"
128     "        .endif\n"
129     ".endmacro\n"
130     ".macro  jcc     Target\n"
131     "        .if     .match(Target, 0)\n"
132     "        bcs     *+5\n"
133     "        jmp     Target\n"
134     "        .elseif .def(Target) .and ((*+2)-(Target) <= 127)\n"
135     "        bcc     Target\n"
136     "        .else\n"
137     "        bcs     *+5\n"
138     "        jmp     Target\n"
139     "        .endif\n"
140     ".endmacro\n"
141     ".macro  jvs     Target\n"
142     "        .if     .match(Target, 0)\n"
143     "        bvc     *+5\n"
144     "        jmp     Target\n"
145     "        .elseif .def(Target) .and ((*+2)-(Target) <= 127)\n"
146     "        bvs     Target\n"
147     "        .else\n"
148     "        bvc     *+5\n"
149     "        jmp     Target\n"
150     "        .endif\n"
151     ".endmacro\n"
152     ".macro  jvc     Target\n"
153     "        .if     .match(Target, 0)\n"
154     "        bvs     *+5\n"
155     "        jmp     Target\n"
156     "        .elseif .def(Target) .and ((*+2)-(Target) <= 127)\n"
157     "        bvc     Target\n"
158     "        .else\n"
159     "        bvs     *+5\n"
160     "        jmp     Target\n"
161     "        .endif\n"
162     ".endmacro\n";
163
164 /* Commodore specific macros */
165 static char MacCBM[] =
166     ".macro scrcode str\n"
167     "        .repeat .strlen(str), i\n"
168     "                .if (.strat(str, i) >= '@' .and .strat(str, i) <= 'z')\n"
169     "                        .byte .strat(str, i) - '@'\n"
170     "                .elseif (.strat(str, i) >= 'A' .and .strat(str, i) <= 'Z')\n"
171     "                        .byte .strat(str, i) - 'A' + 65\n"
172     "                .elseif (.strat(str, i) = '[')\n"
173     "                        .byte 27\n"
174     "                .elseif (.strat(str, i) = ']')\n"
175     "                        .byte 29\n"
176     "                .elseif (.strat(str, i) = '^')\n"
177     "                        .byte 30\n"
178     "                .elseif (.strat(str, i) = '_')\n"
179     "                        .byte 31\n"
180     "                .else\n"
181     "                        .byte .strat(str, i)\n"
182     "                .endif\n"
183     "        .endrepeat\n"
184     ".endmacro\n";
185
186 /* CPU defines */
187 static char MacCPU[] =
188     "CPU_ISET_6502      = $01\n"
189     "CPU_ISET_65SC02    = $02\n"
190     "CPU_ISET_65C02     = $04\n"
191     "CPU_ISET_65816     = $08\n"
192     "CPU_ISET_SUNPLUS   = $10\n"
193     "CPU_6502           = $01\n"
194     "CPU_65SC02         = $03\n"
195     "CPU_65C02          = $07\n"
196     "CPU_65816          = $0F\n"
197     "CPU_SUNPLUS        = $10\n";
198
199
200
201 /* Table with pointers to the different packages */
202 static char* MacPackages [] = {
203     MacGeneric,
204     MacLongBranch,
205     MacCBM,
206     MacCPU
207 };
208
209
210
211 /*****************************************************************************/
212 /*                                   Code                                    */
213 /*****************************************************************************/
214
215
216
217 void InsertMacPack (unsigned Id)
218 /* Insert the macro package with the given id in the input stream */
219 {
220     /* Check the parameter */
221     CHECK (Id < sizeof (MacPackages) / sizeof (MacPackages [0]));
222
223     /* Insert the package */
224     NewInputData (MacPackages [Id], 0);
225 }
226
227
228