Ejemplo n.º 1
0
  /** @see pong.ApplicationState#stop() */
  @Override
  public void stop() {
    Debugger.debugWriteln("Stopping main menu.", this.getClass());

    mainFrame.dispose();
    mainFrame = null;
  }
Ejemplo n.º 2
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();
    }
  }
Ejemplo n.º 3
0
  /** @see pong.ApplicationState#init() */
  @Override
  public void init() {
    JFrame.setDefaultLookAndFeelDecorated(false);

    // Set background scene.

    backgroundScene =
        new PhysicsScene(CollidableMap.getMainMenuMap(), null, null, .0f, new RandomBallStrategy());

    // Create GUI.
    mainFrame = new PongFrame("Pong Adventures -Main menu-", backgroundScene, false, null, false);
    mainFrame.addWindowListener(this);
    mainFrame.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
    mainFrame.setResizable(false);

    // Setting frame to center of screen.
    Point center = GraphicsEnvironment.getLocalGraphicsEnvironment().getCenterPoint();
    mainFrame.setBounds(
        center.x - Global.windowSize.width / 2,
        center.y - Global.windowSize.height / 2,
        Global.windowSize.width,
        Global.windowSize.height);

    newGameButton = new JButton("New Game");
    newGameButton.setAlignmentX(Component.CENTER_ALIGNMENT);
    newGameButton.addActionListener(this);

    settingsButton = new JButton("Settings");
    settingsButton.setAlignmentX(Component.CENTER_ALIGNMENT);
    settingsButton.addActionListener(this);

    exitButton = new JButton("Exit");
    exitButton.setAlignmentX(Component.CENTER_ALIGNMENT);
    exitButton.addActionListener(this);

    Container content = mainFrame.getContentPane();
    content.setLayout(new BoxLayout(content, BoxLayout.Y_AXIS));

    content.add(Box.createGlue());
    content.add(Box.createGlue());
    content.add(newGameButton);
    content.add(Box.createGlue());
    content.add(settingsButton);
    content.add(Box.createGlue());
    content.add(exitButton);
    content.add(Box.createGlue());
    content.add(Box.createGlue());

    mainFrame.setVisible(true);

    Debugger.debugWriteln("Initializing main menu.", this.getClass());
  }
Ejemplo n.º 4
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();
   }
 }
Ejemplo n.º 5
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;
          }
        });
  }
Ejemplo n.º 6
0
 private void step() {
   debugger.breakpointsHalt = false;
   debugger.step();
   registersModel.fireUpdate();
   memoryModel.fireUpdate(0, RAM_SIZE - 1); // TODO optimize
 }
Ejemplo n.º 7
0
 private Address bigIntToAddress(BigInteger i) {
   String s = bigIntToHexString(i);
   return debugger.parseAddress(s);
 }