Esempio n. 1
0
        public MSX(CoreComm comm, GameInfo game, byte[] rom, object settings, object syncSettings)
        {
            ServiceProvider = new BasicServiceProvider(this);
            Settings        = (MSXSettings)settings ?? new MSXSettings();
            SyncSettings    = (MSXSyncSettings)syncSettings ?? new MSXSyncSettings();
            CoreComm        = comm;

            RomData = rom;

            if (RomData.Length % BankSize != 0)
            {
                Array.Resize(ref RomData, ((RomData.Length / BankSize) + 1) * BankSize);
            }

            MSX_Pntr = LibMSX.MSX_create();

            blip_L.SetRates(3579545, 44100);
            blip_R.SetRates(3579545, 44100);

            (ServiceProvider as BasicServiceProvider).Register <ISoundProvider>(this);

            SetupMemoryDomains();

            InputCallbacks = new InputCallbackSystem();

            //var serviceProvider = ServiceProvider as BasicServiceProvider;
            //serviceProvider.Register<ITraceable>(Tracer);
        }
Esempio n. 2
0
        private void SyncState(Serializer ser)
        {
            ser.BeginSection("MSX");

            if (SaveRAM != null)
            {
                ser.Sync(nameof(SaveRAM), ref SaveRAM, false);
            }

            ser.Sync(nameof(SaveRamBank), ref SaveRamBank);

            ser.Sync("Frame", ref _frame);
            ser.Sync("LagCount", ref _lagCount);
            ser.Sync("IsLag", ref _isLag);

            ser.EndSection();

            if (ser.IsReader)
            {
                ser.Sync(nameof(MSX_core), ref MSX_core, false);
                LibMSX.MSX_load_state(MSX_Pntr, MSX_core);
            }
            else
            {
                LibMSX.MSX_save_state(MSX_Pntr, MSX_core);
                ser.Sync(nameof(MSX_core), ref MSX_core, false);
            }
        }
Esempio n. 3
0
        void SetupMemoryDomains()
        {
            var domains = new List <MemoryDomain>
            {
                new MemoryDomainDelegate(
                    "System Bus",
                    0x10000,
                    MemoryDomain.Endian.Little,
                    (addr) => LibMSX.MSX_getsysbus(MSX_Pntr, (int)(addr & 0xFFFF)),
                    (addr, value) => { },
                    1),
                new MemoryDomainDelegate(
                    "VRAM",
                    0x4000,
                    MemoryDomain.Endian.Little,
                    (addr) => LibMSX.MSX_getvram(MSX_Pntr, (int)(addr & 0x3FFF)),
                    (addr, value) => { },
                    1),
            };

            if (SaveRAM != null)
            {
                var saveRamDomain = new MemoryDomainDelegate("Save RAM", SaveRAM.Length, MemoryDomain.Endian.Little,
                                                             addr => SaveRAM[addr],
                                                             (addr, value) => { SaveRAM[addr] = value; SaveRamModified = true; }, 1);
                domains.Add(saveRamDomain);
            }

            SyncAllByteArrayDomains();

            MemoryDomains = new MemoryDomainList(_byteArrayDomains.Values.Concat(domains).ToList());
            (ServiceProvider as BasicServiceProvider).Register <IMemoryDomains>(MemoryDomains);

            _memoryDomainsInit = true;
        }
Esempio n. 4
0
        private void MakeTrace(int t)
        {
            StringBuilder new_d = new StringBuilder(Disasm_Length);
            StringBuilder new_r = new StringBuilder(Reg_String_Length);

            LibMSX.MSX_getdisassembly(MSX_Pntr, new_d, t, Disasm_Length);
            LibMSX.MSX_getregisterstate(MSX_Pntr, new_r, t, Reg_String_Length);

            Tracer.Put(new(disassembly: new_d.ToString().PadRight(36), registerInfo: new_r.ToString()));
        }
