mirror of
https://github.com/deater/dos33fsprogs.git
synced 2025-01-13 22:30:49 +00:00
fancy_lores: add 4048d viewer
This commit is contained in:
parent
7557c966a2
commit
af97f5583a
@ -2,24 +2,34 @@ include ../Makefile.inc
|
||||
|
||||
DOS33 = ../dos33fs-utils/dos33
|
||||
|
||||
all: fancy_lores_viewer.dsk png_to_40x96 katahdin_40_96.inc
|
||||
all: fancy_lores_viewer.dsk png_to_40x96 png_to_40x48d
|
||||
|
||||
fancy_lores_viewer.dsk: DISP4096
|
||||
fancy_lores_viewer.dsk: DISP4096 DISP4048D
|
||||
$(DOS33) -y fancy_lores_viewer.dsk BSAVE -a 0x1000 DISP4096
|
||||
$(DOS33) -y fancy_lores_viewer.dsk BSAVE -a 0x1000 DISP4048D
|
||||
# $(DOS33) -y fancy_lores_viewer.dsk BSAVE -a 0x2000 APPLE_ORIG.BIN
|
||||
# $(DOS33) -y fancy_lores_viewer.dsk BSAVE -a 0x2000 KATAHDIN_ORIG.BIN
|
||||
|
||||
####
|
||||
|
||||
DISP4096: disp4096.o
|
||||
ld65 -o DISP4096 disp4096.o -C ../linker_scripts/apple2_1000.inc
|
||||
|
||||
|
||||
disp4096.o: disp4096.s gr_copy.s \
|
||||
apple_40_96.inc katahdin_40_96.inc
|
||||
ca65 -o disp4096.o disp4096.s -l disp4096.lst
|
||||
|
||||
katahdin_40_96.inc: png_to_40x96 katahdin_40_96.png
|
||||
./png_to_40x96 asm katahdin_40_96.png katahdin > katahdin_40_96.inc
|
||||
####
|
||||
|
||||
apple_40_96.inc: png_to_40x96 apple_40_96.png
|
||||
./png_to_40x96 asm apple_40_96.png apple > apple_40_96.inc
|
||||
DISP4048D: disp4048d.o
|
||||
ld65 -o DISP4048D disp4048d.o -C ../linker_scripts/apple2_1000.inc
|
||||
|
||||
disp4048d.o: disp4048d.s gr_copy.s \
|
||||
apple_40_48d.inc katahdin_40_48d.inc
|
||||
ca65 -o disp4048d.o disp4048d.s -l disp4048d.lst
|
||||
|
||||
|
||||
####
|
||||
|
||||
png_to_40x96: png_to_40x96.o
|
||||
$(CC) $(LFLAGS) -lpng -o png_to_40x96 png_to_40x96.o
|
||||
@ -27,11 +37,39 @@ png_to_40x96: png_to_40x96.o
|
||||
png_to_40x96.o: png_to_40x96.c
|
||||
$(CC) $(CFLAGS) -c png_to_40x96.c
|
||||
|
||||
####
|
||||
|
||||
png_to_40x48d: png_to_40x48d.o
|
||||
$(CC) $(LFLAGS) -lpng -o png_to_40x48d png_to_40x48d.o
|
||||
|
||||
png_to_40x48d.o: png_to_40x48d.c
|
||||
$(CC) $(CFLAGS) -g -c png_to_40x48d.c
|
||||
|
||||
###
|
||||
|
||||
katahdin_40_96.inc: png_to_40x96 katahdin_40_96.png
|
||||
./png_to_40x96 asm katahdin_40_96.png katahdin > katahdin_40_96.inc
|
||||
|
||||
apple_40_96.inc: png_to_40x96 apple_40_96.png
|
||||
./png_to_40x96 asm apple_40_96.png apple > apple_40_96.inc
|
||||
|
||||
###
|
||||
|
||||
katahdin_40_48d.inc: png_to_40x48d katahdin_40_48d.png
|
||||
./png_to_40x48d asm katahdin_40_48d.png katahdin > katahdin_40_48d.inc
|
||||
|
||||
apple_40_48d.inc: png_to_40x48d apple_40_48d.png
|
||||
./png_to_40x48d asm apple_40_48d.png apple > apple_40_48d.inc
|
||||
|
||||
|
||||
|
||||
###
|
||||
|
||||
|
||||
install:
|
||||
cp png_to_40x96 $(INSTALL_LOC)
|
||||
|
||||
clean:
|
||||
rm -f *~ *.o *.lst *.inc png_to_40x96 DISP4096
|
||||
rm -f *~ *.o *.lst *.inc png_to_40x96 png_to_40x48d DISP4096 DISP4048D
|
||||
|
||||
|
||||
|
352
fancy_lores/disp4048d.s
Normal file
352
fancy_lores/disp4048d.s
Normal file
@ -0,0 +1,352 @@
|
||||
; Display a 40x48d lo-res image
|
||||
|
||||
; Uses the 40x48d page1/page2 every-1-scanline pageflip mode
|
||||
|
||||
; by deater (Vince Weaver) <vince@deater.net>
|
||||
|
||||
; Zero Page
|
||||
FRAMEBUFFER = $00 ; $00 - $0F
|
||||
YPOS = $10
|
||||
YPOS_SIN = $11
|
||||
CH = $24
|
||||
CV = $25
|
||||
GBASL = $26
|
||||
GBASH = $27
|
||||
BASL = $28
|
||||
BASH = $29
|
||||
FRAME = $60
|
||||
BLARGH = $69
|
||||
DRAW_PAGE = $EE
|
||||
LASTKEY = $F1
|
||||
PADDLE_STATUS = $F2
|
||||
TEMP = $FA
|
||||
WHICH = $FB
|
||||
|
||||
; Soft Switches
|
||||
KEYPRESS= $C000
|
||||
KEYRESET= $C010
|
||||
SET_GR = $C050 ; Enable graphics
|
||||
FULLGR = $C052 ; Full screen, no text
|
||||
PAGE0 = $C054 ; Page0
|
||||
PAGE1 = $C055 ; Page1
|
||||
LORES = $C056 ; Enable LORES graphics
|
||||
PADDLE_BUTTON0 = $C061
|
||||
PADDL0 = $C064
|
||||
PTRIG = $C070
|
||||
|
||||
; ROM routines
|
||||
|
||||
TEXT = $FB36 ;; Set text mode
|
||||
HOME = $FC58 ;; Clear the text screen
|
||||
WAIT = $FCA8 ;; delay 1/2(26+27A+5A^2) us
|
||||
|
||||
MAX = 2
|
||||
|
||||
lda #$ff
|
||||
sta WHICH
|
||||
|
||||
start_over:
|
||||
inc WHICH
|
||||
lda WHICH
|
||||
cmp #MAX
|
||||
bne in_range
|
||||
lda #0
|
||||
sta WHICH
|
||||
|
||||
in_range:
|
||||
|
||||
;===================
|
||||
; init screen
|
||||
jsr TEXT
|
||||
jsr HOME
|
||||
bit KEYRESET
|
||||
|
||||
;===================
|
||||
; init vars
|
||||
|
||||
lda #0
|
||||
sta DRAW_PAGE
|
||||
|
||||
;=============================
|
||||
; Load graphic page0
|
||||
|
||||
lda #$0c
|
||||
sta BASH
|
||||
lda #$00
|
||||
sta BASL ; load image to $c00
|
||||
|
||||
lda WHICH
|
||||
asl
|
||||
asl ; which*4
|
||||
tay
|
||||
|
||||
lda pictures,Y
|
||||
sta GBASL
|
||||
lda pictures+1,Y
|
||||
sta GBASH
|
||||
jsr load_rle_gr
|
||||
|
||||
lda #4
|
||||
sta DRAW_PAGE
|
||||
|
||||
jsr gr_copy_to_current ; copy to page1
|
||||
|
||||
; GR part
|
||||
bit PAGE1
|
||||
bit LORES ; 4
|
||||
bit SET_GR ; 4
|
||||
bit FULLGR ; 4
|
||||
|
||||
jsr wait_until_keypressed
|
||||
|
||||
|
||||
;=============================
|
||||
; Load graphic page1
|
||||
|
||||
lda #$0c
|
||||
sta BASH
|
||||
lda #$00
|
||||
sta BASL ; load image to $c00
|
||||
|
||||
lda WHICH
|
||||
asl
|
||||
asl ; which*4
|
||||
tay
|
||||
|
||||
lda pictures+2,Y
|
||||
sta GBASL
|
||||
lda pictures+3,Y
|
||||
sta GBASH
|
||||
jsr load_rle_gr
|
||||
|
||||
lda #0
|
||||
sta DRAW_PAGE
|
||||
|
||||
jsr gr_copy_to_current
|
||||
|
||||
; GR part
|
||||
bit PAGE0
|
||||
|
||||
jsr wait_until_keypressed
|
||||
|
||||
|
||||
;==============================
|
||||
; setup graphics for vapor lock
|
||||
;==============================
|
||||
|
||||
; Clear Page0
|
||||
lda #$0
|
||||
sta DRAW_PAGE
|
||||
lda #$44
|
||||
jsr clear_gr
|
||||
|
||||
; Make screen half green
|
||||
lda #$11
|
||||
ldy #24
|
||||
jsr clear_page_loop
|
||||
|
||||
|
||||
;=====================================================
|
||||
; attempt vapor lock
|
||||
; by reading the "floating bus" we can see most recently
|
||||
; written value of the display
|
||||
; we look for $55 (which is the grey line)
|
||||
;=====================================================
|
||||
; See:
|
||||
; Have an Apple Split by Bob Bishop
|
||||
; Softalk, October 1982
|
||||
|
||||
; Challenges: each scan line scans 40 bytes.
|
||||
; The blanking happens at the *beginning*
|
||||
; So 65 bytes are scanned, starting at adress of the line - 25
|
||||
|
||||
; the scan takes 8 cycles, look for 4 repeats of the value
|
||||
; to avoid false positive found if the horiz blanking is mirroring
|
||||
; the line (max 3 repeats in that case)
|
||||
|
||||
vapor_lock_loop: ; first make sure we have all zeroes
|
||||
LDA #$11
|
||||
zxloop:
|
||||
LDX #$04
|
||||
wiloop:
|
||||
CMP $C051
|
||||
BNE zxloop
|
||||
DEX
|
||||
BNE wiloop
|
||||
|
||||
LDA #$44 ; now look for our border color (4 times)
|
||||
zloop:
|
||||
LDX #$04
|
||||
qloop:
|
||||
CMP $C051
|
||||
BNE zloop
|
||||
DEX
|
||||
BNE qloop
|
||||
|
||||
; found first line of black after green, at up to line 26 on screen
|
||||
; so we want roughly 22 lines * 4 = 88*65 = 5720 + 4550 = 10270
|
||||
; - 65 (for the scanline we missed) = 10205 - 12 = 10193
|
||||
|
||||
jsr gr_copy_to_current ; 6+ 9292
|
||||
; 10193 - 9298 = 895
|
||||
; Fudge factor (unknown) -30 = 865
|
||||
|
||||
; GR part
|
||||
bit LORES ; 4
|
||||
bit SET_GR ; 4
|
||||
bit FULLGR ; 4
|
||||
|
||||
; Try X=88 Y=2 cycles=893 R2
|
||||
|
||||
nop
|
||||
ldy #2 ; 2
|
||||
loopA:
|
||||
ldx #88 ; 2
|
||||
loopB:
|
||||
dex ; 2
|
||||
bne loopB ; 2nt/3
|
||||
|
||||
dey ; 2
|
||||
bne loopA ; 2nt/3
|
||||
|
||||
jmp display_loop
|
||||
.align $100
|
||||
|
||||
|
||||
;================================================
|
||||
; Display Loop
|
||||
;================================================
|
||||
; each scan line 65 cycles
|
||||
; 1 cycle each byte (40cycles) + 25 for horizontal
|
||||
; Total of 12480 cycles to draw screen
|
||||
; Vertical blank = 4550 cycles (70 scan lines)
|
||||
; Total of 17030 cycles to get back to where was
|
||||
|
||||
; We want to alternate between page1 and page2 every 65 cycles
|
||||
; vblank = 4550 cycles to do scrolling
|
||||
|
||||
|
||||
; 2 + 48*( (4+2+25*(2+3)) + (4+2+23*(2+3)+4+5)) + 9)
|
||||
; 48*[(6+125)-1] + [(6+115+10)-1]
|
||||
|
||||
display_loop:
|
||||
|
||||
ldy #96 ; 2
|
||||
|
||||
outer_loop:
|
||||
|
||||
bit PAGE0 ; 4
|
||||
ldx #12 ; 65 cycles with PAGE0 ; 2
|
||||
page0_loop: ; delay 61+bit
|
||||
dex ; 2
|
||||
bne page0_loop ; 2/3
|
||||
|
||||
|
||||
; bit(4) -1(fallthrough) + loop*5 -1(fallthrouh)+4 extra = 61
|
||||
; 5L = 55
|
||||
|
||||
bit PAGE1 ; 4
|
||||
ldx #11 ; 65 cycles with PAGE1 ; 2
|
||||
;
|
||||
page1_loop: ; delay 115+(7 loop)+4 (bit)+4(extra)
|
||||
dex ; 2
|
||||
bne page1_loop ; 2/3
|
||||
|
||||
dey ; 2
|
||||
bne outer_loop ; 2/3
|
||||
|
||||
|
||||
|
||||
;======================================================
|
||||
; We have 4550 cycles in the vblank, use them wisely
|
||||
;======================================================
|
||||
; do_nothing should be 4550+1 -2-9 -7= 4533
|
||||
|
||||
jsr do_nothing ; 6
|
||||
|
||||
lda KEYPRESS ; 4
|
||||
bpl no_keypress ; 3
|
||||
jmp start_over
|
||||
no_keypress:
|
||||
|
||||
jmp display_loop ; 3
|
||||
|
||||
|
||||
|
||||
;=================================
|
||||
; do nothing
|
||||
;=================================
|
||||
; and take 4533-6 = 4527 cycles to do it
|
||||
do_nothing:
|
||||
|
||||
; Try X=4 Y=174 cycles=4525 R2
|
||||
|
||||
nop ; 2
|
||||
|
||||
ldy #174 ; 2
|
||||
loop1:
|
||||
ldx #4 ; 2
|
||||
loop2:
|
||||
dex ; 2
|
||||
bne loop2 ; 2nt/3
|
||||
|
||||
dey ; 2
|
||||
bne loop1 ; 2nt/3
|
||||
|
||||
|
||||
rts ; 6
|
||||
|
||||
|
||||
|
||||
;==================================
|
||||
; HLINE
|
||||
;==================================
|
||||
|
||||
; Color in A
|
||||
; Y has which line
|
||||
hline:
|
||||
pha ; 3
|
||||
ldx gr_offsets,y ; 4+
|
||||
stx hline_loop+1 ; 4
|
||||
lda gr_offsets+1,y ; 4+
|
||||
clc ; 2
|
||||
adc DRAW_PAGE ; 3
|
||||
sta hline_loop+2 ; 4
|
||||
pla ; 4
|
||||
ldx #39 ; 2
|
||||
hline_loop:
|
||||
sta $5d0,X ; 38 ; 5
|
||||
dex ; 2
|
||||
bpl hline_loop ; 2nt/3
|
||||
rts ; 6
|
||||
|
||||
;==========================
|
||||
; Clear gr screen
|
||||
;==========================
|
||||
; Color in A
|
||||
clear_gr:
|
||||
ldy #46
|
||||
clear_page_loop:
|
||||
jsr hline
|
||||
dey
|
||||
dey
|
||||
bpl clear_page_loop
|
||||
rts
|
||||
|
||||
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
|
||||
|
||||
|
||||
.include "../asm_routines/gr_unrle.s"
|
||||
.include "../asm_routines/keypress.s"
|
||||
.include "gr_copy.s"
|
||||
|
||||
pictures:
|
||||
.word apple_low,apple_high
|
||||
.word katahdin_low,katahdin_high
|
||||
|
||||
.include "apple_40_48d.inc"
|
||||
.include "katahdin_40_48d.inc"
|
||||
|
Binary file not shown.
@ -48,11 +48,22 @@ void gen_color(int col1, int col2) {
|
||||
return;
|
||||
}
|
||||
|
||||
void hex_color(int col1, int col2) {
|
||||
|
||||
if (col1>=col2)
|
||||
printf("\t\tcase 0x%02x%02x%02x: hi=%d; low=%d; break;\n",
|
||||
average(gr_colors[col1][0],gr_colors[col2][0]),
|
||||
average(gr_colors[col1][1],gr_colors[col2][1]),
|
||||
average(gr_colors[col1][2],gr_colors[col2][2]),col1,col2);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
|
||||
int x,y;
|
||||
|
||||
#if 1
|
||||
printf("GIMP Palette\n");
|
||||
printf("Name: Apple II Lores Dither.gpl\n");
|
||||
printf("Columns: 16\n");
|
||||
@ -62,5 +73,12 @@ int main(int argc, char **argv) {
|
||||
gen_color(x,y);
|
||||
}
|
||||
}
|
||||
#else
|
||||
for(x=0;x<16;x++) {
|
||||
for(y=0;y<16;y++) {
|
||||
hex_color(x,y);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
return 0;
|
||||
}
|
||||
|
571
fancy_lores/png_to_40x48d.c
Normal file
571
fancy_lores/png_to_40x48d.c
Normal file
@ -0,0 +1,571 @@
|
||||
/* Convert a 40x48d image into two, 40x48 images suitable of loading */
|
||||
/* with my kfest18 based code, inteleaving at one scanline resolution */
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include <unistd.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <stdarg.h>
|
||||
|
||||
#include <png.h>
|
||||
|
||||
#define OUTPUT_C 0
|
||||
#define OUTPUT_ASM 1
|
||||
|
||||
|
||||
static int convert_color(int color,int which) {
|
||||
|
||||
int hi,low;
|
||||
|
||||
switch(color) {
|
||||
case 0x000000: hi=0; low=0; break;
|
||||
case 0xa01543: hi=1; low=0; break;
|
||||
case 0xe31e60: hi=1; low=1; break;
|
||||
case 0x433785: hi=2; low=0; break;
|
||||
case 0xae3b95: hi=2; low=1; break;
|
||||
case 0x604ebd: hi=2; low=2; break;
|
||||
case 0xb430b2: hi=3; low=0; break;
|
||||
case 0xf134bf: hi=3; low=1; break;
|
||||
case 0xc049df: hi=3; low=2; break;
|
||||
case 0xff44fd: hi=3; low=3; break;
|
||||
case 0x007343: hi=4; low=0; break;
|
||||
case 0xa07560: hi=4; low=1; break;
|
||||
case 0x437f95: hi=4; low=2; break;
|
||||
case 0xb47cbf: hi=4; low=3; break;
|
||||
case 0x00a360: hi=4; low=4; break;
|
||||
case 0x6e6e6e: hi=5; low=0; break;
|
||||
case 0xc27081: hi=5; low=1; break;
|
||||
case 0x817bad: hi=5; low=2; break;
|
||||
case 0xd378d2: hi=5; low=3; break;
|
||||
case 0x6e9f81: hi=5; low=4; break;
|
||||
case 0x9c9c9c: hi=5; low=5; break;
|
||||
case 0x0e92b2: hi=6; low=0; break;
|
||||
case 0xa193bf: hi=6; low=1; break;
|
||||
case 0x459cdf: hi=6; low=2; break;
|
||||
case 0xb49afd: hi=6; low=3; break;
|
||||
case 0x0ebabf: hi=6; low=4; break;
|
||||
case 0x6fb7d2: hi=6; low=5; break;
|
||||
case 0x14cffd: hi=6; low=6; break;
|
||||
case 0x9389b4: hi=7; low=0; break;
|
||||
case 0xd98bc0: hi=7; low=1; break;
|
||||
case 0xa194e0: hi=7; low=2; break;
|
||||
case 0xe892fe: hi=7; low=3; break;
|
||||
case 0x93b3c0: hi=7; low=4; break;
|
||||
case 0xb7b0d3: hi=7; low=5; break;
|
||||
case 0x93c9fe: hi=7; low=6; break;
|
||||
case 0xd0c3ff: hi=7; low=7; break;
|
||||
case 0x435002: hi=8; low=0; break;
|
||||
case 0xae5343: hi=8; low=1; break;
|
||||
case 0x606185: hi=8; low=2; break;
|
||||
case 0xc05db2: hi=8; low=3; break;
|
||||
case 0x438c43: hi=8; low=4; break;
|
||||
case 0x81886e: hi=8; low=5; break;
|
||||
case 0x45a7b2: hi=8; low=6; break;
|
||||
case 0xa19fb4: hi=8; low=7; break;
|
||||
case 0x607203: hi=8; low=8; break;
|
||||
case 0xb44a2a: hi=9; low=0; break;
|
||||
case 0xf14d50: hi=9; low=1; break;
|
||||
case 0xc05d8c: hi=9; low=2; break;
|
||||
case 0xff59b7: hi=9; low=3; break;
|
||||
case 0xb48950: hi=9; low=4; break;
|
||||
case 0xd38576: hi=9; low=5; break;
|
||||
case 0xb4a4b7: hi=9; low=6; break;
|
||||
case 0xe89cb9: hi=9; low=7; break;
|
||||
case 0xc06e2a: hi=9; low=8; break;
|
||||
case 0xff6a3c: hi=9; low=9; break;
|
||||
#if 0
|
||||
case 0x6f6f6f: hi=10; low=0; break;
|
||||
case 0xc37182: hi=10; low=1; break;
|
||||
case 0x827bad: hi=10; low=2; break;
|
||||
case 0xd378d2: hi=10; low=3; break;
|
||||
case 0x6fa082: hi=10; low=4; break;
|
||||
case 0x9c9c9c: hi=10; low=5; break;
|
||||
case 0x6fb7d2: hi=10; low=6; break;
|
||||
case 0xb8b1d3: hi=10; low=7; break;
|
||||
case 0x82896f: hi=10; low=8; break;
|
||||
case 0xd38576: hi=10; low=9; break;
|
||||
case 0x9d9d9d: hi=10; low=10; break;
|
||||
#endif
|
||||
case 0xb47193: hi=11; low=0; break;
|
||||
case 0xf173a1: hi=11; low=1; break;
|
||||
case 0xc07dc6: hi=11; low=2; break;
|
||||
case 0xff7ae7: hi=11; low=3; break;
|
||||
case 0xb4a1a1: hi=11; low=4; break;
|
||||
case 0xd39eb7: hi=11; low=5; break;
|
||||
case 0xb4b8e7: hi=11; low=6; break;
|
||||
case 0xe8b2e8: hi=11; low=7; break;
|
||||
case 0xc08a93: hi=11; low=8; break;
|
||||
case 0xff8799: hi=11; low=9; break;
|
||||
case 0xd39eb8: hi=11; low=10; break;
|
||||
case 0xffa0d0: hi=11; low=11; break;
|
||||
case 0x0ead2a: hi=12; low=0; break;
|
||||
case 0xa1ae50: hi=12; low=1; break;
|
||||
case 0x45b58c: hi=12; low=2; break;
|
||||
case 0xb4b3b7: hi=12; low=3; break;
|
||||
case 0x0ed050: hi=12; low=4; break;
|
||||
case 0x6fcd76: hi=12; low=5; break;
|
||||
case 0x14e2b7: hi=12; low=6; break;
|
||||
case 0x93ddb9: hi=12; low=7; break;
|
||||
case 0x45bf2a: hi=12; low=8; break;
|
||||
case 0xb4bc3c: hi=12; low=9; break;
|
||||
// case 0x6fcd76: hi=12; low=10; break;
|
||||
case 0xb4ce99: hi=12; low=11; break;
|
||||
case 0x14f53c: hi=12; low=12; break;
|
||||
case 0x939c63: hi=13; low=0; break;
|
||||
case 0xd99d78: hi=13; low=1; break;
|
||||
case 0xa1a5a6: hi=13; low=2; break;
|
||||
case 0xe8a3cc: hi=13; low=3; break;
|
||||
case 0x93c278: hi=13; low=4; break;
|
||||
case 0xb7bf94: hi=13; low=5; break;
|
||||
case 0x93d6cc: hi=13; low=6; break;
|
||||
case 0xd0d0ce: hi=13; low=7; break;
|
||||
case 0xa1af63: hi=13; low=8; break;
|
||||
case 0xe8ad6c: hi=13; low=9; break;
|
||||
case 0xb8bf95: hi=13; low=10; break;
|
||||
case 0xe8c0b1: hi=13; low=11; break;
|
||||
case 0x93e96c: hi=13; low=12; break;
|
||||
case 0xd0dd8d: hi=13; low=13; break;
|
||||
case 0x50b493: hi=14; low=0; break;
|
||||
case 0xb3b5a1: hi=14; low=1; break;
|
||||
case 0x69bcc6: hi=14; low=2; break;
|
||||
case 0xc5bae7: hi=14; low=3; break;
|
||||
case 0x50d6a1: hi=14; low=4; break;
|
||||
case 0x88d3b7: hi=14; low=5; break;
|
||||
case 0x51e8e7: hi=14; low=6; break;
|
||||
case 0xa7e2e8: hi=14; low=7; break;
|
||||
case 0x69c593: hi=14; low=8; break;
|
||||
case 0xc5c399: hi=14; low=9; break;
|
||||
case 0x89d3b8: hi=14; low=10; break;
|
||||
case 0xc5d4d0: hi=14; low=11; break;
|
||||
case 0x51fa99: hi=14; low=12; break;
|
||||
case 0xa7eeb1: hi=14; low=13; break;
|
||||
case 0x72ffd0: hi=14; low=14; break;
|
||||
case 0xb4b4b4: hi=15; low=0; break;
|
||||
case 0xf1b5c0: hi=15; low=1; break;
|
||||
case 0xc0bce0: hi=15; low=2; break;
|
||||
case 0xffbafe: hi=15; low=3; break;
|
||||
case 0xb4d6c0: hi=15; low=4; break;
|
||||
case 0xd3d3d3: hi=15; low=5; break;
|
||||
case 0xb4e8fe: hi=15; low=6; break;
|
||||
case 0xe8e2ff: hi=15; low=7; break;
|
||||
case 0xc0c5b4: hi=15; low=8; break;
|
||||
case 0xffc3b9: hi=15; low=9; break;
|
||||
// case 0xd3d3d3: hi=15; low=10; break;
|
||||
case 0xffd4e8: hi=15; low=11; break;
|
||||
case 0xb4fab9: hi=15; low=12; break;
|
||||
case 0xe8eece: hi=15; low=13; break;
|
||||
case 0xc5ffe8: hi=15; low=14; break;
|
||||
case 0xffffff: hi=15; low=15; break;
|
||||
|
||||
|
||||
default:
|
||||
printf("Unknown color %x\n",color);
|
||||
break;
|
||||
}
|
||||
|
||||
if (which==0) return hi;
|
||||
else return low;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/* expects a PNG where the xsize is 40 */
|
||||
int loadpng(char *filename, unsigned char **image_ptr, int *xsize, int *ysize,
|
||||
int high) {
|
||||
|
||||
int x,y;
|
||||
int color;
|
||||
FILE *infile;
|
||||
int debug=0;
|
||||
unsigned char *image,*out_ptr;
|
||||
int width, height;
|
||||
int a2_color;
|
||||
|
||||
png_byte bit_depth;
|
||||
png_structp png_ptr;
|
||||
png_infop info_ptr;
|
||||
png_bytep *row_pointers;
|
||||
png_byte color_type;
|
||||
// int number_of_passes;
|
||||
|
||||
unsigned char header[8];
|
||||
|
||||
/* open file and test for it being a png */
|
||||
infile = fopen(filename, "rb");
|
||||
if (infile==NULL) {
|
||||
fprintf(stderr,"Error! Could not open %s\n",filename);
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* Check the header */
|
||||
fread(header, 1, 8, infile);
|
||||
if (png_sig_cmp(header, 0, 8)) {
|
||||
fprintf(stderr,"Error! %s is not a PNG file\n",filename);
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* initialize stuff */
|
||||
png_ptr = png_create_read_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL);
|
||||
if (!png_ptr) {
|
||||
fprintf(stderr,"Error create_read_struct\n");
|
||||
exit(-1);
|
||||
}
|
||||
|
||||
info_ptr = png_create_info_struct(png_ptr);
|
||||
if (!info_ptr) {
|
||||
fprintf(stderr,"Error png_create_info_struct\n");
|
||||
exit(-1);
|
||||
}
|
||||
|
||||
png_init_io(png_ptr, infile);
|
||||
png_set_sig_bytes(png_ptr, 8);
|
||||
|
||||
png_read_info(png_ptr, info_ptr);
|
||||
|
||||
width = png_get_image_width(png_ptr, info_ptr);
|
||||
height = png_get_image_height(png_ptr, info_ptr);
|
||||
*xsize=width;
|
||||
*ysize=height;
|
||||
|
||||
color_type = png_get_color_type(png_ptr, info_ptr);
|
||||
bit_depth = png_get_bit_depth(png_ptr, info_ptr);
|
||||
|
||||
|
||||
|
||||
if (debug) {
|
||||
printf("PNG: width=%d height=%d depth=%d\n",width,height,bit_depth);
|
||||
if (color_type==PNG_COLOR_TYPE_RGB) printf("Type RGB\n");
|
||||
else if (color_type==PNG_COLOR_TYPE_RGB_ALPHA) printf("Type RGBA\n");
|
||||
else if (color_type==PNG_COLOR_TYPE_PALETTE) printf("Type palette\n");
|
||||
}
|
||||
|
||||
// number_of_passes = png_set_interlace_handling(png_ptr);
|
||||
png_read_update_info(png_ptr, info_ptr);
|
||||
|
||||
row_pointers = (png_bytep*) malloc(sizeof(png_bytep) * height);
|
||||
for (y=0; y<height; y++) {
|
||||
row_pointers[y] = (png_byte*) malloc(png_get_rowbytes(png_ptr,info_ptr));
|
||||
}
|
||||
|
||||
png_read_image(png_ptr, row_pointers);
|
||||
|
||||
fclose(infile);
|
||||
|
||||
image=calloc(width*height,sizeof(unsigned char));
|
||||
if (image==NULL) {
|
||||
fprintf(stderr,"Memory error!\n");
|
||||
return -1;
|
||||
}
|
||||
out_ptr=image;
|
||||
|
||||
if (color_type==PNG_COLOR_TYPE_RGB_ALPHA) {
|
||||
for(y=0;y<height;y+=2) {
|
||||
for(x=0;x<width;x++) {
|
||||
|
||||
/* top color */
|
||||
color= (row_pointers[y][x*4]<<16)+
|
||||
(row_pointers[y][x*4+1]<<8)+
|
||||
(row_pointers[y][x*4+2]);
|
||||
if (debug) {
|
||||
printf("%x ",color);
|
||||
}
|
||||
|
||||
a2_color=convert_color(color,high);
|
||||
|
||||
/* bottom color */
|
||||
color= (row_pointers[y+1][x*4]<<16)+
|
||||
(row_pointers[y+1][x*4+1]<<8)+
|
||||
(row_pointers[y+1][x*4+2]);
|
||||
if (debug) {
|
||||
printf("%x ",color);
|
||||
}
|
||||
|
||||
a2_color|=(convert_color(color,high)<<4);
|
||||
|
||||
*out_ptr=a2_color;
|
||||
out_ptr++;
|
||||
}
|
||||
if (debug) printf("\n");
|
||||
}
|
||||
}
|
||||
else if (color_type==PNG_COLOR_TYPE_PALETTE) {
|
||||
|
||||
for(y=0;y<height;y+=2) {
|
||||
for(x=0;x<width;x++) {
|
||||
|
||||
if (high) {
|
||||
/* top color */
|
||||
a2_color=row_pointers[y][x]/16;
|
||||
|
||||
/* bottom color */
|
||||
color=row_pointers[y+1][x]/16;
|
||||
}
|
||||
else {
|
||||
/* top color */
|
||||
a2_color=row_pointers[y][x]%16;
|
||||
|
||||
/* bottom color */
|
||||
color=row_pointers[y+1][x]%16;
|
||||
}
|
||||
|
||||
a2_color|=(color<<4);
|
||||
|
||||
if (debug) {
|
||||
printf("%x ",a2_color);
|
||||
}
|
||||
|
||||
*out_ptr=a2_color;
|
||||
out_ptr++;
|
||||
}
|
||||
if (debug) printf("\n");
|
||||
}
|
||||
}
|
||||
else {
|
||||
printf("Unknown color type\n");
|
||||
}
|
||||
|
||||
/* Stripe test image */
|
||||
// for(x=0;x<40;x++) for(y=0;y<40;y++) image[(y*width)+x]=y%16;
|
||||
|
||||
/*
|
||||
Addr Row /80 %40
|
||||
$400 0 0 0 0
|
||||
$428 28 16 0
|
||||
$450 50 32 0
|
||||
$480 80 2 1
|
||||
$4A8 a8 18 1
|
||||
$4D0 d0 34 1
|
||||
$500 100 3 2
|
||||
0,0 0,1 0,2....0,39 16,0 16,1 ....16,39 32,0..32,39, X X X X X X X X
|
||||
*/
|
||||
|
||||
*image_ptr=image;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/*****************************************/
|
||||
/* \/ \/ */
|
||||
/* Converts a PNG to RLE compressed data */
|
||||
/*****************************************/
|
||||
|
||||
|
||||
static int print_run(int count, int out_type, int run, int last) {
|
||||
|
||||
int size=0;
|
||||
|
||||
if (count==0) {
|
||||
if (out_type==OUTPUT_C) {
|
||||
printf("\n\t");
|
||||
}
|
||||
else {
|
||||
printf("\n\t.byte ");
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (out_type==OUTPUT_C) {
|
||||
}
|
||||
else {
|
||||
printf(", ");
|
||||
}
|
||||
}
|
||||
|
||||
if (run==1) {
|
||||
if (out_type==OUTPUT_C) {
|
||||
printf("0x%02X,",last);
|
||||
}
|
||||
else {
|
||||
printf("$%02X",last);
|
||||
}
|
||||
size++;
|
||||
}
|
||||
if (run==2) {
|
||||
if (out_type==OUTPUT_C) {
|
||||
printf("0x%02X,0x%02X,",last,last);
|
||||
}
|
||||
else {
|
||||
printf("$%02X,$%02X",last,last);
|
||||
}
|
||||
size+=2;
|
||||
}
|
||||
|
||||
if ((run>2) && (run<16)) {
|
||||
if (out_type==OUTPUT_C) {
|
||||
printf("0x%02X,0x%02X,",0xA0|run,last);
|
||||
}
|
||||
else {
|
||||
printf("$%02X,$%02X",0xA0|run,last);
|
||||
}
|
||||
size+=2;
|
||||
}
|
||||
|
||||
if (run>=16) {
|
||||
if (out_type==OUTPUT_C) {
|
||||
printf("0x%02X,0x%02X,0x%02X,",0xA0,run,last);
|
||||
}
|
||||
else {
|
||||
printf("$%02X,$%02X,$%02X",0xA0,run,last);
|
||||
}
|
||||
size+=3;
|
||||
}
|
||||
|
||||
return size;
|
||||
}
|
||||
|
||||
int rle_smaller(int out_type, char *varname,
|
||||
int xsize,int ysize, unsigned char *image,int high) {
|
||||
|
||||
int run=0;
|
||||
int x;
|
||||
|
||||
int last=-1,next;
|
||||
int size=0;
|
||||
int count=0;
|
||||
|
||||
x=0;
|
||||
|
||||
/* Write out xsize and ysize */
|
||||
|
||||
if (out_type==OUTPUT_C) {
|
||||
fprintf(stdout,"unsigned char %s_%s[]={\n",varname,
|
||||
high?"high":"low");
|
||||
fprintf(stdout,"\t0x%X, /* ysize=%d */",xsize,ysize);
|
||||
}
|
||||
else {
|
||||
fprintf(stdout,"%s_%s:",varname,high?"high":"low");
|
||||
fprintf(stdout,"\t.byte $%X ; ysize=%d",xsize,ysize);
|
||||
}
|
||||
|
||||
size+=2;
|
||||
|
||||
/* Get first top/bottom color pair */
|
||||
last=image[x];
|
||||
run++;
|
||||
x++;
|
||||
|
||||
while(1) {
|
||||
|
||||
/* get next top/bottom color pair */
|
||||
next=image[x];
|
||||
|
||||
if ((next&0xf0)==0xA0) {
|
||||
fprintf(stderr,"Warning! Using color A (grey2)!\n");
|
||||
next&=~0xf0;
|
||||
next|=0x50; // substitute grey1
|
||||
}
|
||||
|
||||
/* If color change (or too big) then output our run */
|
||||
/* Note 0xff for run length is special case meaning "finished" */
|
||||
if ((next!=last) || (run>254)) {
|
||||
|
||||
size+=print_run(count,out_type,run,last);
|
||||
|
||||
count++;
|
||||
run=0;
|
||||
last=next;
|
||||
}
|
||||
|
||||
x++;
|
||||
|
||||
/* If we reach the end */
|
||||
if (x>=xsize*(ysize/2)) {
|
||||
run++;
|
||||
|
||||
size+=print_run(count,out_type,run,last);
|
||||
|
||||
break;
|
||||
|
||||
}
|
||||
|
||||
run++;
|
||||
if (count>6) count=0;
|
||||
|
||||
}
|
||||
|
||||
/* Print closing marker */
|
||||
|
||||
if (out_type==OUTPUT_C) {
|
||||
fprintf(stdout,"0xA1,");
|
||||
fprintf(stdout,"\t};\n");
|
||||
} else {
|
||||
fprintf(stdout,"\n\t.byte $A1\n");
|
||||
}
|
||||
|
||||
size+=1;
|
||||
|
||||
return size;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/* Converts a PNG to RLE compressed data */
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
|
||||
unsigned char *image;
|
||||
int xsize,ysize;
|
||||
int size=0;
|
||||
int out_type=OUTPUT_C;
|
||||
|
||||
if (argc<4) {
|
||||
fprintf(stderr,"Usage:\t%s type INFILE varname\n\n",argv[0]);
|
||||
fprintf(stderr,"\ttype: c or asm\n");
|
||||
fprintf(stderr,"\tvarname: label for graphic\n");
|
||||
fprintf(stderr,"\n");
|
||||
|
||||
exit(-1);
|
||||
}
|
||||
|
||||
if (!strcmp(argv[1],"c")) {
|
||||
out_type=OUTPUT_C;
|
||||
}
|
||||
else if (!strcmp(argv[1],"asm")) {
|
||||
out_type=OUTPUT_ASM;
|
||||
}
|
||||
|
||||
if (loadpng(argv[2],&image,&xsize,&ysize,1)<0) {
|
||||
fprintf(stderr,"Error loading png!\n");
|
||||
exit(-1);
|
||||
}
|
||||
|
||||
fprintf(stderr,"Loaded image %d by %d\n",xsize,ysize);
|
||||
|
||||
// size=rle_original(out_type,argv[3],
|
||||
// xsize,ysize,image);
|
||||
|
||||
size=rle_smaller(out_type,argv[3],
|
||||
xsize,ysize,image,0);
|
||||
|
||||
fprintf(stderr,"Size %d bytes\n",size);
|
||||
|
||||
if (loadpng(argv[2],&image,&xsize,&ysize,0)<0) {
|
||||
fprintf(stderr,"Error loading png!\n");
|
||||
exit(-1);
|
||||
}
|
||||
|
||||
fprintf(stderr,"Loaded image %d by %d\n",xsize,ysize);
|
||||
|
||||
// size=rle_original(out_type,argv[3],
|
||||
// xsize,ysize,image);
|
||||
|
||||
size=rle_smaller(out_type,argv[3],
|
||||
xsize,ysize,image,1);
|
||||
|
||||
fprintf(stderr,"Size %d bytes\n",size);
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user