[stella] Bubble Sort

Subject: [stella] Bubble Sort
From: Manuel Polik <cybergoth@xxxxxxxx>
Date: Mon, 25 Mar 2002 22:07:20 +0100
Hi there!

Ok, after yet another headache, I can present here the 
fastest implementation of Bubble Sorting Y-Positions to 
an index table I can think of:

First the Routine:

BubbleSort:
    LDX #MAXOBJECTS-2
    STX tempVar1
OuterSortLoop:
    LDX tempVar1
InnerSortLoop
    LDA indextbl+1,X
    TAY
    LDA ypos,Y
    STA tempVar2
    LDA indextbl,X
    TAY
    LDA ypos,Y
    CMP tempVar2
    BPL NoSwap
    LDA indextbl+1,X
    STY indextbl+1,X
    STA indextbl,X
NoSwap
    DEX
    BPL InnerSortLoop
    DEC tempVar1
    BPL OuterSortLoop
    RTS

The data is:

MAXOBJECTS -> # of objects to sort.

indextbl -> The index array, it starts filled with 
		 0,1,2,...,MAXOBJECTS-1.

ypos -> array with vertical positions.

Well, this is as fast as I can get with a sort capable 
of sorting even worst case input any frame. (Sorry 
Thomas, I won't rely on any assumptions and *normally* 
theories. I don't know what I'm doing with that routine 
in the future, so it must do 100% always, no matter what 
input I feed it :-))

So, is anybody here seeing a spot where to still speed-
up the algorithm? (Without illegal opcodes... :-))

Greetings,
	Manuel

----------------------------------------------------------------------------------------------
Archives (includes files) at http://www.biglist.com/lists/stella/archives/
Unsub & more at http://www.biglist.com/lists/stella/


Current Thread