Source code for /engineering/bos/rewrite/IBUILD.CPPOriginal file IBUILD.CPP
   1 /*
   2 	BattleOS : Engage battling programs.
   3 
   4 	Copyright (C) 1993 Erich P Gatejen    ALL RIGHTS RESERVED
   5 
   6 
   7 	File     : IBUILD.CPP
   8 	Purpose  : Program code for the BattleOS Assembler
   9 
  10 	!! Program code for the instruction builder class members   !!
  11 	!! Must be linked to the BOA				    !!
  12 
  13 */
  14 
  15 
  16 // --------------------------------------------------------------------------
  17 // ---- INCLUDE files -------------------------------------------------------
  18 #include<stdlib.h>
  19 #include<stdio.h>
  20 #include<string.h>
  21 #include "ibuild.h"
  22 
  23 // --------------------------------------------------------------------------
  24 // ---- Local Classes -------------------------------------------------------
  25 
  26 
  27 // --------------------------------------------------------------------------
  28 // ---- Global Variables ----------------------------------------------------
  29 
  30 // - Allowable operands table
  31 #include "allops.h"
  32 
  33 // - Instruction mnemonic table
  34 #include "instarry.h"
  35 
  36 // --------------------------------------------------------------------------
  37 // |||| Member function code ||||||||||||||||||||||||||||||||||||||||||||||||
  38 // --------------------------------------------------------------------------
  39 
  40 // <<-- CLASS  : IBuilder ------------------------------------------------->>
  41 
  42 // ---- MEMBER : constructor ----
  43    IBuilder::IBuilder( void ) {
  44 
  45    // Start with a bad instruction
  46    MValid = FALSE;
  47    LValid = FALSE;
  48    RValid = FALSE;
  49 
  50 }; // end constructor
  51 
  52 
  53 // ---- MEMBER : IsValid ----
  54 BOOLEAN IBuilder::IsValid( void ) {
  55 
  56    if ( MValid && LValid && RValid ) return TRUE;
  57    else return FALSE;
  58 
  59 }; // end IsValid
  60 
  61 
  62 // ---- MEMBER : IsMnemonic ----
  63 BOOLEAN  IBuilder::IsMnemonic( char  *Text ) {
  64 
  65   int	Step;
  66 
  67   // Search the instruction table for the mnemonic
  68   for ( Step = DAT; Step <= INT; ++Step ) {
  69      if ( !strcmp( Text, InstrTable[Step].Text ) ) return TRUE;
  70   };
  71 
  72   // Not found
  73   return FALSE;
  74 
  75 }; // end IsMnemonic
  76 
  77 
  78 // ---- MEMBER : BinaryIs ----
  79 char*  IBuilder::BinaryIs ( void ) {
  80 
  81    unsigned int	  Word;
  82 
  83    // First word
  84    Word = Instruction.FirstWord();
  85    sprintf( Binary, "%04x", Word );
  86    Binary[4] = ':';
  87 
  88    // Second word
  89    Word = Instruction.LeftOperandIs();
  90    sprintf( &Binary[5], "%04x", Word );
  91    Binary[9] = ':';
  92 
  93    // Third word
  94    Word = Instruction.RightOperandIs();
  95    sprintf( &Binary[10], "%04x", Word );
  96 
  97    return( Binary );
  98 
  99 }; // end BinaryIs
 100 
 101 
 102 // ---- MEMBER : LoadMnemonic ----
 103 InstrError  IBuilder::LoadMnemonic( char*  Text ) {
 104 
 105   int	Step;
 106 
 107   // Search the instruction table for the mnemonic
 108   for ( Step = DAT; Step <= INT; ++Step ) {
 109      if ( !strcmp( Text, InstrTable[Step].Text ) ) {
 110 
 111 	// - Found
 112 	Instruction.TokenIs( InstrTable[Step].Token );
 113         MValid = TRUE;
 114 	return NOERROR;
 115 
 116      }; // end if
 117 
 118   }; // end for
 119 
 120   // Not found
 121   return UNKNOWNMNEMONIC;
 122 
 123 }; // end LoadMnemonic