]> git.sur5r.net Git - cc65/blobdiff - libsrc/runtime/lcmp.s
no TGI_ERR_NO_MEM or TGI_ERR_NO_IOCB anymore: replaced by TGI_ERR_NO_RES
[cc65] / libsrc / runtime / lcmp.s
index c2cb9ffe3a9fd92a142b256603e53ba149812f6f..4e50aa538f89cc5a79c5f0e13adde59c7b201d22 100644 (file)
@@ -1,50 +1,56 @@
 ;
-; Ullrich von Bassewitz, 10.12.1998
+; Piotr Fusik, 15.04.2002
+; originally by Ullrich von Bassewitz
 ;
 ; Long int compare function - used by the compare operators
 ;
 
-       .export         lcmp
-       .import         incsp4
-       .importzp       sp, sreg, ptr1
+       .export         toslcmp
+       .import         incsp4
+       .importzp       sp, sreg, ptr1
 
 
-lcmp:          sta     ptr1
-       stx     ptr1+1          ; EAX now in sreg:ptr1
+toslcmp:
+       sta     ptr1
+       stx     ptr1+1          ; EAX now in sreg:ptr1
 
-       ldy     #$03
-               lda     (sp),y
-       cmp     sreg+1
-       bne     L4
+       ldy     #$03
+       lda     (sp),y
+       sec
+       sbc     sreg+1
+       bne     L4
 
-       dey
-       lda     (sp),y
-       cmp     sreg
-       bne     L1
+       dey
+       lda     (sp),y
+       cmp     sreg
+       bne     L1
 
-       dey
-       lda     (sp),y
-       cmp     ptr1+1
-       bne     L1
+       dey
+       lda     (sp),y
+       cmp     ptr1+1
+       bne     L1
 
-       dey
-       lda     (sp),y
-       cmp     ptr1
+       dey
+       lda     (sp),y
+       cmp     ptr1
 
-L1:    php                     ; Save flags
-       jsr     incsp4          ; Drop TOS
-       plp                     ; Restore the flags
-       beq     L2
-       bcs     L3
-       lda     #$FF            ; Set the N flag
-L2:    rts
+L1:    php                     ; Save flags
+       jsr     incsp4          ; Drop TOS
+       plp                     ; Restore the flags
+       beq     L2
+       bcs     L3
+       lda     #$FF            ; Set the N flag
+L2:    rts
 
 L3:    lda     #$01            ; Clear the N flag
-       rts
+       rts
 
-L4:    php                     ; Save flags
+L4:    bvc     L5
+       eor     #$FF            ; Fix the N flag if overflow
+       ora     #$01            ; Clear the Z flag
+L5:    php                     ; Save flags
        jsr     incsp4          ; Drop TOS
-       plp                     ; Restore flags
-       rts
+       plp                     ; Restore flags
+       rts
+
 
-