Added INPUTOFFS and INPUTSIZE

git-svn-id: svn://svn.cc65.org/cc65/trunk@2411 b7a2c559-68d2-44c3-8de9-860c34a00d81
This commit is contained in:
cuz
2003-08-23 16:03:58 +00:00
parent e3d3a43c3c
commit fd2fa25f28
7 changed files with 81 additions and 20 deletions

View File

@@ -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",

View File

@@ -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 */

View File

@@ -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

View File

@@ -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 },

View File

@@ -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) {

View File

@@ -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,