Source code for /engineering/bos/BOSMSG.COriginal file BOSMSG.C
   1 /*
   2 	BattleOS : Engage battling programs.
   3 
   4 	Copyright (C) 1993 Erich P Gatejen    ALL RIGHTS RESERVED
   5 
   6 	Version  : 1.0
   7 
   8 	File     : BOSMSG.C
   9 	Purpose  : Program code for the Battle Operating System console messages
  10 
  11 */
  12 
  13 #include<stdlib.h>
  14 #include<stdio.h>
  15 #include<conio.h>
  16 #include<time.h>
  17 #include<string.h>
  18 #include"bos.h"
  19 #include"bosmsg.h"
  20 
  21 /* --- External vars.  Defined in BOS.C ----------------------------------*/
  22 extern char		  MMICmnd[MAXCMDSIZE]; /* User input command	    */
  23 extern unsigned char  MMICmndPtr;		 /* Pointer into ^		    */
  24 extern unsigned char  MMICmndArgs;		 /* Number of arguments to a line */
  25 extern long		  TotalClocks;	      /* Number of clocks so far executed */
  26 extern int            MsgMode;		 /* Message format type to use    */
  27 extern unsigned int	  CoreSize;		 /* Core size in instructions     */
  28 
  29 
  30 /* -------- MMI Routines -------------------------------------------------*/
  31 
  32 /* --- TimeStamp -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  */
  33 /* Put a time stamp on screen */
  34 void  TimeStamp() {
  35 
  36    time_t   Time;
  37    char	  *TimeString, *FindEnd;
  38 
  39    Time        = time(NULL); 		/* Get time 		 */
  40    TimeString  = ctime( &Time );   /* Convert to string */
  41 
  42    /* Chop the string */
  43    TimeString = TimeString + 11;   /* Move start to start of time */
  44    FindEnd    = TimeString + 8;
  45    *FindEnd   = 0;			     /* NULL terminate before year
  46 
  47    /* Put the timestamp */
  48    cputs( TimeString );
  49 
  50 }; /* end TimeStamp */
  51 
  52 /* --- BOSMsg -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  */
  53 /* Send a message from the BOS */
  54 void  BOSMsg ( char  *Message ) {
  55 
  56    cputs("BOS>");
  57 
  58    /* What to put next? */
  59    switch( MsgMode ) {
  60 
  61 	 case TIMEM   : /* Put the timestamp */
  62 				 TimeStamp();
  63 				 cputs("<|");
  64 				 break;
  65 
  66 	 case SYSCNTM : /* Put the total system clocks */
  67 				 printf("%ld", TotalClocks );
  68 				 cputs("<|");
  69 				 break;
  70 
  71 	 default      : /* No info */
  72 				 putch('|');
  73 
  74    }; /* end case */
  75 
  76    cputs( Message );
  77 
  78 }; /* end BOSMsg */
  79 
  80 
  81 /* --- BOSMsgI-  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  */
  82 /* Send a message from the BOS, interrupt the command line */
  83 void  BOSMsgI ( char  *Message ) {
  84 
  85    cputs("\rBOS>");
  86 
  87    /* What to put next? */
  88    switch( MsgMode ) {
  89 
  90 	 case TIMEM   : /* Put the timestamp */
  91 				 TimeStamp();
  92 				 cputs("<|");
  93 				 break;
  94 
  95 	 case SYSCNTM : /* Put the total system clocks */
  96 				 printf("%ld", TotalClocks );
  97 				 cputs("<|");
  98 				 break;
  99 
 100 	 default      : /* No info */
 101 				 putch('|');
 102 
 103    }; /* end case */
 104 
 105    cputs( Message );
 106 
 107 }; /* end BOSMsgI */
 108 
 109 
 110 /* --- BOSMsgIDone-  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  */
 111 /* Restore the MMI command line after a BOS message interrupt			*/
 112 void  BOSMsgIDone () {
 113 
 114    /* Put prompt and command line back */
 115    cputs("\n\rBOS>>");
 116    MMICmnd[MMICmndPtr] = NULL;
 117    cputs( MMICmnd );
 118 
 119 }; /* BOSMsgIDone */
 120 
 121 
 122 /* --- BOSMsgTaunt   -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  */
 123 /* Send a taunt from the BOS, interrupt and restore the command line */
 124 void  BOSMsgTaunt ( char  *ProgName, char  *Message ) {
 125 
 126    /* carrage return */
 127    putch('\r');
 128 
 129    /* Put the message */
 130    cputs(ProgName);
 131    putch('>');
 132  
 133    /* What to put next? */
 134    switch( MsgMode ) {
 135 
 136 	 case TIMEM   : /* Put the timestamp */
 137 				 TimeStamp();
 138 				 cputs("<|");
 139 				 break;
 140 
 141 	 case SYSCNTM : /* Put the total system clocks */
 142 				 printf("%d", TotalClocks );
 143 				 cputs("<|");
 144 				 break;
 145 
 146 	 default      : /* No info */
 147 				 putch('|');
 148 
 149    }; /* end case */   
 150 
 151    cputs( Message );
 152    cputs("\n\r");    /* must have return */
 153 
 154    /* Put prompt and command line back */
 155    cputs("BOS>>");
 156    MMICmnd[MMICmndPtr] = NULL;
 157    cputs( MMICmnd );
 158 
 159 }; /* end BOSMsgTaunt */
 160 
 161 
 162 /* --- BOSMsgU -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  - */
 163 /* Continue a BOS Message with an unsigned integer */
 164 void  BOSMsgU ( char  *String, unsigned int  Number ) {
 165 
 166    cprintf( String, Number );
 167 
 168 }; /* end BOSMsgU */
 169 
 170 
 171 /* --- BOSMsgS -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  - */
 172 /* Continue a BOS Message with a signed integer */
 173 void  BOSMsgS ( char  *String, int  Number ) {
 174 
 175    cprintf( String, Number );
 176 
 177 }; /* end BOSMsgS */
 178 
 179 
 180 /* --- BOSMsgL -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  - */
 181 /* Continue a BOS Message with a long integer */
 182 void  BOSMsgL ( char  *String, long  Number ) {
 183 
 184    cprintf( String, Number );
 185 
 186 }; /* end BOSMsgL */
 187 
 188 
 189 /* --- BOSMsgST -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  - */
 190 /* Continue a BOS Message with a string */
 191 void  BOSMsgST ( char  *String, char  *String2 ) {
 192 
 193    cprintf( String, String2 );
 194 
 195 }; /* end BOSMsgST */
 196 
 197 
 198 /* --- BOSMsgC -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  - */
 199 /* Continue a BOS Message */
 200 void  BOSMsgC ( char  *String ) {
 201 
 202    cputs( String );
 203 
 204 }; /* end BOSMsgC */
 205 
 206 
 207 /* --- BOSPrompt -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  - */
 208 /* Put the BOS prompt on the screen */
 209 void  BOSPrompt () {
 210 
 211    cputs("BOS>>");
 212 
 213 }; /* end BOSPrompt */
 214 
 215 
 216 /* --- MsgInitBOS   -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  - */
 217 /* Tell user BOS is ready */
 218 void  MsgInitBOS() {
 219 
 220    clrscr();
 221    cputs("[[[         BATTLE OPERATING SYSTEM  v1.0           ]]]\n\r");
 222    cputs("[ Copyright Erich P Gatejen 1993  All Rights Reserved ]\n\n\r");
 223    printf("!BOS Initialized!  Core Available : %d\n\n\r", CoreSize);
 224 
 225 }; /* end MsgInitBOS */
 226 
 227 
 228 /* --- MsgNoCoreSpec   -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  - */
 229 /* Tell user that they need to specify a core size a the first param of the
 230    command line												*/
 231 void  MsgNoCoreSpec () {
 232 
 233    cputs("\n\r");
 234    BOSMsg("Core size not specified on command line!\n\r");
 235    BOSMsg("BOS ABORTING!\n\n\r");
 236 
 237 }; /* end MsgNoCoreSpec */
 238 
 239 
 240 /* --- MsgBadCoreSpec -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  - */
 241 /* Tell user that they specified a core incorrect size ont the command line */
 242 void  MsgBadCoreSpec () {
 243 
 244    cputs("\n\r");
 245    BOSMsg("Bad core size specified on command line!\n\r");
 246    BOSMsg("BOS ABORTING!\n\n\r");
 247 
 248 }; /* end MsgNoCoreSpec */
 249 
 250 
 251 /* --- MsgNoCore -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  - */
 252 /* Tell user that BOS could not obtain memory for a core */
 253 void  MsgNoCore () {
 254 
 255    cputs("\n\r");
 256    BOSMsg("Cannot allocate core memory.");
 257    BOSMsg("BOS ABORTING!\n\n\r");
 258 
 259 }; /* end MsgNoCoreSpec */
 260 
 261 
 262 /* --- MsgBadCommand   -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  - */
 263 /* Tell user that the command entered is bad ( not recognized ) */
 264 void  MsgBadCommand () {
 265 
 266    int	Step;
 267    char	Text[80];
 268 
 269    Step = 1;
 270    /* Find first space after the first character and NULL it */
 271    while (( Step < MAXCMDSIZE + 1 )&&( MMICmnd[Step] != ' ')) Step++;
 272    MMICmnd[Step] = NULL;
 273 
 274    /* Leave safety net so MMI command displayed doesn't excede displayable
 275 	 size                                                                */
 276    MMICmnd[40] = NULL;
 277 
 278    /* Assemble message */
 279    strcpy( Text, "Command > " );
 280    strcat( Text, MMICmnd );
 281    strcat( Text, " < not used!\n\n\r");
 282 
 283    /* Send the message */
 284    BOSMsg( Text );
 285 
 286 };
 287 
 288 
 289 /* --- DisplayState   -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  - */
 290 /* Put the state of the screen.  Always use 8 chars */
 291 void  DisplayState( int  State ) {
 292 
 293    /* Case through states */
 294    switch( State ) {
 295 
 296 	 case READY_RUN  : cputs("RUNNING ");
 297       		         break;	
 298 
 299 	 case HELD       : cputs("HELD    ");
 300 			         break;
 301 
 302 	 case WAIT       : cputs("WAITING ");
 303    				    break;
 304 
 305 	 case NEW        : cputs("NEW     ");
 306 				    break;
 307 
 308 	 case KILLED     : cputs("KILLED  ");
 309 				    break;
 310 
 311 	 case UNUSED     : cputs("UNUSED  ");
 312 			         break;
 313 
 314    }; /* end case */
 315 
 316 }; /* end DiplayState */
 317 
 318 
 319 /* --- DisplayOpToken   -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  - */
 320 /* Put the character for the optoken */
 321 void  DisplayOpToken( unsigned char  Byte ) {
 322 
 323    /* -- Put the first token */
 324    switch( Byte ) {
 325 
 326 	    case NOTOKEN : BOSMsgC("X");
 327 				    break;
 328 	    case REG     : BOSMsgC("R");
 329 				    break;
 330 	    case PTR     : BOSMsgC("^");
 331 				    break;
 332 	    case MEM     : BOSMsgC("M");
 333 				    break;
 334 	    case IMMEDIATE : BOSMsgC("I");
 335 
 336     }; /* end case */
 337 
 338 }; /* end DisplayOpToken */
 339 
 340 
 341 /* --- Continue   -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  - */
 342 /* Put message and wait for user to hit a key */
 343 char  Continue() {
 344 
 345    cputs("-- Press [ENTER] to continue -- -- -- -- -- -- \n\r");
 346    return ( getch() );
 347 
 348 }; /* end Continue */
 349 
 350 
 351 /* --- BOSMsgClean-  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  - */
 352 /* Clean the next screen line */
 353 void  BOSMsgClean() {
 354 
 355    cputs("\r");
 356    clreol();
 357 
 358 }; /* end BOSMsgClean */