home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
ftp.barnyard.co.uk
/
2015.02.ftp.barnyard.co.uk.tar
/
ftp.barnyard.co.uk
/
cpm
/
walnut-creek-CDROM
/
ZSYS
/
SIMTEL20
/
SYSLIB
/
SYSLIB.LBR
/
SYSLIBI.HQP
/
SYSLIBI.HLP
Wrap
Text File
|
2000-06-30
|
6KB
|
159 lines
Memory Allocation Concept
ALLOC -- Allocate a Block of Memory
IALLOC -- Initialize Memory Allocation System
:Memory Allocation Concept
Thσ concep⌠ oµ memor∙ allocatioε witΦ thesσ routine≤ i≤ ì
relativel∙á simple«á Routine≤á arσá provideΣá t∩á givσá thσ ì
programme≥áá simplσá memor∙á allocatioεáá anΣáá deallocatioε ì
capabilities¼ bu⌠ thσ programme≥ i≤ stil∞ iε control.
Thσá basiπá ideß herσ i≤ t∩ reservσ ß buffe≥ iεá memor∙ ì
froφá whicΦá t∩ takσ bit≤ anΣ piece≤ froφ a⌠á ßá time«á Thσ ì
boundinτá addresse≤ oµ thi≤ buffe≥ arσ specifieΣ (o≥ se⌠á b∙ ì
default⌐á b∙ thσ IALLO├ routine¼á anΣ thσ ALLO├á routinσá i≤ ì
useΣá t∩ obtaiε subbuffer≤ froφ thi≤ large≥ buffe≥ froφ timσ ì
t∩ time«á ALLO├ constantl∙ check≤ t∩ seσ iµ thσ buffe≥á ha≤ ì
enougΦ spacσ lef⌠ t∩ gran⌠ thσ reques⌠ fo≥ ß subbuffer¼ and¼ ì
if it does, the subbuffer is provided.
Thσ larges⌠ buffe≥ whicΦ ma∙ bσ reserveΣ b∙ thσá IALLO├ ì
routinσá i≤á tha⌠ buffe≥ whicΦ extend≤ froφ thσ enΣá oµá thσ ì
prograφá t∩ jus⌠ belo≈ thσ CCP«á Thi≤ buffe≥ i≤ selecteΣ iµ ì
IALLO├ i≤ calleΣ witΦ A=0.
Fo≥ example¼á thσ followinτ illustrate≤ thσ applicatioε ì
using the largest buffer possible:
XRA A ; Select Full Buffer
CALL IALLOC
...
LXI D,1024 ; Request 1K
CALL ALLOC
JZ MEMOVFL ; Abort if Memory Overflow
SHLD BUF1 ; Set Pointer to First Subbuffer
...
LXI D,36 ; Request 36 bytes
CALL ALLOC
JZ MEMOVFL ; Abort if Memory Overflow
SHLD BUF2 ; Set Pointer to 2nd Subbuffer
...
Thi≤ memor∙ allocatioε schemσ als∩ permit≤ thσ divisioε ì
oµá memor∙á int∩á ß grou≡ oµ buffers«á Onσá buffe≥á ma∙á bσ ì
allocated¼á it≤á addres≤ preserved¼á anothe≥ buffe≥á ma∙á bσ ì
allocated¼á it≤ addres≤ preserved¼ anΣ theε subsequen⌠ call≤ ì
t∩á IALLO├á ma∙ bσ useΣ t∩ selec⌠ onσ buffe≥ o≥á thσá other« ì
EacΦá cal∞ t∩ IALLO├ free≤ thσ entirσ buffe≥ area¼á s∩á carσ ì
should be taken in doing this. For example:
...
CALL CODEND ; Use Codend as First Buffer
SHLD BUF1
XCHG ; Address in DE
LXI H,1024 ; 1K for this buffer
DAD D ; HL pts to after this buffer
XCHG ; HL is start, DE is end
MVI A,3 ; Select Start and End
CALL IALLOC
...
IALLOC/ALLOC Example, Con't
...
CALL ALLOC ; Calls to ALLOC
...
LHLD BUF1 ; Pt to 1st Buffer
LXI D,1024 ; Set 2nd Buffer
DAD D ; Pt to 2nd Buffer
SHLD BUF2
XCHG
DAD D ; Pt to end of 2nd Buffer (1K also)
XCHG ; HL is start, DE is end
MVI A,3 ; Select Start and End
CALL IALLOC
...
CALL ALLOC ; Calls to ALLOC
...
:Allocate a Block of Memory
Routine: ALLOC
Function:
ALLO├á allocate≤á ß blocδ oµ memory¼á whicΦ ma∙á bσá a≤ ì
smal∞ a≤ onσ byte¼ fo≥ thσ use≥ froφ thσ buffe≥ poo∞ boundeΣ ì
b∙á thσ value≤ se⌠ b∙ ß preceedinτ cal∞ t∩á IALLOC«á IALLO├ ì
mus⌠ bσ calleΣ beforσ ALLO├ i≤ used.
Thσ programme≥ indicate≤ thσ numbe≥ oµ byte≤ hσá wishe≤ ì
t∩ usσ iε thσ D┼ registe≥ pair« Hσ theε call≤ ALLOC¼ which¼ ì
iµá enougΦá spacσ i≤ available¼á return≤ thσ addres≤ oµá thσ ì
firs⌠ bytσ oµ tha⌠ blocδ oµ memor∙ iε HL« Thσ PS╫ return≤ ß ì
flaτ sayinτ iµ thσ allocatioε wa≤ donσ successfully.
Inputs: DE = number of bytes requested
Outputs: HL = Address of first byte allocated
A=░ anΣ Zer∩ Flaτ Se⌠ (Z⌐ iµ no⌠ enougΦ space;
A=0FFH and Zero Flag Reset (NZ) if request
granted
Registers Affected: HL, PSW
SYSLIB Routines Called: None
Special Error Conditions: As indicated by return code
:Initialize Memory Allocation Buffer
Routine: IALLOC
Function:
IALLO├áá initialize≤á thσá buffe≥á froφá whicΦáá memor∙ ì
allocatioεá vißá call≤ t∩ thσ ALLO├ routinσ i≤ t∩á bσá done« ì
Thσá programme≥ ma∙ specif∙ thσ bound≤ oµá thi≤á buffer¼á o≥ ì
defaul⌠ bound≤ wil∞ bσ se⌠ b∙ IALLO├ iµ nonσ arσ specified.
Upoεá callinτá IALLOC¼á H╠á ma∙á contaiεá thσá startinτ ì
addres≤ oµ thσ buffe≥ area« Iµ i⌠ doe≤ not¼ theε thσ enΣ oµ ì
thσá user'≤á prograφ (returneΣ b∙ CODEND⌐ i≤ used«á D┼á ma∙ ì
contaiε thσ endinτ addres≤ oµ thσ buffe≥ area«á Iµ i⌠á doe≤ ì
not¼á theεá thσ bytσ belo≈ thσ CC╨ i≤ used«á Thσ ┴ registe≥ ì
contain≤ ß codeΣ flaτ sayinτ whicΦ boundar∙ value≤ t∩ use.
IALLOC, Con't
Iµ Bi⌠ ░ oµ ┴ i≤ 1¼ H╠ i≤ useΣ t∩ indicatσ thσ startinτ ì
addres≤ oµ thσ buffer« Iµ Bi⌠ ░ i≤ 0¼ thσ valuσ returneΣ b∙ ì
CODEN─á i≤ used«á Iµ Bi⌠ ▒ oµ ┴ i≤ 1¼á D┼ i≤ t∩ bσ useΣá t∩ ì
indicatσ thσ endinτ addres≤ oµ thσ buffer«á Iµ Bi⌠ ▒ i≤á 0¼ ì
thσ bytσ belo≈ thσ CC╨ i≤ used.
Inputs: HL = Possible Starting Address of Buffer
DE = Possible Ending Address of Buffer
A = Selection Code:
Bit 0 - Use HL as Starting Address if 1
Use CODEND Value if 0
Bit 1 - Use DE as Ending Address if 1
Use CCP-1 if 0
Outputs: None
Registers Affected: None
IALLOC, Con't
SYSLIB Routines Called: CODEND
Special Error Conditions: None