# HG changeset patch # User Paul Boddie # Date 1541096933 -3600 # Node ID b1c95dc9c07a56ff6750313a8c56d775d5c35fbd # Parent d3de41d851b917e4c96b12f7307bb9976f4d33ad Introduced tracking of the vertical origin so that the background is repainted properly, scrolling onto the screen horizontally at the appropriate level. diff -r d3de41d851b9 -r b1c95dc9c07a examples/vga/main.c --- a/examples/vga/main.c Wed Oct 31 18:02:07 2018 +0100 +++ b/examples/vga/main.c Thu Nov 01 19:28:53 2018 +0100 @@ -114,7 +114,7 @@ uint8_t background[sprite_width * sprite_height]; int x, y; int dir[] = {1, 0, -1, 0, 1}, i = 0, width, column_width; - int xsource, xdisplay, xorigin = 0; + int xsource, xdisplay, xorigin = 0, yorigin = 0; while (1) { @@ -144,6 +144,18 @@ scroll_display(&display_config, dir[i], dir[i + 1]); + /* Update the vertical origin if appropriate. */ + + if (dir[i + 1]) + { + yorigin += dir[i + 1]; + + if (yorigin < 0) + yorigin += screendata_height; + else if (yorigin >= screendata_height) + yorigin -= screendata_height; + } + /* For horizontal scrolling, plot the exposed column at the left (if scrolling left) or at the right (if scrolling right). */ @@ -164,14 +176,39 @@ /* Determine the location of the column to be plotted. */ xorigin += width; + + if (xorigin < 0) + xorigin += screendata_width; + else if (xorigin >= screendata_width) + xorigin -= screendata_width; + xsource = (xdisplay + xorigin) % screendata_width; + /* Plot a column in two pieces if the vertical origin is + non-zero. The first piece is at (xdisplay, 0) and + provides the lower part of the background image displaced + upwards (or downwards having wrapped around) on the + screen. */ + copy_display_section(&display_config, screendata, screendata_width, screendata_height, - xsource, 0, - column_width, screendata_height, + xsource, yorigin, + column_width, screendata_height - yorigin, xdisplay, 0, -1, 1); + + /* The second column is at (xdisplay, h - yorigin) and + provides the upper part of the background image displaced + downwards (or upwards having wrapped around) on the + screen. */ + + if (yorigin) + copy_display_section(&display_config, screendata, + screendata_width, screendata_height, + xsource, 0, + column_width, yorigin, + xdisplay, screendata_height - yorigin, + -1, 1); } }