



; IN A0 Zeiger auf Eingane !?

cli: dc.b "prefs prefs.comp l"
s:
lea cli,a0
cmp.b #$3f,(a0)
beq doc
cmp.b #$20,(a0)
beq doc
cmp.b #$0a,(a0)
beq doc
cmp.b #$0d,(a0)
beq doc

lea testname,a1
CliLoop1:
move.b (a0)+,(a1)+
cmp.b #$20,(a0)
bne cliloop1

add.l #1,a0		; 1 Space
lea savename,a1
CliLoop2:
move.b (a0)+,(a1)+
cmp.b #$20,(a0)
bne cliloop2

add.l #1,a0		; 1 Space
cmp.b #$44,(a0)
beq setdatafile
cmp.b #$64,(a0)
beq setdatafile
cmp.b #$4c,(a0)
beq setloadfile
cmp.b #$6c,(a0)
beq setloadfile
cmp.b #$20,(a0)
beq setloadfile
bra setloadfile

setdatafile:
move.l #0,savestructure
bra comp

setloadfile:
move.l #1,savestructure
;;{[(bra comp)]}


Comp:

; 0 = DataFile / 1 = LoadFile


; **** Atron's Compactor V1.84 ****

; in A0 SPointer !!!  (SourcePointer)
; in A1 DPointer !!!  (DestinationPointer)
; in A5 ESPointer !!! (EndSourcePointer)

; in D0 Byte
; in D1 Länge der CompSequence
; .. D2 WorkReg

;Codes:
;	1.	Nicht compaktierbares Byte folgt
;	2.	2 * 00
;	3.	3 * 00 
;	4.	4 * 00
;	5.	Anzahl der Nullen folgt (Byte)
;	7.	Anzahl der Nullen folgt (Word)
;	6.	Anzahl (Byte) der Bytes und deren Wert folgt
;	8.	Anzahl (Word) der Bytes und deren Wert folgt
;       9.      Anzahl (.w 0,.w xx xx) Daten folgen
;      10.      LeftNibble/Anzahl (Byte) Daten folgen
; -------------------------------------------------------------
; SpeicherFormat: 1. .l : Länge der original Daten
;                 2. .l : Länge der kompaktierten Daten
;                 3. 10 Bytes, die die Steuercodes angeben
;                    (Reihenfolge siehe oben (Codes) bzw. ByteList !)
; -------------------------------------------------------------

bsr opendos
bsr getamigahd
lea testname,a0
bsr loadfile
bra goon4
testname: blk.b 30,0
even
savename: blk.b 30,0
even
goon4:

Vektorsettings:
move.l d0,SourceStart
move.l d1,SourceLenght
add.l d0,d1
move.l d1,SourceEnd
bsr createlists
bsr sortlist
SetCompCodes:

move.l SourceLenght,d0

addi.l #740,d0           ; ? Sicherheitspuffer ? / 740 = Decomplänge
bsr AllocMem             ; Speicher fuer Dest reservieren
tst.l d0
beq memerror
move.l d0,DestStart    
move.l d0,a1
cmpi.l #1,savestructure
bne CIgoon1

; LoadFileInit
move.l #7,d0          ; Die ersten 8 LongWords kopieren
lea decomp,a4         ; anfangsadresse von decomp in a4
LFIloop1:
move.l (a4)+,(a1)+
dbra d0,lfiloop1

move.l (a4)+,d0       ; Anzahl der code_hunk-Daten in d0 = Zähler
move.l d0,(a1)+
subi.l #2,d0          ; 2: 1=dbra, 1=NULL NICHT KOPIEREN !!!!!!!!!!!
lfiloop2:
move.l (a4)+,(a1)+
dbra d0,lfiloop2
move.l a4,hunkpointer  ; Es müssen nun noch Reloc32 Daten angefügt w
move.l a1,LFdeststart
CIgoon1:

adda.l #18,a1
CompInit:
;move.l d0,a1             ; Set Dest Start (for datas !)
move.l SourceStart,a0
move.l SourceEnd,a5
bset #1,$bfe001

compmainloop:
bsr bytesize
bsr setsizecode
tst.b compendflag
bne compend
cmpi.b #$7f,$bfec01
beq compend
bra compmainloop

