示例#1
0
        public string ListAssembler(SpecialMode specialMode = SpecialMode.None)
        {
            opCodes = new OpCodes();

            ushort ui16Loop = (ushort)(Format == ProgramFormat.OrixProgram ? OtherFileInfo.ORIX_HEADER_LENGTH : 0);
            ushort ui16Address;
            ushort ui16BranchAddr;

            string strAscii;

            StringBuilder stbDissassembly = new StringBuilder();

            stbDissassembly.EnsureCapacity(65000);

            if (ProgramName == null)
            {
                ProgramName = "";
            }

            ui16Address = (ushort)(StartAddress + (Format == ProgramFormat.OrixProgram ? OtherFileInfo.ORIX_HEADER_LENGTH : 0));

            byte bByte;

            while (ui16Loop < ProgramLength)
            {
                bByte = ProgramData[ui16Loop];

                OpCodes.sOpCode sTmpStructOpCodes = opCodes.FindOpInfo(bByte);

                // if the byte is 00 (BRK instruction) and it is a Telestrat (Stratsed) floppy disk,
                // this mnemonic is accompanied by an argument so we adjust the default properties
                if (bByte == 0 && specialMode == SpecialMode.Telestrat)
                {
                    sTmpStructOpCodes.bOpBytes = 2; //instead of 1
                    sTmpStructOpCodes.bOpMode  = 4; //instead of 1
                }

                strAscii = "";

                string strOpParams = "";

                // Current address
                stbDissassembly.AppendFormat("${0:X4}  ", ui16Address);

                if (ui16Loop + sTmpStructOpCodes.bOpBytes > ProgramLength)
                {
                    byte bCurrByte = Convert.ToByte(ProgramData[ui16Loop]);

                    stbDissassembly.AppendFormat("{0:X2} ", bCurrByte);

                    sTmpStructOpCodes.bOpBytes = 1;
                    sTmpStructOpCodes.bOpMode  = 0;

                    if (bCurrByte < 32 || bCurrByte > 126)
                    {
                        strAscii += ".";
                    }
                    else
                    {
                        strAscii += Convert.ToChar(bCurrByte);
                    }
                }
                else
                {
                    for (ushort siIndex = 0; siIndex < sTmpStructOpCodes.bOpBytes; siIndex++)
                    {
                        byte bCurrByte = Convert.ToByte(ProgramData[ui16Loop + siIndex]);

                        stbDissassembly.AppendFormat("{0:X2} ", bCurrByte);

                        if (bCurrByte < 32 || bCurrByte > 126)
                        {
                            strAscii += ".";
                        }
                        else
                        {
                            strAscii += Convert.ToChar(bCurrByte);
                        }
                    }
                }

                if (sTmpStructOpCodes.bOpBytes < 2)
                {
                    stbDissassembly.Append("   ");
                }

                if (sTmpStructOpCodes.bOpBytes < 3)
                {
                    stbDissassembly.Append("   ");
                }

                byte bByte1 = 0;
                byte bByte2 = 0;

                if (sTmpStructOpCodes.bOpBytes > 1)
                {
                    bByte1 = Convert.ToByte(ProgramData[ui16Loop + 1]);
                }

                if (sTmpStructOpCodes.bOpBytes > 2)
                {
                    bByte2 = Convert.ToByte(ProgramData[ui16Loop + 2]);
                }

                switch (sTmpStructOpCodes.bOpMode)
                {
                case 0:
                case 1:
                    strOpParams = "";
                    break;

                case 2:
                    strOpParams = string.Format("#${0:X2}", bByte1);
                    break;

                case 3:
                    strOpParams = string.Format("${0:X2}{1:X2}", bByte2, bByte1);
                    break;

                case 4:
                    strOpParams = string.Format("${0:X2}", bByte1);
                    break;

                case 5:     // Calculate jump address
                    if (bByte1 > 127)
                    {
                        ui16BranchAddr = (ushort)(ui16Address - (255 - bByte1));
                        ui16BranchAddr++;
                    }
                    else
                    {
                        ui16BranchAddr = (ushort)((ui16Address + 2) + bByte1);
                    }

                    strOpParams = string.Format("${0:X4}", ui16BranchAddr);
                    break;

                case 6:
                    strOpParams = string.Format("${0:X2}{1:X2},X", bByte2, bByte1);
                    break;

                case 7:
                    strOpParams = string.Format("${0:X2}{1:X2},Y", bByte2, bByte1);
                    break;

                case 8:
                    strOpParams = string.Format("${0:X2},X", bByte1);
                    break;

                case 9:
                    strOpParams = string.Format("${0:X2},Y", bByte1);
                    break;

                case 10:
                    strOpParams = string.Format("(${0:X2},X)", bByte1);
                    break;

                case 11:
                    strOpParams = string.Format("(${0:X2}),Y", bByte1);
                    break;

                case 12:
                    strOpParams = "A";
                    break;

                case 13:
                    strOpParams = string.Format("${0:X2}{1:X2}", bByte2, bByte1);
                    break;
                }

                stbDissassembly.AppendFormat("   {0,-3:G} {1,-8:G}   {2,-3}\n",
                                             sTmpStructOpCodes.strOpMne, strOpParams, strAscii);

                ui16Address += sTmpStructOpCodes.bOpBytes;
                ui16Loop    += sTmpStructOpCodes.bOpBytes;
            }

            return(stbDissassembly.ToString().Replace('`', '©'));
        }
