public void EnterTriad(GBASMParser.TriadContext context) { PrintLine("Triad Detected"); argFSM = ArgFSM.SRC; currentInst.op = Instruction.MapOp(context.GetText()); }
public void EnterValue(GBASMParser.ValueContext context) { PrintLine("Numeric Value"); String s = context.GetText(); PrintLine(s); Int16 value = (Int16)ParseNum(s); if (isReptArg) { isReptArg = false; rep_stack.Peek().reps = value-1; //Offset for the fact the original code will be copied } else if (isSectionArg) { isSectionArg = false; sec_stack.Peek().size = value; } else { if (db_stack > 0) { RomPush(context, (Byte)value); } else { if (Math.Abs(value) > 255) { SetArgLoc(Locations.WIDE_IMM); } else { SetArgLoc(Locations.IMM); } SetArgVal(value); } } }
public void EnterRegister(GBASMParser.RegisterContext context) { PrintLine("Register"); LocationInfo l = GetCurrentArg(); l.isReg = true; String target = context.GetText(); SetArgLoc(ParseLocation(target)); if(target == "HL+" || target == "HLI") { currentInst.op = Instructions.LDI; } if (target == "HL-" || target == "HLD") { currentInst.op = Instructions.LDD; } }
public void EnterString_data(GBASMParser.String_dataContext context) { PrintLine("Literal Value"); if (db_stack > 0) { String s = context.GetText(); //Remove quotations for (int i = 1; i < s.Length-1; ++i) { RomPush(context, (Byte)s[i]); } } }
public void EnterNegvalue(GBASMParser.NegvalueContext context) { PrintLine("Signed Value"); Int16 value = (Int16)(-ParseNum(context.GetText().Substring(1))); if (db_stack > 0) { RomPush(context, (Byte)value); } else { if (Math.Abs(value) > 127) { SetArgLoc(Locations.WIDE_IMM); } else { SetArgLoc(Locations.IMM); } SetArgVal(value); } }
public void EnterMonad(GBASMParser.MonadContext context) { PrintLine("Monad Detected"); argFSM = ArgFSM.COMPLETE; currentInst.op = Instruction.MapOp(context.GetText()); currentInst.src.loc = Locations.NONE; currentInst.dst.loc = Locations.NONE; }
public void EnterLabel(GBASMParser.LabelContext context) { PrintLine("Label Defined"); String label = context.GetText(); label = label.Substring(0, label.Length - 1); //Chop the colon jumpAddressIndex.Add(label, rom.Count); if(unProcessedJumpLabels.ContainsKey(label)) { foreach(LabelInfo info in unProcessedJumpLabels[label]) { ResolveLabel(jumpAddressIndex[label], info); } } }
public void EnterJump(GBASMParser.JumpContext context) { PrintLine("Label Dereference"); String label = context.GetText(); LabelInfo l = new LabelInfo(); OffsetInfo o; l.startByte = rom.Count; l.isRelative = currentInst.op == Instructions.JR; o = currentInst.GetCurrentOffset(); l.labelOffset = l.startByte + o.total; //This will be 0 if no src is encoded l.endByte = l.labelOffset + ((l.isRelative) ? 1 : 2); l.byteStringIndex = byteLines.Count; if (jumpAddressIndex.ContainsKey(label)) { SetArgVal((Int16)ComputeJump(jumpAddressIndex[label], l)); } else { SetArgVal(0); //CALCULATE SPACE REQUIRED if(!unProcessedJumpLabels.ContainsKey(label)) { unProcessedJumpLabels.Add(label, new List<LabelInfo>()); } //An arg size of NONE should not effect current address calculations //SRC should always be set before DST is set unProcessedJumpLabels[label].Add(l); } switch (currentInst.op) { case Instructions.JR: SetArgLoc(Locations.IMM); break; case Instructions.JP: default: SetArgLoc(Locations.WIDE_IMM); break; } }
public void EnterFlag(GBASMParser.FlagContext context) { PrintLine("Flag"); LocationInfo l = GetCurrentArg(); l.isFlag = true; switch (context.GetText()) { case "Z": SetArgLoc(Locations.Z); break; case "C": SetArgLoc(Locations.C); break; case "NZ": SetArgLoc(Locations.NZ); break; case "NC": SetArgLoc(Locations.NC); break; default: break; } }