home *** CD-ROM | disk | FTP | other *** search
/ Amiga Elysian Archive / AmigaElysianArchive.iso / prog / source / dcassem.lha / No.8 < prev    next >
Text File  |  1988-05-14  |  2KB  |  57 lines

  1.         XREF    _LVOAllocMem,_LVOFreeMem
  2.  
  3. ;==============================================================================
  4. ; Success = AllocMemory( memtable )
  5. ;   d0                a0
  6. ;
  7. ; Allocates all memory in the given table and returns false if it failed.
  8. ; memory table is formatted as follows:-
  9. ;
  10. ; size.l,type.w,offset.w
  11. ; ......
  12. ; -1
  13. ;
  14. ; Size is the required size for this chunk of memory.
  15. ; Type is the memory type required, it is always ored with MEMF_CLEAR
  16. ; Offset is the offset to store at (off the a5 global pointer)
  17. ;==============================================================================
  18. AllocMemory    movem.l    a2/a6,-(sp)
  19.         movea.l    SysLib(a5),a6        using exec library
  20.         movea.l    a0,a2            stash memtable address
  21.  
  22. 10$        move.l    (a2)+,d0        get size
  23.         bmi.s    MemAlloced        last entry, return true
  24.         moveq.l    #0,d1
  25.         move.w    (a2)+,d1        get type
  26.         bset.l    #MEMB_CLEAR,d1        clear it too
  27.         jsr    _LVOAllocMem(a6)    allocate it
  28.         move.w    (a2)+,d1        get store offset
  29.         move.l    d0,0(a5,d1.w)        save it
  30.         bne.s    10$            OK, memory fetched
  31. MemAlloced    movem.l    (sp)+,a2/a6        could return 0 if it failed
  32.         rts
  33.  
  34. ;==============================================================================
  35. ; FreeMemory( memtable )
  36. ;         a0
  37. ;
  38. ; Frees all the memory that was allocated by AllocMemory up to the first zero
  39. ; pointer (or allocation that failed).  Use same table as used for AllocMemory.
  40. ;==============================================================================
  41. FreeMemory    movem.l    a2/a6,-(sp)
  42.         movea.l    SysLib(a5),a6        using exec library
  43.         movea.l    a0,a2            stash table pointer
  44.  
  45. 10$        move.l    (a2)+,d0        end of list
  46.         bmi.s    MemFreed        yep, exit now
  47.         move.l    (a2)+,d1        offset to lower word
  48.         move.l    0(a5,d1.w),d1        get pointer
  49.         beq.s    MemFreed        quit! alloc failed on this one
  50.         movea.l    d1,a1
  51.         jsr    _LVOFreeMem(a6)
  52.         bra.s    10$
  53. MemFreed    movem.l    (sp)+,a2/a6
  54.         rts
  55.  
  56.         END
  57.