Exemple #1
0
        public void SoftReset()
        {
            Control = new ControlRegisterValues(0);
            Mask    = new MaskRegisterValues(0);
            Status  = new StatusRegisterValues(0);

            isFrameOdd = false;

            Memory.SoftReset();
        }
Exemple #2
0
        public void HardReset()
        {
            Control = new ControlRegisterValues(0);
            Mask    = new MaskRegisterValues(0);
            Status  = new StatusRegisterValues(0);

            FastBits.Clear(ImageBuffer);

            isFrameOdd      = false;
            CurrentScanline = 0;
            CurrentDot      = 0;

            Memory.HardReset();
        }
Exemple #3
0
        public void Write(ushort address, byte value)
        {
            if (address >= 8)
            {
                throw new Exception("Tried writing out of range from PPU");
            }

            ExtMemResult = value;

            if (address == 0)
            {
                // PPUCTRL ($2000)
                Control = (ControlRegisterValues)value;
                temporaryAddress.NametableSelect = Control.Nametable;
            }
            else if (address == 1)
            {
                // PPUMASK ($2001)
                Mask = (MaskRegisterValues)value;
            }
            else if (address == 3)
            {
                // OAMADDR ($2003)
                ExtMemOAMAddress = value;
            }
            else if (address == 4)
            {
                // OAMDATA ($2004)
                Memory.OAMram[ExtMemOAMAddress++] = value;
            }
            else if (address == 5)
            {
                // PPUSCROLL ($2005)
                if (!ExtMemLatch)
                {
                    fineXScroll = (byte)(value & 7);
                    temporaryAddress.CoarseXScroll = (byte)(value >> 3);
                }
                else
                {
                    temporaryAddress.FineYScroll   = (byte)(value & 7);
                    temporaryAddress.CoarseYScroll = (byte)(value >> 3);
                }
            }
            else if (address == 6)
            {
                // PPUADDR ($2006)
                if (!ExtMemLatch)
                {
                    temporaryAddress.High = (byte)(value & 0x3F);
                }
                else
                {
                    temporaryAddress.Low = value;
                    currentAddress.Full  = temporaryAddress.Full;
                }

                ExtMemLatch = !ExtMemLatch;
            }
            else if (address == 7)
            {
                // PPUDATA ($2007)
                Bus.Write(currentAddress.Address, value);
                currentAddress.Address += (ushort)(Control.AddressIncrement ? 32 : 1);
            }
        }