Exemple #1
0
        public Screen(Zilog.Z80 cpu, bool renderBorder, bool switchColors, int borderTop = 48, int borderBottom = 56, int borderSide = 64)
        {
            for (int a = 0; a < ScreenAttributes.Length; a++)
            {
                ScreenAttributes[a] = new ScreenAttribute();
            }


            SwitchColors(switchColors);
            RenderBorder = renderBorder;

            if (renderBorder)
            {
                this.bordertop    = borderTop;
                this.borderbottom = borderBottom;
                this.bordersides  = borderSide;
            }
            else
            {
                bordertop    = 0;
                borderbottom = 0;
                bordersides  = 0;
            }

            Height      = 192 + (bordertop + borderbottom);
            Width       = 256 + (bordersides * 2);
            screen      = new uint[Height * Width];
            screenflash = new uint[Height * Width];
            pixels      = new bool[Height * Width];
            this.cpu    = cpu;
        }
Exemple #2
0
        /*
         * public static bool CompareFunction(TestState ts, TestState z80)
         * {
         *  bool comparetrue = true;
         *  if ((ts.af & 0xD7) != (z80.af & 0xD7))
         *  {
         *      comparetrue = false;
         *      Debug.WriteLine("af");
         *      Assert.AreEqual((ts.af & 0xD7), (z80.af & 0xD7));
         *  }
         *  if (ts.af_ != z80.af_)
         *  {
         *      comparetrue = false;
         *      Assert.AreEqual(ts.af_, z80.af_);
         *  }
         *  if (ts.bc != z80.bc)
         *      comparetrue=false;
         *  if (ts.bc_ != z80.bc_)
         *      comparetrue=false;
         *  if (ts.de != z80.de)
         *      comparetrue=false;
         *  if (ts.de_ != z80.de_)
         *      comparetrue=false;
         *  if (ts.hl != z80.hl)
         *      comparetrue=false;
         *  if (ts.hl_ != z80.hl_)
         *      comparetrue=false;
         *  if (ts.i != z80.i)
         *      comparetrue=false;
         *  if (ts.iff1 != z80.iff1)
         *      comparetrue=false;
         *  if (ts.iff2 != z80.iff2)
         *      comparetrue=false;
         *  if (ts.im != z80.im)
         *      comparetrue=false;
         *  if (ts.ix != z80.ix)
         *      comparetrue=false;
         *  if (ts.iy != z80.iy)
         *      comparetrue=false;
         *
         *  if(ts.end_tstates2!=z80.end_tstates2)
         *  {
         *      comparetrue = false;
         *      //Debug.WriteLine("Tstates: "+ts.end_tstates2 + "-" + z80.end_tstates2);
         *  }
         *
         *  for (int a=0;a<ts.Memory.Length;a++)
         *  {
         *      if (ts.Memory[a] != z80.Memory[a])
         *      {
         *          comparetrue = false;
         *          break;
         *      }
         *  }
         *
         *  if (ts.pc != z80.pc)
         *  {
         *      comparetrue = false;
         *      Assert.AreEqual(ts.pc, z80.pc,"PC");
         *  }
         *
         *  if (ts.r != z80.r)
         *      comparetrue=false;
         *  if (ts.sp != z80.sp)
         *      comparetrue = false;
         *
         *  return comparetrue;
         * }
         */
        public static TestState ExtractState(Zilog.Z80 z80)
        {
            TestState ts = new TestState();

            ts.af   = z80.AF;
            ts.af_  = z80.AFPrim;
            ts.bc   = z80.BC;
            ts.bc_  = z80.BCPrim;
            ts.de   = z80.DE;
            ts.de_  = z80.DEPrim;
            ts.hl   = z80.HL;
            ts.hl_  = z80.HLPrim;
            ts.i    = z80.I;
            ts.iff1 = z80.IFF;
            ts.iff2 = z80.IFF2;
            ts.im   = z80.IM;
            ts.ix   = z80.IX;
            ts.iy   = z80.IY;
            for (int m = 0; m < ts.Memory.Length; m++)
            {
                ts.Memory[m] = z80.ReadByteFromMemory(m);
            }
            ts.pc           = z80.PC;
            ts.r            = z80.R;
            ts.sp           = z80.SP;
            ts.end_tstates2 = z80.EndTstates2;
            return(ts);
        }
Exemple #3
0
        public void LoadSnapshot(byte[] snapshotbytes, Zilog.Z80 cpu)
