2 Example1.C version 1.5
\r
3 by Robert Schmidt of Ztiff Zox Softwear 1993
\r
5 Example of making use of a TWEAK file by loading it directly at
\r
6 run-time. This program needs the file(s) created by TWEAK
\r
7 available at run-time.
\r
14 #include "TwkUser.h" /* declares the neccessary functions and types */
\r
18 /* Define the pointer that should point to the loaded array of
\r
19 Registers, and the int to hold its size */
\r
26 cprintf("This example program loads a TWEAK register file at run-time\n\r");
\r
27 cprintf("and uses this to set Mode X (320x240x256).\n\rPress any key.");
\r
30 /* Now use the loadRegArray function declared in TwkUser.h to load the
\r
31 TWEAK file. Memory is automatically allocated. Note that the
\r
32 second argument is the address of the pointer defined above!
\r
33 The returned value is the number of Register elements loaded. */
\r
35 rsize = loadRegArray("320x240.256", &rarray);
\r
37 /* Save the number of the current BIOS mode, so we can restore it
\r
44 /* Set mode 13h, to make sure the EGA palette set is correct for a 256
\r
50 /* rarray now points to the loaded array. The second argument to
\r
51 outRegArray is the number if Register elements in the array. */
\r
53 outRegArray(rarray, rsize);
\r
55 outpw(0x3c4, 0x0f02); /* Enable all 4 planes */
\r
57 /* Fill the screen with a blend of pink and green lines, defining the
\r
58 palette on the fly. */
\r
60 outp(0x3c8, 0); /* start with color 0 */
\r
61 for (y = 0; y<240; y++)
\r
63 outp(0x3c9, y>>2); /* red component */
\r
64 outp(0x3c9, (256-y) >> 2); /* green component */
\r
65 outp(0x3c9, y>>2); /* blue component */
\r
66 memset((char*)MK_FP(0xa000,0) + y*80, y, 80);
\r
69 /* The mode is now set, so wait for the user to press a key...
\r
70 Nothing much interesting to look at, I'm afraid. */
\r
74 /* Restore the saved mode number. Borland's textmode() won't work, as the
\r
75 C library still thinks we're in the mode it detected at startup.
\r
76 The palette will be set to the BIOS mode's default. */
\r
81 /* Free the Register array allocated in loadRegArray. *You* are
\r
82 responsible for doing this! */
\r