highload.inc

来自「Dos6.0」· INC 代码 · 共 1,910 行 · 第 1/5 页

INC
1,910
字号

HideUMBs	proc
	pushreg	<ax, cx, ds, es>

	call	UmbTest		; See if we REALLY linked in anything...
	jc	husX		; ...if not, there's nothing for us to do.

	call	FixMem		; Concatenate adjacent free MCBs in upper mem
	call	setUMBs		; Link UMBs and set memory-allocation strategy

	putdata	fInHigh, 1	; Remember that we're now running high

	call	GetLoadUMB	; See if they gave us a list to leave free
	cmp	al, UNSPECIFIED	; If they didn't,
	jz	husX		; then we shouldn't do this loop:

	xor	cx, cx

; -----------------------------------------------
; HUS10-CX - UMB number (after inc, 1==first UMB)
; -----------------------------------------------

hus10:	inc	cx		; For each UMB:
	cmp	cx, MaxUMB
	jae	hus20

	mov	al, cl		; (stopping as soon as we're outside of the
	push	es
	call	findumb		; valid range of UMBs)
	pop	es		; push/pop: trash what findumb finds.  :-)
	jc	hus20

	call	hideUMB?	; hide what we need to hide.

	jmp short hus10

hus20:	call	GetLoadUMB	; Now check if they offered /L:0
	or	al, al		; --Is the load UMB 0? (-1==unspecified)
	jnz	husX		; If not, we're done.

	call	hl_unlink	; If so, however, fix UMBs and strategy.

husX:	popreg	<es, ds, cx, ax>
	ret
HideUMBs	endp

; -----------------------------------------------------------------------------
;*** GetLoadUMB - Returns the load UMB number in AL (-1 if not specified)
; -----------------------------------------------------------------------------
; ENTRY:  None
; EXIT:   AL == load UMB
; ERROR:  None
; USES:   Flags, AX
; -----------------------------------------------------------------------------

	public	GetLoadUMB

GetLoadUMB	proc	near
	getdata	al, UmbLoad
	ret
GetLoadUMB	endp

; -----------------------------------------------------------------------------
;*** GetLoadSize - Returns the load UMB minimum size (0 if not specified)
; -----------------------------------------------------------------------------
; ENTRY:  None
; EXIT:   AX == load UMB minimum size
; ERROR:  None
; USES:   Flags, AX
; -----------------------------------------------------------------------------

	public	GetLoadSize

GetLoadSize	proc	near
	pushreg	<bx, si, ds>
	dataseg	ds

	mov	al, UmbLoad

	xor	ah, ah			;    ax==UMB
	mov	bx, offset DS:UmbSize	;                     bx==array
	shl	al, 1	                ;    ax==offset
	add	ax, bx			;    ax==element index
	mov	si, ax			; ds:si==element index

	lodsw				;    ax==size

	popreg	<ds, si, bx>
	normseg	ds
	ret
GetLoadSize	endp

; -----------------------------------------------------------------------------
;*** GetSize - Returns the UMB in AL's minimum size (0 if not specified)
; -----------------------------------------------------------------------------
; ENTRY:  AL == a UMB number
; EXIT:   AX == UMB minimum size, as specified by the user
; ERROR:  None
; USES:   Flags, AX
; -----------------------------------------------------------------------------

GetSize	proc	near
	pushreg	<bx, si, ds>
	dataseg	ds

	xor	ah, ah			;    ax==UMB
	mov	bx, offset DS:UmbSize	;                     bx==array
	shl	al, 1	                ;    ax==offset
	add	ax, bx			;    ax==element index
	mov	si, ax			; ds:si==element index

	lodsw				;    ax==size

	popreg	<ds, si, bx>
	normseg	ds
	ret
GetSize	endp

; -----------------------------------------------------------------------------
;*** StoLoadUMB - Overrides the load UMB number with what's in AL
; -----------------------------------------------------------------------------
; ENTRY:   AL == new load UMB
; EXIT:    None
; ERROR:   None
; USES:    Flags, AX
; -----------------------------------------------------------------------------
; CAUTION: Should only be used if /L:... was used.  Logically, that is the only
;          time you would ever need this, so that's okay.
; -----------------------------------------------------------------------------

	public	StoLoadUMB

