Skip to content

Commit

Permalink
Version 1.0.9 - changes by Nick
Browse files Browse the repository at this point in the history
- fixed disk speed-up bug (Sherwood Forest reads with the drive motor off)
- added check for 2IMG header ID
- fixed processor status bugs in BRK, PLP, RTI, NMI, IRQ
  • Loading branch information
sicklittlemonkey committed Aug 1, 2015
1 parent add3d41 commit dc8f597
Show file tree
Hide file tree
Showing 8 changed files with 87 additions and 37 deletions.
2 changes: 1 addition & 1 deletion Source/AppleDisplay.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
/**
* AppleIIGo
* Display processing
* (C) 2006 by Marc S. Ressl ([email protected])
* Copyright 2006 by Marc S. Ressl ([email protected])
* Released under the GPL
*/

Expand Down
9 changes: 7 additions & 2 deletions Source/AppleIIGo.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,18 @@
/**
* AppleIIGo
* The Java Apple II Emulator
* Copyright 2011 by Nick Westgate ([email protected])
* Copyright 2014 by Nick Westgate ([email protected])
* Copyright 2006 by Marc S. Ressl ([email protected])
* Released under the GNU General Public License version 2
* See http://www.gnu.org/licenses/
*
* Change list:
*
* Version 1.0.9 - changes by Nick:
* - fixed disk speed-up bug (Sherwood Forest reads with the drive motor off)
* - added check for 2IMG header ID
* - fixed processor status bugs in BRK, PLP, RTI, NMI, IRQ
*
* Version 1.0.8 - changes by Nick:
* - implemented disk writing (only in memory, not persisted)
* - added support for .2MG (2IMG) disk images, including lock flag and volume number
Expand Down Expand Up @@ -80,7 +85,7 @@ public class AppleIIGo extends Applet implements KeyListener, ComponentListener,

private static final long serialVersionUID = -3302282815441501352L;

final String version = "1.0.8";
final String version = "1.0.9";
final String versionString = "AppleIIGo Version " + version;
final String metaStart = "_meta_";

Expand Down
2 changes: 1 addition & 1 deletion Source/AppleSpeaker.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
/**
* AppleIIGo
* Speaker processing
* (C) 2006 by Marc S. Ressl([email protected])
* Copyright 2006 by Marc S. Ressl([email protected])
* Released under the GPL
*/

Expand Down
41 changes: 24 additions & 17 deletions Source/DiskII.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
/**
* AppleIIGo
* Disk II Emulator
* (C) 2006 by Marc S. Ressl(mressl@gmail.com)
* (C) 2011 by Nick Westgate (Nick.Westgate@gmail.com)
* Copyright 2014 by Nick Westgate (Nick.Westgate@gmail.com)
* Copyright 2006 by Marc S. Ressl(mressl@gmail.com)
* Released under the GPL
* Based on work by Doug Kwan
*/
Expand Down Expand Up @@ -38,6 +38,7 @@ public class DiskII extends Peripheral {
private static final int DOS_NUM_TRACKS = 35;
private static final int DOS_TRACK_BYTES = 256 * DOS_NUM_SECTORS;
private static final int RAW_TRACK_BYTES = 0x1A00; // 0x1A00 (6656) for .NIB (was 6250)
private static final int STANDARD_2IMG_HEADER_ID = 0x32494D47;
private static final int STANDARD_2IMG_HEADER_SIZE = 64;
private static final int STANDARD_PRODOS_BLOCKS = 280;

Expand Down Expand Up @@ -168,20 +169,8 @@ public int ioRead(int address) {
break;
}

if ((address & 1) == 0)
{
// only even addresses return the latch
if (isMotorOn)
{
return latchData;
}

// simple hack to fool DOS SAMESLOT drive spin check (usually at $BD34)
driveSpin = !driveSpin;
return driveSpin ? 0x7E : 0x7F;
}

return rand.nextInt(256); // TODO: floating bus
// only even addresses return the latch
return ((address & 1) == 0) ? latchData : rand.nextInt(256); // TODO: floating bus
}

/**
Expand Down Expand Up @@ -247,7 +236,10 @@ public int memoryRead(int address) {
* Reset peripheral
*/
public void reset() {
ioRead(0x8);
drive = 0;
isMotorOn = false;
loadMode = false;
writeMode = false;
}

/**
Expand All @@ -266,6 +258,10 @@ public boolean readDisk(int drive, DataInputStream is, String name, boolean isWr
byte[] header = new byte[STANDARD_2IMG_HEADER_SIZE];
is.readFully(header, 0, STANDARD_2IMG_HEADER_SIZE);

int id = (header[0x00] << 24) | (header[0x01] << 16) | (header[0x02] << 8) | (header[0x03]);
if (id != STANDARD_2IMG_HEADER_ID)
return false;

int headerSize = (header[0x09] << 8) | (header[0x08]);
if (headerSize != STANDARD_2IMG_HEADER_SIZE)
return false;
Expand Down Expand Up @@ -352,6 +348,17 @@ private void ioLatchC() {
loadMode = false;
if (!writeMode)
{
if (!isMotorOn)
{
// simple hack to fool DOS SAMESLOT drive spin check (usually at $BD34)
driveSpin = !driveSpin;
if (driveSpin)
{
latchData = 0x7F;
return;
}
}

// Read data: C0xE, C0xC
latchData = (realTrack[currNibble] & 0xff);

Expand Down
64 changes: 51 additions & 13 deletions Source/Em6502.java
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
import java.io.PrintWriter;


/**
* AppleIIGo
* Apple II Emulator for J2SE
* (C) 2006 by Marc S. Ressl([email protected])
* Copyright 2006 by Marc S. Ressl([email protected])
* Released under the GPL
* Adapted from code by Doug Kwan
* Adapted from code by Randy Frank [email protected]
* Adapted from code (C) 1989 Ben Koning [556498717 408/738-1763 [email protected]]
* Adapted from code Copyright 1989 Ben Koning [556498717 408/738-1763 [email protected]]
*/

