コード例 #1
0
ファイル: ZX48.Port.cs プロジェクト: retr0s4ge/BizHawk
        /// <summary>
        /// Writes a byte of data to a specified port address
        /// </summary>
        /// <param name="port"></param>
        /// <param name="value"></param>
        public override void WritePort(ushort port, byte value)
        {
            // Check whether the low bit is reset
            // Technically the ULA should respond to every even I/O address
            if ((port & 0x0001) != 0)
            {
                return;
            }

            // store the last OUT byte
            LastULAOutByte = value;

            /*
             *  Bit   7   6   5   4   3   2   1   0
             +-------------------------------+
             |   |   |   | E | M |   Border  |
             +-------------------------------+
             */

            // Border - LSB 3 bits hold the border colour
            if (ULADevice.BorderColor != (value & BORDER_BIT))
            {
                //ULADevice.RenderScreen((int)CurrentFrameCycle);
                ULADevice.BorderColor = value & BORDER_BIT;
            }

            // Buzzer
            BuzzerDevice.ProcessPulseValue((value & EAR_BIT) != 0);

            // Tape
            TapeDevice.WritePort(port, value);

            // Tape mic processing (not implemented yet)
            //TapeDevice.ProcessMicBit((value & MIC_BIT) != 0);
        }
コード例 #2
0
        public void SyncState(Serializer ser)
        {
            ser.BeginSection("ZXMachine");
            ser.Sync("FrameCompleted", ref FrameCompleted);
            ser.Sync("OverFlow", ref OverFlow);
            ser.Sync("FrameCount", ref FrameCount);
            ser.Sync("_frameCycles", ref _frameCycles);
            ser.Sync("inputRead", ref inputRead);
            ser.Sync("LastFrameStartCPUTick", ref LastFrameStartCPUTick);
            ser.Sync("LastULAOutByte", ref LastULAOutByte);
            ser.Sync("ROM0", ref ROM0, false);
            ser.Sync("ROM1", ref ROM1, false);
            ser.Sync("ROM2", ref ROM2, false);
            ser.Sync("ROM3", ref ROM3, false);
            ser.Sync("RAM0", ref RAM0, false);
            ser.Sync("RAM1", ref RAM1, false);
            ser.Sync("RAM2", ref RAM2, false);
            ser.Sync("RAM3", ref RAM3, false);
            ser.Sync("RAM4", ref RAM4, false);
            ser.Sync("RAM5", ref RAM5, false);
            ser.Sync("RAM6", ref RAM6, false);
            ser.Sync("RAM7", ref RAM7, false);
            ser.Sync("ROMPaged", ref ROMPaged);
            ser.Sync("SHADOWPaged", ref SHADOWPaged);
            ser.Sync("RAMPaged", ref RAMPaged);
            ser.Sync("PagingDisabled", ref PagingDisabled);
            ser.Sync("SpecialPagingMode", ref SpecialPagingMode);
            ser.Sync("PagingConfiguration", ref PagingConfiguration);
            ser.Sync("ROMhigh", ref ROMhigh);
            ser.Sync("ROMlow", ref ROMlow);

            KeyboardDevice.SyncState(ser);
            BuzzerDevice.SyncState(ser);
            TapeBuzzer.SyncState(ser);
            ULADevice.SyncState(ser);

            if (AYDevice != null)
            {
                AYDevice.SyncState(ser);
                ((AYChip)AYDevice as AYChip).PanningConfiguration = Spectrum.Settings.AYPanConfig;
            }

            if (UPDDiskDevice != null)
            {
                UPDDiskDevice.SyncState(ser);
            }

            ser.Sync("tapeMediaIndex", ref tapeMediaIndex);
            TapeMediaIndex = tapeMediaIndex;

            ser.Sync("diskMediaIndex", ref diskMediaIndex);
            DiskMediaIndex = diskMediaIndex;

            TapeDevice.SyncState(ser);

            ser.EndSection();
        }
