Skip to content

Commit

Permalink
#2 Removed hard coded values, preparing scan line rendering
Browse files Browse the repository at this point in the history
  • Loading branch information
hagronnestad committed Oct 21, 2019
1 parent 66c9f1e commit e55a801
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 22 deletions.
6 changes: 4 additions & 2 deletions ComputerSystems/Commodore64/C64.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using Hardware.Mos6526Cia;
using System.Threading.Tasks;
using System;
using static Commodore64.VicIi;

namespace Commodore64 {
public class C64 {
Expand Down Expand Up @@ -37,8 +38,9 @@ public void Initialize() {
RemoveEventHandlers();

Cia = new Cia();
Vic = new VicIi();
Vic.C64 = this;
Vic = new VicIi(TvSystem.PAL) {
C64 = this
};
Memory = new C64Bus(Cia, Vic);
Cpu = new Cpu(Memory);

Expand Down
2 changes: 1 addition & 1 deletion ComputerSystems/Commodore64/FormC64Screen.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public FormC64Screen(C64 c64) {

C64 = c64;

_bC64ScreenBuffer = new Bitmap(320, 200, PixelFormat.Format24bppRgb);
_bC64ScreenBuffer = new Bitmap(VicIi.USABLE_WIDTH_BORDER, VicIi.USABLE_HEIGHT_BORDER, PixelFormat.Format24bppRgb);
_bC64ScreenOutputBuffer = new Bitmap(pScreen.Width, pScreen.Height);
_gC64ScreenOutputBuffer = Graphics.FromImage(_bC64ScreenOutputBuffer);
_penScanLine = new Pen(Color.FromArgb(100, 127, 127, 127));
Expand Down
40 changes: 21 additions & 19 deletions ComputerSystems/Commodore64/VicIi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,9 @@ public class VicIi {
private const byte REGISTER_INTERRUPT_STATUS_0x19 = 0x19;
private const byte REGISTER_INTERRUPT_CONTROL_0x1A = 0x1A;

public Color[] ScreenBufferPixels { get; } = new Color[320 * 200];
public Color[] ScreenBufferPixels { get; }

private readonly TvSystem _tvSystem;
private int _rasterLineToGenerateInterruptAt = 0;

public byte this[int index] {
Expand Down Expand Up @@ -86,16 +87,15 @@ public enum TvSystem {

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_BORDER = 320;
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 const int USABLE_HEIGHT_BORDER = 200;

public int CurrentLine = 0;
public int CurrentLineCycle = 0;

Expand All @@ -118,31 +118,33 @@ public enum TvSystem {

//public bool IsInBorder =>

public VicIi() {
public VicIi(TvSystem tvSystem) {
_tvSystem = tvSystem;

ScreenBufferPixels = new Color[USABLE_WIDTH_BORDER * USABLE_HEIGHT_BORDER];
}

public int X = 0;
public int Y = 0;

public void Cycle() {

if (InBorder && CurrentLine >= 0 && CurrentLine <= 200) {
var bgColor = Colors.FromByte((byte)(_registers[0x20] & 0b00001111));
//if (InBorder && CurrentLine >= 0 && CurrentLine <= 200) {
// var bgColor = Colors.FromByte((byte)(_registers[0x20] & 0b00001111));

for (int i = 0; i < 8; i++) {
ScreenBufferPixels[Y * 320 + X + i] = bgColor;
}
// for (int i = 0; i < 8; i++) {
// ScreenBufferPixels[Y * 320 + X + i] = bgColor;
// }

X += 8;
// X += 8;

if (X == 40) {
X = 0;
Y++;
// if (X == 40) {
// X = 0;
// Y++;

if (Y == 200) Y = 0;
}
}
// if (Y == 200) Y = 0;
// }
//}

CurrentLineCycle++;

Expand Down Expand Up @@ -187,7 +189,7 @@ public void UpdateScreenBufferPixels() {
for (int row = 0; row <= 7; row++) {
var charRow = vicRead((ushort)(getCharacterMemoryPointer() + (petsciiCode * 8) + row));

var indexRowOffset = indexLineOffset + (320 * row);
var indexRowOffset = indexLineOffset + (USABLE_WIDTH_BORDER * row);

for (int col = 0; col <= 7; col++) {
var indexPixelOffset = indexRowOffset + col;
Expand Down

0 comments on commit e55a801

Please sign in to comment.