Code:
#include <stdio.h>
#include <system.h>
#include "altera_avalon_pio_regs.h"
//Color definitions
#define black 0
#define blue 1
#define green 2
#define cyan 3
#define red 4
#define magenta 5
#define yellow 6
#define white 7
//print_pix function
unsigned int x;
unsigned int y;
unsigned int rgb;
//Print_hline/print_vline
unsigned int x_start;
unsigned int y_start;
unsigned int length;
//Print_character function
unsigned int pix_count = 64;
unsigned int size = 8;
unsigned int n = 0;
unsigned int bg_rgb;
char character;
//Value for pixel-memory
int rgb_value;
//Arrays for the characters A/B/C
int A[64] = {0,0,0,1,1,0,0,0,0,0,1,0,0,1,0,0,0,1,0,0,0,0,1,0,0,1,0,0,0,0,1,0,0,1,1,1,1,1,1,0,0,1,0,0,0,0,1,0,0,1,0,0,0,0,1,0,0,1,0,0,0,0,1,0};
int B[64] = {0,0,1,1,0,0,0,0,0,0,1,0,1,0,0,0,0,0,1,0,1,0,0,0,0,0,1,1,0,0,0,0,0,0,1,0,1,0,0,0,0,0,1,0,1,0,0,0,0,0,1,0,1,0,0,0,0,0,1,1,0,0,0,0};
int C[64] = {0,0,0,0,1,1,0,0,0,0,0,1,0,0,0,0,0,0,1,0,0,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,1,1,0,0};
//Print's a pixel
void print_pixel (alt_u16 x, alt_u16 y, alt_u8 rgb)
{
// The value (color) that will be written to an address
IOWR(VGA_DATA_W_BASE, 0, rgb);
// The address that the value will be written on
IOWR(VGA_ADRESS_W_BASE, 0, x + y * 320);
// Writes to picture-memory
IOWR(VGA_CONTROL_W_BASE, 0, 1);
// When written, stop writing to picture-memory
IOWR(VGA_CONTROL_W_BASE, 0, 0);
}
//Print horizontal line
void print_hline (alt_u16 x_start, alt_u16 y_start, alt_u16 length, alt_u8 rgb)
{
for(x = x_start; x <= x_start + length; x++)
print_pixel(x+x_start,y_start,rgb);
}
//Prints a vertical line
void print_vline (alt_u16 x_start, alt_u16 y_start, alt_u16 length, alt_u8 rgb)
{
for(y = y_start; y <= y_start + length; y++)
print_pixel(x_start,y+y_start,rgb);
}
//Prints a character (A/B/C only)
void print_chararcter (alt_u16 x, alt_u16 y, alt_u8 rgb, alt_u8 bg_rgb, char character)
{
//Start while-loop if both true
while ((pix_count > 0) && (character == 'C')){
while (size > 0){
//If Character is = 1, then print with the rgb color
if (C [n] == 1){
print_pixel(x, y, rgb);
}
//If Character is = 0, then print with the bg_rgb color
else{
print_pixel(x, y, bg_rgb);
}
pix_count = pix_count - 1;
size = size - 1;
n++;
x++;
}
x = x - 8;
size = 8;
y++;
}
}
// Read pixel-ram value
int read_pixel_ram_int (alt_u16 x_start, alt_u16 y_start)
{
//Store value in rgb_value
int rgb_value;
//Pix_nr =x+y*320
IOWR(VGA_ADRESS_W_BASE, 0, x + y * 320);
//When written, stop writing to picture-memory
IOWR(VGA_CONTROL_W_BASE,0,0);
//The color that will be read.
rgb_value=IORD_ALTERA_AVALON_PIO_DATA(VGA_DATA_R_BASE);
//Return the value
return rgb_value;
}
int main(){
//Example print_xxxxx (X,Y,LENGTH,COLOR,CHARACTER);
print_pixel(23,23,cyan);
print_pixel(23,24,green);
print_pixel(23,25,red);
print_pixel(24,24,magenta);
print_hline(50,50,320,yellow);
print_hline(10,5,200,blue);
print_vline(77,20,239, magenta);
print_vline(78,20,100, white);
rgb_value = read_pixel_ram_int(23,23);
print_chararcter(150,100,4,blue,'C');
printf("Pixel value: %d",&rgb_value);
However there is a part of it which i did not make myself entierly and would be happy if anyone could describe this part of code for me since the person who wrote that part is out of contact for a while...
Code:
unsigned char a[8][8] = {
{0,0,0,1,1,0,0,0},
{0,0,1,0,0,1,0,0},
{0,1,0,0,0,0,1,0},
{0,1,0,0,0,0,1,0},
{0,1,1,1,1,1,1,0},
{0,1,0,0,0,0,1,0},
{0,1,0,0,0,0,1,0},
{0,1,0,0,0,0,1,0},
};
This is supposed to represent the letter "A"