OOStuBS - Technische Informatik II (TI-II)  2.4
cgascr.cc
gehe zur Dokumentation dieser Datei
1 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *\
2  * Technische Informatik II *
3  * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
4  * *
5  * C G A _ S C R E E N *
6  * *
7 \* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
8 
9 #include "machine/cgascr.h"
10 
11 CGA_Screen::CGA_Screen() : screen((ScreenChar(*)[80])memoryBase),
12  index_port(CGA_Screen::indexPortNum),
13  data_port(CGA_Screen::dataPortNum),
14  attribute(0x7){
15 
16  clear();
17 }
18 
20 
21 }
22 
23 void CGA_Screen::setpos (unsigned short x, unsigned short y) {
24  unsigned short pos;
25  unsigned short high, low;
26 
27  if (x >= COLUMNS || y > ROWS) return;
28 
29  pos = y * COLUMNS + x;
30  low = pos & 0xff;
31  high = (pos >> 8 ) & 0xff;
32 
33  /* Indexregister 14 (Cursor high) an Port INDEX_PORT ausgeben */
34  index_port.outb (14);
35  /* Datenregister an Port DATA_PORT schreiben */
36  data_port.outb (high);
37  /* Indexregister 15 (Cursor low) an Port INDEX_PORT ausgeben */
38  index_port.outb (15);
39  /* Datenregister an Port DATA_PORT schreiben */
40  data_port.outb (low);
41 }
42 
43 void CGA_Screen::getpos (unsigned short& x, unsigned short& y) const{
44  unsigned short pos;
45  unsigned char high, low;
46 
47  /* Indexregister 14 (Cursor high) an Port INDEX_PORT ausgeben */
48  index_port.outb (14);
49  /* Datenregister an Port DATA_PORT auslesen */
50  high = data_port.inb ();
51  /* Indexregister 15 (Cursor low) an Port INDEX_PORT ausgeben */
52  index_port.outb (15);
53  /* Datenregister an Port DATA_PORT auslesen */
54  low = data_port.inb ();
55 
56  pos = ((unsigned short)high) << 8 | low;
57  x = pos % COLUMNS;
58  y = pos / COLUMNS;
59 }
60 
61 void CGA_Screen::show (unsigned short x, unsigned short y, char character, unsigned char attrib) {
62 
63  if (x >= COLUMNS || y > ROWS) return;
64 
65  screen[y][x].c = character;
66  screen[y][x].attrib = attrib;
67 }
68 
69 void CGA_Screen::print (const char* string, unsigned int n) {
70  unsigned short x, y;
71  getpos (x, y);
72 
73  while (n) {
74  switch (*string) {
75  case '\n':
76  x = 0;
77  y++;
78  break;
79 
80  default:
81  show(x,y,*string, attribute);
82  x++;
83  if (x >= COLUMNS) {
84  x = 0;
85  y++;
86  }
87  break;
88  }
89 
90  string++;
91  if (y >= ROWS) {
92  scrollup ();
93  y--;
94  }
95  n--;
96  }
97  setpos (x, y);
98 }
99 
101 
102  for(unsigned short y=1;y<ROWS;y++){
103  for(unsigned short x=0;x<COLUMNS;x++){
104  show(x,y-1,screen[y][x].c, screen[y][x].attrib);
105  }
106  }
107 
108  for(unsigned short x=0;x<COLUMNS;x++){
109  show(x,ROWS-1,' ', attribute);
110  }
111 }
112 
113 
114 
115 void CGA_Screen::setAttributes(int fgColor, int bgColor, bool blink){
116  attribute = ((bgColor & 0x7) << 4) | (fgColor & 0xF);
117  if(blink)
118  attribute |= 0x80;
119  else
120  attribute &= ~0x80;
121 }
122 
124  for(unsigned short x=0; x<COLUMNS; x++){
125  for(unsigned short y=0; y<=ROWS; y++){
126  show(x, y, ' ', attribute);
127  }
128  }
129  setpos(0,0);
130 }