2 * QEMU HP Artist Emulation
4 * Copyright (c) 2019 Sven Schnelle <svens@stackframe.org>
6 * This work is licensed under the terms of the GNU GPL, version 2 or later.
9 #include "qemu/osdep.h"
10 #include "qemu-common.h"
11 #include "qemu/error-report.h"
12 #include "qemu/typedefs.h"
14 #include "qemu/module.h"
15 #include "qemu/units.h"
16 #include "qapi/error.h"
17 #include "hw/sysbus.h"
18 #include "hw/loader.h"
19 #include "hw/qdev-core.h"
20 #include "hw/qdev-properties.h"
21 #include "migration/vmstate.h"
22 #include "ui/console.h"
24 #include "framebuffer.h"
25 #include "qom/object.h"
27 #define TYPE_ARTIST "artist"
28 typedef struct ARTISTState ARTISTState
;
29 DECLARE_INSTANCE_CHECKER(ARTISTState
, ARTIST
,
32 #ifdef HOST_WORDS_BIGENDIAN
33 #define ROP8OFF(_i) (3 - (_i))
47 SysBusDevice parent_obj
;
50 MemoryRegion vram_mem
;
51 MemoryRegion mem_as_root
;
53 MemoryRegionSection fbsection
;
58 struct vram_buffer vram_buffer
[16];
68 uint32_t vram_bitmask
;
75 uint32_t blockmove_source
;
76 uint32_t blockmove_dest
;
77 uint32_t blockmove_size
;
82 uint32_t line_pattern_start
;
83 uint32_t line_pattern_skip
;
87 uint32_t cursor_height
;
88 uint32_t cursor_width
;
97 uint32_t cmap_bm_access
;
98 uint32_t dst_bm_access
;
99 uint32_t src_bm_access
;
100 uint32_t control_plane
;
101 uint32_t transfer_data
;
102 uint32_t image_bitmap_op
;
104 uint32_t font_write1
;
105 uint32_t font_write2
;
106 uint32_t font_write_pos_y
;
108 int draw_line_pattern
;
112 ARTIST_BUFFER_AP
= 1,
113 ARTIST_BUFFER_OVERLAY
= 2,
114 ARTIST_BUFFER_CURSOR1
= 6,
115 ARTIST_BUFFER_CURSOR2
= 7,
116 ARTIST_BUFFER_ATTRIBUTE
= 13,
117 ARTIST_BUFFER_CMAP
= 15,
122 VRAM_BITMASK
= 0x1005a0,
123 VRAM_WRITE_INCR_X
= 0x100600,
124 VRAM_WRITE_INCR_X2
= 0x100604,
125 VRAM_WRITE_INCR_Y
= 0x100620,
126 VRAM_START
= 0x100800,
127 BLOCK_MOVE_SIZE
= 0x100804,
128 BLOCK_MOVE_SOURCE
= 0x100808,
129 TRANSFER_DATA
= 0x100820,
130 FONT_WRITE_INCR_Y
= 0x1008a0,
131 VRAM_START_TRIGGER
= 0x100a00,
132 VRAM_SIZE_TRIGGER
= 0x100a04,
133 FONT_WRITE_START
= 0x100aa0,
134 BLOCK_MOVE_DEST_TRIGGER
= 0x100b00,
135 BLOCK_MOVE_SIZE_TRIGGER
= 0x100b04,
137 PATTERN_LINE_START
= 0x100ecc,
138 LINE_SIZE
= 0x100e04,
140 CMAP_BM_ACCESS
= 0x118000,
141 DST_BM_ACCESS
= 0x118004,
142 SRC_BM_ACCESS
= 0x118008,
143 CONTROL_PLANE
= 0x11800c,
146 PLANE_MASK
= 0x118018,
147 IMAGE_BITMAP_OP
= 0x11801c,
148 CURSOR_POS
= 0x300100,
149 CURSOR_CTRL
= 0x300104,
153 ARTIST_ROP_CLEAR
= 0,
156 ARTIST_ROP_NOT_DST
= 10,
160 #define REG_NAME(_x) case _x: return " "#_x;
161 static const char *artist_reg_name(uint64_t addr
)
163 switch ((artist_reg_t
)addr
) {
165 REG_NAME(VRAM_BITMASK
);
166 REG_NAME(VRAM_WRITE_INCR_X
);
167 REG_NAME(VRAM_WRITE_INCR_X2
);
168 REG_NAME(VRAM_WRITE_INCR_Y
);
169 REG_NAME(VRAM_START
);
170 REG_NAME(BLOCK_MOVE_SIZE
);
171 REG_NAME(BLOCK_MOVE_SOURCE
);
174 REG_NAME(PLANE_MASK
);
175 REG_NAME(VRAM_START_TRIGGER
);
176 REG_NAME(VRAM_SIZE_TRIGGER
);
177 REG_NAME(BLOCK_MOVE_DEST_TRIGGER
);
178 REG_NAME(BLOCK_MOVE_SIZE_TRIGGER
);
179 REG_NAME(TRANSFER_DATA
);
180 REG_NAME(CONTROL_PLANE
);
181 REG_NAME(IMAGE_BITMAP_OP
);
182 REG_NAME(CMAP_BM_ACCESS
);
183 REG_NAME(DST_BM_ACCESS
);
184 REG_NAME(SRC_BM_ACCESS
);
185 REG_NAME(CURSOR_POS
);
186 REG_NAME(CURSOR_CTRL
);
188 REG_NAME(PATTERN_LINE_START
);
191 REG_NAME(FONT_WRITE_INCR_Y
);
192 REG_NAME(FONT_WRITE_START
);
198 /* artist has a fixed line length of 2048 bytes. */
199 #define ADDR_TO_Y(addr) extract32(addr, 11, 11)
200 #define ADDR_TO_X(addr) extract32(addr, 0, 11)
202 static int16_t artist_get_x(uint32_t reg
)
207 static int16_t artist_get_y(uint32_t reg
)
212 static void artist_invalidate_lines(struct vram_buffer
*buf
,
213 int starty
, int height
)
215 int start
= starty
* buf
->width
;
218 if (starty
+ height
> buf
->height
)
219 height
= buf
->height
- starty
;
221 size
= height
* buf
->width
;
223 if (start
+ size
<= buf
->size
) {
224 memory_region_set_dirty(&buf
->mr
, start
, size
);
228 static int vram_write_pix_per_transfer(ARTISTState
*s
)
230 if (s
->cmap_bm_access
) {
231 return 1 << ((s
->cmap_bm_access
>> 27) & 0x0f);
233 return 1 << ((s
->dst_bm_access
>> 27) & 0x0f);
237 static int vram_pixel_length(ARTISTState
*s
)
239 if (s
->cmap_bm_access
) {
240 return (s
->cmap_bm_access
>> 24) & 0x07;
242 return (s
->dst_bm_access
>> 24) & 0x07;
246 static int vram_write_bufidx(ARTISTState
*s
)
248 if (s
->cmap_bm_access
) {
249 return (s
->cmap_bm_access
>> 12) & 0x0f;
251 return (s
->dst_bm_access
>> 12) & 0x0f;
255 static int vram_read_bufidx(ARTISTState
*s
)
257 if (s
->cmap_bm_access
) {
258 return (s
->cmap_bm_access
>> 12) & 0x0f;
260 return (s
->src_bm_access
>> 12) & 0x0f;
264 static struct vram_buffer
*vram_read_buffer(ARTISTState
*s
)
266 return &s
->vram_buffer
[vram_read_bufidx(s
)];
269 static struct vram_buffer
*vram_write_buffer(ARTISTState
*s
)
271 return &s
->vram_buffer
[vram_write_bufidx(s
)];
274 static uint8_t artist_get_color(ARTISTState
*s
)
276 if (s
->image_bitmap_op
& 2) {
283 static artist_rop_t
artist_get_op(ARTISTState
*s
)
285 return (s
->image_bitmap_op
>> 8) & 0xf;
288 static void artist_rop8(ARTISTState
*s
, struct vram_buffer
*buf
,
289 unsigned int offset
, uint8_t val
)
291 const artist_rop_t op
= artist_get_op(s
);
295 if (offset
>= buf
->size
) {
296 qemu_log_mask(LOG_GUEST_ERROR
,
297 "rop8 offset:%u bufsize:%u\n", offset
, buf
->size
);
300 dst
= buf
->data
+ offset
;
301 plane_mask
= s
->plane_mask
& 0xff;
304 case ARTIST_ROP_CLEAR
:
308 case ARTIST_ROP_COPY
:
309 *dst
= (*dst
& ~plane_mask
) | (val
& plane_mask
);
313 *dst
^= val
& plane_mask
;
316 case ARTIST_ROP_NOT_DST
:
325 qemu_log_mask(LOG_UNIMP
, "%s: unsupported rop %d\n", __func__
, op
);
330 static void artist_get_cursor_pos(ARTISTState
*s
, int *x
, int *y
)
333 * Don't know whether these magic offset values are configurable via
334 * some register. They are the same for all resolutions, so don't
338 *y
= 0x47a - artist_get_y(s
->cursor_pos
);
339 *x
= ((artist_get_x(s
->cursor_pos
) - 338) / 2);
345 if (*y
> s
->height
) {
350 static void artist_invalidate_cursor(ARTISTState
*s
)
353 artist_get_cursor_pos(s
, &x
, &y
);
354 artist_invalidate_lines(&s
->vram_buffer
[ARTIST_BUFFER_AP
],
355 y
, s
->cursor_height
);
358 static void vram_bit_write(ARTISTState
*s
, int posy
, bool incr_x
,
359 int size
, uint32_t data
)
361 struct vram_buffer
*buf
;
362 uint32_t vram_bitmask
= s
->vram_bitmask
;
363 int mask
, i
, pix_count
, pix_length
;
364 unsigned int posx
, offset
, width
;
367 pix_count
= vram_write_pix_per_transfer(s
);
368 pix_length
= vram_pixel_length(s
);
370 buf
= vram_write_buffer(s
);
373 if (s
->cmap_bm_access
) {
374 offset
= s
->vram_pos
;
376 posx
= ADDR_TO_X(s
->vram_pos
>> 2);
377 posy
+= ADDR_TO_Y(s
->vram_pos
>> 2);
378 offset
= posy
* width
+ posx
;
381 if (!buf
->size
|| offset
>= buf
->size
) {
387 if (pix_count
> size
* 8) {
388 pix_count
= size
* 8;
391 switch (pix_length
) {
393 if (s
->image_bitmap_op
& 0x20000000) {
394 data
&= vram_bitmask
;
397 for (i
= 0; i
< pix_count
; i
++) {
398 uint32_t off
= offset
+ pix_count
- 1 - i
;
399 if (off
< buf
->size
) {
400 artist_rop8(s
, buf
, off
,
401 (data
& 1) ? (s
->plane_mask
>> 24) : 0);
405 memory_region_set_dirty(&buf
->mr
, offset
, pix_count
);
409 if (s
->cmap_bm_access
) {
410 if (offset
+ 3 < buf
->size
) {
411 *(uint32_t *)(p
+ offset
) = data
;
415 data8
= (uint8_t *)&data
;
417 for (i
= 3; i
>= 0; i
--) {
418 if (!(s
->image_bitmap_op
& 0x20000000) ||
419 s
->vram_bitmask
& (1 << (28 + i
))) {
420 uint32_t off
= offset
+ 3 - i
;
421 if (off
< buf
->size
) {
422 artist_rop8(s
, buf
, off
, data8
[ROP8OFF(i
)]);
426 memory_region_set_dirty(&buf
->mr
, offset
, 3);
433 vram_bitmask
= s
->vram_bitmask
;
437 vram_bitmask
= s
->vram_bitmask
>> 16;
441 vram_bitmask
= s
->vram_bitmask
>> 24;
445 for (i
= 0; i
< pix_count
&& offset
+ i
< buf
->size
; i
++) {
446 mask
= 1 << (pix_count
- 1 - i
);
448 if (!(s
->image_bitmap_op
& 0x20000000) ||
449 (vram_bitmask
& mask
)) {
451 artist_rop8(s
, buf
, offset
+ i
, s
->fg_color
);
453 if (!(s
->image_bitmap_op
& 0x10000002)) {
454 artist_rop8(s
, buf
, offset
+ i
, s
->bg_color
);
459 memory_region_set_dirty(&buf
->mr
, offset
, pix_count
);
463 qemu_log_mask(LOG_UNIMP
, "%s: unknown pixel length %d\n",
464 __func__
, pix_length
);
469 if (s
->cmap_bm_access
) {
472 s
->vram_pos
+= pix_count
<< 2;
476 if (vram_write_bufidx(s
) == ARTIST_BUFFER_CURSOR1
||
477 vram_write_bufidx(s
) == ARTIST_BUFFER_CURSOR2
) {
478 artist_invalidate_cursor(s
);
482 static void block_move(ARTISTState
*s
,
483 unsigned int source_x
, unsigned int source_y
,
484 unsigned int dest_x
, unsigned int dest_y
,
485 unsigned int width
, unsigned int height
)
487 struct vram_buffer
*buf
;
488 int line
, endline
, lineincr
, startcolumn
, endcolumn
, columnincr
, column
;
489 unsigned int dst
, src
;
491 trace_artist_block_move(source_x
, source_y
, dest_x
, dest_y
, width
, height
);
493 if (s
->control_plane
!= 0) {
494 /* We don't support CONTROL_PLANE accesses */
495 qemu_log_mask(LOG_UNIMP
, "%s: CONTROL_PLANE: %08x\n", __func__
,
500 buf
= &s
->vram_buffer
[ARTIST_BUFFER_AP
];
501 if (height
> buf
->height
) {
502 height
= buf
->height
;
504 if (width
> buf
->width
) {
508 if (dest_y
> source_y
) {
520 if (dest_x
> source_x
) {
522 startcolumn
= width
- 1;
532 for ( ; line
!= endline
; line
+= lineincr
) {
533 src
= source_x
+ ((line
+ source_y
) * buf
->width
) + startcolumn
;
534 dst
= dest_x
+ ((line
+ dest_y
) * buf
->width
) + startcolumn
;
536 for (column
= startcolumn
; column
!= endcolumn
; column
+= columnincr
) {
537 if (dst
>= buf
->size
|| src
>= buf
->size
) {
540 artist_rop8(s
, buf
, dst
, buf
->data
[src
]);
546 artist_invalidate_lines(buf
, dest_y
, height
);
549 static void fill_window(ARTISTState
*s
,
550 unsigned int startx
, unsigned int starty
,
551 unsigned int width
, unsigned int height
)
554 uint8_t color
= artist_get_color(s
);
555 struct vram_buffer
*buf
;
558 trace_artist_fill_window(startx
, starty
, width
, height
,
559 s
->image_bitmap_op
, s
->control_plane
);
561 if (s
->control_plane
!= 0) {
562 /* We don't support CONTROL_PLANE accesses */
563 qemu_log_mask(LOG_UNIMP
, "%s: CONTROL_PLANE: %08x\n", __func__
,
568 if (s
->reg_100080
== 0x7d) {
570 * Not sure what this register really does, but
571 * 0x7d seems to enable autoincremt of the Y axis
572 * by the current block move height.
574 height
= artist_get_y(s
->blockmove_size
);
575 s
->vram_start
+= height
;
578 buf
= &s
->vram_buffer
[ARTIST_BUFFER_AP
];
580 for (y
= starty
; y
< starty
+ height
; y
++) {
581 offset
= y
* s
->width
;
583 for (x
= startx
; x
< startx
+ width
; x
++) {
584 artist_rop8(s
, buf
, offset
+ x
, color
);
587 artist_invalidate_lines(buf
, starty
, height
);
590 static void draw_line(ARTISTState
*s
,
591 unsigned int x1
, unsigned int y1
,
592 unsigned int x2
, unsigned int y2
,
593 bool update_start
, int skip_pix
, int max_pix
)
595 struct vram_buffer
*buf
= &s
->vram_buffer
[ARTIST_BUFFER_AP
];
597 int dx
, dy
, t
, e
, x
, y
, incy
, diago
, horiz
;
600 trace_artist_draw_line(x1
, y1
, x2
, y2
);
602 if ((x1
>= buf
->width
&& x2
>= buf
->width
) ||
603 (y1
>= buf
->height
&& y2
>= buf
->height
)) {
609 s
->vram_start
= (x2
<< 16) | y2
;
651 diago
= (dy
- dx
) << 1;
661 color
= artist_get_color(s
);
667 ofs
= x
* s
->width
+ y
;
669 ofs
= y
* s
->width
+ x
;
675 artist_rop8(s
, buf
, ofs
, color
);
685 } while (x
<= x2
&& (max_pix
== -1 || --max_pix
> 0));
687 artist_invalidate_lines(buf
, x
, dy
+1);
689 artist_invalidate_lines(buf
, y
, dx
+1);
692 static void draw_line_pattern_start(ARTISTState
*s
)
695 int startx
= artist_get_x(s
->vram_start
);
696 int starty
= artist_get_y(s
->vram_start
);
697 int endx
= artist_get_x(s
->blockmove_size
);
698 int endy
= artist_get_y(s
->blockmove_size
);
699 int pstart
= s
->line_pattern_start
>> 16;
701 draw_line(s
, startx
, starty
, endx
, endy
, false, -1, pstart
);
702 s
->line_pattern_skip
= pstart
;
705 static void draw_line_pattern_next(ARTISTState
*s
)
708 int startx
= artist_get_x(s
->vram_start
);
709 int starty
= artist_get_y(s
->vram_start
);
710 int endx
= artist_get_x(s
->blockmove_size
);
711 int endy
= artist_get_y(s
->blockmove_size
);
712 int line_xy
= s
->line_xy
>> 16;
714 draw_line(s
, startx
, starty
, endx
, endy
, false, s
->line_pattern_skip
,
715 s
->line_pattern_skip
+ line_xy
);
716 s
->line_pattern_skip
+= line_xy
;
717 s
->image_bitmap_op
^= 2;
720 static void draw_line_size(ARTISTState
*s
, bool update_start
)
723 int startx
= artist_get_x(s
->vram_start
);
724 int starty
= artist_get_y(s
->vram_start
);
725 int endx
= artist_get_x(s
->line_size
);
726 int endy
= artist_get_y(s
->line_size
);
728 draw_line(s
, startx
, starty
, endx
, endy
, update_start
, -1, -1);
731 static void draw_line_xy(ARTISTState
*s
, bool update_start
)
734 int startx
= artist_get_x(s
->vram_start
);
735 int starty
= artist_get_y(s
->vram_start
);
736 int sizex
= artist_get_x(s
->blockmove_size
);
737 int sizey
= artist_get_y(s
->blockmove_size
);
738 int linexy
= s
->line_xy
>> 16;
745 endx
= startx
+ linexy
;
754 endy
= starty
+ linexy
;
778 draw_line(s
, startx
, starty
, endx
, endy
, false, -1, -1);
781 static void draw_line_end(ARTISTState
*s
, bool update_start
)
784 int startx
= artist_get_x(s
->vram_start
);
785 int starty
= artist_get_y(s
->vram_start
);
786 int endx
= artist_get_x(s
->line_end
);
787 int endy
= artist_get_y(s
->line_end
);
789 draw_line(s
, startx
, starty
, endx
, endy
, update_start
, -1, -1);
792 static void font_write16(ARTISTState
*s
, uint16_t val
)
794 struct vram_buffer
*buf
;
795 uint32_t color
= (s
->image_bitmap_op
& 2) ? s
->fg_color
: s
->bg_color
;
799 unsigned int startx
= artist_get_x(s
->vram_start
);
800 unsigned int starty
= artist_get_y(s
->vram_start
) + s
->font_write_pos_y
;
801 unsigned int offset
= starty
* s
->width
+ startx
;
803 buf
= &s
->vram_buffer
[ARTIST_BUFFER_AP
];
805 if (startx
>= buf
->width
|| starty
>= buf
->height
||
806 offset
+ 16 >= buf
->size
) {
810 for (i
= 0; i
< 16; i
++) {
811 mask
= 1 << (15 - i
);
813 artist_rop8(s
, buf
, offset
+ i
, color
);
815 if (!(s
->image_bitmap_op
& 0x20000000)) {
816 artist_rop8(s
, buf
, offset
+ i
, s
->bg_color
);
820 artist_invalidate_lines(buf
, starty
, 1);
823 static void font_write(ARTISTState
*s
, uint32_t val
)
825 font_write16(s
, val
>> 16);
826 if (++s
->font_write_pos_y
== artist_get_y(s
->blockmove_size
)) {
827 s
->vram_start
+= (s
->blockmove_size
& 0xffff0000);
831 font_write16(s
, val
& 0xffff);
832 if (++s
->font_write_pos_y
== artist_get_y(s
->blockmove_size
)) {
833 s
->vram_start
+= (s
->blockmove_size
& 0xffff0000);
838 static void combine_write_reg(hwaddr addr
, uint64_t val
, int size
, void *out
)
841 * FIXME: is there a qemu helper for this?
844 #ifndef HOST_WORDS_BIGENDIAN
850 *(uint8_t *)(out
+ (addr
& 3)) = val
;
854 *(uint16_t *)(out
+ (addr
& 2)) = val
;
858 *(uint32_t *)out
= val
;
862 qemu_log_mask(LOG_UNIMP
, "unsupported write size: %d\n", size
);
866 static void artist_reg_write(void *opaque
, hwaddr addr
, uint64_t val
,
869 ARTISTState
*s
= opaque
;
872 trace_artist_reg_write(size
, addr
, artist_reg_name(addr
& ~3ULL), val
);
874 switch (addr
& ~3ULL) {
876 combine_write_reg(addr
, val
, size
, &s
->reg_100080
);
880 combine_write_reg(addr
, val
, size
, &s
->fg_color
);
884 combine_write_reg(addr
, val
, size
, &s
->bg_color
);
888 combine_write_reg(addr
, val
, size
, &s
->vram_bitmask
);
891 case VRAM_WRITE_INCR_Y
:
892 vram_bit_write(s
, s
->vram_char_y
++, false, size
, val
);
895 case VRAM_WRITE_INCR_X
:
896 case VRAM_WRITE_INCR_X2
:
897 vram_bit_write(s
, s
->vram_char_y
, true, size
, val
);
901 combine_write_reg(addr
, val
, size
, &s
->vram_pos
);
903 s
->draw_line_pattern
= 0;
907 combine_write_reg(addr
, val
, size
, &s
->vram_start
);
908 s
->draw_line_pattern
= 0;
911 case VRAM_START_TRIGGER
:
912 combine_write_reg(addr
, val
, size
, &s
->vram_start
);
913 fill_window(s
, artist_get_x(s
->vram_start
),
914 artist_get_y(s
->vram_start
),
915 artist_get_x(s
->blockmove_size
),
916 artist_get_y(s
->blockmove_size
));
919 case VRAM_SIZE_TRIGGER
:
920 combine_write_reg(addr
, val
, size
, &s
->vram_size
);
922 if (size
== 2 && !(addr
& 2)) {
923 height
= artist_get_y(s
->blockmove_size
);
925 height
= artist_get_y(s
->vram_size
);
928 if (size
== 2 && (addr
& 2)) {
929 width
= artist_get_x(s
->blockmove_size
);
931 width
= artist_get_x(s
->vram_size
);
934 fill_window(s
, artist_get_x(s
->vram_start
),
935 artist_get_y(s
->vram_start
),
940 combine_write_reg(addr
, val
, size
, &s
->line_xy
);
941 if (s
->draw_line_pattern
) {
942 draw_line_pattern_next(s
);
944 draw_line_xy(s
, true);
948 case PATTERN_LINE_START
:
949 combine_write_reg(addr
, val
, size
, &s
->line_pattern_start
);
950 s
->draw_line_pattern
= 1;
951 draw_line_pattern_start(s
);
955 combine_write_reg(addr
, val
, size
, &s
->line_size
);
956 draw_line_size(s
, true);
960 combine_write_reg(addr
, val
, size
, &s
->line_end
);
961 draw_line_end(s
, true);
964 case BLOCK_MOVE_SIZE
:
965 combine_write_reg(addr
, val
, size
, &s
->blockmove_size
);
968 case BLOCK_MOVE_SOURCE
:
969 combine_write_reg(addr
, val
, size
, &s
->blockmove_source
);
972 case BLOCK_MOVE_DEST_TRIGGER
:
973 combine_write_reg(addr
, val
, size
, &s
->blockmove_dest
);
975 block_move(s
, artist_get_x(s
->blockmove_source
),
976 artist_get_y(s
->blockmove_source
),
977 artist_get_x(s
->blockmove_dest
),
978 artist_get_y(s
->blockmove_dest
),
979 artist_get_x(s
->blockmove_size
),
980 artist_get_y(s
->blockmove_size
));
983 case BLOCK_MOVE_SIZE_TRIGGER
:
984 combine_write_reg(addr
, val
, size
, &s
->blockmove_size
);
987 artist_get_x(s
->blockmove_source
),
988 artist_get_y(s
->blockmove_source
),
989 artist_get_x(s
->vram_start
),
990 artist_get_y(s
->vram_start
),
991 artist_get_x(s
->blockmove_size
),
992 artist_get_y(s
->blockmove_size
));
996 combine_write_reg(addr
, val
, size
, &s
->plane_mask
);
1000 combine_write_reg(addr
, val
, size
, &s
->cmap_bm_access
);
1004 combine_write_reg(addr
, val
, size
, &s
->dst_bm_access
);
1005 s
->cmap_bm_access
= 0;
1009 combine_write_reg(addr
, val
, size
, &s
->src_bm_access
);
1010 s
->cmap_bm_access
= 0;
1014 combine_write_reg(addr
, val
, size
, &s
->control_plane
);
1018 combine_write_reg(addr
, val
, size
, &s
->transfer_data
);
1022 combine_write_reg(addr
, val
, size
, &s
->reg_300200
);
1026 combine_write_reg(addr
, val
, size
, &s
->reg_300208
);
1030 combine_write_reg(addr
, val
, size
, &s
->reg_300218
);
1034 artist_invalidate_cursor(s
);
1035 combine_write_reg(addr
, val
, size
, &s
->cursor_pos
);
1036 artist_invalidate_cursor(s
);
1042 case IMAGE_BITMAP_OP
:
1043 combine_write_reg(addr
, val
, size
, &s
->image_bitmap_op
);
1046 case FONT_WRITE_INCR_Y
:
1047 combine_write_reg(addr
, val
, size
, &s
->font_write1
);
1048 font_write(s
, s
->font_write1
);
1051 case FONT_WRITE_START
:
1052 combine_write_reg(addr
, val
, size
, &s
->font_write2
);
1053 s
->font_write_pos_y
= 0;
1054 font_write(s
, s
->font_write2
);
1061 qemu_log_mask(LOG_UNIMP
, "%s: unknown register: reg=%08" HWADDR_PRIx
1062 " val=%08" PRIx64
" size=%d\n",
1063 __func__
, addr
, val
, size
);
1068 static uint64_t combine_read_reg(hwaddr addr
, int size
, void *in
)
1071 * FIXME: is there a qemu helper for this?
1074 #ifndef HOST_WORDS_BIGENDIAN
1080 return *(uint8_t *)(in
+ (addr
& 3));
1083 return *(uint16_t *)(in
+ (addr
& 2));
1086 return *(uint32_t *)in
;
1089 qemu_log_mask(LOG_UNIMP
, "unsupported read size: %d\n", size
);
1094 static uint64_t artist_reg_read(void *opaque
, hwaddr addr
, unsigned size
)
1096 ARTISTState
*s
= opaque
;
1099 switch (addr
& ~3ULL) {
1100 /* Unknown status registers */
1105 val
= (s
->width
<< 16) | s
->height
;
1106 if (s
->depth
== 1) {
1121 * FIFO ready flag. we're not emulating the FIFOs
1122 * so we're always ready
1128 val
= s
->reg_300200
;
1132 val
= s
->reg_300208
;
1136 val
= s
->reg_300218
;
1144 /* 0x02000000 Buserror */
1149 qemu_log_mask(LOG_UNIMP
, "%s: unknown register: %08" HWADDR_PRIx
1150 " size %d\n", __func__
, addr
, size
);
1153 val
= combine_read_reg(addr
, size
, &val
);
1154 trace_artist_reg_read(size
, addr
, artist_reg_name(addr
& ~3ULL), val
);
1158 static void artist_vram_write(void *opaque
, hwaddr addr
, uint64_t val
,
1161 ARTISTState
*s
= opaque
;
1162 struct vram_buffer
*buf
;
1163 unsigned int posy
, posx
;
1164 unsigned int offset
;
1165 trace_artist_vram_write(size
, addr
, val
);
1167 if (s
->cmap_bm_access
) {
1168 buf
= &s
->vram_buffer
[ARTIST_BUFFER_CMAP
];
1169 if (addr
+ 3 < buf
->size
) {
1170 *(uint32_t *)(buf
->data
+ addr
) = val
;
1175 buf
= vram_write_buffer(s
);
1176 posy
= ADDR_TO_Y(addr
);
1177 posx
= ADDR_TO_X(addr
);
1183 if (posy
> buf
->height
|| posx
> buf
->width
) {
1187 offset
= posy
* buf
->width
+ posx
;
1188 if (offset
>= buf
->size
) {
1194 if (offset
+ 3 < buf
->size
) {
1195 *(uint32_t *)(buf
->data
+ offset
) = be32_to_cpu(val
);
1196 memory_region_set_dirty(&buf
->mr
, offset
, 4);
1200 if (offset
+ 1 < buf
->size
) {
1201 *(uint16_t *)(buf
->data
+ offset
) = be16_to_cpu(val
);
1202 memory_region_set_dirty(&buf
->mr
, offset
, 2);
1206 if (offset
< buf
->size
) {
1207 *(uint8_t *)(buf
->data
+ offset
) = val
;
1208 memory_region_set_dirty(&buf
->mr
, offset
, 1);
1216 static uint64_t artist_vram_read(void *opaque
, hwaddr addr
, unsigned size
)
1218 ARTISTState
*s
= opaque
;
1219 struct vram_buffer
*buf
;
1221 unsigned int posy
, posx
;
1223 if (s
->cmap_bm_access
) {
1224 buf
= &s
->vram_buffer
[ARTIST_BUFFER_CMAP
];
1226 if (addr
< buf
->size
&& addr
+ 3 < buf
->size
) {
1227 val
= *(uint32_t *)(buf
->data
+ addr
);
1229 trace_artist_vram_read(size
, addr
, 0, 0, val
);
1233 buf
= vram_read_buffer(s
);
1238 posy
= ADDR_TO_Y(addr
);
1239 posx
= ADDR_TO_X(addr
);
1241 if (posy
> buf
->height
|| posx
> buf
->width
) {
1245 val
= cpu_to_be32(*(uint32_t *)(buf
->data
+ posy
* buf
->width
+ posx
));
1246 trace_artist_vram_read(size
, addr
, posx
, posy
, val
);
1250 static const MemoryRegionOps artist_reg_ops
= {
1251 .read
= artist_reg_read
,
1252 .write
= artist_reg_write
,
1253 .endianness
= DEVICE_NATIVE_ENDIAN
,
1254 .impl
.min_access_size
= 1,
1255 .impl
.max_access_size
= 4,
1258 static const MemoryRegionOps artist_vram_ops
= {
1259 .read
= artist_vram_read
,
1260 .write
= artist_vram_write
,
1261 .endianness
= DEVICE_NATIVE_ENDIAN
,
1262 .impl
.min_access_size
= 1,
1263 .impl
.max_access_size
= 4,
1266 static void artist_draw_cursor(ARTISTState
*s
)
1268 DisplaySurface
*surface
= qemu_console_surface(s
->con
);
1269 uint32_t *data
= (uint32_t *)surface_data(surface
);
1270 struct vram_buffer
*cursor0
, *cursor1
, *buf
;
1271 int cx
, cy
, cursor_pos_x
, cursor_pos_y
;
1273 cursor0
= &s
->vram_buffer
[ARTIST_BUFFER_CURSOR1
];
1274 cursor1
= &s
->vram_buffer
[ARTIST_BUFFER_CURSOR2
];
1275 buf
= &s
->vram_buffer
[ARTIST_BUFFER_AP
];
1277 artist_get_cursor_pos(s
, &cursor_pos_x
, &cursor_pos_y
);
1279 for (cy
= 0; cy
< s
->cursor_height
; cy
++) {
1281 for (cx
= 0; cx
< s
->cursor_width
; cx
++) {
1283 if (cursor_pos_y
+ cy
< 0 ||
1284 cursor_pos_x
+ cx
< 0 ||
1285 cursor_pos_y
+ cy
> buf
->height
- 1 ||
1286 cursor_pos_x
+ cx
> buf
->width
) {
1290 int dstoffset
= (cursor_pos_y
+ cy
) * s
->width
+
1291 (cursor_pos_x
+ cx
);
1293 if (cursor0
->data
[cy
* cursor0
->width
+ cx
]) {
1294 data
[dstoffset
] = 0;
1296 if (cursor1
->data
[cy
* cursor1
->width
+ cx
]) {
1297 data
[dstoffset
] = 0xffffff;
1304 static void artist_draw_line(void *opaque
, uint8_t *d
, const uint8_t *src
,
1305 int width
, int pitch
)
1307 ARTISTState
*s
= ARTIST(opaque
);
1308 uint32_t *cmap
, *data
= (uint32_t *)d
;
1311 cmap
= (uint32_t *)(s
->vram_buffer
[ARTIST_BUFFER_CMAP
].data
+ 0x400);
1313 for (x
= 0; x
< s
->width
; x
++) {
1314 *data
++ = cmap
[*src
++];
1318 static void artist_update_display(void *opaque
)
1320 ARTISTState
*s
= opaque
;
1321 DisplaySurface
*surface
= qemu_console_surface(s
->con
);
1322 int first
= 0, last
;
1325 framebuffer_update_display(surface
, &s
->fbsection
, s
->width
, s
->height
,
1326 s
->width
, s
->width
* 4, 0, 0, artist_draw_line
,
1329 artist_draw_cursor(s
);
1331 dpy_gfx_update(s
->con
, 0, 0, s
->width
, s
->height
);
1334 static void artist_invalidate(void *opaque
)
1336 ARTISTState
*s
= ARTIST(opaque
);
1337 struct vram_buffer
*buf
= &s
->vram_buffer
[ARTIST_BUFFER_AP
];
1338 memory_region_set_dirty(&buf
->mr
, 0, buf
->size
);
1341 static const GraphicHwOps artist_ops
= {
1342 .invalidate
= artist_invalidate
,
1343 .gfx_update
= artist_update_display
,
1346 static void artist_initfn(Object
*obj
)
1348 SysBusDevice
*sbd
= SYS_BUS_DEVICE(obj
);
1349 ARTISTState
*s
= ARTIST(obj
);
1351 memory_region_init_io(&s
->reg
, obj
, &artist_reg_ops
, s
, "artist.reg",
1353 memory_region_init_io(&s
->vram_mem
, obj
, &artist_vram_ops
, s
, "artist.vram",
1355 sysbus_init_mmio(sbd
, &s
->reg
);
1356 sysbus_init_mmio(sbd
, &s
->vram_mem
);
1359 static void artist_create_buffer(ARTISTState
*s
, const char *name
,
1360 hwaddr
*offset
, unsigned int idx
,
1361 int width
, int height
)
1363 struct vram_buffer
*buf
= s
->vram_buffer
+ idx
;
1365 memory_region_init_ram(&buf
->mr
, NULL
, name
, width
* height
,
1367 memory_region_add_subregion_overlap(&s
->mem_as_root
, *offset
, &buf
->mr
, 0);
1369 buf
->data
= memory_region_get_ram_ptr(&buf
->mr
);
1370 buf
->size
= height
* width
;
1372 buf
->height
= height
;
1374 *offset
+= buf
->size
;
1377 static void artist_realizefn(DeviceState
*dev
, Error
**errp
)
1379 ARTISTState
*s
= ARTIST(dev
);
1380 struct vram_buffer
*buf
;
1383 if (s
->width
> 2048 || s
->height
> 2048) {
1384 error_report("artist: screen size can not exceed 2048 x 2048 pixel.");
1385 s
->width
= MIN(s
->width
, 2048);
1386 s
->height
= MIN(s
->height
, 2048);
1389 if (s
->width
< 640 || s
->height
< 480) {
1390 error_report("artist: minimum screen size is 640 x 480 pixel.");
1391 s
->width
= MAX(s
->width
, 640);
1392 s
->height
= MAX(s
->height
, 480);
1395 memory_region_init(&s
->mem_as_root
, OBJECT(dev
), "artist", ~0ull);
1396 address_space_init(&s
->as
, &s
->mem_as_root
, "artist");
1398 artist_create_buffer(s
, "cmap", &offset
, ARTIST_BUFFER_CMAP
, 2048, 4);
1399 artist_create_buffer(s
, "ap", &offset
, ARTIST_BUFFER_AP
,
1400 s
->width
, s
->height
);
1401 artist_create_buffer(s
, "cursor1", &offset
, ARTIST_BUFFER_CURSOR1
, 64, 64);
1402 artist_create_buffer(s
, "cursor2", &offset
, ARTIST_BUFFER_CURSOR2
, 64, 64);
1403 artist_create_buffer(s
, "attribute", &offset
, ARTIST_BUFFER_ATTRIBUTE
,
1406 buf
= &s
->vram_buffer
[ARTIST_BUFFER_AP
];
1407 framebuffer_update_memory_section(&s
->fbsection
, &buf
->mr
, 0,
1408 buf
->width
, buf
->height
);
1410 * no idea whether the cursor is fixed size or not, so assume 32x32 which
1411 * seems sufficient for HP-UX X11.
1413 s
->cursor_height
= 32;
1414 s
->cursor_width
= 32;
1416 s
->con
= graphic_console_init(dev
, 0, &artist_ops
, s
);
1417 qemu_console_resize(s
->con
, s
->width
, s
->height
);
1420 static int vmstate_artist_post_load(void *opaque
, int version_id
)
1422 artist_invalidate(opaque
);
1426 static const VMStateDescription vmstate_artist
= {
1429 .minimum_version_id
= 1,
1430 .post_load
= vmstate_artist_post_load
,
1431 .fields
= (VMStateField
[]) {
1432 VMSTATE_UINT16(height
, ARTISTState
),
1433 VMSTATE_UINT16(width
, ARTISTState
),
1434 VMSTATE_UINT16(depth
, ARTISTState
),
1435 VMSTATE_UINT32(fg_color
, ARTISTState
),
1436 VMSTATE_UINT32(bg_color
, ARTISTState
),
1437 VMSTATE_UINT32(vram_char_y
, ARTISTState
),
1438 VMSTATE_UINT32(vram_bitmask
, ARTISTState
),
1439 VMSTATE_UINT32(vram_start
, ARTISTState
),
1440 VMSTATE_UINT32(vram_pos
, ARTISTState
),
1441 VMSTATE_UINT32(vram_size
, ARTISTState
),
1442 VMSTATE_UINT32(blockmove_source
, ARTISTState
),
1443 VMSTATE_UINT32(blockmove_dest
, ARTISTState
),
1444 VMSTATE_UINT32(blockmove_size
, ARTISTState
),
1445 VMSTATE_UINT32(line_size
, ARTISTState
),
1446 VMSTATE_UINT32(line_end
, ARTISTState
),
1447 VMSTATE_UINT32(line_xy
, ARTISTState
),
1448 VMSTATE_UINT32(cursor_pos
, ARTISTState
),
1449 VMSTATE_UINT32(cursor_height
, ARTISTState
),
1450 VMSTATE_UINT32(cursor_width
, ARTISTState
),
1451 VMSTATE_UINT32(plane_mask
, ARTISTState
),
1452 VMSTATE_UINT32(reg_100080
, ARTISTState
),
1453 VMSTATE_UINT32(reg_300200
, ARTISTState
),
1454 VMSTATE_UINT32(reg_300208
, ARTISTState
),
1455 VMSTATE_UINT32(reg_300218
, ARTISTState
),
1456 VMSTATE_UINT32(cmap_bm_access
, ARTISTState
),
1457 VMSTATE_UINT32(dst_bm_access
, ARTISTState
),
1458 VMSTATE_UINT32(src_bm_access
, ARTISTState
),
1459 VMSTATE_UINT32(control_plane
, ARTISTState
),
1460 VMSTATE_UINT32(transfer_data
, ARTISTState
),
1461 VMSTATE_UINT32(image_bitmap_op
, ARTISTState
),
1462 VMSTATE_UINT32(font_write1
, ARTISTState
),
1463 VMSTATE_UINT32(font_write2
, ARTISTState
),
1464 VMSTATE_UINT32(font_write_pos_y
, ARTISTState
),
1465 VMSTATE_END_OF_LIST()
1469 static Property artist_properties
[] = {
1470 DEFINE_PROP_UINT16("width", ARTISTState
, width
, 1280),
1471 DEFINE_PROP_UINT16("height", ARTISTState
, height
, 1024),
1472 DEFINE_PROP_UINT16("depth", ARTISTState
, depth
, 8),
1473 DEFINE_PROP_END_OF_LIST(),
1476 static void artist_reset(DeviceState
*qdev
)
1480 static void artist_class_init(ObjectClass
*klass
, void *data
)
1482 DeviceClass
*dc
= DEVICE_CLASS(klass
);
1484 dc
->realize
= artist_realizefn
;
1485 dc
->vmsd
= &vmstate_artist
;
1486 dc
->reset
= artist_reset
;
1487 device_class_set_props(dc
, artist_properties
);
1490 static const TypeInfo artist_info
= {
1491 .name
= TYPE_ARTIST
,
1492 .parent
= TYPE_SYS_BUS_DEVICE
,
1493 .instance_size
= sizeof(ARTISTState
),
1494 .instance_init
= artist_initfn
,
1495 .class_init
= artist_class_init
,
1498 static void artist_register_types(void)
1500 type_register_static(&artist_info
);
1503 type_init(artist_register_types
)