Esempio n. 1
0
  private void toggleBreakpoint() {
    try {
      int lineno = sourceTextarea.getLineOfOffset(sourceTextarea.getCaretPosition()) + 1;
      Character asmaddr = asmMap.src2bin(lineno);
      if (srcBreakpoints.contains(lineno)) {
        srcBreakpoints.remove(lineno);
        if (asmaddr != null) debugger.setBreakpoint(asmaddr, false);
      } else {
        srcBreakpoints.add(lineno);
        if (asmaddr != null) debugger.setBreakpoint(asmaddr, true);
      }

      sourceRowHeader.breakpointChanged(lineno);
    } catch (BadLocationException e1) {
      e1.printStackTrace();
    }
  }
Esempio n. 2
0
 private void openBin() {
   fileChooser.resetChoosableFileFilters();
   fileChooser.addChoosableFileFilter(binFilter);
   fileChooser.setFileFilter(binFilter);
   if (fileChooser.showOpenDialog(frame) == JFileChooser.APPROVE_OPTION) {
     try {
       FileInputStream inbinf = new FileInputStream(fileChooser.getSelectedFile());
       int len = inbinf.available();
       if (len % 2 == 1) throw new IOException(String.format("Odd file size (0x%x)\n", len));
       len /= 2;
       if (len > 0x10000) throw new IOException(String.format("Too large file (0x%x)\n", len));
       binary = new char[len];
       for (int i = 0; i < len; i++) {
         int lo = inbinf.read();
         int hi = inbinf.read();
         if (lo == -1 || hi == -1) throw new IOException("Unable to read\n");
         binary[i] = (char) ((hi << 8) | lo);
       }
       asmMap = new AsmMap();
       Disassembler dasm = new Disassembler();
       dasm.init(binary);
       // TODO attach asmmap
       StringBuilder sb = new StringBuilder();
       while (dasm.getAddress() < binary.length) {
         int addr = dasm.getAddress();
         sb.append(String.format("%-26s ; [%04x] =", dasm.next(true), addr));
         int addr2 = dasm.getAddress();
         while (addr < addr2) {
           char i = binary[addr++];
           sb.append(
               String.format(" %04x '%s'", (int) i, (i >= 0x20 && i < 0x7f) ? (char) i : '.'));
         }
         sb.append("\n");
       }
       srcBreakpoints.clear();
       sourceRowHeader.breakpointsChanged();
       sourceTextarea.setText(sb.toString());
     } catch (IOException e1) {
       JOptionPane.showMessageDialog(
           frame, "Unable to open file: %s" + e1.getMessage(), "Error", JOptionPane.ERROR_MESSAGE);
       e1.printStackTrace();
     }
   }
 }
Esempio n. 3
0
 private void openSrc() {
   fileChooser.resetChoosableFileFilters();
   fileChooser.addChoosableFileFilter(asmFilter);
   fileChooser.setFileFilter(asmFilter);
   if (fileChooser.showOpenDialog(frame) == JFileChooser.APPROVE_OPTION) {
     try {
       FileInputStream input = new FileInputStream(fileChooser.getSelectedFile());
       char[] csources = new char[input.available()];
       new InputStreamReader(input).read(csources, 0, csources.length);
       srcBreakpoints.clear();
       sourceRowHeader.breakpointsChanged();
       sourceTextarea.setText(new String(csources));
       asmMap = new AsmMap();
       binary = new char[0];
     } catch (IOException e1) {
       JOptionPane.showMessageDialog(
           frame, "Unable to open file", "Error", JOptionPane.ERROR_MESSAGE);
       e1.printStackTrace();
     }
   }
 }
Esempio n. 4
0
  public IdeMain() {
    cpu = new Dcpu();
    debugger = new Debugger();
    debugger.breakpointListener =
        new PreListener<Character>() {
          public void preExecute(Character arg) {
            breakpointHit(arg);
          }
        };
    debugger.attachTo(cpu);
    asmMap = new AsmMap();

    MonitorLEM1802 monitor = new MonitorLEM1802();
    cpu.attach(monitor);
    MonitorWindow window = new MonitorWindow(cpu, monitor, false);
    window.show();

    Sped3 sped = new Sped3();
    cpu.attach(sped);
    SpedWindow spedWindow = new SpedWindow(cpu, sped, false);
    spedWindow.show();
    spedWindow.getFrame().setSize(600, 600);

    GenericClock clock = new GenericClock(MonitorLEM1802.MANUFACTURER_ID); // Nya Elektriska
    GenericKeyboard keyboard = new GenericKeyboard(MonitorLEM1802.MANUFACTURER_ID, 16);
    cpu.attach(clock);
    cpu.attach(keyboard);
    window.addKeyListener(keyboard);

    fileChooser = new JFileChooser();
    fileChooser.setCurrentDirectory(new File("."));

    registersModel = new RegistersModel(cpu, debugger);
    registersTable.setModel(registersModel);
    memoryModel = new MemoryModel(cpu, debugger);
    memoryTable.setModel(memoryModel);

    sourceRowHeader = new SourceRowHeader(sourceTextarea, srcBreakpoints);
    sourceRowHeader.setBackground(Color.LIGHT_GRAY);
    sourceScrollPane.setRowHeaderView(sourceRowHeader);

    frame = new JFrame("JA-DCPU IDE");
    frame.setContentPane(rootPanel);
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.pack();
    frame.setVisible(true);

    openSrcButton.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            openSrc();
          }
        });
    asmButton.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            assemble();
          }
        });
    saveSrcButton.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            saveSrc();
          }
        });
    hardResetButton.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            cpu.memzero();
            memoryModel.fireUpdate(0, RAM_SIZE);
            cpu.reset();
            registersModel.fireUpdate();
          }
        });
    resetButton.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            cpu.reset();
            registersModel.fireUpdate();
          }
        });
    saveBinButton.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            saveBin();
          }
        });
    openBinButton.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            openBin();
          }
        });
    stepButton.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            step();
          }
        });
    breakpointButton.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            toggleBreakpoint();
          }
        });
    runButton.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            debugger.breakpointsHalt = true;
            runCpu();
          }
        });
    execButton.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            debugger.breakpointsHalt = false;
            runCpu();
          }
        });
    pauseButton.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            cpu.halt = true;
          }
        });
  }