; Description:  Example of how to open a PUBSCREEN
; Type:         Intuition

NoCli

MyFont$="topaz.font"
MyFontSize=8

;Fill the TextAttr structure
MyFontAttr.TextAttr\ta_Name = &MyFont$,MyFontSize,0,0

;Needed to get the palette right!
;it sets what colour is used for what
Dim scr0_pens.w(21)
scr0_pens(0)=-1
scr0_pens(1)=0
scr0_pens(2)=0
scr0_pens(3)=0
scr0_pens(4)=0
scr0_pens(5)=0
scr0_pens(6)=0
scr0_pens(7)=0
scr0_pens(8)=0
scr0_pens(9)=0

a$="Test Screen"

mysig.l=AllocSignal_(-1)
If mysig=0
  mysig=-1
EndIf

Dim scr0_tags.TagItem (9)
scr0_tags(0)\ti_Tag=#SA_Depth,2
scr0_tags(1)\ti_Tag=#SA_Pens,&scr0_pens(0)
scr0_tags(2)\ti_Tag=#SA_DetailPen,0
scr0_tags(3)\ti_Tag=#SA_BlockPen,1
scr0_tags(4)\ti_Tag=#SA_DisplayID,$8000    ; $a9004 DBLPalHiresNoFlicker
scr0_tags(5)\ti_Tag=#SA_Font,MyFontAttr
scr0_tags(6)\ti_Tag=#SA_PubName,&a$
scr0_tags(7)\ti_Tag=#SA_Title,&a$
scr0_tags(8)\ti_Tag=#SA_PubSig,mysig
scr0_tags(9)\ti_Tag=#SA_PubTask,0

;Open the screen...
*myscreen.Screen=OpenScreenTagList_(0,&scr0_tags(0)\ti_Tag)
;
;*myscreen will be 0 if the screen could not be
;opened. NO CHECKING YET!!!!
;All the code below relies on the fact hat
;screen COULD be opened.

;Give the screen a number
;
;if the screen did not open, the debugger (LES)
;will throw up an error.
FindScreen 0,a$

;Activate the pubscreen to the system
PubScreenStatus_ *myscreen,0
SetDefaultPubScreen_ &a$

;Open a test window on the screen
Window 0,10,15,400,87,$0000100E,"Work Window",1,0

;Bring up an AmigaGuide File of the users choice
MaxLen fi$=162
MaxLen pa$=162
testfile$=ASLFileRequest$("Select A Nice Guide File...",pa$,fi$,"#?.guide")

;Notice I don't give the PUBSCREEN option
;to AmigaGuide, this is because our screen
;is the default PUBSCREEN. In real life
;you would add "PUBSCREEN BUG.1" to the
;end of the command line.

b$="run >nil: <nil: amigaguide "+testfile$
p.l=Execute_(&b$,0,0)

;Wait until all windows are shut down,
;ALL windows must be closed before
;I can shut down the screen
Repeat
  VWait
  ev.l=Event
  ew.l=EventWindow

  ;has my window been closed?
  If ev=$200 AND ew=0
    CloseWindow 0
  EndIf

  ;Are there any windows out there?
  If *myscreen.Screen\FirstWindow=0
    exitr=True
  EndIf
Until exitr=True

;Free my screen from Blitz and the system
;BOTH COMMANDS REQUIRED!!!!
;
;MAKE SURE ALL WINDOWS ARE SHUT!!!!!!!!!
;The main loop does this...
SetDefaultPubScreen_ 0

CloseScreen 0
CloseScreen_ *myscreen

;Free My Nice Signal
;If you don't do this
;you WILL get a guru
;
;I found out the hard way!
If mysig>0
  FreeSignal_(mysig)
EndIf

; BYE BYE (bang!) extract from WORMS
End

