OpenCores
URL https://opencores.org/ocsvn/pci/pci/trunk

Subversion Repositories pci

[/] [pci/] [tags/] [rel_11/] [apps/] [sw/] [driver/] [slide.c] - Blame information for rev 154

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 21 mihad
#include <sys/types.h>        
2
#include <sys/stat.h>        
3
#include <fcntl.h>  
4
#include <malloc.h>
5
#include <unistd.h>
6
#include <stdio.h>
7
#include <spartan_kint.h>
8
#include <sys/ioctl.h>
9
 
10
int main()
11
{
12
        int result ;
13
        int fd ;
14
        int i = 0;
15
        char buff[640*480] ;
16
        int palette[256] ;
17
        int c;
18
        unsigned long value ;
19
 
20
        fd = open("/dev/spartan", O_RDWR) ;
21
 
22
        if (fd < 0) {
23
                printf("Error: Opening device /dev/spartan\n");
24
                return fd ;
25
        }
26
 
27
        while (i < 54) {
28
                c = getchar();
29
                if (c == EOF)
30
                        error("Early end-of-file.");
31
                if ((i == 0) && (c != 0x42))
32
                        error("Not BMP format.");
33
                if ((i == 1) && (c != 0x4d))
34
                        error("Not BMP format.");
35
                if ((i == 2) && (c != 0x38))
36
                        error("Not 8-bit BMP format.");
37
                if ((i == 10) && (c != 0x36))
38
                        error("Not limited to 64 colors (6 bits).");
39
                if ((i == 11) && (c != 0x01))
40
                        error("Not limited to 64 colors (6 bits).");
41
                if ((i == 18) && (c != 0x80))
42
                        error("Not 640 pixels horizontal resolution.");
43
                if ((i == 19) && (c != 0x02))
44
                        error("Not 640 pixels horizontal resolution.");
45
                if ((i == 22) && (c != 0xe0))
46
                        error("Not 480 pixels vertical resolution.");
47
                if ((i == 23) && (c != 0x01))
48
                        error("Not 480 pixels vertical resolution.");
49
                i++;
50
        }
51
 
52
        // activate resource 2
53
        value = 0x00000002 ;
54
        result = ioctl(fd, SPARTAN_IOC_CURRESSET, value) ;
55
 
56
        /* Set palette */
57
        lseek(fd, SPARTAN_CRT_PALETTE_BASE, 0);
58
 
59
        while (i < 310) {
60
                if (c == EOF)
61
                        error("Early end-of-file.");
62
 
63
                palette[(i - 54)/4] = ((getchar() >> 4) << 12) | ((getchar() >> 4) << 8) | ((getchar() >> 4) << 4);
64
 
65
printf("%.4x\n", palette[(i - 54)/4]);
66
        getchar();
67
                i+=4;
68
        }
69
 
70
        while (i < 307510) {
71
                buff[sizeof(buff) - (i - 310)] =  (char)getchar();
72
                i++;
73
        }
74
 
75
        if(write(fd, palette, 0x400) != 0x400) {
76
                printf("Error writing device /dev/spartan\n");
77
                return -1;
78
        }
79
 
80
        ioctl(fd, SPARTAN_IOC_SET_VIDEO_BUFF, buff) ;
81
 
82
        close(fd);
83
        return 0;
84
}
85
 

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.