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