# HG changeset patch # User Paul Boddie # Date 1541722121 -3600 # Node ID 2686a14efbde9bd02bc0c80a1df1422e7ca221d7 # Parent 1d5ca38cab46156f0977d204259fa22015ecfe74 Renamed the display functions to indicate their origin. diff -r 1d5ca38cab46 -r 2686a14efbde examples/vga/main.c --- a/examples/vga/main.c Fri Nov 09 00:33:42 2018 +0100 +++ b/examples/vga/main.c Fri Nov 09 01:08:41 2018 +0100 @@ -110,10 +110,10 @@ static void plot_sprite(uint8_t *background, int x, int y) { - copy_display(&display_config, background, + display_copy(&display_config, background, sprite_width, sprite_height / SOURCE_YSTEP, 1, x, y, -1, 0); - copy_display(&display_config, sprite, + display_copy(&display_config, sprite, sprite_width, sprite_height, SOURCE_YSTEP, x, y, 0x8c, 1); } @@ -122,7 +122,7 @@ static void unplot_sprite(uint8_t *background, int x, int y) { - copy_display(&display_config, background, + display_copy(&display_config, background, sprite_width, sprite_height / SOURCE_YSTEP, 1, x, y, -1, 1); } @@ -161,7 +161,7 @@ upwards (or downwards having wrapped around) on the screen. */ - copy_display_section(&display_config, screendata, + display_copy_section(&display_config, screendata, screendata_width, screendata_height, xsource, ypos, width, screendata_height - ypos, @@ -175,7 +175,7 @@ screen. */ if (ypos) - copy_display_section(&display_config, screendata, + display_copy_section(&display_config, screendata, screendata_width, screendata_height, xsource, 0, width, ypos, @@ -273,7 +273,7 @@ /* Select the next frame to plot to. */ frame = wrap_value(frame + 1, display_config.frames); - select_frame(&display_config, frame, frame_offset[frame]); + display_select_frame(&display_config, frame, frame_offset[frame]); /* Prepare the frame for updates. */ @@ -309,12 +309,12 @@ /* Scroll the frame. */ - scroll_display(&display_config, xstep / SCROLL_XSTEP, + display_scroll(&display_config, xstep / SCROLL_XSTEP, ystep / SOURCE_YSTEP); /* Record the new screen start offset. */ - frame_offset[frame] = get_start_offset(&display_config); + frame_offset[frame] = display_get_start_offset(&display_config); /* For horizontal scrolling, plot the exposed column at the left (if scrolling left) or at the right (if scrolling right). */ @@ -372,11 +372,11 @@ { /* Obtain the frame. */ - select_frame(&display_config, frame, 0); + display_select_frame(&display_config, frame, 0); /* Plot the image centred on the screen. */ - copy_display(&display_config, screendata, + display_copy(&display_config, screendata, screendata_width, screendata_height, SOURCE_YSTEP, (display_config.line_length - screendata_width) / 2, @@ -388,7 +388,7 @@ write_chars(); } - select_frame(&display_config, 0, 0); + display_select_frame(&display_config, 0, 0); } diff -r 1d5ca38cab46 -r 2686a14efbde include/display.h --- a/include/display.h Fri Nov 09 00:33:42 2018 +0100 +++ b/include/display.h Fri Nov 09 01:08:41 2018 +0100 @@ -97,33 +97,31 @@ void init_display_properties(display_config_t *cfg, uint32_t offset); -void select_frame(display_config_t *cfg, int frame, uint32_t offset); +void display_select_frame(display_config_t *cfg, int frame, uint32_t offset); -void set_frames(display_config_t *cfg, int frames); +void display_set_frames(display_config_t *cfg, int frames); -uint32_t get_start_offset(display_config_t *cfg); +uint32_t display_get_start_offset(display_config_t *cfg); /* Access functions. */ -int get_position(display_config_t *cfg, int x); +int display_get_position(display_config_t *cfg, int x); -void test_linedata(display_config_t *cfg); - -void copy_display(display_config_t *cfg, uint8_t *store, +void display_copy(display_config_t *cfg, uint8_t *store, int width, int height, int ystep, int x, int y, int key, int to_display); -void copy_display_section(display_config_t *cfg, uint8_t *store, +void display_copy_section(display_config_t *cfg, uint8_t *store, int width, int height, int xstart, int ystart, int xsize, int ysize, int ystep, int x, int y, int key, int to_display); -void scroll_display(display_config_t *cfg, int x, int y); +void display_scroll(display_config_t *cfg, int x, int y); + +void display_test_linedata(display_config_t *cfg); /* Address-related functions. */ -uint8_t *wrap_pointer(uint8_t *ptr, uint8_t *lower, uint8_t *upper); - -uint8_t *wrap_screen_pointer(display_config_t *cfg, uint8_t *ptr); +uint8_t *display_wrap_pointer(display_config_t *cfg, uint8_t *ptr); #endif /* __DISPLAY_H__ */ diff -r 1d5ca38cab46 -r 2686a14efbde lib/display.c --- a/lib/display.c Fri Nov 09 00:33:42 2018 +0100 +++ b/lib/display.c Fri Nov 09 01:08:41 2018 +0100 @@ -18,6 +18,7 @@ */ #include "display.h" +#include "utils.h" @@ -71,9 +72,27 @@ cfg->line_multiplier = cfg->scanlines / cfg->line_count; } + + +/* Select a frame in the framebuffer. */ + +void display_select_frame(display_config_t *cfg, int frame, uint32_t offset) +{ + if ((frame < 0) || (frame >= cfg->frames)) + return; + + /* Update the frame details. */ + + cfg->frame = frame; + + /* Set the screen start offset when switching frames. */ + + init_display_properties(cfg, offset); +} + /* Set the number of frames in the framebuffer memory. */ -void set_frames(display_config_t *cfg, int frames) +void display_set_frames(display_config_t *cfg, int frames) { if ((frames <= 0) || (frames > cfg->max_frames)) return; @@ -94,32 +113,11 @@ init_display_properties(cfg, 0); } -/* Select a frame in the framebuffer. */ -void select_frame(display_config_t *cfg, int frame, uint32_t offset) -{ - if ((frame < 0) || (frame >= cfg->frames)) - return; - - /* Update the frame details. */ - - cfg->frame = frame; - - /* Set the screen start offset when switching frames. */ - - init_display_properties(cfg, offset); -} - -/* Return the screen start offset. */ - -uint32_t get_start_offset(display_config_t *cfg) -{ - return cfg->screen_start - cfg->frame_start; -} /* Return the line data position for the given pixel. */ -int get_position(display_config_t *cfg, int x) +int display_get_position(display_config_t *cfg, int x) { int cell, offset, pos; @@ -143,51 +141,36 @@ return cell % 2 ? pos + cfg->line_length / 2 : pos; } -/* Provide a pattern to test the line data. */ - -void test_linedata(display_config_t *cfg) -{ - int x, y; - uint8_t *linedata = cfg->screen_start; +/* Return the screen start offset. */ - for (y = 0; y < cfg->line_count; y++) - { - for (x = 0; x < cfg->line_length; x++) - { - /* Pixel: I0RRGGBB = Y0YYYYXX */ +uint32_t display_get_start_offset(display_config_t *cfg) +{ + return cfg->screen_start - cfg->frame_start; +} - linedata[get_position(cfg, x)] = (x % 2) ? - (((y / (cfg->line_count / 32)) & 0b1) << 7) | - (((y / (cfg->line_count / 16)) & 0b1111) << 2) | - ((x / (cfg->line_length / 4)) & 0b11) : - 0x00; - } - linedata = wrap_screen_pointer(cfg, linedata + cfg->line_length); - } -} /* Copying from/to the display to/from a backing store. */ -void copy_display(display_config_t *cfg, uint8_t *store, +void display_copy(display_config_t *cfg, uint8_t *store, int width, int height, int ystep, int x, int y, int key, int to_display) { - copy_display_section(cfg, store, width, height, + display_copy_section(cfg, store, width, height, 0, 0, width, height, ystep, x, y, key, to_display); } /* Copying from/to the display to/from a backing store region. */ -void copy_display_section(display_config_t *cfg, uint8_t *store, +void display_copy_section(display_config_t *cfg, uint8_t *store, int width, int height, int xstart, int ystart, int xsize, int ysize, int ystep, int x, int y, int key, int to_display) { int sx, sy, dx, dy; uint8_t *storeline = store + ystart * width, - *displayline = wrap_screen_pointer(cfg, cfg->screen_start + y * cfg->line_length), + *displayline = display_wrap_pointer(cfg, cfg->screen_start + y * cfg->line_length), pixel; /* Define the limits of the copying in the store. */ @@ -210,45 +193,55 @@ { pixel = storeline[sx]; if ((key < 0) || (pixel != key)) - displayline[get_position(cfg, dx)] = pixel; + displayline[display_get_position(cfg, dx)] = pixel; } else - storeline[sx] = displayline[get_position(cfg, dx)]; + storeline[sx] = displayline[display_get_position(cfg, dx)]; } storeline += width * ystep; - displayline = wrap_screen_pointer(cfg, displayline + cfg->line_length); + displayline = display_wrap_pointer(cfg, displayline + cfg->line_length); } } /* Scroll the display. */ -void scroll_display(display_config_t *cfg, int x, int y) +void display_scroll(display_config_t *cfg, int x, int y) { /* Move the screen start by the given number of bytes and lines, wrapping around the start and end of the framebuffer. */ - cfg->screen_start = wrap_screen_pointer(cfg, cfg->screen_start + x + - y * cfg->line_length); + cfg->screen_start = display_wrap_pointer(cfg, cfg->screen_start + x + + y * cfg->line_length); } -/* Wrap a pointer within the given limits. */ +/* Provide a pattern to test the line data. */ -uint8_t *wrap_pointer(uint8_t *ptr, uint8_t *lower, uint8_t *upper) +void display_test_linedata(display_config_t *cfg) { - uint32_t size = upper - lower; + int x, y; + uint8_t *linedata = cfg->screen_start; - if (ptr < lower) - return upper - (lower - ptr) % size; - else if (ptr >= upper) - return lower + (ptr - upper) % size; - else - return ptr; + for (y = 0; y < cfg->line_count; y++) + { + for (x = 0; x < cfg->line_length; x++) + { + /* Pixel: I0RRGGBB = Y0YYYYXX */ + + linedata[display_get_position(cfg, x)] = (x % 2) ? + (((y / (cfg->line_count / 32)) & 0b1) << 7) | + (((y / (cfg->line_count / 16)) & 0b1111) << 2) | + ((x / (cfg->line_length / 4)) & 0b11) : + 0x00; + } + + linedata = display_wrap_pointer(cfg, linedata + cfg->line_length); + } } /* Wrap the screen pointer to the current frame. */ -uint8_t *wrap_screen_pointer(display_config_t *cfg, uint8_t *ptr) +uint8_t *display_wrap_pointer(display_config_t *cfg, uint8_t *ptr) { return wrap_pointer(ptr, cfg->frame_start, cfg->screen_limit); } diff -r 1d5ca38cab46 -r 2686a14efbde lib/font.c --- a/lib/font.c Fri Nov 09 00:33:42 2018 +0100 +++ b/lib/font.c Fri Nov 09 01:08:41 2018 +0100 @@ -76,7 +76,7 @@ for (dx = x, mask = 1 << (chardef->width - 1); (mask) && (dx < cfg->line_length); dx++, mask >>= 1) { if (bitmap & mask) - displayline[get_position(cfg, dx)] = colour; + displayline[display_get_position(cfg, dx)] = colour; } imagerow += 1;