;==============================================
;	IFF-ILBM-LADER / POSTERPRINT
; 68oooer 3/1988	Markt&Technik Verlag AG
;
;	von Rolf Wagner und Volker Raum
; Mit Dank an S. Angerer, P. Jakobi, A. Hommel
;==============================================
;
;
; offsets intutition
;
OpenIntuition         =   -30 -  0            
Intuition             =   -30 -  6            
CloseScreen           =   -30 -  36           
OpenScreen            =   -30 -  168          
PrintIText            =   -30 -  186          
;
; offsets exec
;
OpenLib               =   -30 -  378
OpenLibrary           =   -30 -  378          
CloseLibrary          =   -30 -  384          
AllocMem              =   -30 -  168
FreeMem               =   -30 -  180
;
; offset graphics (gfx)
;
LoadRGB4              =   -30 -  162
ReadPixel             =   -30 -  288
WritePixel            =   -30 -  294
SetDrMod              =   -30 -  324
;
; offsets dos
;					
Open                  =   -30
Close                 =   -30 -    6
Read                  =   -30 -   12
Write                 =   -30 -   18
Exit                  =   -30 -  114           
;
;
; einzige absolute adresse des amiga-betriebsystems:
;
ExecBase = 4
;
even
;
;
; beginn des hauptprogramms
;
start:
 clr.l d0
 move.l ExecBase,a6		; oeffnen der    
 lea.l gfxname,a1		; gfx-library
 jsr openlibrary(a6)
 move.l d0,gfxbase		; basisadresse der gfx-library
;
 move.l execbase,a6     	; oeffnen der
 lea intname,a1         	; intuition-library
 jsr openlibrary(a6) 
 move.l d0,a6 
 move.l d0,intuitionbase	; basisadresse der intuition-
;				  library
;
 jsr open_dos			; oeffnen der dos-library
 jsr entername
continue:
 jsr open_file 			; file oeffnen
 move.l #disk_buf,d2
 move.l #8,d3			; iff-header lesen
 jsr load			; um gesamte filelaenge zu 
 move.l d2,a0			; erfahren
;
 move.l 4(a0),d3		; chunklaenge
 move.l d3,chunk_size		; (laenge des ges. files)
 jsr allocate			; speicher vom exec holen
 move.l chunk_size,d3		; anzahl bytes 
 move.l pic_buf,d2		; zieladresse
 jsr load			; file laden
 jsr close_file			; file schliessen
;
 jsr iff_search			; chunks etc. suchen
;
 move.l intuitionbase,a6
 lea.l newscreen,a0		; bildschirmdaten
 jsr openscreen(a6)		; bildschirm oeffnen
 move.l d0,screen		; datenliste des screens
;
 jsr pic_print			; geladenes bild zeigen
 jsr free			; benoetigten speicher
;				  zurueckgeben
wait_loop:			 
 cmp.b	#$33,$bfec01
 bne	notleft
 move.b	#'c',modus
 jmp	plop
notleft:
 cmp.b	#$31,$bfec01
 bne	wait_loop
 move.b	#'m',modus
plop:
 jsr	ausdruck
wait_end:
 move.l intuitionbase,a6	; bildschirm
 move.l screen,a0   		; schliessen
 jsr closescreen(a6)
;
 move.l execbase,a6		; intuition-library
 move.l intuitionbase,a1	; schliessen
 jsr closelibrary(a6)      
;
 move.l gfxbase,a1		; graphic-library
 jsr closelibrary(a6)		; schliessen
;
 move.l dos_base,a1		; dos-library
 jsr closelibrary(a6)		; schliessen
;
prg_end:
 move.l dos_base,a6		; zurueck in cli...
 jmp exit(a6)
;
;
; daten fuer screenaufbau und bidschirmverwaltung
;
align 4
title: dc.b '68000er presents:',0
align 4
dosname: dc.b 'dos.library',0
align 4
intname: dc.b "intuition.library",0
align 4
gfxname: dc.b "graphics.library",0
align 4
gfxbase: 	blk.l 1,0
intuitionbase: 	blk.l 1,0
dos_base: 	blk.l 1,0
;
Newscreen:
		 dc.w 0,0	; X und Y position
width:		 dc.w 320	; breite
height:		 dc.w 200	; hoehe
		 dc.w 5		; tiefe (anzahl bitplanes)
		 dc.b 0,1	; DetailPen, BlockPen
modes:		 dc.w $0,$0f	; ViewModes, Screen Type
		 dc.l font	; APTR font (scr. and wind.)
		 dc.l title	; APTR Screen Title
 		 dc.l 0,0	; APTR Gadgets, CustomBitMap
;
font = 0			; system-zeichensatz
; 
screen: dc.l 0			; adresse der screen-datenliste
;
even
;
planes: blk.l 10,0		; zwischenspeicher fuer bitplanes
colour_map: blk.w 32,0		; max. 32 farben a 1 word
black_colour: blk.w 32,0	; alle farben auf schwarz
even
;
planes_init:
 move.l screen,a0		; suchen der anfangsadressen
 add.l #$c0,a0			; der von openscreen
 move.l #planes,a1		; bereitgestellten
 move.w planes_num,d0		; bitplanes
plane_loop:
 move.w d0,d1
 mulu #4,d1
 move.l (a0,d1),(a1,d1)
 dbra d0,plane_loop
 rts
;
colours_init:
 move.l cmap_chunk,a0		; aufbau einer colourmap
 add.l #8,a0			; fuer den loadrgb4 befehl
 move.l #colour_map,a1		; destination
 move #31,d7			; 32 farben
co_loop1:
 clr.w d0			; d0 loeschen
 move.b (a0)+,d0		; rot-wert
 and.b #$f0,d0			; nur obere 4 bits
 lsl.w #4,d0			; high-byte,low-nibble
 move.b (a0)+,d0		; gruen-wert
 and.w #$0ff0,d0		; bits 11 bis 4
 clr.w d1			; hilfs-reg
 move.b (a0)+,d1		; blau-wert
 lsr.b #4,d1	
 and.b #$0f,d1			; nur bits 3 bis 0
 or.b d1,d0			; low-byte,low-nibble
 move.w d0,(a1)+
 dbra d7,co_loop1
 rts
;
pic_print:
 jsr planes_init		; adressen der bitplanes
 jsr colours_init		; aufbau einer colourmap
 jsr black_colour_set
 jsr unpacker			; bild dekomprimieren
 jsr colour_set			; farben setzen
 rts
;
colour_set:
 move.l screen,a0		; neue farbpalette
 add.l #44,a0			; setzen
 move.l #colour_map,a1		; unter verwendung
 move.w #32,d0			; der loadrgb4 routine
 move.l gfxbase,a6
 jsr LoadRGB4(a6)
 rts
;
black_colour_set:
 move.l screen,a0		; neue farbpalette
 add.l #44,a0			; setzen
 move.l #black_colour,a1	; unter verwendung
 move.w #32,d0			; der loadrgb4 routine
 move.l gfxbase,a6
 jsr LoadRGB4(a6)
 rts
;
iff_search:
 move.l pic_buf,a0		; ermitteln der
 add.l #4,a0			; startadressen
 move.l a0,bmhd_chunk		; bitmap-header-chunk
 move.l 4(a0),d0
 add.l d0,a0
 add.l #8,a0
 move.l a0,cmap_chunk		; colourmap-chunk
iff_l1:
 move.l 4(a0),d0		; suchen des body-chunks
 add.l d0,a0
 add.l #8,a0
 move.l #"BODY",d1
 cmp.l (a0),d1			; bereits Body-Chunk?
 bne iff_l1
 move.l a0,body_chunk		; body-chunk
 move.l bmhd_chunk,a2
 move.l a2,a1
 add.l #16,a1			; anzahl bitplanes
 clr.w d0			; ermitteln
 move.b (a1),d0
 cmp.w #6,d0			; max. 6 bitplanes
 blt iff_cont
 move.w #6,d0
iff_cont:
 move.l #newscreen,a0
 move.w d0,8(a0)
 subq.w #1,d0
 move.w d0,planes_num		; in planes_num steht 
;				  anzahl bitplanes -1
 move.l a2,a1
 add.l #18,a1			; gepackt?
 move.b (a1),comp_flag
 move.l a2,a1
 add.l #8,a1			; breite
 clr.l d0
 move.w (a1)+,d0
 move.w d0,width
 clr.l d3
 cmp.w #640,d0
 blt iff_cont3
 or.w #$8000,d3
iff_cont3:
 move.w d0,d1
 and.w #7,d1
 beq iff_cont2
 or.w #8,d0
iff_cont2:
 divu #8,d0
 move.w d0,width_bytes
 clr.l d0
 move.w (a1),d0
 move.w d0,height
 cmp.w #400,d0
 blt iff_cont4
 or.w #4,d3
