]> 4ch.mooo.com Git - 16.git/blobdiff - 16/tweak16/EXAMPLE2.C
added tweak16 for experiments
[16.git] / 16 / tweak16 / EXAMPLE2.C
diff --git a/16/tweak16/EXAMPLE2.C b/16/tweak16/EXAMPLE2.C
new file mode 100755 (executable)
index 0000000..ff3d327
--- /dev/null
@@ -0,0 +1,81 @@
+/*\r
+       Example2.C version 1.0\r
+       by Robert Schmidt of Ztiff Zox Softwear 1993\r
+\r
+       Example of making use of a TWEAK file by linking its contents in\r
+       with the program.  This program doesn't need any external files at\r
+       run time.\r
+*/\r
+\r
+#include <mem.h>\r
+#include <dos.h>\r
+#include <alloc.h>\r
+#include <conio.h>\r
+#include "TwkUser.h"\r
+\r
+/*     The following included file defines the Mode320x240 table of Registers.\r
+       The file should be created by running\r
+       TWEAK2C 320x240.256 320x240.c Mode320x240 */\r
+\r
+#include "320x240.c"\r
+\r
+main()\r
+       {\r
+       int y, lastMode;\r
+\r
+       cprintf("This example program was compiled with the C version of a TWEAK\n\r");\r
+       cprintf("register file, and so will not need the external file.\n\r");\r
+       cprintf("The C array is now used to set Mode X (320x240x256).\n\rPress any key.");\r
+       getch();\r
+\r
+       /* Save the number of the current BIOS mode, so we can restore it\r
+          later. */\r
+\r
+       _AH = 0x0f;\r
+       geninterrupt(0x10);\r
+       lastMode = _AL;\r
+\r
+       /* Set mode 13h, to make sure the EGA palette set is correct for a 256\r
+          color mode */\r
+\r
+       _AX = 0x13;\r
+       geninterrupt(0x10);\r
+\r
+       /* Note that no initialization is neccessary now.  The Register array\r
+          is linked in as global data, and is directly accessible.  Take\r
+          note of the way the number of Register elements in the array is\r
+          calculated: */\r
+\r
+       outRegArray(Mode320x240, sizeof(Mode320x240)/sizeof(Register));\r
+\r
+       outpw(0x3c4, 0x0f02);   /* Enable all 4 planes */\r
+\r
+       /* Fill the screen with a blend of red and blue lines, defining the\r
+          palette on the fly. */\r
+\r
+       outp(0x3c8, 0);                                 /* start with color 0 */\r
+       for (y = 0; y<240; y++)\r
+               {\r
+               outp(0x3c9, y>>2);                      /* red component */\r
+               outp(0x3c9, 0);                         /* green component */\r
+               outp(0x3c9, (256-y) >> 2);      /* blue component */\r
+               memset((char*)MK_FP(0xa000,0) + y*80, y, 80);\r
+               }\r
+\r
+       /* The picture is drawn, so wait for user to get tired of it. */\r
+\r
+       getch();\r
+\r
+       /* Restore the saved mode number.  Borland's textmode() won't work, as the\r
+          C library still thinks we're in the mode it detected at startup.\r
+          The palette will be set to the BIOS mode's default. */\r
+\r
+       _AX = lastMode;\r
+       geninterrupt(0x10);\r
+\r
+\r
+       /* Also note that since the array is static, global data, there is\r
+          no pointer to free(), as was done in Example1.C */\r
+\r
+       return 0;\r
+       }\r