1 /*****************************************************************************/
5 /* Configuration file parsing for the sim65 6502 simulator */
9 /* (C) 1998-2002 Ullrich von Bassewitz */
11 /* D-70597 Stuttgart */
12 /* EMail: uz@musoftware.de */
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. */
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: */
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 */
32 /*****************************************************************************/
56 /*****************************************************************************/
58 /*****************************************************************************/
62 static void FlagAttr (unsigned* Flags, unsigned Mask, const char* Name)
63 /* Check if the item is already defined. Print an error if so. If not, set
64 * the marker that we have a definition now.
68 CfgError ("%s is already defined", Name);
75 static void AttrCheck (unsigned Attr, unsigned Mask, const char* Name)
76 /* Check that a mandatory attribute was given */
78 if ((Attr & Mask) == 0) {
79 CfgError ("%s attribute is missing", Name);
85 static void ParseChips (void)
86 /* Parse a CHIPS section */
88 static const IdentTok Attributes [] = {
89 { "ADDR", CFGTOK_ADDR },
90 { "RANGE", CFGTOK_RANGE },
93 /* Bits and stuff to remember which attributes we have read */
100 /* Attribute values. Initialize to make gcc happy. */
105 while (CfgTok == CFGTOK_IDENT) {
107 /* Search the chip with the given name */
108 C = FindChip (CfgSVal);
110 CfgError ("No such chip: `%s'", CfgSVal);
113 /* Skip the name plus the following colon */
117 /* Read the attributes */
119 while (CfgTok == CFGTOK_IDENT) {
121 /* Map the identifier to a token */
123 CfgSpecialToken (Attributes, ENTRY_COUNT (Attributes), "Attribute");
126 /* An optional assignment follows */
128 CfgOptionalAssign ();
130 /* Check which attribute was given */
135 CfgRangeCheck (0, 0xFFFF);
136 FlagAttr (&Attr, CA_ADDR, "ADDR");
137 Addr = (unsigned) CfgIVal;
142 CfgRangeCheck (0, 0xFFFF);
143 FlagAttr (&Attr, CA_RANGE, "RANGE");
144 Range = (unsigned) CfgIVal;
148 FAIL ("Unexpected attribute token");
152 /* Skip the attribute value and an optional comma */
157 /* Skip the semicolon */
160 /* Check for mandatory parameters */
161 AttrCheck (Attr, CA_ADDR, "ADDR");
162 AttrCheck (Attr, CA_RANGE, "RANGE");
164 /* Address + Range may not exceed 16 bits */
165 if (((unsigned long) Range) > 0x10000UL - Addr) {
166 CfgError ("Range error");
169 /* Create the chip ## */
176 static void ParseConfig (void)
177 /* Parse the config file */
179 static const IdentTok BlockNames [] = {
180 { "CHIPS", CFGTOK_CHIPS },
186 /* Read the block ident */
187 CfgSpecialToken (BlockNames, ENTRY_COUNT (BlockNames), "Block identifier");
191 /* Expected a curly brace */
192 CfgConsume (CFGTOK_LCURLY, "`{' expected");
202 FAIL ("Unexpected block token");
206 /* Skip closing brace */
207 CfgConsume (CFGTOK_RCURLY, "`}' expected");
209 } while (CfgTok != CFGTOK_EOF);
215 /* Read the configuration */
217 /* If we have a config name given, open the file, otherwise we will read
225 /* Close the input file */