Title: 8.7 Memory management
18.7 Memory management
DOS INT 21, function 48H Allocate Memory
Specification allocates a number of memory
paragraphs. Paragraph a chunk of 16 memory
bytes, starting at a physical address of type
XXXX0H.
Program A
Input AH 48H (function code), BX the number
of requested paragraphs.
Program B
Output if succeeds CF 0, AX the starting
segment address of the allocated memory
block. if DOS cannot allocate the requested
memory CF 1, AX error code, BX the
largest free memory block size (in paragraphs).
Program C
DOS INT 21, function 49H Free Allocated Memory
Specification frees a memory block.
Input AH 49H (function code), ES the block
segment address.
Output if succeeds CF 0. if DOS cannot free
memory block CF 1, AX error code.
System memory
Constrain the block segment address must be
previously obtained trough INT 21H, function 48H.
DOS INT 21, function 4AH Modify Allocated
Memory Blocks
Specification modifies the length of an already
allocated memory block.
Input AH 4AH (function code), ES the block
segment address, BX the block size (in
paragraphs) needed after modification.
Output if succeeds CF 0. if DOS cannot modify
the memory block CF 1, AX error code, BX
the maximum size available for the requested
block (in paragraphs).
Constrain the block segment address must be
previously obtained trough INT 21H, function 48H.
28.8 Using the Mouse
MOUSE INT 33, function 00H Mouse Reset and
Status
Specification reset mouse controller and return
status.
Input AH 00 (function code)
Output AX Mouse Status (0FFh mouse
initialized, 0 no mouse functions available) BX
mouse buttons status (bit 0 1 gtleft button
pressed, bit 1 1 gtright button pressed.
Constrain INT 33 is neither a DOS or BIOS
interrupt. The mouse driver MOUSE.SYS should be
loaded or MOUSE.COM executed, to install this
interrupt.
MOUSE INT 33, function 01H Show mouse cursor
Specification turn on the mouse cursor (inverse
video box in text mode, arrow in graphics mode).
Input AH 01(function code)
MOUSE INT 33, function 02H Hide mouse cursor
Specification turn off the mouse cursor.
Input AH 02 (function code)
MOUSE INT 33, function 03H Get Button Status
and Mouse Position
Specification returns button status and mouse
position.
Input AH 03 (function code)
OutputBX Button Status (similar to function
00), CX horizontal position of the mouse
cursor (CX 0 gt cursor on the most left
position. DX vertical position of the mouse
cursor (DX 0 gt cursor on the most upper
position. The maximum CX and DX values depend on
current video mode.
38.9 Writing a Memory Resident Program
DOS INT 21, function 31H Terminate and Stay
Resident
Specification returns control to DOS, keeping
allocated memory.
Input AH 31H (function code), DX the number of
paragraphs remaining resident.
Note The keeped memory allocation must be large
enough to store the Program Segment Prefix and
the necessary code and data segments .
DOS INT 21, function 27H Terminate and Stay
Resident (only .COM files)
Specification returns control to DOS, keeping
allocated memory.
Input AH 27H (function code), DX the number
of bytes remaining resident.
Constrain used only for .COM programs.
The TSR (Terminate and Stay Resident) program
can be activated using an interrupt. To be able
to do this, it should be installed hooking an
interrupt (timer, keyboard, serial port...). When
discharging the allocated memory, the TSR should
restore the IPT (Interrupt Pointer Table) at the
previous state.
The TSR (when activated by the hooked interrupt)
uses the current SSSP of the interrupted program
to save the used registers (beside FLAGS and
return address already saved by interrupt
acknowledging). If a large stack amount is
needed, the TSR should use its own stack area
(modifying SSSP) and restore the current SSSP
before returning.