From bf789eb2fdc985b7e0ed1a1b97f14a649b4d6ea9 Mon Sep 17 00:00:00 2001 From: Will Scullin Date: Sat, 23 Jul 2022 15:51:12 -0700 Subject: [PATCH] Add hires preview (#146) --- js/canvas.ts | 14 +++--- js/components/debugger/FileViewer.tsx | 43 ++++++++++++++++--- .../debugger/css/FileViewer.module.css | 22 +++++++++- 3 files changed, 65 insertions(+), 14 deletions(-) diff --git a/js/canvas.ts b/js/canvas.ts index 8fae70f..18eb7f9 100644 --- a/js/canvas.ts +++ b/js/canvas.ts @@ -113,7 +113,7 @@ export class LoresPage2D implements LoresPage { private highColorTextMode = false; - dirty: Region = {...notDirty}; + dirty: Region = { ...notDirty }; imageData: ImageData; constructor( @@ -485,7 +485,7 @@ export class LoresPage2D implements LoresPage { export class HiresPage2D implements HiresPage { public imageData: ImageData; - dirty: Region = {...notDirty}; + dirty: Region = { ...notDirty }; private _buffer: memory[] = []; private _refreshing = false; @@ -604,7 +604,7 @@ export class HiresPage2D implements HiresPage { if (x > this.dirty.right) { this.dirty.right = x; } dy = rowa << 4 | rowb << 1; - let bz, b0, b1, b2, b3, b4, c, hb; + let bz, b0, b1, b2, b3, b4, c; if (this.oneSixtyMode && !this.vm.monoMode) { // 1 byte = two pixels, but 3:4 ratio const c3 = val & 0xf; @@ -643,8 +643,8 @@ export class HiresPage2D implements HiresPage { ((b2 & 0x40) >> 6) | ((b3 & 0x07) << 1), // 5 ((b3 & 0x78) >> 3), // 6 0 - ], // 7 - hb = [ + ]; // 7 + const hb = [ 0, b0 & 0x80, // 0 b0 & 0x80, // 1 @@ -1092,8 +1092,8 @@ export class VideoModes2D implements VideoModes { gr.imageData, gr.dirty ); } - hgr.dirty = {...notDirty}; - gr.dirty = {...notDirty}; + hgr.dirty = { ...notDirty }; + gr.dirty = { ...notDirty }; return blitted; } diff --git a/js/components/debugger/FileViewer.tsx b/js/components/debugger/FileViewer.tsx index 86470a3..3318b59 100644 --- a/js/components/debugger/FileViewer.tsx +++ b/js/components/debugger/FileViewer.tsx @@ -1,5 +1,6 @@ +import { HiresPage2D, LoresPage2D, VideoModes2D } from 'js/canvas'; import { h, Fragment } from 'preact'; -import { useEffect, useState } from 'preact/hooks'; +import { useEffect, useRef, useState } from 'preact/hooks'; import { Modal, ModalContent, ModalFooter } from '../Modal'; import styles from './css/FileViewer.module.css'; @@ -15,6 +16,35 @@ export interface FileViewerProps { onClose: () => void; } +const HiresPreview = ({ binary }: { binary: Uint8Array }) => { + const canvasRef = useRef(null); + if (binary.byteLength < 8187 || binary.byteLength > 8192) { + return null; + } + + if (canvasRef.current) { + const vm = new VideoModes2D(canvasRef.current, true); + const lores = new LoresPage2D(vm, 1, new Uint8Array(), false); + const hires = new HiresPage2D(vm, 1); + vm.setLoresPage(1, lores); + vm.setHiresPage(1, hires); + vm.text(false); + vm.hires(true); + vm.doubleHires(false); + vm.page(1); + + for (let idx = 0; idx < 0x20; idx++) { + for (let jdx = 0; jdx < 0x100; jdx++) { + hires.write(idx + 0x20, jdx, binary[idx * 0x100 + jdx]); + } + } + vm.blit(); + } + + return ; +}; + + export const FileViewer = ({ fileData, onClose }: FileViewerProps) => { const [binaryHref, setBinaryHref] = useState(''); const [textHref, setTextHref] = useState(''); @@ -41,15 +71,18 @@ export const FileViewer = ({ fileData, onClose }: FileViewerProps) => { return null; } - const { fileName, text } = fileData; + const { fileName, text, binary } = fileData; return ( <> -
-                        {text}
-                    
+
+ +
+                            {text}
+                        
+