Allow 32 bit segments, add .TOPBYTE pseduo instruction
Some checks failed
Snapshot Build / Build, Test, and Snapshot (Linux) (push) Has been skipped
Snapshot Build / Build (Windows) (push) Has been cancelled
Windows Test Scheduled / Build, Test (Windows MSVC) (push) Has been cancelled

This commit is contained in:
2026-05-08 09:52:51 -07:00
parent 8eed63fa52
commit a5a3e40ffe
13 changed files with 73 additions and 11 deletions

View File

@@ -291,6 +291,23 @@ static ExprNode* BankByte (ExprNode* Operand)
return Expr;
}
static ExprNode* TopByte (ExprNode* Operand)
/* Return the top byte of the given expression */
{
ExprNode* Expr;
long Val;
/* Special handling for const expressions */
if (IsEasyConst (Operand, &Val)) {
FreeExpr (Operand);
Expr = GenLiteralExpr ((Val >> 24) & 0xFF);
} else {
/* Extract byte #2 */
Expr = NewExprNode (EXPR_BYTE3);
Expr->Left = Operand;
}
return Expr;
}
static ExprNode* LoWord (ExprNode* Operand)
@@ -579,6 +596,11 @@ static ExprNode* FuncLoWord (void)
}
ExprNode* FuncTopByte (void)
/* Handle the .TOPBYTE builtin function */
{
return TopByte (Expression ());
}
static ExprNode* DoMatch (enum TC EqualityLevel)
/* Handle the .MATCH and .XMATCH builtin functions */
@@ -1287,6 +1309,10 @@ static ExprNode* Factor (void)
NextTok ();
break;
case TOK_TOPBYTE:
N = Function (FuncTopByte);
break;
case TOK_VERSION:
N = GenLiteralExpr (GetVersionAsNumber ());
NextTok ();

View File

@@ -1275,6 +1275,8 @@ int main (int argc, char* argv [])
/* Define the default options */
SetOptions ();
CreateDefaultSegments ();
/* Assemble the input */
Assemble ();

View File

