Skip to content

Commit

Permalink
#2 Started implementing the VIC-II
Browse files Browse the repository at this point in the history
  • Loading branch information
hagronnestad committed Oct 12, 2019
1 parent 93042ae commit e8a8b8f
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 0 deletions.
1 change: 1 addition & 0 deletions ComputerSystems/Commodore64/Commodore64.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Settings.cs" />
<Compile Include="VicIi.cs" />
<EmbeddedResource Include="FormC64Screen.resx">
<DependentUpon>FormC64Screen.cs</DependentUpon>
</EmbeddedResource>
Expand Down
71 changes: 71 additions & 0 deletions ComputerSystems/Commodore64/VicIi.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
using Hardware.Memory;
using System.Drawing;

namespace Commodore64 {
public class VicIi {

public enum TvSystem {
NTSC,
PAL
}

public TvSystem CurrentTvSystem = TvSystem.PAL;

public const int FULL_WIDTH = 504;
public const int FULL_WIDTH_CYCLES = 63;
public const int USABLE_WIDTH_BORDER = 403;
public const int USABLE_WIDTH = 320;
public const int USABLE_WIDTH_CYCLES = 40;

public const int FULL_HEIGHT_NTSC = 262;
public const int FULL_HEIGHT_PAL = 312;
public const int USABLE_HEIGHT = 200;
public const int USABLE_HEIGHT_BORDER = 284;
public int CurrentLine = 0;
public int CurrentLineCycle = 0;

public int TotalCycles = 0;

public Color[] ScreenBufferPixels = new Color[USABLE_WIDTH_BORDER * USABLE_HEIGHT_BORDER];

public bool ScreenOn => (Read(0xD011) & 0b00010000) == 1;


private readonly IMemory<byte> _bus;


public VicIi(IMemory<byte> bus) {
_bus = bus;
}

public void Cycle() {


CurrentLineCycle++;

if (CurrentLineCycle == 64) {
CurrentLineCycle = 0;

CurrentLine++;

if ((CurrentTvSystem == TvSystem.PAL && CurrentLine == FULL_HEIGHT_PAL) ||
(CurrentTvSystem == TvSystem.NTSC && CurrentLine == FULL_HEIGHT_NTSC)) {

CurrentLine = 0;
}
}

UpdateScreenBufferPixels();

TotalCycles++;
}

private void UpdateScreenBufferPixels() {

}

public byte Read(int address) {
return _bus[address];
}
}
}

0 comments on commit e8a8b8f

Please sign in to comment.