5.1 --- a/examples/vga/main.c Sat Nov 10 17:02:18 2018 +0100
5.2 +++ b/examples/vga/main.c Sat Nov 10 17:03:17 2018 +0100
5.3 @@ -21,6 +21,7 @@
5.4 #include "debug.h"
5.5 #include "display.h"
5.6 #include "font.h"
5.7 +#include "image.h"
5.8 #include "init.h"
5.9 #include "pic32_c.h"
5.10 #include "utils.h"
5.11 @@ -102,10 +103,8 @@
5.12
5.13 /* Bundled image and font data. */
5.14
5.15 -extern uint8_t screendata[];
5.16 -extern uint32_t screendata_width, screendata_height;
5.17 -extern uint8_t sprite[];
5.18 -extern uint32_t sprite_width, sprite_height;
5.19 +extern image_t screendata;
5.20 +extern image_t sprite;
5.21
5.22 extern uint8_t fontchars[];
5.23 extern uint32_t fonttable[];
5.24 @@ -115,48 +114,15 @@
5.25
5.26
5.27
5.28 -/* Stored display regions. */
5.29 -
5.30 -typedef struct
5.31 -{
5.32 - /* Stored region overplotted by the sprite. */
5.33 -
5.34 - uint8_t *image;
5.35 - int stored;
5.36 -
5.37 - /* Position of the stored region. */
5.38 -
5.39 - int x, y;
5.40 -
5.41 -} stored_region_t;
5.42 -
5.43 -/* Initialise the stored regions. */
5.44 -
5.45 -void init_stored_regions(stored_region_t *r, int frames,
5.46 - uint8_t *regions, uint32_t region_size)
5.47 -{
5.48 - int frame;
5.49 -
5.50 - for (frame = 0; frame < frames; frame++)
5.51 - {
5.52 - r->stored = 0;
5.53 - r->image = regions;
5.54 - regions += region_size;
5.55 - r++;
5.56 - }
5.57 -}
5.58 -
5.59 -
5.60 -
5.61 /* Copy to the store from the display, then blit the image. */
5.62
5.63 static void plot_sprite(stored_region_t *r, int x, int y, int key)
5.64 {
5.65 display_copy(&display_config, r->image,
5.66 - sprite_width, sprite_height / SOURCE_YSTEP, 1,
5.67 + sprite.width, sprite.height / SOURCE_YSTEP, 1,
5.68 x, y, -1, 0);
5.69 - display_copy(&display_config, sprite,
5.70 - sprite_width, sprite_height, SOURCE_YSTEP,
5.71 + display_copy(&display_config, sprite.image,
5.72 + sprite.width, sprite.height, SOURCE_YSTEP,
5.73 x, y, key, 1);
5.74
5.75 /* Record the stored background. */
5.76 @@ -172,7 +138,7 @@
5.77 {
5.78 if (r->stored)
5.79 display_copy(&display_config, r->image,
5.80 - sprite_width, sprite_height / SOURCE_YSTEP, 1,
5.81 + sprite.width, sprite.height / SOURCE_YSTEP, 1,
5.82 r->x, r->y, -1, 1);
5.83 }
5.84
5.85 @@ -183,16 +149,16 @@
5.86 {
5.87 /* Determine positions within the image. */
5.88
5.89 - int xpos = wrap_value(xorigin, screendata_width);
5.90 - int ypos = wrap_value(yorigin, screendata_height);
5.91 + int xpos = wrap_value(xorigin, screendata.width);
5.92 + int ypos = wrap_value(yorigin, screendata.height);
5.93
5.94 /* The display region is either the left or right edge. */
5.95
5.96 - int xdisplay = xstep < 0 ? 0 : screendata_width - xstep;
5.97 + int xdisplay = xstep < 0 ? 0 : screendata.width - xstep;
5.98
5.99 /* The source region depends on the origin within the background image. */
5.100
5.101 - int xsource = wrap_value(xdisplay + xpos, screendata_width);
5.102 + int xsource = wrap_value(xdisplay + xpos, screendata.width);
5.103
5.104 /* The column width is the absolute increment. */
5.105
5.106 @@ -201,7 +167,7 @@
5.107 /* Not all of the column may be available if close to the edge of the
5.108 image, requiring multiple slices. */
5.109
5.110 - int available = screendata_width - xsource;
5.111 + int available = screendata.width - xsource;
5.112
5.113 while (width)
5.114 {
5.115 @@ -211,10 +177,10 @@
5.116 upwards (or downwards having wrapped around) on the
5.117 screen. */
5.118
5.119 - display_copy_section(&display_config, screendata,
5.120 - screendata_width, screendata_height,
5.121 + display_copy_section(&display_config, screendata.image,
5.122 + screendata.width, screendata.height,
5.123 xsource, ypos,
5.124 - width, screendata_height - ypos,
5.125 + width, screendata.height - ypos,
5.126 v->yscale,
5.127 xdisplay, 0,
5.128 -1, 1);
5.129 @@ -225,12 +191,12 @@
5.130 screen. */
5.131
5.132 if (ypos)
5.133 - display_copy_section(&display_config, screendata,
5.134 - screendata_width, screendata_height,
5.135 + display_copy_section(&display_config, screendata.image,
5.136 + screendata.width, screendata.height,
5.137 xsource, 0,
5.138 width, ypos,
5.139 v->yscale,
5.140 - xdisplay, (screendata_height - ypos) / v->yscale,
5.141 + xdisplay, (screendata.height - ypos) / v->yscale,
5.142 -1, 1);
5.143
5.144 /* Get the next slice of the column. */
5.145 @@ -239,8 +205,8 @@
5.146 {
5.147 width -= available;
5.148 xsource = 0;
5.149 - xdisplay = wrap_value(xdisplay + available, screendata_width);
5.150 - available = screendata_width;
5.151 + xdisplay = wrap_value(xdisplay + available, screendata.width);
5.152 + available = screendata.width;
5.153 }
5.154 else
5.155 width = 0;
5.156 @@ -253,7 +219,7 @@
5.157 {
5.158 /* Stores of background details, replotted when moving the sprite. */
5.159
5.160 - uint8_t backgrounds[FRAME_COUNT][(sprite_width * sprite_height) / SOURCE_YSTEP];
5.161 + uint8_t backgrounds[FRAME_COUNT][(sprite.width * sprite.height) / SOURCE_YSTEP];
5.162 stored_region_t regions[FRAME_COUNT];
5.163
5.164 /* Sprite position. */
5.165 @@ -279,15 +245,15 @@
5.166 SCROLL_XSTEP, SOURCE_YSTEP, plot_screen_edge);
5.167
5.168 init_stored_regions(regions, display_config.frames, (uint8_t *) backgrounds,
5.169 - (sprite_width * sprite_height) / SOURCE_YSTEP);
5.170 + (sprite.width * sprite.height) / SOURCE_YSTEP);
5.171
5.172 /* Animation loop. */
5.173
5.174 while (1)
5.175 {
5.176 - for (y = 0; y < display_config.line_count - sprite_height; y++)
5.177 + for (y = 0; y < display_config.line_count - sprite.height; y++)
5.178 {
5.179 - for (x = 0; x < display_config.line_length - sprite_width; x++)
5.180 + for (x = 0; x < display_config.line_length - sprite.width; x++)
5.181 {
5.182 plot_sprite(®ions[display_config.frame], x, y, 0x8c);
5.183
5.184 @@ -371,11 +337,11 @@
5.185
5.186 /* Plot the image centred on the screen. */
5.187
5.188 - display_copy(&display_config, screendata,
5.189 - screendata_width, screendata_height,
5.190 + display_copy(&display_config, screendata.image,
5.191 + screendata.width, screendata.height,
5.192 SOURCE_YSTEP,
5.193 - (display_config.line_length - screendata_width) / 2,
5.194 - (display_config.line_count - (screendata_height / SOURCE_YSTEP)) / 2,
5.195 + (display_config.line_length - screendata.width) / 2,
5.196 + (display_config.line_count - (screendata.height / SOURCE_YSTEP)) / 2,
5.197 -1, 1);
5.198
5.199 /* Write a sequence of characters. */
9.1 --- a/tools/makeimage.py Sat Nov 10 17:02:18 2018 +0100
9.2 +++ b/tools/makeimage.py Sat Nov 10 17:03:17 2018 +0100
9.3 @@ -54,13 +54,14 @@
9.4 .globl %s_width
9.5 .globl %s_height
9.6
9.7 +%s:
9.8 %s_width:
9.9 .word %d
9.10 %s_height:
9.11 .word %d
9.12
9.13 -%s:
9.14 -""" % (options, label, label, label, label, width, label, height, label)
9.15 +%s_image:
9.16 +""" % (options, label, label, label, label, label, width, label, height, label)
9.17
9.18 word = []
9.19 y = 0
9.20 @@ -274,7 +275,7 @@
9.21 base_height = height = 256
9.22
9.23 input_filename, output_filename, label = sys.argv[1:4]
9.24 - options = sys.argv[4:]
9.25 + options = sys.argv[3:]
9.26
9.27 # Basic image properties.
9.28