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