OpenCores
URL https://opencores.org/ocsvn/thor/thor/trunk

Subversion Repositories thor

[/] [thor/] [trunk/] [software/] [FMTK/] [source/] [kernel/] [console.c] - Blame information for rev 23

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 23 robfinch
#include "types.h"
2
#include "proto.h"
3
 
4
// The text screen memory can only handle half-word transfers, hence the use
5
// of memsetH, memcpyH.
6
 
7
extern int IOFocusNdx;
8
 
9
short int *GetScreenLocation()
10
{
11
      return GetJCBPtr()->pVidMem;
12
}
13
 
14
short int GetCurrAttr()
15
{
16
      return GetJCBPtr()->NormAttr;
17
}
18
 
19
void SetCurrAttr(short int attr)
20
{
21
     GetJCBPtr()->NormAttr = attr & 0xFFFFFC00;
22
}
23
 
24
static pascal void SetVideoReg(int regno, int val)
25
{
26
     if (regno < 0 or regno > 11) {
27
         printf("bad video regno: %d", regno);
28
         return;
29
     }
30
     asm {
31
         lw   r1,32[bp]
32
         lw   r2,40[bp]
33
         shli  r1,r1,#2
34
         sh    r2,zs:$FFDA0000[r1]
35
     }
36
}
37
 
38
void SetCursorPos(int row, int col)
39
{
40
    JCB *j;
41
 
42
    j = GetJCBPtr();
43
    j->CursorCol = col;
44
    j->CursorRow = row;
45
    UpdateCursorPos();
46
}
47
 
48
void SetCursorCol(int col)
49
{
50
    JCB *j;
51
 
52
    j = GetJCBPtr();
53
    j->CursorCol = col;
54
    UpdateCursorPos();
55
}
56
 
57
int GetCursorPos()
58
{
59
    JCB *j;
60
 
61
    j = GetJCBPtr();
62
    return j->CursorCol | (j->CursorRow << 8);
63
}
64
 
65
int GetTextCols()
66
{
67
    return GetJCBPtr()->VideoCols;
68
}
69
 
70
int GetTextRows()
71
{
72
    return GetJCBPtr()->VideoRows;
73
}
74
 
75
char AsciiToScreen(char ch)
76
{
77
     if (ch==0x5B)
78
         return 0x1B;
79
     if (ch==0x5D)
80
         return 0x1D;
81
     ch &= 0xFF;
82
     ch |= 0x100;
83
     if (!(ch & 0x20))
84
         return ch;
85
     if (!(ch & 0x40))
86
         return ch;
87
     ch = ch & 0x19F;
88
     return ch;
89
}
90
 
91
char ScreenToAscii(char ch)
92
{
93
     ch &= 0xFF;
94
     if (ch==0x1B)
95
        return 0x5B;
96
     if (ch==0x1D)
97
        return 0x5D;
98
     if (ch < 27)
99
        ch += 0x60;
100
     return ch;
101
}
102
 
103
 
104
void UpdateCursorPos()
105
{
106
    JCB *j;
107
    int pos;
108
 
109
    j = GetJCBPtr();
110
//    if (j == IOFocusNdx) {
111
       pos = j->CursorRow * j->VideoCols + j->CursorCol;
112
       SetVideoReg(11,pos);
113
//    }
114
}
115
 
116
void HomeCursor()
117
{
118
    JCB *j;
119
 
120
    j = GetJCBPtr();
121
    j->CursorCol = 0;
122
    j->CursorRow = 0;
123
    UpdateCursorPos();
124
}
125
 
126
short int *CalcScreenLocation()
127
{
128
    JCB *j;
129
    int pos;
130
 
131
    j = GetJCBPtr();
132
    pos = j->CursorRow * j->VideoCols + j->CursorCol;
133
//    if (j == IOFocusNdx) {
134
       SetVideoReg(11,pos);
135
//    }
136
    return GetScreenLocation()+pos;
137
}
138
 
139
void ClearScreen()
140
{
141
     short int *p;
142
     int nn;
143
     int mx;
144
     JCB *j;
145
     short int vc;
146
 
147
     j = GetJCBPtr();
148
     p = GetScreenLocation();
149
     // Compiler did a byte multiply generating a single byte result first
150
     // before assigning it to mx. The (int) casts force the compiler to use
151
     // an int result.
152
     mx = (int)j->VideoRows * (int)j->VideoCols;
153
     vc = GetCurrAttr() | AsciiToScreen(' ');
154
     memsetH(p, vc, mx);
155
}
156
 
157
void ClearBmpScreen()
158
{
159
     memsetW(0x400000, 0, 0x80000);
160
}
161
 
