home *** CD-ROM | disk | FTP | other *** search
/ BURKS 2 / BURKS_AUG97.ISO / BURKS / SOFTWARE / LIBS / PMC101.ZIP / LIBSRC.ZIP / BMINIT.ASM (.txt) < prev    next >
Assembly Source File  |  1994-06-26  |  3KB  |  95 lines

  1. ;──────────────────────────────────────────────────────────────────────────────
  2. ;                     MEMBLOCK Init for Memory Allocation
  3. ;──────────────────────────────────────────────────────────────────────────────
  4. ;
  5. ; Borland C++ 4.0 for WIN32 prototype:
  6. ; int   __pascal mbinit (MEMBLOCK *mb);
  7. ;
  8. ; version 0.3
  9. ; - White Shadow -
  10. ;
  11. .386p
  12. Ideal
  13. include "bmmalloc.inc"
  14.  
  15. Public MBINIT, MBHEADERSIZE
  16.  
  17.  
  18. extrn _zeroptr:dword
  19.  
  20. ;──────────────────────────────────────────────────────────────────────────────
  21. Segment _DATA dword public use32 'DATA'
  22.  
  23. MBHEADERSIZE    dd MBSigSize + (size MemNode)
  24.  
  25. EndS    _DATA
  26.  
  27.  
  28. ;──────────────────────────────────────────────────────────────────────────────
  29. Segment _TEXT byte public use32 'CODE'
  30. Assume  cs:_TEXT, ds:DGROUP
  31.  
  32.  
  33. ; -- argument stack offsets
  34. arg1 = 0                ; -> MEMBLOCK
  35.  
  36. MBINIT:         push ebx
  37. pct = (4)+(1*4)         ; # bytes pushed on stack after last argument
  38.  
  39.                 ;-- Get memblock info
  40.                 mov  eax, [esp+pct+arg1]        ; -> MEMBLOCK
  41. ;
  42. ;                mov  ebx, [_zeroptr]
  43. ;                mov  [ebx+04c4h], eax
  44. ;
  45.                 mov  ebx, [eax+MEMBLOCK.base]
  46.                 mov  ecx, [eax+MEMBLOCK.size]
  47.  
  48.                 ;-- Align MEMBLOCK base
  49. IN_AlignBase:   test bl, 03h
  50.                 jz   IN_AlignSize
  51.                 inc  ebx
  52.                 dec  ecx
  53.                 jmp  short IN_AlignBase
  54.  
  55.                 ;-- Align MEMBLOCK size
  56. IN_AlignSize:   and  cl, NOT(03h)
  57.  
  58. IN_CheckSize:   ;-- Is size too big or small??
  59.                 cmp  ecx, MBSigSize + (size MemNode)    ; high bit is needed
  60.                 jle  IN_BadMBSize               ; for node availability flag
  61.                 ; sig+1stnodesize < ecx < 2^31
  62.  
  63.                 ;-- Writeback base and size of MEMBLOCK
  64.                 mov  [eax+MEMBLOCK.base], ebx
  65.                 mov  [eax+MEMBLOCK.size], ecx
  66.  
  67.                 ;-- Convert linear base adx to relative
  68.                 sub  ebx, [_database]
  69.  
  70. If DebugMode    ;-- Write memory block signature
  71.                 mov  [dword ebx], MBSig
  72.                 add  ebx, MBSigSize             ; -> first node
  73. EndIf
  74.  
  75.                 ;-- Write first node
  76.                 sub  ecx, (MBSigSize + size MemNode)    ; size of 1st mem area
  77.                 mov  [ebx+MemNode.size], ecx
  78. If DebugMode
  79.                 xor  ecx, NodeSigKey
  80.                 mov  [ebx+MemNode.sig], ecx
  81. EndIf
  82.  
  83.                 ;-- Init ok
  84.                 mov  eax, 1
  85. IN_Exit:        pop  ebx
  86.                 ret  4
  87.  
  88. IN_BadMBSize:   xor  eax, eax
  89.                 jmp  short IN_Exit
  90.  
  91.  
  92. ;──────────────────────────────────────────────────────────────────────────────
  93. EndS            _TEXT
  94. End
  95.