;*      Macro include file - copyright Mike Fuller 11-July-1991
;*      These are the macros required for the ColourWindow and CW-Example
;*      assembly programs on this disk.  Examples of their use are given
;*      under each macro.


Syslib  MACRO               ;execute a system library function
        IFEQ    NARG-2          ;if 2 arguments
        movea.l \2,a6           ;get relevant library base address
        ENDC
        jsr     _LVO\1(a6)      ;perform function
        ENDM

;*      eg. Syslib  OpenWindow                (opens a window)
;*      eg. Syslib  OpenLibrary,_AbsExecBase  (opens a library)


Push    MACRO
        movem.l  \1,-(sp)       ;save registers
        ENDM

Pop     MACRO
        movem.l  (sp)+,\1       ;restore registers
        ENDM

;*      eg. Push    d2-d5/a2      (save registers d2,d3,d4,d5,a2)


;*      Exec library function calls

Openlib MACRO                   ;open a system library
        moveq   #0,d0           ;any version
        movea.l \1,a1           ;null terminated pointer to library name
        Syslib  OpenLibrary,_AbsExecBase     ;open library
        move.l  d0,\2           ;save library base address
        ENDM

;*      eg. Openlib #Graphname,Graphbase    (open graphics library)


Closelib MACRO              ;close a system library
        movea.l \1,a1           ;library base address
        Syslib  CloseLibrary,_AbsExecBase    ;close library
        ENDM

;*      eg. Closelib Graphbase              (close graphics library)


;*      The following graphics macros should have the graphics library
;*      pointer (Graphbase) in register a6 prior to using them.
;*      It has been left out of the macros to speed up any multiple
;*      execution.


Pos     MACRO                   ;position pen or draw a line
        movea.l \1,a1               ;rastport pointer
        move.l  \2,d0               ;x position
        move.l  \3,d1               ;y position
        Syslib  \4                  ;move or draw line
        ENDM

;*      eg. Pos     Rport,#10,#20,Move      (position pen at 10,20)
;*      eg. Pos     Rport,#100,#20,Draw     (draw line to 100,20)


Drawbox MACRO                   ;draw a box from 4 coordinates
        Pos     \1,\2,\3,Move       ;top left position
        Pos     \1,\4,\3,Draw       ;draw to top right
        Pos     \1,\4,\5,Draw       ;draw to bottom right
        Pos     \1,\2,\5,Draw       ;draw to bottom left
        Pos     \1,\2,\3,Draw       ;draw to initial position
        ENDM

;*      eg. Drawbox Rport,#10,#60,#100,#80


Recfill MACRO                   ;draw a filled coloured rectangle
        Setpen  A,\1,\2             ;set pen colour
        movea.l \1,a1               ;rastport pointer
        move.w  \3,d0               ;x1 position
        move.w  \4,d1               ;y1 position
        move.w  \5,d2               ;x2 position
        move.w  \6,d3               ;y2 position
        Syslib  RectFill            ;draw rectangle
        ENDM

;*      eg. Recfill Rport,colour,#10,#10,#20,#15


Setpen  MACRO                   ;set the pen colour
        movea.l \2,a1               ;rastport pointer
        move.b  \3,d0               ;pen colour
        Syslib  Set\1Pen            ;set pen colour
        ENDM

;*      eg. Setpen  A,Rport,#5      (set foreground pen to colour 5)


SetRGB  MACRO                   ;change a colour
        moveq   #0,d0               ;clear register
        movea.l \1,a0               ;pointer to viewport
        move.b  \2,d0               ;colour number
        move.b  \3,d1               ;red value
        move.b  \4,d2               ;green value
        move.b  \5,d3               ;blue value
        Syslib  SetRGB4             ;set the colour
        ENDM

;*      eg. SetRGB  Vport,#0,#0,#0,#0   ;set background colour to black


Setpointer  MACRO               ;change the pointer
        movea.l \1,a0               ;pointer to Window structure
        lea     \2,a1               ;address of pointer data
        move.l  \3,d0               ;height of pointer
        move.l  \4,d1               ;width of pointer
        move.l  \5,d2               ;XOffset
        move.l  \6,d3               ;YOffset
        Syslib  SetPointer,Intbase   ;set the pointer
        ENDM

;*      eg. Setpointer window,pointdata,#16,#16,#-1,#-1


Wtext   MACRO                   ;write text in a window
        Pos     \1,\4,\5,Move       ;position pen
        movea.l \1,a1               ;rastport pointer
        lea     \2,a0               ;string pointer
        move.l  \3,d0               ;string length
        Syslib  Text                ;write text
        ENDM

;*      eg. Wtext   Rport,Stringbuf,#10,#120,#50    ;write 10 characters
;*                  from Stringbuf at position 120,50.
