1.1 --- a/examples/vga/main.c Sun Nov 11 18:15:24 2018 +0100
1.2 +++ b/examples/vga/main.c Sun Nov 11 22:23:40 2018 +0100
1.3 @@ -107,57 +107,7 @@
1.4
1.5 static void plot_screen_edge(int xorigin, int yorigin, int xstep, int ystep)
1.6 {
1.7 - /* The display regions are either the left or right edge... */
1.8 -
1.9 - int xedge = xstep < 0 ? 0 : display_config.line_length - xstep;
1.10 - int xdisplay = xedge;
1.11 -
1.12 - /* and either the top or bottom edge... */
1.13 -
1.14 - int yedge = ystep < 0 ? 0 : display_config.line_count * scr.yscale - ystep;
1.15 - int ydisplay = yedge / scr.yscale;
1.16 -
1.17 - /* Determine the origin position within the image. */
1.18 -
1.19 - int xpos = wrap_value(xorigin, scr.image->width);
1.20 - int ypos = wrap_value(yorigin, scr.image->height);
1.21 - int xsource, ysource;
1.22 -
1.23 - /* Horizontal scrolling requires columns spanning the height of the screen
1.24 - at the appropriate edge (left or right). */
1.25 -
1.26 - /* The column width is the absolute increment. */
1.27 -
1.28 - if (xstep)
1.29 - {
1.30 - /* Find the source position for the appropriate edge. */
1.31 -
1.32 - xsource = wrap_value(xpos + xedge, scr.image->width);
1.33 - ysource = ypos;
1.34 -
1.35 - /* Request tiling in the source coordinates. */
1.36 -
1.37 - image_tile_sprite(&scr, xsource, ysource,
1.38 - abs(xstep), display_config.line_count * scr.yscale,
1.39 - xdisplay, 0);
1.40 - }
1.41 -
1.42 - /* Vertical scrolling requires columns across the width of the screen at the
1.43 - appropriate edge (top or bottom). */
1.44 -
1.45 - if (ystep)
1.46 - {
1.47 - /* Find the source position for the appropriate edge. */
1.48 -
1.49 - xsource = xpos;
1.50 - ysource = wrap_value(ypos + yedge, scr.image->height);
1.51 -
1.52 - /* Request tiling in the source coordinates. */
1.53 -
1.54 - image_tile_sprite(&scr, xsource, ysource,
1.55 - display_config.line_length, abs(ystep),
1.56 - 0, ydisplay);
1.57 - }
1.58 + image_update_scrolled_tiled_image(&scr, xorigin, yorigin, xstep, ystep);
1.59 }
1.60
1.61
2.1 --- a/include/image.h Sun Nov 11 18:15:24 2018 +0100
2.2 +++ b/include/image.h Sun Nov 11 22:23:40 2018 +0100
2.3 @@ -160,4 +160,7 @@
2.4 int width, int height,
2.5 int xdisplay, int ydisplay);
2.6
2.7 +void image_update_scrolled_tiled_image(sprite_t *s, int xorigin, int yorigin,
2.8 + int xstep, int ystep);
2.9 +
2.10 #endif /* __IMAGE_H__ */
3.1 --- a/lib/image.c Sun Nov 11 18:15:24 2018 +0100
3.2 +++ b/lib/image.c Sun Nov 11 22:23:40 2018 +0100
3.3 @@ -175,3 +175,61 @@
3.4 source_width = s->image->width;
3.5 }
3.6 }
3.7 +
3.8 +/* Plot a scrolling tiled image upon a viewport update. */
3.9 +
3.10 +void image_update_scrolled_tiled_image(sprite_t *s, int xorigin, int yorigin,
3.11 + int xstep, int ystep)
3.12 +{
3.13 + /* The display regions are either the left or right edge... */
3.14 +
3.15 + int xedge = xstep < 0 ? 0 : s->cfg->line_length - xstep;
3.16 + int xdisplay = xedge;
3.17 +
3.18 + /* and either the top or bottom edge... */
3.19 +
3.20 + int yedge = ystep < 0 ? 0 : s->cfg->line_count * s->yscale - ystep;
3.21 + int ydisplay = yedge / s->yscale;
3.22 +
3.23 + /* Determine the origin position within the image. */
3.24 +
3.25 + int xpos = wrap_value(xorigin, s->image->width);
3.26 + int ypos = wrap_value(yorigin, s->image->height);
3.27 + int xsource, ysource;
3.28 +
3.29 + /* Horizontal scrolling requires columns spanning the height of the screen
3.30 + at the appropriate edge (left or right). */
3.31 +
3.32 + /* The column width is the absolute increment. */
3.33 +
3.34 + if (xstep)
3.35 + {
3.36 + /* Find the source position for the appropriate edge. */
3.37 +
3.38 + xsource = wrap_value(xpos + xedge, s->image->width);
3.39 + ysource = ypos;
3.40 +
3.41 + /* Request tiling in the source coordinates. */
3.42 +
3.43 + image_tile_sprite(s, xsource, ysource,
3.44 + abs(xstep), s->cfg->line_count * s->yscale,
3.45 + xdisplay, 0);
3.46 + }
3.47 +
3.48 + /* Vertical scrolling requires columns across the width of the screen at the
3.49 + appropriate edge (top or bottom). */
3.50 +
3.51 + if (ystep)
3.52 + {
3.53 + /* Find the source position for the appropriate edge. */
3.54 +
3.55 + xsource = xpos;
3.56 + ysource = wrap_value(ypos + yedge, s->image->height);
3.57 +
3.58 + /* Request tiling in the source coordinates. */
3.59 +
3.60 + image_tile_sprite(s, xsource, ysource,
3.61 + s->cfg->line_length, abs(ystep),
3.62 + 0, ydisplay);
3.63 + }
3.64 +}