Skip to content

Commit 1f434cc

Browse files
committed
Fix simple IO bugs.
1 parent e22e9cd commit 1f434cc

File tree

5 files changed

+44
-53
lines changed

5 files changed

+44
-53
lines changed

src/main/java/ca/craigthomas/yacoco3e/components/CPU.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,14 +44,14 @@ public int executeInstruction() throws MalformedInstructionException {
4444
* stored at $FFF8.
4545
*/
4646
public void interruptRequest() {
47+
io.regs.cc.or(CC_E);
4748
io.pushStack(Register.S, io.regs.pc);
4849
io.pushStack(Register.S, io.regs.u);
4950
io.pushStack(Register.S, io.regs.y);
5051
io.pushStack(Register.S, io.regs.x);
5152
io.pushStack(Register.S, io.regs.dp);
5253
io.pushStack(Register.S, io.regs.b);
5354
io.pushStack(Register.S, io.regs.a);
54-
io.regs.cc.or(CC_E);
5555
io.pushStack(Register.S, io.regs.cc);
5656
io.regs.cc.or(CC_I);
5757
io.regs.pc.set(io.readWord(0xFFF8));
@@ -63,8 +63,8 @@ public void interruptRequest() {
6363
* $FFF6.
6464
*/
6565
public void fastInterruptRequest() {
66-
io.pushStack(Register.S, io.regs.pc);
6766
io.regs.cc.and(~CC_E);
67+
io.pushStack(Register.S, io.regs.pc);
6868
io.pushStack(Register.S, io.regs.cc);
6969
io.regs.cc.or(CC_F);
7070
io.regs.cc.or(CC_I);
@@ -77,14 +77,14 @@ public void fastInterruptRequest() {
7777
* stored at $FFFC.
7878
*/
7979
public void nonMaskableInterruptRequest() {
80+
io.regs.cc.or(CC_E);
8081
io.pushStack(Register.S, io.regs.pc);
8182
io.pushStack(Register.S, io.regs.u);
8283
io.pushStack(Register.S, io.regs.y);
8384
io.pushStack(Register.S, io.regs.x);
8485
io.pushStack(Register.S, io.regs.dp);
8586
io.pushStack(Register.S, io.regs.b);
8687
io.pushStack(Register.S, io.regs.a);
87-
io.regs.cc.or(CC_E);
8888
io.pushStack(Register.S, io.regs.cc);
8989
io.regs.cc.or(CC_I);
9090
io.regs.cc.or(CC_F);

src/main/java/ca/craigthomas/yacoco3e/components/Emulator.java

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -460,11 +460,10 @@ public void run() {
460460
status = EmulatorStatus.PAUSED;
461461
}
462462

463-
/* Increment timers if necessary */
464-
io.timerTick(operationTicks);
465-
466-
/* Fire interrupts if set */
467-
cpu.serviceInterrupts();
463+
/* Check to see if we had an instruction - if it's a SYNC, just add to the timers */
464+
if (io.waitForIRQ) {
465+
operationTicks += 1;
466+
}
468467

469468
/* Check to see if we should trace the output */
470469
if (this.trace) {
@@ -474,6 +473,12 @@ public void run() {
474473
System.out.println();
475474
}
476475
}
476+
477+
/* Increment timers if necessary */
478+
io.timerTick(operationTicks);
479+
480+
/* Fire interrupts if set */
481+
cpu.serviceInterrupts();
477482
}
478483
}
479484
this.shutdown();

src/main/java/ca/craigthomas/yacoco3e/components/IOController.java

Lines changed: 4 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -348,22 +348,18 @@ public UnsignedByte readIOByte(int address) {
348348

349349
/* Disk Drive Status Register */
350350
case 0xFF48:
351-
// System.out.println("$FF48 - Reading drive " + diskDriveSelect + " status register " + disk[diskDriveSelect].getStatusRegister());
352351
return disk[diskDriveSelect].getStatusRegister();
353352

354353
/* Disk Track Status Register */
355354
case 0xFF49:
356-
// System.out.println("$FF49 - Reading drive " + diskDriveSelect + " track register " + disk[diskDriveSelect].getTrack());
357355
return new UnsignedByte(disk[diskDriveSelect].getTrack());
358356

359357
/* Disk Sector Status Register */
360358
case 0xFF4A:
361-
// System.out.println("$FF4A - Reading drive " + diskDriveSelect + " sector register " + disk[diskDriveSelect].getSector());
362359
return new UnsignedByte(disk[diskDriveSelect].getSector());
363360

364361
/* Disk Data Register */
365362
case 0xFF4B:
366-
// System.out.println("$FF4B - Reading drive " + diskDriveSelect + " data register " + disk[diskDriveSelect].getDataRegister());
367363
return new UnsignedByte(disk[diskDriveSelect].getDataRegister());
368364

369365
/* IRQs Enabled Register */
@@ -571,7 +567,6 @@ public void writeIOByte(UnsignedWord address, UnsignedByte value) {
571567

572568
/* Disk Drive Control Register */
573569
case 0xFF40:
574-
// System.out.println("$FF40 - Writing control register drive " + diskDriveSelect + " value " + value);
575570
/* Bit 2-0 = Disk drive select */
576571
diskDriveSelect = (value.isMasked(0x1)) ? 0 : diskDriveSelect;
577572
diskDriveSelect = (value.isMasked(0x2)) ? 1 : diskDriveSelect;
@@ -609,19 +604,16 @@ public void writeIOByte(UnsignedWord address, UnsignedByte value) {
609604

610605
/* Track Status Register */
611606
case 0xFF49:
612-
// System.out.println("$FF49 - Writing track register drive " + diskDriveSelect + " value " + value);
613607
disk[diskDriveSelect].setTrack(value);
614608
break;
615609

616610
/* Sector Status Register */
617611
case 0xFF4A:
618-
// System.out.println("$FF4A - Writing sector register drive " + diskDriveSelect + " value " + value);
619612
disk[diskDriveSelect].setSector(value);
620613
break;
621614

622615
/* Disk Data Register */
623616
case 0xFF4B:
624-
// System.out.println("$FF4B - Writing data register drive " + diskDriveSelect + " value " + value);
625617
disk[diskDriveSelect].setDataRegister(value);
626618
break;
627619

@@ -658,7 +650,6 @@ public void writeIOByte(UnsignedWord address, UnsignedByte value) {
658650
}
659651

660652
/* Bit 5 = Timer Rate - 0 is 63.5 microseconds, 1 is 70 nanoseconds */
661-
// timerTickThreshold = (value.isMasked(0x20)) ? TIMER_63_5_MICROS : TIMER_63_5_MICROS;
662653
timerTickThreshold = TIMER_63_5_MICROS;
663654
break;
664655

@@ -782,37 +773,31 @@ public void writeIOByte(UnsignedWord address, UnsignedByte value) {
782773
/* SAM - Video Display - V0 - Clear */
783774
case 0xFFC0:
784775
samControlBits.and(~0x1);
785-
updateVideoMode(pia2b.getVDGOperatingMode());
786776
break;
787777

788778
/* SAM - Video Display - V0 - Set */
789779
case 0xFFC1:
790780
samControlBits.or(0x1);
791-
updateVideoMode(pia2b.getVDGOperatingMode());
792781
break;
793782

794783
/* SAM - Video Display - V1 - Clear */
795784
case 0xFFC2:
796785
samControlBits.and(~0x2);
797-
updateVideoMode(pia2b.getVDGOperatingMode());
798786
break;
799787

800788
/* SAM - Video Display - V1 - Set */
801789
case 0xFFC3:
802790
samControlBits.or(0x2);
803-
updateVideoMode(pia2b.getVDGOperatingMode());
804791
break;
805792

806793
/* SAM - Video Display - V2 - Clear */
807794
case 0xFFC4:
808795
samControlBits.and(~0x4);
809-
updateVideoMode(pia2b.getVDGOperatingMode());
810796
break;
811797

812798
/* SAM - Video Display - V2 - Set */
813799
case 0xFFC5:
814800
samControlBits.or(0x4);
815-
updateVideoMode(pia2b.getVDGOperatingMode());
816801
break;
817802

818803
/* SAM - Display Offset Register - Bit 0 - Clear */
@@ -922,17 +907,6 @@ public void writeIOByte(UnsignedWord address, UnsignedByte value) {
922907
break;
923908

924909
default:
925-
switch(address.getInt()) {
926-
case 0xFFFA:
927-
case 0xFFF2:
928-
case 0xFFF4:
929-
System.out.println("Write to IO address " + address);
930-
break;
931-
932-
default:
933-
break;
934-
}
935-
memory.writeByte(address, value);
936910
break;
937911
}
938912
}
@@ -1011,7 +985,8 @@ public void updateVideoMode(UnsignedByte vdgOperatingMode) {
1011985

1012986
default:
1013987
UnsignedByte fullMode = new UnsignedByte(vdgOperatingMode.getShort() + samControlBits.getShort());
1014-
throw new RuntimeException("Unknown screen mode: " + fullMode);
988+
System.out.println("Unknown screen mode: " + fullMode);
989+
return;
1015990
}
1016991
} else {
1017992
switch (samControlBits.getShort()) {
@@ -1033,7 +1008,8 @@ public void updateVideoMode(UnsignedByte vdgOperatingMode) {
10331008

10341009
default:
10351010
UnsignedByte fullMode = new UnsignedByte(vdgOperatingMode.getShort() + samControlBits.getShort());
1036-
throw new RuntimeException("Unknown screen mode: " + fullMode);
1011+
System.out.println("Unknown screen mode: " + fullMode);
1012+
return;
10371013
}
10381014
}
10391015

src/test/java/ca/craigthomas/yacoco3e/components/BranchInstructionTest.java

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -92,19 +92,24 @@ public void testBranchToSubroutineSavesPCAndReturnsTrue() {
9292

9393
@Test
9494
public void testBranchSubroutine() throws MalformedInstructionException {
95-
io.writeWord(0x0000, 0x8D1F);
95+
io.regs.s.set(0x3000);
96+
regs.pc.set(0x1021);
97+
io.writeWord(0x1021, 0x8D1F);
9698
cpu.executeInstruction();
97-
assertEquals(0x0021, regs.pc.getInt());
98-
assertEquals(0x02, memory.readByte(io.getWordRegister(Register.S).next()).getShort());
99+
assertEquals(0x1042, regs.pc.getInt());
100+
assertEquals(0x23, memory.readByte(0x2FFF).getShort());
101+
assertEquals(0x10, memory.readByte(0x2FFE).getShort());
99102
}
100103

101104
@Test
102105
public void testBranchSubroutineNegativeOffsetCorrect() throws MalformedInstructionException {
103-
regs.pc.set(0x0021);
104-
io.writeWord(0x0021, 0x8DDD);
106+
io.regs.s.set(0x3000);
107+
regs.pc.set(0x1021);
108+
io.writeWord(0x1021, 0x8DDD);
105109
cpu.executeInstruction();
106-
assertEquals(0x0000, regs.pc.getInt());
107-
assertEquals(0x23, memory.readByte(io.getWordRegister(Register.S).next()).getShort());
110+
assertEquals(0x1000, regs.pc.getInt());
111+
assertEquals(0x23, memory.readByte(0x2FFF).getShort());
112+
assertEquals(0x10, memory.readByte(0x2FFE).getShort());
108113
}
109114

110115
@Test

src/test/java/ca/craigthomas/yacoco3e/components/LongBranchInstructionTest.java

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -85,21 +85,26 @@ public void testLongBranchNever() throws MalformedInstructionException {
8585

8686
@Test
8787
public void testLongBranchSubroutine1() throws MalformedInstructionException {
88-
io.writeByte(0x0000, 0x17);
89-
io.writeWord(0x0001, 0x001F);
88+
io.regs.s.set(0x3000);
89+
io.regs.pc.set(0x1000);
90+
io.writeByte(0x1000, 0x17);
91+
io.writeWord(0x1001, 0x001F);
9092
cpu.executeInstruction();
91-
assertEquals(0x0022, regs.pc.getInt());
92-
assertEquals(0x03, memory.readByte(io.getWordRegister(Register.S).next()).getShort());
93+
assertEquals(0x1022, regs.pc.getInt());
94+
assertEquals(0x03, memory.readByte(0x2FFF).getShort());
95+
assertEquals(0x10, memory.readByte(0x2FFE).getShort());
9396
}
9497

9598
@Test
9699
public void testLongBranchSubroutineNegativeOffsetCorrect() throws MalformedInstructionException {
97-
regs.pc.set(0x0021);
98-
io.writeByte(0x0021, 0x17);
99-
io.writeWord(0x0022, 0xFFDC);
100-
cpu.executeInstruction();
101-
assertEquals(0x0000, regs.pc.getInt());
102-
assertEquals(0x24, memory.readByte(io.getWordRegister(Register.S).next()).getShort());
100+
regs.s.set(0x3000);
101+
regs.pc.set(0x1021);
102+
io.writeByte(0x1021, 0x17);
103+
io.writeWord(0x1022, 0xFFDC);
104+
cpu.executeInstruction();
105+
assertEquals(0x1000, regs.pc.getInt());
106+
assertEquals(0x24, memory.readByte(0x2FFF).getShort());
107+
assertEquals(0x10, memory.readByte(0x2FFE).getShort());
103108
}
104109

105110
@Test

0 commit comments

Comments
 (0)