1.1 --- a/lib/display.c Sun Nov 04 15:46:13 2018 +0100
1.2 +++ b/lib/display.c Sun Nov 04 16:14:58 2018 +0100
1.3 @@ -147,10 +147,7 @@
1.4 0x00;
1.5 }
1.6
1.7 - linedata += cfg->line_length;
1.8 -
1.9 - if (linedata >= cfg->screen_limit)
1.10 - linedata -= cfg->screen_size;
1.11 + linedata = wrap_screen_pointer(cfg, linedata + cfg->line_length);
1.12 }
1.13 }
1.14
1.15 @@ -172,7 +169,7 @@
1.16 {
1.17 int sx, sy, dx, dy;
1.18 uint8_t *storeline = store + ystart * width,
1.19 - *displayline = cfg->screen_start + y * cfg->line_length,
1.20 + *displayline = wrap_screen_pointer(cfg, cfg->screen_start + y * cfg->line_length),
1.21 pixel;
1.22
1.23 /* Define the limits of the copying in the store. */
1.24 @@ -189,9 +186,6 @@
1.25
1.26 for (sy = ystart, dy = y; (sy < ylimit) && (dy < cfg->line_count); sy++, dy++)
1.27 {
1.28 - if (displayline >= cfg->screen_limit)
1.29 - displayline -= cfg->screen_size;
1.30 -
1.31 for (sx = xstart, dx = x; (sx < xlimit) && (dx < cfg->line_length); sx++, dx++)
1.32 {
1.33 if (to_display)
1.34 @@ -205,7 +199,7 @@
1.35 }
1.36
1.37 storeline += width;
1.38 - displayline += cfg->line_length;
1.39 + displayline = wrap_screen_pointer(cfg, displayline + cfg->line_length);
1.40 }
1.41 }
1.42
1.43 @@ -213,21 +207,30 @@
1.44
1.45 void scroll_display(display_config_t *cfg, int x, int y)
1.46 {
1.47 - uint8_t *start;
1.48 -
1.49 - /* Move the screen start by the given number of bytes and lines. */
1.50 + /* Move the screen start by the given number of bytes and lines, wrapping
1.51 + around the start and end of the framebuffer. */
1.52
1.53 - start = cfg->screen_start + x + y * cfg->line_length;
1.54 + cfg->screen_start = wrap_screen_pointer(cfg, cfg->screen_start + x +
1.55 + y * cfg->line_length);
1.56 +}
1.57
1.58 - /* Wrap around the start of the framebuffer to the end. */
1.59 +/* Wrap a pointer within the given limits. */
1.60 +
1.61 +uint8_t *wrap_pointer(uint8_t *ptr, uint8_t *lower, uint8_t *upper)
1.62 +{
1.63 + uint32_t size = upper - lower;
1.64
1.65 - if (start < cfg->frame_start)
1.66 - start = cfg->screen_limit - (cfg->frame_start - start) % cfg->screen_size;
1.67 -
1.68 - /* Wrap around the end of the framebuffer to the start. */
1.69 + if (ptr < lower)
1.70 + return upper - (lower - ptr) % size;
1.71 + else if (ptr >= upper)
1.72 + return lower + (ptr - upper) % size;
1.73 + else
1.74 + return ptr;
1.75 +}
1.76
1.77 - else if (start >= cfg->screen_limit)
1.78 - start = cfg->frame_start + (start - cfg->screen_limit) % cfg->screen_size;
1.79 +/* Wrap the screen pointer to the current frame. */
1.80
1.81 - cfg->screen_start = start;
1.82 +uint8_t *wrap_screen_pointer(display_config_t *cfg, uint8_t *ptr)
1.83 +{
1.84 + return wrap_pointer(ptr, cfg->frame_start, cfg->screen_limit);
1.85 }