! Hellow world program for SH7045F(Alpha Project)
! Satofumi KAMIMURA
! $I$

	.global start
	.text
! main rutine
start:
	bsr	sci_init	nop
	nop

	! print "Hello.\r\n"
 	bsr	put1ch
 	mov	#'H', r0
	bsr	put1ch
	mov	#'e', r0
	bsr	put1ch
	mov	#'l', r0
	bsr	put1ch
	mov	#'l', r0
	bsr	put1ch
	mov	#'o', r0
	bsr	put1ch
	mov	#'.', r0
	bsr	put1ch
	mov	#'\r', r0
	bsr	put1ch
	mov	#'\n', r0

	! infinity loop
	nop
inf_loop:
	bra	inf_loop
	nop

! Put a character
	nop
put1ch:
	mov	r0, r3
	mov.w	SSR1, r4	! while (!(SSR & 0x80)) !
put1ch_begin:
	mov.b	@r4, r0
	and	#0x80, r0
	cmp/pl  r0
	bf	put1ch_begin

	mov.w	TDR1, r2	! TDR = r0
	mov.b	r3, @r2

	mov.b	@r4, r0		! SSR &= ~0x80
	and	#~0x80, r0
	mov.b	r0, @r4

	rts
	nop

	.text
! SCI1 Initialize
	nop
sci_init:
	mov.w	PACRL2, r2	! enable RxD1, TxD1
	mov.w	PACRL2_D, r0
	mov.w	r0, @r2

	mov.w	SMR1, r2	! 115200bps, 8bit, 1stop bit, no parity
	mov	#0, r0
	mov.b	r0, @r2

	mov.w	BRR1, r2	! set BBR
	mov	#7, r0
	mov.b	r0, @r2

	! wait 1bit time

	mov.w	SCR1, r2	! TE = 1, RE = 1
	mov	#0x30, r0
	mov.b	r0, @r2

	mov.w	SSR1, r2	! SSR = 0x80
	mov.b	@r2, r0
	mov	#0x80, r0
	mov.b	r0, @r2

	rts
	nop

	.align 2
PACRL2:		.word	0x838e
SMR1:		.word	0x81b0
BRR1:		.word	0x81b1
SCR1:		.word	0x81b2
TDR1:		.word	0x81b3
SSR1:		.word	0x81b4
PACRL2_D:	.word	0x0140
