source: buchla-68k/vlib/glcinit.c@ 4b63bf3

Last change on this file since 4b63bf3 was 5c4721b, checked in by Thomas Lopatic <thomas@…>, 7 years ago

Fixed integer width.

  • Property mode set to 100644
File size: 7.2 KB
RevLine 
[f40a309]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.
[fa38804]36
[f40a309]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
[b28a12e]47#include "ram.h"
[f40a309]48
[5c4721b]49int16_t lcdbase; /* LCD graphics base address */
[bf89cfb]50int16_t lcdbit; /* LCD graphics pixel bit mask */
51int16_t lcdcol; /* LCD text column */
52int16_t lcdctl1; /* LCD display control -- command */
53int16_t lcdctl2; /* LCD display control -- data */
[5c4721b]54int16_t lcdcurs; /* LCD graphics pixel byte address */
[bf89cfb]55int16_t lcdrow; /* LCD text row */
56int16_t lcdx; /* LCD graphics x */
57int16_t lcdy; /* LCD graphics y */
[f40a309]58
59/* GLC initialization values */
60
[bf89cfb]61uint8_t glc_is1[] = { 0x12, 0x05, 0x07, 0x54, 0x58, 0x3F, 0x55, 0x00 };
62uint8_t glc_is2[] = { 0x00, 0x00, 0x3F, 0x00, 0x20, 0x3F, 0x00, 0x00 };
[f40a309]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
[7258c6a]71void GLCdisp(int16_t dsp, int16_t crs, int16_t blk1, int16_t blk2, int16_t blk3)
[f40a309]72{
[7258c6a]73 register int16_t val;
[f40a309]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
[bf89cfb]81 LCD_WC = (uint8_t)lcdctl1;
82 LCD_WD = (uint8_t)lcdctl2;
[f40a309]83
84}
85
86/*
87 =============================================================================
88 GLCcurs() -- turns the cursor on or off
89 =============================================================================
90*/
91
[7258c6a]92void GLCcurs(int16_t crs)
[f40a309]93{
94 lcdctl2 = (crs & 3) | (lcdctl2 & ~3);
95
[bf89cfb]96 LCD_WC = (uint8_t)lcdctl1;
97 LCD_WD = (uint8_t)lcdctl2;
[f40a309]98}
99
100/*
101 =============================================================================
102 GLCinit() -- initialize GLC
103 Initializes the GLC.
104 =============================================================================
105*/
106
[0580615]107void GLCinit(void)
[f40a309]108{
[7258c6a]109 register int16_t i;
110 register int32_t ic;
[bf89cfb]111 register uint8_t *gp;
[f40a309]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++)
[bf89cfb]128 LCD_WD = *gp++;
[f40a309]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
[fa38804]144
[f40a309]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
[bf89cfb]177int16_t GLCcrc(int16_t row, int16_t col)
[f40a309]178{
[bf89cfb]179 int16_t curad;
[f40a309]180
181 curad = col + (row * 85); /* calculate cursor location */
182
183 LCD_WC = G_CRSWR; /* send cursor address to GLC */
[bf89cfb]184 LCD_WD = (uint8_t)(curad & 0xFF);
185 LCD_WD = (uint8_t)((curad >> 8) & 0xFF);
[f40a309]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
[bf89cfb]203int16_t GLCcxy(int16_t x, int16_t y)
[f40a309]204{
[5c4721b]205 register int16_t curad, xby6;
[f40a309]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;
[bf89cfb]216 LCD_WD = (uint8_t)(curad & 0xFF);
217 LCD_WD = (uint8_t)((curad >> 8) & 0xFF);
[f40a309]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
[7258c6a]241void GLCwrts(int8_t *s)
[f40a309]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
[bf89cfb]249 LCD_WD = (uint8_t)*s++;
[f40a309]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
[bf89cfb]264void GLCtext(int16_t row, int16_t col, int8_t *s)
[f40a309]265{
[bf89cfb]266 register int16_t curad;
[f40a309]267
268 curad = col + (row * 85); /* calculate cursor address */
269
270 LCD_WC = G_CRSWR; /* send cursor address to GLC */
[bf89cfb]271 LCD_WD = (uint8_t)(curad & 0xFF);
272 LCD_WD = (uint8_t)((curad >> 8) & 0xFF);
[f40a309]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
[bf89cfb]283 LCD_WD = (uint8_t)*s++;
[f40a309]284 lcdcol++; /* keep cursor column up to date */
285 }
286}
287
[6262b5c]288
Note: See TracBrowser for help on using the repository browser.