Example #1
0
        public Window(GameWindowSettings settings, NativeWindowSettings nativeSettings) : base(settings, nativeSettings)
        {
            device  = ALC.OpenDevice("");
            context = ALC.CreateContext(device, new ALContextAttributes()
            {
                Frequency = 44100
            });

            ALC.MakeContextCurrent(context);

            Console.WriteLine("Version : " + AL.Get(ALGetString.Version));
            Console.WriteLine("Vendor  : " + AL.Get(ALGetString.Vendor));
            Console.WriteLine("Renderer: " + AL.Get(ALGetString.Renderer));

            _gameboy = new Gameboy(() => { return(new AudioEmitter()); });

            string path = "Roms/Games/Mario Deluxe.gbc ";

            string[] args = Environment.GetCommandLineArgs();
            if (args.Length > 1)
            {
                path = args[1];
            }

            if (!File.Exists(path))
            {
                Console.WriteLine(path);
                Console.WriteLine("Invalid usage... GBSharp [rom]");

                foreach (string s in args)
                {
                    Console.WriteLine("S: " + s);
                }

                throw new Exception();
            }

            Cartridge cartridge = Cartridge.Load(path);

            //Cartridge cartridge = GetNextTestRom();
            //CartridgeLoader.LoadDataIntoMemory(_mmu, GetNextTestRom(), 0x00);
            _gameboy.LoadCartridge(cartridge);

            thread   = new Thread(new ThreadStart(_gameboy.Run));
            _isAlive = true;
            thread.Start();
        }
Example #2
0
        /// <summary>
        /// Allows the game to perform any initialization it needs to before starting to run.
        /// This is where it can query for any required services and load any non-graphic
        /// related content.  Calling base.Initialize will enumerate through any components
        /// and initialize them as well.
        /// </summary>
        protected override void Initialize()
        {
            // TODO: Add your initialization logic here
            _gameboy   = new Gameboy(() => { return(new AudioEmitter()); });
            _debugMode = false;
            //_gameboy.Debug();

            //_cpu.SetPalette(new PPU.Color(8, 24, 32), new PPU.Color(52, 104, 86), new PPU.Color(136, 192, 112), new PPU.Color(224, 248, 208));

            graphics.PreferMultiSampling            = false;
            graphics.SynchronizeWithVerticalRetrace = false;
            IsFixedTimeStep = true;
            if (!_debugMode)
            {
                //graphics.IsFullScreen = true;
                //graphics.PreferredBackBufferWidth = GraphicsDevice.DisplayMode.Width;
                //graphics.PreferredBackBufferHeight = GraphicsDevice.DisplayMode.Height;
                graphics.PreferredBackBufferWidth  = PPU.SCREEN_WIDTH * 3;
                graphics.PreferredBackBufferHeight = PPU.SCREEN_HEIGHT * 3;
            }
            graphics.ApplyChanges();

            gameScale = 2f;

            while (PPU.SCREEN_WIDTH * gameScale <= graphics.PreferredBackBufferWidth && PPU.SCREEN_HEIGHT * gameScale <= graphics.PreferredBackBufferHeight)
            {
                gameScale++;
            }

            gameScale -= 1;

            //_gameboy.Debug();
            //_cpu.StartInBios();
            //_gameboy.StartInBios();

            _frame  = new Texture2D(GraphicsDevice, PPU.SCREEN_WIDTH, PPU.SCREEN_HEIGHT);
            _tiles  = new Texture2D(GraphicsDevice, 128, 192);
            _tiles2 = new Texture2D(GraphicsDevice, 128, 192);

            //CartridgeLoader.LoadDataIntoMemory(_mmu, CartridgeLoader.LoadCart("Roms/opus5.gb"), 0x00);

            string path = "Roms/Games/Pokemon Silver.gbc";

            string[] args = Environment.GetCommandLineArgs();
            if (args.Length > 1)
            {
                path = args[1];
            }

            if (!File.Exists(path))
            {
                Console.WriteLine(path);
                Console.WriteLine("Invalid usage... GBSharp [rom]");

                foreach (string s in args)
                {
                    Console.WriteLine("S: " + s);
                }

                Exit();
                throw new Exception();
            }

            Cartridge cartridge = Cartridge.Load(path);

            //Cartridge cartridge = GetNextTestRom();
            //CartridgeLoader.LoadDataIntoMemory(_mmu, GetNextTestRom(), 0x00);
            _gameboy.LoadCartridge(cartridge);

            this.Window.Title = cartridge.Name;

            oldState = Keyboard.GetState();

            colors     = new Color[PPU.SCREEN_WIDTH * PPU.SCREEN_HEIGHT];
            tileColors = new Color[128 * 192];

            Exiting += new EventHandler <EventArgs>(OnExit);

            thread = new Thread(new ThreadStart(_gameboy.Run));
            thread.Start();

            base.Initialize();

            Directory.CreateDirectory("Pictures");
        }
