home *** CD-ROM | disk | FTP | other *** search
/ The Fatted Calf / The Fatted Calf.iso / Applications / Misc / a2 / Source / table.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-03-21  |  10.2 KB  |  414 lines

  1. /*
  2.  *  a2, an Apple II emulator in C
  3.  *  (c) Copyright 1990 by Rich Skrenta
  4.  *
  5.  *  Command line interface written by Tom Markson
  6.  *
  7.  *  Distribution agreement:
  8.  *
  9.  *    You may freely copy or redistribute this software, so long
  10.  *    as there is no profit made from its use, sale, trade or
  11.  *    reproduction.  You may not change this copyright notice,
  12.  *    and it must be included prominently in any copy made.
  13.  *
  14.  *  Send emulator related mail to:  skrenta@blekko.commodore.com
  15.  *                    skrenta@blekko.uucp
  16.  */
  17.  
  18.  
  19.  
  20. #import    <stdio.h>
  21. #import    "a2.h"
  22.  
  23.  
  24.  
  25. struct op_info opcode[] = {
  26.     {"brk",    M_NONE},    /* 0x0 */
  27.     {"ora",    M_INDX},    /* 0x1 */
  28.     {"",    M_NONE},    /* 0x2 */
  29.     {"",    M_NONE},    /* 0x3 */
  30.     {"tsb",    M_ZP},        /* 0x4 */    /* 65C02 */
  31.     {"ora",    M_ZP},        /* 0x5 */
  32.     {"asl",    M_ZP},        /* 0x6 */
  33.     {"",    M_NONE},    /* 0x7 */
  34.     {"php",    M_NONE},    /* 0x8 */
  35.     {"ora",    M_IMM},        /* 0x9 */
  36.     {"asl",    M_NONE},    /* 0xa */
  37.     {"",    M_NONE},    /* 0xb */
  38.     {"tsb",    M_ABS},        /* 0xc */    /* 65C02 */
  39.     {"ora",    M_ABS},        /* 0xd */
  40.     {"asl",    M_ABS},        /* 0xe */
  41.     {"",    M_NONE},    /* 0xf */
  42.     {"bpl",    M_REL},        /* 0x10 */
  43.     {"ora",    M_INDY},    /* 0x11 */
  44.     {"ora",    M_ZIND},    /* 0x12 */    /* 65C02 */
  45.     {"",    M_NONE},    /* 0x13 */
  46.     {"trb",    M_ZP},        /* 0x14 */    /* 65C02 */
  47.     {"ora",    M_ZPX},        /* 0x15 */
  48.     {"asl",    M_ZPX},        /* 0x16 */
  49.     {"",    M_NONE},    /* 0x17 */
  50.     {"clc",    M_NONE},    /* 0x18 */
  51.     {"ora",    M_ABSY},    /* 0x19 */
  52.     {"ina",    M_NONE},    /* 0x1a */    /* 65C02 */
  53.     {"",    M_NONE},    /* 0x1b */
  54.     {"trb",    M_ABS},        /* 0x1c */    /* 65C02 */
  55.     {"ora",    M_ABSX},    /* 0x1d */
  56.     {"asl",    M_ABSX},    /* 0x1e */
  57.     {"",    M_NONE},    /* 0x1f */
  58.     {"jsr",    M_ABS},        /* 0x20 */
  59.     {"and",    M_INDX},    /* 0x21 */
  60.     {"",    M_NONE},    /* 0x22 */
  61.     {"",    M_NONE},    /* 0x23 */
  62.     {"bit",    M_ZP},        /* 0x24 */
  63.     {"and",    M_ZP},        /* 0x25 */
  64.     {"rol",    M_ZP},        /* 0x26 */
  65.     {"",    M_NONE},    /* 0x27 */
  66.     {"plp",    M_NONE},    /* 0x28 */
  67.     {"and",    M_IMM},        /* 0x29 */
  68.     {"rol",    M_NONE},    /* 0x2a */
  69.     {"",    M_NONE},    /* 0x2b */
  70.     {"bit",    M_ABS},        /* 0x2c */
  71.     {"and",    M_ABS},        /* 0x2d */
  72.     {"rol",    M_ABS},        /* 0x2e */
  73.     {"",    M_NONE},    /* 0x2f */
  74.     {"bmi",    M_REL},        /* 0x30 */
  75.     {"and",    M_INDY},    /* 0x31 */
  76.     {"and",    M_ZIND},    /* 0x32 */    /* 65C02 */
  77.     {"",    M_NONE},    /* 0x33 */
  78.     {"bit",    M_ZPX},        /* 0x34 */    /* 65C02 */
  79.     {"and",    M_ZPX},        /* 0x35 */
  80.     {"rol",    M_ZPX},        /* 0x36 */
  81.     {"",    M_NONE},    /* 0x37 */
  82.     {"sec",    M_NONE},    /* 0x38 */
  83.     {"and",    M_ABSY},    /* 0x39 */
  84.     {"dey",    M_NONE},    /* 0x3a */    /* 65C02 */
  85.     {"",    M_NONE},    /* 0x3b */
  86.     {"bit",    M_ABSX},    /* 0x3c */    /* 65C02 */
  87.     {"and",    M_ABSX},    /* 0x3d */
  88.     {"rol",    M_ABSX},    /* 0x3e */
  89.     {"",    M_NONE},    /* 0x3f */
  90.     {"rti",    M_NONE},    /* 0x40 */
  91.     {"eor",    M_INDX},    /* 0x41 */
  92.     {"",    M_NONE},    /* 0x42 */
  93.     {"",    M_NONE},    /* 0x43 */
  94.     {"",    M_NONE},    /* 0x44 */
  95.     {"eor",    M_ZP},        /* 0x45 */
  96.     {"lsr",    M_ZP},        /* 0x46 */
  97.     {"",    M_NONE},    /* 0x47 */
  98.     {"pha",    M_NONE},    /* 0x48 */
  99.     {"eor",    M_IMM},        /* 0x49 */
  100.     {"lsr",    M_NONE},    /* 0x4a */
  101.     {"",    M_NONE},    /* 0x4b */
  102.     {"jmp",    M_ABS},        /* 0x4c */
  103.     {"eor",    M_ABS},        /* 0x4d */
  104.     {"lsr",    M_ABS},        /* 0x4e */
  105.     {"",    M_NONE},    /* 0x4f */
  106.     {"bvc",    M_REL},        /* 0x50 */
  107.     {"eor",    M_INDY},    /* 0x51 */
  108.     {"eor",    M_ZIND},    /* 0x52 */    /* 65C02 */
  109.     {"",    M_NONE},    /* 0x53 */
  110.     {"",    M_NONE},    /* 0x54 */
  111.     {"eor",    M_ZPX},        /* 0x55 */
  112.     {"lsr",    M_ZPX},        /* 0x56 */
  113.     {"",    M_NONE},    /* 0x57 */
  114.     {"cli",    M_NONE},    /* 0x58 */
  115.     {"eor",    M_ABSY},    /* 0x59 */
  116.     {"phy",    M_NONE},    /* 0x5a */    /* 65C02 */
  117.     {"",    M_NONE},    /* 0x5b */
  118.     {"",    M_NONE},    /* 0x5c */
  119.     {"eor",    M_ABSX},    /* 0x5d */
  120.     {"lsr",    M_ABSX},    /* 0x5e */
  121.     {"",    M_NONE},    /* 0x5f */
  122.     {"rts",    M_NONE},    /* 0x60 */
  123.     {"adc",    M_INDX},    /* 0x61 */
  124.     {"",    M_NONE},    /* 0x62 */
  125.     {"",    M_NONE},    /* 0x63 */
  126.     {"stz",    M_ZP},        /* 0x64 */    /* 65C02 */
  127.     {"adc",    M_ZP},        /* 0x65 */
  128.     {"ror",    M_ZP},        /* 0x66 */
  129.     {"",    M_NONE},    /* 0x67 */
  130.     {"pla",    M_NONE},    /* 0x68 */
  131.     {"adc",    M_IMM},        /* 0x69 */
  132.     {"ror",    M_NONE},    /* 0x6a */
  133.     {"",    M_NONE},    /* 0x6b */
  134.     {"jmp",    M_IND},        /* 0x6c */
  135.     {"adc",    M_ABS},        /* 0x6d */
  136.     {"ror",    M_ABS},        /* 0x6e */
  137.     {"",    M_NONE},    /* 0x6f */
  138.     {"bvs",    M_REL},        /* 0x70 */
  139.     {"adc",    M_INDX},    /* 0x71 */
  140.     {"adc",    M_ZIND},    /* 0x72 */    /* 65C02 */
  141.     {"",    M_NONE},    /* 0x73 */
  142.     {"stz",    M_ZPX},        /* 0x74 */    /* 65C02 */
  143.     {"adc",    M_ZPX},        /* 0x75 */
  144.     {"ror",    M_ZPX},        /* 0x76 */
  145.     {"",    M_NONE},    /* 0x77 */
  146.     {"sei",    M_NONE},    /* 0x78 */
  147.     {"adc",    M_ABSY},    /* 0x79 */
  148.     {"ply",    M_NONE},    /* 0x7a */    /* 65C02 */
  149.     {"",    M_NONE},    /* 0x7b */
  150.     {"jmp",    M_ABINDX},    /* 0x7c */    /* 65C02 */
  151.     {"adc",    M_ABSX},    /* 0x7d */
  152.     {"ror",    M_ABSX},    /* 0x7e */
  153.     {"",    M_NONE},    /* 0x7f */
  154.     {"bra",    M_REL},        /* 0x80 */    /* 65C02 */
  155.     {"sta",    M_INDX},    /* 0x81 */
  156.     {"",    M_NONE},    /* 0x82 */
  157.     {"",    M_NONE},    /* 0x83 */
  158.     {"sty",    M_ZP},        /* 0x84 */
  159.     {"sta",    M_ZP},        /* 0x85 */
  160.     {"stx",    M_ZP},        /* 0x86 */
  161.     {"",    M_NONE},    /* 0x87 */
  162.     {"dey",    M_NONE},    /* 0x88 */
  163.     {"",    M_NONE},    /* 0x89 */
  164.     {"txa",    M_NONE},    /* 0x8a */
  165.     {"",    M_NONE},    /* 0x8b */
  166.     {"sty",    M_ABS},        /* 0x8c */
  167.     {"sta",    M_ABS},        /* 0x8d */
  168.     {"stx",    M_ABS},        /* 0x8e */
  169.     {"",    M_NONE},    /* 0x8f */
  170.     {"bcc",    M_REL},        /* 0x90 */
  171.     {"sta",    M_INDY},    /* 0x91 */
  172.     {"sta",    M_ZIND},    /* 0x92 */    /* 65C02 */
  173.     {"",    M_NONE},    /* 0x93 */
  174.     {"sty",    M_ZPX},        /* 0x94 */
  175.     {"sta",    M_ZPX},        /* 0x95 */
  176.     {"stx",    M_ZPX},        /* 0x96 */
  177.     {"",    M_NONE},    /* 0x97 */
  178.     {"tya",    M_NONE},    /* 0x98 */
  179.     {"sta",    M_ABSY},    /* 0x99 */
  180.     {"txs",    M_NONE},    /* 0x9a */
  181.     {"",    M_NONE},    /* 0x9b */
  182.     {"stz",    M_ABS},        /* 0x9c */    /* 65C02 */
  183.     {"sta",    M_ABSX},    /* 0x9d */
  184.     {"stz",    M_ABSX},    /* 0x9e */    /* 65C02 */
  185.     {"",    M_NONE},    /* 0x9f */
  186.     {"ldy",    M_IMM},        /* 0xa0 */
  187.     {"lda",    M_INDX},    /* 0xa1 */
  188.     {"ldx",    M_IMM},        /* 0xa2 */
  189.     {"",    M_NONE},    /* 0xa3 */
  190.     {"ldy",    M_ZP},        /* 0xa4 */
  191.     {"lda",    M_ZP},        /* 0xa5 */
  192.     {"ldx",    M_ZP},        /* 0xa6 */
  193.     {"",    M_NONE},    /* 0xa7 */
  194.     {"tay",    M_NONE},    /* 0xa8 */
  195.     {"lda",    M_IMM},        /* 0xa9 */
  196.     {"tax",    M_NONE},    /* 0xaa */
  197.     {"",    M_NONE},    /* 0xab */
  198.     {"ldy",    M_ABS},        /* 0xac */
  199.     {"lda",    M_ABS},        /* 0xad */
  200.     {"ldx",    M_ABS},        /* 0xae */
  201.     {"",    M_NONE},    /* 0xaf */
  202.     {"bcs",    M_REL},        /* 0xb0 */
  203.     {"lda",    M_INDY},    /* 0xb1 */
  204.     {"lda",    M_ZIND},    /* 0xb2 */    /* 65C02 */
  205.     {"",    M_NONE},    /* 0xb3 */
  206.     {"ldy",    M_ZPX},        /* 0xb4 */
  207.     {"lda",    M_ZPX},        /* 0xb5 */
  208.     {"ldx",    M_ZPY},        /* 0xb6 */
  209.     {"",    M_NONE},    /* 0xb7 */
  210.     {"clv",    M_NONE},    /* 0xb8 */
  211.     {"lda",    M_ABSY},    /* 0xb9 */
  212.     {"tsx",    M_NONE},    /* 0xba */
  213.     {"",    M_NONE},    /* 0xbb */
  214.     {"ldy",    M_ABSX},    /* 0xbc */
  215.     {"lda",    M_ABSX},    /* 0xbd */
  216.     {"ldx",    M_ABSY},    /* 0xbe */
  217.     {"",    M_NONE},    /* 0xbf */
  218.     {"cpy",    M_IMM},        /* 0xc0 */
  219.     {"cmp",    M_INDX},    /* 0xc1 */
  220.     {"",    M_NONE},    /* 0xc2 */
  221.     {"",    M_NONE},    /* 0xc3 */
  222.     {"cpy",    M_ZP},        /* 0xc4 */
  223.     {"cmp",    M_ZP},        /* 0xc5 */
  224.     {"dec",    M_ZP},        /* 0xc6 */
  225.     {"",    M_NONE},    /* 0xc7 */
  226.     {"iny",    M_NONE},    /* 0xc8 */
  227.     {"cmp",    M_IMM},        /* 0xc9 */
  228.     {"dex",    M_NONE},    /* 0xca */
  229.     {"",    M_NONE},    /* 0xcb */
  230.     {"cpy",    M_ABS},        /* 0xcc */
  231.     {"cmp",    M_ABS},        /* 0xcd */
  232.     {"dec",    M_ABS},        /* 0xce */
  233.     {"",    M_NONE},    /* 0xcf */
  234.     {"bne",    M_REL},        /* 0xd0 */
  235.     {"cmp",    M_INDY},    /* 0xd1 */
  236.     {"cmp",    M_ZIND},    /* 0xd2 */    /* 65C02 */
  237.     {"",    M_NONE},    /* 0xd3 */
  238.     {"",    M_NONE},    /* 0xd4 */
  239.     {"cmp",    M_ZPX},        /* 0xd5 */
  240.     {"dec",    M_ZPX},        /* 0xd6 */
  241.     {"",    M_NONE},    /* 0xd7 */
  242.     {"cld",    M_NONE},    /* 0xd8 */
  243.     {"cmp",    M_ABSY},    /* 0xd9 */
  244.     {"phx",    M_NONE},    /* 0xda */    /* 65C02 */
  245.     {"",    M_NONE},    /* 0xdb */
  246.     {"",    M_NONE},    /* 0xdc */
  247.     {"cmp",    M_ABSX},    /* 0xdd */
  248.     {"dec",    M_ABSX},    /* 0xde */
  249.     {"",    M_NONE},    /* 0xdf */
  250.     {"cpx",    M_IMM},        /* 0xe0 */
  251.     {"sbc",    M_INDX},    /* 0xe1 */
  252.     {"",    M_NONE},    /* 0xe2 */
  253.     {"",    M_NONE},    /* 0xe3 */
  254.     {"cpx",    M_ZP},        /* 0xe4 */
  255.     {"sbc",    M_ZP},        /* 0xe5 */
  256.     {"inc",    M_ZP},        /* 0xe6 */
  257.     {"",    M_NONE},    /* 0xe7 */
  258.     {"inx",    M_NONE},    /* 0xe8 */
  259.     {"sbc",    M_IMM},        /* 0xe9 */
  260.     {"nop",    M_NONE},    /* 0xea */
  261.     {"",    M_NONE},    /* 0xeb */
  262.     {"cpx",    M_ABS},        /* 0xec */
  263.     {"sbc",    M_ABS},        /* 0xed */
  264.     {"inc",    M_ABS},        /* 0xee */
  265.     {"",    M_NONE},    /* 0xef */
  266.     {"beq",    M_REL},        /* 0xf0 */
  267.     {"sbc",    M_INDY},    /* 0xf1 */
  268.     {"sbc",    M_ZIND},    /* 0xf2 */    /* 65C02 */
  269.     {"",    M_NONE},    /* 0xf3 */
  270.     {"",    M_NONE},    /* 0xf4 */
  271.     {"sbc",    M_ZPX},        /* 0xf5 */
  272.     {"inc",    M_ZPX},        /* 0xf6 */
  273.     {"",    M_NONE},    /* 0xf7 */
  274.     {"sed",    M_NONE},    /* 0xf8 */
  275.     {"sbc",    M_ABSY},    /* 0xf9 */
  276.     {"plx",    M_NONE},    /* 0xfa */    /* 65C02 */
  277.     {"",    M_NONE},    /* 0xfb */
  278.     {"",    M_NONE},    /* 0xfc */
  279.     {"sbc",    M_ABSX},    /* 0xfd */
  280.     {"inc",    M_ABSX},    /* 0xfe */
  281.     {"",    M_NONE},    /* 0xff */
  282. };
  283.  
  284.  
  285. int diss(unsigned short pc, FILE *fp)
  286. {
  287. char *s;
  288. int count;
  289. int tmp;
  290. unsigned short addr;
  291. unsigned char one, two, three;
  292.  
  293.     fprintf(fp, "%.4X:  ", pc);
  294.  
  295.     addr = pc;
  296.     one = mem[pc++];
  297.     two = mem[pc++];
  298.     three = mem[pc++];
  299.  
  300.     s = opcode[one].name;
  301.  
  302.     if (s == NULL || *s == '\0')
  303.         s = "???";
  304.  
  305.     switch (opcode[one].add_mode) {
  306.         case 0:
  307.             fprintf(fp, "%.2x        %s           ", one, s);
  308.             count = 1;
  309.             break;
  310.  
  311.         case M_ZP:
  312.             fprintf(fp, "%.2x %.2x     %s  $%.2x      ",
  313.                             one, two, s, two);
  314.             count = 2;
  315.             break;
  316.  
  317.         case M_ZPX:
  318.             fprintf(fp, "%.2x %.2x     %s  $%.2x,X    ",
  319.                             one, two, s, two);
  320.             count = 2;
  321.             break;
  322.  
  323.         case M_ZPY:
  324.             fprintf(fp, "%.2x %.2x     %s  $%.2x,Y    ",
  325.                             one, two, s, two);
  326.             count = 2;
  327.             break;
  328.  
  329.         case M_IND:
  330.             fprintf(fp, "%.2x %.2x %.2x  %s  ($%.4x)  ",
  331.                         one, two, three, s,
  332.                         join(two, three));
  333.             count = 3;
  334.             break;
  335.  
  336.         case M_INDX:
  337.             fprintf(fp, "%.2x %.2x     %s  ($%.2x,X)  ",
  338.                         one, two, s, two);
  339.             count = 2;
  340.             break;
  341.  
  342.         case M_INDY:
  343.             fprintf(fp, "%.2x %.2x     %s  ($%.2x),Y  ",
  344.                         one, two, s, two);
  345.             count = 2;
  346.             break;
  347.  
  348.         case M_ABS:
  349.             fprintf(fp, "%.2x %.2x %.2x  %s  $%.4x    ",
  350.                         one, two, three, s,
  351.                         join(two, three));
  352.             count = 3;
  353.             break;
  354.  
  355.         case M_ABSX:
  356.             fprintf(fp, "%.2x %.2x %.2x  %s  $%.4x,X  ",
  357.                         one, two, three, s,
  358.                         join(two, three));
  359.             count = 3;
  360.             break;
  361.  
  362.         case M_ABSY:
  363.             fprintf(fp, "%.2x %.2x %.2x  %s  $%.4x,Y  ",
  364.                         one, two, three, s,
  365.                         join(two, three));
  366.             count = 3;
  367.             break;
  368.  
  369.         case M_IMM:
  370.             fprintf(fp, "%.2x %.2x     %s  #$%.2x     ",
  371.                         one, two, s, two);
  372.             count = 2;
  373.             break;
  374.  
  375.         case M_REL:
  376.             tmp = two;
  377.             if (tmp > 127)
  378.                 tmp = tmp - 256;
  379.             tmp += addr + 2;
  380.             tmp &= 0xFFFF;
  381.  
  382.             fprintf(fp, "%.2x %.2x     %s  $%.4x    ",
  383.                         one, two, s, tmp);
  384.             count = 2;
  385.             break;
  386.  
  387.         case M_ZIND:
  388.             fprintf(fp, "%.2x %.2x     %s  ($%.2x)    ",
  389.                         one, two, s, two);
  390.             count = 2;
  391.             break;
  392.  
  393.         case M_ABINDX:
  394.             fprintf(fp, "%.2x %.2x %.2x  %s  ($%.4x,X)",
  395.                         one, two, three, s,
  396.                         join(two, three));
  397.             count = 3;
  398.             break;
  399.  
  400.         default:
  401.             fprintf(fp, "%.2x        %s             ", "???", one);
  402.             count = 1;
  403.     }
  404.  
  405.     return(count);
  406. }
  407.  
  408. void flags(FILE *fp)
  409. {
  410.     fprintf(fp, " A=%.2X X=%.2X Y=%.2X SP=%.2X", A, X, Y, Sp);
  411.     fprintf(fp, "  N%d V%d B%d D%d I%d Z%d C%d\n",
  412.                 !!N, !!V, !!B, !!D, !!I, !NZ, !!C);
  413. }
  414.