All files / asm80-core/cpu cdp1802.js

100% Statements 205/205
100% Branches 34/34
100% Functions 6/6
100% Lines 205/205

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 2061x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 21x 21x 21x 21x 21x 21x 2x 21x 21x 21x 21x 20x 20x 1x 1x 1x 20x 2x 2x 2x 2x 20x 20x 2x 2x 2x 2x 20x 20x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 20x 20x 20x 7x 7x 7x 5x 4x 4x 4x 4x 1x 1x 4x 7x 3x 3x 4x 4x 4x 20x 5x 5x 5x 1x 1x 1x 1x 1x 1x 1x 5x 3x 3x 2x 2x 2x 20x 20x 20x 1x 1x 21x 1x  
/*
The MIT License (MIT)
 
Copyright (c) 2014 Martin Maly, maly@maly.cz
 
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
 
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
 
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
 
 
 
 */
 
export const CDP1802 = {
  endian: true,
  cpu: "cdp1802",
  ext: "a18",
  set: {
    //typ 0 - bez parm.
    //1 - IMM
    //2 - reg
    //3 - addr. 8bit
    //4 - addr 16bit
    //5 - port (1-7)
    "ADC" :[0x74,0],
    "ADCI":[0x7C,1],
    "ADD" :[0xF4,0],
    "ADI" :[0xFC,1],
    "AND" :[0xF2,0],
    "ANI" :[0xFA,1],
    "B1"  :[0x34,3],
    "B2"  :[0x35,3],
    "B3"  :[0x36,3],
    "B4"  :[0x37,3],
    "BDF" :[0x33,3],
    "BN1" :[0x3C,3],
    "BN2" :[0x3D,3],
    "BN3" :[0x3E,3],
    "BN4" :[0x3F,3],
    "BNF" :[0x3B,3],
    "BNQ" :[0x39,3],
    "BNZ" :[0x3A,3],
    "BQ"  :[0x31,3],
    "BR"  :[0x30,3],
    "BZ"  :[0x32,3],
    "DEC" :[0x20,2],
    "DIS" :[0x71,0],
    "GHI" :[0x90,2],
    "GLO" :[0x80,2],
    "IDL" :[0x00,0],
    "INC" :[0x10,2],
    "INP" :[0x68,5],
    "IRX" :[0x60,0],
    "LBDF":[0xC3,4],
    "LBNF":[0xCB,4],
    "LBNQ":[0xC9,4],
    "LBNZ":[0xCA,4],
    "LBQ" :[0xC1,4],
    "LBR" :[0xC0,4],
    "LBZ" :[0xC2,4],
    "LDA" :[0x40,2],
    "LDI" :[0xF8,1],
    "LDN" :[0x00,2],
    "LDX" :[0xF0,0],
    "LDXA":[0x72,0],
    "LSDF":[0xCF,0],
    "LSIE":[0xCC,0],
    "LSKP":[0xC8,0],
    "LSNF":[0xC7,0],
    "LSNQ":[0xC5,0],
    "LSNZ":[0xC6,0],
    "LSQ" :[0xCD,0],
    "LSZ" :[0xCE,0],
    "MARK":[0x79,0],
    "NOP" :[0xC4,0],
    "OR"  :[0xF1,0],
    "ORI" :[0xF9,1],
    "OUT" :[0x60,5],
    "PHI" :[0xB0,2],
    "PLO" :[0xA0,2],
    "REQ" :[0x7A,0],
    "RET" :[0x70,0],
    "SAV" :[0x78,0],
    "SD"  :[0xF5,0],
    "SDB" :[0x75,0],
    "SDBI":[0x7D,1],
    "SDI" :[0xFD,1],
    "SEP" :[0xD0,2],
    "SEQ" :[0x7B,0],
    "SEX" :[0xE0,2],
    "SHL" :[0xFE,0],
    "SHLC":[0x7E,0],
    "SHR" :[0xF6,0],
    "SHRC":[0x76,0],
    "SKP" :[0x38,0],
    "SM"  :[0xF7,0],
    "SMB" :[0x77,0],
    "SMBI":[0x7F,1],
    "SMI" :[0xFF,1],
    "STR" :[0x50,2],
    "STXD":[0x73,0],
    "XOR" :[0xF3,0],
    "XRI" :[0xFB,1]
  },
 
 
 
  parseOpcode: function(s, vars, Parser) {
    var p1;
    var ax = CDP1802.set[s.opcode];
 
    s.lens=[];
 
    var fixhash = function(p) {
      return p.replace("#","$");
    };
 
 
    if (ax) {
      switch(ax[1]) {
        case 0: //0 params.
          s.lens = [ax[0]];
          s.bytes = 1;
          return s;
        case 1: //IMM param.
          p1 = fixhash(s.params[0]+'');
          s.lens = [ax[0], function(vars){return Parser.evaluate(p1,vars) & 0xFF;}];
          s.bytes = 2;
          return s;
 
        case 4: //Long address
          p1 = s.params[0]+'';
          s.lens = [ax[0], function(vars){return Parser.evaluate(p1,vars) & 0xFF;}, function(vars){return (Parser.evaluate(p1,vars) >> 8) & 0xFF;}];
          s.bytes = 3;
          return s;
 
        case 3: //Short address
          p1 = s.params[0]+'';
          s.lens = [ax[0], function(vars){
            var n= Parser.evaluate(p1,vars);
            var nx = n & 0xff;
            var npc = vars._PC;
            var nt = npc & 0xff00 | nx;
            if (nt!=n) throw "Cross page jump";
            return nx;}];
          s.bytes = 2;
          return s;
 
 
        case 2: //REGNUM
          p1 = s.params[0]+'';
          var regnum;
          if(p1.length==1) {regnum = parseInt(p1,16);} else
          if((p1.length==2 || p1.length==3) && p1[0].toUpperCase()=='R') {regnum = parseInt(p1.substr(1),10);} else
          {
            try {
              regnum = Parser.evaluate(p1,vars);
            } catch (e){
              regnum = NaN;
            }
          }
          if (isNaN(regnum) || regnum>15 || regnum<0) {
            throw "Unrecognized register: "+p1;
          }
          s.lens = [ax[0]+regnum];
          s.bytes = 1;
          return s;
        case 5: //PORT
          p1 = s.params[0]+'';
          var portnum;
          if(p1.length==1) {portnum = parseInt(p1,10);} else
          {
            try {
              portnum = Parser.evaluate(p1,vars);
            } catch (e){
              portnum = NaN;
            }
          }
          if (isNaN(portnum) || portnum>7 || portnum<1) {
            throw "Unrecognized port: "+p1;
          }
          s.lens = [ax[0]+portnum];
          s.bytes = 1;
          return s;
      }
 
    }
    // not found
    return null;
  }
};