
GetDivideValue:
	lpm	bl, Z+
	lpm	bh, Z+
	lpm	bul, Z+
	lpm	buh, Z+
	ret

DECLONG:
	push	ZL
	push	ZH
	ldi	ZL, LOW(LongDivideTable)
	ldi	ZH, HIGH(LongDivideTable)
	ldi	YL, LOW(DispBytes+11)
	ldi	YH, HIGH(DispBytes+11)
	rcall	GetDivideValue		; first digit - the 1,000,000,000's place
	ldi	param0, -1 + '0'	; going up - start at 0-
_bcdl1:	inc	param0
	sub	al, bl
	sbc	ah, bh
	sbc	aul, bul
	sbc	auh, buh
	brcc	_bcdl1
	st	-Y, param0
	rcall	GetDivideValue		; second digit - the 100,000,000's place
	ldi	param0, 10 + '0'	; going down - start at 10+
_bcdl2:	dec	param0
	sub	al, bl
	sbc	ah, bh
	sbc	aul, bul
	sbc	auh, buh
	brcs	_bcdl2
	st	-Y, param0
	rcall	GetDivideValue		; third digit - the 10,000,000's place
	ldi	param0, -1 + '0'	; going up - start at 0-
_bcdl3:	inc	param0
	sub	al, bl
	sbc	ah, bh
	sbc	aul, bul
	sbc	auh, buh
	brcc	_bcdl3
	st	-Y, param0
	rcall	GetDivideValue		; fourth digit - the 1,000,000's place
	ldi	param0, 10 + '0'	; going down - start at 10+
_bcdl4:	dec	param0			; note that we only need 3 bytes now - the value is already below 16777215
	sub	al, bl
	sbc	ah, bh
	sbc	aul, bul
	sbc	auh, buh
	brcs	_bcdl4
	st	-Y, param0
	rcall	GetDivideValue		; fifth digit - the 100,000's place
	ldi	param0, -1 + '0'	; going up - start at 0-
_bcdl5:	inc	param0
	sub	al, bl
	sbc	ah, bh
	sbc	aul, bul
	sbc	auh, buh
	brcc	_bcdl5
	st	-Y, param0
	rcall	GetDivideValue		; sixth digit - the 10,000's place
	ldi	param0, 10 + '0'	; going down - start at 10+
_bcdl6:	dec	param0
	sub	al, bl
	sbc	ah, bh
	sbc	aul, bul
	sbc	auh, buh
	brcs	_bcdl6
	st	-Y, param0
	rcall	GetDivideValue		; seventh digit - the 1,000's place
	ldi	param0, -1 + '0'	; going up - start at 0-
_bcdl7:	inc	param0			; we have started using only 2 bytes now
	sub	al, bl
	sbc	ah, bh
	sbc	aul, bul
	sbc	auh, buh
	brcc	_bcdl7
	st	-Y, param0
	rcall	GetDivideValue		; eighth digit - the 100's place
	ldi	param0, 10 + '0'	; going down - start at 10+
_bcdl8:	dec	param0
	sub	al, bl
	sbc	ah, bh
	sbc	aul, bul
	sbc	auh, buh
	brcs	_bcdl8
	st	-Y, param0
	ldi	counter, 10
	ldi	param0, -1 + '0'	; going up - start at 0-
_bcdl9:	inc	param0			; we have started using only 2 bytes now
	sub	al, counter
	brcc	_bcdl9
	st	-Y, param0

	clr	counter

	mov	param0, al
	subi	param0, -('0'+10)	; last digit - the 1's place
	st	-Y, param0

	st	-Y, ZERO
	adiw	YL, 11
	pop	ZH
	pop	ZL
	ret

LongDivideTable:
	dd	 1000000000
	dd	-100000000
	dd	 10000000
	dd	-1000000
	dd	 100000
	dd	-10000
	dd	 1000
	dd	-100
