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"
26 #define TYPE_ARTIST "artist"
27 #define ARTIST(obj) OBJECT_CHECK(ARTISTState, (obj), TYPE_ARTIST)
29 #ifdef HOST_WORDS_BIGENDIAN
30 #define ROP8OFF(_i) (3 - (_i))
43 typedef struct ARTISTState
{
44 SysBusDevice parent_obj
;
47 MemoryRegion vram_mem
;
48 MemoryRegion mem_as_root
;
50 MemoryRegionSection fbsection
;
55 struct vram_buffer vram_buffer
[16];
65 uint32_t vram_bitmask
;
72 uint32_t blockmove_source
;
73 uint32_t blockmove_dest
;
74 uint32_t blockmove_size
;
79 uint32_t line_pattern_start
;
80 uint32_t line_pattern_skip
;
84 uint32_t cursor_height
;
85 uint32_t cursor_width
;
94 uint32_t cmap_bm_access
;
95 uint32_t dst_bm_access
;
96 uint32_t src_bm_access
;
97 uint32_t control_plane
;
98 uint32_t transfer_data
;
99 uint32_t image_bitmap_op
;
101 uint32_t font_write1
;
102 uint32_t font_write2
;
103 uint32_t font_write_pos_y
;
105 int draw_line_pattern
;
109 ARTIST_BUFFER_AP
= 1,
110 ARTIST_BUFFER_OVERLAY
= 2,
111 ARTIST_BUFFER_CURSOR1
= 6,
112 ARTIST_BUFFER_CURSOR2
= 7,
113 ARTIST_BUFFER_ATTRIBUTE
= 13,
114 ARTIST_BUFFER_CMAP
= 15,
119 VRAM_BITMASK
= 0x1005a0,
120 VRAM_WRITE_INCR_X
= 0x100600,
121 VRAM_WRITE_INCR_X2
= 0x100604,
122 VRAM_WRITE_INCR_Y
= 0x100620,
123 VRAM_START
= 0x100800,
124 BLOCK_MOVE_SIZE
= 0x100804,
125 BLOCK_MOVE_SOURCE
= 0x100808,
126 TRANSFER_DATA
= 0x100820,
127 FONT_WRITE_INCR_Y
= 0x1008a0,
128 VRAM_START_TRIGGER
= 0x100a00,
129 VRAM_SIZE_TRIGGER
= 0x100a04,
130 FONT_WRITE_START
= 0x100aa0,
131 BLOCK_MOVE_DEST_TRIGGER
= 0x100b00,
132 BLOCK_MOVE_SIZE_TRIGGER
= 0x100b04,
134 PATTERN_LINE_START
= 0x100ecc,
135 LINE_SIZE
= 0x100e04,
137 CMAP_BM_ACCESS
= 0x118000,
138 DST_BM_ACCESS
= 0x118004,
139 SRC_BM_ACCESS
= 0x118008,
140 CONTROL_PLANE
= 0x11800c,
143 PLANE_MASK
= 0x118018,
144 IMAGE_BITMAP_OP
= 0x11801c,
145 CURSOR_POS
= 0x300100,
146 CURSOR_CTRL
= 0x300104,
150 ARTIST_ROP_CLEAR
= 0,
153 ARTIST_ROP_NOT_DST
= 10,
157 #define REG_NAME(_x) case _x: return " "#_x;
158 static const char *artist_reg_name(uint64_t addr
)
160 switch ((artist_reg_t
)addr
) {
162 REG_NAME(VRAM_BITMASK
);
163 REG_NAME(VRAM_WRITE_INCR_X
);
164 REG_NAME(VRAM_WRITE_INCR_X2
);
165 REG_NAME(VRAM_WRITE_INCR_Y
);
166 REG_NAME(VRAM_START
);
167 REG_NAME(BLOCK_MOVE_SIZE
);
168 REG_NAME(BLOCK_MOVE_SOURCE
);
171 REG_NAME(PLANE_MASK
);
172 REG_NAME(VRAM_START_TRIGGER
);
173 REG_NAME(VRAM_SIZE_TRIGGER
);
174 REG_NAME(BLOCK_MOVE_DEST_TRIGGER
);
175 REG_NAME(BLOCK_MOVE_SIZE_TRIGGER
);
176 REG_NAME(TRANSFER_DATA
);
177 REG_NAME(CONTROL_PLANE
);
178 REG_NAME(IMAGE_BITMAP_OP
);
179 REG_NAME(CMAP_BM_ACCESS
);
180 REG_NAME(DST_BM_ACCESS
);
181 REG_NAME(SRC_BM_ACCESS
);
182 REG_NAME(CURSOR_POS
);
183 REG_NAME(CURSOR_CTRL
);
185 REG_NAME(PATTERN_LINE_START
);
188 REG_NAME(FONT_WRITE_INCR_Y
);
189 REG_NAME(FONT_WRITE_START
);
195 static int16_t artist_get_x(uint32_t reg
)
200 static int16_t artist_get_y(uint32_t reg
)
205 static void artist_invalidate_lines(struct vram_buffer
*buf
,
206 int starty
, int height
)
208 int start
= starty
* buf
->width
;
209 int size
= height
* buf
->width
;
211 if (start
+ size
<= buf
->size
) {
212 memory_region_set_dirty(&buf
->mr
, start
, size
);
216 static int vram_write_pix_per_transfer(ARTISTState
*s
)
218 if (s
->cmap_bm_access
) {
219 return 1 << ((s
->cmap_bm_access
>> 27) & 0x0f);
221 return 1 << ((s
->dst_bm_access
>> 27) & 0x0f);
225 static int vram_pixel_length(ARTISTState
*s
)
227 if (s
->cmap_bm_access
) {
228 return (s
->cmap_bm_access
>> 24) & 0x07;
230 return (s
->dst_bm_access
>> 24) & 0x07;
234 static int vram_write_bufidx(ARTISTState
*s
)
236 if (s
->cmap_bm_access
) {
237 return (s
->cmap_bm_access
>> 12) & 0x0f;
239 return (s
->dst_bm_access
>> 12) & 0x0f;
243 static int vram_read_bufidx(ARTISTState
*s
)
245 if (s
->cmap_bm_access
) {
246 return (s
->cmap_bm_access
>> 12) & 0x0f;
248 return (s
->src_bm_access
>> 12) & 0x0f;
252 static struct vram_buffer
*vram_read_buffer(ARTISTState
*s
)
254 return &s
->vram_buffer
[vram_read_bufidx(s
)];
257 static struct vram_buffer
*vram_write_buffer(ARTISTState
*s
)
259 return &s
->vram_buffer
[vram_write_bufidx(s
)];
262 static uint8_t artist_get_color(ARTISTState
*s
)
264 if (s
->image_bitmap_op
& 2) {
271 static artist_rop_t
artist_get_op(ARTISTState
*s
)
273 return (s
->image_bitmap_op
>> 8) & 0xf;
276 static void artist_rop8(ARTISTState
*s
, uint8_t *dst
, uint8_t val
)
279 const artist_rop_t op
= artist_get_op(s
);
280 uint8_t plane_mask
= s
->plane_mask
& 0xff;
283 case ARTIST_ROP_CLEAR
:
287 case ARTIST_ROP_COPY
:
289 *dst
|= val
& plane_mask
;
293 *dst
^= val
& plane_mask
;
296 case ARTIST_ROP_NOT_DST
:
305 qemu_log_mask(LOG_UNIMP
, "%s: unsupported rop %d\n", __func__
, op
);
310 static void artist_get_cursor_pos(ARTISTState
*s
, int *x
, int *y
)
313 * Don't know whether these magic offset values are configurable via
314 * some register. They are the same for all resolutions, so don't
318 *y
= 0x47a - artist_get_y(s
->cursor_pos
);
319 *x
= ((artist_get_x(s
->cursor_pos
) - 338) / 2);
325 if (*y
> s
->height
) {
330 static void artist_invalidate_cursor(ARTISTState
*s
)
333 artist_get_cursor_pos(s
, &x
, &y
);
334 artist_invalidate_lines(&s
->vram_buffer
[ARTIST_BUFFER_AP
],
335 y
, s
->cursor_height
);
338 static void vram_bit_write(ARTISTState
*s
, int posx
, int posy
, bool incr_x
,
339 int size
, uint32_t data
)
341 struct vram_buffer
*buf
;
342 uint32_t vram_bitmask
= s
->vram_bitmask
;
343 int mask
, i
, pix_count
, pix_length
, offset
, height
, width
;
346 pix_count
= vram_write_pix_per_transfer(s
);
347 pix_length
= vram_pixel_length(s
);
349 buf
= vram_write_buffer(s
);
350 height
= buf
->height
;
353 if (s
->cmap_bm_access
) {
354 offset
= s
->vram_pos
;
356 offset
= posy
* width
+ posx
;
360 qemu_log("write to non-existent buffer\n");
366 if (pix_count
> size
* 8) {
367 pix_count
= size
* 8;
370 if (posy
* width
+ posx
+ pix_count
> buf
->size
) {
371 qemu_log("write outside bounds: wants %dx%d, max size %dx%d\n",
372 posx
, posy
, width
, height
);
377 switch (pix_length
) {
379 if (s
->image_bitmap_op
& 0x20000000) {
380 data
&= vram_bitmask
;
383 for (i
= 0; i
< pix_count
; i
++) {
384 artist_rop8(s
, p
+ offset
+ pix_count
- 1 - i
,
385 (data
& 1) ? (s
->plane_mask
>> 24) : 0);
388 memory_region_set_dirty(&buf
->mr
, offset
, pix_count
);
392 if (s
->cmap_bm_access
) {
393 *(uint32_t *)(p
+ offset
) = data
;
396 data8
= (uint8_t *)&data
;
398 for (i
= 3; i
>= 0; i
--) {
399 if (!(s
->image_bitmap_op
& 0x20000000) ||
400 s
->vram_bitmask
& (1 << (28 + i
))) {
401 artist_rop8(s
, p
+ offset
+ 3 - i
, data8
[ROP8OFF(i
)]);
404 memory_region_set_dirty(&buf
->mr
, offset
, 3);
411 vram_bitmask
= s
->vram_bitmask
;
415 vram_bitmask
= s
->vram_bitmask
>> 16;
419 vram_bitmask
= s
->vram_bitmask
>> 24;
423 for (i
= 0; i
< pix_count
; i
++) {
424 mask
= 1 << (pix_count
- 1 - i
);
426 if (!(s
->image_bitmap_op
& 0x20000000) ||
427 (vram_bitmask
& mask
)) {
429 artist_rop8(s
, p
+ offset
+ i
, s
->fg_color
);
431 if (!(s
->image_bitmap_op
& 0x10000002)) {
432 artist_rop8(s
, p
+ offset
+ i
, s
->bg_color
);
437 memory_region_set_dirty(&buf
->mr
, offset
, pix_count
);
441 qemu_log_mask(LOG_UNIMP
, "%s: unknown pixel length %d\n",
442 __func__
, pix_length
);
447 if (s
->cmap_bm_access
) {
450 s
->vram_pos
+= pix_count
<< 2;
454 if (vram_write_bufidx(s
) == ARTIST_BUFFER_CURSOR1
||
455 vram_write_bufidx(s
) == ARTIST_BUFFER_CURSOR2
) {
456 artist_invalidate_cursor(s
);
460 static void block_move(ARTISTState
*s
, int source_x
, int source_y
, int dest_x
,
461 int dest_y
, int width
, int height
)
463 struct vram_buffer
*buf
;
464 int line
, endline
, lineincr
, startcolumn
, endcolumn
, columnincr
, column
;
467 trace_artist_block_move(source_x
, source_y
, dest_x
, dest_y
, width
, height
);
469 if (s
->control_plane
!= 0) {
470 /* We don't support CONTROL_PLANE accesses */
471 qemu_log_mask(LOG_UNIMP
, "%s: CONTROL_PLANE: %08x\n", __func__
,
476 buf
= &s
->vram_buffer
[ARTIST_BUFFER_AP
];
478 if (dest_y
> source_y
) {
490 if (dest_x
> source_x
) {
492 startcolumn
= width
- 1;
502 for ( ; line
!= endline
; line
+= lineincr
) {
503 src
= source_x
+ ((line
+ source_y
) * buf
->width
);
504 dst
= dest_x
+ ((line
+ dest_y
) * buf
->width
);
506 for (column
= startcolumn
; column
!= endcolumn
; column
+= columnincr
) {
507 if (dst
+ column
> buf
->size
|| src
+ column
> buf
->size
) {
510 artist_rop8(s
, buf
->data
+ dst
+ column
, buf
->data
[src
+ column
]);
514 artist_invalidate_lines(buf
, dest_y
, height
);
517 static void fill_window(ARTISTState
*s
, int startx
, int starty
,
518 int width
, int height
)
521 uint8_t color
= artist_get_color(s
);
522 struct vram_buffer
*buf
;
525 trace_artist_fill_window(startx
, starty
, width
, height
,
526 s
->image_bitmap_op
, s
->control_plane
);
528 if (s
->control_plane
!= 0) {
529 /* We don't support CONTROL_PLANE accesses */
530 qemu_log_mask(LOG_UNIMP
, "%s: CONTROL_PLANE: %08x\n", __func__
,
535 if (s
->reg_100080
== 0x7d) {
537 * Not sure what this register really does, but
538 * 0x7d seems to enable autoincremt of the Y axis
539 * by the current block move height.
541 height
= artist_get_y(s
->blockmove_size
);
542 s
->vram_start
+= height
;
545 buf
= &s
->vram_buffer
[ARTIST_BUFFER_AP
];
547 for (y
= starty
; y
< starty
+ height
; y
++) {
548 offset
= y
* s
->width
;
550 for (x
= startx
; x
< startx
+ width
; x
++) {
551 artist_rop8(s
, buf
->data
+ offset
+ x
, color
);
554 artist_invalidate_lines(buf
, starty
, height
);
557 static void draw_line(ARTISTState
*s
, int x1
, int y1
, int x2
, int y2
,
558 bool update_start
, int skip_pix
, int max_pix
)
560 struct vram_buffer
*buf
;
562 int dx
, dy
, t
, e
, x
, y
, incy
, diago
, horiz
;
566 trace_artist_draw_line(x1
, y1
, x2
, y2
);
569 s
->vram_start
= (x2
<< 16) | y2
;
614 diago
= (dy
- dx
) << 1;
624 color
= artist_get_color(s
);
625 buf
= &s
->vram_buffer
[ARTIST_BUFFER_AP
];
629 p
= buf
->data
+ x
* s
->width
+ y
;
631 p
= buf
->data
+ y
* s
->width
+ x
;
637 artist_rop8(s
, p
, color
);
641 artist_invalidate_lines(buf
, y
, 1);
648 } while (x
<= x2
&& (max_pix
== -1 || --max_pix
> 0));
651 static void draw_line_pattern_start(ARTISTState
*s
)
654 int startx
= artist_get_x(s
->vram_start
);
655 int starty
= artist_get_y(s
->vram_start
);
656 int endx
= artist_get_x(s
->blockmove_size
);
657 int endy
= artist_get_y(s
->blockmove_size
);
658 int pstart
= s
->line_pattern_start
>> 16;
660 draw_line(s
, startx
, starty
, endx
, endy
, false, -1, pstart
);
661 s
->line_pattern_skip
= pstart
;
664 static void draw_line_pattern_next(ARTISTState
*s
)
667 int startx
= artist_get_x(s
->vram_start
);
668 int starty
= artist_get_y(s
->vram_start
);
669 int endx
= artist_get_x(s
->blockmove_size
);
670 int endy
= artist_get_y(s
->blockmove_size
);
671 int line_xy
= s
->line_xy
>> 16;
673 draw_line(s
, startx
, starty
, endx
, endy
, false, s
->line_pattern_skip
,
674 s
->line_pattern_skip
+ line_xy
);
675 s
->line_pattern_skip
+= line_xy
;
676 s
->image_bitmap_op
^= 2;
679 static void draw_line_size(ARTISTState
*s
, bool update_start
)
682 int startx
= artist_get_x(s
->vram_start
);
683 int starty
= artist_get_y(s
->vram_start
);
684 int endx
= artist_get_x(s
->line_size
);
685 int endy
= artist_get_y(s
->line_size
);
687 draw_line(s
, startx
, starty
, endx
, endy
, update_start
, -1, -1);
690 static void draw_line_xy(ARTISTState
*s
, bool update_start
)
693 int startx
= artist_get_x(s
->vram_start
);
694 int starty
= artist_get_y(s
->vram_start
);
695 int sizex
= artist_get_x(s
->blockmove_size
);
696 int sizey
= artist_get_y(s
->blockmove_size
);
697 int linexy
= s
->line_xy
>> 16;
704 endx
= startx
+ linexy
;
713 endy
= starty
+ linexy
;
737 draw_line(s
, startx
, starty
, endx
, endy
, false, -1, -1);
740 static void draw_line_end(ARTISTState
*s
, bool update_start
)
743 int startx
= artist_get_x(s
->vram_start
);
744 int starty
= artist_get_y(s
->vram_start
);
745 int endx
= artist_get_x(s
->line_end
);
746 int endy
= artist_get_y(s
->line_end
);
748 draw_line(s
, startx
, starty
, endx
, endy
, update_start
, -1, -1);
751 static void font_write16(ARTISTState
*s
, uint16_t val
)
753 struct vram_buffer
*buf
;
754 uint32_t color
= (s
->image_bitmap_op
& 2) ? s
->fg_color
: s
->bg_color
;
758 int startx
= artist_get_x(s
->vram_start
);
759 int starty
= artist_get_y(s
->vram_start
) + s
->font_write_pos_y
;
760 int offset
= starty
* s
->width
+ startx
;
762 buf
= &s
->vram_buffer
[ARTIST_BUFFER_AP
];
764 if (offset
+ 16 > buf
->size
) {
768 for (i
= 0; i
< 16; i
++) {
769 mask
= 1 << (15 - i
);
771 artist_rop8(s
, buf
->data
+ offset
+ i
, color
);
773 if (!(s
->image_bitmap_op
& 0x20000000)) {
774 artist_rop8(s
, buf
->data
+ offset
+ i
, s
->bg_color
);
778 artist_invalidate_lines(buf
, starty
, 1);
781 static void font_write(ARTISTState
*s
, uint32_t val
)
783 font_write16(s
, val
>> 16);
784 if (++s
->font_write_pos_y
== artist_get_y(s
->blockmove_size
)) {
785 s
->vram_start
+= (s
->blockmove_size
& 0xffff0000);
789 font_write16(s
, val
& 0xffff);
790 if (++s
->font_write_pos_y
== artist_get_y(s
->blockmove_size
)) {
791 s
->vram_start
+= (s
->blockmove_size
& 0xffff0000);
796 static void combine_write_reg(hwaddr addr
, uint64_t val
, int size
, void *out
)
799 * FIXME: is there a qemu helper for this?
802 #ifndef HOST_WORDS_BIGENDIAN
808 *(uint8_t *)(out
+ (addr
& 3)) = val
;
812 *(uint16_t *)(out
+ (addr
& 2)) = val
;
816 *(uint32_t *)out
= val
;
820 qemu_log_mask(LOG_UNIMP
, "unsupported write size: %d\n", size
);
824 static void artist_reg_write(void *opaque
, hwaddr addr
, uint64_t val
,
827 ARTISTState
*s
= opaque
;
831 trace_artist_reg_write(size
, addr
, artist_reg_name(addr
& ~3ULL), val
);
833 switch (addr
& ~3ULL) {
835 combine_write_reg(addr
, val
, size
, &s
->reg_100080
);
839 combine_write_reg(addr
, val
, size
, &s
->fg_color
);
843 combine_write_reg(addr
, val
, size
, &s
->bg_color
);
847 combine_write_reg(addr
, val
, size
, &s
->vram_bitmask
);
850 case VRAM_WRITE_INCR_Y
:
851 posx
= (s
->vram_pos
>> 2) & 0x7ff;
852 posy
= (s
->vram_pos
>> 13) & 0x3ff;
853 vram_bit_write(s
, posx
, posy
+ s
->vram_char_y
++, false, size
, val
);
856 case VRAM_WRITE_INCR_X
:
857 case VRAM_WRITE_INCR_X2
:
858 posx
= (s
->vram_pos
>> 2) & 0x7ff;
859 posy
= (s
->vram_pos
>> 13) & 0x3ff;
860 vram_bit_write(s
, posx
, posy
+ s
->vram_char_y
, true, size
, val
);
864 combine_write_reg(addr
, val
, size
, &s
->vram_pos
);
866 s
->draw_line_pattern
= 0;
870 combine_write_reg(addr
, val
, size
, &s
->vram_start
);
871 s
->draw_line_pattern
= 0;
874 case VRAM_START_TRIGGER
:
875 combine_write_reg(addr
, val
, size
, &s
->vram_start
);
876 fill_window(s
, artist_get_x(s
->vram_start
),
877 artist_get_y(s
->vram_start
),
878 artist_get_x(s
->blockmove_size
),
879 artist_get_y(s
->blockmove_size
));
882 case VRAM_SIZE_TRIGGER
:
883 combine_write_reg(addr
, val
, size
, &s
->vram_size
);
885 if (size
== 2 && !(addr
& 2)) {
886 height
= artist_get_y(s
->blockmove_size
);
888 height
= artist_get_y(s
->vram_size
);
891 if (size
== 2 && (addr
& 2)) {
892 width
= artist_get_x(s
->blockmove_size
);
894 width
= artist_get_x(s
->vram_size
);
897 fill_window(s
, artist_get_x(s
->vram_start
),
898 artist_get_y(s
->vram_start
),
903 combine_write_reg(addr
, val
, size
, &s
->line_xy
);
904 if (s
->draw_line_pattern
) {
905 draw_line_pattern_next(s
);
907 draw_line_xy(s
, true);
911 case PATTERN_LINE_START
:
912 combine_write_reg(addr
, val
, size
, &s
->line_pattern_start
);
913 s
->draw_line_pattern
= 1;
914 draw_line_pattern_start(s
);
918 combine_write_reg(addr
, val
, size
, &s
->line_size
);
919 draw_line_size(s
, true);
923 combine_write_reg(addr
, val
, size
, &s
->line_end
);
924 draw_line_end(s
, true);
927 case BLOCK_MOVE_SIZE
:
928 combine_write_reg(addr
, val
, size
, &s
->blockmove_size
);
931 case BLOCK_MOVE_SOURCE
:
932 combine_write_reg(addr
, val
, size
, &s
->blockmove_source
);
935 case BLOCK_MOVE_DEST_TRIGGER
:
936 combine_write_reg(addr
, val
, size
, &s
->blockmove_dest
);
938 block_move(s
, artist_get_x(s
->blockmove_source
),
939 artist_get_y(s
->blockmove_source
),
940 artist_get_x(s
->blockmove_dest
),
941 artist_get_y(s
->blockmove_dest
),
942 artist_get_x(s
->blockmove_size
),
943 artist_get_y(s
->blockmove_size
));
946 case BLOCK_MOVE_SIZE_TRIGGER
:
947 combine_write_reg(addr
, val
, size
, &s
->blockmove_size
);
950 artist_get_x(s
->blockmove_source
),
951 artist_get_y(s
->blockmove_source
),
952 artist_get_x(s
->vram_start
),
953 artist_get_y(s
->vram_start
),
954 artist_get_x(s
->blockmove_size
),
955 artist_get_y(s
->blockmove_size
));
959 combine_write_reg(addr
, val
, size
, &s
->plane_mask
);
963 combine_write_reg(addr
, val
, size
, &s
->cmap_bm_access
);
967 combine_write_reg(addr
, val
, size
, &s
->dst_bm_access
);
968 s
->cmap_bm_access
= 0;
972 combine_write_reg(addr
, val
, size
, &s
->src_bm_access
);
973 s
->cmap_bm_access
= 0;
977 combine_write_reg(addr
, val
, size
, &s
->control_plane
);
981 combine_write_reg(addr
, val
, size
, &s
->transfer_data
);
985 combine_write_reg(addr
, val
, size
, &s
->reg_300200
);
989 combine_write_reg(addr
, val
, size
, &s
->reg_300208
);
993 combine_write_reg(addr
, val
, size
, &s
->reg_300218
);
997 artist_invalidate_cursor(s
);
998 combine_write_reg(addr
, val
, size
, &s
->cursor_pos
);
999 artist_invalidate_cursor(s
);
1005 case IMAGE_BITMAP_OP
:
1006 combine_write_reg(addr
, val
, size
, &s
->image_bitmap_op
);
1009 case FONT_WRITE_INCR_Y
:
1010 combine_write_reg(addr
, val
, size
, &s
->font_write1
);
1011 font_write(s
, s
->font_write1
);
1014 case FONT_WRITE_START
:
1015 combine_write_reg(addr
, val
, size
, &s
->font_write2
);
1016 s
->font_write_pos_y
= 0;
1017 font_write(s
, s
->font_write2
);
1024 qemu_log_mask(LOG_UNIMP
, "%s: unknown register: reg=%08" HWADDR_PRIx
1025 " val=%08" PRIx64
" size=%d\n",
1026 __func__
, addr
, val
, size
);
1031 static uint64_t combine_read_reg(hwaddr addr
, int size
, void *in
)
1034 * FIXME: is there a qemu helper for this?
1037 #ifndef HOST_WORDS_BIGENDIAN
1043 return *(uint8_t *)(in
+ (addr
& 3));
1046 return *(uint16_t *)(in
+ (addr
& 2));
1049 return *(uint32_t *)in
;
1052 qemu_log_mask(LOG_UNIMP
, "unsupported read size: %d\n", size
);
1057 static uint64_t artist_reg_read(void *opaque
, hwaddr addr
, unsigned size
)
1059 ARTISTState
*s
= opaque
;
1062 switch (addr
& ~3ULL) {
1063 /* Unknown status registers */
1068 val
= (s
->width
<< 16) | s
->height
;
1069 if (s
->depth
== 1) {
1084 * FIFO ready flag. we're not emulating the FIFOs
1085 * so we're always ready
1091 val
= s
->reg_300200
;
1095 val
= s
->reg_300208
;
1099 val
= s
->reg_300218
;
1107 /* 0x02000000 Buserror */
1112 qemu_log_mask(LOG_UNIMP
, "%s: unknown register: %08" HWADDR_PRIx
1113 " size %d\n", __func__
, addr
, size
);
1116 val
= combine_read_reg(addr
, size
, &val
);
1117 trace_artist_reg_read(size
, addr
, artist_reg_name(addr
& ~3ULL), val
);
1121 static void artist_vram_write(void *opaque
, hwaddr addr
, uint64_t val
,
1124 ARTISTState
*s
= opaque
;
1125 struct vram_buffer
*buf
;
1126 int posy
= (addr
>> 11) & 0x3ff;
1127 int posx
= addr
& 0x7ff;
1129 trace_artist_vram_write(size
, addr
, val
);
1131 if (s
->cmap_bm_access
) {
1132 buf
= &s
->vram_buffer
[ARTIST_BUFFER_CMAP
];
1133 if (addr
+ 3 < buf
->size
) {
1134 *(uint32_t *)(buf
->data
+ addr
) = val
;
1139 buf
= vram_write_buffer(s
);
1144 if (posy
> buf
->height
|| posx
> buf
->width
) {
1148 offset
= posy
* buf
->width
+ posx
;
1151 *(uint32_t *)(buf
->data
+ offset
) = be32_to_cpu(val
);
1152 memory_region_set_dirty(&buf
->mr
, offset
, 4);
1155 *(uint16_t *)(buf
->data
+ offset
) = be16_to_cpu(val
);
1156 memory_region_set_dirty(&buf
->mr
, offset
, 2);
1159 *(uint8_t *)(buf
->data
+ offset
) = val
;
1160 memory_region_set_dirty(&buf
->mr
, offset
, 1);
1167 static uint64_t artist_vram_read(void *opaque
, hwaddr addr
, unsigned size
)
1169 ARTISTState
*s
= opaque
;
1170 struct vram_buffer
*buf
;
1174 if (s
->cmap_bm_access
) {
1175 buf
= &s
->vram_buffer
[ARTIST_BUFFER_CMAP
];
1176 val
= *(uint32_t *)(buf
->data
+ addr
);
1177 trace_artist_vram_read(size
, addr
, 0, 0, val
);
1181 buf
= vram_read_buffer(s
);
1186 posy
= (addr
>> 13) & 0x3ff;
1187 posx
= (addr
>> 2) & 0x7ff;
1189 if (posy
> buf
->height
|| posx
> buf
->width
) {
1193 val
= cpu_to_be32(*(uint32_t *)(buf
->data
+ posy
* buf
->width
+ posx
));
1194 trace_artist_vram_read(size
, addr
, posx
, posy
, val
);
1198 static const MemoryRegionOps artist_reg_ops
= {
1199 .read
= artist_reg_read
,
1200 .write
= artist_reg_write
,
1201 .endianness
= DEVICE_NATIVE_ENDIAN
,
1203 .min_access_size
= 1,
1204 .max_access_size
= 4,
1208 static const MemoryRegionOps artist_vram_ops
= {
1209 .read
= artist_vram_read
,
1210 .write
= artist_vram_write
,
1211 .endianness
= DEVICE_NATIVE_ENDIAN
,
1213 .min_access_size
= 1,
1214 .max_access_size
= 4,
1218 static void artist_draw_cursor(ARTISTState
*s
)
1220 DisplaySurface
*surface
= qemu_console_surface(s
->con
);
1221 uint32_t *data
= (uint32_t *)surface_data(surface
);
1222 struct vram_buffer
*cursor0
, *cursor1
, *buf
;
1223 int cx
, cy
, cursor_pos_x
, cursor_pos_y
;
1225 cursor0
= &s
->vram_buffer
[ARTIST_BUFFER_CURSOR1
];
1226 cursor1
= &s
->vram_buffer
[ARTIST_BUFFER_CURSOR2
];
1227 buf
= &s
->vram_buffer
[ARTIST_BUFFER_AP
];
1229 artist_get_cursor_pos(s
, &cursor_pos_x
, &cursor_pos_y
);
1231 for (cy
= 0; cy
< s
->cursor_height
; cy
++) {
1233 for (cx
= 0; cx
< s
->cursor_width
; cx
++) {
1235 if (cursor_pos_y
+ cy
< 0 ||
1236 cursor_pos_x
+ cx
< 0 ||
1237 cursor_pos_y
+ cy
> buf
->height
- 1 ||
1238 cursor_pos_x
+ cx
> buf
->width
) {
1242 int dstoffset
= (cursor_pos_y
+ cy
) * s
->width
+
1243 (cursor_pos_x
+ cx
);
1245 if (cursor0
->data
[cy
* cursor0
->width
+ cx
]) {
1246 data
[dstoffset
] = 0;
1248 if (cursor1
->data
[cy
* cursor1
->width
+ cx
]) {
1249 data
[dstoffset
] = 0xffffff;
1256 static void artist_draw_line(void *opaque
, uint8_t *d
, const uint8_t *src
,
1257 int width
, int pitch
)
1259 ARTISTState
*s
= ARTIST(opaque
);
1260 uint32_t *cmap
, *data
= (uint32_t *)d
;
1263 cmap
= (uint32_t *)(s
->vram_buffer
[ARTIST_BUFFER_CMAP
].data
+ 0x400);
1265 for (x
= 0; x
< s
->width
; x
++) {
1266 *data
++ = cmap
[*src
++];
1270 static void artist_update_display(void *opaque
)
1272 ARTISTState
*s
= opaque
;
1273 DisplaySurface
*surface
= qemu_console_surface(s
->con
);
1274 int first
= 0, last
;
1277 framebuffer_update_display(surface
, &s
->fbsection
, s
->width
, s
->height
,
1278 s
->width
, s
->width
* 4, 0, 0, artist_draw_line
,
1281 artist_draw_cursor(s
);
1283 dpy_gfx_update(s
->con
, 0, 0, s
->width
, s
->height
);
1286 static void artist_invalidate(void *opaque
)
1288 ARTISTState
*s
= ARTIST(opaque
);
1289 struct vram_buffer
*buf
= &s
->vram_buffer
[ARTIST_BUFFER_AP
];
1290 memory_region_set_dirty(&buf
->mr
, 0, buf
->size
);
1293 static const GraphicHwOps artist_ops
= {
1294 .invalidate
= artist_invalidate
,
1295 .gfx_update
= artist_update_display
,
1298 static void artist_initfn(Object
*obj
)
1300 SysBusDevice
*sbd
= SYS_BUS_DEVICE(obj
);
1301 ARTISTState
*s
= ARTIST(obj
);
1303 memory_region_init_io(&s
->reg
, obj
, &artist_reg_ops
, s
, "artist.reg",
1305 memory_region_init_io(&s
->vram_mem
, obj
, &artist_vram_ops
, s
, "artist.vram",
1307 sysbus_init_mmio(sbd
, &s
->reg
);
1308 sysbus_init_mmio(sbd
, &s
->vram_mem
);
1311 static void artist_create_buffer(ARTISTState
*s
, const char *name
,
1312 hwaddr
*offset
, unsigned int idx
,
1313 int width
, int height
)
1315 struct vram_buffer
*buf
= s
->vram_buffer
+ idx
;
1317 memory_region_init_ram(&buf
->mr
, NULL
, name
, width
* height
,
1319 memory_region_add_subregion_overlap(&s
->mem_as_root
, *offset
, &buf
->mr
, 0);
1321 buf
->data
= memory_region_get_ram_ptr(&buf
->mr
);
1322 buf
->size
= height
* width
;
1324 buf
->height
= height
;
1326 *offset
+= buf
->size
;
1329 static void artist_realizefn(DeviceState
*dev
, Error
**errp
)
1331 ARTISTState
*s
= ARTIST(dev
);
1332 struct vram_buffer
*buf
;
1335 memory_region_init(&s
->mem_as_root
, OBJECT(dev
), "artist", ~0ull);
1336 address_space_init(&s
->as
, &s
->mem_as_root
, "artist");
1338 artist_create_buffer(s
, "cmap", &offset
, ARTIST_BUFFER_CMAP
, 2048, 4);
1339 artist_create_buffer(s
, "ap", &offset
, ARTIST_BUFFER_AP
,
1340 s
->width
, s
->height
);
1341 artist_create_buffer(s
, "cursor1", &offset
, ARTIST_BUFFER_CURSOR1
, 64, 64);
1342 artist_create_buffer(s
, "cursor2", &offset
, ARTIST_BUFFER_CURSOR2
, 64, 64);
1343 artist_create_buffer(s
, "attribute", &offset
, ARTIST_BUFFER_ATTRIBUTE
,
1346 buf
= &s
->vram_buffer
[ARTIST_BUFFER_AP
];
1347 framebuffer_update_memory_section(&s
->fbsection
, &buf
->mr
, 0,
1348 buf
->width
, buf
->height
);
1350 * no idea whether the cursor is fixed size or not, so assume 32x32 which
1351 * seems sufficient for HP-UX X11.
1353 s
->cursor_height
= 32;
1354 s
->cursor_width
= 32;
1356 s
->con
= graphic_console_init(dev
, 0, &artist_ops
, s
);
1357 qemu_console_resize(s
->con
, s
->width
, s
->height
);
1360 static int vmstate_artist_post_load(void *opaque
, int version_id
)
1362 artist_invalidate(opaque
);
1366 static const VMStateDescription vmstate_artist
= {
1369 .minimum_version_id
= 1,
1370 .post_load
= vmstate_artist_post_load
,
1371 .fields
= (VMStateField
[]) {
1372 VMSTATE_UINT16(height
, ARTISTState
),
1373 VMSTATE_UINT16(width
, ARTISTState
),
1374 VMSTATE_UINT16(depth
, ARTISTState
),
1375 VMSTATE_UINT32(fg_color
, ARTISTState
),
1376 VMSTATE_UINT32(bg_color
, ARTISTState
),
1377 VMSTATE_UINT32(vram_char_y
, ARTISTState
),
1378 VMSTATE_UINT32(vram_bitmask
, ARTISTState
),
1379 VMSTATE_UINT32(vram_start
, ARTISTState
),
1380 VMSTATE_UINT32(vram_pos
, ARTISTState
),
1381 VMSTATE_UINT32(vram_size
, ARTISTState
),
1382 VMSTATE_UINT32(blockmove_source
, ARTISTState
),
1383 VMSTATE_UINT32(blockmove_dest
, ARTISTState
),
1384 VMSTATE_UINT32(blockmove_size
, ARTISTState
),
1385 VMSTATE_UINT32(line_size
, ARTISTState
),
1386 VMSTATE_UINT32(line_end
, ARTISTState
),
1387 VMSTATE_UINT32(line_xy
, ARTISTState
),
1388 VMSTATE_UINT32(cursor_pos
, ARTISTState
),
1389 VMSTATE_UINT32(cursor_height
, ARTISTState
),
1390 VMSTATE_UINT32(cursor_width
, ARTISTState
),
1391 VMSTATE_UINT32(plane_mask
, ARTISTState
),
1392 VMSTATE_UINT32(reg_100080
, ARTISTState
),
1393 VMSTATE_UINT32(reg_300200
, ARTISTState
),
1394 VMSTATE_UINT32(reg_300208
, ARTISTState
),
1395 VMSTATE_UINT32(reg_300218
, ARTISTState
),
1396 VMSTATE_UINT32(cmap_bm_access
, ARTISTState
),
1397 VMSTATE_UINT32(dst_bm_access
, ARTISTState
),
1398 VMSTATE_UINT32(src_bm_access
, ARTISTState
),
1399 VMSTATE_UINT32(control_plane
, ARTISTState
),
1400 VMSTATE_UINT32(transfer_data
, ARTISTState
),
1401 VMSTATE_UINT32(image_bitmap_op
, ARTISTState
),
1402 VMSTATE_UINT32(font_write1
, ARTISTState
),
1403 VMSTATE_UINT32(font_write2
, ARTISTState
),
1404 VMSTATE_UINT32(font_write_pos_y
, ARTISTState
),
1405 VMSTATE_END_OF_LIST()
1409 static Property artist_properties
[] = {
1410 DEFINE_PROP_UINT16("width", ARTISTState
, width
, 1280),
1411 DEFINE_PROP_UINT16("height", ARTISTState
, height
, 1024),
1412 DEFINE_PROP_UINT16("depth", ARTISTState
, depth
, 8),
1413 DEFINE_PROP_END_OF_LIST(),
1416 static void artist_reset(DeviceState
*qdev
)
1420 static void artist_class_init(ObjectClass
*klass
, void *data
)
1422 DeviceClass
*dc
= DEVICE_CLASS(klass
);
1424 dc
->realize
= artist_realizefn
;
1425 dc
->vmsd
= &vmstate_artist
;
1426 dc
->reset
= artist_reset
;
1427 device_class_set_props(dc
, artist_properties
);
1430 static const TypeInfo artist_info
= {
1431 .name
= TYPE_ARTIST
,
1432 .parent
= TYPE_SYS_BUS_DEVICE
,
1433 .instance_size
= sizeof(ARTISTState
),
1434 .instance_init
= artist_initfn
,
1435 .class_init
= artist_class_init
,
1438 static void artist_register_types(void)
1440 type_register_static(&artist_info
);
1443 type_init(artist_register_types
)