	zpage	btmp0
	zpage	btmp1
	zpage	btmp2
	zpage	r30
	zpage	r31

	global	___divint32

	section	text
___divint32:
	lda	btmp0+3
	sta	r30
	bpl	a1pos
	lda	#0
	tax
	tay
	taz
	sec
	sbcq	btmp0
	bra	a1done
a1pos:
	ldq	btmp0
a1done:
	stq	$d770
	lda	btmp1+3
	sta	r31
	bpl	a2pos
	lda	#0
	tax
	tay
	taz
	sec
	sbcq	btmp1
	bra	a2done
a2pos:
	ldq	btmp1
a2done:
	stq	$d774
	lda	r30
	eor	r31
	bpl	respos
	lda	#0
	tax
	tay
	taz
	sec
	sbcq	$d76c ; do we need more delay?
	stq	btmp0
	ldz	#0
	rts
respos:
	ldq	$d76c ; do we need more delay?
	stq	btmp0
	ldz	#0
	rts
