From e8ee8435e90c191f5e74c4a73e80ad0b708da27d Mon Sep 17 00:00:00 2001 From: Lauri Kasanen Date: Wed, 12 Oct 2022 12:36:26 +0300 Subject: [PATCH] Add addrMode to RANGE --- src/da65/attrtab.h | 15 ++++++++-- src/da65/infofile.c | 68 +++++++++++++++++++++++++++++++++++++-------- src/da65/scanner.h | 1 + 3 files changed, 69 insertions(+), 15 deletions(-) diff --git a/src/da65/attrtab.h b/src/da65/attrtab.h index 847f44b8a..37143c0d1 100644 --- a/src/da65/attrtab.h +++ b/src/da65/attrtab.h @@ -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; diff --git a/src/da65/infofile.c b/src/da65/infofile.c index 48a95c9b0..923cc53c9 100644 --- a/src/da65/infofile.c +++ b/src/da65/infofile.c @@ -35,6 +35,7 @@ #include #include +#include #include #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) { diff --git a/src/da65/scanner.h b/src/da65/scanner.h index 63d3273f6..60648a40c 100644 --- a/src/da65/scanner.h +++ b/src/da65/scanner.h @@ -90,6 +90,7 @@ typedef enum token_t { INFOTOK_START, INFOTOK_END, INFOTOK_TYPE, + INFOTOK_ADDRMODE, INFOTOK_CODE, INFOTOK_BYTETAB,