home *** CD-ROM | disk | FTP | other *** search
/ Amiga ISO Collection / AmigaUtilCD1.iso / GFX / Converter / PHOGEN3.DMS / in.adf / DevDocs.lha / examples / noise / noise.asm < prev    next >
Encoding:
Assembly Source File  |  1995-03-30  |  10.4 KB  |  356 lines

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