mode7: update scroller to use compressed files

This commit is contained in:
Vince Weaver 2017-12-14 15:59:54 -05:00
parent 8657ed35d4
commit c534cf4b3e
6 changed files with 446 additions and 53 deletions

View File

@ -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

Binary file not shown.

View File

@ -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

View File

@ -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 #<deater_scroll
sta INL
jsr decompress_scroll
scroll_loop:
ldx #0
@ -83,7 +100,7 @@ sm4:
clc
lda ANGLE
adc #40
cmp scroll_length
cmp SCROLL_LENGTH
bne blah
lda #0
sta ANGLE
@ -93,11 +110,88 @@ blah:
inc ANGLE
jmp scroll_loop ; 3
;===============================================
; External modules
;===============================================
.include "utils.s"
;=======================
; decompress scroll
;=======================
decompress_scroll:
ldy #0
jsr load_and_increment
sta SCROLL_LENGTH
lda #<scroll_row1
sta OUTL
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

View File

@ -1,6 +1,5 @@
/* Use grey2 to make RLE more efficient? */
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
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<strlen(string);i++) {
if (string[i]<5) { which_color=string[i]-1; continue;}
width=font[(int)string[i]][0];
for(x=0;x<width;x++) {
color=!!(font[(int)string[i]][1]&(0x80>>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;
}

View File

@ -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