Add addrMode to RANGE

This commit is contained in:
Lauri Kasanen
2022-10-12 12:36:26 +03:00
parent 89fc5e30c4
commit e8ee8435e9
3 changed files with 69 additions and 15 deletions

View File

@@ -35,6 +35,7 @@
#include <stdio.h>
#include <string.h>
#include <ctype.h>
#include <limits.h>
#if defined(_MSC_VER)
/* Microsoft compiler */
@@ -521,11 +522,12 @@ static void RangeSection (void)
/* Parse a range section */
{
static const IdentTok RangeDefs[] = {
{ "COMMENT", INFOTOK_COMMENT },
{ "END", INFOTOK_END },
{ "NAME", INFOTOK_NAME },
{ "START", INFOTOK_START },
{ "TYPE", INFOTOK_TYPE },
{ "COMMENT", INFOTOK_COMMENT },
{ "END", INFOTOK_END },
{ "NAME", INFOTOK_NAME },
{ "START", INFOTOK_START },
{ "TYPE", INFOTOK_TYPE },
{ "ADDRMODE", INFOTOK_ADDRMODE },
};
static const IdentTok TypeDefs[] = {
@@ -543,12 +545,13 @@ static void RangeSection (void)
/* Which values did we get? */
enum {
tNone = 0x00,
tStart = 0x01,
tEnd = 0x02,
tType = 0x04,
tName = 0x08,
tComment= 0x10,
tNone = 0x00,
tStart = 0x01,
tEnd = 0x02,
tType = 0x04,
tName = 0x08,
tComment = 0x10,
tAddrMode = 0x20,
tNeeded = (tStart | tEnd | tType)
};
unsigned Attributes = tNone;
@@ -557,6 +560,7 @@ static void RangeSection (void)
unsigned Start = 0;
unsigned End = 0;
unsigned char Type = 0;
unsigned AddrMode = 0;
char* Name = 0;
char* Comment = 0;
unsigned MemberSize = 0;
@@ -647,6 +651,37 @@ static void RangeSection (void)
InfoNextTok ();
break;
case INFOTOK_ADDRMODE:
AddAttr ("ADDRMODE", &Attributes, tAddrMode);
InfoNextTok ();
InfoAssureStr ();
if (InfoSVal[0] == '\0') {
InfoError ("AddrMode may not be empty");
}
if (InfoSVal[1] == '\0') {
InfoError ("AddrMode must be two characters long");
}
if (tolower(InfoSVal[0]) == 'm') {
if (InfoSVal[0] == 'm') {
AddrMode = atMem16;
} else {
AddrMode = atMem8;
}
} else {
InfoError ("AddrMode syntax: mx");
}
if (tolower(InfoSVal[1]) == 'x') {
if (InfoSVal[1] == 'x') {
AddrMode |= atIdx16;
} else {
AddrMode |= atIdx8;
}
} else {
InfoError ("AddrMode syntax: mx");
}
InfoNextTok ();
break;
default:
Internal ("Unexpected token: %u", InfoTok);
}
@@ -661,6 +696,15 @@ static void RangeSection (void)
InfoError ("Required values missing from this section");
}
if (CPU == CPU_65816) {
if (Type == atCode && !(Attributes & tAddrMode)) {
InfoError ("65816 code sections require addressing mode");
}
if (Type != atCode && (Attributes & tAddrMode)) {
InfoError ("AddrMode is only valid for code sections");
}
}
/* Start must be less than end */
if (Start > End) {
InfoError ("Start value must not be greater than end value");
@@ -672,7 +716,7 @@ static void RangeSection (void)
}
/* Set the range */
MarkRange (Start, End, Type);
MarkRange (Start, End, Type | AddrMode);
/* Do we have a label? */
if (Attributes & tName) {