2020-12-14 14:30:18 +01:00
|
|
|
%target cx16
|
2020-12-25 17:00:11 +01:00
|
|
|
%import gfx2
|
2020-12-14 14:30:18 +01:00
|
|
|
%import textio
|
|
|
|
%import diskio
|
2021-01-07 20:01:11 +01:00
|
|
|
%import string
|
2020-12-14 14:30:18 +01:00
|
|
|
%import koala_module
|
|
|
|
%import iff_module
|
|
|
|
%import pcx_module
|
|
|
|
%import bmp_module
|
2020-12-14 15:34:52 +01:00
|
|
|
;; %import ci_module
|
2020-12-24 05:46:57 +01:00
|
|
|
%zeropage basicsafe
|
2020-12-14 14:30:18 +01:00
|
|
|
|
2020-12-22 04:52:46 +01:00
|
|
|
|
2020-12-14 14:30:18 +01:00
|
|
|
main {
|
|
|
|
sub start() {
|
2020-12-14 15:34:52 +01:00
|
|
|
; trick to check if we're running on sdcard or host system shared folder
|
|
|
|
txt.print("\nimage viewer for commander x16\nformats supported: .iff, .pcx, .bmp, .koa (c64 koala)\n\n")
|
2021-01-07 20:01:11 +01:00
|
|
|
if string.length(diskio.status(8)) {
|
2020-12-14 15:34:52 +01:00
|
|
|
txt.print("enter image file name or just enter for all on disk: ")
|
|
|
|
ubyte i = txt.input_chars(diskio.filename)
|
2020-12-26 01:25:52 +01:00
|
|
|
gfx2.screen_mode(1) ; 320*240, 256c
|
2020-12-14 15:34:52 +01:00
|
|
|
if i
|
|
|
|
attempt_load(diskio.filename)
|
|
|
|
else
|
|
|
|
show_pics_sdcard()
|
|
|
|
|
2020-12-25 17:00:11 +01:00
|
|
|
; txt.print("\nnothing more to do.\n")
|
2020-12-14 14:30:18 +01:00
|
|
|
}
|
2020-12-14 15:34:52 +01:00
|
|
|
else
|
|
|
|
txt.print("files are read with sequential file loading.\nin the emulator this currently only works with files on an sd-card image.\nsorry :(\n")
|
2020-12-14 14:30:18 +01:00
|
|
|
|
2020-12-26 01:25:52 +01:00
|
|
|
gfx2.screen_mode(255) ; back to default text mode and palette
|
2020-12-25 17:00:11 +01:00
|
|
|
txt.print("that was all folks!\n")
|
2020-12-14 14:30:18 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
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
|
2020-12-30 23:34:00 +01:00
|
|
|
ubyte num_files = diskio.list_files(8, 0, &filename_ptrs, len(filename_ptrs))
|
2020-12-14 14:30:18 +01:00
|
|
|
if num_files {
|
|
|
|
while num_files {
|
|
|
|
num_files--
|
|
|
|
attempt_load(filename_ptrs[num_files])
|
|
|
|
}
|
|
|
|
} else
|
|
|
|
txt.print("no files in directory!\n")
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
sub attempt_load(uword filenameptr) {
|
2020-12-25 17:00:11 +01:00
|
|
|
;txt.print(">> ")
|
|
|
|
;txt.print(filenameptr)
|
2021-01-08 16:56:17 +01:00
|
|
|
;txt.nl()
|
2020-12-14 14:30:18 +01:00
|
|
|
uword extension = filenameptr + rfind(filenameptr, '.')
|
2021-01-07 23:01:31 +01:00
|
|
|
if string.compare(extension, ".iff")==0 {
|
2020-12-25 17:00:11 +01:00
|
|
|
;txt.print("loading ")
|
|
|
|
;txt.print("iff\n")
|
|
|
|
if iff_module.show_image(filenameptr) {
|
|
|
|
if iff_module.num_cycles {
|
|
|
|
repeat 500 {
|
2021-01-03 02:36:45 +01:00
|
|
|
sys.wait(1)
|
2020-12-25 17:00:11 +01:00
|
|
|
iff_module.cycle_colors_each_jiffy()
|
|
|
|
}
|
2020-12-23 23:23:16 +01:00
|
|
|
}
|
2020-12-25 17:00:11 +01:00
|
|
|
else
|
2021-01-03 02:36:45 +01:00
|
|
|
sys.wait(180)
|
2020-12-25 17:00:11 +01:00
|
|
|
} else {
|
|
|
|
load_error(filenameptr)
|
2020-12-23 23:23:16 +01:00
|
|
|
}
|
2020-12-14 14:30:18 +01:00
|
|
|
}
|
2021-01-07 23:01:31 +01:00
|
|
|
else if string.compare(extension, ".pcx")==0 {
|
2020-12-25 17:00:11 +01:00
|
|
|
;txt.print("loading ")
|
|
|
|
;txt.print("pcx\n")
|
|
|
|
if pcx_module.show_image(filenameptr) {
|
2021-01-03 02:36:45 +01:00
|
|
|
sys.wait(180)
|
2020-12-25 17:00:11 +01:00
|
|
|
} else {
|
|
|
|
load_error(filenameptr)
|
|
|
|
}
|
2020-12-14 14:30:18 +01:00
|
|
|
}
|
2021-01-07 23:01:31 +01:00
|
|
|
else if string.compare(extension,".koa")==0 {
|
2020-12-25 17:00:11 +01:00
|
|
|
;txt.print("loading ")
|
|
|
|
;txt.print("koala\n")
|
|
|
|
if koala_module.show_image(filenameptr) {
|
2021-01-03 02:36:45 +01:00
|
|
|
sys.wait(180)
|
2020-12-25 17:00:11 +01:00
|
|
|
} else {
|
|
|
|
load_error(filenameptr)
|
|
|
|
}
|
2020-12-14 14:30:18 +01:00
|
|
|
}
|
2021-01-07 23:01:31 +01:00
|
|
|
else if string.compare(extension, ".bmp")==0 {
|
2020-12-25 17:00:11 +01:00
|
|
|
;txt.print("loading ")
|
|
|
|
;txt.print("bmp\n")
|
|
|
|
if bmp_module.show_image(filenameptr) {
|
2021-01-03 02:36:45 +01:00
|
|
|
sys.wait(180)
|
2020-12-25 17:00:11 +01:00
|
|
|
} else {
|
|
|
|
load_error(filenameptr)
|
|
|
|
}
|
2020-12-14 14:30:18 +01:00
|
|
|
}
|
2021-01-07 20:01:11 +01:00
|
|
|
; else if extension == ".ci" {
|
2020-12-27 03:35:56 +01:00
|
|
|
;; txt.print("loading ")
|
|
|
|
;; txt.print("ci\n")
|
|
|
|
; if ci_module.show_image(filenameptr) {
|
2021-01-03 02:36:45 +01:00
|
|
|
; sys.wait(180)
|
2020-12-25 17:00:11 +01:00
|
|
|
; } else {
|
|
|
|
; load_error(filenameptr)
|
|
|
|
; }
|
2020-12-14 15:34:52 +01:00
|
|
|
; }
|
2020-12-14 14:30:18 +01:00
|
|
|
}
|
|
|
|
|
2020-12-25 17:00:11 +01:00
|
|
|
sub load_error(uword filenameptr) {
|
2020-12-26 01:25:52 +01:00
|
|
|
gfx2.screen_mode(255) ; back to default text mode and palette
|
2020-12-25 17:00:11 +01:00
|
|
|
txt.print(filenameptr)
|
|
|
|
txt.print(": load error\n")
|
2021-01-08 16:20:56 +01:00
|
|
|
sys.exit(1)
|
2020-12-25 17:00:11 +01:00
|
|
|
}
|
|
|
|
|
2020-12-14 14:30:18 +01:00
|
|
|
sub extension_equals(uword stringptr, uword extensionptr) -> ubyte {
|
|
|
|
ubyte ix = rfind(stringptr, '.')
|
2021-01-07 20:01:11 +01:00
|
|
|
return ix<255 and string.compare(stringptr+ix, extensionptr)==0
|
2020-12-14 14:30:18 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
sub rfind(uword stringptr, ubyte char) -> ubyte {
|
|
|
|
ubyte i
|
2021-01-07 20:01:11 +01:00
|
|
|
for i in string.length(stringptr)-1 downto 0 {
|
2020-12-14 14:30:18 +01:00
|
|
|
if @(stringptr+i)==char
|
|
|
|
return i
|
|
|
|
}
|
|
|
|
return 0
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2020-12-26 13:38:14 +01:00
|
|
|
custompalette {
|
2020-12-14 14:30:18 +01:00
|
|
|
|
2020-12-14 15:34:52 +01:00
|
|
|
sub set_bgra(uword palletteptr, uword num_colors) {
|
|
|
|
uword vera_palette_ptr = $fa00
|
|
|
|
ubyte red
|
|
|
|
ubyte greenblue
|
|
|
|
|
|
|
|
; 4 bytes per color entry (BGRA), adjust color depth from 8 to 4 bits per channel.
|
|
|
|
repeat num_colors {
|
|
|
|
red = @(palletteptr+2) >> 4
|
|
|
|
greenblue = @(palletteptr+1) & %11110000
|
|
|
|
greenblue |= @(palletteptr+0) >> 4 ; add Blue
|
|
|
|
palletteptr+=4
|
|
|
|
cx16.vpoke(1, vera_palette_ptr, greenblue)
|
|
|
|
vera_palette_ptr++
|
|
|
|
cx16.vpoke(1, vera_palette_ptr, red)
|
|
|
|
vera_palette_ptr++
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-12-26 13:38:14 +01:00
|
|
|
sub set_grayscale256() {
|
|
|
|
; grays $000- $fff stretched out over all the 256 colors
|
2020-12-14 14:30:18 +01:00
|
|
|
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
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|