コード例 #1
0
ファイル: CPU.java プロジェクト: jgonis/TEOC
  /**
   * Executes the current instruction (ROM at pc). Throws ProgramException if the current
   * instruction is illegal or if it causes an illegal effect (read/write from M when A is an
   * illegal address or jump when A is an illegal address).
   */
  public void executeInstruction() throws ProgramException {
    short instruction = rom.getValueAt(PC.get());
    boolean pcChanged = false;

    if ((instruction & 0x8000) == 0) {
      bus.send(rom, PC.get(), A, 0);
    } else if ((instruction & 0xe000) == 0xe000) {
      computeExp(instruction);
      setDestination(instruction);
      pcChanged = checkJump(instruction);
    } else if (instruction != HackAssemblerTranslator.NOP) {
      throw new ProgramException("At line " + PC.get() + ": Illegal instruction");
    }

    if (!pcChanged) {
      short newPC = (short) (PC.get() + 1);
      if ((newPC < 0) || (newPC >= Definitions.ROM_SIZE)) {
        throw new ProgramException("At line " + PC.get() + ": Can't continue past last line");
      }
      PC.setValueAt(0, newPC, true);
    }

    time++;
  }