home *** CD-ROM | disk | FTP | other *** search
/ Best Objectech Shareware Selections / UNTITLED.iso / boss / grap / util / 020 / regtable.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1993-01-27  |  3.8 KB  |  157 lines

  1. /*
  2.     RegTable.CPP version 1.0
  3.     by Robert Schmidt of Ztiff Zox Softwear 1993
  4.  
  5.     Defines the member and friend functions of the RegisterTable class
  6.         declared in RegTable.HPP.
  7. */
  8.  
  9. #include <conio.h>
  10. #include <fstream.h>
  11. #include "Screen.hpp"
  12. #include "RegTable.hpp"
  13.  
  14.  
  15.  
  16. RegisterTable::RegisterTable(const char* fname)
  17.     {
  18.     // Open the file containing register descriptions
  19.     ifstream ins(fname);
  20.     // Read number of registers (first number in file)
  21.     ins >> registers;
  22.     // Allocate enough space
  23.     reg = new NamedRegister[registers];
  24.     // Read reg. descriptions
  25.     for (int i=0; i<registers; i++)
  26.         ins >> reg[i];
  27.     // Get current register configuration from VGA, and use as default
  28.     in();
  29.     prevSel = select = 0;
  30.     }
  31.  
  32. void RegisterTable::printCon(int r)
  33.     {
  34.     // This gotoxy divides the registers into two columns.
  35.     gotoxy(40*(r / editHeight) +1, r % editHeight +1);
  36.     // Optionally print the left cursor.
  37.     textattr(CURSOR_COLOR);
  38.     cprintf(r==select ? "\20" : " ");
  39.     // Then put out the meat.
  40.     reg[r].printCon();
  41.     // And possibly the right cursor.
  42.     textattr(CURSOR_COLOR);
  43.     cprintf(r==select ? "\21" : " ");
  44.     // This gotoxy just puts the hardware cursor where it won't distract you.
  45.     gotoxy(40*(r / editHeight)+38, r % editHeight +1);
  46.     }
  47.  
  48. void RegisterTable::printAllCon()
  49.     {
  50.     for (int r = 0; r < registers; r++)
  51.         printCon(r);
  52.     }
  53.  
  54. int RegisterTable::updateSelect()
  55.     {
  56.     if (select < 0)
  57.         select = registers - 1;
  58.     else
  59.         if (select >= registers)
  60.             select = 0;
  61.     if (prevSel != select)
  62.         {
  63.         printCon(prevSel);
  64.         prevSel = select;
  65.         }
  66.     printCon(select);
  67.     return select;
  68.     }
  69.  
  70. void RegisterTable::in()
  71.     {
  72.     for (int r = 0; r < registers; r++)
  73.         reg[r].in();
  74.     }
  75.  
  76. void RegisterTable::out()
  77.     {
  78.     // The next 5 lines are VGA specific
  79.     outportb(0x3d4,0x11);                // Ensure CRT regs. 0-7 are writable!
  80.     int v = inportb(0x3d5);                //    That is, clear bit 7 of port
  81.     v &= 0x7f;                            //    0x3D4, index 0x11.
  82.     outportb(0x3d4,0x11);
  83.     outportb(0x3d5,v);
  84.  
  85.     for (int r = 0; r < registers; r++)
  86.         if (reg[r].isEnabled())
  87.             reg[r].out();
  88.     }
  89.  
  90. /*
  91.     This istream operator >> reads an entire table of Register values
  92.     into 'this' table.
  93.     Notes:
  94.         The stream is read until good() is no longer true.  Not good
  95.             practice, but hey!
  96.         If the read Register's port and index pair is not found in 'this'
  97.             table, it is ignored.
  98.         In effect, only the *values* in the table may change after >>,
  99.             not port or index numbers.
  100. */
  101.  
  102. istream& operator>> (istream &in, RegisterTable &t)
  103.     {
  104.     int r = 0;
  105.     t.doDisable();                            // first disable all registers
  106.     while (in.good())
  107.         {
  108.         Register temp;
  109.         in >> temp;
  110.  
  111.         int prevr = r;
  112.  
  113.         //Search for the correct register position:
  114.         while (temp.getPort() != t.reg[r].getPort() ||
  115.             temp.getIndex() != t.reg[r].getIndex())
  116.             {
  117.             if (++r >= t.registers)
  118.                 r = 0;
  119.             if (r == prevr)                    // Have we looped around once?
  120.                 goto skip;                    //    Register not supported!
  121.             }
  122.         // Correct register found, now store the value and enable it.
  123.         t.reg[r].setValue(temp.getValue());
  124.         t.reg[r].doEnable();                // enable this single register
  125. skip:
  126.         }
  127.     return in;
  128.     }
  129.  
  130.  
  131. //    This operator << sends all enabled registers in t to the out stream.
  132.  
  133. ostream& operator<< (ostream &out, RegisterTable &t)
  134.     {
  135.     for (int r = 0; r < t.registers; r++)
  136.         if (t.reg[r].isEnabled())
  137.             out << Register(t.reg[r]);
  138.     return out;
  139.     }
  140.  
  141.  
  142. // RegisterTable::showBitMask() updates the bit pattern display with
  143. //    the value of selected register.  This is TWEAK specific.
  144.  
  145. void RegisterTable::showBitMask()
  146.     {
  147.     gotoxy(42,editHeight-4);
  148.     textattr(BITHEADER_COLOR);
  149.     cprintf("Bit mask: 7 6 5 4 3 2 1 0");
  150.     gotoxy(51,editHeight-3);
  151.     textattr(BITPATTERN_COLOR);
  152.     unsigned char v = reg[select].getValue();
  153.     for (int e=7; e>=0; e--)
  154.         cprintf( v&(1<<e) ? " 1" : " 0");
  155.     }
  156.  
  157.