--- /dev/null
+/*\r
+ Screen.CPP version 1.0\r
+ by Robert Schmidt of Ztiff Zox Softwear 1993\r
+\r
+ Defines some primitives for handling the screen, some screen\r
+ buffer pointers, and the functions that handle the single\r
+ temporary screen used in TWEAK.\r
+\r
+*/\r
+\r
+#include <conio.h>\r
+#include <mem.h>\r
+#include <dos.h>\r
+#include <iostream.h>\r
+#include <stdlib.h>\r
+#include "Screen.HPP"\r
+\r
+char palette16[16];\r
+char palette256[768];\r
+\r
+// editHeight and editWidth hold the dimensions of the editing screen.\r
+// Not everything is formatted according to those horizontally, but\r
+// vertically it should work fine.\r
+\r
+unsigned editMode, editHeight, editWidth, editSize;\r
+\r
+// Now for the screens used in TWEAK.\r
+\r
+// This one points to the standard VGA text screen buffer. textscr[80]\r
+// addresses the first character/attribute pair on the second line\r
+// if the current mode is an 80-column one, for example.\r
+\r
+unsigned *textScr = (unsigned far *)MK_FP(0xb800,0);\r
+\r
+// graphScr points to the standard VGA graphics buffer, being 64Kb.\r
+\r
+char *graphScr = (char far *)MK_FP(0xa000,0);\r
+\r
+// setBiosMode() sets the given standard BIOS mode.\r
+\r
+void setBiosMode(int modeno)\r
+ {\r
+ _AX = modeno;\r
+ geninterrupt(0x10);\r
+ }\r
+\r
+// getBiosMode() returns the current BIOS mode.\r
+\r
+int getBiosMode(void)\r
+ {\r
+ _AH = 0x0f;\r
+ geninterrupt(0x10);\r
+ return _AL;\r
+ }\r
+\r
+// The following two functions saves and restores the temporary screen.\r
+// The tempScr buffer is allocated and destroyed each time.\r
+\r
+void tempBuffer::save(void)\r
+ {\r
+ if (temp)\r
+ delete[] temp;\r
+ if (!(temp = new unsigned[editSize]))\r
+ {\r
+ cout << "Out of memory for swap screen!" << endl;\r
+ exit(1);\r
+ }\r
+ memcpy(temp, link, sizeof(unsigned)*editSize);\r
+ }\r
+\r
+void tempBuffer::restore(void)\r
+ {\r
+ setBiosMode(3);\r
+ textmode(editMode);\r
+ if (temp)\r
+ {\r
+ memcpy(link, temp, sizeof(unsigned)*editSize);\r
+ delete[] temp;\r
+ temp = NULL;\r
+ }\r
+ }\r
+\r
+void getPalette16()\r
+ {\r
+ for (int c=0; c<16; c++)\r
+ {\r
+ outp(0x3c0, 0x20 | c);\r
+ palette16[c] = inp(0x3c0);\r
+ }\r
+ }\r
+\r
+void setEgaPalette(char *p)\r
+ {\r
+ inp(0x3da);\r
+ for (int c=0; c<16; c++)\r
+ {\r
+ outp(0x3c0, c);\r
+ outp(0x3c0, p[c]);\r
+ }\r
+ outp(0x3c0, 0x20);\r
+ }\r
+\r
+void setPalette16()\r
+ {\r
+ char egaPal[] = {0,1,2,3,4,5,0x14,7,0x38,0x39,0x3a,0x3b,0x3c,0x3d,0x3e,0x3f};\r
+ setEgaPalette(egaPal);\r
+ for (int c=0; c<16; c++)\r
+ {\r
+ outp(0x3c0, 0x20 | c);\r
+ outp(0x3c0, palette16[c]);\r
+ }\r
+ }\r
+\r
+void getPalette256()\r
+ {\r
+ outp(0x3c7, 0);\r
+ for (int c=0; c<768; c++)\r
+ palette256[c] = inp(0x3c9);\r
+ }\r
+\r
+void setPalette256()\r
+ {\r
+ char egaPal[] = {0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15};\r
+ setEgaPalette(egaPal);\r
+ outp(0x3c8, 0);\r
+ for (int c=0; c<768; c++)\r
+ outp(0x3c9, palette256[c]);\r
+ }\r
+\r
+void preparePalettes()\r
+ {\r
+ int m=getBiosMode();\r
+ setBiosMode(0x13);\r
+ getPalette256();\r
+ setBiosMode(0x12);\r
+ getPalette16();\r
+ setBiosMode(m);\r
+ }
\ No newline at end of file