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

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [rtos/] [ucos-ii/] [2.91/] [drivers/] [console.c] - Blame information for rev 825

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 471 julius
/*
2
   Functions to control a console
3
 
4
   Very basic right now.
5
 
6
   Author: Julius Baxter, julius@opencores.org
7
 
8
*/
9
 
10
/*
11
  This program is free software; you can redistribute it and/or modify
12
  it under the terms of the GNU General Public License as published by
13
  the Free Software Foundation; either version 2 of the License, or
14
  (at your option) any later version.
15
 
16
  This program is distributed in the hope that it will be useful,
17
  but WITHOUT ANY WARRANTY; without even the implied warranty of
18
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19
  GNU General Public License for more details.
20
 
21
  You should have received a copy of the GNU General Public License
22
  along with this program; if not, write to the Free Software
23
  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
24
*/
25
 
26
#include "includes.h"
27
 
28
/* ANSI escape code values */
29
/* String these two together to create the control sequence indicator "ESC[" */
30
/* ASCII escape value, ESC*/
31
#define ESC 0x1b
32
/* Left square bracket '[' */
33
#define CSI 0x5b
34
 
35
#define PUT_CSI1(X) putc(ESC);putc(CSI);putc(X)
36
#define PUT_CSI2(X, Y) putc(ESC);putc(CSI);putc(X);putc(Y)
37
 
38
#define ASCII_DEC_OFFSET 0x30
39
 
40
static int cWidth, cHeight;
41
 
42
static void console_place_cursor(int x, int y);
43
 
44
void
45
console_init (int width, int height)
46
{
47
  /* Save width and height */
48
  cWidth = width;
49
  cHeight = height;
50
 
51
  console_clear();
52
 
53
  /* Hide cursor - stops cursor block flickering about as the
54
   console is updated. */
55
  putc(ESC);putc(CSI);putc('?');putc('2');putc('5');putc('l');
56
 
57
}
58
 
59
void
60
console_finish (void)
61
{
62
  console_clear();
63
 
64
  /* Finishing up - reset console to show cursor. */
65
  putc(ESC);putc(CSI);putc('?');putc('2');putc('5');putc('h');
66
 
67
}
68
 
69
void
70
console_clear (void)
71
{
72
  /* Erase whole display */
73
  PUT_CSI2('2','J');
74
  console_place_cursor(1,1);
75
}
76
 
77
static void
78
console_place_cursor (int x, int y)
79
{
80
  /* First convert Y to a decimal string */
81
  /* This is a hacky way of doing it. */
82
  int yHunds = 0;
83
  int yTens = 0;
84
  int yOnes = 0;
85
 
86
  while (y >= 100){
87
    y -= 100; yHunds ++;
88
  }
89
  while (y >= 10){
90
    y -= 10; yTens ++;
91
  }
92
  while (y > 0){
93
    y --; yOnes++;
94
  }
95
 
96
  /* This is a hacky way of doing it. */
97
  int xHunds = 0;
98
  int xTens = 0;
99
  int xOnes = 0;
100
 
101
  while (x >= 100){
102
    x -= 100; xHunds ++;
103
  }
104
  while (x >= 10){
105
    x -= 10; xTens ++;
106
  }
107
  while (x > 0){
108
    x --; xOnes++;
109
  }
110
 
111
  /* Output control sequence */
112
  putc(ESC);
113
  putc(CSI);
114
  if (yHunds) putc(yHunds + ASCII_DEC_OFFSET);
115
  if (yTens) putc(yTens + ASCII_DEC_OFFSET);
116
  putc(yOnes + ASCII_DEC_OFFSET);
117
  putc(';');
118
  if (xHunds) putc(xHunds + ASCII_DEC_OFFSET);
119
  if (xTens) putc(xTens + ASCII_DEC_OFFSET);
120
  putc(xOnes + ASCII_DEC_OFFSET);
121
  putc('f');
122
}
123
 
124
void
125
console_puts (int x, int y, char* str)
126
{
127
  int i;
128
  OS_CPU_SR cpu_sr;
129
 
130
  if ((y >= cHeight) || (x >= cWidth))
131
    return; /* Nothing to do, out of our range */
132
 
133
  /* Ensure this output doesn't get interrupted, as stuff will be spewed
134
     out to random places if the console control sequences are interrupted
135
  */
136
 
137
  OS_ENTER_CRITICAL()
138
 
139
  console_place_cursor(x, y);
140
 
141
  /* Print string contents, don't overflow line,
142
     and don't handle wrapping.*/
143
  while((str[i]!=0) && (i+y < cWidth))
144
        putc(str[i++]);
145
 
146
  /* Return cursor to 1,1 */
147
  console_place_cursor(1,1);
148
 
149
  OS_EXIT_CRITICAL()
150
 
151
}
152
 
153
 
154
void
155
console_putc (int x, int y, char c)
156
{
157
  OS_CPU_SR cpu_sr;
158
 
159
  if ((y >= cHeight) || (x >= cWidth))
160
    return; /* Nothing to do, out of our range */
161
 
162
  /* Ensure this output doesn't get interrupted, as stuff will be spewed
163
     out to random places if the console control sequences are interrupted
164
  */
165
 
166
  OS_ENTER_CRITICAL()
167
 
168
  console_place_cursor(x, y);
169
 
170
  putc(c);
171
 
172
  /* Return cursor to 1,1 */
173
  console_place_cursor(1,1);
174
 
175
  OS_EXIT_CRITICAL()
176
 
177
}
178
 

powered by: WebSVN 2.1.0

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