Use proper data bank when calling comparison function in qsort.

When using the large memory model, the wrong data bank (that of the library code rather than the program's static data) would be in place when the comparison function was called, potentially leading to data corruption or other incorrect behavior.
This commit is contained in:
Stephen Heumann 2023-02-14 18:53:27 -06:00
parent 60d49c7dc3
commit 3417a98d10
1 changed files with 20 additions and 6 deletions

View File

@ -700,13 +700,14 @@ ret stx n
qsort start qsort start
csubroutine (4:base,4:count,4:size,4:compar),0 csubroutine (4:base,4:count,4:size,4:compar),0
phb
phk
plb
lda count nothing to do if count is 0 lda count nothing to do if count is 0
ora count+2 ora count+2
beq done beq done
phb
phk
plb
dec4 count set count to the addr of the last entry dec4 count set count to the addr of the last entry
mul4 count,size mul4 count,size
add4 count,base add4 count,base
@ -717,12 +718,13 @@ qsort start
lda compar+1 lda compar+1
sta jsl1+2 sta jsl1+2
sta jsl2+2 sta jsl2+2
plb
ph4 <count do the sort ph4 <count do the sort
ph4 <base ph4 <base
jsl rsort jsl rsort
done plb done creturn
creturn
end end
**************************************************************** ****************************************************************
@ -781,10 +783,14 @@ sr1a move4 last,right right = last
move4 first,left left = first move4 first,left left = first
bra sr3 bra sr3
sr2 add4 left,lsize inc left until *left >= *last sr2 add4 left,lsize inc left until *left >= *last
sr3 ph4 <last sr3 plb
ph4 <last
ph4 <left ph4 <left
jsl1 entry jsl1 entry
jsl jsl1 jsl jsl1
phb
phk
plb
tax tax
bmi sr2 bmi sr2
sr4 lda right quit if right = first sr4 lda right quit if right = first
@ -794,10 +800,14 @@ sr4 lda right quit if right = first
cmp first+2 cmp first+2
beq sr4b beq sr4b
sr4a sub4 right,lsize dec right until *right <= *last sr4a sub4 right,lsize dec right until *right <= *last
plb
ph4 <last ph4 <last
ph4 <right ph4 <right
jsl2 entry jsl2 entry
jsl jsl2 jsl jsl2
phb
phk
plb
dec A dec A
bpl sr4 bpl sr4
sr4b ph4 <left swap left/right entries sr4b ph4 <left swap left/right entries
@ -816,9 +826,13 @@ sr5 blt sr2
ph4 <last ph4 <last
jsr swap jsr swap
sub4 left,lsize,right sort left part of array sub4 left,lsize,right sort left part of array
plb
ph4 <right ph4 <right
ph4 <first ph4 <first
jsl rsort jsl rsort
phb
phk
plb
add4 left,lsize,first sort right part of array add4 left,lsize,first sort right part of array
brl sr0 brl sr0
; ;