|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.zmpp.vm.AbstractInstruction
public abstract class AbstractInstruction
This class represents can be considered as a mutable value object, which basically stores an instruction's information in order to restrict the Instruction class's responsibility to executing logic. This information will be incrementally added by the decoder, therefore there are setter methods to add information.
Nested Class Summary | |
---|---|
static class |
AbstractInstruction.InstructionForm
The available instruction forms. |
static class |
AbstractInstruction.OperandCount
The available operand count types. |
Field Summary | |
---|---|
static short |
FALSE
The constant for false. |
static short |
TRUE
The constant for true. |
Constructor Summary | |
---|---|
AbstractInstruction(Machine machineState,
int opcode)
Constructor. |
Method Summary | |
---|---|
void |
addOperand(Operand operand)
Adds an operand to this object. |
boolean |
branchIfTrue()
Returns true if this is a branch condition and the branch is executed if the test condition is true, false otherwise. |
protected void |
branchOnTest(boolean condition)
Performs a branch, depending on the state of the condition flag. |
short |
getBranchOffset()
Returns the branch offset. |
abstract AbstractInstruction.InstructionForm |
getInstructionForm()
Returns the instruction's form. |
int |
getLength()
Returns the instruction's length in bytes. |
protected Machine |
getMachine()
Returns the reference to the machine state. |
int |
getNumOperands()
Returns the number of operands. |
int |
getOpcode()
Returns the instruction's opcode. |
Operand |
getOperand(int operandNum)
Returns the operand at the specified position. |
abstract AbstractInstruction.OperandCount |
getOperandCount()
Returns the instruction's operand count type. |
int |
getStoreVariable()
Returns the instruction's store variable. |
int |
getUnsignedValue(int operandNum)
Retrieves the value of the specified operand as an unsigned 16 bit integer. |
short |
getValue(int operandNum)
Converts the specified value into a signed value, depending on the type of the operand. |
boolean |
isBranch()
Returns true, if this instruction is a branch, false, otherwise. |
protected void |
nextInstruction()
Advances the program counter to the next instruction. |
protected void |
returnFromRoutine(short returnValue)
This function returns from the current routine, setting the return value into the specified return variable. |
void |
setBranchIfTrue(boolean flag)
Sets the branch if condition true flag. |
void |
setBranchOffset(short offset)
Sets the branch offset. |
void |
setLength(int length)
Sets the instruction's length in bytes. |
void |
setOpcode(int opcode)
Sets the instruction's opcode. |
void |
setStoreVariable(int var)
Sets the store variable. |
protected void |
storeResult(short value)
Stores the specified value in the result variable. |
boolean |
storesResult()
Returns true, if this instruction stores a result, false, otherwise. |
protected void |
throwInvalidOpcode()
Halt the virtual machine with an error message about this instruction. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Methods inherited from interface org.zmpp.vm.Instruction |
---|
execute |
Field Detail |
---|
public static final short FALSE
public static final short TRUE
Constructor Detail |
---|
public AbstractInstruction(Machine machineState, int opcode)
machineState
- a reference to the machine stateopcode
- the opcodeMethod Detail |
---|
protected Machine getMachine()
public int getOpcode()
public abstract AbstractInstruction.InstructionForm getInstructionForm()
public abstract AbstractInstruction.OperandCount getOperandCount()
public Operand getOperand(int operandNum)
operandNum
- the operand number, starting with 0 as the first operand.
public int getNumOperands()
public int getStoreVariable()
public short getBranchOffset()
public int getLength()
public void setOpcode(int opcode)
opcode
- the opcodepublic void addOperand(Operand operand)
operand
- the operand to addpublic void setStoreVariable(int var)
var
- the store variablepublic void setBranchOffset(short offset)
offset
- the branch offsetpublic void setBranchIfTrue(boolean flag)
flag
- the branch if condition true flagpublic void setLength(int length)
length
- the length in bytespublic boolean storesResult()
public boolean isBranch()
public boolean branchIfTrue()
public short getValue(int operandNum)
operandNum
- the operand number
public int getUnsignedValue(int operandNum)
operandNum
- the operand number
protected void storeResult(short value)
value
- the value to storeprotected void throwInvalidOpcode()
protected void nextInstruction()
protected void branchOnTest(boolean condition)
condition
- the test conditionprotected void returnFromRoutine(short returnValue)
returnValue
- the return value
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |