From 3417a98d1022b3abc4e6d85721282c3d4db8a246 Mon Sep 17 00:00:00 2001 From: Stephen Heumann Date: Tue, 14 Feb 2023 18:53:27 -0600 Subject: [PATCH] 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. --- stdlib.asm | 26 ++++++++++++++++++++------ 1 file changed, 20 insertions(+), 6 deletions(-) diff --git a/stdlib.asm b/stdlib.asm index bcbe300..329c67b 100644 --- a/stdlib.asm +++ b/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 = *last -sr3 ph4