2023-11-25 12:54:44 +00:00
|
|
|
; Viewer program for BMX image files.
|
|
|
|
; BMX file format: see https://cx16forum.com/forum/viewtopic.php?t=6945
|
2023-11-24 20:26:34 +00:00
|
|
|
|
|
|
|
%import textio
|
2023-11-25 12:54:44 +00:00
|
|
|
%import palette
|
2023-11-24 20:26:34 +00:00
|
|
|
%import bmx
|
|
|
|
%option no_sysinit
|
|
|
|
%zeropage basicsafe
|
|
|
|
|
|
|
|
main {
|
|
|
|
sub start() {
|
|
|
|
str filename = "?"*40
|
|
|
|
|
|
|
|
repeat {
|
|
|
|
txt.print("\nenter bmx image filename: ")
|
2024-02-04 22:18:11 +00:00
|
|
|
if txt.input_chars(&filename)!=0 {
|
2023-11-29 20:04:31 +00:00
|
|
|
|
2023-11-29 20:44:04 +00:00
|
|
|
if bmx.open(8, filename) {
|
2023-11-25 12:54:44 +00:00
|
|
|
txt.print("\nsize: ")
|
2023-11-24 20:26:34 +00:00
|
|
|
txt.print_uw(bmx.width)
|
2023-11-25 12:54:44 +00:00
|
|
|
txt.chrout('*')
|
2023-11-24 20:26:34 +00:00
|
|
|
txt.print_uw(bmx.height)
|
2023-11-25 12:54:44 +00:00
|
|
|
txt.print(" bpp: ")
|
2023-11-24 20:26:34 +00:00
|
|
|
txt.print_uw(bmx.bitsperpixel)
|
2023-11-29 20:44:04 +00:00
|
|
|
txt.print(" num colors: ")
|
|
|
|
txt.print_uw(bmx.palette_entries)
|
2023-11-24 20:26:34 +00:00
|
|
|
txt.nl()
|
|
|
|
sys.wait(100)
|
|
|
|
|
2023-11-25 12:54:44 +00:00
|
|
|
; tell the loader to put the palette into system memory instead
|
|
|
|
; also make palette black at first, to hide loading (even though it is very fast)
|
|
|
|
; (you could do a soft fade-in effect with this for instance)
|
|
|
|
bmx.palette_buffer_ptr = memory("palette", 512, 0)
|
|
|
|
sys.memset(bmx.palette_buffer_ptr, 512, 0)
|
|
|
|
palette.set_rgb(bmx.palette_buffer_ptr, 256)
|
|
|
|
|
2023-11-29 20:04:31 +00:00
|
|
|
; switch to bitmap screen mode and color depth: 320*240
|
|
|
|
void cx16.screen_mode($80, false) ; we're lazy and just use a kernal routine to set up the basics
|
2023-11-24 20:26:34 +00:00
|
|
|
cx16.VERA_L0_CONFIG = cx16.VERA_L0_CONFIG & %11111100 | bmx.vera_colordepth
|
2023-11-25 12:54:44 +00:00
|
|
|
|
|
|
|
; now load the image
|
2023-11-29 20:04:31 +00:00
|
|
|
if bmx.width==320 {
|
|
|
|
; can use the fast, full-screen load routine
|
2023-11-29 20:44:04 +00:00
|
|
|
if bmx.continue_load(0, 0) {
|
2023-11-29 20:04:31 +00:00
|
|
|
if bmx.height<240 {
|
|
|
|
; fill the remaining bottom part of the screen
|
|
|
|
cx16.GRAPH_set_colors(bmx.border, bmx.border, 99)
|
|
|
|
cx16.GRAPH_draw_rect(0, bmx.height, 320, 240-bmx.height, 0, true)
|
|
|
|
}
|
|
|
|
activate_palette()
|
|
|
|
void txt.waitkey()
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
; clear the screen with the border color
|
|
|
|
cx16.GRAPH_set_colors(0, 0, bmx.border)
|
|
|
|
cx16.GRAPH_clear()
|
|
|
|
; need to use the slower load routine that does padding
|
|
|
|
; center the image on the screen nicely
|
|
|
|
uword offset = (320-bmx.width)/2 + (240-bmx.height)/2*320
|
2023-11-29 20:44:04 +00:00
|
|
|
if bmx.continue_load_stamp(0, offset, 320) {
|
2023-11-29 20:04:31 +00:00
|
|
|
activate_palette()
|
|
|
|
void txt.waitkey()
|
|
|
|
}
|
2023-11-24 20:26:34 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
cbm.CINT() ; reset screen
|
|
|
|
|
2024-02-04 22:18:11 +00:00
|
|
|
if bmx.error_message!=0 {
|
2023-11-24 20:26:34 +00:00
|
|
|
txt.print("load error:\n")
|
|
|
|
txt.print(bmx.error_message)
|
|
|
|
txt.nl()
|
|
|
|
sys.wait(120)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2023-11-25 12:54:44 +00:00
|
|
|
|
|
|
|
sub activate_palette() {
|
|
|
|
; copies the pallette data from the memory buffer into vram
|
2023-11-29 20:04:31 +00:00
|
|
|
cx16.VERA_DC_BORDER = bmx.border
|
2023-11-25 12:54:44 +00:00
|
|
|
cx16.r1 = bmx.palette_buffer_ptr
|
|
|
|
cx16.r2L = bmx.palette_start
|
2023-11-29 20:44:04 +00:00
|
|
|
cx16.r3L = lsb(bmx.palette_entries)
|
2023-11-25 12:54:44 +00:00
|
|
|
do {
|
|
|
|
palette.set_color(cx16.r2L, peekw(cx16.r1))
|
|
|
|
cx16.r1+=2
|
|
|
|
cx16.r2L++
|
|
|
|
cx16.r3L--
|
|
|
|
} until cx16.r3L==0
|
|
|
|
}
|
2023-11-24 20:26:34 +00:00
|
|
|
}
|