Demo of low res colour vga video for stm32f3 discovery board

Dependencies:   STM32F3-Discovery-minimal

Fork of Space_Invaders_Demo by Martin Johnson

Committer:
MartinJohnson
Date:
Tue Mar 01 02:40:19 2016 +0000
Revision:
0:404dae88af71
Child:
3:93e488fbb8a2
space invaders game

Who changed what in which revision?

UserRevisionLine numberNew contents of line
MartinJohnson 0:404dae88af71 1 /***************************************************************************
MartinJohnson 0:404dae88af71 2 * STM32 VGA demo
MartinJohnson 0:404dae88af71 3 * Copyright (C) 2012 Artekit Italy
MartinJohnson 0:404dae88af71 4 * http://www.artekit.eu
MartinJohnson 0:404dae88af71 5 * Written by Ruben H. Meleca
MartinJohnson 0:404dae88af71 6
MartinJohnson 0:404dae88af71 7 ### demo.c
MartinJohnson 0:404dae88af71 8
MartinJohnson 0:404dae88af71 9 # This program is free software; you can redistribute it and/or modify
MartinJohnson 0:404dae88af71 10 # it under the terms of the GNU General Public License as published by
MartinJohnson 0:404dae88af71 11 # the Free Software Foundation; either version 2 of the License, or
MartinJohnson 0:404dae88af71 12 # (at your option) any later version.
MartinJohnson 0:404dae88af71 13 #
MartinJohnson 0:404dae88af71 14 # This program is distributed in the hope that it will be useful,
MartinJohnson 0:404dae88af71 15 # but WITHOUT ANY WARRANTY; without even the implied warranty of
MartinJohnson 0:404dae88af71 16 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
MartinJohnson 0:404dae88af71 17 # GNU General Public License for more details.
MartinJohnson 0:404dae88af71 18 #
MartinJohnson 0:404dae88af71 19 # You should have received a copy of the GNU General Public License
MartinJohnson 0:404dae88af71 20 # along with this program; if not, write to the Free Software
MartinJohnson 0:404dae88af71 21 # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
MartinJohnson 0:404dae88af71 22
MartinJohnson 0:404dae88af71 23 ***************************************************************************/
MartinJohnson 0:404dae88af71 24
MartinJohnson 0:404dae88af71 25 #include "stm32f30x.h"
MartinJohnson 0:404dae88af71 26 #include "sys.h"
MartinJohnson 0:404dae88af71 27 #include "video.h"
MartinJohnson 0:404dae88af71 28 #include "gdi.h"
MartinJohnson 0:404dae88af71 29 #include "string.h"
MartinJohnson 0:404dae88af71 30 //#include <stdlib.h>
MartinJohnson 0:404dae88af71 31
MartinJohnson 0:404dae88af71 32 extern volatile u32 sysTicks;
MartinJohnson 0:404dae88af71 33 int rndseed=0;
MartinJohnson 0:404dae88af71 34
MartinJohnson 0:404dae88af71 35 void srand(int i) {
MartinJohnson 0:404dae88af71 36 rndseed=i;
MartinJohnson 0:404dae88af71 37 }
MartinJohnson 0:404dae88af71 38
MartinJohnson 0:404dae88af71 39
MartinJohnson 0:404dae88af71 40 int rand() {
MartinJohnson 0:404dae88af71 41 return( ((rndseed = rndseed * 214013L + 2531011L) >> 16) &
MartinJohnson 0:404dae88af71 42 0x7fff );
MartinJohnson 0:404dae88af71 43 }
MartinJohnson 0:404dae88af71 44
MartinJohnson 0:404dae88af71 45 const u8 deBadBoys1[] = { 0x00, 0x00,
MartinJohnson 0:404dae88af71 46 0x00, 0x00,
MartinJohnson 0:404dae88af71 47 0x07, 0xc0,
MartinJohnson 0:404dae88af71 48 0x1f, 0xf0,
MartinJohnson 0:404dae88af71 49 0x3f, 0xf8,
MartinJohnson 0:404dae88af71 50 0x33, 0x98,
MartinJohnson 0:404dae88af71 51 0x3f, 0xf8,
MartinJohnson 0:404dae88af71 52 0x0c, 0x60,
MartinJohnson 0:404dae88af71 53 0x1b, 0xb0,
MartinJohnson 0:404dae88af71 54 0x30, 0x18,
MartinJohnson 0:404dae88af71 55 0x00, 0x00,
MartinJohnson 0:404dae88af71 56 0x00, 0x00 };
MartinJohnson 0:404dae88af71 57
MartinJohnson 0:404dae88af71 58 const u8 deBadBoys2[] = { 0x00, 0x00,
MartinJohnson 0:404dae88af71 59 0x00, 0x00,
MartinJohnson 0:404dae88af71 60 0x07, 0xc0,
MartinJohnson 0:404dae88af71 61 0x1f, 0xf0,
MartinJohnson 0:404dae88af71 62 0x3f, 0xf8,
MartinJohnson 0:404dae88af71 63 0x33, 0x98,
MartinJohnson 0:404dae88af71 64 0x3f, 0xf8,
MartinJohnson 0:404dae88af71 65 0x0c, 0x60,
MartinJohnson 0:404dae88af71 66 0x1b, 0xb0,
MartinJohnson 0:404dae88af71 67 0x0c, 0x60,
MartinJohnson 0:404dae88af71 68 0x00, 0x00,
MartinJohnson 0:404dae88af71 69 0x00, 0x00 };
MartinJohnson 0:404dae88af71 70 void conway_demo(void);
MartinJohnson 0:404dae88af71 71 void demoInit(void) {
MartinJohnson 0:404dae88af71 72
MartinJohnson 0:404dae88af71 73 i32 x, y, x1, y1, i, flip;
MartinJohnson 0:404dae88af71 74
MartinJohnson 0:404dae88af71 75
MartinJohnson 0:404dae88af71 76 // Demo Point
MartinJohnson 0:404dae88af71 77 while(1) {
MartinJohnson 0:404dae88af71 78 GPIOE->ODR=0x100;
MartinJohnson 0:404dae88af71 79 vidClearScreen();
MartinJohnson 0:404dae88af71 80 GPIOE->ODR=0x200;
MartinJohnson 0:404dae88af71 81 gdiRectangle(0,0,(VID_PIXELS_X - 1),VID_VSIZE - 1,0);
MartinJohnson 0:404dae88af71 82 GPIOE->ODR=0x300;
MartinJohnson 0:404dae88af71 83 gdiDrawTextEx(180, 40, "ARTEKIT", GDI_ROP_COPY);
MartinJohnson 0:404dae88af71 84 GPIOE->ODR=0x400;
MartinJohnson 0:404dae88af71 85 gdiDrawTextEx(161, 55, "AK-STM32-LKIT", GDI_ROP_COPY);
MartinJohnson 0:404dae88af71 86 gdiDrawTextEx(172, 70, "POINT DEMO", GDI_ROP_COPY);
MartinJohnson 0:404dae88af71 87 GPIOE->ODR=0x500;
MartinJohnson 0:404dae88af71 88 sysDelayMs(300);
MartinJohnson 0:404dae88af71 89 GPIOE->ODR=0x600;
MartinJohnson 0:404dae88af71 90 srand(sysTicks);
MartinJohnson 0:404dae88af71 91 for (i = 0; i < 950000; i++) {
MartinJohnson 0:404dae88af71 92 // sysDelayMs(1);
MartinJohnson 0:404dae88af71 93 x = rand(); x = x % (VID_PIXELS_X - 1);
MartinJohnson 0:404dae88af71 94 y = rand(); y = y % VID_VSIZE - 1;
MartinJohnson 0:404dae88af71 95 gdiPoint(NULL,x,y,GDI_ROP_XOR);
MartinJohnson 0:404dae88af71 96 }
MartinJohnson 0:404dae88af71 97 sysDelayMs(300);
MartinJohnson 0:404dae88af71 98 GPIOE->ODR=0x700;
MartinJohnson 0:404dae88af71 99
MartinJohnson 0:404dae88af71 100 conway_demo();
MartinJohnson 0:404dae88af71 101
MartinJohnson 0:404dae88af71 102 // Demo Line
MartinJohnson 0:404dae88af71 103
MartinJohnson 0:404dae88af71 104 vidClearScreen();
MartinJohnson 0:404dae88af71 105 gdiRectangle(0,0,(VID_PIXELS_X - 1),VID_VSIZE - 1,0);
MartinJohnson 0:404dae88af71 106 gdiDrawTextEx(180, 40, "ARTEKIT", GDI_ROP_COPY);
MartinJohnson 0:404dae88af71 107 gdiDrawTextEx(161, 55, "AK-STM32-LKIT", GDI_ROP_COPY);
MartinJohnson 0:404dae88af71 108 gdiDrawTextEx(175, 70, "LINE DEMO", GDI_ROP_COPY);
MartinJohnson 0:404dae88af71 109 sysDelayMs(300);
MartinJohnson 0:404dae88af71 110 srand(sysTicks);
MartinJohnson 0:404dae88af71 111 for (i = 0; i < 10000; i++) {
MartinJohnson 0:404dae88af71 112 // sysDelayMs(50);
MartinJohnson 0:404dae88af71 113 x = rand(); x = x % (VID_PIXELS_X - 1);
MartinJohnson 0:404dae88af71 114 y = rand(); y = y % VID_VSIZE - 1;
MartinJohnson 0:404dae88af71 115 x1 = rand(); x1 = x1 % (VID_PIXELS_X - 1);
MartinJohnson 0:404dae88af71 116 y1 = rand(); y1 = y1 % VID_VSIZE - 1;
MartinJohnson 0:404dae88af71 117 gdiLine(NULL,x,y,x1,y1,GDI_ROP_XOR);
MartinJohnson 0:404dae88af71 118 }
MartinJohnson 0:404dae88af71 119 sysDelayMs(300);
MartinJohnson 0:404dae88af71 120
MartinJohnson 0:404dae88af71 121 // Demo Square
MartinJohnson 0:404dae88af71 122
MartinJohnson 0:404dae88af71 123 vidClearScreen();
MartinJohnson 0:404dae88af71 124 gdiRectangle(0,0,(VID_PIXELS_X - 1),VID_VSIZE - 1,0);
MartinJohnson 0:404dae88af71 125 gdiDrawTextEx(180, 40, "ARTEKIT", GDI_ROP_COPY);
MartinJohnson 0:404dae88af71 126 gdiDrawTextEx(161, 55, "AK-STM32-LKIT", GDI_ROP_COPY);
MartinJohnson 0:404dae88af71 127 gdiDrawTextEx(157, 70, "RECTANGLE DEMO", GDI_ROP_COPY);
MartinJohnson 0:404dae88af71 128 sysDelayMs(300);
MartinJohnson 0:404dae88af71 129 srand(sysTicks);
MartinJohnson 0:404dae88af71 130 for (i = 0; i < 1000; i++) {
MartinJohnson 0:404dae88af71 131 // sysDelayMs(50);
MartinJohnson 0:404dae88af71 132 x = rand(); x = x % (VID_PIXELS_X - 1);
MartinJohnson 0:404dae88af71 133 y = rand(); y = y % VID_VSIZE - 1;
MartinJohnson 0:404dae88af71 134 x1 = rand(); x1 = x1 % 100;
MartinJohnson 0:404dae88af71 135 y1 = rand(); y1 = y1 % 100;
MartinJohnson 0:404dae88af71 136 gdiRectangle(x,y,x1,y1,GDI_ROP_COPY);
MartinJohnson 0:404dae88af71 137 }
MartinJohnson 0:404dae88af71 138 sysDelayMs(300);
MartinJohnson 0:404dae88af71 139
MartinJohnson 0:404dae88af71 140 // Demo Circle
MartinJohnson 0:404dae88af71 141
MartinJohnson 0:404dae88af71 142 vidClearScreen();
MartinJohnson 0:404dae88af71 143 gdiRectangle(0,0,(VID_PIXELS_X - 1),VID_VSIZE - 1,0);
MartinJohnson 0:404dae88af71 144 gdiDrawTextEx(180, 40, "ARTEKIT", GDI_ROP_COPY);
MartinJohnson 0:404dae88af71 145 gdiDrawTextEx(161, 55, "AK-STM32-LKIT", GDI_ROP_COPY);
MartinJohnson 0:404dae88af71 146 gdiDrawTextEx(165, 70, "CIRCLE DEMO", GDI_ROP_COPY);
MartinJohnson 0:404dae88af71 147 sysDelayMs(300);
MartinJohnson 0:404dae88af71 148 srand(sysTicks);
MartinJohnson 0:404dae88af71 149 for (i = 0; i < 500; i++) {
MartinJohnson 0:404dae88af71 150 // sysDelayMs(20);
MartinJohnson 0:404dae88af71 151 x = rand(); x = x % (VID_PIXELS_X - 1);
MartinJohnson 0:404dae88af71 152 y = rand(); y = y % VID_VSIZE - 1;
MartinJohnson 0:404dae88af71 153 x1 = rand(); x1 = x1 % 80;
MartinJohnson 0:404dae88af71 154 gdiCircle(x,y,x1,GDI_ROP_COPY);
MartinJohnson 0:404dae88af71 155 }
MartinJohnson 0:404dae88af71 156 sysDelayMs(300);
MartinJohnson 0:404dae88af71 157
MartinJohnson 0:404dae88af71 158 // Demo Bitmap
MartinJohnson 0:404dae88af71 159
MartinJohnson 0:404dae88af71 160 vidClearScreen();
MartinJohnson 0:404dae88af71 161 gdiRectangle(0,0,(VID_PIXELS_X - 1),VID_VSIZE - 1,0);
MartinJohnson 0:404dae88af71 162 gdiDrawTextEx(180, 40, "ARTEKIT", GDI_ROP_COPY);
MartinJohnson 0:404dae88af71 163 gdiDrawTextEx(161, 55, "AK-STM32-LKIT", GDI_ROP_COPY);
MartinJohnson 0:404dae88af71 164 gdiDrawTextEx(165, 70, "BITMAP DEMO", GDI_ROP_COPY);
MartinJohnson 0:404dae88af71 165 sysDelayMs(300);
MartinJohnson 0:404dae88af71 166
MartinJohnson 0:404dae88af71 167 x = 100;
MartinJohnson 0:404dae88af71 168 y = 130;
MartinJohnson 0:404dae88af71 169 flip = 0;
MartinJohnson 0:404dae88af71 170 for (i = 0; i < 100000; i++) {
MartinJohnson 0:404dae88af71 171 // sysDelayMs(150);
MartinJohnson 0:404dae88af71 172 x = rand(); x = x % (VID_PIXELS_X - 20);
MartinJohnson 0:404dae88af71 173 y = rand(); y = y % (VID_VSIZE - 20);
MartinJohnson 0:404dae88af71 174
MartinJohnson 0:404dae88af71 175 if (flip) {
MartinJohnson 0:404dae88af71 176 flip = 0;
MartinJohnson 0:404dae88af71 177 gdiBitBlt(NULL,x,y,15,12,(pu8) deBadBoys1,GDI_ROP_COPY);
MartinJohnson 0:404dae88af71 178 } else {
MartinJohnson 0:404dae88af71 179 flip = 1;
MartinJohnson 0:404dae88af71 180 gdiBitBlt(NULL,x,y,15,12,(pu8) deBadBoys2,GDI_ROP_COPY);
MartinJohnson 0:404dae88af71 181 }
MartinJohnson 0:404dae88af71 182 x += 2;
MartinJohnson 0:404dae88af71 183 }
MartinJohnson 0:404dae88af71 184 sysDelayMs(300);
MartinJohnson 0:404dae88af71 185 vidClearScreen();
MartinJohnson 0:404dae88af71 186 for (i = 0; i < 100000; i++) {
MartinJohnson 0:404dae88af71 187 // sysDelayMs(150);
MartinJohnson 0:404dae88af71 188 x = rand(); x = x % (VID_PIXELS_X - 20);
MartinJohnson 0:404dae88af71 189 y = rand(); y = y % (VID_VSIZE - 20);
MartinJohnson 0:404dae88af71 190
MartinJohnson 0:404dae88af71 191 if (flip) {
MartinJohnson 0:404dae88af71 192 flip = 0;
MartinJohnson 0:404dae88af71 193 gdiBitBlt(NULL,x,y,15,12,(pu8) deBadBoys1,GDI_ROP_XOR);
MartinJohnson 0:404dae88af71 194 } else {
MartinJohnson 0:404dae88af71 195 flip = 1;
MartinJohnson 0:404dae88af71 196 gdiBitBlt(NULL,x,y,15,12,(pu8) deBadBoys2,GDI_ROP_XOR);
MartinJohnson 0:404dae88af71 197 }
MartinJohnson 0:404dae88af71 198 x += 2;
MartinJohnson 0:404dae88af71 199 }
MartinJohnson 0:404dae88af71 200 sysDelayMs(3000);
MartinJohnson 0:404dae88af71 201
MartinJohnson 0:404dae88af71 202
MartinJohnson 0:404dae88af71 203 vidClearScreen();
MartinJohnson 0:404dae88af71 204 gdiRectangle(0,0,(VID_PIXELS_X - 1),VID_VSIZE - 1,0);
MartinJohnson 0:404dae88af71 205 gdiDrawTextEx(180, 40, "ARTEKIT", GDI_ROP_COPY);
MartinJohnson 0:404dae88af71 206 gdiDrawTextEx(161, 55, "AK-STM32-LKIT", GDI_ROP_COPY);
MartinJohnson 0:404dae88af71 207 gdiDrawTextEx(115, 75, "ARM CORTEX DEVELOPMENT BOARDS", GDI_ROP_COPY);
MartinJohnson 0:404dae88af71 208
MartinJohnson 0:404dae88af71 209 gdiDrawTextEx(156, 90, "WWW.ARTEKIT.EU", GDI_ROP_COPY);
MartinJohnson 0:404dae88af71 210 gdiDrawTextEx(141, 120, "FREE GRAPHIC ENGINE", GDI_ROP_COPY);
MartinJohnson 0:404dae88af71 211 gdiDrawTextEx(165, 130, "SOURCE CODE", GDI_ROP_COPY);
MartinJohnson 0:404dae88af71 212 sysDelayMs(300);
MartinJohnson 0:404dae88af71 213 }
MartinJohnson 0:404dae88af71 214
MartinJohnson 0:404dae88af71 215
MartinJohnson 0:404dae88af71 216 }
MartinJohnson 0:404dae88af71 217