Jspice3
vgacolor.c
Go to the documentation of this file.
1 /*************************************************************************
2  MFB graphics and miscellaneous library
3  Copyright (c) Stephen R. Whiteley 1992
4  Author: Stephen R. Whiteley
5  *************************************************************************/
6 
7 #include <dos.h>
8 
9 #if __GNUC__
10 #define inp inportb
11 #define outp outportb
12 #define outpw outportw
13 #endif
14 
15 void
16 vga_get_color(num, red, green, blue)
17 
18 /* get DAC register */
19 int num, *red, *green, *blue;
20 {
21  if (num > 255 || num < 0) return;
22  outp(0x3c7,num); /* write index */
23  while (!(inp(0x3da) & 0x8)) ; /* wait for V retrace */
24  *red = inp(0x3c9); /* read rgb */
25  *green = inp(0x3c9);
26  *blue = inp(0x3c9);
27 }
28 
29 
30 void
31 vga_set_color(num, red, green, blue)
32 
33 /* set DAC register */
34 int num, red, green, blue;
35 {
36  if (num > 255 || num < 0) return;
37  outp(0x3c8,num); /* write index */
38  while (!(inp(0x3da) & 0x8)) ; /* wait for V retrace */
39  outp(0x3c9,red); /* write rgb */
40  outp(0x3c9,green);
41  outp(0x3c9,blue);
42 }
43 
44 
45 void
47 
48 /* get block of DAC registers */
49 char (*p)[3];
50 int i, n;
51 {
52  int j;
53 
54  if (i+n > 256 || i < 0 || n < 0) return;
55  outp(0x3c4,1); /* sequencer clock mode */
56  outp(0x3c5,0x21); /* blank the display */
57  outp(0x3c7,i); /* write index */
58  for (j = 0; j < n; j++) {
59  p[j][0] = inp(0x3c9); /* read rgb */
60  p[j][1] = inp(0x3c9);
61  p[j][2] = inp(0x3c9);
62  }
63  outp(0x3c5,0x1); /* turn display on */
64 }
65 
66 
67 void
69 /* set block of DAC registers */
70 
71 char (*p)[3];
72 int i, n;
73 {
74  int j;
75 
76  if (i+n > 256 || i < 0 || n < 0) return;
77  outp(0x3c4,1); /* sequencer clock mode */
78  outp(0x3c5,0x21); /* blank the display */
79  outp(0x3c8,i); /* write index */
80  for (j = 0; j < n; j++) {
81  outp(0x3c9,p[j][0]); /* write rgb */
82  outp(0x3c9,p[j][1]);
83  outp(0x3c9,p[j][2]);
84  }
85  outp(0x3c5,0x1); /* turn display on */
86 }
87 
88 
89 void
91 
92 /* get 16 entry palette register block */
93 char *p;
94 {
95  int j;
96 
97  while (!(inp(0x3da) & 0x8)) ; /* wait for V retrace */
98  for (j = 0; j < 16; j++) {
99  outp(0x3c0,j); /* index, enable xfer */
100  p[j] = inp(0x3c1); /* read data */
101  inp(0x3da); /* reset to address mode */
102  outp(0x3c0,j | 0x20); /* index, enable EGA */
103  inp(0x3da); /* reset to address mode */
104  }
105 }
106 
107 
108 void
110 
111 /* set 16 entry palette register block */
112 char *p;
113 {
114  int j;
115 
116  while (!(inp(0x3da) & 0x8)) ; /* wait for V retrace */
117  for (j = 0; j < 16; j++) {
118  outp(0x3c0,j); /* index, enable xfer */
119  outp(0x3c0,p[j]); /* write data */
120  inp(0x3da); /* reset to address mode */
121  outp(0x3c0,j | 0x20); /* index, enable EGA */
122  inp(0x3da); /* reset to address mode */
123  }
124 }
void vga_get_color(int num, int *red, int *green, int *blue)
Definition: vgacolor.c:16
void vga_get_cblock(char *p, int i, int n)
Definition: vgacolor.c:46
void vga_set_cblock(char *p, int i, int n)
Definition: vgacolor.c:68
Definition: cddefs.h:215
void vga_set_cpblock(char *p)
Definition: vgacolor.c:109
void vga_set_color(int num, int red, int green, int blue)
Definition: vgacolor.c:31
void vga_get_cpblock(char *p)
Definition: vgacolor.c:90