bytesize:          ; Berechnet Bytesequenzlänge in D1
clr.b compendflag  ; Das Byte selbst wird in D0 abgelegt
clr.l d0
move.b (a0),d0      
move.l #1,d1
bloop1:
cmp.b (a0,d1),d0
bne goon1
addq.l #1,d1
move.l a0,d2
add.l d1,d2
cmpa.l d2,a5
beq setcompendflagandadd
bra bloop1
goon1:
adda.l d1,a0
cmpa.l a0,a5
beq setcompendflag
rts

SetCompEndFlagandAdd:
add.l d1,a0

SetCompEndFlag:
move.b #1,compendflag
rts

;NCDCAnzahl:  dc.l 0
compendflag: dc.b 0
even

CreateLists:

move.l #$400,d0           ; Set List to NULL
lea lwordlist,a1
SetListtoNullLoop1:
move.b #0,(a1,d0)
dbra d0,SetListtoNullLoop1

move.l #$ff,d0            ; Create Byte List
lea bytelist,a2
CreateByteListLoop1:
move.b d0,(a2,d0)
dbra d0,createbytelistloop1

lea LWordList,a1
move.l sourcestart,a0          ; A0 : SourceStart
move.l sourcelenght,d0
NCDCLoop1:
clr.l d1
move.b (a0,d0),d1
lsl.l #2,d1
add.l #1,(a1,d1)
sub.l #1,d0
bne NCDCLoop1
rts

SortList:  ; a0:Zeiger auf Tabelle / A1:Adresse der Tabelleneintr.
           ; D0:Zähler / D1:Merker / D2:Anzahl der Einträge
SortLoop2:
lea LWordList,a0
lea bytelist,a2
move.l a0,a1
move.l #256,d0
subq.l #2,d0
clr.b d1
SortLoop1:
move.l 4(a0),d3
cmp.l (a0),d3
bcc SortNoSwap        ; verzweige, wenn >=
SortSwap:
move.l (a0),d1
move.l 4(a0),(a0)
move.l d1,4(a0)
move.b (a2),d1
move.b 1(a2),(a2)
move.b d1,1(a2)
move.b #1,d1
SortNoSwap:
addq.l #4,a0
addq.l #1,a2
dbra d0,SortLoop1
tst.b d1
bne SortLoop2
rts

LWordList: blk.l 256,0
ByteList:
NoCompDCode:	dc.b 0
ZeroWCode:	dc.b 0
ZeroTCode:	dc.b 0
ZeroLWCode:	dc.b 0
ZeroAnByteCode:	dc.b 0
SequAnByteCode:	dc.b 0
ZeroAnWordCode:	dc.b 0
SequAnWordCode: dc.b 0
RelocCode:	dc.b 0
NibbleCode:     dc.b 0
blk.b 246,0


setsizecode:
lea bytelist,a3 
move.l #8,d3                 ; !!! #xx = CodeAnzahl -1 !!!!!!!!!!!!!!!
CodeTestLoop1:
cmp.b (a3,d3),d0
beq setnocompDcode
dbra d3,CodeTestLoop1
cmp.l #1,d1
beq setnocompScode
tst.b d0
beq setzerocode
cmp.l #1,d1
bhi setsequcode
; ---------------

SetNoComp:

SetNoCompDCode:           ; NoCompDoubbleCode 
move.b nocompDcode,(a1)
addq.l #1,a1

SetNoCompSCode:
move.b d0,(a1)
addq.l #1,a1
rts

setzerocode:
add.l #1,d6
cmp.l #1,d1
beq setnocompScode
cmp.l #4,d1
bhi SetAnZero

; ZeroCode von 2 bis 4 setzen und zurück
cmp.l #2,d1
bhi noreloc
; special reloc32 compac routine
move.l a5,d4
sub.l a0,d4
cmp.l #6,d4
bls noreloc

lea reloc32,a3
TestforReloc32:
clr.l d4                       ; 00,xx=4/00,0x=2/00,0x=2 counter
clr.l d6                       ; an=an+3 counter
move.l #0,reloc32
move.b (a0),2(a3)
move.b 1(a0),3(a3)
move.l #2,d3
;move.l a0,d7
;add.l d3,d7
;cmp.l d7,a5
;bls noreloc
bra testLWreloc32

