summaryrefslogtreecommitdiffstats
path: root/private/ntos/nthals/halflex/xxdisp.c
blob: 2722c3223430962227dbbcf79762c42f9f390dce (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
/*++

Copyright (c) 1991  Microsoft Corporation

Module Name:

    jxdisp.c

Abstract:

    This module implements the HAL display initialization and output routines
    for a MIPS R3000 or R4000 Jazz system.

Author:

    Andre Vachon    (andreva) 09-May-1992
    David N. Cutler (davec)   27-Apr-1991
    Michael D. Kinney         30-Apr-1995

Environment:

    Kernel mode

Revision History:

--*/

#include "halp.h"

#define CSI 0x9b
#define MAX_DISPLAY_BUFFER 256

int    sprintf();

extern ULONG IoSpaceAlreadyMapped;

static UCHAR DisplayInitializationString[] = {CSI,'3','7',';','4','4','m',CSI,'2','J',0};
static UCHAR CarriageReturnString[]        = {10,13,0};

static ULONG HalOwnsDisplay      = FALSE;
static ULONG DisplayFile;

static UCHAR DisplayBuffer[MAX_DISPLAY_BUFFER];
static ULONG DisplayBufferInitialized = FALSE;

PHAL_RESET_DISPLAY_PARAMETERS HalpResetDisplayParameters;


VOID
HalAcquireDisplayOwnership (
    IN PHAL_RESET_DISPLAY_PARAMETERS  ResetDisplayParameters
    )

/*++

Routine Description:

    This routine switches ownership of the display away from the HAL to
    the system display driver. It is called when the system has reached
    a point during bootstrap where it is self supporting and can output
    its own messages. Once ownership has passed to the system display
    driver any attempts to output messages using HalDisplayString must
    result in ownership of the display reverting to the HAL and the
    display hardware reinitialized for use by the HAL.

Arguments:

    ResetDisplayParameters - if non-NULL the address of a function
    the hal can call to reset the video card.  The function returns
    TRUE if the display was reset.

Return Value:

    None.

--*/

{
    HalpAllocateArcsResources();
    ArcClose(DisplayFile);
    HalpFreeArcsResources();
    HalOwnsDisplay = FALSE;
    HalpResetDisplayParameters = ResetDisplayParameters;
    return;
}


VOID
HalDisplayString (
    PUCHAR String
    )

/*++

Routine Description:

    This routine displays a character string on the display screen.

Arguments:

    String - Supplies a pointer to the characters that are to be displayed.

Return Value:

    None.

--*/

{
    ULONG Count;
    ULONG i;

    if (DisplayBufferInitialized==FALSE) {
        DisplayBufferInitialized = TRUE;
        strcpy(DisplayBuffer,"");
    }

    if (IoSpaceAlreadyMapped == FALSE) {
        if ((strlen(DisplayBuffer)+strlen(String)) < MAX_DISPLAY_BUFFER) {
            strcat(DisplayBuffer,String);
        }
        return;
    }

    if (HalOwnsDisplay==FALSE) {

        if (HalpResetDisplayParameters != NULL) {
            (HalpResetDisplayParameters)(80,25);
        }

        HalpResetX86DisplayAdapter();

        HalpAllocateArcsResources();

        ArcOpen(ArcGetEnvironmentVariable("ConsoleOut"),ArcOpenWriteOnly,&DisplayFile);
        ArcWrite(DisplayFile,DisplayInitializationString,strlen(DisplayInitializationString),&Count);
        if (strlen(DisplayBuffer)!=0) {

            for(i=0;i<strlen(DisplayBuffer);i++) {
                switch (DisplayBuffer[i]) {
                    case '\n' : ArcWrite(DisplayFile,CarriageReturnString,strlen(CarriageReturnString),&Count);
                                break;
                    default   : ArcWrite(DisplayFile,&(DisplayBuffer[i]),1,&Count);
                                break;
                }
            }

            strcpy(DisplayBuffer,"");
        }

        HalpFreeArcsResources();

        HalOwnsDisplay=TRUE;

    }

    HalpAllocateArcsResources();

    for(i=0;i<strlen(String);i++) {
        switch (String[i]) {
            case '\n' : ArcWrite(DisplayFile,CarriageReturnString,strlen(CarriageReturnString),&Count);
                        break;
            default   : ArcWrite(DisplayFile,&(String[i]),1,&Count);
                        break;
        }
    }

    HalpFreeArcsResources();

    return;
}


VOID
HalQueryDisplayParameters (
    OUT PULONG WidthInCharacters,
    OUT PULONG HeightInLines,
    OUT PULONG CursorColumn,
    OUT PULONG CursorRow
    )

/*++

Routine Description:

    This routine return information about the display area and current
    cursor position.

Arguments:

    WidthInCharacter - Supplies a pointer to a varible that receives
        the width of the display area in characters.

    HeightInLines - Supplies a pointer to a variable that receives the
        height of the display area in lines.

    CursorColumn - Supplies a pointer to a variable that receives the
        current display column position.

    CursorRow - Supplies a pointer to a variable that receives the
        current display row position.

Return Value:

    None.

--*/

{
    ARC_DISPLAY_STATUS *DisplayStatus;

    //
    // Get the display parameter values and return.
    //

    //
    // If the HAL does not already own the display, then print an empty string.
    // This guarantees that the file descriptor DisplayFile is valid.
    //

    if (!HalOwnsDisplay) {
        HalDisplayString("");
    }

    //
    // Make firmware call to get the display's current status
    //

    HalpAllocateArcsResources();

    DisplayStatus = ArcGetDisplayStatus(DisplayFile);

    HalpFreeArcsResources();

    *WidthInCharacters = DisplayStatus->CursorMaxXPosition;
    *HeightInLines     = DisplayStatus->CursorMaxYPosition;
    *CursorColumn      = DisplayStatus->CursorXPosition;
    *CursorRow         = DisplayStatus->CursorYPosition;

    return;
}

VOID
HalSetDisplayParameters (
    IN ULONG CursorColumn,
    IN ULONG CursorRow
    )

/*++

Routine Description:

    This routine set the current cursor position on the display area.

Arguments:

    CursorColumn - Supplies the new display column position.

    CursorRow - Supplies a the new display row position.

Return Value:

    None.

--*/

{
    CHAR  SetCursorPositionString[20];
    ULONG Count;

    //
    // If the HAL does not already own the display, then print an empty string.
    // This guarantees that the file descriptor DisplayFile is valid.
    //

    if (!HalOwnsDisplay) {
        HalDisplayString("");
    }

    //
    // Build ANSI sequence to set the cursor position.
    //

    sprintf(SetCursorPositionString,"%c%d;%dH",CSI,CursorRow,CursorColumn);

    HalpAllocateArcsResources();

    ArcWrite(DisplayFile,SetCursorPositionString,strlen(SetCursorPositionString),&Count);

    HalpFreeArcsResources();
  
    return;
}