import { Utility } from '../misc/utility' ; export const MAX_MEM_SIZE = 0x10000 ; export class BaseMemory { protected memory : Uint8Array ; protected startAddress : number ; protected size : number ; param startAddress param sizeOrArr constructor ( startAddress , sizeOrArr ) { if ( typeof sizeOrArr == 'number' ) { const size = sizeOrArr ; this . memory = new Uint8Array ( size ) ; } else { this . memory = sizeOrArr ; } this . startAddress = startAddress ; this . size = this . memory . length ; } param index param value public setValueAtIndex ( index , value ) { this . memory [ index ] = value ; } param address returns public getValueAt ( address ) { address &= ( MAX_MEM_SIZE - 1 ) ; let index = address - this . startAddress ; if ( index < 0 ) { index += MAX_MEM_SIZE ; } Utility . assert ( index >= 0 , 'getValueAt 1' ) ; Utility . assert ( index < this . size , 'getValueAt 2' ) ; return this . memory [ index ] ; } param address returns public getWordValueAt ( address ) { const word = this . getValueAt ( address ) + 256 * this . getValueAt ( address + 1 ) ; return word ; } param address returns public getBigEndianWordValueAt ( address ) { const word = 256 * this . getValueAt ( address ) + this . getValueAt ( address + 1 ) ; return word ; } }