10 ; SUPERSORT v2 2/19/81›20 ; rev. 2 fits under basic...must use w/ autorun.sys file›30 ;›40 ; Bob Fraser›50 ;›60 ;›70 ;›80 *=$CB›90 AZ=*›0100 *=*+2›0110 BZ=*›0120 *=*+2›0130 TZ=*›0140 *=*+2›0150 ;›0160 *=$600›0170 RLENG=* record length›0180 *=*+1›0190 KLENG=* key length›0200 *=*+1›0210 M=* smallest sort done by quicksort›0220 *=*+1›0230 N=* location of beginning of last record›0240 *=*+2›0250 I=* next 4 are internal sort vars›0260 *=*+2›0270 J=*›0280 *=*+2›0290 L=*›0300 *=*+2›0310 R=*›0320 *=*+2›0330 MSCALE=* m scaled for comparison›0340 *=*+2›0350 ST=* table start address›0360 *=*+2›0370 SP=* stack pointer›0380 *=*+1›0390 STACK1=*›0400 *=*+26›0410 STACK2=*›0420 *=*+26›0430 TREC=* temporary record›0440 *=*+185›0450 Q=*›0460 *=$1D5A leave room for memlo reset routine›0470 PLA pop off USR's n value›0480 PLA›0490 STA ST+1›0500 STA AZ+1›0510 PLA›0520 STA ST›0530 STA AZ store address of data table›0540 PLA›0550 STA N+1›0560 PLA›0570 STA N store parameter 'n'›0580 ;›0590 LDA RLENG›0600 STA MSCALE›0610 LDA #0›0620 STA MSCALE+1›0630 LDX M›0640 L0 CLC›0650 LDA MSCALE›0660 ADC RLENG›0670 STA MSCALE›0680 LDA MSCALE+1›0690 ADC #0›0700 STA MSCALE+1›0710 DEX›0720 BNE L0 mscale <- rleng*(m+1)›0730 ;›0740 CLC›0750 LDA N›0760 ADC RLENG›0770 STA BZ›0780 LDA N+1›0790 ADC #0›0800 STA BZ+1 BZ <- N+1›0810 ;›0820 LDY #0›0830 Q0 LDA #0›0840 STA (AZ),Y›0850 LDA #$FF›0860 STA (BZ),Y›0870 INY›0880 CPY KLENG›0890 BNE Q0›0900 ;›0910 Q1 LDA #0›0920 STA SP stack <= empty›0930 CLC›0940 LDA AZ›0950 ADC RLENG›0960 STA L›0970 LDA AZ+1›0980 ADC #0›0990 STA L+1 l <- 1›1000 LDA N›1010 STA R r <- N›1020 LDA N+1›1030 STA R+1›1040 ;›1050 Q2 CLC›1060 LDA R›1070 ADC RLENG›1080 STA J›1090 LDA R+1›1100 ADC #0›1110 STA J+1 j <- r+1›1120 ;›1130 LDA L›1140 STA AZ›1150 STA I›1160 LDA L+1›1170 STA AZ+1›1180 STA I+1 i <- l›1190 ;›1200 LDY #0›1210 L1 LDA (AZ),Y›1220 STA TREC,Y›1230 INY›1240 CPY RLENG›1250 BNE L1›1260 JMP Q3 R <- R(l)›1270 ;›1280 Q6 LDY #0›1290 LDA I›1300 STA AZ›1310 LDA I+1›1320 STA AZ+1›1330 LDA J›1340 STA BZ›1350 LDA J+1›1360 STA BZ+1›1370 L2 LDA (AZ),Y›1380 TAX›1390 LDA (BZ),Y›1400 STA (AZ),Y›1410 TXA›1420 STA (BZ),Y›1430 INY›1440 CPY RLENG›1450 BNE L2 R(i) <-> R(j)›1460 ;›1470 Q3 CLC›1480 LDA I›1490 ADC RLENG›1500 STA I›1510 STA AZ›1520 LDA I+1›1530 ADC #0›1540 STA I+1 i <- i+1›1550 STA AZ+1›1560 ;›1570 LDY #0›1580 L3 LDA (AZ),Y K(i) < K ?›1590 CMP TREC,Y›1600 BCC Q3 yes›1610 BNE Q4 no›1620 INY›1630 CPY KLENG›1640 BNE L3 don't know›1650 ;›1660 Q4 SEC›1670 LDA J›1680 SBC RLENG›1690 STA J›1700 STA AZ›1710 LDA J+1›1720 SBC #0›1730 STA J+1›1740 STA AZ+1 j <- j-1›1750 ;›1760 LDY #0›1770 L4 LDA TREC,Y›1780 CMP (AZ),Y K < K(j) ?›1790 BCC Q4 yes›1800 BNE Q5 no›1810 INY›1820 CPY KLENG›1830 BNE L4 don't know›1840 ;›1850 Q5 LDA I+1›1860 CMP J+1 j <= i ?›1870 BCC Q6 no›1880 BNE L5 yes›1890 LDA I›1900 CMP J›1910 BCS L5 yes›1920 JMP Q6 no›1930 ;›1940 L5 LDA L›1950 STA AZ›1960 LDA L+1›1970 STA AZ+1›1980 LDA J›1990 STA BZ›2000 LDA J+1›2010 STA BZ+1›2020 LDY #0›2030 L6 LDA (AZ),Y›2040 TAX›2050 LDA (BZ),Y›2060 STA (AZ),Y›2070 TXA›2080 STA (BZ),Y›2090 INY›2100 CPY RLENG›2110 BNE L6 R(l) <-> R(j)›2120 ;›2130 Q7 SEC›2140 LDA J›2150 SBC L›2160 STA BZ›2170 LDA J+1›2180 SBC L+1›2190 STA BZ+1›2200 SEC›2210 LDA BZ›2220 SBC MSCALE›2230 STA BZ›2240 LDA BZ+1›2250 SBC MSCALE+1›2260 STA BZ+1 B <- j-l-(M+1)›2270 ;›2280 SEC›2290 LDA R›2300 SBC J›2310 STA AZ›2320 LDA R+1›2330 SBC J+1›2340 STA AZ+1›2350 SEC›2360 LDA AZ›2370 SBC MSCALE›2380 STA AZ›2390 LDA AZ+1›2400 SBC MSCALE+1›2410 STA AZ+1 A <- r-j-(M+1)›2420 ;›2430 SEC A>=B ?›2440 LDA AZ›2450 SBC BZ›2460 LDA AZ+1›2470 SBC BZ+1›2480 BMI L8 no›2490 ;›2500 LDA BZ+1 B>M ? (B>=M+1 ?)›2510 BPL L6B yes›2520 L6A JMP L11 no›2530 ;›2540 L6B LDX SP›2550 CLC›2560 LDA J›2570 ADC RLENG›2580 STA STACK1,X›2590 LDA J+1›2600 ADC #0›2610 INX›2620 STA STACK1,X›2630 DEX›2640 LDA R›2650 STA STACK2,X›2660 INX›2670 LDA R+1›2680 STA STACK2,X›2690 INX›2700 STX SP STACK <= j+1,r›2710 ;›2720 L7 SEC›2730 LDA J›2740 SBC RLENG›2750 STA R›2760 LDA J+1›2770 SBC #0›2780 STA R+1 r <- j-1›2790 JMP Q2›2800 ;›2810 L8 LDA AZ+1 A>M ? (A>=M+1 ?)›2820 BMI L10 no›2830 ;›2840 LDX SP yes›2850 LDA L›2860 STA STACK1,X›2870 INX›2880 LDA L+1›2890 STA STACK1,X›2900 DEX›2910 SEC›2920 LDA J›2930 SBC RLENG›2940 STA STACK2,X›2950 LDA J+1›2960 SBC #0›2970 INX›2980 STA STACK2,X›2990 INX›3000 STX SP STACK <= l,j-1›3010 ;›3020 L9 CLC›3030 LDA J›3040 ADC RLENG›3050 STA L›3060 LDA J+1›3070 ADC #0›3080 STA L+1›3090 JMP Q2 l <- j+1›3100 ;›3110 L10 LDA BZ+1 B>M ? (B>=M+1 ?)›3120 BPL L7 yes›3130 JMP Q8 no›3140 ;›3150 L11 LDA AZ+1 A>M ? (A>=M+1 ?)›3160 BPL L9 yes›3170 ;›3180 Q8 LDX SP›3190 BEQ Q9 STACK EMPTY ?›3200 DEX›3210 LDA STACK1,X›3220 STA L+1›3230 DEX›3240 LDA STACK1,X›3250 STA L›3260 INX›3270 LDA STACK2,X›3280 STA R+1›3290 DEX›3300 LDA STACK2,X›3310 STA R›3320 STX SP l,r <= STACK›3330 JMP Q2›3340 ;›3350 Q9 CLC›3360 LDA ST›3370 ADC RLENG›3380 STA AZ›3390 LDA ST+1›3400 ADC #0›3410 STA AZ+1 j <- 1›3420 ;›3430 L12 LDA AZ›3440 STA TZ›3450 ADC RLENG›3460 STA AZ›3470 LDA AZ+1›3480 STA TZ+1 t <- j›3490 ADC #0›3500 STA AZ+1 j <- j+1›3510 ;›3520 LDY #0›3530 L13 LDA (TZ),Y›3540 CMP (AZ),Y K(j-1)>K(j) ?›3550 BCC L21 no›3560 BNE L14 yes›3570 INY don't know›3580 CPY KLENG›3590 BNE L13›3600 JMP L21 no›3610 ;›3620 L14 LDY #0›3630 L15 LDA (AZ),Y›3640 STA TREC,Y›3650 INY›3660 CPY RLENG›3670 BNE L15 R <- R(j)›3680 ;›3690 LDA AZ›3700 STA BZ›3710 LDA AZ+1›3720 STA BZ+1 i <- j›3730 ;›3740 L16 SEC›3750 LDA BZ›3760 STA TZ›3770 SBC RLENG›3780 STA BZ›3790 LDA BZ+1›3800 STA TZ+1 t <- i›3810 SBC #0›3820 STA BZ+1 i <- i-1›3830 ;›3840 LDY #0›3850 L17 LDA TREC,Y›3860 CMP (BZ),Y K(i) <= K ?›3870 BCC L17A no›3880 BNE L19 yes›3890 INY›3900 CPY KLENG›3910 BNE L17 don't know›3920 JMP L19 yes›3930 ;›3940 L17A LDY #0›3950 L18 LDA (BZ),Y›3960 STA (TZ),Y›3970 INY›3980 CPY RLENG›3990 BNE L18 R(t) <- R(i)›4000 JMP L16›4010 ;›4020 L19 LDY #0›4030 L20 LDA TREC,Y›4040 STA (TZ),Y›4050 INY›4060 CPY RLENG›4070 BNE L20 K(t) <- K›4080 ;›4090 L21 LDA AZ+1 j < N ?›4100 CMP N+1›4110 BCC L21A yes›4120 BNE L22 no›4130 LDA AZ don't know›4140 CMP N›4150 BCS L22 no›4160 L21A JMP L12 yes›4170 ;›4180 L22 RTS›4190 .END›