iff_cont4:
 move.w d3,modes
 rts
;
unpacker:
 move.l #planes,a2		; grafikdaten dekomprimieren
 move.l body_chunk,a0
 add.l #4,a0
 move.l (a0)+,d7		; chunk-groesse, anzahl bytes
 move.l a0,a3
 add.l d7,a3			; endadresse
 move.w planes_num,d2		; anzahl bitplanes
 addq.w #1,d2
;
unp_loop:
 cmp.l a3,a0			; endadresse erreicht?
 bge unpack_end			; ja!
;
 clr.w d3
pic_loop1:
 move.w d3,d4			; ermitteln der
 mulu #4,d4			; plane-adresse
 move.l (a2,d4),a5
 jsr unpack_row			; eine Zeile dekomprimieren
 move.l a5,(a2,d4)
 addq.w #1,d3
 cmp.w d2,d3
 blt pic_loop1
 move.l bmhd_chunk,a5		; masken-plane vorhanden?
 andi.b #1,17(a5)
 beq unp_loop
 move.l #mask_dummy,a5
 jsr unpack_row
 bra unp_loop
unpack_row: move.l d2,-(sp)	; d2 retten
 move.w width_bytes,d2
unp_loop1: tst.w d2
 beq unpack_row_end
 clr.w d0
 tst.w comp_flag
 bne unp_comp
 move.w width_bytes,d0
 subq.w #1,d0
 bra unp_loop2 
unp_comp:
 move.b (a0)+,d0		; befehlsbyte
 bmi packed			; gepackt!
unp_loop2:
 move.b (a0)+,(a5)+	
 subq.w #1,d2			; bytes uebernehmen
 dbra d0,unp_loop2
 bra unp_loop1
;
packed:
 neg.b d0			; vorzeichen wechseln
 move.b (a0)+,d1		; datenbyte
unp_loop3:
 move.b d1,(a5)+		; byte vervielfaeltigen
 subq.w #1,d2
 dbra d0,unp_loop3
 bra unp_loop1
;
unpack_row_end:
 move.l (sp)+,d2
 rts
;
unpack_end:
 rts
;
;
; chunk-daten
;
align 4
bmhd_chunk: blk.l 1,0
cmap_chunk: blk.l 1,0
body_chunk: blk.l 1,0
planes_num: blk.w 1,0
comp_flag:  blk.w 1,0
width_bytes: blk.w 1,0
;  
; disk routinen fuer filehandling
;
open_dos:
 move.l	execbase,a6		; Dos-Library oeffnen
 lea.l	dosname,a1
 jsr	OpenLib(a6)
 move.l	d0,dos_base		; basisadresse der
 rts				; dos-library
;
open_file:
 move.l dos_base,a6		; file oeffnen
 move.l	#filename,d1
 move.l	#1005,d2		; code fuer read
 jsr	Open(a6)
 beq	prg_end
 move.l	d0,bif			; Handle-nummer
 rts
;
load:
 move.l dos_base,a6		; file laden
 move.l	bif,d1			; in d3 Anzahl Bytes
 jsr	Read(a6)		; in d2 destination-addr
 rts
;
close_file:
 move.l dos_base,a6		; file schliessen
 move.l	bif,d1			; handlenummer des files
 jsr	Close(a6)
 rts
;
allocate:
 move.l execbase,a6		; speicher zuteilen lassen
 move.l #$10000,d1		; code fuer "clear memory"
 move.l chunk_size,d0		; anzahl bytes
 jsr	AllocMem(a6)
 move.l d0,pic_buf		; adresse des datenpuffers
 rts
;
;
free:
 move.l execbase,a6		; speicher zurueckgeben
 move.l pic_buf,a1		; adresse des speichers
 move.l chunk_size,d0		; anzahl bytes
 jsr 	FreeMem(a6)
 rts
;
;
; daten fuer file handling
;
align	4
bif:		dc.l	0
disk_buf:	blk.b 10,0
align 4
pic_buf:	blk.l 1,0
chunk_size:	blk.l 1,0
mask_dummy:	blk.b 128,0

ausdruck:	move.l	dos_base,a6
		jsr	openprinter
		jsr	preferences
		jsr	kommaprint
		move.l	 screen,RastPort
		add.l	 #84,Rastport
		move.l	 rastport,a1
		move.l	 #2,d0
		move.l	 gfxbase,a6
		jsr	 SetDrMod(a6)
		move.l	 #79,ypos
