2000-05-28 13:40:48 +00:00
|
|
|
;
|
2018-05-24 01:55:40 +00:00
|
|
|
; Christian Krueger, 24-May-2018
|
2000-05-28 13:40:48 +00:00
|
|
|
;
|
|
|
|
; CC65 runtime: modulo operation for signed ints
|
|
|
|
;
|
|
|
|
|
|
|
|
; When negating values, we will ignore the possibility here, that one of the
|
2018-05-24 01:55:40 +00:00
|
|
|
; values is $8000, in which case the negate will fail.
|
2000-05-28 13:40:48 +00:00
|
|
|
|
2013-05-09 11:56:54 +00:00
|
|
|
.export tosmoda0, tosmodax
|
2018-05-24 09:31:43 +00:00
|
|
|
.import absvaludiv16, negax
|
2018-05-24 01:55:40 +00:00
|
|
|
.importzp sp, sreg, tmp1
|
2000-05-28 13:40:48 +00:00
|
|
|
|
|
|
|
tosmoda0:
|
2013-05-09 11:56:54 +00:00
|
|
|
ldx #0
|
2000-05-28 13:40:48 +00:00
|
|
|
tosmodax:
|
|
|
|
|
2018-05-24 01:55:40 +00:00
|
|
|
; Prepare adjustment of the sign of the result. The sign of the result of the
|
|
|
|
; modulo operation is the same as that of the left operand.
|
|
|
|
|
|
|
|
pha
|
2018-05-25 14:10:16 +00:00
|
|
|
ldy #1 ; Prepare lhs operant hi-byte fetch
|
2018-05-24 01:55:40 +00:00
|
|
|
lda (sp),y
|
2018-05-25 14:10:16 +00:00
|
|
|
sta tmp1 ; Save post negation indicator to tmp1
|
|
|
|
pla ; Back to entry accu
|
2018-05-24 09:31:43 +00:00
|
|
|
jsr absvaludiv16
|
2018-05-25 14:10:16 +00:00
|
|
|
ldx sreg+1 ; Remainder to return registers
|
2018-05-24 01:55:40 +00:00
|
|
|
lda sreg
|
2018-05-25 14:10:16 +00:00
|
|
|
ldy tmp1 ; Fetch indicator
|
2018-05-24 01:55:40 +00:00
|
|
|
bmi negate
|
|
|
|
rts
|
|
|
|
negate: jmp negax
|