public PtrMemoryWriter(RangeContainer container, MMU mmu, uint dest) { dest = BitConverter.ToUInt32(container.Memory, (int)dest); MMU = mmu; Dest = dest; }
//Initialize a new CPU public CPU() { //Create a new MMU mmu = new MMU(MMU.standardMap); //TODO: add other initialization }
public InstructionTests() { _mmu = new MMU(); _ppu = new PPU(_mmu); _input = new Input(_mmu); _cpu = new CPU(_mmu, _ppu, _input); }
public TestVM ExecuteTestVM(string testCode) { CompilationContext context = CmCompiler.CompileText(testCode); byte[] objectCode; using (var s = new MemoryStream()) { CmCompiler.CreateObjectCode(s, new RIVMArchitecture(), context.GetIR(), context.GetStringConstants(), context.GetGlobalVariables(), context.GetFunctions()); objectCode = s.GetBuffer(); } byte[] executableCode; using (var s = new MemoryStream()) { CmLinker.Link(s, new List <byte[]> { objectCode }, false, SystemMemoryMap.BIOS_ROM_START); executableCode = s.GetBuffer(); } var bios = new BIOS(executableCode); var mmu = new MMU(SystemMemoryMap.BIOS_STACK_END, bios, null, null); var cpu = new CPU(mmu); cpu.Start(); return(new TestVM(cpu)); }
public RegisterTests() { _mmu = new MMU(); _ppu = new PPU(_mmu); _input = new Input(_mmu); _cpu = new CPU(_mmu, _ppu, _input); }
public void SetUp() { mmu = new MMU(); regs = new Registers(mmu); cpu = new CPU(mmu, regs); regs.SP--; }
public void UpdateCGB(MMU mmu, int value) { int register = mmu.ReadByte(PaletteIndexAddress); bool increment = Bitwise.IsBitOn(register, 7); int index = register & 0x3F; int colorToModify = (index % 8) / 2; if ((index % 8) % 2 == 0) { red[colorToModify] = value & 0x1F; green[colorToModify] = (green[colorToModify] & 0x18) | (value >> 5); } else { green[colorToModify] = (green[colorToModify] & 0x07) | ((value & 0x03) << 3); blue[colorToModify] = (value >> 2) & 0x1F; } Colors[colorToModify].R = (int)((red[colorToModify] / 31.0) * 255); Colors[colorToModify].G = (int)((green[colorToModify] / 31.0) * 255); Colors[colorToModify].B = (int)((blue[colorToModify] / 31.0) * 255); if (increment) { index = (index + 1) % 64; mmu.WriteByte(index | (0x80), PaletteIndexAddress); } }
public void StartAlgoritmo() { while (controlador) { if (RAM.Processos.Count > 1) { var processo = RAM.Processos[1]; if (processo.Nome != "Windows 10") { MMU.AdicionarProcesso(processo); Thread.Sleep(1000); CPU.AdicionarProcesso(processo); Thread.Sleep(quantum * 1000); processo.TempoExecucao = processo.TempoExecucao - quantum; if (processo.TempoExecucao <= 0) { CPU.RemoverProcesso(); } else { CPU.VoltarProcesso(processo); } } } } }
/// <summary> /// Sets the cache for the CPU passed in with size matching the largest program in the job file /// </summary> /// <param name="core">Core the cache is set for</param> static void LoadCPUCache(CPU core) { core.Cache = new Word[Driver.LargestProgram]; for (int i = 0; i < core.ActiveProgram.ProgramSize; i++) { core.Cache[i] = MMU.ReadWord(i, core.ActiveProgram); } }
public void Setup() { cart = new Cartridge(TestCartsPaths.tetris); clock = new Clock(); ppu = new PPU(clock); mmu = new MMU(cart, ppu, clock); reg = new Registers(mmu); cpu = new CPU(mmu, reg); }
public VMInternalState1() { ShiftRotateUnit = MainModule.GetOrCreateGClass19(); ALU = MainModule.GetOrCreateALU(); object_3 = MainModule.GetOrCreateGClass11(); RegisterContainer = MainModule.smethod_59(); Registers = MainModule.GetOrCreateRegisters(); MMU = MainModule.smethod_53(); }
public void ReadWriteWord() { var mmu = new MMU(); ushort testword = 0xf1b2; mmu.WriteWord(0xff80, testword); Assert.That(mmu.rw(0xff80), Is.EqualTo(testword)); }
public OpcodeTests() { var gpu = new GPU(); var cpu = new CPU(); var mmu = new MMU(); Bus.Init(cpu, gpu, mmu); _romReader = new Mock <IROMReader>(); _gameboy = new GameboyDevice(_romReader.Object); }
public GameBoyEmu(uint width, uint height, uint x = 0, uint y = 0) : base("GameBoyEmu", width, height, x, y) { Rom = Files.TetrisRom; mmu = new MMU(); cpu = new CPU(mmu); ppu = new PPU(); timer = new TIMER(); joypad = new JOYPAD(); mmu.loadGamePak(Rom); }
public GameBoyEmulator(CPU cpu, MMU mmu) { _cpu = cpu; _mmu = mmu; _graphics = new GraphicsDeviceManager(this) { PreferredBackBufferWidth = 1800, PreferredBackBufferHeight = 1000 }; IsMouseVisible = true; }
public EmuBytePusher(ConfigsBytePusher aConfigs) { m_configs = aConfigs; m_cpu = new CPU(); m_mmu = new MMU(); m_cpu.BindMMU(m_mmu); // Temp bind DrawDisplay = (aVRAM, aStartOffset) => { }; PlayAudio = (aRAM, aStartOffset) => { }; UpdateInputKeys = (aRAM, aStartOffset) => { }; }
public GameBoy(string rom) { this.cart = new Cartridge(rom); //build the hardware and load the cartridge/ this.clock = new Clock(); this.ppu = new PPU(clock); this.JoyPad = new Joypad(); this.sound = new Sound(clock); this.memory = new MMU(this.cart, this.ppu, this.clock, sound, JoyPad); this.cpu = new CPU(this.memory, clock); this.PowerSwitch = true; }
static void Main() { MMU mmu = new MMU(); mmu.LoadRom("roms\\Tetris.gb"); cpu = new CPU(mmu); Thread a = new Thread(ThreadExec); a.Start(); using (GameBoyEmulator game = new GameBoyEmulator(cpu, mmu)) game.Run(); }
public void TestGPUMode3ToMode0Timing() { CPU cpu = new CPU(new GPU()); MMU mmu = new MMU(); var rom = new ROM(); cpu.GPU.LCDC = LCDC.LCDEnable; decimal timeSpentMicroSec = 0; while (cpu.GPU.Mode != GPUMode.Mode3) { cpu.Exec(0x00); if (cpu.InstructionsCount > 10000) { Assert.Fail("GPU did not changed to correct state"); } } GPUMode gpuMode = cpu.GPU.Mode; while (true) { cpu.Exec(0x00); timeSpentMicroSec += (decimal)1.0 / cpu.ClockFrequencyMhz * cpu.LastInstructionClockTime; var newMode = cpu.GPU.Mode; if (gpuMode != newMode) { if (newMode == GPUMode.Mode0) { Assert.IsTrue(timeSpentMicroSec > 41); Assert.IsTrue(timeSpentMicroSec < 42M); return; } else { Assert.Fail("GPU Mode should transition from Mode0 to Mode2"); } } if (cpu.InstructionsCount > 10000) { Assert.Fail("GPU did not changed to correct state"); } } }
public void LoadFile(byte[] loadFile) { interruptManager = new InterruptManager(); timer = new GBTimer(interruptManager); serial = new Serial(); audio = new GBAudio(); wram = new WRAM(); hram = new HRAM(); video = new Video(interruptManager, screen); cart = CartLoader.LoadCart(loadFile); input = new GBInput(interruptManager, inputHandler); mmu = new MMU(interruptManager, cart, input, audio, timer, serial, video, wram, hram); cpu = new CPU(interruptManager, mmu.Read, mmu.Write, mmu.UpdateTime); }
public SpaceGameboy(IMyTextPanel screen, Action <string> Echo) { SpaceGameboy.Echo = Echo; // Echo("Loading GPU"); this.gPU = new GPU(screen); //Echo("Loading MMU"); this.mMU = new MMU(); //Echo("Loading Z80"); this.z80 = new Z80(); //Echo("Loading KEY"); this.kEY = new KEY(); //Echo("Loading TIMER"); // this.tIMER = new TIMER(); }
void MMUOnMemoryAccess(MMU mmu, ushort addr) { if (enableBreakPoints) { for (int i = 0; i < memoryBreakPoints.Count; i++) { if (memoryBreakPoints[i].IsActivated(addr, emu)) { Debug.Log(string.Format("<color=blue>PAUSED on memory access: {0:X4}</color>", addr)); emu.paused = true; break; } } } }
public int Read(MMU mmu) { int register = mmu.ReadByte(PaletteIndexAddress); int index = register & 0x3F; int colorToModify = (index % 8) / 2; if ((index % 8) % 2 == 0) { return((red[colorToModify] & 0x1F) | ((green[colorToModify] & 0x07) << 5)); } else { return(((green[colorToModify] & 0x18) >> 3) | (blue[colorToModify] << 5)); } }
public void TestGPUMode0ToMode2Timing() { CPU cpu = new CPU(new GPU()); MMU mmu = new MMU(); var rom = new ROM(); cpu.GPU.LCDC = LCDC.LCDEnable; cpu.GPU.Mode = GPUMode.Mode0; decimal timeSpentMicroSec = 0; GPUMode gpuMode = cpu.GPU.Mode; while (true) { cpu.Exec(0x00); timeSpentMicroSec += (decimal)1.0 / cpu.ClockFrequencyMhz * cpu.LastInstructionClockTime; var newMode = cpu.GPU.Mode; if (gpuMode != newMode) { if (newMode == GPUMode.Mode2) { // We got the new mode, check that timings are ok // Mode0 should stay up for 204 clock, meaning 48.6µsec Assert.IsTrue(timeSpentMicroSec > 48.5M); Assert.IsTrue(timeSpentMicroSec < 48.7M); return; } else { Assert.Fail("GPU Mode should transition from Mode0 to Mode2"); } } if (cpu.InstructionsCount > 100000) { Assert.Fail("GPU did not changed to correct state"); } } }
static void Main(string[] args) { if (args.Length == 0) { Console.WriteLine("USAGE: gbnet bios_path rom_path [verbose]"); Console.ReadKey(); //Temporary while system is run inside VS System.Environment.Exit(1); } var biosPath = args[0]; var romPath = args[1]; var verbose = (args.Length > 2 && args[2] == "true") ? true : false; Console.WriteLine($"Verbose mode: <{(verbose ? "ON" : "OFF")}>"); Console.WriteLine("Bootstrapping emulator components..."); Console.WriteLine("Decoding BIOS into byte values..."); byte[] bios = File.ReadAllBytes(biosPath); Console.WriteLine("Initializing component: MMU..."); var mmu = new MMU(bios); Console.WriteLine("Initializing component: CPU..."); var cpu = new CPU(mmu); Console.WriteLine("Decoding ROM into byte values..."); byte[] rom = File.ReadAllBytes(romPath); Console.WriteLine("Loading ROM data into MMU..."); mmu.LoadRom(rom); Console.WriteLine("Starting CPU cycle..."); cpu.Start(verbose); Console.WriteLine("System terminated. Presss any key to exit..."); Console.ReadKey(); System.Environment.Exit(1); }
static void TestPattern() { GPU.reset(); GPU._bgon = 1; // turn Background on GPU._lcdon = 1; // turn LCD on GPU._winon = 1; // turn Window on GPU._xscrl = 0; GPU._yscrl = 0; // tile pattern tables are 0x8000 => 0x8FFF, or 0x8800 => 0x97FF // set tile 0 to all 0 for (int i = 0; i < 4; i++) { MMU.wb(0x8000 + i, 0); // low bit MMU.wb(0x8001 + i, 0); // high bit } // set tile 1 to all 1 MMU.wb(0x8002, 0xFF); // low bit MMU.wb(0x8003, 0); // high bit // set tile 2 to all 2 MMU.wb(0x8004, 0x00); // low bit MMU.wb(0x8005, 0xFF); // high bit // set tile 3 to all 3 MMU.wb(0x8004, 0xFF); // low bit MMU.wb(0x8005, 0xFF); // high bit // set the background tiles to all be tile 3 (all 0x3) // Map Display Select Mode 0 0x9800 => 0x9BFF (32 * 32) for (int i = 0; i < 32 * 32; i++) { MMU.wb(0x9800 + i, i % 4); } GPU.RenderTiles(); }
public void reset(Z80 z80, MMU mMU) { this.z80 = z80; this.mMU = mMU; Array.Clear(_vram, 0x00, _vram.Length); Array.Clear(_oam, 0x00, _oam.Length); // SpaceGameboy.Echo("Clearing palettes"); bgPalette[0] = '\uE00F'; bgPalette[1] = '\uE00E'; bgPalette[2] = '\uE00D'; bgPalette[3] = '\uE006'; obj0Palette[0] = '\uE00F'; obj0Palette[1] = '\uE00E'; obj0Palette[2] = '\uE00D'; obj0Palette[3] = '\uE006'; obj1Palette[0] = '\uE00F'; obj1Palette[1] = '\uE00E'; obj1Palette[2] = '\uE00D'; obj1Palette[3] = '\uE006'; // SpaceGameboy.Echo("Clearing tilemaps"); for (int i = 0; i < 512; i++) { _tilemap[i] = new int[8][]; for (int j = 0; j < 8; j++) { _tilemap[i][j] = new int[9]; for (int k = 0; k < 8; k++) { _tilemap[i][j][k] = 0x00; } } } }
public void BindMMU(MMU aMMU) { m_bbj_core.BindAddressBUS(aMMU.Read8, aMMU.Write8, aMMU.Read24, aMMU.Write24); m_mmu = aMMU; }
public PtrMemoryReader(RangeContainer container, MMU mmu, uint ptr, int size) { ptr = BitConverter.ToUInt32(container.Memory, (int)ptr); Data = mmu.ReadBytes(ptr, size); }
public GB() { mmu = new MMU(this); cpu = new CPU(this); cart = new Cart(); }