📄 rxdosmem.asm
字号:
TITLE 'mem - Memory Management Functions'
PAGE 59, 132
.LALL
;''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''';
; MEM - Memory Management Functions ;
;...............................................................;
;''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''';
; Real Time Dos ;
;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -;
; ;
; This material was created as a published version of a DOS ;
; equivalent product. This program logically functions in ;
; the same way as MSDOS functions and it is internal data ;
; structure compliant with MSDOS 6.0 ;
; ;
; This product is distributed AS IS and contains no warranty ;
; whatsoever, including warranty of merchantability or ;
; fitness for a particular purpose. ;
; ;
; ;
; (c) Copyright 1990, 1997. Api Software and Mike Podanoffsky ;
; All Rights Reserved Worldwide. ;
; ;
; This product is protected under copyright laws and may not ;
; be reproduced in whole or in part, in any form or media, ;
; included but not limited to source listing, facsimile, data ;
; transmission, cd-rom, or floppy disk without the expressed ;
; written consent of the author. ;
; ;
; License for distribution for commercial use or resale ;
; required from: ;
; ;
; Api Software ;
; 12 South Walker Street ;
; Lowell, MA 01851 ;
; ;
; internet: mikep@world.std.com ;
; ;
;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -;
; Compile with MASM 5.1 ;
;...............................................................;
include rxdosmac.asm
include rxdosdef.asm
RxDOS SEGMENT PUBLIC 'CODE'
assume cs:RxDOS, ds:RxDOS, es:RxDOS, ss:RxDOS
;''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''';
; MEM - Memory Management Functions ;
;...............................................................;
public allocateMemBlock
public _freeMemBlock
public _modifyMemBlock
public _initializeMemoryBlock
public _collectMemoryBlocks
public _releaseOwnerMemoryBlocks
public _allocateUpperMB
public _allocateConvMB
public _allocateMinMaxMemBlock
extrn _RxDOS_CurrentPSP : word
extrn _RxDOS_pStartMemBlock : word
extrn _RxDOS_DOSProgramName : byte
extrn _RxDOS_AllocStrategy : word
extrn _RetCallersStackFrame : near
extrn pexterrInvalidFunction : near
extrn pexterrFileNotFound : near
extrn pexterrPathNotFound : near
extrn pexterrIllegalName : near
extrn pexterrNoHandlesAvailable : near
extrn pexterrAccessDenied : near
extrn pexterrInvalidHandle : near
extrn pexterrArenaTrashed : near
extrn pexterrNotEnoughMemory : near
extrn pexterrInvalidBlock : near
extrn pexterrInvalidAccess : near
extrn pexterrInvalidDrive : near
extrn pexterrCurrentDirectory : near
extrn pexterrNoMoreFiles : near
extrn pexterrFileExists : near
;''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''';
; Allocate Min Max Memory Block ;
;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -;
; ;
; Input: ;
; ax minimum block ;
; dx maximum block ;
; ;
; Returns: ;
; es segment address of allocated memory block ;
; ax segment address of allocated memory block header ;
; cx size of memory available ;
;...............................................................;
_allocateMinMaxMemBlock:
Entry
def _minParag, ax
def _maxParag, dx
mov cx, dx ; try for max
call allocateMemBlock ; will probably fail
jnc _allocateMinMaxMemBlock_20 ; if ok -->
cmp cx, word ptr [ _minParag ][ bp ] ; largest available will fit ?
jnc _allocateMinMaxMemBlock_12 ; yes, go for max -->
SetError pexterrNotEnoughMemory, _allocateMinMaxMemBlock_20
_allocateMinMaxMemBlock_12:
call allocateMemBlock ; allocate largest available
mov es, ax ; segment address
sub ax, (sizeMEMBLOCK/ PARAGRAPH)
or ax, ax
_allocateMinMaxMemBlock_20:
Return
;''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''';
; Initialize Memory Block ;
;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -;
; ;
; es segment points to memory block to initialize ;
; ax is size to initialize (paragraphs ) ;
; bx parent ;
; 0000 block is free ;
; 0008 (_RxDOS_PARENT_SIGNATURE) block belongs to RxDOS ;
;...............................................................;
_initializeMemoryBlock:
push ax ; init length (paragraphs )
xor ax, ax
xor di, di
mov cx, (sizeMEMBLOCK)/2 ; size of memory header (words )
rep stosw
pop ax
xor di, di
mov byte ptr es:[ _memSignature ], _RxDOS_ENDSIGNATURE
mov word ptr es:[ _memAlloc ], ax
mov word ptr es:[ _memParent ], bx
;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
; if valid PSP, copy program name to memory block
;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
cmp bx, _RxDOS_PARENT_SIGNATURE ; RxDOS Block ?
jnz _initMemory_20 ; if not RxDOS -->
push ds
push si
push di
currSegment ds ; point to data segment
mov si, offset [ _RxDOS_DOSProgramName ]
lea di, offset _memPgmName [ di ]
mov cx, 4 ; (size _RxDOS_DOSProgramName)/2
rep movsw ; copy RxDOS name to memory block
pop di
pop si
pop ds
_initMemory_20:
ret
;''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''';
; Allocate Memory Block ;
;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -;
; ;
; Input: ;
; cx # paragraphs of memory requested ;
; ;
; Returns: ;
; es segment address of allocated memory block ;
; cx size of largest block of memory available in ;
; paragraphs, if allocation fails. ;
; cy if error ;
;...............................................................;
allocateMemBlock:
Entry
def _allocation, cx
mov bx, cx
call _allocateUpperMB ; allocate upper mem blocks
jnc allocateMemBlock_12 ; if allocation made -->
getarg bx, _allocation
call _allocateConvMB ; allocate lower mem blocks
allocateMemBlock_12:
mov es, ax ; segment allocation
mov cx, dx ; largest block
Return
;''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''';
; Collect Memory Blocks ;
;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -;
; ;
; This routine will scan all memory blocks and merge all free ;
; memory blocks together. ;
;...............................................................;
_collectMemoryBlocks:
push ds
push es
push ax
mov ax, word ptr ss:[ _RxDOS_pStartMemBlock ]
;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
; is block free ?
;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
_collectMemoryBlocks_08:
mov ds, ax ; next in ax
_collectMemoryBlocks_12:
cmp byte ptr ds:[ _memSignature ], _RxDOS_MEMSIGNATURE
jnz _collectMemoryBlocks_36 ; done -->
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -