mirror of
https://github.com/irmen/prog8.git
synced 2024-07-09 02:29:02 +00:00
incremental file loading
This commit is contained in:
parent
e6220a464c
commit
4f6c45c86c
@ -47,20 +47,19 @@
|
|||||||
; (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)
|
; (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 {
|
main {
|
||||||
|
%option force_output
|
||||||
ubyte[256] buffer
|
ubyte[256] buffer
|
||||||
ubyte[256] buffer2 ; add two more buffers to make enoughs space
|
ubyte[256] buffer2 ; add two more buffers to make enough space
|
||||||
ubyte[256] buffer3 ; to store a 256 color palette
|
ubyte[256] buffer3 ; to store a 256 color palette
|
||||||
|
ubyte[256] buffer4 ; .. and some more to be able to store 1280=
|
||||||
|
ubyte[256] buffer5 ; two 640 bytes worth of bitmap scanline data
|
||||||
|
|
||||||
str filename = "trsi256.ci"
|
str filename = "trsi256.ci"
|
||||||
|
|
||||||
sub start() {
|
sub start() {
|
||||||
buffer[0] = 0
|
|
||||||
buffer2[0] = 0
|
|
||||||
buffer3[0] = 0
|
|
||||||
ubyte read_success = false
|
ubyte read_success = false
|
||||||
uword bitmap_load_address = progend()
|
uword bitmap_load_address = progend()
|
||||||
uword max_bitmap_size = $9eff - bitmap_load_address
|
; uword max_bitmap_size = $9eff - bitmap_load_address
|
||||||
|
|
||||||
txt.print(filename)
|
txt.print(filename)
|
||||||
txt.chrout('\n')
|
txt.chrout('\n')
|
||||||
@ -69,65 +68,60 @@ main {
|
|||||||
uword size = diskio.f_read(buffer, 12) ; read the header
|
uword size = diskio.f_read(buffer, 12) ; read the header
|
||||||
if size==12 {
|
if size==12 {
|
||||||
if buffer[0]=='c' and buffer[1]=='i' and buffer[2] == 9 {
|
if buffer[0]=='c' and buffer[1]=='i' and buffer[2] == 9 {
|
||||||
if buffer[11] {
|
uword width = mkword(buffer[4], buffer[3])
|
||||||
txt.print("file too large >64kb!\n") ; TODO add support for large files
|
uword height = mkword(buffer[6], buffer[5])
|
||||||
|
ubyte bpp = buffer[7]
|
||||||
|
uword num_colors = 2 ** bpp
|
||||||
|
ubyte flags = buffer[8]
|
||||||
|
ubyte compression = flags & %00000011
|
||||||
|
ubyte palette_format = (flags & %00000100) >> 2
|
||||||
|
ubyte bitmap_format = (flags & %00001000) >> 3
|
||||||
|
; ubyte hscale = (flags & %00010000) >> 4
|
||||||
|
; ubyte vscale = (flags & %00100000) >> 5
|
||||||
|
uword bitmap_size = mkword(buffer[10], buffer[9])
|
||||||
|
uword palette_size = num_colors*2
|
||||||
|
if palette_format
|
||||||
|
palette_size += num_colors ; 3
|
||||||
|
txt.print_uw(width)
|
||||||
|
txt.chrout('*')
|
||||||
|
txt.print_uw(height)
|
||||||
|
txt.print(" * ")
|
||||||
|
txt.print_uw(num_colors)
|
||||||
|
txt.print(" colors\n")
|
||||||
|
if width > graphics.WIDTH {
|
||||||
|
txt.print("image is too wide for the display!\n")
|
||||||
|
} else if compression!=0 {
|
||||||
|
txt.print("compressed image not yet supported!\n") ; TODO implement the various decompressions
|
||||||
|
} else if bitmap_format==1 {
|
||||||
|
txt.print("tiled bitmap not yet supported!\n") ; TODO implement tiled image
|
||||||
} else {
|
} else {
|
||||||
uword width = mkword(buffer[4], buffer[3])
|
txt.print("loading...")
|
||||||
uword height = mkword(buffer[6], buffer[5])
|
size = diskio.f_read(buffer, palette_size)
|
||||||
ubyte bpp = buffer[7]
|
if size==palette_size {
|
||||||
uword num_colors = 2 ** bpp
|
if compression {
|
||||||
ubyte flags = buffer[8]
|
txt.print("todo: compressed image support\n")
|
||||||
ubyte compression = flags & %00000011
|
} else {
|
||||||
ubyte palette_format = (flags & %00000100) >> 2
|
; uncompressed bitmap data. read it a scanline at a time and display as we go.
|
||||||
ubyte bitmap_format = (flags & %00001000) >> 3
|
; restrict height to the maximun that can be displayed
|
||||||
; ubyte hscale = (flags & %00010000) >> 4
|
if height > graphics.HEIGHT
|
||||||
; ubyte vscale = (flags & %00100000) >> 5
|
height = graphics.HEIGHT
|
||||||
uword bitmap_size = mkword(buffer[10], buffer[9])
|
graphics.enable_bitmap_mode()
|
||||||
uword palette_size = num_colors*2
|
set_palette(num_colors, palette_format, buffer)
|
||||||
if palette_format
|
cx16.r0 = 0
|
||||||
palette_size += num_colors ; 3
|
cx16.r1 = 0
|
||||||
txt.print_uw(width)
|
cx16.FB_cursor_position()
|
||||||
txt.chrout('*')
|
uword scanline_size = width * bpp / 8
|
||||||
txt.print_uw(height)
|
ubyte y
|
||||||
txt.print(" * ")
|
for y in 0 to lsb(height)-1 {
|
||||||
txt.print_uw(num_colors)
|
void diskio.f_read(buffer, scanline_size)
|
||||||
txt.print(" colors\n")
|
|
||||||
if width > graphics.WIDTH {
|
|
||||||
txt.print("image is too wide for the display!\n")
|
|
||||||
} else if compression!=0 {
|
|
||||||
txt.print("compressed image not yet supported!\n") ; TODO implement the various decompressions
|
|
||||||
} else if bitmap_format==1 {
|
|
||||||
txt.print("tiled bitmap not yet supported!\n") ; TODO implement tiled image
|
|
||||||
} else if bitmap_size > max_bitmap_size {
|
|
||||||
; TODO implement large file support by using memory banks (nasty if compression is used though)
|
|
||||||
; TODO in case of uncompressed data: do not read the full bitmap in memory but read a scanline at a time and display them as we go
|
|
||||||
txt.print("not enough ram to load bitmap!\nrequired: ")
|
|
||||||
txt.print_uw(bitmap_size)
|
|
||||||
txt.print(" available: ")
|
|
||||||
txt.print_uw(max_bitmap_size)
|
|
||||||
txt.chrout('\n')
|
|
||||||
} else {
|
|
||||||
txt.print("loading...")
|
|
||||||
size = diskio.f_read(buffer, palette_size)
|
|
||||||
if size==palette_size {
|
|
||||||
size = diskio.f_read(bitmap_load_address, bitmap_size)
|
|
||||||
if size==bitmap_size {
|
|
||||||
; all data has been loaded, display the image
|
|
||||||
diskio.f_close()
|
|
||||||
read_success = true
|
|
||||||
txt.print("ok\n")
|
|
||||||
; restrict the height to what can be displayed using the graphics functions...
|
|
||||||
if height > graphics.HEIGHT
|
|
||||||
height = graphics.HEIGHT
|
|
||||||
graphics.enable_bitmap_mode()
|
|
||||||
set_palette(num_colors, palette_format, buffer)
|
|
||||||
when bpp {
|
when bpp {
|
||||||
8 -> display_uncompressed_256c(width, height, bitmap_load_address)
|
8 -> display_scanline_256c(buffer, scanline_size)
|
||||||
4 -> display_uncompressed_16c(width, height, bitmap_load_address)
|
4 -> display_scanline_16c(buffer, scanline_size)
|
||||||
2 -> display_uncompressed_4c(width, height, bitmap_load_address)
|
2 -> display_scanline_4c(buffer, scanline_size)
|
||||||
1 -> display_uncompressed_2c(width, height, bitmap_load_address)
|
1 -> display_scanline_2c(buffer, scanline_size)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
read_success = true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -177,28 +171,20 @@ main {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
sub display_uncompressed_256c(uword width, uword height, uword bitmapptr) {
|
sub display_scanline_256c(uword dataptr, uword numbytes) {
|
||||||
uword y
|
; FB_set_pixels in rom v38 crashes with a size > 255 so we use our own replacement for now
|
||||||
for y in 0 to height-1 {
|
cx16.FB_set_pixels_from_buf(dataptr, numbytes)
|
||||||
cx16.r0 = 0
|
|
||||||
cx16.r1 = y
|
|
||||||
cx16.FB_cursor_position()
|
|
||||||
|
|
||||||
; FB_set_pixels in rom v38 crashes with a size > 255 so we use our own replacement for now
|
|
||||||
cx16.FB_set_pixels_from_buf(bitmapptr, width)
|
|
||||||
bitmapptr += width
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
sub display_uncompressed_16c(uword width, uword height, uword bitmapptr) {
|
sub display_scanline_16c(uword dataptr, uword numbytes) {
|
||||||
; TODO 16 color
|
; TODO
|
||||||
}
|
}
|
||||||
|
|
||||||
sub display_uncompressed_4c(uword width, uword height, uword bitmapptr) {
|
sub display_scanline_4c(uword dataptr, uword numbytes) {
|
||||||
; TODO 4 color
|
; TODO
|
||||||
}
|
}
|
||||||
|
|
||||||
sub display_uncompressed_2c(uword width, uword height, uword bitmapptr) {
|
sub display_scanline_2c(uword dataptr, uword numbytes) {
|
||||||
; TODO 2 color
|
; TODO
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -8,6 +8,10 @@
|
|||||||
|
|
||||||
main {
|
main {
|
||||||
sub start () {
|
sub start () {
|
||||||
|
|
||||||
|
uword bitmap_load_address = progend()
|
||||||
|
uword max_bitmap_size = $9eff - bitmap_load_address ; TODO why is this not optimized away?
|
||||||
|
|
||||||
uword xx = progend()
|
uword xx = progend()
|
||||||
txt.print_uwhex(xx, 1)
|
txt.print_uwhex(xx, 1)
|
||||||
txt.print_uwhex(progend(), 1)
|
txt.print_uwhex(progend(), 1)
|
||||||
|
Loading…
Reference in New Issue
Block a user