コード例 #3
0
ファイル: ZX48.Port.cs プロジェクト: mfloresn90/BizHawk
        /// <summary>
        /// Writes a byte of data to a specified port address
        /// </summary>
        /// <param name="port"></param>
        /// <param name="value"></param>
        public override void WritePort(ushort port, byte value)
        {
            // process IO contention
            ContendPortAddress(port);

            // Check whether the low bit is reset
            // Technically the ULA should respond to every even I/O address
            if ((port & 0x0001) != 0)
            {
                return;
            }

            // store the last OUT byte
            LastULAOutByte = value;

            /*
             *  Bit   7   6   5   4   3   2   1   0
             +-------------------------------+
             |   |   |   | E | M |   Border  |
             +-------------------------------+
             */

            // Border - LSB 3 bits hold the border colour
            if (ULADevice.borderColour != (value & BORDER_BIT))
            {
                // border value has changed - update the screen buffer
                ULADevice.UpdateScreenBuffer(CurrentFrameCycle);
            }

            ULADevice.borderColour = value & BORDER_BIT;

            // Buzzer
            BuzzerDevice.ProcessPulseValue((value & EAR_BIT) != 0);

            // Tape
            TapeDevice.WritePort(port, value);

            // Tape mic processing (not implemented yet)
            //TapeDevice.ProcessMicBit((value & MIC_BIT) != 0);
        }
コード例 #4
0
ファイル: ZX128Plus3.Port.cs プロジェクト: mfloresn90/BizHawk
        /// <summary>
        /// Writes a byte of data to a specified port address
        /// </summary>
        /// <param name="port"></param>
        /// <param name="value"></param>
        public override void WritePort(ushort port, byte value)
        {
            // process IO contention
            ContendPortAddress(port);

            // get a BitArray of the port
            BitArray portBits = new BitArray(BitConverter.GetBytes(port));
            // get a BitArray of the value byte
            BitArray bits = new BitArray(new byte[] { value });

            // Check whether the low bit is reset
            bool lowBitReset = !portBits[0]; // (port & 0x01) == 0;

            AYDevice.WritePort(port, value);

            UPDDiskDevice.WritePort(port, value);

            // port 0x7ffd - hardware should only respond when bits 1 & 15 are reset and bit 14 is set
            if (port == 0x7ffd)
            {
                if (!PagingDisabled)
                {
                    // bits 0, 1, 2 select the RAM page
                    var rp = value & 0x07;
                    if (rp < 8)
                    {
                        RAMPaged = rp;
                    }

                    // bit 3 controls shadow screen
                    SHADOWPaged = bits[3];

                    // Bit 5 set signifies that paging is disabled until next reboot
                    PagingDisabled = bits[5];

                    // portbit 4 is the LOW BIT of the ROM selection
                    ROMlow = bits[4];
                }
            }
            // port 0x1ffd - hardware should only respond when bits 1, 13, 14 & 15 are reset and bit 12 is set
            if (port == 0x1ffd)
            {
                if (!PagingDisabled)
                {
                    if (!bits[0])
                    {
                        // special paging is not enabled - get the ROMpage high byte
                        ROMhigh = bits[2];

                        // set the special paging mode flag
                        SpecialPagingMode = false;
                    }
                    else
                    {
                        // special paging is enabled
                        // this is decided based on combinations of bits 1 & 2
                        // Config 0 = Bit1-0 Bit2-0
                        // Config 1 = Bit1-1 Bit2-0
                        // Config 2 = Bit1-0 Bit2-1
                        // Config 3 = Bit1-1 Bit2-1
                        BitArray confHalfNibble = new BitArray(2);
                        confHalfNibble[0] = bits[1];
                        confHalfNibble[1] = bits[2];

                        // set special paging configuration
                        PagingConfiguration = ZXSpectrum.GetIntFromBitArray(confHalfNibble);

                        // set the special paging mode flag
                        SpecialPagingMode = true;
                    }
                }

                // bit 4 is the printer port strobe
                PrinterPortStrobe = bits[4];
            }

            // Only even addresses address the ULA
            if (lowBitReset)
            {
                // store the last OUT byte
                LastULAOutByte = value;

                /*
                 *  Bit   7   6   5   4   3   2   1   0
                 +-------------------------------+
                 |   |   |   | E | M |   Border  |
                 +-------------------------------+
                 */

                // Border - LSB 3 bits hold the border colour
                if (ULADevice.borderColour != (value & BORDER_BIT))
                {
                    ULADevice.UpdateScreenBuffer(CurrentFrameCycle);
                }

                ULADevice.borderColour = value & BORDER_BIT;

                // Buzzer
                BuzzerDevice.ProcessPulseValue((value & EAR_BIT) != 0);

                // Tape
                TapeDevice.WritePort(port, value);

                // Tape
                //TapeDevice.ProcessMicBit((value & MIC_BIT) != 0);
            }


            LastULAOutByte = value;
        }
コード例 #5
0
        /// <summary>
        /// Executes a single frame
        /// </summary>
        public virtual void ExecuteFrame(bool render, bool renderSound)
        {
            InputRead    = false;
            _render      = render;
            _renderSound = renderSound;

            FrameCompleted = false;

            TapeDevice.StartFrame();

            if (_renderSound)
            {
                BuzzerDevice.StartFrame();
                TapeBuzzer.StartFrame();
                if (AYDevice != null)
                {
                    AYDevice.StartFrame();
                }
            }

            PollInput();

            while (CurrentFrameCycle < ULADevice.FrameLength)
            {
                // check for interrupt
                ULADevice.CheckForInterrupt(CurrentFrameCycle);

                // run a single CPU instruction
                CPU.ExecuteOne();

                // cycle the tape device
                TapeDevice.TapeCycle();
            }

            // we have reached the end of a frame
            LastFrameStartCPUTick = CPU.TotalExecutedCycles - OverFlow;

            // paint the buffer if needed
            if (ULADevice.needsPaint && _render)
            {
                ULADevice.UpdateScreenBuffer(ULADevice.FrameLength);
            }

            if (_renderSound)
            {
                BuzzerDevice.EndFrame();
                TapeBuzzer.EndFrame();
            }

            if (AYDevice != null)
            {
                AYDevice.EndFrame();
            }

            FrameCount++;

            // setup for next frame
            ULADevice.ResetInterrupt();

            TapeDevice.EndFrame();

            FrameCompleted = true;

            // is this a lag frame?
            Spectrum.IsLagFrame = !InputRead;
        }
コード例 #6
0
        /// <summary>
        /// Writes a byte of data to a specified port address
        /// </summary>
        public override void WritePort(ushort port, byte value)
        {
            // get a BitArray of the port
            BitArray portBits = new BitArray(BitConverter.GetBytes(port));
            // get a BitArray of the value byte
            BitArray bits = new BitArray(new byte[] { value });

            // handle AY port writes
            AYDevice.WritePort(port, value);

            // memory paging
            // this is controlled by writes to port 0x7ffd
            // but it is only partially decoded so it actually responds to any port with bits 1 and 15 reset
            if (portBits[1] == false && portBits[15] == false)
            {
                Last7ffd = value;

                // if paging is disabled then all writes to this port are ignored until the next reboot
                if (!PagingDisabled)
                {
                    // Bits 0, 1, 2 select the RAM page
                    var rp = value & 0x07;
                    if (RAMPaged != rp && rp < 8)
                    {
                        RAMPaged = rp;
                    }

                    // bit 3 controls shadow screen
                    if (SHADOWPaged != bits[3])
                    {
                        SHADOWPaged = bits[3];
                    }

                    // ROM page
                    if (bits[4])
                    {
                        // 48k basic rom
                        ROMPaged = 1;
                    }
                    else
                    {
                        // 128k editor and menu system
                        ROMPaged = 0;
                    }

                    // Bit 5 set signifies that paging is disabled until next reboot
                    PagingDisabled = bits[5];
                }
                else
                {
                    // no changes to paging
                }
            }

            if (port == 0x1ffd)
            {
            }

            // Check whether the low bit is reset
            // Technically the ULA should respond to every even I/O address
            bool lowBitReset = !portBits[0]; // (port & 0x01) == 0;

            // Only even addresses address the ULA
            if (lowBitReset)
            {
                LastFe = value;

                // store the last OUT byte
                LastULAOutByte = value;

                /*
                 *  Bit   7   6   5   4   3   2   1   0
                 +-------------------------------+
                 |   |   |   | E | M |   Border  |
                 +-------------------------------+
                 */

                // Border - LSB 3 bits hold the border colour
                if (ULADevice.BorderColor != (value & BORDER_BIT))
                {
                    //ULADevice.RenderScreen((int)CurrentFrameCycle);
                    ULADevice.BorderColor = value & BORDER_BIT;
                }

                // Buzzer
                BuzzerDevice.ProcessPulseValue((value & EAR_BIT) != 0, _renderSound);
                TapeDevice.WritePort(port, value);

                // Tape
                //TapeDevice.ProcessMicBit((value & MIC_BIT) != 0);
            }
        }
