Skip to content

Commit

Permalink
Fix XO-Chip display issue to clear only active planes instead of all
Browse files Browse the repository at this point in the history
  • Loading branch information
franciscodelahoz committed Apr 4, 2024
1 parent aa5d95f commit f3df25b
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 13 deletions.
5 changes: 2 additions & 3 deletions src/scripts/emulator/cpu.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ export class CPU {
private readonly audioInterface: AudioInterface,
private readonly keyboardInterface: KeyBoardInterface,
) {
this.displayInstance.clearDisplay();
this.displayInstance.clearDisplayBuffer();
}

private loadFont() {
Expand Down Expand Up @@ -109,7 +109,6 @@ export class CPU {
this.isPaused = false;

this.displayInstance.setResolutionMode(this.hiresMode);
this.displayInstance.clearDisplay();

this.displayInstance.render();
this.keyboardInterface.reset();
Expand Down Expand Up @@ -207,7 +206,7 @@ export class CPU {
* Clear the display.
*/
case 0x00E0: {
this.displayInstance.clearDisplay();
this.displayInstance.clearDisplayBuffer();
this.drawingFlag = true;
break;
}
Expand Down
24 changes: 14 additions & 10 deletions src/scripts/emulator/interfaces/display.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,6 @@ export class DisplayInterface {
this.createDisplayBuffer(),
this.createDisplayBuffer(),
];

this.clearDisplay();
}

public setColorPalette(palette: EmulatorColorPalette) {
Expand All @@ -97,14 +95,16 @@ export class DisplayInterface {
this.planeColors = colorPalettes[palette];
}

clearDisplay() {
this.displayBuffers = [
this.createDisplayBuffer(),
this.createDisplayBuffer(),
];
clearDisplayBuffer() {
for (let plane = 0; plane < 2; plane += 1) {
if (!(this.bitPlane & (plane + 1))) continue;

this.context.fillStyle = this.foregroundColor;
this.context.fillRect(0, 0, this.displayWidth, this.displayHeight);
for (let y = 0; y < this.rows; y += 1) {
for (let x = 0; x < this.columns; x += 1) {
this.displayBuffers[plane][y][x] = 0;
}
}
}
}

setPixel(plane: number = 0, x: number, y: number, value: number) {
Expand All @@ -129,9 +129,13 @@ export class DisplayInterface {
return this.planeColors[colorIndex];
}

render() {
clearCanvas() {
this.context.fillStyle = this.foregroundColor;
this.context.fillRect(0, 0, this.displayWidth, this.displayHeight);
}

render() {
this.clearCanvas();

for (let y = 0; y < this.rows; y += 1) {
for (let x = 0; x < this.columns; x += 1) {
Expand Down

0 comments on commit f3df25b

Please sign in to comment.