Skip to content

Commit

Permalink
#2 Added Vic-folder and renamed namespace
Browse files Browse the repository at this point in the history
  • Loading branch information
hagronnestad committed Mar 29, 2020
1 parent a126d0e commit cf36a70
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 17 deletions.
3 changes: 2 additions & 1 deletion ComputerSystems/Commodore64/C64.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
using Hardware.Mos6526Cia;
using System.Threading.Tasks;
using System;
using static Commodore64.VicIi;
using static Commodore64.Vic.VicIi;
using Commodore64.Vic;

namespace Commodore64 {
public class C64 {
Expand Down
1 change: 1 addition & 0 deletions ComputerSystems/Commodore64/C64Bus.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using System.Diagnostics;
using System.IO;
using System;
using Commodore64.Vic;

namespace Commodore64 {

Expand Down
2 changes: 1 addition & 1 deletion ComputerSystems/Commodore64/Commodore64.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Settings.cs" />
<Compile Include="VicIi.cs" />
<Compile Include="Vic\VicIi.cs" />
<EmbeddedResource Include="FormC64Screen.resx">
<DependentUpon>FormC64Screen.cs</DependentUpon>
</EmbeddedResource>
Expand Down
1 change: 1 addition & 0 deletions ComputerSystems/Commodore64/FormC64Screen.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
using System.Threading;
using System.Drawing.Imaging;
using System.Drawing.Drawing2D;
using Commodore64.Vic;

namespace ComputerSystem.Commodore64 {
public partial class FormC64Screen : Form {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
using Extensions.Byte;
using Extensions.Enums;

namespace Commodore64 {
namespace Commodore64.Vic {
public class VicIi {

/// <summary>
Expand Down Expand Up @@ -65,7 +65,7 @@ public byte this[int index] {
case REGISTER_0x11_SCREEN_CONTROL_1:
// Bit #7 og 0x11 is set if current raster line > 255
_registers[index].SetBit(BitFlag.BIT_7, CurrentLine > 255);

return _registers[index];

// Current raster line (bits #0-#7).
Expand Down Expand Up @@ -170,7 +170,7 @@ public void Cycle() {

// Generate raster interrupt if the current line equals interrupt line
// TODO: Implement the Interrupt latch register ($D019) !!!!!!!
if (InterruptControlRegisterRasterInterruptEnabled && (CurrentLine == _rasterLineToGenerateInterruptAt)) {
if (InterruptControlRegisterRasterInterruptEnabled && CurrentLine == _rasterLineToGenerateInterruptAt) {
OnGenerateRasterLineInterrupt?.Invoke(this, null);
}

Expand Down Expand Up @@ -214,7 +214,7 @@ public void Cycle() {
}

} else {

if (IsInBorder(p)) {
RenderBorder();
}
Expand Down Expand Up @@ -259,10 +259,10 @@ private void RenderStandardCharacterMode() {
var fgColor = Colors.FromByte((byte)(C64.Memory[C64MemoryOffsets.SCREEN_COLOR_RAM + charNumber] & 0b00001111));

var charRow = (CurrentLine - DisplayFrame.Y) % 8;
var charRowData = vicRead((ushort)(getCharacterMemoryPointer() + (petsciiCode * 8) + charRow));
var charRowData = vicRead((ushort)(getCharacterMemoryPointer() + petsciiCode * 8 + charRow));

for (int col = 0; col <= 7; col++) {
ScreenBufferPixels[DisplayFrame.Y + (charLine * 8) + charRow, DisplayFrame.X + (charNumberInLine * 8) + col] = charRowData.IsBitSet(7 - (BitIndex)col) ? fgColor : bgColor;
ScreenBufferPixels[DisplayFrame.Y + charLine * 8 + charRow, DisplayFrame.X + charNumberInLine * 8 + col] = charRowData.IsBitSet(7 - (BitIndex)col) ? fgColor : bgColor;
}
}

Expand All @@ -271,16 +271,16 @@ private void RenderBorder() {
var bgColor = Colors.FromByte((byte)(_registers[0x20] & 0b00001111));

for (int i = 0; i < 8; i++) {
ScreenBufferPixels[CurrentLine, (CurrentLineCycle * 8) + i] = bgColor;
ScreenBufferPixels[CurrentLine, CurrentLineCycle * 8 + i] = bgColor;
}

}

public GraphicsMode GetCurrentGraphicsMode() {
var ecm_bmm_r0x11_b65 = (this[REGISTER_0x11_SCREEN_CONTROL_1] >> 5) & 0b00000011;
var mcm_r0x16_b4 = (this[REGISTER_0x16_SCREEN_CONTROL_2] >> 4) & 0b00000001;
var ecm_bmm_r0x11_b65 = this[REGISTER_0x11_SCREEN_CONTROL_1] >> 5 & 0b00000011;
var mcm_r0x16_b4 = this[REGISTER_0x16_SCREEN_CONTROL_2] >> 4 & 0b00000001;

var graphicsMode = mcm_r0x16_b4 | (ecm_bmm_r0x11_b65 << 1);
var graphicsMode = mcm_r0x16_b4 | ecm_bmm_r0x11_b65 << 1;
return (GraphicsMode)graphicsMode;
}

Expand Down Expand Up @@ -310,14 +310,14 @@ public void UpdateScreenBufferPixels() {
var fgColor = Colors.FromByte((byte)(C64.Memory[C64MemoryOffsets.SCREEN_COLOR_RAM + i] & 0b00001111));
//var fgColor = Colors.FromByte((byte)(vicRead((ushort)(0x0800 + i)) & 0b00001111));

var line = (i / 40);
var line = i / 40;
var characterInLine = i % 40;

for (int row = 0; row <= 7; row++) {
var charRow = vicRead((ushort)(getCharacterMemoryPointer() + (petsciiCode * 8) + row));
var charRow = vicRead((ushort)(getCharacterMemoryPointer() + petsciiCode * 8 + row));

for (int col = 0; col <= 7; col++) {
ScreenBufferPixels[DisplayFrame.Y + (line * 8) + row, DisplayFrame.X + (characterInLine * 8) + col] = charRow.IsBitSet(7 - (BitIndex)col) ? fgColor : bgColor;
ScreenBufferPixels[DisplayFrame.Y + line * 8 + row, DisplayFrame.X + characterInLine * 8 + col] = charRow.IsBitSet(7 - (BitIndex)col) ? fgColor : bgColor;
}

}
Expand All @@ -326,7 +326,7 @@ public void UpdateScreenBufferPixels() {
}

public int getScreenMemoryPointer() {
var bit4to7 = (C64.Memory.Read(0xD018) >> 4) & 0b00001111;
var bit4to7 = C64.Memory.Read(0xD018) >> 4 & 0b00001111;

switch (bit4to7) {
case 0b0000:
Expand Down Expand Up @@ -368,7 +368,7 @@ public int getScreenMemoryPointer() {
}

public int getCharacterMemoryPointer() {
var bit1to3 = (C64.Memory.Read(0xD018) >> 1) & 0b00000111;
var bit1to3 = C64.Memory.Read(0xD018) >> 1 & 0b00000111;

switch (bit1to3) {
case 0b000:
Expand Down

0 comments on commit cf36a70

Please sign in to comment.