
MAIN = 1	; 0 = ASM | 1 = object file

;--------------------------------------------------------------------
;	FastGFX Show	©  Copyright 1993 by Ralf Thanner
;					     Ellerstr. 83
;					  40227  Duesseldorf
;					       Germany
;
;	Version:	v0.2
;	Date:		01/06/93
;
;	- just a little text writer to show how often the patched
;	  routines have been executed (or skipped).
;
;--------------------------------------------------------------------
; a6 = $dff000	(oder execbase)
; a5 = pointer auf globales Variablenfeld (VAR)
;--------------------------------------------------------------------
;
;
;--------------------------------------------------------------------
;                 ********** Allgemeine Konstanten ***********
;--------------------------------------------------------------------
; no includes to ensure this proggy works on every Amiga!-)
;=====================================================================
disable		EQU	-120	; 	Exec.library
enable		EQU	-126
forbid		EQU	-132
permit		EQU	-138
allocmem	EQU	-198
freemem		EQU	-210
availmem	EQU	-216
findname	EQU	-276
addtask		EQU	-282
findtask	EQU	-294
settaskpri	EQU	-300
allocsignal	EQU	-330
freesignal	EQU	-336
addport		EQU	-354
RemPort		EQU	-360
putmsg		EQU	-366
getmsg		EQU	-372
replymsg	EQU	-378
waitport	EQU	-384
findport	EQU	-390
closelib	EQU	-414
SetFunction	equ	-420
OpenDevice	EQU	-444
CloseDevice	EQU	-450
doio		EQU	-456
openresource	EQU	-498
RawDoFmt:	EQU	-522
openlib		EQU	-552
open		EQU	-30	;	Dos.library
close		EQU	-36
read		EQU	-42
write		EQU	-48
output		EQU	-60
seek		EQU	-66
delete		EQU	-72
Lock		EQU	-84
UnLock		EQU	-90
Info		EQU	-114
loadseg		EQU	-150
unloadseg	EQU	-156
deviceproc	EQU	-174
delay		EQU	-198
mode_rw		EQU	1004
mode_old	EQU	1005
mode_new	EQU	1006

SetApen		EQU	-342	; gfx -> patched vectors
SetBpen		EQU	-348
SetDrMod	EQU	-354
WritePixel	EQU	-324
;=====================================================================

POWER:
	movem.l		d0-d7/a0-a6,-(a7); save registers

 IFEQ MAIN
	bra.b	cli_call
 ENDC

	move.l		$04.w,a6
	suba.l		a1,a1
	jsr	findtask(a6)
	move.l		d0,a4

	tst.l		$ac(a4)
	bne.b	cli_call

* Worbench Part (und direkt wieder raus!)

	lea		$5c(a4),a0
	jsr	waitport(a6)
	lea		$5c(a4),a0
	jsr	getmsg(a6)
	move.l		d0,A4	; WB_Message

	jsr	forbid(a6)
	move.l		A4,a1
	jsr	replymsg(a6)
	movem.l 	(a7)+,d0-d7/a0-a6
	moveq		#00,d0
	rts

* CLI-PARAMETER HANDLER

cli_call:
	movem.l 	(a7),d0-d7/a0-a4

	lea		VAR(pc),a5	; to avoid RELOC_32 hunks

	lea		GFXname(pc),a1
	moveq		#$21,d0
	jsr	openlib(a6)
	move.l		d0,Gfxbase-var(a5)

	lea.l		Dosname(pc),a1
	moveq		#$21,d0
	jsr	openlib(a6)
	move.l		d0,dosbase-var(a5)

	move.l		d0,a6
	jsr	output(a6)
	move.l		d0,outputhandle-var(a5)

	lea		mes0(pc),a0
	move.l		#mes0length,d3
;	moveq		#$fc,d3
	bsr.w	writer			; Copyright TXT
;---------------------------------------------------------------------
	move.l		gfxbase(pc),a0
	move.l		setapen+2(a0),a1
	move.l		a1,a3			; Mein Patch (?!?)

	move.l		-44(a1),d1
	swap		d1
	cmp.w		#'SP',d1
	beq.b	speed_test_installed		; Zahlen auswerten

	move.l		-20(a1),d1
	swap		d1
	cmp.w		#'RT',d1
	beq.b	real_patch_installed		; real FastGFX installed

	bra.w	Patch_not_installed		; weder noch...

