NES.Engine.ReadMemory8 C# (CSharp) Method

ReadMemory8() public method

public ReadMemory8 ( ushort addr ) : byte
addr ushort
return byte
        public byte ReadMemory8(ushort addr)
        {
            // Depends on where!
            if (addr < 0x2000)
            {
                // Ram w/ mirroring
                return RAM[addr % 2048];
            } else if ((addr >= 0x2000) && (addr < 0x4020))
            {
                // Registers
                if (addr < 0x4000)
                    addr = (ushort)(((addr - 0x2000) % 0x8) + 0x2000);

                return IORegisters.ReadMemory8(addr);
            } else if (addr < 0x8000)
            {
                Console.WriteLine("$02 = {0:x}", ReadMemory8((ushort)0x02));
                Console.WriteLine("$03 = {0:x}", ReadMemory8((ushort)0x03));
                throw new NotImplementedException();
            } else if (addr <= 0xFFFF)
            {
                int desiredBank = (addr < 0xC000) ? 1 : 0;
                addr = (ushort)((addr < 0xC000) ? addr - 0x8000 : addr - 0xC000);
                desiredBank = (Cartridge.PRGROMBanks.Length == 1) ? 0 : desiredBank;
                return Cartridge.PRGROMBanks[desiredBank][addr];
            } else
                throw new ArgumentException();
        }

Usage Example

示例#1
0
文件: Stack.cs 项目: SpydazWebAI/nes
 public byte Pop8()
 {
     SP++;
     return(Engine.ReadMemory8((ushort)(0x0100 + SP)));
 }