📄 rxdosmem.asm
字号:
cmp word ptr ds:[ _memParent ], 0000 ; is block free ?
jnz _collectMemoryBlocks_26 ; no, go to next -->
;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
; is next also free ?
;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
mov ax, ds ; get current segment
add ax, word ptr ds:[ _memAlloc ] ; increment to next block
inc ax
mov es, ax
cmp word ptr es:[ _memParent ], 0000 ; is next block free ?
jnz _collectMemoryBlocks_08 ; no, go to next -->
mov ax, word ptr es:[ _memAlloc ] ; get next allocation
inc ax ; kill interim Mem block as well
add word ptr ds:[ _memAlloc ], ax ; add to current block
mov al, byte ptr es:[ _memSignature ] ; last signature is passed to current block
mov byte ptr ds:[ _memSignature ], al ;
jmp _collectMemoryBlocks_12
;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
; go to next
;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
_collectMemoryBlocks_26:
mov ax, ds ; get current segment
add ax, word ptr ds:[ _memAlloc ] ; increment to next block
inc ax
jmp _collectMemoryBlocks_08
;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
; done
;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
_collectMemoryBlocks_36:
pop ax
pop es
pop ds
ret
;''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''';
; release all Mem blocks for owner ;
;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -;
; ;
; Usage: ;
; bx PSP address of owner ;
;...............................................................;
_releaseOwnerMemoryBlocks:
push es
mov ax, word ptr ss:[ _RxDOS_pStartMemBlock ]
;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
; does block belong to owner ?
;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
_releaseOwnerMemoryBlocks_08:
mov es, ax ; next block in ax
cmp bx, word ptr es:[ _memParent ] ; owner block ?
jnz _releaseOwnerMemoryBlocks_12 ; no -->
mov word ptr es:[ _memParent ], 0000 ; free up block
_releaseOwnerMemoryBlocks_12:
cmp byte ptr es:[ _memSignature ], _RxDOS_MEMSIGNATURE
jnz _releaseOwnerMemoryBlocks_24 ; if at end -->
mov ax, es ; get current segment
add ax, word ptr es:[ _memAlloc ] ; increment to next block
inc ax
jmp _releaseOwnerMemoryBlocks_08
_releaseOwnerMemoryBlocks_24:
pop es
ret
;''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''';
; Free Memory Block ;
;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -;
; ;
; Usage: ;
; es memory block ;
;...............................................................;
_freeMemBlock:
push es
mov ax, es
sub ax, ( sizeMEMBLOCK / PARAGRAPH )
mov es, ax
cmp byte ptr es:[ _memSignature ], _RxDOS_MEMSIGNATURE
jz _freeMemBlock_12
cmp byte ptr es:[ _memSignature ], _RxDOS_ENDSIGNATURE
jnz _freeMemBlock_16
_freeMemBlock_12:
mov word ptr es:[ _memParent ], 0000 ; free up block
_freeMemBlock_16:
pop es
ret
;''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''';
; Modify Block Size ;
;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -;
; ;
; On Call: ;
; es paragraph to modify ;
; bx new paragraph size ;
; ;
; On Return: ;
; es paragraph to modify ;
; bx max block available ;
; ax error code, if error ;
; cy set if error ;
; ;
; Contraction involves splitting a block into two smaller ;
; portions. Expansion requires that the block which follows ;
; be empty. If it is, it is combined with the modify block ;
; to create a huge block, which can then be split. ;
;...............................................................;
_modifyMemBlock:
Entry
def _modifyBlock, es
def _modifySize, bx
call _collectMemoryBlocks ; collect free blocks
mov ax, es
sub ax, ( sizeMEMBLOCK / PARAGRAPH )
mov es, ax
storarg _modifyBlock, es
cmp byte ptr es:[ _memSignature ], _RxDOS_MEMSIGNATURE
jz _modifyMemBlock_12
cmp byte ptr es:[ _memSignature ], _RxDOS_ENDSIGNATURE
jz _modifyMemBlock_12
SetError pexterrInvalidBlock, _modifyMemBlock_66
;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
; are we expanding allocation ?
;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
_modifyMemBlock_12:
cmp bx, word ptr es:[ _memAlloc ]
jc _modifyMemBlock_32 ; if contracting allocation -->
ifz _modifyMemBlock_42 ; same size as now, ignore request -->
mov dx, word ptr es:[ _memAlloc ] ; get current allocation size
cmp byte ptr es:[ _memSignature ], _RxDOS_MEMSIGNATURE
jnz _modifyMemBlock_14 ; if at end block, can't expand ->
inc dx
mov ax, es
add ax, dx
mov es, ax ; address of next block
cmp word ptr es:[ _memParent ], 0000 ; is next block free ?
jnz _modifyMemBlock_14 ; no, error -->
add dx, word ptr es:[ _memAlloc ] ; total expansion space
cmp bx, dx ; is extra block enough to expand ?
jc _modifyMemBlock_18 ; yes, ok to try to expand -->
jz _modifyMemBlock_18 ; yes, ok to try to expand -->
_modifyMemBlock_14:
mov bx, dx ; available size
jmp _modifyMemBlock_46 ; not enough memory -->
;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
; merge blocks together
;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
_modifyMemBlock_18:
mov al, byte ptr es:[ _memSignature ] ; sig of next block
getarg es, _modifyBlock
mov word ptr es:[ _memAlloc ], dx ; new expanded size
mov byte ptr es:[ _memSignature ], al ; sig of next block
;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
; collapse allocated space
;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
_modifyMemBlock_32:
mov cx, es ; current segment
add cx, bx
inc cx ; where to create next mem seg
mov dl, byte ptr es:[ _memSignature ] ; sig of next block
mov ax, word ptr es:[ _memAlloc ] ; existing allocated space
sub ax, bx ; size of remaining block
jz _modifyMemBlock_42 ; same as now -- done
dec ax ; make room for mem header
mov byte ptr es:[ _memSignature ], _RxDOS_MEMSIGNATURE
mov word ptr es:[ _memAlloc ], bx ; re-allocate space
push dx
mov es, cx
xor bx, bx ; free block
call _initializeMemoryBlock ; initialize memory block.
pop dx
mov byte ptr es:[ _memSignature ], dl
_modifyMemBlock_42:
xor bx, bx ; clear carry
Return
;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
; return
;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
_modifyMemBlock_46:
RetCallersStackFrame es, si
mov word ptr es:[ _BX ][ si ], bx ; max amount allowed
mov ax, offset pexterrNotEnoughMemory
_modifyMemBlock_66:
stc
Return
;''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''';
; Allocate Upper Memory Blocks ;
;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -