2 * QEMU TCX Frame buffer
4 * Copyright (c) 2003-2005 Fabrice Bellard
6 * Permission is hereby granted, free of charge, to any person obtaining a copy
7 * of this software and associated documentation files (the "Software"), to deal
8 * in the Software without restriction, including without limitation the rights
9 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 * copies of the Software, and to permit persons to whom the Software is
11 * furnished to do so, subject to the following conditions:
13 * The above copyright notice and this permission notice shall be included in
14 * all copies or substantial portions of the Software.
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
25 #include "qemu/osdep.h"
26 #include "qemu-common.h"
27 #include "qapi/error.h"
28 #include "ui/console.h"
29 #include "ui/pixel_ops.h"
30 #include "hw/loader.h"
31 #include "hw/qdev-properties.h"
32 #include "hw/sysbus.h"
33 #include "migration/vmstate.h"
34 #include "qemu/error-report.h"
35 #include "qemu/module.h"
37 #define TCX_ROM_FILE "QEMU,tcx.bin"
38 #define FCODE_MAX_ROM_SIZE 0x10000
42 #define TCX_DAC_NREGS 16
43 #define TCX_THC_NREGS 0x1000
44 #define TCX_DHC_NREGS 0x4000
45 #define TCX_TEC_NREGS 0x1000
46 #define TCX_ALT_NREGS 0x8000
47 #define TCX_STIP_NREGS 0x800000
48 #define TCX_BLIT_NREGS 0x800000
49 #define TCX_RSTIP_NREGS 0x800000
50 #define TCX_RBLIT_NREGS 0x800000
52 #define TCX_THC_MISC 0x818
53 #define TCX_THC_CURSXY 0x8fc
54 #define TCX_THC_CURSMASK 0x900
55 #define TCX_THC_CURSBITS 0x980
57 #define TYPE_TCX "SUNW,tcx"
58 #define TCX(obj) OBJECT_CHECK(TCXState, (obj), TYPE_TCX)
60 typedef struct TCXState
{
61 SysBusDevice parent_obj
;
66 uint32_t *vram24
, *cplane
;
69 MemoryRegion vram_mem
;
70 MemoryRegion vram_8bit
;
71 MemoryRegion vram_24bit
;
74 MemoryRegion vram_cplane
;
84 ram_addr_t vram24_offset
, cplane_offset
;
87 uint32_t palette
[260];
88 uint8_t r
[260], g
[260], b
[260];
89 uint16_t width
, height
, depth
;
90 uint8_t dac_index
, dac_state
;
92 uint32_t cursmask
[32];
93 uint32_t cursbits
[32];
98 static void tcx_set_dirty(TCXState
*s
, ram_addr_t addr
, int len
)
100 memory_region_set_dirty(&s
->vram_mem
, addr
, len
);
102 if (s
->depth
== 24) {
103 memory_region_set_dirty(&s
->vram_mem
, s
->vram24_offset
+ addr
* 4,
105 memory_region_set_dirty(&s
->vram_mem
, s
->cplane_offset
+ addr
* 4,
110 static int tcx_check_dirty(TCXState
*s
, DirtyBitmapSnapshot
*snap
,
111 ram_addr_t addr
, int len
)
115 ret
= memory_region_snapshot_get_dirty(&s
->vram_mem
, snap
, addr
, len
);
117 if (s
->depth
== 24) {
118 ret
|= memory_region_snapshot_get_dirty(&s
->vram_mem
, snap
,
119 s
->vram24_offset
+ addr
* 4, len
* 4);
120 ret
|= memory_region_snapshot_get_dirty(&s
->vram_mem
, snap
,
121 s
->cplane_offset
+ addr
* 4, len
* 4);
127 static void update_palette_entries(TCXState
*s
, int start
, int end
)
129 DisplaySurface
*surface
= qemu_console_surface(s
->con
);
132 for (i
= start
; i
< end
; i
++) {
133 if (is_surface_bgr(surface
)) {
134 s
->palette
[i
] = rgb_to_pixel32bgr(s
->r
[i
], s
->g
[i
], s
->b
[i
]);
136 s
->palette
[i
] = rgb_to_pixel32(s
->r
[i
], s
->g
[i
], s
->b
[i
]);
139 tcx_set_dirty(s
, 0, memory_region_size(&s
->vram_mem
));
142 static void tcx_draw_line32(TCXState
*s1
, uint8_t *d
,
143 const uint8_t *s
, int width
)
147 uint32_t *p
= (uint32_t *)d
;
149 for (x
= 0; x
< width
; x
++) {
151 *p
++ = s1
->palette
[val
];
155 static void tcx_draw_cursor32(TCXState
*s1
, uint8_t *d
,
160 uint32_t *p
= (uint32_t *)d
;
163 mask
= s1
->cursmask
[y
];
164 bits
= s1
->cursbits
[y
];
165 len
= MIN(width
- s1
->cursx
, 32);
167 for (x
= 0; x
< len
; x
++) {
168 if (mask
& 0x80000000) {
169 if (bits
& 0x80000000) {
170 *p
= s1
->palette
[259];
172 *p
= s1
->palette
[258];
182 XXX Could be much more optimal:
183 * detect if line/page/whole screen is in 24 bit mode
184 * if destination is also BGR, use memcpy
186 static inline void tcx24_draw_line32(TCXState
*s1
, uint8_t *d
,
187 const uint8_t *s
, int width
,
188 const uint32_t *cplane
,
191 DisplaySurface
*surface
= qemu_console_surface(s1
->con
);
194 uint32_t *p
= (uint32_t *)d
;
196 bgr
= is_surface_bgr(surface
);
197 for(x
= 0; x
< width
; x
++, s
++, s24
++) {
198 if (be32_to_cpu(*cplane
) & 0x03000000) {
199 /* 24-bit direct, BGR order */
206 dval
= rgb_to_pixel32bgr(r
, g
, b
);
208 dval
= rgb_to_pixel32(r
, g
, b
);
210 /* 8-bit pseudocolor */
212 dval
= s1
->palette
[val
];
219 /* Fixed line length 1024 allows us to do nice tricks not possible on
222 static void tcx_update_display(void *opaque
)
224 TCXState
*ts
= opaque
;
225 DisplaySurface
*surface
= qemu_console_surface(ts
->con
);
227 DirtyBitmapSnapshot
*snap
= NULL
;
228 int y
, y_start
, dd
, ds
;
231 if (surface_bits_per_pixel(surface
) != 32) {
237 d
= surface_data(surface
);
239 dd
= surface_stride(surface
);
242 snap
= memory_region_snapshot_and_clear_dirty(&ts
->vram_mem
, 0x0,
243 memory_region_size(&ts
->vram_mem
),
246 for (y
= 0; y
< ts
->height
; y
++, page
+= ds
) {
247 if (tcx_check_dirty(ts
, snap
, page
, ds
)) {
251 tcx_draw_line32(ts
, d
, s
, ts
->width
);
252 if (y
>= ts
->cursy
&& y
< ts
->cursy
+ 32 && ts
->cursx
< ts
->width
) {
253 tcx_draw_cursor32(ts
, d
, y
, ts
->width
);
257 /* flush to display */
258 dpy_gfx_update(ts
->con
, 0, y_start
,
259 ts
->width
, y
- y_start
);
267 /* flush to display */
268 dpy_gfx_update(ts
->con
, 0, y_start
,
269 ts
->width
, y
- y_start
);
274 static void tcx24_update_display(void *opaque
)
276 TCXState
*ts
= opaque
;
277 DisplaySurface
*surface
= qemu_console_surface(ts
->con
);
279 DirtyBitmapSnapshot
*snap
= NULL
;
280 int y
, y_start
, dd
, ds
;
282 uint32_t *cptr
, *s24
;
284 if (surface_bits_per_pixel(surface
) != 32) {
290 d
= surface_data(surface
);
294 dd
= surface_stride(surface
);
297 snap
= memory_region_snapshot_and_clear_dirty(&ts
->vram_mem
, 0x0,
298 memory_region_size(&ts
->vram_mem
),
301 for (y
= 0; y
< ts
->height
; y
++, page
+= ds
) {
302 if (tcx_check_dirty(ts
, snap
, page
, ds
)) {
306 tcx24_draw_line32(ts
, d
, s
, ts
->width
, cptr
, s24
);
307 if (y
>= ts
->cursy
&& y
< ts
->cursy
+32 && ts
->cursx
< ts
->width
) {
308 tcx_draw_cursor32(ts
, d
, y
, ts
->width
);
312 /* flush to display */
313 dpy_gfx_update(ts
->con
, 0, y_start
,
314 ts
->width
, y
- y_start
);
324 /* flush to display */
325 dpy_gfx_update(ts
->con
, 0, y_start
,
326 ts
->width
, y
- y_start
);
331 static void tcx_invalidate_display(void *opaque
)
333 TCXState
*s
= opaque
;
335 tcx_set_dirty(s
, 0, memory_region_size(&s
->vram_mem
));
336 qemu_console_resize(s
->con
, s
->width
, s
->height
);
339 static void tcx24_invalidate_display(void *opaque
)
341 TCXState
*s
= opaque
;
343 tcx_set_dirty(s
, 0, memory_region_size(&s
->vram_mem
));
344 qemu_console_resize(s
->con
, s
->width
, s
->height
);
347 static int vmstate_tcx_post_load(void *opaque
, int version_id
)
349 TCXState
*s
= opaque
;
351 update_palette_entries(s
, 0, 256);
352 tcx_set_dirty(s
, 0, memory_region_size(&s
->vram_mem
));
356 static const VMStateDescription vmstate_tcx
= {
359 .minimum_version_id
= 4,
360 .post_load
= vmstate_tcx_post_load
,
361 .fields
= (VMStateField
[]) {
362 VMSTATE_UINT16(height
, TCXState
),
363 VMSTATE_UINT16(width
, TCXState
),
364 VMSTATE_UINT16(depth
, TCXState
),
365 VMSTATE_BUFFER(r
, TCXState
),
366 VMSTATE_BUFFER(g
, TCXState
),
367 VMSTATE_BUFFER(b
, TCXState
),
368 VMSTATE_UINT8(dac_index
, TCXState
),
369 VMSTATE_UINT8(dac_state
, TCXState
),
370 VMSTATE_END_OF_LIST()
374 static void tcx_reset(DeviceState
*d
)
376 TCXState
*s
= TCX(d
);
378 /* Initialize palette */
379 memset(s
->r
, 0, 260);
380 memset(s
->g
, 0, 260);
381 memset(s
->b
, 0, 260);
382 s
->r
[255] = s
->g
[255] = s
->b
[255] = 255;
383 s
->r
[256] = s
->g
[256] = s
->b
[256] = 255;
384 s
->r
[258] = s
->g
[258] = s
->b
[258] = 255;
385 update_palette_entries(s
, 0, 260);
386 memset(s
->vram
, 0, MAXX
*MAXY
);
387 memory_region_reset_dirty(&s
->vram_mem
, 0, MAXX
* MAXY
* (1 + 4 + 4),
391 s
->cursx
= 0xf000; /* Put cursor off screen */
395 static uint64_t tcx_dac_readl(void *opaque
, hwaddr addr
,
398 TCXState
*s
= opaque
;
401 switch (s
->dac_state
) {
403 val
= s
->r
[s
->dac_index
] << 24;
407 val
= s
->g
[s
->dac_index
] << 24;
411 val
= s
->b
[s
->dac_index
] << 24;
412 s
->dac_index
= (s
->dac_index
+ 1) & 0xff; /* Index autoincrement */
422 static void tcx_dac_writel(void *opaque
, hwaddr addr
, uint64_t val
,
425 TCXState
*s
= opaque
;
429 case 0: /* Address */
430 s
->dac_index
= val
>> 24;
433 case 4: /* Pixel colours */
434 case 12: /* Overlay (cursor) colours */
436 index
= (s
->dac_index
& 3) + 256;
438 index
= s
->dac_index
;
440 switch (s
->dac_state
) {
442 s
->r
[index
] = val
>> 24;
443 update_palette_entries(s
, index
, index
+ 1);
447 s
->g
[index
] = val
>> 24;
448 update_palette_entries(s
, index
, index
+ 1);
452 s
->b
[index
] = val
>> 24;
453 update_palette_entries(s
, index
, index
+ 1);
454 s
->dac_index
= (s
->dac_index
+ 1) & 0xff; /* Index autoincrement */
461 default: /* Control registers */
466 static const MemoryRegionOps tcx_dac_ops
= {
467 .read
= tcx_dac_readl
,
468 .write
= tcx_dac_writel
,
469 .endianness
= DEVICE_NATIVE_ENDIAN
,
471 .min_access_size
= 4,
472 .max_access_size
= 4,
476 static uint64_t tcx_stip_readl(void *opaque
, hwaddr addr
,
482 static void tcx_stip_writel(void *opaque
, hwaddr addr
,
483 uint64_t val
, unsigned size
)
485 TCXState
*s
= opaque
;
492 addr
= (addr
>> 3) & 0xfffff;
493 col
= cpu_to_be32(s
->tmpblit
);
494 if (s
->depth
== 24) {
495 for (i
= 0; i
< 32; i
++) {
496 if (val
& 0x80000000) {
497 s
->vram
[addr
+ i
] = s
->tmpblit
;
498 s
->vram24
[addr
+ i
] = col
;
503 for (i
= 0; i
< 32; i
++) {
504 if (val
& 0x80000000) {
505 s
->vram
[addr
+ i
] = s
->tmpblit
;
510 tcx_set_dirty(s
, addr
, 32);
514 static void tcx_rstip_writel(void *opaque
, hwaddr addr
,
515 uint64_t val
, unsigned size
)
517 TCXState
*s
= opaque
;
524 addr
= (addr
>> 3) & 0xfffff;
525 col
= cpu_to_be32(s
->tmpblit
);
526 if (s
->depth
== 24) {
527 for (i
= 0; i
< 32; i
++) {
528 if (val
& 0x80000000) {
529 s
->vram
[addr
+ i
] = s
->tmpblit
;
530 s
->vram24
[addr
+ i
] = col
;
531 s
->cplane
[addr
+ i
] = col
;
536 for (i
= 0; i
< 32; i
++) {
537 if (val
& 0x80000000) {
538 s
->vram
[addr
+ i
] = s
->tmpblit
;
543 tcx_set_dirty(s
, addr
, 32);
547 static const MemoryRegionOps tcx_stip_ops
= {
548 .read
= tcx_stip_readl
,
549 .write
= tcx_stip_writel
,
550 .endianness
= DEVICE_NATIVE_ENDIAN
,
552 .min_access_size
= 4,
553 .max_access_size
= 4,
557 static const MemoryRegionOps tcx_rstip_ops
= {
558 .read
= tcx_stip_readl
,
559 .write
= tcx_rstip_writel
,
560 .endianness
= DEVICE_NATIVE_ENDIAN
,
562 .min_access_size
= 4,
563 .max_access_size
= 4,
567 static uint64_t tcx_blit_readl(void *opaque
, hwaddr addr
,
573 static void tcx_blit_writel(void *opaque
, hwaddr addr
,
574 uint64_t val
, unsigned size
)
576 TCXState
*s
= opaque
;
583 addr
= (addr
>> 3) & 0xfffff;
584 adsr
= val
& 0xffffff;
585 len
= ((val
>> 24) & 0x1f) + 1;
586 if (adsr
== 0xffffff) {
587 memset(&s
->vram
[addr
], s
->tmpblit
, len
);
588 if (s
->depth
== 24) {
589 val
= s
->tmpblit
& 0xffffff;
590 val
= cpu_to_be32(val
);
591 for (i
= 0; i
< len
; i
++) {
592 s
->vram24
[addr
+ i
] = val
;
596 memcpy(&s
->vram
[addr
], &s
->vram
[adsr
], len
);
597 if (s
->depth
== 24) {
598 memcpy(&s
->vram24
[addr
], &s
->vram24
[adsr
], len
* 4);
601 tcx_set_dirty(s
, addr
, len
);
605 static void tcx_rblit_writel(void *opaque
, hwaddr addr
,
606 uint64_t val
, unsigned size
)
608 TCXState
*s
= opaque
;
615 addr
= (addr
>> 3) & 0xfffff;
616 adsr
= val
& 0xffffff;
617 len
= ((val
>> 24) & 0x1f) + 1;
618 if (adsr
== 0xffffff) {
619 memset(&s
->vram
[addr
], s
->tmpblit
, len
);
620 if (s
->depth
== 24) {
621 val
= s
->tmpblit
& 0xffffff;
622 val
= cpu_to_be32(val
);
623 for (i
= 0; i
< len
; i
++) {
624 s
->vram24
[addr
+ i
] = val
;
625 s
->cplane
[addr
+ i
] = val
;
629 memcpy(&s
->vram
[addr
], &s
->vram
[adsr
], len
);
630 if (s
->depth
== 24) {
631 memcpy(&s
->vram24
[addr
], &s
->vram24
[adsr
], len
* 4);
632 memcpy(&s
->cplane
[addr
], &s
->cplane
[adsr
], len
* 4);
635 tcx_set_dirty(s
, addr
, len
);
639 static const MemoryRegionOps tcx_blit_ops
= {
640 .read
= tcx_blit_readl
,
641 .write
= tcx_blit_writel
,
642 .endianness
= DEVICE_NATIVE_ENDIAN
,
644 .min_access_size
= 4,
645 .max_access_size
= 4,
649 static const MemoryRegionOps tcx_rblit_ops
= {
650 .read
= tcx_blit_readl
,
651 .write
= tcx_rblit_writel
,
652 .endianness
= DEVICE_NATIVE_ENDIAN
,
654 .min_access_size
= 4,
655 .max_access_size
= 4,
659 static void tcx_invalidate_cursor_position(TCXState
*s
)
661 int ymin
, ymax
, start
, end
;
663 /* invalidate only near the cursor */
665 if (ymin
>= s
->height
) {
668 ymax
= MIN(s
->height
, ymin
+ 32);
672 tcx_set_dirty(s
, start
, end
- start
);
675 static uint64_t tcx_thc_readl(void *opaque
, hwaddr addr
,
678 TCXState
*s
= opaque
;
681 if (addr
== TCX_THC_MISC
) {
682 val
= s
->thcmisc
| 0x02000000;
689 static void tcx_thc_writel(void *opaque
, hwaddr addr
,
690 uint64_t val
, unsigned size
)
692 TCXState
*s
= opaque
;
694 if (addr
== TCX_THC_CURSXY
) {
695 tcx_invalidate_cursor_position(s
);
696 s
->cursx
= val
>> 16;
698 tcx_invalidate_cursor_position(s
);
699 } else if (addr
>= TCX_THC_CURSMASK
&& addr
< TCX_THC_CURSMASK
+ 128) {
700 s
->cursmask
[(addr
- TCX_THC_CURSMASK
) >> 2] = val
;
701 tcx_invalidate_cursor_position(s
);
702 } else if (addr
>= TCX_THC_CURSBITS
&& addr
< TCX_THC_CURSBITS
+ 128) {
703 s
->cursbits
[(addr
- TCX_THC_CURSBITS
) >> 2] = val
;
704 tcx_invalidate_cursor_position(s
);
705 } else if (addr
== TCX_THC_MISC
) {
711 static const MemoryRegionOps tcx_thc_ops
= {
712 .read
= tcx_thc_readl
,
713 .write
= tcx_thc_writel
,
714 .endianness
= DEVICE_NATIVE_ENDIAN
,
716 .min_access_size
= 4,
717 .max_access_size
= 4,
721 static uint64_t tcx_dummy_readl(void *opaque
, hwaddr addr
,
727 static void tcx_dummy_writel(void *opaque
, hwaddr addr
,
728 uint64_t val
, unsigned size
)
733 static const MemoryRegionOps tcx_dummy_ops
= {
734 .read
= tcx_dummy_readl
,
735 .write
= tcx_dummy_writel
,
736 .endianness
= DEVICE_NATIVE_ENDIAN
,
738 .min_access_size
= 4,
739 .max_access_size
= 4,
743 static const GraphicHwOps tcx_ops
= {
744 .invalidate
= tcx_invalidate_display
,
745 .gfx_update
= tcx_update_display
,
748 static const GraphicHwOps tcx24_ops
= {
749 .invalidate
= tcx24_invalidate_display
,
750 .gfx_update
= tcx24_update_display
,
753 static void tcx_initfn(Object
*obj
)
755 SysBusDevice
*sbd
= SYS_BUS_DEVICE(obj
);
756 TCXState
*s
= TCX(obj
);
758 memory_region_init_rom_nomigrate(&s
->rom
, obj
, "tcx.prom",
759 FCODE_MAX_ROM_SIZE
, &error_fatal
);
760 sysbus_init_mmio(sbd
, &s
->rom
);
762 /* 2/STIP : Stippler */
763 memory_region_init_io(&s
->stip
, obj
, &tcx_stip_ops
, s
, "tcx.stip",
765 sysbus_init_mmio(sbd
, &s
->stip
);
767 /* 3/BLIT : Blitter */
768 memory_region_init_io(&s
->blit
, obj
, &tcx_blit_ops
, s
, "tcx.blit",
770 sysbus_init_mmio(sbd
, &s
->blit
);
772 /* 5/RSTIP : Raw Stippler */
773 memory_region_init_io(&s
->rstip
, obj
, &tcx_rstip_ops
, s
, "tcx.rstip",
775 sysbus_init_mmio(sbd
, &s
->rstip
);
777 /* 6/RBLIT : Raw Blitter */
778 memory_region_init_io(&s
->rblit
, obj
, &tcx_rblit_ops
, s
, "tcx.rblit",
780 sysbus_init_mmio(sbd
, &s
->rblit
);
783 memory_region_init_io(&s
->tec
, obj
, &tcx_dummy_ops
, s
, "tcx.tec",
785 sysbus_init_mmio(sbd
, &s
->tec
);
788 memory_region_init_io(&s
->dac
, obj
, &tcx_dac_ops
, s
, "tcx.dac",
790 sysbus_init_mmio(sbd
, &s
->dac
);
793 memory_region_init_io(&s
->thc
, obj
, &tcx_thc_ops
, s
, "tcx.thc",
795 sysbus_init_mmio(sbd
, &s
->thc
);
798 memory_region_init_io(&s
->dhc
, obj
, &tcx_dummy_ops
, s
, "tcx.dhc",
800 sysbus_init_mmio(sbd
, &s
->dhc
);
803 memory_region_init_io(&s
->alt
, obj
, &tcx_dummy_ops
, s
, "tcx.alt",
805 sysbus_init_mmio(sbd
, &s
->alt
);
808 static void tcx_realizefn(DeviceState
*dev
, Error
**errp
)
810 SysBusDevice
*sbd
= SYS_BUS_DEVICE(dev
);
811 TCXState
*s
= TCX(dev
);
812 ram_addr_t vram_offset
= 0;
815 char *fcode_filename
;
817 memory_region_init_ram_nomigrate(&s
->vram_mem
, OBJECT(s
), "tcx.vram",
818 s
->vram_size
* (1 + 4 + 4), &error_fatal
);
819 vmstate_register_ram_global(&s
->vram_mem
);
820 memory_region_set_log(&s
->vram_mem
, true, DIRTY_MEMORY_VGA
);
821 vram_base
= memory_region_get_ram_ptr(&s
->vram_mem
);
823 /* 10/ROM : FCode ROM */
824 vmstate_register_ram_global(&s
->rom
);
825 fcode_filename
= qemu_find_file(QEMU_FILE_TYPE_BIOS
, TCX_ROM_FILE
);
826 if (fcode_filename
) {
827 ret
= load_image_mr(fcode_filename
, &s
->rom
);
828 g_free(fcode_filename
);
829 if (ret
< 0 || ret
> FCODE_MAX_ROM_SIZE
) {
830 warn_report("tcx: could not load prom '%s'", TCX_ROM_FILE
);
834 /* 0/DFB8 : 8-bit plane */
837 memory_region_init_alias(&s
->vram_8bit
, OBJECT(s
), "tcx.vram.8bit",
838 &s
->vram_mem
, vram_offset
, size
);
839 sysbus_init_mmio(sbd
, &s
->vram_8bit
);
843 /* 1/DFB24 : 24bit plane */
844 size
= s
->vram_size
* 4;
845 s
->vram24
= (uint32_t *)vram_base
;
846 s
->vram24_offset
= vram_offset
;
847 memory_region_init_alias(&s
->vram_24bit
, OBJECT(s
), "tcx.vram.24bit",
848 &s
->vram_mem
, vram_offset
, size
);
849 sysbus_init_mmio(sbd
, &s
->vram_24bit
);
853 /* 4/RDFB32 : Raw Framebuffer */
854 size
= s
->vram_size
* 4;
855 s
->cplane
= (uint32_t *)vram_base
;
856 s
->cplane_offset
= vram_offset
;
857 memory_region_init_alias(&s
->vram_cplane
, OBJECT(s
), "tcx.vram.cplane",
858 &s
->vram_mem
, vram_offset
, size
);
859 sysbus_init_mmio(sbd
, &s
->vram_cplane
);
861 /* 9/THC24bits : NetBSD writes here even with 8-bit display: dummy */
863 memory_region_init_io(&s
->thc24
, OBJECT(s
), &tcx_dummy_ops
, s
,
864 "tcx.thc24", TCX_THC_NREGS
);
865 sysbus_init_mmio(sbd
, &s
->thc24
);
868 sysbus_init_irq(sbd
, &s
->irq
);
871 s
->con
= graphic_console_init(dev
, 0, &tcx_ops
, s
);
873 s
->con
= graphic_console_init(dev
, 0, &tcx24_ops
, s
);
877 qemu_console_resize(s
->con
, s
->width
, s
->height
);
880 static Property tcx_properties
[] = {
881 DEFINE_PROP_UINT32("vram_size", TCXState
, vram_size
, -1),
882 DEFINE_PROP_UINT16("width", TCXState
, width
, -1),
883 DEFINE_PROP_UINT16("height", TCXState
, height
, -1),
884 DEFINE_PROP_UINT16("depth", TCXState
, depth
, -1),
885 DEFINE_PROP_END_OF_LIST(),
888 static void tcx_class_init(ObjectClass
*klass
, void *data
)
890 DeviceClass
*dc
= DEVICE_CLASS(klass
);
892 dc
->realize
= tcx_realizefn
;
893 dc
->reset
= tcx_reset
;
894 dc
->vmsd
= &vmstate_tcx
;
895 device_class_set_props(dc
, tcx_properties
);
898 static const TypeInfo tcx_info
= {
900 .parent
= TYPE_SYS_BUS_DEVICE
,
901 .instance_size
= sizeof(TCXState
),
902 .instance_init
= tcx_initfn
,
903 .class_init
= tcx_class_init
,
906 static void tcx_register_types(void)
908 type_register_static(&tcx_info
);
911 type_init(tcx_register_types
)