	IF 0
GPU	set 1

	path "e:\"
	include "js\macro\help.mac"
	include "js\include\textscr.reg"


max_x	equ 384/8
max_y	equ 10

	run $f03000

	movei #SP_start,SP
	moveta SP,SP.a
	
	movei #$1fb250,r0
	moveta r0,ScreenPtr.a
	movei #InitTextScreen,r0
	JSR (r0)
	movei #PrintHex,r24
	movei #PrintR0,r23
	movei #.loop,r22
	moveq #0,r2
	moveq #GPU,r1
.loop	moveta r1,Cursor.a ; Cursor =0
	movei #Hallo,r0
	JSR (r23)
	move r2,r0
	addq #1,r2
	PUSH r22
	jump (r24)
;	JSR (r24)
;	jump (r22)
;	addq #1,r2

	align 4
Hallo	dc.b "Counter :",0
	align 4
	ENDIF

****************************
* Textscreen with 8x8-Font *
* created : 29.06.95       *
* (c) Bastian Schick       *
****************************
;global EQUs
; max_x, max_y must be preset !
;global registers
;Cursor.a	
;ScreenPtr.a		; must be initialized !

****************  
clr	reg 2
ptr	reg 1
count	reg 0
InitTextScreen::
	PUSH r0,r1,r2
	movefa ScreenPtr.a,ptr
	xor clr,clr
	movei #max_x*max_y<<1-1,count

msubq #1,clr
	store clr,(ptr)
.loop	subq #1,count
	addqt #4,ptr
	jr nz,.loop
	store clr,(ptr)
	moveta clr,Cursor.a
	movei #$f00400,ptr
	movei #$fff,clr
	store clr,(ptr)		; set color
	POP r2,r1,r0
	RTS
	unreg clr,ptr,count
********************
* Print char in r0 *
********************
PChelp1	reg 3
PChelp	reg 2
ptr	reg 1
CharPtr	reg 0

PrintChar::	PUSH r1,r2,r3
	movei #ASCII,ptr
	shlq #24,CharPtr
	movefa Cursor.a,PChelp	; get current cursor
	shrq #24-3,CharPtr	; (r0 and $ff)*8
	shrq #16,PChelp		; get x
	add ptr,CharPtr
	movefa ScreenPtr.a,ptr
	add PChelp,ptr
	movefa Cursor.a,PChelp
	movei #max_x<<3,PChelp1	; bytes per line*8
	mult PChelp1,PChelp
	shrq #3,PChelp1		; = bytes per line
	add PChelp,ptr
	load (CharPtr),PChelp	; get 4 bytes of char
	addq #4,CharPtr
	REPT 4
		rorq #24,PChelp	; first byte down
		storeb PChelp,(ptr)
		add PChelp1,ptr
	ENDR
	load (CharPtr),PChelp
	REPT 3
		rorq #24,PChelp	; first byte down
		storeb PChelp,(ptr)
		add PChelp1,ptr
	ENDR
	rorq #24,PChelp
	storeb PChelp,(ptr)
	movefa Cursor.a,PChelp
	move PChelp,r0
	shlq #16,r0
	shrq #16,PChelp
	shrq #16,r0
	addq #1,PChelp
	cmp PChelp,PChelp1
	jr nz,._1
	nop
		moveq #0,PChelp
		movei #max_y,PChelp1
		addq #1,r0
		cmp PChelp1,r0
		jr nz,._1
		nop
			moveq #0,r0
._1	shlq #16,PChelp
	or PChelp,r0
	moveta r0,Cursor.a
	POP r3,r2,r1
	RTS
	ALIGN 4
ASCII	ibytes "\jaguar\ascii8.bin"
	ALIGN 2
	unreg CharPtr,ptr,PChelp,PChelp1
***************
* prints r0 hex at cursor
printchar	reg 4
null	reg 3
PHhelp1	reg 2
PHHelp	reg 1
PrintHex::	PUSH r0,r1,r2,r3,r4
	movei #"0",null
	movei #PrintChar,printchar
	move r0,r1

	REPT 4
		rorq #24,r1
		move r1,r0
		shlq #24,r0	; first byte up
		move r0,r2
		shrq #28,r0	; high nibble down
		shlq #4,r2	; low nibble up
		shrq #28,r2	; low nibble down
		cmpq #10,r0
		jr n,._1@
		add null,r0
			addq #7,r0
._1@		cmpq #10,r2
		jr n,._2@
		add null,r2
			addq #7,r2
._2@		JSR (printchar)
		move r2,r0
		JSR (printchar)
		INC@
	ENDR
	POP r4,r3,r2,r1,r0
	RTS
	unreg PHHelp,PHhelp1,null,printchar
****************
* prints text at r0 (C-style)
* text must be Long-aligned
****************
EXIT	reg 5
LOOP	reg 4
PRhelp	reg 3
printchar	reg 2
ptr	reg 1
PrintR0::	PUSH r1,r2,r3,r4,r5
	move r0,ptr
	movei #PrintChar,printchar
	movei #.loop,LOOP
	movei #.exit,EXIT
	load (ptr),PRhelp
.loop	addq #4,ptr
	REPT 4
		rorq #24,PRhelp
		nop
		move PRhelp,r0
		shlq #24,r0
		jump z,(EXIT)
		shrq #24,r0	; get byte
		JSR (printchar)
	ENDR
	jump (LOOP)
	load (ptr),PRhelp

.exit	POP r5,r4,r3,r2,r1
	RTS
	unreg EXIT,LOOP,PRhelp,printchar,ptr