StoLoadUMB	proc	near
	putdata	UmbLoad, al
	ret
StoLoadUMB	endp

; -----------------------------------------------------------------------------
;*** StoLoadSize - Overrides the load UMB minimum size with what's in AX
; -----------------------------------------------------------------------------
; ENTRY:  AL == new load size
; EXIT:   None
; ERROR:  None
; USES:   Flags, AX
; -----------------------------------------------------------------------------

	public	StoLoadSize

StoLoadSize	proc
	push	dx

	getdata	dl, UmbLoad		; Put UMB# in DL and size in AX
	cmp	dl, UNSPECIFIED
	jz	sls10

	call	stowsiz			; We've got a function to do just this

sls10:	pop	dx
	ret
StoLoadSize	endp

; -----------------------------------------------------------------------------
;*** hideUMB - marks as HIDDEN all FREE elements in UMB passed as AL
; -----------------------------------------------------------------------------
; ENTRY:    AL must indicate a valid UMB; 0==conv && is invalid.
; EXIT:     None; free elements in UMB marked as hidden
; ERROR:    None
; USES:     Flags
; -----------------------------------------------------------------------------

hideUMB	proc	near
	pushreg	<ax, es>

	call	findUMB		; Returns with carry if err, else ES == MCB
	jc	huX

; ------------------------------------------------
; HU10--ES - MCB inside UMB; if it's a system MCB,
;            we're not in the same UMB, so exit.
; ------------------------------------------------

hu10:	call	isSysMCB	; Returns with ZF set if owner is SYSTEM
	jz	huX		; If it is, we've finished the UMB.
	call	isFreeMCB	; Returns with ZF set if owner is 0
	jnz	hu20

	call	hideMCB

hu20:	mov	al, es:[arena_signature]
	cmp	al, arena_signature_end
	jz	huX		; 'Z' means this was the last MCB... that's it.

	NextMCB	es, ax		; Go on forward.

	jmp short hu10

huX:	popreg	<es, ax>
	ret
hideUMB	endp

; -----------------------------------------------------------------------------
;*** isTiny - returns with ZF set if user didn't specify /S
; -----------------------------------------------------------------------------
; ENTRY:    None
; EXIT:     ZF set if user DIDN'T specify /S
; ERROR:    None
; USES:     Flags
; -----------------------------------------------------------------------------

isTiny	proc	near
	push	ax
	getdata	al, fUmbTiny
	or	al, al
	pop	ax
	ret
isTiny	endp

; -----------------------------------------------------------------------------
;*** isFreeMCB - returns with ZF set if current MCB (ES:0) is FREE
; -----------------------------------------------------------------------------
; ENTRY:    ES:0 should point to an MCB
; EXIT:     ZF set if MCB is free, else !ZF
; ERROR:    None
; USES:     Flags
; -----------------------------------------------------------------------------

isFreeMCB	proc	near
	or	ES:[arena_owner], 0
	ret
isFreeMCB	endp

; -----------------------------------------------------------------------------
;*** hideMCB - marks as HIDDEN the MCB at ES:0
; -----------------------------------------------------------------------------
; ENTRY:    ES:0 should point to an MCB
; EXIT:     None; MCB marked as HIDDEN
; ERROR:    None
; USES:     None
; -----------------------------------------------------------------------------

hideMCB	proc	near
	mov	es:[arena_owner], SystemPSPOwner
	mov	word ptr es:[arena_name+0], 'IH'
	mov	word ptr es:[arena_name+2], 'DD'
	mov	word ptr es:[arena_name+4], 'NE'
	mov	word ptr es:[arena_name+6], '  '
	ret
hideMCB	endp

; -----------------------------------------------------------------------------
;*** unHideMCB - marks as FREE the MCB at ES:0
; -----------------------------------------------------------------------------
; ENTRY:    ES:0 should point to an MCB
; EXIT:     None; MCB marked as FREE
; ERROR:    None
; USES:     None
; -----------------------------------------------------------------------------