Example #3
0
        /// <summary>
        /// Allows the game to run logic such as updating the world,
        /// checking for collisions, gathering input, and playing audio.
        /// </summary>
        /// <param name="gameTime">Provides a snapshot of timing values.</param>
        protected override void Update(GameTime gameTime)
        {
            if (task.IsCompleted)
            {
                if (cartridge == null)
                {
                    cartridge = task.Result;
                    _gameboy.LoadCartridge(cartridge);
                    thread.Start();
                }
                if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed)
                {
                    Close();
                    Exit();
                }

                dpad.Reset();
                start.Reset();
                select.Reset();
                btnB.Reset();
                btnA.Reset();

                TouchCollection tc = TouchPanel.GetState();

                foreach (TouchLocation tl in tc)
                {
                    if (dpad.BeingHandled && tl.Id == dpad.TLIndex)
                    {
                        continue;
                    }

                    int mx = (int)tl.Position.X, my = (int)tl.Position.Y;
                    if (tl.State == TouchLocationState.Pressed)
                    {
                        dpad.SetInput(mx, my, tl.Id);
                    }
                    start.HandleInput(mx, my);
                    select.HandleInput(mx, my);
                    btnB.HandleInput(mx, my);
                    btnA.HandleInput(mx, my);
                }

                if (dpad.BeingHandled)
                {
                    bool stillValid = tc.FindById(dpad.TLIndex, out var tl);
                    if (!stillValid || tl.State == TouchLocationState.Released)
                    {
                        dpad.ResetInput();
                    }
                    else
                    {
                        dpad.HandleInput((int)tl.Position.X, (int)tl.Position.Y);
                    }
                }

                float deadzone = .35f;
                _gameboy.SetInput(Input.Button.Up, dpad.YAxis < -deadzone);
                _gameboy.SetInput(Input.Button.Down, dpad.YAxis > deadzone);
                _gameboy.SetInput(Input.Button.Left, dpad.XAxis < -deadzone);
                _gameboy.SetInput(Input.Button.Right, dpad.XAxis > deadzone);

                _gameboy.SetInput(Input.Button.Start, start.Down);
                _gameboy.SetInput(Input.Button.Select, select.Down);
                _gameboy.SetInput(Input.Button.B, btnB.Down);
                _gameboy.SetInput(Input.Button.A, btnA.Down);

                //_gameboy.ExecuteFrame();

                if (_gameboy.GetFrameBufferCount() > 0)
                {
                    int[] frameBuffer = _gameboy.DequeueFrameBuffer();

                    for (int i = 0; i < frameBuffer.Length; i += 4)
                    {
                        colors[i / 4] = new Color(frameBuffer[i], frameBuffer[i + 1], frameBuffer[i + 2], frameBuffer[i + 3]);
                    }

                    _frame.SetData <Color>(colors);
                }
            }

            base.Update(gameTime);
        }