private bool Run() { _zMemory.Running = true; bool restart = false; while (_zMemory.Running) { var opCode = _zMemory.GetCurrentByteAndInc(); IOperation operation; OpCodes opCodeEnum; (opCode, opCodeEnum, operation) = _zOperations.GetOperation(opCode); if (opCodeEnum == OpCodes.Restart) { restart = true; break; } if (operation == null) { throw new Exception($"No operation found for Op Code {opCode} ({opCode:X2})!"); } Log.WriteLine($" OP: {opCodeEnum:D} ({(byte)opCodeEnum:X2}) - {operation.GetType().Name})"); var args = _zMemory.OperandManager.GetOperands(opCode); if (opCodeEnum == OpCodes.Read && !_interruptMode) { _io.ShowStatus(_zMemory); Read read = (Read)operation; read.SetParseAddresses(args[0], args[1]); break; } operation.Execute(args); Log.Flush(); } return(restart); }
public (byte opCode, OpCodes opCodeEnum, IOperation operation) GetOperation(byte opCode) { //NOTE: http://inform-fiction.org/zmachine/standards/z1point1/sect14.html IOperation operation; OpCodes opCodeEnum; if (opCode == (byte)OpCodes.Extended) // 0OP:190 - special op, indicates next byte contains Extended Op { opCodeEnum = OpCodes.Extended; opCode = _zMemory.GetCurrentByteAndInc(); _extendedOperations.TryGetValue((KindExtOpCodes)(opCode & 0x1f), out operation); // TODO: hack to make this a VAR opcode... opCode |= 0xc0; } else { opCodeEnum = opCode.ToOpCode(); _operations.TryGetValue(opCodeEnum, out operation); } return(opCode, opCodeEnum, operation); }