# HG changeset patch # User Paul Boddie # Date 1541360702 -3600 # Node ID ec41bb0393497a2458966b322345e581f2bbc969 # Parent 000b6b782bf4e8fb08d72291120128649643f8fa Introduced multiple frame usage in the example. diff -r 000b6b782bf4 -r ec41bb039349 examples/vga/main.c --- a/examples/vga/main.c Sun Nov 04 18:13:06 2018 +0100 +++ b/examples/vga/main.c Sun Nov 04 20:45:02 2018 +0100 @@ -225,7 +225,16 @@ { /* Stored region behind the sprite. */ - uint8_t background[(sprite_width * sprite_height) / SOURCE_YSTEP]; + uint8_t background[FRAME_COUNT][(sprite_width * sprite_height) / SOURCE_YSTEP]; + + /* Positions of the stored regions for each frame. */ + + int background_x[FRAME_COUNT], background_y[FRAME_COUNT]; + int background_stored[FRAME_COUNT]; + + /* Screen start values for each frame. */ + + uint32_t frame_offset[FRAME_COUNT]; /* Sprite position. */ @@ -240,58 +249,107 @@ int xorigin = 0, yorigin = 0; + /* Scrolling positions for each frame. */ + + int xorigins[FRAME_COUNT], yorigins[FRAME_COUNT]; + /* Scroll increments and replotted column details. */ - int xdir, ydir, xstep; + int xdir, ydir, xstep, ystep; + + /* Current frame being accessed. */ + + int frame; + + for (frame = 0; frame < display_config.frames; frame++) + { + background_stored[frame] = 0; + frame_offset[frame] = 0; + xorigins[frame] = xorigin; + yorigins[frame] = yorigin; + } + + frame = display_config.frame; + + /* Animation loop. */ while (1) { - for (y = 0; y < screendata_height - sprite_height; y++) + for (y = 0; y < display_config.line_count - sprite_height; y++) { - for (x = 0; x < screendata_width - sprite_width; x++) + for (x = 0; x < display_config.line_length - sprite_width; x++) { - plot_sprite(background, x, y); + plot_sprite(background[frame], x, y); + + /* Record the stored background. */ + + background_x[frame] = x; + background_y[frame] = y; + background_stored[frame] = 1; /* Update the display with the frame details. */ vga_set_frame(&display_config); wait(delay); - unplot_sprite(background, x, y); + /* Select the next frame to plot to. */ + + frame = wrap_value(frame + 1, display_config.frames); + select_frame(&display_config, frame, frame_offset[frame]); + + /* Prepare the frame for updates. */ + + if (background_stored[frame]) + unplot_sprite(background[frame], background_x[frame], background_y[frame]); /* Scroll in the indicated direction. */ xdir = dir[dirindex]; ydir = dir[dirindex + 1]; - scroll_display(&display_config, xdir, ydir); + /* Update the origin if appropriate. */ - /* Update the vertical origin if appropriate. */ + /* Due to the effect of a simple screen start increment in the + dual channel configuration, horizontal scrolling involves two + pixel increments and thus requires a two-pixel column to be + plotted. */ + + if (xdir) + xorigin += xdir * SCROLL_XSTEP; if (ydir) - yorigin = wrap_value(yorigin + ydir * SOURCE_YSTEP, - screendata_height); + yorigin += ydir * SOURCE_YSTEP; + + /* Determine the magnitude of the scrolling required from this + frame to the current origin. */ + + xstep = xorigin - xorigins[frame]; + ystep = yorigin - yorigins[frame]; + + /* Scroll the frame. */ + + scroll_display(&display_config, xstep / SCROLL_XSTEP, + ystep / SOURCE_YSTEP); + + /* Record the new screen start offset. */ + + frame_offset[frame] = get_start_offset(&display_config); + + /* Update the current origin. */ + + xorigin = wrap_value(xorigin, screendata_width); + yorigin = wrap_value(yorigin, screendata_height); /* For horizontal scrolling, plot the exposed column at the left (if scrolling left) or at the right (if scrolling right). */ - if (xdir) - { - /* Due to the effect of a simple screen start increment in - the dual channel configuration, horizontal scrolling - involves two pixel increments and thus requires a two- - pixel column to be plotted. */ - - xstep = xdir * SCROLL_XSTEP; + if (xstep) + plot_screen_edge(xorigin, yorigin, xstep); - /* Determine the location of the column to be plotted. */ - - xorigin = wrap_value(xorigin + xstep, screendata_width); + /* Record the origin for this frame. */ - /* Plot either at the left or right edge. */ - - plot_screen_edge(xorigin, yorigin, xstep); - } + xorigins[frame] = xorigin; + yorigins[frame] = yorigin; } /* Switch direction periodically. */