Demo of low res colour vga video for stm32f3 discovery board

Dependencies:   STM32F3-Discovery-minimal

Fork of Space_Invaders_Demo by Martin Johnson

demo.c

Committer:
MartinJohnson
Date:
2019-04-03
Revision:
17:833f1b69e11d
Parent:
14:3035b3271395

File content as of revision 17:833f1b69e11d:

/***************************************************************************
 * STM32 VGA demo
 
### demo.c
 
#   This program is free software; you can redistribute it and/or modify
#   it under the terms of the GNU General Public License as published by
#   the Free Software Foundation; either version 2 of the License, or
#   (at your option) any later version.
#
#   This program is distributed in the hope that it will be useful,
#   but WITHOUT ANY WARRANTY; without even the implied warranty of
#   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#   GNU General Public License for more details.
#
#   You should have received a copy of the GNU General Public License
#   along with this program; if not, write to the Free Software
#   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.

***************************************************************************/

#include "stm32f30x.h"
#include "sys.h"
#include "video.h"
#include "gdi.h"
#include "string.h"
//#include <stdlib.h>

extern volatile u32		sysTicks;
int rndseed=0;

void srand(int i) {
rndseed=i;
}


int rand() {
return( ((rndseed = rndseed * 214013L + 2531011L) >> 16) &
    0x7fff );
}

const u8	deBadBoys1[] = {	0x00, 0x00,
								0x00, 0x00,
								0x07, 0xc0,
								0x1f, 0xf0,
								0x3f, 0xf8,
								0x33, 0x98,
								0x3f, 0xf8,
								0x0c, 0x60,
								0x1b, 0xb0,
								0x30, 0x18,
								0x00, 0x00,
								0x00, 0x00 };

const u8	deBadBoys2[] = {	0x00, 0x00,
								0x00, 0x00,
								0x07, 0xc0,
								0x1f, 0xf0,
								0x3f, 0xf8,
								0x33, 0x98,
								0x3f, 0xf8,
								0x0c, 0x60,
								0x1b, 0xb0,
								0x0c, 0x60,
								0x00, 0x00,
								0x00, 0x00 };
