;------------------------------------------------!
; *OLD* testroutine, just for checking out how   !
; boring it is not to use the blitter......      !
; I have not modified the original code, which   !
; I wrote a long time ago.. This code CAN be     !
; Optimized in a LOT of ways. Please don't mail  !
; any "why do that, when you can do this", "You  !
; sure are inconsequent" (I was inconsequent!),  !
; "Slow code, this is much faster" (I can also   !
; make this routine faster...), "You brake every !
; bloody rule here boy.." (I did that yes, and   !
; still do, but very faster..:-), "Grrr." and    !
; so on. If you don't like it then get rid of it!!
; You can always use it to look at the patterns  !
; by changing the pointer-speeds!                !
;------------------------------------------------!

	org	$20000
	load	$20000
j:
	move.l 	4,a6
	move.l 	#0,d0
	lea 	gfxname,a1
	jsr 	-408(a6)
	tst 	d0
	beq 	error
	move.l 	d0,a6
	move.l 	38(a6),oldcop
	move.l 	#copperlist,$dff080
	clr.w 	$dff088
	move.w	#$0020,$dff096
	move.w	#$4000,$dff09a

	bsr	main

	move.w	#$8020,$dff096
	move.w	#$c000,$dff09a
	move.l 	oldcop,$dff080
	clr.l 	$dff088
error:	rts

gfxname:dc.b 	'graphics.library',0,0
	even
oldcop:	dc.l 	0

;==============================================================================
screen	=	$40000
width	=	40
height	=	256

sinx_pointer1:	dc.l	sin_xtab
sinx_pointer2:	dc.l	sin_xtab
siny_pointer1:	dc.l	sin_ytab
siny_pointer2:	dc.l	sin_ytab
sinx_add1:	dc.w	4		;change values here to obtain
sinx_add2:	dc.w	2		;new patterns
siny_add1:	dc.w	2
siny_add2:	dc.w	4
sinx_dist1:	dc.w	12
sinx_dist2:	dc.w	6
siny_dist1:	dc.w	2
siny_dist2:	dc.w	14
number:		dc.w	23		;number of 'pobs'
;==============================================================================
main:	bsr	InPtabs
	bsr	Rmasks

.loop:	cmp.b	#$30,$dff006
	bne	.loop
	
	bsr	Swap
	bsr	Clear
	bsr	Calc		
	bsr	Put		
		
	btst	#6,$bfe001
	bne	.loop
	rts

;--------------------------------------------
InPtabs:lea	pob_xbuffer(pc),a0
	move.w	#0,d0
.xloop:	move.w	d0,d1
	move.w	d0,d2
	and.w	#$000f,d1
	lsl.w	#6,d1
	move.w	d1,(a0)+
	and.w	#$fff0,d2
	ror.w	#3,d2
	move.w	d2,(a0)+
	addq	#1,d0
	cmp.w	#width*8,d0
	bne.s	.xloop
		
	lea	pob_ybuffer,a0
	move.w	#0,d0
.yloop:	move.w	d0,d1
	mulu	#width,d1
	add.l	#screen,d1
	move.l	d1,(a0)+
	addq	#1,d0
	cmp.w	#height,d0
	bne.s	.yloop
	rts
;--------------------------------------------
Rmasks:	move.w	#0,d7
	lea	shape_buffer(pc),a1
.loop1:	lea	pob_shape2(pc),a0
	move.w	#16,d6
.loop2:	move.l	(a0)+,d0
	ror.l	d7,d0
	move.l	d0,(a1)+
	subq	#1,d6
	bne.s	.loop2
	addq	#1,d7
	cmp.w	#16,d7
	bne.s	.loop1
	rts
;--------------------------------------------
Clear:	move.l	#screen,d0
	add.w	work_add(pc),d0
	move.l	d0,$dff054
	move.l	#$01000000,$dff040
	move.w	#0,$dff066
	move.w	#$4014,$dff058
	rts
;--------------------------------------------
Wblit:	btst	#6,$dff002
	bne.s	Wblit
	rts
;--------------------------------------------
InPput:	lea	pob_xbuffer(pc),a0
	lea	pob_ybuffer(pc),a1
	lea	shape_buffer(pc),a4
	move.w	work_add(pc),d6
	move.w	#width,d2
	rts
;--------------------------------------------
Swap:	cmp.w	#0,work_add
	beq.s	.set
	move.w	#$0000,work_add
	move.w	#$5000,cop1
	rts
.set:	move.w	#$5000,work_add
	move.w	#$0000,cop1
	rts
;--------------------------------------------
Calc:
	bsr	Inc
	lea	coord_stack(pc),a0
	move.l	sinx_pointer1(pc),a2
	move.l	sinx_pointer2(pc),a3
	move.l	siny_pointer1(pc),a4
	move.l	siny_pointer2(pc),a5
	move.w	number,d7
.loop:	add.w	sinx_dist1(pc),a2
	add.w	sinx_dist2(pc),a3
	cmp.w	#$eeee,(a2)
	bne.s	.not_x1
	suba	#720,a2
.not_x1:cmp.w	#$eeee,(a3)
	bne.s	.not_x2
	suba	#720,a3
.not_x2:move.w	(a2),d0
	add.w	(a3),d0
	add.w	siny_dist1(pc),a4
	add.w	siny_dist2(pc),a5
	cmp.w	#$eeee,(a4)
	bne.s	.not_y1
	suba	#720,a4
.not_y1:cmp.w	#$eeee,(a5)
	bne.s	.not_y2
	suba	#720,a5
.not_y2:move.w	(a4),d1
	add.w	(a5),d1
	move.w	d0,(a0)+
	move.w	d1,(a0)+
	subq	#1,d7
	bne	.loop
	rts
;--------------------------------------------
Inc:	move.l	sinx_pointer1(pc),a0
	add.w	sinx_add1(pc),a0
	cmp.w	#$eeee,(a0)
	bne.s	.skip1
	sub.w	#720,a0
.skip1:	move.l	a0,sinx_pointer1

	move.l	sinx_pointer2(pc),a0
	add.w	sinx_add2(pc),a0
	cmp.w	#$eeee,(a0)
	bne.s	.skip2
	sub.w	#720,a0
.skip2:	move.l	a0,sinx_pointer2

	move.l	siny_pointer1(pc),a0
	add.w	siny_add1(pc),a0
	cmp.w	#$eeee,(a0)
	bne.s	.skip3
	sub.w	#720,a0
.skip3:	move.l	a0,siny_pointer1

	move.l	siny_pointer2(pc),a0
	add.w	siny_add2(pc),a0
	cmp.w	#$eeee,(a0)
	bne.s	.skip4
	sub.w	#720,a0
.skip4:	move.l	a0,siny_pointer2
	rts
;--------------------------------------------
Put:	bsr	InPput
	lea	coord_stack(pc),a5
	move.w	number(pc),d7
.loop:	move.w	(a5)+,d0
	move.w	(a5)+,d1

	add.w	d0,d0
	add.w	d0,d0
	add.w	d1,d1
	add.w	d1,d1
	move.l	(a0,d0.w),d0
	move.l	(a1,d1.w),a3
	add.w	d6,a3
	add.w	d0,a3
	swap	d0
	move.l	a4,a2
	adda	d0,a2
		
	move.l	(a2)+,d0
	or.l	d0,(a3)
	add.w	d2,a3
	move.l	(a2)+,d0
	or.l	d0,(a3)
	add.w	d2,a3
	move.l	(a2)+,d0
	or.l	d0,(a3)
	add.w	d2,a3
	move.l	(a2)+,d0
	or.l	d0,(a3)
	add.w	d2,a3
	move.l	(a2)+,d0
	or.l	d0,(a3)
	add.w	d2,a3
	move.l	(a2)+,d0
	or.l	d0,(a3)

	subq	#1,d7
	bne.s	.loop
	rts

;==============================================================================
shape_buffer:	blk.l	256,0
pob_xbuffer:	blk.l	[width*8],0
pob_ybuffer:	blk.l	height,0

pob_shape:	dc.w	%0000001111000000,0
		dc.w	%0000111111110000,0
		dc.w	%0001111111111000,0
		dc.w	%0011111111111100,0
		dc.w	%0011111111111100,0
		dc.w	%0111111111111110,0
		dc.w	%1111111111111111,0
		dc.w	%1111111111111111,0
		dc.w	%1111111111111111,0
		dc.w	%1111111111111111,0
		dc.w	%0111111111111110,0
		dc.w	%0011111111111100,0
		dc.w	%0011111111111100,0
		dc.w	%0001111111111000,0
		dc.w	%0000111111110000,0
		dc.w	%0000001111000000,0

pob_shape2:	dc.w	%0000000110000000,0
		dc.w	%0000000110000000,0
		dc.w	%0000011111100000,0
		dc.w	%0000011111100000,0
		dc.w	%0000000110000000,0
		dc.w	%0000000110000000,0
work_add:	dc.w	0

coord_stack:	blk.l	500,0

sin_xtab:
	dc.w	75,76,78,79,80,82,83,84
	dc.w	85,87,88,89,91,92,93,94
	dc.w	96,97,98,99,101,102,103,104
	dc.w	106,107,108,109,110,111,112,114
	dc.w	115,116,117,118,119,120,121,122
	dc.w	123,124,125,126,127,128,129,130
	dc.w	131,132,132,133,134,135,136,136
	dc.w	137,138,139,139,140,141,141,142
	dc.w	142,143,144,144,145,145,145,146
	dc.w	146,147,147,147,148,148,148,149
	dc.w	149,149,149,149,150,150,150,150
	dc.w	150,150,150,150,150,150,150,150
	dc.w	150,149,149,149,149,149,148,148
	dc.w	148,147,147,147,146,146,145,145
	dc.w	145,144,144,143,142,142,141,141
	dc.w	140,139,139,138,137,136,136,135
	dc.w	134,133,132,132,131,130,129,128
	dc.w	127,126,125,124,123,122,121,120
	dc.w	119,118,117,116,115,114,113,111
	dc.w	110,109,108,107,106,104,103,102
	dc.w	101,99,98,97,96,94,93,92
	dc.w	91,89,88,87,85,84,83,82
	dc.w	80,79,78,76,75,74,72,71
	dc.w	70,68,67,66,65,63,62,61
	dc.w	59,58,57,56,54,53,52,51
	dc.w	49,48,47,46,44,43,42,41
	dc.w	40,39,38,36,35,34,33,32
	dc.w	31,30,29,28,27,26,25,24
	dc.w	23,22,21,20,19,18,18,17
	dc.w	16,15,14,14,13,12,11,11
	dc.w	10, 9, 9, 8, 8, 7, 6, 6
	dc.w	 5, 5, 5, 4, 4, 3, 3, 3
	dc.w	 2, 2, 2, 1, 1, 1, 1, 1
	dc.w	 0, 0, 0, 0, 0, 0, 0, 0
	dc.w	 0, 0, 0, 0, 0, 1, 1, 1
	dc.w	 1, 1, 2, 2, 2, 3, 3, 3
	dc.w	 4, 4, 5, 5, 5, 6, 6, 7
	dc.w	 8, 8, 9, 9,10,11,11,12
	dc.w	13,14,14,15,16,17,18,18
	dc.w	19,20,21,22,23,24,25,26
	dc.w	27,28,29,30,31,32,33,34
	dc.w	35,36,37,39,40,41,42,43
	dc.w	44,46,47,48,49,51,52,53
	dc.w	54,56,57,58,59,61,62,63
	dc.w	65,66,67,68,70,71,72,74
	dc.w	75
	dc.w	$eeee,$eeee,$eeee,$eeee
	dc.w	$eeee,$eeee,$eeee,$eeee
	dc.w	$eeee,$eeee,$eeee,$eeee
	dc.w	$eeee,$eeee,$eeee,$eeee
	dc.w	$eeee,$eeee,$eeee,$eeee
	dc.w	$eeee,$eeee,$eeee,$eeee
	dc.w	$eeee,$eeee,$eeee,$eeee
	dc.w	$eeee,$eeee,$eeee,$eeee
	dc.w	$eeee,$eeee,$eeee,$eeee
	dc.w	$eeee,$eeee,$eeee,$eeee


sin_ytab:
	dc.w	57,59,60,61,62,63,64,65
	dc.w	66,66,67,68,69,70,71,72
	dc.w	73,74,75,76,77,78,79,80
	dc.w	81,82,83,84,84,85,86,87
	dc.w	88,89,90,90,91,92,93,94
	dc.w	94,95,96,97,97,98,99,100
	dc.w	100,101,102,102,103,103,104,105
	dc.w	105,106,106,107,107,108,108,109
	dc.w	109,110,110,110,111,111,112,112
	dc.w	112,112,113,113,113,114,114,114
	dc.w	114,114,114,115,115,115,115,115
	dc.w	115,115,115,115,115,115,115,115
	dc.w	115,115,114,114,114,114,114,114
	dc.w	113,113,113,112,112,112,112,111
	dc.w	111,110,110,110,109,109,108,108
	dc.w	107,107,106,106,105,105,104,103
	dc.w	103,102,102,101,100,100,99,98
	dc.w	97,97,96,95,94,94,93,92
	dc.w	91,90,90,89,88,87,86,85
	dc.w	84,84,83,82,81,80,79,78
	dc.w	77,76,75,74,73,72,71,70
	dc.w	69,68,67,66,66,65,64,63
	dc.w	62,61,60,59,58,56,55,54
	dc.w	53,52,51,50,49,49,48,47
	dc.w	46,45,44,43,42,41,40,39
	dc.w	38,37,36,35,34,33,32,31
	dc.w	31,30,29,28,27,26,25,25
	dc.w	24,23,22,21,21,20,19,18
	dc.w	18,17,16,15,15,14,13,13
	dc.w	12,12,11,10,10, 9, 9, 8
	dc.w	 8, 7, 7, 6, 6, 5, 5, 5
	dc.w	 4, 4, 3, 3, 3, 3, 2, 2
	dc.w	 2, 1, 1, 1, 1, 1, 1, 0
	dc.w	 0, 0, 0, 0, 0, 0, 0, 0
	dc.w	 0, 0, 0, 0, 0, 0, 1, 1
	dc.w	 1, 1, 1, 1, 2, 2, 2, 3
	dc.w	 3, 3, 3, 4, 4, 5, 5, 5
	dc.w	 6, 6, 7, 7, 8, 8, 9, 9
	dc.w	10,10,11,12,12,13,13,14
	dc.w	15,15,16,17,18,18,19,20
	dc.w	21,21,22,23,24,25,25,26
	dc.w	27,28,29,30,31,31,32,33
	dc.w	34,35,36,37,38,39,40,41
	dc.w	42,43,44,45,46,47,48,49
	dc.w	49,50,51,52,53,54,55,56
	dc.w	57
	dc.w	$eeee,$eeee,$eeee,$eeee
	dc.w	$eeee,$eeee,$eeee,$eeee
	dc.w	$eeee,$eeee,$eeee,$eeee
	dc.w	$eeee,$eeee,$eeee,$eeee
	dc.w	$eeee,$eeee,$eeee,$eeee
	dc.w	$eeee,$eeee,$eeee,$eeee
	dc.w	$eeee,$eeee,$eeee,$eeee
	dc.w	$eeee,$eeee,$eeee,$eeee
	dc.w	$eeee,$eeee,$eeee,$eeee
	dc.w	$eeee,$eeee,$eeee,$eeee

;==============================================================================
copperlist:
	dc.l 	$008e2c81,$00902cc1
	dc.l 	$00920038,$009400d0
	dc.l 	$01001200	
	dc.l	$01800000
	dc.l 	$01820ff0
	dc.l 	$00e00004
	dc.w	$00e2
cop1:	dc.w	$0000
	dc.w 	$ffff,$fffe
