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, write to the Free Software Foundation, Inc.,
19 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
22 #include "qemu-common.h"
27 #include "pixel_ops.h"
29 typedef void (*blizzard_fn_t
)(uint8_t *, const uint8_t *, unsigned int);
75 blizzard_fn_t
*line_fn_tab
[2];
78 uint8_t hssi_config
[3];
85 uint8_t tv_filter_config
;
86 uint8_t tv_filter_idx
;
87 uint8_t tv_filter_coeff
[0x20];
93 uint8_t gamma_lut
[0x100];
95 uint8_t matrix_coeff
[0x12];
105 uint8_t gpio_edge
[2];
121 blizzard_fn_t line_fn
;
125 /* Bytes(!) per pixel */
126 static const int blizzard_iformat_bpp
[0x10] = {
129 3, /* RGB 6:6:6 mode 1 */
130 3, /* RGB 8:8:8 mode 1 */
132 4, /* RGB 6:6:6 mode 2 */
133 4, /* RGB 8:8:8 mode 2 */
139 static inline void blizzard_rgb2yuv(int r
, int g
, int b
,
140 int *y
, int *u
, int *v
)
142 *y
= 0x10 + ((0x838 * r
+ 0x1022 * g
+ 0x322 * b
) >> 13);
143 *u
= 0x80 + ((0xe0e * b
- 0x04c1 * r
- 0x94e * g
) >> 13);
144 *v
= 0x80 + ((0xe0e * r
- 0x0bc7 * g
- 0x247 * b
) >> 13);
147 static void blizzard_window(BlizzardState
*s
)
153 blizzard_fn_t fn
= s
->data
.line_fn
;
157 if (s
->mx
[0] > s
->data
.x
)
158 s
->mx
[0] = s
->data
.x
;
159 if (s
->my
[0] > s
->data
.y
)
160 s
->my
[0] = s
->data
.y
;
161 if (s
->mx
[1] < s
->data
.x
+ s
->data
.dx
)
162 s
->mx
[1] = s
->data
.x
+ s
->data
.dx
;
163 if (s
->my
[1] < s
->data
.y
+ s
->data
.dy
)
164 s
->my
[1] = s
->data
.y
+ s
->data
.dy
;
167 bypp
[1] = (ds_get_bits_per_pixel(s
->state
) + 7) >> 3;
168 bypl
[0] = bypp
[0] * s
->data
.pitch
;
169 bypl
[1] = bypp
[1] * s
->x
;
170 bypl
[2] = bypp
[0] * s
->data
.dx
;
173 dst
= s
->fb
+ bypl
[1] * s
->data
.y
+ bypp
[1] * s
->data
.x
;
174 for (y
= s
->data
.dy
; y
> 0; y
--, src
+= bypl
[0], dst
+= bypl
[1])
175 fn(dst
, src
, bypl
[2]);
178 static int blizzard_transfer_setup(BlizzardState
*s
)
180 if (s
->source
> 3 || !s
->bpp
||
181 s
->ix
[1] < s
->ix
[0] || s
->iy
[1] < s
->iy
[0])
184 s
->data
.angle
= s
->effect
& 3;
185 s
->data
.line_fn
= s
->line_fn_tab
[!!s
->data
.angle
][s
->iformat
];
186 s
->data
.x
= s
->ix
[0];
187 s
->data
.y
= s
->iy
[0];
188 s
->data
.dx
= s
->ix
[1] - s
->ix
[0] + 1;
189 s
->data
.dy
= s
->iy
[1] - s
->iy
[0] + 1;
190 s
->data
.len
= s
->bpp
* s
->data
.dx
* s
->data
.dy
;
191 s
->data
.pitch
= s
->data
.dx
;
192 if (s
->data
.len
> s
->data
.buflen
) {
193 s
->data
.buf
= qemu_realloc(s
->data
.buf
, s
->data
.len
);
194 s
->data
.buflen
= s
->data
.len
;
196 s
->data
.ptr
= s
->data
.buf
;
197 s
->data
.data
= s
->data
.buf
;
202 static void blizzard_reset(BlizzardState
*s
)
213 s
->memrefresh
= 0x25c;
219 s
->lcd_config
= 0x74;
246 s
->bpp
= blizzard_iformat_bpp
[s
->iformat
];
248 s
->hssi_config
[0] = 0x00;
249 s
->hssi_config
[1] = 0x00;
250 s
->hssi_config
[2] = 0x01;
252 s
->tv_timing
[0] = 0x00;
253 s
->tv_timing
[1] = 0x00;
254 s
->tv_timing
[2] = 0x00;
255 s
->tv_timing
[3] = 0x00;
260 s
->tv_filter_config
= 0x80;
261 s
->tv_filter_idx
= 0x00;
265 s
->gamma_config
= 0x00;
267 s
->matrix_ena
= 0x00;
268 memset(&s
->matrix_coeff
, 0, sizeof(s
->matrix_coeff
));
274 s
->rgbgpio_dir
= 0x00;
276 s
->gpio_edge
[0] = 0x00;
277 s
->gpio_edge
[1] = 0x00;
279 s
->gpio_pdown
= 0xff;
282 static inline void blizzard_invalidate_display(void *opaque
) {
283 BlizzardState
*s
= (BlizzardState
*) opaque
;
288 static uint16_t blizzard_reg_read(void *opaque
, uint8_t reg
)
290 BlizzardState
*s
= (BlizzardState
*) opaque
;
293 case 0x00: /* Revision Code */
296 case 0x02: /* Configuration Readback */
297 return 0x83; /* Macrovision OK, CNF[2:0] = 3 */
299 case 0x04: /* PLL M-Divider */
300 return (s
->pll
- 1) | (1 << 7);
301 case 0x06: /* PLL Lock Range Control */
303 case 0x08: /* PLL Lock Synthesis Control 0 */
304 return s
->pll_ctrl
& 0xff;
305 case 0x0a: /* PLL Lock Synthesis Control 1 */
306 return s
->pll_ctrl
>> 8;
307 case 0x0c: /* PLL Mode Control 0 */
310 case 0x0e: /* Clock-Source Select */
313 case 0x10: /* Memory Controller Activate */
314 case 0x14: /* Memory Controller Bank 0 Status Flag */
317 case 0x18: /* Auto-Refresh Interval Setting 0 */
318 return s
->memrefresh
& 0xff;
319 case 0x1a: /* Auto-Refresh Interval Setting 1 */
320 return s
->memrefresh
>> 8;
322 case 0x1c: /* Power-On Sequence Timing Control */
324 case 0x1e: /* Timing Control 0 */
326 case 0x20: /* Timing Control 1 */
329 case 0x24: /* Arbitration Priority Control */
332 case 0x28: /* LCD Panel Configuration */
333 return s
->lcd_config
;
335 case 0x2a: /* LCD Horizontal Display Width */
337 case 0x2c: /* LCD Horizontal Non-display Period */
339 case 0x2e: /* LCD Vertical Display Height 0 */
341 case 0x30: /* LCD Vertical Display Height 1 */
343 case 0x32: /* LCD Vertical Non-display Period */
345 case 0x34: /* LCD HS Pulse-width */
347 case 0x36: /* LCd HS Pulse Start Position */
348 return s
->skipx
>> 3;
349 case 0x38: /* LCD VS Pulse-width */
351 case 0x3a: /* LCD VS Pulse Start Position */
354 case 0x3c: /* PCLK Polarity */
357 case 0x3e: /* High-speed Serial Interface Tx Configuration Port 0 */
358 return s
->hssi_config
[0];
359 case 0x40: /* High-speed Serial Interface Tx Configuration Port 1 */
360 return s
->hssi_config
[1];
361 case 0x42: /* High-speed Serial Interface Tx Mode */
362 return s
->hssi_config
[2];
363 case 0x44: /* TV Display Configuration */
365 case 0x46 ... 0x4c: /* TV Vertical Blanking Interval Data bits */
366 return s
->tv_timing
[(reg
- 0x46) >> 1];
367 case 0x4e: /* VBI: Closed Caption / XDS Control / Status */
369 case 0x50: /* TV Horizontal Start Position */
371 case 0x52: /* TV Vertical Start Position */
373 case 0x54: /* TV Test Pattern Setting */
375 case 0x56: /* TV Filter Setting */
376 return s
->tv_filter_config
;
377 case 0x58: /* TV Filter Coefficient Index */
378 return s
->tv_filter_idx
;
379 case 0x5a: /* TV Filter Coefficient Data */
380 if (s
->tv_filter_idx
< 0x20)
381 return s
->tv_filter_coeff
[s
->tv_filter_idx
++];
384 case 0x60: /* Input YUV/RGB Translate Mode 0 */
386 case 0x62: /* Input YUV/RGB Translate Mode 1 */
388 case 0x64: /* U Data Fix */
390 case 0x66: /* V Data Fix */
393 case 0x68: /* Display Mode */
396 case 0x6a: /* Special Effects */
399 case 0x6c: /* Input Window X Start Position 0 */
400 return s
->ix
[0] & 0xff;
401 case 0x6e: /* Input Window X Start Position 1 */
402 return s
->ix
[0] >> 3;
403 case 0x70: /* Input Window Y Start Position 0 */
404 return s
->ix
[0] & 0xff;
405 case 0x72: /* Input Window Y Start Position 1 */
406 return s
->ix
[0] >> 3;
407 case 0x74: /* Input Window X End Position 0 */
408 return s
->ix
[1] & 0xff;
409 case 0x76: /* Input Window X End Position 1 */
410 return s
->ix
[1] >> 3;
411 case 0x78: /* Input Window Y End Position 0 */
412 return s
->ix
[1] & 0xff;
413 case 0x7a: /* Input Window Y End Position 1 */
414 return s
->ix
[1] >> 3;
415 case 0x7c: /* Output Window X Start Position 0 */
416 return s
->ox
[0] & 0xff;
417 case 0x7e: /* Output Window X Start Position 1 */
418 return s
->ox
[0] >> 3;
419 case 0x80: /* Output Window Y Start Position 0 */
420 return s
->oy
[0] & 0xff;
421 case 0x82: /* Output Window Y Start Position 1 */
422 return s
->oy
[0] >> 3;
423 case 0x84: /* Output Window X End Position 0 */
424 return s
->ox
[1] & 0xff;
425 case 0x86: /* Output Window X End Position 1 */
426 return s
->ox
[1] >> 3;
427 case 0x88: /* Output Window Y End Position 0 */
428 return s
->oy
[1] & 0xff;
429 case 0x8a: /* Output Window Y End Position 1 */
430 return s
->oy
[1] >> 3;
432 case 0x8c: /* Input Data Format */
434 case 0x8e: /* Data Source Select */
436 case 0x90: /* Display Memory Data Port */
439 case 0xa8: /* Border Color 0 */
441 case 0xaa: /* Border Color 1 */
443 case 0xac: /* Border Color 2 */
446 case 0xb4: /* Gamma Correction Enable */
447 return s
->gamma_config
;
448 case 0xb6: /* Gamma Correction Table Index */
450 case 0xb8: /* Gamma Correction Table Data */
451 return s
->gamma_lut
[s
->gamma_idx
++];
453 case 0xba: /* 3x3 Matrix Enable */
454 return s
->matrix_ena
;
455 case 0xbc ... 0xde: /* Coefficient Registers */
456 return s
->matrix_coeff
[(reg
- 0xbc) >> 1];
457 case 0xe0: /* 3x3 Matrix Red Offset */
459 case 0xe2: /* 3x3 Matrix Green Offset */
461 case 0xe4: /* 3x3 Matrix Blue Offset */
464 case 0xe6: /* Power-save */
466 case 0xe8: /* Non-display Period Control / Status */
467 return s
->status
| (1 << 5);
468 case 0xea: /* RGB Interface Control */
469 return s
->rgbgpio_dir
;
470 case 0xec: /* RGB Interface Status */
472 case 0xee: /* General-purpose IO Pins Configuration */
474 case 0xf0: /* General-purpose IO Pins Status / Control */
476 case 0xf2: /* GPIO Positive Edge Interrupt Trigger */
477 return s
->gpio_edge
[0];
478 case 0xf4: /* GPIO Negative Edge Interrupt Trigger */
479 return s
->gpio_edge
[1];
480 case 0xf6: /* GPIO Interrupt Status */
482 case 0xf8: /* GPIO Pull-down Control */
483 return s
->gpio_pdown
;
486 fprintf(stderr
, "%s: unknown register %02x\n", __FUNCTION__
, reg
);
491 static void blizzard_reg_write(void *opaque
, uint8_t reg
, uint16_t value
)
493 BlizzardState
*s
= (BlizzardState
*) opaque
;
496 case 0x04: /* PLL M-Divider */
497 s
->pll
= (value
& 0x3f) + 1;
499 case 0x06: /* PLL Lock Range Control */
500 s
->pll_range
= value
& 3;
502 case 0x08: /* PLL Lock Synthesis Control 0 */
503 s
->pll_ctrl
&= 0xf00;
504 s
->pll_ctrl
|= (value
<< 0) & 0x0ff;
506 case 0x0a: /* PLL Lock Synthesis Control 1 */
507 s
->pll_ctrl
&= 0x0ff;
508 s
->pll_ctrl
|= (value
<< 8) & 0xf00;
510 case 0x0c: /* PLL Mode Control 0 */
511 s
->pll_mode
= value
& 0x77;
512 if ((value
& 3) == 0 || (value
& 3) == 3)
513 fprintf(stderr
, "%s: wrong PLL Control bits (%i)\n",
514 __FUNCTION__
, value
& 3);
517 case 0x0e: /* Clock-Source Select */
518 s
->clksel
= value
& 0xff;
521 case 0x10: /* Memory Controller Activate */
522 s
->memenable
= value
& 1;
524 case 0x14: /* Memory Controller Bank 0 Status Flag */
527 case 0x18: /* Auto-Refresh Interval Setting 0 */
528 s
->memrefresh
&= 0xf00;
529 s
->memrefresh
|= (value
<< 0) & 0x0ff;
531 case 0x1a: /* Auto-Refresh Interval Setting 1 */
532 s
->memrefresh
&= 0x0ff;
533 s
->memrefresh
|= (value
<< 8) & 0xf00;
536 case 0x1c: /* Power-On Sequence Timing Control */
537 s
->timing
[0] = value
& 0x7f;
539 case 0x1e: /* Timing Control 0 */
540 s
->timing
[1] = value
& 0x17;
542 case 0x20: /* Timing Control 1 */
543 s
->timing
[2] = value
& 0x35;
546 case 0x24: /* Arbitration Priority Control */
547 s
->priority
= value
& 1;
550 case 0x28: /* LCD Panel Configuration */
551 s
->lcd_config
= value
& 0xff;
552 if (value
& (1 << 7))
553 fprintf(stderr
, "%s: data swap not supported!\n", __FUNCTION__
);
556 case 0x2a: /* LCD Horizontal Display Width */
559 case 0x2c: /* LCD Horizontal Non-display Period */
560 s
->hndp
= value
& 0xff;
562 case 0x2e: /* LCD Vertical Display Height 0 */
564 s
->y
|= (value
<< 0) & 0x0ff;
566 case 0x30: /* LCD Vertical Display Height 1 */
568 s
->y
|= (value
<< 8) & 0x300;
570 case 0x32: /* LCD Vertical Non-display Period */
571 s
->vndp
= value
& 0xff;
573 case 0x34: /* LCD HS Pulse-width */
574 s
->hsync
= value
& 0xff;
576 case 0x36: /* LCD HS Pulse Start Position */
577 s
->skipx
= value
& 0xff;
579 case 0x38: /* LCD VS Pulse-width */
580 s
->vsync
= value
& 0xbf;
582 case 0x3a: /* LCD VS Pulse Start Position */
583 s
->skipy
= value
& 0xff;
586 case 0x3c: /* PCLK Polarity */
587 s
->pclk
= value
& 0x82;
588 /* Affects calculation of s->hndp, s->hsync and s->skipx. */
591 case 0x3e: /* High-speed Serial Interface Tx Configuration Port 0 */
592 s
->hssi_config
[0] = value
;
594 case 0x40: /* High-speed Serial Interface Tx Configuration Port 1 */
595 s
->hssi_config
[1] = value
;
596 if (((value
>> 4) & 3) == 3)
597 fprintf(stderr
, "%s: Illegal active-data-links value\n",
600 case 0x42: /* High-speed Serial Interface Tx Mode */
601 s
->hssi_config
[2] = value
& 0xbd;
604 case 0x44: /* TV Display Configuration */
605 s
->tv_config
= value
& 0xfe;
607 case 0x46 ... 0x4c: /* TV Vertical Blanking Interval Data bits 0 */
608 s
->tv_timing
[(reg
- 0x46) >> 1] = value
;
610 case 0x4e: /* VBI: Closed Caption / XDS Control / Status */
613 case 0x50: /* TV Horizontal Start Position */
616 case 0x52: /* TV Vertical Start Position */
617 s
->tv_y
= value
& 0x7f;
619 case 0x54: /* TV Test Pattern Setting */
622 case 0x56: /* TV Filter Setting */
623 s
->tv_filter_config
= value
& 0xbf;
625 case 0x58: /* TV Filter Coefficient Index */
626 s
->tv_filter_idx
= value
& 0x1f;
628 case 0x5a: /* TV Filter Coefficient Data */
629 if (s
->tv_filter_idx
< 0x20)
630 s
->tv_filter_coeff
[s
->tv_filter_idx
++] = value
;
633 case 0x60: /* Input YUV/RGB Translate Mode 0 */
634 s
->yrc
[0] = value
& 0xb0;
636 case 0x62: /* Input YUV/RGB Translate Mode 1 */
637 s
->yrc
[1] = value
& 0x30;
639 case 0x64: /* U Data Fix */
642 case 0x66: /* V Data Fix */
646 case 0x68: /* Display Mode */
647 if ((s
->mode
^ value
) & 3)
649 s
->mode
= value
& 0xb7;
650 s
->enable
= value
& 1;
651 s
->blank
= (value
>> 1) & 1;
652 if (value
& (1 << 4))
653 fprintf(stderr
, "%s: Macrovision enable attempt!\n", __FUNCTION__
);
656 case 0x6a: /* Special Effects */
657 s
->effect
= value
& 0xfb;
660 case 0x6c: /* Input Window X Start Position 0 */
662 s
->ix
[0] |= (value
<< 0) & 0x0ff;
664 case 0x6e: /* Input Window X Start Position 1 */
666 s
->ix
[0] |= (value
<< 8) & 0x300;
668 case 0x70: /* Input Window Y Start Position 0 */
670 s
->iy
[0] |= (value
<< 0) & 0x0ff;
672 case 0x72: /* Input Window Y Start Position 1 */
674 s
->iy
[0] |= (value
<< 8) & 0x300;
676 case 0x74: /* Input Window X End Position 0 */
678 s
->ix
[1] |= (value
<< 0) & 0x0ff;
680 case 0x76: /* Input Window X End Position 1 */
682 s
->ix
[1] |= (value
<< 8) & 0x300;
684 case 0x78: /* Input Window Y End Position 0 */
686 s
->iy
[1] |= (value
<< 0) & 0x0ff;
688 case 0x7a: /* Input Window Y End Position 1 */
690 s
->iy
[1] |= (value
<< 8) & 0x300;
692 case 0x7c: /* Output Window X Start Position 0 */
694 s
->ox
[0] |= (value
<< 0) & 0x0ff;
696 case 0x7e: /* Output Window X Start Position 1 */
698 s
->ox
[0] |= (value
<< 8) & 0x300;
700 case 0x80: /* Output Window Y Start Position 0 */
702 s
->oy
[0] |= (value
<< 0) & 0x0ff;
704 case 0x82: /* Output Window Y Start Position 1 */
706 s
->oy
[0] |= (value
<< 8) & 0x300;
708 case 0x84: /* Output Window X End Position 0 */
710 s
->ox
[1] |= (value
<< 0) & 0x0ff;
712 case 0x86: /* Output Window X End Position 1 */
714 s
->ox
[1] |= (value
<< 8) & 0x300;
716 case 0x88: /* Output Window Y End Position 0 */
718 s
->oy
[1] |= (value
<< 0) & 0x0ff;
720 case 0x8a: /* Output Window Y End Position 1 */
722 s
->oy
[1] |= (value
<< 8) & 0x300;
725 case 0x8c: /* Input Data Format */
726 s
->iformat
= value
& 0xf;
727 s
->bpp
= blizzard_iformat_bpp
[s
->iformat
];
729 fprintf(stderr
, "%s: Illegal or unsupported input format %x\n",
730 __FUNCTION__
, s
->iformat
);
732 case 0x8e: /* Data Source Select */
733 s
->source
= value
& 7;
734 /* Currently all windows will be "destructive overlays". */
735 if ((!(s
->effect
& (1 << 3)) && (s
->ix
[0] != s
->ox
[0] ||
736 s
->iy
[0] != s
->oy
[0] ||
737 s
->ix
[1] != s
->ox
[1] ||
738 s
->iy
[1] != s
->oy
[1])) ||
739 !((s
->ix
[1] - s
->ix
[0]) & (s
->iy
[1] - s
->iy
[0]) &
740 (s
->ox
[1] - s
->ox
[0]) & (s
->oy
[1] - s
->oy
[0]) & 1))
741 fprintf(stderr
, "%s: Illegal input/output window positions\n",
744 blizzard_transfer_setup(s
);
747 case 0x90: /* Display Memory Data Port */
748 if (!s
->data
.len
&& !blizzard_transfer_setup(s
))
751 *s
->data
.ptr
++ = value
;
752 if (-- s
->data
.len
== 0)
756 case 0xa8: /* Border Color 0 */
759 case 0xaa: /* Border Color 1 */
762 case 0xac: /* Border Color 2 */
766 case 0xb4: /* Gamma Correction Enable */
767 s
->gamma_config
= value
& 0x87;
769 case 0xb6: /* Gamma Correction Table Index */
770 s
->gamma_idx
= value
;
772 case 0xb8: /* Gamma Correction Table Data */
773 s
->gamma_lut
[s
->gamma_idx
++] = value
;
776 case 0xba: /* 3x3 Matrix Enable */
777 s
->matrix_ena
= value
& 1;
779 case 0xbc ... 0xde: /* Coefficient Registers */
780 s
->matrix_coeff
[(reg
- 0xbc) >> 1] = value
& ((reg
& 2) ? 0x80 : 0xff);
782 case 0xe0: /* 3x3 Matrix Red Offset */
785 case 0xe2: /* 3x3 Matrix Green Offset */
788 case 0xe4: /* 3x3 Matrix Blue Offset */
792 case 0xe6: /* Power-save */
793 s
->pm
= value
& 0x83;
794 if (value
& s
->mode
& 1)
795 fprintf(stderr
, "%s: The display must be disabled before entering "
796 "Standby Mode\n", __FUNCTION__
);
798 case 0xe8: /* Non-display Period Control / Status */
799 s
->status
= value
& 0x1b;
801 case 0xea: /* RGB Interface Control */
802 s
->rgbgpio_dir
= value
& 0x8f;
804 case 0xec: /* RGB Interface Status */
805 s
->rgbgpio
= value
& 0xcf;
807 case 0xee: /* General-purpose IO Pins Configuration */
810 case 0xf0: /* General-purpose IO Pins Status / Control */
813 case 0xf2: /* GPIO Positive Edge Interrupt Trigger */
814 s
->gpio_edge
[0] = value
;
816 case 0xf4: /* GPIO Negative Edge Interrupt Trigger */
817 s
->gpio_edge
[1] = value
;
819 case 0xf6: /* GPIO Interrupt Status */
820 s
->gpio_irq
&= value
;
822 case 0xf8: /* GPIO Pull-down Control */
823 s
->gpio_pdown
= value
;
827 fprintf(stderr
, "%s: unknown register %02x\n", __FUNCTION__
, reg
);
832 uint16_t s1d13745_read(void *opaque
, int dc
)
834 BlizzardState
*s
= (BlizzardState
*) opaque
;
835 uint16_t value
= blizzard_reg_read(s
, s
->reg
);
837 if (s
->swallow
-- > 0)
845 void s1d13745_write(void *opaque
, int dc
, uint16_t value
)
847 BlizzardState
*s
= (BlizzardState
*) opaque
;
849 if (s
->swallow
-- > 0)
852 blizzard_reg_write(s
, s
->reg
, value
);
854 if (s
->reg
!= 0x90 && s
->reg
!= 0x5a && s
->reg
!= 0xb8)
857 s
->reg
= value
& 0xff;
860 void s1d13745_write_block(void *opaque
, int dc
,
861 void *buf
, size_t len
, int pitch
)
863 BlizzardState
*s
= (BlizzardState
*) opaque
;
866 if (s
->reg
== 0x90 && dc
&&
867 (s
->data
.len
|| blizzard_transfer_setup(s
)) &&
868 len
>= (s
->data
.len
<< 1)) {
869 len
-= s
->data
.len
<< 1;
873 s
->data
.pitch
= pitch
;
875 s
->data
.data
= s
->data
.buf
;
879 s1d13745_write(opaque
, dc
, *(uint16_t *) buf
);
887 static void blizzard_update_display(void *opaque
)
889 BlizzardState
*s
= (BlizzardState
*) opaque
;
890 int y
, bypp
, bypl
, bwidth
;
896 if (s
->x
!= ds_get_width(s
->state
) || s
->y
!= ds_get_height(s
->state
)) {
898 qemu_console_resize(s
->state
, s
->x
, s
->y
);
905 bypp
= (ds_get_bits_per_pixel(s
->state
) + 7) >> 3;
906 memset(ds_get_data(s
->state
), 0, bypp
* s
->x
* s
->y
);
916 if (s
->mx
[1] <= s
->mx
[0])
919 bypp
= (ds_get_bits_per_pixel(s
->state
) + 7) >> 3;
921 bwidth
= bypp
* (s
->mx
[1] - s
->mx
[0]);
923 src
= s
->fb
+ bypl
* y
+ bypp
* s
->mx
[0];
924 dst
= ds_get_data(s
->state
) + bypl
* y
+ bypp
* s
->mx
[0];
925 for (; y
< s
->my
[1]; y
++, src
+= bypl
, dst
+= bypl
)
926 memcpy(dst
, src
, bwidth
);
928 dpy_update(s
->state
, s
->mx
[0], s
->my
[0],
929 s
->mx
[1] - s
->mx
[0], y
- s
->my
[0]);
937 static void blizzard_screen_dump(void *opaque
, const char *filename
) {
938 BlizzardState
*s
= (BlizzardState
*) opaque
;
940 blizzard_update_display(opaque
);
941 if (s
&& ds_get_data(s
->state
))
942 ppm_save(filename
, s
->state
->surface
);
946 #include "blizzard_template.h"
948 #include "blizzard_template.h"
950 #include "blizzard_template.h"
952 #include "blizzard_template.h"
954 #include "blizzard_template.h"
956 void *s1d13745_init(qemu_irq gpio_int
)
958 BlizzardState
*s
= (BlizzardState
*) qemu_mallocz(sizeof(*s
));
960 s
->fb
= qemu_malloc(0x180000);
962 s
->state
= graphic_console_init(blizzard_update_display
,
963 blizzard_invalidate_display
,
964 blizzard_screen_dump
, NULL
, s
);
966 switch (ds_get_bits_per_pixel(s
->state
)) {
968 s
->line_fn_tab
[0] = s
->line_fn_tab
[1] =
969 qemu_mallocz(sizeof(blizzard_fn_t
) * 0x10);
972 s
->line_fn_tab
[0] = blizzard_draw_fn_8
;
973 s
->line_fn_tab
[1] = blizzard_draw_fn_r_8
;
976 s
->line_fn_tab
[0] = blizzard_draw_fn_15
;
977 s
->line_fn_tab
[1] = blizzard_draw_fn_r_15
;
980 s
->line_fn_tab
[0] = blizzard_draw_fn_16
;
981 s
->line_fn_tab
[1] = blizzard_draw_fn_r_16
;
984 s
->line_fn_tab
[0] = blizzard_draw_fn_24
;
985 s
->line_fn_tab
[1] = blizzard_draw_fn_r_24
;
988 s
->line_fn_tab
[0] = blizzard_draw_fn_32
;
989 s
->line_fn_tab
[1] = blizzard_draw_fn_r_32
;
992 fprintf(stderr
, "%s: Bad color depth\n", __FUNCTION__
);