void conway_demo(void);
void demoInit(void) {

i32		x, y, x1, y1, i, flip;


//	Demo Point
//while(1) {
	GPIOE->ODR|=0x100;
	vidClearScreen();
	GPIOE->ODR|=0x200;
	gdiRectangle(0,0,(VID_PIXELS_X - 1),VID_VSIZE - 1,0);
	GPIOE->ODR|=0x300;
	GPIOE->ODR|=0x400;
	gdiDrawTextEx(40, 55, "STM32F3 Discovery", GDI_ROP_COPY);
	gdiDrawTextEx(40, 70, "Point Demo", GDI_ROP_COPY);
	GPIOE->ODR|=0x500;
	vidNextBuffer();
	sysDelayMs(2000);
	GPIOE->ODR|=0x600;
	srand(sysTicks);
	for (i = 0; i < 950000; i++) {
//		sysDelayMs(1);
		x = rand();	x = x % (VID_PIXELS_X - 1);
		y = rand();	y = y % VID_VSIZE - 1;
		gdiSetColour(rand()%7+1);
		gdiPoint(NULL,x,y,GDI_ROP_XOR);
		if(i%20000==0)
			vidNextBuffer();
	}
	vidNextBuffer();
	sysDelayMs(300);
	GPIOE->ODR=0x700;

//	conway_demo();
	
//	if(GPIOA->IDR&1) bubble_demo();

//	Demo Line

	vidClearScreen();
	gdiRectangle(0,0,(VID_PIXELS_X - 1),VID_VSIZE - 1,0);
	gdiDrawTextEx(40, 55, "STM32F3 Discovery", GDI_ROP_COPY);
	gdiDrawTextEx(40, 70, "Line Demo", GDI_ROP_COPY);
	vidNextBuffer();
	sysDelayMs(300);
	srand(sysTicks);
	for (i = 0; i < 10000; i++) {
//		sysDelayMs(50);
		x = rand();	x = x % (VID_PIXELS_X - 1);
		y = rand();	y = y % VID_VSIZE - 1;
		x1 = rand();	x1 = x1 % (VID_PIXELS_X - 1);
		y1 = rand();	y1 = y1 % VID_VSIZE - 1;
		gdiSetColour(rand()%7+1);
		gdiLine(NULL,x,y,x1,y1,GDI_ROP_XOR);
		if(i%500==0)
			vidNextBuffer();
	}
	sysDelayMs(300);

//	Demo Square

	vidClearScreen();
	gdiRectangle(0,0,(VID_PIXELS_X - 1),VID_VSIZE - 1,0);
	gdiDrawTextEx(40, 55, "STM32F3 Discovery", GDI_ROP_COPY);
	gdiDrawTextEx(40, 70, "Rectangle Demo", GDI_ROP_COPY);
	vidNextBuffer();
	sysDelayMs(300);
	srand(sysTicks);
	for (i = 0; i < 8000; i++) {
//		sysDelayMs(50);
		x = rand();	x = x % (VID_PIXELS_X - 1);
		y = rand();	y = y % VID_VSIZE - 1;
		x1 = rand();	x1 = x1 % 100;
		y1 = rand();	y1 = y1 % 100;
		gdiSetColour(rand()%7+1);
		gdiRectangle(x,y,x1,y1,GDI_ROP_COPY);
		if(i%50==0)
			vidNextBuffer();

	}
	sysDelayMs(300);

//	Demo Circle

	vidClearScreen();
	gdiRectangle(0,0,(VID_PIXELS_X - 1),VID_VSIZE - 1,0);
	gdiDrawTextEx(40, 55, "STM32F3 Discovery", GDI_ROP_COPY);
	gdiDrawTextEx(40, 70, "Circle Demo", GDI_ROP_COPY);
	vidNextBuffer();
	sysDelayMs(300);
	srand(sysTicks);
	for (i = 0; i < 2000; i++) {
//		sysDelayMs(20);
		x = rand();	x = x % (VID_PIXELS_X - 1);
		y = rand();	y = y % VID_VSIZE - 1;
		x1 = rand(); x1 = x1 % 80;
		gdiSetColour(rand()%7+1);
		gdiCircle(x,y,x1,0);
		if(i%10==0)
			vidNextBuffer();
	}
	sysDelayMs(300);

//	Demo Bitmap

	vidClearScreen();
	gdiRectangle(0,0,(VID_PIXELS_X - 1),VID_VSIZE - 1,0);
	gdiDrawTextEx(40, 55, "STM32F3 Discovery", GDI_ROP_COPY);
	gdiDrawTextEx(40, 70, "Bitmap Demo", GDI_ROP_COPY);
	vidNextBuffer();
	sysDelayMs(300);

	x = 100;
	y = 130;
	flip = 0;
	for (i = 0; i < 10000; i++) {
//		sysDelayMs(150);
		x = rand();     x = x % (VID_PIXELS_X - 20);
                y = rand();     y = y % (VID_VSIZE - 20);

	gdiSetColour(rand()%7+1);
		if (flip) {
			flip = 0;
			gdiBitBlt(NULL,x,y,15,12,(pu8) deBadBoys1,GDI_ROP_COPY);
		} else {
			flip = 1;
			gdiBitBlt(NULL,x,y,15,12,(pu8) deBadBoys2,GDI_ROP_COPY);
		}
		x += 2;
		if(i%500==0)
			vidNextBuffer();
	}
	sysDelayMs(300);
	vidClearScreen();
	        for (i = 0; i < 10000; i++) {
//              sysDelayMs(150);
                x = rand();     x = x % (VID_PIXELS_X - 20);
                y = rand();     y = y % (VID_VSIZE - 20);
gdiSetColour(rand()%7+1);
                if (flip) {
                        flip = 0;
                        gdiBitBlt(NULL,x,y,15,12,(pu8) deBadBoys1,GDI_ROP_XOR);
                } else {
                        flip = 1;
                        gdiBitBlt(NULL,x,y,15,12,(pu8) deBadBoys2,GDI_ROP_XOR);
                }
                x += 2;
                		if(i%500==0)
			vidNextBuffer();
        }
        sysDelayMs(300);

	//conway_demo();
	//}


}