pub fn new() -> Result<Self, io::Error> {
        // rather than being clever about paging RAM/ROM, since the whole thing
        // is ~32.5kib, let's just malloc the whole address space
        let mut mm = Chip8MemoryMap {
            bytes: Box::new([0u8; COSMAC_MAX_RAM_BYTES as usize]),
            program_addr: CHIP8_PROGRAM_ADDR,
            stack_addr: CHIP8_RAM_SIZE_BYTES - CHIP8_STACK_OFFSET,
            work_addr: CHIP8_RAM_SIZE_BYTES - CHIP8_WORK_OFFSET,
            var_addr: CHIP8_RAM_SIZE_BYTES - CHIP8_VAR_OFFSET,
            display_addr: CHIP8_RAM_SIZE_BYTES - CHIP8_DISPLAY_OFFSET,
        };
        // write the original chip-8 interpreter at 0x000
        mm.write(&CHIP8_INTERPRETER_SOURCE, 0x0, 0x200)?;

        // write the COSMAC VIP ROM at 0x8000
        mm.write(&COSMAC_VIP_ROM, 0x8000, 0x200)?;

        Ok(mm)
    }
/// initialises CHIP-8 with contemporary memory contents
initialises CHIP-8 with contemporary memory contents
initialises CHIP - 8 with contemporary memory contents
pub fn new() -> Result<Self, io::Error> {
        // rather than being clever about paging RAM/ROM, since the whole thing
        // is ~32.5kib, let's just malloc the whole address space
        let mut mm = Chip8MemoryMap {
            bytes: Box::new([0u8; COSMAC_MAX_RAM_BYTES as usize]),
            program_addr: CHIP8_PROGRAM_ADDR,
            stack_addr: CHIP8_RAM_SIZE_BYTES - CHIP8_STACK_OFFSET,
            work_addr: CHIP8_RAM_SIZE_BYTES - CHIP8_WORK_OFFSET,
            var_addr: CHIP8_RAM_SIZE_BYTES - CHIP8_VAR_OFFSET,
            display_addr: CHIP8_RAM_SIZE_BYTES - CHIP8_DISPLAY_OFFSET,
        };
        // write the original chip-8 interpreter at 0x000
        mm.write(&CHIP8_INTERPRETER_SOURCE, 0x0, 0x200)?;
        // write the COSMAC VIP ROM at 0x8000
        mm.write(&COSMAC_VIP_ROM, 0x8000, 0x200)?;
        Ok(mm)
    }
pub fn new ( ) -> Result < Self , io :: Error > { // rather than being clever about paging RAM/ROM, since the whole thing // is ~32.5kib, let's just malloc the whole address space let mut mm = Chip8MemoryMap { bytes : Box :: new ( [ 0u8 ; COSMAC_MAX_RAM_BYTES as usize ] ) , program_addr : CHIP8_PROGRAM_ADDR , stack_addr : CHIP8_RAM_SIZE_BYTES - CHIP8_STACK_OFFSET , work_addr : CHIP8_RAM_SIZE_BYTES - CHIP8_WORK_OFFSET , var_addr : CHIP8_RAM_SIZE_BYTES - CHIP8_VAR_OFFSET , display_addr : CHIP8_RAM_SIZE_BYTES - CHIP8_DISPLAY_OFFSET , } ; // write the original chip-8 interpreter at 0x000 mm . write ( & CHIP8_INTERPRETER_SOURCE , 0x0 , 0x200 ) ? ; // write the COSMAC VIP ROM at 0x8000 mm . write ( & COSMAC_VIP_ROM , 0x8000 , 0x200 ) ? ; Ok ( mm ) }
initialises CHIP-8 with contemporary memory contents
initialises CHIP - 8 with contemporary memory contents