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);
76 blizzard_fn_t
*line_fn_tab
[2];
79 uint8_t hssi_config
[3];
86 uint8_t tv_filter_config
;
87 uint8_t tv_filter_idx
;
88 uint8_t tv_filter_coeff
[0x20];
94 uint8_t gamma_lut
[0x100];
96 uint8_t matrix_coeff
[0x12];
106 uint8_t gpio_edge
[2];
122 blizzard_fn_t line_fn
;
126 /* Bytes(!) per pixel */
127 static const int blizzard_iformat_bpp
[0x10] = {
130 3, /* RGB 6:6:6 mode 1 */
131 3, /* RGB 8:8:8 mode 1 */
133 4, /* RGB 6:6:6 mode 2 */
134 4, /* RGB 8:8:8 mode 2 */
140 static inline void blizzard_rgb2yuv(int r
, int g
, int b
,
141 int *y
, int *u
, int *v
)
143 *y
= 0x10 + ((0x838 * r
+ 0x1022 * g
+ 0x322 * b
) >> 13);
144 *u
= 0x80 + ((0xe0e * b
- 0x04c1 * r
- 0x94e * g
) >> 13);
145 *v
= 0x80 + ((0xe0e * r
- 0x0bc7 * g
- 0x247 * b
) >> 13);
148 static void blizzard_window(struct blizzard_s
*s
)
154 blizzard_fn_t fn
= s
->data
.line_fn
;
158 if (s
->mx
[0] > s
->data
.x
)
159 s
->mx
[0] = s
->data
.x
;
160 if (s
->my
[0] > s
->data
.y
)
161 s
->my
[0] = s
->data
.y
;
162 if (s
->mx
[1] < s
->data
.x
+ s
->data
.dx
)
163 s
->mx
[1] = s
->data
.x
+ s
->data
.dx
;
164 if (s
->my
[1] < s
->data
.y
+ s
->data
.dy
)
165 s
->my
[1] = s
->data
.y
+ s
->data
.dy
;
168 bypp
[1] = (ds_get_bits_per_pixel(s
->state
) + 7) >> 3;
169 bypl
[0] = bypp
[0] * s
->data
.pitch
;
170 bypl
[1] = bypp
[1] * s
->x
;
171 bypl
[2] = bypp
[0] * s
->data
.dx
;
174 dst
= s
->fb
+ bypl
[1] * s
->data
.y
+ bypp
[1] * s
->data
.x
;
175 for (y
= s
->data
.dy
; y
> 0; y
--, src
+= bypl
[0], dst
+= bypl
[1])
176 fn(dst
, src
, bypl
[2]);
179 static int blizzard_transfer_setup(struct blizzard_s
*s
)
181 if (s
->source
> 3 || !s
->bpp
||
182 s
->ix
[1] < s
->ix
[0] || s
->iy
[1] < s
->iy
[0])
185 s
->data
.angle
= s
->effect
& 3;
186 s
->data
.line_fn
= s
->line_fn_tab
[!!s
->data
.angle
][s
->iformat
];
187 s
->data
.x
= s
->ix
[0];
188 s
->data
.y
= s
->iy
[0];
189 s
->data
.dx
= s
->ix
[1] - s
->ix
[0] + 1;
190 s
->data
.dy
= s
->iy
[1] - s
->iy
[0] + 1;
191 s
->data
.len
= s
->bpp
* s
->data
.dx
* s
->data
.dy
;
192 s
->data
.pitch
= s
->data
.dx
;
193 if (s
->data
.len
> s
->data
.buflen
) {
194 s
->data
.buf
= qemu_realloc(s
->data
.buf
, s
->data
.len
);
195 s
->data
.buflen
= s
->data
.len
;
197 s
->data
.ptr
= s
->data
.buf
;
198 s
->data
.data
= s
->data
.buf
;
203 static void blizzard_reset(struct blizzard_s
*s
)
214 s
->memrefresh
= 0x25c;
220 s
->lcd_config
= 0x74;
247 s
->bpp
= blizzard_iformat_bpp
[s
->iformat
];
249 s
->hssi_config
[0] = 0x00;
250 s
->hssi_config
[1] = 0x00;
251 s
->hssi_config
[2] = 0x01;
253 s
->tv_timing
[0] = 0x00;
254 s
->tv_timing
[1] = 0x00;
255 s
->tv_timing
[2] = 0x00;
256 s
->tv_timing
[3] = 0x00;
261 s
->tv_filter_config
= 0x80;
262 s
->tv_filter_idx
= 0x00;
266 s
->gamma_config
= 0x00;
268 s
->matrix_ena
= 0x00;
269 memset(&s
->matrix_coeff
, 0, sizeof(s
->matrix_coeff
));
275 s
->rgbgpio_dir
= 0x00;
277 s
->gpio_edge
[0] = 0x00;
278 s
->gpio_edge
[1] = 0x00;
280 s
->gpio_pdown
= 0xff;
283 static inline void blizzard_invalidate_display(void *opaque
) {
284 struct blizzard_s
*s
= (struct blizzard_s
*) opaque
;
289 static uint16_t blizzard_reg_read(void *opaque
, uint8_t reg
)
291 struct blizzard_s
*s
= (struct blizzard_s
*) opaque
;
294 case 0x00: /* Revision Code */
297 case 0x02: /* Configuration Readback */
298 return 0x83; /* Macrovision OK, CNF[2:0] = 3 */
300 case 0x04: /* PLL M-Divider */
301 return (s
->pll
- 1) | (1 << 7);
302 case 0x06: /* PLL Lock Range Control */
304 case 0x08: /* PLL Lock Synthesis Control 0 */
305 return s
->pll_ctrl
& 0xff;
306 case 0x0a: /* PLL Lock Synthesis Control 1 */
307 return s
->pll_ctrl
>> 8;
308 case 0x0c: /* PLL Mode Control 0 */
311 case 0x0e: /* Clock-Source Select */
314 case 0x10: /* Memory Controller Activate */
315 case 0x14: /* Memory Controller Bank 0 Status Flag */
318 case 0x18: /* Auto-Refresh Interval Setting 0 */
319 return s
->memrefresh
& 0xff;
320 case 0x1a: /* Auto-Refresh Interval Setting 1 */
321 return s
->memrefresh
>> 8;
323 case 0x1c: /* Power-On Sequence Timing Control */
325 case 0x1e: /* Timing Control 0 */
327 case 0x20: /* Timing Control 1 */
330 case 0x24: /* Arbitration Priority Control */
333 case 0x28: /* LCD Panel Configuration */
334 return s
->lcd_config
;
336 case 0x2a: /* LCD Horizontal Display Width */
338 case 0x2c: /* LCD Horizontal Non-display Period */
340 case 0x2e: /* LCD Vertical Display Height 0 */
342 case 0x30: /* LCD Vertical Display Height 1 */
344 case 0x32: /* LCD Vertical Non-display Period */
346 case 0x34: /* LCD HS Pulse-width */
348 case 0x36: /* LCd HS Pulse Start Position */
349 return s
->skipx
>> 3;
350 case 0x38: /* LCD VS Pulse-width */
352 case 0x3a: /* LCD VS Pulse Start Position */
355 case 0x3c: /* PCLK Polarity */
358 case 0x3e: /* High-speed Serial Interface Tx Configuration Port 0 */
359 return s
->hssi_config
[0];
360 case 0x40: /* High-speed Serial Interface Tx Configuration Port 1 */
361 return s
->hssi_config
[1];
362 case 0x42: /* High-speed Serial Interface Tx Mode */
363 return s
->hssi_config
[2];
364 case 0x44: /* TV Display Configuration */
366 case 0x46 ... 0x4c: /* TV Vertical Blanking Interval Data bits */
367 return s
->tv_timing
[(reg
- 0x46) >> 1];
368 case 0x4e: /* VBI: Closed Caption / XDS Control / Status */
370 case 0x50: /* TV Horizontal Start Position */
372 case 0x52: /* TV Vertical Start Position */
374 case 0x54: /* TV Test Pattern Setting */
376 case 0x56: /* TV Filter Setting */
377 return s
->tv_filter_config
;
378 case 0x58: /* TV Filter Coefficient Index */
379 return s
->tv_filter_idx
;
380 case 0x5a: /* TV Filter Coefficient Data */
381 if (s
->tv_filter_idx
< 0x20)
382 return s
->tv_filter_coeff
[s
->tv_filter_idx
++];
385 case 0x60: /* Input YUV/RGB Translate Mode 0 */
387 case 0x62: /* Input YUV/RGB Translate Mode 1 */
389 case 0x64: /* U Data Fix */
391 case 0x66: /* V Data Fix */
394 case 0x68: /* Display Mode */
397 case 0x6a: /* Special Effects */
400 case 0x6c: /* Input Window X Start Position 0 */
401 return s
->ix
[0] & 0xff;
402 case 0x6e: /* Input Window X Start Position 1 */
403 return s
->ix
[0] >> 3;
404 case 0x70: /* Input Window Y Start Position 0 */
405 return s
->ix
[0] & 0xff;
406 case 0x72: /* Input Window Y Start Position 1 */
407 return s
->ix
[0] >> 3;
408 case 0x74: /* Input Window X End Position 0 */
409 return s
->ix
[1] & 0xff;
410 case 0x76: /* Input Window X End Position 1 */
411 return s
->ix
[1] >> 3;
412 case 0x78: /* Input Window Y End Position 0 */
413 return s
->ix
[1] & 0xff;
414 case 0x7a: /* Input Window Y End Position 1 */
415 return s
->ix
[1] >> 3;
416 case 0x7c: /* Output Window X Start Position 0 */
417 return s
->ox
[0] & 0xff;
418 case 0x7e: /* Output Window X Start Position 1 */
419 return s
->ox
[0] >> 3;
420 case 0x80: /* Output Window Y Start Position 0 */
421 return s
->oy
[0] & 0xff;
422 case 0x82: /* Output Window Y Start Position 1 */
423 return s
->oy
[0] >> 3;
424 case 0x84: /* Output Window X End Position 0 */
425 return s
->ox
[1] & 0xff;
426 case 0x86: /* Output Window X End Position 1 */
427 return s
->ox
[1] >> 3;
428 case 0x88: /* Output Window Y End Position 0 */
429 return s
->oy
[1] & 0xff;
430 case 0x8a: /* Output Window Y End Position 1 */
431 return s
->oy
[1] >> 3;
433 case 0x8c: /* Input Data Format */
435 case 0x8e: /* Data Source Select */
437 case 0x90: /* Display Memory Data Port */
440 case 0xa8: /* Border Color 0 */
442 case 0xaa: /* Border Color 1 */
444 case 0xac: /* Border Color 2 */
447 case 0xb4: /* Gamma Correction Enable */
448 return s
->gamma_config
;
449 case 0xb6: /* Gamma Correction Table Index */
451 case 0xb8: /* Gamma Correction Table Data */
452 return s
->gamma_lut
[s
->gamma_idx
++];
454 case 0xba: /* 3x3 Matrix Enable */
455 return s
->matrix_ena
;
456 case 0xbc ... 0xde: /* Coefficient Registers */
457 return s
->matrix_coeff
[(reg
- 0xbc) >> 1];
458 case 0xe0: /* 3x3 Matrix Red Offset */
460 case 0xe2: /* 3x3 Matrix Green Offset */
462 case 0xe4: /* 3x3 Matrix Blue Offset */
465 case 0xe6: /* Power-save */
467 case 0xe8: /* Non-display Period Control / Status */
468 return s
->status
| (1 << 5);
469 case 0xea: /* RGB Interface Control */
470 return s
->rgbgpio_dir
;
471 case 0xec: /* RGB Interface Status */
473 case 0xee: /* General-purpose IO Pins Configuration */
475 case 0xf0: /* General-purpose IO Pins Status / Control */
477 case 0xf2: /* GPIO Positive Edge Interrupt Trigger */
478 return s
->gpio_edge
[0];
479 case 0xf4: /* GPIO Negative Edge Interrupt Trigger */
480 return s
->gpio_edge
[1];
481 case 0xf6: /* GPIO Interrupt Status */
483 case 0xf8: /* GPIO Pull-down Control */
484 return s
->gpio_pdown
;
487 fprintf(stderr
, "%s: unknown register %02x\n", __FUNCTION__
, reg
);
492 static void blizzard_reg_write(void *opaque
, uint8_t reg
, uint16_t value
)
494 struct blizzard_s
*s
= (struct blizzard_s
*) opaque
;
497 case 0x04: /* PLL M-Divider */
498 s
->pll
= (value
& 0x3f) + 1;
500 case 0x06: /* PLL Lock Range Control */
501 s
->pll_range
= value
& 3;
503 case 0x08: /* PLL Lock Synthesis Control 0 */
504 s
->pll_ctrl
&= 0xf00;
505 s
->pll_ctrl
|= (value
<< 0) & 0x0ff;
507 case 0x0a: /* PLL Lock Synthesis Control 1 */
508 s
->pll_ctrl
&= 0x0ff;
509 s
->pll_ctrl
|= (value
<< 8) & 0xf00;
511 case 0x0c: /* PLL Mode Control 0 */
512 s
->pll_mode
= value
& 0x77;
513 if ((value
& 3) == 0 || (value
& 3) == 3)
514 fprintf(stderr
, "%s: wrong PLL Control bits (%i)\n",
515 __FUNCTION__
, value
& 3);
518 case 0x0e: /* Clock-Source Select */
519 s
->clksel
= value
& 0xff;
522 case 0x10: /* Memory Controller Activate */
523 s
->memenable
= value
& 1;
525 case 0x14: /* Memory Controller Bank 0 Status Flag */
528 case 0x18: /* Auto-Refresh Interval Setting 0 */
529 s
->memrefresh
&= 0xf00;
530 s
->memrefresh
|= (value
<< 0) & 0x0ff;
532 case 0x1a: /* Auto-Refresh Interval Setting 1 */
533 s
->memrefresh
&= 0x0ff;
534 s
->memrefresh
|= (value
<< 8) & 0xf00;
537 case 0x1c: /* Power-On Sequence Timing Control */
538 s
->timing
[0] = value
& 0x7f;
540 case 0x1e: /* Timing Control 0 */
541 s
->timing
[1] = value
& 0x17;
543 case 0x20: /* Timing Control 1 */
544 s
->timing
[2] = value
& 0x35;
547 case 0x24: /* Arbitration Priority Control */
548 s
->priority
= value
& 1;
551 case 0x28: /* LCD Panel Configuration */
552 s
->lcd_config
= value
& 0xff;
553 if (value
& (1 << 7))
554 fprintf(stderr
, "%s: data swap not supported!\n", __FUNCTION__
);
557 case 0x2a: /* LCD Horizontal Display Width */
560 case 0x2c: /* LCD Horizontal Non-display Period */
561 s
->hndp
= value
& 0xff;
563 case 0x2e: /* LCD Vertical Display Height 0 */
565 s
->y
|= (value
<< 0) & 0x0ff;
567 case 0x30: /* LCD Vertical Display Height 1 */
569 s
->y
|= (value
<< 8) & 0x300;
571 case 0x32: /* LCD Vertical Non-display Period */
572 s
->vndp
= value
& 0xff;
574 case 0x34: /* LCD HS Pulse-width */
575 s
->hsync
= value
& 0xff;
577 case 0x36: /* LCD HS Pulse Start Position */
578 s
->skipx
= value
& 0xff;
580 case 0x38: /* LCD VS Pulse-width */
581 s
->vsync
= value
& 0xbf;
583 case 0x3a: /* LCD VS Pulse Start Position */
584 s
->skipy
= value
& 0xff;
587 case 0x3c: /* PCLK Polarity */
588 s
->pclk
= value
& 0x82;
589 /* Affects calculation of s->hndp, s->hsync and s->skipx. */
592 case 0x3e: /* High-speed Serial Interface Tx Configuration Port 0 */
593 s
->hssi_config
[0] = value
;
595 case 0x40: /* High-speed Serial Interface Tx Configuration Port 1 */
596 s
->hssi_config
[1] = value
;
597 if (((value
>> 4) & 3) == 3)
598 fprintf(stderr
, "%s: Illegal active-data-links value\n",
601 case 0x42: /* High-speed Serial Interface Tx Mode */
602 s
->hssi_config
[2] = value
& 0xbd;
605 case 0x44: /* TV Display Configuration */
606 s
->tv_config
= value
& 0xfe;
608 case 0x46 ... 0x4c: /* TV Vertical Blanking Interval Data bits 0 */
609 s
->tv_timing
[(reg
- 0x46) >> 1] = value
;
611 case 0x4e: /* VBI: Closed Caption / XDS Control / Status */
614 case 0x50: /* TV Horizontal Start Position */
617 case 0x52: /* TV Vertical Start Position */
618 s
->tv_y
= value
& 0x7f;
620 case 0x54: /* TV Test Pattern Setting */
623 case 0x56: /* TV Filter Setting */
624 s
->tv_filter_config
= value
& 0xbf;
626 case 0x58: /* TV Filter Coefficient Index */
627 s
->tv_filter_idx
= value
& 0x1f;
629 case 0x5a: /* TV Filter Coefficient Data */
630 if (s
->tv_filter_idx
< 0x20)
631 s
->tv_filter_coeff
[s
->tv_filter_idx
++] = value
;
634 case 0x60: /* Input YUV/RGB Translate Mode 0 */
635 s
->yrc
[0] = value
& 0xb0;
637 case 0x62: /* Input YUV/RGB Translate Mode 1 */
638 s
->yrc
[1] = value
& 0x30;
640 case 0x64: /* U Data Fix */
643 case 0x66: /* V Data Fix */
647 case 0x68: /* Display Mode */
648 if ((s
->mode
^ value
) & 3)
650 s
->mode
= value
& 0xb7;
651 s
->enable
= value
& 1;
652 s
->blank
= (value
>> 1) & 1;
653 if (value
& (1 << 4))
654 fprintf(stderr
, "%s: Macrovision enable attempt!\n", __FUNCTION__
);
657 case 0x6a: /* Special Effects */
658 s
->effect
= value
& 0xfb;
661 case 0x6c: /* Input Window X Start Position 0 */
663 s
->ix
[0] |= (value
<< 0) & 0x0ff;
665 case 0x6e: /* Input Window X Start Position 1 */
667 s
->ix
[0] |= (value
<< 8) & 0x300;
669 case 0x70: /* Input Window Y Start Position 0 */
671 s
->iy
[0] |= (value
<< 0) & 0x0ff;
673 case 0x72: /* Input Window Y Start Position 1 */
675 s
->iy
[0] |= (value
<< 8) & 0x300;
677 case 0x74: /* Input Window X End Position 0 */
679 s
->ix
[1] |= (value
<< 0) & 0x0ff;
681 case 0x76: /* Input Window X End Position 1 */
683 s
->ix
[1] |= (value
<< 8) & 0x300;
685 case 0x78: /* Input Window Y End Position 0 */
687 s
->iy
[1] |= (value
<< 0) & 0x0ff;
689 case 0x7a: /* Input Window Y End Position 1 */
691 s
->iy
[1] |= (value
<< 8) & 0x300;
693 case 0x7c: /* Output Window X Start Position 0 */
695 s
->ox
[0] |= (value
<< 0) & 0x0ff;
697 case 0x7e: /* Output Window X Start Position 1 */
699 s
->ox
[0] |= (value
<< 8) & 0x300;
701 case 0x80: /* Output Window Y Start Position 0 */
703 s
->oy
[0] |= (value
<< 0) & 0x0ff;
705 case 0x82: /* Output Window Y Start Position 1 */
707 s
->oy
[0] |= (value
<< 8) & 0x300;
709 case 0x84: /* Output Window X End Position 0 */
711 s
->ox
[1] |= (value
<< 0) & 0x0ff;
713 case 0x86: /* Output Window X End Position 1 */
715 s
->ox
[1] |= (value
<< 8) & 0x300;
717 case 0x88: /* Output Window Y End Position 0 */
719 s
->oy
[1] |= (value
<< 0) & 0x0ff;
721 case 0x8a: /* Output Window Y End Position 1 */
723 s
->oy
[1] |= (value
<< 8) & 0x300;
726 case 0x8c: /* Input Data Format */
727 s
->iformat
= value
& 0xf;
728 s
->bpp
= blizzard_iformat_bpp
[s
->iformat
];
730 fprintf(stderr
, "%s: Illegal or unsupported input format %x\n",
731 __FUNCTION__
, s
->iformat
);
733 case 0x8e: /* Data Source Select */
734 s
->source
= value
& 7;
735 /* Currently all windows will be "destructive overlays". */
736 if ((!(s
->effect
& (1 << 3)) && (s
->ix
[0] != s
->ox
[0] ||
737 s
->iy
[0] != s
->oy
[0] ||
738 s
->ix
[1] != s
->ox
[1] ||
739 s
->iy
[1] != s
->oy
[1])) ||
740 !((s
->ix
[1] - s
->ix
[0]) & (s
->iy
[1] - s
->iy
[0]) &
741 (s
->ox
[1] - s
->ox
[0]) & (s
->oy
[1] - s
->oy
[0]) & 1))
742 fprintf(stderr
, "%s: Illegal input/output window positions\n",
745 blizzard_transfer_setup(s
);
748 case 0x90: /* Display Memory Data Port */
749 if (!s
->data
.len
&& !blizzard_transfer_setup(s
))
752 *s
->data
.ptr
++ = value
;
753 if (-- s
->data
.len
== 0)
757 case 0xa8: /* Border Color 0 */
760 case 0xaa: /* Border Color 1 */
763 case 0xac: /* Border Color 2 */
767 case 0xb4: /* Gamma Correction Enable */
768 s
->gamma_config
= value
& 0x87;
770 case 0xb6: /* Gamma Correction Table Index */
771 s
->gamma_idx
= value
;
773 case 0xb8: /* Gamma Correction Table Data */
774 s
->gamma_lut
[s
->gamma_idx
++] = value
;
777 case 0xba: /* 3x3 Matrix Enable */
778 s
->matrix_ena
= value
& 1;
780 case 0xbc ... 0xde: /* Coefficient Registers */
781 s
->matrix_coeff
[(reg
- 0xbc) >> 1] = value
& ((reg
& 2) ? 0x80 : 0xff);
783 case 0xe0: /* 3x3 Matrix Red Offset */
786 case 0xe2: /* 3x3 Matrix Green Offset */
789 case 0xe4: /* 3x3 Matrix Blue Offset */
793 case 0xe6: /* Power-save */
794 s
->pm
= value
& 0x83;
795 if (value
& s
->mode
& 1)
796 fprintf(stderr
, "%s: The display must be disabled before entering "
797 "Standby Mode\n", __FUNCTION__
);
799 case 0xe8: /* Non-display Period Control / Status */
800 s
->status
= value
& 0x1b;
802 case 0xea: /* RGB Interface Control */
803 s
->rgbgpio_dir
= value
& 0x8f;
805 case 0xec: /* RGB Interface Status */
806 s
->rgbgpio
= value
& 0xcf;
808 case 0xee: /* General-purpose IO Pins Configuration */
811 case 0xf0: /* General-purpose IO Pins Status / Control */
814 case 0xf2: /* GPIO Positive Edge Interrupt Trigger */
815 s
->gpio_edge
[0] = value
;
817 case 0xf4: /* GPIO Negative Edge Interrupt Trigger */
818 s
->gpio_edge
[1] = value
;
820 case 0xf6: /* GPIO Interrupt Status */
821 s
->gpio_irq
&= value
;
823 case 0xf8: /* GPIO Pull-down Control */
824 s
->gpio_pdown
= value
;
828 fprintf(stderr
, "%s: unknown register %02x\n", __FUNCTION__
, reg
);
833 uint16_t s1d13745_read(void *opaque
, int dc
)
835 struct blizzard_s
*s
= (struct blizzard_s
*) opaque
;
836 uint16_t value
= blizzard_reg_read(s
, s
->reg
);
838 if (s
->swallow
-- > 0)
846 void s1d13745_write(void *opaque
, int dc
, uint16_t value
)
848 struct blizzard_s
*s
= (struct blizzard_s
*) opaque
;
850 if (s
->swallow
-- > 0)
853 blizzard_reg_write(s
, s
->reg
, value
);
855 if (s
->reg
!= 0x90 && s
->reg
!= 0x5a && s
->reg
!= 0xb8)
858 s
->reg
= value
& 0xff;
861 void s1d13745_write_block(void *opaque
, int dc
,
862 void *buf
, size_t len
, int pitch
)
864 struct blizzard_s
*s
= (struct blizzard_s
*) opaque
;
867 if (s
->reg
== 0x90 && dc
&&
868 (s
->data
.len
|| blizzard_transfer_setup(s
)) &&
869 len
>= (s
->data
.len
<< 1)) {
870 len
-= s
->data
.len
<< 1;
874 s
->data
.pitch
= pitch
;
876 s
->data
.data
= s
->data
.buf
;
880 s1d13745_write(opaque
, dc
, *(uint16_t *) buf
);
888 static void blizzard_update_display(void *opaque
)
890 struct blizzard_s
*s
= (struct blizzard_s
*) opaque
;
891 int y
, bypp
, bypl
, bwidth
;
897 if (s
->x
!= ds_get_width(s
->state
) || s
->y
!= ds_get_height(s
->state
)) {
899 qemu_console_resize(s
->console
, s
->x
, s
->y
);
906 bypp
= (ds_get_bits_per_pixel(s
->state
) + 7) >> 3;
907 memset(ds_get_data(s
->state
), 0, bypp
* s
->x
* s
->y
);
917 if (s
->mx
[1] <= s
->mx
[0])
920 bypp
= (ds_get_bits_per_pixel(s
->state
) + 7) >> 3;
922 bwidth
= bypp
* (s
->mx
[1] - s
->mx
[0]);
924 src
= s
->fb
+ bypl
* y
+ bypp
* s
->mx
[0];
925 dst
= ds_get_data(s
->state
) + bypl
* y
+ bypp
* s
->mx
[0];
926 for (; y
< s
->my
[1]; y
++, src
+= bypl
, dst
+= bypl
)
927 memcpy(dst
, src
, bwidth
);
929 dpy_update(s
->state
, s
->mx
[0], s
->my
[0],
930 s
->mx
[1] - s
->mx
[0], y
- s
->my
[0]);
938 static void blizzard_screen_dump(void *opaque
, const char *filename
) {
939 struct blizzard_s
*s
= (struct blizzard_s
*) opaque
;
941 blizzard_update_display(opaque
);
942 if (s
&& ds_get_data(s
->state
))
943 ppm_save(filename
, ds_get_data(s
->state
), s
->x
, s
->y
, ds_get_linesize(s
->state
));
947 #include "blizzard_template.h"
949 #include "blizzard_template.h"
951 #include "blizzard_template.h"
953 #include "blizzard_template.h"
955 #include "blizzard_template.h"
957 void *s1d13745_init(qemu_irq gpio_int
, DisplayState
*ds
)
959 struct blizzard_s
*s
= (struct blizzard_s
*) qemu_mallocz(sizeof(*s
));
962 s
->fb
= qemu_malloc(0x180000);
964 switch (ds_get_bits_per_pixel(s
->state
)) {
966 s
->line_fn_tab
[0] = s
->line_fn_tab
[1] =
967 qemu_mallocz(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__
);
996 s
->console
= graphic_console_init(s
->state
, blizzard_update_display
,
997 blizzard_invalidate_display
,
998 blizzard_screen_dump
, NULL
, s
);