]> git.sur5r.net Git - cc65/blob - src/ca65/macpack.c
Added text tables
[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     Ullrich von Bassewitz                                        */
10 /*              Wacholderweg 14                                              */
11 /*              D-70597 Stuttgart                                            */
12 /* EMail:       uz@musoftware.de                                             */
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 static const char MacGeneric [] =       /* Generic macros */
54     ".macro  add     Arg1, Arg2\n"
55     "        clc\n"
56     "        .if .paramcount = 2\n"
57     "        adc     Arg1, Arg2\n"
58     "        .else\n"
59     "        adc     Arg1\n"
60     "        .endif\n"
61     ".endmacro\n"
62     ".macro  sub     Arg1, Arg2\n"
63     "        sec\n"
64     "        .if .paramcount = 2\n"
65     "        sbc     Arg1, Arg2\n"
66     "        .else\n"
67     "        sbc     Arg1\n"
68     "        .endif\n"
69     ".endmacro\n";
70
71
72
73 static const char MacLongBranch [] =    /* Long branch macros */
74     ".macro  jeq     Target\n"
75     "        .if     .def(Target) .and ((*+2)-(Target) <= 127)\n"
76     "        beq     Target\n"
77     "        .else\n"
78     "        bne     *+5\n"
79     "        jmp     Target\n"
80     "        .endif\n"
81     ".endmacro\n"
82     ".macro  jne     Target\n"
83     "        .if     .def(Target) .and ((*+2)-(Target) <= 127)\n"
84     "        bne     Target\n"
85     "        .else\n"
86     "        beq     *+5\n"
87     "        jmp     Target\n"
88     "        .endif\n"
89     ".endmacro\n"
90     ".macro  jmi     Target\n"
91     "        .if     .def(Target) .and ((*+2)-(Target) <= 127)\n"
92     "        bmi     Target\n"
93     "        .else\n"
94     "        bpl     *+5\n"
95     "        jmp     Target\n"
96     "        .endif\n"
97     ".endmacro\n"
98     ".macro  jpl     Target\n"
99     "        .if     .def(Target) .and ((*+2)-(Target) <= 127)\n"
100     "        bpl     Target\n"
101     "        .else\n"
102     "        bmi     *+5\n"
103     "        jmp     Target\n"
104     "        .endif\n"
105     ".endmacro\n"
106     ".macro  jcs     Target\n"
107     "        .if     .def(Target) .and ((*+2)-(Target) <= 127)\n"
108     "        bcs     Target\n"
109     "        .else\n"
110     "        bcc     *+5\n"
111     "        jmp     Target\n"
112     "        .endif\n"
113     ".endmacro\n"
114     ".macro  jcc     Target\n"
115     "        .if     .def(Target) .and ((*+2)-(Target) <= 127)\n"
116     "        bcc     Target\n"
117     "        .else\n"
118     "        bcs     *+5\n"
119     "        jmp     Target\n"
120     "        .endif\n"
121     ".endmacro\n"
122     ".macro  jvs     Target\n"
123     "        .if     .def(Target) .and ((*+2)-(Target) <= 127)\n"
124     "        bvs     Target\n"
125     "        .else\n"
126     "        bvc     *+5\n"
127     "        jmp     Target\n"
128     "        .endif\n"
129     ".endmacro\n"
130     ".macro  jvc     Target\n"
131     "        .if     .def(Target) .and ((*+2)-(Target) <= 127)\n"
132     "        bvc     Target\n"
133     "        .else\n"
134     "        bvs     *+5\n"
135     "        jmp     Target\n"
136     "        .endif\n"
137     ".endmacro\n";
138
139
140
141 /* Table with pointers to the different packages */
142 static const char* MacPackages [] = {
143     MacGeneric,
144     MacLongBranch,
145 };
146
147
148
149 /*****************************************************************************/
150 /*                                   Code                                    */
151 /*****************************************************************************/
152
153
154
155 void InsertMacPack (unsigned Id)
156 /* Insert the macro package with the given id in the input stream */
157 {
158     /* Check the parameter */
159     CHECK (Id < sizeof (MacPackages) / sizeof (MacPackages [0]));
160
161     /* Insert the package */
162     NewInputData (MacPackages [Id], 0);
163 }
164
165
166