?lang_form? ?lang_select? ?lang_submit? ?lang_endform?
{HEADER END}
{BLAME START}

library

?curdirlinks? -

Blame information for rev 32

Line No. Rev Author Line
1 32 kaklik /*****************************************************************************
2 * Module for Microchip Graphics Library
3 * Solomon Systech. SSD1926 LCD controller driver
4 * to be used with GFX 3 PICtail board
5 *****************************************************************************
6 * FileName: SSD1926.c
7 * Dependencies: Graphics.h
8 * Processor: PIC24, PIC32
9 * Compiler: MPLAB C30, MPLAB C32
10 * Linker: MPLAB LINK30, MPLAB LINK32
11 * Company: Microchip Technology Incorporated
12 *
13 * Software License Agreement
14 *
15 * Copyright © 2008 Microchip Technology Inc. All rights reserved.
16 * Microchip licenses to you the right to use, modify, copy and distribute
17 * Software only when embedded on a Microchip microcontroller or digital
18 * signal controller, which is integrated into your product or third party
19 * product (pursuant to the sublicense terms in the accompanying license
20 * agreement).
21 *
22 * You should refer to the license agreement accompanying this Software
23 * for additional information regarding your rights and obligations.
24 *
25 * SOFTWARE AND DOCUMENTATION ARE PROVIDED “AS IS” WITHOUT WARRANTY OF ANY
26 * KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION, ANY WARRANTY
27 * OF MERCHANTABILITY, TITLE, NON-INFRINGEMENT AND FITNESS FOR A PARTICULAR
28 * PURPOSE. IN NO EVENT SHALL MICROCHIP OR ITS LICENSORS BE LIABLE OR
29 * OBLIGATED UNDER CONTRACT, NEGLIGENCE, STRICT LIABILITY, CONTRIBUTION,
30 * BREACH OF WARRANTY, OR OTHER LEGAL EQUITABLE THEORY ANY DIRECT OR INDIRECT
31 * DAMAGES OR EXPENSES INCLUDING BUT NOT LIMITED TO ANY INCIDENTAL, SPECIAL,
32 * INDIRECT, PUNITIVE OR CONSEQUENTIAL DAMAGES, LOST PROFITS OR LOST DATA,
33 * COST OF PROCUREMENT OF SUBSTITUTE GOODS, TECHNOLOGY, SERVICES, OR ANY
34 * CLAIMS BY THIRD PARTIES (INCLUDING BUT NOT LIMITED TO ANY DEFENSE THEREOF),
35 * OR OTHER SIMILAR COSTS.
36 *
37 * Author Date Comment
38 *~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
39 * Anton Alkhimenok 08/27/08
40 * Jayanth Murthy 06/25/09 dsPIC & PIC24H support
41 * Pradeep Budagutta 07/30/09 Added Palette Support
42 * PAT 02/05/10 Fixed GetPixel() bug
43 * PAT 03/03/10 Fixed Circle() bug
44 * PAT 03/26/10 Fixed Line2D() bug
45 *****************************************************************************/
46 #include "Graphics\Graphics.h"
47  
48 // Color
49 WORD _color;
50  
51 // Clipping region control
52 SHORT _clipRgn;
53  
54 // Clipping region borders
55 SHORT _clipLeft;
56 SHORT _clipTop;
57 SHORT _clipRight;
58 SHORT _clipBottom;
59  
60 #define RED8(color16) (BYTE) ((color16 & 0xF800) >> 8)
61 #define GREEN8(color16) (BYTE) ((color16 & 0x07E0) >> 3)
62 #define BLUE8(color16) (BYTE) ((color16 & 0x001F) << 3)
63  
64 /////////////////////// LOCAL FUNCTIONS PROTOTYPES ////////////////////////////
65 void SetAddress(DWORD address);
66 void SetReg(WORD index, BYTE value);
67 BYTE GetReg(WORD index);
68  
69 void PutImage1BPP(SHORT left, SHORT top, FLASH_BYTE *bitmap, BYTE stretch);
70 void PutImage4BPP(SHORT left, SHORT top, FLASH_BYTE *bitmap, BYTE stretch);
71 void PutImage8BPP(SHORT left, SHORT top, FLASH_BYTE *bitmap, BYTE stretch);
72 void PutImage16BPP(SHORT left, SHORT top, FLASH_BYTE *bitmap, BYTE stretch);
73  
74 void PutImage1BPPExt(SHORT left, SHORT top, void *bitmap, BYTE stretch);
75 void PutImage4BPPExt(SHORT left, SHORT top, void *bitmap, BYTE stretch);
76 void PutImage8BPPExt(SHORT left, SHORT top, void *bitmap, BYTE stretch);
77 void PutImage16BPPExt(SHORT left, SHORT top, void *bitmap, BYTE stretch);
78  
79 #if (DISPLAY_PANEL == TFT_G240320LTSW_118W_E)
80 #include "TCON_SSD1289.c"
81  
82 #elif (DISPLAY_PANEL == TFT_G320240DTSW_69W_TP_E)
83 #include "TCON_HX8238.c"
84  
85 #elif (DISPLAY_PANEL == PH480272T_005_I06Q)
86 #include "TCON_HX8257.c"
87  
88 #else
89 #include "TCON_Custom.c"
90 #endif
91  
92 #ifdef USE_PALETTE
93 extern void *_palette;
94 static BYTE PaletteBpp = 16;
95 extern BYTE blPaletteChangeError;
96 extern void *pPendingPalette;
97 extern WORD PendingStartEntry;
98 extern WORD PendingLength;
99 #endif
100  
101 /*********************************************************************
102 * Macro: WritePixel(color)
103 *
104 * PreCondition: none
105 *
106 * Input: color
107 *
108 * Output: none
109 *
110 * Side Effects: none
111 *
112 * Overview: writes pixel at the current address
113 *
114 * Note: chip select should be enabled
115 *
116 ********************************************************************/
117 #ifdef USE_16BIT_PMP
118 #define WritePixel(color) DeviceWrite(color)
119 #else
120 #ifdef USE_PALETTE
121 #define WritePixel(color) DeviceWrite(color)
122 #else
123 #define WritePixel(color) { DeviceWrite(((WORD_VAL)color).v[1]); DeviceWrite(((WORD_VAL)color).v[0]);}
124 #endif
125 #endif
126  
127 /*********************************************************************
128 * Function: void SetAddress(DWORD address)
129 *
130 * PreCondition: none
131 *
132 * Input: address - address
133 *
134 * Output: none
135 *
136 * Side Effects: none
137 *
138 * Overview: sets the address for read/write operations
139 *
140 * Note: chip select should be enabled
141 *
142 ********************************************************************/
143 void SetAddress(DWORD address)
144 {
145 #ifdef USE_16BIT_PMP
146 WORD_VAL temp;
147  
148 DeviceSetCommand(); // set RS line to low for command
149  
150 temp.v[0] = ((DWORD_VAL) address).v[1];
151 temp.v[1] = ((DWORD_VAL) address).v[2] | 0x80;
152 DeviceWrite(temp.Val);
153 temp.v[0] = 0x01;
154 temp.v[1] = ((DWORD_VAL) address).v[0];
155 DeviceWrite(temp.Val);
156  
157 DeviceSetData(); // set RS line to high for data
158  
159 #else
160  
161 DeviceSetCommand(); // set RS line to low for command
162  
163 DeviceWrite(((DWORD_VAL) address).v[2] | 0x80);
164 DeviceWrite(((DWORD_VAL) address).v[1]);
165 DeviceWrite(((DWORD_VAL) address).v[0]);
166  
167 DeviceSetData(); // set RS line to high for data
168  
169 #endif
170 }
171  
172 /*********************************************************************
173 * Function: void SetReg(WORD index, BYTE value)
174 *
175 * PreCondition: none
176 *
177 * Input: index - register number
178 * value - value to be set
179 *
180 * Output: none
181 *
182 * Side Effects: none
183 *
184 * Overview: sets graphics controller register (byte access)
185 *
186 * Note: none
187 *
188 ********************************************************************/
189 void SetReg(WORD index, BYTE value)
190 {
191 #ifdef USE_16BIT_PMP
192  
193 DeviceSetCommand(); // set RS line to low for command
194 DeviceSelect(); // enable SSD1926
195  
196 DeviceWrite(((WORD_VAL) index).v[1]);
197 DeviceWrite(index << 8);
198  
199 DeviceSetData(); // set RS line to high for data
200  
201 if(index & 0x0001)
202 DeviceWrite(value);
203 else
204 DeviceWrite(value << 8);
205  
206 DeviceDeselect(); // disable SSD1926
207  
208 #else
209  
210 DeviceSetCommand(); // set RS line to low for command
211 DeviceSelect(); // enable SSD1926
212  
213 DeviceWrite(0x00); // register access
214 DeviceWrite(((WORD_VAL) index).v[1]);
215 DeviceWrite(((WORD_VAL) index).v[0]);
216  
217 DeviceSetData(); // set RS line to high for data
218 DeviceWrite(value);
219  
220 DeviceDeselect(); // disable SSD1926
221 #endif
222 }
223  
224 /*********************************************************************
225 * Function: BYTE GetReg(WORD index)
226 *
227 * PreCondition: none
228 *
229 * Input: index - register number
230 *
231 * Output: none
232 *
233 * Side Effects: none
234 *
235 * Overview: returns graphics controller register value (byte access)
236 *
237 * Note: none
238 *
239 ********************************************************************/
240 BYTE GetReg(WORD index)
241 {
242 #ifdef USE_16BIT_PMP
243  
244 WORD value;
245  
246 DeviceSetCommand(); // set RS line to low for command
247 DeviceSelect(); // enable SSD1926
248  
249 DeviceWrite(((WORD_VAL) index).v[1]);
250 DeviceWrite(index << 8);
251  
252 DeviceSetData(); // set RS line to high for data
253  
254 value = DeviceRead();
255 value = DeviceRead();
256  
257 DeviceDeselect(); // disable SSD1926
258  
259 if(index & 0x0001)
260 value &= 0x00ff;
261 else
262 value = (value >> 8) & 0x00ff;
263  
264 #else
265 BYTE value;
266  
267 DeviceSetCommand(); // set RS line to low for command
268 DeviceSelect(); // enable SSD1926
269  
270 DeviceWrite(0x00); // register access
271 DeviceWrite(((WORD_VAL) index).v[1]);
272 DeviceWrite(((WORD_VAL) index).v[0]);
273  
274 DeviceSetData(); // set RS line to high for data
275  
276 value = DeviceRead();
277 value = DeviceRead();
278  
279 DeviceDeselect(); // disable SSD1926
280 #endif
281  
282 return (value);
283 }
284  
285 /*********************************************************************
286 * Function: void ResetDevice()
287 *
288 * PreCondition: none
289 *
290 * Input: none
291 *
292 * Output: none
293 *
294 * Side Effects: none
295 *
296 * Overview: resets LCD, initializes PMP
297 *
298 * Note: none
299 *
300 ********************************************************************/
301 void ResetDevice(void)
302 {
303 /////////////////////////////////////////////////////////////////////
304 // Initialize the device
305 /////////////////////////////////////////////////////////////////////
306 DeviceInit();
307  
308 /////////////////////////////////////////////////////////////////////
309 // PLL SETUP
310 // Crystal frequency x M / N = 80 MHz
311 // for 4 MHz crystal:
312 /////////////////////////////////////////////////////////////////////
313 SetReg(REG_PLL_CONFIG_0, 0x0a); // set N = 10
314 SetReg(REG_PLL_CONFIG_1, 0xc8); // set M = 200
315 SetReg(REG_PLL_CONFIG_2, 0xae); // must be programmed to 0xAE
316 SetReg(REG_PLL_CONFIG_0, 0x8a); // enable PLL
317  
318 /////////////////////////////////////////////////////////////////////
319 // VIDEO BUFFER MEMORY CLOCK SETUP
320 // Memory frequency = PLL frequency / (MCLK + 1)
321 /////////////////////////////////////////////////////////////////////
322 SetReg(REG_MEMCLK_CONFIG, 0x00); // set MCLK = 0 (80 MHz)
323  
324 /////////////////////////////////////////////////////////////////////
325  
326 // PIXEL OUTPUT CLOCK SETUP (LCD_SHIFT SIGNAL)
327 // Pixel clock = Memory frequency * (PCLK + 1) / 0x100000
328 /////////////////////////////////////////////////////////////////////
329 SetReg(REG_PCLK_FREQ_RATIO_0, 0x00); // set PCLK = 0x020000
330 SetReg(REG_PCLK_FREQ_RATIO_1, 0x00); // Pixel clock = 10 MHz
331 SetReg(REG_PCLK_FREQ_RATIO_2, 0x02);
332  
333 /////////////////////////////////////////////////////////////////////
334 // Panel Configuration (reg 10h)
335 // TFT display with 18 bit or 24-bit RGB parallel interface.
336 /////////////////////////////////////////////////////////////////////
337 #if (DISP_DATA_WIDTH == 18)
338 SetReg(REG_PANEL_TYPE, 0x61);
339 #else
340 SetReg(REG_PANEL_TYPE, 0x71);
341 #endif
342  
343 /////////////////////////////////////////////////////////////////////
344 // Horizontal total HT (reg 12h)
345 /////////////////////////////////////////////////////////////////////
346 #define HT (DISP_HOR_PULSE_WIDTH + DISP_HOR_BACK_PORCH + DISP_HOR_FRONT_PORCH + DISP_HOR_RESOLUTION)
347 SetReg(REG_HORIZ_TOTAL_0, HT / 8);
348 SetReg(REG_HORIZ_TOTAL_1, HT % 8);
349  
350 /////////////////////////////////////////////////////////////////////
351 // Horizontal display period HDP (reg 14h)
352 /////////////////////////////////////////////////////////////////////
353 SetReg(REG_HDP, DISP_HOR_RESOLUTION / 8 - 1);
354  
355 /////////////////////////////////////////////////////////////////////
356 // Horizontal display period start HDPS (regs 16h, 17h)
357 /////////////////////////////////////////////////////////////////////
358 #define HDPS (DISP_HOR_PULSE_WIDTH + DISP_HOR_BACK_PORCH)
359 SetReg(REG_HDP_START_POS0, HDPS & 0x00FF);
360 SetReg(REG_HDP_START_POS1, (HDPS >> 8) & 0x00FF);
361  
362 /////////////////////////////////////////////////////////////////////
363 // Horizontal syncronization pulse width HPW (reg 20h)
364 /////////////////////////////////////////////////////////////////////
365 SetReg(REG_HSYNC_PULSE_WIDTH, DISP_HOR_PULSE_WIDTH - 1);
366  
367 /////////////////////////////////////////////////////////////////////
368 // Vertical total VT (regs 18h, 19h)
369 /////////////////////////////////////////////////////////////////////
370 #define VT (DISP_VER_PULSE_WIDTH + DISP_VER_BACK_PORCH + DISP_VER_FRONT_PORCH + DISP_VER_RESOLUTION)
371 SetReg(REG_VERT_TOTAL0, VT & 0x00FF);
372 SetReg(REG_VERT_TOTAL1, (VT >> 8) & 0x00FF);
373  
374 /////////////////////////////////////////////////////////////////////
375 // Vertical display period VDP (regs 1ch, 1dh)
376 /////////////////////////////////////////////////////////////////////
377 #define VDP (DISP_VER_RESOLUTION - 1)
378 SetReg(REG_VDP0, VDP & 0x00FF);
379 SetReg(REG_VDP1, (VDP >> 8) & 0x00FF);
380  
381 /////////////////////////////////////////////////////////////////////
382 // Vertical display period start VDPS (regs 1eh, 1fh)
383 /////////////////////////////////////////////////////////////////////
384 #define VDPS (DISP_VER_PULSE_WIDTH + DISP_VER_BACK_PORCH)
385 SetReg(REG_VDP_START_POS0, VDPS & 0x00FF);
386 SetReg(REG_VDP_START_POS1, (VDPS >> 8) & 0x00FF);
387  
388 /////////////////////////////////////////////////////////////////////
389 // Vertical syncronization pulse width VPW (reg 24h)
390 /////////////////////////////////////////////////////////////////////
391 SetReg(REG_VSYNC_PULSE_WIDTH, DISP_VER_PULSE_WIDTH - 1);
392  
393 /////////////////////////////////////////////////////////////////////
394 // PALETTE INIT
395 #ifdef USE_PALETTE
396 PaletteInit();
397 #endif
398  
399 /////////////////////////////////////////////////////////////////////
400 // ROTATION MODE
401 #if (DISP_ORIENTATION == 0)
402 #define WIN_START_ADDR 0ul
403 #define ROTATION 0
404  
405 #elif (DISP_ORIENTATION == 90)
406 #ifndef USE_PALETTE
407 #define WIN_START_ADDR ((((DWORD) GetMaxX() + 1) >> 1) - 1)
408 #else
409 #define WIN_START_ADDR (((((DWORD) GetMaxX() + 1) * PaletteBpp) >> 5) - 1)
410 #endif
411 #define ROTATION 1
412  
413 #elif (DISP_ORIENTATION == 180)
414 #ifndef USE_PALETTE
415 #define WIN_START_ADDR (((((DWORD) GetMaxX() + 1) * (GetMaxY() + 1)) >> 1) - 1)
416 #else
417 #define WIN_START_ADDR (((((DWORD) GetMaxX() + 1) * (GetMaxY() + 1) * PaletteBpp) >> 5) - 1)
418 #endif
419 #define ROTATION 2
420  
421 #elif (DISP_ORIENTATION == 270)
422 #ifndef USE_PALETTE
423 #define WIN_START_ADDR ((((DWORD) GetMaxX() + 1) * GetMaxY()) >> 1)
424 #else
425 #define WIN_START_ADDR ((((DWORD) GetMaxX() + 1) * GetMaxY() * PaletteBpp) >> 5)
426 #endif
427 #define ROTATION 3
428 #endif
429  
430 /////////////////////////////////////////////////////////////////////
431 // Special Effects Register (reg 71h)
432 /////////////////////////////////////////////////////////////////////
433 #ifndef USE_PALETTE
434 SetReg(REG_SPECIAL_EFFECTS, 0x40 | ROTATION);
435 #else
436 SetReg(REG_SPECIAL_EFFECTS, 0x00 | ROTATION);
437 #endif
438  
439 /////////////////////////////////////////////////////////////////////
440 // Main Window Display Start Address (regs 74h, 75h, 76h)
441 /////////////////////////////////////////////////////////////////////
442 SetReg(REG_MAIN_WIN_DISP_START_ADDR0, WIN_START_ADDR & 0x00FF);
443 SetReg(REG_MAIN_WIN_DISP_START_ADDR1, (WIN_START_ADDR >> 8) & 0x00FF);
444 SetReg(REG_MAIN_WIN_DISP_START_ADDR2, (WIN_START_ADDR >> 16) & 0x00FF);
445  
446 /////////////////////////////////////////////////////////////////////
447 // Main Window Display Offset (regs 78h, 79h)
448 /////////////////////////////////////////////////////////////////////
449 #ifndef USE_PALETTE
450 #define WIN_OFFSET ((GetMaxX() + 1) >> 1)
451 #else
452 #define WIN_OFFSET (((GetMaxX() + 1) * PaletteBpp) >> 5)
453 #endif
454 SetReg(REG_MAIN_WIN_ADDR_OFFSET0, WIN_OFFSET & 0x00FF);
455 SetReg(REG_MAIN_WIN_ADDR_OFFSET1, (WIN_OFFSET >> 8) & 0x00FF);
456  
457 /////////////////////////////////////////////////////////////////////
458 // Display Mode Register (reg 70h)
459 /////////////////////////////////////////////////////////////////////
460 SetReg(REG_DISPLAY_MODE, 0x04); // 16 BPP, enable RAM content to screen
461  
462 /////////////////////////////////////////////////////////////////////
463  
464 // RGB Settings Register (reg 1a4h)
465 /////////////////////////////////////////////////////////////////////
466 SetReg(REG_RGB_SETTING, 0xc0); // RGB format
467  
468 /////////////////////////////////////////////////////////////////////
469  
470 // Power Saving Configuration Register (reg a0h)
471 /////////////////////////////////////////////////////////////////////
472 SetReg(REG_POWER_SAVE_CONFIG, 0x00); // wake up
473  
474 /////////////////////////////////////////////////////////////////////
475  
476 // LSHIFT Polarity Register (reg 38h)
477 /////////////////////////////////////////////////////////////////////
478 #ifdef DISP_INV_LSHIFT
479 SetReg(REG_LSHIFT_POLARITY, 0x01); // 1 means falling trigger
480 #endif
481  
482 /////////////////////////////////////////////////////////////////////
483 // LCD Power Control Register (reg adh)
484 // If LCD_POWER is connected to the glass DISPON or RESET
485 /////////////////////////////////////////////////////////////////////
486 SetReg(REG_GPIO_STATUS_CONTROL1, 0x80); // release the glass from reset
487  
488 /////////////////////////////////////////////////////////////////////
489 // Panel TCON Programming
490 /////////////////////////////////////////////////////////////////////
491 TCON_Init();
492 }
493  
494 /*********************************************************************
495 * Function: void PutPixel(SHORT x, SHORT y)
496 *
497 * PreCondition: none
498 *
499 * Input: x,y - pixel coordinates
500 *
501 * Output: none
502 *
503 * Side Effects: none
504 *
505 * Overview: puts pixel
506 *
507 * Note: none
508 *
509 ********************************************************************/
510 void PutPixel(SHORT x, SHORT y)
511 {
512 DWORD address;
513  
514 if(_clipRgn)
515 {
516 if(x < _clipLeft)
517 return;
518 if(x > _clipRight)
519 return;
520 if(y < _clipTop)
521 return;
522 if(y > _clipBottom)
523 return;
524 }
525  
526 #ifndef USE_PALETTE
527 address = (((DWORD) (GetMaxX() + 1)) * y + x) << 1;
528 #else
529 address = ((((DWORD) (GetMaxX() + 1)) * y + x) * PaletteBpp) >> 3;
530 #endif
531 DeviceSelect(); // enable SSD1926
532 SetAddress(address);
533 WritePixel(_color);
534 DeviceDeselect(); // disable SSD1926
535 }
536  
537 /*********************************************************************
538 * Function: WORD GetPixel(SHORT x, SHORT y)
539 *
540 * PreCondition: none
541 *
542 * Input: x,y - pixel coordinates
543 *
544 * Output: pixel color
545 *
546 * Side Effects: none
547 *
548 * Overview: returns pixel color at x,y position
549 *
550 * Note: none
551 *
552 ********************************************************************/
553 WORD GetPixel(SHORT x, SHORT y)
554 {
555 DWORD address;
556  
557 address = (((DWORD) (GetMaxX() + 1)) * y + x) << 1;
558  
559 #ifdef USE_16BIT_PMP
560  
561 WORD value;
562  
563 DeviceSelect();
564  
565 SetAddress(address);
566 value = DeviceRead();
567 value = DeviceRead();
568  
569 DeviceDeselect();
570  
571 return (value);
572 #else
573  
574 WORD_VAL value;
575  
576 DeviceSelect();
577  
578 SetAddress(address);
579  
580 #if defined(USE_GFX_PMP)
581 // this first two reads are a dummy reads
582 value.Val = SingleDeviceRead();
583 value.Val = SingleDeviceRead();
584 // these are the reads that will get the actual pixel data
585 value.v[1] = SingleDeviceRead();
586 value.v[0] = SingleDeviceRead();
587 #endif
588  
589 #if defined(USE_GFX_EPMP)
590 value.Val = DeviceRead();
591 value.v[1] = DeviceRead();
592 value.v[0] = DeviceRead();
593 #endif
594 DeviceDeselect();
595  
596 return (value.Val);
597 #endif
598 }
599  
600 #ifdef USE_DRV_LINE
601  
602 /*********************************************************************
603 * Function: WORD Line2D(SHORT x1, SHORT y1, SHORT x2, SHORT y2)
604 *
605 * PreCondition: none
606 *
607 * Input: x1,y1 - starting coordinates, x2,y2 - ending coordinates
608 *
609 * Output: For NON-Blocking configuration:
610 * - Returns 0 when device is busy and the shape is not yet completely drawn.
611 * - Returns 1 when the shape is completely drawn.
612 * For Blocking configuration:
613 * - Always return 1.
614 *
615 * Side Effects: none
616 *
617 * Overview: draws solid line
618 *
619 * Note: none
620 *
621 ********************************************************************/
622 static WORD Line2D(SHORT x1, SHORT y1, SHORT x2, SHORT y2)
623 {
624 #ifndef USE_NONBLOCKING_CONFIG
625 while(IsDeviceBusy() != 0);
626  
627 /* Ready */
628 #else
629 if(IsDeviceBusy() != 0)
630 return (0);
631 #endif
632  
633 /* Line Boundaries */
634 SetReg(REG_2D_1e4, x1 & 0xFF);
635 SetReg(REG_2D_1e5, (x1 >> 8) & 0xFF);
636 SetReg(REG_2D_1e8, y1 & 0xFF);
637 SetReg(REG_2D_1e9, (y1 >> 8) & 0xFF);
638 SetReg(REG_2D_1ec, x2 & 0xFF);
639 SetReg(REG_2D_1ed, (x2 >> 8) & 0xFF);
640 SetReg(REG_2D_1f0, y2 & 0xFF);
641 SetReg(REG_2D_1f1, (y2 >> 8) & 0xFF);
642  
643 /* Source & Destination Window Start Addresses */
644 SetReg(REG_2D_1d4, 0);
645 SetReg(REG_2D_1d5, 0);
646 SetReg(REG_2D_1d6, 0);
647 SetReg(REG_2D_1f4, 0);
648 SetReg(REG_2D_1f5, 0);
649 SetReg(REG_2D_1f6, 0);
650  
651 /* Display width */
652 SetReg(REG_2D_1f8, (GetMaxX() + 1) & 0xFF);
653 SetReg(REG_2D_1f9, ((GetMaxX() + 1) >> 8) & 0xFF);
654  
655 /* Display 2d width */
656 SetReg(REG_2D_1d8, (GetMaxY() + 1) & 0xFF);
657 SetReg(REG_2D_1d9, ((GetMaxY() + 1) >> 8) & 0xFF);
658  
659 /* Set Color */
660 SetReg(REG_2D_1fe, RED8(_color));
661 SetReg(REG_2D_1fd, GREEN8(_color));
662 SetReg(REG_2D_1fc, BLUE8(_color));
663  
664 /* 16bpp */
665 SetReg(REG_2D_1dd, 0x00);
666  
667 /* Line command */
668 SetReg(REG_2D_1d1, 0x01);
669  
670 /* Draw2d command */
671 SetReg(REG_2D_1d2, 0x01);
672  
673 #ifndef USE_NONBLOCKING_CONFIG
674 while(IsDeviceBusy() != 0);
675  
676 /* Ready */
677 #endif
678 return (1);
679 }
680  
681 /*********************************************************************
682 * Function: WORD Line(SHORT x1, SHORT y1, SHORT x2, SHORT y2)
683 *
684 * PreCondition: none
685 *
686 * Input: x1,y1 - starting coordinates, x2,y2 - ending coordinates
687 *
688 * Output: For NON-Blocking configuration:
689 * - Returns 0 when device is busy and the shape is not yet completely drawn.
690 * - Returns 1 when the shape is completely drawn.
691 * For Blocking configuration:
692 * - Always return 1.
693 *
694 * Side Effects: none
695 *
696 * Overview: draws line
697 *
698 * Note: none
699 *
700 ********************************************************************/
701 WORD Line(SHORT x1, SHORT y1, SHORT x2, SHORT y2)
702 {
703 #ifdef USE_PALETTE
704 #error "In SSD1926 2D-Acceleration is not supported in Palette mode. Use Line function of Primitive layer"
705 #endif
706  
707 SHORT deltaX, deltaY;
708 SHORT error, stepErrorLT, stepErrorGE;
709 SHORT stepX, stepY;
710 SHORT steep;
711 SHORT temp;
712 SHORT style, type;
713  
714 stepX = 0;
715 deltaX = x2 - x1;
716 if(deltaX < 0)
717 {
718 deltaX = -deltaX;
719 --stepX;
720 }
721 else
722 {
723 ++stepX;
724 }
725  
726 stepY = 0;
727 deltaY = y2 - y1;
728 if(deltaY < 0)
729 {
730 deltaY = -deltaY;
731 --stepY;
732 }
733 else
734 {
735 ++stepY;
736 }
737  
738 steep = 0;
739 if(deltaX < deltaY)
740 {
741 ++steep;
742 }
743  
744 #ifndef USE_NONBLOCKING_CONFIG
745 while(IsDeviceBusy() != 0);
746  
747 /* Ready */
748 #else
749 if(IsDeviceBusy() != 0)
750 return (0);
751 #endif
752 if(_lineType == 0)
753 {
754 if(!Line2D(x1, y1, x2, y2))
755 return (0);
756 if(_lineThickness)
757 {
758 if(steep)
759 {
760 while(!Line2D(x1 + 1, y1, x2 + 1, y2));
761 while(!Line2D(x1 - 1, y1, x2 - 1, y2));
762 }
763 else
764 {
765 while(!Line2D(x1, y1 + 1, x2, y2 + 1));
766 while(!Line2D(x1, y1 - 1, x2, y2 - 1));
767 }
768 }
769  
770 return (1);
771 }
772  
773 // Move cursor
774 MoveTo(x2, y2);
775  
776 if(x1 == x2)
777 {
778 if(y1 > y2)
779 {
780 temp = y1;
781 y1 = y2;
782 y2 = temp;
783 }
784  
785 style = 0;
786 type = 1;
787 for(temp = y1; temp < y2 + 1; temp++)
788 {
789 if((++style) == _lineType)
790 {
791 type ^= 1;
792 style = 0;
793 }
794  
795 if(type)
796 {
797 PutPixel(x1, temp);
798 if(_lineThickness)
799 {
800 PutPixel(x1 + 1, temp);
801 PutPixel(x1 - 1, temp);
802 }
803 }
804 }
805  
806 return (1);
807 }
808  
809 if(y1 == y2)
810 {
811 if(x1 > x2)
812 {
813 temp = x1;
814 x1 = x2;
815 x2 = temp;
816 }
817  
818 style = 0;
819 type = 1;
820 for(temp = x1; temp < x2 + 1; temp++)
821 {
822 if((++style) == _lineType)
823 {
824 type ^= 1;
825 style = 0;
826 }
827  
828 if(type)
829 {
830 PutPixel(temp, y1);
831 if(_lineThickness)
832 {
833 PutPixel(temp, y1 + 1);
834 PutPixel(temp, y1 - 1);
835 }
836 }
837 }
838  
839 return (1);
840 }
841  
842 if(deltaX < deltaY)
843 {
844 temp = deltaX;
845 deltaX = deltaY;
846 deltaY = temp;
847 temp = x1;
848 x1 = y1;
849 y1 = temp;
850 temp = stepX;
851 stepX = stepY;
852 stepY = temp;
853 PutPixel(y1, x1);
854 }
855 else
856 {
857 PutPixel(x1, y1);
858 }
859  
860 // If the current error greater or equal zero
861 stepErrorGE = deltaX << 1;
862  
863 // If the current error less than zero
864 stepErrorLT = deltaY << 1;
865  
866 // Error for the first pixel
867 error = stepErrorLT - deltaX;
868  
869 style = 0;
870 type = 1;
871  
872 while(--deltaX >= 0)
873 {
874 if(error >= 0)
875 {
876 y1 += stepY;
877 error -= stepErrorGE;
878 }
879  
880 x1 += stepX;
881 error += stepErrorLT;
882  
883 if((++style) == _lineType)
884 {
885 type ^= 1;
886 style = 0;
887 }
888  
889 if(type)
890 {
891 if(steep)
892 {
893 PutPixel(y1, x1);
894 if(_lineThickness)
895 {
896 PutPixel(y1 + 1, x1);
897 PutPixel(y1 - 1, x1);
898 }
899 }
900 else
901 {
902 PutPixel(x1, y1);
903 if(_lineThickness)
904 {
905 PutPixel(x1, y1 + 1);
906 PutPixel(x1, y1 - 1);
907 }
908 }
909 }
910 } // end of while
911  
912 return (1);
913 }
914  
915 #endif
916 #ifdef USE_DRV_BAR
917  
918 /*********************************************************************
919 * Function: WORD Bar(SHORT left, SHORT top, SHORT right, SHORT bottom)
920 *
921 * PreCondition: none
922 *
923 * Input: left,top - top left corner coordinates,
924 * right,bottom - bottom right corner coordinates
925 *
926 * Output: For NON-Blocking configuration:
927 * - Returns 0 when device is busy and the shape is not yet completely drawn.
928 * - Returns 1 when the shape is completely drawn.
929 * For Blocking configuration:
930 * - Always return 1.
931 *
932 * Side Effects: none
933 *
934 * Overview: draws rectangle filled with current color
935 *
936 * Note: none
937 *
938 ********************************************************************/
939 WORD Bar(SHORT left, SHORT top, SHORT right, SHORT bottom)
940 {
941 #ifdef USE_PALETTE
942  
943 DWORD address;
944 register SHORT x, y;
945  
946 if(_clipRgn)
947 {
948 if(left < _clipLeft)
949 left = _clipLeft;
950 if(right > _clipRight)
951 right = _clipRight;
952 if(top < _clipTop)
953 top = _clipTop;
954 if(bottom > _clipBottom)
955 bottom = _clipBottom;
956 }
957  
958 #ifndef USE_PALETTE
959 address = ((DWORD) (GetMaxX() + 1) * top + left) << 1;
960 #else
961 address = (((DWORD) (GetMaxX() + 1) * top + left) * PaletteBpp) >> 3;
962 #endif
963 CS_LAT_BIT = 0;
964 for(y = top; y < bottom + 1; y++)
965 {
966 SetAddress(address);
967 for(x = left; x < right + 1; x++)
968 {
969 WritePixel(_color);
970 }
971  
972 #ifndef USE_PALETTE
973 address += (GetMaxX() + 1) << 1;
974 #else
975 address += ((GetMaxX() + 1) * PaletteBpp) >> 3;
976 #endif
977 }
978  
979 CS_LAT_BIT = 1;
980  
981 #else
982  
983 DWORD address;
984 SHORT width, height;
985  
986 #ifndef USE_NONBLOCKING_CONFIG
987 while(IsDeviceBusy() != 0);
988  
989 /* Ready */
990 #else
991 if(IsDeviceBusy() != 0)
992 return (0);
993 #endif
994 if(left > right)
995 {
996 return (1); /* Don't draw but return 1 */
997 }
998  
999 if(top > bottom)
1000 {
1001 return (1); /* Don't draw but return 1 */
1002 }
1003  
1004 if(_clipRgn)
1005 {
1006 if(left < _clipLeft)
1007 left = _clipLeft;
1008 if(right > _clipRight)
1009 right = _clipRight;
1010 if(top < _clipTop)
1011 top = _clipTop;
1012 if(bottom > _clipBottom)
1013 bottom = _clipBottom;
1014 }
1015  
1016 width = right - left + 1;
1017 height = bottom - top + 1;
1018  
1019 address = top * (GetMaxX() + (DWORD) 1) + left;
1020  
1021 PutPixel(left, top);
1022  
1023 /* Source, Destination & Brush Window Start Addresses */
1024 SetReg(REG_2D_1d4, address & 0xFF);
1025 SetReg(REG_2D_1d5, (address >> 8) & 0xFF);
1026 SetReg(REG_2D_1d6, (address >> 16) & 0xFF);
1027 SetReg(REG_2D_1f4, address & 0xFF);
1028 SetReg(REG_2D_1f5, (address >> 8) & 0xFF);
1029 SetReg(REG_2D_1f6, (address >> 16) & 0xFF);
1030 SetReg(REG_2D_204, address & 0xFF);
1031 SetReg(REG_2D_205, (address >> 8) & 0xFF);
1032 SetReg(REG_2D_206, (address >> 16) & 0xFF);
1033  
1034 /* Source & Destination Window Width */
1035 SetReg(REG_2D_1ec, width & 0xFF);
1036 SetReg(REG_2D_1ed, (width >> 8) & 0xFF);
1037 SetReg(REG_2D_1e4, width & 0xFF);
1038 SetReg(REG_2D_1e5, (width >> 8) & 0xFF);
1039  
1040 /* Source & Destination Window Height */
1041 SetReg(REG_2D_1f0, height & 0xFF);
1042 SetReg(REG_2D_1f1, (height >> 8) & 0xFF);
1043 SetReg(REG_2D_1e8, height & 0xFF);
1044 SetReg(REG_2D_1e9, (height >> 8) & 0xFF);
1045  
1046 /* Brush width */
1047 SetReg(REG_2D_214, 1);
1048 SetReg(REG_2D_215, 0);
1049  
1050 /* Brush height */
1051 SetReg(REG_2D_218, 1);
1052 SetReg(REG_2D_219, 0);
1053  
1054 /* Display width */
1055 SetReg(REG_2D_1f8, (GetMaxX() + 1) & 0xFF);
1056 SetReg(REG_2D_1f9, ((GetMaxX() + 1) >> 8) & 0xFF);
1057  
1058 /* Display 2d width */
1059 SetReg(REG_2D_1d8, (GetMaxX() + 1) & 0xFF);
1060 SetReg(REG_2D_1d9, ((GetMaxX() + 1) >> 8) & 0xFF);
1061  
1062 /* ROP3 Command */
1063 SetReg(REG_2D_1fc, 0xF0);
1064  
1065 /* 16bpp */
1066 SetReg(REG_2D_1dd, 0x00);
1067  
1068 /* ROP command */
1069 SetReg(REG_2D_1d1, 0x09);
1070  
1071 /* Draw2d command */
1072 SetReg(REG_2D_1d2, 0x01);
1073  
1074 #ifndef USE_NONBLOCKING_CONFIG
1075 while(IsDeviceBusy() != 0);
1076  
1077 /* Ready */
1078 #endif
1079 return (1);
1080 #endif
1081 }
1082  
1083 #endif
1084  
1085 #ifdef USE_DRV_CIRCLE
1086  
1087 /***************************************************************************
1088 * Function: WORD Circle(SHORT x, SHORT y, SHORT radius)
1089 *
1090 * Overview: This macro draws a circle with the given center and radius.
1091 *
1092 * Input: x - Center x position.
1093 * y - Center y position.
1094 * radius - the radius of the circle.
1095 *
1096 * Output: For NON-Blocking configuration:
1097 * - Returns 0 when device is busy and the shape is not yet completely drawn.
1098 * - Returns 1 when the shape is completely drawn.
1099 * For Blocking configuration:
1100 * - Always return 1.
1101 *
1102 * Side Effects: none
1103 *
1104 ********************************************************************/
1105 WORD Circle(SHORT x, SHORT y, SHORT radius)
1106 {
1107 #define Rx (WORD) radius
1108 #define Ry (WORD) radius
1109 #define Angle1 (WORD) 0
1110 #define Angle2 (WORD) 0x0200
1111  
1112 #ifndef USE_NONBLOCKING_CONFIG
1113 while(IsDeviceBusy() != 0);
1114  
1115 /* Ready */
1116 #else
1117 if(IsDeviceBusy() != 0)
1118 return (0);
1119 #endif
1120  
1121 /* Ellipse Parameters & Y-Limit */
1122 SetReg(REG_2D_1d4, x & 0xFF);
1123 SetReg(REG_2D_1d5, ((((GetMaxY() + (WORD) 1) << 1) & 0xFE) + ((x >> 8) & 0x01)));
1124 SetReg(REG_2D_1d6, ((GetMaxY() + (WORD) 1) >> 7) & 0x03);
1125  
1126 SetReg(REG_2D_1e4, y & 0xFF);
1127 SetReg(REG_2D_1e5, (y >> 8) & 0xFF);
1128  
1129 SetReg(REG_2D_1e8, Rx & 0xFF);
1130 SetReg(REG_2D_1e9, (Rx >> 8) & 0xFF);
1131  
1132 SetReg(REG_2D_1d8, Ry & 0xFF);
1133 SetReg(REG_2D_1d9, (Ry >> 8) & 0xFF);
1134  
1135 SetReg(REG_2D_1ec, Angle1 & 0xFF);
1136 SetReg(REG_2D_1ed, (Angle1 >> 8) & 0xFF);
1137  
1138 SetReg(REG_2D_1f0, Angle2 & 0xFF);
1139 SetReg(REG_2D_1f1, (Angle2 >> 8) & 0xFF);
1140  
1141 /* Destination Window Start Addresses */
1142 SetReg(REG_2D_1f4, 0);
1143 SetReg(REG_2D_1f5, 0);
1144 SetReg(REG_2D_1f6, 0);
1145  
1146 /* Destination Window Width */
1147 SetReg(REG_2D_1f8, (GetMaxX() + 1) & 0xFF);
1148 SetReg(REG_2D_1f9, ((GetMaxX() + 1) >> 8) & 0xFF);
1149  
1150 /* Set Color */
1151 SetReg(REG_2D_1fe, RED8(_color));
1152 SetReg(REG_2D_1fd, GREEN8(_color));
1153 SetReg(REG_2D_1fc, BLUE8(_color));
1154  
1155 /* 16bpp */
1156 SetReg(REG_2D_1dd, 0x00);
1157  
1158 /* Ellipse command */
1159 SetReg(REG_2D_1d1, 0x03);
1160  
1161 /* Draw2d command */
1162 SetReg(REG_2D_1d2, 0x01);
1163  
1164 #ifndef USE_NONBLOCKING_CONFIG
1165 while(IsDeviceBusy() != 0);
1166  
1167 /* Ready */
1168 #endif
1169 return (1);
1170 }
1171  
1172 #endif
1173 #ifdef USE_DRV_CLEARDEVICE
1174  
1175 /*********************************************************************
1176 * Function: void ClearDevice(void)
1177 *
1178 * PreCondition: none
1179 *
1180 * Input: none
1181 *
1182 * Output: none
1183 *
1184 * Side Effects: none
1185 *
1186 * Overview: clears screen with current color
1187 *
1188 * Note: none
1189 *
1190 ********************************************************************/
1191 void ClearDevice(void)
1192 {
1193 #ifdef USE_PALETTE
1194  
1195 DWORD counter;
1196  
1197 CS_LAT_BIT = 0;
1198 SetAddress(0);
1199 SetAddress(0);
1200 for(counter = 0; counter < (DWORD) (GetMaxX() + 1) * (GetMaxY() + 1); counter++)
1201 {
1202 WritePixel(_color);
1203 }
1204  
1205 CS_LAT_BIT = 1;
1206  
1207 #else
1208 while(GetReg(REG_2D_220) == 0);
1209 while(!Bar(0, 0, GetMaxX(), GetMaxY()));
1210 while(GetReg(REG_2D_220) == 0);
1211  
1212 /* Ready */
1213 #endif
1214 }
1215  
1216 #endif
1217  
1218 /*********************************************************************
1219 * Function: WORD PutImage(SHORT left, SHORT top, void* bitmap, BYTE stretch)
1220 *
1221 * PreCondition: none
1222 *
1223 * Input: left,top - left top image corner,
1224 * bitmap - image pointer,
1225 * stretch - image stretch factor
1226 *
1227 * Output: For NON-Blocking configuration:
1228 * - Returns 0 when device is busy and the image is not yet completely drawn.
1229 * - Returns 1 when the image is completely drawn.
1230 * For Blocking configuration:
1231 * - Always return 1.
1232 *
1233 * Side Effects: none
1234 *
1235 * Overview: outputs image starting from left,top coordinates
1236 *
1237 * Note: image must be located in flash
1238 *
1239 ********************************************************************/
1240 WORD PutImage(SHORT left, SHORT top, void *bitmap, BYTE stretch)
1241 {
1242 #if defined (USE_BITMAP_FLASH) || defined (USE_BITMAP_EXTERNAL)
1243 FLASH_BYTE *flashAddress;
1244 BYTE colorDepth;
1245 #endif
1246 WORD colorTemp;
1247  
1248 #ifndef USE_NONBLOCKING_CONFIG
1249 while(IsDeviceBusy() != 0);
1250  
1251 /* Ready */
1252 #else
1253 if(IsDeviceBusy() != 0)
1254 return (0);
1255 #endif
1256  
1257 // Save current color
1258 colorTemp = _color;
1259  
1260 switch(*((SHORT *)bitmap))
1261 {
1262 #ifdef USE_BITMAP_FLASH
1263  
1264 case FLASH:
1265  
1266 // Image address
1267 flashAddress = ((BITMAP_FLASH *)bitmap)->address;
1268  
1269 // Read color depth
1270 colorDepth = *(flashAddress + 1);
1271  
1272 // Draw picture
1273 switch(colorDepth)
1274 {
1275 case 1: PutImage1BPP(left, top, flashAddress, stretch); break;
1276 case 4: PutImage4BPP(left, top, flashAddress, stretch); break;
1277 case 8: PutImage8BPP(left, top, flashAddress, stretch); break;
1278 case 16: PutImage16BPP(left, top, flashAddress, stretch); break;
1279 }
1280  
1281 break;
1282 #endif
1283 #ifdef USE_BITMAP_EXTERNAL
1284  
1285 case EXTERNAL:
1286  
1287 // Get color depth
1288 ExternalMemoryCallback(bitmap, 1, 1, &colorDepth);
1289  
1290 // Draw picture
1291 switch(colorDepth)
1292 {
1293 case 1: PutImage1BPPExt(left, top, bitmap, stretch); break;
1294 case 4: PutImage4BPPExt(left, top, bitmap, stretch); break;
1295 case 8: PutImage8BPPExt(left, top, bitmap, stretch); break;
1296 case 16: PutImage16BPPExt(left, top, bitmap, stretch); break;
1297 default: break;
1298 }
1299  
1300 break;
1301 #endif
1302  
1303 default:
1304 break;
1305 }
1306  
1307 // Restore current color
1308 _color = colorTemp;
1309 return (1);
1310 }
1311  
1312 #ifdef USE_BITMAP_FLASH
1313  
1314 /*********************************************************************
1315 * Function: void PutImage1BPP(SHORT left, SHORT top, FLASH_BYTE* bitmap, BYTE stretch)
1316 *
1317 * PreCondition: none
1318 *
1319 * Input: left,top - left top image corner,
1320 * bitmap - image pointer,
1321 * stretch - image stretch factor
1322 *
1323 * Output: none
1324 *
1325 * Side Effects: none
1326 *
1327 * Overview: outputs monochrome image starting from left,top coordinates
1328 *
1329 * Note: image must be located in flash
1330 *
1331 ********************************************************************/
1332 void PutImage1BPP(SHORT left, SHORT top, FLASH_BYTE *bitmap, BYTE stretch)
1333 {
1334 register DWORD address;
1335 register FLASH_BYTE *flashAddress;
1336 register FLASH_BYTE *tempFlashAddress;
1337 BYTE temp = 0;
1338 WORD sizeX, sizeY;
1339 WORD x, y;
1340 BYTE stretchX, stretchY;
1341 WORD pallete[2];
1342 BYTE mask;
1343  
1344 // Move pointer to size information
1345 flashAddress = bitmap + 2;
1346  
1347 // Set start address
1348 #ifndef USE_PALETTE
1349 address = ((DWORD) (GetMaxX() + 1) * top + left) << 1;
1350 #else
1351 address = (((DWORD) (GetMaxX() + 1) * top + left) * PaletteBpp) >> 3;
1352 #endif
1353  
1354 // Read image size
1355 sizeY = *((FLASH_WORD *)flashAddress);
1356 flashAddress += 2;
1357 sizeX = *((FLASH_WORD *)flashAddress);
1358 flashAddress += 2;
1359 pallete[0] = *((FLASH_WORD *)flashAddress);
1360 flashAddress += 2;
1361 pallete[1] = *((FLASH_WORD *)flashAddress);
1362 flashAddress += 2;
1363  
1364 CS_LAT_BIT = 0;
1365 for(y = 0; y < sizeY; y++)
1366 {
1367 tempFlashAddress = flashAddress;
1368 for(stretchY = 0; stretchY < stretch; stretchY++)
1369 {
1370 flashAddress = tempFlashAddress;
1371 SetAddress(address);
1372 mask = 0;
1373 for(x = 0; x < sizeX; x++)
1374 {
1375  
1376 // Read 8 pixels from flash
1377 if(mask == 0)
1378 {
1379 temp = *flashAddress;
1380 flashAddress++;
1381 mask = 0x80;
1382 }
1383  
1384 // Set color
1385 if(mask & temp)
1386 {
1387 #ifdef USE_PALETTE
1388 if(IsPaletteEnabled())
1389 {
1390 SetColor(1);
1391 }
1392 else
1393 #endif
1394 {
1395 SetColor(pallete[1]);
1396 }
1397 }
1398 else
1399 {
1400 #ifdef USE_PALETTE
1401 if(IsPaletteEnabled())
1402 {
1403 SetColor(0);
1404 }
1405 else
1406 #endif
1407 {
1408 SetColor(pallete[0]);
1409 }
1410 }
1411  
1412 // Write pixel to screen
1413 for(stretchX = 0; stretchX < stretch; stretchX++)
1414 {
1415 WritePixel(_color);
1416 }
1417  
1418 // Shift to the next pixel
1419 mask >>= 1;
1420 }
1421  
1422 #ifndef USE_PALETTE
1423 address += (GetMaxX() + 1) << 1;
1424 #else
1425 address += ((GetMaxX() + 1) * PaletteBpp) >> 3;
1426 #endif
1427 }
1428 }
1429  
1430 CS_LAT_BIT = 1;
1431 }
1432  
1433 /*********************************************************************
1434 * Function: void PutImage4BPP(SHORT left, SHORT top, FLASH_BYTE* bitmap, BYTE stretch)
1435 *
1436 * PreCondition: none
1437 *
1438 * Input: left,top - left top image corner, bitmap - image pointer,
1439 * stretch - image stretch factor
1440 *
1441 * Output: none
1442 *
1443 * Side Effects: none
1444 *
1445 * Overview: outputs 16 color image starting from left,top coordinates
1446 *
1447 * Note: image must be located in flash
1448 *
1449 ********************************************************************/
1450 void PutImage4BPP(SHORT left, SHORT top, FLASH_BYTE *bitmap, BYTE stretch)
1451 {
1452 register DWORD address;
1453 register FLASH_BYTE *flashAddress;
1454 register FLASH_BYTE *tempFlashAddress;
1455 WORD sizeX, sizeY;
1456 register WORD x, y;
1457 BYTE temp = 0;
1458 register BYTE stretchX, stretchY;
1459 WORD pallete[16];
1460 WORD counter;
1461  
1462 // Move pointer to size information
1463 flashAddress = bitmap + 2;
1464  
1465 // Set start address
1466 #ifndef USE_PALETTE
1467 address = ((DWORD) (GetMaxX() + 1) * top + left) << 1;
1468 #else
1469 address = (((DWORD) (GetMaxX() + 1) * top + left) * PaletteBpp) >> 3;
1470 #endif
1471  
1472 // Read image size
1473 sizeY = *((FLASH_WORD *)flashAddress);
1474 flashAddress += 2;
1475 sizeX = *((FLASH_WORD *)flashAddress);
1476 flashAddress += 2;
1477  
1478 // Read pallete
1479 for(counter = 0; counter < 16; counter++)
1480 {
1481 pallete[counter] = *((FLASH_WORD *)flashAddress);
1482 flashAddress += 2;
1483 }
1484  
1485 CS_LAT_BIT = 0;
1486 for(y = 0; y < sizeY; y++)
1487 {
1488 tempFlashAddress = flashAddress;
1489 for(stretchY = 0; stretchY < stretch; stretchY++)
1490 {
1491 flashAddress = tempFlashAddress;
1492 SetAddress(address);
1493 for(x = 0; x < sizeX; x++)
1494 {
1495  
1496 // Read 2 pixels from flash
1497 if(x & 0x0001)
1498 {
1499  
1500 // second pixel in byte
1501 #ifdef USE_PALETTE
1502 if(IsPaletteEnabled())
1503 {
1504 SetColor(temp >> 4);
1505 }
1506 else
1507 #endif
1508 {
1509 SetColor(pallete[temp >> 4]);
1510 }
1511 }
1512 else
1513 {
1514 temp = *flashAddress;
1515 flashAddress++;
1516  
1517 // first pixel in byte
1518 #ifdef USE_PALETTE
1519 if(IsPaletteEnabled())
1520 {
1521 SetColor(temp & 0x0f);
1522 }
1523 else
1524 #endif
1525 {
1526 SetColor(pallete[temp & 0x0f]);
1527 }
1528 }
1529  
1530 // Write pixel to screen
1531 for(stretchX = 0; stretchX < stretch; stretchX++)
1532 {
1533 WritePixel(_color);
1534 }
1535  
1536 // Shift to the next pixel
1537 //temp >>= 4;
1538 }
1539  
1540 #ifndef USE_PALETTE
1541 address += (GetMaxX() + 1) << 1;
1542 #else
1543 address += ((GetMaxX() + 1) * PaletteBpp) >> 3;
1544 #endif
1545 }
1546 }
1547  
1548 CS_LAT_BIT = 1;
1549 }
1550  
1551 /*********************************************************************
1552 * Function: void PutImage8BPP(SHORT left, SHORT top, FLASH_BYTE* bitmap, BYTE stretch)
1553 *
1554 * PreCondition: none
1555 *
1556 * Input: left,top - left top image corner, bitmap - image pointer,
1557 * stretch - image stretch factor
1558 *
1559 * Output: none
1560 *
1561 * Side Effects: none
1562 *
1563 * Overview: outputs 256 color image starting from left,top coordinates
1564 *
1565 * Note: image must be located in flash
1566 *
1567 ********************************************************************/
1568 void PutImage8BPP(SHORT left, SHORT top, FLASH_BYTE *bitmap, BYTE stretch)
1569 {
1570 register DWORD address;
1571 register FLASH_BYTE *flashAddress;
1572 register FLASH_BYTE *tempFlashAddress;
1573 WORD sizeX, sizeY;
1574 WORD x, y;
1575 BYTE temp;
1576 BYTE stretchX, stretchY;
1577 WORD pallete[256];
1578 WORD counter;
1579  
1580 // Move pointer to size information
1581 flashAddress = bitmap + 2;
1582  
1583 // Set start address
1584 #ifndef USE_PALETTE
1585 address = ((DWORD) (GetMaxX() + 1) * top + left) << 1;
1586 #else
1587 address = (((DWORD) (GetMaxX() + 1) * top + left) * PaletteBpp) >> 3;
1588 #endif
1589  
1590 // Read image size
1591 sizeY = *((FLASH_WORD *)flashAddress);
1592 flashAddress += 2;
1593 sizeX = *((FLASH_WORD *)flashAddress);
1594 flashAddress += 2;
1595  
1596 // Read pallete
1597 for(counter = 0; counter < 256; counter++)
1598 {
1599 pallete[counter] = *((FLASH_WORD *)flashAddress);
1600 flashAddress += 2;
1601 }
1602  
1603 CS_LAT_BIT = 0;
1604 for(y = 0; y < sizeY; y++)
1605 {
1606 tempFlashAddress = flashAddress;
1607 for(stretchY = 0; stretchY < stretch; stretchY++)
1608 {
1609 flashAddress = tempFlashAddress;
1610 SetAddress(address);
1611 for(x = 0; x < sizeX; x++)
1612 {
1613  
1614 // Read pixels from flash
1615 temp = *flashAddress;
1616 flashAddress++;
1617  
1618 // Set color
1619 #ifdef USE_PALETTE
1620 if(IsPaletteEnabled())
1621 {
1622 SetColor(temp);
1623 }
1624 else
1625 #endif
1626 {
1627 SetColor(pallete[temp]);
1628 }
1629  
1630 // Write pixel to screen
1631 for(stretchX = 0; stretchX < stretch; stretchX++)
1632 {
1633 WritePixel(_color);
1634 }
1635 }
1636  
1637 #ifndef USE_PALETTE
1638 address += (GetMaxX() + 1) << 1;
1639 #else
1640 address += ((GetMaxX() + 1) * PaletteBpp) >> 3;
1641 #endif
1642 }
1643 }
1644  
1645 CS_LAT_BIT = 1;
1646 }
1647  
1648 /*********************************************************************
1649 * Function: void PutImage16BPP(SHORT left, SHORT top, FLASH_BYTE* bitmap, BYTE stretch)
1650 *
1651 * PreCondition: none
1652 *
1653 * Input: left,top - left top image corner, bitmap - image pointer,
1654 * stretch - image stretch factor
1655 *
1656 * Output: none
1657 *
1658 * Side Effects: none
1659 *
1660 * Overview: outputs hicolor image starting from left,top coordinates
1661 *
1662 * Note: image must be located in flash
1663 *
1664 ********************************************************************/
1665 void PutImage16BPP(SHORT left, SHORT top, FLASH_BYTE *bitmap, BYTE stretch)
1666 {
1667 register DWORD address;
1668 register FLASH_WORD *flashAddress;
1669 register FLASH_WORD *tempFlashAddress;
1670 WORD sizeX, sizeY;
1671 register WORD x, y;
1672 WORD temp;
1673 register BYTE stretchX, stretchY;
1674  
1675 // Move pointer to size information
1676 flashAddress = (FLASH_WORD *)bitmap + 1;
1677  
1678 // Set start address
1679 #ifndef USE_PALETTE
1680 address = ((DWORD) (GetMaxX() + 1) * top + left) << 1;
1681 #else
1682 address = (((DWORD) (GetMaxX() + 1) * top + left) * PaletteBpp) >> 3;
1683 #endif
1684  
1685 // Read image size
1686 sizeY = *flashAddress;
1687 flashAddress++;
1688 sizeX = *flashAddress;
1689 flashAddress++;
1690  
1691 CS_LAT_BIT = 0;
1692 for(y = 0; y < sizeY; y++)
1693 {
1694 tempFlashAddress = flashAddress;
1695 for(stretchY = 0; stretchY < stretch; stretchY++)
1696 {
1697 flashAddress = tempFlashAddress;
1698 SetAddress(address);
1699 for(x = 0; x < sizeX; x++)
1700 {
1701  
1702 // Read pixels from flash
1703 temp = *flashAddress;
1704 flashAddress++;
1705  
1706 // Set color
1707 #ifdef USE_PALETTE
1708 if(IsPaletteEnabled())
1709 {
1710 SetColor(0); /* Paint first value of Palette instead of junk */
1711 }
1712 else
1713 #endif
1714 {
1715 SetColor(temp);
1716 }
1717  
1718 // Write pixel to screen
1719 for(stretchX = 0; stretchX < stretch; stretchX++)
1720 {
1721 WritePixel(_color);
1722 }
1723 }
1724  
1725 #ifndef USE_PALETTE
1726 address += (GetMaxX() + 1) << 1;
1727 #else
1728 address += ((GetMaxX() + 1) * PaletteBpp) >> 3;
1729 #endif
1730 }
1731 }
1732  
1733 CS_LAT_BIT = 1;
1734 }
1735  
1736 #endif
1737 #ifdef USE_BITMAP_EXTERNAL
1738  
1739 /*********************************************************************
1740 * Function: void PutImage1BPPExt(SHORT left, SHORT top, void* bitmap, BYTE stretch)
1741 *
1742 * PreCondition: none
1743 *
1744 * Input: left,top - left top image corner, bitmap - image pointer,
1745 * stretch - image stretch factor
1746 *
1747 * Output: none
1748 *
1749 * Side Effects: none
1750 *
1751 * Overview: outputs monochrome image starting from left,top coordinates
1752 *
1753 * Note: image must be located in external memory
1754 *
1755 ********************************************************************/
1756 void PutImage1BPPExt(SHORT left, SHORT top, void *bitmap, BYTE stretch)
1757 {
1758 register DWORD address;
1759 register DWORD memOffset;
1760 BITMAP_HEADER bmp;
1761 WORD pallete[2];
1762 BYTE lineBuffer[((GetMaxX() + 1) / 8) + 1];
1763 BYTE *pData;
1764 SHORT byteWidth;
1765  
1766 BYTE temp = 0;
1767 BYTE mask;
1768 WORD sizeX, sizeY;
1769 WORD x, y;
1770 BYTE stretchX, stretchY;
1771  
1772 // Set start address
1773 #ifndef USE_PALETTE
1774 address = ((DWORD) (GetMaxX() + 1) * top + left) << 1;
1775 #else
1776 address = (((DWORD) (GetMaxX() + 1) * top + left) * PaletteBpp) >> 3;
1777 #endif
1778  
1779 // Get bitmap header
1780 ExternalMemoryCallback(bitmap, 0, sizeof(BITMAP_HEADER), &bmp);
1781  
1782 // Get pallete (2 entries)
1783 ExternalMemoryCallback(bitmap, sizeof(BITMAP_HEADER), 2 * sizeof(WORD), pallete);
1784  
1785 // Set offset to the image data
1786 memOffset = sizeof(BITMAP_HEADER) + 2 * sizeof(WORD);
1787  
1788 // Line width in bytes
1789 byteWidth = bmp.width >> 3;
1790 if(bmp.width & 0x0007)
1791 byteWidth++;
1792  
1793 // Get size
1794 sizeX = bmp.width;
1795 sizeY = bmp.height;
1796  
1797 for(y = 0; y < sizeY; y++)
1798 {
1799  
1800 // Get line
1801 ExternalMemoryCallback(bitmap, memOffset, byteWidth, lineBuffer);
1802 memOffset += byteWidth;
1803  
1804 CS_LAT_BIT = 0;
1805 for(stretchY = 0; stretchY < stretch; stretchY++)
1806 {
1807 pData = lineBuffer;
1808 SetAddress(address);
1809 mask = 0;
1810 for(x = 0; x < sizeX; x++)
1811 {
1812  
1813 // Read 8 pixels from flash
1814 if(mask == 0)
1815 {
1816 temp = *pData++;
1817 mask = 0x80;
1818 }
1819  
1820 // Set color
1821 if(mask & temp)
1822 {
1823 #ifdef USE_PALETTE
1824 if(IsPaletteEnabled())
1825 {
1826 SetColor(1);
1827 }
1828 else
1829 #endif
1830 {
1831 SetColor(pallete[1]);
1832 }
1833 }
1834 else
1835 {
1836 #ifdef USE_PALETTE
1837 if(IsPaletteEnabled())
1838 {
1839 SetColor(0);
1840 }
1841 else
1842 #endif
1843 {
1844 SetColor(pallete[0]);
1845 }
1846 }
1847  
1848 // Write pixel to screen
1849 for(stretchX = 0; stretchX < stretch; stretchX++)
1850 {
1851 WritePixel(_color);
1852 }
1853  
1854 // Shift to the next pixel
1855 mask >>= 1;
1856 }
1857  
1858 #ifndef USE_PALETTE
1859 address += (GetMaxX() + 1) << 1;
1860 #else
1861 address += ((GetMaxX() + 1) * PaletteBpp) >> 3;
1862 #endif
1863 }
1864  
1865 CS_LAT_BIT = 1;
1866 }
1867 }
1868  
1869 /*********************************************************************
1870 * Function: void PutImage4BPPExt(SHORT left, SHORT top, void* bitmap, BYTE stretch)
1871 *
1872 * PreCondition: none
1873 *
1874 * Input: left,top - left top image corner, bitmap - image pointer,
1875 * stretch - image stretch factor
1876 *
1877 * Output: none
1878 *
1879 * Side Effects: none
1880 *
1881 * Overview: outputs monochrome image starting from left,top coordinates
1882 *
1883 * Note: image must be located in external memory
1884 *
1885 ********************************************************************/
1886 void PutImage4BPPExt(SHORT left, SHORT top, void *bitmap, BYTE stretch)
1887 {
1888 register DWORD address;
1889 register DWORD memOffset;
1890 BITMAP_HEADER bmp;
1891 WORD pallete[16];
1892 BYTE lineBuffer[((GetMaxX() + 1) / 2) + 1];
1893 BYTE *pData;
1894 SHORT byteWidth;
1895  
1896 BYTE temp = 0;
1897 WORD sizeX, sizeY;
1898 WORD x, y;
1899 BYTE stretchX, stretchY;
1900  
1901 // Set start address
1902 #ifndef USE_PALETTE
1903 address = ((DWORD) (GetMaxX() + 1) * top + left) << 1;
1904 #else
1905 address = (((DWORD) (GetMaxX() + 1) * top + left) * PaletteBpp) >> 3;
1906 #endif
1907  
1908 // Get bitmap header
1909 ExternalMemoryCallback(bitmap, 0, sizeof(BITMAP_HEADER), &bmp);
1910  
1911 // Get pallete (16 entries)
1912 ExternalMemoryCallback(bitmap, sizeof(BITMAP_HEADER), 16 * sizeof(WORD), pallete);
1913  
1914 // Set offset to the image data
1915 memOffset = sizeof(BITMAP_HEADER) + 16 * sizeof(WORD);
1916  
1917 // Line width in bytes
1918 byteWidth = bmp.width >> 1;
1919 if(bmp.width & 0x0001)
1920 byteWidth++;
1921  
1922 // Get size
1923 sizeX = bmp.width;
1924 sizeY = bmp.height;
1925  
1926 for(y = 0; y < sizeY; y++)
1927 {
1928  
1929 // Get line
1930 ExternalMemoryCallback(bitmap, memOffset, byteWidth, lineBuffer);
1931 memOffset += byteWidth;
1932 CS_LAT_BIT = 0;
1933 for(stretchY = 0; stretchY < stretch; stretchY++)
1934 {
1935 pData = lineBuffer;
1936 SetAddress(address);
1937  
1938 for(x = 0; x < sizeX; x++)
1939 {
1940  
1941 // Read 2 pixels from flash
1942 if(x & 0x0001)
1943 {
1944 // second pixel in byte
1945 #ifdef USE_PALETTE
1946 if(IsPaletteEnabled())
1947 {
1948 SetColor(temp >> 4);
1949 }
1950 else
1951 #endif
1952 {
1953 SetColor(pallete[temp >> 4]);
1954 }
1955 }
1956 else
1957 {
1958 temp = *pData++;
1959  
1960 // first pixel in byte
1961 #ifdef USE_PALETTE
1962 if(IsPaletteEnabled())
1963 {
1964 SetColor(temp & 0x0f);
1965 }
1966 else
1967 #endif
1968 {
1969 SetColor(pallete[temp & 0x0f]);
1970 }
1971 }
1972  
1973 // Write pixel to screen
1974 for(stretchX = 0; stretchX < stretch; stretchX++)
1975 {
1976 WritePixel(_color);
1977 }
1978 }
1979  
1980 #ifndef USE_PALETTE
1981 address += (GetMaxX() + 1) << 1;
1982 #else
1983 address += ((GetMaxX() + 1) * PaletteBpp) >> 3;
1984 #endif
1985 }
1986  
1987 CS_LAT_BIT = 1;
1988 }
1989 }
1990  
1991 /*********************************************************************
1992 * Function: void PutImage8BPPExt(SHORT left, SHORT top, void* bitmap, BYTE stretch)
1993 *
1994 * PreCondition: none
1995 *
1996 * Input: left,top - left top image corner, bitmap - image pointer,
1997 * stretch - image stretch factor
1998 *
1999 * Output: none
2000 *
2001 * Side Effects: none
2002 *
2003 * Overview: outputs monochrome image starting from left,top coordinates
2004 *
2005 * Note: image must be located in external memory
2006 *
2007 ********************************************************************/
2008 void PutImage8BPPExt(SHORT left, SHORT top, void *bitmap, BYTE stretch)
2009 {
2010 register DWORD address;
2011 register DWORD memOffset;
2012 BITMAP_HEADER bmp;
2013 WORD pallete[256];
2014 BYTE lineBuffer[(GetMaxX() + 1)];
2015 BYTE *pData;
2016  
2017 BYTE temp;
2018 WORD sizeX, sizeY;
2019 WORD x, y;
2020 BYTE stretchX, stretchY;
2021  
2022 // Set start address
2023 #ifndef USE_PALETTE
2024 address = ((DWORD) (GetMaxX() + 1) * top + left) << 1;
2025 #else
2026 address = (((DWORD) (GetMaxX() + 1) * top + left) * PaletteBpp) >> 3;
2027 #endif
2028  
2029 // Get bitmap header
2030 ExternalMemoryCallback(bitmap, 0, sizeof(BITMAP_HEADER), &bmp);
2031  
2032 // Get pallete (256 entries)
2033 ExternalMemoryCallback(bitmap, sizeof(BITMAP_HEADER), 256 * sizeof(WORD), pallete);
2034  
2035 // Set offset to the image data
2036 memOffset = sizeof(BITMAP_HEADER) + 256 * sizeof(WORD);
2037  
2038 // Get size
2039 sizeX = bmp.width;
2040 sizeY = bmp.height;
2041  
2042 for(y = 0; y < sizeY; y++)
2043 {
2044  
2045 // Get line
2046 ExternalMemoryCallback(bitmap, memOffset, sizeX, lineBuffer);
2047 memOffset += sizeX;
2048 CS_LAT_BIT = 0;
2049 for(stretchY = 0; stretchY < stretch; stretchY++)
2050 {
2051 pData = lineBuffer;
2052 SetAddress(address);
2053  
2054 for(x = 0; x < sizeX; x++)
2055 {
2056 temp = *pData++;
2057  
2058 #ifdef USE_PALETTE
2059 if(IsPaletteEnabled())
2060 {
2061 SetColor(temp);
2062 }
2063 else
2064 #endif
2065 {
2066 SetColor(pallete[temp]);
2067 }
2068  
2069 // Write pixel to screen
2070 for(stretchX = 0; stretchX < stretch; stretchX++)
2071 {
2072 WritePixel(_color);
2073 }
2074 }
2075  
2076 #ifndef USE_PALETTE
2077 address += (GetMaxX() + 1) << 1;
2078 #else
2079 address += ((GetMaxX() + 1) * PaletteBpp) >> 3;
2080 #endif
2081 }
2082  
2083 CS_LAT_BIT = 1;
2084 }
2085 }
2086  
2087 /*********************************************************************
2088 * Function: void PutImage16BPPExt(SHORT left, SHORT top, void* bitmap, BYTE stretch)
2089 *
2090 * PreCondition: none
2091 *
2092 * Input: left,top - left top image corner, bitmap - image pointer,
2093 * stretch - image stretch factor
2094 *
2095 * Output: none
2096 *
2097 * Side Effects: none
2098 *
2099 * Overview: outputs monochrome image starting from left,top coordinates
2100 *
2101 * Note: image must be located in external memory
2102 *
2103 ********************************************************************/
2104 void PutImage16BPPExt(SHORT left, SHORT top, void *bitmap, BYTE stretch)
2105 {
2106 register DWORD address;
2107 register DWORD memOffset;
2108 BITMAP_HEADER bmp;
2109 WORD lineBuffer[(GetMaxX() + 1)];
2110 WORD *pData;
2111 WORD byteWidth;
2112  
2113 WORD temp;
2114 WORD sizeX, sizeY;
2115 WORD x, y;
2116 BYTE stretchX, stretchY;
2117  
2118 // Set start address
2119 #ifndef USE_PALETTE
2120 address = ((DWORD) (GetMaxX() + 1) * top + left) << 1;
2121 #else
2122 address = (((DWORD) (GetMaxX() + 1) * top + left) * PaletteBpp) >> 3;
2123 #endif
2124  
2125 // Get bitmap header
2126 ExternalMemoryCallback(bitmap, 0, sizeof(BITMAP_HEADER), &bmp);
2127  
2128 // Set offset to the image data
2129 memOffset = sizeof(BITMAP_HEADER);
2130  
2131 // Get size
2132 sizeX = bmp.width;
2133 sizeY = bmp.height;
2134  
2135 byteWidth = sizeX << 1;
2136  
2137 for(y = 0; y < sizeY; y++)
2138 {
2139  
2140 // Get line
2141 ExternalMemoryCallback(bitmap, memOffset, byteWidth, lineBuffer);
2142 memOffset += byteWidth;
2143 CS_LAT_BIT = 0;
2144 for(stretchY = 0; stretchY < stretch; stretchY++)
2145 {
2146 pData = lineBuffer;
2147 SetAddress(address);
2148  
2149 for(x = 0; x < sizeX; x++)
2150 {
2151 temp = *pData++;
2152  
2153 #ifdef USE_PALETTE
2154 if(IsPaletteEnabled())
2155 {
2156 SetColor(0); /* Paint first value of Palette instead of junk */
2157 }
2158 else
2159 #endif
2160 {
2161 SetColor(temp);
2162 }
2163  
2164 // Write pixel to screen
2165 for(stretchX = 0; stretchX < stretch; stretchX++)
2166 {
2167 WritePixel(_color);
2168 }
2169 }
2170  
2171 #ifndef USE_PALETTE
2172 address += (GetMaxX() + 1) << 1;
2173 #else
2174 address += ((GetMaxX() + 1) * PaletteBpp) >> 3;
2175 #endif
2176 }
2177  
2178 CS_LAT_BIT = 1;
2179 }
2180 }
2181  
2182 #endif
2183 #ifdef USE_PALETTE
2184  
2185 /*********************************************************************
2186 * Function: void PaletteInit(void)
2187 *
2188 * Overview: Initializes the CLUT.
2189 *
2190 * PreCondition: none
2191 *
2192 * Input: none
2193 *
2194 * Output: none
2195 *
2196 * Side Effects: Drawing mode will change to support palettes
2197 *
2198 ********************************************************************/
2199 void PaletteInit(void)
2200 {
2201 PaletteBpp = 16;
2202 blPaletteChangeError = 0;
2203 pPendingPalette = NULL;
2204 PendingStartEntry = 0;
2205 PendingLength = 0;
2206 }
2207  
2208 /*********************************************************************
2209 * Function: BYTE SetPaletteBpp(BYTE bpp)
2210 *
2211 * Overview: Sets the CLUT's number of valid entries.
2212 *
2213 * PreCondition: PaletteInit() must be called before.
2214 *
2215 * Input: bpp -> Bits per pixel
2216 *
2217 * Output: Status: Zero -> Success, Non-zero -> Error.
2218 *
2219 * Side Effects: Drawing mode will change to support palettes
2220 *
2221 ********************************************************************/
2222 BYTE SetPaletteBpp(BYTE bpp)
2223 {
2224 switch(bpp)
2225 {
2226 /*case 1: SetReg(REG_DISPLAY_MODE,0x00);
2227 break;
2228  
2229 case 2: SetReg(REG_DISPLAY_MODE,0x01);
2230 break;
2231  
2232 case 4: SetReg(REG_DISPLAY_MODE,0x02);
2233 break;*/
2234 case 8: SetReg(REG_DISPLAY_MODE, 0x03); break;
2235 case 16: SetReg(REG_DISPLAY_MODE, 0x04); break;
2236 default: SetReg(REG_DISPLAY_MODE, 0x04); PaletteBpp = 16; return (-1);
2237 }
2238  
2239 PaletteBpp = bpp;
2240  
2241 /////////////////////////////////////////////////////////////////////
2242 // ROTATION MODE
2243 /////////////////////////////////////////////////////////////////////
2244 #if (DISP_ORIENTATION == 0)
2245 #define WIN_START_ADDR 0ul
2246 #define ROTATION 0
2247  
2248 #elif (DISP_ORIENTATION == 90)
2249 #ifndef USE_PALETTE
2250 #define WIN_START_ADDR ((((DWORD) GetMaxX() + 1) >> 1) - 1)
2251 #else
2252 #define WIN_START_ADDR (((((DWORD) GetMaxX() + 1) * PaletteBpp) >> 5) - 1)
2253 #endif
2254 #define ROTATION 1
2255  
2256 #elif (DISP_ORIENTATION == 180)
2257 #ifndef USE_PALETTE
2258 #define WIN_START_ADDR (((((DWORD) GetMaxX() + 1) * (GetMaxY() + 1)) >> 1) - 1)
2259 #else
2260 #define WIN_START_ADDR (((((DWORD) GetMaxX() + 1) * (GetMaxY() + 1) * PaletteBpp) >> 5) - 1)
2261 #endif
2262 #define ROTATION 2
2263  
2264 #elif (DISP_ORIENTATION == 270)
2265 #ifndef USE_PALETTE
2266 #define WIN_START_ADDR ((((DWORD) GetMaxX() + 1) * GetMaxY()) >> 1)
2267 #else
2268 #define WIN_START_ADDR ((((DWORD) GetMaxX() + 1) * GetMaxY() * PaletteBpp) >> 5)
2269 #endif
2270 #define ROTATION 3
2271 #endif
2272  
2273 /////////////////////////////////////////////////////////////////////
2274 // Special Effects Register (reg 71h)
2275 /////////////////////////////////////////////////////////////////////
2276 #ifndef USE_PALETTE
2277 SetReg(REG_SPECIAL_EFFECTS, 0x40 | ROTATION);
2278 #else
2279 SetReg(REG_SPECIAL_EFFECTS, 0x00 | ROTATION);
2280 #endif
2281  
2282 /////////////////////////////////////////////////////////////////////
2283 // Main Window Display Start Address (regs 74h, 75h, 76h)
2284 /////////////////////////////////////////////////////////////////////
2285 SetReg(REG_MAIN_WIN_DISP_START_ADDR0, WIN_START_ADDR & 0x00FF);
2286 SetReg(REG_MAIN_WIN_DISP_START_ADDR1, (WIN_START_ADDR >> 8) & 0x00FF);
2287 SetReg(REG_MAIN_WIN_DISP_START_ADDR2, (WIN_START_ADDR >> 16) & 0x00FF);
2288  
2289 /////////////////////////////////////////////////////////////////////
2290 // Main Window Display Offset (regs 78h, 79h)
2291 /////////////////////////////////////////////////////////////////////
2292 #ifndef USE_PALETTE
2293 #define WIN_OFFSET ((GetMaxX() + 1) >> 1)
2294 #else
2295 #define WIN_OFFSET (((GetMaxX() + 1) * PaletteBpp) >> 5)
2296 #endif
2297 SetReg(REG_MAIN_WIN_ADDR_OFFSET0, WIN_OFFSET & 0x00FF);
2298 SetReg(REG_MAIN_WIN_ADDR_OFFSET1, (WIN_OFFSET >> 8) & 0x00FF);
2299  
2300 return (0);
2301 }
2302  
2303 /*********************************************************************
2304 * Function: void EnablePalette(void)
2305 *
2306 * Overview: Enables the Palette mode
2307 *
2308 * PreCondition: none
2309 *
2310 * Input: none
2311 *
2312 * Output: none
2313 *
2314 * Side Effects:
2315 *
2316 ********************************************************************/
2317 void EnablePalette(void)
2318 {
2319 SetPaletteBpp(PaletteBpp);
2320 }
2321  
2322 /*********************************************************************
2323 * Function: void DisablePalette(void)
2324 *
2325 * Overview: Disables the Palette mode
2326 *
2327 * PreCondition: none
2328 *
2329 * Input: none
2330 *
2331 * Output: none
2332 *
2333 * Side Effects:
2334 *
2335 ********************************************************************/
2336 void DisablePalette(void)
2337 {
2338 SetPaletteBpp(16);
2339 }
2340  
2341 /*********************************************************************
2342 * Function: BYTE IsPaletteEnabled(void)
2343 *
2344 * Overview: Returns if the Palette mode is enabled or not
2345 *
2346 * PreCondition: none
2347 *
2348 * Input: none
2349 *
2350 * Output: Enabled -> 1, Disabled -> 0
2351 *
2352 * Side Effects:
2353 *
2354 ********************************************************************/
2355 BYTE IsPaletteEnabled(void)
2356 {
2357 return ((PaletteBpp == 16) ? 0 : 1);
2358 }
2359  
2360 /*********************************************************************
2361 * Function: void StartVBlankInterrupt(void)
2362 *
2363 * Overview: Sets up the Vertical Blanking Interrupt
2364 *
2365 * PreCondition: Interrupts must be enabled
2366 *
2367 * Input: none
2368 *
2369 * Output: none
2370 *
2371 * Side Effects: none
2372 *
2373 ********************************************************************/
2374 void StartVBlankInterrupt(void)
2375 {
2376  
2377 /* We don't use Vertical Blanking Interrupt in SSD1926 */
2378 if(pPendingPalette != NULL)
2379 {
2380 blPaletteChangeError = SetPalette(pPendingPalette, PendingStartEntry, PendingLength);
2381 if(!blPaletteChangeError)
2382 {
2383 _palette = pPendingPalette;
2384 }
2385 }
2386 }
2387  
2388 /*********************************************************************
2389 * Function: BYTE SetPaletteFlash(PALETTE_ENTRY *pPaletteEntry, WORD startEntry, WORD length)
2390 *
2391 * Overview: Loads the palettes from the flash immediately.
2392 *
2393 * PreCondition: PaletteInit() must be called before.
2394 *
2395 * Input: pPaletteEntry - Pointer to the palette table in ROM
2396 * startEntry - Start entry to load (inclusive)
2397 * length - Number of entries
2398 *
2399 * Output: Status: Zero -> Success, Non-zero -> Error.
2400 *
2401 * Side Effects: There may be a slight flicker when the Palette entries
2402 * are getting loaded one by one.
2403 *
2404 ********************************************************************/
2405 BYTE SetPaletteFlash(PALETTE_ENTRY *pPaletteEntry, WORD startEntry, WORD length)
2406 {
2407 WORD counter;
2408  
2409 if((pPaletteEntry == NULL) || ((startEntry + length) > 256))
2410 {
2411 return (-1);
2412 }
2413  
2414 for(counter = 0; counter < length; counter++)
2415 {
2416 SetReg(REG_LUT_RED_WRITE_DATA, RED8(pPaletteEntry[counter].value));
2417 SetReg(REG_LUT_GREEN_WRITE_DATA, GREEN8(pPaletteEntry[counter].value));
2418 SetReg(REG_LUT_BLUE_WRITE_DATA, BLUE8(pPaletteEntry[counter].value));
2419 SetReg(REG_LUT_WRITE_ADDR, startEntry + counter);
2420 }
2421  
2422 return (0);
2423 }
2424  
2425 #endif
{BLAME END}
{FOOTER START}

Powered by WebSVN v2.8.3