Implemented basic VGA routines
[reactos.git] / reactos / drivers / dd / vga / miniport / vgavideo.c
1 #include "vgavideo.h"
2
3 div_t div(int num, int denom)
4 {
5 div_t r;
6 if (num > 0 && denom < 0) {
7 num = -num;
8 denom = -denom;
9 }
10 r.quot = num / denom;
11 r.rem = num % denom;
12 if (num < 0 && denom > 0)
13 {
14 if (r.rem > 0)
15 {
16 r.quot++;
17 r.rem -= denom;
18 }
19 }
20 return r;
21 }
22
23 int mod(int num, int denom)
24 {
25 div_t dvt = div(num, denom);
26 return dvt.rem;
27 }
28
29 VOID vgaPreCalc()
30 {
31 ULONG j;
32
33 startmasks[1] = 127;
34 startmasks[2] = 63;
35 startmasks[3] = 31;
36 startmasks[4] = 15;
37 startmasks[5] = 7;
38 startmasks[6] = 3;
39 startmasks[7] = 1;
40 startmasks[8] = 255;
41
42 endmasks[0] = 128;
43 endmasks[1] = 192;
44 endmasks[2] = 224;
45 endmasks[3] = 240;
46 endmasks[4] = 248;
47 endmasks[5] = 252;
48 endmasks[6] = 254;
49 endmasks[7] = 255;
50 endmasks[8] = 255;
51
52 for(j=0; j<80; j++)
53 {
54 maskbit[j*8] = 128;
55 maskbit[j*8+1] = 64;
56 maskbit[j*8+2] = 32;
57 maskbit[j*8+3] = 16;
58 maskbit[j*8+4] = 8;
59 maskbit[j*8+5] = 4;
60 maskbit[j*8+6] = 2;
61 maskbit[j*8+7] = 1;
62
63 bit8[j*8] = 7;
64 bit8[j*8+1] = 6;
65 bit8[j*8+2] = 5;
66 bit8[j*8+3] = 4;
67 bit8[j*8+4] = 3;
68 bit8[j*8+5] = 2;
69 bit8[j*8+6] = 1;
70 bit8[j*8+7] = 0;
71 }
72 for(j=0; j<480; j++)
73 {
74 y80[j] = j*80;
75 }
76 for(j=0; j<640; j++)
77 {
78 xconv[j] = j >> 3;
79 }
80 }
81
82 void vgaSetWriteMode(char mode)
83 {
84 VideoPortWritePortUchar((PUCHAR)0x03ce, 0x03);
85 VideoPortWritePortUchar((PUCHAR)0x03cf, mode);
86 }
87
88 void vgaSetColor(int cindex, int red, int green, int blue)
89 {
90 VideoPortWritePortUchar((PUCHAR)0x03c8, cindex);
91 VideoPortWritePortUchar((PUCHAR)0x03c9, red);
92 VideoPortWritePortUchar((PUCHAR)0x03c9, green);
93 VideoPortWritePortUchar((PUCHAR)0x03c9, blue);
94 }