1.1 --- a/examples/vga/main.c Mon Oct 29 01:43:42 2018 +0100
1.2 +++ b/examples/vga/main.c Mon Oct 29 01:46:31 2018 +0100
1.3 @@ -67,24 +67,32 @@
1.4
1.5 extern uint8_t screendata[];
1.6 extern uint32_t screendata_width, screendata_height;
1.7 +extern uint8_t sprite[];
1.8 +extern uint32_t sprite_width, sprite_height;
1.9 +
1.10
1.11
1.12 +/* Busy wait. */
1.13 +
1.14 +static void wait(uint32_t delay)
1.15 +{
1.16 + uint32_t counter = delay;
1.17 +
1.18 + if (!delay) return;
1.19 + while (counter--) __asm__(""); /* retain loop */
1.20 +}
1.21
1.22 /* Blink an attached LED with delays implemented using a loop. */
1.23
1.24 static void blink(uint32_t delay, uint32_t port, uint32_t pins)
1.25 {
1.26 - uint32_t counter;
1.27 -
1.28 /* Clear outputs (LED). */
1.29
1.30 CLR_REG(port, pins);
1.31
1.32 while (1)
1.33 {
1.34 - counter = delay;
1.35 -
1.36 - while (counter--) __asm__(""); /* retain loop */
1.37 + wait(delay);
1.38
1.39 /* Invert outputs (LED). */
1.40
1.41 @@ -92,6 +100,31 @@
1.42 }
1.43 }
1.44
1.45 +/* Move a sprite around on the framebuffer. */
1.46 +
1.47 +static void animate(uint32_t delay)
1.48 +{
1.49 + uint8_t background[sprite_width * sprite_height];
1.50 + int x, y;
1.51 +
1.52 + while (1)
1.53 + for (y = 0; y < screendata_height - sprite_height; y++)
1.54 + for (x = 0; x < screendata_width - sprite_width; x++)
1.55 + {
1.56 + /* Copy to the store from the display, then blit the image. */
1.57 +
1.58 + copy_display(&display_config, background, sprite_width, sprite_height, x, y, -1, 0);
1.59 + copy_display(&display_config, sprite, sprite_width, sprite_height, x, y, 0x8c, 1);
1.60 +
1.61 + wait(delay);
1.62 +
1.63 + /* Copy to the display from the store, restoring the original
1.64 + background. */
1.65 +
1.66 + copy_display(&display_config, background, sprite_width, sprite_height, x, y, -1, 1);
1.67 + }
1.68 +}
1.69 +
1.70
1.71
1.72 /* Main program. */
1.73 @@ -136,8 +169,14 @@
1.74
1.75 interrupts_on();
1.76
1.77 - copy_to_framebuffer(&display_config, screendata, screendata_width, screendata_height);
1.78 - blink(1 << 24, PORTA, LED_PIN);
1.79 + /* Plot the image centred on the screen. */
1.80 +
1.81 + copy_display(&display_config, screendata, screendata_width, screendata_height,
1.82 + (LINE_LENGTH - screendata_width) / 2, (LINE_COUNT - screendata_height) / 2, -1, 1);
1.83 +
1.84 + /* Move a sprite around on the screen with a delay between each movement. */
1.85 +
1.86 + animate(1 << 24);
1.87 }
1.88
1.89