0 Members and 2 Guests are viewing this topic.
#ifndef scrap#define scrap 8000h.echo "Warning, 'scrap' not defined, defining scrap=8000h"#endif#ifndef SMCarraybase= scraparraylen = scrap+2#endifheapflags= 33curchild = 0heapsort:; HL points to the array data; BC is the size of the array. NOT GREATER THAN 32767; IX points to the routine that compares the values#ifdef fast call heapify ld hl,(arraylen)#else push bc call heapify pop hl#endif_: dec hl ld (arraylen),hl#ifndef fast push hl#endif ld de,(arraybase) add hl,hl inc de add hl,de#ifdef fast ld a,(de) ldd inc hl ld (hl),a dec hl ld a,(de) ldd inc hl ld (hl),a#else call swap#endif ld bc,1 call propogate#ifdef fast ld hl,(arraylen)#else pop hl#endif ld a,h or l jr nz,-_ retheapify:;Inputs:; HL points to the array data; BC is the size of the array. NOT GREATER THAN 32767; IX points to the routine that compares the values ld (arraybase),hl ld (arraylen),bc srl b rr c_: push bc call propogate pop bc dec bc ld a,b or c jr nz,-_ retpropogate:;BC-1 is the parent index;2BC is the child1 index res curchild,(iy+heapflags)proppost: sla c rl b ld d,b ld e,c#ifdef SMCarraylen=$+1 ld hl,0#else ld hl,(arraylen)#endif sbc hl,de add hl,de ret c ;no children;compare the two children#ifdef SMCarraybase=$+1 ld hl,0#else ld hl,(arraybase)#endif add hl,de add hl,de inc hl ld d,(hl) dec hl ld e,(hl) dec hl push hl ld a,(hl) dec hl ld l,(hl) ld h,a ;HL holds the value of child0 ;DE holds the value of child1 jr z,+_ call callix jr nc,+_ ex de,hl pop de inc de inc de set curchild,(iy+heapflags) push de_:;{stack} points to the child;HL is the value of the child;BC points to the parent;now compare the child and parent ex de,hl ld hl,(arraybase) add hl,bc push hl dec hl ld a,(hl) dec hl ld l,(hl) ld h,a call callix pop hl pop de ret nc dec hl call swap;values swapped, now set parent=child;BC is the index of child1 bit curchild,(iy+heapflags) jp z,proppost inc bc jp propogateswap:;HL points to the top of one word;DE points to the top of another;Must preserve BC#ifdef fast ld a,(de) ldd inc hl ld (hl),a dec hl ld a,(de) ldd inc hl ld (hl),a inc c inc bc#else call +__: ld a,(de) ldd inc hl ld (hl),a dec hl inc bc#endif retcallix: jp (ix)
Ooh that would be cool. Are you allowed to post modified roms? I have a couple of my own that I could add in the extremely low chance anyone does anything about it.
It would be interesting if someone patched a bunch of TI-OS's commands with faster versions like this. That's pretty awesome @Xeda112358. You really need to compile a bunch of your routines into an easy to use library ;P