	
	
;*********************************************************************	
; includes
;*********************************************************************	

	.incdir	"F:\git\goldmomo_endlos\assembler_files\ucore\"
	.include "include\ucore_ctrl.i"

;*********************************************************************	
; sd header is placed here
;*********************************************************************	

	.include "boot_level_sdHeader.s"

;*********************************************************************
;* start at address 32 here
;*********************************************************************

start	
	cli
	
	movei	r0,0
	movei	r1,0
	moveih	r0,0
	moveih	r1,$d0	;$d000 0000
	
	nop
	esadr	r1,r0
	
	movei	r2,$cd
	nop
	moveih	r2,$ab
	nop
	
	est	r2,0
	nop
	erqldi	0
	eld	r1
	
	movei	r0,0
	
	;draw to hex	
			
	gpci	r7,2		
	br	longToHexMap
	nop			;delay slot
	nop			;delay slot
	nop			;delay slot
	nop			;delay slot
		
	gpci	r7,2		
	br	drawHex
	nop			;delay slot
	nop			;delay slot
	nop			;delay slot
	nop			;delay slot
	
	
end	br	end	
	nop			;delay slot
	nop			;delay slot
	nop			;delay slot
	nop			;delay slot
	
;******************************
;* longToHexMap
;*
;* r0 = high value
;* r1 = low value
;* 	

longToHexMap

	push	r0
	push	r1
	push	r2
	push	r3
	push	r4
	push	r5
	push	r6
	push	r7
	
	
	movei	r2,hexMap
	movei	r7,hex7seg
	movei	r5,$f		;msk
	moveih	r2,>hexMap	;8 h
	moveih	r7,>hex7seg
	
	movei	r6,1

highLow
	
	or	r3,r0,r0
	or	r4,r0,r0
	lsri	r3,12
	lsri	r4,8
	and	r3,r3,r5
	and	r4,r4,r5
	
	add	r3,r3,r7
	add	r4,r4,r7
	rqldi	r3,0
	rqldi	r4,0
	nop
	ld	r3
	ld	r4
	nop
	
	st	r2,r3		;8;4
	addi	r2,1		
	nop
	st	r2,r4		;7;3
	addi	r2,1
	
	or	r3,r0,r0
	and	r4,r0,r5
	lsri	r3,4
	nop
	and	r3,r3,r5
	nop
	
	add	r3,r3,r7
	add	r4,r4,r7
	rqldi	r3,0
	rqldi	r4,0
	nop
	ld	r3
	ld	r4
	nop
	
	st	r2,r3		;6;2
	addi	r2,1		
	nop
	st	r2,r4		;5;1
	addi	r2,1
	
	or	r0,r1,r1	;next 4 digits
	subi	r6,1
	brts	highLow
	nop			;delay slot
	nop			;delay slot
	nop			;delay slot
	nop			;delay slot
	
	rqpop	
	rqpop	
	rqpop	
	pop	r7
	pop	r6
	pop	r5
	
	rqpop	
	rqpop	
	rqpop	
	pop	r4
	pop	r3
	pop	r2
	
	rqpop	
	rqpop	
	nop
	pop	r1
	pop	r0
	
	jmpi	r7,0
	nop			;delay slot
	nop			;delay slot
	nop			;delay slot
	nop			;delay slot
		
 ;--     0
 ;--    ###
 ;--  5 # # 1
 ;--    #6#
 ;--  4 # # 2
 ;--    ###
 ;--     3	

hex7seg			
	
	word	%00111111 ; 0		
	word	%00000110 ; 1			
	word	%01011011 ; 2		
	word	%01001111 ; 3		
	word	%01100110 ; 4		
	word	%01101101 ; 5		
	word	%01111101 ; 6		
	word	%00000111 ; 7		
	word	%01111111 ; 8		
	word	%01101111 ; 9		
	word	%01110111 ; A		
	word	%01111100 ; b		
	word	%00111001 ; C		
	word	%01011110 ; d		
	word	%01111001 ; E		
	word	%01110001 ; F	
	
;******************************
;* drawHex
;* 
;*
;* 

drawHex	

	push	r0
	push	r1
	push	r2
	push	r3
	push	r4

	movei	r0,hexMap
	movei	r1,Uc7SegHex76
	moveih	r0,>hexMap
	moveih	r1,>Uc7SegHex76		;r1 = (hex7:hex6)
	
	movei	r2,0

drawHexLoop

	rqldi	r0,0
	rqldi	r0,1
	addi	r0,2		
	ld	r3		;hex n
	ld	r4		;hex n + 1
	cmplo	r3,r3		;set t = 0 (removed swp cmd now swptc have to used as replacment)
	swptc	r3,r3
	nop
	or	r4,r4,r3
	nop
	st	r1,r4
	subi	r1,1

	cmpeqi	r2,6
	brtc	drawHexLoop
	addi	r2,2		;delay slot (t is not used so hazard can ignored)
	nop			;delay slot
	nop			;delay slot
	nop			;delay slot
	
	rqpop	
	rqpop	
	rqpop	
	pop	r4
	pop	r3
	pop	r2
	
	rqpop	
	rqpop	
	nop
	pop	r1
	pop	r0
	
	jmpi	r7,0
	nop			;delay slot
	nop			;delay slot
	nop			;delay slot
	nop			;delay slot
	
hexMap	word	$10	;h0
	word	$11
	word	0
	word	0
	word	0
	word	0
	word	0
	word	0	;h7		