Esempio n. 5
0
        public bool FrameAdvance(IController controller, bool render, bool rendersound)
        {
            _controller = controller;

            byte ctrl1_byte = 0;

            if (_controller.IsPressed("P1 Up"))
            {
                ctrl1_byte |= 0x01;
            }
            if (_controller.IsPressed("P1 Down"))
            {
                ctrl1_byte |= 0x02;
            }
            if (_controller.IsPressed("P1 Left"))
            {
                ctrl1_byte |= 0x04;
            }
            if (_controller.IsPressed("P1 Right"))
            {
                ctrl1_byte |= 0x08;
            }
            if (_controller.IsPressed("P1 B1"))
            {
                ctrl1_byte |= 0x10;
            }
            if (_controller.IsPressed("P1 B2"))
            {
                ctrl1_byte |= 0x20;
            }

            if (_controller.IsPressed("P1 Start"))
            {
                ctrl1_byte |= 0x80;
            }

            _frame++;

            if (Tracer.Enabled)
            {
                tracecb = MakeTrace;
            }
            else
            {
                tracecb = null;
            }

            LibMSX.MSX_settracecallback(MSX_Pntr, tracecb);

            LibMSX.MSX_frame_advance(MSX_Pntr, ctrl1_byte, 0, true, true);

            return(true);
        }
Esempio n. 6
0
        public void Dispose()
        {
            if (MSX_Pntr != IntPtr.Zero)
            {
                LibMSX.MSX_destroy(MSX_Pntr);
                MSX_Pntr = IntPtr.Zero;
            }

            if (blip != null)
            {
                blip.Dispose();
                blip = null;
            }
        }
Esempio n. 7
0
        public void GetSamplesSync(out short[] samples, out int nsamp)
        {
            uint f_clock = LibMSX.MSX_get_audio(MSX_Pntr, Aud, ref num_samp);

            for (int i = 0; i < num_samp; i++)
            {
                blip.AddDelta((uint)Aud[i * 2], Aud[i * 2 + 1]);
            }

            blip.EndFrame(f_clock);

            nsamp   = blip.SamplesAvailable();
            samples = new short[nsamp * 2];

            blip.ReadSamples(samples, nsamp, true);
        }
Esempio n. 8
0
        public MSX(CoreComm comm, GameInfo game, byte[] rom, object settings, object syncSettings)
        {
            ServiceProvider = new BasicServiceProvider(this);
            Settings        = (MSXSettings)settings ?? new MSXSettings();
            SyncSettings    = (MSXSyncSettings)syncSettings ?? new MSXSyncSettings();
            CoreComm        = comm;

            RomData = rom;

            if (RomData.Length % BankSize != 0)
            {
                Array.Resize(ref RomData, ((RomData.Length / BankSize) + 1) * BankSize);
            }

            MSX_Pntr = LibMSX.MSX_create();
            LibMSX.MSX_load(MSX_Pntr, RomData, (uint)RomData.Length, 0);

            blip_L.SetRates(3579545, 44100);
            blip_R.SetRates(3579545, 44100);

            (ServiceProvider as BasicServiceProvider).Register <ISoundProvider>(this);

            SetupMemoryDomains();

            InputCallbacks = new InputCallbackSystem();

            Header_Length     = LibMSX.MSX_getheaderlength(MSX_Pntr);
            Disasm_Length     = LibMSX.MSX_getdisasmlength(MSX_Pntr);
            Reg_String_Length = LibMSX.MSX_getregstringlength(MSX_Pntr);

            StringBuilder new_header = new StringBuilder(Header_Length);

            LibMSX.MSX_getheader(MSX_Pntr, new_header, Header_Length);



            Console.WriteLine(Header_Length + " " + Disasm_Length + " " + Reg_String_Length);

            Tracer = new TraceBuffer {
                Header = new_header.ToString()
            };

            var serviceProvider = ServiceProvider as BasicServiceProvider;

            serviceProvider.Register <ITraceable>(Tracer);
        }
Esempio n. 9
0
        public bool FrameAdvance(IController controller, bool render, bool rendersound)
        {
            _controller = controller;

            _frame++;

            if (Tracer.Enabled)
            {
                tracecb = MakeTrace;
            }
            else
            {
                tracecb = null;
            }

            LibMSX.MSX_settracecallback(MSX_Pntr, tracecb);

            LibMSX.MSX_frame_advance(MSX_Pntr, 0, 0, true, true);

            return(true);
        }
Esempio n. 10
0
        public void GetSamplesSync(out short[] samples, out int nsamp)
        {
            uint f_clock = LibMSX.MSX_get_audio(MSX_Pntr, Aud_L, Aud_R, ref num_samp_L, ref num_samp_R);

            for (int i = 0; i < num_samp_L; i++)
            {
                blip_L.AddDelta(Aud_L[i * 2], (int)Aud_L[i * 2 + 1]);
            }

            for (int i = 0; i < num_samp_R; i++)
            {
                blip_R.AddDelta(Aud_R[i * 2], (int)Aud_R[i * 2 + 1]);
            }

            blip_L.EndFrame(f_clock);
            blip_R.EndFrame(f_clock);

            nsamp   = Math.Max(Math.Max(blip_L.SamplesAvailable(), blip_R.SamplesAvailable()), 1);
            samples = new short[nsamp * 2];

            blip_L.ReadSamplesLeft(samples, nsamp);
            blip_R.ReadSamplesRight(samples, nsamp);
        }
