2 ; Ullrich von Bassewitz, 17.08.1998
4 ; CC65 runtime: division for signed long ints
7 ; When negating values, we will ignore the possibility here, that one of the
8 ; values if $80000000, in which case the negate will fail.
11 .import poplsargs, udiv32, negeax
12 .importzp ptr1, tmp1, tmp2
15 jsr poplsargs ; Get arguments from stack, adjust sign
16 jsr udiv32 ; Do the division, result is in (ptr1:sreg)
17 ldx ptr1+1 ; Load byte 1 of result
19 ; Adjust the sign of the result
21 lda tmp1 ; Get sign of left operand
22 eor tmp2 ; Calculate sign of result
23 bpl Pos ; Jump if result positive
27 lda ptr1 ; Load byte 0
28 jmp negeax ; Negate value