# HG changeset patch # User Paul Boddie # Date 1541889489 -3600 # Node ID 301fb9b9ed234e8e4e4390a2640f598c16491dd5 # Parent a695872c3adb0bf94d32371c5cd40af5b771919f Introduced partial sprite plotting into the screen edge update function. diff -r a695872c3adb -r 301fb9b9ed23 examples/vga/main.c --- a/examples/vga/main.c Sat Nov 10 23:00:40 2018 +0100 +++ b/examples/vga/main.c Sat Nov 10 23:38:09 2018 +0100 @@ -93,6 +93,8 @@ extern image_t screendata; extern image_t sprite; +static SpriteOverwriting(scr, &screendata, &display_config, SOURCE_YSTEP); + extern uint8_t fontchars[]; extern uint32_t fonttable[]; extern uint32_t fontbase, fontlimit; @@ -108,16 +110,16 @@ { /* Determine positions within the image. */ - int xpos = wrap_value(xorigin, screendata.width); - int ypos = wrap_value(yorigin, screendata.height); + int xpos = wrap_value(xorigin, scr.image->width); + int ypos = wrap_value(yorigin, scr.image->height); /* The display region is either the left or right edge. */ - int xdisplay = xstep < 0 ? 0 : screendata.width - xstep; + int xdisplay = xstep < 0 ? 0 : scr.image->width - xstep; /* The source region depends on the origin within the background image. */ - int xsource = wrap_value(xdisplay + xpos, screendata.width); + int xsource = wrap_value(xdisplay + xpos, scr.image->width); /* The column width is the absolute increment. */ @@ -126,7 +128,7 @@ /* Not all of the column may be available if close to the edge of the image, requiring multiple slices. */ - int available = screendata.width - xsource; + int available = scr.image->width - xsource; while (width) { @@ -136,13 +138,10 @@ upwards (or downwards having wrapped around) on the screen. */ - display_copy_section(&display_config, screendata.image, - screendata.width, screendata.height, - xsource, ypos, - width, screendata.height - ypos, - v->yscale, - xdisplay, 0, - -1, 1); + image_plot_sprite_section(&scr, xsource, ypos, + width, scr.image->height - ypos, + xdisplay, 0, + -1); /* The second column is at (xdisplay, h - ypos) and provides the upper part of the background image displaced @@ -150,13 +149,10 @@ screen. */ if (ypos) - display_copy_section(&display_config, screendata.image, - screendata.width, screendata.height, - xsource, 0, - width, ypos, - v->yscale, - xdisplay, (screendata.height - ypos) / v->yscale, - -1, 1); + image_plot_sprite_section(&scr, xsource, 0, + width, ypos, + xdisplay, (scr.image->height - ypos) / v->yscale, + -1); /* Get the next slice of the column. */ @@ -164,8 +160,8 @@ { width -= available; xsource = 0; - xdisplay = wrap_value(xdisplay + available, screendata.width); - available = screendata.width; + xdisplay = wrap_value(xdisplay + available, scr.image->width); + available = scr.image->width; } else width = 0; @@ -281,7 +277,6 @@ static void setup(void) { - SpriteOverwriting(scr, &screendata, &display_config, SOURCE_YSTEP); int frame; for (frame = 0; frame < display_config.frames; frame++) diff -r a695872c3adb -r 301fb9b9ed23 include/image.h --- a/include/image.h Sat Nov 10 23:00:40 2018 +0100 +++ b/include/image.h Sat Nov 10 23:38:09 2018 +0100 @@ -144,10 +144,16 @@ .yscale=YSCALE, \ .cfg=CFG}; -/* Plotting operations. */ +/* Sprite plotting operations. */ void image_plot_sprite(sprite_t *s, int x, int y, int key); void image_unplot_sprite(sprite_t *s); +/* Convenience operations. */ + +void image_plot_sprite_section(sprite_t *s, + int xstart, int ystart, int xsize, int ysize, + int x, int y, int key); + #endif /* __IMAGE_H__ */ diff -r a695872c3adb -r 301fb9b9ed23 lib/image.c --- a/lib/image.c Sat Nov 10 23:00:40 2018 +0100 +++ b/lib/image.c Sat Nov 10 23:38:09 2018 +0100 @@ -96,3 +96,17 @@ s->image->width, s->image->height / s->yscale, 1, p->x, p->y, -1, 1); } + + + +/* Plot a section of an image without storing the background beforehand. */ + +void image_plot_sprite_section(sprite_t *s, + int xstart, int ystart, int xsize, int ysize, + int x, int y, int key) +{ + display_copy_section(s->cfg, s->image->image, + s->image->width, s->image->height, + xstart, ystart, xsize, ysize, s->yscale, + x, y, key, 1); +}