2 * Epson S1D13744/S1D13745 (Blizzard/Hailstorm/Tornado) LCD/TV controller.
4 * Copyright (C) 2008 Nokia Corporation
5 * Written by Andrzej Zaborowski <andrew@openedhand.com>
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License as
9 * published by the Free Software Foundation; either version 2 or
10 * (at your option) version 3 of the License.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License along
18 * with this program; if not, see <http://www.gnu.org/licenses/>.
21 #include "qemu/osdep.h"
22 #include "qemu/bitops.h"
23 #include "ui/console.h"
24 #include "hw/display/blizzard.h"
25 #include "ui/pixel_ops.h"
27 typedef void (*blizzard_fn_t
)(uint8_t *, const uint8_t *, unsigned int);
73 blizzard_fn_t
*line_fn_tab
[2];
76 uint8_t hssi_config
[3];
83 uint8_t tv_filter_config
;
84 uint8_t tv_filter_idx
;
85 uint8_t tv_filter_coeff
[0x20];
91 uint8_t gamma_lut
[0x100];
93 uint8_t matrix_coeff
[0x12];
103 uint8_t gpio_edge
[2];
119 blizzard_fn_t line_fn
;
123 /* Bytes(!) per pixel */
124 static const int blizzard_iformat_bpp
[0x10] = {
127 3, /* RGB 6:6:6 mode 1 */
128 3, /* RGB 8:8:8 mode 1 */
130 4, /* RGB 6:6:6 mode 2 */
131 4, /* RGB 8:8:8 mode 2 */
137 static void blizzard_window(BlizzardState
*s
)
139 DisplaySurface
*surface
= qemu_console_surface(s
->con
);
144 blizzard_fn_t fn
= s
->data
.line_fn
;
148 if (s
->mx
[0] > s
->data
.x
)
149 s
->mx
[0] = s
->data
.x
;
150 if (s
->my
[0] > s
->data
.y
)
151 s
->my
[0] = s
->data
.y
;
152 if (s
->mx
[1] < s
->data
.x
+ s
->data
.dx
)
153 s
->mx
[1] = s
->data
.x
+ s
->data
.dx
;
154 if (s
->my
[1] < s
->data
.y
+ s
->data
.dy
)
155 s
->my
[1] = s
->data
.y
+ s
->data
.dy
;
158 bypp
[1] = surface_bytes_per_pixel(surface
);
159 bypl
[0] = bypp
[0] * s
->data
.pitch
;
160 bypl
[1] = bypp
[1] * s
->x
;
161 bypl
[2] = bypp
[0] * s
->data
.dx
;
164 dst
= s
->fb
+ bypl
[1] * s
->data
.y
+ bypp
[1] * s
->data
.x
;
165 for (y
= s
->data
.dy
; y
> 0; y
--, src
+= bypl
[0], dst
+= bypl
[1])
166 fn(dst
, src
, bypl
[2]);
169 static int blizzard_transfer_setup(BlizzardState
*s
)
171 if (s
->source
> 3 || !s
->bpp
||
172 s
->ix
[1] < s
->ix
[0] || s
->iy
[1] < s
->iy
[0])
175 s
->data
.angle
= s
->effect
& 3;
176 s
->data
.line_fn
= s
->line_fn_tab
[!!s
->data
.angle
][s
->iformat
];
177 s
->data
.x
= s
->ix
[0];
178 s
->data
.y
= s
->iy
[0];
179 s
->data
.dx
= s
->ix
[1] - s
->ix
[0] + 1;
180 s
->data
.dy
= s
->iy
[1] - s
->iy
[0] + 1;
181 s
->data
.len
= s
->bpp
* s
->data
.dx
* s
->data
.dy
;
182 s
->data
.pitch
= s
->data
.dx
;
183 if (s
->data
.len
> s
->data
.buflen
) {
184 s
->data
.buf
= g_realloc(s
->data
.buf
, s
->data
.len
);
185 s
->data
.buflen
= s
->data
.len
;
187 s
->data
.ptr
= s
->data
.buf
;
188 s
->data
.data
= s
->data
.buf
;
193 static void blizzard_reset(BlizzardState
*s
)
204 s
->memrefresh
= 0x25c;
210 s
->lcd_config
= 0x74;
237 s
->bpp
= blizzard_iformat_bpp
[s
->iformat
];
239 s
->hssi_config
[0] = 0x00;
240 s
->hssi_config
[1] = 0x00;
241 s
->hssi_config
[2] = 0x01;
243 s
->tv_timing
[0] = 0x00;
244 s
->tv_timing
[1] = 0x00;
245 s
->tv_timing
[2] = 0x00;
246 s
->tv_timing
[3] = 0x00;
251 s
->tv_filter_config
= 0x80;
252 s
->tv_filter_idx
= 0x00;
256 s
->gamma_config
= 0x00;
258 s
->matrix_ena
= 0x00;
259 memset(&s
->matrix_coeff
, 0, sizeof(s
->matrix_coeff
));
265 s
->rgbgpio_dir
= 0x00;
267 s
->gpio_edge
[0] = 0x00;
268 s
->gpio_edge
[1] = 0x00;
270 s
->gpio_pdown
= 0xff;
273 static inline void blizzard_invalidate_display(void *opaque
) {
274 BlizzardState
*s
= (BlizzardState
*) opaque
;
279 static uint16_t blizzard_reg_read(void *opaque
, uint8_t reg
)
281 BlizzardState
*s
= (BlizzardState
*) opaque
;
284 case 0x00: /* Revision Code */
287 case 0x02: /* Configuration Readback */
288 return 0x83; /* Macrovision OK, CNF[2:0] = 3 */
290 case 0x04: /* PLL M-Divider */
291 return (s
->pll
- 1) | (1 << 7);
292 case 0x06: /* PLL Lock Range Control */
294 case 0x08: /* PLL Lock Synthesis Control 0 */
295 return s
->pll_ctrl
& 0xff;
296 case 0x0a: /* PLL Lock Synthesis Control 1 */
297 return s
->pll_ctrl
>> 8;
298 case 0x0c: /* PLL Mode Control 0 */
301 case 0x0e: /* Clock-Source Select */
304 case 0x10: /* Memory Controller Activate */
305 case 0x14: /* Memory Controller Bank 0 Status Flag */
308 case 0x18: /* Auto-Refresh Interval Setting 0 */
309 return s
->memrefresh
& 0xff;
310 case 0x1a: /* Auto-Refresh Interval Setting 1 */
311 return s
->memrefresh
>> 8;
313 case 0x1c: /* Power-On Sequence Timing Control */
315 case 0x1e: /* Timing Control 0 */
317 case 0x20: /* Timing Control 1 */
320 case 0x24: /* Arbitration Priority Control */
323 case 0x28: /* LCD Panel Configuration */
324 return s
->lcd_config
;
326 case 0x2a: /* LCD Horizontal Display Width */
328 case 0x2c: /* LCD Horizontal Non-display Period */
330 case 0x2e: /* LCD Vertical Display Height 0 */
332 case 0x30: /* LCD Vertical Display Height 1 */
334 case 0x32: /* LCD Vertical Non-display Period */
336 case 0x34: /* LCD HS Pulse-width */
338 case 0x36: /* LCd HS Pulse Start Position */
339 return s
->skipx
>> 3;
340 case 0x38: /* LCD VS Pulse-width */
342 case 0x3a: /* LCD VS Pulse Start Position */
345 case 0x3c: /* PCLK Polarity */
348 case 0x3e: /* High-speed Serial Interface Tx Configuration Port 0 */
349 return s
->hssi_config
[0];
350 case 0x40: /* High-speed Serial Interface Tx Configuration Port 1 */
351 return s
->hssi_config
[1];
352 case 0x42: /* High-speed Serial Interface Tx Mode */
353 return s
->hssi_config
[2];
354 case 0x44: /* TV Display Configuration */
356 case 0x46 ... 0x4c: /* TV Vertical Blanking Interval Data bits */
357 return s
->tv_timing
[(reg
- 0x46) >> 1];
358 case 0x4e: /* VBI: Closed Caption / XDS Control / Status */
360 case 0x50: /* TV Horizontal Start Position */
362 case 0x52: /* TV Vertical Start Position */
364 case 0x54: /* TV Test Pattern Setting */
366 case 0x56: /* TV Filter Setting */
367 return s
->tv_filter_config
;
368 case 0x58: /* TV Filter Coefficient Index */
369 return s
->tv_filter_idx
;
370 case 0x5a: /* TV Filter Coefficient Data */
371 if (s
->tv_filter_idx
< 0x20)
372 return s
->tv_filter_coeff
[s
->tv_filter_idx
++];
375 case 0x60: /* Input YUV/RGB Translate Mode 0 */
377 case 0x62: /* Input YUV/RGB Translate Mode 1 */
379 case 0x64: /* U Data Fix */
381 case 0x66: /* V Data Fix */
384 case 0x68: /* Display Mode */
387 case 0x6a: /* Special Effects */
390 case 0x6c: /* Input Window X Start Position 0 */
391 return s
->ix
[0] & 0xff;
392 case 0x6e: /* Input Window X Start Position 1 */
393 return s
->ix
[0] >> 3;
394 case 0x70: /* Input Window Y Start Position 0 */
395 return s
->ix
[0] & 0xff;
396 case 0x72: /* Input Window Y Start Position 1 */
397 return s
->ix
[0] >> 3;
398 case 0x74: /* Input Window X End Position 0 */
399 return s
->ix
[1] & 0xff;
400 case 0x76: /* Input Window X End Position 1 */
401 return s
->ix
[1] >> 3;
402 case 0x78: /* Input Window Y End Position 0 */
403 return s
->ix
[1] & 0xff;
404 case 0x7a: /* Input Window Y End Position 1 */
405 return s
->ix
[1] >> 3;
406 case 0x7c: /* Output Window X Start Position 0 */
407 return s
->ox
[0] & 0xff;
408 case 0x7e: /* Output Window X Start Position 1 */
409 return s
->ox
[0] >> 3;
410 case 0x80: /* Output Window Y Start Position 0 */
411 return s
->oy
[0] & 0xff;
412 case 0x82: /* Output Window Y Start Position 1 */
413 return s
->oy
[0] >> 3;
414 case 0x84: /* Output Window X End Position 0 */
415 return s
->ox
[1] & 0xff;
416 case 0x86: /* Output Window X End Position 1 */
417 return s
->ox
[1] >> 3;
418 case 0x88: /* Output Window Y End Position 0 */
419 return s
->oy
[1] & 0xff;
420 case 0x8a: /* Output Window Y End Position 1 */
421 return s
->oy
[1] >> 3;
423 case 0x8c: /* Input Data Format */
425 case 0x8e: /* Data Source Select */
427 case 0x90: /* Display Memory Data Port */
430 case 0xa8: /* Border Color 0 */
432 case 0xaa: /* Border Color 1 */
434 case 0xac: /* Border Color 2 */
437 case 0xb4: /* Gamma Correction Enable */
438 return s
->gamma_config
;
439 case 0xb6: /* Gamma Correction Table Index */
441 case 0xb8: /* Gamma Correction Table Data */
442 return s
->gamma_lut
[s
->gamma_idx
++];
444 case 0xba: /* 3x3 Matrix Enable */
445 return s
->matrix_ena
;
446 case 0xbc ... 0xde: /* Coefficient Registers */
447 return s
->matrix_coeff
[(reg
- 0xbc) >> 1];
448 case 0xe0: /* 3x3 Matrix Red Offset */
450 case 0xe2: /* 3x3 Matrix Green Offset */
452 case 0xe4: /* 3x3 Matrix Blue Offset */
455 case 0xe6: /* Power-save */
457 case 0xe8: /* Non-display Period Control / Status */
458 return s
->status
| (1 << 5);
459 case 0xea: /* RGB Interface Control */
460 return s
->rgbgpio_dir
;
461 case 0xec: /* RGB Interface Status */
463 case 0xee: /* General-purpose IO Pins Configuration */
465 case 0xf0: /* General-purpose IO Pins Status / Control */
467 case 0xf2: /* GPIO Positive Edge Interrupt Trigger */
468 return s
->gpio_edge
[0];
469 case 0xf4: /* GPIO Negative Edge Interrupt Trigger */
470 return s
->gpio_edge
[1];
471 case 0xf6: /* GPIO Interrupt Status */
473 case 0xf8: /* GPIO Pull-down Control */
474 return s
->gpio_pdown
;
477 fprintf(stderr
, "%s: unknown register %02x\n", __func__
, reg
);
482 static void blizzard_reg_write(void *opaque
, uint8_t reg
, uint16_t value
)
484 BlizzardState
*s
= (BlizzardState
*) opaque
;
487 case 0x04: /* PLL M-Divider */
488 s
->pll
= (value
& 0x3f) + 1;
490 case 0x06: /* PLL Lock Range Control */
491 s
->pll_range
= value
& 3;
493 case 0x08: /* PLL Lock Synthesis Control 0 */
494 s
->pll_ctrl
&= 0xf00;
495 s
->pll_ctrl
|= (value
<< 0) & 0x0ff;
497 case 0x0a: /* PLL Lock Synthesis Control 1 */
498 s
->pll_ctrl
&= 0x0ff;
499 s
->pll_ctrl
|= (value
<< 8) & 0xf00;
501 case 0x0c: /* PLL Mode Control 0 */
502 s
->pll_mode
= value
& 0x77;
503 if ((value
& 3) == 0 || (value
& 3) == 3)
504 fprintf(stderr
, "%s: wrong PLL Control bits (%i)\n",
505 __func__
, value
& 3);
508 case 0x0e: /* Clock-Source Select */
509 s
->clksel
= value
& 0xff;
512 case 0x10: /* Memory Controller Activate */
513 s
->memenable
= value
& 1;
515 case 0x14: /* Memory Controller Bank 0 Status Flag */
518 case 0x18: /* Auto-Refresh Interval Setting 0 */
519 s
->memrefresh
&= 0xf00;
520 s
->memrefresh
|= (value
<< 0) & 0x0ff;
522 case 0x1a: /* Auto-Refresh Interval Setting 1 */
523 s
->memrefresh
&= 0x0ff;
524 s
->memrefresh
|= (value
<< 8) & 0xf00;
527 case 0x1c: /* Power-On Sequence Timing Control */
528 s
->timing
[0] = value
& 0x7f;
530 case 0x1e: /* Timing Control 0 */
531 s
->timing
[1] = value
& 0x17;
533 case 0x20: /* Timing Control 1 */
534 s
->timing
[2] = value
& 0x35;
537 case 0x24: /* Arbitration Priority Control */
538 s
->priority
= value
& 1;
541 case 0x28: /* LCD Panel Configuration */
542 s
->lcd_config
= value
& 0xff;
543 if (value
& (1 << 7))
544 fprintf(stderr
, "%s: data swap not supported!\n", __func__
);
547 case 0x2a: /* LCD Horizontal Display Width */
550 case 0x2c: /* LCD Horizontal Non-display Period */
551 s
->hndp
= value
& 0xff;
553 case 0x2e: /* LCD Vertical Display Height 0 */
555 s
->y
|= (value
<< 0) & 0x0ff;
557 case 0x30: /* LCD Vertical Display Height 1 */
559 s
->y
|= (value
<< 8) & 0x300;
561 case 0x32: /* LCD Vertical Non-display Period */
562 s
->vndp
= value
& 0xff;
564 case 0x34: /* LCD HS Pulse-width */
565 s
->hsync
= value
& 0xff;
567 case 0x36: /* LCD HS Pulse Start Position */
568 s
->skipx
= value
& 0xff;
570 case 0x38: /* LCD VS Pulse-width */
571 s
->vsync
= value
& 0xbf;
573 case 0x3a: /* LCD VS Pulse Start Position */
574 s
->skipy
= value
& 0xff;
577 case 0x3c: /* PCLK Polarity */
578 s
->pclk
= value
& 0x82;
579 /* Affects calculation of s->hndp, s->hsync and s->skipx. */
582 case 0x3e: /* High-speed Serial Interface Tx Configuration Port 0 */
583 s
->hssi_config
[0] = value
;
585 case 0x40: /* High-speed Serial Interface Tx Configuration Port 1 */
586 s
->hssi_config
[1] = value
;
587 if (((value
>> 4) & 3) == 3)
588 fprintf(stderr
, "%s: Illegal active-data-links value\n",
591 case 0x42: /* High-speed Serial Interface Tx Mode */
592 s
->hssi_config
[2] = value
& 0xbd;
595 case 0x44: /* TV Display Configuration */
596 s
->tv_config
= value
& 0xfe;
598 case 0x46 ... 0x4c: /* TV Vertical Blanking Interval Data bits 0 */
599 s
->tv_timing
[(reg
- 0x46) >> 1] = value
;
601 case 0x4e: /* VBI: Closed Caption / XDS Control / Status */
604 case 0x50: /* TV Horizontal Start Position */
607 case 0x52: /* TV Vertical Start Position */
608 s
->tv_y
= value
& 0x7f;
610 case 0x54: /* TV Test Pattern Setting */
613 case 0x56: /* TV Filter Setting */
614 s
->tv_filter_config
= value
& 0xbf;
616 case 0x58: /* TV Filter Coefficient Index */
617 s
->tv_filter_idx
= value
& 0x1f;
619 case 0x5a: /* TV Filter Coefficient Data */
620 if (s
->tv_filter_idx
< 0x20)
621 s
->tv_filter_coeff
[s
->tv_filter_idx
++] = value
;
624 case 0x60: /* Input YUV/RGB Translate Mode 0 */
625 s
->yrc
[0] = value
& 0xb0;
627 case 0x62: /* Input YUV/RGB Translate Mode 1 */
628 s
->yrc
[1] = value
& 0x30;
630 case 0x64: /* U Data Fix */
633 case 0x66: /* V Data Fix */
637 case 0x68: /* Display Mode */
638 if ((s
->mode
^ value
) & 3)
640 s
->mode
= value
& 0xb7;
641 s
->enable
= value
& 1;
642 s
->blank
= (value
>> 1) & 1;
643 if (value
& (1 << 4))
644 fprintf(stderr
, "%s: Macrovision enable attempt!\n", __func__
);
647 case 0x6a: /* Special Effects */
648 s
->effect
= value
& 0xfb;
651 case 0x6c: /* Input Window X Start Position 0 */
653 s
->ix
[0] |= (value
<< 0) & 0x0ff;
655 case 0x6e: /* Input Window X Start Position 1 */
657 s
->ix
[0] |= (value
<< 8) & 0x300;
659 case 0x70: /* Input Window Y Start Position 0 */
661 s
->iy
[0] |= (value
<< 0) & 0x0ff;
663 case 0x72: /* Input Window Y Start Position 1 */
665 s
->iy
[0] |= (value
<< 8) & 0x300;
667 case 0x74: /* Input Window X End Position 0 */
669 s
->ix
[1] |= (value
<< 0) & 0x0ff;
671 case 0x76: /* Input Window X End Position 1 */
673 s
->ix
[1] |= (value
<< 8) & 0x300;
675 case 0x78: /* Input Window Y End Position 0 */
677 s
->iy
[1] |= (value
<< 0) & 0x0ff;
679 case 0x7a: /* Input Window Y End Position 1 */
681 s
->iy
[1] |= (value
<< 8) & 0x300;
683 case 0x7c: /* Output Window X Start Position 0 */
685 s
->ox
[0] |= (value
<< 0) & 0x0ff;
687 case 0x7e: /* Output Window X Start Position 1 */
689 s
->ox
[0] |= (value
<< 8) & 0x300;
691 case 0x80: /* Output Window Y Start Position 0 */
693 s
->oy
[0] |= (value
<< 0) & 0x0ff;
695 case 0x82: /* Output Window Y Start Position 1 */
697 s
->oy
[0] |= (value
<< 8) & 0x300;
699 case 0x84: /* Output Window X End Position 0 */
701 s
->ox
[1] |= (value
<< 0) & 0x0ff;
703 case 0x86: /* Output Window X End Position 1 */
705 s
->ox
[1] |= (value
<< 8) & 0x300;
707 case 0x88: /* Output Window Y End Position 0 */
709 s
->oy
[1] |= (value
<< 0) & 0x0ff;
711 case 0x8a: /* Output Window Y End Position 1 */
713 s
->oy
[1] |= (value
<< 8) & 0x300;
716 case 0x8c: /* Input Data Format */
717 s
->iformat
= value
& 0xf;
718 s
->bpp
= blizzard_iformat_bpp
[s
->iformat
];
720 fprintf(stderr
, "%s: Illegal or unsupported input format %x\n",
721 __func__
, s
->iformat
);
723 case 0x8e: /* Data Source Select */
724 s
->source
= value
& 7;
725 /* Currently all windows will be "destructive overlays". */
726 if ((!(s
->effect
& (1 << 3)) && (s
->ix
[0] != s
->ox
[0] ||
727 s
->iy
[0] != s
->oy
[0] ||
728 s
->ix
[1] != s
->ox
[1] ||
729 s
->iy
[1] != s
->oy
[1])) ||
730 !((s
->ix
[1] - s
->ix
[0]) & (s
->iy
[1] - s
->iy
[0]) &
731 (s
->ox
[1] - s
->ox
[0]) & (s
->oy
[1] - s
->oy
[0]) & 1))
732 fprintf(stderr
, "%s: Illegal input/output window positions\n",
735 blizzard_transfer_setup(s
);
738 case 0x90: /* Display Memory Data Port */
739 if (!s
->data
.len
&& !blizzard_transfer_setup(s
))
742 *s
->data
.ptr
++ = value
;
743 if (-- s
->data
.len
== 0)
747 case 0xa8: /* Border Color 0 */
750 case 0xaa: /* Border Color 1 */
753 case 0xac: /* Border Color 2 */
757 case 0xb4: /* Gamma Correction Enable */
758 s
->gamma_config
= value
& 0x87;
760 case 0xb6: /* Gamma Correction Table Index */
761 s
->gamma_idx
= value
;
763 case 0xb8: /* Gamma Correction Table Data */
764 s
->gamma_lut
[s
->gamma_idx
++] = value
;
767 case 0xba: /* 3x3 Matrix Enable */
768 s
->matrix_ena
= value
& 1;
770 case 0xbc ... 0xde: /* Coefficient Registers */
771 s
->matrix_coeff
[(reg
- 0xbc) >> 1] = value
& ((reg
& 2) ? 0x80 : 0xff);
773 case 0xe0: /* 3x3 Matrix Red Offset */
776 case 0xe2: /* 3x3 Matrix Green Offset */
779 case 0xe4: /* 3x3 Matrix Blue Offset */
783 case 0xe6: /* Power-save */
784 s
->pm
= value
& 0x83;
785 if (value
& s
->mode
& 1)
786 fprintf(stderr
, "%s: The display must be disabled before entering "
787 "Standby Mode\n", __func__
);
789 case 0xe8: /* Non-display Period Control / Status */
790 s
->status
= value
& 0x1b;
792 case 0xea: /* RGB Interface Control */
793 s
->rgbgpio_dir
= value
& 0x8f;
795 case 0xec: /* RGB Interface Status */
796 s
->rgbgpio
= value
& 0xcf;
798 case 0xee: /* General-purpose IO Pins Configuration */
801 case 0xf0: /* General-purpose IO Pins Status / Control */
804 case 0xf2: /* GPIO Positive Edge Interrupt Trigger */
805 s
->gpio_edge
[0] = value
;
807 case 0xf4: /* GPIO Negative Edge Interrupt Trigger */
808 s
->gpio_edge
[1] = value
;
810 case 0xf6: /* GPIO Interrupt Status */
811 s
->gpio_irq
&= value
;
813 case 0xf8: /* GPIO Pull-down Control */
814 s
->gpio_pdown
= value
;
818 fprintf(stderr
, "%s: unknown register %02x\n", __func__
, reg
);
823 uint16_t s1d13745_read(void *opaque
, int dc
)
825 BlizzardState
*s
= (BlizzardState
*) opaque
;
826 uint16_t value
= blizzard_reg_read(s
, s
->reg
);
828 if (s
->swallow
-- > 0)
836 void s1d13745_write(void *opaque
, int dc
, uint16_t value
)
838 BlizzardState
*s
= (BlizzardState
*) opaque
;
840 if (s
->swallow
-- > 0)
843 blizzard_reg_write(s
, s
->reg
, value
);
845 if (s
->reg
!= 0x90 && s
->reg
!= 0x5a && s
->reg
!= 0xb8)
848 s
->reg
= value
& 0xff;
851 void s1d13745_write_block(void *opaque
, int dc
,
852 void *buf
, size_t len
, int pitch
)
854 BlizzardState
*s
= (BlizzardState
*) opaque
;
857 if (s
->reg
== 0x90 && dc
&&
858 (s
->data
.len
|| blizzard_transfer_setup(s
)) &&
859 len
>= (s
->data
.len
<< 1)) {
860 len
-= s
->data
.len
<< 1;
864 s
->data
.pitch
= pitch
;
866 s
->data
.data
= s
->data
.buf
;
870 s1d13745_write(opaque
, dc
, *(uint16_t *) buf
);
876 static void blizzard_update_display(void *opaque
)
878 BlizzardState
*s
= (BlizzardState
*) opaque
;
879 DisplaySurface
*surface
= qemu_console_surface(s
->con
);
880 int y
, bypp
, bypl
, bwidth
;
886 if (s
->x
!= surface_width(surface
) || s
->y
!= surface_height(surface
)) {
888 qemu_console_resize(s
->con
, s
->x
, s
->y
);
889 surface
= qemu_console_surface(s
->con
);
896 bypp
= surface_bytes_per_pixel(surface
);
897 memset(surface_data(surface
), 0, bypp
* s
->x
* s
->y
);
907 if (s
->mx
[1] <= s
->mx
[0])
910 bypp
= surface_bytes_per_pixel(surface
);
912 bwidth
= bypp
* (s
->mx
[1] - s
->mx
[0]);
914 src
= s
->fb
+ bypl
* y
+ bypp
* s
->mx
[0];
915 dst
= surface_data(surface
) + bypl
* y
+ bypp
* s
->mx
[0];
916 for (; y
< s
->my
[1]; y
++, src
+= bypl
, dst
+= bypl
)
917 memcpy(dst
, src
, bwidth
);
919 dpy_gfx_update(s
->con
, s
->mx
[0], s
->my
[0],
920 s
->mx
[1] - s
->mx
[0], y
- s
->my
[0]);
928 static void blizzard_draw_line16_32(uint32_t *dest
,
929 const uint16_t *src
, unsigned int width
)
932 unsigned int r
, g
, b
;
933 const uint16_t *end
= (const void *) src
+ width
;
936 b
= extract16(data
, 0, 5) << 3;
937 g
= extract16(data
, 5, 6) << 2;
938 r
= extract16(data
, 11, 5) << 3;
939 *dest
++ = rgb_to_pixel32(r
, g
, b
);
943 static void blizzard_draw_line24mode1_32(uint32_t *dest
,
944 const uint8_t *src
, unsigned int width
)
946 /* TODO: check if SDL 24-bit planes are not in the same format and
947 * if so, use memcpy */
948 unsigned int r
[2], g
[2], b
[2];
949 const uint8_t *end
= src
+ width
;
955 *dest
++ = rgb_to_pixel32(r
[0], g
[0], b
[0]);
958 *dest
++ = rgb_to_pixel32(r
[1], g
[1], b
[1]);
962 static void blizzard_draw_line24mode2_32(uint32_t *dest
,
963 const uint8_t *src
, unsigned int width
)
965 unsigned int r
, g
, b
;
966 const uint8_t *end
= src
+ width
;
972 *dest
++ = rgb_to_pixel32(r
, g
, b
);
977 static blizzard_fn_t blizzard_draw_fn_32
[0x10] = {
980 (blizzard_fn_t
) blizzard_draw_line16_32
,
981 /* RGB 6:6:6 mode 1 */
982 (blizzard_fn_t
) blizzard_draw_line24mode1_32
,
983 /* RGB 8:8:8 mode 1 */
984 (blizzard_fn_t
) blizzard_draw_line24mode1_32
,
986 /* RGB 6:6:6 mode 2 */
987 (blizzard_fn_t
) blizzard_draw_line24mode2_32
,
988 /* RGB 8:8:8 mode 2 */
989 (blizzard_fn_t
) blizzard_draw_line24mode2_32
,
994 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
,
997 /* 90deg, 180deg and 270deg rotation */
998 static blizzard_fn_t blizzard_draw_fn_r_32
[0x10] = {
1003 static const GraphicHwOps blizzard_ops
= {
1004 .invalidate
= blizzard_invalidate_display
,
1005 .gfx_update
= blizzard_update_display
,
1008 void *s1d13745_init(qemu_irq gpio_int
)
1010 BlizzardState
*s
= (BlizzardState
*) g_malloc0(sizeof(*s
));
1011 DisplaySurface
*surface
;
1013 s
->fb
= g_malloc(0x180000);
1015 s
->con
= graphic_console_init(NULL
, 0, &blizzard_ops
, s
);
1016 surface
= qemu_console_surface(s
->con
);
1018 assert(surface_bits_per_pixel(surface
) == 32);
1020 s
->line_fn_tab
[0] = blizzard_draw_fn_32
;
1021 s
->line_fn_tab
[1] = blizzard_draw_fn_r_32
;