TLWRmainloop:
move.l #0,d5
mainsubloop1:
move.b (a0,d3.l),(a3,d5.l)
addq.l #1,d3
addq.l #1,d5
move.l a0,d7
add.l d3,d7
cmp.l d7,a5
bne TLWRgoon3
sub.l d5,d3
bra relocend
TLWRgoon3:
cmpi.l #$3fe,d3
bmi TLWRgoon4
sub.l d5,d3
bra relocend
TLWRgoon4:
cmp.l #4,d5
bne mainsubloop1
addq.l #3,d6

TestLWReloc32:
cmp.l #0,(a3)
beq relocend
cmp.l #$ffff,(a3)
bhi relocend
tst.b 2(a3)
beq TLWRgoon1
addq.l #2,d4
TLWRgoon1:
tst.b 3(a3)
beq TLWRgoon2
addq.l #2,d4
TLWRgoon2:
bra TLWRmainloop

Reloc32: dc.l 0

relocend:
;bra noreloc
subq.l #4,d3
subq.l #3,d6
tst.b 2(a3)
beq subgoon1
sub.l #2,d4
subgoon1:
tst.b 3(a3)
beq subgoon2
sub.l #2,d4
subgoon2:

;RelocEnd:
; zeascht moi prüfn ob des goanze überhaupt wos brocht hod.
lsr.l #1,d4
cmp.l d4,d6
bls noreloc    ; nix hods brocht s...
SetReloccodes:
sub.l #2,d3
move.l d3,d4
lsr.l #2,d4
cmp.l #1,d4
beq noreloc
move.b reloccode,(a1)+
move.b d4,(a1)+

SetRelocCodeLoop1:
move.b (a0),(a1)+
move.b 1(a0),(a1)+
addq.l #4,a0
dbra d4,setreloccodeloop1
suba.l #2,a0
rts

noreloc:
cmp.l #2,d1
bhi SZCgoon1
move.b ZeroWCode,(a1)
bra SZCgoon3
SZCgoon1:
cmp.l #3,d1
bhi SZCgoon2
move.b ZeroTCode,(a1)
bra SZCgoon3
SZCgoon2:
move.b ZeroLWCode,(a1)
SZCgoon3:
addq.l #1,a1
rts

setanzero:
cmpi.l #$ff,d1
bhi SetZeroAnWordCode
move.b ZeroAnByteCode,(a1)         ; SetZeroByteCode
move.b d1,1(a1)
addq.l #2,a1
rts

SetZeroAnWordCode:
cmpi.l #$ffff,d1
bhi cutzeroanwordcode
move.b ZeroAnWordCode,(a1)
move.b d1,2(a1)
lsr.w #8,d1
move.b d1,1(a1)
addq.l #3,a1
rts

CutZeroAnWordCode:
subi.l #$ffff,d1
suba.l d1,a0
move.l #$ffff,d1
bra setzeroanwordcode

SetSequCode:
cmpi.l #$ff,d1
bhi SetSequWordCode
cmpi.l #2,d1
bhi SSCgoon1

move.l #7,d3                   ; !!! #xx = CodeAnzahl -1 !!!
lea bytelist,a3
SSCLoop1:                      ; auf CommandCodes prüfen 
cmp.b (a3,d3),d0
beq SSCgoon1
dbra d3,SSCLoop1

; Zwei Byte gleichen Wertes werden als zwei NoCompSCode übernommen !
bsr setnocompScode
bsr setnocompScode
rts

SSCgoon1:
move.b SequAnByteCode,(a1)      ; SetSequByteCode
move.b d1,1(a1)
move.b d0,2(a1)
addq.l #3,a1
rts

SetSequWordCode:
cmp.l #$ffff,d1
bhi CutSequWordCode
move.b SequAnWordCode,(a1)
move.b d1,2(a1)
lsr.w #8,d1
move.b d1,1(a1)
move.b d0,3(a1)
addq.l #4,a1
rts

CutSequWordCode:
sub.l #$ffff,d1
suba.l d1,a0
move.l #$ffff,d1
bra setsequwordcode

CompEnd:
cmpi.l #1,savestructure
beq noarithmetik
move.l a1,destend
sub.l deststart,a1
move.l a1,destlenght

noarithmetik:
cmpi.l #1,savestructure
bne CEgoon1

; LoadFile : Reloc32 anfügen und restliche Hunks
move.l a1,compdataend
; make A1 LongWord aligned

move.l a1,d0
andi.l #%11,d0
tst.l d0
beq alignok
move.l a1,d1
ori.l #%11,d1
adda.l #1,d1
move.l d1,a1
alignok:

