コード例 #1
0
        public PtrMemoryWriter(RangeContainer container, MMU mmu, uint dest)
        {
            dest = BitConverter.ToUInt32(container.Memory, (int)dest);

            MMU  = mmu;
            Dest = dest;
        }
コード例 #2
0
        //Initialize a new CPU
        public CPU()
        {
            //Create a new MMU
            mmu = new MMU(MMU.standardMap);

            //TODO: add other initialization
        }
コード例 #3
0
 public InstructionTests()
 {
     _mmu   = new MMU();
     _ppu   = new PPU(_mmu);
     _input = new Input(_mmu);
     _cpu   = new CPU(_mmu, _ppu, _input);
 }
コード例 #4
0
ファイル: TestBase.cs プロジェクト: claassen/CmC
        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));
        }
コード例 #5
0
ファイル: RegisterTests.cs プロジェクト: honased/GBSharp
 public RegisterTests()
 {
     _mmu = new MMU();
     _ppu = new PPU(_mmu);
     _input = new Input(_mmu);
     _cpu = new CPU(_mmu, _ppu, _input);
 }
コード例 #6
0
 public void SetUp()
 {
     mmu  = new MMU();
     regs = new Registers(mmu);
     cpu  = new CPU(mmu, regs);
     regs.SP--;
 }
コード例 #7
0
ファイル: Palette.cs プロジェクト: honased/GBSharp
        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);
            }
        }
コード例 #8
0
        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);
                        }
                    }
                }
            }
        }
コード例 #9
0
 /// <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);
     }
 }
コード例 #10
0
 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);
 }
コード例 #11
0
 public VMInternalState1()
 {
     ShiftRotateUnit   = MainModule.GetOrCreateGClass19();
     ALU               = MainModule.GetOrCreateALU();
     object_3          = MainModule.GetOrCreateGClass11();
     RegisterContainer = MainModule.smethod_59();
     Registers         = MainModule.GetOrCreateRegisters();
     MMU               = MainModule.smethod_53();
 }
コード例 #12
0
        public void ReadWriteWord()
        {
            var mmu = new MMU();

            ushort testword = 0xf1b2;

            mmu.WriteWord(0xff80, testword);

            Assert.That(mmu.rw(0xff80), Is.EqualTo(testword));
        }
コード例 #13
0
        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);
        }
コード例 #14
0
        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);
        }
コード例 #15
0
    public GameBoyEmulator(CPU cpu, MMU mmu)
    {
        _cpu      = cpu;
        _mmu      = mmu;
        _graphics = new GraphicsDeviceManager(this)
        {
            PreferredBackBufferWidth  = 1800,
            PreferredBackBufferHeight = 1000
        };

        IsMouseVisible = true;
    }
コード例 #16
0
ファイル: EmuBytePusher.cs プロジェクト: fattard/xFF
                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) => { };
                }
コード例 #17
0
ファイル: GameBoy.cs プロジェクト: Scott-Klein/GB
        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;
        }
コード例 #18
0
ファイル: Program.cs プロジェクト: Dotpys/JMGBE
    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();
    }
コード例 #19
0
        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");
                }
            }
        }
コード例 #20
0
 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);
 }
コード例 #21
0
 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();
 }
コード例 #22
0
 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;
             }
         }
     }
 }
コード例 #23
0
ファイル: Palette.cs プロジェクト: honased/GBSharp
        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));
            }
        }
コード例 #24
0
        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");
                }
            }
        }
コード例 #25
0
ファイル: Emulator.cs プロジェクト: wjhuds/gb.NET-Core
        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);
        }
コード例 #26
0
ファイル: Program.cs プロジェクト: elvishfiend/jsGB
        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();
        }
コード例 #27
0
    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;
                }
            }
        }
    }
コード例 #28
0
ファイル: CPU.cs プロジェクト: fattard/xFF
 public void BindMMU(MMU aMMU)
 {
     m_bbj_core.BindAddressBUS(aMMU.Read8, aMMU.Write8, aMMU.Read24, aMMU.Write24);
     m_mmu = aMMU;
 }
コード例 #29
0
ファイル: MemoryReader.cs プロジェクト: nvareille/KhelljyrVM
 public PtrMemoryReader(RangeContainer container, MMU mmu, uint ptr, int size)
 {
     ptr  = BitConverter.ToUInt32(container.Memory, (int)ptr);
     Data = mmu.ReadBytes(ptr, size);
 }
コード例 #30
0
 public GB()
 {
     mmu  = new MMU(this);
     cpu  = new CPU(this);
     cart = new Cart();
 }