import { Labels } from '../labels/labels' ; import { Utility } from '../misc/utility' ; import { Z80Registers } from './z80registers' ; export type RegisterData = any ; /**
 * Parses the register data for PC etc.
 */ export class DecodeRegisterData { protected regMap = new Map < string , { ( data ) : number ; } > ( ) ; /**
    * Called during the launchRequest.
    */ constructor ( ) { this . regMap . set ( "PC" , this . parsePC . bind ( this ) ) ; this . regMap . set ( "SP" , this . parseSP . bind ( this ) ) ; this . regMap . set ( "AF" , this . parseAF . bind ( this ) ) ; this . regMap . set ( "BC" , this . parseBC . bind ( this ) ) ; this . regMap . set ( "DE" , this . parseDE . bind ( this ) ) ; this . regMap . set ( "HL" , this . parseHL . bind ( this ) ) ; this . regMap . set ( "IX" , this . parseIX . bind ( this ) ) ; this . regMap . set ( "IY" , this . parseIY . bind ( this ) ) ; this . regMap . set ( "AF'" , this . parseAF2 . bind ( this ) ) ; this . regMap . set ( "BC'" , this . parseBC2 . bind ( this ) ) ; this . regMap . set ( "DE'" , this . parseDE2 . bind ( this ) ) ; this . regMap . set ( "HL'" , this . parseHL2 . bind ( this ) ) ; this . regMap . set ( "A" , this . parseA . bind ( this ) ) ; this . regMap . set ( "F" , this . parseF . bind ( this ) ) ; this . regMap . set ( "B" , this . parseB . bind ( this ) ) ; this . regMap . set ( "C" , this . parseC . bind ( this ) ) ; this . regMap . set ( "D" , this . parseD . bind ( this ) ) ; this . regMap . set ( "E" , this . parseE . bind ( this ) ) ; this . regMap . set ( "H" , this . parseH . bind ( this ) ) ; this . regMap . set ( "L" , this . parseL . bind ( this ) ) ; this . regMap . set ( "I" , this . parseI . bind ( this ) ) ; this . regMap . set ( "R" , this . parseR . bind ( this ) ) ; this . regMap . set ( "IM" , this . parseIM . bind ( this ) ) ; this . regMap . set ( "A'" , this . parseA2 . bind ( this ) ) ; this . regMap . set ( "F'" , this . parseF2 . bind ( this ) ) ; this . regMap . set ( "IXL" , this . parseIXL . bind ( this ) ) ; this . regMap . set ( "IXH" , this . parseIXH . bind ( this ) ) ; this . regMap . set ( "IYL" , this . parseIYL . bind ( this ) ) ; this . regMap . set ( "IYH" , this . parseIYH . bind ( this ) ) ; } param regName returns public getRegValueByName ( regName , data ) { let handler = this . regMap . get ( regName . toUpperCase ( ) ) || ( data => 0 ) ; Utility . assert ( handler != undefined , 'Register ' + regName + ' does not exist.' ) ; Utility . assert ( data ) ; let value = handler ( data ) ; return value ; } public parsePC ( data ) { Utility . assert ( false ) ; return 0 ; } public parseSP ( data ) { Utility . assert ( false ) ; return 0 ; } public parseAF ( data ) { Utility . assert ( false ) ; return 0 ; } public parseBC ( data ) { Utility . assert ( false ) ; return 0 ; } public parseHL ( data ) { Utility . assert ( false ) ; return 0 ; } public parseDE ( data ) { Utility . assert ( false ) ; return 0 ; } public parseIX ( data ) { Utility . assert ( false ) ; return 0 ; } public parseIY ( data ) { Utility . assert ( false ) ; return 0 ; } public parseAF2 ( data ) { Utility . assert ( false ) ; return 0 ; } public parseBC2 ( data ) { Utility . assert ( false ) ; return 0 ; } public parseHL2 ( data ) { Utility . assert ( false ) ; return 0 ; } public parseDE2 ( data ) { Utility . assert ( false ) ; return 0 ; } public parseI ( data ) { Utility . assert ( false ) ; return 0 ; } public parseR ( data ) { Utility . assert ( false ) ; return 0 ; } public parseIM ( data ) { Utility . assert ( false ) ; return 0 ; } public parseSlots ( data ) { Utility . assert ( false ) ; return [ ] ; } public parsePCLong ( data ) { const pc = this . parsePC ( data ) ; if ( ! Labels . AreLongAddressesUsed ( ) ) return pc ; const slots = this . parseSlots ( data ) ; if ( slots . length == 0 ) return pc ; const pcLong = Z80Registers . createLongAddress ( pc , slots ) ; return pcLong ; } public parseA ( data ) { const res = this . parseAF ( data ) >>> 8 ; return res ; } public parseF ( data ) { const res = this . parseAF ( data ) & 0xFF ; return res ; } public parseB ( data ) { const res = this . parseBC ( data ) >>> 8 ; return res ; } public parseC ( data ) { const res = this . parseBC ( data ) & 0xFF ; return res ; } public parseD ( data ) { const res = this . parseDE ( data ) >>> 8 ; return res ; } public parseE ( data ) { const res = this . parseDE ( data ) & 0xFF ; return res ; } public parseH ( data ) { const res = this . parseHL ( data ) >>> 8 ; return res ; } public parseL ( data ) { const res = this . parseHL ( data ) & 0xFF ; return res ; } public parseA2 ( data ) { const res = this . parseAF2 ( data ) >>> 8 ; return res ; } public parseF2 ( data ) { const res = this . parseAF2 ( data ) & 0xFF ; return res ; } public parseIXL ( data ) { const res = this . parseIX ( data ) & 0xFF ; return res ; } public parseIXH ( data ) { const res = this . parseIX ( data ) >>> 8 ; return res ; } public parseIYL ( data ) { const res = this . parseIY ( data ) & 0xFF ; return res ; } public parseIYH ( data ) { const res = this . parseIY ( data ) >>> 8 ; return res ; } }