import { Controller , Button } from '../api/controller' ; import { uint8 } from '../api/types' ; export class StandardController implements Controller { private data : number ; private isStrobe = false ; private offset = 0 ; public update ( button , isPressDown ) { if ( isPressDown ) this . data |= button ; else this . data &= ~ button & 0xFF ; } public write ( data ) { if ( data & 0x01 ) { this . isStrobe = true ; } else { this . offset = 0 ; this . isStrobe = false ; } } public read ( ) { const data = this . isStrobe ? this . data & Button . A : this . data & ( 0x80 >> this . offset ++ ) ; return data ? 1 : 0 ; } }