home *** CD-ROM | disk | FTP | other *** search
/ io Programmo 23 / IOPROG_23.ISO / SOFT / ASM / GRDBDL17.ZIP / MEMORY.ASM < prev    next >
Encoding:
Assembly Source File  |  1998-10-26  |  1.9 KB  |  147 lines

  1. ;
  2. ; GRDP
  3. ;
  4. ; Copyright(c) LADsoft
  5. ;
  6. ; David Lindauer, camille@bluegrass.net
  7. ;
  8. ;
  9. ; MEMORY.ASM
  10. ;
  11. ; Function: Handle various memory-management tasks
  12. ;
  13.     ;MASM MODE
  14.     .MODEL SMALL
  15.     .386
  16.  
  17.  
  18. include  eprints.inc 
  19. include  einput.inc 
  20. include  emtrap.inc 
  21. include  ebreaks.inc 
  22. include eloader.inc
  23. include eoptions.inc
  24.  
  25.     PUBLIC ReleaseMemory,tagarena, ResizeMem, ReleaseDebugMem
  26.  
  27.     .data
  28.  
  29.     .CODE
  30. ;
  31. ; resize mem
  32. ;
  33. ResizeMem PROC
  34.     mov    ax,ss
  35.     sub    ax,[psp]
  36.     mov    bx,[stackofs]
  37.     shr    bx,4
  38.     add    bx,ax
  39.     mov    ah,4ah
  40.     push    es
  41.     mov    es,[psp]
  42.     int    21h
  43.     pop    es
  44.     ret
  45. ResizeMem ENDP
  46. ;
  47. ; release all memory belonging to a given PSP
  48. ;
  49. ReleaseDebugMem    PROC
  50.     mov    cx,[psp]
  51.     jmp    dorelease
  52. ReleaseDebugMem    ENDP
  53. ReleaseMemory PROC
  54.     mov    cx,[userbasepsp]
  55. dorelease    proc
  56.     push    es
  57.     mov    ah,52h    
  58.     int    21h
  59.     mov    bx,es:[bx-2]
  60.     pop    es
  61.     sub    dx,dx
  62. rm_lp:
  63.     mov    fs,bx
  64.     inc    bx
  65.     cmp    byte ptr fs:[0],'M'
  66.     jz    rm_ok
  67.     cmp    byte ptr fs:[0],'Z'
  68.     jz    rm_ok
  69.     PRINT_MESSAGE    <13,10,"Warning : Arena trashed">
  70. rm_xit:
  71.     ret
  72. rm_ok:
  73.     mov    ax,fs:[1]
  74.     test    ax,-1
  75.     jz    docombine
  76.     cmp    cx,ax
  77.     jnz    uncombine
  78.     mov    word ptr fs:[1],0    
  79.     sub    ax,ax
  80. docombine:
  81.     or    dx,dx
  82.     jz    firstcombine
  83.     mov    gs,dx
  84.     mov    ax,fs:[3]
  85.     inc    ax
  86.     add    gs:[3],ax
  87.     mov    al,fs:[0]
  88.     mov    gs:[0],al
  89.     jmp    join
  90. uncombine:
  91.     sub    dx,dx
  92.     jmp    join
  93. firstcombine:
  94.     mov    dx,fs
  95. join:
  96.     cmp    byte ptr fs:[0],'Z'
  97.     jz    rm_xit
  98.     add    bx,fs:[3]
  99.     jmp    rm_lp
  100. dorelease    ENDP
  101. ReleaseMemory ENDP
  102. ;
  103. ; tag an arena entry with a name
  104. ;
  105. tagarena PROC
  106.     push    es
  107.     push    si
  108.     push    di
  109.     push    cx
  110.     mov    es,bx
  111.     mov    es:[1],ax
  112.     push    si
  113. taxl:
  114.     lodsb
  115.     or    al,al
  116.     jz    taxx
  117.     cmp    al,'\'
  118.     jnz    taxl
  119.     xchg    [esp],si
  120.     jmp    taxl
  121. taxx:
  122.     pop    si
  123.     mov    di,8
  124.     mov    cx,8
  125. talp:
  126.     lodsb
  127.     or    al,al
  128.     jz    tadn
  129.     cmp    al,'.'
  130.     jz    tadn
  131.     cmp    al,'a'
  132.     jc    nouc
  133.     sub    al,20h
  134. nouc:
  135.     stosb
  136.     loop    talp
  137. tadn:
  138.     jcxz    noo
  139.         mov    byte ptr es:[di],0
  140. noo:
  141.     pop    cx
  142.     pop    di
  143.     pop    si
  144.     pop    es
  145.     ret
  146. tagarena ENDP
  147. end