From df5132d31c0e3b3cf49460d230870863c10d39d9 Mon Sep 17 00:00:00 2001 From: cuz Date: Tue, 3 Dec 2002 22:32:38 +0000 Subject: [PATCH] New feature: startaddress git-svn-id: svn://svn.cc65.org/cc65/trunk@1713 b7a2c559-68d2-44c3-8de9-860c34a00d81 --- src/ld65/config.c | 110 ++++++++++++++++++++++++++++++++++++++------- src/ld65/global.c | 5 ++- src/ld65/global.h | 4 +- src/ld65/main.c | 1 + src/ld65/scanner.h | 6 ++- 5 files changed, 107 insertions(+), 19 deletions(-) diff --git a/src/ld65/config.c b/src/ld65/config.c index 6e310a8d5..c06824ecb 100644 --- a/src/ld65/config.c +++ b/src/ld65/config.c @@ -1152,37 +1152,115 @@ static void ParseConDes (void) +static void ParseStartAddress (void) +/* Parse the STARTADDRESS feature */ +{ + static const IdentTok Attributes [] = { + { "DEFAULT", CFGTOK_DEFAULT }, + }; + + + /* Attribute values. */ + unsigned long DefStartAddr = 0; + + /* Bitmask to remember the attributes we got already */ + enum { + atNone = 0x0000, + atDefault = 0x0001 + }; + unsigned AttrFlags = atNone; + + /* Parse the attributes */ + while (1) { + + /* Map the identifier to a token */ + cfgtok_t AttrTok; + CfgSpecialToken (Attributes, ENTRY_COUNT (Attributes), "Attribute"); + AttrTok = CfgTok; + + /* An optional assignment follows */ + CfgNextTok (); + CfgOptionalAssign (); + + /* Check which attribute was given */ + switch (AttrTok) { + + case CFGTOK_DEFAULT: + /* Don't allow this twice */ + FlagAttr (&AttrFlags, atDefault, "DEFAULT"); + /* We expect a number */ + CfgAssureInt (); + CfgRangeCheck (0, 0xFFFFFF); + /* Remember the value for later */ + DefStartAddr = CfgIVal; + break; + + default: + FAIL ("Unexpected attribute token"); + + } + + /* Skip the attribute value */ + CfgNextTok (); + + /* Semicolon ends the ConDes decl, otherwise accept an optional comma */ + if (CfgTok == CFGTOK_SEMI) { + break; + } else if (CfgTok == CFGTOK_COMMA) { + CfgNextTok (); + } + } + + /* Check if we have all mandatory attributes */ + AttrCheck (AttrFlags, atDefault, "DEFAULT"); + + /* If no start address was given on the command line, use the one given + * here + */ + if (!HaveStartAddr) { + StartAddr = DefStartAddr; + } +} + + + static void ParseFeatures (void) /* Parse a features section */ { static const IdentTok Features [] = { - { "CONDES", CFGTOK_CONDES }, + { "CONDES", CFGTOK_CONDES }, + { "STARTADDRESS", CFGTOK_STARTADDRESS }, }; while (CfgTok == CFGTOK_IDENT) { - /* Map the identifier to a token */ - cfgtok_t FeatureTok; + /* Map the identifier to a token */ + cfgtok_t FeatureTok; CfgSpecialToken (Features, ENTRY_COUNT (Features), "Feature"); FeatureTok = CfgTok; - /* Skip the name and the following colon */ - CfgNextTok (); - CfgConsumeColon (); + /* Skip the name and the following colon */ + CfgNextTok (); + CfgConsumeColon (); - /* Parse the format options */ - switch (FeatureTok) { + /* Parse the format options */ + switch (FeatureTok) { - case CFGTOK_CONDES: - ParseConDes (); - break; + case CFGTOK_CONDES: + ParseConDes (); + break; - default: - Error ("Unexpected feature token"); - } + case CFGTOK_STARTADDRESS: + ParseStartAddress (); + break; - /* Skip the semicolon */ - CfgConsumeSemi (); + + default: + Error ("Unexpected feature token"); + } + + /* Skip the semicolon */ + CfgConsumeSemi (); } } diff --git a/src/ld65/global.c b/src/ld65/global.c index a12167306..6ac6f9cce 100644 --- a/src/ld65/global.c +++ b/src/ld65/global.c @@ -46,7 +46,10 @@ const char* OutputName = "a.out"; /* Name of output file */ unsigned ModuleId = 0; /* Id for o65 module */ -unsigned long StartAddr = 0x200; /* Start address */ + +/* Start address */ +unsigned char HaveStartAddr = 0; /* Start address not given */ +unsigned long StartAddr = 0x200; /* Start address */ unsigned char VerboseMap = 0; /* Verbose map file */ const char* MapFileName = 0; /* Name of the map file */ diff --git a/src/ld65/global.h b/src/ld65/global.h index d68b69029..a56daf19f 100644 --- a/src/ld65/global.h +++ b/src/ld65/global.h @@ -45,8 +45,10 @@ extern const char* OutputName; /* Name of output file */ - + extern unsigned ModuleId; /* Id for o65 module */ + +extern unsigned char HaveStartAddr; /* True if start address was given */ extern unsigned long StartAddr; /* Start address */ extern unsigned char VerboseMap; /* Verbose map file */ diff --git a/src/ld65/main.c b/src/ld65/main.c index 450088971..528c7c095 100644 --- a/src/ld65/main.c +++ b/src/ld65/main.c @@ -270,6 +270,7 @@ static void OptStartAddr (const char* Opt, const char* Arg) /* Set the default start address */ { StartAddr = CvtNumber (Opt, Arg); + HaveStartAddr = 1; } diff --git a/src/ld65/scanner.h b/src/ld65/scanner.h index 744abdb9a..d2af2af42 100644 --- a/src/ld65/scanner.h +++ b/src/ld65/scanner.h @@ -106,6 +106,8 @@ typedef enum { CFGTOK_CC65, CFGTOK_CONDES, + CFGTOK_STARTADDRESS, + CFGTOK_SEGMENT, CFGTOK_LABEL, CFGTOK_COUNT, @@ -115,7 +117,9 @@ typedef enum { CFGTOK_DESTRUCTOR, CFGTOK_DECREASING, - CFGTOK_INCREASING + CFGTOK_INCREASING, + + CFGTOK_DEFAULT } cfgtok_t; -- 2.39.5