コード例 #1
0
ファイル: PLM.cs プロジェクト: DJuttmann/SM3E
        // Read data from ROM at given PC address.
        public override bool ReadFromROM(Rom rom, int addressPC)
        {
            int sAddressPC = addressPC;

            byte [] b = new byte [2];
            rom.Seek(addressPC);
            if (!rom.Read(b, 0, 2))
            {
                return(false);
            }

            int n = 0;

            while (b [0] != 0 || b [1] != 0)
            {
                Plms.Add(new Plm());
                if (!Plms [n].ReadFromROM(rom, addressPC))
                {
                    return(false);
                }
                addressPC += Plms [n].Size;
                rom.Seek(addressPC);
                if (!rom.Read(b, 0, 2))
                {
                    return(false);
                }
                n++;
            }
            startAddressPC = sAddressPC;
            return(true);
        }
コード例 #2
0
ファイル: Background_Fx.cs プロジェクト: DJuttmann/SM3E
        // Read data from ROM at given PC address.
        public override bool ReadFromROM(Rom rom, int addressPC)
        {
            int startAddress = addressPC;

            byte [] b = new byte [2];
            rom.Seek(addressPC);
            if (!rom.Read(b, 0, 2))
            {
                return(false);
            }
            if (b [0] == TerminatorByte && b [1] == TerminatorByte)
            {
                startAddressPC = addressPC;
                return(true);
            }

            FxData newFxData;
            int    adPC = addressPC;

            do
            {
                newFxData = new FxData();
                rom.Seek(adPC);
                newFxData.ReadFromROM(rom, adPC);
                FxDatas.Add(newFxData);
                adPC += newFxData.Size;
            }while (newFxData.DoorPtr != 0x830000);

            startAddressPC = startAddress;
            return(true);
        }
コード例 #3
0
        // Read data from ROM at given PC address.
        public override bool ReadFromROM(Rom rom, int addressPC)
        {
            //byte [] buffer;
            //int DecompressedSize = Compression.ReadCompressedData (out buffer, addressPC);
            rom.Seek(addressPC);
            int compressedSize = rom.Decompress(out List <byte> buffer);

            CompressedData.Clear();
            rom.Seek(addressPC);
            rom.Read(CompressedData, compressedSize);
            CompressionUpToDate = true;
            int decompressedSize = buffer.Count;
            int colour_count     = decompressedSize / 2;

            R.Clear();
            G.Clear();
            B.Clear();
            for (int n = 0; n < colour_count; n++)
            {
                int colour = Tools.ConcatBytes(buffer [n << 1], buffer [n << 1 | 1]);
                R.Add((byte)((colour & 0x001F) << 3));
                G.Add((byte)((colour & 0x03E0) >> 2));
                B.Add((byte)((colour & 0x7C00) >> 7));
            }
            startAddressPC = addressPC;
            return(true);
        }
コード例 #4
0
ファイル: Background_Fx.cs プロジェクト: DJuttmann/SM3E
        // Read data from ROM at given PC address.
        public override bool ReadFromROM(Rom rom, int addressPC)
        {
            rom.Seek(addressPC);
            int compressedSize = rom.Decompress(out Bytes);

            CompressedData.Clear();
            rom.Seek(addressPC);
            rom.Read(CompressedData, compressedSize);
            CompressionUpToDate = true;

            return(true);
        }
コード例 #5
0
        // Read data from ROM at given PC address.
        public override bool ReadFromROM(Rom rom, int addressPC)
        {
            int size = TileCount * 16;

            byte [] b = new byte [size];
            rom.Seek(addressPC);
            if (!rom.Read(b, 0, size))
            {
                return(false);
            }

            int index = 0;

            for (int t = 0; t < TileCount; t++)
            {
                for (int tileRow = 0; tileRow < 8; tileRow++)
                {
                    for (int bit = 0; bit < 8; bit++)
                    {
                        int value = ((b [16 * t + 2 * tileRow] >> bit) & 1) +
                                    ((b [16 * t + 2 * tileRow + 1] >> bit) & 1) * 2;
                        Bytes [index] = (byte)value;
                        index++;
                    }
                }
            }

            startAddressPC = addressPC;
            return(true);
        }
