/Pristine-Pro/DRIVEKIT/VESA/PLRALLOC.ASM

http://github.com/AnimatorPro/Animator-Pro · Assembly · 89 lines · 53 code · 16 blank · 20 comment · 0 complexity · a2c3eebbf7b71436b91d01cdfbcf181e MD5 · raw file

  1. ;*****************************************************************************
  2. ;* PLRALLOC.ASM - Allocate/Free DOS real (below 1mb line) memory (Phar Lap).
  3. ;*
  4. ;* Phar Lap has special functions for allocating memory below the 1mb line.
  5. ;* It (like native DOS) deals with things in terms of segments and
  6. ;* paragraphs. Our caller deals with far32 pointers and bytes, so the
  7. ;* routines below translate the values appropriately.
  8. ;*****************************************************************************
  9. include stdmacro.i
  10. include dosmem.i
  11. Err_no_memory = -2
  12. _TEXT segment
  13. public pj_dosmem_alloc
  14. public pj_dosmem_free
  15. ;*****************************************************************************
  16. ;* Errcode pj_dosmem_alloc(size_t bytes, struct dosmem_block *block);
  17. ;* This allocates a memory block of the specified size below the 1mb line.
  18. ;* If it succeeds, it return Success and the structure at *block holds
  19. ;* the selector:off32 and dos segment number of the realmode memory block.
  20. ;* If it fails, it returns Err_no_memory.
  21. ;*****************************************************************************
  22. pj_dosmem_alloc proc near
  23. Entry
  24. Args #bytes,#block
  25. Save ebx,esi,edi
  26. mov ebx,#bytes ; load requested size,
  27. add ebx,15 ; round up to next 16-byte value,
  28. shr ebx,4 ; adjust to paragraph count.
  29. mov eax,25c0h ; pharlap alloc-dos-memory function,
  30. int 21h ; do it. if CARRY set, go handle
  31. jnc short #good ; error, else move returned DOS
  32. mov eax,Err_no_memory
  33. jmp short #return
  34. #good:
  35. mov ebx,#block ; PLS returns the dos segment number
  36. mov [ebx+6],ax ; in AX, just store it. We construct
  37. movzx eax,ax ; the 16:32 pointer by cleaning up the
  38. shl eax,4 ; high bits of the dos segment number,
  39. mov [ebx],eax ; shifting up to create a 32-bit offset,
  40. mov [ebx+4],gs ; and using the global below-1mb-line
  41. xor eax,eax ; selector from GS. Return Success.
  42. #return:
  43. Restore ebx,esi,edi
  44. Exit
  45. pj_dosmem_alloc endp
  46. ;*****************************************************************************
  47. ;* void pj_dosmem_free(struct dosmem_block *block)
  48. ;* this accepts a pointer to a dosmem_block structure which describes
  49. ;* a dos memory block allocated by pj_dosmem_alloc, and frees the block.
  50. ;*****************************************************************************
  51. pj_dosmem_free proc near
  52. Entry
  53. Args #block
  54. Save ebx,esi,edi
  55. mov ecx,#block ; load pointer to dosmem_block struct.
  56. test ecx,ecx ; if pointer is NULL, just punt,
  57. jz short #punt ; else load the dos segment number
  58. movzx ecx,wptr [ecx+6] ; from the structure, and if it's
  59. test ecx,ecx ; NULL, just punt, else pass it
  60. jz short #punt ; to the pharlap free DOS memory
  61. mov ax,25C1h ; function.
  62. int 21h ; do it.
  63. mov edx,#block
  64. xor eax,eax
  65. mov [edx],eax
  66. mov [edx+4],eax
  67. #punt:
  68. Restore ebx,esi,edi
  69. Exit
  70. pj_dosmem_free endp
  71. _TEXT ends
  72. end
  73.