From fd2fa25f28b069460dbc250b2089b5defd3199ca Mon Sep 17 00:00:00 2001 From: cuz Date: Sat, 23 Aug 2003 16:03:58 +0000 Subject: [PATCH] Added INPUTOFFS and INPUTSIZE git-svn-id: svn://svn.cc65.org/cc65/trunk@2411 b7a2c559-68d2-44c3-8de9-860c34a00d81 --- doc/da65.sgml | 16 +++++++++++++++- src/da65/code.c | 39 ++++++++++++++++++++++++++++++++------- src/da65/global.c | 12 +++++++----- src/da65/global.h | 9 +++++---- src/da65/infofile.c | 19 ++++++++++++++++++- src/da65/main.c | 2 +- src/da65/scanner.h | 4 +++- 7 files changed, 81 insertions(+), 20 deletions(-) diff --git a/doc/da65.sgml b/doc/da65.sgml index cd9b6315b..9513ab9f3 100644 --- a/doc/da65.sgml +++ b/doc/da65.sgml @@ -79,7 +79,7 @@ Here is a description of all the command line options: --comments n Set the comment level for the output. Valid arguments are 0..4. Greater - values will increase the level of additional information written to the + values will increase the level of additional information written to the output file in form of comments. @@ -261,6 +261,20 @@ following attributes are recognized: input file name on the command line. + INPUTOFFS + + The attribute is followed by a numerical value that gives an offset into + the input file which is skipped before reading data. The attribute may be + used to skip headers or unwanted code sections in the input file. + + + INPUTSIZE + + INPUTSIZE is followed by a numerical value that gives the amount of data + to read from the input file. Data beyond OUTPUTNAME The attribute is followed by string value, which gives the name of the diff --git a/src/da65/code.c b/src/da65/code.c index cef4ef2dd..ceb303fd5 100644 --- a/src/da65/code.c +++ b/src/da65/code.c @@ -86,18 +86,43 @@ void LoadCode (void) Error ("Cannot seek on file `%s': %s", InFile, strerror (errno)); } Size = ftell (F); - rewind (F); + + /* The input offset must be smaller than the size */ + if (InputOffs >= 0) { + if (InputOffs >= Size) { + Error ("Input offset is greater than file size"); + } + } else { + /* Use a zero offset */ + InputOffs = 0; + } + + /* Seek to the input offset and correct size to contain the remainder of + * the file. + */ + if (fseek (F, InputOffs, SEEK_SET) != 0) { + Error ("Cannot seek on file `%s': %s", InFile, strerror (errno)); + } + Size -= InputOffs; + + /* Limit the size to the maximum input size if one is given */ + if (InputSize >= 0) { + if (InputSize > Size) { + Error ("Input size is greater than what is available"); + } + Size = InputSize; + } /* If the start address was not given, set it so that the code loads to * 0x10000 - Size. This is a reasonable default assuming that the file * is a ROM that contains the hardware vectors at $FFFA. */ if (StartAddr < 0) { - if (Size > 0x10000) { - StartAddr = 0; - } else { - StartAddr = 0x10000 - Size; - } + if (Size > 0x10000) { + StartAddr = 0; + } else { + StartAddr = 0x10000 - Size; + } } /* Calculate the maximum code size */ @@ -105,7 +130,7 @@ void LoadCode (void) /* Check if the size is larger than what we can read */ if (Size == 0) { - Error ("File `%s' contains no data", InFile); + Error ("Nothing to read from input file `%s'", InFile); } if (Size > MaxCount) { Warning ("File `%s' is too large, ignoring %ld bytes", diff --git a/src/da65/global.c b/src/da65/global.c index 2742cb8dc..7051d68b8 100644 --- a/src/da65/global.c +++ b/src/da65/global.c @@ -53,15 +53,17 @@ const char CfgExt[] = ".cfg"; /* Config file extension */ /* Flags and other command line stuff */ unsigned char DebugInfo = 0; /* Add debug info to the object file */ -unsigned char FormFeeds = 0; /* Add form feeds to the output? */ -unsigned char PassCount = 2; /* How many passed do we do? */ -long StartAddr = -1; /* Start/load address of the program */ +unsigned char FormFeeds = 0; /* Add form feeds to the output? */ +unsigned char PassCount = 2; /* How many passed do we do? */ +long StartAddr = -1L; /* Start/load address of the program */ +long InputOffs = -1L; /* Offset into input file */ +long InputSize = -1L; /* Number of bytes to read from input */ /* Stuff needed by many routines */ -unsigned char Pass = 0; /* Disassembler pass */ +unsigned Pass = 0; /* Disassembler pass */ /* Comments */ -unsigned char Comments = 0; /* Add which comments to the output? */ +unsigned Comments = 0; /* Add which comments to the output? */ /* Page formatting */ unsigned PageLength = 0; /* Length of a listing page */ diff --git a/src/da65/global.h b/src/da65/global.h index 96f11c912..9d46feae4 100644 --- a/src/da65/global.h +++ b/src/da65/global.h @@ -44,7 +44,7 @@ -/* File names */ +/* File stuff */ extern const char* InFile; /* Name of input file */ extern const char* OutFile; /* Name of output file */ @@ -57,15 +57,16 @@ extern unsigned char DebugInfo; /* Add debug info to the object file */ extern unsigned char FormFeeds; /* Add form feeds to the output? */ extern unsigned char PassCount; /* How many passed do we do? */ extern long StartAddr; /* Start/load address of the program */ - +extern long InputOffs; /* Offset into input file */ +extern long InputSize; /* Number of bytes to read from input */ /* Stuff needed by many routines */ -extern unsigned char Pass; /* Disassembler pass */ +extern unsigned Pass; /* Disassembler pass */ /* Comments */ #define MIN_COMMENTS 0 #define MAX_COMMENTS 4 -extern unsigned char Comments; /* Add which comments to the output? */ +extern unsigned Comments; /* Add which comments to the output? */ /* Page formatting */ #define MIN_PAGE_LEN 32 diff --git a/src/da65/infofile.c b/src/da65/infofile.c index 4f32661ba..bf756ac0f 100644 --- a/src/da65/infofile.c +++ b/src/da65/infofile.c @@ -70,6 +70,8 @@ static void GlobalSection (void) { "COMMENTS", INFOTOK_COMMENTS }, { "CPU", INFOTOK_CPU }, { "INPUTNAME", INFOTOK_INPUTNAME }, + { "INPUTOFFS", INFOTOK_INPUTOFFS }, + { "INPUTSIZE", INFOTOK_INPUTSIZE }, { "OUTPUTNAME", INFOTOK_OUTPUTNAME }, { "PAGELENGTH", INFOTOK_PAGELENGTH }, { "STARTADDR", INFOTOK_STARTADDR }, @@ -119,6 +121,21 @@ static void GlobalSection (void) InfoNextTok (); break; + case INFOTOK_INPUTOFFS: + InfoNextTok (); + InfoAssureInt (); + InputOffs = InfoIVal; + InfoNextTok (); + break; + + case INFOTOK_INPUTSIZE: + InfoNextTok (); + InfoAssureInt (); + InfoRangeCheck (1, 0x10000); + InputSize = InfoIVal; + InfoNextTok (); + break; + case INFOTOK_OUTPUTNAME: InfoNextTok (); InfoAssureStr (); @@ -174,7 +191,7 @@ static void RangeSection (void) { "CODE", INFOTOK_CODE }, { "BYTETABLE", INFOTOK_BYTETAB }, { "DBYTETABLE", INFOTOK_DBYTETAB }, - { "WORDTABLE", INFOTOK_WORDTAB }, + { "WORDTABLE", INFOTOK_WORDTAB }, { "DWORDTABLE", INFOTOK_DWORDTAB }, { "ADDRTABLE", INFOTOK_ADDRTAB }, { "RTSTABLE", INFOTOK_RTSTAB }, diff --git a/src/da65/main.c b/src/da65/main.c index 3d3d96d9a..6fcd58218 100644 --- a/src/da65/main.c +++ b/src/da65/main.c @@ -247,7 +247,7 @@ static void OneOpcode (unsigned RemainingBytes) * - ...if we have enough bytes remaining for the code at this address. * - ...if the current instruction is valid for the given CPU. * - ...if there is no label somewhere between the instruction bytes. - * If any of these conditions is true, switch to data mode. + * If any of these conditions is false, switch to data mode. */ if (GetStyleAttr (PC) == atDefault) { if (D->Size > RemainingBytes) { diff --git a/src/da65/scanner.h b/src/da65/scanner.h index a8af803b9..28e24784b 100644 --- a/src/da65/scanner.h +++ b/src/da65/scanner.h @@ -68,6 +68,8 @@ typedef enum token_t { INFOTOK_COMMENTS, INFOTOK_CPU, INFOTOK_INPUTNAME, + INFOTOK_INPUTOFFS, + INFOTOK_INPUTSIZE, INFOTOK_OUTPUTNAME, INFOTOK_PAGELENGTH, INFOTOK_STARTADDR, @@ -78,7 +80,7 @@ typedef enum token_t { INFOTOK_TYPE, INFOTOK_CODE, - INFOTOK_BYTETAB, + INFOTOK_BYTETAB, INFOTOK_DBYTETAB, INFOTOK_WORDTAB, INFOTOK_DWORDTAB,