home *** CD-ROM | disk | FTP | other *** search
/ Amiga ISO Collection / AmigaUtilCD1.iso / GFX / Converter / DC-PGS21.DMS / in.adf / Extras / DevDocs.LHA / DeveloperDocs / examples / efx / balance.asm next >
Encoding:
Assembly Source File  |  1996-06-03  |  8.4 KB  |  313 lines

  1.     opt l+
  2.  
  3. VERSION  equ 1
  4. REVISION equ 1
  5.  
  6. LIBNAME    macro
  7.         dc.b    "Balance.efx"
  8.         endm
  9.  
  10. TODAY   macro
  11.         dc.b    "(15/5/96)"
  12.         endm
  13.  
  14. COPYRIGHT macro
  15.         dc.b    "Copyright © Almathera 1995-6. All Rights Reserved"
  16.         endm
  17.  
  18. ASTRING macro
  19.         LIBNAME
  20.         dc.b    " Version \<VERSION>.\<REVISION>.",10,10
  21.         COPYRIGHT
  22.         dc.b    10,10
  23.     dc.b    "Balance Effect. Written by Jolyon Ralph",0
  24.         endm
  25.  
  26.  
  27. *************************************************************************
  28. **                                                                     **
  29. ** End of user-editable stuff...                                       **
  30. **                                                                     **
  31. *************************************************************************
  32.  
  33.  
  34.  
  35. VSTRING macro
  36.         dc.b    "$VER "
  37.         LIBNAME
  38.         dc.b    " \<VERSION>.\<REVISION> "
  39.         TODAY
  40.         dc.b    10
  41.         COPYRIGHT
  42.         dc.b    0
  43.         endm
  44.  
  45.         SECTION    code
  46.  
  47.         machine mc68020
  48.  
  49.         incdir    "include:"
  50.         include "exec/funcdef.i"
  51.         include "exec/types.i"
  52.         INCLUDE "exec/initializers.i"
  53.         INCLUDE "exec/libraries.i"
  54.         INCLUDE "exec/lists.i"
  55.         include "exec/memory.i"
  56.         INCLUDE "exec/alerts.i"
  57.         INCLUDE "exec/resident.i"
  58.         INCLUDE "libraries/dos.i"
  59.         include "exec/exec_lib.i"
  60.     include "photogenics/pgs_lib.i"
  61.         include "photogenics/efxbase.i"
  62.     include "photogenics/gio.i"
  63.  
  64.         XDEF    InitTable
  65.         XDEF    Open
  66.         XDEF    Close
  67.         XDEF    Expunge
  68.         XDEF    Null
  69.         XDEF    LibName
  70.         XDEF    _main
  71.  
  72.         XREF    _EfxInfo
  73.         XREF    _EfxPreRender
  74.         XREF    _EfxRender
  75.         XREF    _EfxPrefs
  76.  
  77. _main:
  78. Start:
  79.     moveq    #-1,d0
  80.     rts
  81.  
  82. MYPRI   EQU   0
  83.  
  84. RomTag:
  85.              ;STRUCTURE RT,0
  86.      DC.W    RTC_MATCHWORD      ; UWORD RT_MATCHWORD
  87.      DC.L    RomTag             ; APTR  RT_MATCHTAG
  88.      DC.L    EndCode            ; APTR  RT_ENDSKIP
  89.      DC.B    RTF_AUTOINIT       ; UBYTE RT_FLAGS
  90.      DC.B    VERSION            ; UBYTE RT_VERSION
  91.      DC.B    NT_LIBRARY         ; UBYTE RT_TYPE
  92.      DC.B    MYPRI              ; BYTE  RT_PRI
  93.      DC.L    LibName            ; APTR  RT_NAME
  94.      DC.L    IDString           ; APTR  RT_IDSTRING
  95.      DC.L    InitTable          ; APTR  RT_INIT  table for InitResident()
  96.  
  97.    ; this is the name that the library will have
  98. LibName:   LIBNAME
  99.             dc.b 0
  100. IDString:  VSTRING
  101.  
  102.  
  103.    ; force alignment
  104.  
  105.     cnop    0,4
  106.  
  107.  
  108.    ; The romtag specified that we were "RTF_AUTOINIT".  This means that the RT_INIT
  109.    ; structure member points to one of these tables below.  If the AUTOINIT bit was not
  110.    ; set then RT_INIT would point to a routine to run.
  111.  
  112. InitTable:
  113.    DC.L   EfxBase_SIZEOF    ; size of library base data space
  114.    DC.L   funcTable         ; pointer to function initializers
  115.    DC.L   dataTable         ; pointer to data initializers
  116.    DC.L   initRoutine       ; routine to run
  117.  
  118.  
  119. funcTable:
  120.  
  121.    ;------ standard system routines
  122.    dc.l   Open
  123.    dc.l   Close
  124.    dc.l   Expunge
  125.    dc.l   Null
  126.  
  127.    ;------ my libraries definitions
  128.    dc.l   _EfxInfo
  129.    dc.l   _EfxPreRender
  130.    dc.l   _EfxRender
  131.    dc.l   _EfxPrefs
  132.    dc.l   _EfxAbout
  133.  
  134.    ;------ function table end marker
  135.    dc.l   -1
  136.  
  137.  
  138.    ; The data table initializes static data structures.  The format is specified in
  139.    ; exec/InitStruct routine's manual pages.  The INITBYTE/INITWORD/INITLONG routines are
  140.    ; in the file "exec/initializers.i".  The first argument is the offset from the library
  141.    ; base for this byte/word/long.  The second argument is the value to put in that cell.
  142.    ; The table is null terminated.
  143.    ; NOTE - LN_TYPE below is a correction - old example had LH_TYPE.
  144.  
  145. dataTable:
  146.         INITBYTE        LN_TYPE,NT_LIBRARY
  147.         INITLONG        LN_NAME,LibName
  148.         INITBYTE        LIB_FLAGS,LIBF_SUMUSED!LIBF_CHANGED
  149.         INITWORD        LIB_VERSION,VERSION
  150.         INITWORD        LIB_REVISION,REVISION
  151.         INITLONG        LIB_IDSTRING,IDString
  152.         DC.L   0
  153.  
  154.    ; This routine gets called after the library has been allocated.  The library pointer is
  155.    ; in D0.  The segment list is in A0.  If it returns non-zero then the library will be
  156.    ; linked into the library list.
  157.  
  158. initRoutine:
  159.  
  160.    ;------ get the library pointer into a convenient A register
  161.    move.l   a5,-(sp)
  162.    move.l   d0,a5
  163.  
  164.    ;------ save a pointer to exec
  165.    move.l   a6,efxb_SysLib(a5)
  166.  
  167.    ;------ save a pointer to our loaded code
  168.    move.l   a0,efxb_SegList(a5)
  169.  
  170.    ;------ now build the static data that we need
  171.    ;
  172.    ; put your initialization here...
  173.    ;
  174.  
  175.    move.l   a5,d0
  176.    move.l   (sp)+,a5
  177.    rts
  178.  
  179. ;------------------------------------------------------------------------------------------
  180. ; here begins the system interface commands.  When the user calls OpenLibrary/CloseLibrary/
  181. ; RemoveLibrary, this eventually gets translated into a call to the following routines
  182. ; (Open/Close/Expunge).  Exec has already put our library pointer in A6 for us.  Exec has
  183. ; turned off task switching while in these routines (via Forbid/Permit), so we should not
  184. ; take too long in them.
  185. ;------------------------------------------------------------------------------------------
  186.  
  187.    ; Open returns the library pointer in d0 if the open was successful.  If the open failed
  188.    ; then null is returned.  It might fail if we allocated memory on each open, or if only
  189.    ; open application could have the library open at a time...
  190.  
  191. Open:      ; ( libptr:a6, version:d0 )
  192.  
  193.    ;------ mark us as having another opener
  194.    addq.w   #1,LIB_OPENCNT(a6)
  195.  
  196.    ;------ prevent delayed expunges
  197.    bclr   #LIBB_DELEXP,efxb_Flags(a6)
  198.  
  199.    move.l   a6,d0
  200.    rts
  201.  
  202.    ; There are two different things that might be returned from the Close routine.  If the
  203.    ; library is no longer open and there is a delayed expunge then Close should return the
  204.    ; segment list (as given to Init).  Otherwise close should return NULL.
  205.  
  206. Close:      ; ( libptr:a6 )
  207.  
  208.    ;------ set the return value
  209.    moveq    #0,d0
  210.  
  211.    ;------ mark us as having one fewer openers
  212.    subq.w   #1,LIB_OPENCNT(a6)
  213.  
  214.    ;------ see if there is anyone left with us open
  215.    bne.s   1$
  216.  
  217.    ;------ see if we have a delayed expunge pending
  218.    btst   #LIBB_DELEXP,efxb_Flags(a6)
  219.    beq.s   1$
  220.  
  221.    ;------ do the expunge
  222.    bsr   Expunge
  223. 1$:
  224.    rts
  225.  
  226.    ; There are two different things that might be returned from the Expunge routine.  If
  227.    ; the library is no longer open then Expunge should return the segment list (as given
  228.    ; to Init).  Otherwise Expunge should set the delayed expunge flag and return NULL.
  229.    ;
  230.    ; One other important note: because Expunge is called from the memory allocator, it may
  231.    ; NEVER Wait() or otherwise take long time to complete.
  232.  
  233. Expunge:   ; ( libptr: a6 )
  234.  
  235.    movem.l   d2/a5/a6,-(sp)
  236.    move.l   a6,a5
  237.    move.l   efxb_SysLib(a5),a6
  238.  
  239.    ;------ see if anyone has us open
  240.    tst.w   LIB_OPENCNT(a5)
  241.    beq   1$
  242.  
  243.    ;------ it is still open.  set the delayed expunge flag
  244.    bset   #LIBB_DELEXP,efxb_Flags(a5)
  245.    moveq    #0,d0
  246.    bra.s   Expunge_End
  247.  
  248. 1$:
  249.    ;------ go ahead and get rid of us.  Store our seglist in d2
  250.    move.l   efxb_SegList(a5),d2
  251.  
  252.    ;------ unlink from library list
  253.    move.l   a5,a1
  254.    jsr        _LVORemove(a6)
  255.  
  256.    ;------ free our memory
  257.    moveq    #0,d0
  258.    move.l   a5,a1
  259.    move.w   LIB_NEGSIZE(a5),d0
  260.  
  261.    sub.l   d0,a1
  262.    add.w   LIB_POSSIZE(a5),d0
  263.  
  264.     jsr        _LVOFreeMem(a6)
  265.  
  266.    ;------ set up our return value
  267.    move.l   d2,d0
  268.  
  269. Expunge_End:
  270.    movem.l   (sp)+,d2/a5/a6
  271.    rts
  272.  
  273. Null:
  274.    moveq    #0,d0
  275.    rts
  276. EndCode:
  277.  
  278.  
  279. wintitle:
  280.         dc.b "About "
  281.         LIBNAME
  282.         dc.b    0
  283.  
  284. textmsg:
  285.         ASTRING
  286.         dc.b    0
  287. button:
  288.         dc.b "Ok",0
  289.  
  290.     cnop     0,4
  291.  
  292. *******************************************************************
  293. *******************************************************************
  294. *******************************************************************
  295. ***                                                             ***
  296. *** Main code functions for library follow here...              ***
  297. ***                                                             ***
  298. *******************************************************************
  299. *******************************************************************
  300. *******************************************************************
  301.  
  302.  
  303. _EfxAbout
  304.         movem.l  a6/a2,-(sp)
  305.         move.l  gio_PgsBase(a0),a6
  306.         lea     wintitle(pc),a0
  307.         lea     textmsg(pc),a1
  308.         lea     button(pc),a2
  309.         jsr     _LVOOneButtonReq(a6)
  310.         movem.l  (sp)+,a6/a2
  311.         rts
  312.  
  313.