]> git.sur5r.net Git - cc65/blob - src/ca65/options.c
Added condes tables to c64 config
[cc65] / src / ca65 / options.c
1 /*****************************************************************************/
2 /*                                                                           */
3 /*                                 options.c                                 */
4 /*                                                                           */
5 /*              Object file options for the ca65 macroassembler              */
6 /*                                                                           */
7 /*                                                                           */
8 /*                                                                           */
9 /* (C) 1998-2000 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 #include <string.h>
37
38 /* common */
39 #include "optdefs.h"
40 #include "xmalloc.h"
41
42 /* ca65 */
43 #include "error.h"
44 #include "objfile.h"
45 #include "options.h"
46
47
48
49 /*****************************************************************************/
50 /*                                   Data                                    */
51 /*****************************************************************************/
52
53
54
55 /* Option list */
56 static Option*          OptRoot = 0;
57 static Option*          OptLast = 0;
58 static unsigned         OptCount = 0;
59
60
61
62 /*****************************************************************************/
63 /*                                   Code                                    */
64 /*****************************************************************************/
65
66
67
68 static Option* NewOption (unsigned char Type)
69 /* Create a new option, insert it into the list and return it */
70 {
71     Option* Opt;
72
73     /* Allocate memory */
74     Opt = xmalloc (sizeof (*Opt));
75
76     /* Initialize fields */
77     Opt->Next  = 0;
78     Opt->Type  = Type;
79     Opt->V.Str = 0;
80
81     /* Insert it into the list */
82     if (OptRoot == 0) {
83         OptRoot = Opt;
84     } else {
85         OptLast->Next = Opt;
86     }
87     OptLast = Opt;
88
89     /* One more option now */
90     ++OptCount;
91
92     /* Return the new struct */
93     return Opt;
94 }
95
96
97
98 void OptStr (unsigned char Type, const char* Text)
99 /* Add a string option */
100 {
101     Option* O;
102
103     /* String must have less than 255 bytes */
104     if (strlen (Text) > 255) {
105         Fatal (FAT_STRING_TOO_LONG);
106     }
107     O        = NewOption (Type);
108     O->V.Str = xstrdup (Text);
109 }
110
111
112
113 void OptComment (const char* Comment)
114 /* Add a comment */
115 {
116     OptStr (OPT_COMMENT, Comment);
117 }
118
119
120
121 void OptAuthor (const char* Author)
122 /* Add an author statement */
123 {
124     OptStr (OPT_AUTHOR, Author);
125 }
126
127
128
129 void OptTranslator (const char* Translator)
130 /* Add a translator option */
131 {
132     OptStr (OPT_TRANSLATOR, Translator);
133 }
134
135
136
137 void OptCompiler (const char* Compiler)
138 /* Add a compiler option */
139 {
140     OptStr (OPT_COMPILER, Compiler);
141 }
142
143
144
145 void OptOS (const char* OS)
146 /* Add an operating system option */
147 {
148     OptStr (OPT_OS, OS);
149 }
150
151
152
153 void OptDateTime (unsigned long DateTime)
154 /* Add a date/time option */
155 {
156     Option* O = NewOption (OPT_DATETIME);
157     O->V.Val = DateTime;
158 }
159
160
161
162 void WriteOptions (void)
163 /* Write the options to the object file */
164 {
165     Option* O;
166
167     /* Tell the object file module that we're about to start the options */
168     ObjStartOptions ();
169
170     /* Write the option count */
171     ObjWriteVar (OptCount);
172
173     /* Walk through the list and write the options */
174     O = OptRoot;
175     while (O) {
176
177         /* Write the type of the option */
178         ObjWrite8 (O->Type);
179
180         /* Write the argument */
181         switch (O->Type & OPT_ARGMASK) {
182
183             case OPT_ARGSTR:
184                 ObjWriteStr (O->V.Str);
185                 break;
186
187             case OPT_ARGNUM:
188                 ObjWrite32 (O->V.Val);
189                 break;
190
191             default:
192                 Internal ("Invalid option type: $%02X", O->Type & 0xFF);
193
194         }
195
196         /* Next option */
197         O = O->Next;
198
199     }
200
201     /* Done writing options */
202     ObjEndOptions ();
203 }
204
205
206