home *** CD-ROM | disk | FTP | other *** search
/ Mac-Source 1994 July / Mac-Source_July_1994.iso / C and C++ / Simulation / PDP-8 Simulator / Source Code / Assembler / Code.c copy < prev    next >
Encoding:
Text File  |  1992-03-13  |  7.4 KB  |  329 lines  |  [TEXT/KAHL]

  1. /************************************************************
  2. *
  3. *
  4. *    Unit containing instruction code.
  5. *
  6. *    by Adrian Bool in cooperation with Graham Cox.
  7. *
  8. *    copyright © phantasm coding 1992.
  9. *
  10. *
  11. ************************************************************/
  12.  
  13. #include "Global.h"
  14. #include "Code.h"
  15.  
  16. /* memory referance instructions */
  17.     
  18. void cmpAND(short pass,rBlock data,short *size,pHandle theProgram)
  19.     { /* ANDs the ACC with amemory location */
  20.     *size=1;
  21.     if (pass == 1) 
  22.         {
  23.         str255 dummy;
  24.         *size = 1;
  25.         getSection((*theProgram)->sourceCode,dummy);
  26.         }
  27.     if (pass == 2)
  28.         {
  29.         makeMemoryInstruction(and,data,theProgram);
  30.         }
  31.     }
  32.             
  33. void cmpTAD(short pass,rBlock data,short *size,pHandle theProgram)
  34.     {    /* adds a memory location to the ACC */
  35.     *size = 1;
  36.     if (pass == 1) 
  37.         {
  38.         str255 dummy;
  39.         getSection((*theProgram)->sourceCode,dummy);
  40.         }
  41.     if (pass == 2)
  42.         {
  43.         makeMemoryInstruction(tad,data,theProgram);
  44.         }
  45.     }
  46.             
  47. void cmpISZ(short pass,rBlock data,short *size,pHandle theProgram)
  48.     {    /* increments memory location then skips if result = 0 */
  49.     *size = 1;
  50.     if (pass == 1) 
  51.         {
  52.         str255 dummy;
  53.         getSection((*theProgram)->sourceCode,dummy);
  54.         }
  55.     if (pass == 2)
  56.         {
  57.         makeMemoryInstruction(isz,data,theProgram);
  58.         }
  59.     }
  60.             
  61. void cmpDCA(short pass,rBlock data,short *size,pHandle theProgram)
  62.     {    /* deposit ACC in memory then set ACC to 0 */
  63.     *size = 1;
  64.     if (pass == 1) 
  65.         {
  66.         str255 dummy;
  67.         getSection((*theProgram)->sourceCode,dummy);
  68.         }
  69.     if (pass == 2)
  70.         {
  71.         makeMemoryInstruction(dca,data,theProgram);
  72.         }
  73.     }
  74.             
  75. void cmpJMS(short pass,rBlock data,short *size,pHandle theProgram)
  76.     {    /* jump to subroutine */
  77.     *size = 1;
  78.     if (pass == 1) 
  79.         {
  80.         str255 dummy;
  81.         getSection((*theProgram)->sourceCode,dummy);
  82.         }
  83.     if (pass == 2)
  84.         {
  85.         makeMemoryInstruction(jms,data,theProgram);
  86.         }
  87.     }
  88.     
  89. void cmpJMP(short pass,rBlock data,short *size,pHandle theProgram)
  90.     {    /* jump to address */
  91.     *size=1;
  92.     if (pass == 1) 
  93.         {
  94.         str255 dummy;
  95.         getSection((*theProgram)->sourceCode,dummy);
  96.         }
  97.     if (pass == 2)
  98.         {
  99.         makeMemoryInstruction(jmp,data,theProgram);
  100.         }
  101.     }
  102.             
  103. void cmpIO(short pass,rBlock data,short *size,pHandle theProgram)
  104.     {    /* input/output instruction */
  105.     *size = 1;
  106.     if (pass == 1) 
  107.         {
  108.         str255 dummy;
  109.         getSection((*theProgram)->sourceCode,dummy);                
  110.         }
  111.     }
  112.             
  113. /* accumulator instructions : group one */
  114.         
  115. void cmpCLL(short pass,rBlock data,short *size,pHandle theProgram)        
  116.     {    /* clear link */
  117.     *size = 1;
  118.     if (pass == 2) data[0] = pdp8[cll].iNumber;
  119.     }
  120.             
  121. void cmpCMA(short pass,rBlock data,short *size,pHandle theProgram)                 
  122.     {    /* complement accumulator */
  123.     *size = 1;
  124.     if (pass == 2) data[0] = pdp8[cma].iNumber;
  125.     }
  126.             
  127. void cmpCML(short pass,rBlock data,short *size,pHandle theProgram)
  128.     {    /* complement link */
  129.     *size = 1;
  130.     if (pass == 2) data[0] = pdp8[cml].iNumber;
  131.     }
  132.             
  133. void cmpIAC(short pass,rBlock data,short *size,pHandle theProgram)
  134.     {    /* increment accumulator */
  135.     *size = 1;
  136.     if (pass == 2) data[0] = pdp8[iac].iNumber;
  137.     }
  138.  
  139. void cmpRAR(short pass,rBlock data,short *size,pHandle theProgram)
  140.     {    /* rotate accumulator one position right */
  141.     *size = 1;
  142.     if (pass == 2) data[0] = pdp8[rar].iNumber;
  143.     }
  144.     
  145. void cmpRAL(short pass,rBlock data,short *size,pHandle theProgram)
  146.     {    /* rotate accumulator one position left */
  147.     *size = 1;
  148.     if (pass == 2) data[0] = pdp8[ral].iNumber;
  149.     }
  150.     
  151. void cmpRTR(short pass,rBlock data,short *size,pHandle theProgram)
  152.     {    /* rotate accumulator two positions right */
  153.     *size = 1;
  154.     if (pass == 2) data[0] = pdp8[rtr].iNumber;
  155.     }
  156.     
  157. void cmpRTL(short pass,rBlock data,short *size,pHandle theProgram)
  158.     {    /* rotate accumulator two positions left */
  159.     *size = 1;
  160.     if (pass == 2) data[0] = pdp8[rtl].iNumber;
  161.     }
  162.     
  163. void cmpNOP(short pass,rBlock data,short *size,pHandle theProgram)
  164.     {    /* no operation */
  165.     *size = 1;
  166.     if (pass == 2) data[0] = pdp8[nop].iNumber;
  167.     }
  168.     
  169. /* accumulator instuctions : group 2 */
  170.                     
  171. void cmpSMA(short pass,rBlock data,short *size,pHandle theProgram)        
  172.     {    /* skip on minus accumulator */
  173.     *size = 1;
  174.     if (pass == 2) data[0] = pdp8[sma].iNumber;
  175.     }
  176.             
  177. void cmpSZA(short pass,rBlock data,short *size,pHandle theProgram)
  178.     {    /* skip on zero link */
  179.     *size = 1;
  180.     if (pass == 2) data[0] = pdp8[sza].iNumber;
  181.     }
  182.     
  183. void cmpSNL(short pass,rBlock data,short *size,pHandle theProgram)        
  184.     {    /* skip on non-zero link */
  185.     *size = 1;
  186.     if (pass == 2) data[0] = pdp8[snl].iNumber;
  187.     }
  188.     
  189. void cmpSPA(short pass,rBlock data,short *size,pHandle theProgram)        
  190.     {    /* skip on positive accumulator */
  191.     *size = 1;
  192.     if (pass == 2) data[0] = pdp8[spa].iNumber;
  193.     }
  194.     
  195. void cmpSNA(short pass,rBlock data,short *size,pHandle theProgram)        
  196.     {    /* skip on non-zero accumulator */
  197.     *size = 1;
  198.     if (pass == 2) data[0] = pdp8[sna].iNumber;
  199.     }
  200.     
  201. void cmpSZL(short pass,rBlock data,short *size,pHandle theProgram)        
  202.     {    /* skip on zero link */
  203.     *size = 1;
  204.     if (pass == 2) data[0] = pdp8[szl].iNumber;
  205.     }
  206.     
  207. void cmpCLA(short pass,rBlock data,short *size,pHandle theProgram)        
  208.     {    /* clear accumulator */
  209.     *size = 1;
  210.     if (pass == 2) data[0] = pdp8[cla].iNumber;
  211.     }
  212.             
  213. void cmpOSR(short pass,rBlock data,short *size,pHandle theProgram)
  214.     {    /* or switches in accumulator */
  215.     /* not implementated */
  216.     AsmError = OSRNotImplemented;
  217.     }
  218.             
  219. void cmpHLT(short pass,rBlock data,short *size,pHandle theProgram)
  220.     {    /* Halt proccessor */
  221.     *size = 1;
  222.     if (pass == 2) data[0] = pdp8[hlt].iNumber;
  223.     }
  224.  
  225. /* pseudo operations */
  226.             
  227. void cmpORG(short pass,rBlock data,short *size,pHandle theProgram)        
  228.     {    /* set start address of code */
  229.     *size = 0;
  230.     if (pass == 1) 
  231.         {
  232.         str255 startAddress;
  233.         addressType theAddress;
  234.                 
  235.         getSection((*theProgram)->sourceCode,startAddress);
  236.         theAddress = decodeNumber(theProgram, startAddress,0);
  237.         
  238.         (*(*theProgram)->objectCode)->startAddress = theAddress;
  239.         (*(*theProgram)->objectCode)->address = theAddress;    
  240.         }
  241.     if (pass == 2)
  242.         {
  243.         str255 dummy;
  244.         
  245.         getSection((*theProgram)->sourceCode,dummy);
  246.         }
  247.     }
  248.             
  249. void cmpEQU(short pass,rBlock data,short *size,pHandle theProgram)
  250.     {    /* equate symbol to value */
  251.     *size = 0;
  252.     if (pass == 1)
  253.         {
  254.         str255 theLabel;
  255.         str255 theValue;
  256.         lValue aValue;
  257.         
  258.         getSection((*theProgram)->sourceCode,theLabel);
  259.         getSection((*theProgram)->sourceCode,theValue);
  260.         
  261.         aValue = decodeNumber(theProgram,theValue,0);
  262.         if (aValue != 0xffff)
  263.             newLabel((*theProgram)->labelHeader,theLabel,aValue);
  264.         }
  265.     if (pass == 2)
  266.         {
  267.         str255 dummy;
  268.         
  269.         getSection((*theProgram)->sourceCode,dummy);
  270.         getSection((*theProgram)->sourceCode,dummy);
  271.         }
  272.     }
  273.             
  274. void cmpEND(short pass,rBlock data,short *size,pHandle theProgram)
  275.     {    /* signify physical end of source code */
  276.     *size = 0;
  277.     }
  278.             
  279. void cmpDATA(short pass,rBlock returnData,short *size,pHandle theProgram)
  280.     {    /* allocate values to memory locations */
  281.     str255 theData;
  282.     str255 aData;
  283.     short position;
  284.     wordType theValue;
  285.     
  286.     getSection((*theProgram)->sourceCode,theData);
  287.     
  288.     *size = 0;
  289.     position = 0;
  290.     theValue = 0;
  291.     
  292.     while (getDataSection(theData,&position,aData))
  293.         {
  294.         if (pass == 2)
  295.             {
  296.             theValue = decodeNumber(theProgram,aData,0);
  297.             if (theValue == 0xFFFF) break;
  298.             returnData[*size] = theValue;
  299.             }
  300.         if (theValue == 0xFFFF) break;
  301.         (*size)++;
  302.         }
  303.     }
  304.             
  305. void cmpSTORE(short pass,rBlock data,short *size,pHandle theProgram)    
  306.     {    /* allocate a number of words in memory */
  307.     short x,noOfWords;
  308.     str255 request;
  309.     
  310.     getSection((*theProgram)->sourceCode,request);
  311.     noOfWords = decodeNumber(theProgram,request,0);
  312.     
  313.     if (noOfWords > 255)
  314.         AsmError = TooManyDataItems;
  315.     
  316.     if (pass == 2) for (x=0 ; x < noOfWords ; x++) data[x] = 0;
  317.     *size = noOfWords;
  318.     }
  319.     
  320.             
  321.         
  322.         
  323.         
  324.         
  325.         
  326.         
  327.         
  328.         
  329.