home *** CD-ROM | disk | FTP | other *** search
/ Groovy Bytes: Behind the Moon / groovybytes.iso / GROOVY / SND_TOOL / FUNK108A.ZIP / DOS32V30.ZIP / PAL / INCLUDE / MEMORY.INC < prev    next >
Encoding:
Text File  |  1995-04-01  |  1.7 KB  |  60 lines

  1. ;****************************************************************************
  2. ; Filename: MEMORY.INC
  3. ;   Author: Peter Andersson
  4. ;  Version: 0.0
  5. ;  Created: 1994.12.25
  6. ;  Updated: -
  7. ; Function: 
  8. ;    Input: 
  9. ;   Output: 
  10. ;  Comment: 
  11. ; See also: 
  12. ;****************************************************************************
  13. ; Copyright Peter Andersson, 1994-1995.
  14. ; All rights reserved.
  15. ;****************************************************************************
  16.  
  17. MEMALIGN = 8        ; Alignment address
  18. MINBLOCK = 16        ; Minimum block size in bytes
  19. MEMBLOCK = 8        ; Total number of memory block sizes
  20. ALLOCID = 0ADD2FEEDh    ; Identifier for an allocated block - High and odd.
  21.  
  22. Struc    AllocBlock    ; Alloc block - 16 bytes
  23. Ident        Dd    ALLOCID        ; Identifier for allocated block
  24. BlockSize    Dd    0        ; Block size in bytes inc. header
  25. PrevBlock    Dd    0        ; Pointer to previous block
  26. Debug        Dd    0        ; Debug ID pointer (PSZ)
  27. Ends    AllocBlock
  28.  
  29. Struc    FreeBlock    ; Free block - 16 bytes
  30. NextFree    Dd    0        ; Pointer to next free block
  31. BlockSize    Dd    0        ; Block size in bytes inc. header
  32. PrevBlock    Dd    0        ; Pointer to previous block
  33. PrevFree    Dd    0        ; Pointer to previous free block
  34. Ends    FreeBlock
  35.  
  36. Global BlockTable:FreeBlock,BlockTableEnd:FreeBlock
  37.  
  38. Macro    GetSize    BlockReg:REQ,SizeReg:REQ
  39.     Local    @@ExitSize
  40. BitSize = MINBLOCK Shl 2
  41.         Mov    BlockReg,Offset BlockTable
  42.     Rept MEMBLOCK-1
  43.         Cmp    SizeReg,BitSize
  44.         Jbe    @@ExitSize
  45. BitSize = BitSize Shl 2
  46.         Add    BlockReg,Size FreeBlock
  47.     Endm
  48.     Align    4
  49. @@ExitSize:
  50. Endm    GetSize
  51.  
  52. Macro    Adjust MemReg:REQ,Value:REQ
  53.     Local    @@NoAlign
  54.         Test    MemReg,(Value-1)
  55.         Jz    @@NoAlign
  56.         And    MemReg,Not (Value-1)
  57.         Add    MemReg,Value
  58. @@NoAlign:
  59. Endm    Adjust
  60.