2000-05-28 13:40:48 +00:00
|
|
|
;
|
|
|
|
; Ullrich von Bassewitz, 07.08.1998
|
2017-03-12 22:21:43 +00:00
|
|
|
; Christian Krueger, 11-Mar-2017, added 65SC02 optimization
|
2000-05-28 13:40:48 +00:00
|
|
|
; CC65 runtime: modulo operation for long signed ints
|
|
|
|
;
|
|
|
|
|
|
|
|
; When negating values, we will ignore the possibility here, that one of the
|
|
|
|
; values if $8000, in which case the negate will fail.
|
|
|
|
|
2013-05-09 11:56:54 +00:00
|
|
|
.export tosmod0ax, tosmodeax
|
|
|
|
.import poplsargs, udiv32, negeax
|
|
|
|
.importzp sreg, ptr1, ptr2, tmp1, tmp3, tmp4
|
2000-05-28 13:40:48 +00:00
|
|
|
|
2017-03-12 22:21:43 +00:00
|
|
|
.macpack cpu
|
|
|
|
|
2009-08-15 20:58:35 +00:00
|
|
|
tosmod0ax:
|
2017-03-12 22:21:43 +00:00
|
|
|
.if (.cpu .bitand ::CPU_ISET_65SC02)
|
|
|
|
stz sreg
|
|
|
|
stz sreg+1
|
|
|
|
.else
|
2009-08-15 20:58:35 +00:00
|
|
|
ldy #$00
|
|
|
|
sty sreg
|
|
|
|
sty sreg+1
|
2017-03-12 22:21:43 +00:00
|
|
|
.endif
|
2009-08-15 20:58:35 +00:00
|
|
|
|
2022-04-17 14:06:22 +00:00
|
|
|
tosmodeax:
|
2013-05-09 11:56:54 +00:00
|
|
|
jsr poplsargs ; Get arguments from stack, adjust sign
|
|
|
|
jsr udiv32 ; Do the division, remainder is in (ptr2:tmp3:tmp4)
|
2000-05-28 13:40:48 +00:00
|
|
|
|
2002-10-24 19:23:24 +00:00
|
|
|
; Load the result
|
2002-09-28 19:55:19 +00:00
|
|
|
|
2002-10-24 19:23:24 +00:00
|
|
|
lda ptr2
|
2013-05-09 11:56:54 +00:00
|
|
|
ldx ptr2+1
|
|
|
|
ldy tmp3
|
|
|
|
sty sreg
|
|
|
|
ldy tmp4
|
|
|
|
sty sreg+1
|
2002-09-28 19:55:19 +00:00
|
|
|
|
|
|
|
; Check the sign of the result. It is the sign of the left operand.
|
|
|
|
|
2002-10-24 19:23:24 +00:00
|
|
|
bit tmp1 ; Check sign of left operand
|
2002-09-28 19:55:19 +00:00
|
|
|
bpl Pos ; Jump if result is positive
|
|
|
|
|
|
|
|
; Result is negative
|
|
|
|
|
|
|
|
jmp negeax ; Negate result
|
|
|
|
|
|
|
|
; Result is positive
|
|
|
|
|
2002-10-24 19:23:24 +00:00
|
|
|
Pos: rts ; Done
|
2000-05-28 13:40:48 +00:00
|
|
|
|