Esempio n. 11
0
        public MSX(CoreComm comm, GameInfo game, byte[] rom, MSX.MSXSettings settings, MSX.MSXSyncSettings syncSettings)
        {
            ServiceProvider = new BasicServiceProvider(this);
            Settings        = (MSXSettings)settings ?? new MSXSettings();
            SyncSettings    = (MSXSyncSettings)syncSettings ?? new MSXSyncSettings();

            RomData = new byte[rom.Length];

            // look up game in db before transforming ROM
            var    hash_md5 = MD5Checksum.ComputePrefixedHex(rom);
            var    gi       = Database.CheckDatabase(hash_md5);
            var    dict     = (gi != null) ? gi.GetOptions() : null;
            string s_mapper;

            for (int i = 0; i < rom.Length; i++)
            {
                RomData[i] = rom[i];
            }

            int size = RomData.Length;

            int mapper_1 = 0;

            if (RomData.Length % BankSize != 0)
            {
                Array.Resize(ref RomData, ((RomData.Length / BankSize) + 1) * BankSize);
            }

            // we want all ROMS to be multiples of 64K for easy memory mapping later
            if (RomData.Length < 0x10000)
            {
                Array.Resize(ref RomData, 0x10000);
            }
            else
            {
                // Assume default konami style mapper
                if (gi == null)
                {
                    mapper_1 = 3;
                    Console.WriteLine("Using Ascii 8 KB Mapper");
                }
                else if (!dict.TryGetValue("mapper", out s_mapper))
                {
                    mapper_1 = 3;
                    Console.WriteLine("Using Ascii 8 KB Mapper");
                }
                else
                {
                    if (s_mapper == "1")
                    {
                        mapper_1 = 1;
                        Console.WriteLine("Using Konami Mapper");
                    }

                    if (s_mapper == "2")
                    {
                        mapper_1 = 2;
                        Console.WriteLine("Using Konami Mapper with SCC");
                    }
                }
            }

            // if the original was not 64 or 48 k, move it (may need to do this case by case)

            if (size == 0x8000)
            {
                for (int i = 0x7FFF; i >= 0; i--)
                {
                    RomData[i + 0x4000] = RomData[i];
                }
                for (int i = 0; i < 0x4000; i++)
                {
                    RomData[i] = 0;
                }
            }

            if (size == 0x4000)
            {
                for (int i = 0; i < 0x4000; i++)
                {
                    RomData[i + 0x4000] = RomData[i];
                    RomData[i + 0x8000] = RomData[i];
                    RomData[i + 0xC000] = RomData[i];
                }
            }

            // loook for combination BIOS + BASIC files first
            byte[] loc_bios = null;
            if (SyncSettings.Region_Setting == MSXSyncSettings.RegionType.USA)
            {
                loc_bios = comm.CoreFileProvider.GetFirmware(new("MSX", "bios_basic_usa"));
            }
            else
            {
                loc_bios = comm.CoreFileProvider.GetFirmwareOrThrow(new("MSX", "bios_basic_jpn"));
            }

            // look for individual files (not implemented yet)
            if (loc_bios == null)
            {
                throw new Exception("Cannot load, no BIOS files found for selected region.");
            }

            if (loc_bios.Length == 32768)
            {
                Bios  = new byte[0x4000];
                Basic = new byte[0x4000];

                for (int i = 0; i < 0x4000; i++)
                {
                    Bios[i]  = loc_bios[i];
                    Basic[i] = loc_bios[i + 0x4000];
                }
            }

            //only use one rom cart for now
            RomData2 = new byte[0x10000];

            for (int i = 0; i < 0x10000; i++)
            {
                RomData2[i] = 0;
            }

            MSX_Pntr = LibMSX.MSX_create();

            LibMSX.MSX_load_bios(MSX_Pntr, Bios, Basic);
            LibMSX.MSX_load(MSX_Pntr, RomData, (uint)RomData.Length, mapper_1, RomData2, (uint)RomData2.Length, 0);

            blip.SetRates(3579545, 44100);

            (ServiceProvider as BasicServiceProvider).Register <ISoundProvider>(this);

            SetupMemoryDomains();

            Header_Length     = LibMSX.MSX_getheaderlength(MSX_Pntr);
            Disasm_Length     = LibMSX.MSX_getdisasmlength(MSX_Pntr);
            Reg_String_Length = LibMSX.MSX_getregstringlength(MSX_Pntr);

            var newHeader = new StringBuilder(Header_Length);

            LibMSX.MSX_getheader(MSX_Pntr, newHeader, Header_Length);

            Console.WriteLine(Header_Length + " " + Disasm_Length + " " + Reg_String_Length);

            Tracer = new TraceBuffer(newHeader.ToString());

            var serviceProvider = ServiceProvider as BasicServiceProvider;

            serviceProvider.Register <ITraceable>(Tracer);
            serviceProvider.Register <IStatable>(new StateSerializer(SyncState));

            current_controller = SyncSettings.Contr_Setting == MSXSyncSettings.ContrType.Keyboard ? MSXControllerKB : MSXControllerJS;
        }
