mode7: work on scrolling sky

This commit is contained in:
Vince Weaver 2017-12-18 15:26:31 -05:00
parent 68731d3182
commit 531b20478b
5 changed files with 305 additions and 3 deletions

View File

@ -4,17 +4,18 @@ DOS33 = ../dos33fs-utils/dos33
PNG2GR = ../gr-utils/png2gr
PNG2RLE = ../gr-utils/png2rle
all: mode7.dsk scroller
all: mode7.dsk scroller background
$(DOS33):
cd ../dos33fs-utils && make
mode7.dsk: $(DOS33) MODE7_ISLAND MODE7_CHECKERBOARD MODE7_RAINBOW \
SCROLL_DEMO
SCROLL_DEMO SKY_DEMO
$(DOS33) -y mode7.dsk BSAVE -a 0x1000 MODE7_ISLAND
$(DOS33) -y mode7.dsk BSAVE -a 0x1000 MODE7_CHECKERBOARD
$(DOS33) -y mode7.dsk BSAVE -a 0x1000 MODE7_RAINBOW
$(DOS33) -y mode7.dsk BSAVE -a 0x1000 SCROLL_DEMO
$(DOS33) -y mode7.dsk BSAVE -a 0x1000 SKY_DEMO
###
@ -72,14 +73,31 @@ scroll_demo.o: scroll_demo.s \
../asm_routines/gr_setpage.s
ca65 -o scroll_demo.o scroll_demo.s -l scroll_demo.lst
SKY_DEMO: sky_demo.o
ld65 -o SKY_DEMO sky_demo.o -C ./apple2_1000.inc
sky_demo.o: sky_demo.s \
starry_sky.scroll \
../asm_routines/hlin_clearscreen.s \
../asm_routines/gr_scroll.s \
../asm_routines/pageflip.s \
../asm_routines/gr_setpage.s
ca65 -o sky_demo.o sky_demo.s -l sky_demo.lst
scroller: scroller.o
$(CC) $(LFLAGS) -o scroller scroller.o
scroller.o: scroller.c
$(CC) $(CFLAGS) -c scroller.c
background: background.o
$(CC) $(LFLAGS) -o background background.o
background.o: background.c
$(CC) $(CFLAGS) -c background.c
clean:
rm -f *~ *.o scroller \
rm -f *~ *.o scroller background \
MODE7 MODE7_ISLAND MODE7_CHECKERBOARD MODE7_RAINBOW \
SCROLL_DEMO *.lst

116
mode7/background.c Normal file
View File

@ -0,0 +1,116 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
static int runlen[4]={0,0,0,0},last_color[4]={-1,-1,-1,-1};
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]<255)) {
runlen[j]++;
// printf("Match %d %d\n",color,runlen[j]);
}
else {
need_comma=1;
// printf("Run of color %d length %d\n",
// last_color[j],runlen[j]);
if (runlen[j]==0) { // first color, skip
need_comma=0;
}
else if (runlen[j]==1) {
printf("$%02X",last_color[j]);
new_size++;
}
else if (runlen[j]==2) {
printf("$%02X,$%02X",last_color[j],last_color[j]);
new_size+=2;
}
else 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 */
else if ((runlen[j]>15) && (runlen[j]<256)) {
new_size+=3;
printf("$%02X,$%02X,$%02X",0xa0,
runlen[j],last_color[j]);
}
else if (runlen[j]>=256) {
printf("Too big!\n");
exit(1);
}
last_color[j]=color;
runlen[j]=1;
}
return need_comma;
}
void plot(int x, int y, int color) {
int half,odd;
half=y/2;
odd=y&1;
if (odd) {
row[half][x]=row[half][x]|(color<<4);
}
else {
row[half][x]=row[half][x]|(color);
}
}
int main(int argc, char **argv) {
int length=0,x,y;
int need_comma;
memset(row,0,sizeof(row));
length=255;
/* 0 - 20 */
plot(2,5,15); plot(5,2,15); plot(9,1,13);
plot(12,3,15); plot(13,5,15); plot(16,5,15); plot(17,2,15);
plot(19,1,5); plot(20,0,5); plot(20,2,5); plot(21,1,5);
plot(20,1,15);
printf("; Original size = %d bytes\n",length*4);
printf("sky_background:\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

@ -603,6 +603,11 @@ update_z_factor:
draw_background_mode7:
.if .def(CHECKERBOARD_MAP)
.else
; Only draw sky if necessary
; (at start, or if we have switched to text, we never overwrite it)
@ -645,6 +650,8 @@ sky_loop: ; draw line across screen
;===========
; 63+(X*16)+14
.endif
no_draw_sky:
; setup initial odd/even color mask

151
mode7/sky_demo.s Normal file
View File

@ -0,0 +1,151 @@
.include "zp.inc"
;================================
; Clear screen and setup graphics
;================================
jsr clear_screens ; clear top/bottom of page 0/1
jsr set_gr_page0
;===============
; Init Variables
;===============
lda #0
sta DISP_PAGE
;=======================
; decompress scroll text
;=======================
lda #0
sta CV
sta ANGLE
lda #>sky_background
sta INH
lda #<sky_background
sta INL
jsr decompress_scroll
scroll_forever:
jsr scroll_background
; lda #250
; jsr WAIT
jsr wait_until_keypressed
inc ANGLE
lda ANGLE
and #$0f
sta ANGLE
jmp scroll_forever
;===============================================
; Routines
;===============================================
.include "../asm_routines/hlin_clearscreen.s"
.include "../asm_routines/gr_scroll.s"
.include "../asm_routines/pageflip.s"
.include "../asm_routines/gr_setpage.s"
.include "../asm_routines/keypress.s"
;===============================================
; Variables
;===============================================
.include "starry_sky.scroll"
;==================
; scroll background
;==================
; background already loaded
; ANGLE 0-15 sets angle
; CV is Y position to display at
; 182/220... 220/16 = 13.75
; 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
; 0 13 27 41 55 68 82 96 110 123 137 151 165 178 192 206 220
scroll_offsets:
.byte 0,13,27,41,55,68,82,96,110,123,137,151,165,178,192,206
scroll_background:
ldy ANGLE
lda scroll_offsets,Y
sta OFFSET
scrollbg_loop:
ldx #0
ldy CV
lsr
lda gr_offsets,Y ; get position
sta bgsm1+1
lda gr_offsets+2,Y ; get position
sta bgsm2+1
lda gr_offsets+4,Y ; get position
sta bgsm3+1
lda gr_offsets+6,Y ; get position
sta bgsm4+1
iny
clc
lda gr_offsets,Y ; get position
adc DRAW_PAGE
sta bgsm1+2
lda gr_offsets+2,Y ; get position
adc DRAW_PAGE
sta bgsm2+2
lda gr_offsets+4,Y ; get position
adc DRAW_PAGE
sta bgsm3+2
lda gr_offsets+6,Y ; get position
adc DRAW_PAGE
sta bgsm4+2
ldy OFFSET
bgdraw_loop:
lda scroll_row1,Y
bgsm1:
sta $400,X
lda scroll_row2,Y
bgsm2:
sta $480,X
lda scroll_row3,Y
bgsm3:
sta $500,X
lda scroll_row4,Y
bgsm4:
sta $580,X
iny
inx
cpx #40
bne bgdraw_loop
;==================
; flip pages
;==================
jsr page_flip ; 6
done_bgscrolling:
rts

10
mode7/starry_sky.scroll Normal file
View File

@ -0,0 +1,10 @@
; Original size = 1020 bytes
sky_background:
; scroll_length:
.byte 255
.byte $A9,$00,$D0,$A9,$00,$50,$F5,$50,$A0,$EA,$00
.byte $A5,$00,$0F,$A6,$00,$F0,$A4,$00,$0F,$00,$00,$05,$A0,$EB,$00
.byte $00,$00,$F0,$AA,$00,$F0,$00,$00,$F0,$A0,$EF,$00
.byte $A0,$FF,$00,$00
.byte $A1
; Compressed size = 43 bytes