1.1 --- a/lib/display.c Fri Nov 09 21:04:23 2018 +0100
1.2 +++ b/lib/display.c Fri Nov 09 21:05:06 2018 +0100
1.3 @@ -25,7 +25,8 @@
1.4 /* Initialise a display configuration. */
1.5
1.6 void init_display(display_config_t *cfg, uint8_t *framebuffer,
1.7 - uint32_t line_length, uint32_t line_count, int frames)
1.8 + uint32_t line_length, uint32_t line_count,
1.9 + int frames, uint8_t **screen_starts)
1.10 {
1.11 /* Framebuffer address. */
1.12
1.13 @@ -47,21 +48,32 @@
1.14 cfg->frames = frames;
1.15 cfg->frame = 0;
1.16
1.17 - init_display_properties(cfg, 0);
1.18 + /* Set the pointer to a collection of screen start pointers, one per
1.19 + frame. */
1.20 +
1.21 + cfg->screen_starts = screen_starts;
1.22 +
1.23 + init_frames(cfg);
1.24 + init_display_properties(cfg);
1.25 }
1.26
1.27 /* Initialise the display constraints. */
1.28
1.29 -void init_display_properties(display_config_t *cfg, uint32_t offset)
1.30 +void init_display_properties(display_config_t *cfg)
1.31 {
1.32 /* Fixed address of the frame. */
1.33
1.34 - cfg->frame_start = cfg->framebuffer +
1.35 - (cfg->screen_size + cfg->line_length) * cfg->frame;
1.36 + cfg->frame_start = display_get_frame_start(cfg, cfg->frame);
1.37
1.38 /* Floating address of the screen contents. */
1.39
1.40 - cfg->screen_start = cfg->frame_start + offset;
1.41 + if (cfg->screen_starts)
1.42 + cfg->screen_start = cfg->screen_starts[cfg->frame];
1.43 +
1.44 + /* Without any way of recording the address, just reset the start. */
1.45 +
1.46 + else
1.47 + cfg->screen_start = cfg->frame_start;
1.48
1.49 /* Fixed limit of the frame. */
1.50
1.51 @@ -72,22 +84,37 @@
1.52 cfg->line_multiplier = cfg->scanlines / cfg->line_count;
1.53 }
1.54
1.55 +/* Initialise the screen start addresses for all frames. */
1.56 +
1.57 +void init_frames(display_config_t *cfg)
1.58 +{
1.59 + int frame;
1.60 +
1.61 + for (frame = 0; frame < cfg->frames; frame++)
1.62 + cfg->screen_starts[frame] = display_get_frame_start(cfg, frame);
1.63 +}
1.64 +
1.65
1.66
1.67 /* Select a frame in the framebuffer. */
1.68
1.69 -void display_select_frame(display_config_t *cfg, int frame, uint32_t offset)
1.70 +void display_select_frame(display_config_t *cfg, int frame)
1.71 {
1.72 if ((frame < 0) || (frame >= cfg->frames))
1.73 return;
1.74
1.75 + /* Store the current frame's screen start, if possible. */
1.76 +
1.77 + if (cfg->screen_starts)
1.78 + cfg->screen_starts[cfg->frame] = cfg->screen_start;
1.79 +
1.80 /* Update the frame details. */
1.81
1.82 cfg->frame = frame;
1.83
1.84 /* Set the screen start offset when switching frames. */
1.85
1.86 - init_display_properties(cfg, offset);
1.87 + init_display_properties(cfg);
1.88 }
1.89
1.90 /* Set the number of frames in the framebuffer memory. */
1.91 @@ -110,11 +137,19 @@
1.92 cfg->frames = frames;
1.93 cfg->frame = 0;
1.94
1.95 - init_display_properties(cfg, 0);
1.96 + init_frames(cfg);
1.97 + init_display_properties(cfg);
1.98 }
1.99
1.100
1.101
1.102 +/* Return the start address of the given frame. */
1.103 +
1.104 +uint8_t *display_get_frame_start(display_config_t *cfg, int frame)
1.105 +{
1.106 + return cfg->framebuffer + (cfg->screen_size + cfg->line_length) * frame;
1.107 +}
1.108 +
1.109 /* Return the line data position for the given pixel. */
1.110
1.111 int display_get_position(display_config_t *cfg, int x)