コード例 #1
0
        public static void SaveSNA(string filename, SNA_SNAPSHOT sna)
        {
            using (System.IO.FileStream fs = new System.IO.FileStream(filename, System.IO.FileMode.Create)) {
                byte[] bytes = ByteUtililty.RawSerialize(sna.HEADER);
                fs.Write(bytes, 0, bytes.Length);

                if (sna is SNA_48K)
                {
                    fs.Write(((SNA_48K)sna).RAM, 0, ((SNA_48K)sna).RAM.Length);
                }
                else
                {
                    //Write speccy banks 5, 2 and n which are pre-prepared in snapshot ram 0 to 5
                    for (int f = 0; f < 6; f++)
                    {
                        fs.Write(((SNA_128K)sna).RAM_BANK[f], 0, 8192);
                    }

                    bytes = ByteUtililty.RawSerialize(((SNA_128K)sna).PC);
                    fs.Write(bytes, 0, bytes.Length);
                    fs.WriteByte(((SNA_128K)sna).PORT_7FFD);
                    fs.WriteByte(((SNA_128K)sna).TR_DOS);

                    //Write remaining banks
                    for (int f = 6; f < 16; f++)
                    {
                        fs.Write(((SNA_128K)sna).RAM_BANK[f], 0, 8192);
                    }
                }
            }
        }
