#include #include #include "glovar.h" /*****************************************************************/ /* Computing Science MSc Dissertation */ /* `newogg' oggin Interpreter */ /* By Lydia L W Wong (C) August 1990 */ /* University of Stirling */ /*****************************************************************/ /* this file named newg3.c contains a package of functions which */ /* execute the job of function codes of group 3. */ /*****************************************************************/ extern void Caseerror(); /* function for output error message*/ extern char grp3code[][4]; /* group 3 mnemonics */ /*****************************************************************/ /* input value 'r' of bits 12-14 and the whole instruction value */ /* 'data' from dogroup3(); compute value of bits 10-11 to decide */ /* the function code of group 3. */ /*****************************************************************/ void degrp3(r, data, code, signal) int r; /* value of bits 12-14 */ int data; /* value of instruction */ ingroup3 *code; /* function code of group 3 */ int signal; /* signal lookahead if 1 */ { switch (r) { case 0: switch ((data % 4096) / 512) { case 0: (*code) = beq; break ; case 2: (*code) = bne; break ; case 4: (*code) = bgt; break ; case 6: (*code) = bge; break ; default: Caseerror(Line); /* should never get here */ } break ; case 7: switch ((data % 4096) / 512) { case 0: (*code) = blt; break ; case 2: (*code) = ble; break ; case 4: (*code) = bcs; break ; case 6: (*code) = bcc; break ; default: Caseerror(Line); /* or here */ } break ; default: Caseerror(Line); } } /*****************************************************************/ /* move the decoded assembly instruction to assl_win for display */ /*****************************************************************/ void assl_g3(code,operand,line) ingroup3 code; /* function code of group 3 */ int operand; /* value of operand bits */ int line; /* line number of assl_win */ { mvwprintw(assl_win,line,0,"%s",grp3code[code]); mvwprintw(assl_win,line,3,"%c",','); mvwprintw(assl_win,line,4,"%o",operand); } /*****************************************************************/ /* output a comment to comm_win depending on the input signal and*/ /* a flag character. */ /*****************************************************************/ void messa3(ch,operand,s) char ch; /* flag character of C,N,Z,V */ int operand; /* location number */ int s; /* signal digit of 0 or 1 */ { char string[5]; if (s == 0) mvwprintw(comm_win,1,1,"branch to %o if %c %s.",operand,ch,"clear"); else mvwprintw(comm_win,1,1,"branch to %o if %c %s.",operand,ch,"set"); } /*****************************************************************/ /* input location number; if bits N,Z clear then pcnew takes the */ /* value, else set pcnew to pc + 1; move comments to comm_win. */ /*****************************************************************/ void bgt_group3(data) int data; /* location number */ { if ((psw.z == 0) && (psw.n == 0)) pcnew = (data); else pcnew = pc + 1; mvwprintw(comm_win,1,1,"branch to %o if Z,N clear.",data); } /*****************************************************************/ /* input location number; if Z set, N clear then pcnew becomes */ /* `data', else set pcnew to pc + 1; move comments to comm_win. */ /*****************************************************************/ void blt_group3(data) int data; /* location number */ { if ((psw.n == 1) && (psw.z == 0)) pcnew = (data); else pcnew = pc + 1; mvwprintw(comm_win,1,1,"branch to %o if N set,Z clear.",data); } /*****************************************************************/ /* input location number; check if N or Z set then pcnew becomes */ /* `data', else set pcnew to pc + 1; move comments to comm_win. */ /*****************************************************************/ void ble_group3(data) int data; /* location number */ { if ((psw.n == 1) || (psw.z == 1)) pcnew = (data); else pcnew = pc + 1; mvwprintw(comm_win,1,1,"branch to %o if N or Z set.",data); } /*****************************************************************/ /* test one of the psw flags depending on `ch' and branch if the */ /* flag is set to the value of signal; otherwise pcnew is pc + 1 */ /*****************************************************************/ void test_branch(ch,data,signal) char ch; /* character of 'C','Z','N' */ int data; /* location for branching */ int signal; /* signal value of 0 or 1 */ { boolean yes; /* true = (psw.ch == signal) */ switch (ch) { case 'N' : yes = (psw.n == signal); break; case 'Z' : yes = (psw.z == signal); break; case 'C' : yes = (psw.c == signal); break; } if (yes) pcnew = data; else pcnew = pc + 1; messa3(ch,data,signal); } /*****************************************************************/ /* input function code and operand from dogroup3(); execute the */ /* function code. */ /*****************************************************************/ void exgrp3(code, operand) ingroup3 code; /* function code of group 3 */ int operand; /* value of operand bits */ { switch (code) { case beq: test_branch('Z',operand,1); break ; case bne: test_branch('Z',operand,0); break ; case bgt: bgt_group3(operand); break ; case bge: test_branch('N',operand,0); break ; case blt: blt_group3(operand); break ; case ble: ble_group3(operand); break ; case bcs: test_branch('C',operand,1); break ; case bcc: test_branch('C',operand,0); break ; default: Caseerror(Line); } } /*****************************************************************/ /* input values of bits 12-14, bits 10-15 and operand bits from */ /* inst(); decode and return result to code3; execute code3. */ /*****************************************************************/ void dogroup3(bits12_14, bits10_15, code3, operand,signal) int bits12_14; /* value of bits 12-14 */ int bits10_15; /* value of bits 10-15 */ ingroup3 *code3; /* function code of group 3 */ int operand; /* value of operand bits */ int signal; /* value of either 1 or 0 */ { ingroup3 g3; /* function code of group 3 */ octalcode str; /* octal no. output as a string */ int randbits;/* value of operand bits */ if (signal == 1) { randbits = operand; degrp3(bits12_14, bits10_15, &(*code3),signal); assl_g3(*code3,randbits,2); } else { randbits = operand; degrp3(bits12_14, bits10_15, &(*code3),signal); exgrp3((*code3), operand); wattron(assl_win,A_STANDOUT); assl_g3(*code3,randbits,1); wattroff(assl_win,A_STANDOUT); mvwprintw(expl_win,2,0,"%s",grp3code[*code3]); mvwprintw(expl_win,4,0,"%s","none"); mvwprintw(expl_win,6,0,"none"); } } /* ** End of newg3.c */