From 131fe670a45c2885d577767546412622ccdc5ff6 Mon Sep 17 00:00:00 2001 From: Irmen de Jong Date: Tue, 24 Mar 2020 17:33:47 +0100 Subject: [PATCH] optimized scroll routines by removing needless twin loops --- compiler/res/prog8lib/c64utils.p8 | 94 +++---------------------------- 1 file changed, 8 insertions(+), 86 deletions(-) diff --git a/compiler/res/prog8lib/c64utils.p8 b/compiler/res/prog8lib/c64utils.p8 index 432a2da31..bf9fea306 100644 --- a/compiler/res/prog8lib/c64utils.p8 +++ b/compiler/res/prog8lib/c64utils.p8 @@ -594,8 +594,6 @@ asmsub scroll_left_full (ubyte alsocolors @ Pc) clobbers(A, Y) { ; contents of the rightmost column are unchanged, you should clear/refill this yourself ; Carry flag determines if screen color data must be scrolled too - ; TODO why are the two inner loops split apart? can't they just be one single .for/.next macro? - %asm {{ stx c64.SCRATCH_ZPREGX bcs + @@ -605,18 +603,7 @@ asmsub scroll_left_full (ubyte alsocolors @ Pc) clobbers(A, Y) { ldx #0 ldy #38 - - .for row=0, row<=12, row+=1 - lda c64.Colors + 40*row + 1,x - sta c64.Colors + 40*row,x - .next - inx - dey - bpl - - - ldx #0 - ldy #38 -- - .for row=13, row<=24, row+=1 + .for row=0, row<=24, row+=1 lda c64.Colors + 40*row + 1,x sta c64.Colors + 40*row,x .next @@ -628,18 +615,7 @@ _scroll_screen ; scroll the screen memory ldx #0 ldy #38 - - .for row=0, row<=12, row+=1 - lda c64.Screen + 40*row + 1,x - sta c64.Screen + 40*row,x - .next - inx - dey - bpl - - - ldx #0 - ldy #38 -- - .for row=13, row<=24, row+=1 + .for row=0, row<=24, row+=1 lda c64.Screen + 40*row + 1,x sta c64.Screen + 40*row,x .next @@ -664,41 +640,23 @@ asmsub scroll_right_full (ubyte alsocolors @ Pc) clobbers(A) { + ; scroll the color memory ldx #38 - - .for row=0, row<=12, row+=1 + .for row=0, row<=24, row+=1 lda c64.Colors + 40*row + 0,x sta c64.Colors + 40*row + 1,x .next dex bpl - - ldx #38 -- - .for row=13, row<=24, row+=1 - lda c64.Colors + 40*row,x - sta c64.Colors + 40*row + 1,x - .next - dex - bpl - - _scroll_screen ; scroll the screen memory ldx #38 - - .for row=0, row<=12, row+=1 + .for row=0, row<=24, row+=1 lda c64.Screen + 40*row + 0,x sta c64.Screen + 40*row + 1,x .next dex bpl - - ldx #38 -- - .for row=13, row<=24, row+=1 - lda c64.Screen + 40*row,x - sta c64.Screen + 40*row + 1,x - .next - dex - bpl - - ldx c64.SCRATCH_ZPREGX rts }} @@ -716,16 +674,7 @@ asmsub scroll_up_full (ubyte alsocolors @ Pc) clobbers(A) { + ; scroll the color memory ldx #39 - - .for row=1, row<=11, row+=1 - lda c64.Colors + 40*row,x - sta c64.Colors + 40*(row-1),x - .next - dex - bpl - - - ldx #39 -- - .for row=12, row<=24, row+=1 + .for row=1, row<=24, row+=1 lda c64.Colors + 40*row,x sta c64.Colors + 40*(row-1),x .next @@ -735,16 +684,7 @@ asmsub scroll_up_full (ubyte alsocolors @ Pc) clobbers(A) { _scroll_screen ; scroll the screen memory ldx #39 - - .for row=1, row<=11, row+=1 - lda c64.Screen + 40*row,x - sta c64.Screen + 40*(row-1),x - .next - dex - bpl - - - ldx #39 -- - .for row=12, row<=24, row+=1 + .for row=1, row<=24, row+=1 lda c64.Screen + 40*row,x sta c64.Screen + 40*(row-1),x .next @@ -768,16 +708,7 @@ asmsub scroll_down_full (ubyte alsocolors @ Pc) clobbers(A) { + ; scroll the color memory ldx #39 - - .for row=23, row>=12, row-=1 - lda c64.Colors + 40*row,x - sta c64.Colors + 40*(row+1),x - .next - dex - bpl - - - ldx #39 -- - .for row=11, row>=0, row-=1 + .for row=23, row>=0, row-=1 lda c64.Colors + 40*row,x sta c64.Colors + 40*(row+1),x .next @@ -787,16 +718,7 @@ asmsub scroll_down_full (ubyte alsocolors @ Pc) clobbers(A) { _scroll_screen ; scroll the screen memory ldx #39 - - .for row=23, row>=12, row-=1 - lda c64.Screen + 40*row,x - sta c64.Screen + 40*(row+1),x - .next - dex - bpl - - - ldx #39 -- - .for row=11, row>=0, row-=1 + .for row=23, row>=0, row-=1 lda c64.Screen + 40*row,x sta c64.Screen + 40*(row+1),x .next