2 ; Ullrich von Bassewitz, 07.08.1998
4 ; CC65 runtime: division for signed ints
7 ; When negating values, we will ignore the possibility here, that one of the
8 ; values if $8000, in which case the negate will fail.
10 .export tosdiva0, tosdivax
11 .import popsargs, udiv16, negax
12 .importzp sreg, tmp1, tmp2
17 jsr popsargs ; Get arguments from stack, adjust sign
18 jsr udiv16 ; Do the division
19 ldx sreg+1 ; Load high byte of result
21 ; Adjust the sign of the result. tmp1 contains the high byte of the left
22 ; operand, tmp2 contains the high byte of the right operand.
26 bpl Pos ; Jump if sign of result positive
30 lda sreg ; Load low byte of result
31 jmp negax ; Adjust the sign