;Amiga Byte numero 6, prog1.s ** apertura finestra intuition

;** Exec Offsets
ExecBase      EQU 4
CloseLibrary  EQU -$19E
OpenLibrary   EQU -$228

;** Intuition Offsets
CloseWindow   EQU -$48
OpenWindow    EQU -$cc

start:
    move.l  ExecBase,a6         ;a6 -> ExecBase
    lea     IntuiName,a1        ;a1 -> 'intuition.library'
    moveq   #0,d0               ;versione = 0
    jsr     OpenLibrary(A6)     ;apre Intuition
    move.l  d0,IntuiBase        ;d0 -> IntuitionBase
    beq     exit3               ;errore, esci

;apre la finestra
    move.l  IntuiBase,a6        ;puntatore a IntuitionBase
    lea     NuovaWindow,a0      ;puntatore a str. NewWindow 
    jsr     OpenWindow(a6)      ;apre la nuova finestra
    move.l  d0,MyWindow         ;e ne salva il puntatore
    beq     exit2               ;errore, esci

;ciclo di ritardo 
    move.l  #1000000,d0         ;contatore ciclo ritardo
ritardo:
    subi.l  #1,d0               ;decrementa contatore
    bne     ritardo             ;fino a zero

;termine del programma
exit1:
    move.l  MyWindow,a0         ;puntatore alla finestra
    jsr     CloseWindow(A6)     ;chiude la finestra
exit2:
    move.l  ExecBase,a6         ;puntatore ad ExecBase
    move.l  IntuiBase,a1        ;puntatore ad IntuitionBase
    jsr     CloseLibrary(A6)    ;chiude Intuition 
exit3:
    rts                         ;esci 
    

;dati del programma
IntuiBase:  DC.L  0
MyWindow:   DC.L  0

;struttura NewWindow NuovaWindow
NuovaWindow:  
    DC.W  20                    ;nw_LeftEdge
    DC.W  100                   ;nw_TopEdge
    DC.W  600                   ;nw_Width
    DC.W  156                   ;nw_Height
    DC.B  0                     ;nw_DetailPen
    DC.B  1                     ;nw_BlockPen
    DC.L  0                     ;nw_IDCMPFlags
    DC.L  $1000                 ;nw_Flags
    DC.L  0                     ;nw_FirstGadget
    DC.L  0                     ;nw_CheckMark
    DC.L  Titolo                ;nw_Title
    DC.L  0                     ;nw_Screen
    DC.L  0                     ;nw_Bitmap
    DC.W  0                     ;nw_MinWidth
    DC.W  0                     ;nw_MinHeight
    DC.W  0                     ;nw_MaxWidth
    DC.W  0                     ;nw_MaxHeight
    DC.W  1                     ;nw_Type

IntuiName:  DC.B  'intuition.library',0
Titolo:     DC.B  'MyWindow',0
