Esempio n. 1
0
 private int ComputeJump(int addr, LabelInfo info)
 {
     if (info.isRelative)
     {
         //Determine distance and direction
         int delta = addr - info.startByte;
         //We can't insert, because that would be destructive to all following labels and jumps
         if (delta > 127 || delta < -128)
         {
             ErrorMsg("Realtive Jump out of range (-128 to 127)");
         }
         return (delta & 0xFF);
     }
     else
     {
         return addr;
     }
 }
Esempio n. 2
0
        private void ResolveLabel(int addr, LabelInfo info)
        {
            //Assume size has been allocated
            addr = ComputeJump(addr, info);
            if(info.isRelative)
            {
                rom[info.labelOffset] = (Byte)addr;
            }
            else
            {
                rom[info.labelOffset] = (Byte)((addr >> 8) & 0xFF);
                rom[info.labelOffset + 1] = (Byte)(addr & 0xFF);
            }

            String bs = "";
            for (int i = info.startByte; i < info.endByte; ++i)
            {
                bs += "0x" + rom[i].ToString("X2");
                if (i < (info.endByte - 1))
                {
                    bs += " ";
                }
            }
            byteLines[info.byteStringIndex] = bs;
        }
Esempio n. 3
0
        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;
            }
        }