コード例 #2
0
ファイル: SZXFile.cs プロジェクト: Specchum/Zero-Emulator
        public byte[] GetSZXData()
        {
            byte[] szxData = null;
            using (MemoryStream ms = new MemoryStream(1000)) {
                using (BinaryWriter r = new BinaryWriter(ms)) {
                    byte[]     buf;
                    ZXST_Block block = new ZXST_Block();

                    buf = ByteUtililty.RawSerialize(header); //header is filled in by the callee machine
                    r.Write(buf);

                    block.Id   = GetUIntFromString("CRTR");
                    block.Size = (uint)Marshal.SizeOf(creator);
                    buf        = ByteUtililty.RawSerialize(block);
                    r.Write(buf);
                    buf = ByteUtililty.RawSerialize(creator);
                    r.Write(buf);

                    block.Id   = GetUIntFromString("Z80R");
                    block.Size = (uint)Marshal.SizeOf(z80Regs);
                    buf        = ByteUtililty.RawSerialize(block);
                    r.Write(buf);
                    buf = ByteUtililty.RawSerialize(z80Regs);
                    r.Write(buf);

                    block.Id   = GetUIntFromString("SPCR");
                    block.Size = (uint)Marshal.SizeOf(specRegs);
                    buf        = ByteUtililty.RawSerialize(block);
                    r.Write(buf);
                    buf = ByteUtililty.RawSerialize(specRegs);
                    r.Write(buf);

                    block.Id   = GetUIntFromString("KEYB");
                    block.Size = (uint)Marshal.SizeOf(keyboard);
                    buf        = ByteUtililty.RawSerialize(block);
                    r.Write(buf);
                    buf = ByteUtililty.RawSerialize(keyboard);
                    r.Write(buf);

                    if (paletteLoaded)
                    {
                        block.Id   = GetUIntFromString("PLTT");
                        block.Size = (uint)Marshal.SizeOf(palette);
                        buf        = ByteUtililty.RawSerialize(block);
                        r.Write(buf);
                        buf = ByteUtililty.RawSerialize(palette);
                        r.Write(buf);
                    }
                    if (header.MachineId > (byte)ZXTYPE.ZXSTMID_48K)
                    {
                        block.Id   = GetUIntFromString("AY\0\0");
                        block.Size = (uint)Marshal.SizeOf(ayState);
                        buf        = ByteUtililty.RawSerialize(block);
                        r.Write(buf);
                        buf = ByteUtililty.RawSerialize(ayState);
                        r.Write(buf);
                        byte[] ram = new byte[16384];
                        for (int f = 0; f < 8; f++)
                        {
                            ZXST_RAMPage ramPage = new ZXST_RAMPage();
                            ramPage.chPageNo = (byte)f;
                            ramPage.wFlags   = 0; //not compressed
                            block.Id         = GetUIntFromString("RAMP");
                            block.Size       = (uint)(Marshal.SizeOf(ramPage) + 16384);
                            buf = ByteUtililty.RawSerialize(block);
                            r.Write(buf);
                            buf = ByteUtililty.RawSerialize(ramPage);
                            r.Write(buf);
                            for (int g = 0; g < 8192; g++)
                            {
                                ram[g]        = (byte)(RAM_BANK[f * 2][g] & 0xff);
                                ram[g + 8192] = (byte)(RAM_BANK[f * 2 + 1][g] & 0xff);
                            }
                            r.Write(ram);
                        }
                    }
                    else   //48k
                    {
                        byte[] ram = new byte[16384];
                        //page 0
                        ZXST_RAMPage ramPage = new ZXST_RAMPage();
                        ramPage.chPageNo = 0;
                        ramPage.wFlags   = 0; //not compressed
                        block.Id         = GetUIntFromString("RAMP");
                        block.Size       = (uint)(Marshal.SizeOf(ramPage) + 16384);
                        buf = ByteUtililty.RawSerialize(block);
                        r.Write(buf);
                        buf = ByteUtililty.RawSerialize(ramPage);
                        r.Write(buf);
                        for (int g = 0; g < 8192; g++)
                        {
                            //me am angry.. poda thendi... saree vangi tharamattaaai?? poda! nonsense! style moonji..madiyan changu..malayalam ariyatha
                            //Lol! That's my wife cursing me for spending my time on this crap instead of her. Such a sweetie pie!
                            ram[g]        = (byte)(RAM_BANK[0][g] & 0xff);
                            ram[g + 8192] = (byte)(RAM_BANK[1][g] & 0xff);
                        }
                        r.Write(ram);

                        //page 2
                        ramPage.chPageNo = 2;
                        ramPage.wFlags   = 0; //not compressed
                        //ramPage.chData = new byte[16384];
                        // Array.Copy(RAM_BANK[2 * 2], 0, ramPage.chData, 0, 8192);
                        //Array.Copy(RAM_BANK[2 * 2 + 1], 0, ramPage.chData, 8192, 8192);
                        block.Id   = GetUIntFromString("RAMP");
                        block.Size = (uint)(Marshal.SizeOf(ramPage) + 16384);
                        buf        = ByteUtililty.RawSerialize(block);
                        r.Write(buf);
                        buf = ByteUtililty.RawSerialize(ramPage);
                        r.Write(buf);
                        for (int g = 0; g < 8192; g++)
                        {
                            ram[g]        = (byte)(RAM_BANK[ramPage.chPageNo * 2][g] & 0xff);
                            ram[g + 8192] = (byte)(RAM_BANK[ramPage.chPageNo * 2 + 1][g] & 0xff);
                        }
                        r.Write(ram);

                        //page 5
                        ramPage.chPageNo = 5;
                        ramPage.wFlags   = 0; //not compressed
                        block.Id         = GetUIntFromString("RAMP");
                        block.Size       = (uint)(Marshal.SizeOf(ramPage) + 16384);
                        buf = ByteUtililty.RawSerialize(block);
                        r.Write(buf);
                        buf = ByteUtililty.RawSerialize(ramPage);
                        r.Write(buf);
                        for (int g = 0; g < 8192; g++)
                        {
                            ram[g]        = (byte)(RAM_BANK[ramPage.chPageNo * 2][g] & 0xff);
                            ram[g + 8192] = (byte)(RAM_BANK[ramPage.chPageNo * 2 + 1][g] & 0xff);
                        }
                        r.Write(ram);
                    }
                    if (InsertTape)
                    {
                        tape     = new ZXST_Tape();
                        block.Id = GetUIntFromString("TAPE");

                        char[] ext = System.IO.Path.GetExtension(externalTapeFile).ToLower().ToCharArray();
                        tape.fileExtension = new char[16];
                        for (int f = 1; f < ext.Length; f++)
                        {
                            tape.fileExtension[f - 1] = ext[f];
                        }

                        externalTapeFile      = externalTapeFile + char.MinValue; //add a null terminator
                        tape.flags            = 0;
                        tape.currentBlockNo   = 0;
                        tape.compressedSize   = externalTapeFile.Length;
                        tape.uncompressedSize = externalTapeFile.Length;
                        block.Size            = (uint)Marshal.SizeOf(tape) + (uint)tape.uncompressedSize;
                        buf = ByteUtililty.RawSerialize(block);
                        r.Write(buf);
                        buf = ByteUtililty.RawSerialize(tape);
                        r.Write(buf);

                        char[] tapeName = externalTapeFile.ToCharArray();

                        r.Write(tapeName);
                    }
                }

                szxData = ms.ToArray();
            }
            return(szxData);
        }