/**
 * Represents the port behavior for a ZX80 CPU.
 */ export class Z80Ports { protected defaultPortIn ; protected genericOutPortFunc : ( ( port : number , value : number ) => void ) | undefined ; protected genericInPortFunc : ( ( port : number ) => number | undefined ) | undefined ; protected outPortMap : Map < number , ( port : number , value : number ) => void > ; protected inPortMap : Map < number , ( port : number ) => number > ; param defaultPortIn constructor ( defaultPortIn ) { this . defaultPortIn = defaultPortIn ; this . outPortMap = new Map < number , ( port : number , value : number ) => void > ( ) ; this . inPortMap = new Map < number , ( port : number ) => number > ( ) ; } param func public registerGenericOutPortFunction ( func ) { this . genericOutPortFunc = func ; } param func public registerGenericInPortFunction ( func ) { this . genericInPortFunc = func ; } param port param func public registerSpecificOutPortFunction ( port , func ) { if ( func ) this . outPortMap . set ( port , func ) ; else this . outPortMap . delete ( port ) ; } param port param func public registerSpecificInPortFunction ( port , func ) { if ( func ) this . inPortMap . set ( port , func ) ; else this . inPortMap . delete ( port ) ; } /**
     *  Read 1 byte. Used by the CPU when doing a 'in a,(c)'.
     */ public read ( port ) { let value ; const func = this . inPortMap . get ( port ) ; if ( func ) value = func ( port ) ; if ( value == undefined ) { if ( this . genericInPortFunc ) value = this . genericInPortFunc ( port ) ; } if ( value == undefined ) value = this . defaultPortIn ; return value ; } /**
     * Write 1 byte. Used by the CPU when doing a 'out (c),a'.
     * Executes a custom method.
     */ public write ( port , data ) { const writefunc = this . outPortMap . get ( port ) ; if ( writefunc ) { writefunc ( port , data ) ; } if ( this . genericOutPortFunc ) { this . genericOutPortFunc ( port , data ) ; } } }