; fast & clear chunky-to-planar conversion incdir 'includes:' include 'graphics/gfx.i' xdef @c2p ; input: ; a0: chunky buffer ; a1: interleaved bitmap to store result @c2p: movem.l d2-d7/a2-a6,-(a7) ; preparation move.w (bm_Rows,a1),-(a7) movea.l (bm_Planes,a1),a2 ; bitplane movea.l (bm_Planes+4,a1),a3 ; end of row movea.l a3,a4 suba.l a2,a4 ; bytes to next plane ; move.w (bm_BytesPerRow,a1),a5 ; bytes to next row ; sub.w a4,a5 ; move.w (bm_Rows,a1),a6 ; rows adda.l a4,a4 ; bytes to next odd/even plane move.l #$3333cccc,d7 move.l #$00ff00ff,d6 move.l #$55555555,a5 move.l #$0f0f0f0f,a6 .more: ; pass 1: ; move.l #$3333cccc,d7 ; mask move.l (a0)+,d0 move.l d0,d1 and.l d7,d0 eor.l d0,d1 lsr.w #2,d0 swap d0 lsl.w #2,d0 or.l d1,d0 move.l (a0)+,d1 move.l d1,d2 and.l d7,d1 eor.l d1,d2 lsr.w #2,d1 swap d1 lsl.w #2,d1 or.l d2,d1 move.l (a0)+,d2 move.l d2,d3 and.l d7,d2 eor.l d2,d3 lsr.w #2,d2 swap d2 lsl.w #2,d2 or.l d3,d2 move.l (a0)+,d3 move.l d3,d4 and.l d7,d3 eor.l d3,d4 lsr.w #2,d3 swap d3 lsl.w #2,d3 or.l d4,d3 ; pass 2/3: ; move.l #$00ff00ff,d3 exg d7,a5 ; move.l #$55555555,d6 move.l d0,d4 move.l d2,d5 and.l d6,d0 and.l d6,d2 eor.l d0,d4 eor.l d2,d5 lsl.l #8,d0 lsr.l #8,d5 or.l d2,d0 or.l d5,d4 move.l d0,d2 move.l d4,d5 and.l d7,d0 and.l d7,d4 eor.l d0,d2 eor.l d4,d5 add.l d4,d4 lsr.l #1,d2 or.l d4,d0 or.l d5,d2 move.l d1,d4 move.l d3,d5 and.l d6,d1 and.l d6,d3 eor.l d1,d4 eor.l d3,d5 lsl.l #8,d1 lsr.l #8,d5 or.l d3,d1 or.l d5,d4 move.l d1,d3 move.l d4,d5 and.l d7,d1 and.l d7,d4 eor.l d1,d3 eor.l d4,d5 add.l d4,d4 lsr.l #1,d3 or.l d4,d1 or.l d5,d3 exg d7,a5 ; move.l #$0f0f0f0f,d7 exg d7,a6 move.l d0,d4 move.l d1,d5 and.l d7,d0 and.l d7,d1 eor.l d0,d4 eor.l d1,d5 lsl.l #4,d0 lsr.l #4,d5 or.l d1,d0 or.l d5,d4 ; done move.w a4,d1 move.w d0,(a2) swap d0 move.w d0,(a2,d1.w) add.w a4,d1 move.w d4,(a2,d1.w) swap d4 add.w a4,d1 move.w d4,(a2,d1.w) move.l d2,d1 move.l d3,d5 and.l d7,d2 and.l d7,d3 eor.l d2,d1 eor.l d3,d5 lsl.l #4,d2 lsr.l #4,d5 or.l d3,d2 or.l d5,d1 exg d7,a6 ; done move.w a4,d3 lsr.w #1,d3 move.w d2,(a2,d3.w) swap d2 add.w a4,d3 move.w d2,(a2,d3.w) add.w a4,d3 move.w d1,(a2,d3.w) swap d1 add.w a4,d3 move.w d1,(a2,d3.w) adda.l #2,a2 cmpa.l a3,a2 blt .more move.w (bm_BytesPerRow,a1),d1 move.w a4,d0 lsr.w #1,d0 sub.w d0,d1 ext.l d1 adda.l d1,a2 ; adda.l a5,a2 lea (a2,d0.w),a3 subq.w #1,(bm_Rows,a1) ; subq.w #1,a6 ; cmpa.w #0,a6 bgt .more move.w (a7)+,(bm_Rows,a1) movem.l (a7)+,d2-d7/a2-a6 rts