***********************************************************
*----------------- System Text routine  05 [DEVPAC]
*----------- By Maurice `Digital Dictator` Wielink 	
*--------- Coded (exclusive) for NEWSFLASH Magazine
*---------------------------- PAL
***********************************************************
LineLen		equ	31		
CharSpeed	equ	3		0 = Fast / Higher then 0 = Slower
DisplayTime	equ	100		0 = Fast / Higher then 0 = Slower	

		movem.l	d0-d7/a0-a6,-(a7)
		bra	BOOST
*************************************************
*-----------------------------------------------*
MESSY_TEXT:	MOVEA.L	GfxBase,A6		;GfxBase at a6
DoText:		lea	Text(pc),A4		;Address of Text Data at a4
		move.l	#20,d6			;Reset Y
NextTxt:	lea	PosTable(pc),a3		;A3 = Character Position List		
		move.l	#LineLen-1,d7		;Nr of Chars -1 (for DBRA)		

NextChar:	move.b	(a3)+,d0		;Get Char Position from List
		andi.l	#$FF,d0			;Only Last BYTE Needed !
		lea	0(a4,d0),a5		;Get Right Character at a5
		mulu	#10,d0			;Calculate X Coord
		addq	#5,d0			;X = X + 5 (First X = 5)

		move.w	d6,d1			;Y coord
		movea.l	WD_RastPort,A1		;Windows RastPort			
		JSR	-$F0(A6)		;_LVOMove
		movea.l	a5,A0			;Text(A5) at A0
		moveq	#1,D0			;We'll Print One Character !
		JSR	-$3C(A6)		;Print It !

		btst	#6,$BFE001		;Check Left Mouse Button !
		beq	Quit	 		;Quit if Button was Down.

		cmp.b	#" ",(a5)		;Was Character a Space ?
		beq.s	NoDelay			;If So, No Delay
		move.l	#CharSpeed,d5		;Otherwise, Delayvalue in D5
		jsr	Delay(pc)		;and use our Delay Routine !
NoDelay		dbra	d7,NextChar		;Next Character
		*--------------------*
		add.l	#10,d6			;Next Y Coord
		cmp.w	#250,d6			;End of Screen ?
		bne.s	_YOk			;Skip if not

		move.l	#DisplayTime,d5		;Hold Page for a Moment
		jsr	Delay(pc)
		jsr	E05_Erase(pc)
		move.l	#20,d6			;Reset Y

_YOk		lea	31(a4),a4		;Find Next Line (a4 + 31) 
		cmp.l	#TextEnd,a4		;End of text ?
		bne	NextTxt			;Branch if not .....
		bra	DoText 			;Reset if it is !
*-----------------------------------------------*
E05_Erase	move.l	#20,d6			;Y
_E05_EraseNL	lea	PosTable(pc),a3		;A3 = Character Position List		
		move.l	#LineLen-1,d7		;Nr of Chars -1 (for DBRA)		
_E05_EraseChar	move.b	(a3)+,d0		;Get Char Position from List
		andi.l	#$FF,d0			;Only Last BYTE Needed !
		mulu	#10,d0			;Calculate X Coord
		addq	#5,d0			;X = X + 5 (First X = 5)
		move.w	d6,d1			;Y coord
		movea.l	WD_RastPort,A1		;Windows RastPort			
		JSR	-$F0(A6)		;_LVOMove
		move.b	#" ",(A0)		;Print a SPACE
		moveq	#1,D0			;We'll Print One Character !
		JSR	-$3C(A6)		;Print It !
		move.l	#0,d5			;Delayvalue in D5
		jsr	Delay(pc)		;and use our Delay Routine !
		dbra	d7,_E05_EraseChar
		add.l	#10,d6			;next Y (Depends on Font)
 		cmp.w	#250,d6
		bne.s	_E05_EraseNL
		rts

*****************************************************************************
*-------------- Open Libraries, Screen, Window, Set colors

BOOST		lea	IntName(pc),A1		;Intuition.lib Name
		MOVEQ	#0,D0
		MOVEA.L	4.W,A6			;ExecBase at A6
		JSR	-$228(A6)		;Open IntLib
		MOVE.L	D0,IntBase		;Save Address
		BEQ	_Error			;Branch incase of Error

		lea	GfxName(pc),A1
		MOVEQ	#0,D0
		JSR	-$228(A6)		;Open GfxLib (ExecBase at A6)
		MOVE.L	D0,GfxBase		;Save Address
		BEQ	_CloseInt

		lea	NewScreen(pc),A0	;Screen Structure
		MOVEA.L	IntBase,A6		;IntBase
		JSR	-$C6(A6)		;OpenScreen
		MOVE.L	D0,ScreenBase		;Save ScreenBase
		BEQ	_CloseGfx		;branch incase of Error

		MOVEA.L	d0,A0			;ScreenBase at a0
		LEA	$2C(A0),A0		;Find Screens ViewPort
		MOVE.L	A0,Scr_ViewPort		;Save Screens Viewport

		LEA	CMap(pc),A1		;CMap
		MOVEQ	#2,D0			;Nr of Colors
		MOVEA.L	GfxBase,A6		;GfxBase
		JSR	-$C0(A6)		;Load RGB4
		LEA	NewWindow(pc),A0	;Window Structure
		MOVE.L	ScreenBase,D0		;ScreenBase
		MOVE.L	D0,$1E(A0)		;Store ScrPTR in Window		
		MOVEA.L	IntBase,A6		;IntBase
		JSR	-$CC(A6)		;OpenWindow
		MOVE.L	D0,WindowBase		;Save  Window Base
		BEQ	_CloseScreen		;branch incase of Error

		MOVEA.L	d0,A0			;WindowBase at a0
		MOVE.L	$32(A0),WD_RastPort	;Save address of RastPort.

		MOVEA.L	GfxBase,A6		;GfxBase
		MOVEA.L	WD_RastPort,A1		;WD_RastPort
		MOVEQ.L	#1,D0			;Color in CMap
		JSR	-$156(A6)		;SetAPen

		MOVE.W	#$3A,$DFF096		;Remove Mouse Pointer
		MOVEA.L	4,A6			;ExecBase
		JSR	-$84(A6)		;Forbid

		BRA	MESSY_TEXT		;START !!!
*-----------------------------------------------*
*------ Delay Routine -> Store Delay Value in D5

Delay		btst	#6,$BFE001		;Check for Abort
		beq.s	_Delex
		cmpi.b	#200,$DFF006		;Check Vertical Beam Position
		bne.s	Delay			;If not 200, Loop
		dbf	d5,Delay			
_Delex		rts
*-----------------------------------------------*
*-------------- Clean Up

Quit		MOVEA.L	4,A6				
		JSR	-$8A(A6)			;Permit
		MOVE.W	#$803A,$DFF096			;Mouse Pointer Back
_CloseWindow	MOVEA.L	WindowBase,A0			;Window Base
		MOVEA.L	IntBase,A6			;IntBase
		JSR	-$48(A6)			;Close Window
_CloseScreen	MOVEA.L	ScreenBase,A0			;ScreenBase
		MOVEA.L	IntBase,A6			;IntBase
		JSR	-$42(A6)			;CloseScreen
_CloseGfx	MOVEA.L	GfxBase,A1			;GfxBase
		MOVEA.L	4.W,A6				;ExecBase
		JSR	-$19E(A6)			;Close Library	
_CloseInt	MOVEA.L	IntBase,A1			;IntBase
		MOVEA.L	4.W,A6 				;ExecBase
		JSR	-$19E(A6)			;Close Library
_Error		movem.l	(a7)+,d0-d7/a0-a6
		RTS					;and Exit !
*****************************************************************************
*----------------------- STRUCTURES and DATA -------------------------------*

*-------------- NewScreen Structure
		even
NewScreen	dc.w	0,0,320,256	  ;Left, Top, Width, Height
		dc.w	2		  ;number of bitplanes
		dc.b	0,0		  ;detail , block pen
		dc.w	0,$f+$100	  ;Low-Res,CustomScreen+ScreenQuiet
		dc.l	DefaultFont,0,0,0

*-------------- Font

DefaultFont:	dc.l	FontName
		dc.w	8		;Size
		dc.b	0,0
FontName:	dc.b	'topaz.font',0

*-------------- NewWindow Structure
		even
NewWindow:	dc.w	0,0,320,256
		dc.b	0,0	
		dc.l	0,$1000+$0800+$0100
		dc.l	0,0,0,0,0	
		dc.w	320,256,320,256,$F

*-------------- Library Names

IntName		dc.b	'intuition.library',0
GfxName 	dc.b	'graphics.library',0

*-------------- Pointers
		even
ScreenBase 	dc.l	0			;ScreenBase
Scr_ViewPort 	dc.l	0			;Screen ViewPort 
WindowBase 	dc.l	0			;WindowBase
WD_RastPort	dc.l	0			;WD_RastPort
IntBase 	dc.l	0			;IntBase
GfxBase 	dc.l	0			;GfxBase

*-------------- Color Map

CMap:		dc.w	$000,$5fa		

*-------------- Caracter Position List
		
PosTable	dc.b	15,23,7,17,28,18,5,26,4,27,0,13,2,21,12,19
		dc.b	1,24,10,29,3,22,8,16,14,20,6,25,11,30,9

*-------------- Text Data
		even
Text:		dc.b	'  Another System Text Routine  '
		dc.b	'          coded by             '
		dc.b	'       Maurice Wielink         '
		dc.b	'      Hondemanstraat 51        '
		dc.b	'      1508 GA - Zaandam        '
		dc.b	'       The Netherlands         '
		dc.b	'                               '
		dc.b	'   Coded for the programming   '
		dc.b	' section on NEWSFLASH Magazine '
		dc.b	'                               '
		dc.b	'The Character Speed + the Page '
		dc.b	' Display time can be changed ! '
		dc.b	'                               '
		dc.b	'Character-Speed is the Time to '
		dc.b	'wait before the next character '
		dc.b	'       appears on screen.      '
		dc.b	'                               '
		dc.b	'  Display-Time is the time to  '
		dc.b	'  wait before the page will go '
		dc.b	'away after its filled with text'
		dc.b	'                               '
		dc.b	' Hope you can use this source !'
		dc.b	'           --------            '
TextEnd:
;The
 end 

