// ================================
// Moscovium
//		hfpu sin function test
//		(c) 2021	1YEN Toru
// ================================
asm		"mcoc_irom.mem"
incl	"mcoc115.incl"
# ================================
equ		chr_lf,0x0a
equ		chr_spc,0x20
equ		chr_cma,0x2c
equ		reso,63
# ================================

// initialize
ldwi	r7,ramtop+0x0100
movtc	sp,r7

// check HFPU
ldbiu	r0,0
hneg	r0,r0
mov		r0,r0
bne		chk_ok
// error: no hfpu
ldwi	r7,princhr
ldwi	r1,lab_chk_str_no_hfpu
chk_loop:
ldb		r0,[r1]
mov		r0,r0
beq		tstfail
stw		[r7],r0
addi	r1,1
bra		chk_loop

chk_str_no_hfpu:
dats	"ERR: no HFPU found\r\n\0"
chk_ok:

// ================================
// sin test
// ================================
ldwi	r7,princhr
ldwi	r6,lab_func_name
prin_lp:
ldb		r0,[r6]
stw		[r7],r0
addi	r6,1
mov		r0,r0
bne		prin_lp
ldwi	r7,princtl
ldbiu	r0,prin_nld
stw		[r7],r0							// not print NL

#// ********************************
#// sin (x)
#ldbiu	r0,0
#stw		[r7],r0							// print NL
#ldbil	r7,prinhlf&0xff
#hldi	r1,-0.138184
##ldwi	r1,half_max
##ldwi	r1,half_max_n
##ldwi	r1,half_nan
##ldwi	r1,half_inf
##ldwi	r1,half_inf_n
##ldwi	r1,half_zer
##ldwi	r1,half_zer_n
#stw		[r7],r1
#jalwr6	math_sin
#stw		[r7],r0
#hldi	r2,sin(-0.138184)
#stw		[r7],r2
#cmp		r0,r2
#bne		tstfail
#bra		tstpass
#// ********************************

// -reso<=x<0
// plot range
hldi	r4,2.2*3.1415926535
ldwi	r5,reso
hhalf	r1,r5
hdiv	r4,r1
// loop
test_mi_lp:
hhalf	r1,r5
hmul	r1,r4
hneg	r1,r1
// print r1+" "
ldbil	r7,prinhlf&0xff
stw		[r7],r1
ldbil	r7,princhr&0xff
ldbiu	r0,chr_spc
stw		[r7],r0
// sin (x)
pushwm	r4,r5
jalwr6	math_sin
// print r0+LF
ldbil	r7,prinhlf&0xff
stw		[r7],r0
ldbil	r7,princhr&0xff
ldbiu	r0,chr_lf
stw		[r7],r0
// end of loop
popwm	r5,r4
subi	r5,1
bne		test_mi_lp

// 0<=x<reso
// plot range
hldi	r4,2.2*3.1415926535
ldwi	r5,reso
hhalf	r1,r5
hdiv	r4,r1
ldbiu	r5,0
// loop
test_pl_lp:
hhalf	r1,r5
hmul	r1,r4
// print r1+" "
ldbil	r7,prinhlf&0xff
stw		[r7],r1
ldbil	r7,princhr&0xff
ldbiu	r0,chr_spc
stw		[r7],r0
// sin (x)
pushwm	r4,r5
jalwr6	math_sin
// print r0+LF
ldbil	r7,prinhlf&0xff
stw		[r7],r0
ldbil	r7,princhr&0xff
ldbiu	r0,chr_lf
stw		[r7],r0
// end of loop
popwm	r5,r4
addi	r5,1
ldwi	r6,reso
cmp		r6,r5
bhs		test_pl_lp

// test pass
bra		tstpass

func_name:
dats	"sin\n\0"

// ================================
tstpass:
ldwi	r0,simpass						// pass: LED=blue
bra		tstfnsh
tstfail:
ldwi	r0,simfail						// fail: LED=red
tstfnsh:
ldwi	r7,simfnsh
stw		[r7],r0
bra		pcnt-2
nop
// ================================

incl	"mcvm_lib_math.incl"

