diff options
-rw-r--r-- | Source/OpenIFF.S | 151 |
1 files changed, 109 insertions, 42 deletions
diff --git a/Source/OpenIFF.S b/Source/OpenIFF.S index 1fbb470..a6256f6 100644 --- a/Source/OpenIFF.S +++ b/Source/OpenIFF.S @@ -1,11 +1,11 @@ ** -** $Id: OpenIFF.S,v 21.3 92/05/17 04:40:45 chris Exp $ -** $Revision: 21.3 $ +** $Id: OpenIFF.S,v 22.1 92/05/26 18:00:52 chris Exp $ +** $Revision: 22.1 $ ** ** $Filename: OpenIFF.S $ ** $Author: chris $ ** $Release: 19.1 $ -** $Date: 92/05/17 04:40:45 $ +** $Date: 92/05/26 18:00:52 $ ** ** iff.library/IFFL_OpenIFF ** @@ -16,12 +16,20 @@ ** MISSION OF THE AUTHOR. USE AT YOUR OWN RISK. ** +DEBUG_DETAIL SET 0 + +XPK IDNT IFFL_OpenIFF SECTION text,CODE INCLUDE "IFFLib.i" + IFD XPK + INCLUDE "INCUSR:libraries/xpk.i" +XPK_MARGIN EQU 256 + ENDC + XREF SetError,ClearError XDEF OpenIFFFunc,OldOpenIFFFunc,OldNewOpenIFFFunc @@ -73,11 +81,11 @@ * ***************************************************************************** -OpenIFFFunc: movem.l d2-d6/a2/a5-a6,-(SP) +OpenIFFFunc: movem.l d2-d6/a2/a4-a6,-(SP) moveq.l #MEMF_ANY,d6 ; MemType: egal tst.l d0 ; IFFL_MODE_READ ? - beq ReadMode + beq.b ReadMode ***************************************************************************** * Schreib-Modus @@ -166,7 +174,7 @@ OpenIFFFunc: movem.l d2-d6/a2/a5-a6,-(SP) ***************************************************************************** OldNewOpenIFFFunc: - movem.l d2-d6/a2/a5-a6,-(SP) + movem.l d2-d6/a2/a4-a6,-(SP) move.l d0,d6 ; D6 : MemType bra.b ReadMode @@ -201,7 +209,7 @@ OldNewOpenIFFFunc: * ***************************************************************************** -OldOpenIFFFunc: movem.l d2-d6/a2/a5-a6,-(SP) +OldOpenIFFFunc: movem.l d2-d6/a2/a4-a6,-(SP) moveq.l #-1,d6 ; Kein MemType angegeben ;; bra.b ReadMode @@ -211,6 +219,9 @@ OldOpenIFFFunc: movem.l d2-d6/a2/a5-a6,-(SP) ReadMode: movea.l a6,a5 ; A5 : IFFBase lea -12(SP),SP ; Arbeitsspeicher reservieren moveq.l #0,d5 ; Fehlernummer rücksetzen + IFD XPK + suba.l a4,a4 ; XpkBase + ENDC *** File öffnen @@ -221,17 +232,30 @@ ReadMode: movea.l a6,a5 ; A5 : IFFBase move.l d0,d4 ; D4 := FileHandle bne.b 1$ moveq #IFFL_ERROR_OPEN,d5 - bra.b .Error2 ; ---> + bra .Error2 ; ---> 1$: - *** Erste 12 Bytes lesen, testen ob 'FORM' + *** Erste 12 Bytes lesen und wieder an den Anfang seeken move.l d4,d1 ; File move.l SP,d2 ; Adr moveq.l #12,d3 ; Len JSRLIB Read ; erste 3 Longwords lesen + cmp.l d3,d0 + bne .ReadError + + move.l d4,d1 ; File + moveq #0,d2 ; Position + moveq #OFFSET_BEGINNING,d3 + JSRLIB Seek ; Zurück an den Fileanfang + + moveq.l #12,d3 ; Remember-Size + 'FORM....' + + *** testen ob 'FORM' steht im ersten LONG + cmpi.l #'FORM',(SP) beq.b .IsIFF + IFD XPK *** Es ist kein IFF. Testen ob's ein xpk-gepacktes IFF ist. lea XpkName(PC),a1 @@ -239,27 +263,38 @@ ReadMode: movea.l a6,a5 ; A5 : IFFBase JSRLIB OldOpenLibrary tst.l d0 ; xpk.library geöffnet ? beq.b .NotIFF ; nope ---> + movea.l d0,a4 ; A4 : XpkBase + + PRINTF 10,<"Opened xpk.library"> - movea.l d0,a6 ; XpkBase lea -xf_SIZEOF(SP),SP ; Platz für FIB movea.l SP,a0 ; fib für XpkExamine() clr.l -(SP) ; TAG_DONE move.l d4,-(SP) ; Filehandle pea XPK_InFH ; TagItem movea.l SP,a1 ; Tags - JSRLIB XpkExamine + movea.l a4,a6 ; XpkBase + jsr _LVOXpkExamine(a6) + movem.l xf_Head+3*4(SP),d1-d3 ; Die 3 ersten LONGs + lea xf_SIZEOF+3*4(SP),SP ; Stack aufräumen + movem.l d1-d3,(SP) ; Die 3 ersten LONGs tst.l d0 - bne.b .XpkNotIFF ; Error ---> + bne.b .NotIFF ; XPKExamine() Error ---> - cmpi.l #'FORM',3*4+xf_Head(SP) - bne.b .XpkNotIFF + PRINTF 10,<"Examine successful"> -.XpkNotIFF: - moveq #IFFL_ERROR_NOTIFF,d5 - bra.b .XpkError -.XpkError: - lea xf_SIZEOF+3*4(SP),SP + move.l d4,d1 ; File + moveq #0,d2 ; Position + moveq #OFFSET_BEGINNING,d3 + movea.l iffb_DOSBase(a5),a6 + JSRLIB Seek ; Zurück an den Fileanfang + + moveq.l #(XPK_MARGIN+12)/4,d3 ; Remember-Size + 'FORM....' + lsl.l #2,d3 ; Spart 2 Bytes :) + cmpi.l #'FORM',(SP) ; Ist's jetzt ein IFF ? + beq.b .IsIFF ; yup!! + ENDC .NotIFF: moveq #IFFL_ERROR_NOTIFF,d5 bra.b .Error1 ; ---> @@ -275,11 +310,8 @@ ReadMode: movea.l a6,a5 ; A5 : IFFBase 3$: *** Speicher für File reservieren - moveq.l #12,d2 ; 'Remember' + FORM.... - move.l 4(SP),d3 ; D3 : FORM-Länge - add.l d3,d2 ; D2 : Gesamtlänge - subq.l #4,d3 ; FUCK!!! IFF-Typ ist ja schon gelesen! - move.l d2,d0 + add.l 4(SP),d3 ; D3 : Länge total + move.l d3,d0 movea.l iffb_SysBase(a5),a6 JSRLIB AllocMem ; requirements von D1 movea.l d0,a2 ; A2 : IFFFile-Adresse @@ -287,42 +319,77 @@ ReadMode: movea.l a6,a5 ; A5 : IFFBase bne.b 4$ ; OK ---> moveq #IFFL_ERROR_NOMEM,d5 bra.b .Error1 ; ---> -4$: - *** File einladen +4$: move.l d3,(a2)+ ; Länge eintragen (Remember) + subq.l #4,d3 ; Remember-Size wieder wegzählen + + *** Je nachdem XPK-gepacktes File laden + IFD XPK + move.l a4,d0 ; XpkBase + beq.b .NoXpkRead ; Kein Xpk-File ---> + + clr.l -(SP) ; TAG_DONE + + move.l d3,-(SP) ; Länge + pea XPK_OutBufLen + + move.l a2,-(SP) ; OutBuf + pea XPK_OutBuf + + move.l d4,-(SP) ; File + pea XPK_InFH + + movea.l SP,a0 ; Tags + movea.l a4,a6 ; XpkBase + jsr _LVOXpkUnpack(a6) + lea 7*4(SP),SP + tst.l d0 ; OK ? + bra.b .ReadCont ; ---> dort weitermachen :) +.NoXpkRead: + ENDC + *** Nicht-XPK-gepacktes IFF-File laden - move.l d2,(a2)+ ; Länge des reserv. Bereichs move.l d4,d1 ; File move.l a2,d2 ; Adr - addq.l #8,d2 ; FORM.... schon gelesen! - addq.l #4,d2 ; IFF-Typ schon gelesen movea.l iffb_DOSBase(a5),a6 JSRLIB Read ; D3 war schon Länge - tst.l d0 - 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 + cmp.l d3,d0 ; Soviel gelesen ? +.ReadCont: beq.b .ReadOK ; Yep ---> OK +.ReadError: moveq #IFFL_ERROR_READ,d5 +.ReadOK: +.Error1: + move.l d4,d1 ; File movea.l iffb_DOSBase(a5),a6 JSRLIB Close +.Error2: -.Error2: move.l d5,d0 ; Error ? + *** Cleanup & quit + + IFD XPK + move.l a4,d0 ; Xpk library offen ? + beq.b .XpkNotOpen ; noe ---> + movea.l a4,a1 ; XpkBase + movea.l iffb_SysBase(a5),a6 + JSRLIB CloseLibrary +.XpkNotOpen: + ENDC + move.l d5,d0 ; Error ? beq.b 6$ ; nein ---> bsr SetError ; Löscht auch D0 - bra.b Ende + bra.b .Ende 6$: bsr ClearError move.l a2,d0 ; Adresse als Return-Code -Ende: +.Ende: lea 12(SP),SP ; Lokalen Speicher freigeben -OpenEnd: movem.l (SP)+,d2-d6/a2/a5-a6 +OpenEnd: movem.l (SP)+,d2-d6/a2/a4-a6 rts IFFHeader: dc.b "FORM",0,0,0,0 + IFD XPK +XpkName: dc.b "xpkmaster.library",0 + ENDC + END |