Skip to content

Commit

Permalink
Version 1.0.6 - changes by Nick
Browse files Browse the repository at this point in the history
- exposed F3/F4 disk swapping method: cycleDisk(int driveNumber)
- exposed reset() method
- exposed setSpeed(int value) method
  • Loading branch information
sicklittlemonkey committed Aug 1, 2015
1 parent d8b391a commit 912d6c3
Showing 1 changed file with 58 additions and 32 deletions.
90 changes: 58 additions & 32 deletions Source/AppleIIGo.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,12 @@
*
* Change list:
*
* Version 1.0.6 - changes by Nick:
*
* - exposed F3/F4 disk swapping method: cycleDisk(int driveNumber)
* - exposed reset() method
* - exposed setSpeed(int value) method
*
* Version 1.0.5 - changes by Nick:
*
* - added support for .NIB (nibble) disk images (also inside ZIP archives)
Expand All @@ -28,7 +34,7 @@
* Version 1.0.2 - changes by Nick:
* - improved sound sync by moving AppleSpeaker into the main thread
* - added version (F1)
* - added multiple disks & switching (F3, F4)
* - added multiple disks & swapping (F3, F4)
* - added ZIP archive support
* - fixed HTTP disk image access bug
*/
Expand Down Expand Up @@ -60,7 +66,7 @@
public class AppleIIGo extends Applet implements KeyListener, ComponentListener,
MouseListener, MouseMotionListener {

final String version = "1.0.5";
final String version = "1.0.6";
final String versionString = "AppleIIGo Version " + version;

// Class instances
Expand All @@ -78,13 +84,11 @@ public class AppleIIGo extends Applet implements KeyListener, ComponentListener,
// Paddle variables
private boolean isPaddleInverted;

// Disk variables
// Disk variables - TODO: refactor into a class
private String diskDriveResource[] = new String[2];
private boolean diskWritable;
private String[] disks0;
private String[] disks1;
private int disk0;
private int disk1;
private String[][] diskImageNames = {{}, {}};
private int diskImageNumber[] = {0, 0};

/**
* Debug
Expand Down Expand Up @@ -146,12 +150,12 @@ public void init() {

// Initialize disk drives
diskWritable = getAppletParameter("diskWritable", "false").equals("true");
disks0 = getAppletParameter("diskDrive1", "").split("[|]");
disk0 = 0;
disks1 = getAppletParameter("diskDrive2", "").split("[|]");
disk1 = 0;
mountDisk(0, disks0[disk0]);
mountDisk(1, disks1[disk1]);
diskImageNames[0] = getAppletParameter("diskDrive1", "").split("[|]");
diskImageNumber[0] = 0;
diskImageNames[1] = getAppletParameter("diskDrive2", "").split("[|]");
diskImageNumber[1] = 0;
mountDisk(0, diskImageNames[0][diskImageNumber[0]]);
mountDisk(1, diskImageNames[1][diskImageNumber[1]]);

// Start CPU
if (!isCpuPaused)
Expand Down Expand Up @@ -200,9 +204,9 @@ public void focus() {
public void pause() {
debug("pause()");
isCpuPaused = true;
apple.setPaused(isCpuPaused);
display.setPaused(isCpuPaused);
apple.speaker.setPaused(isCpuPaused);
apple.setPaused(true);
display.setPaused(true);
apple.speaker.setPaused(true);
}

/**
Expand All @@ -211,9 +215,9 @@ public void pause() {
public void resume() {
debug("resume()");
isCpuPaused = false;
apple.speaker.setPaused(isCpuPaused);
display.setPaused(isCpuPaused);
apple.setPaused(isCpuPaused);
apple.speaker.setPaused(false);
display.setPaused(false);
apple.setPaused(false);
}

/**
Expand All @@ -223,6 +227,35 @@ public void restart() {
debug("restart()");
apple.restart();
}

public void reset() {
debug("reset()");
apple.reset();
}


public void setSpeed(int value) {
debug("setSpeed(" + value + ")");
try
{
pause();
this.wait(1000);
}
catch (Throwable e)
{
}
apple.setCpuSpeed(value);
resume();
}

public void cycleDisk(int driveNumber)
{
debug("cycleDisk(" + driveNumber + ")");
if (diskImageNames[driveNumber].length > 1) {
diskImageNumber[driveNumber] = ++diskImageNumber[driveNumber] % diskImageNames[driveNumber].length;
mountDisk(driveNumber, diskImageNames[driveNumber][diskImageNumber[driveNumber]]);
}
}

/**
* Open input stream
Expand Down Expand Up @@ -318,7 +351,7 @@ public boolean mountDisk(int drive, String resource) {
debug("mountDisk(drive: " + drive + ", resource: " + resource + ")");
boolean success = false;

if ((drive < 0) || (drive > 2))
if ((drive < 0) || (drive > 1))
return success;

try {
Expand All @@ -331,6 +364,7 @@ public boolean mountDisk(int drive, String resource) {

success = disk.readDisk(drive, is, diskname.toString(), false);
is.close();
showStatus("Drive " + (drive + 1) + ": " + resource);
} catch (Exception e) {
debug("Exeption: " + e.getLocalizedMessage());
}
Expand Down Expand Up @@ -463,7 +497,7 @@ else if (e.getKeyLocation() == KeyEvent.KEY_LOCATION_NUMPAD)
break;
case KeyEvent.VK_HOME:
if (e.isControlDown())
apple.restart();
restart();
else
apple.paddle.setButton(0, true);
break;
Expand All @@ -474,18 +508,10 @@ else if (e.getKeyLocation() == KeyEvent.KEY_LOCATION_NUMPAD)
showStatus("AppleIIGo Version " + version);
break;
case KeyEvent.VK_F3:
if (disks0.length > 1) {
disk0 = ++disk0 % disks0.length;
mountDisk(0, disks0[disk0]);
showStatus("Disk 1: " + disks0[disk0]);
}
cycleDisk(0);
break;
case KeyEvent.VK_F4:
if (disks1.length > 1) {
disk1 = ++disk1 % disks1.length;
mountDisk(1, disks1[disk1]);
showStatus("Disk 2: " + disks1[disk1]);
}
cycleDisk(1);
break;
case KeyEvent.VK_F5:
if (isCpuDebugEnabled)
Expand All @@ -510,7 +536,7 @@ else if (e.getKeyLocation() == KeyEvent.KEY_LOCATION_NUMPAD)
case KeyEvent.VK_CANCEL: // Ctrl-Pause/Break sends this (N/A on Mac)
case KeyEvent.VK_F12:
if (e.isControlDown())
apple.reset();
reset();
break;
case KeyEvent.VK_KP_LEFT:
handleKeypadLeft();
Expand Down

0 comments on commit 912d6c3

Please sign in to comment.