btw one thing I could never grasp, how would sprite plexer work with bucket sort, ie not fully sorted but accurate enough ? order of irq doesnt matter for 8 sprites ? just use 1 irq for all 8 ?
// Radix sort of 32 "actors" based on their y-positions [0,223] in ascending order // // Worst case execution time: 2044 cycles // // 1248 bytes of code // 62 bytes of zeropage (in addition to y-positions) // * = $xx85 for no branch page boundary crossings .const NUM_SPRITES = 32 .const NUM_LSD_BUCKETS = 16 .const NUM_MSD_BUCKETS = 14 // Init // Constant 92 cycles lda #$ff // 2 cycles .for (var i = 0; i < NUM_LSD_BUCKETS; i++) sta lsd_buckets + i // 3 .for (var i = 0; i < NUM_MSD_BUCKETS; i++) sta msd_buckets + 8*i // 3 // LSD sort // Constant 576 cycles lda #NUM_LSD_BUCKETS - 1 // 2 .for (var i = 0; i < NUM_SPRITES; i++) { ldx ypos + i // 3 axs #$00 // 2 ldy lsd_buckets,x // 4 sty links + i // 3 .if (i == NUM_LSD_BUCKETS - 1) sta lsd_buckets,x // 4 else { ldy #i // 2 sty lsd_buckets,x // 4 } } // MSD sort // // Execution time per LSD list as a function of number of list elements: // - 0 elements: 6 cycles // - N (odd) elements: 5 + (N - 1) / 2 * (26 + 28) + 27 cycles // - N (even) elements: 5 + (N - 2) / 2 * (26 + 28) + 26 + 27 cycles // // Worst case 958 cycles (15 empty LSD lists, 1 32-element LSD list) .for (var i = 0; i < NUM_LSD_BUCKETS; i++) { ldx lsd_buckets + i // 3 bmi NextBucket // 2/3 Next: lda ypos,x // 4 alr #$f0 // 2 tay // 2 lda msd_buckets,y // 4 stx msd_buckets,y // 4 ldy links,x // 4 sta links,x // 4 bmi NextBucket // 2/3 lda ypos,y // 4 alr #$f0 // 2 tax // 2 lda msd_buckets,x // 4 sty msd_buckets,x // 4 ldx links,y // 4 sta links,y // 5 !!! bpl Next // 2/3 NextBucket: } // Output final sorted order // // Execution time per MSD list as a function of number of list elements: // - 0 elements: 6 cycles // - N (odd) elements: 5 + (N - 1) / 2 * 21 + 10 cycles // - N (even) elements: 5 + (N - 2) / 2 * 21 + 20 cycles // // Worst case 418 cycles (13 empty MSD lists, 1 32-element MSD list) .for (var i = NUM_MSD_BUCKETS - 1; i >= 0; i--) { lax msd_buckets + 8*i // 3 bmi NextBucket // 2/3 Next: pha // 3 lda links,x // 4 bmi NextBucket // 2/3 pha // 3 tay // 2 lax links,y // 4 bpl Next // 2/3 NextBucket: }