Fix qsort code for swapping elements with a size of 64KiB or more.

This code did not previously work properly, because the X register value was overwritten within the loop. This could result in incorrect behavior such as hanging or data corruption when using qsort with element sizes >= 64KiB.
This commit is contained in:
Stephen Heumann 2023-02-14 18:43:40 -06:00
parent 74de206058
commit 60d49c7dc3
1 changed files with 4 additions and 2 deletions

View File

@ -830,8 +830,9 @@ r equ 7 right entry
swap tsc set up addressing swap tsc set up addressing
phd phd
tcd tcd
ldx lsize+2 move 64K chunks lda lsize+2 move 64K chunks
beq sw2 beq sw2
sta banks
ldy #0 ldy #0
sw1 lda [l],Y sw1 lda [l],Y
tax tax
@ -844,7 +845,7 @@ sw1 lda [l],Y
bne sw1 bne sw1
inc l+2 inc l+2
inc r+2 inc r+2
dex dec banks
bne sw1 bne sw1
sw2 lda lsize if there are an odd number of bytes then sw2 lda lsize if there are an odd number of bytes then
lsr A lsr A
@ -893,6 +894,7 @@ sw6 pld
; ;
lsize entry lsize entry
ds 4 local copy of size ds 4 local copy of size
banks ds 2 number of whole banks to swap
end end
**************************************************************** ****************************************************************