Merge pull request #2760 from kugelfuhr/kugelfuhr/fix-2753

Add ".CAPABILITY" to ca65, remove ".MACPACK cpu"
This commit is contained in:
Bob Andrews
2025-07-03 18:43:05 +02:00
committed by GitHub
84 changed files with 717 additions and 361 deletions

View File

@@ -37,6 +37,7 @@
#include <time.h>
/* common */
#include "capability.h"
#include "check.h"
#include "cpu.h"
#include "exprdefs.h"
@@ -60,6 +61,7 @@
#include "studyexpr.h"
#include "symbol.h"
#include "symtab.h"
#include "target.h"
#include "toklist.h"
#include "ulabel.h"
#include "macro.h"
@@ -405,6 +407,66 @@ static ExprNode* FuncBlank (void)
static ExprNode* FuncCapability (void)
/* Handle the .CAPABILITY builtin function */
{
int Result = 1;
/* What follows is a comma separated list of identifiers. An empty list is
** not allowed.
*/
while (1) {
const char* Name;
capability_t Cap;
/* We must have an identifier */
if (CurTok.Tok != TOK_IDENT) {
Error ("Arguments to .CAPABILITY must be identifiers");
/* Skip tokens until closing paren or end of line */
while (CurTok.Tok != TOK_RPAREN && !TokIsSep (CurTok.Tok)) {
NextTok ();
}
return GenLiteral0 ();
}
/* Search for the capability that matches this identifier. Ignore case
** on the specified capabilities.
*/
UpcaseSVal ();
SB_Terminate (&CurTok.SVal);
Name = SB_GetConstBuf (&CurTok.SVal);
Cap = FindCapability (Name);
/* Check if the capability is supported */
if (Cap == CAP_INVALID) {
Error ("Not a valid capability name: %s", Name);
Result = 0;
} else {
/* The pseudo function result is the logical AND of all capabilities
** given.
*/
if (!CPUHasCap (Cap) && !TargetHasCap (Cap)) {
Result = 0;
}
}
/* Skip the capability name */
NextTok ();
/* Handle end of list or next capability */
if (CurTok.Tok != TOK_COMMA) {
break;
}
NextTok ();
}
/* Done */
return GenLiteralExpr (Result);
}
static ExprNode* FuncConst (void)
/* Handle the .CONST builtin function */
{
@@ -484,9 +546,10 @@ static ExprNode* FuncIsMnemonic (void)
if (FindMacro (&CurTok.SVal) == 0) {
Instr = FindInstruction (&CurTok.SVal);
}
}
else {
/* Macros and symbols may NOT use the names of instructions, so just check for the instruction */
} else {
/* Macros and symbols may NOT use the names of instructions, so
** just check for the instruction.
*/
Instr = FindInstruction (&CurTok.SVal);
}
}
@@ -532,7 +595,7 @@ static ExprNode* DoMatch (enum TC EqualityLevel)
token_t Term = GetTokListTerm (TOK_COMMA);
while (CurTok.Tok != Term) {
/* We may not end-of-line of end-of-file here */
/* We may not end-of-line or end-of-file here */
if (TokIsSep (CurTok.Tok)) {
Error ("Unexpected end of line");
return GenLiteral0 ();
@@ -570,7 +633,7 @@ static ExprNode* DoMatch (enum TC EqualityLevel)
Node = Root;
while (CurTok.Tok != Term) {
/* We may not end-of-line of end-of-file here */
/* We may not end-of-line or end-of-file here */
if (TokIsSep (CurTok.Tok)) {
Error ("Unexpected end of line");
return GenLiteral0 ();
@@ -1129,6 +1192,10 @@ static ExprNode* Factor (void)
N = Function (FuncBlank);
break;
case TOK_CAP:
N = Function (FuncCapability);
break;
case TOK_CONST:
N = Function (FuncConst);
break;

View File

@@ -192,6 +192,45 @@ static void CBMSystem (const char* Sys)
static void DefineCpuSymbols (void)
/* Define all the symbols to evaluate .cpu. These were previously in cpu.mac. */
{
NewSymbol ("CPU_ISET_NONE", CPU_ISET_NONE);
NewSymbol ("CPU_ISET_6502", CPU_ISET_6502);
NewSymbol ("CPU_ISET_6502X", CPU_ISET_6502X);
NewSymbol ("CPU_ISET_6502DTV", CPU_ISET_6502DTV);
NewSymbol ("CPU_ISET_65SC02", CPU_ISET_65SC02);
NewSymbol ("CPU_ISET_65C02", CPU_ISET_65C02);
NewSymbol ("CPU_ISET_65816", CPU_ISET_65816);
NewSymbol ("CPU_ISET_SWEET16", CPU_ISET_SWEET16);
NewSymbol ("CPU_ISET_HUC6280", CPU_ISET_HUC6280);
NewSymbol ("CPU_ISET_M740", CPU_ISET_M740);
NewSymbol ("CPU_ISET_4510", CPU_ISET_4510);
NewSymbol ("CPU_ISET_45GS02", CPU_ISET_45GS02);
NewSymbol ("CPU_ISET_W65C02", CPU_ISET_W65C02);
NewSymbol ("CPU_ISET_65CE02", CPU_ISET_65CE02);
/* Additional ones from cpu.mac. Not sure how useful they are after the
** changes from #2751.
*/
NewSymbol ("CPU_NONE", CPUIsets[CPU_NONE]);
NewSymbol ("CPU_6502", CPUIsets[CPU_6502]);
NewSymbol ("CPU_6502X", CPUIsets[CPU_6502X]);
NewSymbol ("CPU_6502DTV", CPUIsets[CPU_6502DTV]);
NewSymbol ("CPU_65SC02", CPUIsets[CPU_65SC02]);
NewSymbol ("CPU_65C02", CPUIsets[CPU_65C02]);
NewSymbol ("CPU_65816", CPUIsets[CPU_65816]);
NewSymbol ("CPU_SWEET16", CPUIsets[CPU_SWEET16]);
NewSymbol ("CPU_HUC6280", CPUIsets[CPU_HUC6280]);
NewSymbol ("CPU_M740", CPUIsets[CPU_M740]);
NewSymbol ("CPU_4510", CPUIsets[CPU_4510]);
NewSymbol ("CPU_45GS02", CPUIsets[CPU_45GS02]);
NewSymbol ("CPU_W65C02", CPUIsets[CPU_W65C02]);
NewSymbol ("CPU_65CE02", CPUIsets[CPU_65CE02]);
}
static void SetSys (const char* Sys)
/* Define a target system */
{
@@ -363,6 +402,9 @@ static void SetSys (const char* Sys)
}
/* Define the symbols for evaluating .cpu */
DefineCpuSymbols ();
/* Initialize the translation tables for the target system */
TgtTranslateInit ();
}

View File

@@ -2114,7 +2114,8 @@ struct CtrlDesc {
};
/* NOTE: .AND, .BITAND, .BITNOT, .BITOR, .BITXOR, .MOD, .NOT, .OR, .SHL, .SHR
and .XOR do NOT go into this table */
** and .XOR do NOT go into this table.
*/
#define PSEUDO_COUNT (sizeof (CtrlCmdTab) / sizeof (CtrlCmdTab [0]))
static CtrlDesc CtrlCmdTab [] = {
{ ccNone, DoA16 }, /* .A16 */
@@ -2132,6 +2133,7 @@ static CtrlDesc CtrlCmdTab [] = {
{ ccNone, DoUnexpected }, /* .BLANK */
{ ccNone, DoBss }, /* .BSS */
{ ccNone, DoByte }, /* .BYT, .BYTE */
{ ccNone, DoUnexpected }, /* .CAP */
{ ccNone, DoCase }, /* .CASE */
{ ccNone, DoCharMap }, /* .CHARMAP */
{ ccNone, DoCode }, /* .CODE */

View File

@@ -158,6 +158,8 @@ struct DotKeyword {
{ ".BSS", TOK_BSS },
{ ".BYT", TOK_BYTE },
{ ".BYTE", TOK_BYTE },
{ ".CAP", TOK_CAP },
{ ".CAPABILITY", TOK_CAP },
{ ".CASE", TOK_CASE },
{ ".CHARMAP", TOK_CHARMAP },
{ ".CODE", TOK_CODE },

View File

@@ -137,6 +137,7 @@ typedef enum token_t {
TOK_BLANK,
TOK_BSS,
TOK_BYTE,
TOK_CAP,
TOK_CASE,
TOK_CHARMAP,
TOK_CODE,