public static async Task <GlulxMachine> CreateAsync(Stream stream) { var memory = await Memory.CreateAsync(stream); var header = new GlulxHeader(memory); VerifyChecksum(memory, header.Checksum); // Initial the memory should have a size equal to ExtStart. // We must expand it to EndMem. if (header.ExtStart != memory.Size) { throw new InvalidOperationException($"Size expected to be {header.ExtStart}"); } memory.Expand((int)header.EndMem); memory.AddReadOnlyRegion(0, (int)header.RamStart); if (header.StackSize % 256 != 0) { throw new InvalidOperationException("Stack size must be a multiple of 256"); } var stack = new Stack((int)header.StackSize); return(new GlulxMachine(header, memory, stack)); }
private GlulxMachine(GlulxHeader header, Memory memory, Stack stack) : base(memory, stack, (int)header.StartFunc) { this.Header = header; }