*****************************************************************************
;   Raster routine - simple raster bar move routine using the blitter,
;		   - taken from the STOLEN DATA intro

;  Copyright - Kreator of ANARCHY
*****************************************************************************

	Incdir	DF1:
	Include	Source/CustomRegisters	; Contains custom reg. equates
	Section	Base,Code_c		; Ensure it assembles into chip mem.

Trap_vec0	= $80
Execbase	= $4
Oldopen		= -$198

	Movem.l	d0-d7/a0-a6,-(a7)
	Move.l	#Start,Trap_vec0
	Trap	#0		; Jump into "Start" routine in Supervisor mode
	Movem.l	(a7)+,d0-d7/a0-a6
	Rts

Start
	Bsr	Killsys
	Bsr	Setup
	Bsr	Main
	Bsr	Sysreturn
	Rte			;Executed with a TRAP instr. (Exception)

*****************************************************************************
;Killsys - Disable operating system and interrupts
*****************************************************************************
Killsys	Move	Intenar,Int_set	; Remember interrupt status
	Move	#$7fff,Intena
	Move.l	$6c.w,Vbl_vec	; Store Vbalnk interrupt vector
	Move	Dmaconr,Dma_set
	Move	#$7fff,Dmacon
	Move	#$87cf,Dmacon	; Set the DMA enable status
	Move.l	Execbase,a6
	Lea	Gfxname(pc),a1
	Jsr	Oldopen(a6)
	Move.l	d0,a5
	Move.l	38(a5),Sys_copl	; Save the system copperlist
	Move.l	#Clstart,Cop1lch	; Start our own copperlist
	Clr	Copjmp1
	Rts

Int_set		Dc.w 0
Dma_set		Dc.w 0
Sys_copl	Dc.l 0
Vbl_vec		Dc.l 0
Gfxname		Dc.b "graphics.library",0
	Even
*****************************************************************************
;Sysreturn - Re-enable operating system and interrupts
*****************************************************************************
Sysreturn
	Move	#$7fff,Intena
	Move.l	Vbl_vec(pc),$6c.w	; Restore the Vblank int. vector
	Move	Int_set(pc),d0
	Or	#$c000,d0
	Move	d0,Intena	; Start up interrupts again
	Move	#$7fff,Dmacon
	Move	Dma_set(pc),d0
	Or	#$8200,d0
	Move	d0,Dmacon	; Restore DMA status
	Move.l	Sys_copl,Cop1lch
	Clr	Copjmp1		; Restore the system copperlist
	Rts
*****************************************************************************
; Main - Central demo calling routine + mouse button check
*****************************************************************************
Main
	Move.l	$dff004,d0
	And.l	#$1ff00,d0
	Cmp.l	#$01000,d0	; Wait for vert. pos. 16
	Bne.s	Main

	Bsr	Rasters

	Btst	#6,$bfe001	; Check left mouse button
	Bne.s	Main
	Rts

*****************************************************************************
; Setup routine
*****************************************************************************
Setup
	;	No routines to setup really
	Rts

*****************************************************************************
; Raster effects
*****************************************************************************
Rasters
	Lea	Logo_bars+6(pc),a0	; Clear the old rasters
	Move.l	#-1,Bltafwm
	Move.l	#$00000006,Bltamod
	Move.l	#$1f00000,Bltcon0
	Clr	Bltadat
	Move.l	a0,Bltdpth
	Move	#136*64+1,Bltsize
Clr_wait
	Btst	#14,Dmaconr		; Wait for the blitter to finish
	Bne.s	Clr_wait

	Lea	Sintable(pc),a1
	Add.b	#2,Bar_pt+1
	Move	Bar_pt(pc),d0		; Get the new sine pointer

	Move.l	#$9f00000,Bltcon0	; Set the blitter ready for
	Move.l	#Bar_cols,Bltapth	; blitting the raster bars into
	Move	#37,d1			; the copperlist (38 of them)
	Moveq	#0,d2
Rast_loop
	Move.b	(a1,d0),d2
	Lsl	#2,d2
	And	#$3f8,d2		; Each line of the copperlist is
					; 8 bytes apart
	Lea	(a0,d2),a2
	Move.l	a2,Bltdpth
	Move	#64*8+1,Bltsize		; Each bar is 8 lines deep
	Addq.b	#6,d0		
Blitit
	Btst	#14,Dmaconr
	Bne.s	Blitit
	Dbf	d1,Rast_loop
	Rts

*****************************************************************************
; Variables
*****************************************************************************

Bar_pt		Dc.w 0

*****************************************************************************
; Copperlists
*****************************************************************************
Clstart
	Mov	$1a64,Diwstrt
	Mov	$39d1,Diwstop
	Mov	$0030,Ddfstrt
	Mov	$00d8,Ddfstop
	Mov	0,Bplcon0

Logo_bars
A set 0
	Rept	136
	Wait	222,(90+A)&$ff
	Mov	0,Color00
A set A+1
	Endr

	Wait	$fe,$ff

*****************************************************************************
; Binaries
*****************************************************************************
Sintable
	Incbin	Binary/Sin1	;256 byte long sintable

Bar_cols
	Dc.w	$600,$900,$c00,$f00,$f00,$c00,$900,$600
	Dc.w	$601,$903,$c04,$f06,$f06,$c04,$903,$601
	Dc.w	$603,$905,$c08,$f0b,$f0b,$c08,$905,$603
	Dc.w	$606,$909,$c0c,$f0f,$f0f,$c0c,$909,$606
	Dc.w	$306,$509,$80c,$b0f,$b0f,$80c,$509,$306
	Dc.w	$106,$309,$50c,$60f,$60f,$50c,$309,$106
	Dc.w	$006,$009,$00c,$00f,$00f,$00c,$009,$006
	Dc.w	$016,$039,$05c,$06f,$06f,$05c,$039,$016
	Dc.w	$036,$059,$08c,$0bf,$0bf,$08c,$059,$036
	Dc.w	$066,$099,$0cc,$0ff,$0ff,$0cc,$099,$066
	Dc.w	$063,$095,$0c8,$0fb,$0fb,$0c8,$095,$063
	Dc.w	$061,$093,$0c5,$0f6,$0f6,$0c5,$093,$061
	Dc.w	$060,$090,$0c0,$0f0,$0f0,$0c0,$090,$060
	Dc.w	$160,$390,$5c0,$6f0,$6f0,$5c0,$390,$160
	Dc.w	$360,$590,$8c0,$bf0,$bf0,$8c0,$590,$360
	Dc.w	$660,$990,$cc0,$ff0,$ff0,$cc0,$990,$660
	Dc.w	$630,$950,$c80,$fb0,$fb0,$c80,$950,$630
	Dc.w	$610,$930,$c50,$f60,$f60,$c50,$930,$610
	Dc.w	$600,$900,$c00,$f00,$f00,$c00,$900,$600
	Dc.w	$600,$900,$c00,$f00,$f00,$c00,$900,$600
	Dc.w	$601,$903,$c04,$f06,$f06,$c04,$903,$601
	Dc.w	$603,$905,$c08,$f0b,$f0b,$c08,$905,$603
	Dc.w	$606,$909,$c0c,$f0f,$f0f,$c0c,$909,$606
	Dc.w	$306,$509,$80c,$b0f,$b0f,$80c,$509,$306
	Dc.w	$106,$309,$50c,$60f,$60f,$50c,$309,$106
	Dc.w	$006,$009,$00c,$00f,$00f,$00c,$009,$006
	Dc.w	$016,$039,$05c,$06f,$06f,$05c,$039,$016
	Dc.w	$036,$059,$08c,$0bf,$0bf,$08c,$059,$036
	Dc.w	$066,$099,$0cc,$0ff,$0ff,$0cc,$099,$066
	Dc.w	$063,$095,$0c8,$0fb,$0fb,$0c8,$095,$063
	Dc.w	$061,$093,$0c5,$0f6,$0f6,$0c5,$093,$061
	Dc.w	$060,$090,$0c0,$0f0,$0f0,$0c0,$090,$060
	Dc.w	$160,$390,$5c0,$6f0,$6f0,$5c0,$390,$160
	Dc.w	$360,$590,$8c0,$bf0,$bf0,$8c0,$590,$360
	Dc.w	$660,$990,$cc0,$ff0,$ff0,$cc0,$990,$660
	Dc.w	$630,$950,$c80,$fb0,$fb0,$c80,$950,$630
	Dc.w	$610,$930,$c50,$f60,$f60,$c50,$930,$610
	Dc.w	$600,$900,$c00,$f00,$f00,$c00,$900,$600

