* Simple Assembly language example. Eats away a little ram
* from WorkBench use, should probably link with some startup
* code to handle the WBenchMsg coming to the task.

   option nl
   INCLUDE "intuition/intuition.i"
   
   option l
   XREF _AbsExecBase
   
   XREF _LVOOpenLibrary
   XREF _LVOCloseLibrary
   XREF _LVOOpenScreen
   XREF _LVOCloseScreen
   XREF _LVOWaitPort
   XREF _LVOOpenWindow
   XREF _LVOCloseWindow
   XREF _LVOExit

   lea 	    DosName,a1		; Need this only to call Exit()
   clr.l    d0
   movea.l  _AbsExecBase,a6
   jsr      _LVOOpenLibrary(a6)		; Ought to make things secure,
   tst.l    d0
   beq      exit
   move.l   d0,DosBase

   lea 	    IntuitionName,a1
   clr.l    d0
   movea.l  _AbsExecBase,a6
   jsr      _LVOOpenLibrary(a6)		; Ought to make things secure,
   tst.l    d0
   beq      exit

   move.l   d0,IntuiBase
   move.l   d0,a6		; Need pointer right away
   lea      MyNewScreen,a0
   jsr      _LVOOpenScreen(a6)		; No error checking done
   tst.l    d0
   beq      3$

   move.l   d0,MyScreen
   move.l   d0,NewWindowScreen
   movea.l  IntuiBase,a6
   lea      MyNewWindow,a0
   jsr      _LVOOpenWindow(a6)		; Still no error checking
   tst.l    d0
   beq      2$

   move.l   d0,MyWindow
   move.l   d0,a0
   move.l   wd_UserPort(a0),a0
   movea.l  _AbsExecBase,a6
   jsr      _LVOWaitPort(a6)		; Wait for close gadget
   
   movea.l  IntuiBase,a6
   movea.l  MyWindow,a0
   jsr      _LVOCloseWindow(a6)
2$:
   movea.l  IntuiBase,a6
   movea.l  MyScreen,a0
   jsr      _LVOCloseScreen(a6)
3$:
   movea.l  _AbsExecBase,a6
   move.l   IntuiBase,a1
   jsr      _LVOCloseLibrary(a6)
exit:
   clr.l    d1			; Return code for CLI
   movea.l  DosBase,a6
   jsr 	    _LVOExit(a6)	; Clean exit from WB also

* Data section

**************** Screen data

MyScreen:
   dc.l 0

MyNewScreen:  dc.w 0,0,320,256   ;size filled in later
              dc.w 4      ;depth
              dc.b 0,1
              dc.w 0      ;viewmodes
              dc.w CUSTOMSCREEN
              dc.l 0
              dc.l ScreenTitle
              dc.l 0,0

**************** Window data

MyWindow:
   dc.l 0

MyFlags       EQU SMART_REFRESH!ACTIVATE!WINDOWDEPTH!WINDOWDRAG!WINDOWCLOSE
MyNewWindow:  dc.w 0,30,250,100
              dc.b 2,5
              dc.l CLOSEWINDOW	; IDCMP Flags
              dc.l MyFlags
              dc.l 0,0
              dc.l WindowTitle
NewWindowScreen: dc.l 0		; Screen to be filled in later
              dc.l 0		; Pointer to bitmap
              dc.w 0,0,0,0
              dc.w CUSTOMSCREEN

ScreenTitle:
   dc.b 'Assembly Language Screen!',0
WindowTitle:
   dc.b 'Assembly Language is fun!',0
IntuitionName:
   dc.b 'intuition.library',0
IntuiBase:
   dc.l 0
DosName:
   dc.b 'dos.library',0
DosBase:
   dc.l 0
