Skip to content

Commit

Permalink
#2 Work on RenderMultiColorCharacterMode, not working properly atm
Browse files Browse the repository at this point in the history
  • Loading branch information
hagronnestad committed Apr 1, 2020
1 parent f0b0e6f commit 27c67ba
Showing 1 changed file with 70 additions and 0 deletions.
70 changes: 70 additions & 0 deletions ComputerSystems/Commodore64/Vic/VicIi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,7 @@ public void Cycle() {
break;

case GraphicsMode.MultiColorCharacterMode:
RenderMultiColorCharacterMode();
break;

case GraphicsMode.StandardBitmapMode:
Expand Down Expand Up @@ -258,6 +259,75 @@ private void RenderStandardCharacterMode() {
}
}



/// <summary>
/// Render MultiColorCharacterMode
/// </summary>
private void RenderMultiColorCharacterMode() {
var p = GetScanlinePoint();

var line = (CurrentLine - DisplayFrame.Y) / 8;
var column = (p.X - DisplayFrame.X) / 8;
var charOffsetInMemory = line * 40 + column;

var charRow = (CurrentLine - DisplayFrame.Y) % 8;

var screenPointer = getScreenMemoryPointer();
var characterPointer = getCharacterMemoryPointer();

//var charDataOffsetInMemory = C64.Memory.Read(screenPointer + charOffsetInMemory);
var charDataOffsetInMemory = vicRead((ushort)(screenPointer + charOffsetInMemory));

//var charRowData = C64.Memory.Read(characterPointer + charDataOffsetInMemory * 8 + charRow);
var charRowData = vicRead((ushort)(characterPointer + charDataOffsetInMemory * 8 + charRow));

var bgColor1 = Colors.FromByte((byte)(this[Register.REGISTER_0x21_BACKGROUND_COLOR_0] & 0b00001111));
var bgColor2 = Colors.FromByte((byte)(this[Register.REGISTER_0x22_BACKGROUND_COLOR_1] & 0b00001111));
var bgColor3 = Colors.FromByte((byte)(this[Register.REGISTER_0x23_BACKGROUND_COLOR_2] & 0b00001111));
var fgColor = (byte)(C64.Memory[C64MemoryOffsets.SCREEN_COLOR_RAM + charOffsetInMemory] & 0b00001111);

for (int col = 0; col <= 7; col += 2) {

if (fgColor.IsBitSet(BitFlag.BIT_3)) {

var bitPair = charRowData >> (6 - col) & 0b11;

Color pixelColor;

switch (bitPair) {

case 0b00:
pixelColor = bgColor1;
break;

case 0b01:
pixelColor = bgColor2;
break;

case 0b10:
pixelColor = bgColor3;
break;

case 0b11:
pixelColor = Colors.FromByte((byte)(fgColor >> 2 & 0b11));
break;

default:
pixelColor = Color.Red;
break;
}

ScreenBufferPixels[DisplayFrame.Y + line * 8 + charRow, DisplayFrame.X + column * 8 + col] = pixelColor;
ScreenBufferPixels[DisplayFrame.Y + line * 8 + charRow, DisplayFrame.X + column * 8 + col + 1] = pixelColor;

} else {
ScreenBufferPixels[DisplayFrame.Y + line * 8 + charRow, DisplayFrame.X + column * 8 + col] = Colors.FromByte((byte)(fgColor & 0b111));
}
}
}


/// <summary>
/// Render Border
/// </summary>
Expand Down

0 comments on commit 27c67ba

Please sign in to comment.