BScreenCurrentScreen	ds.l	1
BScreenCurrentCop	dc.w	0
BScreenCopTable		ds.l	2	;Table inizialized in BScreenInit


*** HARDWAREHACK INTERRUPT HANDLER
BScreenInt3
	move.l	d0,-(sp)
	move.w	$dff01e,d0
	btst.l	#6,d0
	beq.s	.noblit
	bsr	BScreenBlitInt		;<--- Blitter handling called here
	bra.s	BScreenInt3End
.noblit	btst.l	#5,d0
	beq.s	.novb
	bsr.s	BScreenVBInt		;<--- BitPlanes pointers set here
	bra.s	BScreenInt3End
.novb	btst.l	#4,d0
	beq.s	.nocop
	bsr.s	BScreenCopInt		;<--- Call here your Copper int routine
	bra.s	BScreenInt3End
.nocop
* huh ?
	move.w #$0070,$dff09c	;kill all requests to avoid(?) delirium
BScreenInt3End
	move.l	(sp)+,d0
	rte

;****** Handle Vertical Blanking Interrupt *******
BScreenVBInt
	move.w	#$0020,$dff09c	;clear VB request
	movem.l	d0-d1/a0-a1,-(sp)

	lea.l	$dff0e0,a0	;used here

*--- Set Coplist
	lea.l	BScreenCopTable(PC),a1		;table address
	move.w	BScreenCurrentCop(PC),d0	;counter
	move.l	0(a1,d0.w*4),$080-$0e0(a0)	;right address to register
	move.w	d0,$088-$0e0(a0)		;restart coplist
	addq.w	#1,d0				;counter to next
	andi.w	#1,d0				;modulo 2
	move.w	d0,BScreenCurrentCop		;store

*--- Set planes
	move.l	BScreenCurrentScreen(PC),d0
	move.l	#BScreenPlaneSize,d1

	move.l	d0,(a0)+	;first and second plane
	move.l	d0,(a0)+
	add.l	d1,d0
	move.l	d0,(a0)+	;third and fourth
	move.l	d0,(a0)+
	add.l	d1,d0
	move.l	d0,(a0)+	;fifth and sixth
	move.l	d0,(a0)+
	add.l	d1,d0
	move.l	d0,(a0)+	;seventh and eighth
	move.l	d0,(a0)+


*--- All Done
	movem.l	(sp)+,d0-d1/a0-a1
	rts


;******* Handle Copper Interrupt ********
BScreenCopInt
	move.w	#$0010,$dff09c
	rts


;****** Handle Blitter Interrupt ********
BScreenBlitInt
	move.w	#$0040,$dff09c	;clear blit request

	movem.l	d0-d1/a5-a6,-(sp)
	lea.l	$dff000,a5		;Hardware Base Reg
	move.l	bltpc(PC),a6		;Blitter Program Counter

.bltsetreg
	move.l	(a6)+,d0		;next istr for blitter
	move.w	d0,d1 			;copy
	beq.s	.bltintend 		;exit if 0
	swap	d0
	move.w	d0,0(a5,d1.w)		;put value in the right register

	cmp.w	#$5e,d1			;HSize & start ???
	beq.s	.bltstarted		;if yes, start
	cmp.w	#$58,d1			;Size & Start ???
	bne.s	.bltsetreg		;if no, put next
* ---
.bltstarted
	move.l	a6,bltpc		;Store Blitter PC
	movem.l	(sp)+,d0-d1/a5-a6
	rts

.bltintend
	clr.w	bltbsy			;Blitter free for another screen
	movem.l (sp)+,d0-d1/a5-a6
	rts
