;
; DefaultScreen is Copyright © 1994-1995 by Stefano Reksten of 3AM.
; It was made just to learn how to use the ReadArgs() function and the
; LINK/UNLK instructions (these make the program 100 bytes smaller! :-)
;
; This program changes the default public screen and can set the
; SHANGHAI and POPPUBSCREEN flags, if passed the correct arguments.
; I know there are other utilities like (my) PSM to manage public screens,
; but not as small as this one!
;
; Many thanks to Benjamin Hutchings, who debugged this program.
; I hope to have corrected the bugs :-)
;
; To contact me:
;
; rekststef@unisi.it
;
; Stefano Reksten c/o Naimi
; v.le Cavour, 40
; 53100 SIENA - Italy
;
	incdir	"include:"
	include "LVO3.0/exec_lib.i"
	include "LVO3.0/dos_lib.i"
	include "LVO3.0/intuition_lib.i"

SHANGHAI	equ	$0001
POPPUBSCREEN	equ	$0002

DOSBase		equ	0
IntuiBase	equ	4
ArgsPtr		equ	8
Args		equ	12
ScrName		equ	12
SFLG		equ	16
PFLG		equ	20
ScrPtr		equ	24

	link	a5,#-28
	move.l	4,a6
	lea	IntuiName(PC),a1
	move.l	#37,d0
	jsr	_LVOOpenLibrary(a6)
	tst.l	d0
	beq.w	.intuiexit
	move.l	d0,IntuiBase(SP)

	lea	DOSName(PC),a1
	move.l	#37,d0
	jsr	_LVOOpenLibrary(a6)
	tst.l	d0
	beq.w	.dosexit
	move.l	d0,DOSBase(SP)

	move.l	#0,ScrName(SP)
	move.l	#0,SFLG(SP)
	move.l	#0,PFLG(SP)
	move.l	d0,a6
	move.l	#Template,d1
	move.l	SP,d2
	add.l	#Args,d2
	moveq	#0,d3
	jsr	_LVOReadArgs(a6)
	tst.l	d0
	beq.b	.noscrname

	move.l	d0,ArgsPtr(SP)

	move.l	ScrName(SP),d0
	move.l	IntuiBase(SP),a6
	move.l	d0,a0
	jsr	_LVOLockPubScreen(a6)

	tst.l	d0
	beq.b	.nopublic
	move.l	d0,ScrPtr(SP)

	move.l	ScrName(SP),a0
	jsr	_LVOSetDefaultPubScreen(a6)

	moveq	#0,d0
	tst.l	SFLG(SP)
	beq.b	.noshanghai
	or	#SHANGHAI,d0
.noshanghai
	tst.l	PFLG(SP)
	beq.b	.nopopup
	or	#POPPUBSCREEN,d0
.nopopup
	jsr	_LVOSetPubScreenModes(a6)

	move.l	#0,a0
	move.l	ScrPtr(a2),a1
	jsr	_LVOUnlockPubScreen(a6)
	
	bra.b	.freeargs

.nopublic
	move.l	DOSBase(SP),a6
	move.l	#ErrNoPublic,d1
	move.l	SP,d2
	add.l	#Args,d2
	jsr	_LVOVPrintf(a6)
	bra.b	.freeargs
	
.noscrname
	move.l	#ErrNoName,d1
	jsr	_LVOVPrintf(a6)
	bra	.closeDOS
.freeargs
	move.l	DOSBase(SP),a6
	move.l	ArgsPtr(SP),d1
	jsr	_LVOFreeArgs(a6)
.closeDOS
	move.l	4,a6
	move.l	DOSBase(SP),a1
	jsr	_LVOCloseLibrary(a6)
.dosexit
	move.l	IntuiBase(SP),a1
	jsr	_LVOCloseLibrary(a6)
.intuiexit
	unlk	a5
	rts

DOSName
	dc.b	'dos.library',0
IntuiName
	dc.b	'intuition.library',0
Template
	dc.b	'ScreenName/A,S=Shanghai/S,P=PopScreen/S',0
	dc.b	'$VER: DefaultScreen v1.1 (3.5.95)',0
ErrNoName
	dc.b	'No public screen name given',$A,0
ErrNoPublic
	dc.b	'%s is not a public screen',$A,0