コード例 #6
0
        // Read data from ROM at given PC address.
        public override bool ReadFromROM(Rom rom, int addressPC)
        {
            byte bite;
            byte bit;
            int  size = TileCount * 32;

            byte [] b = new byte [size];
            rom.Seek(addressPC);
            if (!rom.Read(b, 0, size))
            {
                return(false);
            }

            for (int t = 0; t < TileCount; t++)
            {
                for (int n = 0; n < 8; n++) // bitplane 0
                {
                    bite = b [t << 5 | n << 1];
                    for (int i = 0; i < 8; i++)
                    {
                        bit = (byte)(bite & 1);
                        Bytes [t << 6 | n << 3 | i] = bit;
                        bite >>= 1;
                    }
                }
                for (int n = 0; n < 8; n++) // bitplane 1
                {
                    bite = b [t << 5 | n << 1 | 1];
                    for (int i = 0; i < 8; i++)
                    {
                        bit = (byte)(bite & 1);
                        Bytes [t << 6 | n << 3 | i] = (byte)(Bytes [t << 6 | n << 3 | i] | bit << 1);
                        bite >>= 1;
                    }
                }
                for (int n = 0; n < 8; n++) // bitplane 2
                {
                    bite = b [t << 5 | n << 1 | 16];
                    for (int i = 0; i < 8; i++)
                    {
                        bit = (byte)(bite & 1);
                        Bytes [t << 6 | n << 3 | i] = (byte)(Bytes [t << 6 | n << 3 | i] | bit << 2);
                        bite >>= 1;
                    }
                }
                for (int n = 0; n < 8; n++) // bitplane 3
                {
                    bite = b [t << 5 | n << 1 | 17];
                    for (int i = 0; i < 8; i++)
                    {
                        bit = (byte)(bite & 1);
                        Bytes [t << 6 | n << 3 | i] = (byte)(Bytes [t << 6 | n << 3 | i] | bit << 3);
                        bite >>= 1;
                    }
                }
            }

            startAddressPC = addressPC;
            return(true);
        }
コード例 #7
0
ファイル: Background_Fx.cs プロジェクト: DJuttmann/SM3E
        // Read data from ROM at given PC address.
        public override bool ReadFromROM(Rom rom, int addressPC)
        {
            byte [] b = new byte [DefaultSize];
            rom.Seek(addressPC);

            if (!rom.Read(b, 0, DefaultSize))
            {
                return(false);
            }
            DoorPtr               = Tools.ConcatBytes(b [0], b [1], 0x83);
            LiquidSurfaceStart    = Tools.ConcatBytes(b [2], b [3]);
            LiquidSurfaceNew      = Tools.ConcatBytes(b [4], b [5]);
            LiquidSurfaceSpeed    = Tools.ConcatBytes(b [6], b [7]);
            LiquidSurfaceDelay    = b [8];
            FxType                = b [9];
            FxBitA                = b [10];
            FxBitB                = b [11];
            FxBitC                = b [12];
            PaletteFxBitflags     = b [13];
            TileAnimationBitflags = b [14];
            PaletteBlend          = b [15];

            startAddressPC = addressPC;
            return(true);
        }
コード例 #8
0
ファイル: Room.cs プロジェクト: DJuttmann/SM3E
        public override bool ReadFromROM(Rom rom, int addressPC)
        {
            byte [] b = new byte [DefaultSize];
            rom.Seek(addressPC);
            if (!rom.Read(b, 0, DefaultSize))
            {
                return(false);
            }

            LevelDataPtr        = Tools.ConcatBytes(b [0], b [1], b [2]);
            TileSet             = b [3];
            SongSet             = b [4];
            PlayIndex           = b [5];
            FxPtr               = Tools.ConcatBytes(b [6], b [7], 0x83);
            EnemySetPtr         = Tools.ConcatBytes(b [8], b [9], 0xA1);
            EnemyGfxPtr         = Tools.ConcatBytes(b [10], b [11], 0xB4);
            BackgroundScrolling = Tools.ConcatBytes(b [12], b [13]);
            ScrollSetPtr        = Tools.ConcatBytes(b [14], b [15], 0x8F);
            UnusedPtr           = Tools.ConcatBytes(b [16], b [17], 0x8F); // almost always null
            MainAsmPtr          = Tools.ConcatBytes(b [18], b [19], 0x8F);
            PlmSetPtr           = Tools.ConcatBytes(b [20], b [21], 0x8F);
            BackgroundPtr       = Tools.ConcatBytes(b [22], b [23], 0x8F);
            SetupAsmPtr         = Tools.ConcatBytes(b [24], b [25], 0x8F);

            startAddressPC = addressPC;
            return(true);
        }