#endif
        {
            cpu.Reset();


            //cpu.I = snapshotbytes[0];
            //cpu.HLPrim = (ushort)(snapshotbytes[1] + 256 * snapshotbytes[2]);
            //cpu.DEPrim = (ushort)(snapshotbytes[3] + 256 * snapshotbytes[4]);
            //cpu.BCPrim = (ushort)(snapshotbytes[5] + 256 * snapshotbytes[6]);
            //cpu.AFPrim = (ushort)(snapshotbytes[7] + 256 * snapshotbytes[8]);

            //cpu.HL = (ushort)(snapshotbytes[9] + 256 * snapshotbytes[10]);
            //cpu.DE = (ushort)(snapshotbytes[11] + 256 * snapshotbytes[12]);
            //cpu.BC = (ushort)(snapshotbytes[13] + 256 * snapshotbytes[14]);
            //cpu.IY = (ushort)(snapshotbytes[15] + 256 * snapshotbytes[16]);
            //cpu.IX = (ushort)(snapshotbytes[17] + 256 * snapshotbytes[18]);
            //cpu.R = snapshotbytes[20];
            //cpu.AF = (ushort)(snapshotbytes[21] + 256 * snapshotbytes[22]);
            //cpu.SP = (ushort)(snapshotbytes[23] + 256 * snapshotbytes[24]);


            cpu.I      = snapshotbytes[0];
            cpu.HLPrim = snapshotbytes[1] | (snapshotbytes[2] << 8);
            cpu.DEPrim = snapshotbytes[3] | (snapshotbytes[4] << 8);
            cpu.BCPrim = snapshotbytes[5] | (snapshotbytes[6] << 8);
            cpu.AFPrim = snapshotbytes[7] | (snapshotbytes[8] << 8);
            cpu.HL     = snapshotbytes[9] | (snapshotbytes[10] << 8);
            cpu.DE     = snapshotbytes[11] | (snapshotbytes[12] << 8);
            cpu.BC     = snapshotbytes[13] | (snapshotbytes[14] << 8);
            cpu.IY     = snapshotbytes[15] | (snapshotbytes[16] << 8);
            cpu.IX     = snapshotbytes[17] | (snapshotbytes[18] << 8);
            cpu.IFF    = cpu.IFF2 = ((snapshotbytes[19] & 0x04) == 0x04);
            cpu.R      = snapshotbytes[20];
            cpu.AF     = snapshotbytes[21] | (snapshotbytes[22] << 8);
            cpu.SP     = snapshotbytes[23] | (snapshotbytes[24] << 8);
            cpu.IM     = (byte)(snapshotbytes[25] & 0x03);
            if (cpu.IM > 2)
            {
                cpu.IM = 2;
            }

            cpu.Out(254, snapshotbytes[26], 0); //Border Color
            //Memory
            MemoryHandler.LoadBytesintoMemory(snapshotbytes, 27, 0x4000, cpu);

            int pc = cpu.ReadWordFromMemory(cpu.SP);

            Debug.WriteLine("Load PC:" + pc);
            //cpu.SP++;
            //cpu.SP++;
            cpu.PC = pc;
            cpu.RET(true, 0, 0);
        }
Exemple #4
0
        public Screen(Zilog.Z80 cpu, bool renderBorder, bool switchColors, int borderTop = 48, int borderBottom = 56, int borderSide = 64)
        {
            SwitchColors(switchColors);
            RenderBorder = renderBorder;

            if (renderBorder)
            {
                this.bordertop    = borderTop;
                this.borderbottom = borderBottom;
                this.bordersides  = borderSide;
            }
            else
            {
                bordertop    = 0;
                borderbottom = 0;
                bordersides  = 0;
            }

            Height = 192 + (bordertop + borderbottom);
            Width  = 256 + (bordersides * 2);
            screen = new uint[Height * Width];

            this.cpu = cpu;
        }
