     NOLIST
DefineSections MACRO
*-------------------------------;    Start of DefineSections macro.
               NOLIST
               IFEQ NARG-1
               LIST
               IDNT "\1"
               NOLIST
               ENDC
               LIST
CodeStart:     SECTION   "",CODE             ; Relocatable code section
DataStart:     SECTION   DataSection,DATA    ; Initialized data section
BSS_Start:     SECTION   BSS_Section,BSS     ; Un-initialized data section
               SECTION   "",CODE             ; Relocatable code section
*-------------------------------;    End of DefineSections macro.
               ENDM

CallLib   MACRO
     NOLIST
     IFND _LVO\1
     LIST
        XREF _LVO\1
     NOLIST
     ENDC
     LIST
        MOVE.L \2.library.ptr,A6
        JSR _LVO\1(A6)
     ENDM

OpenLib   MACRO
*------------------------------; Start of OpenLib macro.
     NOLIST
                               ; Define _AbsExecBase and _LVOOpenLibrary if
     IFND _AbsExecBase         ;  they have not yet been defined.
     LIST
     XREF _AbsExecBase
     NOLIST
     ENDC
     IFND _LVOOpenLibrary
     LIST
     XREF _LVOOpenLibrary
     NOLIST
     ENDC
     LIST
     MOVE.L _AbsExecBase,A6    ; Do set-up for _LVOOpenLibrary.
     CLR.L D0
     MOVE.L #\1.str,A1
     SECTION DataSection,DATA  ; This is the <libname> ASCII string.
\1.str:
     DC.B '\1',0
     CNOP 0,2
     SECTION   "",CODE
     JSR _LVOOpenLibrary(A6)   ; Call OpenLibrary to open <libname>.
     MOVE.L D0,A6              ; Put the result in A6 and at <libname>.ptr.
     MOVE.L D0,\1.ptr
     SECTION   BSS_Section,BSS
     CNOP 0,2
\1.ptr:
     DS.L 1                    ; This is the location of <libname>.ptr.
     SECTION   "",CODE
     TST.L D0                  ; Make the zero flag indicate failure.
*------------------------------; End of OpenLib macro.
     ENDM

CloseLib       MACRO
*------------------------------; Start of CloseLib macro.
                               ; Put the library pointer in A1.
     MOVE.L \1.ptr,A1
     CallLib CloseLibrary,exec ; Call CloseLibrary.
*------------------------------; End of CloseLib macro.
     ENDM

     LIST
