import { Mapper , MapperOptions } from './mapper' ; class Mapper002Base extends Mapper { private bank = 0 ; constructor ( prgBankShift , private options ) { super ( ) ; const BANK_BIT = 14 ; const count = options . prgSize >> BANK_BIT ; this . options . prgBankCtrl . setPrgBank ( 0 , 0 ) ; this . options . prgBankCtrl . setPrgBank ( 1 , 1 ) ; this . options . prgBankCtrl . setPrgBank ( 2 , count * 2 - 2 ) ; this . options . prgBankCtrl . setPrgBank ( 3 , count * 2 - 1 ) ; this . options . bus . setWriteMemory ( 0x8000 , 0xffff , ( _adr , value ) => { const bank = ( value >> prgBankShift ) << 1 ; this . setBank ( bank ) ; } ) ; } public save ( ) { return { bank : this . bank , } ; } public load ( saveData ) { this . setBank ( saveData . bank ) ; } private setBank ( bank ) { this . bank = bank ; this . options . prgBankCtrl . setPrgBank ( 0 , bank ) ; this . options . prgBankCtrl . setPrgBank ( 1 , bank + 1 ) ; } } export class Mapper002 extends Mapper002Base { public static create ( options ) { return new Mapper002 ( options ) ; } constructor ( options ) { super ( 0 , options ) ; } } export class Mapper093 extends Mapper002Base { public static create ( options ) { return new Mapper093 ( options ) ; } constructor ( options ) { super ( 4 , options ) ; } }