Exemple #1
0
        public static int UnpackStringAddress(byte[] memory, ushort byteAddress)
        {
            var version = Header.ReadVersion(memory);

            switch (version)
            {
            case 1:
            case 2:
            case 3:
                return(byteAddress * 2);

            case 4:
            case 5:
                return(byteAddress * 4);

            case 6:
            case 7:
                var stringsOffset = Header.ReadStringsOffset(memory);
                return((byteAddress * 4) + (stringsOffset * 8));

            case 8:
                return(byteAddress * 8);

            default:
                throw new InvalidOperationException("Invalid version number: " + version);
            }
        }
Exemple #2
0
        public static int ReadFileSize(byte[] memory)
        {
            var fileSize = memory.ReadWord(FileSizeIndex);

            var version = Header.ReadVersion(memory);

            switch (version)
            {
            case 1:
            case 2:
            case 3:
                return(fileSize * 2);

            case 4:
            case 5:
                return(fileSize * 4);

            case 6:
            case 7:
            case 8:
                return(fileSize * 8);

            default:
                throw new InvalidOperationException("Invalid version number: " + version);
            }
        }
Exemple #3
0
 public static int ReadMainRoutineAddress(byte[] memory)
 {
     if (Header.ReadVersion(memory) == 6)
     {
         return(Header.UnpackRoutineAddress(memory, Header.ReadInitialPC(memory)));
     }
     else
     {
         return(Header.ReadInitialPC(memory) - 1);
     }
 }
Exemple #4
0
 public static void WriteFontWidthInUnits(byte[] memory, byte fontWidth)
 {
     if (Header.ReadVersion(memory) == 6)
     {
         memory.WriteByte(0x27, fontWidth);
     }
     else
     {
         memory.WriteByte(0x26, fontWidth);
     }
 }
Exemple #5
0
        private void AddAbbreviationRegions(byte[] memory)
        {
            var version = Header.ReadVersion(memory);

            if (version == 1) // V1 did not support abbreviations
            {
                return;
            }

            var tableBase = Header.ReadAbbreviationsTableAddress(memory);
            var count     = version == 2 ? 32 : 96;
            var tableEnd  = tableBase + (count * 2) - 1;

            AddRegion(MemoryMapRegionKind.AbbreviationPointerTable, "Abbreviation pointer table", tableBase, tableEnd);

            var dataBase = 0;
            var dataEnd  = 0;

            for (int i = 0; i < count; i++)
            {
                var address = memory.ReadWord(tableBase + (i * 2)) * 2;

                if (dataBase == 0 || address < dataBase)
                {
                    dataBase = address;
                }

                if (dataEnd == 0 || address > dataEnd)
                {
                    dataEnd = address;
                }
            }

            // scan last string in abbreviation data to get end...
            while (true)
            {
                var zword = memory.ReadWord(dataEnd);
                dataEnd += 2;

                if ((zword & 0x8000) != 0)
                {
                    break;
                }
            }

            dataEnd--;

            AddRegion(MemoryMapRegionKind.AbbreviationData, "Abbreviation data", dataBase, dataEnd);
        }
Exemple #6
0
        private void AddObjectTableRegions(byte[] memory)
        {
            var objectTableBase = Header.ReadObjectTableAddress(memory);
            var objectTableEnd  = 0;
            var objectDataBase  = 0;
            var objectDataEnd   = 0;

            var version             = Header.ReadVersion(memory);
            var entrySize           = ObjectHelpers.GetEntrySize(version);
            var propertyTableOffset = ObjectHelpers.GetPropertyTableAddressOffset(version);

            int objectAddress = objectTableBase + ObjectHelpers.GetPropertyDefaultsTableSize(version);

            while (objectDataBase == 0 || objectAddress < objectDataBase)
            {
                if (objectDataBase == 0 || objectAddress < objectDataBase)
                {
                    var propertyTable = memory.ReadWord(objectAddress + propertyTableOffset);

                    if (objectDataBase == 0 || propertyTable < objectDataBase)
                    {
                        objectDataBase = propertyTable;
                    }

                    if (objectDataEnd == 0 || propertyTable > objectDataEnd)
                    {
                        objectDataEnd = propertyTable;
                    }
                }

                objectAddress += entrySize;
            }

            objectTableEnd = objectAddress - 1;

            // skip last property table to get end...
            var reader = new MemoryReader(memory, objectDataEnd);

            reader.SkipShortName();
            reader.SkipProperties(version);

            objectDataEnd = reader.Address;
            objectDataEnd--;

            AddRegion(MemoryMapRegionKind.ObjectTable, "Object table", objectTableBase, objectTableEnd);
            AddRegion(MemoryMapRegionKind.PropertyData, "Property data", objectDataBase, objectDataEnd);
        }