From b4425496e443c1d95593a4b1cd22e0c84a114ed0 Mon Sep 17 00:00:00 2001 From: "Christian A. Weber" Date: Fri, 15 May 1992 03:24:13 +0000 Subject: Initial revision --- Source/PopChunk.S | 128 +++++++++++++++++++++++++++++++++++++++++++++++ Source/PushChunk.S | 121 ++++++++++++++++++++++++++++++++++++++++++++ Source/WriteChunkBytes.S | 93 ++++++++++++++++++++++++++++++++++ 3 files changed, 342 insertions(+) create mode 100644 Source/PopChunk.S create mode 100644 Source/PushChunk.S create mode 100644 Source/WriteChunkBytes.S (limited to 'Source') diff --git a/Source/PopChunk.S b/Source/PopChunk.S new file mode 100644 index 0000000..ae0d001 --- /dev/null +++ b/Source/PopChunk.S @@ -0,0 +1,128 @@ +** +** $Id: $ +** $Revision: $ +** +** $Filename: PopChunk.S $ +** $Author: Christian A. Weber $ +** $Release: 21.1 $ +** $Date: 92/05/14 22:26:34 $ +** +** iff.library/IFFL_PopChunk +** +** COPYRIGHT (C) 1987-1992 BY CHRISTIAN A. WEBER, BRUGGERWEG 2, +** CH-8037 ZUERICH, SWITZERLAND. ALL RIGHTS RESERVED. NO PART +** OF THIS SOFTWARE MAY BE COPIED, REPRODUCED, OR TRANSMITTED +** IN ANY FORM OR BY ANY MEANS, WITHOUT THE PRIOR WRITTEN PER- +** MISSION OF THE AUTHOR. USE AT YOUR OWN RISK. +** + + + IDNT IFFL_PopChunk + SECTION text,CODE + + INCLUDE "IffLib.i" + + XREF SetError,ClearError + XDEF PopChunkFunc + + +******* iff.library/IFFL_PopChunk ******************************************* +* +* NAME +* IFFL_PopChunk -- Pop top context node off context stack. +* +* SYNOPSIS +* success = IFFL_PopChunk( iff ) +* D0 A0 +* +* BOOL IFFL_PopChunk( IFFL_HANDLE ) +* +* FUNCTION +* Pops top context chunk and updates the file accordingly. +* The function is normally called only for writing files and signals +* the end of a chunk. +* +* INPUTS +* iff - IFF handle +* +* RESULTS +* Non-zero if successful or 0 if not successful (call IFFL_IFFError() +* to get an IFFL_ERROR_... error code. +* +* SEE ALSO +* IFFL_PushChunk(), IFFL_WriteChunkBytes() +* +***************************************************************************** + +PopChunkFunc: movem.l d2-d3/a2/a5-a6,-(SP) + movea.l a6,a5 ; IFFBase für ClearError() + movea.l a0,a2 ; A2 : IFF-Handle + movea.l iffb_DOSBase(a5),a6 ; A6 : DOSBase + + *** Pad-Byte schreiben falls Chunk-Länge ungerade ist + + btst.b #0,ifffh_ChunkSize+3(a2) + beq.b .NoOddChunkSize + + move.l ifffh_File(a2),d1 + move.l a2,d2 ; Hier hat's ein 0 Byte + moveq.l #1,d3 ; Länge: 1 Byte + JSRLIB Write + cmp.l d3,d0 + bne.b .WriteError + add.l d3,ifffh_ChunkSize(a2) +.NoOddChunkSize: + + *** FORM-Grösse += Chunk-Grösse + + moveq.l #8,d0 ; Chunkheadersize + add.l ifffh_ChunkSize(a2),d0 ; plus Chunksize + add.l d0,ifffh_FormSize(a2) ; zur Form-Size dazu + + *** An den Anfang des Chunks seeken + + move.l ifffh_File(a2),d1 + moveq.l #4,d2 ; Grössen-Eintrag im Chunk-Header + add.l ifffh_ChunkFPos(a2),d2 ; Plus Chunk-Anfang + moveq.l #OFFSET_BEGINNING,d3 + JSRLIB Seek + tst.l d0 + bmi.b .SeekError + + *** Richtige Chunk-Grösse eintragen + + move.l ifffh_File(a2),d1 + lea ifffh_ChunkSize(a2),a0 + move.l a0,d2 + moveq.l #4,d3 ; 1 Langwort + JSRLIB Write ; schreiben + cmp.l d3,d0 + beq.b .WriteError + + *** An das Ende des Chunks seeken + + move.l ifffh_File(a2),d1 + moveq.l #0,d2 + moveq.l #OFFSET_END,d3 + JSRLIB Seek + tst.l d0 + bmi.b .SeekError + + *** Okay + + bsr ClearError ; Setzt auch D0 auf TRUE + bra.b .End + + *** Schreibfehler oder Seekfehler + +.SeekError: +.WriteError: moveq.l #IFFL_ERROR_WRITE,d0 + bsr SetError ; Setzt auch D0 auf FALSE + + *** Routine beenden + +.End: movem.l (SP)+,d2-d3/a2/a5-a6 + rts + + + END diff --git a/Source/PushChunk.S b/Source/PushChunk.S new file mode 100644 index 0000000..b021340 --- /dev/null +++ b/Source/PushChunk.S @@ -0,0 +1,121 @@ +** +** $Id: $ +** $Revision: $ +** +** $Filename: PushChunk.S $ +** $Author: Christian A. Weber $ +** $Release: 21.1 $ +** $Date: 92/05/14 22:26:34 $ +** +** iff.library/IFFL_PushChunk +** +** COPYRIGHT (C) 1987-1992 BY CHRISTIAN A. WEBER, BRUGGERWEG 2, +** CH-8037 ZUERICH, SWITZERLAND. ALL RIGHTS RESERVED. NO PART +** OF THIS SOFTWARE MAY BE COPIED, REPRODUCED, OR TRANSMITTED +** IN ANY FORM OR BY ANY MEANS, WITHOUT THE PRIOR WRITTEN PER- +** MISSION OF THE AUTHOR. USE AT YOUR OWN RISK. +** + + + IDNT IFFL_PushChunk + SECTION text,CODE + + INCLUDE "IffLib.i" + + XREF SetError,ClearError + XDEF PushChunkFunc + + +******* iff.library/IFFL_PushChunk ****************************************** +* +* NAME +* IFFL_PushChunk -- Push a new context node on the context stack. +* +* SYNOPSIS +* success = IFFL_PushChunk( iff, type, id ) +* D0 A0 D0 D1 +* +* BOOL IFFL_PushChunk( IFFL_HANDLE, ULONG, ULONG ) +* +* FUNCTION +* Pushes a new context node on the context stack by reading it from the +* stream if this is a read file, or by creating it from the passed +* parameters if this is a write file. Normally this function is only +* called in write mode, where the type and id codes specify the new +* chunk to create. If this is a leaf chunk, i.e. a local chunk inside +* a FORM or PROP chunk, then the type argument is ignored. +* +* INPUTS +* iff - IFF handle +* type - chunk type specifier (ex. ILBM) (ignored for read mode or +* leaf chunks). +* id - chunk id specifier (ex. CMAP) (ignored for read mode). +* +* RESULTS +* Non-zero if successful or 0 if not successful (call IFFL_IFFError() +* to get an IFFL_ERROR_... error code. +* +* SEE ALSO +* IFFL_PopChunk(), IFFL_WriteChunkBytes() +* +***************************************************************************** + +PushChunkFunc: movem.l d0-d3/a2/a5-a6,-(SP) + movea.l a6,a5 ; IFFBase für ClearError() + movea.l a0,a2 ; A2 : IFF-Handle + movea.l iffb_DOSBase(a5),a6 ; A6 : DOSBase + + *** File-Type schreiben falls dies der erste Chunk ist + + tst.l ifffh_FormSize(a2) ; 1. Chunk ? + bne.b .NotFirstChunk ; nee ---> + + move.l ifffh_File(a2),d1 ; Filehandle + move.l SP,d2 ; Type aufm Stack + moveq.l #4,d3 ; Länge: 1 Langwort + JSRLIB Write + cmp.l d3,d0 ; OK geschrieben ? + bne.b .WriteError + add.l d3,ifffh_FormSize(a2) ; FORM-Grösse anpassen +.NotFirstChunk: + + *** Chunk im IFF-Handle initialisieren + + clr.l ifffh_ChunkSize(a2) ; Chunk-Grösse resstten + + move.l ifffh_File(a2),d1 + moveq.l #0,d2 ; Aktuelle Position + moveq.l #OFFSET_CURRENT,d3 + JSRLIB Seek + move.l d0,ifffh_ChunkFPos(a2) ; Chunk-Position eintragen + bmi.b .SeekError ; Error ---> + + *** ID und provisorische Länge schreiben + + move.l ifffh_File(a2),d1 + lea 4(SP),a0 + move.l a0,d2 ; ID und 1 LONG garbage + moveq.l #8,d3 ; ID und provisorische Länge + JSRLIB Write + cmp.l d3,d0 ; OK geschrieben ? + bne.b .WriteError + + *** Okay + + bsr ClearError ; Setzt auch D0 auf TRUE + bra.b .End + + *** Schreibfehler oder Seekfehler + +.SeekError: +.WriteError: moveq.l #IFFL_ERROR_WRITE,d0 + bsr SetError ; Setzt auch D0 auf FALSE + + *** Routine beenden + +.End: move.l d0,(SP) ; D0 in Stack (--> wieder D0) + movem.l (SP)+,d0-d3/a2/a5-a6 + rts + + + END diff --git a/Source/WriteChunkBytes.S b/Source/WriteChunkBytes.S new file mode 100644 index 0000000..68f1b44 --- /dev/null +++ b/Source/WriteChunkBytes.S @@ -0,0 +1,93 @@ +** +** $Id: $ +** $Revision: $ +** +** $Filename: WriteChunkBytes.S $ +** $Author: Christian A. Weber $ +** $Release: 21.1 $ +** $Date: 92/05/14 22:26:34 $ +** +** iff.library/IFFL_WriteChunkBytes +** +** COPYRIGHT (C) 1987-1992 BY CHRISTIAN A. WEBER, BRUGGERWEG 2, +** CH-8037 ZUERICH, SWITZERLAND. ALL RIGHTS RESERVED. NO PART +** OF THIS SOFTWARE MAY BE COPIED, REPRODUCED, OR TRANSMITTED +** IN ANY FORM OR BY ANY MEANS, WITHOUT THE PRIOR WRITTEN PER- +** MISSION OF THE AUTHOR. USE AT YOUR OWN RISK. +** + + + IDNT IFFL_WriteChunkBytes + SECTION text,CODE + + INCLUDE "IffLib.i" + + XREF SetError,ClearError + XDEF WriteChunkBytesFunc + + +******* iff.library/IFFL_WriteChunkBytes ************************************ +* +* NAME +* IFFL_WriteChunkBytes -- Write data into the current chunk +* +* SYNOPSIS +* success = IFFL_WriteChunkBytes( iff, buf, size ) +* D0 A0 A1 D0 +* +* LONG IFFL_WriteChunkBytes( IFFL_HANDLE, APTR, LONG ) +* +* FUNCTION +* Writes "size" bytes from the specified buffer into the current chunk. +* +* INPUTS +* iff - IFF file handle, from IFFL_OpenIFF(). +* buf - pointer to buffer area with bytes to be written. +* size - number of bytes to write. +* +* RESULT +* number of bytes written if successful or NULL if an error +* occurred. Call IFFL_IFFError() to know what's going on. +* +* SEE ALSO +* IFFL_PushChunk(), IFFL_PopChunk(), IFFL_IFFError() +* +***************************************************************************** + +WriteChunkBytesFunc: + movem.l d2-d3/a2/a5-a6,-(SP) + movea.l a6,a5 ; IFFBase für ClearError() + movea.l a0,a2 ; A2 : IFF-Handle + movea.l iffb_DOSBase(a5),a6 ; A6 : DOSBase + + *** Daten in Chunk schreiben (Seek-Position ist schon richtig) + + move.l ifffh_File(a2),d1 + move.l a1,d2 ; Adresse + move.l d0,d3 ; Länge + JSRLIB Write + cmp.l d3,d0 + bne.b .WriteError + + *** Chunk-Grösse updaten + + add.l d3,ifffh_ChunkSize(a2) + + *** Okay + + bsr ClearError ; Setzt auch D0 auf TRUE + bra.b .End + + *** Schreibfehler oder Seekfehler + +.SeekError: +.WriteError: moveq.l #IFFL_ERROR_WRITE,d0 + bsr SetError ; Setzt auch D0 auf FALSE + + *** Routine beenden + +.End: movem.l (SP)+,d2-d3/a2/a5-a6 + rts + + + END -- cgit v1.2.3