	exeobj
	objfile 'ram:pslist'
	;addsym
	multipass
	realtime

CALL	MACRO
	jsr	(_LVO\1,a6)
	ENDM


	lea	(Dt),a4
	OPTIMON BASEREG
	BASEREG A4,Dt

OpenDos				
	movea.l	(4).w,a6
	lea	(dosname),a1
	moveq	#37,d0		
	CALL	OpenLibrary
	move.l	d0,(dosbase)
	bne	OpenInt		
	moveq	#20,d0		
	rts			
				
OpenInt
	lea	(intname),a1
	moveq	#37,d0
	CALL	OpenLibrary
	move.l	d0,(intbase)	
	bne	GetPubScreens	
				
	move.l	(dosbase),a6	
	move.l	#noint,d1
	CALL	PutStr
	moveq	#20,d3	
	bra	closedos

GetPubScreens				

	move.l	(dosbase),a6
	move.l	#listps,d1
	CALL	PutStr

	movea.l	(intbase),a6
	moveq	#0,d0
	CALL	LockPubScreenList
	tst.l	d0
	beq	unlockps
	move.l	d0,a2
	cmp.l	#0,(a2)	;No Pub screens!
	beq	unlockps


	move.l	(LH_HEAD,a2),a2	; (a2),a2 really  ;Get PubScreenListNode

*A2 is now at 1st PubScreen List Node
PSloop
	move.l	(LN_NAME,a2),(arg1)	       
	cmp.w	#PSNF_PRIVATE,(psn_Flags,a2)   
	bne	title
	move.l	#Priv,(arg2)
	bra	print
title	move.l	(psn_Screen,a2),a1   ;Screen in A1
	move.l	(sc_Title,a1),(arg2) 
print	bsr	PSPrintF	;print the results
	move.l	(LN_SUCC,a2),a2 
	cmp.l	#0,(a2)	;does it point back to LH_TAIL yet
	bne	PSloop
unlockps	
	CALL	UnlockPubScreenList
		
	moveq	#0,d3

closeint
	move.l	(4).w,a6
	move.l	(intbase),a1
	CALL	CloseLibrary
closedos
	move.l	(4).w,a6
	move.l	(dosbase),a1
	CALL	CloseLibrary
	move.l	d3,d0	;return code
	rts

PSPrintF
	pushm.l a2/a6		
	move.l	(dosbase),a6	
	move.l	#args,d2	
	move.l	#fv,d1		
	CALL	VPrintf
	popm.l a2/a6
	rts
	
Dt

fv	db '%s (%s)',10,0
dosname db 'dos.library',0
Priv	db 'PRIVATE',0
intname db 'intuition.library',0
noint   db 'Failed to open Intuition!',10,0
listps  db 'PSList... by C Bell',10,0
	even
dosbase dx.l 1
intbase dx.l 1
args
arg1	dx.l	1	
arg2	dx.l	1		
	
