/**
 * Represents the ZX 48K ULA screen. (0x4000-0x5AFF)
 * I.e. it takes a bank and converts it to a gif image.
 */ class VisualMem { protected static palette = [ 0x80 , 0x80 , 0x80 , 0x00 , 0xC0 , 0xC0 , 0x00 , 0xFF , 0xC0 , 0x00 , 0x00 , 0xFF , 0x00 , 0x00 , 0xC0 , 0xFF , ] ; param canvas param visualMem public static drawVisualMemory ( canvas , visualMem ) { const ctx = canvas . getContext ( "2d" ) ! ; const len = visualMem . length ; const imgData = ctx . createImageData ( len , 1 ) ; const pixels = imgData . data ; let pixelIndex = 0 ; for ( let i = 0 ; i < len ; i ++ ) { const value = visualMem [ i ] ; let colorIndex = 4 * value ; pixels [ pixelIndex ++ ] = this . palette [ colorIndex ++ ] ; pixels [ pixelIndex ++ ] = this . palette [ colorIndex ++ ] ; pixels [ pixelIndex ++ ] = this . palette [ colorIndex ++ ] ; pixels [ pixelIndex ++ ] = this . palette [ colorIndex ] ; } canvas . width = len ; canvas . height = 1 ; ctx . putImageData ( imgData , 0 , 0 ) ; } }