Пример #1
0
        protected override void Initialize()
        {
            this.IsMouseVisible = true;

            this.IsFixedTimeStep   = true;
            this.TargetElapsedTime = new TimeSpan(4000); // only if IsFixedTimeStep is true
            bool testROM = true;

            if (testROM)
            {
                CPU.instructionFecther.LoadSourceFile(@".\ROM\SpaceInvaders1978\TEST-ROM2.json", SourceFileFormat.JSON_HEX);
            }
            else
            {
                CPU.instructionFecther.LoadSourceFile(@".\ROM\SpaceInvaders1978\INVADERS-H.json", SourceFileFormat.JSON_HEX);
                //Debug.Write("Next file2\n");
                CPU.instructionFecther.LoadSourceFile(@".\ROM\SpaceInvaders1978\INVADERS-G.json", SourceFileFormat.JSON_HEX);
                //Debug.Write("Next file3\n");
                CPU.instructionFecther.LoadSourceFile(@".\ROM\SpaceInvaders1978\INVADERS-f.json", SourceFileFormat.JSON_HEX);
                //Debug.Write("Next file4\n");
                CPU.instructionFecther.LoadSourceFile(@".\ROM\SpaceInvaders1978\INVADERS-E.json", SourceFileFormat.JSON_HEX);
                CPU.instructionFecther.ParseCurrentContent();
            }


            List <string> spaceInvadersAsm     = new List <string>();
            string        SpaceInvadersAsmPath = @"..\..\..\..\Misc\OutputFiles\SpaceInvaders.8080asm";

            if (File.Exists(SpaceInvadersAsmPath))
            {
                File.Delete(SpaceInvadersAsmPath);
            }
            File.WriteAllLines(SpaceInvadersAsmPath, CPU.instructionFecther.FetchAllCodeLines());

            Memory.RAM2File(); //NO WRITING FOR THE TIME BEING
            Memory.RAM2FileHTML();
            int memoryPointer = 0;

            foreach (byte _byte in CPU.instructionFecther.FetchAllCodeBytes())
            {
                Memory.RAMMemory[memoryPointer] = _byte;
                memoryPointer++;
                Memory.TextSectionSize++;
            }

            //CPU.instructionFecther.ResetInstructionIterator(); //this is overly complicated, better get it from RAM

            DisplayBuffer.Init(GraphicsDevice, Color.Black, Color.White);
            DisplayBuffer.GenerateDisplay(); //Inverted colours. This is bad test, first frame will come emtpy always

            DisplayBuffer.GenerateRAMDisplay();

            screenBitmap = DisplayBuffer.videoTexture; // First screencap
            RAMBitmap    = DisplayBuffer.RAMtexture;   // First screencap



            base.Initialize();
        }
Пример #2
0
        protected override void Update(GameTime gameTime)
        {
            keyboardState = Keyboard.GetState();
            mouseState    = Mouse.GetState();
            if (keyboardState.IsKeyDown(Keys.Escape))
            {
                Exit();
            }

            if (mouseState.X < positionOneCycleButton.X + positionOneCycleButton.Width &&
                mouseState.X > positionOneCycleButton.X &&
                mouseState.Y < positionOneCycleButton.Y + positionOneCycleButton.Height &&
                mouseState.Y > positionOneCycleButton.Y)
            {
                oneCycleHover = true;
            }
            else
            {
                oneCycleHover = false;
            }

            if (mouseState.LeftButton == ButtonState.Pressed)
            {
                leftButtonPressed++;
            }
            else
            {
                leftButtonPressed = 0;
            }

            clickOneCycle = (oneCycleHover &&
                             mouseState.LeftButton == ButtonState.Released &&
                             oldMouseState.LeftButton == ButtonState.Pressed);

            if (true || clickOneCycle || leftButtonPressed > 20 || keyboardState.IsKeyDown(Keys.P))
            {
                if (CPU.cyclesCounter % 100 == 0)
                {
                    DisplayBuffer.GenerateRAMDisplay();
                }



                CPU.Cycle();
                CPU.cyclesCounter++;
                CPU.cyclesPerSecond++;

                if (CPU.cyclesCounter == 49000)
                {
                    this.TargetElapsedTime = new TimeSpan(4000);
                }
            }



            //Debug.WriteLine("Ticks:" + ticks + " Pc: " + CPU.programCounter);
            //Read a instruction
            //Execute instruction

            //string instruction = CPU.instructionFecther.FetchNextInstruction().Item1;

            // TODO: Add your update logic here
            oldMouseState = mouseState;
            base.Update(gameTime);
        }