
; c2p1x1_cpu5_queue     no  320x256?  no    030

;    IFND    BPLX_256
BPLX_256    EQU 320
;    ENDC
;    IFND    BPLY_256
BPLY_256    EQU 256
;    ENDC
;    IFND    BPLSIZE_256
BPLSIZE_256 EQU BPLX_256*BPLY_256/8
;    ENDC
;    IFND    CHUNKYMAX_256
CHUNKYMAX_256 EQU  BPLX_256
;    ENDC
;    IFND    CHUNKYYMAX_256
CHUNKYYMAX_256 EQU  BPLY_256
;    ENDC

;   section c2p,code

; d0.w  chunkyx [chunky-pixels]
; d1.w  chunkyy [chunky-pixels]
; d2.w  (scroffsx) [screen-pixels]
; d3.w  scroffsy [screen-pixels]
; d4.w  (rowlen) [bytes] -- offset between one row and the next in a bpl
; d5.l  (BPLSIZE_256) [bytes] -- offset between one row in one bpl and the next bpl

; a0    c2pscreen
; a1    bitplanes

c2p1x1_cpu5_256

;   bsr c2p_copyinitblock

    lea c2p_data(pc),a2

    move.l  #$33333333,d5
    move.l  #$55555555,d6
    move.l  #$00ff00ff,a6

    add.l   #BPLSIZE_256,a1
;;;;k    add.l   c2p_scroffs-c2p_data(a2),a1

    movem.l a0-a1,-(sp)

    move.l  c2p_pixels-c2p_data(a2),a2


;;; move.l  #320*128,a2
    add.l   a0,a2
    cmp.l   a0,a2
    beq .none

    move.l  (a0)+,d0
    move.l  (a0)+,d2
    move.l  (a0)+,d1
    move.l  (a0)+,d3

    move.l  #$0f0f0f0f,d4       ; Merge 4x1, part 1
    and.l   d4,d0
    and.l   d4,d2
    lsl.l   #4,d0
    or.l    d2,d0

    and.l   d4,d1
    and.l   d4,d3
    lsl.l   #4,d1
    or.l    d3,d1

    move.l  d1,a3

    move.l  (a0)+,d2
    move.l  (a0)+,d1
    move.l  (a0)+,d3
    move.l  (a0)+,d7

    and.l   d4,d1           ; Merge 4x1, part 2
    and.l   d4,d2
    lsl.l   #4,d2
    or.l    d1,d2

    and.l   d4,d3
    and.l   d4,d7
    lsl.l   #4,d3
    or.l    d7,d3

    move.l  a3,d1

    swap    d2          ; Swap 16x2
    move.w  d0,d7
    move.w  d2,d0
    move.w  d7,d2
    swap    d2

    swap    d3
    move.w  d1,d7
    move.w  d3,d1
    move.w  d7,d3
    swap    d3

    bra.s   .start1
.x1
    move.l  (a0)+,d0
    move.l  (a0)+,d2
    move.l  (a0)+,d1
    move.l  (a0)+,d3

    move.l  d7,BPLSIZE_256(a1)

    move.l  #$0f0f0f0f,d4       ; Merge 4x1, part 1
    and.l   d4,d0
    and.l   d4,d2
    lsl.l   #4,d0
    or.l    d2,d0

    and.l   d4,d1
    and.l   d4,d3
    lsl.l   #4,d1
    or.l    d3,d1

    move.l  d1,a3

    move.l  (a0)+,d2
    move.l  (a0)+,d1
    move.l  (a0)+,d3
    move.l  (a0)+,d7

    move.l  a4,(a1)+

    and.l   d4,d1           ; Merge 4x1, part 2
    and.l   d4,d2
    lsl.l   #4,d2
    or.l    d1,d2

    and.l   d4,d3
    and.l   d4,d7
    lsl.l   #4,d3
    or.l    d7,d3

    move.l  a3,d1

    swap    d2          ; Swap 16x2
    move.w  d0,d7
    move.w  d2,d0
    move.w  d7,d2
    swap    d2

    swap    d3
    move.w  d1,d7
    move.w  d3,d1
    move.w  d7,d3
    swap    d3

    move.l  a5,-BPLSIZE_256-4(a1)
