Exemplo n.º 1
0
 public void setValueAt(Object aValue, int rowIndex, int columnIndex) {
   if (columnIndex == 1 && aValue != null) {
     char value;
     if (aValue instanceof Number) {
       value = (char) ((Number) aValue).intValue();
     } else if (aValue instanceof String) {
       String sValue = (String) aValue;
       try {
         if (sValue.startsWith("0x")) {
           value = (char) Integer.parseInt(sValue.substring(2), 16);
         } else if (sValue.startsWith("0b")) {
           value = (char) Integer.parseInt(sValue.substring(2), 2);
         } else {
           value = (char) Integer.parseInt(sValue);
         }
       } catch (NumberFormatException ignored) {
         return;
       }
     } else return;
     cpu.memset(M_A + rowIndex, value); // TODO debugger flag
   }
 }
Exemplo n.º 2
0
 private void assemble() {
   Assembler assembler = new Assembler();
   assembler.genMap = true;
   try {
     binary = new char[] {};
     binary = assembler.assemble(sourceTextarea.getText());
     cpu.upload(binary);
     memoryModel.fireUpdate(0, binary.length);
     asmMap = assembler.asmmap;
     for (Character addr : debugger.getBreakpoints()) {
       debugger.setBreakpoint(addr, false);
     }
     for (Integer breakpoint : srcBreakpoints) {
       Character addr = asmMap.src2bin(breakpoint);
       if (addr != null) { // TODO if null, mark breakpoint somehow
         debugger.setBreakpoint(addr, true);
       }
     }
   } catch (Exception ex) {
     JOptionPane.showMessageDialog(
         frame, "Compilation error " + ex.getMessage(), "Error", JOptionPane.ERROR_MESSAGE);
     ex.printStackTrace();
   }
 }
Exemplo n.º 3
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;
          }
        });
  }
Exemplo n.º 4
0
 public Object getValueAt(int rowIndex, int columnIndex) {
   if (columnIndex == 0) return Reg.l(rowIndex).name;
   return Integer.toHexString(cpu.memget(M_A + rowIndex)); // TODO debugger flag
 }