]> git.sur5r.net Git - cc65/commitdiff
Merge pull request #663 from IrgendwerA8/more_popptr1_adaptations
authorOliver Schmidt <ol.sc@web.de>
Sat, 26 May 2018 11:01:27 +0000 (13:01 +0200)
committerGitHub <noreply@github.com>
Sat, 26 May 2018 11:01:27 +0000 (13:01 +0200)
Adapted div & mod for popptr1.

libsrc/common/abs.s [deleted file]
libsrc/runtime/div.s
libsrc/runtime/mod.s
libsrc/runtime/mulax3.s
libsrc/runtime/neg.s [deleted file]
libsrc/runtime/negabs.s [new file with mode: 0644]
libsrc/runtime/shelp.s
libsrc/runtime/udiv.s
libsrc/runtime/umod.s

diff --git a/libsrc/common/abs.s b/libsrc/common/abs.s
deleted file mode 100644 (file)
index 5daa8a1..0000000
+++ /dev/null
@@ -1,16 +0,0 @@
-;
-; Ullrich von Bassewitz, 17.06.1998
-;
-; int abs (int x);
-;
-
-        .export         _abs
-        .import         negax
-
-_abs:   cpx     #$00            ; test hi byte
-        bpl     L1
-        jmp     negax           ; Negate if negative
-L1:     rts
-
-
-
index cdd340272bf21d66738f45b6301e2f1e13d26e50..e10ebc57d4e23b2ba12b79176aee672e1470d41a 100644 (file)
@@ -5,18 +5,18 @@
 ;
 
 ; When negating values, we will ignore the possibility here, that one of the
-; values if $8000, in which case the negate will fail.
+; values is $8000, in which case the negate will fail.
 
         .export         tosdiva0, tosdivax
-        .import         popsargsudiv16, negax
-        .importzp       sreg, tmp1, tmp2
+        .import         popsargsudiv16, negax
+        .importzp       ptr1, tmp1, tmp2
 
 tosdiva0:
         ldx     #0
 tosdivax:
-        jsr     popsargs        ; Get arguments from stack, adjust sign
-        jsr     udiv16          ; Do the division
-        ldx     sreg+1          ; Load high byte of result
+        jsr     popsargsudiv16  ; Get arguments from stack, adjust sign
+                                ; and do the division
+        ldx     ptr1+1          ; Load high byte of result
 
 ; Adjust the sign of the result. tmp1 contains the high byte of the left
 ; operand, tmp2 contains the high byte of the right operand.
@@ -27,11 +27,11 @@ tosdivax:
 
 ; Result is negative
 
-        lda     sreg            ; Load low byte of result
+        lda     ptr1            ; Load low byte of result
         jmp     negax           ; Adjust the sign
 
 ; Result is positive
 
-Pos:    lda     sreg
+Pos:    lda     ptr1            ; Load low byte of result
         rts
 
index c4331ed855f52105f8d87c2da897e25c0b7c848d..58e7405757d829bebc61bb3b8b78006d406ff4fd 100644 (file)
@@ -5,19 +5,19 @@
 ;
 
 ; When negating values, we will ignore the possibility here, that one of the
-; values if $8000, in which case the negate will fail.
+; values is $8000, in which case the negate will fail.
 
         .export         tosmoda0, tosmodax
-        .import         popsargsudiv16, negax
-        .importzp       ptr1, tmp1
+        .import         popsargsudiv16, negax
+        .importzp       sreg, tmp1
 
 tosmoda0:
         ldx     #0
 tosmodax:
-        jsr     popsargs        ; Get arguments from stack, adjust sign
-        jsr     udiv16          ; Do the division
-        lda     ptr1            ; Load low byte of result
-        ldx     ptr1+1          ; Load high byte of result
+        jsr     popsargsudiv16  ; Get arguments from stack, adjust sign
+                                ; and do the division
+        lda     sreg            ; Load low byte of result
+        ldx     sreg+1          ; Load high byte of result
 
 ; Adjust the sign of the result. tmp1 contains the high byte of the left
 ; operand, tmp2 contains the high byte of the right operand. The sign of
index 472bc60ec5da17826a3669906aa930ba91fac259..513ba723e8585bb2498744130fb742ec83e54e21 100644 (file)
@@ -3,6 +3,7 @@
 ;
 ; CC65 runtime: Multiply the primary register by 3
 ;
+; Don't touch the Y-register here, the optimizer relies on it!
 
         .export         mulax3
         .importzp       ptr1
diff --git a/libsrc/runtime/neg.s b/libsrc/runtime/neg.s
deleted file mode 100644 (file)
index a428fd1..0000000
+++ /dev/null
@@ -1,21 +0,0 @@
-;
-; Ullrich von Bassewitz, 05.08.1998
-;
-; CC65 runtime: negation on ints
-;
-
-        .export         negax
-
-negax:  clc
-        eor     #$FF
-        adc     #1
-        pha
-        txa
-        eor     #$FF
-        adc     #0
-        tax
-        pla
-        rts
-
-
-
diff --git a/libsrc/runtime/negabs.s b/libsrc/runtime/negabs.s
new file mode 100644 (file)
index 0000000..ef660f1
--- /dev/null
@@ -0,0 +1,26 @@
+;
+; Ullrich von Bassewitz, 05.08.1998
+;
+; int abs (int x);
+; and
+; CC65 runtime: negation on ints
+;
+
+        .export         negax
+        .export         _abs
+
+_abs:   cpx     #$00            ; Test hi byte
+        bpl     L1              ; Don't touch if positive
+negax:  clc
+        eor     #$FF
+        adc     #1
+        pha
+        txa
+        eor     #$FF
+        adc     #0
+        tax
+        pla
+ L1:    rts
+
+
+
index b1ebeb7988a28a20aa9dabc5ca62f08c22f52f84..9762dbf44a099750e32e7c68cd39fd72b03c5028 100644 (file)
@@ -1,17 +1,17 @@
 ;
 ; Ullrich von Bassewitz, 07.08.1998
 ;