コード例 #9
0
ファイル: Door.cs プロジェクト: DJuttmann/SM3E
        // Read data from ROM at given PC address.
        public override bool ReadFromROM(Rom rom, int addressPC)
        {
            byte [] b = new byte [DefaultSize];
            rom.Seek(addressPC);
            if (!rom.Read(b, 0, 2))
            {
                return(false);
            }

            if (b [0] == 0 && b [1] == 0)
            {
                ElevatorPad    = true;
                startAddressPC = addressPC;
                return(true);
            }

            if (!rom.Read(b, 2, DefaultSize - 2))
            {
                return(false);
            }
            RoomPtr         = Tools.ConcatBytes(b [0], b [1], 0x8F);
            Bitflag         = b [2];
            Direction       = b [3];
            DoorCapX        = b [4];
            DoorCapY        = b [5];
            ScreenX         = b [6];
            ScreenY         = b [7];
            DistanceToSpawn = Tools.ConcatBytes(b [8], b [9]);
            DoorAsmPtr      = Tools.ConcatBytes(b [10], b [11], 0x8F);
            startAddressPC  = addressPC;
            return(true);
        }
コード例 #10
0
ファイル: Enemy.cs プロジェクト: DJuttmann/SM3E
        // Read data from ROM at given PC address.
        public override bool ReadFromROM(Rom rom, int addressPC)
        {
            int sAddress = addressPC;

            byte [] b = new byte [BlockSize];
            rom.Seek(addressPC);
            if (!rom.Read(b, 2, 2))
            {
                return(false);
            }

            EnemyIDs.Clear();
            Palettes.Clear();
            while (b [2] != TerminatorByte || b [3] != TerminatorByte)
            {
                EnemyIDs.Add(Tools.ConcatBytes(b [2], b [3]));
                if (!rom.Read(b, 0, 4))
                {
                    return(false);
                }
                Palettes.Add(Tools.ConcatBytes(b [0], b [1]));
            }
            startAddressPC = addressPC;
            return(true);
        }
コード例 #11
0
ファイル: LevelData.cs プロジェクト: DJuttmann/SM3E
        // Read data from ROM at given PC address.
        public override bool ReadFromROM(Rom rom, int addressPC)
        {
            rom.Seek(addressPC);
            int compressedSize = rom.Decompress(out List <byte> buffer);

            CompressedData.Clear();
            rom.Seek(addressPC);
            rom.Read(CompressedData, compressedSize);
            CompressionUpToDate = true;
            int decompressedSize = buffer.Count;

            int Layer1Size = Tools.ConcatBytes(buffer [0], buffer [1]);
            int BtsSize    = Layer1Size / 2; // half the amount of data of layer one
            int Layer2Size;

            if (Layer1Size + BtsSize + 2 < decompressedSize)
            {
                Layer2Size = Layer1Size; // check if layer 2 data exists,
            }
            else
            {
                Layer2Size = 0;          // if not, set its size to zero.
            }
            ScreenCount = BtsSize / 256; // divide by 256 tiles per screen.

            int Layer1Counter = 2;
            int BtsCounter    = 2 + Layer1Size;
            int Layer2Counter = 2 + Layer1Size + BtsSize;

            for (int n = 0; n < BtsSize; n++)
            {
                Layer1.Add((ushort)Tools.ConcatBytes(buffer [Layer1Counter],
                                                     buffer [Layer1Counter + 1]));
                Bts.Add(buffer [BtsCounter]);
                if (Layer2Size > 0)
                {
                    Layer2.Add((ushort)Tools.ConcatBytes(buffer [Layer2Counter],
                                                         buffer [Layer2Counter + 1]));
                }
                Layer1Counter += 2;
                BtsCounter    += 1;
                Layer2Counter += 2;
            }

            startAddressPC = addressPC;
            return(decompressedSize > 0);
        }
コード例 #12
0
ファイル: Enemy.cs プロジェクト: DJuttmann/SM3E
        // Read data from ROM at given PC address.
        public override bool ReadFromROM(Rom rom, int addressPC)
        {
            int sAddress = addressPC;

            byte [] b = new byte [2];
            rom.Seek(addressPC);
            if (!rom.Read(b, 0, 2))
            {
                return(false);
            }

            Enemies.Clear();
            while (b [0] != TerminatorByte || b [1] != TerminatorByte)
            {
                Enemy newEnemy = new Enemy();
                if (!newEnemy.ReadFromROM(rom, addressPC))
                {
                    return(false);
                }
                addressPC += newEnemy.Size;
                Enemies.Add(newEnemy);
                rom.Seek(addressPC);
                if (!rom.Read(b, 0, 2))
                {
                    return(false);
                }
            }
            rom.Seek(addressPC + 2);
            if (!rom.Read(b, 0, 1))
            {
                return(false);
            }
            RequiredToKill = b [0];
            startAddressPC = sAddress;
            return(true);
        }
コード例 #13
0
        // Read data from ROM at given PC address.
        public override bool ReadFromROM(Rom rom, int addressPC)
        {
            byte [] data = new byte [DefaultSize];
            rom.Seek(addressPC);
            if (!rom.Read(data, 0, DefaultSize))
            {
                return(false);
            }
            SceTablePtr = Tools.ConcatBytes(data [0], data [1], data [2]);
            SceSheetPtr = Tools.ConcatBytes(data [3], data [4], data [5]);
            PalettePtr  = Tools.ConcatBytes(data [6], data [7], data [8]);

            startAddressPC = addressPC;
            return(true);
        }
コード例 #14
0
        // Read data from ROM at given PC address.
        public override bool ReadFromROM(Rom rom, int addressPC)
        {
            byte ScrollColour = 0x00;

            byte [] b = new byte [3];
            rom.Seek(addressPC);
            if (!rom.Read(b, 0, 3) ||
                b [0] != 0x08 || b [1] != 0xE2 || b [2] != 0x20)
            {
                return(false);
            }

            Entries.Clear();
            do
            {
                if (!rom.Read(b, 0, 2))
                {
                    return(false);
                }
                switch (b [0])
                {
                case 0xA9: // set scroll colour
                    ScrollColour = b [1];
                    break;

                case 0x8F: // set scroll
                    Entries.Add(Tools.ConcatBytes((byte)(b [1] - 0x20), ScrollColour));
                    if (!rom.Read(b, 0, 2) || (b [0] != 0xCD && b [1] != 0x7E))
                    {
                        return(false);
                    }
                    break;

                case 0x28:
                    if (b [1] != 0x60)
                    {
                        return(false);
                    }
                    break;

                default:
                    return(false);
                }
            } while (b [0] != 0x28);

            startAddressPC = addressPC;
            return(true);
        }
コード例 #15
0
ファイル: Global.cs プロジェクト: DJuttmann/SM3E
    // Read data from ROM at given PC address.
    public override bool ReadFromROM (Rom rom, int addressPC)
    {
      byte [] b = new byte [DefaultSize];
      rom.Seek (addressPC);
      if (!rom.Read (b, 0, DefaultSize))
        return false;

      // int TileCount = DefaultSize / 2;
      for (int n = 0; n < TileCount; n++) {
        int index = (n & 31) | ((n & 992) << 1) | ((n & 1024) >> 5);
        Tiles [index] = b [2 * n];
        Properties [index] = b [2 * n + 1];
      }
      startAddressPC = addressPC;
      return true;
    }
