Example #1
0
        public override void Prepare(SpanLocation memory)
        {
            operandResolver.AddOperands(Operands, memory.Bytes.Slice(1));

            Size      = 2 + Operands.Size;
            OpCode    = Bits.BottomFive(memory.Bytes[0]);
            Operation = OpCode switch
            {
                0x00 => new Operation(nameof(Call), Call, hasStore: true),
                0x01 => new Operation(nameof(StoreW), StoreW),
                0x03 => new Operation(nameof(PutProp), PutProp),
                0x04 => new Operation(nameof(Read), Read),
                0x05 => new Operation(nameof(PrintChar), PrintChar),
                0x06 => new Operation(nameof(PrintNum), PrintNum),
                0x08 => new Operation(nameof(Push), Push),
                0x09 => new Operation(nameof(Pull), Pull),
                _ => throw new InvalidOperationException($"Unknown VAR opcode {OpCode:X}")
            };
            if (Operation.HasStore)
            {
                StoreResult = memory.Bytes[Size];
                Size       += 1;
            }
            if (Operation.HasBranch)
            {
                Size += Branch.Size;
                throw new NotImplementedException("Do this");
            }

            DumpToLog(memory, Size);
        }
Example #2
0
        public override void Prepare(SpanLocation memory)
        {
            OpCode    = Bits.BottomFive(memory.Bytes[0]);
            Operation = OpCode switch
            {
                0x01 => new Operation(nameof(JE), JE, hasBranch: true),
                0x02 => new Operation(nameof(JL), JL, hasBranch: true),
                0x03 => new Operation(nameof(JG), JG, hasBranch: true),
                0x04 => new Operation(nameof(DecChk), DecChk, hasBranch: true),
                0x05 => new Operation(nameof(IncChk), IncChk, hasBranch: true),
                0x06 => new Operation(nameof(Jin), Jin, hasBranch: true),
                0x09 => new Operation(nameof(And), And, hasStore: true),
                0x0A => new Operation(nameof(TestAttr), TestAttr, hasBranch: true),
                0x0B => new Operation(nameof(SetAttr), SetAttr),
                0x0D => new Operation(nameof(StoreB), StoreB),
                0x0E => new Operation(nameof(InsertObj), InsertObj),
                0x0F => new Operation(nameof(LoadW), LoadW, hasStore: true),
                0x10 => new Operation(nameof(LoadB), LoadB, hasStore: true),
                0x11 => new Operation(nameof(GetProp), GetProp, hasStore: true),
                0x14 => new Operation(nameof(Add), Add, hasStore: true),
                0x15 => new Operation(nameof(Sub), Sub, hasStore: true),
                _ => throw new InvalidOperationException($"Unknown OP2 opcode {OpCode:X}")
            };

            if (OpCode == 0x05)
            {
                // 😒 seven Z-machine opcodes access variables but by their numbers ...
                // inc, dec, inc_chk, dec_chk, store, pull, load. 😒
                indirectOperandResolver.AddOperands(Operands, memory.Bytes.Slice(1));
                Size = 1 + Operands.Size;
            }
            else if (Bits.SevenSixSet(memory.Bytes[0]) == true &&
                     Bits.FiveSet(memory.Bytes[0]) == false)
            {
                // 😒 2OPS, but VAR operands 😒
                varOperandResolver.AddOperands(Operands, memory.Bytes.Slice(1));
                Size = 2 + Operands.Size;
            }
            else
            {
                op2OperandResolver.AddOperands(Operands, memory.Bytes);
                Size = 1 + Operands.Size;
            }
            if (Operation.HasStore)
            {
                StoreResult = memory.Bytes[Size];
                Size       += 1;
            }
            if (Operation.HasBranch)
            {
                var branchData = machine.Memory.SpanAt(memory.Address + Size);
                Branch = branchResolver.ResolveBranch(branchData);
                Size  += Branch.Size;
            }

            DumpToLog(memory, Size);
        }
Example #3
0
        public GameObjectProperty(Machine machine, MemoryLocation memory)
        {
            if (machine == null)
            {
                throw new ArgumentNullException(nameof(machine));
            }

            this.machine = machine;
            if (machine.Version > 3 && Bits.SevenSet(memory.Bytes.Span[0]))
            {
                throw new NotImplementedException("Not sure how to process 2 size bytes yet");
            }
            else
            {
                var sizeByte = memory.Bytes.Span[0];
                Size   = Bits.TopThree(sizeByte) + 1;
                Number = Bits.BottomFive(sizeByte);
                Value  = machine.Memory.MemoryAt(memory.Address + 1, Size).Bytes;
            }
        }