unHideMCB	proc	near
	push	ax
	mov	es:[arena_owner], FreePSPOwner
	mov	ax, '  '
	mov	word ptr es:[arena_name+0], ax
	mov	word ptr es:[arena_name+2], ax
	mov	word ptr es:[arena_name+4], ax
	mov	word ptr es:[arena_name+6], ax
	pop	ax
	ret
unHideMCB	endp

; -----------------------------------------------------------------------------
;*** findUMB - makes ES:0 point to the first MCB in UMB given as AL
;            -- returns UmbHEAD pointer (0x9FFF) if passed AL==0
; -----------------------------------------------------------------------------
; ENTRY:    AL should be to a valid UMB number
; EXIT:     ES:0 points to first MCB in UMB (_not_ the 8+SC MCB that heads it)
; ERROR:    Carry set if couldn't reach UMB (too high)
; USES:     Flags, ES
; -----------------------------------------------------------------------------

findUMB	proc	near
	pushreg	<ax, cx, dx>

	xor	ah, ah		; Zap ah, so al==ax

	mov	dx, ax		; Store the to-be-found UMB number in DX

	call	UmbHead		; Returns first UMB segment in AX
	mov	es, ax
	xor	cx, cx		; Pretend we're on UMB 0 for now...

; ---------------------------------------------
; FU10--CX - This UMB number; 0 == conventional
;       DX - The UMB number they're looking for
;       ES - The current MCB address
; ---------------------------------------------

fu10:	cmp	cx, dx		; If CX==DX, we've found the UMB we're
	jz	fuX		; searching for--so exit.

	call	isSysMCB	; Returns with ZF set if owner is SYSTEM
	jnz	fu20

	inc	cx		; If it _was_ SYSTEM, we're in a new UMB.

fu20:	mov	al, es:[arena_signature]
	cmp	al, arena_signature_end
	jz	fuE		; 'Z' means this was the last MCB... that's it.

	NextMCB	es, ax		; Go on forward.

	jmp short fu10

fuE:	stc
fuX:	popreg	<dx, cx, ax>	; The address is already in ES.
	ret
findUMB	endp

; -----------------------------------------------------------------------------
;*** BigFree - makes ES:0 point to the largest free MCB in UMB given as AL
; -----------------------------------------------------------------------------
; ENTRY:    AL should be to a valid UMB number
; EXIT:     ES:0 points to largest free MCB in UMB, AX returns its size
; ERROR:    Carry set if couldn't reach UMB (0 or too high)
; USES:     Flags, ES
; -----------------------------------------------------------------------------

	public	BigFree

BigFree	proc	near
	pushreg	<bx, cx>

	call	findUMB			; Returns with CF if err, else ES==MCB
	jc	bfX			; (would be "jc bfE"; it just does stc)

	xor	bx, bx			; Segment address of largest free MCB
	xor	cx, cx			; Size of largest free MCB

; ---------------------------------------------
; BF10--ES - Current MCB address
;       BX - Address of largest free MCB so far
;       CX - Size of largest free MCB so far
; ---------------------------------------------

bf10:	call	isSysMCB		; If we've left the MCB, we're done.
	jz	bf30

	call	isFreeMCB		; Returns with ZF set if owner is 0
	jnz	bf20

	cmp	cx, es:[arena_size]	; Compare sizes...
	jg	bf20			; Unless we're bigger,

	mov	bx, es			; Store this new element's address,
	mov	cx, es:[arena_size]	; and its size.

bf20:	mov	al, es:[arena_signature]
	cmp	al, arena_signature_end
	jz	bf30			; 'Z' means this was the last MCB.

	NextMCB	es, ax			; Go on forward.

	jmp short bf10

bf30:	mov	es, bx			; Return the address
	mov	ax, cx			; Return the size
	or	bx, bx
	jnz	bfX			; (if size==0, there's nothing free)

bfE:	stc
bfX:	popreg	<cx, bx>

	ret
BigFree	endp

; -----------------------------------------------------------------------------
;*** isSpecified - sets ZF if UMB in AL wasn't specified in DH/LH line.
; -----------------------------------------------------------------------------
; ENTRY:    AL should be to a valid UMB number
; EXIT:     ZF set if UMB wasn't specified, ZF clear if it was
; ERROR:    None
; USES:     Flags

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?