コード例 #16
0
ファイル: Room.cs プロジェクト: DJuttmann/SM3E
        // Read room state header from ROM at given PC address.
        public override bool ReadFromROM(Rom rom, int addressPC)
        {
            byte [] b = new byte [3];

            rom.Seek(addressPC);
            if (!rom.Read(b, 0, 2))
            {
                return(false);
            }

            HeaderType = (StateType)Tools.ConcatBytes(b [0], b [1]);
            switch (HeaderType)
            {
            case StateType.Standard:
                RoomStatePtr = Tools.PCtoLR(addressPC + 2);
                break;

            case StateType.Events:
            case StateType.Bosses:
                if (!rom.Read(b, 0, 3))
                {
                    return(false);
                }
                Value        = b [0];
                RoomStatePtr = Tools.ConcatBytes(b [1], b [2], 0x8F);
                break;

            case StateType.TourianBoss:
            case StateType.Morph:
            case StateType.MorphMissiles:
            case StateType.PowerBombs:
            case StateType.SpeedBooster:
                if (!rom.Read(b, 0, 2))
                {
                    return(false);
                }
                RoomStatePtr = Tools.ConcatBytes(b [0], b [1], 0x8F);
                break;

            default:
                Console.WriteLine("Error: unknown state type encountered: ${0}",
                                  Tools.IntToHex((int)HeaderType));
                return(false);
            }
            startAddressPC = addressPC;
            return(true);
        }
コード例 #17
0
ファイル: Door.cs プロジェクト: DJuttmann/SM3E
        // Read data from ROM at given PC address. (DoorCount must be set beforehand)
        public override bool ReadFromROM(Rom rom, int addressPC)
        {
            byte [] b = new byte [Size];
            rom.Seek(addressPC);
            if (!rom.Read(b, 0, Size))
            {
                return(false);
            }

            for (int n = 0; n < DoorCount; n++)
            {
                DoorPtrs [n] = Tools.ConcatBytes(b [2 * n], b [2 * n + 1], 0x83);
            }

            startAddressPC = addressPC;
            return(true);
        }
コード例 #18
0
ファイル: PLM.cs プロジェクト: DJuttmann/SM3E
        // Read data from ROM at given PC address.
        public override bool ReadFromROM(Rom rom, int addressPC)
        {
            byte [] b = new byte [DefaultSize];
            rom.Seek(addressPC);
            if (!rom.Read(b, 0, DefaultSize))
            {
                return(false);
            }

            PlmID        = Tools.ConcatBytes(b [0], b [1]);
            PosX         = b [2];
            PosY         = b [3];
            MainVariable = Tools.ConcatBytes(b [4], b [5], 0x8F);

            startAddressPC = addressPC;
            return(true);
        }
コード例 #19
0
        // Read raw data from ROM at given PC address.
        public override bool ReadFromROM(Rom rom, int addressPC)
        {
            rom.Seek(addressPC);
            byte [] newData = new byte [Bytes.Count];

            if (!rom.Read(newData, 0, Bytes.Count))
            {
                return(false);
            }
            for (int n = 0; n < Bytes.Count; n++)
            {
                Bytes [n] = newData [n];
            }

            startAddressPC = addressPC;
            return(true);
        }
コード例 #20
0
ファイル: Global.cs プロジェクト: DJuttmann/SM3E
    // Read data from ROM at given PC address.
    public override bool ReadFromROM (Rom rom, int addressPC)
    {
      byte [] b = new byte [DefaultSize];
      rom.Seek (addressPC);
      if (!rom.Read (b, 0, DefaultSize))
        return false;
      RoomPtr = Tools.ConcatBytes (b [ 0], b [ 1], 0x8F);
      DoorPtr = Tools.ConcatBytes (b [ 2], b [ 3], 0x83);
      DoorBts = Tools.ConcatBytes (b [ 4], b [ 5]);
      ScreenX = Tools.ConcatBytes (b [ 6], b [ 7]);
      ScreenY = Tools.ConcatBytes (b [ 8], b [ 9]);
      SamusX  = Tools.ConcatBytes (b [10], b [11]);
      SamusY  = Tools.ConcatBytes (b [12], b [13]);

      startAddressPC = addressPC;
      return true;
    }
