- Rearrange reactos.dff according to rosapps rearrange.
[reactos.git] / rosapps / sysutils / utils / pice / module / hercules.c
1 /*++
2
3 Copyright (c) 1998-2001 Klaus P. Gerlicher
4
5 Module Name:
6
7 hercules.c
8
9 Abstract:
10
11 HW dependent draw routines
12
13 Environment:
14
15 Kernel mode only
16
17 Author:
18
19 Klaus P. Gerlicher
20
21 Revision History:
22
23 04-Aug-1998: created
24 15-Nov-2000: general cleanup of source files
25
26 Copyright notice:
27
28 This file may be distributed under the terms of the GNU Public License.
29
30 --*/
31
32 ////////////////////////////////////////////////////
33 // INCLUDES
34 ////
35 #include "remods.h"
36 #include "precomp.h"
37
38 #include "charset.h"
39 #include "logo.h"
40
41 ////////////////////////////////////////////////////
42 // PROTOTYPES
43 ////
44
45 ////////////////////////////////////////////////////
46 // DEFINES
47 ////
48
49 ////////////////////////////////////////////////////
50 // GLOBALS
51 ////
52 // cursor state
53 BOOLEAN bRev=FALSE;
54
55 // HERCULES graphics adapter stuff
56 // 43 line graphics mode
57 UCHAR MGATable43[]={53,45,46, 7,96, 2,91,91, 2, 3, 0, 0, 0, 0, 0, 0};
58
59 PUCHAR pVgaOffset[4];
60 // END of HERCULES graphics adapter stuff
61
62 // used for HERCULES graphics mode
63 WINDOW wWindowHercGraph[4]=
64 {
65 {1,3,1,0,FALSE},
66 {5,6,1,0,FALSE},
67 {12,19,1,0,FALSE},
68 {32,12,1,0,FALSE}
69 };
70 // used for HERCUELS text and VGA text mode
71 WINDOW wWindowHerc[4]=
72 {
73 {1,3,1,0,FALSE},
74 {5,4,1,0,FALSE},
75 {10,9,1,0,FALSE},
76 {20,4,1,0,FALSE}
77 };
78
79 PUCHAR pScreenBufferHercules;
80
81 struct _attr
82 {
83 union
84 {
85 struct
86 {
87
88 UCHAR fgcol : 4;
89 UCHAR bkcol : 3;
90 UCHAR blink : 1;
91 }bits;
92 UCHAR Asuchar;
93 }u;
94 }attr;
95
96 //*************************************************************************
97 // SetForegroundColorVga()
98 //
99 //*************************************************************************
100 void SetForegroundColorHercules(ECOLORS col)
101 {
102 attr.u.bits.fgcol = col;
103 attr.u.bits.blink = 0;
104 }
105
106 //*************************************************************************
107 // SetBackgroundColorVga()
108 //
109 //*************************************************************************
110 void SetBackgroundColorHercules(ECOLORS col)
111 {
112 attr.u.bits.bkcol = col;
113 attr.u.bits.blink = 0;
114 }
115
116 //*************************************************************************
117 // PrintGrafHercules()
118 //
119 //*************************************************************************
120 void PrintGrafHercules(ULONG x,ULONG y,UCHAR c)
121 {
122 ULONG i;
123 PUCHAR p;
124 ULONG _line = y<<3;
125
126 if(!pScreenBufferHercules)
127 return;
128
129 p=&cGraphTable[(ULONG)c<<3];
130
131 if((attr.u.bits.bkcol == COLOR_FOREGROUND && attr.u.bits.fgcol == COLOR_BACKGROUND) ||
132 (attr.u.bits.bkcol == COLOR_CAPTION && attr.u.bits.fgcol == COLOR_TEXT) )
133 for(i=0 ;i<8 ;i++,_line++)
134 {
135 *(PUCHAR)(pVgaOffset[_line & 0x3] + ( 90* (_line >> 2) ) + x) = ~*p++;
136 }
137 else
138 for(i=0 ;i<8 ;i++,_line++)
139 {
140 *(PUCHAR)(pVgaOffset[_line & 0x3] + ( 90* (_line >> 2) ) + x) = *p++;
141 }
142 }
143
144
145 //*************************************************************************
146 // FlushHercules()
147 //
148 //*************************************************************************
149 void FlushHercules(void)
150 {
151 }
152
153 //*************************************************************************
154 // ShowCursor()
155 //
156 // show hardware cursor
157 //*************************************************************************
158 void ShowCursorHercules(void)
159 {
160 ENTER_FUNC();
161
162 bCursorEnabled=TRUE;
163
164 LEAVE_FUNC();
165 }
166
167 //*************************************************************************
168 // HideCursorHercules()
169 //
170 // hide hardware cursor
171 //*************************************************************************
172 void HideCursorHercules(void)
173 {
174 ENTER_FUNC();
175
176 bCursorEnabled=FALSE;
177
178 LEAVE_FUNC();
179 }
180
181 //*************************************************************************
182 // CopyLineTo()
183 //
184 // copy a line from src to dest
185 //*************************************************************************
186 void CopyLineToHercules(USHORT dest,USHORT src)
187 {
188 USHORT i,j;
189 PULONG pDest,pSrc;
190
191 ENTER_FUNC();
192
193 dest <<= 3;
194 src <<= 3;
195 for(i=0;i<8;i++)
196 {
197 (PUCHAR)pDest = (PUCHAR)pScreenBufferHercules + ( ( ( dest+i )&3) <<13 )+ 90 * ((dest+i) >> 2);
198 (PUCHAR)pSrc = (PUCHAR)pScreenBufferHercules + ( ( ( src+i )&3) <<13 )+ 90 * ((src+i) >> 2);
199 for(j=0;j<(GLOBAL_SCREEN_WIDTH>>2);j++)
200 {
201 *pDest++=*pSrc++;
202 }
203 }
204
205 LEAVE_FUNC();
206 }
207
208 //*************************************************************************
209 // InvertLineHercules()
210 //
211 // invert a line on the screen
212 //*************************************************************************
213 void InvertLineHercules(ULONG line)
214 {
215 ULONG i,j;
216 ULONG _line = line<<3;
217 PUSHORT p;
218
219 //ENTER_FUNC();
220
221 for(j=0;j<8;j++)
222 {
223 p=(PUSHORT)( pVgaOffset[_line&3] + (90*(_line>>2)) );
224 for(i=0;i<(GLOBAL_SCREEN_WIDTH>>1);i++)
225 {
226 p[i]=~p[i];
227 }
228 _line++;
229 }
230
231 //LEAVE_FUNC();
232 }
233
234 //*************************************************************************
235 // HatchLineHercules()
236 //
237 // hatches a line on the screen
238 //*************************************************************************
239 void HatchLineHercules(ULONG line)
240 {
241 USHORT cc;
242 ULONG i,j;
243 ULONG _line = (line<<3) ;
244 PUSHORT p;
245 USHORT mask_odd[]={0x8888,0x2222};
246 USHORT mask_even[]={0xaaaa,0x5555};
247 PUSHORT pmask;
248
249 ENTER_FUNC();
250
251 pmask = (line&1)?mask_odd:mask_even;
252
253 for(j=0;j<8;j++,_line++)
254 {
255 p=(PUSHORT)( pVgaOffset[_line&3] + (90*(_line>>2)) );
256 for(i=0;i<(GLOBAL_SCREEN_WIDTH/sizeof(USHORT));i++)
257 {
258 cc = p[i];
259
260 p[i]=(p[i]^pmask[j&1])|cc;
261 }
262 }
263
264 LEAVE_FUNC();
265 }
266
267 //*************************************************************************
268 // ClrLineHercules()
269 //
270 // clear a line on the screen
271 //*************************************************************************
272 void ClrLineHercules(ULONG line)
273 {
274 ULONG j;
275 BOOLEAN bTemplateLine=( (USHORT)line==wWindow[DATA_WINDOW].y-1 ||
276 (USHORT)line==wWindow[SOURCE_WINDOW].y-1 ||
277 (USHORT)line==wWindow[OUTPUT_WINDOW].y-1 ||
278 0);
279 ULONG _line = line<<3;
280 ULONG cc=0;
281 PUCHAR p;
282
283 // ENTER_FUNC();
284
285 if(line > GLOBAL_SCREEN_HEIGHT )
286 {
287 DPRINT((0,"ClrLineHercules(): line %u is out of screen\n",line));
288 //LEAVE_FUNC();
289 return;
290 }
291
292 if(attr.u.bits.bkcol == COLOR_CAPTION && attr.u.bits.fgcol == COLOR_TEXT )
293 cc=~cc;
294
295 if(bTemplateLine)
296 {
297 for(j=0;j<8;j++,_line++)
298 {
299 p = (PUCHAR)(pVgaOffset[_line&3] + (90*(_line>>2)) );
300
301 /*
302 if(j==2 || j==5)cc=0xFF;
303 else if(j==3)cc=0xaa;
304 else if(j==4)cc=0x55;
305 else cc = 0;*/
306 if(j==2 || j==5)cc=0xFF;
307 else cc = 0;
308
309 PICE_memset(p,(UCHAR)cc,GLOBAL_SCREEN_WIDTH);
310 }
311 }
312 else
313 {
314 for(j=0;j<8;j++,_line++)
315 {
316 p = (PUCHAR)(pVgaOffset[_line&3] + (90*(_line>>2)) );
317
318 PICE_memset(p,(UCHAR)cc,GLOBAL_SCREEN_WIDTH);
319 }
320 }
321 //LEAVE_FUNC();
322 }
323
324 //*************************************************************************
325 // PrintLogoHercules()
326 //
327 //*************************************************************************
328 void PrintLogoHercules(BOOLEAN bShow)
329 {
330 LONG x,y;
331 PUCHAR p;
332
333 p=(PUCHAR)pScreenBufferHercules;
334 for(y=0;y<24;y++)
335 {
336 for(x=0;x<8;x++)
337 {
338 p[ ( 0x2000* (( y + 8 ) & 0x3) )+
339 ( 90* ( (y + 8 ) >> 2) )+
340 (81+x)] = cLogo[y*8+x];
341 }
342 }
343 }
344
345 //*************************************************************************
346 // PrintCursorHercules()
347 //
348 // emulate a blinking cursor block
349 //*************************************************************************
350 void PrintCursorHercules(BOOLEAN bForce)
351 {
352 static ULONG count=0;
353
354 if( (bForce) || ((count++>100) && bCursorEnabled) )
355 {
356 ULONG i;
357 ULONG x,y;
358 ULONG _line;
359
360 x=wWindow[OUTPUT_WINDOW].usCurX;
361 y=wWindow[OUTPUT_WINDOW].y+wWindow[OUTPUT_WINDOW].usCurY;
362
363 _line = y<<3;
364 for(i=0;i<8;i++,_line++)
365 {
366 *(PUCHAR)(pVgaOffset[_line & 0x3] + ( 90* (_line >> 2) ) + x) ^= 0xFF ;
367 }
368 bRev=!bRev;
369 count=0;
370 }
371
372 KeStallExecutionProcessor(2500);
373 }
374
375 //*************************************************************************
376 // SaveGraphicsHercules()
377 //
378 //*************************************************************************
379 void SaveGraphicsStateHercules(void)
380 {
381 // not implemented
382 }
383
384 //*************************************************************************
385 // RestoreGraphicsStateHercules()
386 //
387 //*************************************************************************
388 void RestoreGraphicsStateHercules(void)
389 {
390 // not implemented
391 }
392
393 //*************************************************************************
394 // ConsoleInitHercules()
395 //
396 // init terminal screen
397 //*************************************************************************
398 BOOLEAN ConsoleInitHercules(void)
399 {
400 BOOLEAN bResult = FALSE;
401 PUCHAR pMGATable = MGATable43;
402 UCHAR i,reg,data;
403 PHYSICAL_ADDRESS FrameBuffer;
404
405 ENTER_FUNC();
406
407 ohandlers.CopyLineTo = CopyLineToHercules;
408 ohandlers.PrintGraf = PrintGrafHercules;
409 ohandlers.Flush = FlushHercules;
410 ohandlers.ClrLine = ClrLineHercules;
411 ohandlers.InvertLine = InvertLineHercules;
412 ohandlers.HatchLine = HatchLineHercules;
413 ohandlers.PrintLogo = PrintLogoHercules;
414 ohandlers.PrintCursor = PrintCursorHercules;
415 ohandlers.SaveGraphicsState = SaveGraphicsStateHercules;
416 ohandlers.RestoreGraphicsState = RestoreGraphicsStateHercules;
417 ohandlers.ShowCursor = ShowCursorHercules;
418 ohandlers.HideCursor = HideCursorHercules;
419 ohandlers.SetForegroundColor = SetForegroundColorHercules;
420 ohandlers.SetBackgroundColor = SetBackgroundColorHercules;
421
422 ihandlers.GetKeyPolled = KeyboardGetKeyPolled;
423 ihandlers.FlushKeyboardQueue = KeyboardFlushKeyboardQueue;
424
425 // init HERCULES adapter
426 outb_p(0,0x3b8);
427 outb_p(0x03,0x3bf);
428 for(i=0;i<sizeof(MGATable43);i++)
429 {
430 reg=i;
431 outb_p(reg,0x3b4);
432 data=pMGATable[i];
433 outb_p(data,0x3b5);
434 }
435 outb_p(0x0a,0x3b8);
436
437 SetWindowGeometry(wWindowHercGraph);
438
439 GLOBAL_SCREEN_WIDTH = 90;
440 GLOBAL_SCREEN_HEIGHT = 45;
441
442 attr.u.Asuchar = 0x07;
443 FrameBuffer.u.LowPart = 0xb0000;
444 pScreenBufferHercules=MmMapIoSpace(FrameBuffer,FRAMEBUFFER_SIZE,MmNonCached);
445
446 DPRINT((0,"VGA memory phys. 0xb0000 mapped to virt. 0x%x\n",pScreenBufferHercules));
447
448 if(pScreenBufferHercules)
449 {
450 for(i=0;i<4;i++)
451 {
452 pVgaOffset[i] = (PUCHAR)pScreenBufferHercules+0x2000*i;
453 DPRINT((0,"VGA offset %u = 0x%.8X\n",i,pVgaOffset[i]));
454 }
455 bResult = TRUE;
456
457 PICE_memset(pScreenBufferHercules,0x0,FRAMEBUFFER_SIZE);
458
459 EmptyRingBuffer();
460
461 DPRINT((0,"ConsoleInitHercules() SUCCESS!\n"));
462 }
463
464 LEAVE_FUNC();
465
466 return bResult;
467 }
468
469 //*************************************************************************
470 // ConsoleShutdownHercules()
471 //
472 // exit terminal screen
473 //*************************************************************************
474 void ConsoleShutdownHercules(void)
475 {
476 ENTER_FUNC();
477
478 // HERC video off
479 outb_p(0,0x3b8);
480 outb_p(0,0x3bf);
481
482 if(pScreenBufferHercules)
483 MmUnmapIoSpace(pScreenBufferHercules,FRAMEBUFFER_SIZE);
484
485 LEAVE_FUNC();
486 }