	rsreset
* ------- 
ptText		rs.l	1
pause		rs.w	1
* -------
MBcntline	rs.w	1
MBposchar	rs.l	1
MBflagend	rs.w	1
MBposX		rs.w	1
MBcenter	rs.w	1
* -------
ptCopper1	rs.l	1
ptCopper2	rs.l	1
ptCurrentCopper	rs.l	1
flagcoplist	rs.w	1
addBufSin1	rs.l	1
addBufSin2	rs.l	1
ptBufSin1	rs.l	1
ptBufSin1_2	rs.l	1
ptEndBufSin1	rs.l	1
ptBufSin2	rs.l	1
ptBufSin2_2	rs.l	1
ptEndBufSin2	rs.l	1
VARSIZE2	rs.w	0
;--------------------------------------- constant
NumLineas   = 98    		;198
NumColumnas = 53
NumRepeticionesColor = 8 	;minimo 8, sino hay que ampliar la paleta

FontWidthb = 4
FontNumLineas = 5
FontCharsPorLinea = 10


SPL_Init:

	bsr	InitAll
	
	lea		SPL_CopperList,a0
	move.l	a0,Cop1Lch+CustomBase
	clr.w 	CopJmp1+CustomBase
	rts


SPL_Run:
	lea	Vars(pc),a5	
	bsr	DoubleBufCop
	;bsr	DoPlasma	; move sin
	bsr	BlitPlasma	; vertical sin

.fin:
	rts


InitAll:
	lea	Vars(pc),a5

	lea		SPL_CLmb,a0
	move.l	#SPL_BpMb,d0
	moveq	#2-1,d1
	move.l	#44,d2
	bsr		Inst_Plans

	lea		Copper1,a0
	move.l	a0,ptCopper1(a5)
	lea		Copper2,a0
	move.l	a0,ptCopper2(a5)
	lea		BufSin1(pc),a0
	move.l	a0,addBufSin1(a5)
	lea		BufSin2(pc),a0
	move.l	a0,addBufSin2(a5)

	bsr		InitPlasma
	bsr		InitWriter

	rts

* ---------------------------------------------------------
* -------------------------------------------------- Plasma
* ---------------------------------------------------------
InitPlasma:
	lea	SPL_CopperPlasma,a0		;Espacio de la copper para el plasma
	move.l	#$3837fffe,d0	;Primera linea
	move.l	#$01800000,d1	;Color00
	move.l	#$01860000,d2	;Color03

;plasma 180,186
;Probar a pner en 186 en d1 y 180 en d2
;Bonito efecto poiendo 186 y 186 y con el fondo negro

	move.w	#NumLineas-1,d7	;198 lineas de copper
	REPEAT d7 TIMES
		move.l	d0,(a0)+
		move.l	d2,(a0)+	; text color

		move.w	#NumColumnas-1,d6	;53 pseuso columnas		
		REPEAT d6 TIMES
			move.l	d1,(a0)+
		END_REPEAT

		add.l   #$01000000,d0
	END_REPEAT

	;--------------------------------------------
	; Copia de la copper list a Copper1 y Copper2
	;--------------------------------------------
	lea	Copper1,a0
	lea	Copper2,a1
	lea	SPL_CopperList,a2
	move.w	#(SPL_sizecop)/4-1,d0 	;Tamaño.b/4 = Tamaño.l

	REPEAT d0 TIMES
		move.l	(a2),(a0)+
		move.l	(a2)+,(a1)+
	END_REPEAT
	;--------------------------------------------
	; Fin - Copia de la copper list a Copper1 y Copper2
	;--------------------------------------------


