2 ; Ullrich von Bassewitz, 07.08.1998
3 ; Christian Krueger, 11-Mar-2017, added 65SC02 optimization
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.
10 .export tosmod0ax, tosmodeax
11 .import poplsargs, udiv32, negeax
12 .importzp sreg, ptr1, ptr2, tmp1, tmp3, tmp4
17 .if (.cpu .bitand ::CPU_ISET_65SC02)
27 jsr poplsargs ; Get arguments from stack, adjust sign
28 jsr udiv32 ; Do the division, remainder is in (ptr2:tmp3:tmp4)
39 ; Check the sign of the result. It is the sign of the left operand.
41 bit tmp1 ; Check sign of left operand
42 bpl Pos ; Jump if result is positive
46 jmp negeax ; Negate result