From 6af85a9533ec5fb866b31f2cba6ed6cedf10a948 Mon Sep 17 00:00:00 2001 From: Vince Weaver Date: Sun, 31 Dec 2017 15:09:37 -0500 Subject: [PATCH] mode7: update a fast screen clear routine --- .../{hlin_clearscreen.s => gr_hlin.s} | 113 ----------------- asm_routines/gr_offsets.s | 5 + asm_routines/gr_slow_clear.s | 115 ++++++++++++++++++ mode7/Makefile | 19 +-- mode7/mode7.s | 4 +- mode7/scroll_demo.s | 3 +- mode7/sky_demo.s | 3 +- mode7/starfield_demo.s | 22 ++-- 8 files changed, 151 insertions(+), 133 deletions(-) rename asm_routines/{hlin_clearscreen.s => gr_hlin.s} (56%) create mode 100644 asm_routines/gr_offsets.s create mode 100644 asm_routines/gr_slow_clear.s diff --git a/asm_routines/hlin_clearscreen.s b/asm_routines/gr_hlin.s similarity index 56% rename from asm_routines/hlin_clearscreen.s rename to asm_routines/gr_hlin.s index 1024ca21..fb9d816e 100644 --- a/asm_routines/hlin_clearscreen.s +++ b/asm_routines/gr_hlin.s @@ -2,53 +2,6 @@ ;= ROUTINES ;===================================================================== - -clear_screens: - ;=================================== - ; Clear top/bottom of page 0 - ;=================================== - - lda #$0 - sta DRAW_PAGE - jsr clear_top - jsr clear_bottom - - ;=================================== - ; Clear top/bottom of page 1 - ;=================================== - - lda #$4 - sta DRAW_PAGE - jsr clear_top - jsr clear_bottom - - rts - - -clear_screens_notext: - ;=================================== - ; Clear top/bottom of page 0 - ;=================================== - - lda #$0 - sta DRAW_PAGE - jsr clear_top - lda #$0 - jsr clear_bottom_a - - ;=================================== - ; Clear top/bottom of page 1 - ;=================================== - - lda #$4 - sta DRAW_PAGE - jsr clear_top - lda #$0 - jsr clear_bottom_a - - rts - - ;================================ ; hlin_setup ;================================ @@ -168,69 +121,3 @@ hlin_single_bottom_loop: rts - ;============================= - ; clear_top - ;============================= -clear_top: - lda #$00 - - ;============================= - ; clear_top_a - ;============================= -clear_top_a: - - sta COLOR - - ; HLIN Y, V2 AT A - - lda #39 - sta V2 - - lda #0 - -clear_top_loop: - ldy #0 - pha - - jsr hlin_double - - pla - clc - adc #$2 - cmp #40 - bne clear_top_loop - - rts - - ;============================= - ; clear_bottom - ;============================= -clear_bottom: - lda #$a0 ; NORMAL space - -clear_bottom_a: - - sta COLOR - - lda #40 - sta V2 - -clear_bottom_loop: - ldy #0 - pha - - jsr hlin_double - - pla - clc - adc #$2 - cmp #48 - bne clear_bottom_loop - - rts - - ; move these to zero page for slight speed increase? -gr_offsets: - .word $400,$480,$500,$580,$600,$680,$700,$780 - .word $428,$4a8,$528,$5a8,$628,$6a8,$728,$7a8 - .word $450,$4d0,$550,$5d0,$650,$6d0,$750,$7d0 diff --git a/asm_routines/gr_offsets.s b/asm_routines/gr_offsets.s new file mode 100644 index 00000000..f9f575be --- /dev/null +++ b/asm_routines/gr_offsets.s @@ -0,0 +1,5 @@ + ; move these to zero page for slight speed increase? +gr_offsets: + .word $400,$480,$500,$580,$600,$680,$700,$780 + .word $428,$4a8,$528,$5a8,$628,$6a8,$728,$7a8 + .word $450,$4d0,$550,$5d0,$650,$6d0,$750,$7d0 diff --git a/asm_routines/gr_slow_clear.s b/asm_routines/gr_slow_clear.s new file mode 100644 index 00000000..cf6737e9 --- /dev/null +++ b/asm_routines/gr_slow_clear.s @@ -0,0 +1,115 @@ +;===================================================================== +;= ROUTINES +;===================================================================== + + +clear_screens: + ;=================================== + ; Clear top/bottom of page 0 + ;=================================== + + lda #$0 + sta DRAW_PAGE + jsr clear_top + jsr clear_bottom + + ;=================================== + ; Clear top/bottom of page 1 + ;=================================== + + lda #$4 + sta DRAW_PAGE + jsr clear_top + jsr clear_bottom + + rts + + +clear_screens_notext: + ;=================================== + ; Clear top/bottom of page 0 + ;=================================== + + lda #$0 + sta DRAW_PAGE + jsr clear_top + lda #$0 + jsr clear_bottom_a + + ;=================================== + ; Clear top/bottom of page 1 + ;=================================== + + lda #$4 + sta DRAW_PAGE + jsr clear_top + lda #$0 + jsr clear_bottom_a + + rts + + + + ;============================= + ; clear_top + ;============================= + ; takes 2+10+ (24+703 )*20 +6 + ; 14,558 cycles(?) 15ms, 70Hz +clear_top: + lda #$00 ; 2 + + ;============================= + ; clear_top_a + ;============================= +clear_top_a: + + sta COLOR ; 3 + + ; HLIN Y, V2 AT A + + lda #39 ; 2 + sta V2 ; 3 + + lda #0 ; 2 + +clear_top_loop: + ldy #0 ; 2 + pha ; 3 + + jsr hlin_double ; 6+ + + pla ; 4 + clc ; 2 + adc #$2 ; 2 + cmp #40 ; 2 + bne clear_top_loop ; 2nt/3 + + rts ; 6 + + ;============================= + ; clear_bottom + ;============================= +clear_bottom: + lda #$a0 ; NORMAL space + +clear_bottom_a: + + sta COLOR + + lda #40 + sta V2 + +clear_bottom_loop: + ldy #0 + pha + + jsr hlin_double + + pla + clc + adc #$2 + cmp #48 + bne clear_bottom_loop + + rts + diff --git a/mode7/Makefile b/mode7/Makefile index 52c99912..be9fc712 100644 --- a/mode7/Makefile +++ b/mode7/Makefile @@ -27,8 +27,9 @@ MODE7_ISLAND: mode7_island.o mode7_island.o: mode7.s island_lookup.s island_map.inc \ zp.inc sprites.inc \ + ../asm_routines/gr_hlin.s \ ../asm_routines/multiply_fast.s \ - ../asm_routines/hlin_clearscreen.s \ + ../asm_routines/gr_fast_clear.s \ ../asm_routines/pageflip.s \ ../asm_routines/gr_setpage.s \ ../asm_routines/keypress.s \ @@ -41,8 +42,9 @@ MODE7_CHECKERBOARD: mode7_checkerboard.o mode7_checkerboard.o: mode7.s checkerboard_lookup.s \ zp.inc sprites.inc \ + ../asm_routines/gr_hlin.s \ ../asm_routines/multiply_fast.s \ - ../asm_routines/hlin_clearscreen.s \ + ../asm_routines/gr_fast_clear.s \ ../asm_routines/pageflip.s \ ../asm_routines/gr_setpage.s \ ../asm_routines/keypress.s \ @@ -58,7 +60,8 @@ MODE7_RAINBOW: mode7_rainbow.o mode7_rainbow.o: mode7.s rainbow_lookup.s \ zp.inc sprites.inc \ ../asm_routines/multiply_fast.s \ - ../asm_routines/hlin_clearscreen.s \ + ../asm_routines/gr_fast_clear.s \ + ../asm_routines/gr_hlin.s \ ../asm_routines/pageflip.s \ ../asm_routines/gr_setpage.s \ ../asm_routines/keypress.s \ @@ -71,7 +74,8 @@ SCROLL_DEMO: scroll_demo.o scroll_demo.o: scroll_demo.s \ deater_scroll.inc \ - ../asm_routines/hlin_clearscreen.s \ + ../asm_routines/gr_hlin.s \ + ../asm_routines/gr_fast_clear.s \ ../asm_routines/gr_scroll.s \ ../asm_routines/pageflip.s \ ../asm_routines/gr_setpage.s @@ -82,7 +86,8 @@ SKY_DEMO: sky_demo.o sky_demo.o: sky_demo.s \ starry_sky.scroll \ - ../asm_routines/hlin_clearscreen.s \ + ../asm_routines/gr_hlin.s \ + ../asm_routines/gr_fast_clear.s \ ../asm_routines/gr_scroll.s \ ../asm_routines/pageflip.s \ ../asm_routines/gr_setpage.s @@ -92,10 +97,10 @@ STARFIELD_DEMO: starfield_demo.o ld65 -o STARFIELD_DEMO starfield_demo.o -C ./apple2_1000.inc starfield_demo.o: starfield_demo.s \ - ../asm_routines/hlin_clearscreen.s \ ../asm_routines/gr_scroll.s \ ../asm_routines/pageflip.s \ - ../asm_routines/gr_setpage.s + ../asm_routines/gr_setpage.s \ + ../asm_routines/gr_fast_clear.s ca65 -o starfield_demo.o starfield_demo.s -l starfield_demo.lst scroller: scroller.o diff --git a/mode7/mode7.s b/mode7/mode7.s index bfed0d14..f72fe039 100644 --- a/mode7/mode7.s +++ b/mode7/mode7.s @@ -1114,12 +1114,14 @@ exit: ; External modules ;=============================================== -.include "../asm_routines/hlin_clearscreen.s" +.include "../asm_routines/gr_hlin.s" .include "../asm_routines/pageflip.s" .include "../asm_routines/gr_setpage.s" .include "../asm_routines/keypress.s" .include "../asm_routines/gr_putsprite.s" .include "../asm_routines/text_print.s" +.include "../asm_routines/gr_offsets.s" +.include "../asm_routines/gr_fast_clear.s" .if .def(CHECKERBOARD_MAP) .include "../asm_routines/gr_scroll.s" diff --git a/mode7/scroll_demo.s b/mode7/scroll_demo.s index 2bf81ce8..b22bbfea 100644 --- a/mode7/scroll_demo.s +++ b/mode7/scroll_demo.s @@ -36,10 +36,11 @@ scroll_forever: ;=============================================== ; Routines ;=============================================== -.include "../asm_routines/hlin_clearscreen.s" +.include "../asm_routines/gr_fast_clear.s" .include "../asm_routines/gr_scroll.s" .include "../asm_routines/pageflip.s" .include "../asm_routines/gr_setpage.s" +.include "../asm_routines/gr_offsets.s" ;=============================================== ; Variables diff --git a/mode7/sky_demo.s b/mode7/sky_demo.s index 135fa671..38fdaf3a 100644 --- a/mode7/sky_demo.s +++ b/mode7/sky_demo.s @@ -51,12 +51,13 @@ scroll_forever: ;=============================================== ; Routines ;=============================================== -.include "../asm_routines/hlin_clearscreen.s" +.include "../asm_routines/gr_fast_clear.s" .include "../asm_routines/gr_scroll.s" .include "../asm_routines/pageflip.s" .include "../asm_routines/gr_setpage.s" .include "../asm_routines/keypress.s" .include "../asm_routines/bg_scroll.s" +.include "../asm_routines/gr_offsets.s" ;=============================================== ; Variables diff --git a/mode7/starfield_demo.s b/mode7/starfield_demo.s index ca466f9a..8d9055fd 100644 --- a/mode7/starfield_demo.s +++ b/mode7/starfield_demo.s @@ -25,15 +25,15 @@ NUMSTARS EQU 16 ;=============== ; Init Variables ;=============== - lda #0 - sta DRAW_PAGE - sta RANDOM_POINTER + lda #0 ; 2 + sta DRAW_PAGE ; 3 + sta RANDOM_POINTER ; 3 - ldy #(NUMSTARS-1) + ldy #(NUMSTARS-1) ; 2 init_stars: - jsr random_star - dey - bpl init_stars + jsr random_star ; 6 + dey ; 2 + bpl init_stars ; 2nt/3 ;=========================== ;=========================== @@ -46,8 +46,8 @@ starfield_loop: ;=============== ; clear screen ;=============== - jsr clear_top - + jsr clear_top ; 6+ + ; 6047 ;=============== ; draw stars ;=============== @@ -312,12 +312,14 @@ random_star: ; External modules ;=============================================== -.include "../asm_routines/hlin_clearscreen.s" +;.include "../asm_routines/hlin_clearscreen.s" .include "../asm_routines/pageflip.s" .include "../asm_routines/gr_setpage.s" .include "../asm_routines/keypress.s" .include "../asm_routines/gr_putsprite.s" .include "../asm_routines/text_print.s" +.include "../asm_routines/gr_offsets.s" +.include "../asm_routines/gr_fast_clear.s" ;=============================================== ; Variables