;--- sin
	lea		TabSin1(pc),a1
	lea 	BufSin1(pc),a0
	
	move.w	#400-1,d7
	REPEAT d7 TIMES
		moveq	#0,d0
		move.b	(a1)+,d0
		lsl.w	#1,d0	; *2
		move.w	d0,(a0)
		move.w	d0,800(a0)
		move.w	d0,800*2(a0)
		move.w	d0,800*3(a0)
		move.w	d0,800*4(a0)
		addq.w	#2,a0
	END_REPEAT

	move.l	a0,ptEndBufSin1(a5)
	lea		BufSin1(pc),a0
	move.l	a0,ptBufSin1(a5)
	move.l	a0,ptBufSin1_2(a5)

	lea		TabSin1(pc),a1
	lea		BufSin2(pc),a0
	move.w	#100-1,d7
	move.w	#17,d1		;11
	REPEAT d7 TIMES	
		move.b	(a1)+,d0
		lsr.b	#2,d0
		add.b	d1,d0
		move.b	d0,(a0)
		move.b	d0,100*1(a0)
		move.b	d0,100*2(a0)
		move.b	d0,100*3(a0)
		move.b	d0,100*4(a0)
		move.b	d0,100*5(a0)
		move.b	d0,100*6(a0)
		move.b	d0,100*7(a0)
		move.b	d0,100*8(a0)
		move.b	d0,100*9(a0)
		addq.w	#1,a0
	END_REPEAT

	move.l	a0,ptEndBufSin2(a5)
	lea		BufSin2(pc),a0
	move.l	a0,ptBufSin2(a5)
	move.l	a0,ptBufSin2_2(a5)
	rts
;--------
DoubleBufCop:
	bchg	#0,flagcoplist(a5)
	btst	#0,flagcoplist(a5)
	bne.s	.second
	move.l	ptCopper1(a5),ptCurrentCopper(a5)
	move.l	ptCopper1(a5),Cop1Lch+CustomBase
	rts

.second	
	move.l	ptCopper2(a5),ptCurrentCopper(a5)
	move.l	ptCopper2(a5),Cop1Lch+CustomBase
	rts
;---------
DoPlasma:
	move.l	ptEndBufSin1(a5),d0
	move.w	cntloop1(pc),d7

.loop1	
	addq.l	#2,ptBufSin1(a5)
	jif.l 	ptBufSin1(a5),'<>',d0,.next1
	move.l	addBufSin1(a5),ptBufSin1(a5)
.next1	
	dbf	d7,.loop1

	move.l	ptEndBufSin1(a5),d0
	move.l	ptBufSin1_2(a5),d1
	move.w	cntloop2(pc),d7
.loop2	
	addq.w	#2,d1
	cmp.w	d1,d0
	bne.s	.next2
	move.l	addBufSin1(a5),d1
.next2	dbf	d7,.loop2
	move.l	d1,ptBufSin1_2(a5)


	move.l	ptEndBufSin2(a5),d0
	move.w	cntloop3(pc),d7
.loop3	addq.l	#2,ptBufSin2(a5)
	cmp.l	ptBufSin2(a5),d0
	bne.s	.next3
	move.l	addBufSin2(a5),ptBufSin2(a5)
.next3	dbf	d7,.loop3


	move.l	ptEndBufSin2(a5),d0
	move.w	cntloop4(pc),d7
	move.l	ptBufSin2_2(a5),d1
.loop4	addq.w	#2,d1
	cmp.w	d1,d0
	bne.s	.next4
	move.l	addBufSin2(a5),d1
.next4	dbf	d7,.loop4
	move.l	d1,ptBufSin2_2(a5)
	rts

;---------
BlitPlasma:
	movea.l	ptBufSin1(a5),a0
	movea.l	ptBufSin1_2(a5),a1
	move.l	ptCurrentCopper(a5),d0
	add.w	#SPL_CopperPlasma-SPL_CopperList,d0
	addi.w	#10,d0
	move.l	SPL_PaletaEfecto,d1
	move.w	#NumLineas*64+2/2,d3	; bltsize
	move.w	incSin1(pc),d4
	move.w	incSin2(pc),d6
	moveq	#4,d5
	
	gblWaitBlitter 

	move.l	#-1,BltAFwm+CustomBase
	move.l	#$9F00000,BltCon0+CustomBase
	move.w	#0,BltAMod+CustomBase
	move.w	#220-2,BltDMod+CustomBase	; 220-2

	move.w	#NumColumnas-1,d7

	REPEAT d7 TIMES
		move.l	d1,d2
		add.w	(a0),d2
		add.w	(a1),d2
		move.l	d2,BltaPth+CustomBase
		move.l	d0,BltDpth+CustomBase
		move.w	d3,BltSize+CustomBase
		adda.w	d4,a0
		adda.w	d6,a1
		addq.l	#4,d0
		gblWaitBlitter 
	END_REPEAT

	rts
