Пример #1
0
        public void ImageFileDisposeFlushes()
        {
            string filename = System.IO.Path.GetTempFileName();

            DiskImage disk = new DiskImage();

            Assert.AreEqual(true, disk.CreateImage(filename));
            disk.Format("Name", "1");
            IImageFile file = disk.Open("TEST", C64FileType.PRG, "wb");

            Assert.IsNotNull(file);

            byte[] data = Encoding.ASCII.GetBytes("This is some sample data!");
            Assert.AreEqual(data.Length, file.Write(data, data.Length));
            file.Dispose();
            disk.Dispose();

            DiskImage disk1 = new DiskImage();

            Assert.AreEqual(true, disk1.LoadImage(filename));
            IImageFile file1 = disk1.Open("TEST", C64FileType.PRG, "rb");

            Assert.IsNotNull(file1);
            byte[] data1 = new byte[100];
            Assert.AreEqual(25, file1.Read(data1, 100));
            byte[] trucatedData = new byte[25];
            Array.Copy(data1, trucatedData, 25);
            Assert.AreEqual("This is some sample data!", Encoding.ASCII.GetString(trucatedData));
            file1.Close();
            disk1.Dispose();

            System.IO.File.Delete(filename);
        }
Пример #2
0
        public void CreateWriteLoadReadMultiTrackFile()
        {
            string filename = System.IO.Path.GetTempFileName();

            DiskImage disk = new DiskImage();

            Assert.AreEqual(true, disk.CreateImage(filename));
            disk.Format("Name", "1");
            IImageFile file = disk.Open("TEST", C64FileType.PRG, "wb");

            Assert.IsNotNull(file);

            byte[] data = new byte[2000];
            for (int i = 0; i < 2000; ++i)
            {
                data[i] = (byte)(i % 256);
            }
            Assert.AreEqual(data.Length, file.Write(data, data.Length));
            file.Close();
            disk.Dispose();

            DiskImage disk1 = new DiskImage();

            Assert.AreEqual(true, disk1.LoadImage(filename));
            IImageFile file1 = disk1.Open("TEST", C64FileType.PRG, "rb");

            Assert.IsNotNull(file1);
            byte[] data1 = new byte[3000];
            Assert.AreEqual(2000, file1.Read(data1, 3000));
            byte[] trucatedData = new byte[2000];
            Array.Copy(data1, trucatedData, 2000);
            for (int i = 0; i < 2000; ++i)
            {
                Assert.AreEqual(i % 256, trucatedData[i]);
            }
            file1.Close();
            disk1.Dispose();

            System.IO.File.Delete(filename);
        }
Пример #3
0
        public void Load(IDiskImage di, int rosterNumber)
        {
            byte[] buffer = new byte[200000]; // they seem to be 460 bytes, but screw it better safe than sorry.

            IImageFile image = di.Open("P" + rosterNumber, C64FileType.PRG, "rb");

            if (image == null)
            {
                throw new System.IO.FileLoadException("Cannot open save file 'P" + RosterId + ".PRG' for read.");
            }
            int len = image.Read(buffer, buffer.Length);

            RawData = new byte[len];
            Buffer.BlockCopy(buffer, 0, RawData, 0, len);
            image.Close();


            RosterId   = rosterNumber;
            m_name     = ProcessName();
            Sex        = (U1Sex)RawData[SexOffset];
            Class      = (U1Class)RawData[ClassOffset];
            Race       = (U1Race)RawData[RaceOffset];
            HitPoints  = RawData[HitPointsOffset] | (RawData[HitPointsOffset + 1] << 8);
            Experience = RawData[ExperienceOffset] | (RawData[ExperienceOffset + 1] << 8);

            Strength     = RawData[StrengthOffset];
            Agility      = RawData[AgilityOffset];
            Stamina      = RawData[StaminaOffset];
            Charisma     = RawData[CharismaOffset];
            Wisdom       = RawData[WisdomOffset];
            Intelligence = RawData[IntelligenceOffset];

            for (int i = 0; i < 10; ++i)
            {
                Spells[i] = RawData[SpellsOffset + i];
            }

            for (int i = 0; i < 5; ++i)
            {
                Armor[i] = RawData[ArmorOffset + i];
            }

            for (int i = 0; i < 15; ++i)
            {
                Weapons[i] = RawData[WeaponsOffset + i];
            }

            Food  = RawData[FoodOffset] | (RawData[FoodOffset + 1] << 8);
            Coins = RawData[CoinsOffset] | (RawData[CoinsOffset + 1] << 8);

            for (int i = 0; i < 4; ++i)
            {
                Gems[i] = RawData[GemsOffset + i];
            }

            for (int i = 0; i < 6; ++i)
            {
                m_transportation[i] = RawData[TransportationOffset + i];
            }
            m_transportation[6] = RawData[TimeMachineOffset];

            EnemyShips = RawData[EnemyShipsOffset];

            Location.X = RawData[LocationOffset];
            Location.Y = RawData[LocationOffset + 1];
        }