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-common.h"
26 #include "pixel_ops.h"
28 typedef void (*blizzard_fn_t
)(uint8_t *, const uint8_t *, unsigned int);
74 blizzard_fn_t
*line_fn_tab
[2];
77 uint8_t hssi_config
[3];
84 uint8_t tv_filter_config
;
85 uint8_t tv_filter_idx
;
86 uint8_t tv_filter_coeff
[0x20];
92 uint8_t gamma_lut
[0x100];
94 uint8_t matrix_coeff
[0x12];
104 uint8_t gpio_edge
[2];
120 blizzard_fn_t line_fn
;
124 /* Bytes(!) per pixel */
125 static const int blizzard_iformat_bpp
[0x10] = {
128 3, /* RGB 6:6:6 mode 1 */
129 3, /* RGB 8:8:8 mode 1 */
131 4, /* RGB 6:6:6 mode 2 */
132 4, /* RGB 8:8:8 mode 2 */
138 static inline void blizzard_rgb2yuv(int r
, int g
, int b
,
139 int *y
, int *u
, int *v
)
141 *y
= 0x10 + ((0x838 * r
+ 0x1022 * g
+ 0x322 * b
) >> 13);
142 *u
= 0x80 + ((0xe0e * b
- 0x04c1 * r
- 0x94e * g
) >> 13);
143 *v
= 0x80 + ((0xe0e * r
- 0x0bc7 * g
- 0x247 * b
) >> 13);
146 static void blizzard_window(BlizzardState
*s
)
152 blizzard_fn_t fn
= s
->data
.line_fn
;
156 if (s
->mx
[0] > s
->data
.x
)
157 s
->mx
[0] = s
->data
.x
;
158 if (s
->my
[0] > s
->data
.y
)
159 s
->my
[0] = s
->data
.y
;
160 if (s
->mx
[1] < s
->data
.x
+ s
->data
.dx
)
161 s
->mx
[1] = s
->data
.x
+ s
->data
.dx
;
162 if (s
->my
[1] < s
->data
.y
+ s
->data
.dy
)
163 s
->my
[1] = s
->data
.y
+ s
->data
.dy
;
166 bypp
[1] = (ds_get_bits_per_pixel(s
->state
) + 7) >> 3;
167 bypl
[0] = bypp
[0] * s
->data
.pitch
;
168 bypl
[1] = bypp
[1] * s
->x
;
169 bypl
[2] = bypp
[0] * s
->data
.dx
;
172 dst
= s
->fb
+ bypl
[1] * s
->data
.y
+ bypp
[1] * s
->data
.x
;
173 for (y
= s
->data
.dy
; y
> 0; y
--, src
+= bypl
[0], dst
+= bypl
[1])
174 fn(dst
, src
, bypl
[2]);
177 static int blizzard_transfer_setup(BlizzardState
*s
)
179 if (s
->source
> 3 || !s
->bpp
||
180 s
->ix
[1] < s
->ix
[0] || s
->iy
[1] < s
->iy
[0])
183 s
->data
.angle
= s
->effect
& 3;
184 s
->data
.line_fn
= s
->line_fn_tab
[!!s
->data
.angle
][s
->iformat
];
185 s
->data
.x
= s
->ix
[0];
186 s
->data
.y
= s
->iy
[0];
187 s
->data
.dx
= s
->ix
[1] - s
->ix
[0] + 1;
188 s
->data
.dy
= s
->iy
[1] - s
->iy
[0] + 1;
189 s
->data
.len
= s
->bpp
* s
->data
.dx
* s
->data
.dy
;
190 s
->data
.pitch
= s
->data
.dx
;
191 if (s
->data
.len
> s
->data
.buflen
) {
192 s
->data
.buf
= qemu_realloc(s
->data
.buf
, s
->data
.len
);
193 s
->data
.buflen
= s
->data
.len
;
195 s
->data
.ptr
= s
->data
.buf
;
196 s
->data
.data
= s
->data
.buf
;
201 static void blizzard_reset(BlizzardState
*s
)
212 s
->memrefresh
= 0x25c;
218 s
->lcd_config
= 0x74;
245 s
->bpp
= blizzard_iformat_bpp
[s
->iformat
];
247 s
->hssi_config
[0] = 0x00;
248 s
->hssi_config
[1] = 0x00;
249 s
->hssi_config
[2] = 0x01;
251 s
->tv_timing
[0] = 0x00;
252 s
->tv_timing
[1] = 0x00;
253 s
->tv_timing
[2] = 0x00;
254 s
->tv_timing
[3] = 0x00;
259 s
->tv_filter_config
= 0x80;
260 s
->tv_filter_idx
= 0x00;
264 s
->gamma_config
= 0x00;
266 s
->matrix_ena
= 0x00;
267 memset(&s
->matrix_coeff
, 0, sizeof(s
->matrix_coeff
));
273 s
->rgbgpio_dir
= 0x00;
275 s
->gpio_edge
[0] = 0x00;
276 s
->gpio_edge
[1] = 0x00;
278 s
->gpio_pdown
= 0xff;
281 static inline void blizzard_invalidate_display(void *opaque
) {
282 BlizzardState
*s
= (BlizzardState
*) opaque
;
287 static uint16_t blizzard_reg_read(void *opaque
, uint8_t reg
)
289 BlizzardState
*s
= (BlizzardState
*) opaque
;
292 case 0x00: /* Revision Code */
295 case 0x02: /* Configuration Readback */
296 return 0x83; /* Macrovision OK, CNF[2:0] = 3 */
298 case 0x04: /* PLL M-Divider */
299 return (s
->pll
- 1) | (1 << 7);
300 case 0x06: /* PLL Lock Range Control */
302 case 0x08: /* PLL Lock Synthesis Control 0 */
303 return s
->pll_ctrl
& 0xff;
304 case 0x0a: /* PLL Lock Synthesis Control 1 */
305 return s
->pll_ctrl
>> 8;
306 case 0x0c: /* PLL Mode Control 0 */
309 case 0x0e: /* Clock-Source Select */
312 case 0x10: /* Memory Controller Activate */
313 case 0x14: /* Memory Controller Bank 0 Status Flag */
316 case 0x18: /* Auto-Refresh Interval Setting 0 */
317 return s
->memrefresh
& 0xff;
318 case 0x1a: /* Auto-Refresh Interval Setting 1 */
319 return s
->memrefresh
>> 8;
321 case 0x1c: /* Power-On Sequence Timing Control */
323 case 0x1e: /* Timing Control 0 */
325 case 0x20: /* Timing Control 1 */
328 case 0x24: /* Arbitration Priority Control */
331 case 0x28: /* LCD Panel Configuration */
332 return s
->lcd_config
;
334 case 0x2a: /* LCD Horizontal Display Width */
336 case 0x2c: /* LCD Horizontal Non-display Period */
338 case 0x2e: /* LCD Vertical Display Height 0 */
340 case 0x30: /* LCD Vertical Display Height 1 */
342 case 0x32: /* LCD Vertical Non-display Period */
344 case 0x34: /* LCD HS Pulse-width */
346 case 0x36: /* LCd HS Pulse Start Position */
347 return s
->skipx
>> 3;
348 case 0x38: /* LCD VS Pulse-width */
350 case 0x3a: /* LCD VS Pulse Start Position */
353 case 0x3c: /* PCLK Polarity */
356 case 0x3e: /* High-speed Serial Interface Tx Configuration Port 0 */
357 return s
->hssi_config
[0];
358 case 0x40: /* High-speed Serial Interface Tx Configuration Port 1 */
359 return s
->hssi_config
[1];
360 case 0x42: /* High-speed Serial Interface Tx Mode */
361 return s
->hssi_config
[2];
362 case 0x44: /* TV Display Configuration */
364 case 0x46 ... 0x4c: /* TV Vertical Blanking Interval Data bits */
365 return s
->tv_timing
[(reg
- 0x46) >> 1];
366 case 0x4e: /* VBI: Closed Caption / XDS Control / Status */
368 case 0x50: /* TV Horizontal Start Position */
370 case 0x52: /* TV Vertical Start Position */
372 case 0x54: /* TV Test Pattern Setting */
374 case 0x56: /* TV Filter Setting */
375 return s
->tv_filter_config
;
376 case 0x58: /* TV Filter Coefficient Index */
377 return s
->tv_filter_idx
;
378 case 0x5a: /* TV Filter Coefficient Data */
379 if (s
->tv_filter_idx
< 0x20)
380 return s
->tv_filter_coeff
[s
->tv_filter_idx
++];
383 case 0x60: /* Input YUV/RGB Translate Mode 0 */
385 case 0x62: /* Input YUV/RGB Translate Mode 1 */
387 case 0x64: /* U Data Fix */
389 case 0x66: /* V Data Fix */
392 case 0x68: /* Display Mode */
395 case 0x6a: /* Special Effects */
398 case 0x6c: /* Input Window X Start Position 0 */
399 return s
->ix
[0] & 0xff;
400 case 0x6e: /* Input Window X Start Position 1 */
401 return s
->ix
[0] >> 3;
402 case 0x70: /* Input Window Y Start Position 0 */
403 return s
->ix
[0] & 0xff;
404 case 0x72: /* Input Window Y Start Position 1 */
405 return s
->ix
[0] >> 3;
406 case 0x74: /* Input Window X End Position 0 */
407 return s
->ix
[1] & 0xff;
408 case 0x76: /* Input Window X End Position 1 */
409 return s
->ix
[1] >> 3;
410 case 0x78: /* Input Window Y End Position 0 */
411 return s
->ix
[1] & 0xff;
412 case 0x7a: /* Input Window Y End Position 1 */
413 return s
->ix
[1] >> 3;
414 case 0x7c: /* Output Window X Start Position 0 */
415 return s
->ox
[0] & 0xff;
416 case 0x7e: /* Output Window X Start Position 1 */
417 return s
->ox
[0] >> 3;
418 case 0x80: /* Output Window Y Start Position 0 */
419 return s
->oy
[0] & 0xff;
420 case 0x82: /* Output Window Y Start Position 1 */
421 return s
->oy
[0] >> 3;
422 case 0x84: /* Output Window X End Position 0 */
423 return s
->ox
[1] & 0xff;
424 case 0x86: /* Output Window X End Position 1 */
425 return s
->ox
[1] >> 3;
426 case 0x88: /* Output Window Y End Position 0 */
427 return s
->oy
[1] & 0xff;
428 case 0x8a: /* Output Window Y End Position 1 */
429 return s
->oy
[1] >> 3;
431 case 0x8c: /* Input Data Format */
433 case 0x8e: /* Data Source Select */
435 case 0x90: /* Display Memory Data Port */
438 case 0xa8: /* Border Color 0 */
440 case 0xaa: /* Border Color 1 */
442 case 0xac: /* Border Color 2 */
445 case 0xb4: /* Gamma Correction Enable */
446 return s
->gamma_config
;
447 case 0xb6: /* Gamma Correction Table Index */
449 case 0xb8: /* Gamma Correction Table Data */
450 return s
->gamma_lut
[s
->gamma_idx
++];
452 case 0xba: /* 3x3 Matrix Enable */
453 return s
->matrix_ena
;
454 case 0xbc ... 0xde: /* Coefficient Registers */
455 return s
->matrix_coeff
[(reg
- 0xbc) >> 1];
456 case 0xe0: /* 3x3 Matrix Red Offset */
458 case 0xe2: /* 3x3 Matrix Green Offset */
460 case 0xe4: /* 3x3 Matrix Blue Offset */
463 case 0xe6: /* Power-save */
465 case 0xe8: /* Non-display Period Control / Status */
466 return s
->status
| (1 << 5);
467 case 0xea: /* RGB Interface Control */
468 return s
->rgbgpio_dir
;
469 case 0xec: /* RGB Interface Status */
471 case 0xee: /* General-purpose IO Pins Configuration */
473 case 0xf0: /* General-purpose IO Pins Status / Control */
475 case 0xf2: /* GPIO Positive Edge Interrupt Trigger */
476 return s
->gpio_edge
[0];
477 case 0xf4: /* GPIO Negative Edge Interrupt Trigger */
478 return s
->gpio_edge
[1];
479 case 0xf6: /* GPIO Interrupt Status */
481 case 0xf8: /* GPIO Pull-down Control */
482 return s
->gpio_pdown
;
485 fprintf(stderr
, "%s: unknown register %02x\n", __FUNCTION__
, reg
);
490 static void blizzard_reg_write(void *opaque
, uint8_t reg
, uint16_t value
)
492 BlizzardState
*s
= (BlizzardState
*) opaque
;
495 case 0x04: /* PLL M-Divider */
496 s
->pll
= (value
& 0x3f) + 1;
498 case 0x06: /* PLL Lock Range Control */
499 s
->pll_range
= value
& 3;
501 case 0x08: /* PLL Lock Synthesis Control 0 */
502 s
->pll_ctrl
&= 0xf00;
503 s
->pll_ctrl
|= (value
<< 0) & 0x0ff;
505 case 0x0a: /* PLL Lock Synthesis Control 1 */
506 s
->pll_ctrl
&= 0x0ff;
507 s
->pll_ctrl
|= (value
<< 8) & 0xf00;
509 case 0x0c: /* PLL Mode Control 0 */
510 s
->pll_mode
= value
& 0x77;
511 if ((value
& 3) == 0 || (value
& 3) == 3)
512 fprintf(stderr
, "%s: wrong PLL Control bits (%i)\n",
513 __FUNCTION__
, value
& 3);
516 case 0x0e: /* Clock-Source Select */
517 s
->clksel
= value
& 0xff;
520 case 0x10: /* Memory Controller Activate */
521 s
->memenable
= value
& 1;
523 case 0x14: /* Memory Controller Bank 0 Status Flag */
526 case 0x18: /* Auto-Refresh Interval Setting 0 */
527 s
->memrefresh
&= 0xf00;
528 s
->memrefresh
|= (value
<< 0) & 0x0ff;
530 case 0x1a: /* Auto-Refresh Interval Setting 1 */
531 s
->memrefresh
&= 0x0ff;
532 s
->memrefresh
|= (value
<< 8) & 0xf00;
535 case 0x1c: /* Power-On Sequence Timing Control */
536 s
->timing
[0] = value
& 0x7f;
538 case 0x1e: /* Timing Control 0 */
539 s
->timing
[1] = value
& 0x17;
541 case 0x20: /* Timing Control 1 */
542 s
->timing
[2] = value
& 0x35;
545 case 0x24: /* Arbitration Priority Control */
546 s
->priority
= value
& 1;
549 case 0x28: /* LCD Panel Configuration */
550 s
->lcd_config
= value
& 0xff;
551 if (value
& (1 << 7))
552 fprintf(stderr
, "%s: data swap not supported!\n", __FUNCTION__
);
555 case 0x2a: /* LCD Horizontal Display Width */
558 case 0x2c: /* LCD Horizontal Non-display Period */
559 s
->hndp
= value
& 0xff;
561 case 0x2e: /* LCD Vertical Display Height 0 */
563 s
->y
|= (value
<< 0) & 0x0ff;
565 case 0x30: /* LCD Vertical Display Height 1 */
567 s
->y
|= (value
<< 8) & 0x300;
569 case 0x32: /* LCD Vertical Non-display Period */
570 s
->vndp
= value
& 0xff;
572 case 0x34: /* LCD HS Pulse-width */
573 s
->hsync
= value
& 0xff;
575 case 0x36: /* LCD HS Pulse Start Position */
576 s
->skipx
= value
& 0xff;
578 case 0x38: /* LCD VS Pulse-width */
579 s
->vsync
= value
& 0xbf;
581 case 0x3a: /* LCD VS Pulse Start Position */
582 s
->skipy
= value
& 0xff;
585 case 0x3c: /* PCLK Polarity */
586 s
->pclk
= value
& 0x82;
587 /* Affects calculation of s->hndp, s->hsync and s->skipx. */
590 case 0x3e: /* High-speed Serial Interface Tx Configuration Port 0 */
591 s
->hssi_config
[0] = value
;
593 case 0x40: /* High-speed Serial Interface Tx Configuration Port 1 */
594 s
->hssi_config
[1] = value
;
595 if (((value
>> 4) & 3) == 3)
596 fprintf(stderr
, "%s: Illegal active-data-links value\n",
599 case 0x42: /* High-speed Serial Interface Tx Mode */
600 s
->hssi_config
[2] = value
& 0xbd;
603 case 0x44: /* TV Display Configuration */
604 s
->tv_config
= value
& 0xfe;
606 case 0x46 ... 0x4c: /* TV Vertical Blanking Interval Data bits 0 */
607 s
->tv_timing
[(reg
- 0x46) >> 1] = value
;
609 case 0x4e: /* VBI: Closed Caption / XDS Control / Status */
612 case 0x50: /* TV Horizontal Start Position */
615 case 0x52: /* TV Vertical Start Position */
616 s
->tv_y
= value
& 0x7f;
618 case 0x54: /* TV Test Pattern Setting */
621 case 0x56: /* TV Filter Setting */
622 s
->tv_filter_config
= value
& 0xbf;
624 case 0x58: /* TV Filter Coefficient Index */
625 s
->tv_filter_idx
= value
& 0x1f;
627 case 0x5a: /* TV Filter Coefficient Data */
628 if (s
->tv_filter_idx
< 0x20)
629 s
->tv_filter_coeff
[s
->tv_filter_idx
++] = value
;
632 case 0x60: /* Input YUV/RGB Translate Mode 0 */
633 s
->yrc
[0] = value
& 0xb0;
635 case 0x62: /* Input YUV/RGB Translate Mode 1 */
636 s
->yrc
[1] = value
& 0x30;
638 case 0x64: /* U Data Fix */
641 case 0x66: /* V Data Fix */
645 case 0x68: /* Display Mode */
646 if ((s
->mode
^ value
) & 3)
648 s
->mode
= value
& 0xb7;
649 s
->enable
= value
& 1;
650 s
->blank
= (value
>> 1) & 1;
651 if (value
& (1 << 4))
652 fprintf(stderr
, "%s: Macrovision enable attempt!\n", __FUNCTION__
);
655 case 0x6a: /* Special Effects */
656 s
->effect
= value
& 0xfb;
659 case 0x6c: /* Input Window X Start Position 0 */
661 s
->ix
[0] |= (value
<< 0) & 0x0ff;
663 case 0x6e: /* Input Window X Start Position 1 */
665 s
->ix
[0] |= (value
<< 8) & 0x300;
667 case 0x70: /* Input Window Y Start Position 0 */
669 s
->iy
[0] |= (value
<< 0) & 0x0ff;
671 case 0x72: /* Input Window Y Start Position 1 */
673 s
->iy
[0] |= (value
<< 8) & 0x300;
675 case 0x74: /* Input Window X End Position 0 */
677 s
->ix
[1] |= (value
<< 0) & 0x0ff;
679 case 0x76: /* Input Window X End Position 1 */
681 s
->ix
[1] |= (value
<< 8) & 0x300;
683 case 0x78: /* Input Window Y End Position 0 */
685 s
->iy
[1] |= (value
<< 0) & 0x0ff;
687 case 0x7a: /* Input Window Y End Position 1 */
689 s
->iy
[1] |= (value
<< 8) & 0x300;
691 case 0x7c: /* Output Window X Start Position 0 */
693 s
->ox
[0] |= (value
<< 0) & 0x0ff;
695 case 0x7e: /* Output Window X Start Position 1 */
697 s
->ox
[0] |= (value
<< 8) & 0x300;
699 case 0x80: /* Output Window Y Start Position 0 */
701 s
->oy
[0] |= (value
<< 0) & 0x0ff;
703 case 0x82: /* Output Window Y Start Position 1 */
705 s
->oy
[0] |= (value
<< 8) & 0x300;
707 case 0x84: /* Output Window X End Position 0 */
709 s
->ox
[1] |= (value
<< 0) & 0x0ff;
711 case 0x86: /* Output Window X End Position 1 */
713 s
->ox
[1] |= (value
<< 8) & 0x300;
715 case 0x88: /* Output Window Y End Position 0 */
717 s
->oy
[1] |= (value
<< 0) & 0x0ff;
719 case 0x8a: /* Output Window Y End Position 1 */
721 s
->oy
[1] |= (value
<< 8) & 0x300;
724 case 0x8c: /* Input Data Format */
725 s
->iformat
= value
& 0xf;
726 s
->bpp
= blizzard_iformat_bpp
[s
->iformat
];
728 fprintf(stderr
, "%s: Illegal or unsupported input format %x\n",
729 __FUNCTION__
, s
->iformat
);
731 case 0x8e: /* Data Source Select */
732 s
->source
= value
& 7;
733 /* Currently all windows will be "destructive overlays". */
734 if ((!(s
->effect
& (1 << 3)) && (s
->ix
[0] != s
->ox
[0] ||
735 s
->iy
[0] != s
->oy
[0] ||
736 s
->ix
[1] != s
->ox
[1] ||
737 s
->iy
[1] != s
->oy
[1])) ||
738 !((s
->ix
[1] - s
->ix
[0]) & (s
->iy
[1] - s
->iy
[0]) &
739 (s
->ox
[1] - s
->ox
[0]) & (s
->oy
[1] - s
->oy
[0]) & 1))
740 fprintf(stderr
, "%s: Illegal input/output window positions\n",
743 blizzard_transfer_setup(s
);
746 case 0x90: /* Display Memory Data Port */
747 if (!s
->data
.len
&& !blizzard_transfer_setup(s
))
750 *s
->data
.ptr
++ = value
;
751 if (-- s
->data
.len
== 0)
755 case 0xa8: /* Border Color 0 */
758 case 0xaa: /* Border Color 1 */
761 case 0xac: /* Border Color 2 */
765 case 0xb4: /* Gamma Correction Enable */
766 s
->gamma_config
= value
& 0x87;
768 case 0xb6: /* Gamma Correction Table Index */
769 s
->gamma_idx
= value
;
771 case 0xb8: /* Gamma Correction Table Data */
772 s
->gamma_lut
[s
->gamma_idx
++] = value
;
775 case 0xba: /* 3x3 Matrix Enable */
776 s
->matrix_ena
= value
& 1;
778 case 0xbc ... 0xde: /* Coefficient Registers */
779 s
->matrix_coeff
[(reg
- 0xbc) >> 1] = value
& ((reg
& 2) ? 0x80 : 0xff);
781 case 0xe0: /* 3x3 Matrix Red Offset */
784 case 0xe2: /* 3x3 Matrix Green Offset */
787 case 0xe4: /* 3x3 Matrix Blue Offset */
791 case 0xe6: /* Power-save */
792 s
->pm
= value
& 0x83;
793 if (value
& s
->mode
& 1)
794 fprintf(stderr
, "%s: The display must be disabled before entering "
795 "Standby Mode\n", __FUNCTION__
);
797 case 0xe8: /* Non-display Period Control / Status */
798 s
->status
= value
& 0x1b;
800 case 0xea: /* RGB Interface Control */
801 s
->rgbgpio_dir
= value
& 0x8f;
803 case 0xec: /* RGB Interface Status */
804 s
->rgbgpio
= value
& 0xcf;
806 case 0xee: /* General-purpose IO Pins Configuration */
809 case 0xf0: /* General-purpose IO Pins Status / Control */
812 case 0xf2: /* GPIO Positive Edge Interrupt Trigger */
813 s
->gpio_edge
[0] = value
;
815 case 0xf4: /* GPIO Negative Edge Interrupt Trigger */
816 s
->gpio_edge
[1] = value
;
818 case 0xf6: /* GPIO Interrupt Status */
819 s
->gpio_irq
&= value
;
821 case 0xf8: /* GPIO Pull-down Control */
822 s
->gpio_pdown
= value
;
826 fprintf(stderr
, "%s: unknown register %02x\n", __FUNCTION__
, reg
);
831 uint16_t s1d13745_read(void *opaque
, int dc
)
833 BlizzardState
*s
= (BlizzardState
*) opaque
;
834 uint16_t value
= blizzard_reg_read(s
, s
->reg
);
836 if (s
->swallow
-- > 0)
844 void s1d13745_write(void *opaque
, int dc
, uint16_t value
)
846 BlizzardState
*s
= (BlizzardState
*) opaque
;
848 if (s
->swallow
-- > 0)
851 blizzard_reg_write(s
, s
->reg
, value
);
853 if (s
->reg
!= 0x90 && s
->reg
!= 0x5a && s
->reg
!= 0xb8)
856 s
->reg
= value
& 0xff;
859 void s1d13745_write_block(void *opaque
, int dc
,
860 void *buf
, size_t len
, int pitch
)
862 BlizzardState
*s
= (BlizzardState
*) opaque
;
865 if (s
->reg
== 0x90 && dc
&&
866 (s
->data
.len
|| blizzard_transfer_setup(s
)) &&
867 len
>= (s
->data
.len
<< 1)) {
868 len
-= s
->data
.len
<< 1;
872 s
->data
.pitch
= pitch
;
874 s
->data
.data
= s
->data
.buf
;
878 s1d13745_write(opaque
, dc
, *(uint16_t *) buf
);
886 static void blizzard_update_display(void *opaque
)
888 BlizzardState
*s
= (BlizzardState
*) opaque
;
889 int y
, bypp
, bypl
, bwidth
;
895 if (s
->x
!= ds_get_width(s
->state
) || s
->y
!= ds_get_height(s
->state
)) {
897 qemu_console_resize(s
->state
, s
->x
, s
->y
);
904 bypp
= (ds_get_bits_per_pixel(s
->state
) + 7) >> 3;
905 memset(ds_get_data(s
->state
), 0, bypp
* s
->x
* s
->y
);
915 if (s
->mx
[1] <= s
->mx
[0])
918 bypp
= (ds_get_bits_per_pixel(s
->state
) + 7) >> 3;
920 bwidth
= bypp
* (s
->mx
[1] - s
->mx
[0]);
922 src
= s
->fb
+ bypl
* y
+ bypp
* s
->mx
[0];
923 dst
= ds_get_data(s
->state
) + bypl
* y
+ bypp
* s
->mx
[0];
924 for (; y
< s
->my
[1]; y
++, src
+= bypl
, dst
+= bypl
)
925 memcpy(dst
, src
, bwidth
);
927 dpy_update(s
->state
, s
->mx
[0], s
->my
[0],
928 s
->mx
[1] - s
->mx
[0], y
- s
->my
[0]);
936 static void blizzard_screen_dump(void *opaque
, const char *filename
) {
937 BlizzardState
*s
= (BlizzardState
*) opaque
;
939 blizzard_update_display(opaque
);
940 if (s
&& ds_get_data(s
->state
))
941 ppm_save(filename
, s
->state
->surface
);
945 #include "blizzard_template.h"
947 #include "blizzard_template.h"
949 #include "blizzard_template.h"
951 #include "blizzard_template.h"
953 #include "blizzard_template.h"
955 void *s1d13745_init(qemu_irq gpio_int
)
957 BlizzardState
*s
= (BlizzardState
*) qemu_mallocz(sizeof(*s
));
959 s
->fb
= qemu_malloc(0x180000);
961 s
->state
= graphic_console_init(blizzard_update_display
,
962 blizzard_invalidate_display
,
963 blizzard_screen_dump
, NULL
, s
);
965 switch (ds_get_bits_per_pixel(s
->state
)) {
967 s
->line_fn_tab
[0] = s
->line_fn_tab
[1] =
968 qemu_mallocz(sizeof(blizzard_fn_t
) * 0x10);
971 s
->line_fn_tab
[0] = blizzard_draw_fn_8
;
972 s
->line_fn_tab
[1] = blizzard_draw_fn_r_8
;
975 s
->line_fn_tab
[0] = blizzard_draw_fn_15
;
976 s
->line_fn_tab
[1] = blizzard_draw_fn_r_15
;
979 s
->line_fn_tab
[0] = blizzard_draw_fn_16
;
980 s
->line_fn_tab
[1] = blizzard_draw_fn_r_16
;
983 s
->line_fn_tab
[0] = blizzard_draw_fn_24
;
984 s
->line_fn_tab
[1] = blizzard_draw_fn_r_24
;
987 s
->line_fn_tab
[0] = blizzard_draw_fn_32
;
988 s
->line_fn_tab
[1] = blizzard_draw_fn_r_32
;
991 fprintf(stderr
, "%s: Bad color depth\n", __FUNCTION__
);