2 ; Christian Krueger, 24-May-2018
4 ; CC65 runtime: modulo operation for signed ints
7 ; When negating values, we will ignore the possibility here, that one of the
8 ; values is $8000, in which case the negate will fail.
10 .export tosmoda0, tosmodax
11 .import absvaludiv16, negax
12 .importzp sp, sreg, tmp1
18 ; Prepare adjustment of the sign of the result. The sign of the result of the
19 ; modulo operation is the same as that of the left operand.
22 ldy #1 ; Prepare lhs operant hi-byte fetch
24 sta tmp1 ; Save post negation indicator to tmp1
25 pla ; Back to entry accu
27 ldx sreg+1 ; Remainder to return registers
29 ldy tmp1 ; Fetch indicator