* ---------------------------------------------------------
* --------------------------------------------- Message Box
* ---------------------------------------------------------
InitWriter:
	clr.w	MBflagend(a5)

	lea	CharOffset(pc),a0 			;Crea una tabla con los offsets a las letras
	moveq	#0,d0
	move.w	#40*16,d1 				;Siguiente linea del font. (Bytes)
	move.w	#FontNumLineas-1,d7		;5-1

	REPEAT d7 TIMES
		move.w	#FontCharsPorLinea-1,d6

		REPEAT d6 TIMES
			move.w	d0,(a0)+
			addq.w	#FontWidthb,d0
		END_REPEAT

		add.w	d1,d0
	END_REPEAT

	lea		TextMB(pc),a0
	bsr		CenterText
	bsr		InitColors
	move.w	MBcntline(a5),d7
	lea		TextMB(pc),a0

	rts   	;Birra. Para que no escriba el texto

.loop	
	bsr		CenterLine
	bsr		Writer
	addi.l	#44*18,MBposchar(a5)	; next line
	cmpi.w	#1,MBflagend(a5)
	bne.s	.loop
	rts

;-----
CenterText:
	moveq	#0,d0
	moveq	#1,d1
.loop	
	move.b	(a0),d3
	cmpi.b	#0,d3
	bne.s	.noendline
	addi.w	#18,d0	; H of a line
.noendline
	cmp.b	d1,d3
	beq.s	.endtext
	addq.l	#1,a0	; next char
	bra.s	.loop
.endtext
	move.w	d0,MBcntline(a5)
	move.l	#SPL_BpMb,d1
	subq.w	#6,d0
	move.w	#200,d2	; Hscreen
	sub.w	d0,d2	; Hscreen-Htext
	lsr.w	#1,d2	; /2
	move.w	d2,MBcenter(a5)
	mulu.w	#44,d2		; center*width
	add.w	d2,d1
	move.l	d1,MBposchar(a5)
	rts
;---
InitColors:
	lea		Copper1,a0
	lea		Copper2,a1
	adda.l	#SPL_CopperPlasma-SPL_CopperList,a0
	adda.l	#SPL_CopperPlasma-SPL_CopperList,a1
	move.w	#220,d0	; size of line in copperlist
	move.w	MBcenter(a5),d4
	mulu.w	d0,d4
	adda.w	d4,a0
	adda.w	d4,a1
	move.w	d0,d1
	add.w	d1,d1
	suba.w	d1,a0
	suba.w	d1,a1
	lea		paletteMB(pc),a2
	move.w	MBcntline(a5),d7
	divu.w	#18,d7	; nb lines

	REPEAT d7 TIMES	
		moveq	#16,d6	; H line
		REPEAT d6 TIMES	
			move.w	(a2),6(a0)
			move.w	(a2)+,6(a1)
			adda.w	d0,a0
			adda.w	d0,a1
		END_REPEAT
		
		adda.w	d1,a0
		adda.w	d1,a1
		lea	paletteMB(pc),a2
	END_REPEAT

	rts
;-----
CenterLine:
	movea.l	a0,a1
	moveq	#0,d0
	moveq	#16,d1	; width of char
.loopchar
	cmpi.b	#0,(a1)
	beq.s	.endofline
	add.w	d1,d0
	addq.l	#1,a1
	bra.s	.loopchar
.endofline
	move.w	#44*8,d1	; screen width
	sub.w	d0,d1		; screenwidth-linewidth
	lsr.w	#1,d1		; /2
	move.w	d1,MBposX(a5)
	rts
