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
/
CPM
/
ZCPR33
/
S-Z
/
SLB36HLP.LBR
/
SYSLIBB.HZP
/
SYSLIBB.HLP
Wrap
Text File
|
2000-06-30
|
5KB
|
127 lines
Introduction to the Sort Routines
SSBINIT -- SSB Initializer
SORT -- Main Sort Routine
:Introduction to the Sort Routines
Tw∩áá routine≤á arσá provideΣá whicΦá givσá thσá SYSLI┬ ì
programme≥á acces≤ t∩ ß ver∙ flexiblσ sortinτá system«á Thσ ì
maiε routinσ i≤ calleΣ SORT¼ anΣ i⌠ provide≤ ß utilit∙ whicΦ ì
doe≤á aεá in-memor∙ sor⌠ oµ ß se⌠ oµá fixed-lengtΦá records« ì
Thσ sortinτ techniquσ useΣ i≤ ß Shel∞ Sort¼ adapteΣ froφ thσ ì
booδ "Softwarσ Toolsó b∙ Kernigaε anΣ Plaugher¼ publisheΣ b∙ ì
Addison-Wesly¼ 1976¼ pagσ 106« Thi≤ sor⌠ i≤ ver∙ fast¼ mucΦ ì
morσ s∩ thaε thσ simplσ bubblσ sort.
Thi≤á Shel∞á Sor⌠ caε bσ donσ iεá tw∩á ways║á witΦá o≥ ì
withou⌠á usinτ pointers«á Sortinτ withou⌠ usinτ pointer≤ i≤ ì
typicall∙á slowe≥ thaε sortinτ witΦ pointers¼á anΣ thσá onl∙ ì
advantagσá t∩á no⌠ usinτ pointer≤ i≤ thσá saving≤á oµá spacσ ì
whicΦá i≤á takeεá u≡ b∙ thσ pointer≤á (2*numbe≥á oµá entrie≤ ì
bytes)« Iµ pointer≤ arσ useΣ fo≥ thσ sort¼ theε wheneve≥ aε ì
exchangσ i≤ done¼á thσ pointer≤ arσ simpl∙ exchanged¼ rathe≥ ì
thaεá thσ ful∞ records¼á anΣ thi≤ greatl∙ decrease≤ thσ sor⌠ ì
timσ iε mos⌠ casts.
Thσá SOR╘á routinσá i≤ controlleΣ b∙ passinτá t∩á i⌠á ß ì
pointe≥á t∩ ß Sor⌠ Specificatioε Blocδ (SSB⌐á iεá DE«á Thi≤ ì
Sor⌠á Specificatioε Blocδ i≤ ß serie≤ oµ 2-bytσ word≤á whicΦ ì
contaiε thσ followinτ information:
Bytes 0&1: Starting Address of 1st Record
Bytes 2&3: Number of Records to Sort
Bytes 4&5: Size of Each Record (in Bytes)
Bytes 6&7: Address of Compare Routine Provided by User
Thi≤á routinσá compare≤á tw∩á records¼á onσ ì
áááááááááááápointeΣ t∩ b∙ H╠ anΣ thσ othe≥ pointeΣ t∩ b∙ DE« ì
ááááááááááááIµá thσá recorΣá pointeΣ t∩ b∙á D┼á i≤á les≤á iε ì
áááááááááááásortinτá orde≥ thaε tha⌠ pointeΣ t∩ b∙ HL¼á thi≤ ì
ááááááááááááComparσ Routinσ i≤ t∩ returε witΦ Carr∙ Se⌠ (C)« ì
ááááááááááááIµ thσ record≤ arσ equa∞ iε sortinτ order¼á thi≤ ì
ááááááááááááComparσ Routinσ i≤ t∩ returε witΦ Zer∩ Se⌠á (Z)« ì
ááááááááááááOnl∙á thσá PS╫ i≤ t∩ bσ affecteΣ b∙ thσá Comparσ ì
ááááááááááááRoutine.
Bytes 8&9: Address of Pointer Table
Bytσ 10║ Flag╗ ░FFH mean≤ t∩ usσ pointers¼ 0 mean≤ not
Byte 11: Unused
A≤ mentioneΣ previously¼á tw∩ routine≤ arσ availablσ iε ì
thi≤ sor⌠ module«á Thσ firs⌠ routine¼ SSBINIT¼ look≤ a⌠ thσ ì
beginninτá oµ ß scratcΦ areß anΣ thσ initia∞ content≤ oµá aε ì
SS┬á anΣá allocate≤ spacσ fo≥ thσ pointe≥á table«á I⌠á als∩ ì
check≤á t∩ seσ iµ thσ buffe≥ requireΣ wil∞ overflo≈ thσá TP┴ ì
(Transien⌠ Prograφ Area).
Thσá seconΣá routine¼á SORT¼á perform≤á thσá sort¼á anΣ ì
controlleΣ b∙ thσ SS┬ pointe≥ passeΣ t∩ i⌠ iε DE.
:SSB Initializer
Routine: SSBINIT
Function:
Thi≤á routinσá load≤ byte≤ 0&▒ (addres≤á oµá firs⌠ ì
record⌐á anΣá 8&╣á (addres≤ oµ pointe≥á table⌐á oµá aεá SSB¼ ì
checkinτá fo≥ TP┴ overflow«á I⌠ i≤ passeΣ thσ star⌠ addres≤ ì
oµ ß scratcΦ area¼ anΣ set≤ thσ pointe≥ tablσ t∩ star⌠ here¼ ì
look≤ a⌠ thσ recorΣ sizσ anΣ recorΣ coun⌠ entrie≤ oµ aε SSB¼ ì
anΣá add≤ thi≤ produc⌠ t∩ thσ addres≤ oµ thσ pointe≥á table« ì
Thσá resultan⌠á addres≤ i≤ returneΣ a≤ thσá addres≤á oµá thσ ì
firs⌠ record.
SSBINIT, Con't
Thi≤á routinσ ma∙ bσ useΣ a≤ describeΣ abovσ beforσ an∙ ì
record≤á arσ loadeΣ int∩ memor∙ fo≥ thσ sort¼á o≥ i⌠ ma∙á bσ ì
useΣá afte≥ thσ record≤ havσ alread∙ beeεá loaded«á Iεá thσ ì
latte≥á case¼á thσ use≥ shoulΣ savσ thσ star⌠ addres≤ oµ thσ ì
firs⌠ recorΣ anΣ cal∞ SSBINI╘ witΦ thσ addres≤ oµ thσá firs⌠ ì
bytσá afte≥á thσ las⌠ record«á Oncσ SSBINI╘ ha≤ loadeΣá thσ ì
buffer≤ iε thσ SS┬ anΣ checkeΣ fo≥ ß TP┴ overflo≈ (notσ tha⌠ ì
thi≤ i≤ donσ fo≥ thσ pointer≤ only)¼á i⌠ wil∞ returε t∩á thσ ì
caller¼á a⌠á whicΦ timσ thσ calle≥ shoulΣ restorσ thσá firs⌠ ì
tw∩á byte≤á oµ thσ SS┬ t∩ thei≥ prope≥á values¼á thσá actua∞ ì
star⌠ addres≤ oµ thσ firs⌠ record.
SSBINIT, Con't
Inputs: HL pts to start of scratch area, DE pts to SSB
Outputs: Z Flag is Set (Z) if TPA overflow; NZ if OK
Registers Affected: PSW
SYSLIB Routines Called: MOVEB
Special Error Conditions: None
:SORT
Routine: SORT
Function:
SOR╘ sort≤ thσ se⌠ oµ fixeΣ lengtΦ record≤ accordinτ t∩ ì
thσá contro∞á informatioεá iε thσ Sor⌠á Specificatioεá Blocδ ì
(SSB⌐ pointeΣ t∩ b∙ DE.
Inputs: DE pts to SSB
Outputs: None (Records are Sorted)
Registers Affected: None
SYSLIB Routines Called: MOVEB, PRINT
SORT, Con't
Special Error Conditions:
Thσá Erro≥á Messagσ "SOR╘ Pointe≥á Erroróá ma∙á bσ ì
printed¼á bu⌠ i≤ highl∙ unlikely« Thi≤ indicate≤ ß fla≈ ha≤ ì
developeΣá witΦá thσ SOR╘ routinσ fo≥ thi≤ particula≥á case¼ ì
anΣ i⌠ coulΣ no⌠ SOR╘ thσ se⌠ oµ record≤ a≤á desired«á Thi≤ ì
erro≥ i≤ fata∞ anΣ wil∞ abor⌠ t∩ CP/M.