-; CC65 runtime: helper stuff for mod/div/mul with signed ints
+; CC65 runtime: helper stuff for mod/div with 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.
+; values is $8000, in which case the negate will fail.
 
-        .export         popsargs
-        .import         negax, popax
-        .importzp       sreg, tmp1, tmp2, ptr4
+        .export         popsargsudiv16
+        .import         negax, popax, udiv16
+        .importzp       tmp1, tmp2, ptr1, ptr4
 
-popsargs:
+popsargsudiv16:
         stx     tmp2            ; Remember sign
         cpx     #0
         bpl     L1
@@ -24,7 +24,6 @@ L1:     sta     ptr4
         cpx     #0
         bpl     L2
         jsr     negax
-L2:     sta     sreg
-        stx     sreg+1
-        rts
-
+L2:     sta     ptr1
+        stx     ptr1+1
+        jmp     udiv16            ; Call the division
index 93548d0493247d97b8744b604c3976ca4f63591c..4115382c80c13a4fefefe77b5aae944df1c01e10 100644 (file)
@@ -3,9 +3,10 @@
 ;
 ; CC65 runtime: division for unsigned ints
 ;
+; Don't use tmp1 here, the signed division tunnels data with it!
 
         .export         tosudiva0, tosudivax, udiv16
-        .import         popsreg
+        .import         popptr1
         .importzp       sreg, ptr1, ptr4
 
 
@@ -14,50 +15,50 @@ tosudiva0:
 tosudivax:
         sta     ptr4
         stx     ptr4+1          ; Save right operand
-        jsr     popsreg         ; Get left operand
+        jsr     popptr1         ; Get left operand
 
 ; Do the division
 
         jsr     udiv16
 
-; Result is in sreg, remainder in ptr1
+; Result is in ptr1, remainder in sreg
 
-        lda     sreg
-        ldx     sreg+1
+        lda     ptr1
+        ldx     ptr1+1
         rts
 
 ;---------------------------------------------------------------------------
-; 16by16 division. Divide sreg by ptr4. Result is in sreg, remainder in ptr1
+; 16by16 division. Divide ptr1 by ptr4. Result is in ptr1, remainder in sreg
 ; (see mult-div.s from "The Fridge").
 ; This is also the entry point for the signed division
 
 udiv16: lda     #0
-        sta     ptr1+1
+        sta     sreg+1
         ldy     #16
         ldx     ptr4+1
         beq     udiv16by8a
 
-L0:     asl     sreg
-        rol     sreg+1
-        rol     a
+L0:     asl     ptr1
         rol     ptr1+1
+        rol     a
+        rol     sreg+1
 
-        pha
+        tax
         cmp     ptr4
-        lda     ptr1+1
+        lda     sreg+1
         sbc     ptr4+1
         bcc     L1
 
-        sta     ptr1+1
-        pla
+        sta     sreg+1
+        txa
         sbc     ptr4
-        pha
-        inc     sreg
+        tax
+        inc     ptr1
 
-L1:     pla
+L1:     txa
         dey
         bne     L0
-        sta     ptr1
+        sta     sreg
         rts
 
 
@@ -65,18 +66,18 @@ L1:     pla
 ; 16by8 division
 
 udiv16by8a:
-@L0:    asl     sreg
-        rol     sreg+1
+@L0:    asl     ptr1
+        rol     ptr1+1
         rol     a
         bcs     @L1
 
         cmp     ptr4
         bcc     @L2
 @L1:    sbc     ptr4
-        inc     sreg
+        inc     ptr1
 
 @L2:    dey
         bne     @L0
-        sta     ptr1
+        sta     sreg
         rts
 
index 92ebb5f91b9dda50ac26123dedb76a0bfab349a2..5788d569e5bca77908e140918f9e5b1b073d4d7d 100644 (file)
@@ -5,24 +5,24 @@
 ;
 
         .export         tosumoda0, tosumodax
-        .import         popsreg, udiv16
-        .importzp       ptr1, ptr4
+        .import         popptr1, udiv16
+        .importzp       sreg, ptr4
 
 tosumoda0:
         ldx     #0
 tosumodax:
         sta     ptr4
         stx     ptr4+1          ; Save right operand
-        jsr     popsreg         ; Get right operand
+        jsr     popptr1         ; Get right operand
 
 ; Do the division
 
         jsr     udiv16
 
-; Result is in sreg, remainder in ptr1
+; Result is in ptr1, remainder in sreg
 
-        lda     ptr1
-        ldx     ptr1+1
+        lda     sreg
+        ldx     sreg+1
         rts