From 0192932e2c9b2f132bf25f3a865b82f51b7e9fb8 Mon Sep 17 00:00:00 2001 From: cuz Date: Thu, 7 Aug 2003 08:13:46 +0000 Subject: [PATCH] More instruction set stuff git-svn-id: svn://svn.cc65.org/cc65/trunk@2247 b7a2c559-68d2-44c3-8de9-860c34a00d81 --- src/ca65/condasm.c | 13 ++++++-- src/ca65/instr.c | 80 ++++++++++++++++++++++++++++++++++++++++++++-- src/ca65/pseudo.c | 39 +++++++++++++++++++--- src/ca65/scanner.c | 3 ++ src/ca65/scanner.h | 3 ++ 5 files changed, 129 insertions(+), 9 deletions(-) diff --git a/src/ca65/condasm.c b/src/ca65/condasm.c index ebe58f0f1..22ff2a8de 100644 --- a/src/ca65/condasm.c +++ b/src/ca65/condasm.c @@ -394,14 +394,23 @@ void DoConditionals (void) IfCond = GetCurrentIfCond (); break; + case TOK_IFPSC02: + D = AllocIf (".IFPSC02", 1); + NextTok (); + if (IfCond) { + SetIfCond (D, GetCPU() == CPU_65SC02); + } + IfCond = GetCurrentIfCond (); + break; + case TOK_IFREF: D = AllocIf (".IFREF", 1); NextTok (); if (IfCond) { if (Tok != TOK_IDENT) { - ErrorSkip (ERR_IDENT_EXPECTED); + ErrorSkip (ERR_IDENT_EXPECTED); } else { - SetIfCond (D, SymIsRef (SVal, SCOPE_ANY)); + SetIfCond (D, SymIsRef (SVal, SCOPE_ANY)); NextTok (); } } diff --git a/src/ca65/instr.c b/src/ca65/instr.c index dd976f16d..1ba11e556 100644 --- a/src/ca65/instr.c +++ b/src/ca65/instr.c @@ -217,6 +217,83 @@ static const struct { } }; +/* Instruction table for the 65C02 */ +#define INS_COUNT_65C02 66 +static const struct { + unsigned Count; + InsDesc Ins[INS_COUNT_65C02]; +} InsTab65C02 = { + INS_COUNT_65C02, + { + { "ADC", 0x080A66C, 0x60, 0, PutAll }, + { "AND", 0x080A66C, 0x20, 0, PutAll }, + { "ASL", 0x000006e, 0x02, 1, PutAll }, + { "BCC", 0x0020000, 0x90, 0, PutPCRel8 }, + { "BCS", 0x0020000, 0xb0, 0, PutPCRel8 }, + { "BEQ", 0x0020000, 0xf0, 0, PutPCRel8 }, + { "BIT", 0x0A0006C, 0x00, 2, PutAll }, + { "BMI", 0x0020000, 0x30, 0, PutPCRel8 }, + { "BNE", 0x0020000, 0xd0, 0, PutPCRel8 }, + { "BPL", 0x0020000, 0x10, 0, PutPCRel8 }, + { "BRA", 0x0020000, 0x80, 0, PutPCRel8 }, + { "BRK", 0x0000001, 0x00, 0, PutAll }, + { "BVC", 0x0020000, 0x50, 0, PutPCRel8 }, + { "BVS", 0x0020000, 0x70, 0, PutPCRel8 }, + { "CLC", 0x0000001, 0x18, 0, PutAll }, + { "CLD", 0x0000001, 0xd8, 0, PutAll }, + { "CLI", 0x0000001, 0x58, 0, PutAll }, + { "CLV", 0x0000001, 0xb8, 0, PutAll }, + { "CMP", 0x080A66C, 0xc0, 0, PutAll }, + { "CPX", 0x080000C, 0xe0, 1, PutAll }, + { "CPY", 0x080000C, 0xc0, 1, PutAll }, + { "DEA", 0x0000001, 0x00, 3, PutAll }, /* == DEC */ + { "DEC", 0x000006F, 0x00, 3, PutAll }, + { "DEX", 0x0000001, 0xca, 0, PutAll }, + { "DEY", 0x0000001, 0x88, 0, PutAll }, + { "EOR", 0x080A66C, 0x40, 0, PutAll }, + { "INA", 0x0000001, 0x00, 4, PutAll }, /* == INC */ + { "INC", 0x000006f, 0x00, 4, PutAll }, + { "INX", 0x0000001, 0xe8, 0, PutAll }, + { "INY", 0x0000001, 0xc8, 0, PutAll }, + { "JMP", 0x0010808, 0x4c, 6, PutAll }, + { "JSR", 0x0000008, 0x20, 7, PutAll }, + { "LDA", 0x080A66C, 0xa0, 0, PutAll }, + { "LDX", 0x080030C, 0xa2, 1, PutAll }, + { "LDY", 0x080006C, 0xa0, 1, PutAll }, + { "LSR", 0x000006F, 0x42, 1, PutAll }, + { "NOP", 0x0000001, 0xea, 0, PutAll }, + { "ORA", 0x080A66C, 0x00, 0, PutAll }, + { "PHA", 0x0000001, 0x48, 0, PutAll }, + { "PHP", 0x0000001, 0x08, 0, PutAll }, + { "PHX", 0x0000001, 0xda, 0, PutAll }, + { "PHY", 0x0000001, 0x5a, 0, PutAll }, + { "PLA", 0x0000001, 0x68, 0, PutAll }, + { "PLP", 0x0000001, 0x28, 0, PutAll }, + { "PLX", 0x0000001, 0xfa, 0, PutAll }, + { "PLY", 0x0000001, 0x7a, 0, PutAll }, + { "ROL", 0x000006F, 0x22, 1, PutAll }, + { "ROR", 0x000006F, 0x62, 1, PutAll }, + { "RTI", 0x0000001, 0x40, 0, PutAll }, + { "RTS", 0x0000001, 0x60, 0, PutAll }, + { "SBC", 0x080A66C, 0xe0, 0, PutAll }, + { "SEC", 0x0000001, 0x38, 0, PutAll }, + { "SED", 0x0000001, 0xf8, 0, PutAll }, + { "SEI", 0x0000001, 0x78, 0, PutAll }, + { "STA", 0x000A66C, 0x80, 0, PutAll }, + { "STX", 0x000010c, 0x82, 1, PutAll }, + { "STY", 0x000002c, 0x80, 1, PutAll }, + { "STZ", 0x000006c, 0x04, 5, PutAll }, + { "TAX", 0x0000001, 0xaa, 0, PutAll }, + { "TAY", 0x0000001, 0xa8, 0, PutAll }, + { "TRB", 0x000000c, 0x10, 1, PutAll }, + { "TSB", 0x000000c, 0x00, 1, PutAll }, + { "TSX", 0x0000001, 0xba, 0, PutAll }, + { "TXA", 0x0000001, 0x8a, 0, PutAll }, + { "TXS", 0x0000001, 0x9a, 0, PutAll }, + { "TYA", 0x0000001, 0x98, 0, PutAll } + } +}; + /* Instruction table for the 65816 */ #define INS_COUNT_65816 101 static const struct { @@ -340,11 +417,10 @@ static const struct { static const InsTable* InsTabs[CPU_COUNT] = { (const InsTable*) &InsTab6502, (const InsTable*) &InsTab65SC02, + (const InsTable*) &InsTab65C02, (const InsTable*) &InsTab65816, #ifdef SUNPLUS (const InsTable*) &InsTabSunPlus, -#else - NULL, #endif }; const InsTable* InsTab = (const InsTable*) &InsTab6502; diff --git a/src/ca65/pseudo.c b/src/ca65/pseudo.c index d23557948..e0fbea17a 100644 --- a/src/ca65/pseudo.c +++ b/src/ca65/pseudo.c @@ -1250,6 +1250,14 @@ static void DoProc (void) +static void DoPSC02 (void) +/* Switch to 65SC02 CPU */ +{ + SetCPU (CPU_65SC02); +} + + + static void DoPushSeg (void) /* Push the current segment onto the segment stack */ { @@ -1343,12 +1351,12 @@ static void DoSegment (void) strcpy (Name, SVal); NextTok (); - /* Check for an optional segment attribute */ - if (Tok == TOK_COMMA) { - NextTok (); - if (Tok != TOK_IDENT) { + /* Check for an optional segment attribute */ + if (Tok == TOK_COMMA) { + NextTok (); + if (Tok != TOK_IDENT) { ErrorSkip (ERR_IDENT_EXPECTED); - } else { + } else { int Attr = GetSubKey (AttrTab, sizeof (AttrTab) / sizeof (AttrTab [0])); switch (Attr) { @@ -1383,6 +1391,24 @@ static void DoSegment (void) +static void DoSetCPU (void) +/* Switch the CPU instruction set */ +{ + /* We expect an identifier */ + if (Tok != TOK_STRCON) { + ErrorSkip (ERR_STRCON_EXPECTED); + } else { + /* Try to find the CPU, then skip the identifier */ + cpu_t CPU = FindCPU (SVal); + NextTok (); + + /* Switch to the new CPU */ + SetCPU (CPU); + } +} + + + static void DoSmart (void) /* Smart mode on/off */ { @@ -1522,6 +1548,7 @@ static CtrlDesc CtrlCmdTab [] = { { ccKeepToken, DoConditionals }, /* .IFP02 */ { ccKeepToken, DoConditionals }, /* .IFP816 */ { ccKeepToken, DoConditionals }, /* .IFPC02 */ + { ccKeepToken, DoConditionals }, /* .IFPSC02 */ { ccKeepToken, DoConditionals }, /* .IFREF */ { ccNone, DoImport }, { ccNone, DoImportZP }, @@ -1547,6 +1574,7 @@ static CtrlDesc CtrlCmdTab [] = { { ccNone, DoPC02 }, { ccNone, DoPopSeg }, { ccNone, DoProc }, + { ccNone, DoPSC02 }, { ccNone, DoPushSeg }, { ccNone, DoUnexpected }, /* .REFERENCED */ { ccNone, DoReloc }, @@ -1555,6 +1583,7 @@ static CtrlDesc CtrlCmdTab [] = { { ccNone, DoInvalid }, /* .RIGHT */ { ccNone, DoROData }, { ccNone, DoSegment }, + { ccNone, DoSetCPU }, { ccNone, DoSmart }, { ccNone, DoUnexpected }, /* .STRAT */ { ccNone, DoUnexpected }, /* .STRING */ diff --git a/src/ca65/scanner.c b/src/ca65/scanner.c index cec7284a5..432131679 100644 --- a/src/ca65/scanner.c +++ b/src/ca65/scanner.c @@ -185,6 +185,7 @@ struct DotKeyword { { ".IFP02", TOK_IFP02 }, { ".IFP816", TOK_IFP816 }, { ".IFPC02", TOK_IFPC02 }, + { ".IFPSC02", TOK_IFPSC02 }, { ".IFREF", TOK_IFREF }, { ".IMPORT", TOK_IMPORT }, { ".IMPORTZP", TOK_IMPORTZP }, @@ -215,6 +216,7 @@ struct DotKeyword { { ".PC02", TOK_PC02 }, { ".POPSEG", TOK_POPSEG }, { ".PROC", TOK_PROC }, + { ".PSC02", TOK_PSC02 }, { ".PUSHSEG", TOK_PUSHSEG }, { ".REF", TOK_REFERENCED }, { ".REFERENCED", TOK_REFERENCED }, @@ -224,6 +226,7 @@ struct DotKeyword { { ".RIGHT", TOK_RIGHT }, { ".RODATA", TOK_RODATA }, { ".SEGMENT", TOK_SEGMENT }, + { ".SETCPU", TOK_SETCPU }, { ".SHL", TOK_SHL }, { ".SHR", TOK_SHR }, { ".SMART", TOK_SMART }, diff --git a/src/ca65/scanner.h b/src/ca65/scanner.h index 0bf4617b4..93e11b7e5 100644 --- a/src/ca65/scanner.h +++ b/src/ca65/scanner.h @@ -171,6 +171,7 @@ enum Token { TOK_IFP02, TOK_IFP816, TOK_IFPC02, + TOK_IFPSC02, TOK_IFREF, TOK_IMPORT, TOK_IMPORTZP, @@ -196,6 +197,7 @@ enum Token { TOK_PC02, TOK_POPSEG, TOK_PROC, + TOK_PSC02, TOK_PUSHSEG, TOK_REFERENCED, TOK_RELOC, @@ -204,6 +206,7 @@ enum Token { TOK_RIGHT, TOK_RODATA, TOK_SEGMENT, + TOK_SETCPU, TOK_SMART, TOK_STRAT, TOK_STRING, -- 2.39.5