
 ;WINDOWS AND SCREENS
 ;ASSEMBLER SCOURCE CODE

 INCLUDE  "exec/types.i"    ;these files are needed to interpret 
 INCLUDE  "exec/exec.i"     ;the intuition structures


 XREF  _AbsExecBase        ;routines from exec library
 XREF  _LVOOpenLibrary
 XREF  _LVOCloseLibrary
 XREF  _LVOWait

 XREF  _LVOOpenWindow      ;routines from intuition library
 XREF  _LVOCloseWindow
 XREF  _LVOOpenScreen
 XREF  _LVOCloseScreen
 XREF  _LVOSetWindowTitles
 XREF  _LVOMoveWindow
 XREF  _LVOModifyIDCMP

     CSECT text,code       ;this directive is used by the Lattice Assembler

main:
 lea      IntuitionName,a1    ;open the intuition library
 clr.l    d0
 move.l   _AbsExecBase,a6
 jsr      _LVOOpenLibrary(a6)
 movem.l  d0,intuitionbase    ;and store the pointer
 beq      abort               ;exit if the library does not open

 lea      TheNewScreen,a0     ;pointer to new screen information
 move.l   intuitionbase,a6
 jsr      _LVOOpenScreen(a6)  ;open a custom screen
 movem.l  d0,customscreen     ;and store the pointer
 beq      abort               ;exit if the screen does not open

 lea      TheNewWindow,a0     ;pointer to new window information
 move.l   d0,nw_Screen(a0)    ;attach the window to the custom screen
 jsr      _LVOOpenWindow(a6)  ;open the window
 move.l   d0,thiswindow       ;and store the pointer
 beq      abort               ;exit if the window does not open

 lea      TheNewWindow,a0     ;use the same information
 move.b   #3,nw_BlockPen(a0)  ;change it slightly
 jsr      _LVOOpenWindow(a6)  ;and open a second window
 move.l   d0,thatwindow
 beq      abort
 move.l   thatwindow,a0       ;change the windowtitle
 lea      screentitle,a2
 lea      thatwindowtitle,a1
 jsr      _LVOSetWindowTitles(a6)
 move.l   thatwindow,a0       ;change the IDCMP flags so that the window
 clr.l    d0                  ;does not close when the close gadget is clicked
 jsr      _LVOModifyIDCMP(a6)

 move.l   #50,d6
window2loop:                  ;slowly move thatwindow down
 move.l   thatwindow,a0
 move.l   #0,d0
 move.l   #1,d1
 jsr      _LVOMoveWindow(a6)
 dbra     d6,window2loop

 lea      TheNewWindow,a0     ;use the new window information
 move.b   #1,nw_DetailPen(a0) ;change it slightly
 jsr      _LVOOpenWindow(a6)  ;and open a third window
 move.l   d0,otherwindow
 beq      abort

 move.l   otherwindow,a0      ;set its title
 lea      screentitle,a2
 lea      otherwindowtitle,a1
 jsr      _LVOSetWindowTitles(a6)
 move.l   otherwindow,a0
 clr.l    d0
 jsr      _LVOModifyIDCMP(a6) ;and deactivate the close gadget

 move.l   #50,d6
window3loop:                  ;slowly move otherwindow down and across
 move.l   otherwindow,a0
 move.l   #2,d1
 move.l   #1,d0
 jsr      _LVOMoveWindow(a6)
 dbra     d6,window3loop

 move.l   thiswindow,a0
 move.l   wd_UserPort(a0),a0  ;find the first windows user port address
 move.b   MP_SIGBIT(a0),d1    ;find the bit number of its signal
 move.l   #1,d0               ;calculate the signal value
 lsl.l    d1,d0
 move.l   _AbsExecBase,a6
 jsr      _LVOWait(a6)        ;and wait until the signal occurs

 move.l   intuitionbase,a6
 move.l   thiswindow,a0       ;close the windows
 jsr      _LVOCloseWindow(a6)
 move.l   thatwindow,a0
 jsr      _LVOCloseWindow(a6)
 move.l   otherwindow,a0
 jsr      _LVOCloseWindow(a6)
 move.l   customscreen,a0     ;close the screen
 jsr      _LVOCloseScreen(a6)
 move.l   _AbsExecBase,a6
 move.l   intuitionbase,a1
 jsr      _LVOCloseLibrary(a6)
abort:
 clr.l    d0
 rts

