Example #1
0
        private static void InitTestContext(out SnesPlatform snes, out MemoryBin romBin, out int writeOffset)
        {
            snes = new SnesPlatform();
            romBin = new MemoryBin(snes.Memory, 0, snes.Memory.Length);

            snes.Interpreter.RethrowExecutionExceptions = true;
            snes.Interpreter.Trace = true;

            snes.Encoder.EnableInstructionValidation = true;

            writeOffset = 0;
        }
Example #2
0
File: CPU.cs Project: DINKIN/snes
        public CPU(SnesPlatform platform)
        {
            if (platform == null)
                throw new ArgumentNullException("platform");

            Platform = platform;

            // TODO vérifier les plages
            DirectPage = new MemoryBin(platform.Memory, 0, 256);

            RAM = new SnesMemoryMappingBin(platform.Memory);

            NativeStackBin = new MemoryBin(platform.Memory, 0x7E0000, 0x00FFFF + 1);
            EmulationStackBin = new MemoryBin(platform.Memory, NativeStackBin.Start + 0x100, 0xFF + 1);

            DecodeTable = new InstructionsDecodeTable(this);

            Reset();
        }
Example #3
0
        public MainWindow()
        {
            InitializeComponent();

            InitializeGraphics();

            DataContext = this;

#warning TODO A changer lorsqu'il y aura un vrai rendu avec une horloge
            CompositionTarget.Rendering += new EventHandler(CompositionTarget_Rendering);

            using (var strm = new System.IO.FileStream(System.IO.Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location) + "\\SnesInitializationROM.smc",
                System.IO.FileMode.Open, System.IO.FileAccess.Read))
            {
                var snes = new SnesPlatform();

                var romBin = Loader.LoadInto(strm, 0, 0, snes.Memory, 0);

                using (var decodeOut = new System.IO.FileStream(System.IO.Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location) + "\\init-decode.txt",
                    System.IO.FileMode.Create))
                {
                    using (var wr = new System.IO.StreamWriter(decodeOut))
                    {
                        snes.Decoder.Decode(romBin, 0).Print(wr);

                        wr.WriteLine();
                        wr.WriteLine();
                        wr.WriteLine();
                        wr.WriteLine("ALTERATION DU DEBUT");
                        wr.WriteLine();
                        wr.WriteLine();

                        int writeOffset = 0;

                        for (int i = 0; i < 8; i++)
                            snes.Encoder.Write(romBin, ref writeOffset, OpCodes.NOP);

                        snes.Encoder.WriteCallbackInvoke(romBin, ref writeOffset, (i) =>
                        {
                            Debug.WriteLine(snes.CPU.ACC);
                        });
                        snes.Encoder.Write(romBin, ref writeOffset, OpCodes.ADC, AddressingModes.ImmediateMemoryFlag, ArgumentType.I1, 24);
                        snes.Encoder.Write(romBin, ref writeOffset, OpCodes.ADC, AddressingModes.ImmediateMemoryFlag, ArgumentType.I1, 26);
                        snes.Encoder.Write(romBin, ref writeOffset, OpCodes.ADC, AddressingModes.ImmediateMemoryFlag, ArgumentType.I1, 0);
                        snes.Encoder.WriteCallbackInvoke(romBin, ref writeOffset, (i) =>
                        {
                            Debug.Assert(snes.CPU.ACC == 24 + 26);
                        });
                        snes.Encoder.Write(romBin, ref writeOffset, OpCodes.STP);

                        snes.Decoder.Decode(romBin, 0).Print(wr);

                        snes.Interpreter.Interpret(romBin, 0);

                        wr.Flush();
                        decodeOut.Flush();
                    }
                }
            }

            //using (var strm = new System.IO.FileStream(System.IO.Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location) + "\\Super Mario All-Stars.smc",
            //    System.IO.FileMode.Open, System.IO.FileAccess.Read))
            //{
            //    int romSize, ramSize;

            //    bool hasHeader = true;
            //    var headerPosition = hasHeader ? RomHeaderConstants.HeaderedLoROM : RomHeaderConstants.HeaderLessLoROM;

            //    Loader.GetROMParameters(strm, 0, headerPosition, out romSize, out ramSize);

            //    var snes = new SnesPlatform(romSize, ramSize);

            //    var romBin = Loader.LoadInto(strm, 0, headerPosition, snes.Memory, 0);

            //    using (var decodeOut = new System.IO.FileStream(System.IO.Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location) + "\\decode.txt",
            //        System.IO.FileMode.Create))
            //    {
            //        using(var wr = new System.IO.StreamWriter(decodeOut))
            //        {
            //            snes.Decoder.Decode(romBin, 0).Print(wr);

            //            wr.Flush();
            //            decodeOut.Flush();
            //        }
            //    }

            //    snes.Interpreter.Interpret(romBin, 0);

            //    //while (strm.Position < strm.Length - 1000)
            //    //    MiniDecode(strm);

            //    MessageBox.Show("");
            //}
        }