public class Em6502 {
Expand Down Expand Up @@ -78,6 +80,7 @@ protected void onIRQ() {
public static final int FLAG_I = (1 << 2);
public static final int FLAG_D = (1 << 3);
public static final int FLAG_B = (1 << 4);
public static final int FLAG_R = (1 << 6);
public static final int FLAG_V = (1 << 6);
public static final int FLAG_N = (1 << 7);
/*
Expand Down Expand Up @@ -120,6 +123,8 @@ protected void onIRQ() {
* Constructor
*/
public Em6502() {
// createRunFile();

// Init BCD tables
BCDTableAdd = new int[512];
BCDTableSub = new int[512];
Expand All @@ -133,6 +138,10 @@ public Em6502() {
BCDTableSub[i] = ((i & 0x0f) <= 0x09) ? i : (i - 0x06);
BCDTableSub[i] -= ((BCDTableSub[i] & 0xf0) <= 0x90) ? 0 : 0x60;
}

// Init CPU
S = 0xFF;
P = FLAG_B | FLAG_R;
}

/*
Expand Down Expand Up @@ -294,9 +303,39 @@ private final void branch(int operand) {
clock++;
}

// private PrintWriter runFile;
// private void createRunFile()
// {
// try
// {
// runFile = new PrintWriter("C:\\Users\\Public\\AppleIIGoRun.txt");
// }
// catch (Exception ex)
// {
// // swallow
// }
// }
// private final void writeRunFile(int opcode)
// {
// if (
// (PC > 0x0500)
// &&
// (PC < 0x0600)
// )
// {
// setN(getFN());
// setZ(getFZ());
// setC(getFC());
//
// runFile.printf("%04X-%02X P=%02X A=%02X\r\n", PC, opcode, P, A);
// runFile.flush();
// }
// }

/** This executes a single instruction. */
private final void executeInstruction() {
opcode = memoryRead(PC);
// writeRunFile(opcode);
PC++;

switch(opcode) {
Expand Down Expand Up @@ -535,8 +574,7 @@ private final void executeInstruction() {
setN(getFN());
setZ(getFZ());
setC(getFC());
setB(true);
push(P);
push(P); // break flag is always set
setI(true);
PC = memoryRead(0xfffe);
PC |= memoryRead(0xffff) << 8;
Expand Down Expand Up @@ -1043,7 +1081,7 @@ private final void executeInstruction() {
break;

case 0x28: // PLP
P = pop() | 0x20; // fix bug in bit5 of P
P = pop() | FLAG_B | FLAG_R; // fix bug in bit5 of P
setFC(getC());
setFNZ(getN(), getZ());
clock += 4;
Expand Down Expand Up @@ -1144,7 +1182,7 @@ private final void executeInstruction() {
break;

case 0x40: // RTI
P = pop() | 0x20; // bit 5 bug of 6502
P = pop() | FLAG_B | FLAG_R; // bit 5 bug of 6502
setFC(getC());
setFNZ(getN(), getZ());
PC = pop(); // splitting is necessary
Expand Down Expand Up @@ -1570,13 +1608,13 @@ public final void checkInterrupts() {
if ((exceptionRegister & SIG_6502_RESET) != 0) {
onReset();

PC = memoryRead(0xfffc);
PC |= (memoryRead(0xfffd) << 8);
S = (S - 3) & 0xff;
setI(true);
setD(false); // not on NMOS 6502
setFC(getC());
setFNZ(getN(), getZ());
S = (S - 3) & 0xff;
setI(true);
PC = memoryRead(0xfffc);
PC |= (memoryRead(0xfffd) << 8);
clock += 7;
exceptionRegister &= ~SIG_6502_RESET;
}
Expand All @@ -1590,7 +1628,8 @@ public final void checkInterrupts() {
setN(getFN());
setZ(getFZ());
setC(getFC());
push(P);
push(P & ~FLAG_B);
setI(true);
PC = memoryRead(0xfffa);
PC |= memoryRead(0xfffb) << 8;
clock += 7;
Expand All @@ -1608,8 +1647,7 @@ public final void checkInterrupts() {
setN(getFN());
setZ(getFZ());
setC(getFC());
setB(false);
push(P);
push(P & ~FLAG_B);
setI(true);
PC = memoryRead(0xfffe);
PC |= memoryRead(0xffff) << 8;
Expand Down
2 changes: 1 addition & 1 deletion Source/EmAppleII.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
/**
* AppleIIGo
* Apple II Emulator for J2ME
* (C) 2006 by Marc S. Ressl([email protected])
* Copyright 2006 by Marc S. Ressl([email protected])
* Released under the GPL
*/

Expand Down
2 changes: 1 addition & 1 deletion Source/Paddle.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
/**
* AppleIIGo
* Apple II Emulator for J2ME
* (C) 2006 by Marc S. Ressl([email protected])
* Copyright 2006 by Marc S. Ressl([email protected])
* Released under the GPL
*/

Expand Down
2 changes: 1 addition & 1 deletion Source/Peripheral.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
/**
* AppleIIGo
* Slot interface
* (C) 2006 by Marc S. Ressl([email protected])
* Copyright 2006 by Marc S. Ressl([email protected])
* Released under the GPL
* Based on work by Steven E. Hugg
*/
Expand Down

0 comments on commit dc8f597

Please sign in to comment.