ùúùú                                        
;««««««««««««««««««««««««««««««««««»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»
;		the drunken hippopotamus
;««««««««««««««««««««««««««««««««««»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»

		incdir	'BinWorld:Includes/'
		include	'graphics_lib¹²00.i'
		include 'exec_lib¹²00.i'
		include	'dos_lib¹²00.i'
		include 'exec/memory.i'
		include 'customcd³².i'
		incdir	'BinWorld:'

INTB_VERTB	=5					;for vblank interrupt.
INTB_COPER	=4					;for copper interrupt.

max_allocations	=4					;maximum vector allocations.

;««««««««««««««««««««««««««««««««««»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»
		section harmonic,code
;««««««««««««««««««««««««««««««««««»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»

beginning:	movem.l	d2-d7/a2-a6,-(SP)		;stack!
		move.l	ExecBase,a6
		lea	DosName,a1
		moveq.l	#39,d0
		jsr	OpenLibrary(a6)
		move.l	d0,DosBase
		beq.w	no_v39_exit
		lea	GfxName,a1
		moveq.l	#39,d0
		jsr	OpenLibrary(a6)
		move.l	d0,GfxBase
		move.l 	d0,a6
	        move.l  $22(a6),old_wb_view		;store current view.
		move.l 	38(a6),old_copper
		move.w	dmaconr+custom,old_dmareq

;««««««««««««««««««««««««««««««««««»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»
;		open a window for output
;««««««««««««««««««««««««««««««««««»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»

		move.l	DosBase,a6			;open a window for
		move.l	#consol_name,d1			;output.
		move.l	#Mode_Old,d2
		jsr	Open(a6)
		move.l	d0,con_handle

;««««««««««««««««««««««««««««««««««»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»
;		poison the system vbr routine ;)
;««««««««««««««««««««««««««««««««««»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»

		move.l	ExecBase,a6
		moveq.l	#INTB_VERTB,d0
		lea	vbr_server,a1
		jsr	AddIntServer(a6)		;add a vbr interrupt.

;««««««««««««««««««««««««««««««««««»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»
;		allocate a chunky buffer
;««««««««««««««««««««««««««««««««««»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»

		move.l	#320*256,d0
		moveq.l	#MEMF_PUBLIC,d1			;the system flags.
		lea	chunky_buffer,a0		;the pointer here.
		bsr.w	allocate_vector			;allocate memory.
		tst.l	d0				;error?
		beq.w	quit				;not enough.

;««««««««««««««««««««««««««««««««««»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»
;		allocate a view buffer
;««««««««««««««««««««««««««««««««««»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»

		move.l	#40*256*8,d0
		move.l	#MEMF_CHIP!MEMF_CLEAR,d1	;the system flags.
		lea	chip_area,a0			;the pointer here.
		bsr.w	allocate_vector			;allocate memory.
		tst.l	d0				;error?
		beq.w	quit				;not enough.

;««««««««««««««««««««««««««««««««««»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»
;		allocate a buffer for precalculations
;««««««««««««««««««««««««««««««««««»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»

		move.l	#256*256*8*2,d0			;one megabyte!
		moveq.l	#MEMF_PUBLIC,d1			;hopefully there is fast memory.
		lea	chunky_area,a0			;the pointer here.
		bsr.w	allocate_vector			;allocate memory.
		tst.l	d0				;error?
		beq.w	quit				;not enough.

;««««««««««««««««««««««««««««««««««»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»
;		allocate a buffer for the chunky to planar system
;««««««««««««««««««««««««««««««««««»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»

		move.l	#320*256,d0
		moveq.l	#MEMF_PUBLIC,d1			;hopefully there is fast memory.
		lea	fast_buffer,a0			;the pointer here.
		bsr.w	allocate_vector			;allocate memory.
		tst.l	d0				;error?
		beq.w	quit				;not enough.

;««««««««««««««««««««««««««««««««««»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»
;		precalculate the chunky transformation table
;««««««««««««««««««««««««««««««««««»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»

		move.l	chunky_area,a0			;pointer to the table.
		bsr.w	prec_chk_table			;do the calculations.