;-----


WriterfinLinea:
	addq.l	#1,a0
	bra	exitWriter

WriterfinTexto:
	move.w	#1,MBflagend(a5)
	bra		exitWriter


Writer:
	lea	TabChar(pc),a1
	lea	CharOffset(pc),a2
	move.b	(a0),d0

	jif.w 	#0,'=',d0,WriterfinLinea
	jif.w 	#1,'=',d0,WriterfinTexto

.search
	jif.b 	(a1),'=',d0,.blitchar
	addq.l	#1,a1
	addq.l	#2,a2
	bra.s	.search

.blitchar
	moveq	#0,d3
	move.w	(a2),d3 		;Offset de la letra a imprimir
	move.l	#SPL_font,d4 		;Font en d4
	add.l	d4,d3 			;d3 apunta a la letra
	
	move.w	MBposX(a5),d0 	;PosX donde imprimir
	move.w	d0,d1 			
	lsr.w	#3,d0			; /8	
	bclr	#0,d0 			
	andi.w	#$000F,d1
	ror.w	#4,d1
	addi.w	#$0dfc,d1
	move.l	MBposchar(a5),d2
	add.w	d0,d2
	
	gblWaitBlitter 
	
	move.w	d1,BltCon0+CustomBase
	move.w	#0,BltCon1+CustomBase
	move.l	#-1,BltAFwm+CustomBase 	

	move.l	d2,BltDPth+CustomBase 	
	move.l	d2,BltBPth+CustomBase
	move.l	d3,BltAPth+CustomBase
	
	move.w	#40,BltDMod+CustomBase	; 40
	move.w	#40,BltBMod+CustomBase	; 40
	move.w	#36,BltAMod+CustomBase	; 36
	move.w	#16<<6+4/2,BltSize+CustomBase

	addi.w	#16,MBposX(a5)
	addq.l	#1,a0
	bra	Writer

exitWriter
	clr.w	MBposX(a5)
	rts




Inst_plans:		
	move.w	d0,6(a0)
	swap	d0			
	move.w 	d0,2(a0)
	swap	d0
	tst.w	d1
	beq.s	.fin
	add.l	d2,d0
	addq.l	#8,a0
	subq.w	#1,d1
	bra.s	inst_plans
.fin	rts


* ---------------------------------------------------------
Vars	ds.b	VARSIZE2
	even
;-------- messagebox
cntchar	dc.w 16
TabChar dc.b 'ABCDEFGHIJKLMNOPQRSTUVWXYZabc!.,?:0123456789-()+ ',0
TabChar2  
	dc.b 'aaaaaaaaaaaaaaa/0123456789:; = ?_ABCDEFGHIJKLMNOPQRSTUVWXYZB'
	even
CharOffset ds.w	200
	even

TextMB	
	dc.b	'BACK TO FUTURE',0
	dc.b	'INTRO CODED BY BIRRA',0
	DC.B    'GFX BY JOJO073',0
	DC.B    'SFX BY ZOLTAR',0
	dc.b	'- AMIGAWAVE -',0
	dc.b	0
	dc.b	'!1234567890123456789!',0
	dc.b	'+-+-+-+-+-+-+-+-+-+-+',0
	dc.b	1  
	dc.b	0
	even

paletteMB
	dc.w $000,$111,$222,$333,$444,$555,$666,$777,$888,$999,$AAA,$BBB,$CCC,$DDD,$EEE,$FFF

;-------- Plasma
cntloop1 dc.w	2
cntloop2 dc.w	398
cntloop3 dc.w	0
cntloop4 dc.w	98

incSin1  dc.w	5*2
incSin2  dc.w	2*2

