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
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
23 #include "qemu-common.h"
28 #include "pixel_ops.h"
30 typedef void (*blizzard_fn_t
)(uint8_t *, const uint8_t *, unsigned int);
77 blizzard_fn_t
*line_fn_tab
[2];
80 uint8_t hssi_config
[3];
87 uint8_t tv_filter_config
;
88 uint8_t tv_filter_idx
;
89 uint8_t tv_filter_coeff
[0x20];
95 uint8_t gamma_lut
[0x100];
97 uint8_t matrix_coeff
[0x12];
107 uint8_t gpio_edge
[2];
123 blizzard_fn_t line_fn
;
127 /* Bytes(!) per pixel */
128 static const int blizzard_iformat_bpp
[0x10] = {
131 3, /* RGB 6:6:6 mode 1 */
132 3, /* RGB 8:8:8 mode 1 */
134 4, /* RGB 6:6:6 mode 2 */
135 4, /* RGB 8:8:8 mode 2 */
141 static inline void blizzard_rgb2yuv(int r
, int g
, int b
,
142 int *y
, int *u
, int *v
)
144 *y
= 0x10 + ((0x838 * r
+ 0x1022 * g
+ 0x322 * b
) >> 13);
145 *u
= 0x80 + ((0xe0e * b
- 0x04c1 * r
- 0x94e * g
) >> 13);
146 *v
= 0x80 + ((0xe0e * r
- 0x0bc7 * g
- 0x247 * b
) >> 13);
149 static void blizzard_window(struct blizzard_s
*s
)
155 blizzard_fn_t fn
= s
->data
.line_fn
;
159 if (s
->mx
[0] > s
->data
.x
)
160 s
->mx
[0] = s
->data
.x
;
161 if (s
->my
[0] > s
->data
.y
)
162 s
->my
[0] = s
->data
.y
;
163 if (s
->mx
[1] < s
->data
.x
+ s
->data
.dx
)
164 s
->mx
[1] = s
->data
.x
+ s
->data
.dx
;
165 if (s
->my
[1] < s
->data
.y
+ s
->data
.dy
)
166 s
->my
[1] = s
->data
.y
+ s
->data
.dy
;
169 bypp
[1] = (ds_get_bits_per_pixel(s
->state
) + 7) >> 3;
170 bypl
[0] = bypp
[0] * s
->data
.pitch
;
171 bypl
[1] = bypp
[1] * s
->x
;
172 bypl
[2] = bypp
[0] * s
->data
.dx
;
175 dst
= s
->fb
+ bypl
[1] * s
->data
.y
+ bypp
[1] * s
->data
.x
;
176 for (y
= s
->data
.dy
; y
> 0; y
--, src
+= bypl
[0], dst
+= bypl
[1])
177 fn(dst
, src
, bypl
[2]);
180 static int blizzard_transfer_setup(struct blizzard_s
*s
)
182 if (s
->source
> 3 || !s
->bpp
||
183 s
->ix
[1] < s
->ix
[0] || s
->iy
[1] < s
->iy
[0])
186 s
->data
.angle
= s
->effect
& 3;
187 s
->data
.line_fn
= s
->line_fn_tab
[!!s
->data
.angle
][s
->iformat
];
188 s
->data
.x
= s
->ix
[0];
189 s
->data
.y
= s
->iy
[0];
190 s
->data
.dx
= s
->ix
[1] - s
->ix
[0] + 1;
191 s
->data
.dy
= s
->iy
[1] - s
->iy
[0] + 1;
192 s
->data
.len
= s
->bpp
* s
->data
.dx
* s
->data
.dy
;
193 s
->data
.pitch
= s
->data
.dx
;
194 if (s
->data
.len
> s
->data
.buflen
) {
195 s
->data
.buf
= qemu_realloc(s
->data
.buf
, s
->data
.len
);
196 s
->data
.buflen
= s
->data
.len
;
198 s
->data
.ptr
= s
->data
.buf
;
199 s
->data
.data
= s
->data
.buf
;
204 static void blizzard_reset(struct blizzard_s
*s
)
215 s
->memrefresh
= 0x25c;
221 s
->lcd_config
= 0x74;
248 s
->bpp
= blizzard_iformat_bpp
[s
->iformat
];
250 s
->hssi_config
[0] = 0x00;
251 s
->hssi_config
[1] = 0x00;
252 s
->hssi_config
[2] = 0x01;
254 s
->tv_timing
[0] = 0x00;
255 s
->tv_timing
[1] = 0x00;
256 s
->tv_timing
[2] = 0x00;
257 s
->tv_timing
[3] = 0x00;
262 s
->tv_filter_config
= 0x80;
263 s
->tv_filter_idx
= 0x00;
267 s
->gamma_config
= 0x00;
269 s
->matrix_ena
= 0x00;
270 memset(&s
->matrix_coeff
, 0, sizeof(s
->matrix_coeff
));
276 s
->rgbgpio_dir
= 0x00;
278 s
->gpio_edge
[0] = 0x00;
279 s
->gpio_edge
[1] = 0x00;
281 s
->gpio_pdown
= 0xff;
284 static inline void blizzard_invalidate_display(void *opaque
) {
285 struct blizzard_s
*s
= (struct blizzard_s
*) opaque
;
290 static uint16_t blizzard_reg_read(void *opaque
, uint8_t reg
)
292 struct blizzard_s
*s
= (struct blizzard_s
*) opaque
;
295 case 0x00: /* Revision Code */
298 case 0x02: /* Configuration Readback */
299 return 0x83; /* Macrovision OK, CNF[2:0] = 3 */
301 case 0x04: /* PLL M-Divider */
302 return (s
->pll
- 1) | (1 << 7);
303 case 0x06: /* PLL Lock Range Control */
305 case 0x08: /* PLL Lock Synthesis Control 0 */
306 return s
->pll_ctrl
& 0xff;
307 case 0x0a: /* PLL Lock Synthesis Control 1 */
308 return s
->pll_ctrl
>> 8;
309 case 0x0c: /* PLL Mode Control 0 */
312 case 0x0e: /* Clock-Source Select */
315 case 0x10: /* Memory Controller Activate */
316 case 0x14: /* Memory Controller Bank 0 Status Flag */
319 case 0x18: /* Auto-Refresh Interval Setting 0 */
320 return s
->memrefresh
& 0xff;
321 case 0x1a: /* Auto-Refresh Interval Setting 1 */
322 return s
->memrefresh
>> 8;
324 case 0x1c: /* Power-On Sequence Timing Control */
326 case 0x1e: /* Timing Control 0 */
328 case 0x20: /* Timing Control 1 */
331 case 0x24: /* Arbitration Priority Control */
334 case 0x28: /* LCD Panel Configuration */
335 return s
->lcd_config
;
337 case 0x2a: /* LCD Horizontal Display Width */
339 case 0x2c: /* LCD Horizontal Non-display Period */
341 case 0x2e: /* LCD Vertical Display Height 0 */
343 case 0x30: /* LCD Vertical Display Height 1 */
345 case 0x32: /* LCD Vertical Non-display Period */
347 case 0x34: /* LCD HS Pulse-width */
349 case 0x36: /* LCd HS Pulse Start Position */
350 return s
->skipx
>> 3;
351 case 0x38: /* LCD VS Pulse-width */
353 case 0x3a: /* LCD VS Pulse Start Position */
356 case 0x3c: /* PCLK Polarity */
359 case 0x3e: /* High-speed Serial Interface Tx Configuration Port 0 */
360 return s
->hssi_config
[0];
361 case 0x40: /* High-speed Serial Interface Tx Configuration Port 1 */
362 return s
->hssi_config
[1];
363 case 0x42: /* High-speed Serial Interface Tx Mode */
364 return s
->hssi_config
[2];
365 case 0x44: /* TV Display Configuration */
367 case 0x46 ... 0x4c: /* TV Vertical Blanking Interval Data bits */
368 return s
->tv_timing
[(reg
- 0x46) >> 1];
369 case 0x4e: /* VBI: Closed Caption / XDS Control / Status */
371 case 0x50: /* TV Horizontal Start Position */
373 case 0x52: /* TV Vertical Start Position */
375 case 0x54: /* TV Test Pattern Setting */
377 case 0x56: /* TV Filter Setting */
378 return s
->tv_filter_config
;
379 case 0x58: /* TV Filter Coefficient Index */
380 return s
->tv_filter_idx
;
381 case 0x5a: /* TV Filter Coefficient Data */
382 if (s
->tv_filter_idx
< 0x20)
383 return s
->tv_filter_coeff
[s
->tv_filter_idx
++];
386 case 0x60: /* Input YUV/RGB Translate Mode 0 */
388 case 0x62: /* Input YUV/RGB Translate Mode 1 */
390 case 0x64: /* U Data Fix */
392 case 0x66: /* V Data Fix */
395 case 0x68: /* Display Mode */
398 case 0x6a: /* Special Effects */
401 case 0x6c: /* Input Window X Start Position 0 */
402 return s
->ix
[0] & 0xff;
403 case 0x6e: /* Input Window X Start Position 1 */
404 return s
->ix
[0] >> 3;
405 case 0x70: /* Input Window Y Start Position 0 */
406 return s
->ix
[0] & 0xff;
407 case 0x72: /* Input Window Y Start Position 1 */
408 return s
->ix
[0] >> 3;
409 case 0x74: /* Input Window X End Position 0 */
410 return s
->ix
[1] & 0xff;
411 case 0x76: /* Input Window X End Position 1 */
412 return s
->ix
[1] >> 3;
413 case 0x78: /* Input Window Y End Position 0 */
414 return s
->ix
[1] & 0xff;
415 case 0x7a: /* Input Window Y End Position 1 */
416 return s
->ix
[1] >> 3;
417 case 0x7c: /* Output Window X Start Position 0 */
418 return s
->ox
[0] & 0xff;
419 case 0x7e: /* Output Window X Start Position 1 */
420 return s
->ox
[0] >> 3;
421 case 0x80: /* Output Window Y Start Position 0 */
422 return s
->oy
[0] & 0xff;
423 case 0x82: /* Output Window Y Start Position 1 */
424 return s
->oy
[0] >> 3;
425 case 0x84: /* Output Window X End Position 0 */
426 return s
->ox
[1] & 0xff;
427 case 0x86: /* Output Window X End Position 1 */
428 return s
->ox
[1] >> 3;
429 case 0x88: /* Output Window Y End Position 0 */
430 return s
->oy
[1] & 0xff;
431 case 0x8a: /* Output Window Y End Position 1 */
432 return s
->oy
[1] >> 3;
434 case 0x8c: /* Input Data Format */
436 case 0x8e: /* Data Source Select */
438 case 0x90: /* Display Memory Data Port */
441 case 0xa8: /* Border Color 0 */
443 case 0xaa: /* Border Color 1 */
445 case 0xac: /* Border Color 2 */
448 case 0xb4: /* Gamma Correction Enable */
449 return s
->gamma_config
;
450 case 0xb6: /* Gamma Correction Table Index */
452 case 0xb8: /* Gamma Correction Table Data */
453 return s
->gamma_lut
[s
->gamma_idx
++];
455 case 0xba: /* 3x3 Matrix Enable */
456 return s
->matrix_ena
;
457 case 0xbc ... 0xde: /* Coefficient Registers */
458 return s
->matrix_coeff
[(reg
- 0xbc) >> 1];
459 case 0xe0: /* 3x3 Matrix Red Offset */
461 case 0xe2: /* 3x3 Matrix Green Offset */
463 case 0xe4: /* 3x3 Matrix Blue Offset */
466 case 0xe6: /* Power-save */
468 case 0xe8: /* Non-display Period Control / Status */
469 return s
->status
| (1 << 5);
470 case 0xea: /* RGB Interface Control */
471 return s
->rgbgpio_dir
;
472 case 0xec: /* RGB Interface Status */
474 case 0xee: /* General-purpose IO Pins Configuration */
476 case 0xf0: /* General-purpose IO Pins Status / Control */
478 case 0xf2: /* GPIO Positive Edge Interrupt Trigger */
479 return s
->gpio_edge
[0];
480 case 0xf4: /* GPIO Negative Edge Interrupt Trigger */
481 return s
->gpio_edge
[1];
482 case 0xf6: /* GPIO Interrupt Status */
484 case 0xf8: /* GPIO Pull-down Control */
485 return s
->gpio_pdown
;
488 fprintf(stderr
, "%s: unknown register %02x\n", __FUNCTION__
, reg
);
493 static void blizzard_reg_write(void *opaque
, uint8_t reg
, uint16_t value
)
495 struct blizzard_s
*s
= (struct blizzard_s
*) opaque
;
498 case 0x04: /* PLL M-Divider */
499 s
->pll
= (value
& 0x3f) + 1;
501 case 0x06: /* PLL Lock Range Control */
502 s
->pll_range
= value
& 3;
504 case 0x08: /* PLL Lock Synthesis Control 0 */
505 s
->pll_ctrl
&= 0xf00;
506 s
->pll_ctrl
|= (value
<< 0) & 0x0ff;
508 case 0x0a: /* PLL Lock Synthesis Control 1 */
509 s
->pll_ctrl
&= 0x0ff;
510 s
->pll_ctrl
|= (value
<< 8) & 0xf00;
512 case 0x0c: /* PLL Mode Control 0 */
513 s
->pll_mode
= value
& 0x77;
514 if ((value
& 3) == 0 || (value
& 3) == 3)
515 fprintf(stderr
, "%s: wrong PLL Control bits (%i)\n",
516 __FUNCTION__
, value
& 3);
519 case 0x0e: /* Clock-Source Select */
520 s
->clksel
= value
& 0xff;
523 case 0x10: /* Memory Controller Activate */
524 s
->memenable
= value
& 1;
526 case 0x14: /* Memory Controller Bank 0 Status Flag */
529 case 0x18: /* Auto-Refresh Interval Setting 0 */
530 s
->memrefresh
&= 0xf00;
531 s
->memrefresh
|= (value
<< 0) & 0x0ff;
533 case 0x1a: /* Auto-Refresh Interval Setting 1 */
534 s
->memrefresh
&= 0x0ff;
535 s
->memrefresh
|= (value
<< 8) & 0xf00;
538 case 0x1c: /* Power-On Sequence Timing Control */
539 s
->timing
[0] = value
& 0x7f;
541 case 0x1e: /* Timing Control 0 */
542 s
->timing
[1] = value
& 0x17;
544 case 0x20: /* Timing Control 1 */
545 s
->timing
[2] = value
& 0x35;
548 case 0x24: /* Arbitration Priority Control */
549 s
->priority
= value
& 1;
552 case 0x28: /* LCD Panel Configuration */
553 s
->lcd_config
= value
& 0xff;
554 if (value
& (1 << 7))
555 fprintf(stderr
, "%s: data swap not supported!\n", __FUNCTION__
);
558 case 0x2a: /* LCD Horizontal Display Width */
561 case 0x2c: /* LCD Horizontal Non-display Period */
562 s
->hndp
= value
& 0xff;
564 case 0x2e: /* LCD Vertical Display Height 0 */
566 s
->y
|= (value
<< 0) & 0x0ff;
568 case 0x30: /* LCD Vertical Display Height 1 */
570 s
->y
|= (value
<< 8) & 0x300;
572 case 0x32: /* LCD Vertical Non-display Period */
573 s
->vndp
= value
& 0xff;
575 case 0x34: /* LCD HS Pulse-width */
576 s
->hsync
= value
& 0xff;
578 case 0x36: /* LCD HS Pulse Start Position */
579 s
->skipx
= value
& 0xff;
581 case 0x38: /* LCD VS Pulse-width */
582 s
->vsync
= value
& 0xbf;
584 case 0x3a: /* LCD VS Pulse Start Position */
585 s
->skipy
= value
& 0xff;
588 case 0x3c: /* PCLK Polarity */
589 s
->pclk
= value
& 0x82;
590 /* Affects calculation of s->hndp, s->hsync and s->skipx. */
593 case 0x3e: /* High-speed Serial Interface Tx Configuration Port 0 */
594 s
->hssi_config
[0] = value
;
596 case 0x40: /* High-speed Serial Interface Tx Configuration Port 1 */
597 s
->hssi_config
[1] = value
;
598 if (((value
>> 4) & 3) == 3)
599 fprintf(stderr
, "%s: Illegal active-data-links value\n",
602 case 0x42: /* High-speed Serial Interface Tx Mode */
603 s
->hssi_config
[2] = value
& 0xbd;
606 case 0x44: /* TV Display Configuration */
607 s
->tv_config
= value
& 0xfe;
609 case 0x46 ... 0x4c: /* TV Vertical Blanking Interval Data bits 0 */
610 s
->tv_timing
[(reg
- 0x46) >> 1] = value
;
612 case 0x4e: /* VBI: Closed Caption / XDS Control / Status */
615 case 0x50: /* TV Horizontal Start Position */
618 case 0x52: /* TV Vertical Start Position */
619 s
->tv_y
= value
& 0x7f;
621 case 0x54: /* TV Test Pattern Setting */
624 case 0x56: /* TV Filter Setting */
625 s
->tv_filter_config
= value
& 0xbf;
627 case 0x58: /* TV Filter Coefficient Index */
628 s
->tv_filter_idx
= value
& 0x1f;
630 case 0x5a: /* TV Filter Coefficient Data */
631 if (s
->tv_filter_idx
< 0x20)
632 s
->tv_filter_coeff
[s
->tv_filter_idx
++] = value
;
635 case 0x60: /* Input YUV/RGB Translate Mode 0 */
636 s
->yrc
[0] = value
& 0xb0;
638 case 0x62: /* Input YUV/RGB Translate Mode 1 */
639 s
->yrc
[1] = value
& 0x30;
641 case 0x64: /* U Data Fix */
644 case 0x66: /* V Data Fix */
648 case 0x68: /* Display Mode */
649 if ((s
->mode
^ value
) & 3)
651 s
->mode
= value
& 0xb7;
652 s
->enable
= value
& 1;
653 s
->blank
= (value
>> 1) & 1;
654 if (value
& (1 << 4))
655 fprintf(stderr
, "%s: Macrovision enable attempt!\n", __FUNCTION__
);
658 case 0x6a: /* Special Effects */
659 s
->effect
= value
& 0xfb;
662 case 0x6c: /* Input Window X Start Position 0 */
664 s
->ix
[0] |= (value
<< 0) & 0x0ff;
666 case 0x6e: /* Input Window X Start Position 1 */
668 s
->ix
[0] |= (value
<< 8) & 0x300;
670 case 0x70: /* Input Window Y Start Position 0 */
672 s
->iy
[0] |= (value
<< 0) & 0x0ff;
674 case 0x72: /* Input Window Y Start Position 1 */
676 s
->iy
[0] |= (value
<< 8) & 0x300;
678 case 0x74: /* Input Window X End Position 0 */
680 s
->ix
[1] |= (value
<< 0) & 0x0ff;
682 case 0x76: /* Input Window X End Position 1 */
684 s
->ix
[1] |= (value
<< 8) & 0x300;
686 case 0x78: /* Input Window Y End Position 0 */
688 s
->iy
[1] |= (value
<< 0) & 0x0ff;
690 case 0x7a: /* Input Window Y End Position 1 */
692 s
->iy
[1] |= (value
<< 8) & 0x300;
694 case 0x7c: /* Output Window X Start Position 0 */
696 s
->ox
[0] |= (value
<< 0) & 0x0ff;
698 case 0x7e: /* Output Window X Start Position 1 */
700 s
->ox
[0] |= (value
<< 8) & 0x300;
702 case 0x80: /* Output Window Y Start Position 0 */
704 s
->oy
[0] |= (value
<< 0) & 0x0ff;
706 case 0x82: /* Output Window Y Start Position 1 */
708 s
->oy
[0] |= (value
<< 8) & 0x300;
710 case 0x84: /* Output Window X End Position 0 */
712 s
->ox
[1] |= (value
<< 0) & 0x0ff;
714 case 0x86: /* Output Window X End Position 1 */
716 s
->ox
[1] |= (value
<< 8) & 0x300;
718 case 0x88: /* Output Window Y End Position 0 */
720 s
->oy
[1] |= (value
<< 0) & 0x0ff;
722 case 0x8a: /* Output Window Y End Position 1 */
724 s
->oy
[1] |= (value
<< 8) & 0x300;
727 case 0x8c: /* Input Data Format */
728 s
->iformat
= value
& 0xf;
729 s
->bpp
= blizzard_iformat_bpp
[s
->iformat
];
731 fprintf(stderr
, "%s: Illegal or unsupported input format %x\n",
732 __FUNCTION__
, s
->iformat
);
734 case 0x8e: /* Data Source Select */
735 s
->source
= value
& 7;
736 /* Currently all windows will be "destructive overlays". */
737 if ((!(s
->effect
& (1 << 3)) && (s
->ix
[0] != s
->ox
[0] ||
738 s
->iy
[0] != s
->oy
[0] ||
739 s
->ix
[1] != s
->ox
[1] ||
740 s
->iy
[1] != s
->oy
[1])) ||
741 !((s
->ix
[1] - s
->ix
[0]) & (s
->iy
[1] - s
->iy
[0]) &
742 (s
->ox
[1] - s
->ox
[0]) & (s
->oy
[1] - s
->oy
[0]) & 1))
743 fprintf(stderr
, "%s: Illegal input/output window positions\n",
746 blizzard_transfer_setup(s
);
749 case 0x90: /* Display Memory Data Port */
750 if (!s
->data
.len
&& !blizzard_transfer_setup(s
))
753 *s
->data
.ptr
++ = value
;
754 if (-- s
->data
.len
== 0)
758 case 0xa8: /* Border Color 0 */
761 case 0xaa: /* Border Color 1 */
764 case 0xac: /* Border Color 2 */
768 case 0xb4: /* Gamma Correction Enable */
769 s
->gamma_config
= value
& 0x87;
771 case 0xb6: /* Gamma Correction Table Index */
772 s
->gamma_idx
= value
;
774 case 0xb8: /* Gamma Correction Table Data */
775 s
->gamma_lut
[s
->gamma_idx
++] = value
;
778 case 0xba: /* 3x3 Matrix Enable */
779 s
->matrix_ena
= value
& 1;
781 case 0xbc ... 0xde: /* Coefficient Registers */
782 s
->matrix_coeff
[(reg
- 0xbc) >> 1] = value
& ((reg
& 2) ? 0x80 : 0xff);
784 case 0xe0: /* 3x3 Matrix Red Offset */
787 case 0xe2: /* 3x3 Matrix Green Offset */
790 case 0xe4: /* 3x3 Matrix Blue Offset */
794 case 0xe6: /* Power-save */
795 s
->pm
= value
& 0x83;
796 if (value
& s
->mode
& 1)
797 fprintf(stderr
, "%s: The display must be disabled before entering "
798 "Standby Mode\n", __FUNCTION__
);
800 case 0xe8: /* Non-display Period Control / Status */
801 s
->status
= value
& 0x1b;
803 case 0xea: /* RGB Interface Control */
804 s
->rgbgpio_dir
= value
& 0x8f;
806 case 0xec: /* RGB Interface Status */
807 s
->rgbgpio
= value
& 0xcf;
809 case 0xee: /* General-purpose IO Pins Configuration */
812 case 0xf0: /* General-purpose IO Pins Status / Control */
815 case 0xf2: /* GPIO Positive Edge Interrupt Trigger */
816 s
->gpio_edge
[0] = value
;
818 case 0xf4: /* GPIO Negative Edge Interrupt Trigger */
819 s
->gpio_edge
[1] = value
;
821 case 0xf6: /* GPIO Interrupt Status */
822 s
->gpio_irq
&= value
;
824 case 0xf8: /* GPIO Pull-down Control */
825 s
->gpio_pdown
= value
;
829 fprintf(stderr
, "%s: unknown register %02x\n", __FUNCTION__
, reg
);
834 uint16_t s1d13745_read(void *opaque
, int dc
)
836 struct blizzard_s
*s
= (struct blizzard_s
*) opaque
;
837 uint16_t value
= blizzard_reg_read(s
, s
->reg
);
839 if (s
->swallow
-- > 0)
847 void s1d13745_write(void *opaque
, int dc
, uint16_t value
)
849 struct blizzard_s
*s
= (struct blizzard_s
*) opaque
;
851 if (s
->swallow
-- > 0)
854 blizzard_reg_write(s
, s
->reg
, value
);
856 if (s
->reg
!= 0x90 && s
->reg
!= 0x5a && s
->reg
!= 0xb8)
859 s
->reg
= value
& 0xff;
862 void s1d13745_write_block(void *opaque
, int dc
,
863 void *buf
, size_t len
, int pitch
)
865 struct blizzard_s
*s
= (struct blizzard_s
*) opaque
;
868 if (s
->reg
== 0x90 && dc
&&
869 (s
->data
.len
|| blizzard_transfer_setup(s
)) &&
870 len
>= (s
->data
.len
<< 1)) {
871 len
-= s
->data
.len
<< 1;
875 s
->data
.pitch
= pitch
;
877 s
->data
.data
= s
->data
.buf
;
881 s1d13745_write(opaque
, dc
, *(uint16_t *) buf
);
889 static void blizzard_update_display(void *opaque
)
891 struct blizzard_s
*s
= (struct blizzard_s
*) opaque
;
892 int y
, bypp
, bypl
, bwidth
;
898 if (s
->x
!= ds_get_width(s
->state
) || s
->y
!= ds_get_height(s
->state
)) {
900 qemu_console_resize(s
->console
, s
->x
, s
->y
);
907 bypp
= (ds_get_bits_per_pixel(s
->state
) + 7) >> 3;
908 memset(ds_get_data(s
->state
), 0, bypp
* s
->x
* s
->y
);
918 if (s
->mx
[1] <= s
->mx
[0])
921 bypp
= (ds_get_bits_per_pixel(s
->state
) + 7) >> 3;
923 bwidth
= bypp
* (s
->mx
[1] - s
->mx
[0]);
925 src
= s
->fb
+ bypl
* y
+ bypp
* s
->mx
[0];
926 dst
= ds_get_data(s
->state
) + bypl
* y
+ bypp
* s
->mx
[0];
927 for (; y
< s
->my
[1]; y
++, src
+= bypl
, dst
+= bypl
)
928 memcpy(dst
, src
, bwidth
);
930 dpy_update(s
->state
, s
->mx
[0], s
->my
[0],
931 s
->mx
[1] - s
->mx
[0], y
- s
->my
[0]);
939 static void blizzard_screen_dump(void *opaque
, const char *filename
) {
940 struct blizzard_s
*s
= (struct blizzard_s
*) opaque
;
942 blizzard_update_display(opaque
);
943 if (s
&& ds_get_data(s
->state
))
944 ppm_save(filename
, ds_get_data(s
->state
), s
->x
, s
->y
, ds_get_linesize(s
->state
));
948 #include "blizzard_template.h"
950 #include "blizzard_template.h"
952 #include "blizzard_template.h"
954 #include "blizzard_template.h"
956 #include "blizzard_template.h"
958 void *s1d13745_init(qemu_irq gpio_int
, DisplayState
*ds
)
960 struct blizzard_s
*s
= (struct blizzard_s
*) qemu_mallocz(sizeof(*s
));
963 s
->fb
= qemu_malloc(0x180000);
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__
);
997 s
->console
= graphic_console_init(s
->state
, blizzard_update_display
,
998 blizzard_invalidate_display
,
999 blizzard_screen_dump
, NULL
, s
);