1
0
mirror of https://github.com/cc65/cc65.git synced 2024-12-26 08:32:00 +00:00

New default for start address

git-svn-id: svn://svn.cc65.org/cc65/trunk@2366 b7a2c559-68d2-44c3-8de9-860c34a00d81
This commit is contained in:
cuz 2003-08-18 20:36:38 +00:00
parent da8739609d
commit 7faa7ab3b8
5 changed files with 41 additions and 28 deletions

View File

@ -6,10 +6,10 @@
/* */ /* */
/* */ /* */
/* */ /* */
/* (C) 2000 Ullrich von Bassewitz */ /* (C) 2000-2003 Ullrich von Bassewitz */
/* Wacholderweg 14 */ /* Römerstrasse 52 */
/* D-70597 Stuttgart */ /* D-70794 Filderstadt */
/* EMail: uz@musoftware.de */ /* EMail: uz@cc65.org */
/* */ /* */
/* */ /* */
/* This software is provided 'as-is', without any expressed or implied */ /* This software is provided 'as-is', without any expressed or implied */
@ -41,8 +41,9 @@
#include "check.h" #include "check.h"
/* da65 */ /* da65 */
#include "error.h"
#include "code.h" #include "code.h"
#include "error.h"
#include "global.h"
@ -65,53 +66,65 @@ unsigned long PC; /* Current PC */
void LoadCode (const char* Name, unsigned long StartAddress) void LoadCode (void)
/* Load the code from the given file */ /* Load the code from the given file */
{ {
long Count, MaxCount, Size; long Count, MaxCount, Size;
FILE* F; FILE* F;
PRECONDITION (StartAddress < 0x10000); PRECONDITION (StartAddr < 0x10000);
/* Calculate the maximum code size */
MaxCount = 0x10000 - StartAddress;
/* Open the file */ /* Open the file */
F = fopen (Name, "rb"); F = fopen (InFile, "rb");
if (F == 0) { if (F == 0) {
Error ("Cannot open `%s': %s", Name, strerror (errno)); Error ("Cannot open `%s': %s", InFile, strerror (errno));
} }
/* Seek to the end to get the size of the file */ /* Seek to the end to get the size of the file */
if (fseek (F, 0, SEEK_END) != 0) { if (fseek (F, 0, SEEK_END) != 0) {
Error ("Cannot seek on file `%s': %s", Name, strerror (errno)); Error ("Cannot seek on file `%s': %s", InFile, strerror (errno));
} }
Size = ftell (F); Size = ftell (F);
rewind (F); rewind (F);
/* 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;
}
}
/* Calculate the maximum code size */
MaxCount = 0x10000 - StartAddr;
/* Check if the size is larger than what we can read */ /* Check if the size is larger than what we can read */
if (Size == 0) { if (Size == 0) {
Error ("File `%s' contains no data", Name); Error ("File `%s' contains no data", InFile);
} }
if (Size > MaxCount) { if (Size > MaxCount) {
Warning ("File `%s' is too large, ignoring %ld bytes", Warning ("File `%s' is too large, ignoring %ld bytes",
Name, Size - MaxCount); InFile, Size - MaxCount);
} else if (MaxCount > Size) { } else if (MaxCount > Size) {
MaxCount = (unsigned) Size; MaxCount = (unsigned) Size;
} }
/* Read from the file and remember the number of bytes read */ /* Read from the file and remember the number of bytes read */
Count = fread (CodeBuf + StartAddress, 1, MaxCount, F); Count = fread (CodeBuf + StartAddr, 1, MaxCount, F);
if (ferror (F) || Count != MaxCount) { if (ferror (F) || Count != MaxCount) {
Error ("Error reading from `%s': %s", Name, strerror (errno)); Error ("Error reading from `%s': %s", InFile, strerror (errno));
} }
/* Close the file */ /* Close the file */
fclose (F); fclose (F);
/* Set the buffer variables */ /* Set the buffer variables */
CodeStart = PC = StartAddress; CodeStart = PC = StartAddr;
CodeEnd = CodeStart + Count - 1; /* CodeEnd is inclusive */ CodeEnd = CodeStart + Count - 1; /* CodeEnd is inclusive */
} }

View File

@ -6,10 +6,10 @@
/* */ /* */
/* */ /* */
/* */ /* */
/* (C) 2000 Ullrich von Bassewitz */ /* (C) 2000-2003 Ullrich von Bassewitz */
/* Wacholderweg 14 */ /* Römerstrasse 52 */
/* D-70597 Stuttgart */ /* D-70794 Filderstadt */
/* EMail: uz@musoftware.de */ /* EMail: uz@cc65.org */
/* */ /* */
/* */ /* */
/* This software is provided 'as-is', without any expressed or implied */ /* This software is provided 'as-is', without any expressed or implied */
@ -57,7 +57,7 @@ extern unsigned long PC; /* Current PC */
void LoadCode (const char* Name, unsigned long StartAddress); void LoadCode (void);
/* Load the code from the given file */ /* Load the code from the given file */
unsigned char GetCodeByte (unsigned Addr); unsigned char GetCodeByte (unsigned Addr);

View File

@ -55,7 +55,7 @@ const char CfgExt[] = ".cfg"; /* Config file extension */
unsigned char DebugInfo = 0; /* Add debug info to the object file */ unsigned char DebugInfo = 0; /* Add debug info to the object file */
unsigned char FormFeeds = 0; /* Add form feeds to the output? */ unsigned char FormFeeds = 0; /* Add form feeds to the output? */
unsigned char PassCount = 2; /* How many passed do we do? */ unsigned char PassCount = 2; /* How many passed do we do? */
unsigned long StartAddr = 0xC000; /* Start/load address of the program */ long StartAddr = -1; /* Start/load address of the program */
/* Stuff needed by many routines */ /* Stuff needed by many routines */
unsigned char Pass = 0; /* Disassembler pass */ unsigned char Pass = 0; /* Disassembler pass */

View File

@ -56,7 +56,7 @@ extern const char CfgExt[]; /* Config file extension */
extern unsigned char DebugInfo; /* Add debug info to the object file */ extern unsigned char DebugInfo; /* Add debug info to the object file */
extern unsigned char FormFeeds; /* Add form feeds to the output? */ extern unsigned char FormFeeds; /* Add form feeds to the output? */
extern unsigned char PassCount; /* How many passed do we do? */ extern unsigned char PassCount; /* How many passed do we do? */
extern unsigned long StartAddr; /* Start/load address of the program */ extern long StartAddr; /* Start/load address of the program */
/* Stuff needed by many routines */ /* Stuff needed by many routines */

View File

@ -424,7 +424,7 @@ int main (int argc, char* argv [])
} }
/* Load the input file */ /* Load the input file */
LoadCode (InFile, StartAddr); LoadCode ();
/* Open the output file */ /* Open the output file */
OpenOutput (OutFile); OpenOutput (OutFile);