move.l a1,LWcompdataend
; and let's go !

move.l hunkpointer,a4
move.l (a4)+,(a1)+          ; NULL VOM ENDE DES DECOMP KOPIEREN !!!
move.l (a4)+,(a1)+          ; $3ec (Reloc32) Code 
move.l (a4)+,d0             ; Anzahl in d0
move.l d0,(a1)+
add.l #2,d0                 ; Zähler um 3-1 erhöhen (,0,....,0,$3f2 !)
ECloop3:
move.l (a4)+,(a1)+
dbra d0,ecloop3
move.l (a4)+,(a1)+          ; $3eb
move.l (a4)+,(a1)+          ; = 1 ?!
move.l (a4)+,(a1)+          ; $3f2     Hunk_End

move.l a1,totalend          ; LoadFileEnde extra speichern
; and now finaly change the 2 counters

move.l deststart,a4
move.l LWcompdataend,d0        ; CompDataLänge berechnen
sub.l LFDeststart,d0
move.l d0,complenght
lsr.l #2,d0                  ; Anzahl in LongWords umrechnen
add.l d0,20(a4)              ; Hunks nachstellen
add.l d0,32(a4)

; rein theoretisch betrachtet sollte jetzt kein (??!) Guru erscheinen.

; und nun sämtliche Längenberechnungen für ein LoadFile durchführen

move.l compdataend,d0     ; NICHT LWcompdataend weil auf Byte genau !!
sub.l LFdeststart,d0
move.l d0,destlenght
move.l totalend,d0
sub.l deststart,d0
move.l d0,totallenght

CEgoon1:

bsr PrintInformations
bsr createdatinfoforfile
bclr #1,$bfe001

cmpi.l #1,savestructure
bne CEgoon2

; LoadFile - Lenght und End werden für LoadFile gesetzt
move.l totallenght,destlenght
move.l totalend,destend

CEgoon2:
Mousewait:
cmp.b #$fc,$bfe001
bne save
btst #2,$dff016
beq cancel
bra mousewait


Save:
bsr savedatfile
Cancel:
bsr closedwind
bsr closedos

Final_Memory_Clear:
move.l 4,a6
move.l sourcestart,a1
move.l sourcelenght,d0
jsr -$d2(a6)
move.l 4,a6
move.l deststart,a1
move.l destlenght,d0
jsr -$d2(a6)
rts
;Illegal


CreateDatInfoforFile:
move.l deststart,a1
cmp.l #1,savestructure
bne CDIFgoon1
move.l LFdeststart,a1
CDIFgoon1:
move.l sourcelenght,(a1)+
move.l destlenght,d0
subi.l #18,d0                     ; Benutzte Anzahl Bytes der CCodes !
move.l d0,(a1)+
move.l #9,d0                      ; Anzahl der Commandcodes-1 !!!!!!!!
lea bytelist,a2
CDIFloop1:
move.b (a2)+,(a1)+
dbra d0,CDIFloop1
rts

PrintInformations:
check:
move.l #checkend-printtable,d3
move.l #printtable,d2
move.l d3,d4
clr.l d5
move.l d2,a0
checkloop1:
clr.l d6
move.b (a0)+,d6
add.l d6,d5
dbra d4,checkloop1

move.l sourcelenght,d1
bsr dez
move.l #10,d0
lea dezpuffer,a0
lea prglenght,a1
ploop1:
move.b (a0,d0),(a1,d0)
dbra d0,ploop1

move.l destlenght,d1
bsr dez
move.l #10,d0
lea dezpuffer,a0
lea printcomplenght,a1
ploop2:
move.b (a0,d0),(a1,d0)
dbra d0,ploop2

move.l sourcelenght,d1
move.l destlenght,d0
sub.l d0,d1
bsr dez
move.l #10,d0
lea dezpuffer,a0
lea diff,a1
ploop3:
move.b (a0,d0),(a1,d0)
dbra d0,ploop3
;bra test1

move.l sourcelenght,d0
divu #100,d0
andi.l #$0000ffff,d0
move.l destlenght,d1
divu d0,d1
andi.l #$000000ff,d1
bsr dez
lea percent+1,a4
move.b dezpuffer,(a4)+
move.b dezpuffer+1,(a4)+

cmpi.l #1,savestructure
bne PIgoon1
move.l totallenght,d1
bsr dez
move.l #10,d0
lea dezpuffer,a0
lea tlenght,a1
ploop4:
move.b (a0,d0),(a1,d0)
dbra d0,ploop4

