home *** CD-ROM | disk | FTP | other *** search
/ Amiga MA Magazine 1998 #6 / amigamamagazinepolishissue1998.iso / coders / iffconverter / savepicture.a.bak < prev    next >
Text File  |  1997-01-07  |  17KB  |  710 lines

  1. **
  2. **     $VER: SavePicture.a V1.00 (06-12-95)
  3. **
  4. **     Author:  Gerben Venekamp
  5. **     Updates: 06-12-95  Versin 1.00     Initial Module
  6. **
  7. **  SavePicture.a save a screen buffer to a file. This can be done
  8. **  in a number of ways. Possible types of saving: Interleave, RAW
  9. **  Copper and Font8.
  10. **
  11.  
  12.         include    graphics/view.i
  13.         
  14.         
  15. ExtensionSize    equ    6    // Changes should be made to IFFConverter.h too
  16.  
  17.         
  18.         XDEF    _SaveInterleave
  19.         XDEF    _SaveRaw
  20.         XDEF    _SaveCopperAGA
  21.         XDEF    _SaveCopperECS
  22.         XDEF    _SaveCopper32bit
  23.         XDEF    _SaveCopper4bit
  24.         XDEF    _SaveFont8
  25.         
  26.         XREF    _DOSBase
  27.         XREF    _PicDepth
  28.         
  29.         include    exec/types.i
  30.         include    exec/strings.i
  31.         include    dos/dos.i
  32.         include    graphics/gfx.i
  33.  
  34.         include    dos_lib.i
  35.         
  36.         include    Gadgets_enum.i
  37.         
  38.  
  39.         STRUCTURE Save_Buffer_struct,0
  40.            APTR   Buffer
  41.            ULONG  BufferSize
  42.            ULONG  BufferLeft
  43.            BPTR   FileHeader
  44.  
  45.  
  46. * Macro for adding text to an ASCII file
  47.  
  48. AddText        MACRO
  49.         lea    (\1,PC),a5    Set start of text.
  50.         IFLT    (\2-1<<7)    See if text fits in a 'moveq'.
  51.         moveq    #\2,d7        Set text size.
  52.         ELSE            Text size needs to be a longword.
  53.         move.l    #\2,d7        Set text size.
  54.         ENDC
  55.         
  56.         jsr    WriteBuffer    Write text to a buffer.
  57.         ENDM
  58.         
  59. *--------------------------------------------------------------------
  60. *
  61. *  To call a library function use LIBCALL. If A6 is correct, just
  62. *  use LIBCALL with the functionname only. If A6 isn't correct,
  63. *  than use LIBCALL with the functionname AND the library offset.
  64. *
  65. *--------------------------------------------------------------------
  66.  
  67. LIBCALL        MACRO
  68.         IFGT    NARG-2        More Then Two Arguments?
  69.         FAIL            Too many Arguments!!!
  70.         ENDC
  71.         IFEQ    NARG-2        Two Arguments exactly.
  72.         move.l    (_\2),a6
  73.         ENDC
  74.         jsr    (_LVO\1,a6)
  75.         ENDM
  76.         
  77.  
  78. *-------------------------------------------------------------------------
  79. *
  80. *  SaveInterleave(BitMap, BitPlanePtrs, IFFClip, SaveBuffer)
  81. *                 A0      A1            A2       A3
  82. *
  83. *     Save a screen buffer to a file. If a 'SaveBuffer' exists, use it to
  84. *     store the data temporary. If it doesn't, save the screen buffer
  85. *     directly to 'SaveName'. 'SaveName' should be a valid name, because
  86. *     no checking is done to see if 'SaveName' exists or not.
  87. *
  88. *  pre:  A0 - Pointer to the BitMap structure of the screen to be saved.
  89. *        A1 - Pointer to an allocted block of memory. This will be filled
  90. *             with the appropiate pointer values to the bitmaps. The size
  91. *             of this block should be at least: bm_Depth × 4 bytes.
  92. *        A2 - Pointer to a structure containing all the necessary clipping
  93. *             values.
  94. *        A3 - Pointer to a buffer structure.
  95. *  post: None.
  96. *-------------------------------------------------------------------------
  97.  
  98. _SaveInterleave
  99.         SECTION    SaveInterleave,code
  100.  
  101.         movem.l    a4-5,-(SP)
  102.         
  103.         move.l    a1,a4
  104.         lea    (bm_Planes,a0),a5        Copy the bitplane pointers, because
  105.         move.w    (bm_Depth,a0),d0        we will touch them.
  106.         subq.w    #1,d0
  107. CopyBitplanePtr
  108.         move.l    (a5)+,(a4)+
  109.         dbf    d0,CopyBitplanePtr
  110.         
  111.         movem.l    (SP)+,a4-5
  112.         
  113.         rts
  114.  
  115.  
  116.         SECTION    SaveRaw,code
  117. _SaveRaw
  118.         movem.l    a4-5,-(SP)
  119.         
  120.         move.l    a1,a4
  121.         lea    (bm_Planes,a0),a5        Copy the bitplane pointers, because
  122.         move.w    (bm_Depth,a0),d0        we will touch them.
  123.         subq.w    #1,d0
  124. CpBitplanePtr
  125.         move.l    (a5)+,(a4)+
  126.         dbf    d0,CpBitplanePtr
  127.         
  128.         movem.l    (SP)+,a4-5
  129.  
  130.         rts
  131.  
  132.  
  133. *-------------------------------------------------------------------------
  134. *
  135. *  SaveCopper(ColourMap, SaveBuffer )
  136. *             A2         A3
  137. *
  138. *     Save a colourmap to a file. The name of the file can be found in
  139. *     'SaveBuffer'. Since there are currently two distingt chipsets,
  140. *     there are different ways to build a colourmap. One for the ECS and
  141. *     one for AGA. Secondly a colourmap colould be directly implemented
  142. *     as a CopperList, or just the colour data itself and the programmer
  143. *     takes care of the building the CopperList himself. Anyway, this
  144. *     leaves us with four possible way of saving a colourmap. We could
  145. *     ask the user to specify how to save the colourmap or take awy the
  146. *     burden and save them all at once. Since a colourmap does not take
  147. *     up much space, the later methos is prefered. This way, the user
  148. *     will always have the right colourmap.
  149. *     The four ways a colourmap is saved are:
  150. *        1 - AGA             extension will be .AGA
  151. *        2 - ECS             extension will be .ECS
  152. *        3 - 32 bit colours  extension will be .32bit
  153. *        4 -  4 bit colours  extension will be .4bit
  154. *
  155. *  pre:  A2 - Pointer to the ColourMap of the screen to be saved.
  156. *             The structure is the same as for 'LoadRGB32' colourmaps.
  157. *        A3 - Pointer to a buffer structure.
  158. *        A4 - SAS C Stack offset.
  159. *  post: None.
  160. *-------------------------------------------------------------------------
  161.         SECTION    SaveCopper
  162.         
  163. * Code can be found after data!
  164.  
  165.         
  166.         ENUM
  167.           EITEM    dctype_Word
  168.           EITEM    dctype_Long
  169.  
  170. AGAHeader    dc.b    '**',LF
  171.         dc.b    '**     $VER: AGA CopperList',LF
  172.         dc.b    '**',LF
  173.         dc.b    '**     Author: Gerben Venekamp',LF
  174.         dc.b    '**',LF
  175.         dc.b    '**  This is an AGA CopperList made with the IFFConverter.',LF
  176.         dc.b    '**  Just insert this at the appropiate place inside your',LF
  177.         dc.b    '**  Copper List.',LF
  178.         dc.b    '**',LF,LF
  179. ASCII_OrMask    dc.b    'BPLCON3OrMask'
  180. ASCII_OrMaskSize    equ    *-ASCII_OrMask
  181.         dc.b    '    equ    $'
  182. BPLCON3OrMask    dc.b    '0000'
  183.         dc.b    LF
  184. AGAHeaderSize    equ    *-AGAHeader
  185.         
  186. ECSHeader    dc.b    '**',LF
  187.         dc.b    '**     $VER: ECS CopperList',LF
  188.         dc.b    '**',LF
  189.         dc.b    '**     Author: Gerben Venekamp',LF
  190.         dc.b    '**',LF
  191.         dc.b    '**  This is an ECS CopperList made with the IFFConverter.',LF
  192.         dc.b    '**  Just insert this at the appropiate place inside your',LF
  193.         dc.b    '**  Copper List.',LF
  194.         dc.b    '**',LF
  195. ECSHeaderSize    equ    *-ECSHeader
  196.  
  197. bit32Header    dc.b    '**',LF
  198.         dc.b    '**     $VER: 32 bit Colour map',LF
  199.         dc.b    '**',LF
  200.         dc.b    '**     Author: Gerben Venekamp',LF
  201.         dc.b    '**',LF
  202.         dc.b    '**  This is an 32 bit colourmap made with the IFFConverter.',LF
  203.         dc.b    '**  See autodocs/graphics/LoadRGB32 for the structure explaination.',LF
  204.         dc.b    '**  You could pass it on to LoadRGB32.',LF
  205.         dc.b    '**',LF
  206. bit32HeaderSize    equ    *-bit32Header
  207.  
  208. bit4Header    dc.b    '**',LF
  209.         dc.b    '**     $VER: 4 bit Colour map',LF
  210.         dc.b    '**',LF
  211.         dc.b    '**     Author: Gerben Venekamp',LF
  212.         dc.b    '**',LF
  213.         dc.b    '**  This is an 4 bit colourmap made with the IFFConverter.',LF
  214.         dc.b    '**  Each word represents a total RGB colour. Each colour compentent',LF
  215.         dc.b    '**  is a 4 bit value.',LF
  216.         dc.b    '**',LF
  217. bit4HeaderSize    equ    *-bit4Header
  218.  
  219.  
  220. ASCII_TAB    dc.b    '    '
  221. TABSize        equ    *-ASCII_TAB
  222. ASCII_LF        dc.b    LF
  223. LFSize        equ    *-ASCII_LF
  224. Line_dcw        dc.b    'dc.w'
  225. Line_dcw_Length    equ    *-Line_dcw
  226. Line_dcl        dc.b    'dc.l'
  227. Line_dcl_Length    equ    *-Line_dcl
  228. ColourPart    dc.b    'color+'
  229. ColourPartLength    equ    *-ColourPart
  230. ColourOffset    dc.b    '00'
  231. ColourOffsetSize    equ    *-ColourOffset
  232. ColourValue    dc.b    '000'
  233. ColourValueSize    equ    *-ColourValue
  234. ColourBank    dc.b    'bplcon3,$'
  235. ColourBankSize    equ    *-ColourBank
  236. BPLCON3Value    dc.b    '0000'
  237. BPLCON3ValueSize    equ    *-BPLCON3Value
  238. ColourValue24    dc.b    '000000'
  239. ColourValue24Size    equ    *-ColourValue24
  240. Comma        dc.b    ','
  241. CommaLength    equ    *-Comma
  242. CommaStr        dc.b    ',$'
  243. CommaStrLength    equ    *-CommaStr
  244. ASCII_Str    dc.b    '$'
  245. ASCII_StrSize    equ    *-ASCII_Str
  246. ASCII_Or        dc.b    '|'
  247. ASCII_OrSize    equ    *-ASCII_Or
  248.         CNOP    0,2
  249.  
  250. ColourCount    dc.w    0
  251. BPLCON3Extra    dc.w    0
  252.  
  253. bplcon3_LOCTbit    equ    9
  254.  
  255. **
  256. **  Here's where the fun begins, pure code.
  257. **
  258. _SaveCopperAGA
  259.         movem.l    d2-3/d5-7/a5-6,-(SP)    Store affected non scratch registers
  260.         
  261.         clr.w    (BPLCON3Extra)
  262.         AddText    AGAHeader,AGAHeaderSize
  263.         move.l    a2,-(SP)
  264. DoLowNibles
  265.         move.l    (a2)+,d6
  266.         swap    d6
  267.         move.w    d6,(ColourCount)
  268.         subq.w    #1,d6
  269.         move.w    d6,d5            For Later use
  270.         lsr.w    #5,d6
  271.         bpl.s    MakeAGA
  272.         moveq    #0,d6
  273. MakeAGA
  274.         jsr    AddColourBank
  275.         and.w    #$1f,d5
  276. MakeAGA.1
  277.         move.w    #dctype_Word,d0
  278.         bsr    AddStartLine
  279.         
  280.         cmp.w    (_NumberOfItems1),d5
  281.         blt.s    CorrectItems
  282.         move.w    (_NumberOfItems1),d4
  283.         subq.w    #1,d4
  284.         bra.s    RightItems
  285. CorrectItems        
  286.         move.w    d5,d4
  287. RightItems
  288.         sub.w    d4,d5
  289. MakeAGA.2
  290.         lea    (ColourOffset,PC),a0
  291.         move.w    (ColourCount),d0
  292.         subq.w    #1,d0
  293.         sub.w    d5,d0
  294.         sub.w    d4,d0
  295.         add.w    d0,d0
  296.         and.w    #$3f,d0
  297.         moveq    #ColourOffsetSize,d1
  298.         jsr    MakeDecimal
  299.  
  300.         cmp.w    #1<<bplcon3_LOCTbit,(BPLCON3Extra)
  301.         bne.s    BPLCON3_LowNible
  302.         
  303.         move.l    (a2)+,d0            Get Red component
  304.         and.l    #$f0000000,d0
  305.         moveq    #20,d2
  306.         lsr.w    d2,d0            Make R
  307.         move.l    (a2)+,d1            Get Green component
  308.         and.l    #$f0000000,d1
  309.         moveq    #24,d2
  310.         lsr.w    d2,d1
  311.         or.w    d1,d0            Make RG
  312.         move.l    (a2)+,d1            Get Blue component
  313.         and.l    #$f0000000,d1
  314.         moveq    #28,d2
  315.         lsr.l    d2,d1
  316.         or.w    d1,d0            Make RGB
  317.         bra.s    GotColourComponent
  318.  
  319. BPLCON3_LowNible
  320. ;  If not High Nibke that it must be Low Nible
  321.         move.l    (a2)+,d0            Get Red component
  322.         and.l    #$0f000000,d0
  323.         swap    d0            Make R
  324.         move.l    (a2)+,d1            Get Green component
  325.         and.l    #$0f000000,d1
  326.         moveq    #20,d2
  327.         lsr.l    d2,d1
  328.         or.w    d1,d0            Make RG
  329.         move.l    (a2)+,d1            Get Blue component
  330.         and.l    #$0f000000,d1
  331.         moveq    #24,d2
  332.         lsr.l    d2,d1
  333.         or.w    d1,d0            Make RGB
  334.         
  335. GotColourComponent        
  336.         moveq    #ColourValueSize,d1
  337.         lea    (ColourValue,PC),a0
  338.         jsr    MakeHex
  339.         
  340.         AddText    ColourPart,ColourPartLength
  341.         AddText    ColourOffset,ColourOffsetSize
  342.         AddText    CommaStr,CommaStrLength
  343.         AddText    ColourValue,ColourValueSize
  344.         tst.w    d4
  345.         beq.s    AGASkipComma
  346.         AddText    Comma,CommaLength
  347. AGASkipComma
  348.         
  349.         dbf    d4,MakeAGA.2
  350.         
  351.         dbf    d5,MakeAGA.1
  352.         
  353.         dbf    d6,MakeAGA
  354.  
  355. **
  356. **  Okay, a very big NOTE here!!!
  357. **  This piece of code works fine, but *any* extentions might cause
  358. **  problems!!!! BE AWARE OF THIS THREAD!!!!
  359. **
  360. **  What happens is, you need to write the same copperlist twice!
  361. **  This is due to the fact that you write the high nible of each
  362. **  of your 24 bit colour components first, than the low nibles.
  363. **  So, $123456 will be $135 followd by $246.
  364. **  A special bit takes care of the nibles. So using this nible it's
  365. **  an easy test to check when to stop. Any changes could upset this
  366. **  easy rule.
  367. **
  368.         move.l    (SP),A2
  369.         tst.w    (BPLCON3Extra,PC)
  370.         bne.s    EndOfAGA
  371.         or.w    #1<<bplcon3_LOCTbit,(BPLCON3Extra)
  372.         bra    DoLowNibles    
  373. EndOfAGA        
  374.         jsr    FlushBuffer
  375.         
  376.         addq.l    #4,SP
  377.         movem.l    (SP)+,d2-3/d5-7/a5-6    Restore affected non scratch registers
  378.         rts
  379.  
  380.  
  381. _SaveCopperECS
  382.         movem.l    d2-3/d6-7/a5-6,-(SP)    Store affected non scratch registers
  383.  
  384.         AddText    ECSHeader,ECSHeaderSize
  385.         
  386.         jsr    FlushBuffer
  387.         
  388.         movem.l    (SP)+,d2-3/d6-7/a5-6    Restore affected non scratch registers
  389.         rts
  390.  
  391.  
  392.  
  393. _SaveCopper32bit
  394.         movem.l    d2-3/d6-7/a5-6,-(SP)    Store affected non scratch registers
  395.  
  396.         AddText    bit32Header,bit32HeaderSize
  397.         
  398.         moveq    #dctype_Word,d0
  399.         jsr    AddStartLine
  400.         
  401.         move.l    (a2)+,d5
  402.         lea    (BPLCON3Value,PC),a0
  403.         move.w    d5,d0
  404.         moveq    #4,d1
  405.         jsr    MakeHex
  406.         
  407.         AddText    ASCII_Str,ASCII_StrSize
  408.         AddText    BPLCON3Value,BPLCON3ValueSize
  409.         AddText    CommaStr,CommaStrLength
  410.         swap    d5
  411.         lea    (BPLCON3Value,PC),a0
  412.         move.w    d5,d0
  413.         moveq    #4,d1
  414.         jsr    MakeHex
  415.         AddText    BPLCON3Value,BPLCON3ValueSize
  416.         
  417.         move.w    d5,d6            Multiply by three
  418.         add.w    d6,d6            Multiply by three
  419.         add.w    d5,d6            Multiply by three
  420.         subq.w    #1,d6
  421. Make32bit
  422.         moveq    #dctype_Long,d0
  423.         jsr    AddStartLine
  424.         
  425.         cmp.w    (_NumberOfItems2),d6
  426.         blt.s    CorrectItems32bit
  427.         move.w    (_NumberOfItems2),d5
  428.         subq.w    #1,d5
  429.         bra.s    RightItems32bit
  430. CorrectItems32bit
  431.         move.w    d6,d5
  432. RightItems32bit
  433.         sub.w    d5,d6
  434. Make32bit.2        
  435.         move.l    (a2)+,d0
  436.         moveq    #6,d1
  437.         lea    (ColourValue24,PC),a0
  438.         jsr    MakeHex
  439.         
  440.         AddText    ASCII_Str,ASCII_StrSize
  441.         AddText    ColourValue24,ColourValue24Size
  442.         tst.w    d5
  443.         beq.s    bit32SkipComma
  444.         AddText    Comma,CommaLength
  445. bit32SkipComma
  446.         
  447.         dbf    d5,Make32bit.2
  448.         
  449.         dbf    d6,Make32bit
  450.         
  451.         jsr    FlushBuffer
  452.         
  453.         movem.l    (SP)+,d2-3/d6-7/a5-6    Restore affected non scratch registers
  454.         rts
  455.  
  456.  
  457. _SaveCopper4bit
  458.         movem.l    d2-3/d6-7/a5-6,-(SP)    Store affected non scratch registers
  459.  
  460.         AddText    bit4Header,bit4HeaderSize
  461.         
  462.         jsr    FlushBuffer
  463.         
  464.         movem.l    (SP)+,d2-3/d6-7/a5-6    Restore affected non scratch registers
  465.         rts
  466.  
  467.  
  468. *------------------------------------------------------------------------
  469. *
  470. *     AddColourBank
  471. *
  472. *------------------------------------------------------------------------
  473. AddColourBank
  474.         bsr    AddStartLine
  475.         AddText    ColourBank,ColourBankSize
  476.         move.w    (_PicDepth,a4),d0
  477.         subq.w    #1,d0
  478.         sub.w    d6,d0
  479.         ror.w    #3,d0
  480.         or.w    (BPLCON3Extra,PC),d0    Add Extra bits to BPLCON3
  481.         moveq    #BPLCON3ValueSize,d1
  482.         lea    (BPLCON3Value,PC),a0
  483.         jsr    MakeHex
  484.         
  485.         AddText    BPLCON3Value,BPLCON3ValueSize
  486.         AddText    ASCII_Or,ASCII_OrSize
  487.         AddText    ASCII_OrMask,ASCII_OrMaskSize
  488.         
  489.         rts
  490.  
  491.  
  492. *------------------------------------------------------------------------
  493. *
  494. *     AddStartLine( SaveBuffer, DC_Type )
  495. *                   A3          D0
  496. *
  497. *  Adds the beginning of a line to a save buffer. The beginning of a
  498. *  line look like this: <TAB1>dc.w<TAB2>
  499. *
  500. *  pre:  _TAB1 - Number of tabs at the beginning of a line.
  501. *        _TAB2 - Number of tabs after the 'dc.w' statement.
  502. *        D0 - Type of dc statement. Accepted types are: dctype_long
  503. *                                                       dctype_word
  504. *        A3 - Pointer to a savebuffer structure.
  505. *  post: None.
  506. *
  507. *     Uneffected registers:
  508. *
  509. *------------------------------------------------------------------------
  510. AddStartLine
  511.         movem.l    d6/d0,-(SP)
  512.         
  513.         AddText    ASCII_LF,LFSize
  514.         move.w    (_TAB1),d6
  515.         jsr    AddTabs
  516.         move.l    (SP)+,d0
  517.         cmp.w    #dctype_Long,d0
  518.         beq.s    Make_dc_Long
  519.         AddText    Line_dcw,Line_dcw_Length
  520.         bra.s    AddSecondTAB
  521. Make_dc_Long
  522.         AddText    Line_dcl,Line_dcl_Length
  523. AddSecondTAB
  524.         move.w    (_TAB2),d6
  525.         jsr    AddTabs
  526.         
  527.         move.l    (SP)+,d6
  528.         rts
  529.         
  530. *------------------------------------------------------------------------
  531. *
  532. *     AddTabs( Tabs, SaveBuffer )
  533. *              D6    A3
  534. *
  535. *  Adds a series of tabs to SaveBuffer.
  536. *
  537. *  pre:  D6 - Number of tabs to add.
  538. *        A3 - Pointer to a buffer structure.
  539. *  post: None.
  540. *
  541. *------------------------------------------------------------------------
  542. AddTabs
  543.         subq.w    #1,d6
  544. WriteTabs
  545.         AddText    ASCII_TAB,TABSize
  546.         dbf    d6,WriteTabs
  547.         
  548.         rts
  549. **
  550. **  Variables.
  551. **        
  552.         SECTION    __MERGED,data
  553.         XDEF    _TAB1
  554.         XDEF    _TAB2
  555.         XDEF    _NumberOfItems1
  556.         XDEF    _NumberOfItems2
  557.         XDEF    _BPLCON3OrMask
  558.         
  559. _TAB1        dc.w    2        Default Value.
  560. _TAB2        dc.w    1        Same here.
  561. _NumberOfItems1    dc.w    4        Same here.
  562. _NumberOfItems2    dc.w    9        Same here.
  563. _BPLCON3OrMask    dc.l    BPLCON3OrMask
  564.  
  565.         SECTION    SaveFont8,code
  566. _SaveFont8
  567.         move.l    a4,-(SP)        Save SAS C Stack pointer.
  568.         
  569.         move.l    (SP)+,a4        Restore SAS C Stack pointer.
  570.         rts
  571.  
  572.  
  573. *------------------------------------------------------------------------
  574. *
  575. *  WriteBuffer( Buffer, Data, DataSize)
  576. *               A3      A5    D7
  577. *
  578. *     Writes 'Data' to a buffer. When buffer is full, the buffer will
  579. *     be flushed and the remaining data will be written to the buffer.
  580. *
  581. *  pre:  A3 - Pointer to a Buffer structure.
  582. *        A4 - SAS C Stack Pointer
  583. *        A5 - Pointer to the data to be written to 'Buffer'
  584. *        D7 - Size of the 'Data' buffer.
  585. *  post: None
  586. *
  587. *  Uneffected registers: A1-4, D4-6
  588. *
  589. *------------------------------------------------------------------------
  590.  
  591.         SECTION    WriteBuffer,code
  592. WriteBuffer
  593.         tst.l    d7
  594.         beq.s    DataEmpty
  595.         
  596.         move.l    (BufferLeft,a3),d1
  597.         cmp.l    d1,d7
  598.         bge.s    BufferOverflow
  599.         move.l    d7,d2
  600.         sub.l    d7,(BufferLeft,a3)
  601.         bra.s    CopyDataBuffer
  602. BufferOverflow
  603.         move.l    d1,d2
  604.         clr.l    (BufferLeft,a3)
  605. CopyDataBuffer
  606.         sub.l    d2,d7
  607.         move.l    (BufferSize,a3),d0
  608.         sub.l    d1,d0
  609.         move.l    (Buffer,a3),a0
  610.         add.l    d0,a0
  611. CopyDataBuffer.1
  612.         move.b    (a5)+,(a0)+
  613.         subq.l    #1,d2
  614.         bne.s    CopyDataBuffer.1
  615.         
  616.         tst.l    (BufferLeft,a3)
  617.         bne.s    WriteBuffer
  618.         
  619.         bsr.s    FlushBuffer
  620.         bra.s    WriteBuffer
  621. DataEmpty
  622.         rts
  623.  
  624. *------------------------------------------------------------------------
  625. *
  626. *  FlushBuffer( Buffer )
  627. *               A3
  628. *
  629. *     Flush the buffer. If buffer is empty, no flushing will occour.
  630. *
  631. *  pre:  A3 - Pointer to a buffer to be flushed
  632. *        A4 - SAS C Stack Pointer
  633. *  post: None.
  634. *
  635. *------------------------------------------------------------------------
  636.  
  637. FlushBuffer
  638.         move.l    (BufferSize,a3),d3
  639.         sub.l    (BufferLeft,a3),d3
  640.         beq.s    NothingInBuffer
  641.         
  642.         move.l    (FileHeader,a3),d1
  643.         move.l    (Buffer,a3),d2
  644.         move.l    (_DOSBase,a4),a6
  645.         jsr    (_LVOWrite,a6)
  646.         move.l    (BufferSize,a3),(BufferLeft,a3)
  647. NothingInBuffer
  648.         rts
  649.  
  650. *------------------------------------------------------------------------
  651. *
  652. *   MakeDecimal( Inter, Length, Buffer )
  653. *                D0.W   D1.W    A0.L
  654. *
  655. *     Converters an integer to a decimal representation in ASCII,
  656. *     leading zeroes are *not* removed
  657. *
  658. *  pre:  A0 - Pointer into which the converted integer will be stored.
  659. *        D0 - Integer to convert. Upper 16 bits are expected to be zero.
  660. *        D1 - Number of digits to be used.
  661. *  post: None.
  662. *
  663. *------------------------------------------------------------------------
  664.  
  665. MakeDecimal
  666.         subq.w    #1,d1
  667. Convert_dec
  668.         divu.w    #10,d0
  669.         swap    d0
  670.         add.b    #'0',d0
  671.         move.b    d0,(a0,d1)
  672.         clr.w    d0
  673.         swap    d0
  674.         dbf    d1,Convert_dec
  675.         
  676.         rts
  677.         
  678.  
  679. *------------------------------------------------------------------------
  680. *
  681. *   MakeHex( Inter, Length, Buffer )
  682. *            D0.L   D1.W    A0.L
  683. *
  684. *     Converters an integer to a hexadecimal representation in ASCII,
  685. *     leading zeroes are *not* removed
  686. *
  687. *  pre:  A0 - Pointer into which the converted integer will be stored.
  688. *        D0 - Integer to convert. Upper 16 bits are expected to be zero.
  689. *        D1 - Number of digits to be used.
  690. *  post: None.
  691. *
  692. *------------------------------------------------------------------------
  693.  
  694. MakeHex
  695.         subq.w    #1,d1
  696. Convert_hex
  697.         moveq    #0,d2
  698.         divu.l    #16,d2:d0
  699.         cmp.w    #10,d2
  700.         blt.s    NoAdjustment
  701.         addq.w    #7,d2
  702. NoAdjustment
  703.         add.b    #'0',d2
  704.         move.b    d2,(a0,d1)
  705.         dbf    d1,Convert_hex
  706.         
  707.         rts
  708.