mirror of
https://github.com/byteworksinc/ORCALib.git
synced 2025-03-25 19:30:03 +00:00
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:
parent
60d49c7dc3
commit
3417a98d10
26
stdlib.asm
26
stdlib.asm
@ -700,13 +700,14 @@ ret stx n
|
||||
qsort start
|
||||
|
||||
csubroutine (4:base,4:count,4:size,4:compar),0
|
||||
phb
|
||||
phk
|
||||
plb
|
||||
|
||||
lda count nothing to do if count is 0
|
||||
ora count+2
|
||||
beq done
|
||||
|
||||
phb
|
||||
phk
|
||||
plb
|
||||
dec4 count set count to the addr of the last entry
|
||||
mul4 count,size
|
||||
add4 count,base
|
||||
@ -717,12 +718,13 @@ qsort start
|
||||
lda compar+1
|
||||
sta jsl1+2
|
||||
sta jsl2+2
|
||||
plb
|
||||
|
||||
ph4 <count do the sort
|
||||
ph4 <base
|
||||
jsl rsort
|
||||
|
||||
done plb
|
||||
creturn
|
||||
done creturn
|
||||
end
|
||||
|
||||
****************************************************************
|
||||
@ -781,10 +783,14 @@ sr1a move4 last,right right = last
|
||||
move4 first,left left = first
|
||||
bra sr3
|
||||
sr2 add4 left,lsize inc left until *left >= *last
|
||||
sr3 ph4 <last
|
||||
sr3 plb
|
||||
ph4 <last
|
||||
ph4 <left
|
||||
jsl1 entry
|
||||
jsl jsl1
|
||||
phb
|
||||
phk
|
||||
plb
|
||||
tax
|
||||
bmi sr2
|
||||
sr4 lda right quit if right = first
|
||||
@ -794,10 +800,14 @@ sr4 lda right quit if right = first
|
||||
cmp first+2
|
||||
beq sr4b
|
||||
sr4a sub4 right,lsize dec right until *right <= *last
|
||||
plb
|
||||
ph4 <last
|
||||
ph4 <right
|
||||
jsl2 entry
|
||||
jsl jsl2
|
||||
phb
|
||||
phk
|
||||
plb
|
||||
dec A
|
||||
bpl sr4
|
||||
sr4b ph4 <left swap left/right entries
|
||||
@ -816,9 +826,13 @@ sr5 blt sr2
|
||||
ph4 <last
|
||||
jsr swap
|
||||
sub4 left,lsize,right sort left part of array
|
||||
plb
|
||||
ph4 <right
|
||||
ph4 <first
|
||||
jsl rsort
|
||||
phb
|
||||
phk
|
||||
plb
|
||||
add4 left,lsize,first sort right part of array
|
||||
brl sr0
|
||||
;
|
||||
|
Loading…
x
Reference in New Issue
Block a user