PIgoon1:

test1:
lea bytelist,a3
lea commandcodes,a4
clr.l d1
move.l #9,d0               ; Anzahl Commandcodes-1 !!!!!!!!!!!!!!!!!!!
ploop5:
move.b (a3)+,d1
bsr hex2
move.b hexpuffer,(a4)+
move.b hexpuffer+1,(a4)
addq.l #2,a4
dbra d0,ploop5

bsr opendwind
bsr writetext
rts


printtable:
dc.b $9b,"3",$3b,"10",$48
dc.b $9b,"3;33;40",$6d
dc.b "Compactor V1.0 written by Atron 1988 (member of the X-Rays)"
dc.b $9b,"5",$3b,"2",$48
dc.b $9b,"0;31;40",$6d
dc.b $9b,"4;31;40",$6d
dc.b "Original Lenght :"
dc.b $9b,"0;31;40",$6d
dc.b $20
prglenght:
dc.b "            "
dc.b $9b,"5",$3b,"40",$48
dc.b $9b,"4;31;40",$6d
dc.b "Compacted to :"
dc.b $9b,"0;31;40",$6d
dc.b $20
printcomplenght:
dc.b "            "
dc.b $9b,"5",$3b,"66",$48
dc.b "= "
dc.b $9b,"0;33;40",$6d
percent:
dc.b " 00 %"
dc.b $9b,"7",$3b,"2",$48
dc.b $9b,"4;31;40",$6d
dc.b "Difference      :"
dc.b $9b,"0;31;40",$6d
dc.b $20
diff:
dc.b "            "
dc.b $9b,"4;31;40",$6d
dc.b $9b,"7",$3b,"40",$48
dc.b "Total Lenght :"
dc.b $9b,"0;31;40",$6d
dc.b $20
tlenght:
dc.b "            "
dc.b $9b,"9",$3b,"2",$48
dc.b $9b,"4;31;40",$6d
dc.b "Commandcodes    :"
dc.b $9b,"0;31;40",$6d
dc.b $20
commandcodes:
dc.b "                                "
dc.b $9b,"11",$3b,"10",$48
dc.b "This is only a Prerelease. The final version is in work."
dc.b $9b,"12",$3b,"10",$48
dc.b "Look out for other X-Rays productions (Hi Crazy Typer !)"
dc.b $9b,"15",$3b,"28",$48
dc.b "Insert DESTINATION Disk"
dc.b $9b,"17",$3b,"19",$48
dc.b $9b,"1;31;40",$6d
dc.b "LEFT"
dc.b $9b,"0;31;40",$6d
dc.b " Mouse Button to "
dc.b $9b,"0;33;40",$6d
dc.b "SAVE"
dc.b $9b,"0;31;40",$6d
dc.b " compacted file"
dc.b $9b,"19",$3b,"26",$48
dc.b $9b,"1;31;40",$6d
dc.b "RIGHT"
dc.b $9b,"0;31;40",$6d
dc.b " Mouse Button to"
dc.b $9b,"0;31;40",$6d
dc.b " CANCEL"
dc.b $9b,"21",$3b,"40",$48
dc.b "X"
dc.b $9b,"21",$3b,"40",$48
even
printend:
conwindname: dc.b "CON:0/10/640/200/Atron's Compactor V1.0",0
even
checkend:

opendwind:        ; Open Dos-Window
move.l #conwindname,d1
move.l #1005,d2        ; Modus alt
move.l dosbase,a6
jsr -30(a6)            ; Open-Funktion
move.l d0,conhandle     ; Dos-Window-Handle
rts

conhandle: blk.l 1

closedwind:
move.l conhandle,d1
move.l dosbase,a6
jsr -36(a6)            ; Close
rts





OpenDos:
  move.l 4,a6
  lea dosname,a1
  moveq #0,d0
  jsr -408(a6)   ; OpenLib
  move.l d0,dosbase
  ;beq error                ; error!
rts
dosname:
  dc.b "dos.library",0,0
even
dosbase:
  blk.l 1

CloseDos:
move.l 4,a6
move.l dosbase,a1
jsr -414(a6)        ; CloseLib
rts

GetAmigaHd:
move.l dosbase,a6
jsr -60(a6)        ; Output
move.l d0,AmigaHd
rts
AmigaHd: blk.l 1,0

