ite_rh.c revision 1.3 1 /* $NetBSD: ite_rh.c,v 1.3 1994/10/26 02:04:00 cgd Exp $ */
2
3 #include "grfrh.h"
4 #if NGRFRH > 0
5
6 #include <sys/param.h>
7 #include <sys/conf.h>
8 #include <sys/proc.h>
9 #include <sys/device.h>
10 #include <sys/ioctl.h>
11 #include <sys/tty.h>
12 #include <sys/systm.h>
13 #include <dev/cons.h>
14 #include <machine/cpu.h>
15 #include <amiga/amiga/device.h>
16 #include <amiga/dev/grfioctl.h>
17 #include <amiga/dev/grfvar.h>
18 #include <amiga/dev/grf_rhreg.h>
19 #include <amiga/dev/itevar.h>
20
21
22 /*
23 * grfrh_cnprobe is called when the console is being initialized
24 * i.e. very early. grfconfig() has been called, so this implies
25 * that rt_init() was called. If we are functioning rh_inited
26 * will be true.
27 */
28 int
29 grfrh_cnprobe()
30 {
31 static int done;
32 int rv;
33
34 if (done == 0)
35 rv = CN_INTERNAL;
36 else
37 rv = CN_NORMAL;
38 done = 1;
39 return(rv);
40 }
41
42 void
43 grfrh_iteinit(gp)
44 struct grf_softc *gp;
45 {
46 gp->g_iteinit = rh_init;
47 gp->g_itedeinit = rh_deinit;
48 gp->g_iteclear = rh_clear;
49 gp->g_iteputc = rh_putc;
50 gp->g_itescroll = rh_scroll;
51 gp->g_itecursor = rh_cursor;
52 }
53
54 void
55 rh_init(ip)
56 struct ite_softc *ip;
57 {
58 struct MonDef *md;
59 extern unsigned char RZ3StdPalette[];
60
61 #if 0 /* Not in ite_rt.c - DC */
62 if (ip->grf == 0)
63 ip->grf = &grf_softc[ip - ite_softc];
64 #endif
65
66 ip->priv = ip->grf->g_data;
67 md = (struct MonDef *) ip->priv;
68
69 ip->cols = md->TX;
70 ip->rows = md->TY;
71 }
72
73
74 void
75 rh_cursor(ip, flag)
76 struct ite_softc *ip;
77 int flag;
78 {
79 volatile u_char *ba = ip->grf->g_regkva;
80
81 if (flag == START_CURSOROPT || flag == END_CURSOROPT)
82 return;
83
84 if (flag == ERASE_CURSOR) {
85 #if 0
86 /* disable cursor */
87 WCrt (ba, CRT_ID_CURSOR_START,
88 RCrt (ba, CRT_ID_CURSOR_START) | 0x20);
89 #endif
90 } else {
91 int pos = ip->curx + ip->cury * ip->cols;
92 #if 0
93 /* make sure to enable cursor */
94 WCrt (ba, CRT_ID_CURSOR_START,
95 RCrt (ba, CRT_ID_CURSOR_START) & ~0x20);
96 #endif
97
98 /* and position it */
99 RZ3SetCursorPos (ip->grf, pos);
100
101 ip->cursorx = ip->curx;
102 ip->cursory = ip->cury;
103 }
104 }
105
106
107
108 static void
109 screen_up(ip, top, bottom, lines)
110 struct ite_softc *ip;
111 int top;
112 int bottom;
113 int lines;
114 {
115 volatile u_char * ba = ip->grf->g_regkva;
116 volatile u_char * fb = ip->grf->g_fbkva;
117
118 /* do some bounds-checking here.. */
119 if (top >= bottom)
120 return;
121
122 if (top + lines >= bottom) {
123 RZ3AlphaErase(ip->grf, 0, top, bottom - top, ip->cols);
124 return;
125 }
126
127 RZ3AlphaCopy(ip->grf, 0, top+lines, 0, top, ip->cols, bottom-top-lines+1);
128 RZ3AlphaErase(ip->grf, 0, bottom - lines + 1, ip->cols, lines);
129 }
130
131 static void
132 screen_down (ip, top, bottom, lines)
133 struct ite_softc *ip;
134 int top;
135 int bottom;
136 int lines;
137 {
138 volatile u_char * ba = ip->grf->g_regkva;
139 volatile u_char * fb = ip->grf->g_fbkva;
140
141 /* do some bounds-checking here.. */
142 if (top >= bottom)
143 return;
144
145 if (top + lines >= bottom) {
146 RZ3AlphaErase(ip->grf, 0, top, bottom - top, ip->cols);
147 return;
148 }
149
150 RZ3AlphaCopy(ip->grf, 0, top, 0, top+lines, ip->cols, bottom-top-lines+1);
151 RZ3AlphaErase(ip->grf, 0, top, ip->cols, lines);
152 }
153
154 void
155 rh_deinit(ip)
156 struct ite_softc *ip;
157 {
158 ip->flags &= ~ITE_INITED;
159 }
160
161
162 void
163 rh_putc(ip, c, dy, dx, mode)
164 struct ite_softc *ip;
165 int c;
166 int dy;
167 int dx;
168 int mode;
169 {
170 volatile u_char * ba = ip->grf->g_regkva;
171 volatile u_char * fb = ip->grf->g_fbkva;
172 register u_char attr;
173
174 attr = (mode & ATTR_INV) ? 0x21 : 0x10;
175 if (mode & ATTR_UL) attr = 0x01; /* ???????? */
176 if (mode & ATTR_BOLD) attr |= 0x08;
177 if (mode & ATTR_BLINK) attr |= 0x80;
178
179 fb += 4 * (dy * ip->cols + dx);
180 *fb++ = c; *fb = attr;
181 }
182
183 void
184 rh_clear(ip, sy, sx, h, w)
185 struct ite_softc *ip;
186 int sy;
187 int sx;
188 int h;
189 int w;
190 {
191 RZ3AlphaErase (ip->grf, sx, sy, w, h);
192 }
193
194 void
195 rh_scroll(ip, sy, sx, count, dir)
196 struct ite_softc *ip;
197 int sy;
198 int sx;
199 int count;
200 int dir;
201 {
202 volatile u_char * ba = ip->grf->g_regkva;
203 u_long * fb = (u_long *) ip->grf->g_fbkva;
204 register int height, dy, i;
205
206 rh_cursor(ip, ERASE_CURSOR);
207
208 if (dir == SCROLL_UP) {
209 screen_up(ip, sy - count, ip->bottom_margin, count);
210 /* bcopy(fb + sy * ip->cols, fb + (sy - count) * ip->cols,
211 4 * (ip->bottom_margin - sy + 1) * ip->cols); */
212 /* rh_clear(ip, ip->bottom_margin + 1 - count, 0,
213 count, ip->cols); */
214 } else if (dir == SCROLL_DOWN) {
215 screen_down(ip, sy, ip->bottom_margin, count);
216 /* bcopy(fb + sy * ip->cols, fb + (sy + count) * ip->cols,
217 4 * (ip->bottom_margin - sy - count + 1) * ip->cols); */
218 /* rh_clear(ip, sy, 0, count, ip->cols); */
219 } else if (dir == SCROLL_RIGHT) {
220 RZ3AlphaCopy(ip->grf, sx, sy, sx + count, sy,
221 ip->cols - (sx + count), 1);
222 RZ3AlphaErase(ip->grf, sx, sy, count, 1);
223 } else {
224 RZ3AlphaCopy(ip->grf, sx + count, sy, sx, sy,
225 ip->cols - (sx + count), 1);
226 RZ3AlphaErase(ip->grf, ip->cols - count, sy, count, 1);
227 }
228 }
229 #endif /* NGRFRH */
230