home *** CD-ROM | disk | FTP | other *** search
-
- /*
- * help_cop.c
- * Copyright © 1992 Niklas Röjemo
- */
-
- #include "error.h"
- #include "expr.h"
- #include "help_cop.h"
- #include "input.h"
- #include "area.h"
- #include "get.h"
- #include "option.h"
- #include "value.h"
- #include "code.h"
- #include "fix.h"
- #include "reloc.h"
-
- int help_copInt(int max,char *msg)
- {
- Value i;
- exprBuild();
- i = exprEval(ValueInt);
- if(i.Tag == ValueInt) {
- if(i.ValueInt.i <0 || i.ValueInt.i >max) {
- error(ErrorError,TRUE,"%d is not a legal %s.",i.ValueInt.i,msg);
- return 0;
- }
- } else {
- error(ErrorError,TRUE,"Illegal expression as %s.",msg);
- return 0;
- }
- return i.ValueInt.i;
- }
-
- WORD help_copAddr(WORD ir)
- {
- BOOL pre;
- Value offset;
- skipblanks();
- if(inputLook() == ',') { inputSkip(); skipblanks(); }
- else error(ErrorError,TRUE,"Inserting missing comma before address.");
- if(inputLook() == '[') {
- BOOL up = TRUE;
- inputSkip();
- skipblanks();
- ir |= LHS_OP(getCpuReg()); /* Base register */
- skipblanks();
- if(inputLook() == ']') { pre = FALSE; inputSkip(); skipblanks(); }
- else pre = TRUE;
- if(inputLook() == ',') { /* either [base,XX] or [base],XX */
- inputSkip();
- skipblanks();
- if(inputLook() == '+') { inputSkip(); skipblanks(); }
- else if(inputLook() == '-') { inputSkip(); skipblanks(); up = FALSE;}
- if(inputLook() == '#') {
- inputSkip();
- exprBuild();
- if(!up) codeOperator(Op_neg);
- offset = exprEval(ValueInt |ValueCode|ValueLateLabel);
- switch(offset.Tag) {
- case ValueInt:
- ir = fixCopOffset(inputLineNo,ir,offset.ValueInt.i);
- break;
- case ValueCode: case ValueLateLabel:
- relocCopOffset(ir,offset);
- break;
- default:
- error(ErrorError,TRUE,"Illegal offset expression.");
- break;
- }
- } else {
- error(ErrorError,TRUE,"Coprocessor memory instructions can not use register offset.");
- }
- skipblanks();
- } else { /* cop_reg,[base] if this way */
- if(pre)
- error(ErrorError,TRUE,"Illegal character '%c' after base.",inputLook());
- ir |= UP_FLAG; /* changes offset #-0 to #+0, looks nicer when disassembled. */
- }
- if(pre) {
- if(inputLook() == ']') { inputSkip(); skipblanks(); }
- else error(ErrorError,TRUE,"Inserting missing ] after address.");
- ir |= PRE_FLAG;
- }
- if(inputLook() == '!') {
- if(pre) ir |= WB_FLAG;
- else error(ErrorError,TRUE,"Writeback not allowed together with post-(inc/dec)rement.");
- inputSkip();
- skipblanks();
- }
- } else { /* cop_reg,Address */
- ir |= PRE_FLAG | LHS_OP(15);
- exprBuild();
- codePosition(areaCurrent);
- codeOperator(Op_sub);
- codeInt(8);
- codeOperator(Op_sub);
- offset = exprEval(ValueInt |ValueCode|ValueLateLabel);
- switch(offset.Tag) {
- case ValueInt:
- ir = fixCopOffset(inputLineNo,ir,offset.ValueInt.i);
- break;
- case ValueCode: case ValueLateLabel:
- relocCopOffset(ir,offset);
- break;
- default:
- error(ErrorError,TRUE,"Illegal address expression.");
- break;
- }
- }
- return ir;
- }
-