;««««««««««««««««««««««««««««««««««»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»
;		set the pointers and install vbr
;««««««««««««««««««««««««««««««««««»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»

		move.l	chip_area,d0
		lea	intro_planes,a0
		moveq.l	#8-1,d1
		move.l	#10240,d2			;modulus.
		bsr.w	LoadBitplanes			;load planes.

		move.l  GfxBase,a6
		sub.l	a1,a1
                jsr	LoadView(a6)			;flush view to nothing.
		jsr	WaitTOF(a6)			;wait once.
		jsr	WaitTOF(a6)			;wait again.
		move.l	#intro_copper,cop1lc+custom	;install copper list.

;		move.l  GfxBase,a6			;do this twice to correct
;		sub.l	a1,a1				;a bug in the OS.
                jsr	LoadView(a6)			;flush view to nothing.
		jsr	WaitTOF(a6)			;wait once.
		jsr	WaitTOF(a6)			;wait again.
		move.l	#intro_copper,cop1lc+custom	;install copper list.

		lea	intro_palette,a0
		moveq.l	#8-1,d6				;256 colours.
		bsr.w	palettewanker

;««««««««««««««««««««««««««««««««««»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»
;		timberman and his goose
;««««««««««««««««««««««««««««««««««»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»

		clr.l	vbr_delay

connection:	lea	luumaja,a0			;the chunky data.
		move.l	chip_area,a1			;the view.
		move.l	chunky_area,a2			;the table.
		move.w	#160*256/8-1,d0			;this many times.
		bsr.w	chunky_planar			;convert it.
		addq.l	#1,joopa

		cmp.l	#50,vbr_delay
		bge.s	quit

		btst.b	#6,$bfe001			;mouse pressed?
		bne.s	connection			;no.

;««««««««««««««««««««««««««««««««««»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»
;		quit / exit / bye / perish
;««««««««««««««««««««««««««««««««««»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»

quit: 		bsr.w	free_vectors			;free memory.

		move.l	ExecBase,a6
		moveq.l	#INTB_VERTB,d0			;change for vbr
		lea	vbr_server,a1			;interrupt.
		jsr	RemIntServer(a6)		;remove my interrupt.

		move.l	old_wb_view,a1
		move.l	GfxBase,a6
		jsr	LoadView(a6)			;fix the view.
		jsr	WaitTOF(a6)
		jsr	WaitTOF(a6)			;wait for LoadView().
		move.l	old_copper,cop1lc+custom
		move.w	old_dmareq,d0
		or.w	#$8000,d0
		move.w	d0,dmacon+custom
		move.l	DosBase,a6			;close the window.
		move.l	con_handle,d1
		jsr	Close(a6)

;		bsr.b	output_joopa			;output the letters.

		move.l	ExecBase,a6
		move.l	GfxBase,a1
		jsr	CloseLibrary(a6)
		move.l	DosBase,a1
		jsr	CloseLibrary(a6)
no_v39_exit:	movem.l	(SP)+,d2-d7/a2-a6		;unstack!
		moveq.l	#0,d0				;no errors.
		rts

;««««««««««««««««««««««««««««««««««»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»
;		output the frames/second letters
;««««««««««««««««««««««««««««««««««»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»

output_joopa:	move.l	joopa,d0
		lea	version_number,a0
		divu.w	#10,d0
		add.b	#48,d0
		move.b	d0,(a0)+
		swap	d0
		add.b	#48,d0
		move.b	d0,(a0)+
		move.l	#' fra',(a0)+
		move.l	#'mes/',(a0)+
		move.l	#'seco',(a0)+
		move.l	#'nd.0'-38,(a0)
		move.l	DosBase,a6
		jsr	Output(a6)			;get the output.
		move.l	d0,d1				;the handle.
		move.l	#version_number,d2
		moveq.l	#18,d3
		jsr	Write(a6)			;write the text.
		rts

;««««««««««««««««««««««««««««««««««»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»
;		vbr parasite
;««««««««««««««««««««««««««««««««««»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»