コード例 #7
0
ファイル: SpectrumBase.cs プロジェクト: gocha/BizHawk
        public void SyncState(Serializer ser)
        {
            ser.BeginSection("ZXMachine");
            ser.Sync(nameof(FrameCompleted), ref FrameCompleted);
            ser.Sync(nameof(OverFlow), ref OverFlow);
            ser.Sync(nameof(FrameCount), ref FrameCount);
            ser.Sync(nameof(_frameCycles), ref _frameCycles);
            ser.Sync(nameof(inputRead), ref inputRead);
            ser.Sync(nameof(LastFrameStartCPUTick), ref LastFrameStartCPUTick);
            ser.Sync(nameof(LastULAOutByte), ref LastULAOutByte);
            ser.Sync(nameof(ROM0), ref ROM0, false);
            ser.Sync(nameof(ROM1), ref ROM1, false);
            ser.Sync(nameof(ROM2), ref ROM2, false);
            ser.Sync(nameof(ROM3), ref ROM3, false);
            ser.Sync(nameof(RAM0), ref RAM0, false);
            ser.Sync(nameof(RAM1), ref RAM1, false);
            ser.Sync(nameof(RAM2), ref RAM2, false);
            ser.Sync(nameof(RAM3), ref RAM3, false);
            ser.Sync(nameof(RAM4), ref RAM4, false);
            ser.Sync(nameof(RAM5), ref RAM5, false);
            ser.Sync(nameof(RAM6), ref RAM6, false);
            ser.Sync(nameof(RAM7), ref RAM7, false);
            ser.Sync(nameof(ROMPaged), ref ROMPaged);
            ser.Sync(nameof(SHADOWPaged), ref SHADOWPaged);
            ser.Sync(nameof(RAMPaged), ref RAMPaged);
            ser.Sync(nameof(PagingDisabled), ref PagingDisabled);
            ser.Sync(nameof(SpecialPagingMode), ref SpecialPagingMode);
            ser.Sync(nameof(PagingConfiguration), ref PagingConfiguration);
            ser.Sync(nameof(ROMhigh), ref ROMhigh);
            ser.Sync(nameof(ROMlow), ref ROMlow);
            ser.Sync(nameof(LastContendedReadByte), ref LastContendedReadByte);

            KeyboardDevice.SyncState(ser);
            BuzzerDevice.SyncState(ser);
            TapeBuzzer.SyncState(ser);
            ULADevice.SyncState(ser);
            CPUMon.SyncState(ser);

            if (AYDevice != null)
            {
                AYDevice.SyncState(ser);
                ((AY38912)AYDevice).PanningConfiguration = Spectrum.Settings.AYPanConfig;
            }

            ser.Sync(nameof(tapeMediaIndex), ref tapeMediaIndex);
            if (ser.IsReader)
            {
                IsLoadState    = true;
                TapeMediaIndex = tapeMediaIndex;
                IsLoadState    = false;
            }

            TapeDevice.SyncState(ser);

            ser.Sync(nameof(diskMediaIndex), ref diskMediaIndex);
            if (ser.IsReader)
            {
                IsLoadState    = true;
                DiskMediaIndex = diskMediaIndex;
                IsLoadState    = false;
            }

            UPDDiskDevice?.SyncState(ser);

            ser.EndSection();
        }
