CommonPIC32

Changeset

84:b1c95dc9c07a
2018-11-01 Paul Boddie raw files shortlog changelog graph Introduced tracking of the vertical origin so that the background is repainted properly, scrolling onto the screen horizontally at the appropriate level.
examples/vga/main.c (file)
     1.1 --- a/examples/vga/main.c	Wed Oct 31 18:02:07 2018 +0100
     1.2 +++ b/examples/vga/main.c	Thu Nov 01 19:28:53 2018 +0100
     1.3 @@ -114,7 +114,7 @@
     1.4      uint8_t background[sprite_width * sprite_height];
     1.5      int x, y;
     1.6      int dir[] = {1, 0, -1, 0, 1}, i = 0, width, column_width;
     1.7 -    int xsource, xdisplay, xorigin = 0;
     1.8 +    int xsource, xdisplay, xorigin = 0, yorigin = 0;
     1.9  
    1.10      while (1)
    1.11      {
    1.12 @@ -144,6 +144,18 @@
    1.13  
    1.14                  scroll_display(&display_config, dir[i], dir[i + 1]);
    1.15  
    1.16 +                /* Update the vertical origin if appropriate. */
    1.17 +
    1.18 +                if (dir[i + 1])
    1.19 +                {
    1.20 +                    yorigin += dir[i + 1];
    1.21 +
    1.22 +                    if (yorigin < 0)
    1.23 +                        yorigin += screendata_height;
    1.24 +                    else if (yorigin >= screendata_height)
    1.25 +                        yorigin -= screendata_height;
    1.26 +                }
    1.27 +
    1.28                  /* For horizontal scrolling, plot the exposed column at the left
    1.29                     (if scrolling left) or at the right (if scrolling right). */
    1.30  
    1.31 @@ -164,14 +176,39 @@
    1.32                      /* Determine the location of the column to be plotted. */
    1.33  
    1.34                      xorigin += width;
    1.35 +
    1.36 +                    if (xorigin < 0)
    1.37 +                        xorigin += screendata_width;
    1.38 +                    else if (xorigin >= screendata_width)
    1.39 +                        xorigin -= screendata_width;
    1.40 +
    1.41                      xsource = (xdisplay + xorigin) % screendata_width;
    1.42  
    1.43 +                    /* Plot a column in two pieces if the vertical origin is
    1.44 +                       non-zero. The first piece is at (xdisplay, 0) and
    1.45 +                       provides the lower part of the background image displaced
    1.46 +                       upwards (or downwards having wrapped around) on the
    1.47 +                       screen. */
    1.48 +
    1.49                      copy_display_section(&display_config, screendata,
    1.50                                           screendata_width, screendata_height,
    1.51 -                                         xsource, 0,
    1.52 -                                         column_width, screendata_height,
    1.53 +                                         xsource, yorigin,
    1.54 +                                         column_width, screendata_height - yorigin,
    1.55                                           xdisplay, 0,
    1.56                                           -1, 1);
    1.57 +
    1.58 +                    /* The second column is at (xdisplay, h - yorigin) and
    1.59 +                       provides the upper part of the background image displaced
    1.60 +                       downwards (or upwards having wrapped around) on the
    1.61 +                       screen. */
    1.62 +
    1.63 +                    if (yorigin)
    1.64 +                        copy_display_section(&display_config, screendata,
    1.65 +                                             screendata_width, screendata_height,
    1.66 +                                             xsource, 0,
    1.67 +                                             column_width, yorigin,
    1.68 +                                             xdisplay, screendata_height - yorigin,
    1.69 +                                             -1, 1);
    1.70                  }
    1.71              }
    1.72