예제 #1
0
 public static ApplesoftProgram fromMemory(RAM memory) {
   int startAddress = memory.readWordRaw(startingAddressPointer);
   int nextCheck = memory.readWordRaw(startAddress);
   int pos = startAddress;
   List<Byte> bytes = new ArrayList<>();
   while (nextCheck != 0) {
     while (pos < nextCheck + 2) {
       bytes.add(memory.readRaw(pos++));
     }
     nextCheck = memory.readWordRaw(nextCheck);
   }
   return fromBinary(bytes, startAddress);
 }
예제 #2
0
 public static void brun(File binary, int address) throws FileNotFoundException, IOException {
   // If it was halted already, then it was initiated outside of an opcode execution
   // If it was not yet halted, then it is the case that the CPU is processing another opcode
   // So if that is the case, the program counter will need to be decremented here to compensate
   // TODO: Find a better mousetrap for this one -- it's an ugly hack
   Emulator.computer.pause();
   FileInputStream in = new FileInputStream(binary);
   byte[] data = new byte[in.available()];
   in.read(data);
   RAM ram = Emulator.computer.getMemory();
   for (int i = 0; i < data.length; i++) {
     ram.write(address + i, data[i], false, true);
   }
   CPU cpu = Emulator.computer.getCpu();
   Emulator.computer.getCpu().setProgramCounter(address);
   Emulator.computer.resume();
 }
예제 #3
0
  public void run() {
    RAM memory = Emulator.computer.memory;
    Emulator.computer.pause();
    int pos = memory.readWordRaw(startingAddressPointer);
    for (Line line : lines) {
      int nextPos = pos + line.getLength() + 1;
      memory.write(pos++, (byte) (nextPos & 0x0ff), false, true);
      memory.write(pos++, (byte) (nextPos >> 8 & 0x0ff), false, true);
      memory.write(pos++, (byte) (line.getNumber() & 0x0ff), false, true);
      memory.write(pos++, (byte) (line.getNumber() >> 8 & 0x0ff), false, true);
      boolean isFirst = true;
      for (Command command : line.getCommands()) {
        if (!isFirst) {
          memory.write(pos++, (byte) ':', false, true);
        }
        isFirst = false;
        for (Command.ByteOrToken part : command.parts) {
          memory.write(pos++, part.getByte(), false, true);
        }
      }
      memory.write(pos++, (byte) 0, false, true);
    }
    memory.write(pos++, (byte) 0, false, true);
    memory.write(pos++, (byte) 0, false, true);
    memory.write(pos++, (byte) 0, false, true);
    memory.write(pos++, (byte) 0, false, true);

    //        Emulator.computer.cpu.setProgramCounter(BASIC_RUN);
    Emulator.computer.resume();
  }