Skip to content

Commit

Permalink
#2 Started implementing VIC-II bank switching
Browse files Browse the repository at this point in the history
  • Loading branch information
hagronnestad committed Oct 14, 2019
1 parent c1e62b2 commit 5475c13
Showing 1 changed file with 42 additions and 4 deletions.
46 changes: 42 additions & 4 deletions ComputerSystems/Commodore64/FormC64Screen.cs
Original file line number Diff line number Diff line change
Expand Up @@ -89,24 +89,25 @@ private void InvalidateScreen() {
}
}

public void UpdateScreenBuffer() {
public void UpdateScreenBuffer() {
var bgColor = Colors.FromByte((byte)(C64.Memory[C64MemoryLocations.SCREEN_BACKGROUND_COLOR] & 0b00001111));

for (var i = 0; i < 1000; i++) {
var petsciiCode = C64.Memory[C64MemoryOffsets.SCREEN_BUFFER + i];
var petsciiCode = vicRead(0x400 + i);
var fgColor = Colors.FromByte((byte)(C64.Memory[C64MemoryOffsets.SCREEN_COLOR_RAM + i] & 0b00001111));
//var fgColor = Colors.FromByte((byte)(vicRead(0x0800 + i) & 0b00001111));

var line = (i / 40);
var characterInLine = i % 40;
var indexLineOffset = (2560 * line) + (8 * characterInLine);

for (int row = 0; row <= 7; row++) {
var charRow = C64.Memory._romCharacter.Read((petsciiCode * 8) + row);
//var charRow = C64.Memory._romCharacter.Read((petsciiCode * 8) + row);

// TODO: Don't read directly from the character ROM, needs some CIA logic for it to work I think
// We're in the context of the VIC-II here, so we have to keep in mind that the VIC sees other
// memory than the CPU.
//var charRow = C64.Memory.Read(0xD000 + (petsciiCode * 8) + row);
var charRow = vicRead(0x1000 + (petsciiCode * 8) + row);

var indexRowOffset = indexLineOffset + (320 * row);

Expand All @@ -124,6 +125,43 @@ public void UpdateScreenBuffer() {
_gC64ScreenOutputBuffer.DrawImage(_bC64ScreenBuffer, 0, 0, _bC64ScreenOutputBuffer.Width, _bC64ScreenOutputBuffer.Height);
}

public byte vicRead(int address) {

var vicBankOffset = 0;

switch (C64.Memory[0xDD00] & 0b00000011)
{
case 0b00000011:
vicBankOffset = 0;

if (address >= 0x1000 && address <= 0x1FFF) {
return C64.Memory._romCharacter[address - 0x1000];
}

break;

case 0b00000010:
vicBankOffset = 0x4000;
break;

case 0b00000001:
vicBankOffset = 0x8000;

if (address >= 0x9000 && address <= 0x9FFF) {
return C64.Memory._romCharacter[address - 0x9000];
}

break;

case 0b00000000:
vicBankOffset = 0xC000;
break;
}


return C64.Memory.Read(address + vicBankOffset);
}

public void ApplyCrtFilter() {
for (int i = 0; i < _bC64ScreenOutputBuffer.Width; i += (int)(_penScanLine2.Width * 2)) {
_gC64ScreenOutputBuffer.DrawLine(_penScanLine2, i, 0, i, _bC64ScreenOutputBuffer.Height);
Expand Down

0 comments on commit 5475c13

Please sign in to comment.