# HG changeset patch # User Paul Boddie # Date 1541971420 -3600 # Node ID c8bb3228030dcbe7455dc88e5b8de57da359f500 # Parent 14bc79b7e4dc9af5c34459412116a0340bd9302c Moved the function for updating a tiled image background to the image module. diff -r 14bc79b7e4dc -r c8bb3228030d examples/vga/main.c --- a/examples/vga/main.c Sun Nov 11 18:15:24 2018 +0100 +++ b/examples/vga/main.c Sun Nov 11 22:23:40 2018 +0100 @@ -107,57 +107,7 @@ static void plot_screen_edge(int xorigin, int yorigin, int xstep, int ystep) { - /* The display regions are either the left or right edge... */ - - int xedge = xstep < 0 ? 0 : display_config.line_length - xstep; - int xdisplay = xedge; - - /* and either the top or bottom edge... */ - - int yedge = ystep < 0 ? 0 : display_config.line_count * scr.yscale - ystep; - int ydisplay = yedge / scr.yscale; - - /* Determine the origin position within the image. */ - - int xpos = wrap_value(xorigin, scr.image->width); - int ypos = wrap_value(yorigin, scr.image->height); - int xsource, ysource; - - /* Horizontal scrolling requires columns spanning the height of the screen - at the appropriate edge (left or right). */ - - /* The column width is the absolute increment. */ - - if (xstep) - { - /* Find the source position for the appropriate edge. */ - - xsource = wrap_value(xpos + xedge, scr.image->width); - ysource = ypos; - - /* Request tiling in the source coordinates. */ - - image_tile_sprite(&scr, xsource, ysource, - abs(xstep), display_config.line_count * scr.yscale, - xdisplay, 0); - } - - /* Vertical scrolling requires columns across the width of the screen at the - appropriate edge (top or bottom). */ - - if (ystep) - { - /* Find the source position for the appropriate edge. */ - - xsource = xpos; - ysource = wrap_value(ypos + yedge, scr.image->height); - - /* Request tiling in the source coordinates. */ - - image_tile_sprite(&scr, xsource, ysource, - display_config.line_length, abs(ystep), - 0, ydisplay); - } + image_update_scrolled_tiled_image(&scr, xorigin, yorigin, xstep, ystep); } diff -r 14bc79b7e4dc -r c8bb3228030d include/image.h --- a/include/image.h Sun Nov 11 18:15:24 2018 +0100 +++ b/include/image.h Sun Nov 11 22:23:40 2018 +0100 @@ -160,4 +160,7 @@ int width, int height, int xdisplay, int ydisplay); +void image_update_scrolled_tiled_image(sprite_t *s, int xorigin, int yorigin, + int xstep, int ystep); + #endif /* __IMAGE_H__ */ diff -r 14bc79b7e4dc -r c8bb3228030d lib/image.c --- a/lib/image.c Sun Nov 11 18:15:24 2018 +0100 +++ b/lib/image.c Sun Nov 11 22:23:40 2018 +0100 @@ -175,3 +175,61 @@ source_width = s->image->width; } } + +/* Plot a scrolling tiled image upon a viewport update. */ + +void image_update_scrolled_tiled_image(sprite_t *s, int xorigin, int yorigin, + int xstep, int ystep) +{ + /* The display regions are either the left or right edge... */ + + int xedge = xstep < 0 ? 0 : s->cfg->line_length - xstep; + int xdisplay = xedge; + + /* and either the top or bottom edge... */ + + int yedge = ystep < 0 ? 0 : s->cfg->line_count * s->yscale - ystep; + int ydisplay = yedge / s->yscale; + + /* Determine the origin position within the image. */ + + int xpos = wrap_value(xorigin, s->image->width); + int ypos = wrap_value(yorigin, s->image->height); + int xsource, ysource; + + /* Horizontal scrolling requires columns spanning the height of the screen + at the appropriate edge (left or right). */ + + /* The column width is the absolute increment. */ + + if (xstep) + { + /* Find the source position for the appropriate edge. */ + + xsource = wrap_value(xpos + xedge, s->image->width); + ysource = ypos; + + /* Request tiling in the source coordinates. */ + + image_tile_sprite(s, xsource, ysource, + abs(xstep), s->cfg->line_count * s->yscale, + xdisplay, 0); + } + + /* Vertical scrolling requires columns across the width of the screen at the + appropriate edge (top or bottom). */ + + if (ystep) + { + /* Find the source position for the appropriate edge. */ + + xsource = xpos; + ysource = wrap_value(ypos + yedge, s->image->height); + + /* Request tiling in the source coordinates. */ + + image_tile_sprite(s, xsource, ysource, + s->cfg->line_length, abs(ystep), + 0, ydisplay); + } +}