@@ -377,7 +377,11 @@ static void DoAddr (void)
/* Do a range check */
Expr = GenWordExpr (Expr);
}
EmitWord (Expr);
if (GetCPU () == CPU_65C032) {
EmitDWord( Expr );
} else {
EmitWord (Expr);
}
if (CurTok.Tok != TOK_COMMA) {
break;
} else {
@@ -2254,6 +2258,7 @@ static CtrlDesc CtrlCmdTab [] = {
{ ccNone, DoTag }, /* .TAG */
{ ccNone, DoUnexpected }, /* .TCOUNT */
{ ccNone, DoUnexpected }, /* .TIME */
{ ccNone, DoUnexpected }, /* .TOPBYTE */
{ ccKeepToken, DoUnDef }, /* .UNDEF, .UNDEFINE */
{ ccNone, DoUnion }, /* .UNION */
{ ccNone, DoUnexpected }, /* .VERSION */

View File

@@ -316,6 +316,7 @@ struct DotKeyword {
{ ".TAG", TOK_TAG },
{ ".TCOUNT", TOK_TCOUNT },
{ ".TIME", TOK_TIME },
{ ".TOPBYTE", TOK_TOPBYTE },
{ ".UNDEF", TOK_UNDEF },
{ ".UNDEFINE", TOK_UNDEF },
{ ".UNION", TOK_UNION },

View File

@@ -58,6 +58,7 @@
#include "spool.h"
#include "studyexpr.h"
#include "symtab.h"
#include "cpu.h"
@@ -93,7 +94,22 @@ Segment* ActiveSeg;
/* Code */
/*****************************************************************************/
void CreateDefaultSegments(void) {
int AddrSizeAbs;
if (CPU == CPU_65C032) {
AddrSizeAbs = 4;
} else {
AddrSizeAbs = 2;
}
NullSegDef.AddrSize = AddrSizeAbs;
ZeropageSegDef.AddrSize = ADDR_SIZE_ZP;
DataSegDef.AddrSize = AddrSizeAbs;
BssSegDef.AddrSize = AddrSizeAbs;
RODataSegDef.AddrSize = AddrSizeAbs;
CodeSegDef.AddrSize = AddrSizeAbs;
}
static Segment* NewSegFromDef (SegDef* Def)
/* Create a new segment from a segment definition. Used only internally, no

View File

@@ -90,6 +90,8 @@ extern Segment* ActiveSeg;
/* Code */
/*****************************************************************************/
void CreateDefaultSegments (void);
/* Create the default segments, based on the current CPU */
Fragment* GenFragment (unsigned char Type, unsigned short Len);

View File

@@ -48,6 +48,7 @@
#include "symbol.h"
#include "symtab.h"
#include "struct.h"
#include "cpu.h"
@@ -175,7 +176,14 @@ static long DoStructInternal (long Offs, unsigned Type)
case TOK_WORD:
case TOK_ADDR:
NextTok ();
MemberSize = Member (2);
switch (CPU) {
case CPU_65C032:
MemberSize = Member (4);
break;
default:
MemberSize = Member (2);
break;
}
break;
case TOK_FARADDR:

View File

@@ -274,6 +274,7 @@ static const TokDescEntry TokDesc[] = {
{ ".TAG" },
{ ".TCOUNT" },
{ ".TIME" },
{ ".TOPBYTE" },
{ ".UNDEF" },
{ ".UNION" },
{ ".VERSION" },

View File

@@ -280,6 +280,7 @@ typedef enum token_t {
TOK_TAG,
TOK_TCOUNT,
TOK_TIME,
TOK_TOPBYTE,
TOK_UNDEF,
TOK_UNION,
TOK_VERSION,

View File

@@ -47,7 +47,7 @@
/* Maximum possible alignment. Beware: To increase the possible alignment it
** is not enough to bump this value. Check the code inside.
*/
#define MAX_ALIGNMENT 0x10000UL
#define MAX_ALIGNMENT 0x100000000UL
/* The following value marks what is considered a "large alignment" and worth
** a warning if not suppressed.

View File

@@ -217,7 +217,7 @@ int ValidAddrSizeForCPU (unsigned char AddrSize)
case ADDR_SIZE_LONG:
/* "none" supports all sizes */
return (CPU == CPU_NONE);
return (CPU == CPU_65C032);
default:
FAIL ("Invalid address size");

View File

@@ -731,7 +731,7 @@ static void ParseSegments (void)
case CFGTOK_OFFSET:
FlagAttr (&S->Attr, SA_OFFSET, "OFFSET");
S->Addr = CfgCheckedConstExpr (0, 0x1000000);
S->Addr = CfgCheckedConstExpr (0, 0x100000000);
S->Flags |= SF_OFFSET;
break;
@@ -752,7 +752,7 @@ static void ParseSegments (void)
case CFGTOK_START:
FlagAttr (&S->Attr, SA_START, "START");
S->Addr = CfgCheckedConstExpr (0, 0x1000000);
S->Addr = CfgCheckedConstExpr (0, 0x100000000);
S->Flags |= SF_START;
break;
@@ -1959,11 +1959,11 @@ unsigned CfgProcess (void)
GetString (M->Name));
}
M->Size = GetExprVal (M->SizeExpr);
if (M->Size >= 0x80000000) {
PError (GetSourcePos (M->LI),
"Size of memory area `%s' is negative: %ld",
GetString (M->Name), (long)M->Size);
}
// if (M->Size >= 0x80000000) {
// PError (GetSourcePos (M->LI),
// "Size of memory area `%s' is negative: %ld",
// GetString (M->Name), (long)M->Size);
// }
/* Walk through the segments in this memory area */
for (J = 0; J < CollCount (&M->SegList); ++J) {

Binary file not shown.