import { ZxAudioBeeper } from "./zxaudiobeeper" ; declare var acquireVsCodeApi ; declare var cpuLoad ; declare var slots ; declare var visualMem ; declare var screenImgContext ; declare var screenImgImgData ; declare var screenImg ; declare var UIAPI ; declare var zxAudioBeeper ; let countOfProcessedMessages = 0 ; const vscode = acquireVsCodeApi ( ) ; const joystickObjs = new Array < { fire : UiBit ; up : UiBit ; left : UiBit ; right : UiBit ; down : UiBit ; } > ( ) ; const MESSAGE_HIGH_WATERMARK = 100 ; const MESSAGE_LOW_WATERMARK = 10 ; window . addEventListener ( 'message' , event => { countOfProcessedMessages ++ ; if ( countOfProcessedMessages >= MESSAGE_LOW_WATERMARK ) { vscode . postMessage ( { command : 'countOfProcessedMessages' , value : countOfProcessedMessages } ) ; countOfProcessedMessages = 0 ; } const message = event . data ; switch ( message . command ) { case 'cpuStopped' : zxAudioBeeper . stop ( ) ; break ; case 'update' : { if ( message . cpuLoad != undefined ) cpuLoad . innerHTML = message . cpuLoad ; if ( message . slotNames ) { let i = 0 ; for ( const slotString of message . slotNames ) { const slot = slots [ i ++ ] ; if ( slot ) slot . textContent = slotString ; } } if ( message . visualMem ) { VisualMem . drawVisualMemory ( visualMem , message . visualMem ) ; } if ( message . screenImg ) { const data = message . screenImg . ulaData ; const time = message . screenImg . time ; UlaScreen . drawUlaScreen ( screenImgContext , screenImgImgData , data , time ) ; } if ( message . borderColor != undefined ) { const htmlColor = UlaScreen . getHtmlColor ( message . borderColor ) ; screenImg . style . borderColor = htmlColor ; } if ( message . audio ) { const audio = message . audio ; zxAudioBeeper . writeBeeperSamples ( audio ) ; } } break ; case 'receivedFromCustomLogic' : if ( UIAPI . receivedFromCustomLogic ) { const innerMsg = message . value ; UIAPI . receivedFromCustomLogic ( innerMsg ) ; } break ; } } ) ; function cellSelect ( cell , on ) { cell . tag = on ; if ( on ) { cell . className = "td_on" ; } else { cell . className = "td_off" ; } vscode . postMessage ( { command : 'keyChanged' , value : on , key : cell . id } ) ; } function cellClicked ( cell ) { cell . tag = ! cell . tag ; cellSelect ( cell , cell . tag ) ; } function togglePortBit ( cell , port , bitByte ) { vscode . postMessage ( { command : 'portBit' , value : { port : port , on : cell . bitvalue , bitByte : bitByte } } ) ; } function togglePortBitNeg ( cell , port , bitByte ) { vscode . postMessage ( { command : 'portBit' , value : { port : port , on : ! cell . bitvalue , bitByte : bitByte } } ) ; } function findCell ( keyCode ) { const cell = document . getElementById ( "key_" + keyCode ) ; return cell ; } function copyHtmlToClipboard ( ) { const copyText = document . documentElement . innerHTML ; navigator . clipboard . writeText ( copyText ) ; } function reloadCustomLogicAndUi ( ) { vscode . postMessage ( { command : 'reloadCustomLogicAndUi' } ) ; } function volumeChanged ( volumeStr ) { const volume = parseFloat ( volumeStr ) ; zxAudioBeeper . setVolume ( volume ) ; vscode . postMessage ( { command : 'volumeChanged' , value : volume } ) ; } document . addEventListener ( 'keydown' , keydown ) ; function keydown ( e ) { const cell = findCell ( e . code ) ; cellSelect ( cell , true ) ; } document . addEventListener ( 'keyup' , keyup ) ; function keyup ( e ) { const cell = findCell ( e . code ) ; cellSelect ( cell , false ) ; }