コード例 #21
0
        // Read data from ROM at given PC address.
        public override bool ReadFromROM(Rom rom, int addressPC)
        {
            List <byte> buffer = new List <byte> ();

            rom.Seek(addressPC);
            rom.Read(buffer, Size);

            for (int n = 0; n < ColorCount; n++)
            {
                int colour = Tools.ConcatBytes(buffer [n << 1], buffer [n << 1 | 1]);
                R [n] = ((byte)((colour & 0x001F) << 3));
                G [n] = ((byte)((colour & 0x03E0) >> 2));
                B [n] = ((byte)((colour & 0x7C00) >> 7));
            }
            startAddressPC = addressPC;
            return(true);
        }
コード例 #22
0
        // Read data from ROM at given PC address.
        public override bool ReadFromROM(Rom rom, int addressPC)
        {
            //byte [] buffer;
            //int DecompressedSize = Compression.ReadCompressedData (out buffer, addressPC);
            rom.Seek(addressPC);
            rom.Decompress(out List <byte> buffer);
            int decompressedSize = buffer.Count;

            int tile8Count = decompressedSize >> 1;

            for (int n = 0; n < tile8Count; n++)
            {
                Tiles8.Add(Tools.ConcatBytes(buffer [2 * n], buffer [2 * n + 1]));
            }

            startAddressPC = addressPC;
            return(true);
        }
コード例 #23
0
ファイル: Enemy.cs プロジェクト: DJuttmann/SM3E
 // Read data from ROM at given PC address.
 public override bool ReadFromROM(Rom rom, int addressPC)
 {
     byte [] b = new byte [DefaultSize];
     rom.Seek(addressPC);
     if (!rom.Read(b, 0, DefaultSize))
     {
         return(false);
     }
     EnemyID        = Tools.ConcatBytes(b [0], b [1]);
     PosX           = Tools.ConcatBytes(b [2], b [3]);
     PosY           = Tools.ConcatBytes(b [4], b [5]);
     Tilemaps       = Tools.ConcatBytes(b [6], b [7]);
     Special        = Tools.ConcatBytes(b [8], b [9]);
     Graphics       = Tools.ConcatBytes(b [10], b [11]);
     Speed          = Tools.ConcatBytes(b [12], b [13]);
     Speed2         = Tools.ConcatBytes(b [14], b [15]);
     startAddressPC = addressPC;
     return(true);
 }
コード例 #24
0
        // Read data from ROM at given PC address.
        public override bool ReadFromROM(Rom rom, int addressPC)
        {
            byte [] b = new byte [2];
            rom.Seek(addressPC);
            if (!rom.Read(b, 0, 1))
            {
                return(false);
            }

            while (b [0] != 0x80 && Entries.Count < 100)
            {
                if (!rom.Read(b, 1, 1))
                {
                    return(false);
                }
                Entries.Add(Tools.ConcatBytes(b [0], b [1]));
                if (!rom.Read(b, 0, 1))
                {
                    return(false);
                }
            }
            startAddressPC = addressPC;
            return(true);
        }
