2 ; Ullrich von Bassewitz, 07.08.1998
4 ; CC65 runtime: modulo operation for long 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.
11 .import poplsargs, udiv32, negeax
12 .importzp sreg, ptr1, ptr2, tmp1, tmp3, tmp4
15 jsr poplsargs ; Get arguments from stack, adjust sign
16 jsr udiv32 ; Do the division, remainder is in (ptr2:tmp3:tmp4)
18 ; Load the result with the exception of the low byte
26 ; Check the sign of the result. It is the sign of the left operand.
28 lda tmp1 ; Check sign of left operand
29 bpl Pos ; Jump if result is positive
33 lda ptr2 ; Load byte 0 of result
34 jmp negeax ; Negate result
38 Pos: lda ptr2 ; Load byte 0 of result