public DisplayStatusRegister(GameboyAdvance gba, LcdController lcd) { this.lcd = lcd; DispStatRegister r0 = new DispStatRegister(lcd, this, gba.Memory, 0x4000004); MemoryRegister8 r1 = new MemoryRegister8(gba.Memory, 0x4000005, true, true); register = new MemoryRegister16(gba.Memory, 0x4000004, true, true, r0, r1); }
public Window(GameboyAdvance gba, UInt32 rightRegisterAddress, UInt32 registerAddress) { this.gba = gba; if (rightRegisterAddress != 0) { Right = new MemoryRegister8(gba.Memory, rightRegisterAddress, false, true); Left = new MemoryRegister8(gba.Memory, rightRegisterAddress + 1, false, true); Bottom = new MemoryRegister8(gba.Memory, rightRegisterAddress + 4, false, true); Top = new MemoryRegister8(gba.Memory, rightRegisterAddress + 5, false, true); } Register = new MemoryRegister8(gba.Memory, registerAddress, true, true); }
public LcdController(GameboyAdvance gba) { this.gba = gba; frameBuffer0 = new DirectBitmap(Screen_X_Resolution, Screen_Y_Resolution); frameBuffer1 = new DirectBitmap(Screen_X_Resolution, Screen_Y_Resolution); FrameBuffer = frameBuffer0; drawBuffer = frameBuffer1; this.Palettes = new Palettes(); DisplayControlRegister = new DisplayControlRegister(gba, this); DispStatRegister = new DisplayStatusRegister(gba, this); Bg = new Background[4]; UInt32 scrollBaseAddress = 0x4000010; for (int i = 0; i < 4; i++) { BgControlRegister cntReg = new BgControlRegister(gba, this, i, (UInt32) (0x4000008 + (i * 2))); MemoryRegister16 scrollXReg = new MemoryRegister16(gba.Memory, scrollBaseAddress, false, true, 0x01); MemoryRegister16 scrollYReg = new MemoryRegister16(gba.Memory, scrollBaseAddress + 2, false, true, 0x01); Bg[i] = new Background(gba, i, cntReg, scrollXReg, scrollYReg); scrollBaseAddress += 4; } VCount = new MemoryRegister8(gba.Memory, 0x04000006, true, false); this.ObjController = new ObjController(gba); Windows = new Window[4]; Windows[0] = new Window(gba, 0x4000040, 0x4000048); Windows[1] = new Window(gba, 0x4000042, 0x4000049); Windows[2] = new Window(gba, 0, 0x400004A); Windows[3] = new Window(gba, 0, 0x400004B); this.BlendControlRegister = new BlendControlRegister(this, gba); BlendingCoefficientRegister = new PixelCoefficientRegister(this, gba, 0x4000052); BrightnessCoefficientRegister = new PixelCoefficientRegister(this, gba, 0x4000054); #if THREADED_SCANLINE //Interlocked.Exchange(ref drawScanline, 0); drawScanline = 0; exitThread = false; scanlineThread = new Thread(new ThreadStart(ScanlineThread)); scanlineThread.Priority = ThreadPriority.Highest; scanlineThread.Start(); #endif }
public MemoryRegister16(Memory memory, UInt32 address, bool readable, bool writeable) { LowByte = new MemoryRegister8(memory, address, readable, writeable); HighByte = new MemoryRegister8(memory, address + 1, readable, writeable); if (readable) { memory.IoRegisters16Read.Add(address, this); } if (writeable) { memory.IoRegisters16Write.Add(address, this); } }
public DisplayControlRegister(GameboyAdvance gba, LcdController lcd) { this.lcd = lcd; MemoryRegister8WithSetHook r0 = new MemoryRegister8WithSetHook(gba.Memory, 0x4000000, true, true); MemoryRegister8 r1 = new MemoryRegister8(gba.Memory, 0x4000001, true, true); register = new MemoryRegister16(gba.Memory, 0x4000000, true, true, r0, r1); r0.OnSet = (oldValue, newValue) => { // BgMode changed? if ((oldValue & 0x07) != (newValue & 0x07)) { lcd.Bg[0].CacheRenderData(); lcd.Bg[1].CacheRenderData(); lcd.Bg[2].CacheRenderData(); lcd.Bg[3].CacheRenderData(); } }; }
public GbaTimer(Timers timers, GameboyAdvance gba, int timerNumber) { this.timers = timers; this.gba = gba; this.timerNumber = timerNumber; FiresOnCycle = 0xFFFFFFFF; UInt32 baseAddr = (UInt32)(0x4000100 + (timerNumber * 4)); TimerValueRegister r0 = new TimerValueRegister(gba, this, gba.Memory, baseAddr); TimerValueRegister r1 = new TimerValueRegister(gba, this, gba.Memory, baseAddr + 1); TimerValueRegister = new MemoryRegister16(gba.Memory, baseAddr, true, false, r0, r1); ReloadValue = new MemoryRegister16(gba.Memory, baseAddr, false, true); baseAddr = (UInt32)(0x4000102 + (timerNumber * 4)); MemoryRegister8WithSetHook reg = new MemoryRegister8WithSetHook(gba.Memory, baseAddr, true, true); MemoryRegister8 unused = new MemoryRegister8(gba.Memory, baseAddr + 1, true, true); TimerControlRegister = new MemoryRegister16(gba.Memory, baseAddr, true, true, reg, unused); reg.OnSet = (oldValue, newValue) => { CalculateWhichCycleTheTimerWillFire(); timers.CalculateWhenToNextUpdate(); // When a timer is enabled, it reloads it's starting value. When it is disabled it just maintains its current values bool wasEnabled = ((oldValue & 0x80) != 0); bool enabled = ((newValue & 0x80) != 0); if (wasEnabled == false && enabled) { startCycle = gba.Cpu.Cycles; timers.ScheduledUpdate(); TimerValue = ReloadValue.Value; } }; }
public DmaControlRegister(GameboyAdvance gba, DmaChannel channel, UInt32 address) { this.channel = channel; MemoryRegister8 r0 = new MemoryRegister8(gba.Memory, address, true, true); MemoryRegister8WithSetHook r1 = new MemoryRegister8WithSetHook(gba.Memory, address + 1, true, true); register = new MemoryRegister16(gba.Memory, address, true, true, r0, r1); r1.OnSet = (oldValue, newValue) => { bool oldEnable = ((oldValue & 0x80) != 0); bool newEnable = ((newValue & 0x80) != 0); if (oldEnable == false && newEnable == true) { // Dma transfers take 2 cycles to start channel.DelayTransfer = 2; channel.ScheduledUpdateOnCycle = gba.Cpu.Cycles + 2; gba.Scheduler.RefreshSchedule(); } }; }