vbr_interrupt:	moveq.l	#0,d0				;exit needs this.
		addq.l	#1,vbr_delay
		tst.b	vbr_what			;which one to use?
		beq.s	intro_vbr
		rts					;exit vbr parasite.

;««««««««««««««««««««««««««««««««««»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»
;		intro vbr
;««««««««««««««««««««««««««««««««««»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»

intro_vbr:	movem.l	d0-d7/a0-a6,-(SP)
		movem.l	(SP)+,d0-d7/a0-a6
		rts

;««««««««««««««««««««««««««««««««««»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»
;		universal routines
;««««««««««««««««««««««««««««««««««»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»

		include	'Routines/24bit!palette!user.S'
		include 'Routines/24bit!palette!morpher.S'
		include	'Routines/load!bitplanes.S'
		include	'Routines/memory_32bit.S'
		include	'Routines/chunky_to_planar_2x1.S'
		include	'Routines/chunky_init_2x2.S'
		include	'Routines/align!d0.S'

;««««««««««««««««««««««««««««««««««»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»
		section copurit,data_c
;««««««««««««««««««««««««««««««««««»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»

intro_copper:	dc.w ddfstrt,$38
		dc.w ddfstop,$d0
		dc.w diwstrt,$2c81
		dc.w diwstop,$2cc1
		dc.w bplcon0,%0000000000010000
		dc.w bpl1mod,-8
		dc.w bpl2mod,-8
		dc.w fmode,%11
intro_sprites:	dc.w Spr0pth,0,Spr0ptl,0
		dc.w Spr1pth,0,Spr1ptl,0
		dc.w Spr2pth,0,Spr2ptl,0
		dc.w Spr3pth,0,Spr3ptl,0
		dc.w Spr4pth,0,Spr4ptl,0
		dc.w Spr5pth,0,Spr5ptl,0
		dc.w Spr6pth,0,Spr6ptl,0
		dc.w Spr7pth,0,Spr7ptl,0
		dc.w $2a11,$fffe
intro_planes:	dc.w bpl1pth,0,bpl1ptl,0
		dc.w bpl2pth,0,bpl2ptl,0
		dc.w bpl3pth,0,bpl3ptl,0
		dc.w bpl4pth,0,bpl4ptl,0
		dc.w bpl5pth,0,bpl5ptl,0
		dc.w bpl6pth,0,bpl6ptl,0
		dc.w bpl7pth,0,bpl7ptl,0
		dc.w bpl8pth,0,bpl8ptl,0
		dc.w $ffff,$fffe

;««««««««««««««««««««««««««««««««««»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»
		section	variables,data
;««««««««««««««««««««««««««««««««««»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»

		include	'Routines/memory_32bit_data.S'

old_copper:	dc.l 0
old_dmareq:	dc.l 0
old_wb_view:	dc.l 0

GfxBase:	dc.l 0
GfxName:	dc.b 'graphics.library',0
		even
DosBase:	dc.l 0
DosName:	dc.b 'dos.library',0
		even

vbr_server:	dc.l 0,0				;ln_Succ,ln_Pred
		dc.b 2,0				;ln_Type,ln_Pri
		dc.l int_name				;ln_Name
		dc.l 0,vbr_interrupt			;is_Data,is_Code
int_name:	dc.b "Sweet Mr. Granpa IntLevel3",0
		even

chip_area:	dc.l 0
chunky_area:	dc.l 0
vbr_delay:	dc.l 0
fast_buffer:	dc.l 0
chunky_buffer:	dc.l 0
joopa:		dc.l 0

vbr_what:	dc.b 0

consol_name:	dc.b 'RAW:0/11/500/20/Sweet Mr. Granpa v0.1/NOSIZE/NODRAG',0
		even
con_handle:	dc.l 0

		incdir 'BinWorld:Examples/Sörssö/Data/'
intro_palette:	incbin '160x128.PAL'
luumaja:	incbin '160x128.CHK'
		incbin '160x128.CHK'

version_number:	dc.b '$VER: Sweet Sugar Belly v0.1 (07-Jul-96)',0
		even

		END