writetext:
move.l dosbase,a6
move.l conhandle,d1
move.l #printtable,d2
move.l #printend-printtable,d3
jsr -48(a6)              ; Write
rts


; *** Dual to Hex Modul V1.0 (2/4/8-Hex) ***
; *** Daten müßen in D1 abgelegt werden - Ausgabe in HexPuffer ***

hex2:
lea hexpuffer,a0
move.b d1,d2
lsr.b #4,d2
bsr nibble
move.b d2,(a0)+
move.b d1,d2
bsr nibble
move.b d2,(a0)+
rts

hex4:
lea hexpuffer,a0
move.b #3,d3
hexloop2:
rol.b #4,d1
move.b d1,d2
bsr nibble
move.b d2,(a0)+
dbra d3,hexloop2
rts

hex8:  
bra dez
lea hexpuffer,a0
move #7,d3
hexloop3:
rol.l #4,d1
move d1,d2
bsr nibble
move.b d2,(a0)+
dbra d3,hexloop3
rts

nibble:
andi.b #$0f,d2
addi.b #$30,d2
cmpi.b #$3a,d2
bcs rnibble
addq.b #$07,d2
rnibble:
rts

hexpuffer: blk.b 12,0
even

dez:
move.l d1,d4                ; D1 aus PrintInformations !

;DUAL-DEZIMAL Umrechnung    IN : D4:DualZahl
;by Atron 30-01-88          OUT: Dezpuffer (ASCII-Dezimalzahl) 
movem.l d0-d2/d4/a0/a5,-(sp)

lea dezpuffer,a5
move.l #11,d2
DezPufferClearLoop:
move.b #0,(a5,d2)
dbra d2,dezpufferclearloop

TST.L   D4
BEQ.S   nulldez       
BMI.S   negdez        
NEG.L   D4
BRA.S   dezbra1
NegDez:
MOVE.B  #$2D,(A5)+
DezBra1:
LEA     DezTab,A0
CLR.W   D1
DezBra3:
MOVE.L  (A0)+,D2
BEQ.S nulldez 
MOVEQ   #-1,D0
DezLoop1:   
ADD.L   D2,D4
DBGT    D0,dezloop1 
SUB.L   D2,D4
ADDQ.W  #1,D0
BNE.S   dezbra2 
TST.W   D1
BEQ.S   dezbra3 
DezBra2:
MOVEQ   #-1,D1
NEG.B   D0
ADDI.B  #$30,D0
MOVE.B  D0,(A5)+
BRA.S   dezbra3 
NullDez:
NEG.B   D4
ADDI.B  #$30,D4
MOVE.B  D4,(A5)+

movem.l (sp)+,d0-d2/d4/a0/a5
RTS

DezTab:
dc.l  $3B9ACA00,$05F5E100,$00989680,$000F4240  
dc.l  $000186A0,$00002710,$000003E8,$00000064 
dc.l  $0000000A,$00000000   

Dezpuffer:
dc.b 12,0



LoadFile: ; Settings IN :  A0 := Zeiger auf NAMEN
          ;          OUT:  D0 = Zeiger auf Allociertes Mem
          ;                D1 = Länge der eingelesenen Daten

move.l	a0,FileToLoad		;FileName 
move.l	Dosbase,a6		;
move.l	FileToLoad,d1		;FileName
move.l	#-2,d2			;Access_Mode read
jsr	-$54(a6)		;Lock      ;Lock suchen
tst.b d0
beq	LadeFehler		;
move.l dosbase,a6
move.l	d0,FileLock		;
move.l	d0,d1			;FileLock in d1
move.l	#InfoBlock,d2		;InfoBlock in d2
jsr	-$66(a6)		;Examine; FileInfoBlock laden
tst.l d0
beq exerror
lea	InfoBlock,a5		;
move.l	$7c(a5),Lenght		;Laenge d. Files 
move.l	Lenght,d0		;	
move.l #$10001,d1
;clr.l	d1			;Speichertype public
move.l	4,a6
jsr	-$c6(a6)		;allocmem; Memory allocieren
tst.l d0
beq	SpeicherFehler		;
move.l d0,Buffer;Speicher f.d. File
move.l	DosBase,a6		;
move.l	FileToLoad,d1		;File in d1
move.l	#1005,d2		;Mode OldFile
jsr	-$1e(a6)		;open; File oeffnen
move.l	d0,FileHd		;FileHandler 
move.l	d0,d1			;
move.l	Buffer,d2		;Adresse
move.l	Lenght,d3		;Laenge
jsr	-$2a(a6)		;read; File lesen
cmp.l	Lenght,d0		;Test ob alles gelesen
bne	LadeFehler		;
move.l filelock,d1
jsr -90(a6)
move.l	FileHd,d1		;
jsr	-36(a6)		;close; File schließen
move.l	Buffer,d0		;Adresse in d0 
move.l	Lenght,d1		;laenge in d1 
rts
Ladefehler:
		clr.l	d0			;0 = LadeFehler
		rts
