I managed to playe a little with your code.
Seems you had been a little optimistic on that. It's true for 18 "16 pixels blocks" but the first and last "16 pixels blocks" of the screen takes more time : respectively 240+8*2 cycles and 136+4*2 cycles. More, for odd pixels shift you have a penalty of 16 cycles for the first "16 pixels block" and 8 cycles for all the others "16 pixels blocks" due to misalligned bus access produced by the rol instruction.
As you said it wasn't optimized, I've tried to see what can be done, without spending too much time on it. Here, you'll find wha I've managed to do :
Code: Select all
loop:
;first 16 pixels block
move.l d6,d5 ; 4
not.l d5 ; 6 --> 8
movem.l (a1)+,d0-d3 ; 12+8n --> 44
movea.l d0,a2 ; 4
movea.l d1,a6 ; 4 --> 8
rol.l d7,d0 ; 8+2n
and.l d5,d0 ; 8 --> 16+2n
rol.l d7,d1 ; 8+2n
and.l d5,d1 ; 8 --> 16+2n
rol.l d7,d2 ; 8+2n
movea.l d2,a3 ; 4
and.l d6,d2 ; 8
suba.l d2,a3 ; 8
swap.w d2 : 4
add.l d0,d2 ; 8
move.l d2,(a0)+ ; 12 --> 52+2n
rol.l d7,d3 ; 8+2n
movea.l d3,a4 ; 4
and.l d6,d3 ; 8
suba.l d3,a4 ; 8
swap.w d3 ; 4
add.l d1,d3 ; 8
move.l d3,(a0)+ ; 12 --> 52+2n
; = 12+44+8+(16+2n)*2+(52+2n)*2 = 200+8n
;18 "middle" 16 pixels block
movem.l (a1)+,d0-d5 ; 12+8n --> 60
rol.l d7,d0 ; 8+2n
movea.l d0,a5 ; 4
and.l d6,d0 ; 8
suba.l d0,a5 ; 8
swap.w d0 ; 4
add.l a3,d0 ; 8 --> 40+2n
rol.l d7,d1 ; 8+2n
movea.l d1,a3 ; 4
and.l d6,d1 ; 8
suba.l d1,a3 ; 8
swap.w d1 ; 4
add.l a4,d1 ; 8
rol.l d7,d2 ; 8+2n
movea.l d2,a4 ; 4
and.l d6,d2 ; 8
suba.l d2,a4 ; 8
swap.w d2 ; 4
add.l a5,d2 ; 8
rol.l d7,d3 ; 8+2n
movea.l d3,a5 ; 4
and.l d6,d3 ; 8
suba.l d3,a5 ; 8
swap.w d3 ; 4
add.l a3,d3 ; 8
rol.l d7,d4 ; 8+2n
movea.l d4,a3 ; 4
and.l d6,d4 ; 8
suba.l d4,a3 ; 8
swap.w d4 ; 4
add.l a4,d4 ; 8
rol.l d7,d5 ; 8+2n
movea.l d5,a4 ; 4
and.l d6,d5 ; 8
suba.l d5,a4 ; 8
swap.w d5 ; 4
add.l a5,d5 ; 8 --> 40+2n
movem.l d0-d5,(a0) ; 8+8n --> 56
lea.l 24(a0),a0 ; 8
; = 60+6(40+2n)+56+8 --> 364+12n ~ 121,33+4n per 16 pixels block
movem.l (a1)+,d0-d5 ; 12+8n --> 60
rol.l d7,d0 ; 8+2n
movea.l d0,a5 ; 4
and.l d6,d0 ; 8
suba.l d0,a5 ; 8
swap.w d0 ; 4
add.l a3,d0 ; 8 --> 40+2n
rol.l d7,d1 ; 8+2n
movea.l d1,a3 ; 4
and.l d6,d1 ; 8
suba.l d1,a3 ; 8
swap.w d1 ; 4
add.l a4,d1 ; 8
rol.l d7,d2 ; 8+2n
movea.l d2,a4 ; 4
and.l d6,d2 ; 8
suba.l d2,a4 ; 8
swap.w d2 ; 4
add.l a5,d2 ; 8
rol.l d7,d3 ; 8+2n
movea.l d3,a5 ; 4
and.l d6,d3 ; 8
suba.l d3,a5 ; 8
swap.w d3 ; 4
add.l a3,d3 ; 8
rol.l d7,d4 ; 8+2n
movea.l d4,a3 ; 4
and.l d6,d4 ; 8
suba.l d4,a3 ; 8
swap.w d4 ; 4
add.l a4,d4 ; 8
rol.l d7,d5 ; 8+2n
movea.l d5,a4 ; 4
and.l d6,d5 ; 8
suba.l d5,a4 ; 8
swap.w d5 ; 4
add.l a5,d5 ; 8 --> 40+2n
movem.l d0-d5,(a0) ; 8+8n --> 56
lea.l 24(a0),a0 ; 8
movem.l (a1)+,d0-d5 ; 12+8n --> 60
rol.l d7,d0 ; 8+2n
movea.l d0,a5 ; 4
and.l d6,d0 ; 8
suba.l d0,a5 ; 8
swap.w d0 ; 4
add.l a3,d0 ; 8 --> 40+2n
rol.l d7,d1 ; 8+2n
movea.l d1,a3 ; 4
and.l d6,d1 ; 8
suba.l d1,a3 ; 8
swap.w d1 ; 4
add.l a4,d1 ; 8
rol.l d7,d2 ; 8+2n
movea.l d2,a4 ; 4
and.l d6,d2 ; 8
suba.l d2,a4 ; 8
swap.w d2 ; 4
add.l a5,d2 ; 8
rol.l d7,d3 ; 8+2n
movea.l d3,a5 ; 4
and.l d6,d3 ; 8
suba.l d3,a5 ; 8
swap.w d3 ; 4
add.l a3,d3 ; 8
rol.l d7,d4 ; 8+2n
movea.l d4,a3 ; 4
and.l d6,d4 ; 8
suba.l d4,a3 ; 8
swap.w d4 ; 4
add.l a4,d4 ; 8
rol.l d7,d5 ; 8+2n
movea.l d5,a4 ; 4
and.l d6,d5 ; 8
suba.l d5,a4 ; 8
swap.w d5 ; 4
add.l a5,d5 ; 8 --> 40+2n
movem.l d0-d5,(a0) ; 8+8n --> 56
lea.l 24(a0),a0 ; 8
movem.l (a1)+,d0-d5 ; 12+8n --> 60
rol.l d7,d0 ; 8+2n
movea.l d0,a5 ; 4
and.l d6,d0 ; 8
suba.l d0,a5 ; 8
swap.w d0 ; 4
add.l a3,d0 ; 8 --> 40+2n
rol.l d7,d1 ; 8+2n
movea.l d1,a3 ; 4
and.l d6,d1 ; 8
suba.l d1,a3 ; 8
swap.w d1 ; 4
add.l a4,d1 ; 8
rol.l d7,d2 ; 8+2n
movea.l d2,a4 ; 4
and.l d6,d2 ; 8
suba.l d2,a4 ; 8
swap.w d2 ; 4
add.l a5,d2 ; 8
rol.l d7,d3 ; 8+2n
movea.l d3,a5 ; 4
and.l d6,d3 ; 8
suba.l d3,a5 ; 8
swap.w d3 ; 4
add.l a3,d3 ; 8
rol.l d7,d4 ; 8+2n
movea.l d4,a3 ; 4
and.l d6,d4 ; 8
suba.l d4,a3 ; 8
swap.w d4 ; 4
add.l a4,d4 ; 8
rol.l d7,d5 ; 8+2n
movea.l d5,a4 ; 4
and.l d6,d5 ; 8
suba.l d5,a4 ; 8
swap.w d5 ; 4
add.l a5,d5 ; 8 --> 40+2n
movem.l d0-d5,(a0) ; 8+8n --> 56
lea.l 24(a0),a0 ; 8
movem.l (a1)+,d0-d5 ; 12+8n --> 60
rol.l d7,d0 ; 8+2n
movea.l d0,a5 ; 4
and.l d6,d0 ; 8
suba.l d0,a5 ; 8
swap.w d0 ; 4
add.l a3,d0 ; 8 --> 40+2n
rol.l d7,d1 ; 8+2n
movea.l d1,a3 ; 4
and.l d6,d1 ; 8
suba.l d1,a3 ; 8
swap.w d1 ; 4
add.l a4,d1 ; 8
rol.l d7,d2 ; 8+2n
movea.l d2,a4 ; 4
and.l d6,d2 ; 8
suba.l d2,a4 ; 8
swap.w d2 ; 4
add.l a5,d2 ; 8
rol.l d7,d3 ; 8+2n
movea.l d3,a5 ; 4
and.l d6,d3 ; 8
suba.l d3,a5 ; 8
swap.w d3 ; 4
add.l a3,d3 ; 8
rol.l d7,d4 ; 8+2n
movea.l d4,a3 ; 4
and.l d6,d4 ; 8
suba.l d4,a3 ; 8
swap.w d4 ; 4
add.l a4,d4 ; 8
rol.l d7,d5 ; 8+2n
movea.l d5,a4 ; 4
and.l d6,d5 ; 8
suba.l d5,a4 ; 8
swap.w d5 ; 4
add.l a5,d5 ; 8 --> 40+2n
movem.l d0-d5,(a0) ; 8+8n --> 56
lea.l 24(a0),a0 ; 8
movem.l (a1)+,d0-d5 ; 12+8n --> 60
rol.l d7,d0 ; 8+2n
movea.l d0,a5 ; 4
and.l d6,d0 ; 8
suba.l d0,a5 ; 8
swap.w d0 ; 4
add.l a3,d0 ; 8 --> 40+2n
rol.l d7,d1 ; 8+2n
movea.l d1,a3 ; 4
and.l d6,d1 ; 8
suba.l d1,a3 ; 8
swap.w d1 ; 4
add.l a4,d1 ; 8
rol.l d7,d2 ; 8+2n
movea.l d2,a4 ; 4
and.l d6,d2 ; 8
suba.l d2,a4 ; 8
swap.w d2 ; 4
add.l a5,d2 ; 8
rol.l d7,d3 ; 8+2n
movea.l d3,a5 ; 4
and.l d6,d3 ; 8
suba.l d3,a5 ; 8
swap.w d3 ; 4
add.l a3,d3 ; 8
rol.l d7,d4 ; 8+2n
movea.l d4,a3 ; 4
and.l d6,d4 ; 8
suba.l d4,a3 ; 8
swap.w d4 ; 4
add.l a4,d4 ; 8
rol.l d7,d5 ; 8+2n
movea.l d5,a4 ; 4
and.l d6,d5 ; 8
suba.l d5,a4 ; 8
swap.w d5 ; 4
add.l a5,d5 ; 8 --> 40+2n
movem.l d0-d5,(a0) ; 8+8n --> 56
lea.l 24(a0),a0 ; 8
; = 60+6(40+2n)+56+8 --> 364+12n ~ 121,33+4n per 16 pixels block
; total for 18 "middle" 16 pixels blocks : 2184+72n
;last 16 pixels block
move.l a2,d0 ; 4
move.l a6,d1 ; 4 --> 8
rol.l d7,d0 ; 8+2n
and.l d6,d0 ; 8
swap.w d0 ; 4
add.l a3,d0 ; 8
move.l d0,(a0)+ ; 12 --> 40+2n
rol.l d7,d1 : 8+2n
and.l d6,d1 ; 8
swap.w d1 ; 4
add.l a4,d1 ; 8
move.l d1,(a0)+ ; 12 --> 40+2n
; = 88+4n
subi.w #128,d7 ; 8
bpl.w loop ; 10-->12 B / 12 NB --> 20 / 20
rts
If someone can do better, feel free to modifiy the code I've posted and let us know.
In attachement, you'll find a patched version of SCLH.PRG running the modified code listed above.
Unfortunately, RESET instruction "halt" (ok it's more an 'idle wait' state than a real 'halt') the CPU for a 4x number of cycles (124 exactly). So, for what I've understood of wake states until now (I must admit have to reread a certain topic more in details), it won't change anything.