]> 4ch.mooo.com Git - 16.git/blob - 16/tweak16/SCREEN.CPP
cleaned up the repo from debugging watcom2 ^^
[16.git] / 16 / tweak16 / SCREEN.CPP
1 /*\r
2         Screen.CPP version 1.0\r
3         by Robert Schmidt of Ztiff Zox Softwear 1993\r
4 \r
5         Defines some primitives for handling the screen, some screen\r
6                 buffer pointers, and the functions that handle the single\r
7                 temporary screen used in TWEAK.\r
8 \r
9 */\r
10 \r
11 #include <conio.h>\r
12 #include <mem.h>\r
13 #include <dos.h>\r
14 #include <iostream.h>\r
15 #include <stdlib.h>\r
16 #include "Screen.HPP"\r
17 \r
18 char palette16[16];\r
19 char palette256[768];\r
20 \r
21 // editHeight and editWidth hold the dimensions of the editing screen.\r
22 //      Not everything is formatted according to those horizontally, but\r
23 //      vertically it should work fine.\r
24 \r
25 unsigned editMode, editHeight, editWidth, editSize;\r
26 \r
27 // Now for the screens used in TWEAK.\r
28 \r
29 // This one points to the standard VGA text screen buffer.  textscr[80]\r
30 //      addresses the first character/attribute pair on the second line\r
31 //      if the current mode is an 80-column one, for example.\r
32 \r
33 unsigned *textScr = (unsigned far *)MK_FP(0xb800,0);\r
34 \r
35 // graphScr points to the standard VGA graphics buffer, being 64Kb.\r
36 \r
37 char *graphScr = (char far *)MK_FP(0xa000,0);\r
38 \r
39 // setBiosMode() sets the given standard BIOS mode.\r
40 \r
41 void setBiosMode(int modeno)\r
42         {\r
43         _AX = modeno;\r
44         geninterrupt(0x10);\r
45         }\r
46 \r
47 // getBiosMode() returns the current BIOS mode.\r
48 \r
49 int getBiosMode(void)\r
50         {\r
51         _AH = 0x0f;\r
52         geninterrupt(0x10);\r
53         return _AL;\r
54         }\r
55 \r
56 // The following two functions saves and restores the temporary screen.\r
57 //      The tempScr buffer is allocated and destroyed each time.\r
58 \r
59 void tempBuffer::save(void)\r
60         {\r
61         if (temp)\r
62                 delete[] temp;\r
63         if (!(temp = new unsigned[editSize]))\r
64                 {\r
65                 cout << "Out of memory for swap screen!" << endl;\r
66                 exit(1);\r
67                 }\r
68         memcpy(temp, link, sizeof(unsigned)*editSize);\r
69         }\r
70 \r
71 void tempBuffer::restore(void)\r
72         {\r
73         setBiosMode(3);\r
74         textmode(editMode);\r
75         if (temp)\r
76                 {\r
77                 memcpy(link, temp, sizeof(unsigned)*editSize);\r
78                 delete[] temp;\r
79                 temp = NULL;\r
80                 }\r
81         }\r
82 \r
83 void getPalette16()\r
84         {\r
85         for (int c=0; c<16; c++)\r
86                 {\r
87                 outp(0x3c0, 0x20 | c);\r
88                 palette16[c] = inp(0x3c0);\r
89                 }\r
90         }\r
91 \r
92 void setEgaPalette(char *p)\r
93         {\r
94         inp(0x3da);\r
95         for (int c=0; c<16; c++)\r
96                 {\r
97                 outp(0x3c0, c);\r
98                 outp(0x3c0, p[c]);\r
99                 }\r
100         outp(0x3c0, 0x20);\r
101         }\r
102 \r
103 void setPalette16()\r
104         {\r
105         char egaPal[] = {0,1,2,3,4,5,0x14,7,0x38,0x39,0x3a,0x3b,0x3c,0x3d,0x3e,0x3f};\r
106         setEgaPalette(egaPal);\r
107         for (int c=0; c<16; c++)\r
108                 {\r
109                 outp(0x3c0, 0x20 | c);\r
110                 outp(0x3c0, palette16[c]);\r
111                 }\r
112         }\r
113 \r
114 void getPalette256()\r
115         {\r
116         outp(0x3c7, 0);\r
117         for (int c=0; c<768; c++)\r
118                 palette256[c] = inp(0x3c9);\r
119         }\r
120 \r
121 void setPalette256()\r
122         {\r
123         char egaPal[] = {0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15};\r
124         setEgaPalette(egaPal);\r
125         outp(0x3c8, 0);\r
126         for (int c=0; c<768; c++)\r
127                 outp(0x3c9, palette256[c]);\r
128         }\r
129 \r
130 void preparePalettes()\r
131         {\r
132         int m=getBiosMode();\r
133         setBiosMode(0x13);\r
134         getPalette256();\r
135         setBiosMode(0x12);\r
136         getPalette16();\r
137         setBiosMode(m);\r
138         }