real_patch_installed:
	lea		mes2(pc),a0
	move.l		#mes2length,d3
	bra.w	Patch_not_installed_01

speed_test_installed:
	lea		-$18(a1),a1
	movem.l		(a1)+,d0-d5

	lea		txtvariablen(pc),a0
	lea		exe_TXT(pc),a2
	lea		skip_TXT(pc),a3
;--------------------------------
	lea		SA_TXT(pc),a1
	move.l		a1,(a0)+
	move.l		a2,(a0)+
	move.l		d0,(a0)+

	move.l		a1,(a0)+
	move.l		a3,(a0)+
	move.l		d1,(a0)+
;--------------------------------
	lea		SB_TXT(pc),a1
	move.l		a1,(a0)+
	move.l		a2,(a0)+
	move.l		d2,(a0)+

	move.l		a1,(a0)+
	move.l		a3,(a0)+
	move.l		d3,(a0)+
;--------------------------------
	lea		SDR_TXT(pc),a1
	move.l		a1,(a0)+
	move.l		a2,(a0)+
	move.l		d4,(a0)+

	move.l		a1,(a0)+
	move.l		a3,(a0)+
	move.l		d5,(a0)+

;--------------------------------
	moveq		#0,d6
	moveq		#0,d7
	add.l		d0,d6
	add.l		d2,d6
	add.l		d4,d6

	add.l		d1,d7
	add.l		d3,d7
	add.l		d5,d7

	move.l		a2,(a0)+
	move.l		d6,(a0)+
	move.l		a3,(a0)+
	move.l		d7,(a0)+

	move.l		#400,d0			; max txt len
	lea		mes3(pc),a0		; String
	lea		txtvariablen(pc),a1	; DATEN
	lea		TTextBuffer,a3
	bsr.w	dorawformat

	move.l		a3,a0
	move.l		d0,d3
	bra.b	Patch_not_installed_01

Patch_not_installed:
	lea		mes1(pc),a0
	move.l		#mes1length,d3
;	moveq		#$fc,d3
Patch_not_installed_01
	bsr.b	writer
;---------------------------------------------------------------------
close_libs:
	move.l		$04.W,A6
	move.l		dosbase(pc),a1
	jsr	closelib(a6)

	move.l		gfxbase(pc),a1
	jsr	closelib(a6)

	movem.l 	(a7)+,d0-d7/a0-a6
	moveq		#00,d0		; for clear entry into CLI
writer_no:
 	rts
;---------------------------------------------------------------------
writer:
	move.l		a0,d2
	move.l		dosbase(pc),a6		; throws text into the cli
	move.l		outputhandle(pc),d1 	; window
	tst.l		d1
	beq.b	writer_no			; OOPS! no handle

	jmp	write(a6)
;--------------------------------------------------------------------------
DoRawFormat:	; V1.0 by Roger Fischlin  |  V1.1 by Ralf Thanner
;
;			INPUT
;			-----
;			in A0   Zeiger auf den TXT String
;			in A1   Zeiger auf den Data Stream
;			in A3   Zeiger auf den TXT Buffer
;			in D0.l die Bufferlaenge (gegen Overflow)
;
;			OUTPUT
;			------
;			in D0.l  aktuelle Laenge des Textes
;
;--------------------------------------------------------------------------
;
;	 %[flags][width.limit][length]type
;
;	flags  - only one allowed. '-' specifies left justification.
;	width  - field width.  If the first character is a '0', the
;		 field will be padded with leading 0's.
;	  .    - must follow the field width, if specified
;	limit  - maximum number of characters to output from a string.
;		 (only valid for %s).
;	length - size of input data defaults to WORD for types d, x,
;		 and c, 'l' changes this to long (32-bit).
;	type   - supported types are:
;			b - BSTR, data is 32-bit BPTR to byte count followed
;			    by a byte string, or NULL terminated byte string.
;			    A NULL BPTR is treated as an empty string.
;			    (Added in V36 exec)
;			d - decimal
;			x - hexadecimal
;			s - string, a 32-bit pointer to a NULL terminated
;			    byte string.  In V36, a NULL pointer is treated
;			    as an empty string
;			c - character
;
;--------------------------------------------------------------------------
;	z.B.	$12345 als hex Zahl mit 8 Stellen ('$00012345')
;
;	     -> '$%08lx'
;
;		$ - direkt  | % muss sein  | 0 - mit nullen auffuellen
;		8 - 8 chars | l - Long Var | x - hex
;--------------------------------------------------------------------------
	Movem.l		a0-a5,-(sp)
	move.l		d0,rawsize-var(a5)	; Zaehler fuer TXTlen loeschen
						; und MAXrawsize setzen.
	lea		rawformat(pc),a2
	move.l		$04.w,a6
	jsr 	RawDoFmt(a6)
	movem.l		(sp)+,a0-a5
	moveq		#0,d0
	move.w		rawsize(pc),d0	; Len of Text
	subq.w		#1,d0		; $0 byte abziehen
	rts

