; My chunky-to-planar conversion ; Converts 2x4 bitplanes for good use of CPU registers ; Simple input/output as in Amiga CD32. ; First pass: get high (and low) 4 bitplanes for 8 pixels ; Input: d2-d3 - chunky pixels ; d4 - mask $f0f0f0f0 ; Output: d2-d3 - planar pixels high and low 4 bitplanes c2p_pass1: move.l d2,d0 move.l d3,d1 and.l d4,d2 ; a7a6a5a4........ b7b6b5b4........ c7c6c5c4........ d7d6d5d4........ and.l d4,d1 ; e7e6e5e4........ f7f6f5f4........ g7g6g5g4........ h7h6h5h4........ eor.l d2,d0 eor.l d1,d3 lsr.l #4,d1 lsl.l #4,d0 or.l d1,d2 ; high bitplanes or.l d0,d3 ; low bitplanes rts ; done ; Once we did the previous step, the user must choose which bitplanes to perform next (high or low). ; And repeat this call until it's 16 pixels loaded. ; Then he can proceed to finish the conversion. ; Second pass: ; Input: d2-d3 - 16 pixels after pass 1 d4 - mask $cccc3333 d5 - mask $ff00ff00 d6 - mask $aaaaaaaa ; Output: d2-d3 - 16 pixels c2p_pass2: move.l d2,d0 ; a7a6a5a4e7e6e5e4 b7b6b5b4f7f6f5f4 c7c6c5c4g7g6g5g4 d7d6d5d4h7h6h5h4 and.l d4,d2 ; a7a6....e7e6.... b7b6....f7f6.... ....c5c4....g5g4 ....d5d4....h5h4 eor.l d2,d0 ; ....a5a4....e5e4 ....b5b4....f5f4 c7c6....g7g6.... d7d6....h7h6.... lsr.w #2,d0 swap d0 lsl.w #2,d0 or.l d0,d2 ; a7a6c7c6e7e6g7g6 b7b6d7d6f7f6h7h6 a5a4c5c4e5e4g5g4 b5b4d5d4f5f4h5h4 move.l d3,d1 and.l d4,d3 eor.l d3,d1 lsr.w #2,d1 swap d1 lsl.w #2,d1 or.l d1,d3 move.l d2,d0 move.l d3,d1 and.l d5,d2 and.l d5,d1 eor.l d2,d0 eor.l d1,d3 lsr.l #8,d1 lsl.l #8,d0 or.l d1,d2 ; a7a6c7c6e7e6g7g6 i7i6k7k6m7m6o7o6 a5a4c5c4e5e4g5g4 i5i4k5k4m5m4o5o4 or.l d0,d3 ; b7b6d7d6f7f6h7h6 j7j6l7l6n7n6p7p6 b5b4d5d4f5f4h5h4 j5j4l5l4n5n4p5p4 move.l d2,d0 move.l d3,d1 and.l d6,d2 and.l d6,d1 eor.l d2,d0 eor.l d1,d3 lsr.l #1,d1 add.l d0,d0 or.l d1,d2 ; a7b7c7d7e7f7g7h7 i7j7k7l7m7n7o7p7 a5b5c5d5e5f5g5h5 i5j5k5l5m5n5o5p5 or.l d0,d3 ; a6b6c6d6e6f6g6h6 i6j6k6l6m6n6o6p6 a4b4c4d4e4f4g4h4 i4j4k4l4m4n4o4p4 rts ; done ; Finally, we can merge 32 pixels ; Input: d2-d3 - 32 pixels after pass 2 (same bitplanes pairs) ; Output: d2-d3 - 32 planar pixels c2p_pass3: move.w d2,d0 swap d3 move.w d3,d2 move.w d0,d3 swap d3 rts ; done