162
void BlankLine(int row)
163
{
164
     short int *p;
165
     int nn;
166
     int mx;
167
     JCB *j;
168
     short int vc;
169
 
170
     j = GetJCBPtr();
171
     p = GetScreenLocation();
172
     p = p + (int)j->VideoCols * row;
173
     vc = GetCurrAttr() | AsciiToScreen(' ');
174
     memsetH(p, vc, j->VideoCols);
175
}
176
 
177
// ScrollUp will call BlankLine. Scrollup is written in assembler for
178
// performance reasons and is included as part of the video BIOS. Note the
179
// BIOS cannot be called with SYS #10 because the bios isn't re-entrant and
180
// the bios is already active from putch().
181
naked ScrollUp()
182
{
183
     asm {
184
                 addui  sp,sp,#-8
185
             sws        c1,[sp]
186
         bsr   VBScrollUp
187
                 lws    c1,[sp]
188
                 addui  sp,sp,#8
189
         rts
190
     }
191
}
192
 
193
void IncrementCursorRow()
194
{
195
     JCB *j;
196
 
197
     j = GetJCBPtr();
198
     j->CursorRow++;
199
     if (j->CursorRow < j->VideoRows) {
200
         UpdateCursorPos();
201
         return;
202
     }
203
     j->CursorRow--;
204
     UpdateCursorPos();
205
     ScrollUp();
206
}
207
 
208
void IncrementCursorPos()
209
{
210
     JCB *j;
211
 
212
     j = GetJCBPtr();
213
     j->CursorCol++;
214
     if (j->CursorCol < j->VideoCols) {
215
         UpdateCursorPos();
216
         return;
217
     }
218
     j->CursorCol = 0;
219
     IncrementCursorRow();
220
}
221
 
222
void DisplayChar(char ch)
223
{
224
     short int *p;
225
     int nn;
226
     JCB *j;
227
 
228
     j = GetJCBPtr();
229
     switch(ch) {
230
     case '\r':  j->CursorCol = 0; UpdateCursorPos(); break;
231
     case '\n':  IncrementCursorRow(); break;
232
     case 0x91:
233
          if (j->CursorCol < j->VideoCols-1) {
234
             j->CursorCol++;
235
             UpdateCursorPos();
236
          }
237
          break;
238
     case 0x90:
239
          if (j->CursorRow > 0) {
240
               j->CursorRow--;
241
               UpdateCursorPos();
242
          }
243
          break;
244
     case 0x93:
245
          if (j->CursorCol > 0) {
246
               j->CursorCol--;
247
               UpdateCursorPos();
248
          }
249
          break;
250
     case 0x92:
251
          if (j->CursorRow < j->VideoRows-1) {
252
             j->CursorRow++;
253
             UpdateCursorPos();
254
          }
255
          break;
256
     case 0x94:
257
          if (j->CursorCol==0)
258
             j->CursorRow = 0;
259
          j->CursorCol = 0;
260
          UpdateCursorPos();
261
          break;
262
     case 0x99:  // delete
263
          p = CalcScreenLocation();
264
          for (nn = j->CursorCol; nn < j->VideoCols-1; nn++) {
265
              p[nn-j->CursorCol] = p[nn+1-j->CursorCol];
266
          }
267
          p[nn-j->CursorCol] = GetCurrAttr() | AsciiToScreen(' ');
268
          break;
269
     case 0x08: // backspace
270
          if (j->CursorCol > 0) {
271
              j->CursorCol--;
272
              p = CalcScreenLocation();
273
              for (nn = j->CursorCol; nn < j->VideoCols-1; nn++) {
274
                  p[nn-j->CursorCol] = p[nn+1-j->CursorCol];
275
              }
276
              p[nn-j->CursorCol] = GetCurrAttr() | AsciiToScreen(' ');
277
          }
278
          break;
279
     case 0x0C:   // CTRL-L
280
          ClearScreen();
281
          HomeCursor();
282
          break;
283
     case '\t':
284
          DisplayChar(' ');
285
          DisplayChar(' ');
286
          DisplayChar(' ');
287
          DisplayChar(' ');
288
          break;
289
     default:
290
          p = CalcScreenLocation();
291
          *p = GetCurrAttr() | AsciiToScreen(ch);
292
          IncrementCursorPos();
293
          break;
294
     }
295
}
296
 
297
void CRLF()
298
{
299
     DisplayChar('\r');
300
     DisplayChar('\n');
301
}
302
 
303
void DisplayString(char *s)
304
{
305
     while (*s) { DisplayChar(*s); s++; }
306
}
307
 
308
void DisplayStringCRLF(char *s)
309
{
310
     DisplayString(s);
311
     CRLF();
312
}
313
 

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.