Exemple #5
0
        public byte[] SaveSnapshot(Zilog.Z80 cpu)
        {
            byte[] snapshotData = new byte[49179];

            ushort tsp = (ushort)(cpu.SP - 2);

            snapshotData[0] = (byte)cpu.I;
            snapshotData[1] = (byte)(cpu.HLPrim & 0xFF);
            snapshotData[2] = (byte)(cpu.HLPrim >> 8);
            snapshotData[3] = (byte)(cpu.DEPrim & 0xFF);
            snapshotData[4] = (byte)(cpu.DEPrim >> 8);
            snapshotData[5] = (byte)(cpu.BCPrim & 0xFF);
            snapshotData[6] = (byte)(cpu.BCPrim >> 8);
            snapshotData[7] = (byte)(cpu.AFPrim & 0xFF);
            snapshotData[8] = (byte)(cpu.AFPrim >> 8);

            snapshotData[9]  = (byte)(cpu.HL & 0xFF);
            snapshotData[10] = (byte)(cpu.HL >> 8);
            snapshotData[11] = (byte)(cpu.DE & 0xFF);
            snapshotData[12] = (byte)(cpu.DE >> 8);
            snapshotData[13] = (byte)(cpu.BC & 0xFF);
            snapshotData[14] = (byte)(cpu.BC >> 8);

            snapshotData[15] = (byte)(cpu.IY & 0xFF);
            snapshotData[16] = (byte)(cpu.IY >> 8);
            snapshotData[17] = (byte)(cpu.IX & 0xFF);
            snapshotData[18] = (byte)(cpu.IX >> 8);

            snapshotData[20] = (byte)cpu.R;
            snapshotData[21] = (byte)(cpu.AF & 0xFF);
            snapshotData[22] = (byte)(cpu.AF >> 8);
            snapshotData[23] = (byte)(tsp & 0xFF);
            snapshotData[24] = (byte)(tsp >> 8);

            snapshotData[25] = (byte)(cpu.IM & 0x03);
            snapshotData[19] = (byte)(cpu.IFF2 ? 0x04 : 0x00);

            snapshotData[26] = (byte)cpu.In(254);

            var t1 = cpu.ReadByteFromMemory(tsp);

            cpu.WriteByteToMemory(tsp++, (byte)(cpu.PC & 0xFF));
            var t2 = cpu.ReadByteFromMemory(tsp);

            cpu.WriteByteToMemory(tsp++, (byte)(cpu.PC >> 8));
            tsp -= 2;

            var mempos = 27;

            for (int a = 0x4001; a < 64 * 1024; a++)
            {
                snapshotData[mempos++] = (byte)cpu.ReadByteFromMemory(a);
            }
            //foreach (byte b in cpu.Memory.Skip(0x4000))
            //{
            //    snapshotData[mempos++] = b;
            //}

            int pc = cpu.ReadWordFromMemory(cpu.SP);

            //Debug.WriteLine("save PC:" + pc);

            return(snapshotData);
        }
 public byte[] SaveSnapshot(Zilog.Z80 cpu)
 {
     throw new NotImplementedException();
 }
        public void LoadSnapshot(byte[] snapshotbytes, Zilog.Z80 cpu)
        {
#endif
            List <MemoryBlock> MemoryBlocks = new List <MemoryBlock>();
            int snappshotposition           = 0;
            //Read header bytes
            cpu.A  = snapshotbytes[0];
            cpu.F  = snapshotbytes[1];
            cpu.C  = snapshotbytes[2];
            cpu.B  = snapshotbytes[3];
            cpu.L  = snapshotbytes[4];
            cpu.H  = snapshotbytes[5];
            cpu.PC = (snapshotbytes[7] << 8) | snapshotbytes[6];
            cpu.SP = (snapshotbytes[9] << 8) | snapshotbytes[8];
            cpu.I  = snapshotbytes[10];
            cpu.R  = snapshotbytes[11];

            int bytetwelve = snapshotbytes[12];
            if (bytetwelve == 255)
            {
                bytetwelve = 1;
            }

            //Set border color
            //cpu.Out(254, ((bytetwelve >> 1) & 0x07), 0);

            //Set it 7 on refresh register
            if ((bytetwelve & 0x01) != 0)
            {
                cpu.R7 = 0x80;
            }

            //Is snapshot comressed
            bool isCompressed = ((bytetwelve & 0x20) != 0);

            cpu.E = snapshotbytes[13];
            cpu.D = snapshotbytes[14];

            //Load Prim registers
            cpu.CPrim = snapshotbytes[15];
            cpu.BPrim = snapshotbytes[16];
            cpu.EPrim = snapshotbytes[17];
            cpu.DPrim = snapshotbytes[18];
            cpu.LPrim = snapshotbytes[19];
            cpu.HPrim = snapshotbytes[20];

            cpu.APrim = snapshotbytes[21];
            cpu.FPrim = snapshotbytes[22];

            cpu.IY = snapshotbytes[23] | (snapshotbytes[24] << 8);
            cpu.IX = snapshotbytes[25] | (snapshotbytes[26] << 8);

            cpu.IFF  = (snapshotbytes[27] != 0);
            cpu.IFF2 = (snapshotbytes[28] != 0);

            switch (snapshotbytes[29] & 0x03)
            {
            case 0:
                cpu.IM = 0;
                break;

            case 1:
                cpu.IM = 1;
                break;

            default:
                cpu.IM = 2;
                break;
            }

            /*
             * 29      1       Bit 0-1: Interrupt mode (0, 1 or 2)
             *                      Bit 2  : 1=Issue 2 emulation
             *                      Bit 3  : 1=Double interrupt frequency
             *                      Bit 4-5: 1=High video synchronisation
             *                               3=Low video synchronisation
             *                               0,2=Normal
             *                      Bit 6-7: 0=Cursor/Protek/AGF joystick
             *                               1=Kempston joystick
             *                               2=Sinclair 2 Left joystick (or user
             *                                 defined, for version 3 .z80 files)
             *                               3=Sinclair 2 Right joystick
             *  No need to read an support all of these.
             */

            snappshotposition = 30;
            if (cpu.PC == 0)
            {/*
              * Extended format
              * Most bytes in the extended section will be discarded since there are no support for them
              */
                int numberofheaderbytes = snapshotbytes[snappshotposition++] | (snapshotbytes[snappshotposition++] << 8);
                cpu.PC = (snapshotbytes[32]) | (snapshotbytes[33] << 8);

                //The rest of the header information is not relevant for this emulator
                snappshotposition += numberofheaderbytes;

                while (snappshotposition < snapshotbytes.Length)
                { //Load memory blocks
                    MemoryBlock mb                = new MemoryBlock();
                    int         datalength        = (snapshotbytes[snappshotposition++]) | (snapshotbytes[snappshotposition++] << 8);
                    int         MemoryBlockNumber = snapshotbytes[snappshotposition++];
                    if (datalength == 0xffff)
                    {   //Not compressed
                        datalength   = 16384;
                        isCompressed = false;
                    }
                    else
                    {
                        isCompressed = true;
                    }
                    mb = GetMemoryBlock(snapshotbytes, snappshotposition, datalength, isCompressed, MemoryBlockNumber);
                    snappshotposition += datalength;
                    MemoryBlocks.Add(mb);
                }
            }
            else //After the first 30 bytes a memory dump och the 48k Spectrum follows.
            {
                MemoryBlock mb = GetMemoryBlock(snapshotbytes, 30, snapshotbytes.Length - 30, isCompressed, -1);
                //Memoryblock = -1 since this is no "real" block
                MemoryBlocks.Add(mb);
            }

            Debug.WriteLineIf(MemoryBlocks.Count <= 3, "48K Z80");
            Debug.WriteLineIf(MemoryBlocks.Count > 3, "128K Z80");
            Debug.WriteLineIf((snapshotbytes[29] >> 0x06) == 0, "Cursor");
            Debug.WriteLineIf((snapshotbytes[29] >> 0x06) == 1, "Kempston");
            Debug.WriteLineIf((snapshotbytes[29] >> 0x06) == 2, "Sinclair 2 Left joystick");
            Debug.WriteLineIf((snapshotbytes[29] >> 0x06) == 3, "Sinclair 2 Right joystick");


            //Load Memoryblocks into memory
            foreach (MemoryBlock mb in MemoryBlocks)
            {
                switch (mb.MemoryBlockNumber)
                {
                case -1:        //All Ram
                    MemoryHandler.LoadBytesintoMemory(mb.MemoryData.ToArray(), 16384, cpu);
                    break;

                case 0:         //Rom
                    MemoryHandler.LoadBytesintoMemory(mb.MemoryData.ToArray(), 0, cpu);
                    break;

                case 1:         //Interface 1
                case 2:         //Not used for 48
                case 3:         //Not used for 48
                case 6:         //Not used for 48
                case 7:         //Not used for 48
                case 9:         //Not used for 48
                case 10:        //Not used for 48
                case 11:        //Multiface rom
                    //Currently no support, using a file with these blocks might result in errors
                    break;

                case 4:         //Normal 8000-bfff
                    MemoryHandler.LoadBytesintoMemory(mb.MemoryData.ToArray(), 0x8000, cpu);
                    break;

                case 5:         //Normal c000-ffff
                    MemoryHandler.LoadBytesintoMemory(mb.MemoryData.ToArray(), 0xc000, cpu);
                    break;
                    break;

                //case 3:
                case 8:         //Normal 4000-7ffff
                    //Loaded from 3
                    MemoryHandler.LoadBytesintoMemory(mb.MemoryData.ToArray(), 0x4000, cpu);
                    break;
                }
            }
        }
Exemple #8
0
 public static void LoadBytesintoMemory(Byte[] bytes, int MemoryStartIndex, Zilog.Z80 cpu)
 {
     //foreach (byte b in bytes)
     //    cpu.Memory[MemoryStartIndex++] = b;
     LoadBytesintoMemory(bytes, 0, MemoryStartIndex, cpu);
 }
Exemple #9
0
 public static void LoadBytesintoMemory(Byte[] bytes, int ByteArrayStartIndex, int MemoryStartIndex, Zilog.Z80 cpu)
 {
     for (int a = ByteArrayStartIndex; a < bytes.Length && MemoryStartIndex < bytes.Length; a++)
     {
         cpu.WriteByteToMemory(MemoryStartIndex++, bytes[a]);
     }
 }
 public static void LoadBytesintoMemory(Byte[] bytes, int ByteArrayStartIndex, int MemoryStartIndex, Zilog.Z80 cpu)
 {
     for (int a = ByteArrayStartIndex; a < bytes.Length && MemoryStartIndex < cpu.Memory.Length; a++)
     {
         cpu.Memory[MemoryStartIndex++] = bytes[a];
     }
 }