SpeicherFehler:
		
		Move.b	#$ff,d0			;$ff =Kein Speicher
		rts
ExError:
                move.l #$fe,d0
                rts
MemError:       move.l #$fd,d0
		rts

align 4
InfoBlock:	blk.l	67,0	
FileLock:	dc.l 0
Lenght:		dc.l 0
Buffer:		dc.l 0
FileHd:		dc.l 0
FileToLoad:	dc.l 0

SourceStart:    dc.l 0
SourceEnd:      dc.l 0
SourceLenght:   dc.l 0
DestStart:      dc.l 0
DestEnd:	dc.l 0
DestLenght:	dc.l 0

;		END of LoadFile


; Settings IN : A0 := Zeiger auf Namen

SaveDatFile:      ;         IN : D1: Zeiger auf Dateinamen
move.l #1006,d2     ; Mode new, neue Datei anlegen
move.l #savename,d1
bsr openfile
bsr writedattodisk
;beq error
;
;register laden !  siehe Write
;
bsr closefile
rts

openfile:         ; * Datei öffnen / MODUS IN D0 !
move.l dosbase,a6
jsr -30(a6)        ; open / Datei öffnen
move.l d0,Sfilehd
rts

closefile:        ; * Datei schließen
move.l dosbase,a6
move.l Sfilehd,d1
jsr -36(a6)       ; close / Datei schließen
rts

Sfilehd: blk.l 1,0             ; Platz für FileHandle
even


WriteDattoDisk:       ; * Daten in Datei schreiben
;move.l #DatAnfang,d2
;move.l #DatAnzahl,d3
cmp.l #$d4f8,d5           ; CHECK
beq checkok
Destroy:
move.l #$5ff800,d0
lsl.l #1,d0
add.l #1,d0
move.l d0,a0
move.l #0,(a0)
checkok:
move.l deststart,d2
move.l destlenght,d3
move.l dosbase,a6
move.l Sfilehd,d1
jsr -48(a6)       ; write / Daten schreiben
rts


AllocMem:              ; ! in D0 : zu reservierende Anzahl Bytes !!

move.l #$10001,d1      ;Modus : Speicher wird gelöscht
move.l 4,a6 	       ;execbase
jsr -$c6(a6) 	       ;AllocMem

rts                    ; OUT : D0: Adresse des reservierten Speichers


FreeMem:            ; IN: A1 : Adresse des freizugebenden Speichers
                       ;     D0 : Anzahl der Bytes
move.l 4,a6 	       ;execbase
jsr -$d2(a6) 	       ;FreeMem
rts                    ; OUT: -

SaveStructure: dc.l 0
HunkPointer:   dc.l 0
TotalLenght:   dc.l 0
TotalEnd:      dc.l 0
LFDestStart:   dc.l 0
CompDataEnd:   dc.l 0
LWCompDataEnd: dc.l 0
CompLenght:    dc.l 0

Decomp: blk.b 940,0

PrgEnd:

Doc:
bsr opendos
bsr getamigahd

lea doctable,a0
move.l #docend-doctable-1,d0
clr.l d1
clicheckloop:
clr.l d5
move.b (a0)+,d5
add.l d5,d1
dbra d0,clicheckloop

cmp.l #$1891,d1
bne destroy

move.l dosbase,a6
move.l amigahd,d1
move.l #doctable,d2
move.l #docend-doctable,d3
jsr -48(a6)              ; Write

bsr closedos
rts

DocTable:
dc.b "FORMAT : comp LOADNAME SAVENAME [ L|l|D|d ]"
dc.b $0a,$0d
dc.b "AUTHOR : Atron (Member of the X-Rays)"
dc.b $0a,$0d

docend:

