imageviewer is now a single program

This commit is contained in:
Irmen de Jong 2020-12-14 14:30:18 +01:00
parent 8b75ceb412
commit 39b7655264
6 changed files with 189 additions and 284 deletions

View File

@ -3,44 +3,9 @@
%import textio
%import diskio
main {
sub start() {
graphics.enable_bitmap_mode()
bmp_module {
if strlen(diskio.status(8)) ; trick to check if we're running on sdcard or host system shared folder
show_pics_sdcard()
else {
txt.print("only works with files on\nsdcard image!\n")
}
repeat {
;
}
}
sub show_pics_sdcard() {
; load and show all *.bmp pictures on the disk.
; this only works in the emulator V38 with an sd-card image with the files on it.
str[20] filename_ptrs
ubyte num_files = diskio.list_files(8, ".bmp", true, &filename_ptrs, len(filename_ptrs))
if num_files {
while num_files {
num_files--
bmp.show_bmp_image(filename_ptrs[num_files])
cx16.wait(120)
}
} else {
txt.print("no *.bmp files found\n")
}
}
}
bmp {
sub show_bmp_image(uword filenameptr) {
sub show_image(uword filenameptr) {
ubyte load_ok = false
txt.print(filenameptr)
txt.chrout('\n')
@ -85,7 +50,6 @@ bmp {
total_read += size
repeat bm_data_offset - total_read
void c64.CHRIN()
txt.clear_screen()
graphics.clear_screen(1, 0)
set_palette(&palette0, num_colors)
decode_bitmap()
@ -100,10 +64,8 @@ bmp {
if not load_ok {
txt.print("load error!\n")
txt.print(diskio.status(8))
}
sub start_plot() {
offsetx = 0
offsety = 0

View File

@ -46,7 +46,7 @@
; (it is a problem to load let alone decompress a full bitmap at once because there will likely not be enough ram to do that)
; (doing it in chunks of 8 kb allows for sticking each chunk in one of the banked 8kb ram blocks, or even copy it directly to the screen)
main {
ci_module {
%option force_output
ubyte[256] buffer
ubyte[256] buffer2 ; add two more buffers to make enough space
@ -54,19 +54,6 @@ main {
ubyte[256] buffer4 ; .. and some more to be able to store 1280=
ubyte[256] buffer5 ; two 640 bytes worth of bitmap scanline data
sub start() {
str[20] filename_ptrs
ubyte num_files = diskio.list_files(8, ".ci", true, &filename_ptrs, len(filename_ptrs))
while num_files {
num_files--
show_image(filename_ptrs[num_files])
}
repeat {
; endless loop
}
}
sub show_image(uword filename) {
ubyte read_success = false
uword bitmap_load_address = progend()
@ -117,7 +104,11 @@ main {
if height > graphics.HEIGHT
height = graphics.HEIGHT
graphics.enable_bitmap_mode()
set_palette(num_colors, palette_format, buffer)
if palette_format
palette.set_rgb8(buffer, num_colors)
else
palette.set_rgb4(buffer, num_colors)
graphics.clear_screen(1,0)
cx16.r0 = 0
cx16.r1 = 0
cx16.FB_cursor_position()
@ -142,39 +133,6 @@ main {
diskio.f_close()
if not read_success
txt.print("error!\n")
else
txt.print("ok\n")
}
}
sub set_palette(uword num_colors, ubyte format, uword palletteptr) {
uword vera_palette_ptr = $fa00
ubyte red
ubyte greenblue
if format {
; 3 bytes per color entry, adjust color depth from 8 to 4 bits per channel.
repeat num_colors {
red = @(palletteptr) >> 4
palletteptr++
greenblue = @(palletteptr) & %11110000
palletteptr++
greenblue |= @(palletteptr) >> 4 ; add Blue
palletteptr++
cx16.vpoke(1, vera_palette_ptr, greenblue)
vera_palette_ptr++
cx16.vpoke(1, vera_palette_ptr, red)
vera_palette_ptr++
}
} else {
; 2 bytes per color entry, the Vera uses this, but the R/GB bytes order is swapped
repeat num_colors {
cx16.vpoke(1, vera_palette_ptr+1, @(palletteptr))
palletteptr++
cx16.vpoke(1, vera_palette_ptr, @(palletteptr))
palletteptr++
vera_palette_ptr+=2
}
}
}

View File

@ -3,67 +3,9 @@
%import textio
%import diskio
main {
sub start() {
graphics.enable_bitmap_mode()
if strlen(diskio.status(8)) ; trick to check if we're running on sdcard or host system shared folder
show_pics_sdcard()
else {
txt.print("only works with files on\nsdcard image!\n")
}
repeat {
;
}
}
sub show_pics_sdcard() {
; load and show all *.iff pictures on the disk.
; this only works in the emulator V38 with an sd-card image with the files on it.
str[20] filename_ptrs
ubyte num_files = diskio.list_files(8, ".iff", true, &filename_ptrs, len(filename_ptrs))
if num_files {
while num_files {
num_files--
iff.show_iff_image(filename_ptrs[num_files])
cx16.wait(120)
}
} else {
txt.print("no *.iff files found\n")
}
}
sub set_palette_8rgb(uword palletteptr, uword num_colors) {
uword vera_palette_ptr = $fa00
ubyte red
ubyte greenblue
; 3 bytes per color entry, adjust color depth from 8 to 4 bits per channel.
repeat num_colors {
red = @(palletteptr) >> 4
palletteptr++
greenblue = @(palletteptr) & %11110000
palletteptr++
greenblue |= @(palletteptr) >> 4 ; add Blue
palletteptr++
cx16.vpoke(1, vera_palette_ptr, greenblue)
vera_palette_ptr++
cx16.vpoke(1, vera_palette_ptr, red)
vera_palette_ptr++
}
}
}
iff {
sub show_iff_image(uword filenameptr) {
iff_module {
sub show_image(uword filenameptr) {
ubyte load_ok = false
txt.print(filenameptr)
txt.chrout('\n')
uword size
ubyte[32] buffer
ubyte[256] cmap
@ -113,13 +55,12 @@ iff {
void diskio.f_read(&cmap, chunk_size_lo)
}
else if chunk_id == "body" {
txt.clear_screen()
graphics.clear_screen(1, 0)
if camg & $0004
height /= 2 ; interlaced: just skip every odd scanline later
if camg & $0080 and have_cmap
make_ehb_palette()
main.set_palette_8rgb(&cmap, num_colors)
palette.set_rgb8(&cmap, num_colors)
if compression
decode_rle()
else
@ -138,10 +79,8 @@ iff {
diskio.f_close()
}
if not load_ok {
if not load_ok
txt.print("load error!\n")
txt.print(diskio.status(8))
}
sub read_chunk_header() -> ubyte {

View File

@ -0,0 +1,162 @@
%target cx16
%import graphics
%import textio
%import diskio
%import koala_module
%import iff_module
%import pcx_module
%import bmp_module
%import ci_module
main {
sub start() {
graphics.enable_bitmap_mode()
if strlen(diskio.status(8)) ; trick to check if we're running on sdcard or host system shared folder
show_pics_sdcard()
else {
txt.print("only works with files on sdcard image!\n(because of emulator restrictions)")
}
repeat {
;
}
}
sub show_pics_sdcard() {
; load and show the images on the disk with the given extensions.
; this only works in the emulator V38 with an sd-card image with the files on it.
str[40] filename_ptrs
ubyte num_files = diskio.list_files(8, 0, false, &filename_ptrs, len(filename_ptrs))
if num_files {
while num_files {
num_files--
attempt_load(filename_ptrs[num_files])
}
txt.print("\nthat was the last file.\n")
} else
txt.print("no files in directory!\n")
}
sub attempt_load(uword filenameptr) {
txt.print(">> ")
txt.print(filenameptr)
txt.chrout('\n')
uword extension = filenameptr + rfind(filenameptr, '.')
if strcmp(extension, ".iff")==0 {
txt.print("loading ")
txt.print("iff\n")
void iff_module.show_image(filenameptr)
txt.clear_screen()
cx16.wait(120)
}
else if strcmp(extension, ".pcx")==0 {
txt.print("loading ")
txt.print("pcx\n")
void pcx_module.show_image(filenameptr)
txt.clear_screen()
cx16.wait(120)
}
else if strcmp(extension, ".koa")==0 {
txt.print("loading ")
txt.print("koala\n")
void koala_module.show_image(filenameptr)
txt.clear_screen()
cx16.wait(120)
}
else if strcmp(extension, ".bmp")==0 {
txt.print("loading ")
txt.print("bmp\n")
void bmp_module.show_image(filenameptr)
txt.clear_screen()
cx16.wait(120)
}
else if strcmp(extension, ".ci")==0 {
txt.print("loading ")
txt.print("ci\n")
void ci_module.show_image(filenameptr)
txt.clear_screen()
cx16.wait(120)
}
}
sub extension_equals(uword stringptr, uword extensionptr) -> ubyte {
ubyte ix = rfind(stringptr, '.')
return ix<255 and strcmp(stringptr+ix, extensionptr)==0
}
sub rfind(uword stringptr, ubyte char) -> ubyte {
ubyte i
for i in strlen(stringptr)-1 downto 0 {
if @(stringptr+i)==char
return i
}
return 0
}
}
palette {
sub set_rgb4(uword palletteptr, uword num_colors) {
; 2 bytes per color entry, the Vera uses this, but the R/GB bytes order is swapped
uword vera_palette_ptr = $fa00
repeat num_colors {
cx16.vpoke(1, vera_palette_ptr+1, @(palletteptr))
palletteptr++
cx16.vpoke(1, vera_palette_ptr, @(palletteptr))
palletteptr++
vera_palette_ptr+=2
}
}
sub set_rgb8(uword palletteptr, uword num_colors) {
; 3 bytes per color entry, adjust color depth from 8 to 4 bits per channel.
uword vera_palette_ptr = $fa00
ubyte red
ubyte greenblue
repeat num_colors {
red = @(palletteptr) >> 4
palletteptr++
greenblue = @(palletteptr) & %11110000
palletteptr++
greenblue |= @(palletteptr) >> 4 ; add Blue
palletteptr++
cx16.vpoke(1, vera_palette_ptr, greenblue)
vera_palette_ptr++
cx16.vpoke(1, vera_palette_ptr, red)
vera_palette_ptr++
}
}
sub set_monochrome() {
uword vera_palette_ptr = $fa00
cx16.vpoke(1, vera_palette_ptr, 0)
vera_palette_ptr++
cx16.vpoke(1, vera_palette_ptr, 0)
vera_palette_ptr++
repeat 255 {
cx16.vpoke(1, vera_palette_ptr, 255)
vera_palette_ptr++
cx16.vpoke(1, vera_palette_ptr, 255)
vera_palette_ptr++
}
}
sub set_grayscale() {
ubyte c = 0
uword vera_palette_ptr = $fa00
repeat 16 {
repeat 16 {
cx16.vpoke(1, vera_palette_ptr, c)
vera_palette_ptr++
cx16.vpoke(1, vera_palette_ptr, c)
vera_palette_ptr++
}
c += $11
}
}
}

View File

@ -1,88 +1,28 @@
%target cx16
%import graphics
%import textio
%import diskio
%import c64colors
main {
koala_module {
const uword load_location = $6000
sub start() {
graphics.enable_bitmap_mode()
; set a better C64 color palette, the Cx16's default is too saturated
c64colors.set_palette_pepto()
if strlen(diskio.status(8)) ; trick to check if we're running on sdcard or host system shared folder
show_pics_sdcard()
else
show_file_list()
repeat {
;
}
}
sub show_file_list() {
; listing a directory doesn't work with a shared host directory in the emulator...
str[] pictures = [
"i01-blubb-sphinx.koa",
"i02-bugjam-jsl.koa",
"i03-dinothawr-ar.koa",
"i04-fox-leon.koa",
"i05-hunter-agod.koa",
"i06-jazzman-jds.koa",
"i07-katakis-jegg.koa"
]
uword nameptr
for nameptr in pictures {
uword size = diskio.load(8, nameptr, load_location)
if size==10001 {
convert_koalapic()
} else {
txt.print_uw(size)
txt.print("\nload error\n")
txt.print(diskio.status(8))
}
load_image_from_disk(nameptr)
cx16.wait(60)
}
}
sub show_pics_sdcard() {
; load and show all *.koa pictures on the disk.
; this only works in the emulator V38 with an sd-card image with the files on it.
str[20] filename_ptrs
ubyte num_files = diskio.list_files(8, ".koa", true, &filename_ptrs, len(filename_ptrs))
if num_files {
while num_files {
num_files--
load_image_from_disk(filename_ptrs[num_files])
cx16.wait(60)
}
} else {
txt.print("no *.koa files found\n")
}
}
sub load_image_from_disk(uword filenameptr) {
; special load routine that uses per-byte loading so it works from an sd-card image
sub show_image(uword filenameptr) -> ubyte {
ubyte load_ok=false
if diskio.f_open(8, filenameptr) {
uword size = diskio.f_read(load_location, 2) ; skip the first 2 bytes (load address)
if size==2 {
size = diskio.f_read(load_location, 10001)
if size == 10001 {
; set a better C64 color palette, the Cx16's default is too saturated
c64colors.set_palette_pepto()
convert_koalapic()
} else {
txt.print_uw(size)
txt.print("\nload error\n")
txt.print(diskio.status(8))
load_ok = true
}
}
diskio.f_close()
}
return load_ok
}
sub convert_koalapic() {
@ -95,6 +35,8 @@ main {
; theoretically you could put the 8-pixel array in zeropage to squeeze out another tiny bit of performance
ubyte[8] pixels
graphics.clear_screen(1, 0)
for cy in 0 to 24*8 step 8 {
for cx in 0 to 39 {
for d in 0 to 7 {

View File

@ -3,40 +3,9 @@
%import textio
%import diskio
main {
sub start() {
graphics.enable_bitmap_mode()
pcx_module {
if strlen(diskio.status(8)) ; trick to check if we're running on sdcard or host system shared folder
show_pics_sdcard()
else {
txt.print("only works with files on\nsdcard image!\n")
}
repeat {
;
}
}
sub show_pics_sdcard() {
; load and show all *.pcx pictures on the disk.
; this only works in the emulator V38 with an sd-card image with the files on it.
str[20] filename_ptrs
ubyte num_files = diskio.list_files(8, ".pcx", true, &filename_ptrs, len(filename_ptrs))
if num_files {
while num_files {
num_files--
show_pcx_image(filename_ptrs[num_files])
cx16.wait(120)
}
} else {
txt.print("no *.pcx files found\n")
}
}
sub show_pcx_image(uword filenameptr) {
sub show_image(uword filenameptr) {
ubyte load_ok = false
txt.print(filenameptr)
txt.chrout('\n')
@ -55,14 +24,13 @@ main {
uword num_colors = 2**bits_per_pixel
if number_of_planes == 1 {
if (width & 7) == 0 {
txt.clear_screen()
graphics.clear_screen(1, 0)
if palette_format==2
set_grayscale_palette()
palette.set_grayscale()
else if num_colors == 16
set_palette_8rgb(&header + $10, 16)
palette.set_rgb8(&header + $10, 16)
else if num_colors == 2
set_monochrome_palette()
palette.set_monochrome()
when bits_per_pixel {
8 -> load_ok = bitmap.do8bpp(width, height)
4 -> load_ok = bitmap.do4bpp(width, height)
@ -97,33 +65,7 @@ main {
}
}
sub set_monochrome_palette() {
uword vera_palette_ptr = $fa00
cx16.vpoke(1, vera_palette_ptr, 0)
vera_palette_ptr++
cx16.vpoke(1, vera_palette_ptr, 0)
vera_palette_ptr++
repeat 255 {
cx16.vpoke(1, vera_palette_ptr, 255)
vera_palette_ptr++
cx16.vpoke(1, vera_palette_ptr, 255)
vera_palette_ptr++
}
}
sub set_grayscale_palette() {
ubyte c = 0
uword vera_palette_ptr = $fa00
repeat 16 {
repeat 16 {
cx16.vpoke(1, vera_palette_ptr, c)
vera_palette_ptr++
cx16.vpoke(1, vera_palette_ptr, c)
vera_palette_ptr++
}
c += $11
}
}
sub set_palette_8rgb(uword palletteptr, uword num_colors) {
uword vera_palette_ptr = $fa00