Beispiel #1
0
 // 8
 public static void Arithmetics(Chip8 chip8)
 {
     arithmetics[chip8.Opcode & 0x000F](chip8);
 }
Beispiel #2
0
 static void FThree(ushort op, Chip8 emu)
 {
     emu.memory[emu.indexReg]     = (byte)(emu.V[(op & 0x0F00) >> 8] / 100);
     emu.memory[emu.indexReg + 1] = (byte)((emu.V[(op & 0x0F00) >> 8] / 10) % 10);
     emu.memory[emu.indexReg + 2] = (byte)((emu.V[(op & 0x0F00) >> 8] % 100) % 10);
 }
Beispiel #3
0
 static void NOP(ushort op, Chip8 emu)
 {
 }
Beispiel #4
0
        static void FE(ushort op, Chip8 emu)
        {
            int X = (op & 0x0F00) >> 8;

            emu.indexReg += emu.V[X];
        }
Beispiel #5
0
        static void FNine(ushort op, Chip8 emu)
        {
            int X = (op & 0x0F00) >> 8;

            emu.indexReg = (ushort)(emu.V[X] * 5);
        }
Beispiel #6
0
        // 0
        public static void Zeros(Chip8 chip8)
        {
            var kk = Utils.GetKK(chip8.Opcode);

            zeros[kk](chip8);
        }
Beispiel #7
0
        public static void Main(string[] args)
        {
            //Console.WriteLine("Hello World!");

            //byte[] loadedCode = File.ReadAllBytes("pong.rom");
            byte[] loadedCode = File.ReadAllBytes("INVADERS");
            //byte[] loadedCode = File.ReadAllBytes("test_opcode.ch8");
            //byte[] loadedCode = File.ReadAllBytes("BC_test.ch8");
            chip8 = new Chip8(loadedCode);
            RenderWindow app = new RenderWindow(new VideoMode(800, 600), "chip8 emu");

            app.Closed += new EventHandler(OnClose);

            float          TILESIZEX = (float)app.Size.X / 64;
            float          TILESIZEY = (float)app.Size.Y / 32;
            RectangleShape shape     = new RectangleShape(new Vector2f(TILESIZEX, TILESIZEY));

            app.KeyPressed  += OnKeyPressed;
            app.KeyReleased += OnKeyReleased;

            Font font = new Font("Arial.ttf");
            Text text = new Text("", font);

            //app.KeyReleased +=
            // Start the game loop
            //app.SetFramerateLimit(60);
            //app.SetVerticalSyncEnabled(true);
            while (app.IsOpen)
            {
                chip8.Execute();
                // Process events
                app.DispatchEvents();

                //if (chip8.displayUpdated)
                {
                    // Clear screen
                    app.Clear();

                    for (int y = 0; y < 32; y++)
                    {
                        for (int x = 0; x < 64; x++)
                        {
                            shape.Position = new Vector2f(x * TILESIZEX, y * TILESIZEY);
                            if (chip8.display[x, y] == 1)
                            {
                                shape.FillColor = Color.Blue;
                            }
                            else
                            {
                                shape.FillColor = Color.Black;
                            }
                            app.Draw(shape);
                        }
                        //Console.WriteLine();
                    }

                    List <string> lines = chip8.GetCurrentLine();
                    for (int i = 0; i < lines.Count; i++)
                    {
                        text.DisplayedString = lines[i];
                        text.Position        = new Vector2f(0, i * 25);
                        app.Draw(text);
                    }

                    for (int i = 0; i < 16; i++)
                    {
                        text.DisplayedString = chip8.inputs[i] ? "1" : "0";
                        text.Position        = new Vector2f((i % 4) * 25 + 200, (i / 4) * 25);
                        app.Draw(text);
                    }
                    app.Display();
                    chip8.displayUpdated = false;
                }

                //for (int i = 0; i < 16; i++)
                //  chip8.inputs[i] = false;

                // Draw the sprite


                // Draw the string

                // Sleep to slow down emulation speed
            }
        }
Beispiel #8
0
 //0xB
 static void B(ushort op, Chip8 emu)
 {
     emu.progCounter = (ushort)(emu.V[0] + (op & 0x0FFF));
 }
Beispiel #9
0
 //0xF
 static void F(ushort op, Chip8 emu)
 {
     fOpFunctions[op & 0x000F](op, emu);
 }
Beispiel #10
0
 //0x8
 static void Eight(ushort op, Chip8 emu)
 {
     eightOpFunctions[op & 0x000F](op, emu);
 }
Beispiel #11
0
 //0xA
 static void A(ushort op, Chip8 emu)
 {
     emu.indexReg = (ushort)(op & 0x0FFF);
 }
Beispiel #12
0
        //0x6
        /// <summary>
        /// 0x6XNN
        /// Set V[X]to NN
        /// </summary>
        /// <param name="op">Op.</param>
        /// <param name="emu">Emu.</param>
        static void Six(ushort op, Chip8 emu)
        {
            byte X = (byte)((op & 0x0F00) >> 8);

            emu.V[X] = (byte)(op & 0x00FF);
        }
Beispiel #13
0
 /// <summary>
 /// 0x2NNN
 /// Calls the address at NNN
 /// </summary>
 /// <param name="op">Op.</param>
 /// <param name="emu">Emu.</param>
 static void Two(ushort op, Chip8 emu)
 {
     emu.stack[emu.stackPointer] = emu.progCounter;
     ++emu.stackPointer;
     emu.progCounter = (ushort)(op & 0x0FFF);
 }
Beispiel #14
0
 /// <summary>
 /// 0x1NNN
 /// Jump to the address at NNN
 /// </summary>
 /// <param name="op">Op containing address</param>
 /// <param name="emu">Emu.</param>
 static void One(ushort op, Chip8 emu)
 {
     emu.progCounter = (ushort)(op & 0x0FFF);
 }
Beispiel #15
0
        // ANNN
        public static void Mvi_NNN(Chip8 chip8)
        {
            var nnn = Utils.GetNNN(chip8.Opcode);

            chip8.I = (ushort)nnn;
        }
Beispiel #16
0
        static void FSeven(ushort op, Chip8 emu)
        {
            int X = (op & 0x0F00) >> 8;

            emu.V[X] = emu.delayTimer;
        }
Beispiel #17
0
        // BNNN
        public static void Jmi_NNN(Chip8 chip8)
        {
            var nnn = Utils.GetNNN(chip8.Opcode);

            chip8.PC = (ushort)(chip8.V[0] + nnn);
        }
Beispiel #18
0
        static void FEight(ushort op, Chip8 emu)
        {
            int X = (op & 0x0F00) >> 8;

            emu.soundTimer = emu.V[X];
        }
Beispiel #19
0
        // E
        public static void Keyboard(Chip8 chip8)
        {
            var kk = Utils.GetKK(chip8.Opcode);

            keys[kk](chip8);
        }
Beispiel #20
0
 public void Setup()
 {
     emu = new Chip8();
     rnd = new Random();
 }