/// <summary> /// Read a value from the memory at a specific address /// </summary> /// <param name="address">The address to read from</param> /// <returns>Byte The value</returns> public byte Read(ushort address) { if (address < 0x2000) /*RAM*/ { return(Ram[address & 0x07FF]); } if (address < 0x6000) /*IO*/ { switch (address) { case 0x2002: return(_engine.Ppu.Read2002()); case 0x2004: return(_engine.Ppu.Read2004()); case 0x2007: return(_engine.Ppu.Read2007()); case 0x4015: return(_engine.Apu.Read_4015()); case 0x4016: { var v = (byte)(0x40 | (JoyData1 & 1)); JoyData1 = (JoyData1 >> 1) | 0x80; return(v); } case 0x4017: { var v = (byte)(0x40 | Zapper.GetData() | (JoyData2 & 1)); JoyData2 = (JoyData2 >> 1) | 0x80; return(v); } default: if (Map.Cartridge.MapperNo == 225 | Map.Cartridge.MapperNo == 255) { var map225 = (Mapper225255)Map.CurrentMapper; return(map225.ReadRegisters(address)); } break; } } else if (address < 0x8000) /*SRAM*/ { if (Map.Cartridge.MapperNo == 5) { return(1); } return(SRam[address - 0x6000]); } else /*PRG*/ { return(Map.ReadPrg(address)); } return(0); }
/// <summary> /// Read an address from the memory /// </summary> /// <param name="address"></param> /// <returns></returns> public ushort Read16(ushort address) { byte data1; byte data2; if (address < 0x2000) { data1 = Ram[(address & 0x07FF)]; data2 = Ram[(address & 0x07FF) + 1]; } else if (address < 0x8000) { data1 = SRam[address - 0x6000]; data2 = SRam[(address - 0x6000) + 1]; } else { data1 = Map.ReadPrg(address); data2 = Map.ReadPrg((ushort)(address + 1)); } return((ushort)((data2 << 8) | data1)); }