summaryrefslogtreecommitdiff
path: root/Source
diff options
context:
space:
mode:
Diffstat (limited to 'Source')
-rw-r--r--Source/CloseIFF.S105
-rw-r--r--Source/OpenIFF.S218
2 files changed, 250 insertions, 73 deletions
diff --git a/Source/CloseIFF.S b/Source/CloseIFF.S
index b463eaa..3c85bd5 100644
--- a/Source/CloseIFF.S
+++ b/Source/CloseIFF.S
@@ -1,13 +1,13 @@
**
-** $Id: $
-** $Revision: $
+** $Id: CloseIFF.S,v 1.1 92/05/12 22:26:30 chris Exp $
+** $Revision: 1.1 $
**
** $Filename: CloseIFF.S $
-** $Author: Christian A. Weber $
+** $Author: chris $
** $Release: 19.1 $
-** $Date: 92/05/11 21:11:27 $
+** $Date: 92/05/12 22:26:30 $
**
-** iff.library/IFFLib_CloseIFF
+** iff.library/IFFL_CloseIFF
**
** COPYRIGHT (C) 1987-1992 BY CHRISTIAN A. WEBER, BRUGGERWEG 2,
** CH-8037 ZUERICH, SWITZERLAND. ALL RIGHTS RESERVED. NO PART
@@ -17,7 +17,7 @@
**
- IDNT IFFLib_CloseIFF
+ IDNT IFFL_CloseIFF
SECTION text,CODE
INCLUDE "IffLib.i"
@@ -26,42 +26,103 @@
XDEF CloseIFFFunc
-******* iff.library/IFFLib_CloseIFF *****************************************
+******* iff.library/IFFL_CloseIFF *******************************************
*
* NAME
-* IFFLib_CloseIFF -- Close an IFF-file and deallocate buffers
+* IFFL_CloseIFF -- Close an IFF file and deallocate buffers
*
* SYNOPSIS
-* IFFLib_CloseIFF( ifffile )
-* A1
+* IFFL_CloseIFF( iff )
+* A1
*
-* void IFFLib_CloseIFF( IFFFILE )
+* void IFFL_CloseIFF( IFFL_HANDLE )
*
* FUNCTION
-* Returns the memory previously allocated by OpenIFF().
+* Returns the memory previously allocated by IFFL_OpenIFF().
*
* INPUTS
-* ifffile - IFF file pointer, from OpenIFF()
+* iff - IFF file handle, from IFFL_OpenIFF()
*
* RESULTS
* For now, always results TRUE (this may change in the future).
*
* SEE ALSO
-* IFFLib_OpenIFF()
+* IFFL_OpenIFF()
*
*****************************************************************************
-CloseIFFFunc: movem.l a5-a6,-(SP)
- movea.l a6,a5 ; IFFBase für ClearError()
+CloseIFFFunc: movem.l d2-d3/a2/a5-a6,-(SP)
+ movea.l a6,a5 ; IFFBase für ClearError()
- move.l a1,d0 ; Ist a1 == NULL ?
- beq.s 1$ ; ja ---> don't free anything
- move.l -(a1),d0 ; Grösse des reservierten Bereichs
- movea.l ib_SysBase(a5),a6
+ move.l a1,d0 ; Ist a1 == NULL ?
+ beq.b .End ; ja ---> don't free anything
+
+ cmpi.l #IFFFH_MAGIC,ifffh_Magic(a1)
+ beq.b .WriteMode
+
+ *** Read-Modus
+
+ move.l -(a1),d0 ; Grösse des reservierten Bereichs
+ movea.l iffb_SysBase(a5),a6
+ JSRLIB FreeMem ; Bereich freigeben
+ bra.b .End ; ---> fertig
+
+ *** Write-Modus
+
+.WriteMode: movea.l a1,a2 ; A2 : IFF-Handle
+ movea.l iffb_DOSBase(a5),a6 ; A6 : DOSBase
+
+ move.l ifffh_File(a2),d1
+ beq.b .FileNotOpen ; File nicht offen --->
+
+ *** Pad-Word schreiben falls FORM-Länge nicht LONG-aligned ist
+
+ moveq.l #3,d0 ; LONG-Bitmaske
+ and.l ifffh_FormSize(a2),d0 ; Bits gesetzt ?
+ beq.b .NoPad ; noe --->
+ clr.l -(SP)
+ move.l SP,d2
+ moveq.l #2,d3 ; 1 WORD
+ JSRLIB Write
+ add.l d3,ifffh_FormSize(a2)
+.NoPad:
+
+ *** An Offset 4 (FORM-Längen-Eintrag) des Files seeken
+
+ move.l ifffh_File(a2),d1
+ moveq.l #4,d2
+ moveq.l #OFFSET_BEGINNING,d3
+ JSRLIB Seek
+ tst.l d0
+ bmi.b .SeekError
+
+ *** FORM-Länge updaten
+
+ move.l ifffh_File(a2),d1
+ lea ifffh_FormSize(a2),a0
+ move.l a0,d2
+ moveq.l #4,d3
+ JSRLIB Write
+.SeekError:
+
+ *** File schliessen
+
+ move.l ifffh_File(a2),d1
+ JSRLIB Close
+.FileNotOpen:
+
+ *** IFF-Handle freigeben
+
+ movea.l a2,a1 ; IFF-Handle
+ moveq.l #ifffh_SIZEOF,d0 ; Grösse
+ movea.l iffb_SysBase(a5),a6
JSRLIB FreeMem
-1$: bsr ClearError ; IFFError zurücksetzen, D0 := 1
- movem.l (SP)+,a5-a6
+ *** Routine beenden
+
+.End: bsr ClearError ; IFFError zurücksetzen, D0 := 1
+
+ movem.l (SP)+,d2-d3/a2/a5-a6
rts
END
diff --git a/Source/OpenIFF.S b/Source/OpenIFF.S
index 2b0d026..06ac715 100644
--- a/Source/OpenIFF.S
+++ b/Source/OpenIFF.S
@@ -1,13 +1,13 @@
**
-** $Id: $
-** $Revision: $
+** $Id: OpenIFF.S,v 1.1 92/05/12 22:26:43 chris Exp $
+** $Revision: 1.1 $
**
** $Filename: OpenIFF.S $
-** $Author: Christian A. Weber $
+** $Author: chris $
** $Release: 19.1 $
-** $Date: 92/05/11 21:11:27 $
+** $Date: 92/05/12 22:26:43 $
**
-** iff.library/IFFLib_OpenIFF
+** iff.library/IFFL_OpenIFF
**
** COPYRIGHT (C) 1987-1992 BY CHRISTIAN A. WEBER, BRUGGERWEG 2,
** CH-8037 ZUERICH, SWITZERLAND. ALL RIGHTS RESERVED. NO PART
@@ -17,25 +17,130 @@
**
- IDNT IFFLib_OpenIFF
+ IDNT IFFL_OpenIFF
SECTION text,CODE
INCLUDE "IFFLib.i"
XREF SetError,ClearError
- XDEF OpenIFFFunc,NewOpenIFFFunc
+ XDEF OpenIFFFunc,OldOpenIFFFunc,OldNewOpenIFFFunc
-******* iff.library/IFFLib_NewOpenIFF ***************************************
+******* iff.library/IFFL_OpenIFF ********************************************
*
* NAME
-* IFFLib_NewOpenIFF -- allocate memory for an IFF-file and read it
+* IFFL_OpenIFF -- Open an IFF file for reading or writing
*
* SYNOPSIS
-* ifffile = IFFLib_NewOpenIFF( filename, memattr )
-* D0 A0 D0
+* iff = IFFL_OpenIFF( filename, mode )
+* D0 A0 D0
*
-* IFFFILE IFFLib_OpenIFF( char * )
+* IFFL_HANDLE IFFL_OpenIFF( char *, ULONG )
+*
+* FUNCTION
+* If mode == IFFL_MODE_READ:
+* This function opens a file on a disk and looks whether it's an IFF
+* file or not. If it is an IFF file, memory is allocated and the file
+* is read into memory.
+* If an error occurs, NULL is returned, and you can call
+* dos.library/IoErr() to get the IFFERR_... error number.
+*
+* If mode == IFFL_MODE_WRITE:
+* Initializes an IFF file handle for writing. You may create chunks
+* with IFFL_PushChunk() and IFFL_PopChunk(), and you can write data
+* using the IFFL_WriteChunkBytes() routine.
+*
+* INPUTS
+* filename - Pointer to a null-terminated string
+* mode - IFFL_MODE_READ: Open file for reading
+* IFFL_MODE_WRITE: Open file for writing
+*
+* RESULT
+* iff - IFF handle. Making assumptions about the internal structure
+* of this handle is unwise, and may break in the future.
+* If this function fails, NULL will be returned, and you may
+* call IFFL_IFFError() to know the reason of the failure.
+*
+* SEE ALSO
+* IFFL_CloseIFF(), IFFL_PushChunk(), IFFL_PopChunk(),
+* IFFL_WriteChunkBytes(), IFFL_IFFError()
+*
+* BUGS
+* None known
+*
+*****************************************************************************
+
+OpenIFFFunc: movem.l d2-d6/a2/a5-a6,-(SP)
+ moveq.l #MEMF_ANY,d6 ; MemType: egal
+
+ tst.l d1 ; IFFL_MODE_READ ?
+ beq ReadMode
+
+*****************************************************************************
+* Schreib-Modus
+
+ movea.l a6,a5 ; A5 : IFFBase
+ move.l a0,d5 ; D5 : Filename
+
+ *** IFF-Handle allozieren
+
+ moveq.l #ifffh_SIZEOF,d0
+ moveq.l #1,d1
+ swap d1 ; MEMF_CLEAR
+ movea.l iffb_SysBase(a5),a6
+ JSRLIB AllocMem
+ tst.l d0
+ bne.b 1$
+ moveq.l #IFFL_ERROR_NOMEM,d0
+ bra.b .Error ; Error --->
+1$:
+ movea.l d0,a2 ; A2 : IFF-Handle
+
+ move.l #IFFFH_MAGIC,ifffh_Magic(a2)
+
+ *** File zum Schreiben öffnen
+
+ move.l d5,d1 ; Name
+ move.l #MODE_NEWFILE,d2
+ movea.l iffb_DOSBase(a5),a6
+ JSRLIB Open
+ move.l d0,ifffh_File(a2)
+ bne.b 2$
+ moveq.l #IFFL_ERROR_OPEN,d0
+.Error: bsr SetError
+ bra.b .End ; ---> Fertig
+2$:
+ *** Header ('FORM\0\0\0\0') schreiben
+
+ move.l d0,d1 ; File
+ lea IFFHeader(PC),a0
+ move.l a0,d2
+ moveq.l #8,d3
+ JSRLIB Write
+ cmp.l d3,d0
+ beq.b 3$
+ moveq.l #IFFL_ERROR_WRITE,d0
+ bra.b .Error
+3$:
+ *** Alles OK, IFF-Handle zurückgeben
+
+ bsr ClearError
+ move.l a2,d0 ; IFF-Handle
+.End: bra OpenEnd ; ---> Fertig
+
+
+******* iff.library/NewOpenIFF **********************************************
+*
+* NAME
+* NewOpenIFF -- allocate memory for an IFF-file and read it
+*
+* SYNOPSIS
+* >>> THIS FUNCTION IS OBSOLETE. USE IFFL_OpenIFF() INSTEAD <<<
+*
+* ifffile = NewOpenIFF( filename, memattr )
+* D0 A0 D0
+*
+* IFFFILE OpenIFF( char * )
*
* FUNCTION
* This function opens a file on a disk and looks whether it's an IFF
@@ -43,7 +148,7 @@
* is read into memory. The 'memattr' argument is taken to define the
* memory type. Normally memattr is set to MEMF_ANY or MEMF_PUBLIC.
* If an error occurs, NULL is returned, and you can call
-* IFFLib_IFFError() to get the error number.
+* IFFError() to get the error number.
*
* INPUTS
* filename - Pointer to a null-terminated string
@@ -53,41 +158,43 @@
*
* RESULT
* ifffile - 'FileHandle', points to the beginning of the IFF file
-* ("FORM...."), Zero if unsuccessful. Call IFFLib_IFFError() to get
+* ("FORM...."), Zero if unsuccessful. Call IFFError() to get
* the reason of the failure.
*
* SEE ALSO
-* IFFLib_OpenIFF(), IFFLib_CloseIFF(), IFFLib_IFFError()
+* OpenIFF(), CloseIFF(), IFFError()
*
* BUGS
* None known
*
*****************************************************************************
-OpenIFFFunc: movem.l d2-d6/a2/a5-a6,-(SP)
- moveq.l #-1,d6 ; Kein MemType angegeben
- bra.s DoCont
-
+OldNewOpenIFFFunc:
+ movem.l d2-d6/a2/a5-a6,-(SP)
+ move.l d0,d6 ; D6 : MemType
+ bra.b ReadMode
-******* iff.library/IFFLib_OpenIFF ******************************************
+******* iff.library/OpenIFF *************************************************
*
* NAME
-* IFFLib_OpenIFF -- allocate memory for an IFF-file and read it
+* OpenIFF -- allocate memory for an IFF-file and read it
*
* SYNOPSIS
-* ifffile = IFFLib_OpenIFF( filename )
-* D0 A0
+* >>> THIS FUNCTION IS OBSOLETE. USE IFFL_OpenIFF() INSTEAD <<<
*
-* IFFFILE IFFLib_OpenIFF( char * )
+* ifffile = OpenIFF( filename )
+* D0 A0
+*
+* IFFFILE OpenIFF( char * )
*
* FUNCTION
-* This function does the same as the IFFLib_NewOpenIFF() routine
+* This function does the same as the NewOpenIFF() routine
* above, except that you cannot specify the type of memory which is
* allocated for the file. Normally the type is 0 which means 'any
* memory', but if the IFF file type is '8SVX', the file is ALWAYS
* loaded into CHIP memory. If you wish to override these defaults,
-* use IFFLib_NewOpenIFF() instead of IFFLib_OpenIFF().
+* use NewOpenIFF() instead of OpenIFF().
*
* INPUTS
* filename - Pointer to a null-terminated string
@@ -101,13 +208,18 @@ OpenIFFFunc: movem.l d2-d6/a2/a5-a6,-(SP)
* None
*
* SEE ALSO
-* IFFLib_NewOpenIFF(), IFFLib_CloseIFF(), IFFLib_IFFError()
+* NewOpenIFF(), CloseIFF(), IFFError()
*
*****************************************************************************
-NewOpenIFFFunc: movem.l d2-d6/a2/a5-a6,-(SP)
- move.l d0,d6 ; D6 : MemType
-DoCont: movea.l a6,a5 ; IFFBase
+OldOpenIFFFunc: movem.l d2-d6/a2/a5-a6,-(SP)
+ moveq.l #-1,d6 ; Kein MemType angegeben
+;; bra.b ReadMode
+
+*****************************************************************************
+* Lese-Modus
+
+ReadMode: movea.l a6,a5 ; A5 : IFFBase
lea -12(SP),SP ; Arbeitsspeicher reservieren
moveq.l #0,d5 ; Fehlernummer rücksetzen
@@ -115,12 +227,12 @@ DoCont: movea.l a6,a5 ; IFFBase
move.l a0,d1 ; Name
move.l #MODE_OLDFILE,d2 ; accessmode
- movea.l ib_DOSBase(a5),a6
+ movea.l iffb_DOSBase(a5),a6
JSRLIB Open
move.l d0,d4 ; D4 := FileHandle
- bne.s 1$
- moveq #IFF_CANTOPENFILE,d5
- bra.s .Error2 ; --->
+ bne.b 1$
+ moveq #IFFL_ERROR_OPEN,d5
+ bra.b .Error2 ; --->
1$:
*** Erste 12 Bytes lesen, testen ob 'FORM'
@@ -129,17 +241,17 @@ DoCont: movea.l a6,a5 ; IFFBase
moveq.l #12,d3 ; Len
JSRLIB Read ; erste 3 Longwords lesen
cmpi.l #'FORM',(SP)
- beq.s 2$
- moveq #IFF_NOTIFF,d5
- bra.s .Error1 ; --->
+ beq.b 2$
+ moveq #IFFL_ERROR_NOTIFF,d5
+ bra.b .Error1 ; --->
2$:
*** Testen ob Chip-Speicher erwünscht (bei 8SVX-Files)
move.l d6,d1 ; Default-Requirements
- bpl.s 3$ ; sind gültig --->
+ bpl.b 3$ ; sind gültig --->
moveq.l #MEMF_PUBLIC,d1
cmpi.l #'8SVX',8(SP) ; 8SVX-File ?
- bne.s 3$ ; nein --->
+ bne.b 3$ ; nein --->
moveq.l #MEMF_CHIP|MEMF_PUBLIC,d1 ; sonst CHIP-Memory!
3$:
*** Speicher für File reservieren
@@ -149,13 +261,13 @@ DoCont: movea.l a6,a5 ; IFFBase
add.l d3,d2 ; D2 : Gesamtlänge
subq.l #4,d3 ; FUCK!!! IFF-Typ ist ja schon gelesen!
move.l d2,d0
- movea.l ib_SysBase(a5),a6
+ movea.l iffb_SysBase(a5),a6
JSRLIB AllocMem ; requirements von D1
movea.l d0,a2 ; A2 : IFFFile-Adresse
tst.l d0
- bne.s 4$ ; OK --->
- moveq #IFF_NOMEM,d5
- bra.s .Error1 ; --->
+ bne.b 4$ ; OK --->
+ moveq #IFFL_ERROR_NOMEM,d5
+ bra.b .Error1 ; --->
4$:
*** File einladen
@@ -164,30 +276,34 @@ DoCont: movea.l a6,a5 ; IFFBase
move.l a2,d2 ; Adr
addq.l #8,d2 ; FORM.... schon gelesen!
addq.l #4,d2 ; IFF-Typ schon gelesen
- movea.l ib_DOSBase(a5),a6
+ movea.l iffb_DOSBase(a5),a6
JSRLIB Read ; D3 war schon Länge
tst.l d0
- bpl.s 5$ ; OK --->
- moveq #IFF_READERROR,d5
- bra.s .Error1
+ bpl.b 5$ ; OK --->
+ moveq #IFFL_ERROR_READ,d5
+ bra.b .Error1
5$:
movem.l (SP),d0-d2 ; FORM, Länge und Type
movem.l d0-d2,(a2) ; IFF-Filetyp
.Error1: move.l d4,d1 ; File
- movea.l ib_DOSBase(a5),a6
+ movea.l iffb_DOSBase(a5),a6
JSRLIB Close
.Error2: move.l d5,d0 ; Error ?
- beq.s 6$ ; nein --->
+ beq.b 6$ ; nein --->
bsr SetError ; Löscht auch D0
- bra.s Ende
+ bra.b Ende
6$:
bsr ClearError
move.l a2,d0 ; Adresse als Return-Code
Ende:
lea 12(SP),SP ; Lokalen Speicher freigeben
- movem.l (SP)+,d2-d6/a2/a5-a6
+
+OpenEnd: movem.l (SP)+,d2-d6/a2/a5-a6
rts
+
+IFFHeader: dc.b "FORM",0,0,0,0
+
END