; --- IDCMP flag used         ;flags  and structures used by program
CLOSEWINDOW equ   $00000200   ;see include/intuition/intuition.i file
;-----Window flags used       ;for full notes
WINDOWSIZING   equ $0001
WINDOWDRAG     equ $0002
WINDOWDEPTH    equ $0004
WINDOWCLOSE    equ $0008
SIZEBRIGHT     equ $0010
;-----Screen flag used
CUSTOMSCREEN   equ   $000F

 STRUCTURE Window,0
    APTR wd_NextWindow
    WORD wd_LeftEdge
    WORD wd_TopEdge
    WORD wd_Width
    WORD wd_Height
    WORD wd_MouseY
    WORD wd_MouseX
    WORD wd_MinWidth
    WORD wd_MinHeight
    WORD wd_MaxWidth
    WORD wd_MaxHeight
    LONG wd_Flags
    APTR wd_MenuStrip
    APTR wd_Title
    APTR wd_FirstRequest
    APTR wd_DMRequest
    WORD wd_ReqCount
    APTR wd_WScreen
    APTR wd_RPort
    BYTE wd_BorderLeft
    BYTE wd_BorderTop
    BYTE wd_BorderRight
    BYTE wd_BorderBottom
    APTR wd_BorderRPort
    APTR wd_FirstGadget
    APTR wd_Parent
    APTR wd_Descendant
    APTR wd_Pointer
    BYTE wd_PtrHeight
    BYTE wd_PtrWidth
    BYTE wd_XOffset
    BYTE wd_YOffset
    ULONG wd_IDCMPFlags
    APTR wd_UserPort
    APTR wd_WindowPort
    APTR wd_MessageKey
    BYTE wd_DetailPen
    BYTE wd_BlockPen
    APTR wd_CheckMark
    APTR wd_ScreenTitle
    SHORT wd_GZZMouseX
    SHORT wd_GZZMouseY
    SHORT wd_GZZWidth
    SHORT wd_GZZHeight
    APTR wd_ExtData
    APTR wd_UserData
    APTR wd_WLayer
    LABEL wd_Size

 STRUCTURE NewWindow,0
    WORD nw_LeftEdge
    WORD nw_TopEdge
    WORD nw_Width
    WORD nw_Height
    BYTE nw_DetailPen
    BYTE nw_BlockPen
    ULONG nw_IDCMPFlags
    LONG nw_Flags
    APTR nw_FirstGadget
    APTR nw_CheckMark
    APTR nw_Title
    APTR nw_Screen
    APTR nw_BitMap
    WORD nw_MinWidth
    WORD nw_MinHeight
    WORD nw_MaxWidth
    WORD nw_MaxHeight
    WORD nw_Type
    LABEL nw_SIZE

    CSECT data
IntuitionName:                  ;library name
 dc.b 'intuition.library',0
 dc.w  0
thiswindowtitle:                ;window title text
 dc.b 'this window',0
 dc.w  0
thatwindowtitle:
 dc.b 'that window',0
 dc.w  0
otherwindowtitle:
 dc.b 'other window',0
 dc.w  0
screentitle:                    ;screen title text
 dc.b   'custom screen',0
 dc.w   0
TheNewScreen:                   ;NewScreen structure- see intuition.i
 dc.w 0                         ;LeftEdge
 dc.w 0                         ;TopEdge
 dc.w 320                       ;Width
 dc.w 200                       ;Height
 dc.w 3                         ;Depth
 dc.b 1                         ;DetailPen
 dc.b 3                         ;BlockPen
 dc.w 0                         ;special display modes
 dc.w CUSTOMSCREEN              ;screen type
 dc.l 0                         ;pointer to custom font structure
 dc.l screentitle               ;pointer to screen title
 dc.l 0                         ;pointer to screen gadgets
 dc.l 0                         ;pointer to custom bitmap

TheNewWindow:                   ;NewWindow structure for this window
 dc.w 20
 dc.w 20
 dc.w 150
 dc.w 50
 dc.b 0
 dc.b 1
 dc.l CLOSEWINDOW
 dc.l WINDOWSIZING+WINDOWDRAG+WINDOWDEPTH+WINDOWCLOSE+SIZEBRIGHT
 dc.l 0
 dc.l 0
 dc.l thiswindowtitle
 dc.l 0
 dc.l 0
 dc.w 64
 dc.w 20
 dc.w 300
 dc.w 200
 dc.w CUSTOMSCREEN

 SECTION mem,BSS
intuitionbase:            ;intuition library pointer
 ds.l 1
thiswindow:               ;pointers to Window structures
 ds.l 1
thatwindow:
 ds.l 1
otherwindow:
 ds.l 1
customscreen:             ;pointer to Screen structure
 ds.l 1
 END

