;Illustrating how to split a floating point number into its
;component digits and re-combine them. This could be part of a data
;entry routine.

Hundreds	mEQU		0
Tens		mEQU		1
Units		mEQU		2
fNumber		mEQU		4	;4 bytes

	fLoadW		0
	fStore		fNumber
	ON		20		;MS12 backlight

;This test loop excercises every number from 0 to 999.
Next:
	fRecallW	fNumber		;Test number
	GoSub		Split		;Split to hundreds tens and units
	GoSub		Combine		;re-combine
	GoSub		Show		;Show digits
	fRecallQ	fNumber		;Compare original with recombined number
	fSub
	fGoIfNZ		A		;Bad!!

	fRecallW	fNumber
	fInc
	fStore		fNumber

	fLoadQ		1000		;Increment, loop while less than 1000
	fSwap
	fSub
	fGoIfNeg	Next


A	GoTo		A


;Number 0-999 in W. Split into Hundreds, Tens and Units
Split:
	fLoadq		0.01
	fMul			;Scale to 0 - 9.99
	fLoadQ		0.005	;Round off
	fAdd
	Fix			;HUndreds digit in X
	Push
	Store		Hundreds
	fSwap			;Original in Q
	float
	fSub			;Remainder in W
	fLoadQ		10	;Scale remainder 0 - 9.9
	fMul
	Fix			;Tens digit in X
	Push
	Store		Tens
	fSwap			;Original in Q
	float
	fSub			;Remainder in W
	fLoadQ		10	;Scale remainder 0 - 9.
	fMul
	fix
	Store		Units
	Return
	
;Combine Hundreds, Tens and Units back into W
Combine:
	Recall		Hundreds
	Float	
	fLoadQ		10
	fMul
	fSwap
	Recall		Tens
	Float
	fAdd
	fLoadQ		10
	fMul
	fSwap
	Recall		Units
	Float
	fAdd
	Return

;Show hundreds tens and units on LCD
Show:
	OBLCD_SetCur	0,0
	OBLCD_UDecDispMVW	Hundreds
	OBLCD_UDecDispMVW	Tens
	OBLCD_UDecDispMVW	Units
	Return