SSORTASM;--------------------------------------;
; SSORT  reass. aus FA 5/91       9.93 ;
;                                      ;
;      (Schnelles Sortieren von BASIC- ;
;       Stringfeldern, z.B. NA$(I):    ;
;         POKE 1,ASC("N")              ;
;         POKE 0,(ASC("A")+128)        ;
;         POKE 2,0                     ;
;         DOKE 3,I                     ;
;         CALL* 200                    ;
;--------------------------------------;
;
	ORG	200H
;
	LD	A,(0000H)
	LD	HL,(03D9H)
	LD	BC,3000H
AAAB	CPIR
	LD	A,(0001H)
	CP	(HL)
	JR	Z,AAAA
	LD	A,(0000H)
	JR	AAAB
AAAA	INC	HL
	INC	HL
	LD	BC,(0002H)
	PUSH	HL
	LD	B,C
	INC	B
	LD	DE,0004H
AAAC	ADD	HL,DE
	DJNZ	AAAC
	EX	DE,HL
	POP	HL
	PUSH	DE
	LD	BC,(0003H)
	INC	C
	LD	DE,0004H
AAAD	ADD	HL,DE
	DEC	BC
	LD	A,B
	OR	C
	JR	NZ,AAAD
	POP	DE
	EX	DE,HL
AAAQ	PUSH	AF
	PUSH	BC
	PUSH	DE
	PUSH	HL
	CALL	AAAE
	JP	NC,AAAF
	PUSH	HL
	POP	IY
AAAO	EX	(SP),HL
	EX	DE,HL
	PUSH	DE
AAAI	PUSH	IY
	POP	DE
	CALL	AAAG
	POP	DE
	JR	NC,AAAH
	CALL	AAAE
	JR	Z,AAAH
	DEC	HL
	DEC	HL
	DEC	HL
	DEC	HL
	PUSH	DE
	JR	AAAI
AAAH	POP	BC
	EX	(SP),HL
	EX	DE,HL
	PUSH	BC
	EX	(SP),HL
	PUSH	DE
AAAK	PUSH	IY
	POP	DE
	EX	DE,HL
	CALL	AAAG
	EX	DE,HL
	POP	DE
	JR	NC,AAAJ
	JR	Z,AAAJ
	CALL	AAAE
	JR	Z,AAAJ
	INC	HL
	INC	HL
	INC	HL
	INC	HL
	PUSH	DE
	JR	AAAK
AAAJ	POP	BC
	EX	DE,HL
	EX	(SP),HL
	PUSH	BC
	EX	DE,HL
	CALL	AAAE
	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