10 readyVgaRegs() does the initialization to make the VGA ready to
\r
11 accept any combination of configuration register settings.
\r
13 This involves enabling writes to index 0 to 7 of the CRT controller
\r
14 (port 0x3d4), by clearing the most significant bit (bit 7) of index
\r
18 void readyVgaRegs(void)
\r
21 outportb(0x3d4,0x11);
\r
22 v = inportb(0x3d5) & 0x7f;
\r
23 outportb(0x3d4,0x11);
\r
28 outReg sets a single register according to the contents of the
\r
29 passed Register structure.
\r
32 void outReg(Register r)
\r
36 /* First handle special cases: */
\r
39 inportb(STATUS_ADDR); /* reset read/write flip-flop */
\r
40 outportb(ATTRCON_ADDR, r.index | 0x20);
\r
41 /* ensure VGA output is enabled */
\r
42 outportb(ATTRCON_ADDR, r.value);
\r
46 case VGAENABLE_ADDR:
\r
47 outportb(r.port, r.value); /* directly to the port */
\r
53 default: /* This is the default method: */
\r
54 outportb(r.port, r.index); /* index to port */
\r
55 outportb(r.port+1, r.value);/* value to port+1 */
\r
62 outRegArray sets n registers according to the array pointed to by r.
\r
63 First, indexes 0-7 of the CRT controller are enabled for writing.
\r
66 void outRegArray(Register *r, int n)
\r
75 loadRegArray opens the given file, does some validity checking, then
\r
76 reads the entire file into an array of Registers, which is returned
\r
77 via the array parameter.
\r
79 You will probably want to provide your own error handling code in
\r
80 this function, as it never aborts the program, rather than just
\r
81 printing an error message and returning NULL.
\r
83 The returned value is the number of Registers read. The &array
\r
84 parameter is set to the allocated Register array.
\r
86 If you use this function, remember to free() the returned array
\r
87 pointer, as it was allocated dynamically using malloc() (unless NULL
\r
88 is returned, which designates an error)!
\r
91 int loadRegArray(char *fpath, RegisterPtr *array)
\r
97 if ((handle = open(fpath, O_BINARY | O_RDONLY)) == -1)
\r
98 /* error opening file */
\r
99 /* include your error handling code here */
\r
102 if ((fsize = filelength(handle)) == -1)
\r
103 /* error acquiring file size */
\r
105 if (fsize % sizeof(Register))
\r
107 printf("Illegal TWEAK file size: %s\n", fpath);
\r
110 regs = fsize / sizeof(Register);
\r
112 if (!(*array = (Register *)malloc(fsize)))
\r
114 printf("Out of memory allocating buffer for %s\n", fpath);
\r
117 if (read(handle, (void*)*array, fsize) == -1)
\r
118 /* error reading file */
\r
121 if (close(handle) == -1)
\r
123 /* error closing file */
\r
127 /* file read ok, return pointer to buffer */
\r
132 if (*array) free(*array);
\r