# HG changeset patch # User Paul Boddie # Date 1541351586 -3600 # Node ID 000b6b782bf4e8fb08d72291120128649643f8fa # Parent 6d95b67997e657cdb4473d13ebffa2c4d83ea40c Added support for source image scaling where images might be used in single- and double-buffering modes. diff -r 6d95b67997e6 -r 000b6b782bf4 examples/vga-timer/Makefile --- a/examples/vga-timer/Makefile Sun Nov 04 16:14:58 2018 +0100 +++ b/examples/vga-timer/Makefile Sun Nov 04 18:13:06 2018 +0100 @@ -33,6 +33,6 @@ # Application-specific adjustments. # See: examples/vga/Makefile -CFLAGS += -DLINE_CHANNELS=2 -DTRANSFER_TIMER=3 -I../vga +CFLAGS += -DLINE_CHANNELS=2 -DTRANSFER_TIMER=3 -DSOURCE_HEIGHT=128 -I../vga include ../../mk/rules.mk diff -r 6d95b67997e6 -r 000b6b782bf4 examples/vga/main.c --- a/examples/vga/main.c Sun Nov 04 16:14:58 2018 +0100 +++ b/examples/vga/main.c Sun Nov 04 18:13:06 2018 +0100 @@ -81,6 +81,16 @@ +/* Define the relationship between source images and the screen. */ + +#ifndef SOURCE_HEIGHT +#define SOURCE_HEIGHT 256 +#endif + +#define SOURCE_YSTEP (SOURCE_HEIGHT / LINE_COUNT) + + + /* Framebuffer memory. */ static uint8_t framebuffer[FRAME_SIZE * FRAME_COUNT]; @@ -135,10 +145,10 @@ static void plot_sprite(uint8_t *background, int x, int y) { copy_display(&display_config, background, - sprite_width, sprite_height, + sprite_width, sprite_height / SOURCE_YSTEP, 1, x, y, -1, 0); copy_display(&display_config, sprite, - sprite_width, sprite_height, + sprite_width, sprite_height, SOURCE_YSTEP, x, y, 0x8c, 1); } @@ -147,7 +157,7 @@ static void unplot_sprite(uint8_t *background, int x, int y) { copy_display(&display_config, background, - sprite_width, sprite_height, + sprite_width, sprite_height / SOURCE_YSTEP, 1, x, y, -1, 1); } @@ -177,6 +187,7 @@ screendata_width, screendata_height, xsource, yorigin, width, screendata_height - yorigin, + SOURCE_YSTEP, xdisplay, 0, -1, 1); @@ -190,7 +201,8 @@ screendata_width, screendata_height, xsource, 0, width, yorigin, - xdisplay, screendata_height - yorigin, + SOURCE_YSTEP, + xdisplay, (screendata_height - yorigin) / SOURCE_YSTEP, -1, 1); } @@ -213,7 +225,7 @@ { /* Stored region behind the sprite. */ - uint8_t background[sprite_width * sprite_height]; + uint8_t background[(sprite_width * sprite_height) / SOURCE_YSTEP]; /* Sprite position. */ @@ -257,7 +269,8 @@ /* Update the vertical origin if appropriate. */ if (ydir) - yorigin = wrap_value(yorigin + ydir, screendata_height); + yorigin = wrap_value(yorigin + ydir * SOURCE_YSTEP, + screendata_height); /* For horizontal scrolling, plot the exposed column at the left (if scrolling left) or at the right (if scrolling right). */ @@ -326,9 +339,12 @@ /* Plot the image centred on the screen. */ - copy_display(&display_config, screendata, screendata_width, screendata_height, + copy_display(&display_config, screendata, + screendata_width, screendata_height, + SOURCE_YSTEP, (display_config.line_length - screendata_width) / 2, - (display_config.line_count - screendata_height) / 2, -1, 1); + (display_config.line_count - (screendata_height / SOURCE_YSTEP)) / 2, + -1, 1); /* Write a sequence of characters. */ diff -r 6d95b67997e6 -r 000b6b782bf4 include/display.h --- a/include/display.h Sun Nov 04 16:14:58 2018 +0100 +++ b/include/display.h Sun Nov 04 18:13:06 2018 +0100 @@ -105,12 +105,13 @@ void test_linedata(display_config_t *cfg); -void copy_display(display_config_t *cfg, uint8_t *store, int width, int height, +void copy_display(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, int width, int height, - int xstart, int ystart, int xsize, int ysize, + 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); diff -r 6d95b67997e6 -r 000b6b782bf4 lib/display.c --- a/lib/display.c Sun Nov 04 16:14:58 2018 +0100 +++ b/lib/display.c Sun Nov 04 18:13:06 2018 +0100 @@ -153,18 +153,20 @@ /* Copying from/to the display to/from a backing store. */ -void copy_display(display_config_t *cfg, uint8_t *store, int width, int height, +void copy_display(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, 0, 0, width, height, x, y, - key, to_display); + copy_display_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, int width, int height, - int xstart, int ystart, int xsize, int ysize, + int xstart, int ystart, int xsize, int ysize, int ystep, int x, int y, int key, int to_display) { int sx, sy, dx, dy; @@ -184,7 +186,7 @@ /* Perform the copying between the store and display. */ - for (sy = ystart, dy = y; (sy < ylimit) && (dy < cfg->line_count); sy++, dy++) + for (sy = ystart, dy = y; (sy < ylimit) && (dy < cfg->line_count); sy += ystep, dy++) { for (sx = xstart, dx = x; (sx < xlimit) && (dx < cfg->line_length); sx++, dx++) { @@ -198,7 +200,7 @@ storeline[sx] = displayline[get_position(cfg, dx)]; } - storeline += width; + storeline += width * ystep; displayline = wrap_screen_pointer(cfg, displayline + cfg->line_length); } }