1.1 --- a/lib/display.c Tue Oct 30 23:59:47 2018 +0100
1.2 +++ b/lib/display.c Wed Oct 31 18:02:07 2018 +0100
1.3 @@ -36,7 +36,7 @@
1.4 void test_linedata(display_config_t *cfg)
1.5 {
1.6 int x, y;
1.7 - uint8_t *linedata = cfg->framebuffer;
1.8 + uint8_t *linedata = cfg->screen_start;
1.9
1.10 for (y = 0; y < cfg->line_count; y++)
1.11 {
1.12 @@ -52,6 +52,9 @@
1.13 }
1.14
1.15 linedata += cfg->line_length;
1.16 +
1.17 + if (linedata >= cfg->screen_limit)
1.18 + linedata -= cfg->screen_size;
1.19 }
1.20 }
1.21
1.22 @@ -60,14 +63,40 @@
1.23 void copy_display(display_config_t *cfg, uint8_t *store, int width, int height,
1.24 int x, int y, int key, int to_display)
1.25 {
1.26 + copy_display_section(cfg, store, width, height, 0, 0, width, height, x, y,
1.27 + key, to_display);
1.28 +}
1.29 +
1.30 +/* Copying from/to the display to/from a backing store region. */
1.31 +
1.32 +void copy_display_section(display_config_t *cfg, uint8_t *store,
1.33 + int width, int height,
1.34 + int xstart, int ystart, int xsize, int ysize,
1.35 + int x, int y, int key, int to_display)
1.36 +{
1.37 int sx, sy, dx, dy;
1.38 - uint8_t *storeline = store,
1.39 - *displayline = cfg->framebuffer + y * cfg->line_length,
1.40 + uint8_t *storeline = store + ystart * width,
1.41 + *displayline = cfg->screen_start + y * cfg->line_length,
1.42 pixel;
1.43
1.44 - for (sy = 0, dy = y; (sy < height) && (dy < cfg->line_count); sy++, dy++)
1.45 + /* Define the limits of the copying in the store. */
1.46 +
1.47 + int xlimit = xstart + xsize, ylimit = ystart + ysize;
1.48 +
1.49 + if (xlimit > width)
1.50 + xlimit = width;
1.51 +
1.52 + if (ylimit > height)
1.53 + ylimit = height;
1.54 +
1.55 + /* Perform the copying between the store and display. */
1.56 +
1.57 + for (sy = ystart, dy = y; (sy < ylimit) && (dy < cfg->line_count); sy++, dy++)
1.58 {
1.59 - for (sx = 0, dx = x; (sx < width) && (dx < cfg->line_length); sx++, dx++)
1.60 + if (displayline >= cfg->screen_limit)
1.61 + displayline -= cfg->screen_size;
1.62 +
1.63 + for (sx = xstart, dx = x; (sx < xlimit) && (dx < cfg->line_length); sx++, dx++)
1.64 {
1.65 if (to_display)
1.66 {
1.67 @@ -83,3 +112,26 @@
1.68 displayline += cfg->line_length;
1.69 }
1.70 }
1.71 +
1.72 +/* Scroll the display. */
1.73 +
1.74 +void scroll_display(display_config_t *cfg, int x, int y)
1.75 +{
1.76 + uint8_t *start;
1.77 +
1.78 + /* Move the screen start by the given number of bytes and lines. */
1.79 +
1.80 + start = cfg->screen_start + x + y * cfg->line_length;
1.81 +
1.82 + /* Wrap around the start of the framebuffer to the end. */
1.83 +
1.84 + if (start < cfg->framebuffer)
1.85 + start = cfg->screen_limit - (cfg->screen_limit - start) % cfg->screen_size;
1.86 +
1.87 + /* Wrap around the end of the framebuffer to the start. */
1.88 +
1.89 + else if (start >= cfg->screen_limit)
1.90 + start = cfg->framebuffer + (start - cfg->framebuffer) % cfg->screen_size;
1.91 +
1.92 + cfg->screen_start = start;
1.93 +}