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

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