コード例 #25
0
ファイル: Room.cs プロジェクト: DJuttmann/SM3E
        // Read data from ROM at given PC address.
        public override bool ReadFromROM(Rom rom, int addressPC)
        {
            int sAddressPC = addressPC;

            byte [] b = new byte [HeaderSize];
            rom.Seek(addressPC);
            if (!rom.Read(b, 0, HeaderSize))
            {
                return(false);
            }

            RoomIndex         = b [0];
            Area              = b [1];
            MapX              = b [2];
            MapY              = b [3];
            Width             = b [4];
            Height            = b [5];
            UpScroller        = b [6];
            DownScroller      = b [7];
            SpecialGfxBitflag = b [8];
            DoorsPtr          = Tools.ConcatBytes(b [9], b [10], 0x8F);

            // read room state headers
            addressPC += HeaderSize;
            int i = 0;

            RoomStateHeaders.Add(new RoomStateHeader());
            if (!RoomStateHeaders [i].ReadFromROM(rom, addressPC))
            {
                return(false);
            }
            addressPC += RoomStateHeaders [i].Size;
            while (RoomStateHeaders [i].HeaderType != StateType.Standard)
            {
                i++;
                RoomStateHeaders.Add(new RoomStateHeader());
                if (!RoomStateHeaders [i].ReadFromROM(rom, addressPC))
                {
                    return(false);
                }
                addressPC += RoomStateHeaders [i].Size;
            }

            // read room states
            int StateCount = RoomStateHeaders.Count;

            for (int j = 0; j < StateCount; j++)
            {
                RoomStates.Add(null);
            }
            for (int j = 0; j < StateCount; j++)
            {
                RoomStates [j] = new RoomState();
                addressPC      = Tools.LRtoPC(RoomStateHeaders [j].RoomStatePtr);
                if (!RoomStates [j].ReadFromROM(rom, addressPC))
                {
                    return(false);
                }
            }

            startAddressPC = sAddressPC;
            return(true);
        }
コード例 #26
0
ファイル: Background_Fx.cs プロジェクト: DJuttmann/SM3E
        // Read data from ROM at given PC address.
        public override bool ReadFromROM(Rom rom, int addressPC)
        {
            int TilesPtr = 0;

            byte [] b = new byte [11];
            rom.Seek(addressPC);
            if (!rom.Read(b, 0, 2))
            {
                return(false);
            }

            int blockSize;
            int totalSize = 0;

            while (b [0] != 0 || b [1] != 0)
            {
                int type = Tools.ConcatBytes(b [0], b [1]);
                // Bytes.Add (b [0]);
                // Bytes.Add (b [1]);
                switch (type)
                {
                default:
                    Console.WriteLine("Unknown BG block type found: {0}", Tools.IntToHex(type));
                    return(false);

                case 0x000A:
                case 0x000C:
                    blockSize = 2;
                    break;

                case 0x0004:
                    blockSize = 7;
                    break;

                case 0x0002:
                case 0x0008:
                    blockSize = 9;
                    break;

                case 0x000E:
                    blockSize = 11;
                    break;
                }
                if (!rom.Read(b, 2, blockSize - 2))
                {
                    return(false);
                }
                for (int i = 0; i < blockSize; i++)
                {
                    Bytes.Add(b [i]);
                }
                if (type == 0x0004)
                {
                    if (TilesPtr == 0)
                    {
                        TilesPtr = Tools.ConcatBytes(b [2], b [3], b [4]);
                    }
                    else
                    {
                        TilesPtr = 0; // [wip] still an ugly hack to skip Kraid background
                    }
                }
                totalSize += blockSize;
                if (!rom.Read(b, 0, 2))
                {
                    return(false);
                }
            }
            if (TilesPtr != 0)
            {
                MyBackgroundTiles = new BackgroundTiles();
                MyBackgroundTiles.ReadFromROM(rom, Tools.LRtoPC(TilesPtr));
            }
            startAddressPC = addressPC;
            return(true);
        }
