File view
| 1 | //$Id: ism_display.lib,v 1.2 2008-07-27 00:48:10 charlie Exp $ |
| 2 | /* |
| 3 | |
| 4 | $Log: ism_display.lib,v $ |
| 5 | |
| 6 | |
| 7 | */ |
| 8 | |
| 9 | /*** BeginHeader */ |
| 10 | |
| 11 | #ifndef __ISM_DISPLAY_ |
| 12 | #define __ISM_DISPLAY_ |
| 13 | /*** EndHeader */ |
| 14 | |
| 15 | /*** BeginHeader |
| 16 | |
| 17 | InitializeDisplay, |
| 18 | DisplayText, |
| 19 | DisplayTextCentered, |
| 20 | DisplayWindowText, |
| 21 | DisplayTextAt, |
| 22 | DisplayTextCenteredAt, |
| 23 | DisplayWindowTextAt, |
| 24 | DisplayMsg, |
| 25 | DisplayMsg1, |
| 26 | DisplayMsg2, |
| 27 | DisplayMsg1Ctr, |
| 28 | DisplayMsg2Ctr, |
| 29 | DisplayMsgCtr, |
| 30 | DisplayMsg1Pair, |
| 31 | DisplayMsg2Pair, |
| 32 | DisplayBrightness, |
| 33 | DisplayDefineWindow, |
| 34 | DisplayReverse, |
| 35 | DspMsgArrow, |
| 36 | Display2Stdio, |
| 37 | DisplayToggleQuiet, |
| 38 | DisplayMagnify, |
| 39 | ConcatMsg, |
| 40 | DisplayInit4711, |
| 41 | DspUpdate4711, |
| 42 | WrtCmd, |
| 43 | WrtData |
| 44 | |
| 45 | */ |
| 46 | |
| 47 | // ASCII Constants |
| 48 | |
| 49 | #define ESC 0x1b |
| 50 | #define US 0x1f |
| 51 | #define CLR 0x0c |
| 52 | #define HOM 0x0b |
| 53 | #define HT 0x09 |
| 54 | #define BS 0x08 |
| 55 | |
| 56 | // Hardware Constants |
| 57 | #define DSP_MD1 0x01 // See hardware documentation |
| 58 | #define DSP_MD2 0x02 |
| 59 | #define DSP_MD3 0x03 |
| 60 | #define PBUSY_BIT 0x80 // Busy status bit from the hardware |
| 61 | |
| 62 | // Port definitions |
| 63 | #if BOARDREV == 'A' |
| 64 | #define DISPLAY_WR_PORT PEDR // The write bit is in the E port |
| 65 | #define DISPLAY_WR_BIT 0 // The wirte bit is bit 0 |
| 66 | #endif |
| 67 | |
| 68 | #if BOARDREV == 'B' |
| 69 | #define DISPLAY_WR_PORT PEDR // The write bit is in the E port |
| 70 | #define DISPLAY_WR_BIT 5 // The wirte bit is bit 5 |
| 71 | #define DISPLAY_RD_PORT PEDR // The read bit is in the E port |
| 72 | #define DISPLAY_RD_BIT 5 // The read bit is bit 5 |
| 73 | #endif |
| 74 | |
| 75 | #if BOARDREV == 'C' |
| 76 | #define DISPLAY_WR_PORT PEDR // The write bit is in the E port |
| 77 | #define DISPLAY_WR_BIT 7 // The wirte bit is bit 7 |
| 78 | #define DISPLAY_RD_PORT PEDR // The read bit is in the E port |
| 79 | #define DISPLAY_RD_BIT 7 // The read bit is bit 7 |
| 80 | #endif |
| 81 | #define DISPLAY_ADR_BIT_CMD ((~2) & (0xf)) // The address bit to 0 |
| 82 | #define DISPLAY_ADR_BIT_DTA ((~0) & (0xf)) // The address bit to 1 |
| 83 | |
| 84 | |
| 85 | // Other Constants |
| 86 | #define TIMEOUT_MS 100L /* Must be long */ |
| 87 | #define DEFAULT_BRIGHTNESS 8 |
| 88 | |
| 89 | |
| 90 | /***************************************************************** |
| 91 | API for AUTOPAK_DISPLAY.LIB |
| 92 | *****************************************************************/ |
| 93 | |
| 94 | typedef enum |
| 95 | { |
| 96 | STDIO_OFF, |
| 97 | STDIO_ON |
| 98 | } StdioMode; // An enumerated type to indicate stdio on or off |
| 99 | |
| 100 | // API Function Prototypes |
| 101 | |
| 102 | /*********************************************************** |
| 103 | void InitializeDisplay(StdioMode mode) |
| 104 | Call at initialization time to get the display ready |
| 105 | for use. |
| 106 | |
| 107 | InitializeDisplay takes the initial StdioMode as its argument |
| 108 | Returns nothing |
| 109 | ***********************************************************/ |
| 110 | nodebug void InitializeDisplay(StdioMode mode); |
| 111 | |
| 112 | |
| 113 | /******************************************************************* |
| 114 | int DisplayText(char *text) |
| 115 | Clear the display and display the given text |
| 116 | at cursor position 0,0 |
| 117 | |
| 118 | Returns 0 |
| 119 | |
| 120 | int DisplayTextCentered(char *text) |
| 121 | Same as DisplayText, but centers the text |
| 122 | ********************************************************************/ |
| 123 | nodebug int DisplayText(char *text); |
| 124 | nodebug int DisplayTextCentered(char *text); |
| 125 | |
| 126 | |
| 127 | /******************************************************************** |
| 128 | int DisplayWindowText(char window, char *text) |
| 129 | Clear the given window, and write the given text in |
| 130 | the given window. |
| 131 | |
| 132 | Returns 0 |
| 133 | ********************************************************************/ |
| 134 | nodebug int DisplayWindowText(char window, char *text); |
| 135 | |
| 136 | |
| 137 | /******************************************************************** |
| 138 | int DisplayTextAt(char *text, char x, char y) |
| 139 | Set the cursor to x,y, and display the given text. |
| 140 | |
| 141 | x and y refer to character positions, not pixel positions. |
| 142 | |
| 143 | Returns 0 |
| 144 | |
| 145 | int DisplayTextCenteredAt(char *text, char x, char y) |
| 146 | Same as DisplayTextAt, but centers the text |
| 147 | ********************************************************************/ |
| 148 | nodebug int DisplayTextAt(char *text, char x, char y); |
| 149 | nodebug int DisplayTextCenteredAt(char *text, char x, char y); |
| 150 | |
| 151 | |
| 152 | /******************************************************************** |
| 153 | int DisplayWindowTextAt(char window, char *text, char x, char y) |
| 154 | Select the given window, set the cursor to x,y in the window, |
| 155 | and display the given text. |
| 156 | |
| 157 | x and y refer to character positions, not pixel positions. |
| 158 | |
| 159 | Returns 0 |
| 160 | ********************************************************************/ |
| 161 | nodebug int DisplayWindowTextAt(char window, char *text, char x, char y); |
| 162 | |
| 163 | /******************************************************************** |
| 164 | int DisplayMsg(char *line1, char *line2) |
| 165 | Display the given text in window 0: line1 on line 1 and line2 on line 2 |
| 166 | |
| 167 | Returns 0 |
| 168 | |
| 169 | int DisplayMsgCtr(char *line1, char *line2) |
| 170 | |
| 171 | Same as DisplayMsg, but centers the text on each line |
| 172 | ********************************************************************/ |
| 173 | nodebug int DisplayMsg(char *line1, char *line2); |
| 174 | nodebug int DisplayMsgCtr(char *line1, char *line2); |
| 175 | |
| 176 | /******************************************************************** |
| 177 | int DisplayMsg1(char *line) |
| 178 | Display the given text in window 0, line 1 |
| 179 | |
| 180 | int DisplayMsg2(char *line) |
| 181 | Display the given text in window 0, line 2 |
| 182 | |
| 183 | Returns 0 |
| 184 | |
| 185 | int DisplayMsg1Ctr(char *line) |
| 186 | int DisplayMsg2Ctr(char *line) |
| 187 | |
| 188 | Same as DisplayMsg1 and DisplayMsg2, but centers the text |
| 189 | ********************************************************************/ |
| 190 | nodebug int DisplayMsg1(char *line); |
| 191 | nodebug int DisplayMsg2(char *line); |
| 192 | nodebug int DisplayMsg1Ctr(char *line); |
| 193 | nodebug int DisplayMsg2Ctr(char *line); |
| 194 | |
| 195 | /******************************************************************** |
| 196 | int DisplayMsg1Pair(int leftPad, char *leftMsg, char *rightMsg, int rightPad) |
| 197 | Display the given text on line 1. |
| 198 | leftMsg is left-justified after leaving leftPad blanks on the left side |
| 199 | rightMsg is right-justified after leaving rightPad blanks on the right side |
| 200 | |
| 201 | Returns 0 |
| 202 | ********************************************************************/ |
| 203 | nodebug int DisplayMsg1Pair(int leftPad, char *leftMsg, char *rightMsg, int rightPad); |
| 204 | nodebug int DisplayMsg2Pair(int leftPad, char *leftMsg, char *rightMsg, int rightPad); |
| 205 | |
| 206 | |
| 207 | /******************************************************************** |
| 208 | int DisplayBrightness(char n) |
| 209 | Set the brightness from 1 to 8. |
| 210 | |
| 211 | Returns 0 |
| 212 | ********************************************************************/ |
| 213 | nodebug int DisplayBrightness(char n); |
| 214 | |
| 215 | /******************************************************************* |
| 216 | DisplayDefineWindow(char n, int xpos, int ypos, int xsize, int ysize) |
| 217 | Define a window. xpos, ypos, xsize and ysize are the location |
| 218 | of the upper-left corner of the window, and the size of |
| 219 | the window, all in pixels. |
| 220 | |
| 221 | Returns 0 |
| 222 | ********************************************************************/ |
| 223 | nodebug int DisplayDefineWindow(char n, int xpos, int ypos, int xsize, int ysize); |
| 224 | |
| 225 | /******************************************************************* |
| 226 | DisplayReverse(int mode) |
| 227 | Control the "reverse" mode: 1 => reverse mode, 0=> normal mode. |
| 228 | |
| 229 | The reverse mode applies to all subsequent characters written |
| 230 | to the currently active window. Reverse mode is reset to |
| 231 | "normal" when the window is cleared. |
| 232 | |
| 233 | Returns 0 |
| 234 | *******************************************************************/ |
| 235 | nodebug int DisplayReverse(int mode); |
| 236 | |
| 237 | /****************************************************************** |
| 238 | int DisplayClear(void) |
| 239 | Cear the entire display. |
| 240 | |
| 241 | Returns 0 |
| 242 | ******************************************************************/ |
| 243 | nodebug int DisplayClear(void); |
| 244 | |
| 245 | /****************************************************************** |
| 246 | int DisplayWindowClear(int window) |
| 247 | Clear a window, designated by the argument. |
| 248 | |
| 249 | Returns 0 |
| 250 | ******************************************************************/ |
| 251 | nodebug int DisplayWindowClear(int window); |
| 252 | |
| 253 | /****************************************************************** |
| 254 | void DspMsgArrow(char *line1, char *line2); |
| 255 | Show a two-line message, and append an arrow to the end |
| 256 | of the second line. |
| 257 | *******************************************************************/ |
| 258 | nodebug void DspMsgArrow(char *line1, char *line2); |
| 259 | |
| 260 | /****************************************************************** |
| 261 | void Display2Stdio(StdioMode mode); |
| 262 | Turn on/off echoing of display messages to stdio |
| 263 | |
| 264 | void DisplayToggleQuiet() |
| 265 | Toggles echoing of display messages to stdio |
| 266 | *******************************************************************/ |
| 267 | nodebug void Display2Stdio(StdioMode mode); |
| 268 | nodebug void DisplayToggleQuiet(); |
| 269 | |
| 270 | /****************************************************************** |
| 271 | void DisplayMagnify(int n) |
| 272 | Change the size of subsequently written characters |
| 273 | |
| 274 | n = 1 -> normal size |
| 275 | n = 2 -> double size |
| 276 | |
| 277 | Returns 0 |
| 278 | ******************************************************************/ |
| 279 | nodebug int DisplayMagnify(int n); // Magnify subsequenty written characters: 1 => normal, 2 => 2x |
| 280 | |
| 281 | /****************************************************************** |
| 282 | char *ConcatMsg(char *msg1, char *msg2, char *resultMsg) |
| 283 | Concatonate msg1 and msg2, storing the result in resultMsg. |
| 284 | The total resultant string is no longer than DISPLAY_LENGTH |
| 285 | ******************************************************************/ |
| 286 | nodebug char *ConcatMsg(char *msg1, char *msg2, char *resultMsg); // Concatonate two messages. Total result is no longer than DISPLAY_LENGTH |
| 287 | |
| 288 | void DisplayInit4711 (); //initialize display //write initial revision msg to display |
| 289 | int DspUpdate4711 (char *aLine1, char *aLine2); //write array to display |
| 290 | int WrtCmd (char aChar); //write specified command code to display 4711 |
| 291 | int WrtData (char aChar); //write display table contents to display 4711 |
| 292 | |
| 293 | /***************************************************************** |
| 294 | End of API for AUTOPAK_DISPLAY.LIB |
| 295 | *****************************************************************/ |
| 296 | |
| 297 | /*** EndHeader */ |
| 298 | |
| 299 | // Local Function Prototypes |
| 300 | nodebug int DisplayWrChar(char); // Write a byte to the display module |
| 301 | nodebug int DisplayWrString(char*); // Write a string to the display module |
| 302 | nodebug int DisplaySelectWindow(char window); // Select the "current window", 0 - 4, where 0 is the Main window |
| 303 | nodebug int DisplayCharacterWidth(int w); // Set the character cell width: 0 => 6 dots, 1 => 7 dots |
| 304 | nodebug int DisplaySetCursor(int x, int y); // Set the cursor position (the character position) |
| 305 | nodebug char *centerText(char *text, int leftEdge); |
| 306 | nodebug char *centerText2(char *text, int leftEdge); |
| 307 | nodebug int displayMsgPair(int leftPad, char *leftMsg, char *rightMsg, int rightPad, int lineNo); |
| 308 | nodebug int WrChar(char aChar); |
| 309 | nodebug int WrString(char *aString); |
| 310 | |
| 311 | |
| 312 | |
| 313 | // Variables |
| 314 | int CharacterWidth; // Character width in dots |
| 315 | int CharacterHeight; // Character height in dots |
| 316 | int Magnification; // 1 => 1x magnification, 2 => 2x magnification |
| 317 | StdioMode display2StdioFlag; // Echo all display strings to stdio? |
| 318 | |
| 319 | // API functions |
| 320 | |
| 321 | void InitializeDisplay(StdioMode mode) |
| 322 | { |
| 323 | int value; |
| 324 | printf("Init Display ...\n"); |
| 325 | Display2Stdio(mode); |
| 326 | CharacterHeight = 8; |
| 327 | Disp.Timer = MS_TIMER; |
| 328 | Disp.HoldTimer = MS_TIMER; |
| 329 | Disp.NextUpdate = DSP_HOLD; |
| 330 | Disp.UpdateFlag = 1; |
| 331 | Disp.Chan = -1; |
| 332 | Disp.Hold = 0; |
| 333 | |
| 334 | // Set up the hardware write bit |
| 335 | #if BOARDREV == 'A' |
| 336 | value = THREE_WAIT | WRITE_STROBE | PERMIT_WRITE; |
| 337 | WrPortI(IbRegister(DISPLAY_WR_BIT), NULL, value); // Set the appropriate I/O Bank Control register |
| 338 | BitWrPortI(PEFR, &PEFRShadow, 1, DISPLAY_WR_BIT); |
| 339 | BitWrPortI(PEDDR, &PEDDRShadow, 1, DISPLAY_WR_BIT); |
| 340 | #endif |
| 341 | |
| 342 | // Set up the hardware read / write bit |
| 343 | #if BOARDREV == 'B' || BOARDREV == 'C' |
| 344 | value = THREE_WAIT | CHIP_SELECT | PERMIT_WRITE; |
| 345 | WrPortI(IbRegister(DISPLAY_WR_BIT), NULL, value); // Set the appropriate I/O Bank Control register |
| 346 | BitWrPortI(PEFR, &PEFRShadow, 1, DISPLAY_WR_BIT); |
| 347 | BitWrPortI(PEDDR, &PEDDRShadow, 1, DISPLAY_WR_BIT); |
| 348 | |
| 349 | // value = THREE_WAIT | READ_STROBE; |
| 350 | // WrPortI(IbRegister(DISPLAY_RD_BIT), NULL, value); // Set the appropriate I/O Bank Control register |
| 351 | // BitWrPortI(PEFR, &PEFRShadow, 1, DISPLAY_RD_BIT); |
| 352 | // BitWrPortI(PEDDR, &PEDDRShadow, 1, DISPLAY_RD_BIT); |
| 353 | #endif |
| 354 | |
| 355 | #if BOARDREV == 'C' |
| 356 | DisplayInit4711(); |
| 357 | #else |
| 358 | // Initialize |
| 359 | WrChar(ESC); |
| 360 | WrChar('@'); |
| 361 | |
| 362 | // Clear |
| 363 | DisplayClear(); |
| 364 | |
| 365 | // Overwrite Mode (DSP_MD1) |
| 366 | WrChar(US); |
| 367 | WrChar(DSP_MD1); |
| 368 | |
| 369 | // Set the default brightness |
| 370 | DisplayBrightness(DEFAULT_BRIGHTNESS); |
| 371 | |
| 372 | // Fixed character width 1 |
| 373 | DisplayCharacterWidth(1); |
| 374 | |
| 375 | // No Magnification |
| 376 | DisplayMagnify(1); |
| 377 | |
| 378 | // Display screen mode = 0 |
| 379 | WrChar(US); |
| 380 | WrChar('('); |
| 381 | WrChar('w'); |
| 382 | WrChar(0x10); |
| 383 | WrChar(0); |
| 384 | |
| 385 | // American Font Set |
| 386 | WrChar(ESC); |
| 387 | WrChar('R'); |
| 388 | WrChar(0); |
| 389 | |
| 390 | // USA Character Code Type |
| 391 | WrChar(ESC); |
| 392 | WrChar('t'); |
| 393 | WrChar(0); |
| 394 | |
| 395 | // Non-reverse mode |
| 396 | DisplayReverse(0); |
| 397 | |
| 398 | // Write Mixture = Normal |
| 399 | WrChar(US); |
| 400 | WrChar('w'); |
| 401 | WrChar(0); |
| 402 | |
| 403 | // Normal size |
| 404 | DisplayMagnify(1); |
| 405 | #endif |
| 406 | } |
| 407 | |
| 408 | int DisplayText(char *text) {return DisplayWindowText(0, text);} |
| 409 | |
| 410 | char centeredText[DISPLAY_LENGTH + 1]; |
| 411 | char centeredText2[DISPLAY_LENGTH + 1]; |
| 412 | |
| 413 | int DisplayTextCentered(char *text) |
| 414 | { |
| 415 | DisplayText(centerText(text, 0)); |
| 416 | } |
| 417 | |
| 418 | char *centerText(char *text, int leftEdge) |
| 419 | { |
| 420 | int i; |
| 421 | int tspaces; |
| 422 | |
| 423 | tspaces = 0; |
| 424 | tspaces = DISPLAY_LENGTH - leftEdge - strlen(text); |
| 425 | if (tspaces < 0) |
| 426 | { |
| 427 | tspaces = 0; |
| 428 | leftEdge = 0; |
| 429 | } |
| 430 | memset(centeredText, 0, sizeof(centeredText)); |
| 431 | for (i = 0 ; i < leftEdge + tspaces / 2 ; i++) |
| 432 | { |
| 433 | centeredText[i] = ' '; |
| 434 | } |
| 435 | strcat(centeredText + i, text); |
| 436 | return centeredText; |
| 437 | } |
| 438 | |
| 439 | char *centerText2(char *text, int leftEdge) |
| 440 | { |
| 441 | int i; |
| 442 | int tspaces; |
| 443 | |
| 444 | tspaces = 0; |
| 445 | tspaces = DISPLAY_LENGTH - leftEdge - strlen(text); |
| 446 | if (tspaces < 0) |
| 447 | { |
| 448 | tspaces = 0; |
| 449 | leftEdge = 0; |
| 450 | } |
| 451 | memset(centeredText2, 0, sizeof(centeredText2)); |
| 452 | for (i = 0 ; i < leftEdge + tspaces / 2 ; i++) |
| 453 | { |
| 454 | centeredText2[i] = ' '; |
| 455 | } |
| 456 | strcat(centeredText2 + i, text); |
| 457 | return centeredText2; |
| 458 | } |
| 459 | |
| 460 | int DisplayWindowTextCentered(char window, char *text) |
| 461 | { |
| 462 | DisplayWindowText(window, centerText(text, 0)); |
| 463 | } |
| 464 | |
| 465 | int DisplayWindowText(char window, char *text) |
| 466 | { |
| 467 | int result; |
| 468 | int i; |
| 469 | |
| 470 | result = 0; |
| 471 | // Select the window |
| 472 | DisplaySelectWindow(window); |
| 473 | // Clear the window |
| 474 | DisplayWindowClear(window); |
| 475 | // Write the text |
| 476 | WrString(text); |
| 477 | return result; |
| 478 | } |
| 479 | |
| 480 | int DisplayTextAt(char *text, char xpos, char ypos) |
| 481 | { |
| 482 | return DisplayWindowTextAt(0, text, xpos, ypos); |
| 483 | } |
| 484 | |
| 485 | int DisplayTextCenteredAt(char *text, char xpos, char ypos) |
| 486 | { |
| 487 | return DisplayWindowTextAt(0, centerText(text, xpos), xpos, ypos); |
| 488 | } |
| 489 | |
| 490 | int DisplayMsg(char *line1, char *line2) |
| 491 | { |
| 492 | int result; |
| 493 | result = 0; |
| 494 | #if BOARDREV == 'C' |
| 495 | result = DspUpdate4711(line1, line2); |
| 496 | #else |
| 497 | result |= DisplayText(line1); |
| 498 | result |= DisplayTextAt(line2, 0, 1); |
| 499 | #endif |
| 500 | return result; |
| 501 | } |
| 502 | |
| 503 | int DisplayMsg1(char *line) |
| 504 | { |
| 505 | DisplayText(line); |
| 506 | return 0; |
| 507 | } |
| 508 | |
| 509 | int DisplayMsg2(char *line) |
| 510 | { |
| 511 | DisplayTextAt(line, 0, 1); |
| 512 | return 0; |
| 513 | } |
| 514 | |
| 515 | int DisplayMsg1Ctr(char *line) |
| 516 | { |
| 517 | DisplayTextCentered(line); |
| 518 | } |
| 519 | |
| 520 | int DisplayMsg2Ctr(char *line) |
| 521 | { |
| 522 | DisplayTextCenteredAt(line, 0, 1); |
| 523 | } |
| 524 | |
| 525 | int DisplayMsgCtr(char *line1, char *line2) |
| 526 | { |
| 527 | int result; |
| 528 | |
| 529 | result = 0; |
| 530 | |
| 531 | #if BOARDREV == 'C' |
| 532 | result = DspUpdate4711(centerText(line1, 0), centerText2(line2, 0)); |
| 533 | #else |
| 534 | result |= DisplayTextCentered(line1); |
| 535 | result |= DisplayTextCenteredAt(line2, 0, 1); |
| 536 | #endif |
| 537 | return result; |
| 538 | } |
| 539 | |
| 540 | int DisplayMsg1Pair(int leftPad, char *leftMsg, char *rightMsg, int rightPad) |
| 541 | { |
| 542 | return displayMsgPair(leftPad, leftMsg, rightMsg, rightPad, 0); |
| 543 | } |
| 544 | |
| 545 | int DisplayMsg2Pair(int leftPad, char *leftMsg, char *rightMsg, int rightPad) |
| 546 | { |
| 547 | return displayMsgPair(leftPad, leftMsg, rightMsg, rightPad, 1); |
| 548 | } |
| 549 | |
| 550 | int displayMsgPair(int leftPad, char *leftMsg, char *rightMsg, int rightPad, int lineNo) |
| 551 | { |
| 552 | char msg[DISPLAY_LENGTH+1]; |
| 553 | char aSpace; |
| 554 | int i; |
| 555 | char *ptr; |
| 556 | int innerPad; |
| 557 | |
| 558 | innerPad = DISPLAY_LENGTH - leftPad - strlen(leftMsg) - strlen(rightMsg) - rightPad; |
| 559 | if (innerPad < 0) innerPad = 0; // This'll look ugly, but it's the best we can do given the inputs |
| 560 | aSpace = ' '; |
| 561 | memset(msg, 0, sizeof(msg)); |
| 562 | ptr = msg; |
| 563 | for (i = 0 ; i < leftPad && ptr - msg <= DISPLAY_LENGTH ; i++) |
| 564 | { |
| 565 | *ptr++ = aSpace; |
| 566 | } |
| 567 | if (ptr - msg + strlen(leftMsg) <= DISPLAY_LENGTH) |
| 568 | { |
| 569 | strcat(msg, leftMsg); |
| 570 | ptr += strlen(leftMsg); |
| 571 | } |
| 572 | for (i = 0 ; i < innerPad && ptr - msg <= DISPLAY_LENGTH ; i++) |
| 573 | { |
| 574 | *ptr++ = aSpace; |
| 575 | } |
| 576 | if (ptr - msg + strlen(rightMsg) <= DISPLAY_LENGTH) |
| 577 | { |
| 578 | strcat(msg, rightMsg); |
| 579 | ptr += strlen(rightMsg); |
| 580 | } |
| 581 | for (i = 0 ; i < rightPad && ptr - msg <= DISPLAY_LENGTH ; i++) |
| 582 | { |
| 583 | *ptr++ = aSpace; |
| 584 | } |
| 585 | DisplayTextAt(msg, 0, lineNo); |
| 586 | return 0; |
| 587 | } |
| 588 | |
| 589 | int DisplayWindowTextAt(char window, char *text, char xpos, char ypos) |
| 590 | { |
| 591 | int result; |
| 592 | int i; |
| 593 | |
| 594 | result = 0; |
| 595 | |
| 596 | // Select the window |
| 597 | DisplaySelectWindow(window); |
| 598 | // Position the cursor |
| 599 | DisplaySetCursor(xpos, ypos); |
| 600 | // Write the text |
| 601 | WrString(text); |
| 602 | return result; |
| 603 | } |
| 604 | |
| 605 | int DisplayBrightness(char n) |
| 606 | { |
| 607 | int result; |
| 608 | |
| 609 | WrChar(US); |
| 610 | WrChar('X'); |
| 611 | WrChar(n); |
| 612 | |
| 613 | result = 0; |
| 614 | return result; |
| 615 | } |
| 616 | |
| 617 | int DisplaySelectWindow(char a) |
| 618 | { |
| 619 | int result; |
| 620 | result = 0; |
| 621 | |
| 622 | WrChar(US); |
| 623 | WrChar('('); |
| 624 | WrChar('w'); |
| 625 | WrChar(1); |
| 626 | WrChar(a); |
| 627 | |
| 628 | return result; |
| 629 | } |
| 630 | |
| 631 | int DisplayDefineWindow(char window, int xpos, int ypos, int xsize, int ysize) |
| 632 | { |
| 633 | int result; |
| 634 | char xPL, xPH, yPL, yPH, xSL, xSH, ySL, ySH; |
| 635 | result = 0; |
| 636 | |
| 637 | xPL = xpos & 0xff; |
| 638 | xPH = (xpos & 0xff00) >> 8; |
| 639 | yPL = ypos & 0xff; |
| 640 | yPH = (ypos & 0xff00) >> 8; |
| 641 | |
| 642 | xSL = xsize & 0xff; |
| 643 | xSH = (xsize & 0xff00) >> 8; |
| 644 | ySL = ysize & 0xff; |
| 645 | ySH = (ysize & 0xff00) >> 8; |
| 646 | |
| 647 | WrChar(US); |
| 648 | WrChar('('); |
| 649 | WrChar('w'); |
| 650 | WrChar(2); |
| 651 | WrChar(window); |
| 652 | WrChar(1); |
| 653 | WrChar(xPL); |
| 654 | WrChar(xPH); |
| 655 | WrChar(yPL); |
| 656 | WrChar(yPH); |
| 657 | WrChar(xSL); |
| 658 | WrChar(xSH); |
| 659 | WrChar(ySL); |
| 660 | WrChar(ySH); |
| 661 | |
| 662 | return result; |
| 663 | } |
| 664 | |
| 665 | int DisplayReverse(int mode) |
| 666 | { |
| 667 | WrChar(US); |
| 668 | WrChar('r'); |
| 669 | WrChar(mode); |
| 670 | } |
| 671 | |
| 672 | void DspMsgArrow(char *line1, char *line2) |
| 673 | { |
| 674 | DisplayText(line1); |
| 675 | DisplayTextAt(line2, 0, 1); |
| 676 | DisplayTextAt(">", 15, 1); |
| 677 | } |
| 678 | |
| 679 | // Local functions |
| 680 | |
| 681 | int WrChar(char aChar) |
| 682 | { |
| 683 | int result; |
| 684 | int i; |
| 685 | Ms then; |
| 686 | int rdDisplayAddress; |
| 687 | |
| 688 | result = 0; |
| 689 | then = (Ms)MS_TIMER; |
| 690 | |
| 691 | #if BOARDREV == 'A' |
| 692 | while (MS_TIMER - then < 3l); |
| 693 | WrPortE(ExternalAddress(DISPLAY_WR_BIT), NULL, aChar); |
| 694 | #endif |
| 695 | |
| 696 | #if BOARDREV == 'B' |
| 697 | rdDisplayAddress = ExternalAddress(DISPLAY_RD_BIT) + 0x000f; |
| 698 | while ((RdPortE(rdDisplayAddress) & PBUSY_BIT) && |
| 699 | (MS_TIMER - then < TIMEOUT_MS)); |
| 700 | WrPortE(ExternalAddress(DISPLAY_WR_BIT), NULL, aChar); |
| 701 | #endif |
| 702 | |
| 703 | #if BOARDREV == 'C' |
| 704 | result = WrtData(aChar); |
| 705 | #endif |
| 706 | |
| 707 | return result; |
| 708 | } |
| 709 | |
| 710 | int WrString(char *aString) |
| 711 | { |
| 712 | int result; |
| 713 | int i; |
| 714 | result = 0; |
| 715 | |
| 716 | for (i = 0 ; i < strlen(aString) ; i++) WrChar(aString[i]); |
| 717 | if (display2StdioFlag == STDIO_ON) printf("Display::WrString: %s\n", aString); |
| 718 | |
| 719 | return result; |
| 720 | } |
| 721 | |
| 722 | |
| 723 | int DisplayClear() |
| 724 | { |
| 725 | return DisplayWindowClear(0); |
| 726 | } |
| 727 | |
| 728 | int DisplayWindowClear(int window) |
| 729 | { |
| 730 | int result; |
| 731 | |
| 732 | result = 0; |
| 733 | |
| 734 | DisplaySelectWindow(window); |
| 735 | WrChar(CLR); |
| 736 | |
| 737 | return result; |
| 738 | } |
| 739 | |
| 740 | int DisplayCharacterWidth(int w) |
| 741 | { |
| 742 | int result; |
| 743 | result = 0; |
| 744 | |
| 745 | WrChar(US); |
| 746 | WrChar('('); |
| 747 | WrChar('g'); |
| 748 | WrChar(3); |
| 749 | WrChar(w); |
| 750 | |
| 751 | CharacterWidth = 0; |
| 752 | if (w == 0) CharacterWidth = 6; |
| 753 | if (w == 1) CharacterWidth = 7; |
| 754 | |
| 755 | return result; |
| 756 | } |
| 757 | |
| 758 | int DisplayMagnify(int n) |
| 759 | { |
| 760 | if (n > 2) n = 2; |
| 761 | if (n < 1) n = 1; |
| 762 | |
| 763 | WrChar(US); |
| 764 | WrChar('('); |
| 765 | WrChar('g'); |
| 766 | WrChar(0x40); |
| 767 | WrChar(n); |
| 768 | WrChar(n); |
| 769 | |
| 770 | Magnification = n; |
| 771 | } |
| 772 | |
| 773 | int DisplaySetCursor(int xpos, int ypos) |
| 774 | { |
| 775 | char xL, xH, yL, yH; |
| 776 | |
| 777 | xpos *= CharacterWidth * Magnification; |
| 778 | ypos *= Magnification; |
| 779 | |
| 780 | xL = xpos & 0xff; |
| 781 | xH = (xpos & 0xff00) >> 8; |
| 782 | yL = ypos & 0xff; |
| 783 | yH = (ypos & 0xff00) >> 8; |
| 784 | |
| 785 | WrChar(US); |
| 786 | WrChar('$'); |
| 787 | WrChar(xL); |
| 788 | WrChar(xH); |
| 789 | WrChar(yL); |
| 790 | WrChar(yH); |
| 791 | |
| 792 | } |
| 793 | |
| 794 | void Display2Stdio(StdioMode mode) |
| 795 | { |
| 796 | display2StdioFlag = mode; |
| 797 | } |
| 798 | |
| 799 | void DisplayToggleQuiet() // needs to be root because it is called indirectly from keyboard.lib |
| 800 | { |
| 801 | display2StdioFlag = (display2StdioFlag == STDIO_ON) ? STDIO_OFF : STDIO_ON; |
| 802 | } |
| 803 | |
| 804 | char concatMsg[DISPLAY_LENGTH + 1]; |
| 805 | char *ConcatMsg(char *msg1, char *msg2, char *resultMsg) |
| 806 | { |
| 807 | char *dest; |
| 808 | dest = concatMsg; |
| 809 | if (resultMsg != NULL) dest = resultMsg; |
| 810 | StrSafeCopy(dest, msg1, DISPLAY_LENGTH); |
| 811 | strncat(dest, msg2, DISPLAY_LENGTH - strlen(dest)); |
| 812 | return dest; |
| 813 | } |
| 814 | |
| 815 | //Write specified command code to display 4711 ****************************************** |
| 816 | |
| 817 | int WrtCmd (char aChar) |
| 818 | { |
| 819 | int result; |
| 820 | |
| 821 | result = 0; |
| 822 | |
| 823 | WrPortE(ExternalAddress(DISPLAY_WR_BIT) + DISPLAY_ADR_BIT_CMD, NULL, aChar); //return form asm code subroutine |
| 824 | |
| 825 | return result; |
| 826 | } |
| 827 | |
| 828 | //Write chareter in display table array to display - 4711 ******************************** |
| 829 | |
| 830 | int WrtData (char aChar) |
| 831 | { |
| 832 | int result; |
| 833 | |
| 834 | result = 0; |
| 835 | |
| 836 | WrPortE(ExternalAddress(DISPLAY_WR_BIT) + DISPLAY_ADR_BIT_DTA, NULL, aChar); //return form asm code subroutine |
| 837 | |
| 838 | return result; |
| 839 | } |
| 840 | |
| 841 | //Display initialization **************************************************************** |
| 842 | |
| 843 | void DisplayInit4711 () |
| 844 | { |
| 845 | WrtCmd (0x38); //function set, initialize to 8 bit mode |
| 846 | MsDelay (5); //delay 5 ms |
| 847 | WrtCmd (0x38); //function set, initialize to 8 bit mode |
| 848 | MsDelay (5); //delay 5 ms |
| 849 | WrtCmd (0x08); //turn display off |
| 850 | MsDelay (5); //delay 5 ms |
| 851 | WrtCmd (0x01); //clear display to blanks |
| 852 | MsDelay (5); //delay 5 ms |
| 853 | WrtCmd (0x0C); //set display on, cursor off, blink off |
| 854 | MsDelay (5); //delay 5 ms |
| 855 | WrtCmd (0x06); //set increment ads, cursor shift on |
| 856 | MsDelay (5); |
| 857 | } |
| 858 | |
| 859 | //Display Update from selected array **************************************************** |
| 860 | |
| 861 | int DspUpdate4711 (char *aLine1, char *aLine2) |
| 862 | { |
| 863 | int i; //declare local variable |
| 864 | int result; |
| 865 | |
| 866 | result = 0; |
| 867 | |
| 868 | MsDelay (5); //delay in case dsp wrts are close |
| 869 | WrtCmd (0x80); //set DDRAM to begin of first half |
| 870 | MsDelay (5); |
| 871 | for (i = 0 ; i < strlen(aLine1) ; i++) |
| 872 | { |
| 873 | WrtData(aLine1[i]); //delay for dsp exec |
| 874 | MsDelay (2); //delay for dsp exec |
| 875 | } |
| 876 | WrtCmd (0xC0); //set DDRAM to begin of second half |
| 877 | MsDelay (5); //delay for dsp exec |
| 878 | for (i = 0 ; i < strlen(aLine2) ; i++) |
| 879 | { |
| 880 | WrtData(aLine2[i]); //delay for dsp exec |
| 881 | MsDelay (2); //delay for dsp exec |
| 882 | } |
| 883 | } |
| 884 | |
| 885 | /*** BeginHeader */ |
| 886 | #endif |
| 887 | /*** EndHeader */ |