Google
 

Trailing-Edge - PDP-10 Archives - decuslib10-06 - 43,50423/dtsort.mac
There are no other files named dtsort.mac in the archive.
TITLE DTSORT SORT DECTAPE DIRECTORIES ALPHABETICALY

	SW=0
	CNT=1
	TST=2
	BP=3

START:	RESET
	INIT	317		; USE 0 FOR I/O
	SIXBIT 'SAM'
	0
	JRST	ERR1		; OH-OH
	SETZ	1,		; CHECK FOR DECTAPE
	CALLI	1, 4
	TLNN	1, (1B11)
	JRST	ERR2		; NOT A DECTAPE
	USETI	^D100		; GET DIRECTORY
	IN	IOWRD
	SKIPA
	JRST	ERR3		; HAD AN ERROR
	MOVEI	TST, 1		; SET UP MAP CROSS REFERENCE
NXTMAP:	MOVEM	TST, DTMAP-1(TST)
	AOS	TST
	CAIE	TST, ^D23	; DO ALL 22?
	JRST	NXTMAP	; NO
BEGSRT:	SETZ	SW,		; YE OLDE BUBBLE SORT

	SETZ	CNT,
NEXT:	MOVE	TST, FNAME(CNT)	; GET FIRST NAME
	JUMPE	TST, TESTM	; THIS IS ZERO CHECK NEXT ONE
	SKIPN	FNAME+1(CNT)	; NEXT ONE ZERO?
	JRST	TSTEND		; YES, GO ON
	CAMGE	TST, FNAME+1(CNT)
	JRST	TSTEND		; AC < NEXT ONE WE ARE OK
	CAME	TST, FNAME+1(CNT) ; ARE THEY EQUAL
	JRST	SWAPIT		; NO, SWITCH EM
	MOVE	TST, FEXT(CNT)	; YES, TEST EXTENSION
	CAMLE	TST, FEXT+1(CNT)
SWAPIT:	JSR	SWITCH		; AC > NEXT ONE SWITCH IT
TSTEND:	AOS	CNT
	CAIE	CNT, ^D21	; DO ALL 22?
	JRST	NEXT		; NO
	JUMPN	SW, BEGSRT	; GO BACK AND DO IT AGAIN IF WE HAD A SWITCH
	MOVEI	CNT, 1		; REMAP OUR MAP
REMAP:	MOVE	TST, DTMAP-1(CNT)	; EG IF FILE # 24 IS NOW OUR FIRST FILE
	MOVEM	CNT, NEWMAP-1(TST) ; LOC 24  OF REMAP WILL BE SET TO A ONE
	AOS	CNT
	CAIE	CNT, ^D23
	JRST	REMAP
	MOVE	BP, [POINT 5, DIR, 4]
	MOVEI	CNT, ^D581	; REBUILD MAP (OR MAP THE MAP)
NXTBYT:	LDB	TST, BP		; TAKE A NUMBER PLEASE
	CAILE	TST, ^D22	; LESS THAN 23
	JRST	TSTBPC		; NO NOT A REAL FILE
	JUMPE	TST, TSTBPC	; OR IS IT ZERO?
	MOVE	TST, NEWMAP-1(TST)	; GET NEW VALUE
	DPB	TST, BP		; STUFF IT
TSTBPC:	IBP	BP		; ALL DONE?
	SOJG	CNT, NXTBYT
	USETO	^D100		; REWRITE THE DIRECTORY
	OUT	IOWRD
	SKIPA
	JRST	ERR4		; OH-OH WE JUST SCREWED UP A TAPE!
	CLOSE			; THATS ALL FOLKS
	EXIT

TESTM:	SKIPN	FNAME+1(CNT)	; IS NEXT ONE ZERO ALSO
	JRST	TSTEND		; YES
	JRST	SWAPIT		; NO, SWITCH IT

SWITCH:	0
	MOVE	TST, FNAME(CNT)	; SWITCH FILE NAMES
	MOVE	BP, FNAME+1(CNT)
	MOVEM	BP, FNAME(CNT)
	MOVEM	TST, FNAME+1(CNT)
	MOVE	TST, FEXT(CNT)	; SWITCH EXTENSIONS
	MOVE	BP, FEXT+1(CNT)
	MOVEM	BP, FEXT(CNT)
	MOVEM	TST, FEXT+1(CNT)
	MOVE	TST, DTMAP(CNT)	; ADJUST THE MAP
	MOVE	BP, DTMAP+1(CNT)
	MOVEM	BP, DTMAP(CNT)
	MOVEM	TST, DTMAP+1(CNT)
	SETO	SW,		; SET SWITCH MADE FLAG
	JRST	@ SWITCH

IOWRD:	IOWD ^D128, DIR
	0

DIR:	BLOCK ^D82
SLTEND:	0
FNAME:	BLOCK ^D22
FEXT:	BLOCK ^D22
	0

DTMAP:	BLOCK ^D22
NEWMAP:	BLOCK ^D22

ERR1:	OUTSTR	[ASCIZ /? DEVICE "SAM" NOT ASSIGNED
/]
	EXIT
ERR2:	OUTSTR [ASCIZ /? DEVICE "SAM" IS NOT A DECTAPE
/]
	EXIT
ERR3:	OUTSTR [ASCIZ /? INPUT ERROR ON DIRECTORY
/]
	EXIT
ERR4:	OUTSTR [ASCIZ /? OUTPUT ERROR ON DIRECTORY
/]
	EXIT

	LIT
	END	START