Skip to content

Commit ae3ff8d

Browse files
committed
Initial implementation of vic bus trick implementation.
1 parent 4f43f69 commit ae3ff8d

8 files changed

Lines changed: 117 additions & 54 deletions

File tree

core/src/main/java/emu/jvic/io/Via6522.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,8 @@ public Via6522(boolean autoResetIrq) {
183183
* @param value The byte to write into the address.
184184
*/
185185
public void writeMemory(int address, int value) {
186+
memory.setLastBusData(value);
187+
186188
switch (address & 0x000F) {
187189
case VIA_REG_0: // ORB/IRB
188190
outputRegisterB = value;
@@ -538,6 +540,8 @@ else if (ca2ControlMode == OUTPUT_MODE_PULSE) {
538540
break;
539541
}
540542

543+
memory.setLastBusData(value);
544+
541545
return value;
542546
}
543547

core/src/main/java/emu/jvic/memory/Memory.java

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,7 @@ public class Memory {
2929
*/
3030
protected Cpu6502 cpu;
3131

32-
// TODO: To support VIC bus tricks.
33-
protected int lastRead;
34-
protected int lastWrite;
32+
// To support VIC bus tricks.
3533
protected int lastBusData;
3634

3735
/**
@@ -174,13 +172,9 @@ public Cpu6502 getCpu() {
174172
public int getLastBusData() {
175173
return lastBusData;
176174
}
177-
178-
public int getLastRead() {
179-
return lastRead;
180-
}
181175

182-
public int getLastWrite() {
183-
return lastWrite;
176+
public void setLastBusData(int lastBusData) {
177+
this.lastBusData = lastBusData;
184178
}
185179

186180
/**
@@ -200,8 +194,7 @@ public MemoryMappedChip[] getMemoryMap() {
200194
* @return The contents of the memory address.
201195
*/
202196
public int readMemory(int address) {
203-
lastBusData = lastRead = memoryMap[address].readMemory(address);
204-
return (lastBusData);
197+
return memoryMap[address].readMemory(address);
205198
}
206199

207200
/**
@@ -211,7 +204,6 @@ public int readMemory(int address) {
211204
* @param value The value to write to the given address.
212205
*/
213206
public void writeMemory(int address, int value) {
214-
lastBusData = lastWrite = value;
215207
memoryMap[address].writeMemory(address, value);
216208
}
217209

core/src/main/java/emu/jvic/memory/NibbleRamChip.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,9 @@ public class NibbleRamChip extends MemoryMappedChip {
1515
* @return the contents of the memory address.
1616
*/
1717
public int readMemory(int address) {
18-
return mem[address];
18+
int value = mem[address];
19+
memory.setLastBusData(value);
20+
return value;
1921
}
2022

2123
/**
@@ -25,6 +27,7 @@ public int readMemory(int address) {
2527
* @param value the value to write to the given address.
2628
*/
2729
public void writeMemory(int address, int value) {
30+
memory.setLastBusData(value);
2831
mem[address] = (value & 0x0F);
2932
}
3033
}

core/src/main/java/emu/jvic/memory/Vic20Memory.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,22 +76,22 @@ public Vic20Memory(Cpu6502 cpu, Vic vic, Via6522 via1, Via6522 via2, int ramExpa
7676
private void initVicMemory(Vic vic, Via6522 via1, Via6522 via2, byte[] basicRom, byte[] kernalRom, byte[] charRom) {
7777

7878
// This 1K of RAM is always present.
79-
mapChipToMemory(new RamChip(), 0x0000, 0x03FF);
79+
mapChipToMemory(new VicBusRamChip(), 0x0000, 0x03FF);
8080

8181
// The next 3K of memory may have RAM or may be unconnected.
8282
mapChipToMemory((ramExpansion & RAM_1) != 0 ? new RamChip() : new UnconnectedMemory(), 0x0400, 0x07FF);
8383
mapChipToMemory((ramExpansion & RAM_2) != 0 ? new RamChip() : new UnconnectedMemory(), 0x0800, 0x0BFF);
8484
mapChipToMemory((ramExpansion & RAM_3) != 0 ? new RamChip() : new UnconnectedMemory(), 0x0C00, 0x0FFF);
8585

8686
// This 4K of RAM is always present.
87-
mapChipToMemory(new RamChip(), 0x1000, 0x1FFF);
87+
mapChipToMemory(new VicBusRamChip(), 0x1000, 0x1FFF);
8888

8989
// The next three 8K blocks may have RAM or may be unconnected.
9090
mapChipToMemory((ramExpansion & BLK_1) != 0 ? new RamChip() : new UnconnectedMemory(), 0x2000, 0x3FFF);
9191
mapChipToMemory((ramExpansion & BLK_2) != 0 ? new RamChip() : new UnconnectedMemory(), 0x4000, 0x5FFF);
9292
mapChipToMemory((ramExpansion & BLK_3) != 0 ? new RamChip() : new UnconnectedMemory(), 0x6000, 0x7FFF);
9393

94-
mapChipToMemory(new RomChip(), 0x8000, 0x8FFF, charRom);
94+
mapChipToMemory(new VicBusRomChip(), 0x8000, 0x8FFF, charRom);
9595

9696
// These are the standard locations for the VIC, VIA1 and VIA2 chips.
9797
mapChipToMemory(vic, 0x9000, 0x900F);
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
package emu.jvic.memory;
2+
3+
/**
4+
* This class emulates a RAM chip on the VIC bus.
5+
*
6+
* @author Lance Ewing
7+
*/
8+
public class VicBusRamChip extends RamChip {
9+
10+
/**
11+
* Reads the value of the given memory address.
12+
*
13+
* @param address the address to read the byte from.
14+
*
15+
* @return the contents of the memory address.
16+
*/
17+
public int readMemory(int address) {
18+
int value = mem[address];
19+
memory.setLastBusData(value);
20+
return value;
21+
}
22+
23+
/**
24+
* Writes a value to the given memory address.
25+
*
26+
* @param address the address to write the value to.
27+
* @param value the value to write to the given address.
28+
*/
29+
public void writeMemory(int address, int value) {
30+
mem[address] = value;
31+
memory.setLastBusData(value);
32+
}
33+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
package emu.jvic.memory;
2+
3+
/**
4+
* This class emulates a ROM chip on the VIC bus.
5+
*
6+
* @author Lance Ewing
7+
*/
8+
public class VicBusRomChip extends RomChip {
9+
10+
/**
11+
* Reads the value of the given memory address.
12+
*
13+
* @param address the address to read the byte from.
14+
*
15+
* @return the contents of the memory address.
16+
*/
17+
public int readMemory(int address) {
18+
int value = mem[address];
19+
memory.setLastBusData(value);
20+
return value;
21+
}
22+
23+
/**
24+
* Writes a value to the given memory address.
25+
*
26+
* @param address the address to write the value to.
27+
* @param value the value to write to the given address.
28+
*/
29+
public void writeMemory(int address, int value) {
30+
// Has no effect.
31+
memory.setLastBusData(value);
32+
}
33+
}

core/src/main/java/emu/jvic/video/Vic.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -291,6 +291,8 @@ public int readMemory(int address) {
291291
value = charData & 0xFF;
292292
}
293293

294+
memory.setLastBusData(value);
295+
294296
return value;
295297
}
296298

@@ -301,6 +303,8 @@ public int readMemory(int address) {
301303
* @param value The value to write into the address.
302304
*/
303305
public void writeMemory(int address, int value) {
306+
memory.setLastBusData(value);
307+
304308
// This is how the VIC chip is mapped, i.e. each register to multiple addresses.
305309
address = address & 0xFF0F;
306310

core/src/main/java/emu/jvic/video/Vic6561.java

Lines changed: 32 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -749,28 +749,25 @@ public boolean emulateCycle() {
749749
multiColourTable[2] = (colourData & 0x07);
750750

751751
// Calculate address within video memory and fetch cell index.
752-
// TODO: Implement unconnected memory check.
753752
int screenAddress = screen_mem_start + videoMatrixCounter;
754753

755-
//switch ((screenAddress >> 10) & 0xF) {
756-
// case 4:
757-
// case 5:
758-
// case 6:
759-
// case 7:
760-
// case 9:
761-
// case 10:
762-
// case 11:
763-
// cellIndex = memory.getLastWrite();
764-
// break;
765-
//
766-
// default:
767-
// cellIndex = mem[VIC_MEM_TABLE[screenAddress & 0x3FFF]];
768-
// break;
769-
//}
754+
switch ((screenAddress >> 10) & 0xF) {
755+
case 4:
756+
case 5:
757+
case 6:
758+
case 7:
759+
case 9:
760+
case 10:
761+
case 11:
762+
// Unconnected memory, so VIC chip sees what CPU put on bus.
763+
cellIndex = memory.getLastBusData();
764+
break;
765+
766+
default:
767+
cellIndex = mem[VIC_MEM_TABLE[screenAddress & 0x3FFF]];
768+
break;
769+
}
770770

771-
// TODO: Replace with unconnected memory version above.
772-
cellIndex = mem[VIC_MEM_TABLE[screenAddress & 0x3FFF]];
773-
774771
// Due to the way the colour memory is wired up, the above fetch of the cell
775772
// index also happens to automatically fetch the foreground colour from the
776773
// Colour Matrix via the top 4 lines of the data bus (DB8-DB11), which are
@@ -809,25 +806,22 @@ public boolean emulateCycle() {
809806
// Calculate offset of data.
810807
charDataOffset = char_mem_start + (cellIndex << char_size_shift) + cellDepthCounter;
811808

812-
// TODO: Add unconnected memory check here.
813-
//switch ((charDataOffset >> 10) & 0xF) {
814-
// case 4:
815-
// case 5:
816-
// case 6:
817-
// case 7:
818-
// case 9:
819-
// case 10:
820-
// case 11:
821-
// charDataLatch = memory.getLastWrite();
822-
// break;
823-
// default:
824-
// // Adjust offset for memory wrap around.
825-
// charDataLatch = mem[VIC_MEM_TABLE[(charDataOffset & 0x3FFF)]];
826-
// break;
827-
//}
828-
829-
// Fetch cell data, initially latched to the side until it is needed.
830-
charDataLatch = mem[VIC_MEM_TABLE[(charDataOffset & 0x3FFF)]];
809+
switch ((charDataOffset >> 10) & 0xF) {
810+
case 4:
811+
case 5:
812+
case 6:
813+
case 7:
814+
case 9:
815+
case 10:
816+
case 11:
817+
// Unconnected memory, so VIC chip sees what CPU put on bus.
818+
charDataLatch = memory.getLastBusData();
819+
break;
820+
default:
821+
// Fetch cell data, initially latched to the side until it is needed.
822+
charDataLatch = mem[VIC_MEM_TABLE[(charDataOffset & 0x3FFF)]];
823+
break;
824+
}
831825

832826
// Determine next character pixels.
833827
if (hiresMode) {

0 commit comments

Comments
 (0)