Reverted latest changes.
[reactos.git] / reactos / ntoskrnl / kd / mda.c
1 /*
2 * ReactOS kernel
3 * Copyright (C) 1998, 1999, 2000, 2001 ReactOS Team
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18 */
19 /* $Id: mda.c,v 1.3 2002/09/08 10:23:27 chorns Exp $
20 *
21 * PROJECT: ReactOS kernel
22 * FILE: ntoskrnl/kd/mda.c
23 * PURPOSE: Support for debugging using an MDA card.
24 * PROGRAMMER: David Welch <welch@cwcom.net>
25 */
26
27 /* INCLUDES ******************************************************************/
28
29 #include <ddk/ntddk.h>
30 #include <internal/ntoskrnl.h>
31 #include <internal/kd.h>
32 #include <internal/mm.h>
33 #include <roscfg.h>
34 #include "../dbg/kdb.h"
35
36 /* VARIABLES ***************************************************************/
37
38 STATIC ULONG MdaIndexPort;
39 STATIC ULONG MdaValuePort;
40 STATIC ULONG MdaStatusPort;
41 STATIC ULONG MdaGfxPort;
42 STATIC ULONG MdaModePort;
43 STATIC PUSHORT VideoBuffer;
44
45 #define MDA_COLUMNS (80)
46 #define MDA_LINES (25)
47
48 STATIC ULONG MdaCursorX, MdaCursorY;
49
50 /* PRIVATE FUNCTIONS ********************************************************/
51
52 #if 0
53 VOID STATIC
54 KdWriteByteMDA(ULONG Reg, ULONG Value)
55 {
56 WRITE_PORT_UCHAR((PUCHAR)MdaIndexPort, (CHAR)Reg);
57 WRITE_PORT_UCHAR((PUCHAR)MdaValuePort, (CHAR)Value);
58 }
59
60 VOID STATIC
61 KdWriteWordMDA(ULONG Reg, ULONG Value)
62 {
63 WRITE_PORT_UCHAR((PUCHAR)MdaIndexPort, (CHAR)Reg);
64 WRITE_PORT_UCHAR((PUCHAR)MdaValuePort, (CHAR)(Value >> 8));
65 WRITE_PORT_UCHAR((PUCHAR)MdaIndexPort, (CHAR)(Reg + 1));
66 WRITE_PORT_UCHAR((PUCHAR)MdaValuePort, (CHAR)(Value & 0xFF));
67 }
68 #endif
69
70 VOID
71 KdInitializeMda(VOID)
72 {
73 /* Setup the variables for the various port addresses. */
74 MdaIndexPort = 0x3b4;
75 MdaValuePort = 0x3b5;
76 MdaModePort = 0x3b8;
77 MdaStatusPort = 0x3ba;
78 MdaGfxPort = 0x3bf;
79
80 VideoBuffer = (PUSHORT)(0xd0000000 + 0xb0000);
81
82 MdaCursorX = MdaCursorY = 0;
83 }
84
85 VOID STATIC
86 KdScrollMda(VOID)
87 {
88 memmove(&VideoBuffer[(MDA_COLUMNS * 0) + 0],
89 &VideoBuffer[(MDA_COLUMNS * 1) + 0],
90 MDA_COLUMNS * (MDA_LINES - 1) * 2);
91 memset(&VideoBuffer[(MDA_COLUMNS * (MDA_LINES - 1)) + 0], 0,
92 MDA_COLUMNS * 2);
93 }
94
95 VOID STATIC
96 KdPutCharMda(CHAR Ch)
97 {
98 if (Ch == '\n')
99 {
100 if (MdaCursorY == (MDA_LINES - 1))
101 {
102 KdScrollMda();
103 }
104 else
105 {
106 MdaCursorY++;
107 }
108 MdaCursorX = 0;
109 return;
110 }
111 VideoBuffer[(MdaCursorY * MDA_COLUMNS) + MdaCursorX] = (Ch & 0xFF) | 0x0700;
112 MdaCursorX++;
113 if (MdaCursorX == (MDA_COLUMNS - 1))
114 {
115 if (MdaCursorY == (MDA_LINES - 1))
116 {
117 KdScrollMda();
118 }
119 else
120 {
121 MdaCursorY++;
122 }
123 MdaCursorX = 0;
124 }
125 }
126
127 VOID
128 KdPrintMda(PCH pch)
129 {
130 while((*pch) != 0)
131 {
132 if ((*pch) == '\t')
133 {
134 KdPutCharMda(' ');
135 KdPutCharMda(' ');
136 KdPutCharMda(' ');
137 KdPutCharMda(' ');
138 }
139 if ((*pch) == '\r')
140 {
141 /* Nothing. */
142 }
143 else
144 {
145 KdPutCharMda(*pch);
146 }
147 pch++;
148 }
149 }
150
151 /* EOF */