Esempio n. 12
0
        public MSX(CoreComm comm, GameInfo game, byte[] rom, MSX.MSXSettings settings, MSX.MSXSyncSettings syncSettings)
        {
            ServiceProvider = new BasicServiceProvider(this);
            Settings        = (MSXSettings)settings ?? new MSXSettings();
            SyncSettings    = (MSXSyncSettings)syncSettings ?? new MSXSyncSettings();

            RomData = rom;
            int size = RomData.Length;

            if (RomData.Length % BankSize != 0)
            {
                Array.Resize(ref RomData, ((RomData.Length / BankSize) + 1) * BankSize);
            }

            // we want all ROMS to be multiples of 64K for easy memory mapping later
            if (RomData.Length != 0x10000)
            {
                Array.Resize(ref RomData, 0x10000);
            }

            // if the original was not 64 or 48 k, move it (may need to do this case by case)

            if (size == 0x8000)
            {
                for (int i = 0x7FFF; i >= 0; i--)
                {
                    RomData[i + 0x4000] = RomData[i];
                }
                for (int i = 0; i < 0x4000; i++)
                {
                    RomData[i] = 0;
                }
            }

            if (size == 0x4000)
            {
                for (int i = 0; i < 0x4000; i++)
                {
                    RomData[i + 0x4000] = RomData[i];
                    RomData[i + 0x8000] = RomData[i];
                    RomData[i + 0xC000] = RomData[i];
                }
            }

            Bios = comm.CoreFileProvider.GetFirmware("MSX", "bios_jp", false, "BIOS Not Found, Cannot Load");

            if (Bios == null)
            {
                Bios = comm.CoreFileProvider.GetFirmware("MSX", "bios_test_ext", true, "BIOS Not Found, Cannot Load");
            }
            //Basic = comm.CoreFileProvider.GetFirmware("MSX", "basic_test", true, "BIOS Not Found, Cannot Load");


            Basic = new byte[0x4000];

            MSX_Pntr = LibMSX.MSX_create();

            LibMSX.MSX_load_bios(MSX_Pntr, Bios, Basic);
            LibMSX.MSX_load(MSX_Pntr, RomData, (uint)RomData.Length, 0, RomData, (uint)RomData.Length, 0);

            blip.SetRates(3579545, 44100);

            (ServiceProvider as BasicServiceProvider).Register <ISoundProvider>(this);

            SetupMemoryDomains();

            Header_Length     = LibMSX.MSX_getheaderlength(MSX_Pntr);
            Disasm_Length     = LibMSX.MSX_getdisasmlength(MSX_Pntr);
            Reg_String_Length = LibMSX.MSX_getregstringlength(MSX_Pntr);

            var newHeader = new StringBuilder(Header_Length);

            LibMSX.MSX_getheader(MSX_Pntr, newHeader, Header_Length);

            Console.WriteLine(Header_Length + " " + Disasm_Length + " " + Reg_String_Length);

            Tracer = new TraceBuffer {
                Header = newHeader.ToString()
            };

            var serviceProvider = ServiceProvider as BasicServiceProvider;

            serviceProvider.Register <ITraceable>(Tracer);
            serviceProvider.Register <IStatable>(new StateSerializer(SyncState));

            current_controller = SyncSettings.Contr_Setting == MSXSyncSettings.ContrType.Keyboard ? MSXControllerKB : MSXControllerJS;
        }
