;                 IFF-Picture (DpaintII) depacker
;		        written by HQC
;		     transformed by MARTY
;       adapted for comercial use by Excess of the Power-Boys
;
; This little program loads a IFF File and depacks it to bitplane
; format. It separates the colortable too, so that you can link
; the colortable to your New Copperlist. 
; The Bitplane is located at $60000 save it with 'wi' after running
; (lenght : $60000 - ca. $65000) <- depends on size of picture
;
; The Colortable is located at 'coltab' save it with 'wi' after
; running too. (lenght: coltab - colend)  
; Write the name of your picture in 'filename' (bottom of the source)
; 
; Any questions ? Contact the Power-Boys.
;
; Greets, Excess.

move.l	$4,a6
lea	gfxname,a1
jsr	-408(a6)
move.l	d0,gfxbase
lea	dosname,a1
jsr	-408(a6)
move.l	d0,dosbase
move.l	#filename,d1
jsr	disk
move.l	#$60000,a1
move.l	#coltab,tab
jsr	display

rts

display:
	move.l	#bpln,a0		
	add.l	#12,a0
	move.l	a0,bmhdchunk		
	move.l	4(a0),d0
	add.l	d0,a0
	add.l	#8,a0
	move.l	a0,cmapchunk		

sea1:	move.l	4(a0),d0
	add.l	d0,a0
	add.l	#8,a0
	move.l	#'BODY',d1
	cmp.l	(a0),d1
	bne	sea1
	move.l	a0,bodychunk		
	add.l	#4,a0
	move.l	(a0),anzahl		
	add.l	#1,anzahl
	and.l	#$fffffffe,anzahl
	add.l	#4,a0			

	clr.l	d3
sea3:	move.b	(a0)+,zaehler
	clr.l	d5
	move.b	zaehler,d5
	and.b	#$80,d5
	bne	sea4

	clr.l	d4
	move.b	zaehler,d4
sea5:	move.b	(a0)+,(a1)+
	add.l	#1,d3
	dbf	d4,sea5
	sub.l	#1,a0
	bra	sea6

sea4:	neg.b	zaehler
	clr.l	d0
	move.b	zaehler,d0
sea2:	move.b	(a0),(a1)+
	dbf	d0,sea2

	add.l	#2,d3
sea6:	move.l	anzahl,d1
	cmp.l	d3,d1
	ble	sea99
	add.l	#1,a0
	bra	sea3

sea99:	
move.l	cmapchunk,a0
add.l	#8,a0
move.w	#$180,d0
move.l	tab,a1
move.l	#31,d1
lop:
clr.l	d2
move.b	(a0)+,d2
asl.w	#4,d2
move.b	(a0)+,d2
clr.l	d3
move.b	(a0)+,d3
asr.w	#4,d3
or.w	d3,d2
move.w	d0,(a1)+
move.w	d2,(a1)+
add.w	#2,d0
dbra	d1,lop
rts

disk:
move.l	dosbase,a6
move.l	#1005,d2
jsr	-30(a6)
move.l	d0,d1
move.l	#bpln,d2
move.l	#40000,d3
jsr	-42(a6)
move.l	filehandle,d1
jsr	-36(a6)
rts


bmhdchunk:	
	dc.l	0
cmapchunk:
	dc.l	0
bodychunk:
	dc.l	0
anzahl:	dc.l	0
anzahl1:dc.l	0
con:	dc.l	0
co:	dc.w	$9081
co2:	dc.w	$90c1
pt:		dc.l	0
gfxbase:	dc.l	0
dosbase:	dc.l	0
filehandle:	dc.l	0
gfxname:	dc.b	"graphics.library",0
even
dosname:	dc.b	"dos.library",0
even
zaehler:	dc.b	0
even
tab:		dc.l	0

bpln:
blk.b	40000,0
even

table:
dc.w	0,4,8,12,16,20,24,28,32,36,6400,6404,6408,6412,6416
dc.w	6420,6424,6428,6432,6436,12800,12804,12808,12812,12816,12820
dc.w	12824,12828,12832,12836,19200,19204,19208,19212,19216,19220
dc.w	19224,19228,19232,19236

; Rename 'filename' as your picturename ! 

filename:	dc.b	"df1:lo-res/char2",0
even

; Here will be the Colortable written in.
; Link it to your Copperlist !

coltab:       
blk.l	32,0
colend:

