1.1 --- a/examples/vga/main.c Sat Nov 10 17:02:18 2018 +0100
1.2 +++ b/examples/vga/main.c Sat Nov 10 17:03:17 2018 +0100
1.3 @@ -21,6 +21,7 @@
1.4 #include "debug.h"
1.5 #include "display.h"
1.6 #include "font.h"
1.7 +#include "image.h"
1.8 #include "init.h"
1.9 #include "pic32_c.h"
1.10 #include "utils.h"
1.11 @@ -102,10 +103,8 @@
1.12
1.13 /* Bundled image and font data. */
1.14
1.15 -extern uint8_t screendata[];
1.16 -extern uint32_t screendata_width, screendata_height;
1.17 -extern uint8_t sprite[];
1.18 -extern uint32_t sprite_width, sprite_height;
1.19 +extern image_t screendata;
1.20 +extern image_t sprite;
1.21
1.22 extern uint8_t fontchars[];
1.23 extern uint32_t fonttable[];
1.24 @@ -115,48 +114,15 @@
1.25
1.26
1.27
1.28 -/* Stored display regions. */
1.29 -
1.30 -typedef struct
1.31 -{
1.32 - /* Stored region overplotted by the sprite. */
1.33 -
1.34 - uint8_t *image;
1.35 - int stored;
1.36 -
1.37 - /* Position of the stored region. */
1.38 -
1.39 - int x, y;
1.40 -
1.41 -} stored_region_t;
1.42 -
1.43 -/* Initialise the stored regions. */
1.44 -
1.45 -void init_stored_regions(stored_region_t *r, int frames,
1.46 - uint8_t *regions, uint32_t region_size)
1.47 -{
1.48 - int frame;
1.49 -
1.50 - for (frame = 0; frame < frames; frame++)
1.51 - {
1.52 - r->stored = 0;
1.53 - r->image = regions;
1.54 - regions += region_size;
1.55 - r++;
1.56 - }
1.57 -}
1.58 -
1.59 -
1.60 -
1.61 /* Copy to the store from the display, then blit the image. */
1.62
1.63 static void plot_sprite(stored_region_t *r, int x, int y, int key)
1.64 {
1.65 display_copy(&display_config, r->image,
1.66 - sprite_width, sprite_height / SOURCE_YSTEP, 1,
1.67 + sprite.width, sprite.height / SOURCE_YSTEP, 1,
1.68 x, y, -1, 0);
1.69 - display_copy(&display_config, sprite,
1.70 - sprite_width, sprite_height, SOURCE_YSTEP,
1.71 + display_copy(&display_config, sprite.image,
1.72 + sprite.width, sprite.height, SOURCE_YSTEP,
1.73 x, y, key, 1);
1.74
1.75 /* Record the stored background. */
1.76 @@ -172,7 +138,7 @@
1.77 {
1.78 if (r->stored)
1.79 display_copy(&display_config, r->image,
1.80 - sprite_width, sprite_height / SOURCE_YSTEP, 1,
1.81 + sprite.width, sprite.height / SOURCE_YSTEP, 1,
1.82 r->x, r->y, -1, 1);
1.83 }
1.84
1.85 @@ -183,16 +149,16 @@
1.86 {
1.87 /* Determine positions within the image. */
1.88
1.89 - int xpos = wrap_value(xorigin, screendata_width);
1.90 - int ypos = wrap_value(yorigin, screendata_height);
1.91 + int xpos = wrap_value(xorigin, screendata.width);
1.92 + int ypos = wrap_value(yorigin, screendata.height);
1.93
1.94 /* The display region is either the left or right edge. */
1.95
1.96 - int xdisplay = xstep < 0 ? 0 : screendata_width - xstep;
1.97 + int xdisplay = xstep < 0 ? 0 : screendata.width - xstep;
1.98
1.99 /* The source region depends on the origin within the background image. */
1.100
1.101 - int xsource = wrap_value(xdisplay + xpos, screendata_width);
1.102 + int xsource = wrap_value(xdisplay + xpos, screendata.width);
1.103
1.104 /* The column width is the absolute increment. */
1.105
1.106 @@ -201,7 +167,7 @@
1.107 /* Not all of the column may be available if close to the edge of the
1.108 image, requiring multiple slices. */
1.109
1.110 - int available = screendata_width - xsource;
1.111 + int available = screendata.width - xsource;
1.112
1.113 while (width)
1.114 {
1.115 @@ -211,10 +177,10 @@
1.116 upwards (or downwards having wrapped around) on the
1.117 screen. */
1.118
1.119 - display_copy_section(&display_config, screendata,
1.120 - screendata_width, screendata_height,
1.121 + display_copy_section(&display_config, screendata.image,
1.122 + screendata.width, screendata.height,
1.123 xsource, ypos,
1.124 - width, screendata_height - ypos,
1.125 + width, screendata.height - ypos,
1.126 v->yscale,
1.127 xdisplay, 0,
1.128 -1, 1);
1.129 @@ -225,12 +191,12 @@
1.130 screen. */
1.131
1.132 if (ypos)
1.133 - display_copy_section(&display_config, screendata,
1.134 - screendata_width, screendata_height,
1.135 + display_copy_section(&display_config, screendata.image,
1.136 + screendata.width, screendata.height,
1.137 xsource, 0,
1.138 width, ypos,
1.139 v->yscale,
1.140 - xdisplay, (screendata_height - ypos) / v->yscale,
1.141 + xdisplay, (screendata.height - ypos) / v->yscale,
1.142 -1, 1);
1.143
1.144 /* Get the next slice of the column. */
1.145 @@ -239,8 +205,8 @@
1.146 {
1.147 width -= available;
1.148 xsource = 0;
1.149 - xdisplay = wrap_value(xdisplay + available, screendata_width);
1.150 - available = screendata_width;
1.151 + xdisplay = wrap_value(xdisplay + available, screendata.width);
1.152 + available = screendata.width;
1.153 }
1.154 else
1.155 width = 0;
1.156 @@ -253,7 +219,7 @@
1.157 {
1.158 /* Stores of background details, replotted when moving the sprite. */
1.159
1.160 - uint8_t backgrounds[FRAME_COUNT][(sprite_width * sprite_height) / SOURCE_YSTEP];
1.161 + uint8_t backgrounds[FRAME_COUNT][(sprite.width * sprite.height) / SOURCE_YSTEP];
1.162 stored_region_t regions[FRAME_COUNT];
1.163
1.164 /* Sprite position. */
1.165 @@ -279,15 +245,15 @@
1.166 SCROLL_XSTEP, SOURCE_YSTEP, plot_screen_edge);
1.167
1.168 init_stored_regions(regions, display_config.frames, (uint8_t *) backgrounds,
1.169 - (sprite_width * sprite_height) / SOURCE_YSTEP);
1.170 + (sprite.width * sprite.height) / SOURCE_YSTEP);
1.171
1.172 /* Animation loop. */
1.173
1.174 while (1)
1.175 {
1.176 - for (y = 0; y < display_config.line_count - sprite_height; y++)
1.177 + for (y = 0; y < display_config.line_count - sprite.height; y++)
1.178 {
1.179 - for (x = 0; x < display_config.line_length - sprite_width; x++)
1.180 + for (x = 0; x < display_config.line_length - sprite.width; x++)
1.181 {
1.182 plot_sprite(®ions[display_config.frame], x, y, 0x8c);
1.183
1.184 @@ -371,11 +337,11 @@
1.185
1.186 /* Plot the image centred on the screen. */
1.187
1.188 - display_copy(&display_config, screendata,
1.189 - screendata_width, screendata_height,
1.190 + display_copy(&display_config, screendata.image,
1.191 + screendata.width, screendata.height,
1.192 SOURCE_YSTEP,
1.193 - (display_config.line_length - screendata_width) / 2,
1.194 - (display_config.line_count - (screendata_height / SOURCE_YSTEP)) / 2,
1.195 + (display_config.line_length - screendata.width) / 2,
1.196 + (display_config.line_count - (screendata.height / SOURCE_YSTEP)) / 2,
1.197 -1, 1);
1.198
1.199 /* Write a sequence of characters. */