1.1 --- a/lib/display.c Fri Nov 09 00:33:42 2018 +0100
1.2 +++ b/lib/display.c Fri Nov 09 01:08:41 2018 +0100
1.3 @@ -18,6 +18,7 @@
1.4 */
1.5
1.6 #include "display.h"
1.7 +#include "utils.h"
1.8
1.9
1.10
1.11 @@ -71,9 +72,27 @@
1.12 cfg->line_multiplier = cfg->scanlines / cfg->line_count;
1.13 }
1.14
1.15 +
1.16 +
1.17 +/* Select a frame in the framebuffer. */
1.18 +
1.19 +void display_select_frame(display_config_t *cfg, int frame, uint32_t offset)
1.20 +{
1.21 + if ((frame < 0) || (frame >= cfg->frames))
1.22 + return;
1.23 +
1.24 + /* Update the frame details. */
1.25 +
1.26 + cfg->frame = frame;
1.27 +
1.28 + /* Set the screen start offset when switching frames. */
1.29 +
1.30 + init_display_properties(cfg, offset);
1.31 +}
1.32 +
1.33 /* Set the number of frames in the framebuffer memory. */
1.34
1.35 -void set_frames(display_config_t *cfg, int frames)
1.36 +void display_set_frames(display_config_t *cfg, int frames)
1.37 {
1.38 if ((frames <= 0) || (frames > cfg->max_frames))
1.39 return;
1.40 @@ -94,32 +113,11 @@
1.41 init_display_properties(cfg, 0);
1.42 }
1.43
1.44 -/* Select a frame in the framebuffer. */
1.45
1.46 -void select_frame(display_config_t *cfg, int frame, uint32_t offset)
1.47 -{
1.48 - if ((frame < 0) || (frame >= cfg->frames))
1.49 - return;
1.50 -
1.51 - /* Update the frame details. */
1.52 -
1.53 - cfg->frame = frame;
1.54 -
1.55 - /* Set the screen start offset when switching frames. */
1.56 -
1.57 - init_display_properties(cfg, offset);
1.58 -}
1.59 -
1.60 -/* Return the screen start offset. */
1.61 -
1.62 -uint32_t get_start_offset(display_config_t *cfg)
1.63 -{
1.64 - return cfg->screen_start - cfg->frame_start;
1.65 -}
1.66
1.67 /* Return the line data position for the given pixel. */
1.68
1.69 -int get_position(display_config_t *cfg, int x)
1.70 +int display_get_position(display_config_t *cfg, int x)
1.71 {
1.72 int cell, offset, pos;
1.73
1.74 @@ -143,51 +141,36 @@
1.75 return cell % 2 ? pos + cfg->line_length / 2 : pos;
1.76 }
1.77
1.78 -/* Provide a pattern to test the line data. */
1.79 -
1.80 -void test_linedata(display_config_t *cfg)
1.81 -{
1.82 - int x, y;
1.83 - uint8_t *linedata = cfg->screen_start;
1.84 +/* Return the screen start offset. */
1.85
1.86 - for (y = 0; y < cfg->line_count; y++)
1.87 - {
1.88 - for (x = 0; x < cfg->line_length; x++)
1.89 - {
1.90 - /* Pixel: I0RRGGBB = Y0YYYYXX */
1.91 +uint32_t display_get_start_offset(display_config_t *cfg)
1.92 +{
1.93 + return cfg->screen_start - cfg->frame_start;
1.94 +}
1.95
1.96 - linedata[get_position(cfg, x)] = (x % 2) ?
1.97 - (((y / (cfg->line_count / 32)) & 0b1) << 7) |
1.98 - (((y / (cfg->line_count / 16)) & 0b1111) << 2) |
1.99 - ((x / (cfg->line_length / 4)) & 0b11) :
1.100 - 0x00;
1.101 - }
1.102
1.103 - linedata = wrap_screen_pointer(cfg, linedata + cfg->line_length);
1.104 - }
1.105 -}
1.106
1.107 /* Copying from/to the display to/from a backing store. */
1.108
1.109 -void copy_display(display_config_t *cfg, uint8_t *store,
1.110 +void display_copy(display_config_t *cfg, uint8_t *store,
1.111 int width, int height, int ystep,
1.112 int x, int y, int key, int to_display)
1.113 {
1.114 - copy_display_section(cfg, store, width, height,
1.115 + display_copy_section(cfg, store, width, height,
1.116 0, 0, width, height, ystep,
1.117 x, y, key, to_display);
1.118 }
1.119
1.120 /* Copying from/to the display to/from a backing store region. */
1.121
1.122 -void copy_display_section(display_config_t *cfg, uint8_t *store,
1.123 +void display_copy_section(display_config_t *cfg, uint8_t *store,
1.124 int width, int height,
1.125 int xstart, int ystart, int xsize, int ysize, int ystep,
1.126 int x, int y, int key, int to_display)
1.127 {
1.128 int sx, sy, dx, dy;
1.129 uint8_t *storeline = store + ystart * width,
1.130 - *displayline = wrap_screen_pointer(cfg, cfg->screen_start + y * cfg->line_length),
1.131 + *displayline = display_wrap_pointer(cfg, cfg->screen_start + y * cfg->line_length),
1.132 pixel;
1.133
1.134 /* Define the limits of the copying in the store. */
1.135 @@ -210,45 +193,55 @@
1.136 {
1.137 pixel = storeline[sx];
1.138 if ((key < 0) || (pixel != key))
1.139 - displayline[get_position(cfg, dx)] = pixel;
1.140 + displayline[display_get_position(cfg, dx)] = pixel;
1.141 }
1.142 else
1.143 - storeline[sx] = displayline[get_position(cfg, dx)];
1.144 + storeline[sx] = displayline[display_get_position(cfg, dx)];
1.145 }
1.146
1.147 storeline += width * ystep;
1.148 - displayline = wrap_screen_pointer(cfg, displayline + cfg->line_length);
1.149 + displayline = display_wrap_pointer(cfg, displayline + cfg->line_length);
1.150 }
1.151 }
1.152
1.153 /* Scroll the display. */
1.154
1.155 -void scroll_display(display_config_t *cfg, int x, int y)
1.156 +void display_scroll(display_config_t *cfg, int x, int y)
1.157 {
1.158 /* Move the screen start by the given number of bytes and lines, wrapping
1.159 around the start and end of the framebuffer. */
1.160
1.161 - cfg->screen_start = wrap_screen_pointer(cfg, cfg->screen_start + x +
1.162 - y * cfg->line_length);
1.163 + cfg->screen_start = display_wrap_pointer(cfg, cfg->screen_start + x +
1.164 + y * cfg->line_length);
1.165 }
1.166
1.167 -/* Wrap a pointer within the given limits. */
1.168 +/* Provide a pattern to test the line data. */
1.169
1.170 -uint8_t *wrap_pointer(uint8_t *ptr, uint8_t *lower, uint8_t *upper)
1.171 +void display_test_linedata(display_config_t *cfg)
1.172 {
1.173 - uint32_t size = upper - lower;
1.174 + int x, y;
1.175 + uint8_t *linedata = cfg->screen_start;
1.176
1.177 - if (ptr < lower)
1.178 - return upper - (lower - ptr) % size;
1.179 - else if (ptr >= upper)
1.180 - return lower + (ptr - upper) % size;
1.181 - else
1.182 - return ptr;
1.183 + for (y = 0; y < cfg->line_count; y++)
1.184 + {
1.185 + for (x = 0; x < cfg->line_length; x++)
1.186 + {
1.187 + /* Pixel: I0RRGGBB = Y0YYYYXX */
1.188 +
1.189 + linedata[display_get_position(cfg, x)] = (x % 2) ?
1.190 + (((y / (cfg->line_count / 32)) & 0b1) << 7) |
1.191 + (((y / (cfg->line_count / 16)) & 0b1111) << 2) |
1.192 + ((x / (cfg->line_length / 4)) & 0b11) :
1.193 + 0x00;
1.194 + }
1.195 +
1.196 + linedata = display_wrap_pointer(cfg, linedata + cfg->line_length);
1.197 + }
1.198 }
1.199
1.200 /* Wrap the screen pointer to the current frame. */
1.201
1.202 -uint8_t *wrap_screen_pointer(display_config_t *cfg, uint8_t *ptr)
1.203 +uint8_t *display_wrap_pointer(display_config_t *cfg, uint8_t *ptr)
1.204 {
1.205 return wrap_pointer(ptr, cfg->frame_start, cfg->screen_limit);
1.206 }