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

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

@ -66,13 +66,22 @@ typedef enum attr_t {
atDepLabel = 0x0040, /* Dependent label */
atUnnamedLabel = 0x0080, /* Unnamed label */
atStyleMask = 0x000F, /* Output style */
atLabelMask = 0x00F0, /* Label information */
/* Segment */
atSegment = 0x0100, /* Code is in a segment */
atSegmentEnd = 0x0200, /* Segment end */
atSegmentStart = 0x0400, /* Segment start */
/* 65816 addressing mode */
atMem8 = 0x1000, /* M flag enabled, 8-bit */
atMem16 = 0x2000, /* M flag disabled, 16-bit */
atIdx8 = 0x4000, /* X flag enabled, 8-bit */
atIdx16 = 0x8000, /* X flag disabled, 16-bit */
atStyleMask = 0x000F, /* Output style */
atLabelMask = 0x00F0, /* Label information */
atSegmentMask = 0x0F00, /* Segment information */
at65816Mask = 0xF000, /* 65816 information */
} attr_t;

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

View File

@ -90,6 +90,7 @@ typedef enum token_t {
INFOTOK_START,
INFOTOK_END,
INFOTOK_TYPE,
INFOTOK_ADDRMODE,
INFOTOK_CODE,
INFOTOK_BYTETAB,