home *** CD-ROM | disk | FTP | other *** search
/ ftp.barnyard.co.uk / 2015.02.ftp.barnyard.co.uk.tar / ftp.barnyard.co.uk / cpm / walnut-creek-CDROM / ENTERPRS / CPM / UTILS / S / SMC21SRC.LZH / CC42.C < prev    next >
Text File  |  2000-06-30  |  6KB  |  337 lines

  1.  
  2. /*
  3. ** add primary and secondary registers (result in primary)
  4. */
  5. ffadd() {
  6. ol("DAD D");}
  7.  
  8. /*
  9. ** subtract primary from secondary register (result in primary)
  10. */
  11. ffsub() {
  12. ffcall("CCSUB##");}
  13.  
  14. /*
  15. ** multiply primary and secondary registers (result in primary)
  16. */
  17. ffmult() {
  18. ffcall("CCMULT##");}
  19.  
  20. /*
  21. ** divide secondary by primary register
  22. ** (quotient in primary, remainder in secondary)
  23. */
  24. ffdiv() {
  25. ffcall("CCDIV##");}
  26.  
  27. /*
  28. ** remainder of secondary/primary
  29. ** (remainder in primary, quotient in secondary)
  30. */
  31. ffmod() {
  32. ffdiv();swap();}
  33.  
  34. /*
  35. ** inclusive "or" primary and secondary registers
  36. ** (result in primary)
  37. */
  38. ffor() {
  39. ffcall("CCOR##");}
  40.  
  41. /*
  42. ** exclusive "or" the primary and secondary registers
  43. ** (result in primary)
  44. */
  45. ffxor() {
  46. ffcall("CCXOR##");}
  47.  
  48. /*
  49. ** "and" primary and secondary registers
  50. ** (result in primary)
  51. */
  52. ffand() {
  53. ffcall("CCAND##");}
  54.  
  55. /*
  56. ** logical negation of primary register
  57. */
  58. lneg() {
  59. ffcall("CCLNEG##");}
  60.  
  61. /*
  62. ** arithmetic shift right secondary register
  63. ** number of bits given in primary register
  64. ** (result in primary)
  65. */
  66. ffasr() {
  67. ffcall("CCASR##");}
  68.  
  69. /*
  70. ** arithmetic shift left secondary register
  71. ** number of bits given in primary register
  72. ** (result in primary)
  73. */
  74. ffasl() {
  75. ffcall("CCASL##");}
  76.  
  77. /*
  78. ** two's complement primary register
  79. */
  80. neg() {
  81. ffcall("CCNEG##");}
  82.  
  83. /*
  84. ** one's complement primary register
  85. */
  86. com() {
  87. ffcall("CCCOM##");}
  88.  
  89. /*
  90. ** increment primary register by one object of whatever size
  91. */
  92. inc(n) int n; {
  93.   while(1) {
  94.     ol("INX H");
  95.     if(--n < 1) break;
  96.     }
  97.   }
  98.  
  99. /*
  100. ** decrement primary register by one object of whatever size
  101. */
  102. dec(n) int n; {
  103.   while(1) {
  104.     ol("DCX H");
  105.     if(--n < 1) break;
  106.     }
  107.   }
  108.  
  109. /*
  110. ** test for equal to
  111. */
  112. ffeq()  {
  113. ffcall("CCEQ##");}
  114.  
  115. /*
  116. ** test for equal to zero
  117. */
  118. eq0(label) int label; {
  119.   ol("MOV A,H");
  120.   ol("ORA L");
  121.   ot("JNZ ");
  122.   printlabel(label);
  123.   nl();
  124.   }
  125.  
  126. /*
  127. ** test for not equal to
  128. */
  129. ffne()  {
  130. ffcall("CCNE##");}
  131.  
  132. /*
  133. ** test for not equal to zero
  134. */
  135. ne0(label) int label; {
  136.   ol("MOV A,H");
  137.   ol("ORA L");
  138.   ot("JZ ");
  139.   printlabel(label);
  140.   nl();
  141.   }
  142.  
  143. /*
  144. ** test for less than (signed)
  145. */
  146. fflt()  {
  147. ffcall("CCLT##");}
  148.  
  149. /*
  150. ** test for less than to zero
  151. */
  152. lt0(label) int label; {
  153.   ol("XRA A");
  154.   ol("ORA H");
  155.   ot("JP ");
  156.   printlabel(label);
  157.   nl();
  158.   }
  159.  
  160. /*
  161. ** test for less than or equal to (signed)
  162. */
  163. ffle()  {
  164. ffcall("CCLE##");}
  165.  
  166. /*
  167. ** test for less than or equal to zero
  168. */
  169. le0(label) int label; {
  170.   ol("MOV A,H");
  171.   ol("ORA L");
  172.   ol("JZ $+8");
  173.   ol("XRA A");
  174.   ol("ORA H");
  175.   ot("JP ");
  176.   printlabel(label);
  177.   nl();
  178.   }
  179.  
  180. /*
  181. ** test for greater than (signed)
  182. */
  183. ffgt()  {
  184. ffcall("CCGT##");}
  185.  
  186. /*
  187. ** test for greater than to zero
  188. */
  189. gt0(label) int label; {
  190.   ol("XRA A");
  191.   ol("ORA H");
  192.   ot("JM ");
  193.   printlabel(label);
  194.   nl();
  195.   ol("ORA L");
  196.   ot("JZ ");
  197.   printlabel(label);
  198.   nl();
  199.   }
  200.  
  201. /*
  202. ** test for greater than or equal to (signed)
  203. */
  204. ffge()  {
  205. ffcall("CCGE##");}
  206.  
  207. /*
  208. ** test for gteater than or equal to zero
  209. */
  210. ge0(label) int label; {
  211.   ol("XRA A");
  212.   ol("ORA H");
  213.   ot("JM ");
  214.   printlabel(label);
  215.   nl();
  216.   }
  217.  
  218. /*
  219. ** test for less than (unsigned)
  220. */
  221. ult()  {
  222. ffcall("CCULT##");}
  223.  
  224. /*
  225. ** test for less than to zero (unsigned)
  226. */
  227. ult0(label) int label; {
  228.   ot("JMP ");
  229.   printlabel(label);
  230.   nl();
  231.   }
  232.  
  233. /*
  234. ** test for less than or equal to (unsigned)
  235. */
  236. ule()  {
  237. ffcall("CCULE##");}
  238.  
  239. /*
  240. ** test for greater than (unsigned)
  241. */
  242. ugt()  {
  243. ffcall("CCUGT##");}
  244.  
  245. /*
  246. ** test for greater than or equal to (unsigned)
  247. */
  248. uge()  {
  249. ffcall("CCUGE##");}
  250.  
  251. #ifdef OPTIMIZE
  252.  
  253. peephole(ptr) char *ptr; {
  254.   while(*ptr) {
  255.     if(streq(ptr,"LXI H,0\nDAD SP\nCALL CCGINT##")) {
  256.       if(streq(ptr+29, "XCHG;;")) {pp2();ptr=ptr+36;}
  257.       else                        {pp1();ptr=ptr+29;}
  258.       }
  259.     else if(streq(ptr,"LXI H,2\nDAD SP\nCALL CCGINT##")) {
  260.       if(streq(ptr+29, "XCHG;;")) {pp3(pp2);ptr=ptr+36;}
  261.       else                        {pp3(pp1);ptr=ptr+29;}
  262.       }
  263.     else if(optimize) {
  264.       if(streq(ptr, "DAD SP\nCALL CCGINT##")) {
  265.         ol("CALL CCDSGI##");
  266.         ptr=ptr+21;
  267.         }
  268.       else if(streq(ptr, "DAD D\nCALL CCGINT##")) {
  269.         ol("CALL CCDDGI##");
  270.         ptr=ptr+20;
  271.         }
  272.       else if(streq(ptr, "DAD SP\nCALL CCGCHAR##")) {
  273.         ol("CALL CCDSGC##");
  274.         ptr=ptr+22;
  275.           }
  276.       else if(streq(ptr, "DAD D\nCALL CCGCHAR##")) {
  277.         ol("CALL CCDDGC##");
  278.         ptr=ptr+21;
  279.         }
  280.       else if(streq(ptr,
  281. "DAD SP\nMOV D,H\nMOV E,L\nCALL CCGINT##\nINX H\nCALL CCPINT##")) {
  282.         ol("CALL CCINCI##");
  283.         ptr=ptr+57;
  284.         }
  285.       else if(streq(ptr,
  286. "DAD SP\nMOV D,H\nMOV E,L\nCALL CCGINT##\nDCX H\nCALL CCPINT##")) {
  287.         ol("CALL CCDECI##");
  288.         ptr=ptr+57;
  289.         }
  290.       else if(streq(ptr,
  291. "DAD SP\nMOV D,H\nMOV E,L\nCALL CCGCHAR##\nINX H\nMOV A,L\nSTAX D")) {
  292.         ol("CALL CCINCC##");
  293.         ptr=ptr+57;
  294.         }
  295.       else if(streq(ptr,
  296. "DAD SP\nMOV D,H\nMOV E,L\nCALL CCGCHAR##\nDCX H\nMOV A,L\nSTAX D")) {
  297.         ol("CALL CCDECC##");
  298.         ptr=ptr+59;
  299.         }
  300.       else if(streq(ptr, "DAD D\nPOP D\nCALL CCPINT##")) {
  301.         ol("CALL CDPDPI##");
  302.         ptr=ptr+26;
  303.         }
  304.       else if(streq(ptr, "DAD D\nPOP D\nMOV A,L\nSTAX D")) {
  305.         ol("CALL CDPDPC##");
  306.         ptr=ptr+27;
  307.         }
  308.       else if(streq(ptr, "POP D\nCALL CCPINT##")) {
  309.         ol("CALL CCPDPI##");
  310.         ptr=ptr+20;
  311.         }
  312.                                                             /*30*/
  313.       /* additional optimizing logic goes here */
  314.       else cout(*ptr++, output);
  315.       }
  316.     else cout(*ptr++, output);
  317.     }
  318.   }
  319.  
  320. pp1() {
  321.   ol("POP H");
  322.   ol("PUSH H");
  323.   }
  324.  
  325. pp2() {
  326.   ol("POP D");
  327.   ol("PUSH D");
  328.   }
  329.  
  330. pp3(pp) int (*pp)(); {                              /*13*/
  331.   ol("POP B");
  332.   (*pp)();
  333.   ol("PUSH B");
  334.   }
  335.  
  336. #endif /* OPTIMIZE */
  337.