From c534cf4b3e4145b6af437e4d00a594f481386b3f Mon Sep 17 00:00:00 2001 From: Vince Weaver Date: Thu, 14 Dec 2017 15:59:54 -0500 Subject: [PATCH] mode7: update scroller to use compressed files --- mode7/deater_scroll.inc | 19 ++- mode7/mode7.dsk | Bin 143360 -> 143360 bytes mode7/mode7.s | 8 - mode7/scroll_demo.s | 354 +++++++++++++++++++++++++++++++++++++++- mode7/scroller.c | 110 ++++++++++--- mode7/utils.s | 8 + 6 files changed, 446 insertions(+), 53 deletions(-) diff --git a/mode7/deater_scroll.inc b/mode7/deater_scroll.inc index 681498ba..c234891b 100644 --- a/mode7/deater_scroll.inc +++ b/mode7/deater_scroll.inc @@ -1,9 +1,10 @@ -scroll_length: .byte 167 -scroll_row1: - .byte $00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$20,$20,$00,$00,$00,$20,$20,$20,$20,$00,$00,$20,$20,$00,$00,$20,$20,$20,$00,$20,$20,$20,$20,$00,$20,$20,$20,$00,$00,$00,$00,$00,$00,$00,$40,$00,$00,$00,$40,$00,$00,$40,$40,$00,$00,$00,$40,$40,$40,$00,$00,$00,$00,$00,$00,$10,$00,$00,$10,$00,$10,$10,$10,$10,$00,$10,$10,$10,$00,$00,$10,$10,$10,$10,$00,$10,$10,$10,$00,$10,$10,$10,$00,$10,$10,$10,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00 -scroll_row2: - .byte $00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$E6,$00,$06,$E0,$00,$E6,$00,$00,$00,$00,$E6,$00,$00,$E6,$00,$00,$E6,$00,$00,$E6,$00,$00,$00,$00,$E6,$00,$00,$E6,$00,$00,$00,$00,$00,$00,$DC,$00,$00,$00,$DC,$00,$DC,$00,$00,$DC,$00,$DC,$00,$00,$00,$00,$00,$00,$00,$00,$00,$B3,$00,$00,$B3,$00,$B3,$00,$00,$00,$00,$B3,$00,$00,$B3,$00,$B3,$00,$00,$00,$00,$03,$B3,$03,$00,$03,$B3,$03,$00,$03,$B3,$03,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00 -scroll_row3: - .byte $00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$EF,$00,$00,$EF,$00,$EF,$0F,$0F,$00,$00,$EF,$0F,$0F,$EF,$00,$00,$EF,$00,$00,$EF,$0F,$0F,$00,$00,$EF,$0F,$0F,$E0,$00,$00,$00,$00,$00,$00,$DF,$00,$D0,$00,$DF,$00,$DF,$0F,$0F,$DF,$00,$00,$0F,$0F,$D0,$00,$00,$00,$00,$00,$00,$BF,$0F,$0F,$BF,$00,$BF,$0F,$0F,$00,$00,$BF,$0F,$0F,$B0,$00,$BF,$0F,$0F,$00,$00,$00,$0F,$00,$00,$00,$0F,$00,$00,$00,$0F,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00 -scroll_row4: - .byte $00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$26,$20,$06,$00,$00,$26,$20,$20,$20,$00,$26,$00,$00,$26,$00,$00,$26,$00,$00,$26,$20,$20,$20,$00,$26,$00,$00,$26,$00,$00,$00,$00,$00,$00,$4C,$0C,$00,$0C,$4C,$00,$4C,$00,$00,$4C,$00,$40,$40,$40,$0C,$00,$00,$00,$00,$00,$00,$13,$00,$00,$13,$00,$13,$10,$10,$10,$00,$13,$00,$00,$13,$00,$13,$10,$10,$10,$00,$00,$13,$00,$00,$00,$13,$00,$00,$00,$13,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00 +; Original size = 668 bytes +deater_scroll: +; scroll_length: +.byte 167 + .byte $A0,$28,$00,$20,$20,$A3,$00,$A4,$20,$00,$00,$20,$20,$00,$00,$A3,$20,$00,$A4,$20,$00,$A3,$20,$A7,$00,$40,$A3,$00,$40,$00,$00,$40,$40,$A3,$00,$A3,$40,$A6,$00,$10,$00,$00,$10,$00,$A4,$10,$00,$A3,$10,$00,$00,$A4,$10,$00,$A3,$10,$00,$A3,$10,$00,$A3,$10,$A0,$82,$00 + .byte $A0,$28,$00,$E6,$00,$06,$E0,$00,$E6,$A4,$00,$E6,$00,$00,$E6,$00,$00,$E6,$00,$00,$E6,$A4,$00,$E6,$00,$00,$E6,$A6,$00,$DC,$A3,$00,$DC,$00,$DC,$00,$00,$DC,$00,$DC,$A9,$00,$B3,$00,$00,$B3,$00,$B3,$A4,$00,$B3,$00,$00,$B3,$00,$B3,$A4,$00,$03,$B3,$03,$00,$03,$B3,$03,$00,$03,$B3,$03,$A0,$82,$00 + .byte $A0,$28,$00,$EF,$00,$00,$EF,$00,$EF,$0F,$0F,$00,$00,$EF,$0F,$0F,$EF,$00,$00,$EF,$00,$00,$EF,$0F,$0F,$00,$00,$EF,$0F,$0F,$E0,$A6,$00,$DF,$00,$D0,$00,$DF,$00,$DF,$0F,$0F,$DF,$00,$00,$0F,$0F,$D0,$A6,$00,$BF,$0F,$0F,$BF,$00,$BF,$0F,$0F,$00,$00,$BF,$0F,$0F,$B0,$00,$BF,$0F,$0F,$A3,$00,$0F,$A3,$00,$0F,$A3,$00,$0F,$A0,$83,$00 + .byte $A0,$28,$00,$26,$20,$06,$00,$00,$26,$A3,$20,$00,$26,$00,$00,$26,$00,$00,$26,$00,$00,$26,$A3,$20,$00,$26,$00,$00,$26,$A6,$00,$4C,$0C,$00,$0C,$4C,$00,$4C,$00,$00,$4C,$00,$A3,$40,$0C,$A6,$00,$13,$00,$00,$13,$00,$13,$A3,$10,$00,$13,$00,$00,$13,$00,$13,$A3,$10,$00,$00,$13,$A3,$00,$13,$A3,$00,$13,$A0,$83,$00 + .byte $A1 +; Compressed size = 294 bytes diff --git a/mode7/mode7.dsk b/mode7/mode7.dsk index 8f692df3c892105e1b7e37ffe8cf69d78ae527e1..0a0a9d0ce7871cd537a0359d7f136e5b6d2de889 100644 GIT binary patch delta 17011 zcmeHOeQXrR6`z^?-ktrp^WE*4^WE(o!39K!p_M{hNRE`!6pZyt3p+=IVJB=FW;U?K_s5sDxrEj^ZhS5-EwoluRj< z<@qK2)P&1Eh98(c%XHXpUR~A=Tg|TJy3;egKRK}KmCO(Oec3?rdiFQTfvlFi6wE%B zylgD==lgoi>MDIkG&%5xnpKsHF@NWj?DDW(|_5eczwe$#hw> zdZ9i&GD?KLkrQ*rDfYM-D{c|t$`~U9_DHzX+`4ct-;x)hg@~~501{hV5so;EbK;qh z$L_MlI6|hKoK<7|#r*Bc8K$<*BiUE-614=(IqPn&)3Nm%s1jPDF)h;ytx|x36rw1~ z^c*6~wCQ7*GkZ4a!Z|WCHF+uXnR(-xF4$~#C3NS?baG|HavdKj!PlJS`oOGStk2MI zk+o}#kz`>P>u{;L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!qTNt01&-et<5 z*c|YQM*}|bDB}~)mgWb@QW%P`Z@k6(jIc8++EXo2?Iz9jAoLA|1YZzuE z$yhS~amO%x9AoftY&3kl#o*%@fe)}C@UcCBkNX&W zEN1XQv;;ox3*h4h1|Mq~e5@UY4`N5*V|xG}PX_SuB!iFVOT$N?zEtpWdo0Umg{+vB qvT|0*s#z_oXN~OC7SZS}qO1);9qe!p?+A|QNRI4`*&-@>Ip{x{vp|Ue diff --git a/mode7/mode7.s b/mode7/mode7.s index 8d520b32..ac2c99ba 100644 --- a/mode7/mode7.s +++ b/mode7/mode7.s @@ -1104,14 +1104,6 @@ exit: ; Variables ;=============================================== - ; waste memory with a lookup table - ; move this to the zeropage? - -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 - .if .def(ISLAND_MAP) .include "island_map.inc" .endif diff --git a/mode7/scroll_demo.s b/mode7/scroll_demo.s index 43cfcd05..bdd0c1d0 100644 --- a/mode7/scroll_demo.s +++ b/mode7/scroll_demo.s @@ -1,6 +1,13 @@ .include "zp.inc" +scroll_row1 EQU $8A00 +scroll_row2 EQU $8B00 +scroll_row3 EQU $8C00 +scroll_row4 EQU $8D00 + +SCROLL_LENGTH EQU $E6 + ;================================ ; Clear screen and setup graphics ;================================ @@ -15,6 +22,16 @@ sta DISP_PAGE sta ANGLE + ;======================= + ; decompress scroll text + ;======================= + lda #>deater_scroll + sta INH + lda #scroll_row1 + sta OUTH + +decompress_scroll_loop: + jsr load_and_increment ; load compressed value + + cmp #$A1 ; EOF marker + beq done_decompress_scroll ; if EOF, exit + + pha ; save + + and #$f0 ; mask + cmp #$a0 ; see if special AX + beq decompress_special + + pla ; note, PLA sets flags! + + ldx #$1 ; only want to print 1 + bne decompress_run + +decompress_special: + pla + + and #$0f ; check if was A0 + + bne decompress_color ; if A0 need to read run, color + +decompress_large: + jsr load_and_increment ; get run length + +decompress_color: + tax ; put runlen into X + jsr load_and_increment ; get color + +decompress_run: + sta (OUTL),Y + pha + + clc ; increment 16-bit pointer + lda OUTL + adc #$1 + sta OUTL + lda OUTH + adc #$0 + sta OUTH + + pla + + dex ; repeat for X times + bne decompress_run + + beq decompress_scroll_loop ; get next run + +done_decompress_scroll: + rts + + +load_and_increment: + lda (INL),Y ; load and increment 16-bit pointer + pha + clc + lda INL + adc #$1 + sta INL + lda INH + adc #$0 + sta INH + pla + rts + ;=============================================== ; Variables @@ -105,11 +199,253 @@ blah: .include "deater_scroll.inc" - ; waste memory with a lookup table - ; move this to the zeropage? +;===================================================================== +;= 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 + + ;========== + ; page_flip + ;========== + +page_flip: +; lda $c019 ; wait for vertical refresh +; bmi page_flip + + lda DISP_PAGE ; 3 + beq page_flip_show_1 ; 2nt/3 +page_flip_show_0: + bit PAGE0 ; 4 + lda #4 ; 2 + sta DRAW_PAGE ; DRAW_PAGE=1 ; 3 + lda #0 ; 2 + sta DISP_PAGE ; DISP_PAGE=0 ; 3 + rts ; 6 +page_flip_show_1: + bit PAGE1 ; 4 + sta DRAW_PAGE ; DRAW_PAGE=0 ; 3 + lda #1 ; 2 + sta DISP_PAGE ; DISP_PAGE=1 ; 3 + rts ; 6 + ;==================== + ; DISP_PAGE=0 26 + ; DISP_PAGE=1 24 + + + + ;========================================================== + ; set_gr_page0 + ;========================================================== + ; +set_gr_page0: + ;lda #4 + ;sta GR_PAGE + bit PAGE0 ; set page 0 + bit LORES ; Lo-res graphics + bit TEXTGR ; mixed gr/text mode + bit SET_GR ; set graphics + rts + + + + ;================================ + ; hlin_setup + ;================================ + ; put address in GBASL/GBASH + ; Ycoord in A, Xcoord in Y +hlin_setup: + sty TEMPY ; 3 + tay ; y=A ; 2 + lda gr_offsets,Y ; lookup low-res memory address ; 4 + clc ; 2 + adc TEMPY ; 3 + sta GBASL ; 3 + iny ; 2 + + lda gr_offsets,Y ; 4 + adc DRAW_PAGE ; add in draw page offset ; 3 + sta GBASH ; 3 + rts ; 6 + ;=========== + ; 35 + ;================================ + ; hlin_double: + ;================================ + ; HLIN Y, V2 AT A + ; Y, X, A trashed + ; start at Y, draw up to and including X +hlin_double: +;int hlin_double(int page, int x1, int x2, int at) { + + jsr hlin_setup ; 41 + + sec ; 2 + lda V2 ; 3 + sbc TEMPY ; 3 + + tax ; 2 + inx ; 2 + ;=========== + ; 53 + ; fallthrough + + ;================================= + ; hlin_double_continue: width + ;================================= + ; width in X + +hlin_double_continue: + + ldy #0 ; 2 + lda COLOR ; 3 +hlin_double_loop: + sta (GBASL),Y ; 6 + inc GBASL ; 5 + dex ; 2 + bne hlin_double_loop ; 2nt/3 + + rts ; 6 + ;============= + ; 53+5+X*16+5 + + ;================================ + ; hlin_single: + ;================================ + ; HLIN Y, V2 AT A + ; Y, X, A trashed +hlin_single: + + jsr hlin_setup + + sec + lda V2 + sbc TEMPY + + tax + + ; fallthrough + + ;================================= + ; hlin_single_continue: width + ;================================= + ; width in X + +hlin_single_continue: + +hlin_single_top: + lda COLOR + and #$f0 + sta COLOR + +hlin_single_top_loop: + ldy #0 + lda (GBASL),Y + and #$0f + ora COLOR + sta (GBASL),Y + inc GBASL + dex + bne hlin_single_top_loop + + rts + +hlin_single_bottom: + + lda COLOR + and #$0f + sta COLOR + +hlin_single_bottom_loop: + ldy #0 + lda (GBASL),Y + and #$f0 + sta (GBASL),Y + inc GBASL + dex + bne hlin_single_bottom_loop + + rts + + + ;============================= + ; clear_top + ;============================= +clear_top: + lda #$00 + + ;============================= + ; clear_top_a + ;============================= +clear_top_a: + + sta COLOR + + ; VLIN Y, V2 AT A + + lda #40 + 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: + lda #$a0 ; NORMAL space + 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 $428,$4a8,$528,$5a8,$628,$6a8,$728,$7a8 .word $450,$4d0,$550,$5d0,$650,$6d0,$750,$7d0 - diff --git a/mode7/scroller.c b/mode7/scroller.c index bd62dbcd..5a4be403 100644 --- a/mode7/scroller.c +++ b/mode7/scroller.c @@ -1,6 +1,5 @@ -/* Use grey2 to make RLE more efficient? */ - #include +#include #include static unsigned char font[256][9]={ @@ -286,51 +285,90 @@ static int color_map[4][8]={ }; +static int runlen[4]={0,0,0,0},last_color[4]={0,0,0,0}; +static int new_size=0; + +static unsigned char row[4][256]; + +static int rle_compress(int color, int j) { + + int need_comma=0; + + if (color==last_color[j]) { + runlen[j]++; + } + else { +// printf("Run of color %d length %d\n", +// last_color[j],runlen[j]); + if (runlen[j]==0) ; // first color, skip + if (runlen[j]==1) { + printf("$%02X",last_color[j]); + new_size++; + } + if (runlen[j]==2) { + printf("$%02X,$%02X",last_color[j],last_color[j]); + new_size+=2; + } + + if ((runlen[j]>2) && (runlen[j]<16)) { + printf("$%02X,$%02X",0xa0 | (runlen[j]), + last_color[j]); + new_size+=2; + } + /* We could in theory compress up to 272 */ + /* but we leave it at 256 to make the decode easier */ + if ((runlen[j]>15) && (runlen[j]<256)) { + new_size+=3; + printf("$%02X,$%02X,$%02X",0xa0, + runlen[j],last_color[j]); + } + if (runlen[j]>256) { + printf("Too big!\n"); + exit(1); + } + + runlen[j]=1; + need_comma=1; + } + return need_comma; +} + int main(int argc, char **argv) { //char string[]="ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"; char string[]=" \001DEATER \002WAS \003HERE!!! "; - int length=0,width=0,x,y,i; + int length=0,width=0,x,y,i,j; int color,color1,color2; int which_color=0; - - unsigned char row[4][256]; + int need_comma; for(i=0;i>x)); - color1=color?color_map[which_color][0]:0; - color=!!(font[(int)string[i]][2]&(0x80>>x)); - color2=color?(color_map[which_color][1])<<4:0; - row[0][length]=color1|color2; + for(j=0;j<4;j++) { + color=!!(font[(int)string[i]][1+j*2]&(0x80>>x)); + color1=color?color_map[which_color][0+j*2]:0; + color=!!(font[(int)string[i]][2+j*2]&(0x80>>x)); + color2=color?(color_map[which_color][1+j*2])<<4:0; + color=color1|color2; + row[j][length]=color; - color=!!(font[(int)string[i]][3]&(0x80>>x)); - color1=color?color_map[which_color][2]:0; - color=!!(font[(int)string[i]][4]&(0x80>>x)); - color2=color?(color_map[which_color][3])<<4:0; - row[1][length]=color1|color2; - - color=!!(font[(int)string[i]][5]&(0x80>>x)); - color1=color?color_map[which_color][4]:0; - color=!!(font[(int)string[i]][6]&(0x80>>x)); - color2=color?(color_map[which_color][5])<<4:0; - row[2][length]=color1|color2; - - color=!!(font[(int)string[i]][7]&(0x80>>x)); - color1=color?color_map[which_color][6]:0; - color=!!(font[(int)string[i]][8]&(0x80>>x)); - color2=color?(color_map[which_color][7])<<4:0; - row[3][length]=color1|color2; + if (color1==0xa) { + printf("Error! Can't use grey2!\n"); + exit(0); + } + } length++; } } + printf("; Original size = %d bytes\n",length*4); +#if 0 printf("scroll_length: .byte %d\n",length); for(y=0;y<4;y++) { printf("scroll_row%d:\n",y+1); @@ -341,6 +379,24 @@ int main(int argc, char **argv) { } printf("\n"); } +#endif + printf("deater_scroll:\n"); + printf("; scroll_length:\n.byte %d\n",length); + for(y=0;y<4;y++) { + //printf("scroll_row%d:\n",y+1); + printf("\t.byte "); + for(x=0;x<256;x++) { + need_comma=rle_compress(row[y][x],y); + if ((need_comma) && (x!=length-1)) printf(","); + last_color[y]=row[y][x]; + } + rle_compress(-1,y); + printf("\n"); + } + printf("\t.byte $A1\n"); + new_size++; + printf("; Compressed size = %d bytes\n",new_size); + return 0; } diff --git a/mode7/utils.s b/mode7/utils.s index 328c2a8e..f45c0b5d 100644 --- a/mode7/utils.s +++ b/mode7/utils.s @@ -542,3 +542,11 @@ clear_bottom_loop: 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 +