1.1 --- a/examples/vga/main.c Fri Nov 09 00:33:42 2018 +0100
1.2 +++ b/examples/vga/main.c Fri Nov 09 01:08:41 2018 +0100
1.3 @@ -110,10 +110,10 @@
1.4
1.5 static void plot_sprite(uint8_t *background, int x, int y)
1.6 {
1.7 - copy_display(&display_config, background,
1.8 + display_copy(&display_config, background,
1.9 sprite_width, sprite_height / SOURCE_YSTEP, 1,
1.10 x, y, -1, 0);
1.11 - copy_display(&display_config, sprite,
1.12 + display_copy(&display_config, sprite,
1.13 sprite_width, sprite_height, SOURCE_YSTEP,
1.14 x, y, 0x8c, 1);
1.15 }
1.16 @@ -122,7 +122,7 @@
1.17
1.18 static void unplot_sprite(uint8_t *background, int x, int y)
1.19 {
1.20 - copy_display(&display_config, background,
1.21 + display_copy(&display_config, background,
1.22 sprite_width, sprite_height / SOURCE_YSTEP, 1,
1.23 x, y, -1, 1);
1.24 }
1.25 @@ -161,7 +161,7 @@
1.26 upwards (or downwards having wrapped around) on the
1.27 screen. */
1.28
1.29 - copy_display_section(&display_config, screendata,
1.30 + display_copy_section(&display_config, screendata,
1.31 screendata_width, screendata_height,
1.32 xsource, ypos,
1.33 width, screendata_height - ypos,
1.34 @@ -175,7 +175,7 @@
1.35 screen. */
1.36
1.37 if (ypos)
1.38 - copy_display_section(&display_config, screendata,
1.39 + display_copy_section(&display_config, screendata,
1.40 screendata_width, screendata_height,
1.41 xsource, 0,
1.42 width, ypos,
1.43 @@ -273,7 +273,7 @@
1.44 /* Select the next frame to plot to. */
1.45
1.46 frame = wrap_value(frame + 1, display_config.frames);
1.47 - select_frame(&display_config, frame, frame_offset[frame]);
1.48 + display_select_frame(&display_config, frame, frame_offset[frame]);
1.49
1.50 /* Prepare the frame for updates. */
1.51
1.52 @@ -309,12 +309,12 @@
1.53
1.54 /* Scroll the frame. */
1.55
1.56 - scroll_display(&display_config, xstep / SCROLL_XSTEP,
1.57 + display_scroll(&display_config, xstep / SCROLL_XSTEP,
1.58 ystep / SOURCE_YSTEP);
1.59
1.60 /* Record the new screen start offset. */
1.61
1.62 - frame_offset[frame] = get_start_offset(&display_config);
1.63 + frame_offset[frame] = display_get_start_offset(&display_config);
1.64
1.65 /* For horizontal scrolling, plot the exposed column at the left
1.66 (if scrolling left) or at the right (if scrolling right). */
1.67 @@ -372,11 +372,11 @@
1.68 {
1.69 /* Obtain the frame. */
1.70
1.71 - select_frame(&display_config, frame, 0);
1.72 + display_select_frame(&display_config, frame, 0);
1.73
1.74 /* Plot the image centred on the screen. */
1.75
1.76 - copy_display(&display_config, screendata,
1.77 + display_copy(&display_config, screendata,
1.78 screendata_width, screendata_height,
1.79 SOURCE_YSTEP,
1.80 (display_config.line_length - screendata_width) / 2,
1.81 @@ -388,7 +388,7 @@
1.82 write_chars();
1.83 }
1.84
1.85 - select_frame(&display_config, 0, 0);
1.86 + display_select_frame(&display_config, 0, 0);
1.87 }
1.88
1.89
2.1 --- a/include/display.h Fri Nov 09 00:33:42 2018 +0100
2.2 +++ b/include/display.h Fri Nov 09 01:08:41 2018 +0100
2.3 @@ -97,33 +97,31 @@
2.4
2.5 void init_display_properties(display_config_t *cfg, uint32_t offset);
2.6
2.7 -void select_frame(display_config_t *cfg, int frame, uint32_t offset);
2.8 +void display_select_frame(display_config_t *cfg, int frame, uint32_t offset);
2.9
2.10 -void set_frames(display_config_t *cfg, int frames);
2.11 +void display_set_frames(display_config_t *cfg, int frames);
2.12
2.13 -uint32_t get_start_offset(display_config_t *cfg);
2.14 +uint32_t display_get_start_offset(display_config_t *cfg);
2.15
2.16 /* Access functions. */
2.17
2.18 -int get_position(display_config_t *cfg, int x);
2.19 +int display_get_position(display_config_t *cfg, int x);
2.20
2.21 -void test_linedata(display_config_t *cfg);
2.22 -
2.23 -void copy_display(display_config_t *cfg, uint8_t *store,
2.24 +void display_copy(display_config_t *cfg, uint8_t *store,
2.25 int width, int height, int ystep,
2.26 int x, int y, int key, int to_display);
2.27
2.28 -void copy_display_section(display_config_t *cfg, uint8_t *store,
2.29 +void display_copy_section(display_config_t *cfg, uint8_t *store,
2.30 int width, int height,
2.31 int xstart, int ystart, int xsize, int ysize, int ystep,
2.32 int x, int y, int key, int to_display);
2.33
2.34 -void scroll_display(display_config_t *cfg, int x, int y);
2.35 +void display_scroll(display_config_t *cfg, int x, int y);
2.36 +
2.37 +void display_test_linedata(display_config_t *cfg);
2.38
2.39 /* Address-related functions. */
2.40
2.41 -uint8_t *wrap_pointer(uint8_t *ptr, uint8_t *lower, uint8_t *upper);
2.42 -
2.43 -uint8_t *wrap_screen_pointer(display_config_t *cfg, uint8_t *ptr);
2.44 +uint8_t *display_wrap_pointer(display_config_t *cfg, uint8_t *ptr);
2.45
2.46 #endif /* __DISPLAY_H__ */
3.1 --- a/lib/display.c Fri Nov 09 00:33:42 2018 +0100
3.2 +++ b/lib/display.c Fri Nov 09 01:08:41 2018 +0100
3.3 @@ -18,6 +18,7 @@
3.4 */
3.5
3.6 #include "display.h"
3.7 +#include "utils.h"
3.8
3.9
3.10
3.11 @@ -71,9 +72,27 @@
3.12 cfg->line_multiplier = cfg->scanlines / cfg->line_count;
3.13 }
3.14
3.15 +
3.16 +
3.17 +/* Select a frame in the framebuffer. */
3.18 +
3.19 +void display_select_frame(display_config_t *cfg, int frame, uint32_t offset)
3.20 +{
3.21 + if ((frame < 0) || (frame >= cfg->frames))
3.22 + return;
3.23 +
3.24 + /* Update the frame details. */
3.25 +
3.26 + cfg->frame = frame;
3.27 +
3.28 + /* Set the screen start offset when switching frames. */
3.29 +
3.30 + init_display_properties(cfg, offset);
3.31 +}
3.32 +
3.33 /* Set the number of frames in the framebuffer memory. */
3.34
3.35 -void set_frames(display_config_t *cfg, int frames)
3.36 +void display_set_frames(display_config_t *cfg, int frames)
3.37 {
3.38 if ((frames <= 0) || (frames > cfg->max_frames))
3.39 return;
3.40 @@ -94,32 +113,11 @@
3.41 init_display_properties(cfg, 0);
3.42 }
3.43
3.44 -/* Select a frame in the framebuffer. */
3.45
3.46 -void select_frame(display_config_t *cfg, int frame, uint32_t offset)
3.47 -{
3.48 - if ((frame < 0) || (frame >= cfg->frames))
3.49 - return;
3.50 -
3.51 - /* Update the frame details. */
3.52 -
3.53 - cfg->frame = frame;
3.54 -
3.55 - /* Set the screen start offset when switching frames. */
3.56 -
3.57 - init_display_properties(cfg, offset);
3.58 -}
3.59 -
3.60 -/* Return the screen start offset. */
3.61 -
3.62 -uint32_t get_start_offset(display_config_t *cfg)
3.63 -{
3.64 - return cfg->screen_start - cfg->frame_start;
3.65 -}
3.66
3.67 /* Return the line data position for the given pixel. */
3.68
3.69 -int get_position(display_config_t *cfg, int x)
3.70 +int display_get_position(display_config_t *cfg, int x)
3.71 {
3.72 int cell, offset, pos;
3.73
3.74 @@ -143,51 +141,36 @@
3.75 return cell % 2 ? pos + cfg->line_length / 2 : pos;
3.76 }
3.77
3.78 -/* Provide a pattern to test the line data. */
3.79 -
3.80 -void test_linedata(display_config_t *cfg)
3.81 -{
3.82 - int x, y;
3.83 - uint8_t *linedata = cfg->screen_start;
3.84 +/* Return the screen start offset. */
3.85
3.86 - for (y = 0; y < cfg->line_count; y++)
3.87 - {
3.88 - for (x = 0; x < cfg->line_length; x++)
3.89 - {
3.90 - /* Pixel: I0RRGGBB = Y0YYYYXX */
3.91 +uint32_t display_get_start_offset(display_config_t *cfg)
3.92 +{
3.93 + return cfg->screen_start - cfg->frame_start;
3.94 +}
3.95
3.96 - linedata[get_position(cfg, x)] = (x % 2) ?
3.97 - (((y / (cfg->line_count / 32)) & 0b1) << 7) |
3.98 - (((y / (cfg->line_count / 16)) & 0b1111) << 2) |
3.99 - ((x / (cfg->line_length / 4)) & 0b11) :
3.100 - 0x00;
3.101 - }
3.102
3.103 - linedata = wrap_screen_pointer(cfg, linedata + cfg->line_length);
3.104 - }
3.105 -}
3.106
3.107 /* Copying from/to the display to/from a backing store. */
3.108
3.109 -void copy_display(display_config_t *cfg, uint8_t *store,
3.110 +void display_copy(display_config_t *cfg, uint8_t *store,
3.111 int width, int height, int ystep,
3.112 int x, int y, int key, int to_display)
3.113 {
3.114 - copy_display_section(cfg, store, width, height,
3.115 + display_copy_section(cfg, store, width, height,
3.116 0, 0, width, height, ystep,
3.117 x, y, key, to_display);
3.118 }
3.119
3.120 /* Copying from/to the display to/from a backing store region. */
3.121
3.122 -void copy_display_section(display_config_t *cfg, uint8_t *store,
3.123 +void display_copy_section(display_config_t *cfg, uint8_t *store,
3.124 int width, int height,
3.125 int xstart, int ystart, int xsize, int ysize, int ystep,
3.126 int x, int y, int key, int to_display)
3.127 {
3.128 int sx, sy, dx, dy;
3.129 uint8_t *storeline = store + ystart * width,
3.130 - *displayline = wrap_screen_pointer(cfg, cfg->screen_start + y * cfg->line_length),
3.131 + *displayline = display_wrap_pointer(cfg, cfg->screen_start + y * cfg->line_length),
3.132 pixel;
3.133
3.134 /* Define the limits of the copying in the store. */
3.135 @@ -210,45 +193,55 @@
3.136 {
3.137 pixel = storeline[sx];
3.138 if ((key < 0) || (pixel != key))
3.139 - displayline[get_position(cfg, dx)] = pixel;
3.140 + displayline[display_get_position(cfg, dx)] = pixel;
3.141 }
3.142 else
3.143 - storeline[sx] = displayline[get_position(cfg, dx)];
3.144 + storeline[sx] = displayline[display_get_position(cfg, dx)];
3.145 }
3.146
3.147 storeline += width * ystep;
3.148 - displayline = wrap_screen_pointer(cfg, displayline + cfg->line_length);
3.149 + displayline = display_wrap_pointer(cfg, displayline + cfg->line_length);
3.150 }
3.151 }
3.152
3.153 /* Scroll the display. */
3.154
3.155 -void scroll_display(display_config_t *cfg, int x, int y)
3.156 +void display_scroll(display_config_t *cfg, int x, int y)
3.157 {
3.158 /* Move the screen start by the given number of bytes and lines, wrapping
3.159 around the start and end of the framebuffer. */
3.160
3.161 - cfg->screen_start = wrap_screen_pointer(cfg, cfg->screen_start + x +
3.162 - y * cfg->line_length);
3.163 + cfg->screen_start = display_wrap_pointer(cfg, cfg->screen_start + x +
3.164 + y * cfg->line_length);
3.165 }
3.166
3.167 -/* Wrap a pointer within the given limits. */
3.168 +/* Provide a pattern to test the line data. */
3.169
3.170 -uint8_t *wrap_pointer(uint8_t *ptr, uint8_t *lower, uint8_t *upper)
3.171 +void display_test_linedata(display_config_t *cfg)
3.172 {
3.173 - uint32_t size = upper - lower;
3.174 + int x, y;
3.175 + uint8_t *linedata = cfg->screen_start;
3.176
3.177 - if (ptr < lower)
3.178 - return upper - (lower - ptr) % size;
3.179 - else if (ptr >= upper)
3.180 - return lower + (ptr - upper) % size;
3.181 - else
3.182 - return ptr;
3.183 + for (y = 0; y < cfg->line_count; y++)
3.184 + {
3.185 + for (x = 0; x < cfg->line_length; x++)
3.186 + {
3.187 + /* Pixel: I0RRGGBB = Y0YYYYXX */
3.188 +
3.189 + linedata[display_get_position(cfg, x)] = (x % 2) ?
3.190 + (((y / (cfg->line_count / 32)) & 0b1) << 7) |
3.191 + (((y / (cfg->line_count / 16)) & 0b1111) << 2) |
3.192 + ((x / (cfg->line_length / 4)) & 0b11) :
3.193 + 0x00;
3.194 + }
3.195 +
3.196 + linedata = display_wrap_pointer(cfg, linedata + cfg->line_length);
3.197 + }
3.198 }
3.199
3.200 /* Wrap the screen pointer to the current frame. */
3.201
3.202 -uint8_t *wrap_screen_pointer(display_config_t *cfg, uint8_t *ptr)
3.203 +uint8_t *display_wrap_pointer(display_config_t *cfg, uint8_t *ptr)
3.204 {
3.205 return wrap_pointer(ptr, cfg->frame_start, cfg->screen_limit);
3.206 }
4.1 --- a/lib/font.c Fri Nov 09 00:33:42 2018 +0100
4.2 +++ b/lib/font.c Fri Nov 09 01:08:41 2018 +0100
4.3 @@ -76,7 +76,7 @@
4.4 for (dx = x, mask = 1 << (chardef->width - 1); (mask) && (dx < cfg->line_length); dx++, mask >>= 1)
4.5 {
4.6 if (bitmap & mask)
4.7 - displayline[get_position(cfg, dx)] = colour;
4.8 + displayline[display_get_position(cfg, dx)] = colour;
4.9 }
4.10
4.11 imagerow += 1;