looping1:	move.l	 #0,count
		move.l	 ypos,yp
		move.l	 #0,xp
		move.l	 #able,pufspei
looper1:	move.l	 yp,d1
		move.l	 #202,zwi
		cmp.w	 height,d1
		bge	 notesting
		move.l	 xp,d0
		move.l	 Rastport,a1
		move.l	 gfxbase,a6
		jsr	 ReadPixel(a6)
		move.l	 d0,zwi
		move.l	 yp,d1
		move.l	 xp,d0
		move.l	 Rastport,a1
		move.l	 gfxbase,a6
		jsr	 WritePixel(a6)
		cmp.b	 #$39,$bfec01
		bne	 notesting
		move.l	 dos_base,a6
		move.l	 handle,d1
		jsr	 close(a6)
		rts
notesting:	cmp.b	#'c',modus
		bne	notcolor
		jsr	color
		jmp	qwerty
notcolor:	jsr	mono
qwerty:		subi.l	#1,yp
		add.l	#1,count
		cmp.l	#80,count
		bne	looper1
		cmp.b	#'c',modus
		bne	nocol
		jsr	zeile
		move.l	#able,pufspei
		jmp	okay
nocol:		jsr	zeile1
okay:		move.l	ypos,yp
		move.l	#0,count
		add.l	#1,xp
		move.l	xp,d0
		cmp.w	width,d0
		bne	looper1
		jsr	kommaprint
		addi.l	#80,ypos
		move.l	ypos,d0
		subi.l	#79,d0
		cmp.w	height,d0
		blt	looping1
		move.l	dos_base,a6
		move.l	handle,d1
		jsr	close(a6)
		rts	
;---------------------------------------
Zeile:		move.l	handle,d1
		move.l	#daable,d2
		move.l	#647,d3
		move.l	dos_base,a6
		jsr	Write(a6)
		rts
openprinter:	move.l	#Drucker,d1
		move.l	#1006,d2
		jsr	Open(a6)
		move.l	d0,handle
		rts
preferences:	move.l	handle,d1
		move.l	#pref,d2
		move.l	#6,d3
		jsr	Write(a6)
ausgeben:	move.l	#titel,d2
		move.l	handle,d1
		move.l	#41,d3
		jsr	Write(a6)
		rts
kommaprint:	move.l	handle,d1
		move.l	#kommas,d2
		move.l	#82,d3
		jsr	Write(a6)
		rts
Entername:	move.l	#fenstname,d1
		move.l	#1005,d2
		move.l	dos_base,a6
		jsr	Open(a6)
		move.l	d0,fensthdl
		move.l	dos_base,a6
		move.l	fensthdl,d1
		move.l	#tename,d2
		move.l	#teend-tename,d3
		jsr	Write(a6)
		move.l	#40,d3
		move.l	#filename,d2
		move.l	dos_base,a6
		move.l	fensthdl,d1
		jsr	Read(a6)
		move.l	d0,speich
		lea.l	filename,a0
		subi.l	#1,speich
		move.l	speich,d0
		clr.b	0(a0,d0)
		move.l	fensthdl,d1
		move.l	dos_base,a6
		jsr	Close(a6)
		jmp	continue
mono:		move.l	dos_base,a6
		move.l	zwi,d2
		and.l	#1,d2
nottest:	cmp.w	#0,d2
		beq	noset
		move.b	#140,puffer
		jmp	gut
noset:		move.b	#32,puffer
gut:		move.l	count,d0
		move.l	#buffer,a0
		move.b	puffer,(a0,d0)
		rts
;---------------------------------------
Zeile1:		move.l	handle,d1
		move.l	#buffer,d2
		move.l	#82,d3
		move.l	dos_base,a6
		jsr	Write(a6)
		rts
color:		move.l	zwi,d0
		cmp.l	#202,d0
		bne	nonichtende
		move.l	#none,a0
		jmp	nottest1
nonichtende:	rol.l	#1,d0
		move.l	#0,zwi
		move.l	#0,adder
		move.l	#colour_map,a0	
		move.w	(a0,d0),zwi
		clr.l	d0
		move.w	zwi,d0
		and.w	#$0f00,d0
		ror.w	#8,d0
		move.w	d0,adder
		clr.l	d0
		move.w	zwi,d0
		and.w	#$f0,d0
		ror.w	#4,d0
		add.w	d0,adder
		clr.l	d0
		move.w	zwi,d0
		and.w	#15,d0
		add.w	d0,adder
		clr.l	d0
		move.w	adder,d0
		ext.w	d0
		rol.l	#3,d0
		move.l	#daten,d1
		add.l	d0,d1
		move.l	d1,a0
