Ejemplo n.º 1
0
        /// <summary>
        /// Load a Basic PRG.
        /// </summary>
        /// <param name="imageBytes"></param>
        /// <returns></returns>
        private Program LoadPrg(byte[] imageBytes)
        {
            var    stm = new MemoryStream();
            ushort preferredAddress = LoadedImage.ReadLeUInt16(imageBytes, 0);
            ushort alignedAddress   = (ushort)(preferredAddress & ~0xF);
            int    pad = preferredAddress - alignedAddress;

            while (pad-- > 0)
            {
                stm.WriteByte(0);
            }
            stm.Write(imageBytes, 2, imageBytes.Length - 2);
            var loadedBytes = stm.ToArray();
            var image       = new LoadedImage(
                Address.Ptr16(alignedAddress),
                loadedBytes);
            var rdr  = new C64BasicReader(image, 0x0801);
            var prog = rdr.ToSortedList(line => (ushort)line.Address.ToLinear(), line => line);
            var arch = new C64Basic(prog);

            image = new LoadedImage(
                Address.Ptr16(prog.Keys[0]),
                new byte[0xFFFF]);
            var program = new Program(
                image,
                image.CreateImageMap(),
                arch,
                new C64Platform(Services, null));

            program.EntryPoints.Add(new EntryPoint(image.BaseAddress, arch.CreateProcessorState()));
            return(program);
        }
