--- hatari/src/includes/stMemory.h 2019/04/01 07:14:47 1.1.1.8 +++ hatari/src/includes/stMemory.h 2019/04/09 08:48:40 1.1.1.10 @@ -8,10 +8,9 @@ #ifndef HATARI_STMEMORY_H #define HATARI_STMEMORY_H -#include "config.h" +#include "main.h" #include "sysdeps.h" #include "maccess.h" -#include "main.h" #if ENABLE_SMALL_MEM extern Uint8 *STRam; @@ -24,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) \ @@ -34,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; @@ -52,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; @@ -70,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; @@ -88,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; @@ -106,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; @@ -124,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; @@ -143,6 +164,7 @@ static inline Uint8 STMemory_ReadByte(Ui extern void STMemory_Clear(Uint32 StartAddress, Uint32 EndAddress); +extern void STMemory_MemorySnapShot_Capture(bool bSave); extern void STMemory_SetDefaultConfig(void); #endif