Removed (pretty inconsistently used) tab chars from source code base.
This commit is contained in:
@@ -49,7 +49,7 @@
|
||||
|
||||
|
||||
/*****************************************************************************/
|
||||
/* Code */
|
||||
/* Code */
|
||||
/*****************************************************************************/
|
||||
|
||||
|
||||
@@ -84,7 +84,7 @@ void AsmInc (const char* Filename, char CommentStart, int IgnoreUnknown)
|
||||
char* L;
|
||||
const char* Comment;
|
||||
unsigned Line;
|
||||
unsigned Len;
|
||||
unsigned Len;
|
||||
long Val;
|
||||
unsigned DVal;
|
||||
int Sign;
|
||||
@@ -111,12 +111,12 @@ void AsmInc (const char* Filename, char CommentStart, int IgnoreUnknown)
|
||||
++L;
|
||||
}
|
||||
|
||||
/* Remove trailing whitespace */
|
||||
Len = strlen (L);
|
||||
while (Len > 0 && IsSpace (L[Len-1])) {
|
||||
--Len;
|
||||
}
|
||||
L[Len] = '\0';
|
||||
/* Remove trailing whitespace */
|
||||
Len = strlen (L);
|
||||
while (Len > 0 && IsSpace (L[Len-1])) {
|
||||
--Len;
|
||||
}
|
||||
L[Len] = '\0';
|
||||
|
||||
/* If the line is empty or starts with a comment char, ignore it */
|
||||
if (*L == '\0' || *L == CommentStart) {
|
||||
@@ -147,11 +147,11 @@ void AsmInc (const char* Filename, char CommentStart, int IgnoreUnknown)
|
||||
} else if (*L == ':' && *++L == '=') {
|
||||
++L;
|
||||
} else {
|
||||
if (!IgnoreUnknown) {
|
||||
Error ("%s(%u): Missing `='", Filename, Line);
|
||||
}
|
||||
continue;
|
||||
}
|
||||
if (!IgnoreUnknown) {
|
||||
Error ("%s(%u): Missing `='", Filename, Line);
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
/* Allow white space once again */
|
||||
L = SkipWhitespace (L);
|
||||
|
||||
@@ -39,7 +39,7 @@
|
||||
|
||||
|
||||
/*****************************************************************************/
|
||||
/* Code */
|
||||
/* Code */
|
||||
/*****************************************************************************/
|
||||
|
||||
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
/*****************************************************************************/
|
||||
/* */
|
||||
/* attrtab.c */
|
||||
/* attrtab.c */
|
||||
/* */
|
||||
/* Disassembler attribute table */
|
||||
/* Disassembler attribute table */
|
||||
/* */
|
||||
/* */
|
||||
/* */
|
||||
@@ -40,7 +40,7 @@
|
||||
|
||||
|
||||
/*****************************************************************************/
|
||||
/* Data */
|
||||
/* Data */
|
||||
/*****************************************************************************/
|
||||
|
||||
|
||||
@@ -51,7 +51,7 @@ static unsigned short AttrTab[0x10000];
|
||||
|
||||
|
||||
/*****************************************************************************/
|
||||
/* Code */
|
||||
/* Code */
|
||||
/*****************************************************************************/
|
||||
|
||||
|
||||
@@ -60,7 +60,7 @@ void AddrCheck (unsigned Addr)
|
||||
/* Check if the given address has a valid range */
|
||||
{
|
||||
if (Addr >= 0x10000) {
|
||||
Error ("Address out of range: %08X", Addr);
|
||||
Error ("Address out of range: %08X", Addr);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -95,21 +95,21 @@ unsigned GetGranularity (attr_t Style)
|
||||
/* Get the granularity for the given style */
|
||||
{
|
||||
switch (Style) {
|
||||
case atDefault: return 1;
|
||||
case atCode: return 1;
|
||||
case atIllegal: return 1;
|
||||
case atByteTab: return 1;
|
||||
case atDByteTab: return 2;
|
||||
case atWordTab: return 2;
|
||||
case atDWordTab: return 4;
|
||||
case atAddrTab: return 2;
|
||||
case atRtsTab: return 2;
|
||||
case atTextTab: return 1;
|
||||
case atDefault: return 1;
|
||||
case atCode: return 1;
|
||||
case atIllegal: return 1;
|
||||
case atByteTab: return 1;
|
||||
case atDByteTab: return 2;
|
||||
case atWordTab: return 2;
|
||||
case atDWordTab: return 4;
|
||||
case atAddrTab: return 2;
|
||||
case atRtsTab: return 2;
|
||||
case atTextTab: return 1;
|
||||
|
||||
case atSkip:
|
||||
default:
|
||||
Internal ("GetGraularity called for style = %d", Style);
|
||||
return 0;
|
||||
case atSkip:
|
||||
default:
|
||||
Internal ("GetGraularity called for style = %d", Style);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -120,7 +120,7 @@ void MarkRange (unsigned Start, unsigned End, attr_t Attr)
|
||||
{
|
||||
/* Do it easy here... */
|
||||
while (Start <= End) {
|
||||
MarkAddr (Start++, Attr);
|
||||
MarkAddr (Start++, Attr);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -134,9 +134,9 @@ void MarkAddr (unsigned Addr, attr_t Attr)
|
||||
|
||||
/* We must not have more than one style bit */
|
||||
if (Attr & atStyleMask) {
|
||||
if (AttrTab[Addr] & atStyleMask) {
|
||||
Error ("Duplicate style for address %04X", Addr);
|
||||
}
|
||||
if (AttrTab[Addr] & atStyleMask) {
|
||||
Error ("Duplicate style for address %04X", Addr);
|
||||
}
|
||||
}
|
||||
|
||||
/* Set the style */
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
/*****************************************************************************/
|
||||
/* */
|
||||
/* attrtab.h */
|
||||
/* attrtab.h */
|
||||
/* */
|
||||
/* Disassembler attribute table */
|
||||
/* Disassembler attribute table */
|
||||
/* */
|
||||
/* */
|
||||
/* */
|
||||
@@ -39,7 +39,7 @@
|
||||
|
||||
|
||||
/*****************************************************************************/
|
||||
/* Data */
|
||||
/* Data */
|
||||
/*****************************************************************************/
|
||||
|
||||
|
||||
@@ -47,28 +47,28 @@
|
||||
typedef enum attr_t {
|
||||
|
||||
/* Styles */
|
||||
atDefault = 0x0000, /* Default style */
|
||||
atCode = 0x0001,
|
||||
atIllegal = 0x0002,
|
||||
atByteTab = 0x0003, /* Same as illegal */
|
||||
atDefault = 0x0000, /* Default style */
|
||||
atCode = 0x0001,
|
||||
atIllegal = 0x0002,
|
||||
atByteTab = 0x0003, /* Same as illegal */
|
||||
atDByteTab = 0x0004,
|
||||
atWordTab = 0x0005,
|
||||
atDWordTab = 0x0006,
|
||||
atAddrTab = 0x0007,
|
||||
atRtsTab = 0x0008,
|
||||
atWordTab = 0x0005,
|
||||
atDWordTab = 0x0006,
|
||||
atAddrTab = 0x0007,
|
||||
atRtsTab = 0x0008,
|
||||
atTextTab = 0x0009,
|
||||
atSkip = 0x000A, /* Skip code completely */
|
||||
|
||||
/* Label flags */
|
||||
atNoLabel = 0x0000, /* No label for this address */
|
||||
atExtLabel = 0x0010, /* External label */
|
||||
atIntLabel = 0x0020, /* Internally generated label */
|
||||
atDepLabel = 0x0040, /* Dependent label */
|
||||
atNoLabel = 0x0000, /* No label for this address */
|
||||
atExtLabel = 0x0010, /* External label */
|
||||
atIntLabel = 0x0020, /* Internally generated label */
|
||||
atDepLabel = 0x0040, /* Dependent label */
|
||||
atUnnamedLabel = 0x0080, /* Unnamed label */
|
||||
|
||||
atLabelDefined = 0x0100, /* True if we defined the label */
|
||||
|
||||
atStyleMask = 0x000F, /* Output style */
|
||||
atStyleMask = 0x000F, /* Output style */
|
||||
atLabelMask = 0x00F0, /* Label information */
|
||||
|
||||
/* Segment */
|
||||
@@ -79,7 +79,7 @@ typedef enum attr_t {
|
||||
|
||||
|
||||
/*****************************************************************************/
|
||||
/* Code */
|
||||
/* Code */
|
||||
/*****************************************************************************/
|
||||
|
||||
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
/*****************************************************************************/
|
||||
/* */
|
||||
/* code.c */
|
||||
/* code.c */
|
||||
/* */
|
||||
/* Binary code management */
|
||||
/* Binary code management */
|
||||
/* */
|
||||
/* */
|
||||
/* */
|
||||
@@ -48,20 +48,20 @@
|
||||
|
||||
|
||||
/*****************************************************************************/
|
||||
/* Data */
|
||||
/* Data */
|
||||
/*****************************************************************************/
|
||||
|
||||
|
||||
|
||||
unsigned char CodeBuf [0x10000]; /* Code buffer */
|
||||
unsigned long CodeStart; /* Start address */
|
||||
unsigned long CodeEnd; /* End address */
|
||||
unsigned long PC; /* Current PC */
|
||||
unsigned char CodeBuf [0x10000]; /* Code buffer */
|
||||
unsigned long CodeStart; /* Start address */
|
||||
unsigned long CodeEnd; /* End address */
|
||||
unsigned long PC; /* Current PC */
|
||||
|
||||
|
||||
|
||||
/*****************************************************************************/
|
||||
/* Code */
|
||||
/* Code */
|
||||
/*****************************************************************************/
|
||||
|
||||
|
||||
@@ -78,12 +78,12 @@ void LoadCode (void)
|
||||
/* Open the file */
|
||||
F = fopen (InFile, "rb");
|
||||
if (F == 0) {
|
||||
Error ("Cannot open `%s': %s", InFile, strerror (errno));
|
||||
Error ("Cannot open `%s': %s", InFile, strerror (errno));
|
||||
}
|
||||
|
||||
/* Seek to the end to get the size of the file */
|
||||
if (fseek (F, 0, SEEK_END) != 0) {
|
||||
Error ("Cannot seek on file `%s': %s", InFile, strerror (errno));
|
||||
Error ("Cannot seek on file `%s': %s", InFile, strerror (errno));
|
||||
}
|
||||
Size = ftell (F);
|
||||
|
||||
@@ -101,7 +101,7 @@ void LoadCode (void)
|
||||
* the file.
|
||||
*/
|
||||
if (fseek (F, InputOffs, SEEK_SET) != 0) {
|
||||
Error ("Cannot seek on file `%s': %s", InFile, strerror (errno));
|
||||
Error ("Cannot seek on file `%s': %s", InFile, strerror (errno));
|
||||
}
|
||||
Size -= InputOffs;
|
||||
|
||||
@@ -118,11 +118,11 @@ void LoadCode (void)
|
||||
* 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 */
|
||||
@@ -130,19 +130,19 @@ void LoadCode (void)
|
||||
|
||||
/* Check if the size is larger than what we can read */
|
||||
if (Size == 0) {
|
||||
Error ("Nothing to read from input file `%s'", InFile);
|
||||
Error ("Nothing to read from input file `%s'", InFile);
|
||||
}
|
||||
if (Size > MaxCount) {
|
||||
Warning ("File `%s' is too large, ignoring %ld bytes",
|
||||
InFile, Size - MaxCount);
|
||||
Warning ("File `%s' is too large, ignoring %ld bytes",
|
||||
InFile, Size - MaxCount);
|
||||
} else if (MaxCount > Size) {
|
||||
MaxCount = (unsigned) Size;
|
||||
MaxCount = (unsigned) Size;
|
||||
}
|
||||
|
||||
/* Read from the file and remember the number of bytes read */
|
||||
Count = fread (CodeBuf + StartAddr, 1, MaxCount, F);
|
||||
if (ferror (F) || Count != MaxCount) {
|
||||
Error ("Error reading from `%s': %s", InFile, strerror (errno));
|
||||
Error ("Error reading from `%s': %s", InFile, strerror (errno));
|
||||
}
|
||||
|
||||
/* Close the file */
|
||||
@@ -150,7 +150,7 @@ void LoadCode (void)
|
||||
|
||||
/* Set the buffer variables */
|
||||
CodeStart = PC = StartAddr;
|
||||
CodeEnd = CodeStart + Count - 1; /* CodeEnd is inclusive */
|
||||
CodeEnd = CodeStart + Count - 1; /* CodeEnd is inclusive */
|
||||
}
|
||||
|
||||
|
||||
@@ -198,9 +198,9 @@ unsigned GetRemainingBytes (void)
|
||||
/* Return the number of remaining code bytes */
|
||||
{
|
||||
if (CodeEnd >= PC) {
|
||||
return (CodeEnd - PC + 1);
|
||||
return (CodeEnd - PC + 1);
|
||||
} else {
|
||||
return 0;
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
/*****************************************************************************/
|
||||
/* */
|
||||
/* code.h */
|
||||
/* code.h */
|
||||
/* */
|
||||
/* Binary code management */
|
||||
/* Binary code management */
|
||||
/* */
|
||||
/* */
|
||||
/* */
|
||||
@@ -39,20 +39,20 @@
|
||||
|
||||
|
||||
/*****************************************************************************/
|
||||
/* Data */
|
||||
/* Data */
|
||||
/*****************************************************************************/
|
||||
|
||||
|
||||
|
||||
extern unsigned char CodeBuf [0x10000]; /* Code buffer */
|
||||
extern unsigned long CodeStart; /* Start address */
|
||||
extern unsigned long CodeEnd; /* End address */
|
||||
extern unsigned long PC; /* Current PC */
|
||||
extern unsigned char CodeBuf [0x10000]; /* Code buffer */
|
||||
extern unsigned long CodeStart; /* Start address */
|
||||
extern unsigned long CodeEnd; /* End address */
|
||||
extern unsigned long PC; /* Current PC */
|
||||
|
||||
|
||||
|
||||
/*****************************************************************************/
|
||||
/* Code */
|
||||
/* Code */
|
||||
/*****************************************************************************/
|
||||
|
||||
|
||||
|
||||
@@ -44,7 +44,7 @@
|
||||
|
||||
|
||||
/*****************************************************************************/
|
||||
/* Data */
|
||||
/* Data */
|
||||
/*****************************************************************************/
|
||||
|
||||
|
||||
@@ -55,7 +55,7 @@ static const char* CommentTab[0x10000];
|
||||
|
||||
|
||||
/*****************************************************************************/
|
||||
/* Code */
|
||||
/* Code */
|
||||
/*****************************************************************************/
|
||||
|
||||
|
||||
|
||||
@@ -43,7 +43,7 @@
|
||||
|
||||
|
||||
/*****************************************************************************/
|
||||
/* Code */
|
||||
/* Code */
|
||||
/*****************************************************************************/
|
||||
|
||||
|
||||
|
||||
228
src/da65/data.c
228
src/da65/data.c
@@ -1,8 +1,8 @@
|
||||
/*****************************************************************************/
|
||||
/* */
|
||||
/* data.c */
|
||||
/* data.c */
|
||||
/* */
|
||||
/* Data output routines */
|
||||
/* Data output routines */
|
||||
/* */
|
||||
/* */
|
||||
/* */
|
||||
@@ -45,7 +45,7 @@
|
||||
|
||||
|
||||
/*****************************************************************************/
|
||||
/* Code */
|
||||
/* Code */
|
||||
/*****************************************************************************/
|
||||
|
||||
|
||||
@@ -63,9 +63,9 @@ static unsigned GetSpan (attr_t Style)
|
||||
unsigned Count = 1;
|
||||
while (Count < RemainingBytes) {
|
||||
attr_t Attr;
|
||||
if (MustDefLabel(PC+Count)) {
|
||||
break;
|
||||
}
|
||||
if (MustDefLabel(PC+Count)) {
|
||||
break;
|
||||
}
|
||||
Attr = GetAttr (PC+Count);
|
||||
if ((Attr & atStyleMask) != Style) {
|
||||
break;
|
||||
@@ -73,7 +73,7 @@ static unsigned GetSpan (attr_t Style)
|
||||
if ((Attr & atSegmentChange)) {
|
||||
break;
|
||||
}
|
||||
++Count;
|
||||
++Count;
|
||||
}
|
||||
|
||||
/* Return the number of bytes */
|
||||
@@ -95,9 +95,9 @@ static unsigned DoTable (attr_t Style, unsigned MemberSize, void (*TableFunc) (u
|
||||
* than BytesPerLine.
|
||||
*/
|
||||
if (Count < MemberSize) {
|
||||
DataByteLine (Count);
|
||||
DataByteLine (Count);
|
||||
PC += Count;
|
||||
return Count;
|
||||
return Count;
|
||||
}
|
||||
|
||||
/* Make Count an even number of multiples of MemberSize */
|
||||
@@ -107,20 +107,20 @@ static unsigned DoTable (attr_t Style, unsigned MemberSize, void (*TableFunc) (u
|
||||
BytesLeft = Count;
|
||||
while (BytesLeft > 0) {
|
||||
|
||||
/* Calculate the number of bytes for the next line */
|
||||
unsigned Chunk = (BytesLeft > BytesPerLine)? BytesPerLine : BytesLeft;
|
||||
/* Calculate the number of bytes for the next line */
|
||||
unsigned Chunk = (BytesLeft > BytesPerLine)? BytesPerLine : BytesLeft;
|
||||
|
||||
/* Output a line with these bytes */
|
||||
TableFunc (Chunk);
|
||||
/* Output a line with these bytes */
|
||||
TableFunc (Chunk);
|
||||
|
||||
/* Next line */
|
||||
BytesLeft -= Chunk;
|
||||
PC += Chunk;
|
||||
/* Next line */
|
||||
BytesLeft -= Chunk;
|
||||
PC += Chunk;
|
||||
}
|
||||
|
||||
/* If the next line is not the same style, add a separator */
|
||||
if (CodeLeft() && GetStyleAttr (PC) != Style) {
|
||||
SeparatorLine ();
|
||||
SeparatorLine ();
|
||||
}
|
||||
|
||||
/* Return the number of bytes output */
|
||||
@@ -191,28 +191,28 @@ unsigned AddrTable (void)
|
||||
/* Now get the address from the PC */
|
||||
Addr = GetCodeWord (PC);
|
||||
|
||||
/* In pass 1, define a label, in pass 2 output the line */
|
||||
if (Pass == 1) {
|
||||
if (!HaveLabel (Addr)) {
|
||||
AddIntLabel (Addr);
|
||||
}
|
||||
} else {
|
||||
const char* Label = GetLabel (Addr, PC);
|
||||
if (Label == 0) {
|
||||
/* OOPS! Should not happen */
|
||||
Internal ("OOPS - Label for address 0x%06X disappeard!", Addr);
|
||||
}
|
||||
Indent (MCol);
|
||||
Output (".addr");
|
||||
Indent (ACol);
|
||||
Output ("%s", Label);
|
||||
LineComment (PC, 2);
|
||||
LineFeed ();
|
||||
}
|
||||
/* In pass 1, define a label, in pass 2 output the line */
|
||||
if (Pass == 1) {
|
||||
if (!HaveLabel (Addr)) {
|
||||
AddIntLabel (Addr);
|
||||
}
|
||||
} else {
|
||||
const char* Label = GetLabel (Addr, PC);
|
||||
if (Label == 0) {
|
||||
/* OOPS! Should not happen */
|
||||
Internal ("OOPS - Label for address 0x%06X disappeard!", Addr);
|
||||
}
|
||||
Indent (MCol);
|
||||
Output (".addr");
|
||||
Indent (ACol);
|
||||
Output ("%s", Label);
|
||||
LineComment (PC, 2);
|
||||
LineFeed ();
|
||||
}
|
||||
|
||||
/* Next table entry */
|
||||
PC += 2;
|
||||
BytesLeft -= 2;
|
||||
/* Next table entry */
|
||||
PC += 2;
|
||||
BytesLeft -= 2;
|
||||
|
||||
/* If we must define a label here, bail out */
|
||||
if (BytesLeft && MustDefLabel (PC)) {
|
||||
@@ -222,7 +222,7 @@ unsigned AddrTable (void)
|
||||
|
||||
/* If the next line is not an address table line, add a separator */
|
||||
if (CodeLeft() && GetStyleAttr (PC) != atAddrTab) {
|
||||
SeparatorLine ();
|
||||
SeparatorLine ();
|
||||
}
|
||||
|
||||
/* Return the number of bytes output */
|
||||
@@ -255,30 +255,30 @@ unsigned RtsTable (void)
|
||||
ForwardLabel (1);
|
||||
|
||||
/* Now get the address from the PC */
|
||||
Addr = (GetCodeWord (PC) + 1) & 0xFFFF;
|
||||
Addr = (GetCodeWord (PC) + 1) & 0xFFFF;
|
||||
|
||||
/* In pass 1, define a label, in pass 2 output the line */
|
||||
if (Pass == 1) {
|
||||
if (!HaveLabel (Addr)) {
|
||||
AddIntLabel (Addr);
|
||||
}
|
||||
} else {
|
||||
const char* Label = GetLabel (Addr, PC);
|
||||
if (Label == 0) {
|
||||
/* OOPS! Should not happen */
|
||||
Internal ("OOPS - Label for address 0x%06X disappeard!", Addr);
|
||||
}
|
||||
Indent (MCol);
|
||||
Output (".word");
|
||||
Indent (ACol);
|
||||
Output ("%s-1", Label);
|
||||
LineComment (PC, 2);
|
||||
LineFeed ();
|
||||
}
|
||||
/* In pass 1, define a label, in pass 2 output the line */
|
||||
if (Pass == 1) {
|
||||
if (!HaveLabel (Addr)) {
|
||||
AddIntLabel (Addr);
|
||||
}
|
||||
} else {
|
||||
const char* Label = GetLabel (Addr, PC);
|
||||
if (Label == 0) {
|
||||
/* OOPS! Should not happen */
|
||||
Internal ("OOPS - Label for address 0x%06X disappeard!", Addr);
|
||||
}
|
||||
Indent (MCol);
|
||||
Output (".word");
|
||||
Indent (ACol);
|
||||
Output ("%s-1", Label);
|
||||
LineComment (PC, 2);
|
||||
LineFeed ();
|
||||
}
|
||||
|
||||
/* Next table entry */
|
||||
PC += 2;
|
||||
BytesLeft -= 2;
|
||||
/* Next table entry */
|
||||
PC += 2;
|
||||
BytesLeft -= 2;
|
||||
|
||||
/* If we must define a label here, bail out */
|
||||
if (BytesLeft && MustDefLabel (PC)) {
|
||||
@@ -288,7 +288,7 @@ unsigned RtsTable (void)
|
||||
|
||||
/* If the next line is not a return address table line, add a separator */
|
||||
if (CodeLeft() && GetStyleAttr (PC) != atRtsTab) {
|
||||
SeparatorLine ();
|
||||
SeparatorLine ();
|
||||
}
|
||||
|
||||
/* Return the number of bytes output */
|
||||
@@ -307,67 +307,67 @@ unsigned TextTable (void)
|
||||
unsigned BytesLeft = ByteCount;
|
||||
while (BytesLeft > 0) {
|
||||
|
||||
unsigned I;
|
||||
unsigned I;
|
||||
|
||||
/* Count the number of characters that can be output as such */
|
||||
unsigned Count = 0;
|
||||
while (Count < BytesLeft && Count < BytesPerLine*4-1) {
|
||||
unsigned char C = GetCodeByte (PC + Count);
|
||||
if (C >= 0x20 && C <= 0x7E && C != '\"') {
|
||||
++Count;
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
/* Count the number of characters that can be output as such */
|
||||
unsigned Count = 0;
|
||||
while (Count < BytesLeft && Count < BytesPerLine*4-1) {
|
||||
unsigned char C = GetCodeByte (PC + Count);
|
||||
if (C >= 0x20 && C <= 0x7E && C != '\"') {
|
||||
++Count;
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/* If we have text, output it */
|
||||
if (Count > 0) {
|
||||
unsigned CBytes;
|
||||
Indent (MCol);
|
||||
Output (".byte");
|
||||
Indent (ACol);
|
||||
Output ("\"");
|
||||
for (I = 0; I < Count; ++I) {
|
||||
Output ("%c", GetCodeByte (PC+I));
|
||||
}
|
||||
Output ("\"");
|
||||
CBytes = Count;
|
||||
while (CBytes > 0) {
|
||||
unsigned Chunk = CBytes;
|
||||
if (Chunk > BytesPerLine) {
|
||||
Chunk = BytesPerLine;
|
||||
}
|
||||
LineComment (PC, Chunk);
|
||||
LineFeed ();
|
||||
CBytes -= Chunk;
|
||||
PC += Chunk;
|
||||
}
|
||||
BytesLeft -= Count;
|
||||
}
|
||||
/* If we have text, output it */
|
||||
if (Count > 0) {
|
||||
unsigned CBytes;
|
||||
Indent (MCol);
|
||||
Output (".byte");
|
||||
Indent (ACol);
|
||||
Output ("\"");
|
||||
for (I = 0; I < Count; ++I) {
|
||||
Output ("%c", GetCodeByte (PC+I));
|
||||
}
|
||||
Output ("\"");
|
||||
CBytes = Count;
|
||||
while (CBytes > 0) {
|
||||
unsigned Chunk = CBytes;
|
||||
if (Chunk > BytesPerLine) {
|
||||
Chunk = BytesPerLine;
|
||||
}
|
||||
LineComment (PC, Chunk);
|
||||
LineFeed ();
|
||||
CBytes -= Chunk;
|
||||
PC += Chunk;
|
||||
}
|
||||
BytesLeft -= Count;
|
||||
}
|
||||
|
||||
/* Count the number of bytes that must be output as bytes */
|
||||
Count = 0;
|
||||
while (Count < BytesLeft && Count < BytesPerLine) {
|
||||
unsigned char C = GetCodeByte (PC + Count);
|
||||
if (C < 0x20 || C > 0x7E || C == '\"') {
|
||||
++Count;
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
/* Count the number of bytes that must be output as bytes */
|
||||
Count = 0;
|
||||
while (Count < BytesLeft && Count < BytesPerLine) {
|
||||
unsigned char C = GetCodeByte (PC + Count);
|
||||
if (C < 0x20 || C > 0x7E || C == '\"') {
|
||||
++Count;
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/* If we have raw output bytes, print them */
|
||||
if (Count > 0) {
|
||||
DataByteLine (Count);
|
||||
PC += Count;
|
||||
BytesLeft -= Count;
|
||||
}
|
||||
/* If we have raw output bytes, print them */
|
||||
if (Count > 0) {
|
||||
DataByteLine (Count);
|
||||
PC += Count;
|
||||
BytesLeft -= Count;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/* If the next line is not a byte table line, add a separator */
|
||||
if (CodeLeft() && GetStyleAttr (PC) != atTextTab) {
|
||||
SeparatorLine ();
|
||||
SeparatorLine ();
|
||||
}
|
||||
|
||||
/* Return the number of bytes output */
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
/*****************************************************************************/
|
||||
/* */
|
||||
/* data.h */
|
||||
/* data.h */
|
||||
/* */
|
||||
/* Data output routines */
|
||||
/* Data output routines */
|
||||
/* */
|
||||
/* */
|
||||
/* */
|
||||
@@ -39,7 +39,7 @@
|
||||
|
||||
|
||||
/*****************************************************************************/
|
||||
/* Code */
|
||||
/* Code */
|
||||
/*****************************************************************************/
|
||||
|
||||
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
/*****************************************************************************/
|
||||
/* */
|
||||
/* error.c */
|
||||
/* error.c */
|
||||
/* */
|
||||
/* Error handling */
|
||||
/* Error handling */
|
||||
/* */
|
||||
/* */
|
||||
/* */
|
||||
@@ -43,7 +43,7 @@
|
||||
|
||||
|
||||
/*****************************************************************************/
|
||||
/* Code */
|
||||
/* Code */
|
||||
/*****************************************************************************/
|
||||
|
||||
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
/*****************************************************************************/
|
||||
/* */
|
||||
/* error.h */
|
||||
/* error.h */
|
||||
/* */
|
||||
/* Error handling */
|
||||
/* Error handling */
|
||||
/* */
|
||||
/* */
|
||||
/* */
|
||||
@@ -44,7 +44,7 @@
|
||||
|
||||
|
||||
/*****************************************************************************/
|
||||
/* Code */
|
||||
/* Code */
|
||||
/*****************************************************************************/
|
||||
|
||||
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
/*****************************************************************************/
|
||||
/* */
|
||||
/* global.c */
|
||||
/* global.c */
|
||||
/* */
|
||||
/* Global variables for the da65 disassembler */
|
||||
/* Global variables for the da65 disassembler */
|
||||
/* */
|
||||
/* */
|
||||
/* */
|
||||
@@ -38,45 +38,45 @@
|
||||
|
||||
|
||||
/*****************************************************************************/
|
||||
/* Data */
|
||||
/* Data */
|
||||
/*****************************************************************************/
|
||||
|
||||
|
||||
|
||||
/* File names */
|
||||
const char* InFile = 0; /* Name of input file */
|
||||
const char* OutFile = 0; /* Name of output file */
|
||||
const char* InFile = 0; /* Name of input file */
|
||||
const char* OutFile = 0; /* Name of output file */
|
||||
|
||||
/* Default extensions */
|
||||
const char OutExt[] = ".dis"; /* Output file extension */
|
||||
const char CfgExt[] = ".cfg"; /* Config file extension */
|
||||
const char OutExt[] = ".dis"; /* Output file extension */
|
||||
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 FormFeeds = 0; /* Add form feeds to the output? */
|
||||
unsigned char UseHexOffs = 0; /* Use hexadecimal label offsets */
|
||||
unsigned char PassCount = 2; /* How many passed do we do? */
|
||||
unsigned char PassCount = 2; /* How many passed do we do? */
|
||||
signed char NewlineAfterJMP = -1; /* Add a newline after a JMP insn? */
|
||||
signed char NewlineAfterRTS = -1; /* Add a newline after a RTS insn? */
|
||||
long StartAddr = -1L; /* Start/load address of the program */
|
||||
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 Pass = 0; /* Disassembler pass */
|
||||
unsigned Pass = 0; /* Disassembler pass */
|
||||
char Now[128]; /* Current time as string */
|
||||
|
||||
/* Comments */
|
||||
unsigned Comments = 0; /* Add which comments to the output? */
|
||||
|
||||
/* Page formatting */
|
||||
unsigned PageLength = 0; /* Length of a listing page */
|
||||
unsigned PageLength = 0; /* Length of a listing page */
|
||||
unsigned LBreak = 7; /* Linefeed if labels exceed this limit */
|
||||
unsigned MCol = 9; /* Mnemonic column */
|
||||
unsigned ACol = 17; /* Argument column */
|
||||
unsigned CCol = 49; /* Comment column */
|
||||
unsigned TCol = 81; /* Text bytes column */
|
||||
unsigned BytesPerLine = 8; /* Max. number of data bytes per line */
|
||||
unsigned MCol = 9; /* Mnemonic column */
|
||||
unsigned ACol = 17; /* Argument column */
|
||||
unsigned CCol = 49; /* Comment column */
|
||||
unsigned TCol = 81; /* Text bytes column */
|
||||
unsigned BytesPerLine = 8; /* Max. number of data bytes per line */
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
/*****************************************************************************/
|
||||
/* */
|
||||
/* global.h */
|
||||
/* global.h */
|
||||
/* */
|
||||
/* Global variables for the da65 disassembler */
|
||||
/* Global variables for the da65 disassembler */
|
||||
/* */
|
||||
/* */
|
||||
/* */
|
||||
@@ -39,32 +39,32 @@
|
||||
|
||||
|
||||
/*****************************************************************************/
|
||||
/* Data */
|
||||
/* Data */
|
||||
/*****************************************************************************/
|
||||
|
||||
|
||||
|
||||
/* File stuff */
|
||||
extern const char* InFile; /* Name of input file */
|
||||
extern const char* OutFile; /* Name of output file */
|
||||
extern const char* InFile; /* Name of input file */
|
||||
extern const char* OutFile; /* Name of output file */
|
||||
|
||||
/* Default extensions */
|
||||
extern const char OutExt[]; /* Output file extension */
|
||||
extern const char CfgExt[]; /* Config file extension */
|
||||
extern const char OutExt[]; /* Output file extension */
|
||||
extern const char CfgExt[]; /* Config file extension */
|
||||
|
||||
/* Flags and other command line stuff */
|
||||
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 UseHexOffs; /* Use hexadecimal label offsets */
|
||||
extern unsigned char PassCount; /* How many passed do we do? */
|
||||
extern unsigned char PassCount; /* How many passed do we do? */
|
||||
extern signed char NewlineAfterJMP;/* Add a newline after a JMP insn? */
|
||||
extern signed char NewlineAfterRTS;/* Add a newline after a RTS insn? */
|
||||
extern long StartAddr; /* Start/load address of the program */
|
||||
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 Pass; /* Disassembler pass */
|
||||
extern unsigned Pass; /* Disassembler pass */
|
||||
extern char Now[128]; /* Current time as string */
|
||||
|
||||
/* Comments */
|
||||
@@ -73,9 +73,9 @@ extern char Now[128]; /* Current time as string */
|
||||
extern unsigned Comments; /* Add which comments to the output? */
|
||||
|
||||
/* Page formatting */
|
||||
#define MIN_PAGE_LEN 32
|
||||
#define MAX_PAGE_LEN 127
|
||||
extern unsigned PageLength; /* Length of a listing page */
|
||||
#define MIN_PAGE_LEN 32
|
||||
#define MAX_PAGE_LEN 127
|
||||
extern unsigned PageLength; /* Length of a listing page */
|
||||
|
||||
/* Linefeed if labels exceed this limit */
|
||||
#define MIN_LABELBREAK 1
|
||||
@@ -85,27 +85,27 @@ extern unsigned LBreak;
|
||||
/* Mnemonic column */
|
||||
#define MIN_MCOL 1
|
||||
#define MAX_MCOL 127
|
||||
extern unsigned MCol;
|
||||
extern unsigned MCol;
|
||||
|
||||
/* Argument column */
|
||||
#define MIN_ACOL 1
|
||||
#define MAX_ACOL 127
|
||||
extern unsigned ACol;
|
||||
extern unsigned ACol;
|
||||
|
||||
/* Comment column */
|
||||
#define MIN_CCOL 1
|
||||
#define MAX_CCOL 127
|
||||
extern unsigned CCol;
|
||||
extern unsigned CCol;
|
||||
|
||||
/* Text bytes column */
|
||||
#define MIN_TCOL 1
|
||||
#define MAX_TCOL 127
|
||||
extern unsigned TCol;
|
||||
extern unsigned TCol;
|
||||
|
||||
/* Max. number of data bytes per line */
|
||||
#define MIN_BYTESPERLINE 1
|
||||
#define MAX_BYTESPERLINE 127
|
||||
extern unsigned BytesPerLine;
|
||||
extern unsigned BytesPerLine;
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
/*****************************************************************************/
|
||||
/* */
|
||||
/* handler.c */
|
||||
/* handler.c */
|
||||
/* */
|
||||
/* Opcode handler functions for the disassembler */
|
||||
/* Opcode handler functions for the disassembler */
|
||||
/* */
|
||||
/* */
|
||||
/* */
|
||||
@@ -51,7 +51,7 @@
|
||||
|
||||
|
||||
/*****************************************************************************/
|
||||
/* Helper functions */
|
||||
/* Helper functions */
|
||||
/*****************************************************************************/
|
||||
|
||||
|
||||
@@ -110,18 +110,18 @@ static const char* GetAddrArg (unsigned Flags, unsigned Addr)
|
||||
{
|
||||
const char* Label = 0;
|
||||
if (Flags & flUseLabel) {
|
||||
Label = GetLabel (Addr, PC);
|
||||
Label = GetLabel (Addr, PC);
|
||||
}
|
||||
if (Label) {
|
||||
return Label;
|
||||
return Label;
|
||||
} else {
|
||||
static char Buf [32];
|
||||
if (Addr < 0x100) {
|
||||
xsprintf (Buf, sizeof (Buf), "$%02X", Addr);
|
||||
} else {
|
||||
xsprintf (Buf, sizeof (Buf), "$%04X", Addr);
|
||||
}
|
||||
return Buf;
|
||||
static char Buf [32];
|
||||
if (Addr < 0x100) {
|
||||
xsprintf (Buf, sizeof (Buf), "$%02X", Addr);
|
||||
} else {
|
||||
xsprintf (Buf, sizeof (Buf), "$%04X", Addr);
|
||||
}
|
||||
return Buf;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -132,66 +132,66 @@ static void GenerateLabel (unsigned Flags, unsigned Addr)
|
||||
{
|
||||
/* Generate labels in pass #1, and only if we don't have a label already */
|
||||
if (Pass == 1 && !HaveLabel (Addr) &&
|
||||
/* Check if we must create a label */
|
||||
((Flags & flGenLabel) != 0 ||
|
||||
((Flags & flUseLabel) != 0 && Addr >= CodeStart && Addr <= CodeEnd))) {
|
||||
/* Check if we must create a label */
|
||||
((Flags & flGenLabel) != 0 ||
|
||||
((Flags & flUseLabel) != 0 && Addr >= CodeStart && Addr <= CodeEnd))) {
|
||||
|
||||
/* As a special case, handle ranges with tables or similar. Within
|
||||
* such a range with a granularity > 1, do only generate dependent
|
||||
* labels for all addresses but the first one. Be sure to generate
|
||||
* a label for the start of the range, however.
|
||||
*/
|
||||
attr_t Style = GetStyleAttr (Addr);
|
||||
unsigned Granularity = GetGranularity (Style);
|
||||
/* As a special case, handle ranges with tables or similar. Within
|
||||
* such a range with a granularity > 1, do only generate dependent
|
||||
* labels for all addresses but the first one. Be sure to generate
|
||||
* a label for the start of the range, however.
|
||||
*/
|
||||
attr_t Style = GetStyleAttr (Addr);
|
||||
unsigned Granularity = GetGranularity (Style);
|
||||
|
||||
if (Granularity == 1) {
|
||||
/* Just add the label */
|
||||
AddIntLabel (Addr);
|
||||
} else {
|
||||
if (Granularity == 1) {
|
||||
/* Just add the label */
|
||||
AddIntLabel (Addr);
|
||||
} else {
|
||||
|
||||
/* THIS CODE IS A MESS AND WILL FAIL ON SEVERAL CONDITIONS! ### */
|
||||
|
||||
|
||||
/* Search for the start of the range or the last non dependent
|
||||
* label in the range.
|
||||
*/
|
||||
unsigned Offs;
|
||||
attr_t LabelAttr;
|
||||
unsigned LabelAddr = Addr;
|
||||
while (LabelAddr > CodeStart) {
|
||||
/* Search for the start of the range or the last non dependent
|
||||
* label in the range.
|
||||
*/
|
||||
unsigned Offs;
|
||||
attr_t LabelAttr;
|
||||
unsigned LabelAddr = Addr;
|
||||
while (LabelAddr > CodeStart) {
|
||||
|
||||
if (Style != GetStyleAttr (LabelAddr-1)) {
|
||||
/* End of range reached */
|
||||
break;
|
||||
}
|
||||
--LabelAddr;
|
||||
LabelAttr = GetLabelAttr (LabelAddr);
|
||||
if ((LabelAttr & (atIntLabel|atExtLabel)) != 0) {
|
||||
/* The address has an internal or external label */
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (Style != GetStyleAttr (LabelAddr-1)) {
|
||||
/* End of range reached */
|
||||
break;
|
||||
}
|
||||
--LabelAddr;
|
||||
LabelAttr = GetLabelAttr (LabelAddr);
|
||||
if ((LabelAttr & (atIntLabel|atExtLabel)) != 0) {
|
||||
/* The address has an internal or external label */
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/* If the proposed label address doesn't have a label, define one */
|
||||
if ((GetLabelAttr (LabelAddr) & (atIntLabel|atExtLabel)) == 0) {
|
||||
AddIntLabel (LabelAddr);
|
||||
}
|
||||
/* If the proposed label address doesn't have a label, define one */
|
||||
if ((GetLabelAttr (LabelAddr) & (atIntLabel|atExtLabel)) == 0) {
|
||||
AddIntLabel (LabelAddr);
|
||||
}
|
||||
|
||||
/* Create the label */
|
||||
Offs = Addr - LabelAddr;
|
||||
if (Offs == 0) {
|
||||
AddIntLabel (Addr);
|
||||
} else {
|
||||
AddDepLabel (Addr, atIntLabel, GetLabelName (LabelAddr), Offs);
|
||||
}
|
||||
}
|
||||
/* Create the label */
|
||||
Offs = Addr - LabelAddr;
|
||||
if (Offs == 0) {
|
||||
AddIntLabel (Addr);
|
||||
} else {
|
||||
AddDepLabel (Addr, atIntLabel, GetLabelName (LabelAddr), Offs);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*****************************************************************************/
|
||||
/* Code */
|
||||
/* Code */
|
||||
/*****************************************************************************/
|
||||
|
||||
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
/*****************************************************************************/
|
||||
/* */
|
||||
/* handler.h */
|
||||
/* handler.h */
|
||||
/* */
|
||||
/* Opcode handler functions for the disassembler */
|
||||
/* Opcode handler functions for the disassembler */
|
||||
/* */
|
||||
/* */
|
||||
/* */
|
||||
@@ -47,7 +47,7 @@
|
||||
|
||||
|
||||
/*****************************************************************************/
|
||||
/* Code */
|
||||
/* Code */
|
||||
/*****************************************************************************/
|
||||
|
||||
|
||||
|
||||
@@ -63,7 +63,7 @@
|
||||
|
||||
|
||||
/*****************************************************************************/
|
||||
/* Code */
|
||||
/* Code */
|
||||
/*****************************************************************************/
|
||||
|
||||
|
||||
@@ -85,7 +85,7 @@ static void AsmIncSection (void)
|
||||
{
|
||||
static const IdentTok LabelDefs[] = {
|
||||
{ "COMMENTSTART", INFOTOK_COMMENTSTART },
|
||||
{ "FILE", INFOTOK_FILE },
|
||||
{ "FILE", INFOTOK_FILE },
|
||||
{ "IGNOREUNKNOWN", INFOTOK_IGNOREUNKNOWN },
|
||||
};
|
||||
|
||||
@@ -103,11 +103,11 @@ static void AsmIncSection (void)
|
||||
/* Look for section tokens */
|
||||
while (InfoTok != INFOTOK_RCURLY) {
|
||||
|
||||
/* Convert to special token */
|
||||
InfoSpecialToken (LabelDefs, ENTRY_COUNT (LabelDefs), "Asminc directive");
|
||||
/* Convert to special token */
|
||||
InfoSpecialToken (LabelDefs, ENTRY_COUNT (LabelDefs), "Asminc directive");
|
||||
|
||||
/* Look at the token */
|
||||
switch (InfoTok) {
|
||||
/* Look at the token */
|
||||
switch (InfoTok) {
|
||||
|
||||
case INFOTOK_COMMENTSTART:
|
||||
InfoNextTok ();
|
||||
@@ -119,18 +119,18 @@ static void AsmIncSection (void)
|
||||
InfoNextTok ();
|
||||
break;
|
||||
|
||||
case INFOTOK_FILE:
|
||||
InfoNextTok ();
|
||||
if (Name) {
|
||||
InfoError ("File name already given");
|
||||
}
|
||||
InfoAssureStr ();
|
||||
if (InfoSVal[0] == '\0') {
|
||||
InfoError ("File name may not be empty");
|
||||
}
|
||||
Name = xstrdup (InfoSVal);
|
||||
InfoNextTok ();
|
||||
break;
|
||||
case INFOTOK_FILE:
|
||||
InfoNextTok ();
|
||||
if (Name) {
|
||||
InfoError ("File name already given");
|
||||
}
|
||||
InfoAssureStr ();
|
||||
if (InfoSVal[0] == '\0') {
|
||||
InfoError ("File name may not be empty");
|
||||
}
|
||||
Name = xstrdup (InfoSVal);
|
||||
InfoNextTok ();
|
||||
break;
|
||||
|
||||
case INFOTOK_IGNOREUNKNOWN:
|
||||
InfoNextTok ();
|
||||
@@ -144,18 +144,18 @@ static void AsmIncSection (void)
|
||||
|
||||
default:
|
||||
Internal ("Unexpected token: %u", InfoTok);
|
||||
}
|
||||
}
|
||||
|
||||
/* Directive is followed by a semicolon */
|
||||
InfoConsumeSemi ();
|
||||
/* Directive is followed by a semicolon */
|
||||
InfoConsumeSemi ();
|
||||
}
|
||||
|
||||
/* Check for the necessary data and assume defaults */
|
||||
if (Name == 0) {
|
||||
InfoError ("File name is missing");
|
||||
InfoError ("File name is missing");
|
||||
}
|
||||
if (CommentStart == EOF) {
|
||||
CommentStart = ';';
|
||||
CommentStart = ';';
|
||||
}
|
||||
if (IgnoreUnknown == -1) {
|
||||
IgnoreUnknown = 0;
|
||||
@@ -182,9 +182,9 @@ static void GlobalSection (void)
|
||||
{ "COMMENTCOL", INFOTOK_COMMENT_COLUMN },
|
||||
{ "COMMENTCOLUMN", INFOTOK_COMMENT_COLUMN },
|
||||
{ "COMMENTS", INFOTOK_COMMENTS },
|
||||
{ "CPU", INFOTOK_CPU },
|
||||
{ "CPU", INFOTOK_CPU },
|
||||
{ "HEXOFFS", INFOTOK_HEXOFFS },
|
||||
{ "INPUTNAME", INFOTOK_INPUTNAME },
|
||||
{ "INPUTNAME", INFOTOK_INPUTNAME },
|
||||
{ "INPUTOFFS", INFOTOK_INPUTOFFS },
|
||||
{ "INPUTSIZE", INFOTOK_INPUTSIZE },
|
||||
{ "LABELBREAK", INFOTOK_LABELBREAK },
|
||||
@@ -192,9 +192,9 @@ static void GlobalSection (void)
|
||||
{ "MNEMONICCOLUMN", INFOTOK_MNEMONIC_COLUMN },
|
||||
{ "NEWLINEAFTERJMP", INFOTOK_NL_AFTER_JMP },
|
||||
{ "NEWLINEAFTERRTS", INFOTOK_NL_AFTER_RTS },
|
||||
{ "OUTPUTNAME", INFOTOK_OUTPUTNAME },
|
||||
{ "PAGELENGTH", INFOTOK_PAGELENGTH },
|
||||
{ "STARTADDR", INFOTOK_STARTADDR },
|
||||
{ "OUTPUTNAME", INFOTOK_OUTPUTNAME },
|
||||
{ "PAGELENGTH", INFOTOK_PAGELENGTH },
|
||||
{ "STARTADDR", INFOTOK_STARTADDR },
|
||||
{ "TEXTCOL", INFOTOK_TEXT_COLUMN },
|
||||
{ "TEXTCOLUMN", INFOTOK_TEXT_COLUMN },
|
||||
};
|
||||
@@ -208,35 +208,35 @@ static void GlobalSection (void)
|
||||
/* Look for section tokens */
|
||||
while (InfoTok != INFOTOK_RCURLY) {
|
||||
|
||||
/* Convert to special token */
|
||||
InfoSpecialToken (GlobalDefs, ENTRY_COUNT (GlobalDefs), "Global directive");
|
||||
/* Convert to special token */
|
||||
InfoSpecialToken (GlobalDefs, ENTRY_COUNT (GlobalDefs), "Global directive");
|
||||
|
||||
/* Look at the token */
|
||||
switch (InfoTok) {
|
||||
/* Look at the token */
|
||||
switch (InfoTok) {
|
||||
|
||||
case INFOTOK_ARGUMENT_COLUMN:
|
||||
InfoNextTok ();
|
||||
InfoAssureInt ();
|
||||
InfoNextTok ();
|
||||
InfoAssureInt ();
|
||||
InfoRangeCheck (MIN_ACOL, MAX_ACOL);
|
||||
ACol = InfoIVal;
|
||||
InfoNextTok ();
|
||||
break;
|
||||
ACol = InfoIVal;
|
||||
InfoNextTok ();
|
||||
break;
|
||||
|
||||
case INFOTOK_COMMENT_COLUMN:
|
||||
InfoNextTok ();
|
||||
InfoAssureInt ();
|
||||
InfoNextTok ();
|
||||
InfoAssureInt ();
|
||||
InfoRangeCheck (MIN_CCOL, MAX_CCOL);
|
||||
CCol = InfoIVal;
|
||||
InfoNextTok ();
|
||||
break;
|
||||
CCol = InfoIVal;
|
||||
InfoNextTok ();
|
||||
break;
|
||||
|
||||
case INFOTOK_COMMENTS:
|
||||
InfoNextTok ();
|
||||
InfoAssureInt ();
|
||||
InfoNextTok ();
|
||||
InfoAssureInt ();
|
||||
InfoRangeCheck (MIN_COMMENTS, MAX_COMMENTS);
|
||||
Comments = InfoIVal;
|
||||
InfoNextTok ();
|
||||
break;
|
||||
Comments = InfoIVal;
|
||||
InfoNextTok ();
|
||||
break;
|
||||
|
||||
case INFOTOK_CPU:
|
||||
InfoNextTok ();
|
||||
@@ -259,46 +259,46 @@ static void GlobalSection (void)
|
||||
InfoNextTok ();
|
||||
break;
|
||||
|
||||
case INFOTOK_INPUTNAME:
|
||||
InfoNextTok ();
|
||||
InfoAssureStr ();
|
||||
if (InFile) {
|
||||
InfoError ("Input file name already given");
|
||||
}
|
||||
InFile = xstrdup (InfoSVal);
|
||||
InfoNextTok ();
|
||||
break;
|
||||
case INFOTOK_INPUTNAME:
|
||||
InfoNextTok ();
|
||||
InfoAssureStr ();
|
||||
if (InFile) {
|
||||
InfoError ("Input file name already given");
|
||||
}
|
||||
InFile = xstrdup (InfoSVal);
|
||||
InfoNextTok ();
|
||||
break;
|
||||
|
||||
case INFOTOK_INPUTOFFS:
|
||||
InfoNextTok ();
|
||||
InfoAssureInt ();
|
||||
InputOffs = InfoIVal;
|
||||
InfoNextTok ();
|
||||
break;
|
||||
InfoNextTok ();
|
||||
InfoAssureInt ();
|
||||
InputOffs = InfoIVal;
|
||||
InfoNextTok ();
|
||||
break;
|
||||
|
||||
case INFOTOK_INPUTSIZE:
|
||||
InfoNextTok ();
|
||||
InfoAssureInt ();
|
||||
InfoNextTok ();
|
||||
InfoAssureInt ();
|
||||
InfoRangeCheck (1, 0x10000);
|
||||
InputSize = InfoIVal;
|
||||
InfoNextTok ();
|
||||
break;
|
||||
InputSize = InfoIVal;
|
||||
InfoNextTok ();
|
||||
break;
|
||||
|
||||
case INFOTOK_LABELBREAK:
|
||||
InfoNextTok ();
|
||||
InfoAssureInt ();
|
||||
InfoNextTok ();
|
||||
InfoAssureInt ();
|
||||
InfoRangeCheck (0, UCHAR_MAX);
|
||||
LBreak = (unsigned char) InfoIVal;
|
||||
InfoNextTok ();
|
||||
break;
|
||||
LBreak = (unsigned char) InfoIVal;
|
||||
InfoNextTok ();
|
||||
break;
|
||||
|
||||
case INFOTOK_MNEMONIC_COLUMN:
|
||||
InfoNextTok ();
|
||||
InfoAssureInt ();
|
||||
InfoNextTok ();
|
||||
InfoAssureInt ();
|
||||
InfoRangeCheck (MIN_MCOL, MAX_MCOL);
|
||||
MCol = InfoIVal;
|
||||
InfoNextTok ();
|
||||
break;
|
||||
MCol = InfoIVal;
|
||||
InfoNextTok ();
|
||||
break;
|
||||
|
||||
case INFOTOK_NL_AFTER_JMP:
|
||||
InfoNextTok ();
|
||||
@@ -320,49 +320,49 @@ static void GlobalSection (void)
|
||||
InfoNextTok ();
|
||||
break;
|
||||
|
||||
case INFOTOK_OUTPUTNAME:
|
||||
InfoNextTok ();
|
||||
InfoAssureStr ();
|
||||
if (OutFile) {
|
||||
InfoError ("Output file name already given");
|
||||
}
|
||||
OutFile = xstrdup (InfoSVal);
|
||||
InfoNextTok ();
|
||||
break;
|
||||
case INFOTOK_OUTPUTNAME:
|
||||
InfoNextTok ();
|
||||
InfoAssureStr ();
|
||||
if (OutFile) {
|
||||
InfoError ("Output file name already given");
|
||||
}
|
||||
OutFile = xstrdup (InfoSVal);
|
||||
InfoNextTok ();
|
||||
break;
|
||||
|
||||
case INFOTOK_PAGELENGTH:
|
||||
InfoNextTok ();
|
||||
InfoAssureInt ();
|
||||
if (InfoIVal != 0) {
|
||||
InfoRangeCheck (MIN_PAGE_LEN, MAX_PAGE_LEN);
|
||||
}
|
||||
PageLength = InfoIVal;
|
||||
InfoNextTok ();
|
||||
break;
|
||||
case INFOTOK_PAGELENGTH:
|
||||
InfoNextTok ();
|
||||
InfoAssureInt ();
|
||||
if (InfoIVal != 0) {
|
||||
InfoRangeCheck (MIN_PAGE_LEN, MAX_PAGE_LEN);
|
||||
}
|
||||
PageLength = InfoIVal;
|
||||
InfoNextTok ();
|
||||
break;
|
||||
|
||||
case INFOTOK_STARTADDR:
|
||||
InfoNextTok ();
|
||||
InfoAssureInt ();
|
||||
InfoRangeCheck (0x0000, 0xFFFF);
|
||||
StartAddr = InfoIVal;
|
||||
InfoNextTok ();
|
||||
break;
|
||||
case INFOTOK_STARTADDR:
|
||||
InfoNextTok ();
|
||||
InfoAssureInt ();
|
||||
InfoRangeCheck (0x0000, 0xFFFF);
|
||||
StartAddr = InfoIVal;
|
||||
InfoNextTok ();
|
||||
break;
|
||||
|
||||
case INFOTOK_TEXT_COLUMN:
|
||||
InfoNextTok ();
|
||||
InfoAssureInt ();
|
||||
InfoNextTok ();
|
||||
InfoAssureInt ();
|
||||
InfoRangeCheck (MIN_TCOL, MAX_TCOL);
|
||||
TCol = InfoIVal;
|
||||
InfoNextTok ();
|
||||
break;
|
||||
TCol = InfoIVal;
|
||||
InfoNextTok ();
|
||||
break;
|
||||
|
||||
default:
|
||||
Internal ("Unexpected token: %u", InfoTok);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
/* Directive is followed by a semicolon */
|
||||
InfoConsumeSemi ();
|
||||
/* Directive is followed by a semicolon */
|
||||
InfoConsumeSemi ();
|
||||
|
||||
}
|
||||
|
||||
@@ -376,10 +376,10 @@ static void LabelSection (void)
|
||||
/* Parse a label section */
|
||||
{
|
||||
static const IdentTok LabelDefs[] = {
|
||||
{ "COMMENT", INFOTOK_COMMENT },
|
||||
{ "ADDR", INFOTOK_ADDR },
|
||||
{ "NAME", INFOTOK_NAME },
|
||||
{ "SIZE", INFOTOK_SIZE },
|
||||
{ "COMMENT", INFOTOK_COMMENT },
|
||||
{ "ADDR", INFOTOK_ADDR },
|
||||
{ "NAME", INFOTOK_NAME },
|
||||
{ "SIZE", INFOTOK_SIZE },
|
||||
};
|
||||
|
||||
/* Locals - initialize to avoid gcc warnings */
|
||||
@@ -397,84 +397,84 @@ static void LabelSection (void)
|
||||
/* Look for section tokens */
|
||||
while (InfoTok != INFOTOK_RCURLY) {
|
||||
|
||||
/* Convert to special token */
|
||||
InfoSpecialToken (LabelDefs, ENTRY_COUNT (LabelDefs), "Label attribute");
|
||||
/* Convert to special token */
|
||||
InfoSpecialToken (LabelDefs, ENTRY_COUNT (LabelDefs), "Label attribute");
|
||||
|
||||
/* Look at the token */
|
||||
switch (InfoTok) {
|
||||
/* Look at the token */
|
||||
switch (InfoTok) {
|
||||
|
||||
case INFOTOK_ADDR:
|
||||
InfoNextTok ();
|
||||
if (Value >= 0) {
|
||||
InfoError ("Value already given");
|
||||
}
|
||||
InfoAssureInt ();
|
||||
InfoRangeCheck (0, 0xFFFF);
|
||||
Value = InfoIVal;
|
||||
InfoNextTok ();
|
||||
break;
|
||||
case INFOTOK_ADDR:
|
||||
InfoNextTok ();
|
||||
if (Value >= 0) {
|
||||
InfoError ("Value already given");
|
||||
}
|
||||
InfoAssureInt ();
|
||||
InfoRangeCheck (0, 0xFFFF);
|
||||
Value = InfoIVal;
|
||||
InfoNextTok ();
|
||||
break;
|
||||
|
||||
case INFOTOK_COMMENT:
|
||||
InfoNextTok ();
|
||||
if (Comment) {
|
||||
InfoError ("Comment already given");
|
||||
}
|
||||
InfoAssureStr ();
|
||||
if (InfoSVal[0] == '\0') {
|
||||
InfoError ("Comment may not be empty");
|
||||
}
|
||||
Comment = xstrdup (InfoSVal);
|
||||
InfoNextTok ();
|
||||
break;
|
||||
case INFOTOK_COMMENT:
|
||||
InfoNextTok ();
|
||||
if (Comment) {
|
||||
InfoError ("Comment already given");
|
||||
}
|
||||
InfoAssureStr ();
|
||||
if (InfoSVal[0] == '\0') {
|
||||
InfoError ("Comment may not be empty");
|
||||
}
|
||||
Comment = xstrdup (InfoSVal);
|
||||
InfoNextTok ();
|
||||
break;
|
||||
|
||||
case INFOTOK_NAME:
|
||||
InfoNextTok ();
|
||||
if (Name) {
|
||||
InfoError ("Name already given");
|
||||
}
|
||||
InfoAssureStr ();
|
||||
Name = xstrdup (InfoSVal);
|
||||
InfoNextTok ();
|
||||
break;
|
||||
case INFOTOK_NAME:
|
||||
InfoNextTok ();
|
||||
if (Name) {
|
||||
InfoError ("Name already given");
|
||||
}
|
||||
InfoAssureStr ();
|
||||
Name = xstrdup (InfoSVal);
|
||||
InfoNextTok ();
|
||||
break;
|
||||
|
||||
case INFOTOK_SIZE:
|
||||
InfoNextTok ();
|
||||
if (Size >= 0) {
|
||||
InfoError ("Size already given");
|
||||
}
|
||||
InfoAssureInt ();
|
||||
InfoRangeCheck (1, 0x10000);
|
||||
Size = InfoIVal;
|
||||
InfoNextTok ();
|
||||
break;
|
||||
case INFOTOK_SIZE:
|
||||
InfoNextTok ();
|
||||
if (Size >= 0) {
|
||||
InfoError ("Size already given");
|
||||
}
|
||||
InfoAssureInt ();
|
||||
InfoRangeCheck (1, 0x10000);
|
||||
Size = InfoIVal;
|
||||
InfoNextTok ();
|
||||
break;
|
||||
|
||||
default:
|
||||
Internal ("Unexpected token: %u", InfoTok);
|
||||
}
|
||||
}
|
||||
|
||||
/* Directive is followed by a semicolon */
|
||||
InfoConsumeSemi ();
|
||||
/* Directive is followed by a semicolon */
|
||||
InfoConsumeSemi ();
|
||||
}
|
||||
|
||||
/* Did we get the necessary data */
|
||||
if (Name == 0) {
|
||||
InfoError ("Label name is missing");
|
||||
InfoError ("Label name is missing");
|
||||
}
|
||||
if (Name[0] == '\0' && Size > 1) {
|
||||
InfoError ("Unnamed labels must not have a size > 1");
|
||||
}
|
||||
if (Value < 0) {
|
||||
InfoError ("Label value is missing");
|
||||
InfoError ("Label value is missing");
|
||||
}
|
||||
if (Size < 0) {
|
||||
/* Use default */
|
||||
Size = 1;
|
||||
/* Use default */
|
||||
Size = 1;
|
||||
}
|
||||
if (Value + Size > 0x10000) {
|
||||
InfoError ("Invalid size (address out of range)");
|
||||
InfoError ("Invalid size (address out of range)");
|
||||
}
|
||||
if (HaveLabel ((unsigned) Value)) {
|
||||
InfoError ("Label for address $%04lX already defined", Value);
|
||||
InfoError ("Label for address $%04lX already defined", Value);
|
||||
}
|
||||
|
||||
/* Define the label(s) */
|
||||
@@ -505,41 +505,41 @@ static void RangeSection (void)
|
||||
{
|
||||
static const IdentTok RangeDefs[] = {
|
||||
{ "COMMENT", INFOTOK_COMMENT },
|
||||
{ "END", INFOTOK_END },
|
||||
{ "END", INFOTOK_END },
|
||||
{ "NAME", INFOTOK_NAME },
|
||||
{ "START", INFOTOK_START },
|
||||
{ "TYPE", INFOTOK_TYPE },
|
||||
{ "START", INFOTOK_START },
|
||||
{ "TYPE", INFOTOK_TYPE },
|
||||
};
|
||||
|
||||
static const IdentTok TypeDefs[] = {
|
||||
{ "ADDRTABLE", INFOTOK_ADDRTAB },
|
||||
{ "BYTETABLE", INFOTOK_BYTETAB },
|
||||
{ "CODE", INFOTOK_CODE },
|
||||
{ "ADDRTABLE", INFOTOK_ADDRTAB },
|
||||
{ "BYTETABLE", INFOTOK_BYTETAB },
|
||||
{ "CODE", INFOTOK_CODE },
|
||||
{ "DBYTETABLE", INFOTOK_DBYTETAB },
|
||||
{ "DWORDTABLE", INFOTOK_DWORDTAB },
|
||||
{ "RTSTABLE", INFOTOK_RTSTAB },
|
||||
{ "DWORDTABLE", INFOTOK_DWORDTAB },
|
||||
{ "RTSTABLE", INFOTOK_RTSTAB },
|
||||
{ "SKIP", INFOTOK_SKIP },
|
||||
{ "TEXTTABLE", INFOTOK_TEXTTAB },
|
||||
{ "WORDTABLE", INFOTOK_WORDTAB },
|
||||
{ "TEXTTABLE", INFOTOK_TEXTTAB },
|
||||
{ "WORDTABLE", INFOTOK_WORDTAB },
|
||||
};
|
||||
|
||||
|
||||
/* Which values did we get? */
|
||||
enum {
|
||||
tNone = 0x00,
|
||||
tStart = 0x01,
|
||||
tEnd = 0x02,
|
||||
tType = 0x04,
|
||||
tNone = 0x00,
|
||||
tStart = 0x01,
|
||||
tEnd = 0x02,
|
||||
tType = 0x04,
|
||||
tName = 0x08,
|
||||
tComment= 0x10,
|
||||
tNeeded = (tStart | tEnd | tType)
|
||||
tNeeded = (tStart | tEnd | tType)
|
||||
};
|
||||
unsigned Attributes = tNone;
|
||||
|
||||
/* Locals - initialize to avoid gcc warnings */
|
||||
unsigned Start = 0;
|
||||
unsigned End = 0;
|
||||
unsigned char Type = 0;
|
||||
unsigned Start = 0;
|
||||
unsigned End = 0;
|
||||
unsigned char Type = 0;
|
||||
char* Name = 0;
|
||||
char* Comment = 0;
|
||||
unsigned MemberSize = 0;
|
||||
@@ -554,94 +554,94 @@ static void RangeSection (void)
|
||||
/* Look for section tokens */
|
||||
while (InfoTok != INFOTOK_RCURLY) {
|
||||
|
||||
/* Convert to special token */
|
||||
InfoSpecialToken (RangeDefs, ENTRY_COUNT (RangeDefs), "Range attribute");
|
||||
/* Convert to special token */
|
||||
InfoSpecialToken (RangeDefs, ENTRY_COUNT (RangeDefs), "Range attribute");
|
||||
|
||||
/* Look at the token */
|
||||
switch (InfoTok) {
|
||||
/* Look at the token */
|
||||
switch (InfoTok) {
|
||||
|
||||
case INFOTOK_COMMENT:
|
||||
case INFOTOK_COMMENT:
|
||||
AddAttr ("COMMENT", &Attributes, tComment);
|
||||
InfoNextTok ();
|
||||
InfoAssureStr ();
|
||||
if (InfoSVal[0] == '\0') {
|
||||
InfoError ("Comment may not be empty");
|
||||
}
|
||||
Comment = xstrdup (InfoSVal);
|
||||
InfoNextTok ();
|
||||
InfoAssureStr ();
|
||||
if (InfoSVal[0] == '\0') {
|
||||
InfoError ("Comment may not be empty");
|
||||
}
|
||||
Comment = xstrdup (InfoSVal);
|
||||
Attributes |= tComment;
|
||||
InfoNextTok ();
|
||||
break;
|
||||
InfoNextTok ();
|
||||
break;
|
||||
|
||||
case INFOTOK_END:
|
||||
case INFOTOK_END:
|
||||
AddAttr ("END", &Attributes, tEnd);
|
||||
InfoNextTok ();
|
||||
InfoAssureInt ();
|
||||
InfoRangeCheck (0x0000, 0xFFFF);
|
||||
End = InfoIVal;
|
||||
InfoNextTok ();
|
||||
break;
|
||||
InfoNextTok ();
|
||||
InfoAssureInt ();
|
||||
InfoRangeCheck (0x0000, 0xFFFF);
|
||||
End = InfoIVal;
|
||||
InfoNextTok ();
|
||||
break;
|
||||
|
||||
case INFOTOK_NAME:
|
||||
case INFOTOK_NAME:
|
||||
AddAttr ("NAME", &Attributes, tName);
|
||||
InfoNextTok ();
|
||||
InfoAssureStr ();
|
||||
if (InfoSVal[0] == '\0') {
|
||||
InfoError ("Name may not be empty");
|
||||
}
|
||||
Name = xstrdup (InfoSVal);
|
||||
InfoNextTok ();
|
||||
InfoAssureStr ();
|
||||
if (InfoSVal[0] == '\0') {
|
||||
InfoError ("Name may not be empty");
|
||||
}
|
||||
Name = xstrdup (InfoSVal);
|
||||
Attributes |= tName;
|
||||
InfoNextTok ();
|
||||
break;
|
||||
InfoNextTok ();
|
||||
break;
|
||||
|
||||
case INFOTOK_START:
|
||||
case INFOTOK_START:
|
||||
AddAttr ("START", &Attributes, tStart);
|
||||
InfoNextTok ();
|
||||
InfoAssureInt ();
|
||||
InfoRangeCheck (0x0000, 0xFFFF);
|
||||
Start = InfoIVal;
|
||||
InfoNextTok ();
|
||||
break;
|
||||
InfoNextTok ();
|
||||
InfoAssureInt ();
|
||||
InfoRangeCheck (0x0000, 0xFFFF);
|
||||
Start = InfoIVal;
|
||||
InfoNextTok ();
|
||||
break;
|
||||
|
||||
case INFOTOK_TYPE:
|
||||
case INFOTOK_TYPE:
|
||||
AddAttr ("TYPE", &Attributes, tType);
|
||||
InfoNextTok ();
|
||||
InfoSpecialToken (TypeDefs, ENTRY_COUNT (TypeDefs), "TYPE");
|
||||
switch (InfoTok) {
|
||||
case INFOTOK_ADDRTAB: Type = atAddrTab; MemberSize = 2; break;
|
||||
case INFOTOK_BYTETAB: Type = atByteTab; MemberSize = 1; break;
|
||||
case INFOTOK_CODE: Type = atCode; MemberSize = 1; break;
|
||||
InfoNextTok ();
|
||||
InfoSpecialToken (TypeDefs, ENTRY_COUNT (TypeDefs), "TYPE");
|
||||
switch (InfoTok) {
|
||||
case INFOTOK_ADDRTAB: Type = atAddrTab; MemberSize = 2; break;
|
||||
case INFOTOK_BYTETAB: Type = atByteTab; MemberSize = 1; break;
|
||||
case INFOTOK_CODE: Type = atCode; MemberSize = 1; break;
|
||||
case INFOTOK_DBYTETAB: Type = atDByteTab; MemberSize = 2; break;
|
||||
case INFOTOK_DWORDTAB: Type = atDWordTab; MemberSize = 4; break;
|
||||
case INFOTOK_RTSTAB: Type = atRtsTab; MemberSize = 2; break;
|
||||
case INFOTOK_DWORDTAB: Type = atDWordTab; MemberSize = 4; break;
|
||||
case INFOTOK_RTSTAB: Type = atRtsTab; MemberSize = 2; break;
|
||||
case INFOTOK_SKIP: Type = atSkip; MemberSize = 1; break;
|
||||
case INFOTOK_TEXTTAB: Type = atTextTab; MemberSize = 1; break;
|
||||
case INFOTOK_WORDTAB: Type = atWordTab; MemberSize = 2; break;
|
||||
}
|
||||
InfoNextTok ();
|
||||
break;
|
||||
case INFOTOK_TEXTTAB: Type = atTextTab; MemberSize = 1; break;
|
||||
case INFOTOK_WORDTAB: Type = atWordTab; MemberSize = 2; break;
|
||||
}
|
||||
InfoNextTok ();
|
||||
break;
|
||||
|
||||
default:
|
||||
Internal ("Unexpected token: %u", InfoTok);
|
||||
}
|
||||
}
|
||||
|
||||
/* Directive is followed by a semicolon */
|
||||
InfoConsumeSemi ();
|
||||
/* Directive is followed by a semicolon */
|
||||
InfoConsumeSemi ();
|
||||
|
||||
}
|
||||
|
||||
/* Did we get all required values? */
|
||||
if ((Attributes & tNeeded) != tNeeded) {
|
||||
InfoError ("Required values missing from this section");
|
||||
InfoError ("Required values missing from this section");
|
||||
}
|
||||
|
||||
/* Start must be less than end */
|
||||
if (Start > End) {
|
||||
InfoError ("Start value must not be greater than end value");
|
||||
InfoError ("Start value must not be greater than end value");
|
||||
}
|
||||
|
||||
/* Check the granularity */
|
||||
if (((End - Start + 1) % MemberSize) != 0) {
|
||||
InfoError ("Type of range needs a granularity of %u", MemberSize);
|
||||
InfoError ("Type of range needs a granularity of %u", MemberSize);
|
||||
}
|
||||
|
||||
/* Set the range */
|
||||
@@ -673,9 +673,9 @@ static void SegmentSection (void)
|
||||
/* Parse a segment section */
|
||||
{
|
||||
static const IdentTok LabelDefs[] = {
|
||||
{ "END", INFOTOK_END },
|
||||
{ "NAME", INFOTOK_NAME },
|
||||
{ "START", INFOTOK_START },
|
||||
{ "END", INFOTOK_END },
|
||||
{ "NAME", INFOTOK_NAME },
|
||||
{ "START", INFOTOK_START },
|
||||
};
|
||||
|
||||
/* Locals - initialize to avoid gcc warnings */
|
||||
@@ -692,61 +692,61 @@ static void SegmentSection (void)
|
||||
/* Look for section tokens */
|
||||
while (InfoTok != INFOTOK_RCURLY) {
|
||||
|
||||
/* Convert to special token */
|
||||
InfoSpecialToken (LabelDefs, ENTRY_COUNT (LabelDefs), "Segment attribute");
|
||||
/* Convert to special token */
|
||||
InfoSpecialToken (LabelDefs, ENTRY_COUNT (LabelDefs), "Segment attribute");
|
||||
|
||||
/* Look at the token */
|
||||
switch (InfoTok) {
|
||||
/* Look at the token */
|
||||
switch (InfoTok) {
|
||||
|
||||
case INFOTOK_END:
|
||||
InfoNextTok ();
|
||||
if (End >= 0) {
|
||||
InfoError ("Value already given");
|
||||
}
|
||||
InfoAssureInt ();
|
||||
InfoRangeCheck (0, 0xFFFF);
|
||||
End = InfoIVal;
|
||||
InfoNextTok ();
|
||||
break;
|
||||
case INFOTOK_END:
|
||||
InfoNextTok ();
|
||||
if (End >= 0) {
|
||||
InfoError ("Value already given");
|
||||
}
|
||||
InfoAssureInt ();
|
||||
InfoRangeCheck (0, 0xFFFF);
|
||||
End = InfoIVal;
|
||||
InfoNextTok ();
|
||||
break;
|
||||
|
||||
case INFOTOK_NAME:
|
||||
InfoNextTok ();
|
||||
if (Name) {
|
||||
InfoError ("Name already given");
|
||||
}
|
||||
InfoAssureStr ();
|
||||
Name = xstrdup (InfoSVal);
|
||||
InfoNextTok ();
|
||||
break;
|
||||
case INFOTOK_NAME:
|
||||
InfoNextTok ();
|
||||
if (Name) {
|
||||
InfoError ("Name already given");
|
||||
}
|
||||
InfoAssureStr ();
|
||||
Name = xstrdup (InfoSVal);
|
||||
InfoNextTok ();
|
||||
break;
|
||||
|
||||
case INFOTOK_START:
|
||||
InfoNextTok ();
|
||||
if (Start >= 0) {
|
||||
InfoError ("Value already given");
|
||||
}
|
||||
InfoAssureInt ();
|
||||
InfoRangeCheck (0, 0xFFFF);
|
||||
Start = InfoIVal;
|
||||
InfoNextTok ();
|
||||
break;
|
||||
case INFOTOK_START:
|
||||
InfoNextTok ();
|
||||
if (Start >= 0) {
|
||||
InfoError ("Value already given");
|
||||
}
|
||||
InfoAssureInt ();
|
||||
InfoRangeCheck (0, 0xFFFF);
|
||||
Start = InfoIVal;
|
||||
InfoNextTok ();
|
||||
break;
|
||||
|
||||
default:
|
||||
Internal ("Unexpected token: %u", InfoTok);
|
||||
}
|
||||
}
|
||||
|
||||
/* Directive is followed by a semicolon */
|
||||
InfoConsumeSemi ();
|
||||
/* Directive is followed by a semicolon */
|
||||
InfoConsumeSemi ();
|
||||
}
|
||||
|
||||
/* Did we get the necessary data, and is it correct? */
|
||||
if (Name == 0 || Name[0] == '\0') {
|
||||
InfoError ("Segment name is missing");
|
||||
InfoError ("Segment name is missing");
|
||||
}
|
||||
if (End < 0) {
|
||||
InfoError ("End address is missing");
|
||||
}
|
||||
if (Start < 0) {
|
||||
InfoError ("Start address is missing");
|
||||
InfoError ("Start address is missing");
|
||||
}
|
||||
if (Start == End) {
|
||||
InfoError ("Segment is empty");
|
||||
@@ -777,35 +777,35 @@ static void InfoParse (void)
|
||||
{
|
||||
static const IdentTok Globals[] = {
|
||||
{ "ASMINC", INFOTOK_ASMINC },
|
||||
{ "GLOBAL", INFOTOK_GLOBAL },
|
||||
{ "LABEL", INFOTOK_LABEL },
|
||||
{ "RANGE", INFOTOK_RANGE },
|
||||
{ "GLOBAL", INFOTOK_GLOBAL },
|
||||
{ "LABEL", INFOTOK_LABEL },
|
||||
{ "RANGE", INFOTOK_RANGE },
|
||||
{ "SEGMENT", INFOTOK_SEGMENT },
|
||||
};
|
||||
|
||||
while (InfoTok != INFOTOK_EOF) {
|
||||
|
||||
/* Convert an identifier into a token */
|
||||
InfoSpecialToken (Globals, ENTRY_COUNT (Globals), "Config directive");
|
||||
/* Convert an identifier into a token */
|
||||
InfoSpecialToken (Globals, ENTRY_COUNT (Globals), "Config directive");
|
||||
|
||||
/* Check the token */
|
||||
switch (InfoTok) {
|
||||
/* Check the token */
|
||||
switch (InfoTok) {
|
||||
|
||||
case INFOTOK_ASMINC:
|
||||
AsmIncSection ();
|
||||
break;
|
||||
|
||||
case INFOTOK_GLOBAL:
|
||||
GlobalSection ();
|
||||
break;
|
||||
case INFOTOK_GLOBAL:
|
||||
GlobalSection ();
|
||||
break;
|
||||
|
||||
case INFOTOK_LABEL:
|
||||
LabelSection ();
|
||||
break;
|
||||
case INFOTOK_LABEL:
|
||||
LabelSection ();
|
||||
break;
|
||||
|
||||
case INFOTOK_RANGE:
|
||||
RangeSection ();
|
||||
break;
|
||||
case INFOTOK_RANGE:
|
||||
RangeSection ();
|
||||
break;
|
||||
|
||||
case INFOTOK_SEGMENT:
|
||||
SegmentSection ();
|
||||
@@ -813,10 +813,10 @@ static void InfoParse (void)
|
||||
|
||||
default:
|
||||
Internal ("Unexpected token: %u", InfoTok);
|
||||
}
|
||||
}
|
||||
|
||||
/* Semicolon expected */
|
||||
InfoConsumeSemi ();
|
||||
/* Semicolon expected */
|
||||
InfoConsumeSemi ();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -39,7 +39,7 @@
|
||||
|
||||
|
||||
/*****************************************************************************/
|
||||
/* Code */
|
||||
/* Code */
|
||||
/*****************************************************************************/
|
||||
|
||||
|
||||
|
||||
@@ -52,7 +52,7 @@
|
||||
|
||||
|
||||
/*****************************************************************************/
|
||||
/* Data */
|
||||
/* Data */
|
||||
/*****************************************************************************/
|
||||
|
||||
|
||||
@@ -63,7 +63,7 @@ static const char* SymTab[0x10000];
|
||||
|
||||
|
||||
/*****************************************************************************/
|
||||
/* Code */
|
||||
/* Code */
|
||||
/*****************************************************************************/
|
||||
|
||||
|
||||
@@ -88,14 +88,14 @@ static void AddLabel (unsigned Addr, attr_t Attr, const char* Name)
|
||||
|
||||
/* Must not have two symbols for one address */
|
||||
if (ExistingAttr != atNoLabel) {
|
||||
/* Allow redefinition if identical. Beware: Unnamed labels don't
|
||||
/* Allow redefinition if identical. Beware: Unnamed labels don't
|
||||
* have a name (you guessed that, didn't you?).
|
||||
*/
|
||||
if (ExistingAttr == Attr &&
|
||||
if (ExistingAttr == Attr &&
|
||||
((Name == 0 && SymTab[Addr] == 0) || strcmp (SymTab[Addr], Name) == 0)) {
|
||||
return;
|
||||
}
|
||||
Error ("Duplicate label for address $%04X: %s/%s", Addr, SymTab[Addr], Name);
|
||||
return;
|
||||
}
|
||||
Error ("Duplicate label for address $%04X: %s/%s", Addr, SymTab[Addr], Name);
|
||||
}
|
||||
|
||||
/* Create a new label (xstrdup will return NULL if input NULL) */
|
||||
@@ -138,13 +138,13 @@ void AddDepLabel (unsigned Addr, attr_t Attr, const char* BaseName, unsigned Off
|
||||
{
|
||||
/* Allocate memory for the dependent label name */
|
||||
unsigned NameLen = strlen (BaseName);
|
||||
char* DepName = xmalloc (NameLen + 7); /* "+$ABCD\0" */
|
||||
char* DepName = xmalloc (NameLen + 7); /* "+$ABCD\0" */
|
||||
|
||||
/* Create the new name in the buffer */
|
||||
if (UseHexOffs) {
|
||||
sprintf (DepName, "%s+$%02X", BaseName, Offs);
|
||||
sprintf (DepName, "%s+$%02X", BaseName, Offs);
|
||||
} else {
|
||||
sprintf (DepName, "%s+%u", BaseName, Offs);
|
||||
sprintf (DepName, "%s+%u", BaseName, Offs);
|
||||
}
|
||||
|
||||
/* Define the labels */
|
||||
@@ -167,28 +167,28 @@ static void AddLabelRange (unsigned Addr, attr_t Attr,
|
||||
|
||||
/* Define dependent labels if necessary */
|
||||
if (Count > 1) {
|
||||
unsigned Offs;
|
||||
unsigned Offs;
|
||||
|
||||
/* Setup the format string */
|
||||
const char* Format = UseHexOffs? "$%02X" : "%u";
|
||||
|
||||
/* Allocate memory for the dependent label names */
|
||||
unsigned NameLen = strlen (Name);
|
||||
char* DepName = xmalloc (NameLen + 7); /* "+$ABCD" */
|
||||
char* DepOffs = DepName + NameLen + 1;
|
||||
/* Allocate memory for the dependent label names */
|
||||
unsigned NameLen = strlen (Name);
|
||||
char* DepName = xmalloc (NameLen + 7); /* "+$ABCD" */
|
||||
char* DepOffs = DepName + NameLen + 1;
|
||||
|
||||
/* Copy the original name into the buffer */
|
||||
memcpy (DepName, Name, NameLen);
|
||||
DepName[NameLen] = '+';
|
||||
/* Copy the original name into the buffer */
|
||||
memcpy (DepName, Name, NameLen);
|
||||
DepName[NameLen] = '+';
|
||||
|
||||
/* Define the labels */
|
||||
for (Offs = 1; Offs < Count; ++Offs) {
|
||||
sprintf (DepOffs, Format, Offs);
|
||||
AddLabel (Addr + Offs, Attr | atDepLabel, DepName);
|
||||
}
|
||||
/* Define the labels */
|
||||
for (Offs = 1; Offs < Count; ++Offs) {
|
||||
sprintf (DepOffs, Format, Offs);
|
||||
AddLabel (Addr + Offs, Attr | atDepLabel, DepName);
|
||||
}
|
||||
|
||||
/* Free the name buffer */
|
||||
xfree (DepName);
|
||||
/* Free the name buffer */
|
||||
xfree (DepName);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -43,7 +43,7 @@
|
||||
|
||||
|
||||
/*****************************************************************************/
|
||||
/* Code */
|
||||
/* Code */
|
||||
/*****************************************************************************/
|
||||
|
||||
|
||||
|
||||
230
src/da65/main.c
230
src/da65/main.c
@@ -1,8 +1,8 @@
|
||||
/*****************************************************************************/
|
||||
/* */
|
||||
/* main.c */
|
||||
/* main.c */
|
||||
/* */
|
||||
/* Main program for the da65 disassembler */
|
||||
/* Main program for the da65 disassembler */
|
||||
/* */
|
||||
/* */
|
||||
/* */
|
||||
@@ -64,7 +64,7 @@
|
||||
|
||||
|
||||
/*****************************************************************************/
|
||||
/* Code */
|
||||
/* Code */
|
||||
/*****************************************************************************/
|
||||
|
||||
|
||||
@@ -124,20 +124,20 @@ static unsigned long CvtNumber (const char* Arg, const char* Number)
|
||||
*/
|
||||
{
|
||||
unsigned long Val;
|
||||
int Converted;
|
||||
int Converted;
|
||||
char BoundsCheck;
|
||||
|
||||
/* Convert */
|
||||
if (*Number == '$') {
|
||||
++Number;
|
||||
Converted = sscanf (Number, "%lx%c", &Val, &BoundsCheck);
|
||||
++Number;
|
||||
Converted = sscanf (Number, "%lx%c", &Val, &BoundsCheck);
|
||||
} else {
|
||||
Converted = sscanf (Number, "%li%c", (long*)&Val, &BoundsCheck);
|
||||
Converted = sscanf (Number, "%li%c", (long*)&Val, &BoundsCheck);
|
||||
}
|
||||
|
||||
/* Check if we do really have a number */
|
||||
if (Converted != 1) {
|
||||
Error ("Invalid number given in argument: %s\n", Arg);
|
||||
Error ("Invalid number given in argument: %s\n", Arg);
|
||||
}
|
||||
|
||||
/* Return the result */
|
||||
@@ -217,7 +217,7 @@ static void OptCPU (const char* Opt attribute ((unused)), const char* Arg)
|
||||
|
||||
|
||||
static void OptDebugInfo (const char* Opt attribute ((unused)),
|
||||
const char* Arg attribute ((unused)))
|
||||
const char* Arg attribute ((unused)))
|
||||
/* Add debug info to the object file */
|
||||
{
|
||||
DebugInfo = 1;
|
||||
@@ -226,7 +226,7 @@ static void OptDebugInfo (const char* Opt attribute ((unused)),
|
||||
|
||||
|
||||
static void OptFormFeeds (const char* Opt attribute ((unused)),
|
||||
const char* Arg attribute ((unused)))
|
||||
const char* Arg attribute ((unused)))
|
||||
/* Add form feeds to the output */
|
||||
{
|
||||
FormFeeds = 1;
|
||||
@@ -235,7 +235,7 @@ static void OptFormFeeds (const char* Opt attribute ((unused)),
|
||||
|
||||
|
||||
static void OptHelp (const char* Opt attribute ((unused)),
|
||||
const char* Arg attribute ((unused)))
|
||||
const char* Arg attribute ((unused)))
|
||||
/* Print usage information and exit */
|
||||
{
|
||||
Usage ();
|
||||
@@ -245,7 +245,7 @@ static void OptHelp (const char* Opt attribute ((unused)),
|
||||
|
||||
|
||||
static void OptHexOffs (const char* Opt attribute ((unused)),
|
||||
const char* Arg attribute ((unused)))
|
||||
const char* Arg attribute ((unused)))
|
||||
/* Handle the --hexoffs option */
|
||||
{
|
||||
UseHexOffs = 1;
|
||||
@@ -327,7 +327,7 @@ static void OptTextColumn (const char* Opt, const char* Arg)
|
||||
|
||||
|
||||
static void OptVerbose (const char* Opt attribute ((unused)),
|
||||
const char* Arg attribute ((unused)))
|
||||
const char* Arg attribute ((unused)))
|
||||
/* Increase verbosity */
|
||||
{
|
||||
++Verbosity;
|
||||
@@ -336,7 +336,7 @@ static void OptVerbose (const char* Opt attribute ((unused)),
|
||||
|
||||
|
||||
static void OptVersion (const char* Opt attribute ((unused)),
|
||||
const char* Arg attribute ((unused)))
|
||||
const char* Arg attribute ((unused)))
|
||||
/* Print the disassembler version */
|
||||
{
|
||||
fprintf (stderr, "da65 V%s\n", GetVersionAsString ());
|
||||
@@ -364,7 +364,7 @@ static void OneOpcode (unsigned RemainingBytes)
|
||||
if (Comment) {
|
||||
UserComment (Comment);
|
||||
}
|
||||
DefLabel (GetLabelName (PC));
|
||||
DefLabel (GetLabelName (PC));
|
||||
}
|
||||
|
||||
/* Check...
|
||||
@@ -374,33 +374,33 @@ static void OneOpcode (unsigned RemainingBytes)
|
||||
* If any of these conditions is false, switch to data mode.
|
||||
*/
|
||||
if (Style == atDefault) {
|
||||
if (D->Size > RemainingBytes) {
|
||||
Style = atIllegal;
|
||||
MarkAddr (PC, Style);
|
||||
} else if (D->Flags & flIllegal) {
|
||||
Style = atIllegal;
|
||||
MarkAddr (PC, Style);
|
||||
} else {
|
||||
unsigned I;
|
||||
for (I = 1; I < D->Size; ++I) {
|
||||
if (HaveLabel (PC+I) || HaveSegmentChange (PC+I)) {
|
||||
Style = atIllegal;
|
||||
MarkAddr (PC, Style);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (D->Size > RemainingBytes) {
|
||||
Style = atIllegal;
|
||||
MarkAddr (PC, Style);
|
||||
} else if (D->Flags & flIllegal) {
|
||||
Style = atIllegal;
|
||||
MarkAddr (PC, Style);
|
||||
} else {
|
||||
unsigned I;
|
||||
for (I = 1; I < D->Size; ++I) {
|
||||
if (HaveLabel (PC+I) || HaveSegmentChange (PC+I)) {
|
||||
Style = atIllegal;
|
||||
MarkAddr (PC, Style);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* Disassemble the line */
|
||||
switch (Style) {
|
||||
|
||||
case atDefault:
|
||||
D->Handler (D);
|
||||
PC += D->Size;
|
||||
break;
|
||||
case atDefault:
|
||||
D->Handler (D);
|
||||
PC += D->Size;
|
||||
break;
|
||||
|
||||
case atCode:
|
||||
case atCode:
|
||||
/* Beware: If we don't have enough bytes left to disassemble the
|
||||
* following insn, fall through to byte mode.
|
||||
*/
|
||||
@@ -417,42 +417,42 @@ static void OneOpcode (unsigned RemainingBytes)
|
||||
}
|
||||
/* FALLTHROUGH */
|
||||
|
||||
case atByteTab:
|
||||
ByteTable ();
|
||||
break;
|
||||
case atByteTab:
|
||||
ByteTable ();
|
||||
break;
|
||||
|
||||
case atDByteTab:
|
||||
DByteTable ();
|
||||
break;
|
||||
|
||||
case atWordTab:
|
||||
WordTable ();
|
||||
break;
|
||||
case atWordTab:
|
||||
WordTable ();
|
||||
break;
|
||||
|
||||
case atDWordTab:
|
||||
DWordTable ();
|
||||
break;
|
||||
case atDWordTab:
|
||||
DWordTable ();
|
||||
break;
|
||||
|
||||
case atAddrTab:
|
||||
AddrTable ();
|
||||
break;
|
||||
case atAddrTab:
|
||||
AddrTable ();
|
||||
break;
|
||||
|
||||
case atRtsTab:
|
||||
RtsTable ();
|
||||
break;
|
||||
case atRtsTab:
|
||||
RtsTable ();
|
||||
break;
|
||||
|
||||
case atTextTab:
|
||||
TextTable ();
|
||||
break;
|
||||
case atTextTab:
|
||||
TextTable ();
|
||||
break;
|
||||
|
||||
case atSkip:
|
||||
++PC;
|
||||
break;
|
||||
|
||||
default:
|
||||
DataByteLine (1);
|
||||
++PC;
|
||||
break;
|
||||
default:
|
||||
DataByteLine (1);
|
||||
++PC;
|
||||
break;
|
||||
|
||||
}
|
||||
}
|
||||
@@ -466,7 +466,7 @@ static void OnePass (void)
|
||||
|
||||
/* Disassemble until nothing left */
|
||||
while ((Count = GetRemainingBytes()) > 0) {
|
||||
OneOpcode (Count);
|
||||
OneOpcode (Count);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -501,19 +501,19 @@ int main (int argc, char* argv [])
|
||||
{ "--bytes-per-line", 1, OptBytesPerLine },
|
||||
{ "--comment-column", 1, OptCommentColumn },
|
||||
{ "--comments", 1, OptComments },
|
||||
{ "--cpu", 1, OptCPU },
|
||||
{ "--debug-info", 0, OptDebugInfo },
|
||||
{ "--formfeeds", 0, OptFormFeeds },
|
||||
{ "--help", 0, OptHelp },
|
||||
{ "--hexoffs", 0, OptHexOffs },
|
||||
{ "--info", 1, OptInfo },
|
||||
{ "--cpu", 1, OptCPU },
|
||||
{ "--debug-info", 0, OptDebugInfo },
|
||||
{ "--formfeeds", 0, OptFormFeeds },
|
||||
{ "--help", 0, OptHelp },
|
||||
{ "--hexoffs", 0, OptHexOffs },
|
||||
{ "--info", 1, OptInfo },
|
||||
{ "--label-break", 1, OptLabelBreak },
|
||||
{ "--mnemonic-column", 1, OptMnemonicColumn },
|
||||
{ "--pagelength", 1, OptPageLength },
|
||||
{ "--start-addr", 1, OptStartAddr },
|
||||
{ "--pagelength", 1, OptPageLength },
|
||||
{ "--start-addr", 1, OptStartAddr },
|
||||
{ "--text-column", 1, OptTextColumn },
|
||||
{ "--verbose", 0, OptVerbose },
|
||||
{ "--version", 0, OptVersion },
|
||||
{ "--verbose", 0, OptVerbose },
|
||||
{ "--version", 0, OptVersion },
|
||||
};
|
||||
|
||||
unsigned I;
|
||||
@@ -526,63 +526,63 @@ int main (int argc, char* argv [])
|
||||
I = 1;
|
||||
while (I < ArgCount) {
|
||||
|
||||
/* Get the argument */
|
||||
const char* Arg = ArgVec[I];
|
||||
/* Get the argument */
|
||||
const char* Arg = ArgVec[I];
|
||||
|
||||
/* Check for an option */
|
||||
if (Arg [0] == '-') {
|
||||
switch (Arg [1]) {
|
||||
/* Check for an option */
|
||||
if (Arg [0] == '-') {
|
||||
switch (Arg [1]) {
|
||||
|
||||
case '-':
|
||||
LongOption (&I, OptTab, sizeof(OptTab)/sizeof(OptTab[0]));
|
||||
break;
|
||||
case '-':
|
||||
LongOption (&I, OptTab, sizeof(OptTab)/sizeof(OptTab[0]));
|
||||
break;
|
||||
|
||||
case 'g':
|
||||
OptDebugInfo (Arg, 0);
|
||||
break;
|
||||
case 'g':
|
||||
OptDebugInfo (Arg, 0);
|
||||
break;
|
||||
|
||||
case 'h':
|
||||
OptHelp (Arg, 0);
|
||||
break;
|
||||
case 'h':
|
||||
OptHelp (Arg, 0);
|
||||
break;
|
||||
|
||||
case 'i':
|
||||
OptInfo (Arg, GetArg (&I, 2));
|
||||
break;
|
||||
case 'i':
|
||||
OptInfo (Arg, GetArg (&I, 2));
|
||||
break;
|
||||
|
||||
case 'o':
|
||||
OutFile = GetArg (&I, 2);
|
||||
break;
|
||||
case 'o':
|
||||
OutFile = GetArg (&I, 2);
|
||||
break;
|
||||
|
||||
case 'v':
|
||||
OptVerbose (Arg, 0);
|
||||
break;
|
||||
case 'v':
|
||||
OptVerbose (Arg, 0);
|
||||
break;
|
||||
|
||||
case 'S':
|
||||
OptStartAddr (Arg, GetArg (&I, 2));
|
||||
break;
|
||||
case 'S':
|
||||
OptStartAddr (Arg, GetArg (&I, 2));
|
||||
break;
|
||||
|
||||
case 'V':
|
||||
OptVersion (Arg, 0);
|
||||
break;
|
||||
case 'V':
|
||||
OptVersion (Arg, 0);
|
||||
break;
|
||||
|
||||
default:
|
||||
UnknownOption (Arg);
|
||||
break;
|
||||
default:
|
||||
UnknownOption (Arg);
|
||||
break;
|
||||
|
||||
}
|
||||
} else {
|
||||
/* Filename. Check if we already had one */
|
||||
if (InFile) {
|
||||
fprintf (stderr, "%s: Don't know what to do with `%s'\n",
|
||||
ProgName, Arg);
|
||||
exit (EXIT_FAILURE);
|
||||
} else {
|
||||
InFile = Arg;
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
/* Filename. Check if we already had one */
|
||||
if (InFile) {
|
||||
fprintf (stderr, "%s: Don't know what to do with `%s'\n",
|
||||
ProgName, Arg);
|
||||
exit (EXIT_FAILURE);
|
||||
} else {
|
||||
InFile = Arg;
|
||||
}
|
||||
}
|
||||
|
||||
/* Next argument */
|
||||
++I;
|
||||
/* Next argument */
|
||||
++I;
|
||||
}
|
||||
|
||||
/* Try to read the info file */
|
||||
@@ -590,7 +590,7 @@ int main (int argc, char* argv [])
|
||||
|
||||
/* Must have an input file */
|
||||
if (InFile == 0) {
|
||||
AbEnd ("No input file");
|
||||
AbEnd ("No input file");
|
||||
}
|
||||
|
||||
/* Check the formatting options for reasonable values. Note: We will not
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/*****************************************************************************/
|
||||
/* */
|
||||
/* opc6502.c */
|
||||
/* opc6502.c */
|
||||
/* */
|
||||
/* 6502 opcode description table */
|
||||
/* */
|
||||
@@ -40,7 +40,7 @@
|
||||
|
||||
|
||||
/*****************************************************************************/
|
||||
/* Data */
|
||||
/* Data */
|
||||
/*****************************************************************************/
|
||||
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/*****************************************************************************/
|
||||
/* */
|
||||
/* opc6502.h */
|
||||
/* opc6502.h */
|
||||
/* */
|
||||
/* 6502 opcode description table */
|
||||
/* */
|
||||
@@ -43,7 +43,7 @@
|
||||
|
||||
|
||||
/*****************************************************************************/
|
||||
/* Data */
|
||||
/* Data */
|
||||
/*****************************************************************************/
|
||||
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/*****************************************************************************/
|
||||
/* */
|
||||
/* opc6502.c */
|
||||
/* opc6502.c */
|
||||
/* */
|
||||
/* 6502 opcode description table with NMOS illegals */
|
||||
/* */
|
||||
@@ -40,7 +40,7 @@
|
||||
|
||||
|
||||
/*****************************************************************************/
|
||||
/* Data */
|
||||
/* Data */
|
||||
/*****************************************************************************/
|
||||
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/*****************************************************************************/
|
||||
/* */
|
||||
/* opc6502.h */
|
||||
/* opc6502.h */
|
||||
/* */
|
||||
/* 6502 opcode description table with NMOS illegals */
|
||||
/* */
|
||||
@@ -43,7 +43,7 @@
|
||||
|
||||
|
||||
/*****************************************************************************/
|
||||
/* Data */
|
||||
/* Data */
|
||||
/*****************************************************************************/
|
||||
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/*****************************************************************************/
|
||||
/* */
|
||||
/* opc65816.c */
|
||||
/* opc65816.c */
|
||||
/* */
|
||||
/* 65816 opcode description table */
|
||||
/* */
|
||||
@@ -40,7 +40,7 @@
|
||||
|
||||
|
||||
/*****************************************************************************/
|
||||
/* Data */
|
||||
/* Data */
|
||||
/*****************************************************************************/
|
||||
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/*****************************************************************************/
|
||||
/* */
|
||||
/* opc65816.h */
|
||||
/* opc65816.h */
|
||||
/* */
|
||||
/* 65816 opcode description table */
|
||||
/* */
|
||||
@@ -43,7 +43,7 @@
|
||||
|
||||
|
||||
/*****************************************************************************/
|
||||
/* Data */
|
||||
/* Data */
|
||||
/*****************************************************************************/
|
||||
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/*****************************************************************************/
|
||||
/* */
|
||||
/* opc65c02.c */
|
||||
/* opc65c02.c */
|
||||
/* */
|
||||
/* 65C02 opcode description table */
|
||||
/* */
|
||||
@@ -40,7 +40,7 @@
|
||||
|
||||
|
||||
/*****************************************************************************/
|
||||
/* Data */
|
||||
/* Data */
|
||||
/*****************************************************************************/
|
||||
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/*****************************************************************************/
|
||||
/* */
|
||||
/* opc65c02.h */
|
||||
/* opc65c02.h */
|
||||
/* */
|
||||
/* 65C02 opcode description table */
|
||||
/* */
|
||||
@@ -43,7 +43,7 @@
|
||||
|
||||
|
||||
/*****************************************************************************/
|
||||
/* Data */
|
||||
/* Data */
|
||||
/*****************************************************************************/
|
||||
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/*****************************************************************************/
|
||||
/* */
|
||||
/* opc65sc02.c */
|
||||
/* opc65sc02.c */
|
||||
/* */
|
||||
/* 65SC02 opcode description table */
|
||||
/* */
|
||||
@@ -40,7 +40,7 @@
|
||||
|
||||
|
||||
/*****************************************************************************/
|
||||
/* Data */
|
||||
/* Data */
|
||||
/*****************************************************************************/
|
||||
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/*****************************************************************************/
|
||||
/* */
|
||||
/* opc65sc02.h */
|
||||
/* opc65sc02.h */
|
||||
/* */
|
||||
/* 65SC02 opcode description table */
|
||||
/* */
|
||||
@@ -43,7 +43,7 @@
|
||||
|
||||
|
||||
/*****************************************************************************/
|
||||
/* Data */
|
||||
/* Data */
|
||||
/*****************************************************************************/
|
||||
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/*****************************************************************************/
|
||||
/* */
|
||||
/* opcdesc.h */
|
||||
/* opcdesc.h */
|
||||
/* */
|
||||
/* Disassembler description for one opcode */
|
||||
/* */
|
||||
@@ -39,7 +39,7 @@
|
||||
|
||||
|
||||
/*****************************************************************************/
|
||||
/* Data */
|
||||
/* Data */
|
||||
/*****************************************************************************/
|
||||
|
||||
|
||||
@@ -47,10 +47,10 @@
|
||||
/* Constants for Flags */
|
||||
enum {
|
||||
flNone = 0x00, /* No flags given */
|
||||
flNoLabel = 0x00, /* Don't use a label */
|
||||
flGenLabel = 0x01, /* Generate a label */
|
||||
flUseLabel = 0x02, /* Use a label if there is one */
|
||||
flLabel = flUseLabel|flGenLabel, /* Generate and use a label */
|
||||
flNoLabel = 0x00, /* Don't use a label */
|
||||
flGenLabel = 0x01, /* Generate a label */
|
||||
flUseLabel = 0x02, /* Use a label if there is one */
|
||||
flLabel = flUseLabel|flGenLabel, /* Generate and use a label */
|
||||
flIllegal = 0x10, /* Illegal instruction */
|
||||
flAbsOverride = 0x20, /* Need a: override */
|
||||
flFarOverride = 0x40 /* Need f: override */
|
||||
@@ -64,10 +64,10 @@ typedef void (*OpcHandler) (const OpcDesc*);
|
||||
|
||||
/* Description for one opcode */
|
||||
struct OpcDesc {
|
||||
char Mnemo [6]; /* Mnemonic */
|
||||
unsigned char Size; /* Size of this command */
|
||||
unsigned char Flags; /* Flags */
|
||||
OpcHandler Handler; /* Handler routine */
|
||||
char Mnemo [6]; /* Mnemonic */
|
||||
unsigned char Size; /* Size of this command */
|
||||
unsigned char Flags; /* Flags */
|
||||
OpcHandler Handler; /* Handler routine */
|
||||
};
|
||||
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/*****************************************************************************/
|
||||
/* */
|
||||
/* opchuc6280.c */
|
||||
/* opchuc6280.c */
|
||||
/* */
|
||||
/* HuC6280 opcode description table */
|
||||
/* */
|
||||
@@ -40,7 +40,7 @@
|
||||
|
||||
|
||||
/*****************************************************************************/
|
||||
/* Data */
|
||||
/* Data */
|
||||
/*****************************************************************************/
|
||||
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/*****************************************************************************/
|
||||
/* */
|
||||
/* opchuc6280.h */
|
||||
/* opchuc6280.h */
|
||||
/* */
|
||||
/* HuC6280 opcode description table */
|
||||
/* */
|
||||
@@ -43,7 +43,7 @@
|
||||
|
||||
|
||||
/*****************************************************************************/
|
||||
/* Data */
|
||||
/* Data */
|
||||
/*****************************************************************************/
|
||||
|
||||
|
||||
|
||||
@@ -41,7 +41,7 @@
|
||||
|
||||
|
||||
/*****************************************************************************/
|
||||
/* Data */
|
||||
/* Data */
|
||||
/*****************************************************************************/
|
||||
|
||||
|
||||
|
||||
@@ -44,7 +44,7 @@
|
||||
|
||||
|
||||
/*****************************************************************************/
|
||||
/* Data */
|
||||
/* Data */
|
||||
/*****************************************************************************/
|
||||
|
||||
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
/*****************************************************************************/
|
||||
/* */
|
||||
/* opctable.c */
|
||||
/* opctable.c */
|
||||
/* */
|
||||
/* Disassembler opcode description table */
|
||||
/* Disassembler opcode description table */
|
||||
/* */
|
||||
/* */
|
||||
/* */
|
||||
@@ -47,7 +47,7 @@
|
||||
|
||||
|
||||
/*****************************************************************************/
|
||||
/* Data */
|
||||
/* Data */
|
||||
/*****************************************************************************/
|
||||
|
||||
|
||||
@@ -58,7 +58,7 @@ const OpcDesc* OpcTable = OpcTable_6502;
|
||||
|
||||
|
||||
/*****************************************************************************/
|
||||
/* Code */
|
||||
/* Code */
|
||||
/*****************************************************************************/
|
||||
|
||||
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
/*****************************************************************************/
|
||||
/* */
|
||||
/* opctable.h */
|
||||
/* opctable.h */
|
||||
/* */
|
||||
/* Disassembler opcode description table */
|
||||
/* Disassembler opcode description table */
|
||||
/* */
|
||||
/* */
|
||||
/* */
|
||||
@@ -47,7 +47,7 @@
|
||||
|
||||
|
||||
/*****************************************************************************/
|
||||
/* Data */
|
||||
/* Data */
|
||||
/*****************************************************************************/
|
||||
|
||||
|
||||
@@ -58,7 +58,7 @@ extern const OpcDesc* OpcTable;
|
||||
|
||||
|
||||
/*****************************************************************************/
|
||||
/* Code */
|
||||
/* Code */
|
||||
/*****************************************************************************/
|
||||
|
||||
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
/*****************************************************************************/
|
||||
/* */
|
||||
/* output.c */
|
||||
/* output.c */
|
||||
/* */
|
||||
/* Disassembler output routines */
|
||||
/* Disassembler output routines */
|
||||
/* */
|
||||
/* */
|
||||
/* */
|
||||
@@ -53,20 +53,20 @@
|
||||
|
||||
|
||||
/*****************************************************************************/
|
||||
/* Data */
|
||||
/* Data */
|
||||
/*****************************************************************************/
|
||||
|
||||
|
||||
|
||||
static FILE* F = 0; /* Output stream */
|
||||
static unsigned Col = 1; /* Current column */
|
||||
static unsigned Line = 0; /* Current line on page */
|
||||
static unsigned Page = 1; /* Current output page */
|
||||
static FILE* F = 0; /* Output stream */
|
||||
static unsigned Col = 1; /* Current column */
|
||||
static unsigned Line = 0; /* Current line on page */
|
||||
static unsigned Page = 1; /* Current output page */
|
||||
|
||||
|
||||
|
||||
/*****************************************************************************/
|
||||
/* Code */
|
||||
/* Code */
|
||||
/*****************************************************************************/
|
||||
|
||||
|
||||
@@ -75,14 +75,14 @@ static void PageHeader (void)
|
||||
/* Print a page header */
|
||||
{
|
||||
fprintf (F,
|
||||
"; da65 V%s\n"
|
||||
"; da65 V%s\n"
|
||||
"; Created: %s\n"
|
||||
"; Input file: %s\n"
|
||||
"; Page: %u\n\n",
|
||||
GetVersionAsString (),
|
||||
"; Input file: %s\n"
|
||||
"; Page: %u\n\n",
|
||||
GetVersionAsString (),
|
||||
Now,
|
||||
InFile,
|
||||
Page);
|
||||
InFile,
|
||||
Page);
|
||||
}
|
||||
|
||||
|
||||
@@ -112,7 +112,7 @@ void CloseOutput (void)
|
||||
/* Close the output file */
|
||||
{
|
||||
if (F != stdout && fclose (F) != 0) {
|
||||
Error ("Error closing output file: %s", strerror (errno));
|
||||
Error ("Error closing output file: %s", strerror (errno));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -122,10 +122,10 @@ void Output (const char* Format, ...)
|
||||
/* Write to the output file */
|
||||
{
|
||||
if (Pass == PassCount) {
|
||||
va_list ap;
|
||||
va_start (ap, Format);
|
||||
Col += vfprintf (F, Format, ap);
|
||||
va_end (ap);
|
||||
va_list ap;
|
||||
va_start (ap, Format);
|
||||
Col += vfprintf (F, Format, ap);
|
||||
va_end (ap);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -135,10 +135,10 @@ void Indent (unsigned N)
|
||||
/* Make sure the current line column is at position N (zero based) */
|
||||
{
|
||||
if (Pass == PassCount) {
|
||||
while (Col < N) {
|
||||
fputc (' ', F);
|
||||
++Col;
|
||||
}
|
||||
while (Col < N) {
|
||||
fputc (' ', F);
|
||||
++Col;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -148,16 +148,16 @@ void LineFeed (void)
|
||||
/* Add a linefeed to the output file */
|
||||
{
|
||||
if (Pass == PassCount) {
|
||||
fputc ('\n', F);
|
||||
if (PageLength > 0 && ++Line >= PageLength) {
|
||||
if (FormFeeds) {
|
||||
fputc ('\f', F);
|
||||
}
|
||||
++Page;
|
||||
PageHeader ();
|
||||
Line = 5;
|
||||
}
|
||||
Col = 1;
|
||||
fputc ('\n', F);
|
||||
if (PageLength > 0 && ++Line >= PageLength) {
|
||||
if (FormFeeds) {
|
||||
fputc ('\f', F);
|
||||
}
|
||||
++Page;
|
||||
PageHeader ();
|
||||
Line = 5;
|
||||
}
|
||||
Col = 1;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -171,7 +171,7 @@ void DefLabel (const char* Name)
|
||||
* the opcode column, start a new line.
|
||||
*/
|
||||
if (Col > LBreak+2 || Col > MCol) {
|
||||
LineFeed ();
|
||||
LineFeed ();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -249,11 +249,11 @@ void DataByteLine (unsigned ByteCount)
|
||||
Output (".byte");
|
||||
Indent (ACol);
|
||||
for (I = 0; I < ByteCount; ++I) {
|
||||
if (I > 0) {
|
||||
Output (",$%02X", CodeBuf[PC+I]);
|
||||
} else {
|
||||
Output ("$%02X", CodeBuf[PC+I]);
|
||||
}
|
||||
if (I > 0) {
|
||||
Output (",$%02X", CodeBuf[PC+I]);
|
||||
} else {
|
||||
Output ("$%02X", CodeBuf[PC+I]);
|
||||
}
|
||||
}
|
||||
LineComment (PC, ByteCount);
|
||||
LineFeed ();
|
||||
@@ -270,11 +270,11 @@ void DataDByteLine (unsigned ByteCount)
|
||||
Output (".dbyt");
|
||||
Indent (ACol);
|
||||
for (I = 0; I < ByteCount; I += 2) {
|
||||
if (I > 0) {
|
||||
Output (",$%04X", GetCodeDByte (PC+I));
|
||||
} else {
|
||||
Output ("$%04X", GetCodeDByte (PC+I));
|
||||
}
|
||||
if (I > 0) {
|
||||
Output (",$%04X", GetCodeDByte (PC+I));
|
||||
} else {
|
||||
Output ("$%04X", GetCodeDByte (PC+I));
|
||||
}
|
||||
}
|
||||
LineComment (PC, ByteCount);
|
||||
LineFeed ();
|
||||
@@ -291,11 +291,11 @@ void DataWordLine (unsigned ByteCount)
|
||||
Output (".word");
|
||||
Indent (ACol);
|
||||
for (I = 0; I < ByteCount; I += 2) {
|
||||
if (I > 0) {
|
||||
Output (",$%04X", GetCodeWord (PC+I));
|
||||
} else {
|
||||
Output ("$%04X", GetCodeWord (PC+I));
|
||||
}
|
||||
if (I > 0) {
|
||||
Output (",$%04X", GetCodeWord (PC+I));
|
||||
} else {
|
||||
Output ("$%04X", GetCodeWord (PC+I));
|
||||
}
|
||||
}
|
||||
LineComment (PC, ByteCount);
|
||||
LineFeed ();
|
||||
@@ -312,11 +312,11 @@ void DataDWordLine (unsigned ByteCount)
|
||||
Output (".dword");
|
||||
Indent (ACol);
|
||||
for (I = 0; I < ByteCount; I += 4) {
|
||||
if (I > 0) {
|
||||
Output (",$%08lX", GetCodeDWord (PC+I));
|
||||
} else {
|
||||
Output ("$%08lX", GetCodeDWord (PC+I));
|
||||
}
|
||||
if (I > 0) {
|
||||
Output (",$%08lX", GetCodeDWord (PC+I));
|
||||
} else {
|
||||
Output ("$%08lX", GetCodeDWord (PC+I));
|
||||
}
|
||||
}
|
||||
LineComment (PC, ByteCount);
|
||||
LineFeed ();
|
||||
@@ -328,8 +328,8 @@ void SeparatorLine (void)
|
||||
/* Print a separator line */
|
||||
{
|
||||
if (Pass == PassCount && Comments >= 1) {
|
||||
Output ("; ----------------------------------------------------------------------------");
|
||||
LineFeed ();
|
||||
Output ("; ----------------------------------------------------------------------------");
|
||||
LineFeed ();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -350,23 +350,23 @@ void LineComment (unsigned PC, unsigned Count)
|
||||
unsigned I;
|
||||
|
||||
if (Pass == PassCount && Comments >= 2) {
|
||||
Indent (CCol);
|
||||
Output ("; %04X", PC);
|
||||
if (Comments >= 3) {
|
||||
for (I = 0; I < Count; ++I) {
|
||||
Output (" %02X", CodeBuf [PC+I]);
|
||||
}
|
||||
if (Comments >= 4) {
|
||||
Indent (TCol);
|
||||
for (I = 0; I < Count; ++I) {
|
||||
unsigned char C = CodeBuf [PC+I];
|
||||
if (!isprint (C)) {
|
||||
C = '.';
|
||||
}
|
||||
Output ("%c", C);
|
||||
}
|
||||
}
|
||||
}
|
||||
Indent (CCol);
|
||||
Output ("; %04X", PC);
|
||||
if (Comments >= 3) {
|
||||
for (I = 0; I < Count; ++I) {
|
||||
Output (" %02X", CodeBuf [PC+I]);
|
||||
}
|
||||
if (Comments >= 4) {
|
||||
Indent (TCol);
|
||||
for (I = 0; I < Count; ++I) {
|
||||
unsigned char C = CodeBuf [PC+I];
|
||||
if (!isprint (C)) {
|
||||
C = '.';
|
||||
}
|
||||
Output ("%c", C);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
/*****************************************************************************/
|
||||
/* */
|
||||
/* output.h */
|
||||
/* output.h */
|
||||
/* */
|
||||
/* Disassembler output routines */
|
||||
/* Disassembler output routines */
|
||||
/* */
|
||||
/* */
|
||||
/* */
|
||||
@@ -44,7 +44,7 @@
|
||||
|
||||
|
||||
/*****************************************************************************/
|
||||
/* Code */
|
||||
/* Code */
|
||||
/*****************************************************************************/
|
||||
|
||||
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
/*****************************************************************************/
|
||||
/* */
|
||||
/* scanner.c */
|
||||
/* scanner.c */
|
||||
/* */
|
||||
/* Configuration file scanner for the da65 disassembler */
|
||||
/* Configuration file scanner for the da65 disassembler */
|
||||
/* */
|
||||
/* */
|
||||
/* */
|
||||
@@ -50,33 +50,33 @@
|
||||
|
||||
|
||||
/*****************************************************************************/
|
||||
/* Data */
|
||||
/* Data */
|
||||
/*****************************************************************************/
|
||||
|
||||
|
||||
|
||||
/* Current token and attributes */
|
||||
unsigned InfoTok;
|
||||
char InfoSVal [CFG_MAX_IDENT_LEN+1];
|
||||
char InfoSVal [CFG_MAX_IDENT_LEN+1];
|
||||
long InfoIVal;
|
||||
|
||||
/* Error location */
|
||||
unsigned InfoErrorLine;
|
||||
unsigned InfoErrorCol;
|
||||
unsigned InfoErrorLine;
|
||||
unsigned InfoErrorCol;
|
||||
|
||||
/* Input sources for the configuration */
|
||||
static const char* InfoFile = 0;
|
||||
static const char* InfoFile = 0;
|
||||
|
||||
/* Other input stuff */
|
||||
static int C = ' ';
|
||||
static unsigned InputLine = 1;
|
||||
static unsigned InputCol = 0;
|
||||
static FILE* InputFile = 0;
|
||||
static int C = ' ';
|
||||
static unsigned InputLine = 1;
|
||||
static unsigned InputCol = 0;
|
||||
static FILE* InputFile = 0;
|
||||
|
||||
|
||||
|
||||
/*****************************************************************************/
|
||||
/* Error handling */
|
||||
/* Error handling */
|
||||
/*****************************************************************************/
|
||||
|
||||
|
||||
@@ -112,7 +112,7 @@ void InfoError (const char* Format, ...)
|
||||
|
||||
|
||||
/*****************************************************************************/
|
||||
/* Code */
|
||||
/* Code */
|
||||
/*****************************************************************************/
|
||||
|
||||
|
||||
@@ -125,13 +125,13 @@ static void NextChar (void)
|
||||
|
||||
/* Count columns */
|
||||
if (C != EOF) {
|
||||
++InputCol;
|
||||
++InputCol;
|
||||
}
|
||||
|
||||
/* Count lines */
|
||||
if (C == '\n') {
|
||||
++InputLine;
|
||||
InputCol = 0;
|
||||
++InputLine;
|
||||
InputCol = 0;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -141,9 +141,9 @@ static unsigned DigitVal (int C)
|
||||
/* Return the value for a numeric digit */
|
||||
{
|
||||
if (IsDigit (C)) {
|
||||
return C - '0';
|
||||
return C - '0';
|
||||
} else {
|
||||
return toupper (C) - 'A' + 10;
|
||||
return toupper (C) - 'A' + 10;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -153,12 +153,12 @@ void InfoNextTok (void)
|
||||
/* Read the next token from the input stream */
|
||||
{
|
||||
unsigned I;
|
||||
int Esc;
|
||||
int Esc;
|
||||
|
||||
Again:
|
||||
/* Skip whitespace */
|
||||
while (IsSpace (C)) {
|
||||
NextChar ();
|
||||
NextChar ();
|
||||
}
|
||||
|
||||
/* Remember the current position */
|
||||
@@ -168,110 +168,110 @@ Again:
|
||||
/* Identifier? */
|
||||
if (C == '_' || IsAlpha (C)) {
|
||||
|
||||
/* Read the identifier */
|
||||
I = 0;
|
||||
while (C == '_' || IsAlNum (C)) {
|
||||
if (I < CFG_MAX_IDENT_LEN) {
|
||||
InfoSVal [I++] = C;
|
||||
}
|
||||
NextChar ();
|
||||
}
|
||||
InfoSVal [I] = '\0';
|
||||
InfoTok = INFOTOK_IDENT;
|
||||
return;
|
||||
/* Read the identifier */
|
||||
I = 0;
|
||||
while (C == '_' || IsAlNum (C)) {
|
||||
if (I < CFG_MAX_IDENT_LEN) {
|
||||
InfoSVal [I++] = C;
|
||||
}
|
||||
NextChar ();
|
||||
}
|
||||
InfoSVal [I] = '\0';
|
||||
InfoTok = INFOTOK_IDENT;
|
||||
return;
|
||||
}
|
||||
|
||||
/* Hex number? */
|
||||
if (C == '$') {
|
||||
NextChar ();
|
||||
if (!IsXDigit (C)) {
|
||||
InfoError ("Hex digit expected");
|
||||
}
|
||||
InfoIVal = 0;
|
||||
while (IsXDigit (C)) {
|
||||
InfoIVal = InfoIVal * 16 + DigitVal (C);
|
||||
NextChar ();
|
||||
}
|
||||
InfoTok = INFOTOK_INTCON;
|
||||
return;
|
||||
NextChar ();
|
||||
if (!IsXDigit (C)) {
|
||||
InfoError ("Hex digit expected");
|
||||
}
|
||||
InfoIVal = 0;
|
||||
while (IsXDigit (C)) {
|
||||
InfoIVal = InfoIVal * 16 + DigitVal (C);
|
||||
NextChar ();
|
||||
}
|
||||
InfoTok = INFOTOK_INTCON;
|
||||
return;
|
||||
}
|
||||
|
||||
/* Decimal number? */
|
||||
if (IsDigit (C)) {
|
||||
InfoIVal = 0;
|
||||
while (IsDigit (C)) {
|
||||
InfoIVal = InfoIVal * 10 + DigitVal (C);
|
||||
NextChar ();
|
||||
}
|
||||
InfoTok = INFOTOK_INTCON;
|
||||
return;
|
||||
InfoIVal = 0;
|
||||
while (IsDigit (C)) {
|
||||
InfoIVal = InfoIVal * 10 + DigitVal (C);
|
||||
NextChar ();
|
||||
}
|
||||
InfoTok = INFOTOK_INTCON;
|
||||
return;
|
||||
}
|
||||
|
||||
/* Other characters */
|
||||
switch (C) {
|
||||
|
||||
case '{':
|
||||
NextChar ();
|
||||
InfoTok = INFOTOK_LCURLY;
|
||||
break;
|
||||
case '{':
|
||||
NextChar ();
|
||||
InfoTok = INFOTOK_LCURLY;
|
||||
break;
|
||||
|
||||
case '}':
|
||||
NextChar ();
|
||||
InfoTok = INFOTOK_RCURLY;
|
||||
break;
|
||||
case '}':
|
||||
NextChar ();
|
||||
InfoTok = INFOTOK_RCURLY;
|
||||
break;
|
||||
|
||||
case ';':
|
||||
NextChar ();
|
||||
InfoTok = INFOTOK_SEMI;
|
||||
break;
|
||||
case ';':
|
||||
NextChar ();
|
||||
InfoTok = INFOTOK_SEMI;
|
||||
break;
|
||||
|
||||
case '.':
|
||||
NextChar ();
|
||||
InfoTok = INFOTOK_DOT;
|
||||
break;
|
||||
case '.':
|
||||
NextChar ();
|
||||
InfoTok = INFOTOK_DOT;
|
||||
break;
|
||||
|
||||
case ',':
|
||||
NextChar ();
|
||||
InfoTok = INFOTOK_COMMA;
|
||||
break;
|
||||
case ',':
|
||||
NextChar ();
|
||||
InfoTok = INFOTOK_COMMA;
|
||||
break;
|
||||
|
||||
case '=':
|
||||
NextChar ();
|
||||
InfoTok = INFOTOK_EQ;
|
||||
break;
|
||||
case '=':
|
||||
NextChar ();
|
||||
InfoTok = INFOTOK_EQ;
|
||||
break;
|
||||
|
||||
case ':':
|
||||
NextChar ();
|
||||
InfoTok = INFOTOK_COLON;
|
||||
break;
|
||||
NextChar ();
|
||||
InfoTok = INFOTOK_COLON;
|
||||
break;
|
||||
|
||||
case '\"':
|
||||
NextChar ();
|
||||
I = 0;
|
||||
while (C != '\"') {
|
||||
Esc = (C == '\\');
|
||||
if (Esc) {
|
||||
NextChar ();
|
||||
}
|
||||
if (C == EOF || C == '\n') {
|
||||
InfoError ("Unterminated string");
|
||||
}
|
||||
if (Esc) {
|
||||
switch (C) {
|
||||
case '\"': C = '\"'; break;
|
||||
case '\'': C = '\''; break;
|
||||
default: InfoError ("Invalid escape char: %c", C);
|
||||
}
|
||||
}
|
||||
if (I < CFG_MAX_IDENT_LEN) {
|
||||
InfoSVal [I++] = C;
|
||||
}
|
||||
NextChar ();
|
||||
}
|
||||
NextChar ();
|
||||
InfoSVal [I] = '\0';
|
||||
InfoTok = INFOTOK_STRCON;
|
||||
break;
|
||||
NextChar ();
|
||||
I = 0;
|
||||
while (C != '\"') {
|
||||
Esc = (C == '\\');
|
||||
if (Esc) {
|
||||
NextChar ();
|
||||
}
|
||||
if (C == EOF || C == '\n') {
|
||||
InfoError ("Unterminated string");
|
||||
}
|
||||
if (Esc) {
|
||||
switch (C) {
|
||||
case '\"': C = '\"'; break;
|
||||
case '\'': C = '\''; break;
|
||||
default: InfoError ("Invalid escape char: %c", C);
|
||||
}
|
||||
}
|
||||
if (I < CFG_MAX_IDENT_LEN) {
|
||||
InfoSVal [I++] = C;
|
||||
}
|
||||
NextChar ();
|
||||
}
|
||||
NextChar ();
|
||||
InfoSVal [I] = '\0';
|
||||
InfoTok = INFOTOK_STRCON;
|
||||
break;
|
||||
|
||||
case '\'':
|
||||
NextChar ();
|
||||
@@ -288,22 +288,22 @@ Again:
|
||||
break;
|
||||
|
||||
case '#':
|
||||
/* Comment */
|
||||
while (C != '\n' && C != EOF) {
|
||||
NextChar ();
|
||||
}
|
||||
if (C != EOF) {
|
||||
goto Again;
|
||||
}
|
||||
InfoTok = INFOTOK_EOF;
|
||||
break;
|
||||
/* Comment */
|
||||
while (C != '\n' && C != EOF) {
|
||||
NextChar ();
|
||||
}
|
||||
if (C != EOF) {
|
||||
goto Again;
|
||||
}
|
||||
InfoTok = INFOTOK_EOF;
|
||||
break;
|
||||
|
||||
case EOF:
|
||||
InfoTok = INFOTOK_EOF;
|
||||
break;
|
||||
InfoTok = INFOTOK_EOF;
|
||||
break;
|
||||
|
||||
default:
|
||||
InfoError ("Invalid character `%c'", C);
|
||||
default:
|
||||
InfoError ("Invalid character `%c'", C);
|
||||
|
||||
}
|
||||
}
|
||||
@@ -314,7 +314,7 @@ void InfoConsume (unsigned T, const char* Msg)
|
||||
/* Skip a token, print an error message if not found */
|
||||
{
|
||||
if (InfoTok != T) {
|
||||
InfoError (Msg);
|
||||
InfoError (Msg);
|
||||
}
|
||||
InfoNextTok ();
|
||||
}
|
||||
@@ -357,7 +357,7 @@ void InfoOptionalComma (void)
|
||||
/* Consume a comma if there is one */
|
||||
{
|
||||
if (InfoTok == INFOTOK_COMMA) {
|
||||
InfoNextTok ();
|
||||
InfoNextTok ();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -367,7 +367,7 @@ void InfoOptionalAssign (void)
|
||||
/* Consume an equal sign if there is one */
|
||||
{
|
||||
if (InfoTok == INFOTOK_EQ) {
|
||||
InfoNextTok ();
|
||||
InfoNextTok ();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -377,7 +377,7 @@ void InfoAssureInt (void)
|
||||
/* Make sure the next token is an integer */
|
||||
{
|
||||
if (InfoTok != INFOTOK_INTCON) {
|
||||
InfoError ("Integer constant expected");
|
||||
InfoError ("Integer constant expected");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -387,7 +387,7 @@ void InfoAssureStr (void)
|
||||
/* Make sure the next token is a string constant */
|
||||
{
|
||||
if (InfoTok != INFOTOK_STRCON) {
|
||||
InfoError ("String constant expected");
|
||||
InfoError ("String constant expected");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -397,7 +397,7 @@ void InfoAssureChar (void)
|
||||
/* Make sure the next token is a char constant */
|
||||
{
|
||||
if (InfoTok != INFOTOK_STRCON) {
|
||||
InfoError ("Character constant expected");
|
||||
InfoError ("Character constant expected");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -407,7 +407,7 @@ void InfoAssureIdent (void)
|
||||
/* Make sure the next token is an identifier */
|
||||
{
|
||||
if (InfoTok != INFOTOK_IDENT) {
|
||||
InfoError ("Identifier expected");
|
||||
InfoError ("Identifier expected");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -417,7 +417,7 @@ void InfoRangeCheck (long Lo, long Hi)
|
||||
/* Check the range of InfoIVal */
|
||||
{
|
||||
if (InfoIVal < Lo || InfoIVal > Hi) {
|
||||
InfoError ("Range error");
|
||||
InfoError ("Range error");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -431,20 +431,20 @@ void InfoSpecialToken (const IdentTok* Table, unsigned Size, const char* Name)
|
||||
/* We need an identifier */
|
||||
if (InfoTok == INFOTOK_IDENT) {
|
||||
|
||||
/* Make it upper case */
|
||||
I = 0;
|
||||
while (InfoSVal [I]) {
|
||||
InfoSVal [I] = toupper (InfoSVal [I]);
|
||||
++I;
|
||||
}
|
||||
/* Make it upper case */
|
||||
I = 0;
|
||||
while (InfoSVal [I]) {
|
||||
InfoSVal [I] = toupper (InfoSVal [I]);
|
||||
++I;
|
||||
}
|
||||
|
||||
/* Linear search */
|
||||
for (I = 0; I < Size; ++I) {
|
||||
if (strcmp (InfoSVal, Table [I].Ident) == 0) {
|
||||
InfoTok = Table [I].Tok;
|
||||
return;
|
||||
}
|
||||
}
|
||||
/* Linear search */
|
||||
for (I = 0; I < Size; ++I) {
|
||||
if (strcmp (InfoSVal, Table [I].Ident) == 0) {
|
||||
InfoTok = Table [I].Tok;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -458,23 +458,23 @@ void InfoBoolToken (void)
|
||||
/* Map an identifier or integer to a boolean token */
|
||||
{
|
||||
static const IdentTok Booleans [] = {
|
||||
{ "YES", INFOTOK_TRUE },
|
||||
{ "NO", INFOTOK_FALSE },
|
||||
{ "YES", INFOTOK_TRUE },
|
||||
{ "NO", INFOTOK_FALSE },
|
||||
{ "TRUE", INFOTOK_TRUE },
|
||||
{ "FALSE", INFOTOK_FALSE },
|
||||
{ "ON", INFOTOK_TRUE },
|
||||
{ "OFF", INFOTOK_FALSE },
|
||||
{ "ON", INFOTOK_TRUE },
|
||||
{ "OFF", INFOTOK_FALSE },
|
||||
};
|
||||
|
||||
/* If we have an identifier, map it to a boolean token */
|
||||
if (InfoTok == INFOTOK_IDENT) {
|
||||
InfoSpecialToken (Booleans, ENTRY_COUNT (Booleans), "Boolean");
|
||||
InfoSpecialToken (Booleans, ENTRY_COUNT (Booleans), "Boolean");
|
||||
} else {
|
||||
/* We expected an integer here */
|
||||
if (InfoTok != INFOTOK_INTCON) {
|
||||
InfoError ("Boolean value expected");
|
||||
}
|
||||
InfoTok = (InfoIVal == 0)? INFOTOK_FALSE : INFOTOK_TRUE;
|
||||
/* We expected an integer here */
|
||||
if (InfoTok != INFOTOK_INTCON) {
|
||||
InfoError ("Boolean value expected");
|
||||
}
|
||||
InfoTok = (InfoIVal == 0)? INFOTOK_FALSE : INFOTOK_TRUE;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -530,7 +530,7 @@ void InfoCloseInput (void)
|
||||
/* Close the input file if we had one */
|
||||
if (InputFile) {
|
||||
(void) fclose (InputFile);
|
||||
InputFile = 0;
|
||||
InputFile = 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
/*****************************************************************************/
|
||||
/* */
|
||||
/* scanner.h */
|
||||
/* scanner.h */
|
||||
/* */
|
||||
/* Configuration file scanner for the da65 disassembler */
|
||||
/* Configuration file scanner for the da65 disassembler */
|
||||
/* */
|
||||
/* */
|
||||
/* */
|
||||
@@ -39,7 +39,7 @@
|
||||
|
||||
|
||||
/*****************************************************************************/
|
||||
/* Data */
|
||||
/* Data */
|
||||
/*****************************************************************************/
|
||||
|
||||
|
||||
@@ -120,27 +120,27 @@ typedef enum token_t {
|
||||
/* Mapping table entry, special identifier --> token */
|
||||
typedef struct IdentTok IdentTok;
|
||||
struct IdentTok {
|
||||
const char* Ident; /* Identifier */
|
||||
token_t Tok; /* Token for identifier */
|
||||
const char* Ident; /* Identifier */
|
||||
token_t Tok; /* Token for identifier */
|
||||
};
|
||||
#define ENTRY_COUNT(s) (sizeof (s) / sizeof (s [0]))
|
||||
#define ENTRY_COUNT(s) (sizeof (s) / sizeof (s [0]))
|
||||
|
||||
|
||||
|
||||
/* Current token and attributes */
|
||||
#define CFG_MAX_IDENT_LEN 255
|
||||
extern unsigned InfoTok;
|
||||
extern char InfoSVal[CFG_MAX_IDENT_LEN+1];
|
||||
extern long InfoIVal;
|
||||
extern unsigned InfoTok;
|
||||
extern char InfoSVal[CFG_MAX_IDENT_LEN+1];
|
||||
extern long InfoIVal;
|
||||
|
||||
/* Error location */
|
||||
extern unsigned InfoErrorLine;
|
||||
extern unsigned InfoErrorCol;
|
||||
extern unsigned InfoErrorLine;
|
||||
extern unsigned InfoErrorCol;
|
||||
|
||||
|
||||
|
||||
/*****************************************************************************/
|
||||
/* Code */
|
||||
/* Code */
|
||||
/*****************************************************************************/
|
||||
|
||||
|
||||
|
||||
@@ -74,7 +74,7 @@ static Segment* EndTab[HASH_SIZE]; /* Table containing segment ends */
|
||||
|
||||
|
||||
/*****************************************************************************/
|
||||
/* Code */
|
||||
/* Code */
|
||||
/*****************************************************************************/
|
||||
|
||||
|
||||
|
||||
@@ -39,7 +39,7 @@
|
||||
|
||||
|
||||
/*****************************************************************************/
|
||||
/* Code */
|
||||
/* Code */
|
||||
/*****************************************************************************/
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user