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"
22 #include "ui/console.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 inline void blizzard_rgb2yuv(int r
, int g
, int b
,
138 int *y
, int *u
, int *v
)
140 *y
= 0x10 + ((0x838 * r
+ 0x1022 * g
+ 0x322 * b
) >> 13);
141 *u
= 0x80 + ((0xe0e * b
- 0x04c1 * r
- 0x94e * g
) >> 13);
142 *v
= 0x80 + ((0xe0e * r
- 0x0bc7 * g
- 0x247 * b
) >> 13);
145 static void blizzard_window(BlizzardState
*s
)
151 blizzard_fn_t fn
= s
->data
.line_fn
;
155 if (s
->mx
[0] > s
->data
.x
)
156 s
->mx
[0] = s
->data
.x
;
157 if (s
->my
[0] > s
->data
.y
)
158 s
->my
[0] = s
->data
.y
;
159 if (s
->mx
[1] < s
->data
.x
+ s
->data
.dx
)
160 s
->mx
[1] = s
->data
.x
+ s
->data
.dx
;
161 if (s
->my
[1] < s
->data
.y
+ s
->data
.dy
)
162 s
->my
[1] = s
->data
.y
+ s
->data
.dy
;
165 bypp
[1] = (ds_get_bits_per_pixel(s
->state
) + 7) >> 3;
166 bypl
[0] = bypp
[0] * s
->data
.pitch
;
167 bypl
[1] = bypp
[1] * s
->x
;
168 bypl
[2] = bypp
[0] * s
->data
.dx
;
171 dst
= s
->fb
+ bypl
[1] * s
->data
.y
+ bypp
[1] * s
->data
.x
;
172 for (y
= s
->data
.dy
; y
> 0; y
--, src
+= bypl
[0], dst
+= bypl
[1])
173 fn(dst
, src
, bypl
[2]);
176 static int blizzard_transfer_setup(BlizzardState
*s
)
178 if (s
->source
> 3 || !s
->bpp
||
179 s
->ix
[1] < s
->ix
[0] || s
->iy
[1] < s
->iy
[0])
182 s
->data
.angle
= s
->effect
& 3;
183 s
->data
.line_fn
= s
->line_fn_tab
[!!s
->data
.angle
][s
->iformat
];
184 s
->data
.x
= s
->ix
[0];
185 s
->data
.y
= s
->iy
[0];
186 s
->data
.dx
= s
->ix
[1] - s
->ix
[0] + 1;
187 s
->data
.dy
= s
->iy
[1] - s
->iy
[0] + 1;
188 s
->data
.len
= s
->bpp
* s
->data
.dx
* s
->data
.dy
;
189 s
->data
.pitch
= s
->data
.dx
;
190 if (s
->data
.len
> s
->data
.buflen
) {
191 s
->data
.buf
= g_realloc(s
->data
.buf
, s
->data
.len
);
192 s
->data
.buflen
= s
->data
.len
;
194 s
->data
.ptr
= s
->data
.buf
;
195 s
->data
.data
= s
->data
.buf
;
200 static void blizzard_reset(BlizzardState
*s
)
211 s
->memrefresh
= 0x25c;
217 s
->lcd_config
= 0x74;
244 s
->bpp
= blizzard_iformat_bpp
[s
->iformat
];
246 s
->hssi_config
[0] = 0x00;
247 s
->hssi_config
[1] = 0x00;
248 s
->hssi_config
[2] = 0x01;
250 s
->tv_timing
[0] = 0x00;
251 s
->tv_timing
[1] = 0x00;
252 s
->tv_timing
[2] = 0x00;
253 s
->tv_timing
[3] = 0x00;
258 s
->tv_filter_config
= 0x80;
259 s
->tv_filter_idx
= 0x00;
263 s
->gamma_config
= 0x00;
265 s
->matrix_ena
= 0x00;
266 memset(&s
->matrix_coeff
, 0, sizeof(s
->matrix_coeff
));
272 s
->rgbgpio_dir
= 0x00;
274 s
->gpio_edge
[0] = 0x00;
275 s
->gpio_edge
[1] = 0x00;
277 s
->gpio_pdown
= 0xff;
280 static inline void blizzard_invalidate_display(void *opaque
) {
281 BlizzardState
*s
= (BlizzardState
*) opaque
;
286 static uint16_t blizzard_reg_read(void *opaque
, uint8_t reg
)
288 BlizzardState
*s
= (BlizzardState
*) opaque
;
291 case 0x00: /* Revision Code */
294 case 0x02: /* Configuration Readback */
295 return 0x83; /* Macrovision OK, CNF[2:0] = 3 */
297 case 0x04: /* PLL M-Divider */
298 return (s
->pll
- 1) | (1 << 7);
299 case 0x06: /* PLL Lock Range Control */
301 case 0x08: /* PLL Lock Synthesis Control 0 */
302 return s
->pll_ctrl
& 0xff;
303 case 0x0a: /* PLL Lock Synthesis Control 1 */
304 return s
->pll_ctrl
>> 8;
305 case 0x0c: /* PLL Mode Control 0 */
308 case 0x0e: /* Clock-Source Select */
311 case 0x10: /* Memory Controller Activate */
312 case 0x14: /* Memory Controller Bank 0 Status Flag */
315 case 0x18: /* Auto-Refresh Interval Setting 0 */
316 return s
->memrefresh
& 0xff;
317 case 0x1a: /* Auto-Refresh Interval Setting 1 */
318 return s
->memrefresh
>> 8;
320 case 0x1c: /* Power-On Sequence Timing Control */
322 case 0x1e: /* Timing Control 0 */
324 case 0x20: /* Timing Control 1 */
327 case 0x24: /* Arbitration Priority Control */
330 case 0x28: /* LCD Panel Configuration */
331 return s
->lcd_config
;
333 case 0x2a: /* LCD Horizontal Display Width */
335 case 0x2c: /* LCD Horizontal Non-display Period */
337 case 0x2e: /* LCD Vertical Display Height 0 */
339 case 0x30: /* LCD Vertical Display Height 1 */
341 case 0x32: /* LCD Vertical Non-display Period */
343 case 0x34: /* LCD HS Pulse-width */
345 case 0x36: /* LCd HS Pulse Start Position */
346 return s
->skipx
>> 3;
347 case 0x38: /* LCD VS Pulse-width */
349 case 0x3a: /* LCD VS Pulse Start Position */
352 case 0x3c: /* PCLK Polarity */
355 case 0x3e: /* High-speed Serial Interface Tx Configuration Port 0 */
356 return s
->hssi_config
[0];
357 case 0x40: /* High-speed Serial Interface Tx Configuration Port 1 */
358 return s
->hssi_config
[1];
359 case 0x42: /* High-speed Serial Interface Tx Mode */
360 return s
->hssi_config
[2];
361 case 0x44: /* TV Display Configuration */
363 case 0x46 ... 0x4c: /* TV Vertical Blanking Interval Data bits */
364 return s
->tv_timing
[(reg
- 0x46) >> 1];
365 case 0x4e: /* VBI: Closed Caption / XDS Control / Status */
367 case 0x50: /* TV Horizontal Start Position */
369 case 0x52: /* TV Vertical Start Position */
371 case 0x54: /* TV Test Pattern Setting */
373 case 0x56: /* TV Filter Setting */
374 return s
->tv_filter_config
;
375 case 0x58: /* TV Filter Coefficient Index */
376 return s
->tv_filter_idx
;
377 case 0x5a: /* TV Filter Coefficient Data */
378 if (s
->tv_filter_idx
< 0x20)
379 return s
->tv_filter_coeff
[s
->tv_filter_idx
++];
382 case 0x60: /* Input YUV/RGB Translate Mode 0 */
384 case 0x62: /* Input YUV/RGB Translate Mode 1 */
386 case 0x64: /* U Data Fix */
388 case 0x66: /* V Data Fix */
391 case 0x68: /* Display Mode */
394 case 0x6a: /* Special Effects */
397 case 0x6c: /* Input Window X Start Position 0 */
398 return s
->ix
[0] & 0xff;
399 case 0x6e: /* Input Window X Start Position 1 */
400 return s
->ix
[0] >> 3;
401 case 0x70: /* Input Window Y Start Position 0 */
402 return s
->ix
[0] & 0xff;
403 case 0x72: /* Input Window Y Start Position 1 */
404 return s
->ix
[0] >> 3;
405 case 0x74: /* Input Window X End Position 0 */
406 return s
->ix
[1] & 0xff;
407 case 0x76: /* Input Window X End Position 1 */
408 return s
->ix
[1] >> 3;
409 case 0x78: /* Input Window Y End Position 0 */
410 return s
->ix
[1] & 0xff;
411 case 0x7a: /* Input Window Y End Position 1 */
412 return s
->ix
[1] >> 3;
413 case 0x7c: /* Output Window X Start Position 0 */
414 return s
->ox
[0] & 0xff;
415 case 0x7e: /* Output Window X Start Position 1 */
416 return s
->ox
[0] >> 3;
417 case 0x80: /* Output Window Y Start Position 0 */
418 return s
->oy
[0] & 0xff;
419 case 0x82: /* Output Window Y Start Position 1 */
420 return s
->oy
[0] >> 3;
421 case 0x84: /* Output Window X End Position 0 */
422 return s
->ox
[1] & 0xff;
423 case 0x86: /* Output Window X End Position 1 */
424 return s
->ox
[1] >> 3;
425 case 0x88: /* Output Window Y End Position 0 */
426 return s
->oy
[1] & 0xff;
427 case 0x8a: /* Output Window Y End Position 1 */
428 return s
->oy
[1] >> 3;
430 case 0x8c: /* Input Data Format */
432 case 0x8e: /* Data Source Select */
434 case 0x90: /* Display Memory Data Port */
437 case 0xa8: /* Border Color 0 */
439 case 0xaa: /* Border Color 1 */
441 case 0xac: /* Border Color 2 */
444 case 0xb4: /* Gamma Correction Enable */
445 return s
->gamma_config
;
446 case 0xb6: /* Gamma Correction Table Index */
448 case 0xb8: /* Gamma Correction Table Data */
449 return s
->gamma_lut
[s
->gamma_idx
++];
451 case 0xba: /* 3x3 Matrix Enable */
452 return s
->matrix_ena
;
453 case 0xbc ... 0xde: /* Coefficient Registers */
454 return s
->matrix_coeff
[(reg
- 0xbc) >> 1];
455 case 0xe0: /* 3x3 Matrix Red Offset */
457 case 0xe2: /* 3x3 Matrix Green Offset */
459 case 0xe4: /* 3x3 Matrix Blue Offset */
462 case 0xe6: /* Power-save */
464 case 0xe8: /* Non-display Period Control / Status */
465 return s
->status
| (1 << 5);
466 case 0xea: /* RGB Interface Control */
467 return s
->rgbgpio_dir
;
468 case 0xec: /* RGB Interface Status */
470 case 0xee: /* General-purpose IO Pins Configuration */
472 case 0xf0: /* General-purpose IO Pins Status / Control */
474 case 0xf2: /* GPIO Positive Edge Interrupt Trigger */
475 return s
->gpio_edge
[0];
476 case 0xf4: /* GPIO Negative Edge Interrupt Trigger */
477 return s
->gpio_edge
[1];
478 case 0xf6: /* GPIO Interrupt Status */
480 case 0xf8: /* GPIO Pull-down Control */
481 return s
->gpio_pdown
;
484 fprintf(stderr
, "%s: unknown register %02x\n", __FUNCTION__
, reg
);
489 static void blizzard_reg_write(void *opaque
, uint8_t reg
, uint16_t value
)
491 BlizzardState
*s
= (BlizzardState
*) opaque
;
494 case 0x04: /* PLL M-Divider */
495 s
->pll
= (value
& 0x3f) + 1;
497 case 0x06: /* PLL Lock Range Control */
498 s
->pll_range
= value
& 3;
500 case 0x08: /* PLL Lock Synthesis Control 0 */
501 s
->pll_ctrl
&= 0xf00;
502 s
->pll_ctrl
|= (value
<< 0) & 0x0ff;
504 case 0x0a: /* PLL Lock Synthesis Control 1 */
505 s
->pll_ctrl
&= 0x0ff;
506 s
->pll_ctrl
|= (value
<< 8) & 0xf00;
508 case 0x0c: /* PLL Mode Control 0 */
509 s
->pll_mode
= value
& 0x77;
510 if ((value
& 3) == 0 || (value
& 3) == 3)
511 fprintf(stderr
, "%s: wrong PLL Control bits (%i)\n",
512 __FUNCTION__
, value
& 3);
515 case 0x0e: /* Clock-Source Select */
516 s
->clksel
= value
& 0xff;
519 case 0x10: /* Memory Controller Activate */
520 s
->memenable
= value
& 1;
522 case 0x14: /* Memory Controller Bank 0 Status Flag */
525 case 0x18: /* Auto-Refresh Interval Setting 0 */
526 s
->memrefresh
&= 0xf00;
527 s
->memrefresh
|= (value
<< 0) & 0x0ff;
529 case 0x1a: /* Auto-Refresh Interval Setting 1 */
530 s
->memrefresh
&= 0x0ff;
531 s
->memrefresh
|= (value
<< 8) & 0xf00;
534 case 0x1c: /* Power-On Sequence Timing Control */
535 s
->timing
[0] = value
& 0x7f;
537 case 0x1e: /* Timing Control 0 */
538 s
->timing
[1] = value
& 0x17;
540 case 0x20: /* Timing Control 1 */
541 s
->timing
[2] = value
& 0x35;
544 case 0x24: /* Arbitration Priority Control */
545 s
->priority
= value
& 1;
548 case 0x28: /* LCD Panel Configuration */
549 s
->lcd_config
= value
& 0xff;
550 if (value
& (1 << 7))
551 fprintf(stderr
, "%s: data swap not supported!\n", __FUNCTION__
);
554 case 0x2a: /* LCD Horizontal Display Width */
557 case 0x2c: /* LCD Horizontal Non-display Period */
558 s
->hndp
= value
& 0xff;
560 case 0x2e: /* LCD Vertical Display Height 0 */
562 s
->y
|= (value
<< 0) & 0x0ff;
564 case 0x30: /* LCD Vertical Display Height 1 */
566 s
->y
|= (value
<< 8) & 0x300;
568 case 0x32: /* LCD Vertical Non-display Period */
569 s
->vndp
= value
& 0xff;
571 case 0x34: /* LCD HS Pulse-width */
572 s
->hsync
= value
& 0xff;
574 case 0x36: /* LCD HS Pulse Start Position */
575 s
->skipx
= value
& 0xff;
577 case 0x38: /* LCD VS Pulse-width */
578 s
->vsync
= value
& 0xbf;
580 case 0x3a: /* LCD VS Pulse Start Position */
581 s
->skipy
= value
& 0xff;
584 case 0x3c: /* PCLK Polarity */
585 s
->pclk
= value
& 0x82;
586 /* Affects calculation of s->hndp, s->hsync and s->skipx. */
589 case 0x3e: /* High-speed Serial Interface Tx Configuration Port 0 */
590 s
->hssi_config
[0] = value
;
592 case 0x40: /* High-speed Serial Interface Tx Configuration Port 1 */
593 s
->hssi_config
[1] = value
;
594 if (((value
>> 4) & 3) == 3)
595 fprintf(stderr
, "%s: Illegal active-data-links value\n",
598 case 0x42: /* High-speed Serial Interface Tx Mode */
599 s
->hssi_config
[2] = value
& 0xbd;
602 case 0x44: /* TV Display Configuration */
603 s
->tv_config
= value
& 0xfe;
605 case 0x46 ... 0x4c: /* TV Vertical Blanking Interval Data bits 0 */
606 s
->tv_timing
[(reg
- 0x46) >> 1] = value
;
608 case 0x4e: /* VBI: Closed Caption / XDS Control / Status */
611 case 0x50: /* TV Horizontal Start Position */
614 case 0x52: /* TV Vertical Start Position */
615 s
->tv_y
= value
& 0x7f;
617 case 0x54: /* TV Test Pattern Setting */
620 case 0x56: /* TV Filter Setting */
621 s
->tv_filter_config
= value
& 0xbf;
623 case 0x58: /* TV Filter Coefficient Index */
624 s
->tv_filter_idx
= value
& 0x1f;
626 case 0x5a: /* TV Filter Coefficient Data */
627 if (s
->tv_filter_idx
< 0x20)
628 s
->tv_filter_coeff
[s
->tv_filter_idx
++] = value
;
631 case 0x60: /* Input YUV/RGB Translate Mode 0 */
632 s
->yrc
[0] = value
& 0xb0;
634 case 0x62: /* Input YUV/RGB Translate Mode 1 */
635 s
->yrc
[1] = value
& 0x30;
637 case 0x64: /* U Data Fix */
640 case 0x66: /* V Data Fix */
644 case 0x68: /* Display Mode */
645 if ((s
->mode
^ value
) & 3)
647 s
->mode
= value
& 0xb7;
648 s
->enable
= value
& 1;
649 s
->blank
= (value
>> 1) & 1;
650 if (value
& (1 << 4))
651 fprintf(stderr
, "%s: Macrovision enable attempt!\n", __FUNCTION__
);
654 case 0x6a: /* Special Effects */
655 s
->effect
= value
& 0xfb;
658 case 0x6c: /* Input Window X Start Position 0 */
660 s
->ix
[0] |= (value
<< 0) & 0x0ff;
662 case 0x6e: /* Input Window X Start Position 1 */
664 s
->ix
[0] |= (value
<< 8) & 0x300;
666 case 0x70: /* Input Window Y Start Position 0 */
668 s
->iy
[0] |= (value
<< 0) & 0x0ff;
670 case 0x72: /* Input Window Y Start Position 1 */
672 s
->iy
[0] |= (value
<< 8) & 0x300;
674 case 0x74: /* Input Window X End Position 0 */
676 s
->ix
[1] |= (value
<< 0) & 0x0ff;
678 case 0x76: /* Input Window X End Position 1 */
680 s
->ix
[1] |= (value
<< 8) & 0x300;
682 case 0x78: /* Input Window Y End Position 0 */
684 s
->iy
[1] |= (value
<< 0) & 0x0ff;
686 case 0x7a: /* Input Window Y End Position 1 */
688 s
->iy
[1] |= (value
<< 8) & 0x300;
690 case 0x7c: /* Output Window X Start Position 0 */
692 s
->ox
[0] |= (value
<< 0) & 0x0ff;
694 case 0x7e: /* Output Window X Start Position 1 */
696 s
->ox
[0] |= (value
<< 8) & 0x300;
698 case 0x80: /* Output Window Y Start Position 0 */
700 s
->oy
[0] |= (value
<< 0) & 0x0ff;
702 case 0x82: /* Output Window Y Start Position 1 */
704 s
->oy
[0] |= (value
<< 8) & 0x300;
706 case 0x84: /* Output Window X End Position 0 */
708 s
->ox
[1] |= (value
<< 0) & 0x0ff;
710 case 0x86: /* Output Window X End Position 1 */
712 s
->ox
[1] |= (value
<< 8) & 0x300;
714 case 0x88: /* Output Window Y End Position 0 */
716 s
->oy
[1] |= (value
<< 0) & 0x0ff;
718 case 0x8a: /* Output Window Y End Position 1 */
720 s
->oy
[1] |= (value
<< 8) & 0x300;
723 case 0x8c: /* Input Data Format */
724 s
->iformat
= value
& 0xf;
725 s
->bpp
= blizzard_iformat_bpp
[s
->iformat
];
727 fprintf(stderr
, "%s: Illegal or unsupported input format %x\n",
728 __FUNCTION__
, s
->iformat
);
730 case 0x8e: /* Data Source Select */
731 s
->source
= value
& 7;
732 /* Currently all windows will be "destructive overlays". */
733 if ((!(s
->effect
& (1 << 3)) && (s
->ix
[0] != s
->ox
[0] ||
734 s
->iy
[0] != s
->oy
[0] ||
735 s
->ix
[1] != s
->ox
[1] ||
736 s
->iy
[1] != s
->oy
[1])) ||
737 !((s
->ix
[1] - s
->ix
[0]) & (s
->iy
[1] - s
->iy
[0]) &
738 (s
->ox
[1] - s
->ox
[0]) & (s
->oy
[1] - s
->oy
[0]) & 1))
739 fprintf(stderr
, "%s: Illegal input/output window positions\n",
742 blizzard_transfer_setup(s
);
745 case 0x90: /* Display Memory Data Port */
746 if (!s
->data
.len
&& !blizzard_transfer_setup(s
))
749 *s
->data
.ptr
++ = value
;
750 if (-- s
->data
.len
== 0)
754 case 0xa8: /* Border Color 0 */
757 case 0xaa: /* Border Color 1 */
760 case 0xac: /* Border Color 2 */
764 case 0xb4: /* Gamma Correction Enable */
765 s
->gamma_config
= value
& 0x87;
767 case 0xb6: /* Gamma Correction Table Index */
768 s
->gamma_idx
= value
;
770 case 0xb8: /* Gamma Correction Table Data */
771 s
->gamma_lut
[s
->gamma_idx
++] = value
;
774 case 0xba: /* 3x3 Matrix Enable */
775 s
->matrix_ena
= value
& 1;
777 case 0xbc ... 0xde: /* Coefficient Registers */
778 s
->matrix_coeff
[(reg
- 0xbc) >> 1] = value
& ((reg
& 2) ? 0x80 : 0xff);
780 case 0xe0: /* 3x3 Matrix Red Offset */
783 case 0xe2: /* 3x3 Matrix Green Offset */
786 case 0xe4: /* 3x3 Matrix Blue Offset */
790 case 0xe6: /* Power-save */
791 s
->pm
= value
& 0x83;
792 if (value
& s
->mode
& 1)
793 fprintf(stderr
, "%s: The display must be disabled before entering "
794 "Standby Mode\n", __FUNCTION__
);
796 case 0xe8: /* Non-display Period Control / Status */
797 s
->status
= value
& 0x1b;
799 case 0xea: /* RGB Interface Control */
800 s
->rgbgpio_dir
= value
& 0x8f;
802 case 0xec: /* RGB Interface Status */
803 s
->rgbgpio
= value
& 0xcf;
805 case 0xee: /* General-purpose IO Pins Configuration */
808 case 0xf0: /* General-purpose IO Pins Status / Control */
811 case 0xf2: /* GPIO Positive Edge Interrupt Trigger */
812 s
->gpio_edge
[0] = value
;
814 case 0xf4: /* GPIO Negative Edge Interrupt Trigger */
815 s
->gpio_edge
[1] = value
;
817 case 0xf6: /* GPIO Interrupt Status */
818 s
->gpio_irq
&= value
;
820 case 0xf8: /* GPIO Pull-down Control */
821 s
->gpio_pdown
= value
;
825 fprintf(stderr
, "%s: unknown register %02x\n", __FUNCTION__
, reg
);
830 uint16_t s1d13745_read(void *opaque
, int dc
)
832 BlizzardState
*s
= (BlizzardState
*) opaque
;
833 uint16_t value
= blizzard_reg_read(s
, s
->reg
);
835 if (s
->swallow
-- > 0)
843 void s1d13745_write(void *opaque
, int dc
, uint16_t value
)
845 BlizzardState
*s
= (BlizzardState
*) opaque
;
847 if (s
->swallow
-- > 0)
850 blizzard_reg_write(s
, s
->reg
, value
);
852 if (s
->reg
!= 0x90 && s
->reg
!= 0x5a && s
->reg
!= 0xb8)
855 s
->reg
= value
& 0xff;
858 void s1d13745_write_block(void *opaque
, int dc
,
859 void *buf
, size_t len
, int pitch
)
861 BlizzardState
*s
= (BlizzardState
*) opaque
;
864 if (s
->reg
== 0x90 && dc
&&
865 (s
->data
.len
|| blizzard_transfer_setup(s
)) &&
866 len
>= (s
->data
.len
<< 1)) {
867 len
-= s
->data
.len
<< 1;
871 s
->data
.pitch
= pitch
;
873 s
->data
.data
= s
->data
.buf
;
877 s1d13745_write(opaque
, dc
, *(uint16_t *) buf
);
883 static void blizzard_update_display(void *opaque
)
885 BlizzardState
*s
= (BlizzardState
*) opaque
;
886 int y
, bypp
, bypl
, bwidth
;
892 if (s
->x
!= ds_get_width(s
->state
) || s
->y
!= ds_get_height(s
->state
)) {
894 qemu_console_resize(s
->state
, s
->x
, s
->y
);
901 bypp
= (ds_get_bits_per_pixel(s
->state
) + 7) >> 3;
902 memset(ds_get_data(s
->state
), 0, bypp
* s
->x
* s
->y
);
912 if (s
->mx
[1] <= s
->mx
[0])
915 bypp
= (ds_get_bits_per_pixel(s
->state
) + 7) >> 3;
917 bwidth
= bypp
* (s
->mx
[1] - s
->mx
[0]);
919 src
= s
->fb
+ bypl
* y
+ bypp
* s
->mx
[0];
920 dst
= ds_get_data(s
->state
) + bypl
* y
+ bypp
* s
->mx
[0];
921 for (; y
< s
->my
[1]; y
++, src
+= bypl
, dst
+= bypl
)
922 memcpy(dst
, src
, bwidth
);
924 dpy_gfx_update(s
->state
, s
->mx
[0], s
->my
[0],
925 s
->mx
[1] - s
->mx
[0], y
- s
->my
[0]);
933 static void blizzard_screen_dump(void *opaque
, const char *filename
,
934 bool cswitch
, Error
**errp
)
936 BlizzardState
*s
= (BlizzardState
*) opaque
;
938 blizzard_update_display(opaque
);
939 if (s
&& ds_get_data(s
->state
))
940 ppm_save(filename
, s
->state
->surface
, errp
);
944 #include "blizzard_template.h"
946 #include "blizzard_template.h"
948 #include "blizzard_template.h"
950 #include "blizzard_template.h"
952 #include "blizzard_template.h"
954 void *s1d13745_init(qemu_irq gpio_int
)
956 BlizzardState
*s
= (BlizzardState
*) g_malloc0(sizeof(*s
));
958 s
->fb
= g_malloc(0x180000);
960 s
->state
= graphic_console_init(blizzard_update_display
,
961 blizzard_invalidate_display
,
962 blizzard_screen_dump
, NULL
, s
);
964 switch (ds_get_bits_per_pixel(s
->state
)) {
966 s
->line_fn_tab
[0] = s
->line_fn_tab
[1] =
967 g_malloc0(sizeof(blizzard_fn_t
) * 0x10);
970 s
->line_fn_tab
[0] = blizzard_draw_fn_8
;
971 s
->line_fn_tab
[1] = blizzard_draw_fn_r_8
;
974 s
->line_fn_tab
[0] = blizzard_draw_fn_15
;
975 s
->line_fn_tab
[1] = blizzard_draw_fn_r_15
;
978 s
->line_fn_tab
[0] = blizzard_draw_fn_16
;
979 s
->line_fn_tab
[1] = blizzard_draw_fn_r_16
;
982 s
->line_fn_tab
[0] = blizzard_draw_fn_24
;
983 s
->line_fn_tab
[1] = blizzard_draw_fn_r_24
;
986 s
->line_fn_tab
[0] = blizzard_draw_fn_32
;
987 s
->line_fn_tab
[1] = blizzard_draw_fn_r_32
;
990 fprintf(stderr
, "%s: Bad color depth\n", __FUNCTION__
);