2000-05-28 13:40:48 +00:00
|
|
|
;
|
2018-05-24 03:55:40 +02:00
|
|
|
; Christian Krueger, 24-May-2018
|
2000-05-28 13:40:48 +00:00
|
|
|
;
|
|
|
|
; CC65 runtime: division for signed ints
|
|
|
|
;
|
|
|
|
|
|
|
|
; When negating values, we will ignore the possibility here, that one of the
|
2018-05-24 03:55:40 +02:00
|
|
|
; values is $8000, in which case the negate will fail.
|
2000-05-28 13:40:48 +00:00
|
|
|
|
2013-05-09 13:56:54 +02:00
|
|
|
.export tosdiva0, tosdivax
|
2018-05-24 11:31:43 +02:00
|
|
|
.import absvaludiv16, negax
|
2018-05-24 03:55:40 +02:00
|
|
|
.importzp sp, ptr1, tmp1
|
2000-05-28 13:40:48 +00:00
|
|
|
|
|
|
|
tosdiva0:
|
2013-05-09 13:56:54 +02:00
|
|
|
ldx #0
|
2000-05-28 13:40:48 +00:00
|
|
|
tosdivax:
|
2018-05-25 16:10:16 +02:00
|
|
|
pha ; Check if high-bytes indicate
|
|
|
|
txa ; different sign, so that we have to
|
|
|
|
ldy #1 ; negate the result after the operation.
|
|
|
|
eor (sp),y ; Eor with lhs high byte
|
|
|
|
sta tmp1 ; Save post negation indicator to tmp1
|
|
|
|
pla ; Back to entry accu
|
2018-05-24 11:31:43 +02:00
|
|
|
jsr absvaludiv16
|
2018-05-24 03:55:40 +02:00
|
|
|
ldx ptr1+1
|
|
|
|
lda ptr1
|
2018-05-25 16:10:16 +02:00
|
|
|
ldy tmp1 ; Fetch indicator
|
2018-05-24 03:55:40 +02:00
|
|
|
bmi negate
|
2002-09-28 19:41:00 +00:00
|
|
|
rts
|
2018-05-24 03:55:40 +02:00
|
|
|
negate: jmp negax
|