Pārlūkot izejas kodu

+ added tool mk6502ins and generate .inc files from instruction table

Nikolay Nikolov 1 gadu atpakaļ
vecāks
revīzija
72d91c3081

+ 2 - 2
compiler/mos6502/cpubase.pas

@@ -43,7 +43,7 @@ unit cpubase;
 *****************************************************************************}
 *****************************************************************************}
 
 
     type
     type
-      TAsmOp=(A_None);//{$i mos6502op.inc}
+      TAsmOp={$i mos6502op.inc}
 
 
 
 
       { This should define the array of instructions as string }
       { This should define the array of instructions as string }
@@ -55,7 +55,7 @@ unit cpubase;
       { Last value of opcode enumeration  }
       { Last value of opcode enumeration  }
       lastop  = high(tasmop);
       lastop  = high(tasmop);
 
 
-      std_op2str:op2strtable=('None');//{$i mos6502stdopnames.inc}
+      std_op2str:op2strtable={$i mos6502stdopnames.inc}
 
 
       { call/reg instructions are not considered as jmp instructions for the usage cases of
       { call/reg instructions are not considered as jmp instructions for the usage cases of
         this set }
         this set }

+ 2 - 0
compiler/mos6502/mos6502nop.inc

@@ -0,0 +1,2 @@
+{ don't edit, this file is generated from mos6502ins.dat; to regenerate, run 'make insdat' in the compiler directory }
+152;

+ 59 - 0
compiler/mos6502/mos6502op.inc

@@ -0,0 +1,59 @@
+{ don't edit, this file is generated from mos6502ins.dat; to regenerate, run 'make insdat' in the compiler directory }
+(
+A_None,
+A_ADC,
+A_AND,
+A_ASL,
+A_BCC,
+A_BCS,
+A_BEQ,
+A_BIT,
+A_BMI,
+A_BNE,
+A_BPL,
+A_BRK,
+A_BVC,
+A_BVS,
+A_CLC,
+A_CLD,
+A_CLI,
+A_CLV,
+A_CMP,
+A_CPX,
+A_CPY,
+A_DEC,
+A_DEX,
+A_DEY,
+A_EOR,
+A_INC,
+A_INX,
+A_INY,
+A_JMP,
+A_JSR,
+A_LDA,
+A_LDX,
+A_LDY,
+A_LSR,
+A_NOP,
+A_ORA,
+A_PHA,
+A_PHP,
+A_PLA,
+A_PLP,
+A_ROL,
+A_ROR,
+A_RTI,
+A_RTS,
+A_SBC,
+A_SEC,
+A_SED,
+A_SEI,
+A_STA,
+A_STX,
+A_STY,
+A_TAX,
+A_TAY,
+A_TSX,
+A_TXA,
+A_TXS,
+A_TYA);

+ 59 - 0
compiler/mos6502/mos6502stdopnames.inc

@@ -0,0 +1,59 @@
+{ don't edit, this file is generated from mos6502ins.dat; to regenerate, run 'make insdat' in the compiler directory }
+(
+'none',
+'adc',
+'and',
+'asl',
+'bcc',
+'bcs',
+'beq',
+'bit',
+'bmi',
+'bne',
+'bpl',
+'brk',
+'bvc',
+'bvs',
+'clc',
+'cld',
+'cli',
+'clv',
+'cmp',
+'cpx',
+'cpy',
+'dec',
+'dex',
+'dey',
+'eor',
+'inc',
+'inx',
+'iny',
+'jmp',
+'jsr',
+'lda',
+'ldx',
+'ldy',
+'lsr',
+'nop',
+'ora',
+'pha',
+'php',
+'pla',
+'plp',
+'rol',
+'ror',
+'rti',
+'rts',
+'sbc',
+'sec',
+'sed',
+'sei',
+'sta',
+'stx',
+'sty',
+'tax',
+'tay',
+'tsx',
+'txa',
+'txs',
+'tya');

+ 1067 - 0
compiler/mos6502/mos6502tab.inc

@@ -0,0 +1,1067 @@
+{ don't edit, this file is generated from mos6502ins.dat; to regenerate, run 'make insdat' in the compiler directory }
+(
+  (
+    opcode  : A_None;
+    ops     : 0;
+    optypes : (OT_NONE,OT_NONE);
+    code    : 'void';
+    flags   : 0
+  ),
+  (
+    opcode  : A_ADC;
+    ops     : 1;
+    optypes : (OT_INDEXED_INDIRECT,OT_NONE);
+    code    : '$61';
+    flags   : 0
+  ),
+  (
+    opcode  : A_ADC;
+    ops     : 1;
+    optypes : (OT_ZERO_PAGE,OT_NONE);
+    code    : '$65';
+    flags   : 0
+  ),
+  (
+    opcode  : A_ADC;
+    ops     : 1;
+    optypes : (OT_IMMEDIATE,OT_NONE);
+    code    : '$69';
+    flags   : 0
+  ),
+  (
+    opcode  : A_ADC;
+    ops     : 1;
+    optypes : (OT_ABSOLUTE,OT_NONE);
+    code    : '$6D';
+    flags   : 0
+  ),
+  (
+    opcode  : A_ADC;
+    ops     : 1;
+    optypes : (OT_INDIRECT_INDEXED,OT_NONE);
+    code    : '$71';
+    flags   : 0
+  ),
+  (
+    opcode  : A_ADC;
+    ops     : 1;
+    optypes : (OT_ZERO_PAGE_X,OT_NONE);
+    code    : '$75';
+    flags   : 0
+  ),
+  (
+    opcode  : A_ADC;
+    ops     : 1;
+    optypes : (OT_ABSOLUTE_Y,OT_NONE);
+    code    : '$79';
+    flags   : 0
+  ),
+  (
+    opcode  : A_ADC;
+    ops     : 1;
+    optypes : (OT_ABSOLUTE_X,OT_NONE);
+    code    : '$7D';
+    flags   : 0
+  ),
+  (
+    opcode  : A_AND;
+    ops     : 1;
+    optypes : (OT_INDEXED_INDIRECT,OT_NONE);
+    code    : '$21';
+    flags   : 0
+  ),
+  (
+    opcode  : A_AND;
+    ops     : 1;
+    optypes : (OT_ZERO_PAGE,OT_NONE);
+    code    : '$25';
+    flags   : 0
+  ),
+  (
+    opcode  : A_AND;
+    ops     : 1;
+    optypes : (OT_IMMEDIATE,OT_NONE);
+    code    : '$29';
+    flags   : 0
+  ),
+  (
+    opcode  : A_AND;
+    ops     : 1;
+    optypes : (OT_ABSOLUTE,OT_NONE);
+    code    : '$2D';
+    flags   : 0
+  ),
+  (
+    opcode  : A_AND;
+    ops     : 1;
+    optypes : (OT_INDIRECT_INDEXED,OT_NONE);
+    code    : '$31';
+    flags   : 0
+  ),
+  (
+    opcode  : A_AND;
+    ops     : 1;
+    optypes : (OT_ZERO_PAGE_X,OT_NONE);
+    code    : '$35';
+    flags   : 0
+  ),
+  (
+    opcode  : A_AND;
+    ops     : 1;
+    optypes : (OT_ABSOLUTE_Y,OT_NONE);
+    code    : '$39';
+    flags   : 0
+  ),
+  (
+    opcode  : A_AND;
+    ops     : 1;
+    optypes : (OT_ABSOLUTE_X,OT_NONE);
+    code    : '$3D';
+    flags   : 0
+  ),
+  (
+    opcode  : A_ASL;
+    ops     : 1;
+    optypes : (OT_ZERO_PAGE,OT_NONE);
+    code    : '$06';
+    flags   : 0
+  ),
+  (
+    opcode  : A_ASL;
+    ops     : 1;
+    optypes : (OT_ACCUMULATOR,OT_NONE);
+    code    : '$0A';
+    flags   : 0
+  ),
+  (
+    opcode  : A_ASL;
+    ops     : 1;
+    optypes : (OT_ABSOLUTE,OT_NONE);
+    code    : '$0E';
+    flags   : 0
+  ),
+  (
+    opcode  : A_ASL;
+    ops     : 1;
+    optypes : (OT_ZERO_PAGE_X,OT_NONE);
+    code    : '$16';
+    flags   : 0
+  ),
+  (
+    opcode  : A_ASL;
+    ops     : 1;
+    optypes : (OT_ABSOLUTE_X,OT_NONE);
+    code    : '$1E';
+    flags   : 0
+  ),
+  (
+    opcode  : A_BCC;
+    ops     : 1;
+    optypes : (OT_RELATIVE,OT_NONE);
+    code    : '$90';
+    flags   : 0
+  ),
+  (
+    opcode  : A_BCS;
+    ops     : 1;
+    optypes : (OT_RELATIVE,OT_NONE);
+    code    : '$B0';
+    flags   : 0
+  ),
+  (
+    opcode  : A_BEQ;
+    ops     : 1;
+    optypes : (OT_RELATIVE,OT_NONE);
+    code    : '$F0';
+    flags   : 0
+  ),
+  (
+    opcode  : A_BIT;
+    ops     : 1;
+    optypes : (OT_ZERO_PAGE,OT_NONE);
+    code    : '$24';
+    flags   : 0
+  ),
+  (
+    opcode  : A_BIT;
+    ops     : 1;
+    optypes : (OT_ABSOLUTE,OT_NONE);
+    code    : '$2C';
+    flags   : 0
+  ),
+  (
+    opcode  : A_BMI;
+    ops     : 1;
+    optypes : (OT_RELATIVE,OT_NONE);
+    code    : '$30';
+    flags   : 0
+  ),
+  (
+    opcode  : A_BNE;
+    ops     : 1;
+    optypes : (OT_RELATIVE,OT_NONE);
+    code    : '$D0';
+    flags   : 0
+  ),
+  (
+    opcode  : A_BPL;
+    ops     : 1;
+    optypes : (OT_RELATIVE,OT_NONE);
+    code    : '$10';
+    flags   : 0
+  ),
+  (
+    opcode  : A_BRK;
+    ops     : 0;
+    optypes : (OT_NONE,OT_NONE);
+    code    : '$00';
+    flags   : 0
+  ),
+  (
+    opcode  : A_BVC;
+    ops     : 1;
+    optypes : (OT_RELATIVE,OT_NONE);
+    code    : '$50';
+    flags   : 0
+  ),
+  (
+    opcode  : A_BVS;
+    ops     : 1;
+    optypes : (OT_RELATIVE,OT_NONE);
+    code    : '$70';
+    flags   : 0
+  ),
+  (
+    opcode  : A_CLC;
+    ops     : 0;
+    optypes : (OT_NONE,OT_NONE);
+    code    : '$18';
+    flags   : 0
+  ),
+  (
+    opcode  : A_CLD;
+    ops     : 0;
+    optypes : (OT_NONE,OT_NONE);
+    code    : '$D8';
+    flags   : 0
+  ),
+  (
+    opcode  : A_CLI;
+    ops     : 0;
+    optypes : (OT_NONE,OT_NONE);
+    code    : '$58';
+    flags   : 0
+  ),
+  (
+    opcode  : A_CLV;
+    ops     : 0;
+    optypes : (OT_NONE,OT_NONE);
+    code    : '$B8';
+    flags   : 0
+  ),
+  (
+    opcode  : A_CMP;
+    ops     : 1;
+    optypes : (OT_INDEXED_INDIRECT,OT_NONE);
+    code    : '$C1';
+    flags   : 0
+  ),
+  (
+    opcode  : A_CMP;
+    ops     : 1;
+    optypes : (OT_ZERO_PAGE,OT_NONE);
+    code    : '$C5';
+    flags   : 0
+  ),
+  (
+    opcode  : A_CMP;
+    ops     : 1;
+    optypes : (OT_IMMEDIATE,OT_NONE);
+    code    : '$C9';
+    flags   : 0
+  ),
+  (
+    opcode  : A_CMP;
+    ops     : 1;
+    optypes : (OT_ABSOLUTE,OT_NONE);
+    code    : '$CD';
+    flags   : 0
+  ),
+  (
+    opcode  : A_CMP;
+    ops     : 1;
+    optypes : (OT_INDIRECT_INDEXED,OT_NONE);
+    code    : '$D1';
+    flags   : 0
+  ),
+  (
+    opcode  : A_CMP;
+    ops     : 1;
+    optypes : (OT_ZERO_PAGE_X,OT_NONE);
+    code    : '$D5';
+    flags   : 0
+  ),
+  (
+    opcode  : A_CMP;
+    ops     : 1;
+    optypes : (OT_ABSOLUTE_Y,OT_NONE);
+    code    : '$D9';
+    flags   : 0
+  ),
+  (
+    opcode  : A_CMP;
+    ops     : 1;
+    optypes : (OT_ABSOLUTE_X,OT_NONE);
+    code    : '$DD';
+    flags   : 0
+  ),
+  (
+    opcode  : A_CPX;
+    ops     : 1;
+    optypes : (OT_IMMEDIATE,OT_NONE);
+    code    : '$E0';
+    flags   : 0
+  ),
+  (
+    opcode  : A_CPX;
+    ops     : 1;
+    optypes : (OT_ZERO_PAGE,OT_NONE);
+    code    : '$E4';
+    flags   : 0
+  ),
+  (
+    opcode  : A_CPX;
+    ops     : 1;
+    optypes : (OT_ABSOLUTE,OT_NONE);
+    code    : '$EC';
+    flags   : 0
+  ),
+  (
+    opcode  : A_CPY;
+    ops     : 1;
+    optypes : (OT_IMMEDIATE,OT_NONE);
+    code    : '$C0';
+    flags   : 0
+  ),
+  (
+    opcode  : A_CPY;
+    ops     : 1;
+    optypes : (OT_ZERO_PAGE,OT_NONE);
+    code    : '$C4';
+    flags   : 0
+  ),
+  (
+    opcode  : A_CPY;
+    ops     : 1;
+    optypes : (OT_ABSOLUTE,OT_NONE);
+    code    : '$CC';
+    flags   : 0
+  ),
+  (
+    opcode  : A_DEC;
+    ops     : 1;
+    optypes : (OT_ZERO_PAGE,OT_NONE);
+    code    : '$C6';
+    flags   : 0
+  ),
+  (
+    opcode  : A_DEC;
+    ops     : 1;
+    optypes : (OT_ABSOLUTE,OT_NONE);
+    code    : '$CE';
+    flags   : 0
+  ),
+  (
+    opcode  : A_DEC;
+    ops     : 1;
+    optypes : (OT_ZERO_PAGE_X,OT_NONE);
+    code    : '$D6';
+    flags   : 0
+  ),
+  (
+    opcode  : A_DEC;
+    ops     : 1;
+    optypes : (OT_ABSOLUTE_X,OT_NONE);
+    code    : '$DE';
+    flags   : 0
+  ),
+  (
+    opcode  : A_DEX;
+    ops     : 0;
+    optypes : (OT_NONE,OT_NONE);
+    code    : '$CA';
+    flags   : 0
+  ),
+  (
+    opcode  : A_DEY;
+    ops     : 0;
+    optypes : (OT_NONE,OT_NONE);
+    code    : '$88';
+    flags   : 0
+  ),
+  (
+    opcode  : A_EOR;
+    ops     : 1;
+    optypes : (OT_INDEXED_INDIRECT,OT_NONE);
+    code    : '$41';
+    flags   : 0
+  ),
+  (
+    opcode  : A_EOR;
+    ops     : 1;
+    optypes : (OT_ZERO_PAGE,OT_NONE);
+    code    : '$45';
+    flags   : 0
+  ),
+  (
+    opcode  : A_EOR;
+    ops     : 1;
+    optypes : (OT_IMMEDIATE,OT_NONE);
+    code    : '$49';
+    flags   : 0
+  ),
+  (
+    opcode  : A_EOR;
+    ops     : 1;
+    optypes : (OT_ABSOLUTE,OT_NONE);
+    code    : '$4D';
+    flags   : 0
+  ),
+  (
+    opcode  : A_EOR;
+    ops     : 1;
+    optypes : (OT_INDIRECT_INDEXED,OT_NONE);
+    code    : '$51';
+    flags   : 0
+  ),
+  (
+    opcode  : A_EOR;
+    ops     : 1;
+    optypes : (OT_ZERO_PAGE_X,OT_NONE);
+    code    : '$55';
+    flags   : 0
+  ),
+  (
+    opcode  : A_EOR;
+    ops     : 1;
+    optypes : (OT_ABSOLUTE_Y,OT_NONE);
+    code    : '$59';
+    flags   : 0
+  ),
+  (
+    opcode  : A_EOR;
+    ops     : 1;
+    optypes : (OT_ABSOLUTE_X,OT_NONE);
+    code    : '$5D';
+    flags   : 0
+  ),
+  (
+    opcode  : A_INC;
+    ops     : 1;
+    optypes : (OT_ZERO_PAGE,OT_NONE);
+    code    : '$E6';
+    flags   : 0
+  ),
+  (
+    opcode  : A_INC;
+    ops     : 1;
+    optypes : (OT_ABSOLUTE,OT_NONE);
+    code    : '$EE';
+    flags   : 0
+  ),
+  (
+    opcode  : A_INC;
+    ops     : 1;
+    optypes : (OT_ZERO_PAGE_X,OT_NONE);
+    code    : '$F6';
+    flags   : 0
+  ),
+  (
+    opcode  : A_INC;
+    ops     : 1;
+    optypes : (OT_ABSOLUTE_X,OT_NONE);
+    code    : '$FE';
+    flags   : 0
+  ),
+  (
+    opcode  : A_INX;
+    ops     : 0;
+    optypes : (OT_NONE,OT_NONE);
+    code    : '$E8';
+    flags   : 0
+  ),
+  (
+    opcode  : A_INY;
+    ops     : 0;
+    optypes : (OT_NONE,OT_NONE);
+    code    : '$C8';
+    flags   : 0
+  ),
+  (
+    opcode  : A_JMP;
+    ops     : 1;
+    optypes : (OT_ABSOLUTE,OT_NONE);
+    code    : '$4C';
+    flags   : 0
+  ),
+  (
+    opcode  : A_JMP;
+    ops     : 1;
+    optypes : (OT_INDIRECT,OT_NONE);
+    code    : '$6C';
+    flags   : 0
+  ),
+  (
+    opcode  : A_JSR;
+    ops     : 1;
+    optypes : (OT_ABSOLUTE,OT_NONE);
+    code    : '$20';
+    flags   : 0
+  ),
+  (
+    opcode  : A_LDA;
+    ops     : 1;
+    optypes : (OT_INDEXED_INDIRECT,OT_NONE);
+    code    : '$A1';
+    flags   : 0
+  ),
+  (
+    opcode  : A_LDA;
+    ops     : 1;
+    optypes : (OT_ZERO_PAGE,OT_NONE);
+    code    : '$A5';
+    flags   : 0
+  ),
+  (
+    opcode  : A_LDA;
+    ops     : 1;
+    optypes : (OT_IMMEDIATE,OT_NONE);
+    code    : '$A9';
+    flags   : 0
+  ),
+  (
+    opcode  : A_LDA;
+    ops     : 1;
+    optypes : (OT_ABSOLUTE,OT_NONE);
+    code    : '$AD';
+    flags   : 0
+  ),
+  (
+    opcode  : A_LDA;
+    ops     : 1;
+    optypes : (OT_INDIRECT_INDEXED,OT_NONE);
+    code    : '$B1';
+    flags   : 0
+  ),
+  (
+    opcode  : A_LDA;
+    ops     : 1;
+    optypes : (OT_ZERO_PAGE_X,OT_NONE);
+    code    : '$B5';
+    flags   : 0
+  ),
+  (
+    opcode  : A_LDA;
+    ops     : 1;
+    optypes : (OT_ABSOLUTE_Y,OT_NONE);
+    code    : '$B9';
+    flags   : 0
+  ),
+  (
+    opcode  : A_LDA;
+    ops     : 1;
+    optypes : (OT_ABSOLUTE_X,OT_NONE);
+    code    : '$BD';
+    flags   : 0
+  ),
+  (
+    opcode  : A_LDX;
+    ops     : 1;
+    optypes : (OT_IMMEDIATE,OT_NONE);
+    code    : '$A2';
+    flags   : 0
+  ),
+  (
+    opcode  : A_LDX;
+    ops     : 1;
+    optypes : (OT_ZERO_PAGE,OT_NONE);
+    code    : '$A6';
+    flags   : 0
+  ),
+  (
+    opcode  : A_LDX;
+    ops     : 1;
+    optypes : (OT_ABSOLUTE,OT_NONE);
+    code    : '$AE';
+    flags   : 0
+  ),
+  (
+    opcode  : A_LDX;
+    ops     : 1;
+    optypes : (OT_ZERO_PAGE_Y,OT_NONE);
+    code    : '$B6';
+    flags   : 0
+  ),
+  (
+    opcode  : A_LDX;
+    ops     : 1;
+    optypes : (OT_ABSOLUTE_Y,OT_NONE);
+    code    : '$BE';
+    flags   : 0
+  ),
+  (
+    opcode  : A_LDY;
+    ops     : 1;
+    optypes : (OT_IMMEDIATE,OT_NONE);
+    code    : '$A0';
+    flags   : 0
+  ),
+  (
+    opcode  : A_LDY;
+    ops     : 1;
+    optypes : (OT_ZERO_PAGE,OT_NONE);
+    code    : '$A4';
+    flags   : 0
+  ),
+  (
+    opcode  : A_LDY;
+    ops     : 1;
+    optypes : (OT_ABSOLUTE,OT_NONE);
+    code    : '$AC';
+    flags   : 0
+  ),
+  (
+    opcode  : A_LDY;
+    ops     : 1;
+    optypes : (OT_ZERO_PAGE_X,OT_NONE);
+    code    : '$B4';
+    flags   : 0
+  ),
+  (
+    opcode  : A_LDY;
+    ops     : 1;
+    optypes : (OT_ABSOLUTE_X,OT_NONE);
+    code    : '$BC';
+    flags   : 0
+  ),
+  (
+    opcode  : A_LSR;
+    ops     : 1;
+    optypes : (OT_ZERO_PAGE,OT_NONE);
+    code    : '$46';
+    flags   : 0
+  ),
+  (
+    opcode  : A_LSR;
+    ops     : 1;
+    optypes : (OT_ACCUMULATOR,OT_NONE);
+    code    : '$4A';
+    flags   : 0
+  ),
+  (
+    opcode  : A_LSR;
+    ops     : 1;
+    optypes : (OT_ABSOLUTE,OT_NONE);
+    code    : '$4E';
+    flags   : 0
+  ),
+  (
+    opcode  : A_LSR;
+    ops     : 1;
+    optypes : (OT_ZERO_PAGE_X,OT_NONE);
+    code    : '$56';
+    flags   : 0
+  ),
+  (
+    opcode  : A_LSR;
+    ops     : 1;
+    optypes : (OT_ABSOLUTE_X,OT_NONE);
+    code    : '$5E';
+    flags   : 0
+  ),
+  (
+    opcode  : A_NOP;
+    ops     : 0;
+    optypes : (OT_NONE,OT_NONE);
+    code    : '$EA';
+    flags   : 0
+  ),
+  (
+    opcode  : A_ORA;
+    ops     : 1;
+    optypes : (OT_INDEXED_INDIRECT,OT_NONE);
+    code    : '$01';
+    flags   : 0
+  ),
+  (
+    opcode  : A_ORA;
+    ops     : 1;
+    optypes : (OT_ZERO_PAGE,OT_NONE);
+    code    : '$05';
+    flags   : 0
+  ),
+  (
+    opcode  : A_ORA;
+    ops     : 1;
+    optypes : (OT_IMMEDIATE,OT_NONE);
+    code    : '$09';
+    flags   : 0
+  ),
+  (
+    opcode  : A_ORA;
+    ops     : 1;
+    optypes : (OT_ABSOLUTE,OT_NONE);
+    code    : '$0D';
+    flags   : 0
+  ),
+  (
+    opcode  : A_ORA;
+    ops     : 1;
+    optypes : (OT_INDIRECT_INDEXED,OT_NONE);
+    code    : '$11';
+    flags   : 0
+  ),
+  (
+    opcode  : A_ORA;
+    ops     : 1;
+    optypes : (OT_ZERO_PAGE_X,OT_NONE);
+    code    : '$15';
+    flags   : 0
+  ),
+  (
+    opcode  : A_ORA;
+    ops     : 1;
+    optypes : (OT_ABSOLUTE_Y,OT_NONE);
+    code    : '$19';
+    flags   : 0
+  ),
+  (
+    opcode  : A_ORA;
+    ops     : 1;
+    optypes : (OT_ABSOLUTE_X,OT_NONE);
+    code    : '$1D';
+    flags   : 0
+  ),
+  (
+    opcode  : A_PHA;
+    ops     : 0;
+    optypes : (OT_NONE,OT_NONE);
+    code    : '$48';
+    flags   : 0
+  ),
+  (
+    opcode  : A_PHP;
+    ops     : 0;
+    optypes : (OT_NONE,OT_NONE);
+    code    : '$08';
+    flags   : 0
+  ),
+  (
+    opcode  : A_PLA;
+    ops     : 0;
+    optypes : (OT_NONE,OT_NONE);
+    code    : '$68';
+    flags   : 0
+  ),
+  (
+    opcode  : A_PLP;
+    ops     : 0;
+    optypes : (OT_NONE,OT_NONE);
+    code    : '$28';
+    flags   : 0
+  ),
+  (
+    opcode  : A_ROL;
+    ops     : 1;
+    optypes : (OT_ZERO_PAGE,OT_NONE);
+    code    : '$26';
+    flags   : 0
+  ),
+  (
+    opcode  : A_ROL;
+    ops     : 1;
+    optypes : (OT_ACCUMULATOR,OT_NONE);
+    code    : '$2A';
+    flags   : 0
+  ),
+  (
+    opcode  : A_ROL;
+    ops     : 1;
+    optypes : (OT_ABSOLUTE,OT_NONE);
+    code    : '$2E';
+    flags   : 0
+  ),
+  (
+    opcode  : A_ROL;
+    ops     : 1;
+    optypes : (OT_ZERO_PAGE_X,OT_NONE);
+    code    : '$36';
+    flags   : 0
+  ),
+  (
+    opcode  : A_ROL;
+    ops     : 1;
+    optypes : (OT_ABSOLUTE_X,OT_NONE);
+    code    : '$3E';
+    flags   : 0
+  ),
+  (
+    opcode  : A_ROR;
+    ops     : 1;
+    optypes : (OT_ZERO_PAGE,OT_NONE);
+    code    : '$66';
+    flags   : 0
+  ),
+  (
+    opcode  : A_ROR;
+    ops     : 1;
+    optypes : (OT_ACCUMULATOR,OT_NONE);
+    code    : '$6A';
+    flags   : 0
+  ),
+  (
+    opcode  : A_ROR;
+    ops     : 1;
+    optypes : (OT_ABSOLUTE,OT_NONE);
+    code    : '$6E';
+    flags   : 0
+  ),
+  (
+    opcode  : A_ROR;
+    ops     : 1;
+    optypes : (OT_ZERO_PAGE_X,OT_NONE);
+    code    : '$76';
+    flags   : 0
+  ),
+  (
+    opcode  : A_ROR;
+    ops     : 1;
+    optypes : (OT_ABSOLUTE_X,OT_NONE);
+    code    : '$7E';
+    flags   : 0
+  ),
+  (
+    opcode  : A_RTI;
+    ops     : 0;
+    optypes : (OT_NONE,OT_NONE);
+    code    : '$40';
+    flags   : 0
+  ),
+  (
+    opcode  : A_RTS;
+    ops     : 0;
+    optypes : (OT_NONE,OT_NONE);
+    code    : '$60';
+    flags   : 0
+  ),
+  (
+    opcode  : A_SBC;
+    ops     : 1;
+    optypes : (OT_INDEXED_INDIRECT,OT_NONE);
+    code    : '$E1';
+    flags   : 0
+  ),
+  (
+    opcode  : A_SBC;
+    ops     : 1;
+    optypes : (OT_ZERO_PAGE,OT_NONE);
+    code    : '$E5';
+    flags   : 0
+  ),
+  (
+    opcode  : A_SBC;
+    ops     : 1;
+    optypes : (OT_IMMEDIATE,OT_NONE);
+    code    : '$E9';
+    flags   : 0
+  ),
+  (
+    opcode  : A_SBC;
+    ops     : 1;
+    optypes : (OT_ABSOLUTE,OT_NONE);
+    code    : '$ED';
+    flags   : 0
+  ),
+  (
+    opcode  : A_SBC;
+    ops     : 1;
+    optypes : (OT_INDIRECT_INDEXED,OT_NONE);
+    code    : '$F1';
+    flags   : 0
+  ),
+  (
+    opcode  : A_SBC;
+    ops     : 1;
+    optypes : (OT_ZERO_PAGE_X,OT_NONE);
+    code    : '$F5';
+    flags   : 0
+  ),
+  (
+    opcode  : A_SBC;
+    ops     : 1;
+    optypes : (OT_ABSOLUTE_Y,OT_NONE);
+    code    : '$F9';
+    flags   : 0
+  ),
+  (
+    opcode  : A_SBC;
+    ops     : 1;
+    optypes : (OT_ABSOLUTE_X,OT_NONE);
+    code    : '$FD';
+    flags   : 0
+  ),
+  (
+    opcode  : A_SEC;
+    ops     : 0;
+    optypes : (OT_NONE,OT_NONE);
+    code    : '$38';
+    flags   : 0
+  ),
+  (
+    opcode  : A_SED;
+    ops     : 0;
+    optypes : (OT_NONE,OT_NONE);
+    code    : '$F8';
+    flags   : 0
+  ),
+  (
+    opcode  : A_SEI;
+    ops     : 0;
+    optypes : (OT_NONE,OT_NONE);
+    code    : '$78';
+    flags   : 0
+  ),
+  (
+    opcode  : A_STA;
+    ops     : 1;
+    optypes : (OT_INDEXED_INDIRECT,OT_NONE);
+    code    : '$81';
+    flags   : 0
+  ),
+  (
+    opcode  : A_STA;
+    ops     : 1;
+    optypes : (OT_ZERO_PAGE,OT_NONE);
+    code    : '$85';
+    flags   : 0
+  ),
+  (
+    opcode  : A_STA;
+    ops     : 1;
+    optypes : (OT_ABSOLUTE,OT_NONE);
+    code    : '$8D';
+    flags   : 0
+  ),
+  (
+    opcode  : A_STA;
+    ops     : 1;
+    optypes : (OT_INDIRECT_INDEXED,OT_NONE);
+    code    : '$91';
+    flags   : 0
+  ),
+  (
+    opcode  : A_STA;
+    ops     : 1;
+    optypes : (OT_ZERO_PAGE_X,OT_NONE);
+    code    : '$95';
+    flags   : 0
+  ),
+  (
+    opcode  : A_STA;
+    ops     : 1;
+    optypes : (OT_ABSOLUTE_Y,OT_NONE);
+    code    : '$99';
+    flags   : 0
+  ),
+  (
+    opcode  : A_STA;
+    ops     : 1;
+    optypes : (OT_ABSOLUTE_X,OT_NONE);
+    code    : '$9D';
+    flags   : 0
+  ),
+  (
+    opcode  : A_STX;
+    ops     : 1;
+    optypes : (OT_ZERO_PAGE,OT_NONE);
+    code    : '$86';
+    flags   : 0
+  ),
+  (
+    opcode  : A_STX;
+    ops     : 1;
+    optypes : (OT_ABSOLUTE,OT_NONE);
+    code    : '$8E';
+    flags   : 0
+  ),
+  (
+    opcode  : A_STX;
+    ops     : 1;
+    optypes : (OT_ZERO_PAGE_Y,OT_NONE);
+    code    : '$96';
+    flags   : 0
+  ),
+  (
+    opcode  : A_STY;
+    ops     : 1;
+    optypes : (OT_ZERO_PAGE,OT_NONE);
+    code    : '$84';
+    flags   : 0
+  ),
+  (
+    opcode  : A_STY;
+    ops     : 1;
+    optypes : (OT_ABSOLUTE,OT_NONE);
+    code    : '$8C';
+    flags   : 0
+  ),
+  (
+    opcode  : A_STY;
+    ops     : 1;
+    optypes : (OT_ZERO_PAGE_X,OT_NONE);
+    code    : '$94';
+    flags   : 0
+  ),
+  (
+    opcode  : A_TAX;
+    ops     : 0;
+    optypes : (OT_NONE,OT_NONE);
+    code    : '$AA';
+    flags   : 0
+  ),
+  (
+    opcode  : A_TAY;
+    ops     : 0;
+    optypes : (OT_NONE,OT_NONE);
+    code    : '$A8';
+    flags   : 0
+  ),
+  (
+    opcode  : A_TSX;
+    ops     : 0;
+    optypes : (OT_NONE,OT_NONE);
+    code    : '$BA';
+    flags   : 0
+  ),
+  (
+    opcode  : A_TXA;
+    ops     : 0;
+    optypes : (OT_NONE,OT_NONE);
+    code    : '$8A';
+    flags   : 0
+  ),
+  (
+    opcode  : A_TXS;
+    ops     : 0;
+    optypes : (OT_NONE,OT_NONE);
+    code    : '$9A';
+    flags   : 0
+  ),
+  (
+    opcode  : A_TYA;
+    ops     : 0;
+    optypes : (OT_NONE,OT_NONE);
+    code    : '$98';
+    flags   : 0
+  )
+);

+ 235 - 0
compiler/utils/mk6502ins.pp

@@ -0,0 +1,235 @@
+{
+    Copyright (c) 2020, 2024 by Nikolay Nikolov
+
+    Convert mos6502ins.dat to a set of .inc files for usage with
+    the Free pascal compiler
+
+    See the file COPYING.FPC, included in this distribution,
+    for details about the copyright.
+
+    This program is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+
+ **********************************************************************}
+
+program mk6502ins;
+
+{$mode objfpc}{$H+}
+
+uses
+  SysUtils;
+
+const
+  Version = '1.0.0';
+  HeaderStr = '{ don''t edit, this file is generated from mos6502ins.dat; to regenerate, run ''make insdat'' in the compiler directory }';
+  max_operands = 2;
+
+  ParamTypes: array [0..12,0..1] of string = (
+    ('void',    'OT_IMPLICIT'),
+    ('A',       'OT_ACCUMULATOR'),
+    ('#',       'OT_IMMEDIATE'),
+    ('zpg',     'OT_ZERO_PAGE'),
+    ('zpg,X',   'OT_ZERO_PAGE_X'),
+    ('zpg,Y',   'OT_ZERO_PAGE_Y'),
+    ('rel',     'OT_RELATIVE'),
+    ('abs',     'OT_ABSOLUTE'),
+    ('abs,X',   'OT_ABSOLUTE_X'),
+    ('abs,Y',   'OT_ABSOLUTE_Y'),
+    ('(ind)',   'OT_INDIRECT'),
+    ('(ind,X)', 'OT_INDEXED_INDIRECT'),
+    ('(ind),Y', 'OT_INDIRECT_INDEXED')
+  );
+
+type
+
+  { TMOS6502InsDatOutputFiles }
+
+  TMOS6502InsDatOutputFiles = class
+  public
+    OpFile: TextFile;
+    NOpFile: TextFile;
+    StdOpNames: TextFile;
+    InsTabFile: TextFile;
+
+    constructor Create;
+    destructor Destroy;override;
+  end;
+
+{ ***************************************************************************
+  the routines LeftStr, AnsiStartsStr are copied and reformatted
+  from StrUtils and thus covered by the copyright of strutils (see below) as compiler utilities cannot
+  depend on packages
+
+    This file is part of the Free Pascal run time library.
+    Copyright (c) 1999-2005 by the Free Pascal development team
+
+    See the file COPYING.FPC, included in this distribution,
+    for details about the copyright.
+
+    This program is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+*************************************************************************** }
+
+function LeftStr(const AText: AnsiString; const ACount: SizeInt): AnsiString;
+  begin
+    Result:=Copy(AText,1,ACount);
+  end;
+
+
+function AnsiStartsStr(const ASubText, AText: string): Boolean;
+  begin
+    Result := (ASubText = '') or (LeftStr(AText, Length(ASubText)) = ASubText);
+  end;
+
+{ ***************************************************************************
+ end of StrUtils code
+***************************************************************************}
+
+function PasEncode(const S: string): string;
+  var
+    Ch: Char;
+    InQuotes: Boolean;
+  begin
+    Result:='';
+    InQuotes:=False;
+    for Ch in S do
+      if (Ch>=#32) and (Ch<=#126) then
+        begin
+          if not InQuotes then
+            begin
+              Result:=Result+'''';
+              InQuotes:=True;
+            end;
+          if Ch='''' then
+            Result:=Result+''''''
+          else
+            Result:=Result+Ch;
+        end
+      else
+        begin
+          if InQuotes then
+            begin
+              Result:=Result+'''';
+              InQuotes:=False;
+            end;
+          Result:=Result+'#'+IntToStr(Ord(Ch));
+        end;
+    if InQuotes then
+      Result:=Result+'''';
+    if Result='' then
+      Result:='''''';
+  end;
+
+constructor TMOS6502InsDatOutputFiles.Create;
+  begin
+    AssignFile(OpFile,'mos6502op.inc');
+    Rewrite(OpFile);
+    Writeln(OpFile,HeaderStr);
+    Writeln(OpFile,'(');
+    AssignFile(NOpFile,'mos6502nop.inc');
+    Rewrite(NOpFile);
+    Writeln(NOpFile,HeaderStr);
+    AssignFile(StdOpNames,'mos6502stdopnames.inc');
+    Rewrite(StdOpNames);
+    Writeln(StdOpNames,HeaderStr);
+    Writeln(StdOpNames,'(');
+    AssignFile(InsTabFile,'mos6502tab.inc');
+    Rewrite(InsTabFile);
+    Writeln(InsTabFile,HeaderStr);
+    Writeln(InsTabFile,'(');
+  end;
+
+destructor TMOS6502InsDatOutputFiles.Destroy;
+  begin
+    CloseFile(OpFile);
+    CloseFile(NOpFile);
+    CloseFile(StdOpNames);
+    CloseFile(InsTabFile);
+    inherited Destroy;
+  end;
+
+function FindParamType(const ParamTypeStr: string): Integer;
+var
+  I: Integer;
+begin
+  for I:=Low(ParamTypes) to High(ParamTypes) do
+    if ParamTypes[I,0]=ParamTypeStr then
+      exit(I);
+  raise Exception.Create('Invalid param type: '''+ParamTypeStr+'''');
+end;
+
+var
+  InsDatFile: TextFile;
+  OutputFiles: TMOS6502InsDatOutputFiles=nil;
+  S, op, ParamsStr: string;
+  FirstIns: Boolean=true;
+  OpCount: Integer=0;
+  S_Split, S_Params: TStringArray;
+  ParamIdx: Integer;
+begin
+  writeln('FPC 6502 Instruction Table Converter Version ',Version);
+  AssignFile(InsDatFile,'../mos6502/mos6502ins.dat');
+  Reset(InsDatFile);
+  try
+    OutputFiles:=TMOS6502InsDatOutputFiles.Create;
+    while not EoF(InsDatFile) do
+      begin
+        Readln(InsDatFile,S);
+        S:=Trim(S);
+        if AnsiStartsStr(';',S) then
+          continue
+        else if AnsiStartsStr('[',S) then
+          begin
+            op:=Copy(S,2,Length(S)-2);
+            if not FirstIns then
+              begin
+                Writeln(OutputFiles.OpFile,',');
+                Writeln(OutputFiles.StdOpNames,',');
+              end;
+            FirstIns:=False;
+            Write(OutputFiles.OpFile,'A_'+op);
+            Write(OutputFiles.StdOpNames,''''+LowerCase(op)+'''');
+          end
+        else if S<>'' then
+          begin
+            Inc(OpCount);
+            if OpCount<>1 then
+              Writeln(OutputFiles.InsTabFile,',');
+            S_Split:=S.Split(' ',TStringSplitOptions.ExcludeEmpty);
+            S_Params:=S_Split[0].Split('!',TStringSplitOptions.ExcludeEmpty);
+            if (Length(S_Params)=1) and (S_Params[0]='void') then
+              SetLength(S_Params,0);
+            Writeln(OutputFiles.InsTabFile,'  (');
+            Writeln(OutputFiles.InsTabFile,'    opcode  : A_',op,';');
+            Writeln(OutputFiles.InsTabFile,'    ops     : ',Length(S_Params),';');
+            Write(OutputFiles.InsTabFile,  '    optypes : (');
+            if Length(S_Params)>max_operands then
+              raise Exception.Create('Too many operands');
+            for ParamIdx:=0 to max_operands-1 do
+              begin
+                if ParamIdx<>0 then
+                  Write(OutputFiles.InsTabFile,',');
+                if ParamIdx<=High(S_Params) then
+                  Write(OutputFiles.InsTabFile,ParamTypes[FindParamType(S_Params[ParamIdx]),1])
+                else
+                  Write(OutputFiles.InsTabFile,'OT_NONE');
+              end;
+            Writeln(OutputFiles.InsTabFile, ');');
+            Writeln(OutputFiles.InsTabFile,  '    code    : ',PasEncode(S_Split[1]),';');
+            Writeln(OutputFiles.InsTabFile,  '    flags   : 0');
+            Write(OutputFiles.InsTabFile,  '  )');
+          end;
+      end;
+    Writeln(OutputFiles.OpFile,');');
+    Writeln(OutputFiles.StdOpNames,');');
+    Writeln(OutputFiles.NOpFile,OpCount,';');
+    Writeln(OutputFiles.InsTabFile);
+    Writeln(OutputFiles.InsTabFile,');');
+  finally
+    FreeAndNil(OutputFiles);
+    CloseFile(InsDatFile);
+  end;
+end.
+