コード例 #27
0
ファイル: LoadSave.cs プロジェクト: DJuttmann/SM3E
        // Write all data to the Rom.
        public void Save()
        {
            if (!ProjectLoaded)
            {
                return;
            }

            ReallocateAll();
            RepointAll();
            List <Data> objects = CurrentRom.AllData;

            objects.Sort((x, y) => x.StartAddressPC - y.StartAddressPC);

            Stream output  = new FileStream(ProjectPath + RomFileName, FileMode.Create);
            int    address = 0;

            for (int n = 0; n < objects.Count; n++)
            {
                if (address < objects [n].StartAddressPC)
                {
                    CurrentRom.Seek(address);
                    CurrentRom.WriteToFile(output, objects [n].StartAddressPC - address);
                    address = objects [n].StartAddressPC;
                }
                if (address == objects [n].StartAddressPC)
                {
                    int  oldAddress  = address;
                    long oldPosition = output.Position;
                    objects [n].WriteToROM(output, ref address);
                    if (address - oldAddress != output.Position - oldPosition)
                    {
                        Logging.WriteLine("Write error: incorrect # bytes written for " +
                                          objects [n].GetType().ToString() + " at " +
                                          Tools.IntToHex(objects [n].StartAddressPC) +
                                          " - should be " + (address - oldAddress) +
                                          " instead of " + (output.Position - oldPosition));
                    }
                    if (address != output.Position)
                    {
                        Logging.WriteLine("Desync: " + address + " ~ " + output.Position);
                    }
                }
                else
                {
                    Logging.WriteLine("Write error: Invalid address for " +
                                      objects [n].GetType().ToString() + " at " +
                                      Tools.IntToHex(objects [n].StartAddressPC) +
                                      " - output stream already at " + Tools.IntToHex(address));
                }
            }

            // Round address up to multiple of bank size and write remaining data up to there.
            int roundedSize = Math.Max(CurrentRom.Data.Length, (address + 0x7FFF) & ~0x7FFF);

            if (address < roundedSize)
            {
                CurrentRom.Seek(address);
                CurrentRom.WriteToFile(output, roundedSize - address);
            }
            output.Close();

            WriteProjectFileXml();
            ChangesMade = false;
            ProjectSaved?.Invoke(this, null);
        }
コード例 #28
0
        // Read data from ROM at given PC address.
        public override bool ReadFromROM(Rom rom, int addressPC)
        {
            //byte [] buffer;
            //int decompressedSize = 0;
            int  pixelCount = 0;
            byte bite;
            byte bit;

            //decompressedSize = Compression.ReadCompressedData (out b, addressPC);
            rom.Seek(addressPC);
            int compressedSize = rom.Decompress(out List <byte> buffer);

            CompressedData.Clear();
            rom.Seek(addressPC);
            rom.Read(CompressedData, compressedSize);
            CompressionUpToDate = true;
            int decompressedSize = buffer.Count;

            // if (decompressedSize > 100000)
            //   decompressedSize = 100000;  // Dunno how important these lines are (some safety mechanism?)

            pixelCount = decompressedSize << 1; // 2x decompressed size (1 pixel uses 4 bits)
            TileCount  = pixelCount >> 6;       // this resizes the Bytes list

            for (int t = 0; t < TileCount; t++)
            {
                for (int n = 0; n < 8; n++) // bitplane 0
                {
                    bite = buffer [t << 5 | n << 1];
                    for (int i = 0; i < 8; i++)
                    {
                        bit = (byte)(bite & 1);
                        Bytes [t << 6 | n << 3 | i] = bit;
                        bite >>= 1;
                    }
                }
                for (int n = 0; n < 8; n++) // bitplane 1
                {
                    bite = buffer [t << 5 | n << 1 | 1];
                    for (int i = 0; i < 8; i++)
                    {
                        bit = (byte)(bite & 1);
                        Bytes [t << 6 | n << 3 | i] = (byte)(Bytes [t << 6 | n << 3 | i] | bit << 1);
                        bite >>= 1;
                    }
                }
                for (int n = 0; n < 8; n++) // bitplane 2
                {
                    bite = buffer [t << 5 | n << 1 | 16];
                    for (int i = 0; i < 8; i++)
                    {
                        bit = (byte)(bite & 1);
                        Bytes [t << 6 | n << 3 | i] = (byte)(Bytes [t << 6 | n << 3 | i] | bit << 2);
                        bite >>= 1;
                    }
                }
                for (int n = 0; n < 8; n++) // bitplane 3
                {
                    bite = buffer [t << 5 | n << 1 | 17];
                    for (int i = 0; i < 8; i++)
                    {
                        bit = (byte)(bite & 1);
                        Bytes [t << 6 | n << 3 | i] = (byte)(Bytes [t << 6 | n << 3 | i] | bit << 3);
                        bite >>= 1;
                    }
                }
            }

            startAddressPC = addressPC;
            return(true);
        }