home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Power-Programmierung
/
CD1.mdf
/
assemblr
/
library
/
lib4a86
/
lib
/
bheap.lib
< prev
next >
Wrap
Text File
|
1992-02-11
|
12KB
|
702 lines
#IF !LIB4A86
#ELSE
#IF !INTERN_LIB4A86_S
INTERN_LIB4A86_S EQU 01
JMP START
#ENDIF
#ENDIF
BHEAPHEADER STRUC
BHEAPLENGTH DW ?
MAXBHEAPFREE DW ?
LASTBHEAPPTR DW ?
FREEBHEAPPTR DW ?
BHEAPDUMMY DB ?
BHEAPFLAGS DB ?
BHEAPHEADERCRC DW ?
BHEAPUSERDATA1 DW ?
BHEAPUSERDATA2 DW ?
ENDS
FIRSTBHEAPPTR EQU (TYPE BHEAPHEADER)
BHEAPHEADERLENGTH EQU (TYPE BHEAPHEADER)
BHEAPCONTROLBLOCK STRUC
BH_PREVBLOCKPTR DW ?
BH_BLOCKFLAGS DW
BH_NEXTBLOCKPTR DW ?
ENDS
BHEAPCONTROLBLOCKLENGTH EQU TYPE (BHEAPCONTROLBLOCK)
BHEAPFREEBLOCK STRUC
DB BHEAPCONTROLBLOCKLENGTH DUP ?
BH_PREVFREEPTR DW ?
BH_NEXTFREEPTR DW ?
ENDS
BHEAPFREEBLOCKLENGTH EQU TYPE (BHEAPFREEBLOCK)
ISUSEDBHEAPBLOCK EQU 001XB
ISLASTBHEAPBLOCK EQU 010XB
BHEAPBLOCKISFREE EQU NOT ISUSEDBHEAPBLOCK
BHEAPBLOCKISNTLAST EQU NOT ISLASTBHEAPBLOCK
_BHEAPFLAGS EQU (ISUSEDBHEAPBLOCK OR ISLASTBHEAPBLOCK)
_NOBHEAPFLAGS EQU NOT _BHEAPFLAGS
MINBHEAPLENGTH EQU 1024XD
TRYLASTPTRFIRST EQU 001H
FREEPTRFIRST EQU 0FEH
BIGFREEBLOCKS EQU 0FDH
NOBIGFREEBLOCKS EQU 002H
BHEAPFATALERROR EQU 080FFH
BHEAPPOINTERERROR EQU 080FEH
BHEAPFPOINTERERROR EQU 080FDH
BHEAPLENGTHERROR EQU 080FCH
BHEAPNOMOREBLOCKS EQU 08001H
BHEAPFREEBLERROR EQU 08002H
BHEAPMEMORYERROR EQU 08003H
BHEAPREPAIRED EQU 08004H
BHEAPSEG DW 0
CHAINFREEBHEAPBLOCKS_A:
MOV ES,CS:BHEAPSEG
CHAINFREEBHEAPBLOCKS:
CALL INTERN_CHECKBHEAPHEADER
JC RET
PUSH BX,CX,DX,SI,DI,DS
MOV DS,ES
XOR DX,DX
MOV SI,FREEBHEAPPTR
L00:
OR SI,SI
JZ >L02
MOV BX,BH_PREVBLOCKPTR[SI]
TEST BH_NEXTBLOCKPTR[BX],ISUSEDBHEAPBLOCK
JNZ >L01
XCHG BX,SI
CALL INTERN_UNCHAINFREEBLOCK
XCHG BX,SI
ADD MAXBHEAPFREE,BHEAPCONTROLBLOCKLENGTH
INC DX
CALL INTERN_CONCATBHEAPBLOCKS
XCHG BX,SI
CMP LASTBHEAPPTR,BX
IF E MOV LASTBHEAPPTR,SI
L01:
MOV SI,BH_NEXTFREEPTR[SI]
JMP L00
L02:
MOV AX,DX
PUSH AX
CALL INTERN_CALCBHEAPHEADER
POP AX
POP DS,DI,SI,DX,CX,BX
RET
L0:
MOV AX,ES:BHEAPLENGTH
RET
CHANGEBHEAPSIZE_A:
MOV ES,CS:BHEAPSEG
CHANGEBHEAPSIZE:
CALL INTERN_CHECKBHEAPHEADER
JC RET
JCXZ L0
PUSH BX,CX,DX,SI,DS
MOV DS,ES
AND CX,_NOBHEAPFLAGS
CMP CX,BHEAPLENGTH
JE >L90
CMP CX,MINBHEAPLENGTH
JB >L80
CALL INTERN_GETMAXBHEAPPOINTER
CMP AX,CX
JA >L80
MOV DX,BHEAPLENGTH
MOV BHEAPLENGTH,CX
MOV AX,CX
XOR AL,AH
MOV BHEAPDUMMY,AL
MOV BX,LASTBHEAPPTR
MOV SI,BH_NEXTBLOCKPTR[BX]
TEST SI,ISUSEDBHEAPBLOCK
JZ >L1
CMP CX,BHEAPFREEBLOCKLENGTH
JBE >L1
AND BH_NEXTBLOCKPTR[BX],BHEAPBLOCKISNTLAST
AND SI,_NOBHEAPFLAGS
XCHG SI,BX
MOV BH_PREVBLOCKPTR[BX],SI
L1:
OR CX,ISLASTBHEAPBLOCK
MOV BH_NEXTBLOCKPTR[BX],CX
L2:
CALL INTERN_CALCBHEAPHEADER
JC >L9
L90:
MOV AX,BHEAPLENGTH
JMP >L9
L80:
MOV AX,BHEAPLENGTHERROR
L8:
STC
L9:
POP DS,SI,DX,CX,BX
RET
INITBHEAP:
CMP CX, MINBHEAPLENGTH
JAE >L1
STC
MOV AX,BHEAPLENGTHERROR
RET
L1:
PUSH DS,BX,CX
MOV CS:BHEAPSEG,ES
PUSH ES
POP DS
MOV BHEAPFLAGS,0
AND CX,_NOBHEAPFLAGS
MOV BHEAPLENGTH,CX
PUSH CX
XOR CL,CH
MOV BHEAPDUMMY,CL
POP CX
SUB CX,BHEAPCONTROLBLOCKLENGTH
MOV AX,BHEAPHEADERLENGTH
SUB CX,AX
MOV MAXBHEAPFREE,CX
MOV LASTBHEAPPTR,AX
MOV BX,AX
MOV BH_PREVBLOCKPTR[BX],0
ADD CX,BHEAPCONTROLBLOCKLENGTH
ADD CX,BX
MOV BH_NEXTBLOCKPTR[BX],CX
OR BH_BLOCKFLAGS[BX], ISLASTBHEAPBLOCK
MOV FREEBHEAPPTR,0
CALL INTERN_CHAINFREEBLOCK
CALL INTERN_UPDATEBHEAPHEADER
MOV AX,MAXBHEAPFREE
POP CX,BX,DS
RET
GETBHEAPBLOCKLENGTH_A:
MOV ES,CS:BHEAPSEG
GETBHEAPBLOCKLENGTH:
CALL INTERN_CHECKBHEAPBLOCK
JC RET
PUSH BX
SUB BX,BHEAPCONTROLBLOCKLENGTH
CALL INTERN_GETBHEAPBLOCKLENGTH
POP BX
RET
GETFIRSTBHEAPBLOCK_A:
MOV ES,CS:BHEAPSEG
GETFIRSTBHEAPBLOCK:
CALL INTERN_CHECKBHEAPHEADER
JC RET
MOV AX,FIRSTBHEAPPTR
INTERN_GETBHEAPBLOCKDATA0:
AND AX,_NOBHEAPFLAGS
MOV BX,AX
INTERN_GETBHEAPBLOCKDATA:
XOR AX,AX
CALL INTERN_GETBHEAPBLOCKLENGTH
ADD BX,BHEAPCONTROLBLOCKLENGTH
TEST ES:BH_BLOCKFLAGS[BX]-BHEAPCONTROLBLOCKLENGTH,ISUSEDBHEAPBLOCK
CLC
RET
GETNEXTBHEAPBLOCK_A:
MOV ES,CS:BHEAPSEG
GETNEXTBHEAPBLOCK:
CALL INTERN_CHECKBHEAPBLOCK
JC RET
MOV AX,ES:BH_NEXTBLOCKPTR[BX]-BHEAPCONTROLBLOCKLENGTH
TEST AX,ISLASTBHEAPBLOCK
JZ INTERN_GETBHEAPBLOCKDATA0
L8:
MOV AX,BHEAPNOMOREBLOCKS
STC
RET
GETPREVBHEAPBLOCK_A:
MOV ES,CS:BHEAPSEG
GETPREVBHEAPBLOCK:
CALL INTERN_CHECKBHEAPBLOCK
JC RET
MOV AX,ES:BH_PREVBLOCKPTR[BX]-BHEAPCONTROLBLOCKLENGTH
OR AX,AX
JZ L8
JMP SHORT INTERN_GETBHEAPBLOCKDATA0
GETLASTBHEAPBLOCK_A:
MOV ES,CS:BHEAPSEG
GETLASTBHEAPBLOCK:
CALL INTERN_CHECKBHEAPHEADER
JC RET
MOV AX,ES:LASTBHEAPPTR
JMP INTERN_GETBHEAPBLOCKDATA0
GETMAXBHEAPPOINTER_A:
MOV ES,CS:BHEAPSEG
GETMAXBHEAPPOINTER:
CALL INTERN_CHECKBHEAPHEADER
JC RET
INTERN_GETMAXBHEAPPOINTER:
PUSH BX
MOV BX,ES:LASTBHEAPPTR
MOV AX,ES:BH_NEXTBLOCKPTR[BX]
AND AX,_NOBHEAPFLAGS
TEST ES:BH_BLOCKFLAGS[BX],ISUSEDBHEAPBLOCK
JNZ >L1
LEA AX,[BX+BHEAPFREEBLOCKLENGTH+4]
L1:
POP BX
RET
GETBHEAPMEMAVAIL_A:
MOV ES,CS:BHEAPSEG
GETBHEAPMEMAVAIL:
CALL INTERN_CHECKBHEAPHEADER
JC RET
PUSH BX,SI,DI,DS
MOV DS,ES
XOR DX,DX
XOR DI,DI
XOR SI,SI
MOV BX,FREEBHEAPPTR
L0:
OR BX,BX
JZ >L2
CALL INTERN_CHECKFREEBLOCK
JC >L8
INC SI
CALL INTERN_GETBHEAPBLOCKLENGTH
CMP CX,DI
IF A MOV DI,CX
ADD DX,CX
MOV BX,BH_NEXTFREEPTR[BX]
JMP L0
L2:
MOV CX,DI
MOV AX,SI
L8:
POP DS,DI,SI,BX
RET
RELEASEBHEAPMEM_A:
MOV ES,CS:BHEAPSEG
RELEASEBHEAPMEM:
CALL INTERN_CHECKBHEAPBLOCK
JC RET
PUSH BX,CX,DX,DS,SI
MOV DS,ES
MOV SI,LASTBHEAPPTR
MOV AX,BH_NEXTBLOCKPTR[SI]
SUB BX,BHEAPCONTROLBLOCKLENGTH
MOV BH_NEXTBLOCKPTR[BX],AX
OR BH_BLOCKFLAGS[BX],ISUSEDBHEAPBLOCK
CALL INTERN_CALCBHEAPHEADER
POP SI,DS,DX,CX,BX
JNC >L1
RET
FREEBHEAPMEM_A:
MOV ES,CS:BHEAPSEG
FREEBHEAPMEM:
CALL INTERN_CHECKBHEAPBLOCK
JC RET
TEST ES:BH_BLOCKFLAGS[BX]-BHEAPCONTROLBLOCKLENGTH ,ISUSEDBHEAPBLOCK
JNZ >L1
MOV AX,BHEAPFREEBLERROR
STC
RET
L1:
PUSH SI,DI,CX,BX,DS
PUSH ES
POP DS
SUB BX,BHEAPCONTROLBLOCKLENGTH
MOV DI,BH_NEXTBLOCKPTR[BX]
AND DI,_NOBHEAPFLAGS
MOV SI,BH_PREVBLOCKPTR[BX]
CALL INTERN_GETBHEAPBLOCKLENGTH
ADD MAXBHEAPFREE,CX
TEST BHEAPFLAGS,NOBIGFREEBLOCKS
JNZ >L2
OR SI,SI
JZ >L1
TEST BH_BLOCKFLAGS[SI],ISUSEDBHEAPBLOCK
JNZ >L1
ADD MAXBHEAPFREE,BHEAPCONTROLBLOCKLENGTH
CMP LASTBHEAPPTR,BX
IF E MOV LASTBHEAPPTR,SI
XCHG BX,SI
CALL INTERN_UNCHAINFREEBLOCK
CALL INTERN_CONCATBHEAPBLOCKS
L1:
TEST BH_NEXTBLOCKPTR[BX],ISLASTBHEAPBLOCK
JNZ >L2
TEST BH_BLOCKFLAGS[DI],ISUSEDBHEAPBLOCK
JNZ >L2
ADD MAXBHEAPFREE,BHEAPCONTROLBLOCKLENGTH
CMP LASTBHEAPPTR,DI
IF E MOV LASTBHEAPPTR,BX
PUSH BX
MOV BX,DI
CALL INTERN_UNCHAINFREEBLOCK
POP BX
MOV SI,DI
CALL INTERN_CONCATBHEAPBLOCKS
L2:
AND BH_BLOCKFLAGS[BX],BHEAPBLOCKISFREE
CALL INTERN_CHAINFREEBLOCK
CALL INTERN_UPDATEBHEAPHEADER
POP DS,BX,CX,DI,SI
RET
GETBHEAPMEM_A:
MOV ES,CS:BHEAPSEG
GETBHEAPMEM:
CALL INTERN_CHECKBHEAPHEADER
JC RET
TEST CX,_BHEAPFLAGS
PUSHF
AND CX,_NOBHEAPFLAGS
POPF
IF NZ ADD CX,BHEAPCONTROLBLOCKLENGTH
L1:
PUSH DS,DI,SI,CX,DX
PUSH ES
POP DS
MOV AX,CX
CMP AX, MAXBHEAPFREE
JA >L8
TEST BHEAPFLAGS,TRYLASTPTRFIRST
JZ >L1
MOV BX,LASTBHEAPPTR
CMP BX,FREEBHEAPPTR
JE >L1
TEST BH_NEXTBLOCKPTR[BX],ISUSEDBHEAPBLOCK
JNZ >L1
CALL INTERN_GETBHEAPBLOCKLENGTH
CMP AX,CX
JBE >L5
L1:
MOV BX,FREEBHEAPPTR
L0:
OR BX,BX
JE >L8
CALL INTERN_GETBHEAPBLOCKLENGTH
CMP AX,CX
JA >L1
L5:
CALL INTERN_UNCHAINFREEBLOCK
JC >L9
PUSH BX
CALL INTERN_SETNEWBLOCKLENGTH
POP BX
SUB MAXBHEAPFREE,AX
OR BH_BLOCKFLAGS[BX],ISUSEDBHEAPBLOCK
ADD BX,BHEAPCONTROLBLOCKLENGTH
CALL INTERN_UPDATEBHEAPHEADER
JMP >L9
L1:
MOV BX,BH_NEXTFREEPTR[BX]
JMP L0
L8:
MOV AX,BHEAPMEMORYERROR
STC
L9:
POP DX,CX,SI,DI,DS
RET
REPAIRBHEAP_A:
MOV ES,CS:BHEAPSEG
REPAIRBHEAP:
PUSH DS,DI,SI,BX,DX
PUSH ES
POP DS
MOV AX,BHEAPLENGTH
PUSH AX
XOR AL,AH
CMP AL,BHEAPDUMMY
POP AX
JNE >L80
MOV BX,LASTBHEAPPTR
MOV BX,BH_NEXTBLOCKPTR[BX]
AND BX,_NOBHEAPFLAGS
CMP AX,BX
JNE >L80
CALL INTERN_UPDATEBHEAPHEADER
MOV BX,FIRSTBHEAPPTR
XOR SI,SI
L0:
ADD BX,BHEAPCONTROLBLOCKLENGTH
CALL INTERN_CHECKBHEAPBLOCK
JC >L2
SUB BX,BHEAPCONTROLBLOCKLENGTH
MOV DX,BH_NEXTBLOCKPTR[BX]
TEST DX,ISLASTBHEAPBLOCK
JNZ >L1
MOV SI,BX
AND DX,_NOBHEAPFLAGS
XCHG DX,BX
CMP BX,DX
JA L0
JMP >L2
L80:
JMP >L8
L1:
CMP BX,LASTBHEAPPTR
JNE >L2
L90:
CALL INTERN_CALCBHEAPHEADER
JC >L8
JMP >L9
L2:
OR SI,SI
JZ >L8
MOV BX,LASTBHEAPPTR
XOR DI,DI
L0:
ADD BX,BHEAPCONTROLBLOCKLENGTH
CALL INTERN_CHECKBHEAPBLOCK
JC >L2
SUB BX,BHEAPCONTROLBLOCKLENGTH
MOV DI,BX
MOV BX,BH_PREVBLOCKPTR[BX]
CMP DI,BX
JBE >L8
OR BX,BX
JNZ L0
CMP BX,FIRSTBHEAPPTR
JZ L90
L2:
OR DI,DI
JZ >L8
CMP DI,SI
JZ >L8
IF B XCHG DI,SI
MOV BH_PREVBLOCKPTR[DI],SI
MOV BX,SI
MOV BH_NEXTBLOCKPTR[BX],DI
OR BH_BLOCKFLAGS[BX],ISUSEDBHEAPBLOCK
MOV BHEAPFLAGS,0
CALL INTERN_CALCBHEAPHEADER
JC >L8
MOV AX, BHEAPREPAIRED
JMP >L81
L8:
MOV AX,BHEAPFATALERROR
L81:
STC
L9:
POP DX,BX,SI,DI,DS
RET
INTERN_CALCBHEAPHEADER:
XOR AX,AX
MOV MAXBHEAPFREE,AX
MOV LASTBHEAPPTR,AX
MOV FREEBHEAPPTR,AX
MOV BX,FIRSTBHEAPPTR
L0:
CALL INTERN_GETBHEAPBLOCKLENGTH
MOV DX,BH_NEXTBLOCKPTR[BX]
TEST DX,ISUSEDBHEAPBLOCK
JNZ >L1
ADD MAXBHEAPFREE,CX
CALL INTERN_CHAINFREEBLOCK
L1:
TEST DX,ISLASTBHEAPBLOCK
JNZ >L1
AND DX,_NOBHEAPFLAGS
CMP DX,BX
JBE >L01
MOV BX,DX
JMP L0
L01:
MOV AX,BHEAPPOINTERERROR
RET
L1:
MOV LASTBHEAPPTR,BX
INTERN_UPDATEBHEAPHEADER:
CALL INTERN_BUILDHEADERCRC
MOV ES:BHEAPHEADERCRC,AX
CLC
RET
INTERN_BUILDHEADERCRC:
PUSH CX,BX
MOV CX,(OFFSET BHEAPHEADERCRC) - 1
XOR AX,AX
XOR BX,BX
L0:
ADD AL,ES:[BX]
ADC AH,0
INC BX
LOOP L0
POP BX,CX
RET
INTERN_SETNEWBLOCKLENGTH:
PUSH DI
MOV SI,BH_NEXTBLOCKPTR[BX]
SUB CX,AX
JZ >L7
CMP CX,BHEAPCONTROLBLOCKLENGTH
JE >L6
ADD AX,BHEAPCONTROLBLOCKLENGTH
MOV CX,AX
ADD AX,BX
MOV DI,AX
MOV BH_NEXTBLOCKPTR[BX],DI
CMP LASTBHEAPPTR,DI
IF B MOV LASTBHEAPPTR,DI
MOV BH_PREVBLOCKPTR[DI],BX
MOV BH_NEXTBLOCKPTR[DI],SI
XCHG BX,DI
CALL INTERN_CHAINFREEBLOCK
XCHG BX,DI
TEST SI,ISLASTBHEAPBLOCK
JNZ >L6
AND SI,_NOBHEAPFLAGS
MOV BH_PREVBLOCKPTR[SI],DI
L6:
MOV AX,CX
L7:
L9:
POP DI
RET
INTERN_CONCATBHEAPBLOCKS:
PUSH DI
MOV DI,BH_NEXTBLOCKPTR[SI]
MOV BH_NEXTBLOCKPTR[BX],DI
TEST DI,ISLASTBHEAPBLOCK
JNZ >L1
AND DI,_NOBHEAPFLAGS
MOV BH_PREVBLOCKPTR[DI],BX
L1:
POP DI
INTERN_GETBHEAPBLOCKLENGTH:
MOV CX,ES:BH_NEXTBLOCKPTR[BX]
AND CX,_NOBHEAPFLAGS
SUB CX,BX
SUB CX,BHEAPCONTROLBLOCKLENGTH
RET
INTERN_CHECKBHEAPBLOCK:
CALL INTERN_CHECKBHEAPHEADER
JC RET
PUSH BX,SI,DI,DS
PUSH ES
POP DS
SUB BX,BHEAPCONTROLBLOCKLENGTH
TEST BX,_BHEAPFLAGS
JNZ >L8
MOV SI,BH_PREVBLOCKPTR[BX]
MOV DI,BH_NEXTBLOCKPTR[BX]
OR SI,SI
JZ >L1
CMP BX,SI
JBE >L8
MOV AX,BH_NEXTBLOCKPTR[SI]
AND AX,_NOBHEAPFLAGS
CMP AX,BX
JNZ >L8
L1:
TEST DI,ISUSEDBHEAPBLOCK
JNZ >L1
CALL INTERN_CHECKFREEBLOCK
JC >L9
L1:
TEST DI,ISLASTBHEAPBLOCK
JNZ >L1
AND DI,_NOBHEAPFLAGS
CMP BX,DI
JAE >L8
MOV AX,BH_PREVBLOCKPTR[DI]
CMP AX,BX
JNZ >L8
L1:
CLC
L9:
POP DS,DI,SI,BX
RET
L8:
STC
MOV AX,BHEAPPOINTERERROR
JMP L9
INTERN_CHECKBHEAPHEADER:
CALL INTERN_BUILDHEADERCRC
CMP ES:BHEAPHEADERCRC,AX
JZ RET
MOV AX,BHEAPFATALERROR
STC
RET
INTERN_CHECKFREEBLOCK:
PUSH SI
MOV SI,BH_PREVFREEPTR[BX]
OR SI,SI
JZ >L1
CMP BH_NEXTFREEPTR[SI],BX
JNZ >L8
L1:
MOV SI,BH_NEXTFREEPTR[BX]
OR SI,SI
JZ >L1
CMP BH_PREVFREEPTR[SI],BX
JNZ >L8
L1:
JMP >L9
L8:
MOV AX,BHEAPFPOINTERERROR
STC
L9:
POP SI
RET
INTERN_UNCHAINFREEBLOCK:
CALL INTERN_CHECKFREEBLOCK
JC RET
PUSH SI,DI
MOV SI,BH_PREVFREEPTR[BX]
MOV DI,BH_NEXTFREEPTR[BX]
OR SI,SI
JNZ >L1
MOV FREEBHEAPPTR,DI
JMP >L2
L1:
MOV BH_NEXTFREEPTR[SI],DI
L2:
OR DI,DI
JZ >L1
MOV BH_PREVFREEPTR[DI],SI
L1:
CLC
POP DI,SI
RET
INTERN_CHAINFREEBLOCK:
PUSH SI
MOV SI,FREEBHEAPPTR
OR SI,SI
JNZ >L1
MOV BH_PREVFREEPTR[BX],SI
MOV BH_NEXTFREEPTR[BX],SI
JMP >L9
L1:
MOV BH_NEXTFREEPTR[BX],SI
MOV BH_PREVFREEPTR[BX],0
MOV BH_PREVFREEPTR[SI],BX
L9:
MOV FREEBHEAPPTR,BX
CLC
POP SI
RET
#IF !INTERN_CMARK0
INTERN_CMARK0 EQU 01H
INTERN_CMARK1:
PUSH BP
MOV BP,SP
MOV BX,06H
SUB CH,[BP+SI]
SUB AH,[BX+SI]
DEC SP
DEC CX
INC DX
XOR AL,041H
CMP B[02820H],DH
INC BX
SUB W[BX+SI],SP
INC DX
CS AND B[BP+DI+043H],DL
DEC AX
INC BP
DEC BP
DEC BP
INC BP
PUSH DX
AND B[BP+SI],CH
SUB CH,[BP+SI]
POP DX
MOV SP,BP
POP BP
RET
#ENDIF