RawFormat:
	movem.l		d1/a5,-(sp)
	lea		var(pc),a5
	move.w		rawsize(pc),d1
	cmp.w		maxrawsize(pc),d1
	beq.b	RawFormat_dontwrite	; max len erreicht OVERFLOW!
	addq.w		#1,rawsize-var(a5)
	move.b		d0,(a3)+	; Byte in Puffer
RawFormat_Dontwrite:
	movem.l		(sp)+,d1/a5
	rts
;============================================================================
	Cnop	0,4
 rawsize:	dc.w	0
 maxrawsize:	dc.w	0
;--------------------------------------------------------------------------
 VAR:
 dosbase:	dc.l	0
 dosname:	dc.b	'dos.library',0
 outputhandle:	dc.l	0
 gfxbase:	dc.l	0
 gfxname:	dc.b	'graphics.library',0
;--------------------------------------------------------------------------
 EVEN
 	dc.b	"$VER: FastGfxTS v0.2 (01.06.93)",0
 EVEN
;--------------------------------------------------------------------------
mes0:	dc.b	27,"[33mFastGFX Tester Show v0.2"
	dc.b	27,"[0m  © 1993 by Ralf Thanner",10,10,0
mes0end:
mes0length = mes0end-mes0
 EVEN
;--------------------------------------------------------------------------
mes1:	dc.b	"SetApen, SetBPen, SetDrMd and WritePixel are NOT patched.",10,0

mes1end:
mes1length = mes1end-mes1
 EVEN
;--------------------------------------------------------------------------
mes2:	dc.b	"The installed patch is NOT the speed test version.",10,0

mes2end:
mes2length = mes2end-mes2
 EVEN
;--------------------------------------------------------------------------
mes3:
	dc.b	"%s %s %8ld  %s %s %8ld",10
	dc.b	"%s %s %8ld  %s %s %8ld",10
	dc.b	"%s %s %8ld  %s %s %8ld",10
	dc.b	"-----------------------------------------------------",10
	dc.b	"  Total %s %8ld    Total %s %8ld",10,10
	dc.b	"Remove as soon as you are satisfied this speedtest version",10
	dc.b	"and install the real one for more power!",10,0
	CNOP 0,4
;--------------------------------------------------------------------------
SA_TXT:
	dc.b	'SetAPen',0
	EVEN
SB_TXT:
	dc.b	'SetBPen',0
	EVEN
SDR_TXT:
	dc.b	'SetDrMd',0
	EVEN
exe_TXT:
	dc.b	'executed:',0
	EVEN
skip_TXT:
	dc.b	'skipped:',0
	CNOP	0,4

txtvariablen:
	dc.l	0	; "Setapen"	
	dc.l	0	; "executed"
	dc.l	0	; count executed
	dc.l	0	; "Setapen"	
	dc.l	0	; "skipped"
	dc.l	0	; count skipped

	dc.l	0	; "Setbpen"	
	dc.l	0	; "executed"
	dc.l	0	; count executed
	dc.l	0	; "Setbpen"	
	dc.l	0	; "skipped"
	dc.l	0	; count skipped

	dc.l	0	; "Setdrmd"	
	dc.l	0	; "executed"
	dc.l	0	; count executed
	dc.l	0	; "Setdrmd"	
	dc.l	0	; "skipped"
	dc.l	0	; count skipped

	dc.l	0	; "Executed"
	dc.l	0	; total count exec

	dc.l	0	; "skipped"
	dc.l	0	; total count skipped

Textbuffer:	 Section "TXT",BSS
TTextbuffer:
 	ds.b	400
