--- hatari/src/includes/stMemory.h 2019/04/09 08:47:16 1.1.1.9 +++ hatari/src/includes/stMemory.h 2019/04/09 08:49:31 1.1.1.11 @@ -23,6 +23,10 @@ extern Uint8 STRam[16*1024*1024]; extern Uint32 STRamEnd; +/* TODO: when Hatari will support TT/fast-RAM, take it into account + * in STRAM_ADDR() and STMemory_ValidArea(). + */ + /* Offset ST address to PC pointer: */ #if ENABLE_SMALL_MEM # define STRAM_ADDR(Var) \ @@ -33,11 +37,30 @@ extern Uint32 STRamEnd; # define STRAM_ADDR(Var) ((unsigned long)STRam+((Uint32)(Var) & 0x00ffffff)) #endif -/*-----------------------------------------------------------------------*/ -/* - Write 32-bit word into ST memory space. - NOTE - value will be convert to 68000 endian -*/ + +/** + * Check whether given memory address and size are within + * valid ST memory area (i.e. read/write from/to there doesn't + * overwrite Hatari's own memory & cause potential segfaults) + * and that the size is positive. + * + * If they are; return true, otherwise false. + */ +static inline bool STMemory_ValidArea(Uint32 addr, int size) +{ + if (size >= 0 && addr+size < 0xff0000 && + (addr+size < STRamEnd || addr >= 0xe00000)) + { + return true; + } + return false; +} + + +/** + * Write 32-bit word into ST memory space. + * NOTE - value will be convert to 68000 endian + */ static inline void STMemory_WriteLong(Uint32 Address, Uint32 Var) { Address &= 0xffffff; @@ -51,11 +74,11 @@ static inline void STMemory_WriteLong(Ui #endif } -/*-----------------------------------------------------------------------*/ -/* - Write 16-bit word into ST memory space. - NOTE - value will be convert to 68000 endian. -*/ + +/** + * Write 16-bit word into ST memory space. + * NOTE - value will be convert to 68000 endian. + */ static inline void STMemory_WriteWord(Uint32 Address, Uint16 Var) { Address &= 0xffffff; @@ -69,10 +92,10 @@ static inline void STMemory_WriteWord(Ui #endif } -/*-----------------------------------------------------------------------*/ -/* - Write 8-bit byte into ST memory space. -*/ + +/** + * Write 8-bit byte into ST memory space. + */ static inline void STMemory_WriteByte(Uint32 Address, Uint8 Var) { Address &= 0xffffff; @@ -87,11 +110,10 @@ static inline void STMemory_WriteByte(Ui } -/*-----------------------------------------------------------------------*/ -/* - Read 32-bit word from ST memory space. - NOTE - value will be converted to PC endian. -*/ +/** + * Read 32-bit word from ST memory space. + * NOTE - value will be converted to PC endian. + */ static inline Uint32 STMemory_ReadLong(Uint32 Address) { Address &= 0xffffff; @@ -105,11 +127,11 @@ static inline Uint32 STMemory_ReadLong(U #endif } -/*-----------------------------------------------------------------------*/ -/* - Read 16-bit word from ST memory space. - NOTE - value will be converted to PC endian. -*/ + +/** + * Read 16-bit word from ST memory space. + * NOTE - value will be converted to PC endian. + */ static inline Uint16 STMemory_ReadWord(Uint32 Address) { Address &= 0xffffff; @@ -123,10 +145,10 @@ static inline Uint16 STMemory_ReadWord(U #endif } -/*-----------------------------------------------------------------------*/ -/* - Read 8-bit byte from ST memory space -*/ + +/** + * Read 8-bit byte from ST memory space + */ static inline Uint8 STMemory_ReadByte(Uint32 Address) { Address &= 0xffffff; @@ -142,6 +164,8 @@ static inline Uint8 STMemory_ReadByte(Ui extern void STMemory_Clear(Uint32 StartAddress, Uint32 EndAddress); +extern bool STMemory_SafeCopy(Uint32 addr, Uint8 *src, unsigned int len, const char *name); +extern void STMemory_MemorySnapShot_Capture(bool bSave); extern void STMemory_SetDefaultConfig(void); #endif