/*
 *  simpletron.h
 *  Header file for Simpletron simulation program
 *
 */


/* machine's data memory size */
#define MEMSIZE   100


/* sentinel value for end of initialization input */
#define EOINPUT -99999L


/* max and min values storable in a word of memory */
#define MAXDVAL +9999
#define MINDVAL -9999


/* instruction opCodes */
typedef enum { READ = 10, WRITE,
               LOAD = 20, STORE,
               ADD = 30, SUBTRACT, DIVIDE, MULTIPLY,
               BRANCH = 40, BRANCHNEG, BRANCHZERO, HALT }
    op_code;


/* sm_msg
   Takes a string argument and prints it in a field width of 45 
   with *** (three asterisks) at the beginning and end of the line
*/
void sm_msg( char* );


/* sm_dump
   Dumps the current state of the machine, as shown in the handout
*/
void sm_dump( int mem[], int acc, int instrCtr, int instrReg );


/* sm_init_memory 
   Initializes the memory state of the Simpletron machine by
   getting input from the user as described on the handout
*/
void sm_init_memory( int mem[] );


/* sm_init_regs
   Initializes the registers (to zero)
*/
void sm_init_regs( int* acc_ptr, int* instrCtr_ptr, int* instrReg_ptr );


/* sm_run_machine
   Performs the actual simulation of the machine as described in the 
   handout   
*/
void sm_run_machine( int mem[], int acc, int instrCtr, int instrReg );



/* Following three functions are all provided with implementations
   for you in sm_utils.c
*/

/* sm_input_word
   Prompts for (using " ? " as described in the handout) and
   inputs a word of data (4 decimal digits) for the Simpletron
   machine. If loc >= 0 then it is printed out before the 
   prompt.
*/
long sm_input_word( int loc );


/* sm_set_accumulator
   Sets the value of the accumulator to the given argument. If the
   value is too large (i.e. more than 4 decimal digits, or >9999)
   then overflow occurs. In the case of overflow, only the last
   4 digits of the number val are stored.
   
   This functions returns 1 if it completes successfully (without overflow)
   and returns 0 if overflow occurred.
*/
int sm_set_accumulator( int* acc, int val );


/* sign_of
   Returns the sign of the value as a character '+' or '-'
*/
char sign_of( int v );

