public MemoryMap(IoAddresses ioAddresses) { this.IoAddresses = ioAddresses; // TODO: Fix this. this.IoAddresses.Parent = this; this.mbc_ = new MemoryBankController(this.romBank0_, this.romBankX_); var f = IMemorySourceFactory.INSTANCE; this.Vram = f.NewArray(0x2000); var ram = f.NewArray(0xfe00 - 0xe000); this.Oam = f.NewArray(0xa0); this.impl_ = f.BuildMapper(0xffff + 1) .Register(0x0000, this.romBank0_) .Register(0x4000, this.romBankX_) .Register(0x8000, this.Vram) .Register(0xc000, ram) .Register(0xe000, ram) .Register(0xfe00, this.Oam) .Register(0xff00, this.IoAddresses) .Build(); Asserts.Equal(10, this.impl_.SourceCount); this.Reset(); }
/// <summary> /// Initializes the native code page. /// /// Safe to call if we already initialized (this function is idempotent). /// <see cref="NativeCodePage"/> /// </summary> internal static void InitializeNativeCodePage() { // Do nothing if we already initialized. if (NativeCodePage != IntPtr.Zero) { return; } // Allocate the page, write the native code into it, then set it // to be executable. IMemoryMapper mapper = CreateMemoryMapper(); int codeLength = NativeCode.Active.Code.Length; NativeCodePage = mapper.MapWriteable(codeLength); Marshal.Copy(NativeCode.Active.Code, 0, NativeCodePage, codeLength); mapper.SetReadExec(NativeCodePage, codeLength); }
public IoAddresses(ISerialBus serialBus) { this.SerialBus = serialBus; /*case 0x44: * this.data_[relativeAddress] = 0; * return;*/ var f = IMemorySourceFactory.INSTANCE; this.Div = f.BuildValue() .OnSet((value, direct) => { if (!direct) { this.DivCounter = 0; return(0); } return(value); }) .Build(); this.Tima = f.NewValue(); this.Tma = f.NewValue(); this.Tac = f.BuildValue() .OnSet((value, direct) => { if (!direct) { this.TimerCounter = 0; return((byte)(value | 0xf8)); } return(value); }) .Build(); this.ScrollY = f.NewValue(); this.ScrollX = f.NewValue(); this.Bgp = f.NewValue(); this.Obp0 = f.NewValue(); this.Obp1 = f.NewValue(); this.Wy = f.NewValue(); this.Wx = f.NewValue(); this.Ie = f.NewValue(); this.impl_ = f.BuildMapper(0x100) .Register(0x00, this.Joypad) .Register( 0x01, f.BuildValue() .OnSet(this.SerialBus.Bytes.OnNext) .Build() ) .Register(0x04, this.Div) .Register(0x05, this.Tima) .Register(0x06, this.Tma) .Register(0x07, this.Tac) .Register(0x0f, this.If) .Register(0x40, this.Lcdc) .Register(0x41, this.Stat) .Register(0x42, this.ScrollY) .Register(0x43, this.ScrollX) .Register(0x44, this.Ly) .Register(0x45, this.Lyc) .Register(0x46, f.BuildValue() .OnSet(value => { var address = (ushort)(value << 8); this.LastDmaAddress = address; var memory = this.Parent !; var oam = memory.Oam; var oamSize = oam.Size; for (ushort i = 0; i < oamSize; ++i) { oam[i] = memory[(ushort)(address + i)]; } }) .Build()) .Register(0x47, this.Bgp) .Register(0x48, this.Obp0) .Register(0x49, this.Obp1) .Register(0x4a, this.Wy) .Register(0x4b, this.Wx) .Register(0xff, this.Ie) .Build(); }