clean up, remove duplication

This commit is contained in:
Will Scullin 2021-05-23 14:17:38 -07:00
parent 81b30842d8
commit 079cecc367
No known key found for this signature in database
GPG Key ID: 26DCD1042C6638CD
2 changed files with 25 additions and 43 deletions

View File

@ -134,9 +134,7 @@ export class LoresPage2D implements LoresPage {
private readonly e: boolean
) {
this.imageData = this.vm.context.createImageData(560, 192);
for (let idx = 0; idx < 560 * 192 * 4; idx++) {
this.imageData.data[idx] = 0xff;
}
this.imageData.data.fill(0xff);
this._buffer[0] = allocMemPages(0x4);
this._buffer[1] = allocMemPages(0x4);
@ -514,9 +512,7 @@ export class HiresPage2D implements HiresPage {
private page: pageNo,
) {
this.imageData = this.vm.context.createImageData(560, 192);
for (let idx = 0; idx < 560 * 192 * 4; idx++) {
this.imageData.data[idx] = 0xff;
}
this.imageData.data.fill(0xff);
this._buffer[0] = allocMemPages(0x20);
this._buffer[1] = allocMemPages(0x20);
@ -882,15 +878,16 @@ export class VideoModes2D implements VideoModes {
) {
this._canvas = document.createElement('canvas');
const context = this._canvas.getContext('2d');
if (!context) {
const screenContext = this.screen.getContext('2d');
if (!context || !screenContext) {
throw new Error('No 2d context');
}
this.context = context;
const screenContext = this.screen.getContext('2d');
if (!screenContext) {
throw new Error('No 2d screen context');
}
const { width, height } = { width: 560, height: 192 };
this._canvas.width = width;
this._canvas.height = height;
this._screenContext = screenContext;
this._left = (this.screen.width - 560) / 2;
this._top = (this.screen.height - 384) / 2;
@ -1037,18 +1034,9 @@ export class VideoModes2D implements VideoModes {
}
buildScreen(mainData: ImageData, mixData?: ImageData | null) {
if (!this.context) {
throw new Error('No 2d context');
}
const { width, height } = { width: 560, height: 192 };
// TODO(whscullin): - figure out 80 column offset
const { x, y } = this._80colMode ? { x: 0, y: 0 } : { x: 0, y: 0 };
this._canvas.width = width;
this._canvas.height = height;
this.context.fillStyle = 'rgba(0,0,0,1)';
this.context.fillRect(0, 0, width, height);
if (mixData) {
this.context.putImageData(mainData, x, y, 0, 0, 560, 160);
this.context.putImageData(mixData, x, y, 0, 160, 560, 32);

View File

@ -61,9 +61,7 @@ export class LoresPageGL implements LoresPage {
private readonly e: boolean
) {
this.imageData = this.vm.context.createImageData(560, 192);
for (let idx = 0; idx < 560 * 192 * 4; idx++) {
this.imageData.data[idx] = 0xff;
}
this.imageData.data.fill(0xff);
this._buffer[0] = allocMemPages(0x4);
this._buffer[1] = allocMemPages(0x4);
@ -377,9 +375,7 @@ export class HiresPageGL implements HiresPage {
private page: pageNo,
) {
this.imageData = this.vm.context.createImageData(560, 192);
for (let idx = 0; idx < 560 * 192 * 4; idx++) {
this.imageData.data[idx] = 0xff;
}
this.imageData.data.fill(0xff);
this._buffer[0] = allocMemPages(0x20);
this._buffer[1] = allocMemPages(0x20);
@ -569,19 +565,19 @@ export class VideoModesGL implements VideoModes {
public ready: Promise<void>
textMode: boolean;
mixedMode: boolean;
hiresMode: boolean;
pageMode: pageNo;
_80colMode: boolean;
altCharMode: boolean;
an3State: boolean;
doubleHiresMode: boolean;
public textMode: boolean;
public mixedMode: boolean;
public hiresMode: boolean;
public pageMode: pageNo;
public _80colMode: boolean;
public altCharMode: boolean;
public an3State: boolean;
public doubleHiresMode: boolean;
flag = 0;
monoMode: boolean = false;
public flag = 0;
public monoMode: boolean = false;
context: CanvasRenderingContext2D;
public context: CanvasRenderingContext2D;
constructor(
private screen: HTMLCanvasElement,
@ -592,6 +588,9 @@ export class VideoModesGL implements VideoModes {
if (!context) {
throw new Error('no 2d context');
}
const { width, height } = screenEmu.C.NTSC_DETAILS.imageSize;
this._canvas.width = width;
this._canvas.height = height;
this.context = context;
this._sv = new screenEmu.ScreenView(this.screen);
@ -794,11 +793,6 @@ export class VideoModesGL implements VideoModes {
const { width, height } = details.imageSize;
const { x, y } = this._80colMode ? details.topLeft80Col : details.topLeft;
this._canvas.width = width;
this._canvas.height = height;
this.context.fillStyle = 'rgba(0,0,0,1)';
this.context.fillRect(0, 0, width, height);
if (mixData) {
this.context.putImageData(mainData, x, y, 0, 0, 560, 160);
this.context.putImageData(mixData, x, y, 0, 160, 560, 32);