コード例 #8
0
ファイル: SpectrumBase.cs プロジェクト: gocha/BizHawk
        /// <summary>
        /// Executes a single frame
        /// </summary>
        public virtual void ExecuteFrame(bool render, bool renderSound)
        {
            ULADevice.FrameEnd        = false;
            ULADevice.ULACycleCounter = CurrentFrameCycle;

            InputRead    = false;
            _render      = render;
            _renderSound = renderSound;

            FrameCompleted = false;

            //if (UPDDiskDevice == null || !UPDDiskDevice.FDD_IsDiskLoaded)
            //TapeDevice.StartFrame();

            if (_renderSound)
            {
                AYDevice?.StartFrame();
            }

            PollInput();

            for (; ;)
            {
                // run the CPU Monitor cycle
                CPUMon.ExecuteCycle();

                // clock the beepers
                TapeBuzzer.SetClock((int)CurrentFrameCycle);
                BuzzerDevice.SetClock((int)CurrentFrameCycle);

                // cycle the tape device
                if (UPDDiskDevice == null || !UPDDiskDevice.FDD_IsDiskLoaded)
                {
                    TapeDevice.TapeCycle();
                }

                // has frame end been reached?
                if (ULADevice.FrameEnd)
                {
                    break;
                }
            }

            OverFlow = (int)CurrentFrameCycle - ULADevice.FrameLength;

            // we have reached the end of a frame
            LastFrameStartCPUTick = CPU.TotalExecutedCycles - OverFlow;

            ULADevice.LastTState = 0;

            AYDevice?.EndFrame();

            FrameCount++;

            if (UPDDiskDevice == null || !UPDDiskDevice.FDD_IsDiskLoaded)
            {
                TapeDevice.EndFrame();
            }

            FrameCompleted = true;

            // is this a lag frame?
            Spectrum.IsLagFrame = !InputRead;

            // FDC debug
            if (UPDDiskDevice != null && UPDDiskDevice.writeDebug)
            {
                // only write UPD log every second
                if (FrameCount % 10 == 0)
                {
                    System.IO.File.AppendAllLines(UPDDiskDevice.outputfile, UPDDiskDevice.dLog);
                    UPDDiskDevice.dLog = new System.Collections.Generic.List <string>();
                    //System.IO.File.WriteAllText(UPDDiskDevice.outputfile, UPDDiskDevice.outputString);
                }
            }
        }
コード例 #9
0
        /// <summary>
        /// Executes a single frame
        /// </summary>
        public virtual void ExecuteFrame(bool render, bool renderSound)
        {
            InputRead    = false;
            _render      = render;
            _renderSound = renderSound;

            FrameCompleted = false;

            if (UPDDiskDevice == null || !UPDDiskDevice.FDD_IsDiskLoaded)
            {
                TapeDevice.StartFrame();
            }

            if (_renderSound)
            {
                BuzzerDevice.StartFrame();
                TapeBuzzer.StartFrame();

                if (AYDevice != null)
                {
                    AYDevice.StartFrame();
                }
            }

            PollInput();

            while (CurrentFrameCycle < ULADevice.FrameLength)
            {
                // check for interrupt
                ULADevice.CheckForInterrupt(CurrentFrameCycle);

                // run a single CPU instruction
                CPU.ExecuteOne();

                // cycle the tape device
                if (UPDDiskDevice == null || !UPDDiskDevice.FDD_IsDiskLoaded)
                {
                    TapeDevice.TapeCycle();
                }
            }

            // we have reached the end of a frame
            LastFrameStartCPUTick = CPU.TotalExecutedCycles - OverFlow;

            // paint the buffer if needed
            if (ULADevice.needsPaint && _render)
            {
                ULADevice.UpdateScreenBuffer(ULADevice.FrameLength);
            }

            if (_renderSound)
            {
                BuzzerDevice.EndFrame();
                TapeBuzzer.EndFrame();
            }

            if (AYDevice != null)
            {
                AYDevice.EndFrame();
            }

            FrameCount++;

            // setup for next frame
            ULADevice.ResetInterrupt();

            if (UPDDiskDevice == null || !UPDDiskDevice.FDD_IsDiskLoaded)
            {
                TapeDevice.EndFrame();
            }

            FrameCompleted = true;

            // is this a lag frame?
            Spectrum.IsLagFrame = !InputRead;

            // FDC debug

            if (UPDDiskDevice != null && UPDDiskDevice.writeDebug)
            {
                // only write UPD log every second
                if (FrameCount % 10 == 0)
                {
                    System.IO.File.WriteAllText(UPDDiskDevice.outputfile, UPDDiskDevice.outputString);
                }
            }
        }