Fixed wrong compares (new code by Piotr Fusik)
git-svn-id: svn://svn.cc65.org/cc65/trunk@1243 b7a2c559-68d2-44c3-8de9-860c34a00d81
This commit is contained in:
parent
99de22ffe2
commit
fe027ce916
2 changed files with 100 additions and 94 deletions
|
@ -1,43 +1,44 @@
|
||||||
;
|
;
|
||||||
; Ullrich von Bassewitz, 10.12.1998
|
; Piotr Fusik, 15.04.2002
|
||||||
;
|
; originally by Ullrich von Bassewitz
|
||||||
; Integer compare function - used by the compare operators
|
;
|
||||||
;
|
; Integer compare function - used by the compare operators
|
||||||
|
;
|
||||||
.export tosicmp
|
|
||||||
.importzp sp, sreg
|
.export tosicmp
|
||||||
|
.importzp sp, sreg
|
||||||
|
|
||||||
tosicmp:
|
|
||||||
sta sreg
|
tosicmp:
|
||||||
stx sreg+1 ; Save ax
|
sta sreg
|
||||||
|
stx sreg+1 ; Save ax
|
||||||
ldy #$01
|
|
||||||
lda (sp),y ; Get high byte
|
ldy #$00
|
||||||
tax
|
lda (sp),y ; Get low byte
|
||||||
dey
|
tax
|
||||||
lda (sp),y ; Get low byte
|
inc sp ; 5
|
||||||
|
bne @L1 ; 3
|
||||||
; Inline incsp2 for better performance
|
inc sp+1 ; (5)
|
||||||
|
@L1:
|
||||||
inc sp ; 5
|
lda (sp),y ; Get high byte
|
||||||
bne @L1 ; 3
|
inc sp ; 5
|
||||||
inc sp+1 ; (5)
|
bne @L2 ; 3
|
||||||
@L1: inc sp ; 5
|
inc sp+1 ; (5)
|
||||||
bne @L2 ; 3
|
|
||||||
inc sp+1 ; (5)
|
; Do the compare.
|
||||||
|
|
||||||
; Do the compare.
|
@L2: sec
|
||||||
|
sbc sreg+1 ; Compare high byte
|
||||||
@L2: cpx sreg+1 ; Compare high byte
|
bne @L4
|
||||||
bne @L3
|
cpx sreg ; Compare low byte
|
||||||
cmp sreg ; Compare low byte
|
beq @L3
|
||||||
beq @L3
|
adc #$FF ; If the C flag is set then clear the N flag
|
||||||
bcs @L4
|
ora #$01 ; else set the N flag
|
||||||
lda #$FF ; Set the N flag
|
@L3: rts
|
||||||
@L3: rts
|
|
||||||
|
@L4: bvc @L3
|
||||||
@L4: lda #$01 ; Clear the N flag
|
eor #$FF ; Fix the N flag if overflow
|
||||||
rts
|
ora #$01 ; Clear the Z flag
|
||||||
|
rts
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1,51 +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
|
;
|
||||||
;
|
; Long int compare function - used by the compare operators
|
||||||
|
;
|
||||||
.export toslcmp
|
|
||||||
.import incsp4
|
.export toslcmp
|
||||||
.importzp sp, sreg, ptr1
|
.import incsp4
|
||||||
|
.importzp sp, sreg, ptr1
|
||||||
|
|
||||||
toslcmp:
|
|
||||||
sta ptr1
|
toslcmp:
|
||||||
stx ptr1+1 ; EAX now in sreg:ptr1
|
sta ptr1
|
||||||
|
stx ptr1+1 ; EAX now in sreg:ptr1
|
||||||
ldy #$03
|
|
||||||
lda (sp),y
|
ldy #$03
|
||||||
cmp sreg+1
|
lda (sp),y
|
||||||
bne L4
|
sec
|
||||||
|
sbc sreg+1
|
||||||
dey
|
bne L4
|
||||||
lda (sp),y
|
|
||||||
cmp sreg
|
dey
|
||||||
bne L1
|
lda (sp),y
|
||||||
|
cmp sreg
|
||||||
dey
|
bne L1
|
||||||
lda (sp),y
|
|
||||||
cmp ptr1+1
|
dey
|
||||||
bne L1
|
lda (sp),y
|
||||||
|
cmp ptr1+1
|
||||||
dey
|
bne L1
|
||||||
lda (sp),y
|
|
||||||
cmp ptr1
|
dey
|
||||||
|
lda (sp),y
|
||||||
L1: php ; Save flags
|
cmp ptr1
|
||||||
jsr incsp4 ; Drop TOS
|
|
||||||
plp ; Restore the flags
|
L1: php ; Save flags
|
||||||
beq L2
|
jsr incsp4 ; Drop TOS
|
||||||
bcs L3
|
plp ; Restore the flags
|
||||||
lda #$FF ; Set the N flag
|
beq L2
|
||||||
L2: rts
|
bcs L3
|
||||||
|
lda #$FF ; Set the N flag
|
||||||
L3: lda #$01 ; Clear the N flag
|
L2: rts
|
||||||
rts
|
|
||||||
|
L3: lda #$01 ; Clear the N flag
|
||||||
L4: php ; Save flags
|
rts
|
||||||
jsr incsp4 ; Drop TOS
|
|
||||||
plp ; Restore flags
|
L4: bvc L5
|
||||||
rts
|
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
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue