1 | /*
|
---|
2 | =============================================================================
|
---|
3 | glcinit.c -- LCD drivers for the Epson GLC controller chip
|
---|
4 | Version 5 -- 1988-08-03 -- D.N. Lynx Crowe
|
---|
5 | (c) Copyright 1987, 1988 -- D.N. Lynx Crowe
|
---|
6 |
|
---|
7 | GLCinit()
|
---|
8 |
|
---|
9 | Initializes the GLC.
|
---|
10 |
|
---|
11 | GLCcrc(row, col)
|
---|
12 |
|
---|
13 | Positions the GLC cursor at ('row', 'col') preparatory
|
---|
14 | to writing text. Returns the calculated cursor address.
|
---|
15 |
|
---|
16 | GLCcxy(x, y)
|
---|
17 |
|
---|
18 | Positions the GLC cursor at ('x', 'y') preparatory to
|
---|
19 | writing graphics. Returns a bit mask for the pixel.
|
---|
20 | Leaves the cursor address in lcdcurs.
|
---|
21 | Limits: 0 LE x LE 511, 0 LE y LE 63.
|
---|
22 |
|
---|
23 | GLCwrts(s)
|
---|
24 |
|
---|
25 | Writes the character string pointed to by 's' at the
|
---|
26 | current cursor position on the LCD display.
|
---|
27 | Cursor must start and end on the same line.
|
---|
28 | No error checks are done.
|
---|
29 |
|
---|
30 | GLCtext(row, col, s)
|
---|
31 |
|
---|
32 | Sets the GLC cursor to ('row', 'col'), then writes the
|
---|
33 | character string pointed to by 's'.
|
---|
34 | Cursor must start and end on the same line.
|
---|
35 | No error checks are done.
|
---|
36 |
|
---|
37 | GLCdisp(dsp, crs, blk1, blk2, blk3)
|
---|
38 |
|
---|
39 | Sets the overall display, cursor and block status values.
|
---|
40 |
|
---|
41 | GLCcurs(crs)
|
---|
42 |
|
---|
43 | Turns the cursor on or off.
|
---|
44 | =============================================================================
|
---|
45 | */
|
---|
46 |
|
---|
47 | #include "ram.h"
|
---|
48 |
|
---|
49 | int16_t lcdbase; /* LCD graphics base address */
|
---|
50 | int16_t lcdbit; /* LCD graphics pixel bit mask */
|
---|
51 | int16_t lcdcol; /* LCD text column */
|
---|
52 | int16_t lcdctl1; /* LCD display control -- command */
|
---|
53 | int16_t lcdctl2; /* LCD display control -- data */
|
---|
54 | int16_t lcdcurs; /* LCD graphics pixel byte address */
|
---|
55 | int16_t lcdrow; /* LCD text row */
|
---|
56 | int16_t lcdx; /* LCD graphics x */
|
---|
57 | int16_t lcdy; /* LCD graphics y */
|
---|
58 |
|
---|
59 | /* GLC initialization values */
|
---|
60 |
|
---|
61 | uint8_t glc_is1[] = { 0x12, 0x05, 0x07, 0x54, 0x58, 0x3F, 0x55, 0x00 };
|
---|
62 | uint8_t glc_is2[] = { 0x00, 0x00, 0x3F, 0x00, 0x20, 0x3F, 0x00, 0x00 };
|
---|
63 |
|
---|
64 | /*
|
---|
65 | =============================================================================
|
---|
66 | GLCdisp(dsp, crs, blk1, blk2, blk3) -- set GLC display status
|
---|
67 | Sets the overall display, cursor and block status values.
|
---|
68 | =============================================================================
|
---|
69 | */
|
---|
70 |
|
---|
71 | void GLCdisp(int16_t dsp, int16_t crs, int16_t blk1, int16_t blk2, int16_t blk3)
|
---|
72 | {
|
---|
73 | register int16_t val;
|
---|
74 |
|
---|
75 | val = ((blk3 & 3) << 6) | ((blk2 & 3) << 4) | ((blk1 & 3) << 2) |
|
---|
76 | (crs & 3);
|
---|
77 |
|
---|
78 | lcdctl1 = G_DSPCTL | (dsp & 1);
|
---|
79 | lcdctl2 = val;
|
---|
80 |
|
---|
81 | LCD_WC = (uint8_t)lcdctl1;
|
---|
82 | LCD_WD = (uint8_t)lcdctl2;
|
---|
83 |
|
---|
84 | }
|
---|
85 |
|
---|
86 | /*
|
---|
87 | =============================================================================
|
---|
88 | GLCcurs() -- turns the cursor on or off
|
---|
89 | =============================================================================
|
---|
90 | */
|
---|
91 |
|
---|
92 | void GLCcurs(int16_t crs)
|
---|
93 | {
|
---|
94 | lcdctl2 = (crs & 3) | (lcdctl2 & ~3);
|
---|
95 |
|
---|
96 | LCD_WC = (uint8_t)lcdctl1;
|
---|
97 | LCD_WD = (uint8_t)lcdctl2;
|
---|
98 | }
|
---|
99 |
|
---|
100 | /*
|
---|
101 | =============================================================================
|
---|
102 | GLCinit() -- initialize GLC
|
---|
103 | Initializes the GLC.
|
---|
104 | =============================================================================
|
---|
105 | */
|
---|
106 |
|
---|
107 | void GLCinit(void)
|
---|
108 | {
|
---|
109 | register int16_t i;
|
---|
110 | register int32_t ic;
|
---|
111 | register uint8_t *gp;
|
---|
112 |
|
---|
113 | lcdbase = G_PLANE2; /* set defaults for graphics variables */
|
---|
114 | lcdx = 0;
|
---|
115 | lcdy = 0;
|
---|
116 | lcdbit = 0x01;
|
---|
117 |
|
---|
118 | lcdrow = 0; /* set default for text variables */
|
---|
119 | lcdcol = 0;
|
---|
120 |
|
---|
121 | lcdctl1 = G_DSPCTL;
|
---|
122 | lcdctl2 = 0;
|
---|
123 |
|
---|
124 | LCD_WC = G_INIT; /* initialize the GLC */
|
---|
125 | gp = &glc_is1[0];
|
---|
126 |
|
---|
127 | for (i = 0; i < 8; i++)
|
---|
128 | LCD_WD = *gp++;
|
---|
129 |
|
---|
130 | LCD_WC = G_SETSAD; /* setup scroll registers */
|
---|
131 | gp = &glc_is2[0];
|
---|
132 |
|
---|
133 | for (i = 0; i < 8; i++)
|
---|
134 | LCD_WD = *gp++;
|
---|
135 |
|
---|
136 | LCD_WC = G_HSCRL; /* clear the horizontal scroll counter */
|
---|
137 | LCD_WD = 0;
|
---|
138 |
|
---|
139 | LCD_WC = G_OVRLAY; /* setup the display mode */
|
---|
140 | LCD_WD = 0x08;
|
---|
141 |
|
---|
142 | GLCdisp(G_OFF, G_B2, G_ON, G_ON, G_OFF);
|
---|
143 |
|
---|
144 |
|
---|
145 | LCD_WC = G_CRSWR; /* set cursor at (0,0) in G_PLANE1 */
|
---|
146 | LCD_WD = G_PLANE1 & 0xFF;
|
---|
147 | LCD_WD = (G_PLANE1 >> 8) & 0xFF;
|
---|
148 |
|
---|
149 | LCD_WC = G_CRSMRT; /* set cursor motion forward */
|
---|
150 |
|
---|
151 | LCD_WC = G_MWRITE; /* write zeros to GLC RAM */
|
---|
152 |
|
---|
153 | for (ic = 0; ic < 65536L; ic++)
|
---|
154 | LCD_WD = 0;
|
---|
155 |
|
---|
156 | LCD_WC = G_CRSWR; /* set cursor to (0,0) in G_PLANE1 */
|
---|
157 | LCD_WD = G_PLANE1 & 0xFF;
|
---|
158 | LCD_WD = (G_PLANE1 >> 8) & 0xFF;
|
---|
159 |
|
---|
160 | LCD_WC = G_CRSFRM; /* setup a blinking underline cursor */
|
---|
161 | LCD_WD = 0x04;
|
---|
162 | LCD_WD = 0x06;
|
---|
163 |
|
---|
164 | /* enable display */
|
---|
165 |
|
---|
166 | GLCdisp(G_ON, G_B2, G_ON, G_ON, G_OFF);
|
---|
167 | }
|
---|
168 |
|
---|
169 | /*
|
---|
170 | =============================================================================
|
---|
171 | GLCcrc(row, col) -- position GLC text cursor
|
---|
172 | Positions the GLC cursor at ('row', 'col') preparatory
|
---|
173 | to writing text. Returns calculated cursor address.
|
---|
174 | =============================================================================
|
---|
175 | */
|
---|
176 |
|
---|
177 | int16_t GLCcrc(int16_t row, int16_t col)
|
---|
178 | {
|
---|
179 | int16_t curad;
|
---|
180 |
|
---|
181 | curad = col + (row * 85); /* calculate cursor location */
|
---|
182 |
|
---|
183 | LCD_WC = G_CRSWR; /* send cursor address to GLC */
|
---|
184 | LCD_WD = (uint8_t)(curad & 0xFF);
|
---|
185 | LCD_WD = (uint8_t)((curad >> 8) & 0xFF);
|
---|
186 |
|
---|
187 | lcdrow = row; /* set text cursor variables */
|
---|
188 | lcdcol = col;
|
---|
189 |
|
---|
190 | return(curad); /* return calculated cursor address */
|
---|
191 | }
|
---|
192 |
|
---|
193 | /*
|
---|
194 | =============================================================================
|
---|
195 | GLCcxy(x, y) -- position GLC graphics cursor
|
---|
196 | Positions the GLC cursor at ('x', 'y') preparatory to
|
---|
197 | writing graphics. Returns a bit mask for the pixel.
|
---|
198 | Leaves cursor address in lcdcurs.
|
---|
199 | Limits: 0 LE x LE 511, 0 LE y LE 63.
|
---|
200 | =============================================================================
|
---|
201 | */
|
---|
202 |
|
---|
203 | int16_t GLCcxy(int16_t x, int16_t y)
|
---|
204 | {
|
---|
205 | register int16_t curad, xby6;
|
---|
206 |
|
---|
207 | /* calculate cursor address */
|
---|
208 |
|
---|
209 | xby6 = x % 6;
|
---|
210 | curad = lcdbase + (85 * (63 - y)) + (x / 6) + (xby6 >> 3);
|
---|
211 | lcdcurs = curad;
|
---|
212 |
|
---|
213 | /* send cursor address to GLC */
|
---|
214 |
|
---|
215 | LCD_WC = G_CRSWR;
|
---|
216 | LCD_WD = (uint8_t)(curad & 0xFF);
|
---|
217 | LCD_WD = (uint8_t)((curad >> 8) & 0xFF);
|
---|
218 |
|
---|
219 | /* set graphics variables */
|
---|
220 |
|
---|
221 | lcdx = x;
|
---|
222 | lcdy = y;
|
---|
223 |
|
---|
224 | /* calculate bit mask */
|
---|
225 |
|
---|
226 | lcdbit = 0x01 << (xby6 & 0x07);
|
---|
227 |
|
---|
228 | return(lcdbit);
|
---|
229 | }
|
---|
230 |
|
---|
231 | /*
|
---|
232 | =============================================================================
|
---|
233 | GLCwrts(s) -- write text string to GLC
|
---|
234 | Writes the character string pointed to by 's' at the
|
---|
235 | current cursor position on the LCD display.
|
---|
236 | Cursor must start and end on the same line.
|
---|
237 | No error checks are done.
|
---|
238 | =============================================================================
|
---|
239 | */
|
---|
240 |
|
---|
241 | void GLCwrts(int8_t *s)
|
---|
242 | {
|
---|
243 | LCD_WC = G_CRSMRT; /* set cursor motion = right */
|
---|
244 |
|
---|
245 | LCD_WC = G_MWRITE; /* set to write data */
|
---|
246 |
|
---|
247 | while (*s) { /* write string to GLC */
|
---|
248 |
|
---|
249 | LCD_WD = (uint8_t)*s++;
|
---|
250 | lcdcol++; /* keep column variable up to date */
|
---|
251 | }
|
---|
252 | }
|
---|
253 |
|
---|
254 | /*
|
---|
255 | =============================================================================
|
---|
256 | GLCtext(row, col, s) -- position GLC cursor and write text
|
---|
257 | Sets the GLC cursor to ('row', 'col'), then writes the
|
---|
258 | character string pointed to by 's'.
|
---|
259 | Cursor must start and end on the same line.
|
---|
260 | No error checks are done.
|
---|
261 | =============================================================================
|
---|
262 | */
|
---|
263 |
|
---|
264 | void GLCtext(int16_t row, int16_t col, int8_t *s)
|
---|
265 | {
|
---|
266 | register int16_t curad;
|
---|
267 |
|
---|
268 | curad = col + (row * 85); /* calculate cursor address */
|
---|
269 |
|
---|
270 | LCD_WC = G_CRSWR; /* send cursor address to GLC */
|
---|
271 | LCD_WD = (uint8_t)(curad & 0xFF);
|
---|
272 | LCD_WD = (uint8_t)((curad >> 8) & 0xFF);
|
---|
273 |
|
---|
274 | lcdrow = row; /* set GLC text cursor variables */
|
---|
275 | lcdcol = col;
|
---|
276 |
|
---|
277 | LCD_WC = G_CRSMRT; /* set cursor motion = right */
|
---|
278 |
|
---|
279 | LCD_WC = G_MWRITE; /* set to write data */
|
---|
280 |
|
---|
281 | while (*s) { /* write string to GLC */
|
---|
282 |
|
---|
283 | LCD_WD = (uint8_t)*s++;
|
---|
284 | lcdcol++; /* keep cursor column up to date */
|
---|
285 | }
|
---|
286 | }
|
---|
287 |
|
---|
288 |
|
---|