.start1
    move.l  a6,d4

    move.l  d2,d7           ; Swap 2x2
    lsr.l   #2,d7
    eor.l   d0,d7
    and.l   d5,d7
    eor.l   d7,d0
    lsl.l   #2,d7
    eor.l   d7,d2

    move.l  d3,d7
    lsr.l   #2,d7
    eor.l   d1,d7
    and.l   d5,d7
    eor.l   d7,d1
    lsl.l   #2,d7
    eor.l   d7,d3

    move.l  d1,d7
    lsr.l   #8,d7
    eor.l   d0,d7
    and.l   d4,d7
    eor.l   d7,d0
    lsl.l   #8,d7
    eor.l   d7,d1

    move.l  d1,d7
    lsr.l   #1,d7
    eor.l   d0,d7
    and.l   d6,d7
    eor.l   d7,d0
    move.l  d0,BPLSIZE_256*2(a1)
    add.l   d7,d7
    eor.l   d1,d7

    move.l  d3,d1
    lsr.l   #8,d1
    eor.l   d2,d1
    and.l   d4,d1
    eor.l   d1,d2
    lsl.l   #8,d1
    eor.l   d1,d3

    move.l  d3,d1
    lsr.l   #1,d1
    eor.l   d2,d1
    and.l   d6,d1
    eor.l   d1,d2
    add.l   d1,d1
    eor.l   d1,d3

    move.l  d2,a4
    move.l  d3,a5

    cmpa.l  a0,a2
    bne .x1

    move.l  d7,BPLSIZE_256(a1)
    move.l  a4,(a1)+
    move.l  a5,-BPLSIZE_256-4(a1)

    movem.l (sp)+,a0-a1
    add.l   #BPLSIZE_256*4,a1

    move.l  (a0)+,d0
    move.l  (a0)+,d2
    move.l  (a0)+,d1
    move.l  (a0)+,d3

    move.l  #$f0f0f0f0,d4       ; Merge 4x1, part 1
    and.l   d4,d0
    and.l   d4,d2
    lsr.l   #4,d2
    or.l    d2,d0

    and.l   d4,d1
    and.l   d4,d3
    lsr.l   #4,d3
    or.l    d3,d1

    move.l  d1,a3

    move.l  (a0)+,d2
    move.l  (a0)+,d1
    move.l  (a0)+,d3
    move.l  (a0)+,d7

    and.l   d4,d1           ; Merge 4x1, part 2
    and.l   d4,d2
    lsr.l   #4,d1
    or.l    d1,d2

    and.l   d4,d3
    and.l   d4,d7
    lsr.l   #4,d7
    or.l    d7,d3

    move.l  a3,d1

    swap    d2          ; Swap 16x2
    move.w  d0,d7
    move.w  d2,d0
    move.w  d7,d2
    swap    d2

    swap    d3
    move.w  d1,d7
    move.w  d3,d1
    move.w  d7,d3
    swap    d3

    bra.s   .start2
.x2
    move.l  (a0)+,d0
    move.l  (a0)+,d2
    move.l  (a0)+,d1
    move.l  (a0)+,d3

    move.l  d7,BPLSIZE_256(a1)

    move.l  #$f0f0f0f0,d4       ; Merge 4x1, part 1
    and.l   d4,d0
    and.l   d4,d2
    lsr.l   #4,d2
    or.l    d2,d0

    and.l   d4,d1
    and.l   d4,d3
    lsr.l   #4,d3
    or.l    d3,d1

    move.l  d1,a3

    move.l  (a0)+,d2
    move.l  (a0)+,d1
    move.l  (a0)+,d3
    move.l  (a0)+,d7

    move.l  a4,(a1)+

    and.l   d4,d1           ; Merge 4x1, part 2
    and.l   d4,d2
    lsr.l   #4,d1
    or.l    d1,d2

    and.l   d4,d3
    and.l   d4,d7
    lsr.l   #4,d7
    or.l    d7,d3

    move.l  a3,d1

    swap    d2          ; Swap 16x2
    move.w  d0,d7
    move.w  d2,d0
    move.w  d7,d2
    swap    d2

    swap    d3
    move.w  d1,d7
    move.w  d3,d1
    move.w  d7,d3
    swap    d3

    move.l  a5,-BPLSIZE_256-4(a1)
.start2
    move.l  a6,d4

    move.l  d2,d7           ; Swap 2x2
    lsr.l   #2,d7
    eor.l   d0,d7
    and.l   d5,d7
    eor.l   d7,d0
    lsl.l   #2,d7
    eor.l   d7,d2

    move.l  d3,d7
    lsr.l   #2,d7
    eor.l   d1,d7
    and.l   d5,d7
    eor.l   d7,d1
    lsl.l   #2,d7
    eor.l   d7,d3

    move.l  d1,d7
    lsr.l   #8,d7
    eor.l   d0,d7
    and.l   d4,d7
    eor.l   d7,d0
    lsl.l   #8,d7
    eor.l   d7,d1

    move.l  d1,d7
    lsr.l   #1,d7
    eor.l   d0,d7
    and.l   d6,d7
    eor.l   d7,d0
    move.l  d0,BPLSIZE_256*2(a1)
    add.l   d7,d7
    eor.l   d1,d7

    move.l  d3,d1
    lsr.l   #8,d1
    eor.l   d2,d1
    and.l   d4,d1
    eor.l   d1,d2
    lsl.l   #8,d1
    eor.l   d1,d3

    move.l  d3,d1
    lsr.l   #1,d1
    eor.l   d2,d1
    and.l   d6,d1
    eor.l   d1,d2
    add.l   d1,d1
    eor.l   d1,d3

    move.l  d2,a4
    move.l  d3,a5

    cmpa.l  a0,a2
    bne .x2

    move.l  d7,BPLSIZE_256(a1)
    move.l  a4,(a1)+
    move.l  a5,-BPLSIZE_256-4(a1)

.none
    rts