nottest1:	move.l	#0,d0
		move.l	pufspei,a1
kli:		move.b	(a0,d0),(a1,d0)
		add.l	#1,d0
		cmp.l	#8,d0
		bne	kli
		add.l	#8,pufspei
		rts
even
fenstname:	dc.b	'CON:0/0/640/200/PosterPrint  1988 Volker Raum / M&T 68oooer',0
even
tename:		dc.b	'Bitte geben Sie den Namen des Bildes an: '
teend:
even
fensthdl:	dc.l	0	
speich:		dc.l	0
even
ypos:		dc.l	0
xp:		dc.l	0
yp:		dc.l	0
spei:		dc.l	0
Drucker:	dc.b	'PAR:',0
pref:		dc.b	27,'3',23,27,'m',4
even
count:		dc.l	0
puffer:		dc.l	0
handle:		dc.l	0
titel:		dc.b	' Markt&Technik 68oooer 1988  ***  Made by Volker Raum on Amiga 1000',13,10
even
kommas:		blk.b	80,45
endkomma:	dc.b	13,10
adder:		dc.l	0
zwi:		dc.l	0
Rastport:	dc.l	0
even
		dc.b	0
daable:		dc.b	27,'*',4,128,2
able:		blk.b	640,0
		dc.b	13,10
buffer:		blk.b	80,0
endbuffer:	dc.b	13,10
even
pufspei:	dc.l	0
zwischen:	dc.l	0
filename:	blk.b	80,0
modus:		dc.b	0
even
daten:
dc.b	255,255,255,255,255,255,255,255
dc.b	255,255,255,255,255,254,255,255
dc.b	191,255,255,255,255,191,255,255
dc.b	255,255,127,247,223,255,255,254
dc.b	255,255,247,255,239,221,255,127
dc.b	255,255,254,237,239,223,254,239
dc.b	255,223,127,119,255,219,125,255
dc.b	254,234,127,237,223,255,239,255
dc.b	247,247,255,127,111,239,201,254
dc.b	255,242,190,123,250,255,127,215
dc.b	179,247,247,239,223,230,211,247
dc.b	249,247,253,252,245, 94,251, 91
dc.b	123,254,191,215, 79,235, 94,234
dc.b	109,223,255,109,246,170,223,135
dc.b	255,245,111, 55,168,221,174,189
dc.b	155,143,237,239, 51,109,159,115
dc.b	172,219,150,206, 91,247,219, 59
dc.b	184,123,159,117,213,180,223, 74
dc.b	 98,198,123,239,154,175,222, 11
dc.b	249,250, 28,123,184,208,158,157
dc.b	235,109,243,146,228,222,136,226
dc.b	150, 59, 35,102,239,144,237, 58
dc.b	180,184,225, 61,173, 53, 13,105
dc.b	156,  4,230,143, 10,217, 77,182
dc.b	114, 74, 58, 89,133, 41, 48,175
dc.b	224, 52,246, 55,139, 28, 36,130
dc.b	152,178,108, 37, 54,241, 34,  5
dc.b	 42,129, 78,241, 16, 49, 12,179
dc.b	 19,172,224, 84,161, 54,132,  9
dc.b	164,  8,212,108,147,  0,132,184
dc.b	 16, 80,  1, 73, 40, 19, 63, 19
dc.b	 14, 24,  1,  1, 40, 32,117, 89
dc.b	 38, 16,164,133, 35,  8, 35,  2
dc.b	 21, 52, 66, 98, 65,130,  1,  8
dc.b	136, 52,  8,  0,129, 69,  0,195
dc.b	  9,  0, 16, 89,133,  9,  0,160
dc.b	  0, 16,128, 24,120,  0,128,193
dc.b	 86,  0,128,  2,  0,  4, 80, 34
dc.b	 72,  2,  0, 48,  4,  0, 17, 12
dc.b	  0,  0,  8, 92, 64,  0,  4, 64
dc.b	  0,  0, 40,  2,  2,  0,  2, 34
dc.b	 32,  0, 72,  0, 64,  4,  0,  0
dc.b	  0, 16,136,  4,  0,  0,  0,  0
dc.b	  0,  0,  1,  0,  0,128,  0,  0
dc.b	  0,  0,  4,  0,  0,  0,  0,  0
none:
dc.b	  0,  0,  0,  0,  0,  0,  0,  0

