home *** CD-ROM | disk | FTP | other *** search
-
- /*
- * m_cpuctrl.c
- * Copyright © 1992 Niklas Röjemo
- */
-
- #include "mnemonics.h"
- #include "error.h"
- #include "option.h"
- #include "put.h"
- #include "input.h"
- #include "global.h"
- #include "expr.h"
- #include "code.h"
- #include "area.h"
- #include "help_cpu.h"
- #include "get.h"
- #include "value.h"
- #include "fix.h"
-
- /** CONTROL **/
-
- static void branchlow(BOOL swi, unsigned int ir)
- {
- Value im;
- if(swi || inputLook() == '#') {
- if(inputLook() == '#') {
- inputSkip();
- if(swi)
- error(ErrorInfo,TRUE,"Swi is always immediate.");
- }
- exprBuild();
- } else {
- exprBuild();
- codePosition(areaCurrent); /* It's relative */
- codeOperator(Op_sub);
- codeInt(8);
- codeOperator(Op_sub);
- }
- im = exprEval(ValueInt | ValueCode|ValueLateLabel);
- switch(im.Tag) {
- case ValueInt:
- if(swi)
- ir |= fixSwi(inputLineNo,im.ValueInt.i);
- else
- ir |= fixBranch(inputLineNo,im.ValueInt.i);
- break;
- case ValueCode: case ValueLateLabel:
- if(swi)
- relocSwi(im);
- else
- relocBranch(im);
- break;
- default:
- error(ErrorError,TRUE,swi?"Illegal swi expression.":"Illegal branch destination.");
- break;
- }
- putIns(ir);
- }
-
- void m_branch(unsigned int cc)
- {
- branchlow(FALSE,cc|0x0a000000);
- }
-
- void m_swi(unsigned int cc)
- {
- branchlow(TRUE,cc|0x0f000000);
- }
-
-
- /** EXTENSION **/
-
- void m_adr(unsigned int cc)
- {
- int ir = cc;
- Value im;
- ir |= DST_OP(getCpuReg());
- ir |= LHS_OP(15) | IMM_RHS; /* pc */
- skipblanks();
- if(inputLook() == ',') {inputSkip(); skipblanks();}
- else error(ErrorError,TRUE,"Inserting a comma after dst.");
- exprBuild();
- codePosition(areaCurrent); /* It's relative */
- codeOperator(Op_sub);
- codeInt(8);
- codeOperator(Op_sub);
- im = exprEval(ValueInt | ValueCode|ValueLateLabel);
- switch(im.Tag) {
- case ValueInt:
- ir = fixAdr(inputLineNo,ir,im.ValueInt.i);
- break;
- case ValueCode: case ValueLateLabel:
- relocAdr(ir,im);
- break;
- default:
- error(ErrorError,TRUE,"Illegal adr expression.");
- break;
- }
- putIns(ir);
- }
-