Ejemplo n.º 2
0
        public override Program Load(Address addrLoad, IProcessorArchitecture arch, IPlatform platform)
        {
            var    stm = new MemoryStream();
            ushort preferredAddress = ByteMemoryArea.ReadLeUInt16(RawImage, 0);
            ushort alignedAddress   = (ushort)(preferredAddress & ~0xF);
            int    pad = preferredAddress - alignedAddress;

            while (pad-- > 0)
            {
                stm.WriteByte(0);
            }
            stm.Write(RawImage, 2, RawImage.Length - 2);
            var loadedBytes = stm.ToArray();
            var image       = new ByteMemoryArea(
                Address.Ptr16(alignedAddress),
                loadedBytes);
            var rdr    = new C64BasicReader(image, 0x0801);
            var lines  = rdr.ToSortedList(line => line.LineNumber, line => line);
            var cfgSvc = Services.RequireService <IConfigurationService>();

            arch     = new C64Basic(Services, lines);
            platform = cfgSvc.GetEnvironment("c64").Load(Services, arch);
            var        arch6502 = cfgSvc.GetArchitecture("m6502");
            SegmentMap segMap   = CreateSegmentMap(platform, image, lines);
            var        program  = new Program(segMap, arch, platform);

            program.Architectures.Add(arch6502.Name, arch6502);
            var addrBasic = lines.Values[0].Address;
            var sym       = ImageSymbol.Procedure(arch, addrBasic, state: arch.CreateProcessorState());

            program.EntryPoints.Add(sym.Address, sym);
            AddLineNumberSymbols(lines, program);
            return(program);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Load a Basic PRG.
        /// </summary>
        /// <param name="imageBytes"></param>
        /// <returns></returns>
        private Program LoadPrg(byte[] imageBytes)
        {
            var    stm = new MemoryStream();
            ushort preferredAddress = MemoryArea.ReadLeUInt16(imageBytes, 0);
            ushort alignedAddress   = (ushort)(preferredAddress & ~0xF);
            int    pad = preferredAddress - alignedAddress;

            while (pad-- > 0)
            {
                stm.WriteByte(0);
            }
            stm.Write(imageBytes, 2, imageBytes.Length - 2);
            var loadedBytes = stm.ToArray();
            var image       = new MemoryArea(
                Address.Ptr16(alignedAddress),
                loadedBytes);
            var rdr      = new C64BasicReader(image, 0x0801);
            var lines    = rdr.ToSortedList(line => (ushort)line.Address.ToLinear(), line => line);
            var cfgSvc   = Services.RequireService <IConfigurationService>();
            var arch6502 = (Mos6502ProcessorArchitecture)cfgSvc.GetArchitecture("m6502");
            var arch     = new C64Basic(lines);
            var platform = cfgSvc.GetEnvironment("c64").Load(Services, arch);
            var segMap   = platform.CreateAbsoluteMemoryMap();

            segMap.AddSegment(image, "code", AccessMode.ReadWriteExecute);
            var program = new Program(segMap, arch, platform);

            program.Architectures.Add(arch6502.Name, arch6502);
            var addrBasic = Address.Ptr16(lines.Keys[0]);
            var sym       = ImageSymbol.Procedure(arch, addrBasic, state: arch.CreateProcessorState());

            program.EntryPoints.Add(sym.Address, sym);
            return(program);
        }
Ejemplo n.º 4
0
            private Program LoadPrg(IServiceProvider services)
            {
                // Many of these programs use all of the
                // C64 memory, so be generous.
                var image = new ByteMemoryArea(Address.Ptr16(0x800), new byte[0xF800 - 0x800]);
                var src   = this.GetBytes();

                Array.Copy(src, 0, image.Bytes, (int)(this.LoadAddress - (ushort)image.BaseAddress.ToLinear()), src.Length);

                var rdr      = new C64BasicReader(image, 0x0801);
                var lines    = rdr.ToSortedList(line => (ushort)line.LineNumber, line => line);
                var cfgSvc   = services.RequireService <IConfigurationService>();
                var arch6502 = cfgSvc.GetArchitecture("m6502") !;
                var arch     = new C64Basic(services, lines);
                var platform = cfgSvc.GetEnvironment("c64").Load(services, arch);
                var segMap   = platform.CreateAbsoluteMemoryMap() !;

                segMap.AddSegment(image, "code", AccessMode.ReadWriteExecute);
                var program = new Program(segMap, arch, platform);

                program.Location = ImageLocation;

                program.Architectures.Add(arch6502.Name, arch6502);
                var addrBasic = Address.Ptr16(lines.Keys[0]);
                var sym       = ImageSymbol.Procedure(arch, addrBasic, state: arch.CreateProcessorState());

                program.EntryPoints.Add(sym.Address, sym);
                return(program);
            }
Ejemplo n.º 5
0
        /// <summary>
        /// Load a Basic PRG.
        /// </summary>
        /// <param name="imageBytes"></param>
        /// <returns></returns>
        private Program LoadPrg(byte[] imageBytes)
        {
            var    stm = new MemoryStream();
            ushort preferredAddress = MemoryArea.ReadLeUInt16(imageBytes, 0);
            ushort alignedAddress   = (ushort)(preferredAddress & ~0xF);
            int    pad = preferredAddress - alignedAddress;

            while (pad-- > 0)
            {
                stm.WriteByte(0);
            }
            stm.Write(imageBytes, 2, imageBytes.Length - 2);
            var loadedBytes = stm.ToArray();
            var image       = new MemoryArea(
                Address.Ptr16(alignedAddress),
                loadedBytes);
            var rdr  = new C64BasicReader(image, 0x0801);
            var prog = rdr.ToSortedList(line => (ushort)line.Address.ToLinear(), line => line);
            var arch = new C64Basic(prog);

            image = new MemoryArea(
                Address.Ptr16(prog.Keys[0]),
                new byte[0xFFFF]);
            var program = new Program(
                new SegmentMap(
                    image.BaseAddress,
                    new ImageSegment("code", image, AccessMode.ReadWriteExecute)),
                arch,
                new C64Platform(Services, null));
            var sym = ImageSymbol.Procedure(arch, image.BaseAddress, state: arch.CreateProcessorState());

            program.EntryPoints.Add(sym.Address, sym);
            return(program);
        }
Ejemplo n.º 6
0
        private Program LoadPrg(T64FileEntry selectedFile)
        {
            var image = new ByteMemoryArea(
                Address.Ptr16(selectedFile.LoadAddress),
                selectedFile.GetBytes());
            var rdr      = new C64BasicReader(image, 0x0801);
            var lines    = rdr.ToSortedList(line => (ushort)line.LineNumber, line => line);
            var cfgSvc   = Services.RequireService <IConfigurationService>();
            var arch6502 = cfgSvc.GetArchitecture("m6502") !;
            var arch     = new C64Basic(Services, lines);
            var platform = cfgSvc.GetEnvironment("c64").Load(Services, arch);
            var segMap   = platform.CreateAbsoluteMemoryMap() !;

            segMap.AddSegment(image, "code", AccessMode.ReadWriteExecute);
            var program = new Program(segMap, arch, platform);

            program.Architectures.Add(arch6502.Name, arch6502);
            var addrBasic = Address.Ptr16(lines.Keys[0]);
            var sym       = ImageSymbol.Procedure(arch, addrBasic, state: arch.CreateProcessorState());

            program.EntryPoints.Add(sym.Address, sym);
            return(program);
        }