
********* SYSTEM MACRO DEFINITIONS ***********

EvenPC MACRO                           ; used to align pc
   cnop      0,2
   ENDM

Call MACRO                             ; (routine)
   jsr       LVO_\1(a6)
   ENDM

Zero MACRO
   moveq.l   #0,\1
   ENDM

ZerA MACRO
   suba.l    \1,\1
   ENDM

PushReg MACRO
   movem.l   \1,-(SP)
   ENDM

PushAll MACRO
   PushReg   d0-d7/a0-a6
   ENDM

PullReg MACRO
   movem.l   (SP)+,\1
   ENDM

PullAll MACRO
   PullReg  d0-d7/a0-a6
   ENDM

LibCall MACRO                          ; (LIB, routine)
   move.l    \1,a6
   jsr       LVO_\2(a6)
   ENDM

SysCall MACRO                          ; (routine)
   LibCall   SYSBase,\1
   ENDM

DosCall MACRO                          ; (routine)
   LibCall   DOSBase,\1
   ENDM

GfxCall MACRO                          ; (routine [,^RastPort])
   IFNC      '\2', ''
   move.l    \2,a1
   ENDC
   LibCall   GFXBase,\1
   ENDM

IntCall MACRO                          ; (routine)
   LibCall   INTBase,\1
   ENDM

MathCall MACRO                         ; (routine)
   LibCall   MATHBase,\1
   ENDM

TransCall MACRO                        ; (routine)
   LibCall   TRANSBase,\1
   ENDM

IconCall MACRO                         ; (routine)
   LibCall   ICONBase,\1
   ENDM

BailOut MACRO                          ; (Error Code)   (D0)
   move.l    #\1,d0
   jmp       _Error
   ENDM

AllocPubMem MACRO                      ; (Size)
   move.l    \1,d0
   move.l    #MEMF_Public!MEMF_Clear,d1
   SysCall   AllocMem
   ENDM

AllocChipMem MACRO                      ; (Size)
   move.l    \1,d0
   move.l    #MEMF_Chip!MEMF_Clear,d1
   SysCall   AllocMem
   ENDM

FreeMem MACRO                           ; (Address, Size)
   move.l    \1,a1
   move.l    \2,d0
   SysCall   FreeMem
   ENDM

*********** DOS MACRO DEFINITIONS **************


DosRead MACRO                           ; (^FileHandle, ^Buff, Len)   (d1,d2,d3)
   move.l    \1,d1
   move.l    \2,d2
   move.l    \3,d3
   DosCall   Read
   ENDM

DosPrint MACRO                          ; (^FileHandle, ^Message, Len)   (d1,d2,d3)
   PushReg   d1-d3/a0-a1
   move.l    \1,d1
   move.l    \2,d2
   IFC       '\3',''
   bsr       _DosTextLen                ; if no length given, go get it!
   ENDC
   IFNC      '\3',''
   move.l    \3,d3
   ENDC
   DosCall   Write
   PullReg   d1-d3/a0-a1
   ENDM

   IFD DOS

_DosTextLen                             ; Calculates length of ASCIIZ string into d3
   move.l    d2,a0
1$
   tst.b     (a0)+
   bne.s     1$
   move.l    a0,d3
   sub.l     d2,d3
   subq.l    #1,d3
   rts

   ENDC

QPrint MACRO
   move.l    \1,QHandle
   bsr       _P
   ENDM


**********  INTUITION MACRO DEFINITIONS   ***************


RememberChipMem MACRO                   ; (^RememberKey, Size)   (a0,d0)
   lea       \1,a0
   moveq.l   #0,d0 
   move      \2,d0
   move.l    #MEMF_Clear!MEMF_Chip,d1
   IntCall   AllocRemember
   IFNC      '\3',''
   tst.l     d0
   beq       \3
   ENDC
   ENDM

RememberPubMem MACRO                    ; (^RememberKey, Size)   (a0,d0)
   lea       \1,a0
   moveq.l   #0,d0
   move      \2,d0
   move.l    #MEMF_Clear!MEMF_Public,d1
   IntCall   AllocRemember
   IFNC      '\3',''
   tst.l     d0
   beq       \3
   ENDC
   ENDM

