2 RegTable.CPP version 1.0
\r
3 by Robert Schmidt of Ztiff Zox Softwear 1993
\r
5 Defines the member and friend functions of the RegisterTable class
\r
6 declared in RegTable.HPP.
\r
10 //#include <conio.h>
\r
11 #include "RegTable.hpp"
\r
14 RegisterTable::RegisterTable(istream &ins)
\r
16 // Read number of registers (first number in file)
\r
18 // Allocate enough space
\r
19 reg = new NamedRegister[registers];
\r
20 // Read reg. descriptions
\r
21 for (int i=0; i<registers; i++)
\r
23 // Get current register configuration from VGA, and use as default
\r
28 void RegisterTable::in()
\r
30 for (int r = 0; r < registers; r++)
\r
34 void RegisterTable::out()
\r
36 outportb(0x3d4,0x11); // Ensure CRT regs. 0-7 are writable!
\r
37 int v = inportb(0x3d5); // That is, clear bit 7 of port
\r
38 v &= 0x7f; // 0x3D4, index 0x11.
\r
39 outport(0x3d4,0x11 | (v << 8));
\r
41 // outport(0x3c4, 0x0100); // reset sequencer
\r
43 for (int r = 0; r < registers; r++)
\r
44 if (reg[r].isEnabled())
\r
47 // outport(0x3c4, 0x0300); // re-reset sequencer
\r
48 outportb(0x3c0, 0x20); // Reenable display data
\r
52 This istream operator >> reads an entire table of Register values
\r
55 The stream is read until good() is no longer true. Not good
\r
57 If the read Register's port and index pair is not found in 'this'
\r
58 table, it is ignored.
\r
59 In effect, only the *values* in the table may change after >>,
\r
60 not port or index numbers.
\r
63 istream& operator>> (istream &in, RegisterTable &t)
\r
66 t.doDisable(); // first disable all registers
\r
74 //Search for the correct register position:
\r
75 while (temp.getPort() != t.reg[r].getPort() ||
\r
76 temp.getIndex() != t.reg[r].getIndex())
\r
78 if (++r >= t.registers)
\r
80 if (r == prevr) // Have we looped around once?
\r
81 goto skip; // Register not supported!
\r
83 // Correct register found, now store the value and enable it.
\r
84 t.reg[r].setValue(temp.getValue());
\r
85 t.reg[r].doEnable(); // enable this single register
\r
92 // This operator << sends all enabled registers in t to the out stream.
\r
94 ostream& operator<< (ostream &out, RegisterTable &t)
\r
96 for (int r = 0; r < t.registers; r++)
\r
97 if (t.reg[r].isEnabled())
\r
98 out << Register(t.reg[r]);
\r
102 void RegisterTable::doEnable()
\r
104 for (int r=0; r<registers; r++)
\r
108 void RegisterTable::doDisable()
\r
110 for (int r=0; r<registers; r++)
\r
111 reg[r].doDisable();
\r
115 Register *RegisterTable::getRegister(unsigned p, unsigned char i)
\r
117 for (int r = 0; r < registers; ++r)
\r
118 if (reg[r].getPort() == p && reg[r].getIndex() == i)
\r