home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / pascal.zip / pcode / pcode.c < prev    next >
Text File  |  1995-10-29  |  3KB  |  135 lines

  1. /*
  2.  *        C . A . P .   P C O D E   G E N E R A T O R
  3.  *
  4.  *        C O R E   P R O C E D U R E S
  5.  *
  6.  *        Stéphane Charette @ C.A.P. Services
  7.  *
  8.  *        Last modified:  Stéphane Charette, 1995 October 29
  9.  *
  10.  *****************************************************************************
  11.  *
  12.  *        Project:    BILL
  13.  *        Group:    pcode
  14.  *        File:        pcode\pcode.c
  15.  *        Version:    0.1.1
  16.  *
  17.  *        This file contains all of the source code that makes up the pcode
  18.  *        generator used with the interpreter BILL.
  19.  */
  20.  
  21.  
  22.  
  23. /*
  24.  *    Versions:
  25.  *
  26.  *    0.0.1    - design of structure and implementation, Stéphane Charette, 94Apr10
  27.  *    0.1.0    - first working version, SC, 94Apr10
  28.  *    0.1.1    - fixed bug while outputing file, SC, 94Apr11
  29.  * 0.1.1 - changed text formatting, SC, 95Oct29
  30.  */
  31.  #define _PCODE_VERSION "Parser v0.1.1, Stéphane Charette, 95October29\n"
  32.  
  33.  
  34.  
  35. /*
  36.  *    Includes
  37.  */
  38.     #include "..\pcode\pcode.hi"        // internal pcode include file
  39.  
  40.  
  41.  
  42. /*
  43.  *    FUNCTION:  StartPCodeGenerator
  44.  */
  45. ERR StartPCodeGenerator( )
  46.     {
  47.         PCode_State.CurrentIndex = 0;    // start at the beginning of the buffer
  48.  
  49.         return ERR_OK;
  50.     }
  51.  
  52.  
  53.  
  54. /*
  55.  *    FUNCTION:  PCodeError
  56.  */
  57. void PCodeError( )
  58. {
  59.     printf(    "\nOh dear!  It seems you have run into the most foul of the worst type of errors\n"
  60.                 "that have come to pass across this wonderful Earth of ours.  You can either\n"
  61.                 "call it quits now, or attempt to find out what the f**k happened to B.I.L.L.\n"
  62.                 "Should you be interested, this error is the result of the pcode buffer being\n"
  63.                 "filled up.  Thus, all you have to do is increase the size of the buffer!\n" );
  64.     printf(    "\nBy the way - THIS IS A FATAL ERROR.  B.I.L.L. is now officially dead!\n" );
  65.     exit( 1 );
  66. }
  67.  
  68.  
  69.  
  70. /*
  71.  *    FUNCTION:  AddPCode
  72.  */
  73. USHORT AddPCode( SHORT code )
  74. {
  75.     if( PCode_State.CurrentIndex == PCODE_MAX_LEN ) PCodeError( );
  76.  
  77.     PCodeBuffer[PCode_State.CurrentIndex] = code;
  78.  
  79.     return PCode_State.CurrentIndex++;
  80. }
  81.  
  82.  
  83.  
  84. /*
  85.  *    FUNCTION:  AddDPCode
  86.  */
  87. USHORT AddDPCode( SHORT code1, SHORT code2 )
  88. {
  89.     AddPCode( code1 );
  90.  
  91.     return AddPCode( code2 );
  92. }
  93.  
  94.  
  95.  
  96. /*
  97.  *    FUNCTION:  UpdatePCode
  98.  */
  99. USHORT UpdatePCode( USHORT address, SHORT newcode )
  100. {
  101.     PCodeBuffer[address] = newcode;
  102.  
  103.     return address;
  104. }
  105.  
  106.  
  107.  
  108. /*
  109.  *    FUNCTION:  GetCurrentIndex
  110.  */
  111. USHORT GetCurrentIndex( )
  112. {
  113.     return PCode_State.CurrentIndex;
  114. }
  115.  
  116.  
  117.  
  118. /*
  119.  *    FUNCTION:  WritePCodeBuffer
  120.  */
  121. ERR WritePCodeBuffer( )
  122. {
  123.     USHORT i = 0;                    // tmp index counter
  124.     FILE *PCFilePtr;                // file pointer
  125.  
  126.     PCFilePtr = fopen( "PCODE.LST", "wb" );    // open the pcode output file
  127.  
  128.     while( i < PCode_State.CurrentIndex ) fprintf( PCFilePtr, "%i\n", PCodeBuffer[i++] );
  129.  
  130.     fclose( PCFilePtr );            // close the pcode output file
  131.  
  132.     return ERR_OK;
  133. }
  134.  
  135.