# HG changeset patch # User Paul Boddie # Date 1541865797 -3600 # Node ID db91935dc4a635a070faf72a6d1580385f8d742e # Parent 39834d788dcc06bbb37cfe1be562d41c3a7d3c56 Introduced an image abstraction, making image data easier to work with. diff -r 39834d788dcc -r db91935dc4a6 data/screendata_160x128.S --- a/data/screendata_160x128.S Sat Nov 10 17:02:18 2018 +0100 +++ b/data/screendata_160x128.S Sat Nov 10 17:03:17 2018 +0100 @@ -1,19 +1,20 @@ .section .rodata, "a" /* Options: -['-H', '128'] +['screendata', '-H', '128'] */ .globl screendata .globl screendata_width .globl screendata_height +screendata: screendata_width: .word 160 screendata_height: .word 128 -screendata: +screendata_image: .word 0x00000000 .word 0x00000000 diff -r 39834d788dcc -r db91935dc4a6 data/screendata_160x256.S --- a/data/screendata_160x256.S Sat Nov 10 17:02:18 2018 +0100 +++ b/data/screendata_160x256.S Sat Nov 10 17:03:17 2018 +0100 @@ -1,15 +1,20 @@ .section .rodata, "a" +/* Options: +['screendata'] +*/ + .globl screendata .globl screendata_width .globl screendata_height +screendata: screendata_width: .word 160 screendata_height: .word 256 -screendata: +screendata_image: .word 0x00000000 .word 0x00000000 diff -r 39834d788dcc -r db91935dc4a6 data/screendata_92x128.S --- a/data/screendata_92x128.S Sat Nov 10 17:02:18 2018 +0100 +++ b/data/screendata_92x128.S Sat Nov 10 17:03:17 2018 +0100 @@ -1,15 +1,20 @@ .section .rodata, "a" +/* Options: +['screendata', '-W', '92', '-H', '128'] +*/ + .globl screendata .globl screendata_width .globl screendata_height +screendata: screendata_width: .word 92 screendata_height: .word 128 -screendata: +screendata_image: .word 0x00000000 .word 0x00000000 diff -r 39834d788dcc -r db91935dc4a6 data/sprite.S --- a/data/sprite.S Sat Nov 10 17:02:18 2018 +0100 +++ b/data/sprite.S Sat Nov 10 17:03:17 2018 +0100 @@ -1,19 +1,20 @@ .section .rodata, "a" /* Options: -['-W', '48', '-H', '64', '-S', '-b'] +['sprite', '-W', '48', '-H', '64', '-S', '-b'] */ .globl sprite .globl sprite_width .globl sprite_height +sprite: sprite_width: .word 22 sprite_height: .word 64 -sprite: +sprite_image: .byte 0x8c .byte 0x8c diff -r 39834d788dcc -r db91935dc4a6 examples/vga/main.c --- a/examples/vga/main.c Sat Nov 10 17:02:18 2018 +0100 +++ b/examples/vga/main.c Sat Nov 10 17:03:17 2018 +0100 @@ -21,6 +21,7 @@ #include "debug.h" #include "display.h" #include "font.h" +#include "image.h" #include "init.h" #include "pic32_c.h" #include "utils.h" @@ -102,10 +103,8 @@ /* Bundled image and font data. */ -extern uint8_t screendata[]; -extern uint32_t screendata_width, screendata_height; -extern uint8_t sprite[]; -extern uint32_t sprite_width, sprite_height; +extern image_t screendata; +extern image_t sprite; extern uint8_t fontchars[]; extern uint32_t fonttable[]; @@ -115,48 +114,15 @@ -/* Stored display regions. */ - -typedef struct -{ - /* Stored region overplotted by the sprite. */ - - uint8_t *image; - int stored; - - /* Position of the stored region. */ - - int x, y; - -} stored_region_t; - -/* Initialise the stored regions. */ - -void init_stored_regions(stored_region_t *r, int frames, - uint8_t *regions, uint32_t region_size) -{ - int frame; - - for (frame = 0; frame < frames; frame++) - { - r->stored = 0; - r->image = regions; - regions += region_size; - r++; - } -} - - - /* Copy to the store from the display, then blit the image. */ static void plot_sprite(stored_region_t *r, int x, int y, int key) { display_copy(&display_config, r->image, - sprite_width, sprite_height / SOURCE_YSTEP, 1, + sprite.width, sprite.height / SOURCE_YSTEP, 1, x, y, -1, 0); - display_copy(&display_config, sprite, - sprite_width, sprite_height, SOURCE_YSTEP, + display_copy(&display_config, sprite.image, + sprite.width, sprite.height, SOURCE_YSTEP, x, y, key, 1); /* Record the stored background. */ @@ -172,7 +138,7 @@ { if (r->stored) display_copy(&display_config, r->image, - sprite_width, sprite_height / SOURCE_YSTEP, 1, + sprite.width, sprite.height / SOURCE_YSTEP, 1, r->x, r->y, -1, 1); } @@ -183,16 +149,16 @@ { /* Determine positions within the image. */ - int xpos = wrap_value(xorigin, screendata_width); - int ypos = wrap_value(yorigin, screendata_height); + int xpos = wrap_value(xorigin, screendata.width); + int ypos = wrap_value(yorigin, screendata.height); /* The display region is either the left or right edge. */ - int xdisplay = xstep < 0 ? 0 : screendata_width - xstep; + int xdisplay = xstep < 0 ? 0 : screendata.width - xstep; /* The source region depends on the origin within the background image. */ - int xsource = wrap_value(xdisplay + xpos, screendata_width); + int xsource = wrap_value(xdisplay + xpos, screendata.width); /* The column width is the absolute increment. */ @@ -201,7 +167,7 @@ /* Not all of the column may be available if close to the edge of the image, requiring multiple slices. */ - int available = screendata_width - xsource; + int available = screendata.width - xsource; while (width) { @@ -211,10 +177,10 @@ upwards (or downwards having wrapped around) on the screen. */ - display_copy_section(&display_config, screendata, - screendata_width, screendata_height, + display_copy_section(&display_config, screendata.image, + screendata.width, screendata.height, xsource, ypos, - width, screendata_height - ypos, + width, screendata.height - ypos, v->yscale, xdisplay, 0, -1, 1); @@ -225,12 +191,12 @@ screen. */ if (ypos) - display_copy_section(&display_config, screendata, - screendata_width, screendata_height, + display_copy_section(&display_config, screendata.image, + screendata.width, screendata.height, xsource, 0, width, ypos, v->yscale, - xdisplay, (screendata_height - ypos) / v->yscale, + xdisplay, (screendata.height - ypos) / v->yscale, -1, 1); /* Get the next slice of the column. */ @@ -239,8 +205,8 @@ { width -= available; xsource = 0; - xdisplay = wrap_value(xdisplay + available, screendata_width); - available = screendata_width; + xdisplay = wrap_value(xdisplay + available, screendata.width); + available = screendata.width; } else width = 0; @@ -253,7 +219,7 @@ { /* Stores of background details, replotted when moving the sprite. */ - uint8_t backgrounds[FRAME_COUNT][(sprite_width * sprite_height) / SOURCE_YSTEP]; + uint8_t backgrounds[FRAME_COUNT][(sprite.width * sprite.height) / SOURCE_YSTEP]; stored_region_t regions[FRAME_COUNT]; /* Sprite position. */ @@ -279,15 +245,15 @@ SCROLL_XSTEP, SOURCE_YSTEP, plot_screen_edge); init_stored_regions(regions, display_config.frames, (uint8_t *) backgrounds, - (sprite_width * sprite_height) / SOURCE_YSTEP); + (sprite.width * sprite.height) / SOURCE_YSTEP); /* Animation loop. */ while (1) { - for (y = 0; y < display_config.line_count - sprite_height; y++) + for (y = 0; y < display_config.line_count - sprite.height; y++) { - for (x = 0; x < display_config.line_length - sprite_width; x++) + for (x = 0; x < display_config.line_length - sprite.width; x++) { plot_sprite(®ions[display_config.frame], x, y, 0x8c); @@ -371,11 +337,11 @@ /* Plot the image centred on the screen. */ - display_copy(&display_config, screendata, - screendata_width, screendata_height, + display_copy(&display_config, screendata.image, + screendata.width, screendata.height, SOURCE_YSTEP, - (display_config.line_length - screendata_width) / 2, - (display_config.line_count - (screendata_height / SOURCE_YSTEP)) / 2, + (display_config.line_length - screendata.width) / 2, + (display_config.line_count - (screendata.height / SOURCE_YSTEP)) / 2, -1, 1); /* Write a sequence of characters. */ diff -r 39834d788dcc -r db91935dc4a6 include/image.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/include/image.h Sat Nov 10 17:03:17 2018 +0100 @@ -0,0 +1,63 @@ +/* + * Common image-related functions. + * + * Copyright (C) 2018 Paul Boddie + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#ifndef __IMAGE_H__ +#define __IMAGE_H__ + +#include + + + +/* Image data type. */ + +typedef struct +{ + /* Image width and height. */ + + uint32_t width, height; + + /* Image data. */ + + uint8_t image[]; + +} image_t; + +/* Stored display regions. */ + +typedef struct +{ + /* Stored region overplotted by the sprite. */ + + uint8_t *image; + int stored; + + /* Position of the stored region. */ + + int x, y; + +} stored_region_t; + + + +/* Initialise the stored regions. */ + +void init_stored_regions(stored_region_t *r, int frames, + uint8_t *regions, uint32_t region_size); + +#endif /* __IMAGE_H__ */ diff -r 39834d788dcc -r db91935dc4a6 lib/image.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/lib/image.c Sat Nov 10 17:03:17 2018 +0100 @@ -0,0 +1,36 @@ +/* + * Common image-related functions. + * + * Copyright (C) 2018 Paul Boddie + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include "image.h" + + + +void init_stored_regions(stored_region_t *r, int frames, + uint8_t *regions, uint32_t region_size) +{ + int frame; + + for (frame = 0; frame < frames; frame++) + { + r->stored = 0; + r->image = regions; + regions += region_size; + r++; + } +} diff -r 39834d788dcc -r db91935dc4a6 mk/common.mk --- a/mk/common.mk Sat Nov 10 17:02:18 2018 +0100 +++ b/mk/common.mk Sat Nov 10 17:03:17 2018 +0100 @@ -52,8 +52,8 @@ COMMON_SRC = $(LIBDIR)/payload.c $(LIBDIR)/init.c $(LIBDIR)/debug.c $(LIBDIR)/utils.c $(LIBDIR)/cpu.S COMMON_OBJ = $(LIBDIR)/payload.o $(LIBDIR)/init.o $(LIBDIR)/debug.o $(LIBDIR)/utils.o $(LIBDIR)/cpu.o -DISPLAY_COMMON_SRC = $(LIBDIR)/display.c $(LIBDIR)/font.c $(LIBDIR)/viewport.c -DISPLAY_COMMON_OBJ = $(LIBDIR)/display.o $(LIBDIR)/font.o $(LIBDIR)/viewport.o +DISPLAY_COMMON_SRC = $(LIBDIR)/display.c $(LIBDIR)/font.c $(LIBDIR)/image.c $(LIBDIR)/viewport.c +DISPLAY_COMMON_OBJ = $(LIBDIR)/display.o $(LIBDIR)/font.o $(LIBDIR)/image.o $(LIBDIR)/viewport.o DISPLAY_SRC = $(DISPLAY_COMMON_SRC) $(LIBDIR)/vga_display.c DISPLAY_OBJ = $(DISPLAY_COMMON_OBJ) $(LIBDIR)/vga_display.o diff -r 39834d788dcc -r db91935dc4a6 tools/makeimage.py --- a/tools/makeimage.py Sat Nov 10 17:02:18 2018 +0100 +++ b/tools/makeimage.py Sat Nov 10 17:03:17 2018 +0100 @@ -54,13 +54,14 @@ .globl %s_width .globl %s_height +%s: %s_width: .word %d %s_height: .word %d -%s: -""" % (options, label, label, label, label, width, label, height, label) +%s_image: +""" % (options, label, label, label, label, label, width, label, height, label) word = [] y = 0 @@ -274,7 +275,7 @@ base_height = height = 256 input_filename, output_filename, label = sys.argv[1:4] - options = sys.argv[4:] + options = sys.argv[3:] # Basic image properties.