void* ArduinoProgramMemory::readPtrNear(const void* addr) { return pgm_read_ptr_near(addr); }
CGame::CGame( const ROM_REGION *romRegion, const RAM_REGION *ramRegion, const RAM_REGION *ramRegionWriteOnly, const INPUT_REGION *inputRegion, const OUTPUT_REGION *outputRegion, const CUSTOM_FUNCTION *customFunction ) : m_interrupt(ICpu::NMI), m_interruptAutoVector(false), m_interruptResponse(0), m_RomReadRegion(0), m_RamWriteReadRegion(0), m_inputReadRegion(0), m_outputWriteRegion(0), m_outputWriteRegionOn(true), m_customSelect(0) { // Copy the PROGMEM based region into local SRAM // Note that data2n is NOT in PROGMEM currently. { UINT16 uIndexCount = 0; UINT16 uRegionSize = 0; for ( ; pgm_read_word_near(&romRegion[uIndexCount].length) != 0 ; uIndexCount++) {} uRegionSize = sizeof(romRegion[0]) * (uIndexCount+1); m_romRegion = (PROM_REGION) malloc( uRegionSize ); memcpy_P( m_romRegion, romRegion, uRegionSize ); } // Copy the PROGMEM based region into local SRAM { UINT16 uIndexCount = 0; UINT16 uRegionSize = 0; for ( ; pgm_read_word_near(&ramRegion[uIndexCount].end) != 0 ; uIndexCount++) {} uRegionSize = sizeof(ramRegion[0]) * (uIndexCount+1); m_ramRegion = (PRAM_REGION) malloc( uRegionSize ); memcpy_P( m_ramRegion, ramRegion, uRegionSize ); } // Copy the PROGMEM based region into local SRAM { UINT16 uIndexCount = 0; UINT16 uRegionSize = 0; for ( ; pgm_read_word_near(&ramRegionWriteOnly[uIndexCount].end) != 0 ; uIndexCount++) {} uRegionSize = sizeof(ramRegionWriteOnly[0]) * (uIndexCount+1); m_ramRegionWriteOnly = (PRAM_REGION) malloc( uRegionSize ); memcpy_P( m_ramRegionWriteOnly, ramRegionWriteOnly, uRegionSize ); } // Copy the PROGMEM based region into local SRAM { UINT16 uIndexCount = 0; UINT16 uRegionSize = 0; for ( ; pgm_read_byte_near(&inputRegion[uIndexCount].mask) != 0 ; uIndexCount++) {} uRegionSize = sizeof(inputRegion[0]) * (uIndexCount+1); m_inputRegion = (PINPUT_REGION) malloc( uRegionSize ); memcpy_P( m_inputRegion, inputRegion, uRegionSize ); } // Copy the PROGMEM based region into local SRAM { UINT16 uIndexCount = 0; UINT16 uRegionSize = 0; for ( ; pgm_read_byte_near(&outputRegion[uIndexCount].activeMask) != 0 ; uIndexCount++) {} uRegionSize = sizeof(outputRegion[0]) * (uIndexCount+1); m_outputRegion = (POUTPUT_REGION) malloc( uRegionSize ); memcpy_P( m_outputRegion, outputRegion, uRegionSize ); } // Copy the PROGMEM based region into local SRAM { UINT16 uIndexCount = 0; UINT16 uRegionSize = 0; for ( ; pgm_read_ptr_near(&customFunction[uIndexCount].function) != NULL ; uIndexCount++) {} uRegionSize = sizeof(customFunction[0]) * (uIndexCount+1); m_customFunction = (PCUSTOM_FUNCTION) malloc( uRegionSize ); memcpy_P( m_customFunction, customFunction, uRegionSize ); } }