1 // "Build Engine & Tools" Copyright (c) 1993-1997 Ken Silverman 2 // Ken Silverman's official web site: "http://www.advsys.net/ken" 3 // See the included license file "BUILDLIC.TXT" for license info. 4 // 5 // This file has been modified from Ken Silverman's original release 6 // by Jonathon Fowler (jf@jonof.id.au) 7 // by the EDuke32 team (development@voidpoint.com) 8 9 #ifndef cache1d_h_ 10 #define cache1d_h_ 11 12 #include <inttypes.h> 13 14 #define MINCACHEINDEXSIZE 1024 15 #define MINCACHEBLOCKSIZE 16 16 17 typedef struct 18 { 19 char * lock; 20 intptr_t *hand; 21 int32_t leng; 22 int32_t ovh; 23 } cacheindex_t; 24 25 enum cachelock_t : char 26 { 27 CACHE1D_FREE = 1, 28 CACHE1D_UNLOCKED = 199, 29 CACHE1D_LOCKED = 200, 30 CACHE1D_PERMANENT = 255, 31 }; 32 33 class cache1d 34 { 35 public: 36 void initBuffer(intptr_t dacachestart, uint32_t dacachesize, uint32_t minsize = 0); 37 void allocateBlock(intptr_t* newhandle, int32_t newbytes, char* newlockptr); 38 void tryHarder(int32_t const newbytes, int32_t * const besto, int32_t * const bestz); 39 40 void ageBlocks(void); 41 int32_t findBlock(int32_t const newbytes, int32_t * const besto, int32_t * const bestz); 42 void report(void); 43 void reset(void); 44 numBlocks(void)45 int numBlocks(void) { return m_numBlocks; } getIndex(void)46 cacheindex_t const * getIndex(void) { return m_index; } 47 48 private: 49 void inc_and_check_cacnum(void); 50 51 cacheindex_t *m_index{}; 52 53 intptr_t m_baseAddress{}; 54 int32_t m_totalSize{}; 55 int32_t m_minBlockSize{}; 56 57 int m_maxBlocks{}; 58 int m_numBlocks{}; 59 }; 60 61 extern cache1d g_cache; 62 63 #endif // cache1d_h_ 64 65