tiles: initial implementation

This commit is contained in:
Vince Weaver
2025-11-13 00:28:42 -05:00
parent 76b9e24d97
commit cc46c15ee7
5 changed files with 284 additions and 17 deletions
+14 -1
View File
@@ -14,10 +14,12 @@ all: tile_compress.dsk
####
tile_compress.dsk: HELLO \
SATURN_ZX02
SATURN_ZX02 \
SATURN_TILES
cp $(EMPTY_DISK) tile_compress.dsk
$(DOS33) -y tile_compress.dsk SAVE A HELLO
$(DOS33) -y tile_compress.dsk BSAVE -a 0x6000 SATURN_ZX02
$(DOS33) -y tile_compress.dsk BSAVE -a 0x6000 SATURN_TILES
####
@@ -31,6 +33,17 @@ saturn_zx02.o: saturn_zx02.s zx02_optim.s \
####
SATURN_TILES: saturn_tiles.o
ld65 -o SATURN_TILES saturn_tiles.o -C $(LINKER_SCRIPTS)/apple2_6000.inc
saturn_tiles.o: saturn_tiles.s \
zp.inc hardware.inc \
graphics/saturn_tiles.inc
ca65 -o saturn_tiles.o saturn_tiles.s -l saturn_tiles.lst
####
HELLO: hello.bas
$(TOKENIZE) < hello.bas > HELLO
@@ -8,9 +8,12 @@ PNG_TO_DHGR4 = ../../../../utils/hgr-utils/png2dhgr4
PNG2GR = ../../../../utils/gr-utils/png2gr
HGR_SPRITE = ../../../../utils/hgr-utils/hgr_make_sprite
LINKER_SCRIPTS = ../../../../linker_scripts/
LZSA = ~/research/lzsa/lzsa/lzsa
all: pa_house_bottom2.hgr.zx02 \
a2_saturn_warrior.hgr.zx02
a2_saturn_warrior.hgr.zx02 \
a2_saturn_warrior.hgr.lz4 \
a2_saturn_warrior.hgr.lzsa
####
@@ -25,12 +28,24 @@ pa_house_bottom2.hgr: pa_house_bottom2.png
a2_saturn_warrior.hgr.zx02: a2_saturn_warrior.hgr
$(ZX02) a2_saturn_warrior.hgr a2_saturn_warrior.hgr.zx02
a2_saturn_warrior.hgr.init: a2_saturn_warrior.hgr
lz4 -f -16 a2_saturn_warrior.hgr a2_saturn_warrior.hgr.init
a2_saturn_warrior.hgr.lz4: a2_saturn_warrior.hgr.init
dd if=a2_saturn_warrior.hgr.init of=a2_saturn_warrior.hgr.lz4 bs=1 skip=11
truncate a2_saturn_warrior.hgr.lz4 -s -8
a2_saturn_warrior.hgr.lzsa: a2_saturn_warrior.hgr
$(LZSA) -r -f2 a2_saturn_warrior.hgr a2_saturn_warrior.hgr.lzsa
a2_saturn_warrior.hgr: a2_saturn_warrior.png
$(PNG_TO_HGR) a2_saturn_warrior.png > a2_saturn_warrior.hgr
####
clean:
rm -f *~ *.zx02 *.lst *.o *.AUX *.BIN *.raw_top *.raw_bottom *.hgr house_sprites.inc
rm -f *~ *.zx02 *.lz4 *.lzsa *.lst *.o *.AUX *.BIN *.raw_top *.raw_bottom *.hgr house_sprites.inc
+101
View File
@@ -0,0 +1,101 @@
;div7_table = $b800
;mod7_table = $b900
;hposn_high = $ba00
;hposn_low = $bb00
;=====================
; make /7 %7 tables
;=====================
.if 0
hgr_make_7_tables:
ldy #0
lda #0
ldx #0
div7_loop:
sta div7_table,Y
inx
cpx #7
bne div7_not7
clc
adc #1
ldx #0
div7_not7:
iny
bne div7_loop
ldy #0
lda #0
mod7_loop:
sta mod7_table,Y
clc
adc #1
cmp #7
bne mod7_not7
lda #0
mod7_not7:
iny
bne mod7_loop
rts
.endif
hgr_make_tables:
; Hposn table
; hposn_low, hposn_high will each be filled with $C0 bytes
; based on routine by John Brooks
; posted on comp.sys.apple2 on 2018-07-11
; https://groups.google.com/d/msg/comp.sys.apple2/v2HOfHOmeNQ/zD76fJg_BAAJ
; clobbers A,X
; preserves Y
; vmw note: version I was using based on applesoft HPOSN was ~64 bytes
; this one is 37 bytes
build_hposn_tables:
ldx #0
btmi:
txa
and #$F8
bpl btpl1
ora #5
btpl1:
asl
bpl btpl2
ora #5
btpl2:
asl
asl
sta hposn_low, X
txa
and #7
rol
asl hposn_low, X
rol
ora #$20
sta hposn_high, X
inx
cpx #$C0
bne btmi
; go 16 beyond, which allows our text scrolling routine
; ldx #16
;extra_table_loop:
; lda hposn_low,X
; sta hposn_low+192,X
; lda hposn_high,X
; eor #$60
; sta hposn_high+192,X
; dex
; bpl extra_table_loop
rts
@@ -0,0 +1,103 @@
; tiles compression test
.include "zp.inc"
.include "hardware.inc"
hposn_high = $1000
hposn_low = $1100
XPOS = $E0
YPOS = $E1
ROW = $E2
saturn_tiles_start:
bit HIRES
bit FULLGR
bit SET_GR
bit PAGE1
lda #0
sta XPOS
sta YPOS
jsr hgr_make_tables
; for(t=0;t<40*24;t++)
tilemap_loop:
tilemap_smc:
lda tilemap
cmp #$ff
beq tilemap_done
tax
lda tile_lookup_l,X
sta tile_smc+1
lda tile_lookup_h,X
sta tile_smc+2
lda #0
sta ROW
inner_loop:
clc
lda YPOS
adc ROW
tax
lda hposn_low,X
sta output_smc+1
lda hposn_high,X
sta output_smc+2
ldx ROW
ldy XPOS
tile_smc:
lda tile0,X
output_smc:
sta $2000,Y
inc ROW
lda ROW
cmp #8
bne inner_loop
;
;
;
inc XPOS
lda XPOS
cmp #40
bne no_xpos_oflo
lda #0
sta XPOS
lda YPOS
clc
adc #8
sta YPOS
no_xpos_oflo:
inc tilemap_smc+1
bne tilemap_noflo
inc tilemap_smc+2
tilemap_noflo:
jmp tilemap_loop
tilemap_done:
forever:
jmp forever
.include "hgr_table.s"
.include "graphics/saturn_tiles.inc"
+49 -14
View File
@@ -413,11 +413,10 @@ int main(int argc, char **argv) {
exit(1);
}
for(i=optind;i<argc;i++) {
printf("%i %s\n",i,argv[i]);
}
// for(i=optind;i<argc;i++) {
// printf("%i %s\n",i,argv[i]);
// }
#if 0
filename=strdup(argv[optind]);
memset(apple2_image,0,8192);
@@ -456,28 +455,41 @@ int main(int argc, char **argv) {
// fwrite(apple2_image,8192,sizeof(unsigned char),stdout);
#define MAX_TILES 1024
unsigned char temp_tile[8];
#define MAX_TILES 1024
#define TILE_HEIGHT 8
unsigned char temp_tile[TILE_HEIGHT];
int num_tiles=0;
unsigned char tiles[1024][8];
unsigned char tiles[MAX_TILES][TILE_HEIGHT];
unsigned char tilemap[40][24];
int l,t;
/* clear it out */
for(y=0;y<TILE_HEIGHT;y++) {
temp_tile[y]=0;
}
for(t=0;t<MAX_TILES;t++) {
for(y=0;y<TILE_HEIGHT;y++) {
tiles[t][y]=0;
}
}
for(x=0;x<40;x++) {
for(y=0;y<192;y+=8) {
/* create current tile */
for(l=0;l<8;l++) {
for(l=0;l<TILE_HEIGHT;l++) {
temp_tile[l]=apple2_image[hgr_offset(y+l)+x];
}
/* look for match */
for(t=0;t<num_tiles;t++) {
for(l=0;l<8;l++) {
for(l=0;l<TILE_HEIGHT;l++) {
if (temp_tile[l]!=tiles[t][l]) break;
}
/* check if match */
if (l==8) {
tilemap[x][y/8]=t;
printf("*%d,%d=%d\n",x,y/8,t);
//printf("*%d,%d=%d\n",x,y/8,t);
break;
}
}
@@ -487,16 +499,17 @@ int main(int argc, char **argv) {
tiles[t][l]=temp_tile[l];
}
tilemap[x][y/8]=t;
printf("%d,%d=%d\n",x,y/8,t);
//printf("%d,%d=%d\n",x,y/8,t);
num_tiles++;
}
}
}
fprintf(stderr,"Total unique tiles %d\n",num_tiles);
fprintf(stderr,"Total warnings: %d\n",color_warnings);
printf("; Total unique tiles %d\n",num_tiles);
printf("; Total warnings: %d\n",color_warnings);
printf("; Tilemap\n");
printf("tilemap:\n");
for(y=0;y<24;y++) {
printf(".byte\t");
for(x=0;x<40;x++) {
@@ -505,6 +518,28 @@ int main(int argc, char **argv) {
}
printf("\n");
}
#endif
printf(".byte $FF\n");
printf("; Tile lookup\n");
printf("tile_lookup_l:\n");
for(t=0;t<num_tiles;t++) {
printf("\t.byte\t<tile%d\n",t);
}
printf("tile_lookup_h:\n");
for(t=0;t<num_tiles;t++) {
printf("\t.byte\t>tile%d\n",t);
}
printf("; Tiles\n");
for(t=0;t<num_tiles;t++) {
printf("tile%d:\n",t);
for(y=0;y<TILE_HEIGHT;y++) {
printf("\t.byte $%02X\n",tiles[t][y]);
}
}
return 0;
}