;
;	regs.asm -- BASIC の固定変数を通して、レジスタの設定と確認を行う
;
	aseg
	include	A:SC61860.LIB

bcd2bin: equ	1a95h
bin2bcd: equ	1D76h

; 固定変数のアドレス
afix:	equ	5cf8h
bfix:	equ	5cf8h
ifix:	equ	5cf8h
jfix:	equ	5cf8h
xfix:	equ	5c40h
yfix:	equ	5c38h
pfix:	equ	5cf8h
qfix:	equ	5cf8h

regwork:equ	5880h
fwork:	equ	regwork + 0
pwork:	equ	regwork + 1
qwork:	equ	regwork + 2
iwork:	equ	regwork + 3
jwork:	equ	regwork + 4
awork:	equ	regwork + 5
bwork:	equ	regwork + 6
xwork:	equ	regwork + 7
ywork:	equ	regwork + 9
kwork:	equ	regwork + 11
lwork:	equ	regwork + 12

;
;	ここから
;
	org	5800h

entry:	equ	$

;
;	固定変数に設定された値をBCDから変換して作業領域にコピーする
;
	lii	7

	lidp	ffix
	call	tobin
	lidp	fwork
	exbd

	lidp	pfix
	call	tobin
	lidp	pwork
	exbd

	lidp	qfix
	call	tobin
	lidp	qwork
	exbd

	lidp	ifix
	call	tobin
	lidp	iwork
	exbd

	lidp	jfix
	call	tobin
	lidp	jwork
	exbd

	lidp	afix
	call	tobin
	lidp	awork
	exbd

	lidp	bfix
	call	tobin
	lidp	bwork
	exbd

	lidp	xfix
	call	tobin
	lidp	xwork
	exbd

	lidp	yfix
	call	tobin
	lidp	ywork
	exbd

	lidp	kfix
	call	tobin
	lidp	kwork
	exbd

	lidp	lfix
	call	tobin
	lidp	lwork
	exbd

;	copy to registers
	lii	lwork - iwork
	mvdm

;	set p, q
	push
	lidp	pwork
	ldd	
	stp
	lidp	qwork
	ldd
	stq

;	set flags
	lidp	fwork
	ldd
	rc
	sr
	oria	0
;
	pop
;
;	以上で設定終了
;
	call	target
;
;	レジスタを作業領域へコピーする
;
	push
;
;	まず、フラグをAレジに設定して、作業領域へ
	lia	0
	jrnzp	nozero
	lia	1
nozero:
	sl
	lidp	fwork
	std
;
	ldp
	lidp	pwork
	std
;
	ldq
	lidp	qwork
	std
;
	lp	0
	lidp	iwork
	mvdm
	lp	1
	lidp	jwork
	mvdm
;
	pop
	lii	lwork - awork
	lp	2
	lidp	awork
	exwd
;
	lii	7
;
	lidp	fwork
	call	b2bcd
	lidp	ffix
	exwd
;
	lidp	pwork
	call	b2bcd
	lidp	pfix
	exwd
;
	lidp	qwork
	call	b2bcd
	lidp	qfix
	exwd
;
	lidp	iwork
	call	b2bcd
	lidp	ifix
	exwd
;
	lidp	jwork
	call	b2bcd
	lidp	jfix
	exwd
;
	lidp	awork
	call	b2bcd
	lidp	afix
	exwd
;
	lidp	bwork
	call	b2bcd
	lidp	bfix
	exwd
;
	lidp	xwork
	call	w2bcd
	lidp	xfix
	exwd
;
	lidp	ywork
	call	w2bcd
	lidp	yfix
	exwd
;
	lidp	kwork
	call	b2bcd
	lidp	kfix
	exwd
;
	lidp	lwork
	call	b2bcd
	lidp	lfix
	exwd
;
	rtn
;
;
;
tobin:
	lp	10
	mvwd
	cal	bcd2bin
	lp	18
	rtn

b2bcd:
	lp	18
	ldd
	exam
	clra
	lp	19
	exam
	cal	bin2bcd
	lp	10
	rtn

w2bcd:
	lp	18
	exbd
	cal	bin2bcd
	lp	10
	rtn
;
	end
