source: buchla-68k/ram/barbadj.c@ 432327d

Last change on this file since 432327d was 432327d, checked in by Thomas Lopatic <thomas@…>, 7 years ago

Fix conversion warnings.

  • Property mode set to 100644
File size: 8.4 KB
RevLine 
[f40a309]1/*
2 =============================================================================
3 barbadj.c -- MIDAS-VII -- GLC bar graph drivers
4 Version 8 -- 1988-10-27 -- D.N. Lynx Crowe
5
6 BarBadj(bar, val)
7 short bar, val;
8
9 Adjusts a bottom-zero bar graph, 'bar',
10 to read 'val'.
11
12 BarBset(bar, val)
13 short bar, val;
14
15 Sets a bottom-zero bar graph, 'bar',
16 to an intial value, 'val'.
17
18 BarCadj(bar, val)
19 short bar, val;
20
21 Adjusts a centered-zero bar graph, 'bar',
22 to read 'val'.
23
24 BarCset(bar, val)
25 short bar, val;
26
27 Sets a centered-zero bar graph, 'bar',
28 to an intial value, 'val'.
29 =============================================================================
30*/
31
[b28a12e]32#include "ram.h"
[f40a309]33
34/* left-most bar columns */
35
[7258c6a]36int16_t BarCols[14] = { 2, 8, 14, 20, 26, 32, 38, 44, 50, 56, 62, 68, 74, 80 };
[f40a309]37
38/* bar dot data */
39
[432327d]40uint8_t BarDots[3] = { 0x1C, 0xFC, 0xE0 };
[f40a309]41
42#include "glcbars.h" /* bar graph driver constant definitions */
43
44/*
45 =============================================================================
46 BarBadj() -- adjust a bottom-zero bar graph to a new value
47 =============================================================================
48*/
49
[7258c6a]50void BarBadj(int16_t bar, int16_t val)
[f40a309]51{
[432327d]52 uint8_t bardot;
53 register int16_t curdif;
54 register int16_t baradr;
[7258c6a]55 int16_t barcol, bardif, curbar, i, newbar;
[f40a309]56
57 newbar = BarBLn[val]; /* look up the new bar position */
58 curbar = BarBcur[bar]; /* get the current bar position */
59 bardif = newbar - curbar; /* calculate how far to move the bar */
60
61 if (0 EQ bardif) /* done if bar doesn't need to be moved */
62 return;
63
64 GLCcurs(G_ON); /* turn on GLC cursor to enable writing */
65 barcol = BarCols[bar]; /* find leftmost column of bar */
66
67 if (bardif > 0) { /* increasing value */
68
69 /* calculate initial GLC RAM write address */
70
71 baradr = barcol + (85 * (63 - (curbar + 1))) + G_PLANE2;
72
73 LCD_WC = G_CRSMUP; /* set cursor motion "up" */
74
75 for (i = 0; i < 3; i++) { /* for each bar column ... */
76
77 curdif = bardif; /* set difference counter */
78 bardot = BarDots[i]; /* get the column dot value */
79
80 LCD_WC = G_CRSWR; /* set cursor address */
[432327d]81 LCD_WD = (uint8_t)(baradr & 0xFF);
82 LCD_WD = (uint8_t)((baradr >> 8) & 0xFF);
[f40a309]83
84 ++baradr; /* update GLC start address */
85
86 LCD_WC = G_MWRITE; /* setup to write */
87
88 while (curdif--) /* write new dots */
89 LCD_WD = bardot;
90 }
[fa38804]91
[f40a309]92 } else { /* decreasing value */
93
94 /* calculate initial GLC RAM write address */
95
96 baradr = barcol + (85 * (63 - curbar)) + G_PLANE2;
97
98 LCD_WC = G_CRSMDN; /* set cursor motion "down" */
99
100 for (i = 0; i < 3; i++) { /* for each bar column ... */
101
102 curdif = -bardif; /* set difference counter */
103
104 LCD_WC = G_CRSWR; /* set cursor address */
[432327d]105 LCD_WD = (uint8_t)(baradr & 0xFF);
106 LCD_WD = (uint8_t)((baradr >> 8) & 0xFF);
[f40a309]107
108 ++baradr; /* update GLC start address */
109
110 LCD_WC = G_MWRITE; /* setup to write */
111
112 while (curdif--) /* erase old dots */
113 LCD_WD = 0x00;
114 }
115 }
116
117 LCD_WC = G_CRSMRT; /* set cursor motion = "right" */
118 GLCcurs(G_OFF); /* turn off the cursor */
119
120 BarBcur[bar] = newbar; /* update current bar position */
121}
122
123/*
124 =============================================================================
125 BarBset() -- set a bottom-zero bar graph to an initial value
126 =============================================================================
127*/
128
[7258c6a]129void BarBset(int16_t bar, int16_t val)
[f40a309]130{
[432327d]131 uint8_t bardot;
132 register int16_t barpos, newbar;
133 register int16_t baradr;
[7258c6a]134 int16_t barcol, i;
[f40a309]135
136 newbar = BarBLn[val]; /* look up the new bar position */
137 barcol = BarCols[bar]; /* find leftmost column of bar */
138
139 GLCcurs(G_ON); /* turn on GLC cursor to enable writing */
140
141 /* calculate initial GLC RAM write address */
142
143 baradr = barcol + (85 * (63 - BBase)) + G_PLANE2;
144
145 LCD_WC = G_CRSMUP; /* set cursor motion = "up" */
146
147 for (i = 0; i < 3; i++) { /* for each bar column ... */
148
149 bardot = BarDots[i]; /* get the column dot value */
150 barpos = BBase; /* get base of bar */
151
152 LCD_WC = G_CRSWR; /* set cursor address */
[432327d]153 LCD_WD = (uint8_t)(baradr & 0xFF);
154 LCD_WD = (uint8_t)((baradr >> 8) & 0xFF);
[f40a309]155
156 ++baradr; /* update GLC start address */
157
158 LCD_WC = G_MWRITE; /* setup to write */
159
160 while (barpos++ LE newbar) /* write new dots */
[432327d]161 LCD_WD = (uint8_t)bardot;
[f40a309]162
163 while (barpos++ < BTop) /* erase old dots */
164 LCD_WD = 0x00;
165 }
166
167 LCD_WC = G_CRSMRT; /* set cursor motion = "right" */
168 GLCcurs(G_OFF); /* turn off the cursor */
[9519422]169
[f40a309]170 BarBcur[bar] = newbar; /* update current bar position */
171}
172
173/*
174 =============================================================================
175 BarCadj() -- adjust a centered-zero bar graph to a new value
176 =============================================================================
177*/
178
[7258c6a]179void BarCadj(int16_t bar, int16_t val)
[f40a309]180{
[432327d]181 uint8_t bardot;
182 register int16_t barpos, newbar;
183 register int16_t baradr;
[7258c6a]184 int16_t barcol, bardif, curbar, i;
[f40a309]185
186 newbar = BarCLn[val + BOffset]; /* look up the new bar position */
187 curbar = BarCcur[bar]; /* get the current bar position */
188 bardif = newbar - curbar; /* calculate how far to move the bar */
189
190 if (0 EQ bardif) /* done if bar doesn't need to be moved */
191 return;
192
193 GLCcurs(G_ON); /* turn on GLC cursor to enable writing */
194
195 barcol = BarCols[bar]; /* find leftmost column of bar */
196
197 /* calculate initial GLC RAM write address */
198
199 baradr = barcol + (85 * (63 - curbar)) + G_PLANE2;
200
[fa38804]201
[f40a309]202 if (newbar > curbar) { /* increasing value */
203
204 LCD_WC = G_CRSMUP; /* set cursor motion "up" */
205
206 for (i = 0; i < 3; i++) { /* for each bar column ... */
207
208 bardot = BarDots[i]; /* get the column dot value */
209 barpos = curbar; /* set current vert. position */
210
211 LCD_WC = G_CRSWR; /* set cursor address */
[432327d]212 LCD_WD = (uint8_t)(baradr & 0xFF);
213 LCD_WD = (uint8_t)((baradr >> 8) & 0xFF);
[f40a309]214
215 LCD_WC = G_MWRITE; /* setup to write */
216
217 while (barpos NE newbar) /* write bar on LCD */
218 if (barpos++ < BCenter)
219 LCD_WD = 0x00; /* dots off */
220 else
221 LCD_WD = bardot; /* dots on */
222
223 ++baradr; /* update GLC start address */
224 }
[fa38804]225
[f40a309]226 } else { /* decreasing value */
227
228 LCD_WC = G_CRSMDN; /* set cursor motion "down" */
229
230 for (i = 0; i < 3; i++) { /* for each bar column ... */
231
232 bardot = BarDots[i]; /* get column dot value */
233 barpos = curbar; /* set current bar location */
234
235 LCD_WC = G_CRSWR; /* set cursor address */
[432327d]236 LCD_WD = (uint8_t)(baradr & 0xFF);
237 LCD_WD = (uint8_t)((baradr >> 8) & 0xFF);
[f40a309]238
239 LCD_WC = G_MWRITE; /* setup to write */
240
241 while (barpos NE newbar) /* write bar to LCD */
242 if (barpos-- > BCenter)
243 LCD_WD= 0x00; /* dots off */
244 else
245 LCD_WD = bardot; /* dots on */
246
247 ++baradr; /* update GLC start address */
248 }
249 }
250
251 LCD_WC = G_CRSMRT; /* set cursor motion = "right" */
252 GLCcurs(G_OFF); /* turn off the cursor */
[9519422]253
[f40a309]254 BarCcur[bar] = newbar; /* update current bar position */
255}
256
257/*
258 =============================================================================
259 BarCset() -- set a centered-zero bar graph to an initial value
260 =============================================================================
261*/
262
[7258c6a]263void BarCset(int16_t bar, int16_t val)
[f40a309]264{
[432327d]265 uint8_t bardot;
266 register int16_t barpos, barloc1, barloc2;
267 register int16_t baradr;
[7258c6a]268 int16_t barcol, i, newbar;
[f40a309]269
270 GLCcurs(G_ON); /* turn on GLC cursor to enable writing */
271
272 newbar = BarCLn[val + BOffset]; /* look up the new bar position */
273 barcol = BarCols[bar]; /* find leftmost column of bar */
274
275 /* calculate initial GLC RAM write address */
276
277 baradr = barcol + (85 * (63 - BBase)) + G_PLANE2;
278
279 if (newbar < BCenter) { /* target below center */
280
281 barloc1 = newbar; /* off limit */
282 barloc2 = BCenter; /* on limit */
283
284 } else { /* target at or above center */
285
286 barloc1 = BCenter; /* off limit */
287 barloc2 = newbar; /* on limit */
288 }
289
290 LCD_WC = G_CRSMUP; /* set cursor motion "up" */
291
[fa38804]292
[f40a309]293 for (i = 0; i < 3; i++) { /* for each bar column ... */
294
295 bardot = BarDots[i]; /* get the column dot value */
296 barpos = BBase; /* set current vert. position */
297
298 LCD_WC = G_CRSWR; /* set cursor address */
[432327d]299 LCD_WD = (uint8_t)(baradr & 0xFF);
300 LCD_WD = (uint8_t)((baradr >> 8) & 0xFF);
[f40a309]301
302 LCD_WC = G_MWRITE; /* setup to write */
303
304 while (barpos < barloc1) { /* write "off" dots */
305
306 LCD_WD = 0x00;
307 barpos++;
308 }
309
310 while (barpos LE barloc2) { /* write "on" dots */
311
312 LCD_WD = bardot;
313 barpos++;
314 }
315
316 while (barpos LE BTop) { /* write "off" dots */
317
318 LCD_WD = 0x00;
319 barpos++;
320 }
321
322 ++baradr; /* update GLC start address */
323 }
324
325 LCD_WC = G_CRSMRT; /* set cursor motion = "right" */
326 GLCcurs(G_OFF); /* turn off the cursor */
[9519422]327
[f40a309]328 BarCcur[bar] = newbar; /* update current bar position */
329}
[6262b5c]330
Note: See TracBrowser for help on using the repository browser.