示例#2
0
        public String Assembly()
        {
            opCodes = new OpCodes();

            UInt16 ui16Loop       = 0;
            UInt16 ui16Address    = 0;
            UInt16 ui16BranchAddr = 0;

            String strAscii = "";

            StringBuilder strDissassembly = new StringBuilder();

            strDissassembly.EnsureCapacity(65000);

            if (ProgramName == null)
            {
                ProgramName = "";
            }

            ui16Address = StartAddress;

            Byte bByte = 0x00;

            while (ui16Loop < ProgramLength)
            {
                bByte = m_programData[ui16Loop];

                OpCodes.sOpCode sTmpStructOpCodes = new OpCodes.sOpCode();
                sTmpStructOpCodes = opCodes.FindOpInfo(bByte);

                strAscii = "";

                String strOpParams = "";

                // Current address
                strDissassembly.AppendFormat("${0:X4}  ", ui16Address);

                if (ui16Loop + sTmpStructOpCodes.bOpBytes > ProgramLength)
                {
                    Byte bCurrByte = Convert.ToByte(m_programData[ui16Loop]);

                    strDissassembly.AppendFormat("{0:X2} ", bCurrByte);

                    sTmpStructOpCodes.bOpBytes = 1;
                    sTmpStructOpCodes.bOpMode  = 0;

                    if (bCurrByte < 32 || bCurrByte > 126)
                    {
                        strAscii += ".";
                    }
                    else
                    {
                        strAscii += Convert.ToChar(bCurrByte);
                    }
                }
                else
                {
                    for (short siIndex = 0; siIndex < sTmpStructOpCodes.bOpBytes; siIndex++)
                    {
                        Byte bCurrByte = Convert.ToByte(m_programData[ui16Loop + siIndex]);

                        strDissassembly.AppendFormat("{0:X2} ", bCurrByte);

                        if (bCurrByte < 32 || bCurrByte > 126)
                        {
                            strAscii += ".";
                        }
                        else
                        {
                            if (bCurrByte == 0x60)
                            {
                                strAscii += "©";
                            }
                            else
                            {
                                strAscii += Convert.ToChar(bCurrByte);
                            }
                        }
                    }
                }

                if (sTmpStructOpCodes.bOpBytes < 2)
                {
                    strDissassembly.Append("   ");
                }

                if (sTmpStructOpCodes.bOpBytes < 3)
                {
                    strDissassembly.Append("   ");
                }

                Byte bByte1 = 0;
                Byte bByte2 = 0;

                if (sTmpStructOpCodes.bOpBytes > 1)
                {
                    bByte1 = Convert.ToByte(m_programData[ui16Loop + 1]);
                }

                if (sTmpStructOpCodes.bOpBytes > 2)
                {
                    bByte2 = Convert.ToByte(m_programData[ui16Loop + 2]);
                }

                switch (sTmpStructOpCodes.bOpMode)
                {
                case 0:
                case 1: strOpParams = "";
                    break;

                case 2: strOpParams = String.Format("#${0:X2}", bByte1);
                    break;

                case 3: strOpParams = String.Format("${0:X2}{1:X2}", bByte2, bByte1);
                    break;

                case 4: strOpParams = String.Format("${0:X2}", bByte1);
                    break;

                case 5:     // Calculate jump address
                    if (bByte1 > 127)
                    {
                        ui16BranchAddr = (UInt16)(ui16Address - (255 - bByte1));
                        ui16BranchAddr++;
                    }
                    else
                    {
                        ui16BranchAddr = (UInt16)((ui16Address + 2) + bByte1);
                    }

                    strOpParams = String.Format("${0:X4}", ui16BranchAddr);
                    break;

                case 6: strOpParams = String.Format("${0:X2}{1:X2},X", bByte2, bByte1);
                    break;

                case 7: strOpParams = String.Format("${0:X2}{1:X2},Y", bByte2, bByte1);
                    break;

                case 8: strOpParams = String.Format("${0:X2},X", bByte1);
                    break;

                case 9: strOpParams = String.Format("${0:X2},Y", bByte1);
                    break;

                case 10: strOpParams = String.Format("(${0:X2},X)", bByte1);
                    break;

                case 11: strOpParams = String.Format("(${0:X2}),Y", bByte1);
                    break;

                case 12: strOpParams = "A";
                    break;

                case 13: strOpParams = String.Format("${0:X2}{1:X2}", bByte2, bByte1);
                    break;
                }

                strDissassembly.AppendFormat("   {0,-3:G} {1,-8:G}   {2,-3}\n",
                                             sTmpStructOpCodes.strOpMne, strOpParams, strAscii);

                ui16Address += sTmpStructOpCodes.bOpBytes;
                ui16Loop    += sTmpStructOpCodes.bOpBytes;
            }

            return(strDissassembly.ToString());
        }