public override Program Load(Address addr) { byte[] abC = RawImage; byte[] abU = new byte[cpUncompressed * 0x10U + ExeImageLoader.CbPsp]; Array.Copy(abC, exeHdrSize, abU, ExeImageLoader.CbPsp, abC.Length - exeHdrSize); imgU = new MemoryArea(addr, abU); uint SI = hdrOffset - 1; while (abC[SI] == 0xFF) { --SI; } int DI = abU.Length - 1; byte op; do { op = abC[SI]; int cx = MemoryArea.ReadLeUInt16(abC, SI - 2); SI -= 3; if ((op & 0xFE) == 0xB0) { byte b = abC[SI--]; while (cx != 0) { abU[DI--] = b; --cx; } } else { if ((op & 0xFE) != 0xB2) { throw new ApplicationException("Packed file is corrupt."); } while (cx != 0) { abU[DI--] = abC[SI--]; --cx; } } } while ((op & 1) == 0); imageMap = imgU.CreateImageMap(); return(new Program( new ImageMap(imgU.BaseAddress, imgU.Length), arch, platform)); }
void LoadSegments(uint offset) { this.segments = ReadSegmentTable(offset, cSeg); var segFirst = segments[0]; var segLast = segments[segments.Length - 1]; this.image = new MemoryArea( PreferredBaseAddress, new byte[segLast.LinearAddress + segLast.DataLength]); this.imageMap = image.CreateImageMap(); foreach (var segment in segments) { LoadSegment(segment, image, imageMap); } }
public override Program Load(Address addrLoad) { if (!ParseDMKHeader()) return null; var tracks = BuildTrackList(TrackLength); var bytes = tracks.SelectMany(t => t.Sectors) .SelectMany(s => s.GetData()) .ToArray(); var image = new MemoryArea(addrLoad, bytes); return new Program { Architecture = new Z80ProcessorArchitecture(), ImageMap = image.CreateImageMap(), }; }
public MemoryArea Unpack(byte [] abC, Address addrLoad) { // Extract the LZ stuff. EndianImageReader rdr = new LeImageReader(abC, (uint)lzHdrOffset); lzIp = rdr.ReadLeUInt16(); lzCs = rdr.ReadLeUInt16(); ushort lzSp = rdr.ReadLeUInt16(); ushort lzSs = rdr.ReadLeUInt16(); ushort lzcpCompressed = rdr.ReadLeUInt16(); ushort lzcpDecompressed = rdr.ReadLeUInt16(); // Find the start of the compressed stream. int ifile = lzHdrOffset - (lzcpCompressed << 4); // Allocate space for the decompressed goo. int cbUncompressed = ((int)lzcpDecompressed + lzcpDecompressed) << 4; byte [] abU = new byte[cbUncompressed]; // Decompress this sorry mess. int len; int span; int p = 0; BitStream bits = new BitStream(abC, ifile); for (;;) { if (bits.GetBit() != 0) { // 1.... abU[p++] = bits.GetByte(); continue; } if (bits.GetBit() == 0) { // 00..... len = bits.GetBit() << 1; len |= bits.GetBit(); len += 2; span = bits.GetByte() | ~0xFF; } else { // 01..... span = bits.GetByte(); len = bits.GetByte();; span |= ((len & ~0x07) << 5) | ~0x1FFF; len = (len & 0x07) + 2; if (len == 2) { len = bits.GetByte(); if (len == 0) { break; // end mark of compressed load module } if (len == 1) { continue; // segment change } else { ++len; } } } for ( ; len > 0; --len, ++p) { abU[p] = abU[p + span]; } } // Create a new image based on the uncompressed data. this.imgLoaded = new MemoryArea(addrLoad, abU); this.segmentMap = imgLoaded.CreateImageMap(); return(imgLoaded); }