A little while back I wrote some VAT sorting routines, so right now I'm doing a little work as packaging that as a SE and debugging. I've got a bubble sort and a heap sort, but the heap is veery strange and probably extremely buggy. Here's the source for the bubble, if you feel like trying to find bugs.
Code:
It's ZDS syntax, if you're wondering.
Code:
;=================================Bubble Sort==================================
bubble_start:
ld hl,(ProgPtr)
res 0,(IY+Asm_Flags2)
bubble_start1:
push hl
ld de,OP1
call sort_getname
call getnext
jr z,bubble_next
push hl
ld de,OP2
call sort_getname
ld hl,OP1
ld de,OP2
call sort_comparename
pop hl
jr nc,bubble_next
bubble_swap:
pop de
push de
call vatswap
set 0,(IY+Asm_Flags2)
ld a,'.'
B_CALL PutC
bubble_next:
pop hl
call getnext
jr nz,bubble_start1
bit 0,(IY+Asm_Flags2)
jr nz,bubble_start
ret
sort_getname:
;Input:
;hl-> first byte of VAT entry
;Output:
;name saved to (de)
;kills DE, B, and A
push hl
ld de,-6
add hl,de
ld b,(hl)
dec hl
sort_getname1:
ld a,(hl)
ld (de),a
inc de
dec hl
djnz sort_getname1
pop hl
ret
sort_comparename:
;Input:
;HL-> name 1 (printed forwards)
;DE-> name 2
;Output:
;Carry if name 1 higher alphabetically, otherwise NC
;Kills HL, DE, B, A
ld a,(de)
cp (hl)
jr nc, sort_comparename_name2big
inc hl
inc de
jr sort_comparename
sort_comparename_name2big:
ccf
ret
It's ZDS syntax, if you're wondering.