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

Subversion Repositories orsoc_graphics_accelerator

[/] [orsoc_graphics_accelerator/] [trunk/] [sw/] [examples/] [bare/] [vgatest.c] - Blame information for rev 5

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 5 maiden
 
2
 
3
/* VGA defines */
4
#define VMEM           0x01f00000
5
 
6
#define VGA_BASEADDR   0x97000000
7
 
8
#define VGA_CTRL       0x000
9
#define VGA_STAT       0x004
10
#define VGA_HTIM       0x008
11
#define VGA_VTIM       0x00c
12
#define VGA_HVLEN      0x010
13
#define VGA_VBARA      0x014 /* Adress to Video Base Register A */
14
#define VGA_VBARB      0x018 /* Adress to Video Base Register B */
15
#define VGA_PALETTE    0x800
16
 
17
#define VGA_CTRL_VEN   0x00000001 /* Video Enable */
18
#define VGA_CTRL_HIE   0x00000002 /* HSync Interrupt Enable */
19
#define VGA_CTRL_PC    0x00000800 /* 8-bit Pseudo Color Enable*/
20
#define VGA_CTRL_CD8   0x00000000 /* Color Depth 8 */
21
#define VGA_CTRL_CD16  0x00000200 /* Color Depth 16 */
22
#define VGA_CTRL_CD24  0x00000400 /* Color Depth 24 */
23
#define VGA_CTRL_CD32  0x00000600 /* Color Depth 32 */
24
#define VGA_CTRL_VBL1  0x00000000 /* Burst Length 1 */
25
#define VGA_CTRL_VBL2  0x00000080 /* Burst Length 2 */
26
#define VGA_CTRL_VBL4  0x00000100 /* Burst Length 4 */
27
#define VGA_CTRL_VBL8  0x00000180 /* Burst Length 8 */
28
 
29
#define GFX_BASEADDR   0xB8000000
30
 
31
#define GFX_CTRL       0x000
32
#define GFX_STATUS     0x004
33
#define GFX_PIXEL0     0x008
34
#define GFX_PIXEL1     0x00c
35
#define GFX_COLOR      0x010
36
#define GFX_TARGET_BASE 0x014
37
#define GFX_TARGET_SIZE 0x018
38
 
39
/* Register access macros */
40
#define REG8(add) *((volatile unsigned char *)(add))
41
#define REG16(add) *((volatile unsigned short *)(add))
42
#define REG32(add) *((volatile unsigned long *)(add))
43
 
44
void Set640x480_60(void)
45
{
46
        // Set horizontal timing register
47
        REG32(VGA_BASEADDR+VGA_HTIM) = ((96 - 1) << 24) |
48
                      ((48 - 1) << 16) |
49
                      (640 - 1);
50
        // Set vertical timing register
51
        REG32(VGA_BASEADDR+VGA_VTIM) = ((2 - 1) << 24) |
52
                      ((31 - 1) << 16) |
53
                      (480 - 1);
54
        // Set total vertical and horizontal lenghts
55
        REG32(VGA_BASEADDR+VGA_HVLEN) = ((800 - 1) << 16) | (525 - 1);
56
 
57
        REG32(GFX_BASEADDR+GFX_TARGET_SIZE) = (640 << 16) | 480;
58
}
59
 
60
void Set800x600_60(void)
61
{
62
        // Set horizontal timing register
63
        REG32(VGA_BASEADDR+VGA_HTIM) = ((128 - 1) << 24) |
64
                      ((88 - 1) << 16) |
65
                      (800 - 1);
66
        // Set vertical timing register
67
        REG32(VGA_BASEADDR+VGA_VTIM) = ((4 - 1) << 24) |
68
                      ((23 - 1) << 16) |
69
                      (600 - 1);
70
        // Set total vertical and horizontal lenghts
71
        REG32(VGA_BASEADDR+VGA_HVLEN) = ((1056 - 1) << 16) | (628 - 1);
72
 
73
        REG32(GFX_BASEADDR+GFX_TARGET_SIZE) = (800 << 16) | 600;
74
}
75
 
76
void Set1024x768_60(void)
77
{
78
        // Set horizontal timing register
79
        REG32(VGA_BASEADDR+VGA_HTIM) = ((136 - 1) << 24) |
80
                      ((160 - 1) << 16) |
81
                      (1024 - 1);
82
        // Set vertical timing register
83
        REG32(VGA_BASEADDR+VGA_VTIM) = ((6 - 1) << 24) |
84
                      ((29 - 1) << 16) |
85
                      (768 - 1);
86
        // Set total vertical and horizontal lenghts
87
        REG32(VGA_BASEADDR+VGA_HVLEN) = ((1344 - 1) << 16) | (806 - 1);
88
 
89
        REG32(GFX_BASEADDR+GFX_TARGET_SIZE) = (1024 << 16) || 768;
90
}
91
 
92
void drawPixel(int x, int y, int color);
93
 
94
int main(void)
95
{
96
        // Reset VGA first
97
        REG32(VGA_BASEADDR+VGA_CTRL) = 0;
98
 
99
        // Set video mode
100
        Set640x480_60();
101
//      Set800x600_60();
102
 
103
        // Set color depth (start with 8bit grayscale!)
104
//       | VGA_CTRL_PC;
105
//       | VGA_CTRL_CD16;
106
//       | VGA_CTRL_CD24;
107
//       | VGA_CTRL_CD32;
108
 
109
        // Set base address for Video Base Register A
110
        REG32(VGA_BASEADDR+VGA_VBARA) = VMEM;
111
 
112
        // Set base address for Video Base Register B
113
        REG32(VGA_BASEADDR+VGA_VBARB) = VMEM;
114
 
115
        REG32(GFX_BASEADDR+GFX_TARGET_BASE) = VMEM;
116
 
117
        // Activate VGA
118
        REG32(VGA_BASEADDR+VGA_CTRL) = VGA_CTRL_VEN | VGA_CTRL_VBL8 | VGA_CTRL_CD16;
119
        REG32(GFX_BASEADDR+GFX_CTRL) = 6; // 16 bit cd
120
 
121
 
122
//      int z;  for(z=64000; z<100000; z+=4)
123
//      {
124
//      REG32(z) = 0x00ff00ff;
125
//      }
126
 
127
        // Write something to VGA
128
        int x, y;
129
        for(y=100; y<200; ++y)
130
        {
131
                for(x=50; x<100; x++)
132
                {
133
                        int addr = (y*320 + x)*4;
134
                        REG32(VMEM+addr) = 0xff00ff00;
135
                }
136
        }
137
 
138
 
139
        for(y=200; y<300; ++y)
140
                for(x=200; x<300; x+=2)
141
                        drawPixel(x,y,0xf800f800);
142
 
143
        while(1);
144
 
145
        return 0;
146
}
147
 
148
void drawPixel(int x, int y, int color)
149
{
150
        REG32(GFX_BASEADDR+GFX_PIXEL0) = (x << 16) | y;
151
        REG32(GFX_BASEADDR+GFX_COLOR) = color;
152
        REG32(GFX_BASEADDR+GFX_CTRL) |= 1;
153
        REG32(GFX_BASEADDR+GFX_CTRL) &= ~1;
154
}

powered by: WebSVN 2.1.0

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