Пример #1
0
        public byte Read(int address)
        {
            // Special behavior for when the Ms. Pac-Man daughterboard is enabled.
            if (_auxBoardEnabled)
            {
                if (address <= 0x4000)
                {
                    // For all original ROM areas, read our patched version.
                    return(_auxBoard.AuxROMs[address]);
                }
                else if (address >= 0x8000 && address < 0x8800)
                {
                    // Aux ROM U5
                    return(_auxBoard.AuxROMs[address - 0x8000 + 0x6000]);
                }
                else if (address >= 0x8800 && address < 0xA000)
                {
                    // Aux ROM U6
                    return(_auxBoard.AuxROMs[(address & 0xFFF) + 0x5000]);
                }

                // else fall through to original memory read behaviors.
            }

            if (address >= 0x0000 && address <= 0x4FFF)
            {
                // Includes ROM, Video RAM, RAM, and sprites.
                return(_memory[address]);
            }
            else if (address >= 0x5000 && address <= 0x503F)
            {
                // IN0 (player 1 joystick, credit switches, and rack advance button) (each byte returns same value).
                return(ButtonState.GetPortIN0());
            }
            else if (address == 0x5003)
            {
                // Flip screen (bit 0: 0 = normal, 1 = flipped)
                return((byte)(_flipScreen == true ? 1 : 0));
            }
            else if (address == 0x5004)
            {
                // 1 player start lamp (bit 0: 0 = on, 1 = off)
                // I don't believe the Pac-Man arcade cabinet had support for blinking start buttons.
                // Other games on the same platform might though.
                return(0x01);
            }
            else if (address == 0x5005)
            {
                // 2 player start lamp (bit 0: 0 = on, 1 = off)
                // I don't believe the Pac-Man arcade cabinet had support for blinking start buttons.
                // Other games on the same platform might though.
                return(0x01);
            }
            else if (address == 0x5006)
            {
                // Coin lockout (bit 0: 0 = unlocked, 1 = locked)
                // I don't believe the Pac-Man arcade cabinet had a coin lockout mechanism.
                return(0x00);
            }
            else if (address == 0x5007)
            {
                // Coin counter (trigger by changing bit 0 from 0 to 1)
                return(0x00);
            }
            else if (address >= 0x5040 && address <= 0x507F)
            {
                // IN1 (player 2 joystick, start buttons, board test and cabinet mode switches) (each byte returns same value).
                // Note that bit 7 is the cabinet mode setting which comes from a DIP switch.
                var cabinetMode = (byte)((DIPSwitchState.CabinetMode == CabinetMode.Upright ? 1 : 0) << 7);
                return((byte)(ButtonState.GetPortIN1() | cabinetMode));
            }
            else if (address >= 0x5080 && address <= 0x50BF)
            {
                // Dip Switch Settings (each byte returns same value).
                return(DIPSwitchState.GetByte());
            }
            else if (address < 0x00)
            {
                throw new IndexOutOfRangeException(String.Format("Invalid read memory address (< 0x0000): 0x{0:X4}", address));
            }
            else
            {
                // TODO: I may need to remove and/or relax this restriction. Adding an exception for now
                // so I can troubleshoot while getting things running.
                throw new Exception(String.Format("Unexpected read memory address: 0x{0:X4}", address));
            }
        }