Comments!

This commit is contained in:
Brent O'Neil 2017-12-30 08:54:23 +11:00
parent 974b00aa7a
commit 3db05478c1
2 changed files with 16 additions and 8 deletions

View File

@ -4,10 +4,12 @@ import net.simon987.server.assembly.CPU;
import net.simon987.server.assembly.Instruction;
import net.simon987.server.assembly.Status;
/**
* Sets the PC to 0x0200 + Immediate operand
*
*
* Software Interrupt
* Pushes the flags register and the IP to the stack then
* Sets the IP to 0x0200 + 2*src.
* (x2 is to align with jmp instructions)
*
* No reserved interrupt vectors yet
*/
public class IntInstruction extends Instruction{

View File

@ -1,22 +1,28 @@
package net.simon987.server.assembly.instruction;
import net.simon987.server.assembly.CPU;
import net.simon987.server.assembly.Instruction;
import net.simon987.server.assembly.Status;
public class IntrInstruction extends Instruction{
/**
* Interrupt Return
*
* Pops the IP and status flag from the stack.
*/
public class IretInstruction extends Instruction{
public static final int OPCODE = 49;
private CPU cpu;
public IntrInstruction(CPU cpu) {
public IretInstruction(CPU cpu) {
super("intr", OPCODE);
this.cpu = cpu;
}
public Status execute(Status status) {
cpu.setIp((char)cpu.getMemory().get(cpu.getRegisterSet().getRegister("SP").getValue()));
status.fromByte((char) cpu.getMemory().get(cpu.getRegisterSet().getRegister("SP").getValue() + 1));
cpu.setIp((char)cpu.getMemory().get(cpu.getRegisterSet().getRegister("SP").getValue())); //IP (SP + 0)
status.fromByte((char) cpu.getMemory().get(cpu.getRegisterSet().getRegister("SP").getValue() + 1)); //Status (SP + 1)
cpu.getRegisterSet().getRegister("SP").setValue(cpu.getRegisterSet().getRegister("SP").getValue() + 2); //Increment SP (stack grows towards smaller)
return status;
}