TabSin1:	;400 valores entre ff...0...fff
	dc.b $FF,$FF,$FF,$FF,$FF,$FF,$FE,$FE,$FE,$FE	;1
	dc.b $FD,$FD,$FD,$FC,$FC,$FB,$FB,$FA,$FA,$F9
	dc.b $F9,$F8,$F7,$F7,$F6,$F5,$F5,$F4,$F3,$F2
	dc.b $F1,$F0,$EF,$EE,$ED,$EC,$EB,$EA,$E9,$E8
	dc.b $E7,$E5,$E4,$E3,$E2,$E0,$DF,$DE,$DC,$DB
	dc.b $DA,$D8,$D7,$D5,$D4,$D2,$D1,$CF,$CE,$CC
	dc.b $CA,$C9,$C7,$C6,$C4,$C2,$C0,$BF,$BD,$BB
	dc.b $B9,$B8,$B6,$B4,$B2,$B0,$AE,$AD,$AB,$A9
	dc.b $A7,$A5,$A3,$A1,$9F,$9D,$9B,$99,$97,$95
	dc.b $93,$91,$8F,$8D,$8B,$8A,$88,$86,$84,$82	;10
	dc.b $7F,$7D,$7B,$79,$77,$75,$74,$72,$70,$6E
	dc.b $6C,$6A,$68,$66,$64,$62,$60,$5E,$5C,$5A
	dc.b $58,$56,$54,$52,$51,$4F,$4D,$4B,$49,$47
	dc.b $46,$44,$42,$40,$3F,$3D,$3B,$39,$38,$36
	dc.b $35,$33,$31,$30,$2E,$2D,$2B,$2A,$28,$27
	dc.b $25,$24,$23,$21,$20,$1F,$1D,$1C,$1B,$1A
	dc.b $18,$17,$16,$15,$14,$13,$12,$11,$10,$0F
	dc.b $0E,$0D,$0C,$0B,$0A,$0A,$09,$08,$08,$07
	dc.b $06,$06,$05,$05,$04,$04,$03,$03,$02,$02
	dc.b $02,$01,$01,$01,$01,$00,$00,$00,$00,$00	;20
	dc.b $00,$00,$00,$00,$00,$00,$01,$01,$01,$01
	dc.b $02,$02,$02,$03,$03,$04,$04,$05,$05,$06
	dc.b $06,$07,$08,$08,$09,$0A,$0A,$0B,$0C,$0D
	dc.b $0E,$0F,$10,$11,$12,$13,$14,$15,$16,$17
	dc.b $18,$1A,$1B,$1C,$1D,$1F,$20,$21,$23,$24
	dc.b $25,$27,$28,$2A,$2B,$2D,$2E,$30,$31,$33
	dc.b $35,$36,$38,$39,$3B,$3D,$3F,$40,$42,$44
	dc.b $46,$47,$49,$4B,$4D,$4F,$51,$52,$54,$56
	dc.b $58,$5A,$5C,$5E,$60,$62,$64,$66,$68,$6A
	dc.b $6C,$6E,$70,$72,$74,$75,$77,$79,$7B,$7D	;30
	dc.b $80,$82,$84,$86,$88,$8A,$8B,$8D,$8F,$91
	dc.b $93,$95,$97,$99,$9B,$9D,$9F,$A1,$A3,$A5
	dc.b $A7,$A9,$AB,$AD,$AE,$B0,$B2,$B4,$B6,$B8
	dc.b $B9,$BB,$BD,$BF,$C0,$C2,$C4,$C6,$C7,$C9
	dc.b $CA,$CC,$CE,$CF,$D1,$D2,$D4,$D5,$D7,$D8
	dc.b $DA,$DB,$DC,$DE,$DF,$E0,$E2,$E3,$E4,$E5
	dc.b $E7,$E8,$E9,$EA,$EB,$EC,$ED,$EE,$EF,$F0
	dc.b $F1,$F2,$F3,$F4,$F5,$F5,$F6,$F7,$F7,$F8
	dc.b $F9,$F9,$FA,$FA,$FB,$FB,$FC,$FC,$FD,$FD
	dc.b $FD,$FE,$FE,$FE,$FE,$FF,$FF,$FF,$FF,$FF	;40


BufSin1: 
	ds.w 2000	; 70000	2048
BufSin2: 
	ds.w 2000	; 71000


