Beispiel #1
0
 public GameBoy(ICartridge cartridge)
 {
     Cartridge = cartridge;
     Memory    = new GameBoyMemory(this);
     Cpu       = new GameBoyCpu(this);
     Gpu       = new GameBoyGpu(this);
     Spu       = new GameBoySpu(this);
     KeyPad    = new GameBoyPad(this);
     Timer     = new GameBoyTimer(this);
     Reset();
     IsPoweredOn = true;
 }
Beispiel #2
0
        public GameBoy(ICartridge cartridge, IClock clock, bool preferGbcMode)
        {
            GbcMode = preferGbcMode && (cartridge.GameBoyColorFlag & GameBoyColorFlag.SupportsColor) != 0;

            _clock = clock;

            Components = new List <IGameBoyComponent>
            {
                (Cartridge = cartridge),
                (Memory = new GameBoyMemory(this)),
                (Cpu = new GameBoyCpu(this, clock)),
                (Gpu = new GameBoyGpu(this)),
                (Spu = new GameBoySpu(this)),
                (KeyPad = new GameBoyPad(this)),
                (Timer = new GameBoyTimer(this))
            }.AsReadOnly();

            foreach (var component in Components)
            {
                component.Initialize();
            }

            Reset();
            IsPoweredOn = true;

            _clock.Tick += NextFrame;
            new Thread(CpuLoop)
            {
                Name         = "Z80CPULOOP",
                IsBackground = true
            }.Start();


            _lastFrameTime     = DateTime.Now;
            Gpu.VBlankStarted += (_, __) =>
            {
                _framesCount++;

                FrameDelta     = DateTime.Now - _lastFrameTime;
                _lastFrameTime = DateTime.Now;
            };
        }
Beispiel #3
0
        public GameBoy(ICartridge cartridge, IClock clock, bool preferGbcMode)
        {
            GbcMode = preferGbcMode && (cartridge.GameBoyColorFlag & GameBoyColorFlag.SupportsColor) != 0;

            Components = new List <IGameBoyComponent>
            {
                (Cartridge = cartridge),
                (Memory = new GameBoyMemory(this)),
                (Cpu = new GameBoyCpu(this, clock)),
                (Gpu = new GameBoyGpu(this)),
                (Spu = new GameBoySpu(this)),
                (KeyPad = new GameBoyPad(this)),
                (Timer = new GameBoyTimer(this))
            }.AsReadOnly();

            foreach (var component in Components)
            {
                component.Initialize();
            }

            Reset();
            IsPoweredOn = true;
        }
Beispiel #4
0
 public GameBoyTimer(GameBoyMemory m, GameBoyInterrupts i)
 {
     gbMemory     = m;
     gbInterrupts = i;
 }
Beispiel #5
0
    void InitalizeComponent()
    {
        Application.targetFrameRate = 60;

        //Create display
        texture = new Texture2D(width, height);
        Sprite sprite = Sprite.Create(texture, new Rect(0, 0, width, height), Vector2.zero, 1);

        sprite.name = "Screen";
        GogbGraphic = GameObject.Find("GameBoyScreen");
        GogbGraphic.GetComponent <SpriteRenderer>().sprite = sprite;
        Vector2 pivotPoints = new Vector2(0.0f, 0.0f);

        GogbGraphic.GetComponent <RectTransform>().pivot = pivotPoints;


        //Load Cartiridge
        gbCart = new GameBoyCartiridge(0);
        try {
            gbCart.LoadRom(pathToRom);
        } catch {
            Debug.Log("NO ROM LOADED");
        }


        //Create memory
        gbMemory = new GameBoyMemory(gbCart);
        bool reset = false;

        try {
            gbMemory.LoadBios(pathToBios);
        } catch {
            reset = true;
        }

        //Create Interrupts
        gbInterrupts = new GameBoyInterrupts(gbMemory);

        //Create Timer
        gbTimer = new GameBoyTimer(gbMemory, gbInterrupts);
        gbMemory.AddTimer(gbTimer);

        //Create CPU
        gbCPU = new GameBoyCPU(gbMemory, gbInterrupts);
        if (reset && !GameBoyCartiridge.IsGameBoyColor)
        {
            gbCPU.ResetGBNoBios();
        }
        else if (reset && GameBoyCartiridge.IsGameBoyColor)
        {
            gbCPU.ResetCGBNoBios();
        }

        //Create GPU
        gbGraphic = new GameBoyGraphic(width, height, texture, gbInterrupts, gbMemory);
        //Create Audio
        gbAudio = new GameBoyAudio();
        gbMemory.AddGraphics(gbGraphic);
        gbMemory.AddAudio(gbAudio);

        //Create Keyboard
        gbJoyPad = new GameBoyJoyPad(gbInterrupts, gbMemory);
        Debug.Log(GameBoyCartiridge.Title);
        Debug.Log(GameBoyCartiridge.IsGameBoyColor);
        Debug.Log(gbCart.CartiridgeType.ToString("X2"));
    }
Beispiel #6
0
 public Z80Disassembler(GameBoyMemory memory)
 {
     _memory = memory;
 }
Beispiel #7
0
 public GameBoyJoyPad(GameBoyInterrupts interrupts, GameBoyMemory memory)
 {
     this.interrupts = interrupts;
     this.memory     = memory;
     this.UIPanel    = GameObject.Find("UI");
 }
Beispiel #8
0
 public GameBoyInterrupts(GameBoyMemory m)
 {
     memory = m;
 }