Esempio n. 13
0
 public int[] GetVideoBuffer()
 {
     LibMSX.MSX_get_video(MSX_Pntr, _vidbuffer);
     return(_vidbuffer);
 }
        public bool FrameAdvance(IController controller, bool render, bool rendersound)
        {
            _controller = controller;

            byte ctrl1_byte = 0xFF;

            if (_controller.IsPressed("P1 Up"))
            {
                ctrl1_byte -= 0x01;
            }
            if (_controller.IsPressed("P1 Down"))
            {
                ctrl1_byte -= 0x02;
            }
            if (_controller.IsPressed("P1 Left"))
            {
                ctrl1_byte -= 0x04;
            }
            if (_controller.IsPressed("P1 Right"))
            {
                ctrl1_byte -= 0x08;
            }
            if (_controller.IsPressed("P1 B1"))
            {
                ctrl1_byte -= 0x10;
            }
            if (_controller.IsPressed("P1 B2"))
            {
                ctrl1_byte -= 0x20;
            }

            byte ctrl2_byte = 0xFF;

            if (_controller.IsPressed("P2 Up"))
            {
                ctrl2_byte -= 0x01;
            }
            if (_controller.IsPressed("P2 Down"))
            {
                ctrl2_byte -= 0x02;
            }
            if (_controller.IsPressed("P2 Left"))
            {
                ctrl2_byte -= 0x04;
            }
            if (_controller.IsPressed("P2 Right"))
            {
                ctrl2_byte -= 0x08;
            }
            if (_controller.IsPressed("P2 B1"))
            {
                ctrl2_byte -= 0x10;
            }
            if (_controller.IsPressed("P2 B2"))
            {
                ctrl2_byte -= 0x20;
            }

            if (current_controller == MSXControllerKB)
            {
                kb_rows_check(controller);
            }

            _frame++;

            if (Tracer.Enabled)
            {
                tracecb = MakeTrace;
            }
            else
            {
                tracecb = null;
            }

            LibMSX.MSX_settracecallback(MSX_Pntr, tracecb);

            LibMSX.MSX_frame_advance(MSX_Pntr, ctrl1_byte, ctrl2_byte, kb_rows, true, true);

            return(true);
        }
Esempio n. 15
0
        public bool FrameAdvance(IController controller, bool render, bool rendersound)
        {
            _controller = controller;

            byte ctrl1_byte = 0xFF;

            if (_controller.IsPressed("P1 Up"))
            {
                ctrl1_byte -= 0x01;
            }
            if (_controller.IsPressed("P1 Down"))
            {
                ctrl1_byte -= 0x02;
            }
            if (_controller.IsPressed("P1 Left"))
            {
                ctrl1_byte -= 0x04;
            }
            if (_controller.IsPressed("P1 Right"))
            {
                ctrl1_byte -= 0x08;
            }
            if (_controller.IsPressed("P1 B1"))
            {
                ctrl1_byte -= 0x10;
            }
            if (_controller.IsPressed("P1 B2"))
            {
                ctrl1_byte -= 0x20;
            }

            byte ctrl2_byte = 0xFF;

            if (_controller.IsPressed("P2 Up"))
            {
                ctrl2_byte -= 0x01;
            }
            if (_controller.IsPressed("P2 Down"))
            {
                ctrl2_byte -= 0x02;
            }
            if (_controller.IsPressed("P2 Left"))
            {
                ctrl2_byte -= 0x04;
            }
            if (_controller.IsPressed("P2 Right"))
            {
                ctrl2_byte -= 0x08;
            }
            if (_controller.IsPressed("P2 B1"))
            {
                ctrl2_byte -= 0x10;
            }
            if (_controller.IsPressed("P2 B2"))
            {
                ctrl2_byte -= 0x20;
            }

            if (current_controller == MSXControllerKB)
            {
                kb_rows_check(controller);
            }

            if (Tracer.IsEnabled())
            {
                tracecb = MakeTrace;
            }
            else
            {
                tracecb = null;
            }

            LibMSX.MSX_settracecallback(MSX_Pntr, tracecb);

            LibMSX.MSX_frame_advance(MSX_Pntr, ctrl1_byte, ctrl2_byte, kb_rows, true, true);

            LibMSX.MSX_get_video(MSX_Pntr, _vidbuffer);

            /*
             * int msg_l = LibMSX.MSX_getmessagelength(MSX_Pntr);
             * StringBuilder new_msg = new StringBuilder(msg_l);
             * LibMSX.MSX_getmessage(MSX_Pntr, new_msg, msg_l - 1);
             * Console.WriteLine(new_msg);
             */

            _frame++;

            return(true);
        }