

;****
; r0 = text
; r1 = x
; r2 = y
;

printtext

	mov	r3,#$6000000
	add	r3,r3,#2048*8	
	add	r3,r3,r1 lsl 1
	add	r3,r3,r2 lsl 6
	
	
charl
	ldrb	r4,[r0],1
	cmps	r4,#0	
	subne	r4,r4,#32
	strneh	r4,[r3],2
	bne	charl

	mov	pc,lr	
	
;** draw integer hex. 4 Byte long (8 Zeichen)
;*
;* r0 = x; r1 = y; r2 = integer
;*
;**
drawint
	

	mov	r6,#$6000000
	add	r6,r6,#2048*8	
	add	r6,r6,r0 lsl 1
	add	r6,r6,r1 lsl 6

	mov	r3,#8
	mov	r7,#0
byte4
	cmp	r3,#1		;wenn letzte Stelle ereicht
	moveq	r7,#1		;dann erlaube auch führende (eine) Null

	mov	r4,r2

	mov	r5,r3 lsl 2	; 8 * 4 = 32
	sub	r5,r5,#4
	mov	r4,r4 lsr r5	;schiebe nach rechts
	and	r4,r4,#$f	;nur unterstes nibble

	mov	r5,r2

	cmp	r4,#0		;0
	movne	r7,#1
	add	r2,r4,'0'	;mache ascii

	cmp	r2,#'9'		;falls grösser 9
	addgt	r2,r2,#39	;gehe zu a,b,c,... usw.

	cmp	r7,#0
	subne	r2,r2,#32
	strneh	r2,[r6],2

	mov	r2,r5

	subs	r3,r3,#1
	bne	byte4

	
	move	pc,lr	


;*************************** wait for line (24.11.2002)
;*
;* r2 = line
;*
;**

wait
	stmfd 	sp!,{r0,r1}

	mov	r1,#$4000000
        
waitv	ldrh	r0,[r1,6]
	cmp	r0,r2
	bne	waitv	 

	ldmfd	sp!,{r0,r1}
	move	pc,lr
	
;*************************** dma copy (24.11.2002)
;*
;* r0 = source
;* r1 = destination 
;* r2 = size (durch 4 teilbar)
;*
;**

dmacpy  

@ifdef DMAMODE
	mov 	r3,#$04000000			
	str 	r0,[r3,$d4]			
	str	r1,[r3,$d8]			
	mov	r2,r2 lsr 2			; size / 4
	strh 	r2,[r3,$dc]			
	mov 	r0,#$8400 			; 32bit, sofort		
	strh	r0,[r3,$de]
@else

	stmfd 	sp!,{r0,r1,r3}
	
	mov	r2,r2 lsr 2
dmacpyloop
	ldr	r3,[r0],4
	str	r3,[r1],4
	subs	r2,r2,#1
	bne.s	dmacpyloop	
	
	ldmfd	sp!,{r0,r1,r3}
@endif
				
	mov 	pc,lr		
