LCOV - code coverage report
Current view: top level - asar - arch-spc700.cpp (source / functions) Coverage Total Hit
Test: asar.info Lines: 96.3 % 273 263
Test Date: 2024-01-15 16:23:49 Functions: 90.0 % 10 9
Branches: 59.2 % 446 264

             Branch data     Line data    Source code
       1                 :             : #include "asar.h"
       2                 :             : #include "warnings.h"
       3                 :             : #include "errors.h"
       4                 :             : #include "assembleblock.h"
       5                 :             : #include "asar_math.h"
       6                 :             : 
       7                 :             : #include "arch-shared.h"
       8                 :             : 
       9                 :             : #define write1 write1_pick
      10                 :             : 
      11                 :             : static int writesizeto=-1;
      12                 :             : static int inlinestartpos=0;
      13                 :             : 
      14                 :        1074 : static int64_t getnum_ck(const char* math)
      15                 :             : {
      16         [ +  + ]:        1074 :         return pass == 2 ? getnum(math) : 0;
      17                 :             : }
      18                 :             : 
      19                 :           6 : static void inline_finalizeorg()
      20                 :             : {
      21   [ +  +  +  + ]:           6 :         if (writesizeto>=0 && pass==2)
      22                 :             :         {
      23                 :           1 :                 int pcpos=snestopc(writesizeto&0xFFFFFF);
      24   [ -  +  -  - ]:           1 :                 if (pcpos<0) asar_throw_error(2, error_type_block, error_id_snes_address_doesnt_map_to_rom, hex6((unsigned int)realsnespos).data());
      25                 :           1 :                 int num=snespos-startpos;
      26                 :           1 :                 writeromdata_byte(pcpos, (unsigned char)num);
      27                 :           1 :                 writeromdata_byte(pcpos+1, (unsigned char)(num >> 8));
      28                 :             :         }
      29                 :           6 :         writesizeto=-1;
      30                 :           6 : }
      31                 :             : 
      32                 :           3 : static void inline_org(unsigned int num)
      33                 :             : {
      34                 :           3 :         inline_finalizeorg();
      35   [ -  +  -  - ]:           3 :         if (num&~0xFFFF) asar_throw_error(0, error_type_block, error_id_snes_address_out_of_bounds, hex6((unsigned int)num).data());
      36                 :           3 :         writesizeto=realsnespos;
      37                 :           3 :         write2(0x0000);
      38                 :           3 :         write2(num);
      39                 :           3 :         snespos=(int)num;
      40                 :           3 :         startpos=(int)num;
      41                 :           3 : }
      42                 :             : 
      43                 :           3 : static void inline_leavearch()
      44                 :             : {
      45                 :           3 :         inline_finalizeorg();
      46                 :           3 :         write2(0x0000);
      47                 :           3 :         write2((unsigned int)inlinestartpos);
      48                 :           3 : }
      49                 :             : 
      50                 :           0 : void asinit_spc700()
      51                 :             : {
      52                 :           0 : }
      53                 :             : 
      54                 :          18 : void asend_spc700()
      55                 :             : {
      56         [ +  + ]:          18 :         if (arch==arch_spc700_inline) inline_leavearch();
      57                 :          18 : }
      58                 :             : 
      59                 :        3651 : static bool matchandwrite(const char * str, const char * left, const char * right, string& remainder)
      60                 :             : {
      61         [ +  + ]:        3780 :         for (int i=0;left[i];i++)
      62                 :             :         {
      63         [ +  + ]:        1464 :                 if (to_lower(*str)!=left[i]) return false;
      64                 :         129 :                 str++;
      65                 :             :         }
      66                 :        2316 :         int mainlen=(int)(strlen(str)-strlen(right));
      67         [ +  + ]:        2316 :         if(mainlen < 0) return false;
      68         [ +  + ]:        2499 :         for (int i=0;right[i];i++)
      69                 :             :         {
      70         [ +  + ]:        1407 :                 if (to_lower(str[mainlen+i])!=right[i]) return false;
      71                 :             :         }
      72                 :        1092 :         remainder=substr(str, mainlen);
      73                 :        1092 :         return true;
      74                 :             : }
      75                 :             : 
      76                 :        1041 : static bool bitmatch(const char * opnamein, string& opnameout, const char * str, string& math, int& bit)
      77                 :             : {
      78                 :             :         const char * opnameend=strchr(opnamein, '\0');
      79                 :        1041 :         const char * dot=strqrchr(str, '.');
      80   [ +  +  +  -  :        1041 :         if (dot && is_digit(dot[1]) && !dot[2])
                   +  - ]
      81                 :             :         {
      82                 :          21 :                 bit=atoi(dot+1);
      83         [ -  + ]:          21 :                 if (bit>=8) return false;
      84                 :          21 :                 math=substr(str, (int)(dot-str));
      85         [ +  + ]:          21 :                 if (opnameend[-1]=='1') opnameout=substr(opnamein, (int)(opnameend-opnamein-1));
      86                 :             :                 else opnameout=opnamein;
      87                 :          21 :                 return true;
      88                 :             :         }
      89         [ +  + ]:        1020 :         if (opnameend[-1]>='0' && opnameend[-1]<='7')
      90                 :             :         {
      91                 :             :                 math=str;
      92                 :         129 :                 bit=opnameend[-1]-'0';
      93                 :         129 :                 opnameout=substr(opnamein, (int)(opnameend-opnamein-1));
      94                 :         129 :                 return true;
      95                 :             :         }
      96                 :             :         return false;
      97                 :             : }
      98                 :             : 
      99                 :             : #define isop(test) (!stricmp(op, test))
     100                 :          87 : static bool assinglebitwithc(const char * op, const char * math, int bits)
     101                 :             : {
     102                 :             :         unsigned int num;
     103         [ +  + ]:          87 :         if (math[0]=='!')
     104                 :             :         {
     105                 :             :                 if(0);
     106         [ +  + ]:           6 :                 else if (isop("or")) write1(0x2A);
     107         [ +  - ]:           3 :                 else if (isop("and")) write1(0x6A);
     108                 :             :                 else return false;
     109                 :           6 :                 num=getnum_ck(math+1);
     110                 :             :         }
     111                 :             :         else
     112                 :             :         {
     113                 :             :                 if(0);
     114         [ +  + ]:          81 :                 else if (isop("or")) write1(0x0A);
     115         [ +  + ]:          78 :                 else if (isop("and")) write1(0x4A);
     116         [ +  + ]:          75 :                 else if (isop("eor")) write1(0x8A);
     117         [ +  + ]:          72 :                 else if (isop("mov")) write1(0xAA);
     118         [ +  + ]:          69 :                 else if (isop("not")) write1(0xEA);
     119                 :             :                 else return false;
     120                 :          33 :                 num=getnum_ck(math);
     121                 :             :         }
     122   [ -  +  -  - ]:          39 :         if (num>=0x2000) asar_throw_error(2, error_type_block, error_id_spc700_addr_out_of_range, hex4(num).data());
     123                 :          39 :         write2(((unsigned int)bits<<13)|num);
     124                 :          39 :         return true;
     125                 :             : }
     126                 :             : #undef isop
     127                 :             : 
     128                 :        1185 : bool asblock_spc700(char** word, int numwords)
     129                 :             : {
     130                 :             : #define is(test) (!stricmp(word[0], test))
     131                 :             : #define is1(test) (!stricmp(word[0], test) && numwords==2)
     132                 :             : #define par word[1]
     133                 :             :         if(0);
     134   [ +  +  +  +  :        1185 :         else if (arch==arch_spc700_inline && is1("org"))
                   +  - ]
     135                 :             :         {
     136                 :           3 :                 unsigned int num=getnum(par);
     137         [ -  + ]:           3 :                 if (foundlabel) asar_throw_error(0, error_type_block, error_id_org_label_invalid);
     138                 :           3 :                 inline_org(num);
     139                 :           3 :         }
     140   [ +  +  -  +  :        1182 :         else if (arch==arch_spc700_inline && is1("arch"))
                   -  - ]
     141                 :             :         {
     142                 :           0 :                 inline_leavearch();
     143                 :           0 :                 return false;
     144                 :             :         }
     145   [ +  +  -  +  :        1182 :         else if (arch==arch_spc700_inline && is1("skip"))
                   -  - ]
     146                 :             :         {
     147                 :           0 :                 int num=snespos+(int)getnum(par);
     148         [ #  # ]:           0 :                 if (foundlabel) asar_throw_error(0, error_type_block, error_id_skip_label_invalid);
     149                 :           0 :                 inline_org(num);
     150                 :           0 :         }
     151   [ +  +  -  +  :        1182 :         else if (arch==arch_spc700_inline && is1("base"))
                   -  - ]
     152                 :             :         {
     153                 :           0 :                 asar_throw_error(0, error_type_block, error_id_spc700_inline_no_base);
     154                 :             :         }
     155   [ +  +  -  +  :        1182 :         else if (arch==arch_spc700_inline && is1("startpos"))
                   -  - ]
     156                 :             :         {
     157                 :           0 :                 inlinestartpos=(int)getnum_ck(par);
     158                 :             :         }
     159         [ +  + ]:        1182 :         else if (numwords==1)
     160                 :             :         {
     161                 :             : #define op(name, val) else if (is(name)) do { write1(val); } while(0)
     162                 :             :                 if(0);
     163                 :          54 :                 op("nop", 0x00);
     164                 :          42 :                 op("brk", 0x0F);
     165                 :          39 :                 op("clrp", 0x20);
     166                 :          36 :                 op("setp", 0x40);
     167                 :          33 :                 op("clrc", 0x60);
     168                 :          30 :                 op("ret", 0x6F);
     169                 :          27 :                 op("reti", 0x7F);
     170                 :          24 :                 op("setc", 0x80);
     171                 :          21 :                 op("ei", 0xA0);
     172                 :          18 :                 op("di", 0xC0);
     173                 :          15 :                 op("clrv", 0xE0);
     174                 :          12 :                 op("notc", 0xED);
     175                 :           9 :                 op("sleep", 0xEF);
     176                 :           6 :                 op("stop", 0xFF);
     177                 :           3 :                 op("xcn", 0x9F);
     178                 :             :                 else return false;
     179                 :             : #undef op
     180                 :             :         }
     181         [ -  + ]:        1128 :         else if (numwords==2)
     182                 :             :         {
     183                 :             :                 int numwordsinner;
     184                 :             :                 //Detect opcode length before continuing
     185                 :             :                 int opLen=0; //In case of .b or .w, this overwrites auto-detection of opcode length
     186                 :             :                 unsigned int periodLocCount=0;
     187                 :             :                 do {
     188         [ +  + ]:        3987 :                         if (word[0][periodLocCount] == '.') {
     189                 :         336 :                                 opLen=getlenfromchar(word[0][periodLocCount+1]);
     190                 :         336 :                                 word[0][periodLocCount]='\0';
     191                 :             :                         }
     192                 :        3987 :                         periodLocCount++;
     193   [ +  +  +  + ]:        3987 :                 } while ((opLen == 0) && (periodLocCount < strlen(word[0])));
     194         [ -  + ]:        1128 :                 if (opLen > 2) { asar_throw_error(0, error_type_block, error_id_opcode_length_too_long); }
     195                 :        1128 :                 autoptr<char*> parcpy= duplicate_string(par);
     196         [ +  - ]:        1128 :                 autoptr<char**> arg=qpsplit(parcpy, ",", &numwordsinner);
     197         [ +  + ]:        1128 :                 if (numwordsinner ==1)
     198                 :             :                 {
     199                 :         375 :                         string op;
     200                 :         375 :                         string math;
     201                 :             :                         int bits;
     202                 :             : #define isop(str) (!stricmp(word[0], str))
     203                 :             : #define isam(str) (!stricmp(arg[0], str))
     204                 :             : #define ismatch(left, right) (matchandwrite(arg[0], left, right, math))
     205                 :             : #define eq(str) if (isam(str))
     206                 :             : #define w0(hex) do { write1((unsigned int)hex); return true; } while(0)
     207                 :             : #define w1(hex) do { write1((unsigned int)hex); write1(getnum_ck(math)); return true; } while(0)
     208                 :             : #define w2(hex) do { write1((unsigned int)hex); write2(getnum_ck(math)); return true; } while(0)
     209                 :             : #define wv(hex1, hex2) do { if ((opLen == 1) || (opLen == 0 && getlen(math) == 1)) { write1((unsigned int)hex1); write1(getnum_ck(math)); } else { write1((unsigned int)hex2); write2(getnum_ck(math)); } return true; } while(0)
     210                 :             : #define wr(hex) do { int len=getlen(math); int num=(int)getnum_ck(math); int pos=(len==1)?num:num-((snespos&0xFFFFFF)+2); write1((unsigned int)hex); write1((unsigned int)pos); \
     211                 :             :                                                                 if (pass==2 && foundlabel && (pos<-128 || pos>127)) asar_throw_error(2, error_type_block, error_id_relative_branch_out_of_bounds, dec(pos).data()); \
     212                 :             :                                                                 return true; } while(0)
     213                 :             : #define op0(str, hex) if (isop(str)) w0(hex)
     214                 :             : #define op1(str, hex) if (isop(str)) w1(hex)
     215                 :             : #define op2(str, hex) if (isop(str)) w2(hex)
     216                 :             : #define opv(str, hex1, hex2) if (isop(str)) wv(hex1, hex2)
     217                 :             : #define opr(str, hex) if (isop(str)) wr(hex)
     218                 :             : #define match(left, right) if (ismatch(left, right))
     219                 :         375 :                         eq("a")
     220                 :             :                         {
     221                 :          33 :                                 op0("asl", 0x1C);
     222                 :          30 :                                 op0("das", 0xBE);
     223                 :          27 :                                 op0("daa", 0xDF);
     224                 :          24 :                                 op0("dec", 0x9C);
     225                 :          21 :                                 op0("inc", 0xBC);
     226                 :          18 :                                 op0("lsr", 0x5C);
     227                 :          15 :                                 op0("pop", 0xAE);
     228                 :          12 :                                 op0("push", 0x2D);
     229                 :           9 :                                 op0("rol", 0x3C);
     230                 :           6 :                                 op0("ror", 0x7C);
     231                 :           3 :                                 op0("xcn", 0x9F);
     232                 :             :                         }
     233                 :         342 :                         eq("x")
     234                 :             :                         {
     235                 :          12 :                                 op0("dec", 0x1D);
     236                 :           9 :                                 op0("inc", 0x3D);
     237                 :           6 :                                 op0("pop", 0xCE);
     238                 :           3 :                                 op0("push", 0x4D);
     239                 :             :                         }
     240                 :         330 :                         eq("y")
     241                 :             :                         {
     242                 :          12 :                                 op0("dec", 0xDC);
     243                 :           9 :                                 op0("inc", 0xFC);
     244                 :           6 :                                 op0("pop", 0xEE);
     245                 :           3 :                                 op0("push", 0x6D);
     246                 :             :                         }
     247                 :         318 :                         eq("p")
     248                 :             :                         {
     249                 :           6 :                                 op0("pop", 0x8E);
     250                 :           3 :                                 op0("push", 0x0D);
     251                 :             :                         }
     252   [ +  +  +  -  :         312 :                         if (isop("mul") && isam("ya")) w0(0xCF);
                   +  - ]
     253   [ +  +  +  +  :         309 :                         if (isop("jmp") && ismatch("(", "+x)")) w2(0x1F);
          +  -  +  -  +  
                      - ]
     254                 :         306 :                         match("", "+x")
     255                 :             :                         {
     256                 :          18 :                                 op1("asl", 0x1B);
     257                 :          15 :                                 op1("dec", 0x9B);
     258                 :          12 :                                 op1("inc", 0xBB);
     259                 :           9 :                                 op1("lsr", 0x5B);
     260                 :           6 :                                 op1("rol", 0x3B);
     261                 :           3 :                                 op1("ror", 0x7B);
     262                 :             :                         }
     263         [ +  + ]:         288 :                         if (bitmatch(word[0], op, arg[0], math, bits))
     264                 :             :                         {
     265   [ +  -  +  + ]:          57 :                                 if (assinglebitwithc(op, math, bits)) return true;
     266   [ +  +  +  - ]:          48 :                                 else if (!stricmp(op, "set")) write1((unsigned int)(0x02|(bits<<5)));
     267   [ +  -  +  - ]:          24 :                                 else if (!stricmp(op, "clr")) write1((unsigned int)(0x12|(bits<<5)));
     268                 :             :                                 else return false;
     269                 :          48 :                                 unsigned int num=getnum_ck(math);
     270   [ -  +  -  - ]:          48 :                                 if (num>=0x100) asar_throw_error(2, error_type_block, error_id_snes_address_out_of_bounds, hex6(num).data());
     271                 :          48 :                                 write1(num);
     272                 :             :                                 return true;
     273                 :             :                         }
     274                 :             :                         if (true)
     275                 :             :                         {
     276                 :         231 :                                 math=arg[0];
     277         [ +  + ]:         231 :                                 if (isop("tcall"))
     278                 :             :                                 {
     279                 :          48 :                                         unsigned int num = getnum_ck(math);
     280   [ -  +  -  - ]:          48 :                                         if (num >= 16) asar_throw_error(2, error_type_block, error_id_invalid_tcall);
     281                 :          48 :                                         write1(((num<<4)|1));
     282                 :             :                                         return true;
     283                 :             :                                 }
     284                 :         183 :                                 opv("asl", 0x0B, 0x0C);
     285                 :         165 :                                 opv("dec", 0x8B, 0x8C);
     286                 :         147 :                                 opv("inc", 0xAB, 0xAC);
     287                 :         129 :                                 opv("lsr", 0x4B, 0x4C);
     288                 :         111 :                                 opv("rol", 0x2B, 0x2C);
     289                 :          93 :                                 opv("ror", 0x6B, 0x6C);
     290                 :          75 :                                 op2("jmp", 0x5F);
     291                 :          66 :                                 op2("call", 0x3F);
     292                 :          63 :                                 op1("decw", 0x1A);
     293                 :          60 :                                 op1("incw", 0x3A);
     294                 :          57 :                                 op1("pcall", 0x4F);
     295                 :          54 :                                 opr("bpl", 0x10);
     296                 :          51 :                                 opr("bra", 0x2F);
     297                 :          48 :                                 opr("bmi", 0x30);
     298                 :          45 :                                 opr("bvc", 0x50);
     299                 :          42 :                                 opr("bvs", 0x70);
     300                 :          39 :                                 opr("bcc", 0x90);
     301                 :          36 :                                 opr("bcs", 0xB0);
     302                 :          33 :                                 opr("bne", 0xD0);
     303                 :          30 :                                 opr("beq", 0xF0);
     304                 :             :                         }
     305                 :             : #undef isop
     306                 :             : #undef isam
     307                 :             : #undef eq
     308                 :             : #undef w0
     309                 :             : #undef w1
     310                 :             : #undef w2
     311                 :             : #undef wv
     312                 :             : #undef wr
     313                 :             : #undef op0
     314                 :             : #undef op1
     315                 :             : #undef op2
     316                 :             : #undef opv
     317                 :             : #undef opr
     318                 :             : #undef match
     319                 :             :                         return false;
     320                 :         375 :                 }
     321         [ +  - ]:         753 :                 if (numwordsinner==2)
     322                 :             :                 {
     323                 :             : #define iscc(str1, str2) (!stricmp(arg[0], str1) && !stricmp(arg[1], str2))
     324                 :             : #define iscv(str1, left2, right2) (!stricmp(arg[0], str1) && matchandwrite(arg[1], left2, right2, s2))
     325                 :             : #define isvc(left1, right1, str2) (matchandwrite(arg[0], left1, right1, s1) && !stricmp(arg[1], str2))
     326                 :             : #define isvv(left1, right1, left2, right2) (matchandwrite(arg[0], left1, right1, s1) && matchandwrite(arg[1], left2, right2, s2))
     327                 :             : #define cc(str1, str2) if (iscc(str1, str2))
     328                 :             : #define cv(str1, left2, right2) if (iscv(str1, left2, right2))
     329                 :             : #define vc(left1, right1, str2) if (isvc(left1, right1, str2))
     330                 :             : #define vv(left1, right1, left2, right2) if (isvv(left1, right1, left2, right2))
     331                 :             : #define w0(opcode) do { write1((unsigned int)opcode); return true; } while(0)
     332                 :             : #define w1(opcode, math) do { write1((unsigned int)opcode); unsigned int val=getnum_ck(math); \
     333                 :             :                 if ((((val&0xFF00)&&(val&0x80000000)==0)||(((val&0xFF00)!=0xFF00)&&(val&0x80000000)))&&opLen!=1) asar_throw_warning(2, warning_id_spc700_assuming_8_bit); write1(val);return true; } while(0)
     334                 :             : #define w2(opcode, math) do { write1((unsigned int)opcode); write2(getnum_ck(math)); return true; } while(0)
     335                 :             : #define wv(opcode1, opcode2, math) do { if ((opLen == 1) || (opLen == 0 && getlen(math)==1)) { write1((unsigned int)opcode1); write1(getnum_ck(math)); } \
     336                 :             :                                                                                                                                          else { write1((unsigned int)opcode2); write2(getnum_ck(math)); } return true; } while(0)
     337                 :             : #define w11(opcode, math1, math2) do { write1((unsigned int)opcode); write1(getnum_ck(math1)); write1(getnum_ck(math2)); return true; } while(0)
     338                 :             : #define wr(opcode, math) do { int len=getlen(math); int num=(int)getnum_ck(math); int pos=(len==1)?num:num-(snespos+2); \
     339                 :             :                                                                 if (pass && foundlabel && (pos<-128 || pos>127)) asar_throw_error(2, error_type_block, error_id_relative_branch_out_of_bounds, dec(pos).data()); \
     340                 :             :                                                                 write1((unsigned int)opcode); write1((unsigned int)pos); return true; } while(0)
     341                 :             : #define w1r(opcode, math1, math2) do { int len=getlen(math2); int num=(int)getnum_ck(math2); int pos=(len==1)?num:num-(snespos+3); \
     342                 :             :                                                                 if (pass && foundlabel && (pos<-128 || pos>127)) asar_throw_error(2, error_type_block, error_id_relative_branch_out_of_bounds, dec(pos).data()); \
     343                 :             :                                                                 write1((unsigned int)opcode); write1(getnum_ck(math1)); write1((unsigned int)pos); return true; } while(0)
     344                 :         753 :                         string s1;
     345                 :         753 :                         string s2;
     346                 :         753 :                         string op;
     347                 :         753 :                         string math;
     348                 :             :                         int bits;
     349                 :             : #define isop(test) (!stricmp(op, test))
     350   [ +  +  +  - ]:         753 :                         if (!stricmp(arg[0], "c") && bitmatch(word[0], op, arg[1], math, bits))
     351                 :             :                         {
     352   [ +  -  -  + ]:          30 :                                 if (assinglebitwithc(op, math, bits)) return true;
     353                 :             :                         }
     354         [ +  + ]:         723 :                         if (bitmatch(word[0], op, arg[0], s1, bits))
     355                 :             :                         {
     356   [ +  +  -  + ]:          63 :                                 if (isop("mov") && !stricmp(arg[1], "c"))
     357                 :             :                                 {
     358                 :           3 :                                         unsigned int num=getnum_ck(s1);
     359   [ -  +  -  - ]:           3 :                                         if (num>=0x2000) asar_throw_error(2, error_type_block, error_id_snes_address_out_of_bounds, hex6((unsigned int)num).data());
     360                 :           3 :                                         write1(0xCA);
     361                 :           3 :                                         write2(((unsigned int)bits<<13)|num);
     362                 :             :                                         return true;
     363                 :             :                                 }
     364                 :             :                                 if(0);
     365   [ +  +  +  - ]:          60 :                                 else if (isop("bbs")) write1((unsigned int)(0x03|(bits<<5)));
     366   [ +  -  +  - ]:          24 :                                 else if (isop("bbc")) write1((unsigned int)(0x13|(bits<<5)));
     367                 :             :                                 else return false;
     368                 :          60 :                                 unsigned int num=getnum_ck(s1);
     369   [ -  +  -  - ]:          60 :                                 if (num>=0x100) asar_throw_error(2, error_type_block, error_id_snes_address_out_of_bounds, hex6(num).data());
     370                 :          60 :                                 write1(num);
     371                 :          60 :                                 write1((getnum_ck(arg[1])- (unsigned int)(snespos+1)));
     372                 :             :                                 return true;
     373                 :             :                         }
     374                 :             : #undef isop
     375         [ +  + ]:         660 :                         if (is("mov"))
     376                 :             :                         {
     377   [ -  +  -  -  :         219 :                                 if (iscc("(x)+", "a")) asar_throw_error(0, error_type_block, error_id_use_xplus);
                   -  - ]
     378                 :         219 :                                 cc("(x+)"   , "a"      ) w0(0xAF);
     379                 :         216 :                                 cc("(x)"    , "a"      ) w0(0xC6);
     380   [ +  +  -  +  :         213 :                                 if (iscc("a", "(x)+")) asar_throw_error(0, error_type_block, error_id_use_xplus);
                   -  - ]
     381                 :         213 :                                 cc("a"      , "(x+)"   ) w0(0xBF);
     382                 :         210 :                                 cc("a"      , "(x)"    ) w0(0xE6);
     383                 :         207 :                                 cc("a"      , "x"      ) w0(0x7D);
     384                 :         204 :                                 cc("a"      , "y"      ) w0(0xDD);
     385                 :         201 :                                 cc("x"      , "a"      ) w0(0x5D);
     386                 :         198 :                                 cc("x"      , "sp"     ) w0(0x9D);
     387                 :         195 :                                 cc("y"      , "a"      ) w0(0xFD);
     388                 :         192 :                                 cc("sp"     , "x"      ) w0(0xBD);
     389                 :             : 
     390                 :         189 :                                 vc("(","+x)", "a"      ) w1(0xC7, s1);
     391                 :         186 :                                 vc("(",")+y", "a"      ) w1(0xD7, s1);
     392                 :         183 :                                 vc("","+x"  , "a"      ) wv(0xD4, 0xD5, s1);
     393                 :         165 :                                 vc("","+y"  , "a"      ) w2(0xD6, s1);
     394                 :         162 :                                 vc("",""    , "a"      ) wv(0xC4, 0xC5, s1);
     395                 :         144 :                                 vc("","+x"  , "y"      ) w1(0xDB, s1);
     396                 :         141 :                                 vc("","+y"  , "x"      ) w1(0xD9, s1);
     397                 :         138 :                                 vc("",""    , "x"      ) wv(0xD8, 0xC9, s1);
     398                 :         120 :                                 vc("",""    , "y"      ) wv(0xCB, 0xCC, s1);
     399                 :             : 
     400                 :         102 :                                 cv("a"      , "#",""   ) w1(0xE8, s2);
     401                 :          99 :                                 cv("a"      , "(","+x)") w1(0xE7, s2);
     402                 :          96 :                                 cv("a"      , "(",")+y") w1(0xF7, s2);
     403                 :          93 :                                 cv("a"      , "","+x"  ) wv(0xF4, 0xF5, s2);
     404                 :          75 :                                 cv("a"      , "","+y"  ) w2(0xF6, s2);
     405                 :          72 :                                 cv("a"      , "",""    ) wv(0xE4, 0xE5, s2);
     406                 :          54 :                                 cv("x"      , "#",""   ) w1(0xCD, s2);
     407                 :          51 :                                 cv("x"      , "","+y"  ) w1(0xF9, s2);
     408                 :          48 :                                 cv("x"      , "",""    ) wv(0xF8, 0xE9, s2);
     409                 :          30 :                                 cv("y"      , "#",""   ) w1(0x8D, s2);
     410                 :          27 :                                 cv("y"      , "","+x"  ) w1(0xFB, s2);
     411                 :          24 :                                 cv("y"      , "",""    ) wv(0xEB, 0xEC, s2);
     412                 :             : 
     413                 :           6 :                                 vv("",""    , "#",""   ) w11(0x8F, s2, s1);
     414                 :           3 :                                 vv("",""    , "",""    ) w11(0xFA, s2, s1);
     415                 :             :                         }
     416         [ +  + ]:         441 :                         if (is("cmp"))
     417                 :             :                         {
     418                 :         102 :                                 cv("x", "#","") w1(0xC8, s2);
     419                 :          99 :                                 cv("x", "","" ) wv(0x3E, 0x1E, s2);
     420                 :          81 :                                 cv("y", "#","") w1(0xAD, s2);
     421                 :          78 :                                 cv("y", "","" ) wv(0x7E, 0x5E, s2);
     422                 :             :                         }
     423   [ +  +  +  +  :         399 :                         if (is("or") || is("and") || is("eor") || is("cmp") || is("adc") || is("sbc"))
          +  +  +  +  +  
                +  +  + ]
     424                 :             :                         {
     425                 :             :                                 int offset = 0;
     426                 :             :                                 if (is("or" )) offset=0x00;
     427         [ +  + ]:         360 :                                 if (is("and")) offset=0x20;
     428         [ +  + ]:         360 :                                 if (is("eor")) offset=0x40;
     429         [ +  + ]:         360 :                                 if (is("cmp")) offset=0x60;
     430         [ +  + ]:         360 :                                 if (is("adc")) offset=0x80;
     431         [ +  + ]:         360 :                                 if (is("sbc")) offset=0xA0;
     432                 :             : 
     433                 :         360 :                                 cc("a"  , "(x)"    ) w0(offset+0x06);
     434                 :         342 :                                 cc("(x)", "(y)"    ) w0(offset+0x19);
     435                 :             : 
     436                 :         324 :                                 cv("a"  , "#",""   ) w1(offset+0x08, s2);
     437                 :         306 :                                 cv("a"  , "(","+x)") w1(offset+0x07, s2);
     438                 :         288 :                                 cv("a"  , "(",")+y") w1(offset+0x17, s2);
     439                 :         270 :                                 cv("a"  , "","+x"  ) wv(offset+0x14, offset+0x15, s2);
     440                 :         162 :                                 cv("a"  , "","+y"  ) w2(offset+0x16, s2);
     441                 :         144 :                                 cv("a"  , "",""    ) wv(offset+0x04, offset+0x05, s2);
     442                 :             : 
     443                 :          36 :                                 vv("","", "#",""   ) w11(offset+0x18, s2, s1);
     444                 :          18 :                                 vv("","", "",""    ) w11(offset+0x09, s2, s1);
     445                 :             :                         }
     446                 :          39 :                         vc("","", "a")
     447                 :             :                         {
     448   [ +  +  +  -  :           6 :                                 if (is("tset")) w2(0x0E, s1);
             +  -  +  - ]
     449   [ +  -  +  -  :           3 :                                 if (is("tclr")) w2(0x4E, s1);
             +  -  +  - ]
     450                 :             :                         }
     451   [ +  +  +  -  :          33 :                         if (is("div") && iscc("ya", "x")) w0(0x9E);
             -  +  +  - ]
     452                 :          30 :                         cv("ya", "","")
     453                 :             :                         {
     454   [ +  +  +  -  :          12 :                                 if (is("cmpw")) w1(0x5A, s2);
          +  -  -  +  -  
          -  +  -  -  +  
          -  -  -  -  +  
                      - ]
     455   [ +  +  +  -  :           9 :                                 if (is("addw")) w1(0x7A, s2);
          +  -  -  +  -  
          -  +  -  -  +  
          -  -  -  -  +  
                      - ]
     456   [ +  +  +  -  :           6 :                                 if (is("subw")) w1(0x9A, s2);
          +  -  -  +  -  
          -  +  -  -  +  
          -  -  -  -  +  
                      - ]
     457   [ +  -  +  -  :           3 :                                 if (is("movw")) w1(0xBA, s2);
          +  -  -  +  -  
          -  +  -  -  +  
          -  -  -  -  +  
                      - ]
     458                 :             :                         }
     459   [ +  +  +  -  :          18 :                         if (is("movw") && isvc("","", "ya")) w1(0xDA, s1);
          -  +  +  -  +  
          -  -  +  -  -  
          +  -  -  +  -  
             -  -  -  +  
                      - ]
     460   [ +  +  +  +  :          15 :                         if (is("cbne") && isvv("","+x", "","")) w1r(0xDE, s1, s2);
          -  +  +  -  +  
          -  +  -  +  +  
          +  +  -  +  -  
          -  +  -  +  -  
             +  -  +  - ]
     461   [ +  +  +  +  :          12 :                         if (is("dbnz") && iscv("y", "","")) wr(0xFE, s2);
          -  +  +  -  +  
          -  +  -  +  +  
          +  +  -  +  -  
             -  +  -  +  
                      - ]
     462                 :           9 :                         vv("","", "","")
     463                 :             :                         {
     464   [ +  +  +  -  :           9 :                                 if (is("dbnz")) w1r(0x6E, s1, s2);
          +  -  +  -  +  
          +  +  +  -  +  
          -  -  +  -  +  
             -  +  -  +  
                      - ]
     465   [ +  +  +  -  :           6 :                                 if (is("cbne")) w1r(0x2E, s1, s2);
          +  -  +  -  +  
          +  +  +  -  +  
          -  -  +  -  +  
             -  +  -  +  
                      - ]
     466                 :             :                         }
     467                 :             : #undef iscc
     468                 :             : #undef iscv
     469                 :             : #undef isvc
     470                 :             : #undef isvv
     471                 :             : #undef cc
     472                 :             : #undef cv
     473                 :             : #undef vc
     474                 :             : #undef vv
     475                 :             : #undef w0
     476                 :             : #undef w1
     477                 :             : #undef w2
     478                 :             : #undef wv
     479                 :             : #undef w11
     480                 :           3 :                         return false;
     481                 :         753 :                 }
     482                 :             :                 return false;
     483                 :        1128 :         }
     484                 :             :         else return false;
     485                 :             :         return true;
     486                 :             : }
        

Generated by: LCOV version 2.0-1