forked from MoatLab/FEMU
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathartist.c
1435 lines (1183 loc) · 36.8 KB
/
artist.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
* QEMU HP Artist Emulation
*
* Copyright (c) 2019 Sven Schnelle <[email protected]>
*
* This work is licensed under the terms of the GNU GPL, version 2 or later.
*/
#include "qemu/osdep.h"
#include "qemu-common.h"
#include "qemu/error-report.h"
#include "qemu/log.h"
#include "qemu/module.h"
#include "qemu/units.h"
#include "qapi/error.h"
#include "hw/sysbus.h"
#include "hw/loader.h"
#include "hw/qdev-core.h"
#include "hw/qdev-properties.h"
#include "migration/vmstate.h"
#include "ui/console.h"
#include "trace.h"
#include "framebuffer.h"
#include "qom/object.h"
#define TYPE_ARTIST "artist"
OBJECT_DECLARE_SIMPLE_TYPE(ARTISTState, ARTIST)
#ifdef HOST_WORDS_BIGENDIAN
#define ROP8OFF(_i) (3 - (_i))
#else
#define ROP8OFF
#endif
struct vram_buffer {
MemoryRegion mr;
uint8_t *data;
unsigned int size;
unsigned int width;
unsigned int height;
};
struct ARTISTState {
SysBusDevice parent_obj;
QemuConsole *con;
MemoryRegion vram_mem;
MemoryRegion mem_as_root;
MemoryRegion reg;
MemoryRegionSection fbsection;
void *vram_int_mr;
AddressSpace as;
struct vram_buffer vram_buffer[16];
uint16_t width;
uint16_t height;
uint16_t depth;
uint32_t fg_color;
uint32_t bg_color;
uint32_t vram_char_y;
uint32_t vram_bitmask;
uint32_t vram_start;
uint32_t vram_pos;
uint32_t vram_size;
uint32_t blockmove_source;
uint32_t blockmove_dest;
uint32_t blockmove_size;
uint32_t line_size;
uint32_t line_end;
uint32_t line_xy;
uint32_t line_pattern_start;
uint32_t line_pattern_skip;
uint32_t cursor_pos;
uint32_t cursor_cntrl;
uint32_t cursor_height;
uint32_t cursor_width;
uint32_t plane_mask;
uint32_t reg_100080;
uint32_t reg_300200;
uint32_t reg_300208;
uint32_t reg_300218;
uint32_t dst_bm_access;
uint32_t src_bm_access;
uint32_t control_plane;
uint32_t transfer_data;
uint32_t image_bitmap_op;
uint32_t font_write1;
uint32_t font_write2;
uint32_t font_write_pos_y;
int draw_line_pattern;
};
typedef enum {
ARTIST_BUFFER_AP = 1,
ARTIST_BUFFER_OVERLAY = 2,
ARTIST_BUFFER_CURSOR1 = 6,
ARTIST_BUFFER_CURSOR2 = 7,
ARTIST_BUFFER_ATTRIBUTE = 13,
ARTIST_BUFFER_CMAP = 15,
} artist_buffer_t;
typedef enum {
VRAM_IDX = 0x1004a0,
VRAM_BITMASK = 0x1005a0,
VRAM_WRITE_INCR_X = 0x100600,
VRAM_WRITE_INCR_X2 = 0x100604,
VRAM_WRITE_INCR_Y = 0x100620,
VRAM_START = 0x100800,
BLOCK_MOVE_SIZE = 0x100804,
BLOCK_MOVE_SOURCE = 0x100808,
TRANSFER_DATA = 0x100820,
FONT_WRITE_INCR_Y = 0x1008a0,
VRAM_START_TRIGGER = 0x100a00,
VRAM_SIZE_TRIGGER = 0x100a04,
FONT_WRITE_START = 0x100aa0,
BLOCK_MOVE_DEST_TRIGGER = 0x100b00,
BLOCK_MOVE_SIZE_TRIGGER = 0x100b04,
LINE_XY = 0x100ccc,
PATTERN_LINE_START = 0x100ecc,
LINE_SIZE = 0x100e04,
LINE_END = 0x100e44,
DST_SRC_BM_ACCESS = 0x118000,
DST_BM_ACCESS = 0x118004,
SRC_BM_ACCESS = 0x118008,
CONTROL_PLANE = 0x11800c,
FG_COLOR = 0x118010,
BG_COLOR = 0x118014,
PLANE_MASK = 0x118018,
IMAGE_BITMAP_OP = 0x11801c,
CURSOR_POS = 0x300100,
CURSOR_CTRL = 0x300104,
} artist_reg_t;
typedef enum {
ARTIST_ROP_CLEAR = 0,
ARTIST_ROP_COPY = 3,
ARTIST_ROP_XOR = 6,
ARTIST_ROP_NOT_DST = 10,
ARTIST_ROP_SET = 15,
} artist_rop_t;
#define REG_NAME(_x) case _x: return " "#_x;
static const char *artist_reg_name(uint64_t addr)
{
switch ((artist_reg_t)addr) {
REG_NAME(VRAM_IDX);
REG_NAME(VRAM_BITMASK);
REG_NAME(VRAM_WRITE_INCR_X);
REG_NAME(VRAM_WRITE_INCR_X2);
REG_NAME(VRAM_WRITE_INCR_Y);
REG_NAME(VRAM_START);
REG_NAME(BLOCK_MOVE_SIZE);
REG_NAME(BLOCK_MOVE_SOURCE);
REG_NAME(FG_COLOR);
REG_NAME(BG_COLOR);
REG_NAME(PLANE_MASK);
REG_NAME(VRAM_START_TRIGGER);
REG_NAME(VRAM_SIZE_TRIGGER);
REG_NAME(BLOCK_MOVE_DEST_TRIGGER);
REG_NAME(BLOCK_MOVE_SIZE_TRIGGER);
REG_NAME(TRANSFER_DATA);
REG_NAME(CONTROL_PLANE);
REG_NAME(IMAGE_BITMAP_OP);
REG_NAME(DST_SRC_BM_ACCESS);
REG_NAME(DST_BM_ACCESS);
REG_NAME(SRC_BM_ACCESS);
REG_NAME(CURSOR_POS);
REG_NAME(CURSOR_CTRL);
REG_NAME(LINE_XY);
REG_NAME(PATTERN_LINE_START);
REG_NAME(LINE_SIZE);
REG_NAME(LINE_END);
REG_NAME(FONT_WRITE_INCR_Y);
REG_NAME(FONT_WRITE_START);
}
return "";
}
#undef REG_NAME
/* artist has a fixed line length of 2048 bytes. */
#define ADDR_TO_Y(addr) extract32(addr, 11, 11)
#define ADDR_TO_X(addr) extract32(addr, 0, 11)
static int16_t artist_get_x(uint32_t reg)
{
return reg >> 16;
}
static int16_t artist_get_y(uint32_t reg)
{
return reg & 0xffff;
}
static void artist_invalidate_lines(struct vram_buffer *buf,
int starty, int height)
{
int start = starty * buf->width;
int size;
if (starty + height > buf->height)
height = buf->height - starty;
size = height * buf->width;
if (start + size <= buf->size) {
memory_region_set_dirty(&buf->mr, start, size);
}
}
static int vram_write_bufidx(ARTISTState *s)
{
return (s->dst_bm_access >> 12) & 0x0f;
}
static int vram_read_bufidx(ARTISTState *s)
{
return (s->src_bm_access >> 12) & 0x0f;
}
static struct vram_buffer *vram_read_buffer(ARTISTState *s)
{
return &s->vram_buffer[vram_read_bufidx(s)];
}
static struct vram_buffer *vram_write_buffer(ARTISTState *s)
{
return &s->vram_buffer[vram_write_bufidx(s)];
}
static uint8_t artist_get_color(ARTISTState *s)
{
if (s->image_bitmap_op & 2) {
return s->fg_color;
} else {
return s->bg_color;
}
}
static artist_rop_t artist_get_op(ARTISTState *s)
{
return (s->image_bitmap_op >> 8) & 0xf;
}
static void artist_rop8(ARTISTState *s, struct vram_buffer *buf,
unsigned int offset, uint8_t val)
{
const artist_rop_t op = artist_get_op(s);
uint8_t plane_mask;
uint8_t *dst;
if (offset >= buf->size) {
qemu_log_mask(LOG_GUEST_ERROR,
"rop8 offset:%u bufsize:%u\n", offset, buf->size);
return;
}
dst = buf->data + offset;
plane_mask = s->plane_mask & 0xff;
switch (op) {
case ARTIST_ROP_CLEAR:
*dst &= ~plane_mask;
break;
case ARTIST_ROP_COPY:
*dst = (*dst & ~plane_mask) | (val & plane_mask);
break;
case ARTIST_ROP_XOR:
*dst ^= val & plane_mask;
break;
case ARTIST_ROP_NOT_DST:
*dst ^= plane_mask;
break;
case ARTIST_ROP_SET:
*dst |= plane_mask;
break;
default:
qemu_log_mask(LOG_UNIMP, "%s: unsupported rop %d\n", __func__, op);
break;
}
}
static void artist_get_cursor_pos(ARTISTState *s, int *x, int *y)
{
/*
* Don't know whether these magic offset values are configurable via
* some register. They seem to be the same for all resolutions.
* The cursor values provided in the registers are:
* X-value: -295 (for HP-UX 11) and 338 (for HP-UX 10.20) up to 2265
* Y-value: 1146 down to 0
* The emulated Artist graphic is like a CRX graphic, and as such
* it's usually fixed at 1280x1024 pixels.
* Because of the maximum Y-value of 1146 you can not choose a higher
* vertical resolution on HP-UX (unless you disable the mouse).
*/
static int offset = 338;
int lx;
/* ignore if uninitialized */
if (s->cursor_pos == 0) {
*x = *y = 0;
return;
}
lx = artist_get_x(s->cursor_pos);
if (lx < offset)
offset = lx;
*x = (lx - offset) / 2;
*y = 1146 - artist_get_y(s->cursor_pos);
/* subtract cursor offset from cursor control register */
*x -= (s->cursor_cntrl & 0xf0) >> 4;
*y -= (s->cursor_cntrl & 0x0f);
if (*x > s->width) {
*x = s->width;
}
if (*y > s->height) {
*y = s->height;
}
}
static void artist_invalidate_cursor(ARTISTState *s)
{
int x, y;
artist_get_cursor_pos(s, &x, &y);
artist_invalidate_lines(&s->vram_buffer[ARTIST_BUFFER_AP],
y, s->cursor_height);
}
static void block_move(ARTISTState *s,
unsigned int source_x, unsigned int source_y,
unsigned int dest_x, unsigned int dest_y,
unsigned int width, unsigned int height)
{
struct vram_buffer *buf;
int line, endline, lineincr, startcolumn, endcolumn, columnincr, column;
unsigned int dst, src;
trace_artist_block_move(source_x, source_y, dest_x, dest_y, width, height);
if (s->control_plane != 0) {
/* We don't support CONTROL_PLANE accesses */
qemu_log_mask(LOG_UNIMP, "%s: CONTROL_PLANE: %08x\n", __func__,
s->control_plane);
return;
}
buf = &s->vram_buffer[ARTIST_BUFFER_AP];
if (height > buf->height) {
height = buf->height;
}
if (width > buf->width) {
width = buf->width;
}
if (dest_y > source_y) {
/* move down */
line = height - 1;
endline = -1;
lineincr = -1;
} else {
/* move up */
line = 0;
endline = height;
lineincr = 1;
}
if (dest_x > source_x) {
/* move right */
startcolumn = width - 1;
endcolumn = -1;
columnincr = -1;
} else {
/* move left */
startcolumn = 0;
endcolumn = width;
columnincr = 1;
}
for ( ; line != endline; line += lineincr) {
src = source_x + ((line + source_y) * buf->width) + startcolumn;
dst = dest_x + ((line + dest_y) * buf->width) + startcolumn;
for (column = startcolumn; column != endcolumn; column += columnincr) {
if (dst >= buf->size || src >= buf->size) {
continue;
}
artist_rop8(s, buf, dst, buf->data[src]);
src += columnincr;
dst += columnincr;
}
}
artist_invalidate_lines(buf, dest_y, height);
}
static void fill_window(ARTISTState *s,
unsigned int startx, unsigned int starty,
unsigned int width, unsigned int height)
{
unsigned int offset;
uint8_t color = artist_get_color(s);
struct vram_buffer *buf;
int x, y;
trace_artist_fill_window(startx, starty, width, height,
s->image_bitmap_op, s->control_plane);
if (s->control_plane != 0) {
/* We don't support CONTROL_PLANE accesses */
qemu_log_mask(LOG_UNIMP, "%s: CONTROL_PLANE: %08x\n", __func__,
s->control_plane);
return;
}
if (s->reg_100080 == 0x7d) {
/*
* Not sure what this register really does, but
* 0x7d seems to enable autoincremt of the Y axis
* by the current block move height.
*/
height = artist_get_y(s->blockmove_size);
s->vram_start += height;
}
buf = &s->vram_buffer[ARTIST_BUFFER_AP];
for (y = starty; y < starty + height; y++) {
offset = y * s->width;
for (x = startx; x < startx + width; x++) {
artist_rop8(s, buf, offset + x, color);
}
}
artist_invalidate_lines(buf, starty, height);
}
static void draw_line(ARTISTState *s,
unsigned int x1, unsigned int y1,
unsigned int x2, unsigned int y2,
bool update_start, int skip_pix, int max_pix)
{
struct vram_buffer *buf = &s->vram_buffer[ARTIST_BUFFER_AP];
uint8_t color;
int dx, dy, t, e, x, y, incy, diago, horiz;
bool c1;
trace_artist_draw_line(x1, y1, x2, y2);
if ((x1 >= buf->width && x2 >= buf->width) ||
(y1 >= buf->height && y2 >= buf->height)) {
return;
}
if (update_start) {
s->vram_start = (x2 << 16) | y2;
}
if (x2 > x1) {
dx = x2 - x1;
} else {
dx = x1 - x2;
}
if (y2 > y1) {
dy = y2 - y1;
} else {
dy = y1 - y2;
}
c1 = false;
if (dy > dx) {
t = y2;
y2 = x2;
x2 = t;
t = y1;
y1 = x1;
x1 = t;
t = dx;
dx = dy;
dy = t;
c1 = true;
}
if (x1 > x2) {
t = y2;
y2 = y1;
y1 = t;
t = x1;
x1 = x2;
x2 = t;
}
horiz = dy << 1;
diago = (dy - dx) << 1;
e = (dy << 1) - dx;
if (y1 <= y2) {
incy = 1;
} else {
incy = -1;
}
x = x1;
y = y1;
color = artist_get_color(s);
do {
unsigned int ofs;
if (c1) {
ofs = x * s->width + y;
} else {
ofs = y * s->width + x;
}
if (skip_pix > 0) {
skip_pix--;
} else {
artist_rop8(s, buf, ofs, color);
}
if (e > 0) {
y += incy;
e += diago;
} else {
e += horiz;
}
x++;
} while (x <= x2 && (max_pix == -1 || --max_pix > 0));
if (c1)
artist_invalidate_lines(buf, x1, x2 - x1);
else
artist_invalidate_lines(buf, y1 > y2 ? y2 : y1, x2 - x1);
}
static void draw_line_pattern_start(ARTISTState *s)
{
int startx = artist_get_x(s->vram_start);
int starty = artist_get_y(s->vram_start);
int endx = artist_get_x(s->blockmove_size);
int endy = artist_get_y(s->blockmove_size);
int pstart = s->line_pattern_start >> 16;
draw_line(s, startx, starty, endx, endy, false, -1, pstart);
s->line_pattern_skip = pstart;
}
static void draw_line_pattern_next(ARTISTState *s)
{
int startx = artist_get_x(s->vram_start);
int starty = artist_get_y(s->vram_start);
int endx = artist_get_x(s->blockmove_size);
int endy = artist_get_y(s->blockmove_size);
int line_xy = s->line_xy >> 16;
draw_line(s, startx, starty, endx, endy, false, s->line_pattern_skip,
s->line_pattern_skip + line_xy);
s->line_pattern_skip += line_xy;
s->image_bitmap_op ^= 2;
}
static void draw_line_size(ARTISTState *s, bool update_start)
{
int startx = artist_get_x(s->vram_start);
int starty = artist_get_y(s->vram_start);
int endx = artist_get_x(s->line_size);
int endy = artist_get_y(s->line_size);
draw_line(s, startx, starty, endx, endy, update_start, -1, -1);
}
static void draw_line_xy(ARTISTState *s, bool update_start)
{
int startx = artist_get_x(s->vram_start);
int starty = artist_get_y(s->vram_start);
int sizex = artist_get_x(s->blockmove_size);
int sizey = artist_get_y(s->blockmove_size);
int linexy = s->line_xy >> 16;
int endx, endy;
endx = startx;
endy = starty;
if (sizex > 0) {
endx = startx + linexy;
}
if (sizex < 0) {
endx = startx;
startx -= linexy;
}
if (sizey > 0) {
endy = starty + linexy;
}
if (sizey < 0) {
endy = starty;
starty -= linexy;
}
if (startx < 0) {
startx = 0;
}
if (endx < 0) {
endx = 0;
}
if (starty < 0) {
starty = 0;
}
if (endy < 0) {
endy = 0;
}
draw_line(s, startx, starty, endx, endy, false, -1, -1);
}
static void draw_line_end(ARTISTState *s, bool update_start)
{
int startx = artist_get_x(s->vram_start);
int starty = artist_get_y(s->vram_start);
int endx = artist_get_x(s->line_end);
int endy = artist_get_y(s->line_end);
draw_line(s, startx, starty, endx, endy, update_start, -1, -1);
}
static void font_write16(ARTISTState *s, uint16_t val)
{
struct vram_buffer *buf;
uint32_t color = (s->image_bitmap_op & 2) ? s->fg_color : s->bg_color;
uint16_t mask;
int i;
unsigned int startx = artist_get_x(s->vram_start);
unsigned int starty = artist_get_y(s->vram_start) + s->font_write_pos_y;
unsigned int offset = starty * s->width + startx;
buf = &s->vram_buffer[ARTIST_BUFFER_AP];
if (startx >= buf->width || starty >= buf->height ||
offset + 16 >= buf->size) {
return;
}
for (i = 0; i < 16; i++) {
mask = 1 << (15 - i);
if (val & mask) {
artist_rop8(s, buf, offset + i, color);
} else {
if (!(s->image_bitmap_op & 0x20000000)) {
artist_rop8(s, buf, offset + i, s->bg_color);
}
}
}
artist_invalidate_lines(buf, starty, 1);
}
static void font_write(ARTISTState *s, uint32_t val)
{
font_write16(s, val >> 16);
if (++s->font_write_pos_y == artist_get_y(s->blockmove_size)) {
s->vram_start += (s->blockmove_size & 0xffff0000);
return;
}
font_write16(s, val & 0xffff);
if (++s->font_write_pos_y == artist_get_y(s->blockmove_size)) {
s->vram_start += (s->blockmove_size & 0xffff0000);
return;
}
}
static void combine_write_reg(hwaddr addr, uint64_t val, int size, void *out)
{
/*
* FIXME: is there a qemu helper for this?
*/
#ifndef HOST_WORDS_BIGENDIAN
addr ^= 3;
#endif
switch (size) {
case 1:
*(uint8_t *)(out + (addr & 3)) = val;
break;
case 2:
*(uint16_t *)(out + (addr & 2)) = val;
break;
case 4:
*(uint32_t *)out = val;
break;
default:
qemu_log_mask(LOG_UNIMP, "unsupported write size: %d\n", size);
}
}
static void artist_vram_write4(ARTISTState *s, struct vram_buffer *buf,
uint32_t offset, uint32_t data)
{
int i;
int mask = s->vram_bitmask >> 28;
for (i = 0; i < 4; i++) {
if (!(s->image_bitmap_op & 0x20000000) || (mask & 8)) {
artist_rop8(s, buf, offset + i, data >> 24);
data <<= 8;
mask <<= 1;
}
}
memory_region_set_dirty(&buf->mr, offset, 3);
}
static void artist_vram_write32(ARTISTState *s, struct vram_buffer *buf,
uint32_t offset, int size, uint32_t data,
int fg, int bg)
{
uint32_t mask, vram_bitmask = s->vram_bitmask >> ((4 - size) * 8);
int i, pix_count = size * 8;
for (i = 0; i < pix_count && offset + i < buf->size; i++) {
mask = 1 << (pix_count - 1 - i);
if (!(s->image_bitmap_op & 0x20000000) || (vram_bitmask & mask)) {
if (data & mask) {
artist_rop8(s, buf, offset + i, fg);
} else {
if (!(s->image_bitmap_op & 0x10000002)) {
artist_rop8(s, buf, offset + i, bg);
}
}
}
}
memory_region_set_dirty(&buf->mr, offset, pix_count);
}
static int get_vram_offset(ARTISTState *s, struct vram_buffer *buf,
int pos, int posy)
{
unsigned int posx, width;
width = buf->width;
posx = ADDR_TO_X(pos);
posy += ADDR_TO_Y(pos);
return posy * width + posx;
}
static int vram_bit_write(ARTISTState *s, uint32_t pos, int posy,
uint32_t data, int size)
{
struct vram_buffer *buf = vram_write_buffer(s);
switch (s->dst_bm_access >> 16) {
case 0x3ba0:
case 0xbbe0:
artist_vram_write4(s, buf, pos, bswap32(data));
pos += 4;
break;
case 0x1360: /* linux */
artist_vram_write4(s, buf, get_vram_offset(s, buf, pos, posy), data);
pos += 4;
break;
case 0x13a0:
artist_vram_write4(s, buf, get_vram_offset(s, buf, pos >> 2, posy),
data);
pos += 16;
break;
case 0x2ea0:
artist_vram_write32(s, buf, get_vram_offset(s, buf, pos >> 2, posy),
size, data, s->fg_color, s->bg_color);
pos += 4;
break;
case 0x28a0:
artist_vram_write32(s, buf, get_vram_offset(s, buf, pos >> 2, posy),
size, data, 1, 0);
pos += 4;
break;
default:
qemu_log_mask(LOG_UNIMP, "%s: unknown dst bm access %08x\n",
__func__, s->dst_bm_access);
break;
}
if (vram_write_bufidx(s) == ARTIST_BUFFER_CURSOR1 ||
vram_write_bufidx(s) == ARTIST_BUFFER_CURSOR2) {
artist_invalidate_cursor(s);
}
return pos;
}
static void artist_vram_write(void *opaque, hwaddr addr, uint64_t val,
unsigned size)
{
ARTISTState *s = opaque;
s->vram_char_y = 0;
trace_artist_vram_write(size, addr, val);
vram_bit_write(opaque, addr, 0, val, size);
}
static uint64_t artist_vram_read(void *opaque, hwaddr addr, unsigned size)
{
ARTISTState *s = opaque;
struct vram_buffer *buf;
unsigned int offset;
uint64_t val;
buf = vram_read_buffer(s);
if (!buf->size) {
return 0;
}
offset = get_vram_offset(s, buf, addr >> 2, 0);
if (offset > buf->size) {
return 0;
}
switch (s->src_bm_access >> 16) {
case 0x3ba0:
val = *(uint32_t *)(buf->data + offset);
break;
case 0x13a0:
case 0x2ea0:
val = bswap32(*(uint32_t *)(buf->data + offset));
break;
default:
qemu_log_mask(LOG_UNIMP, "%s: unknown src bm access %08x\n",
__func__, s->dst_bm_access);
val = -1ULL;
break;
}
trace_artist_vram_read(size, addr, val);
return val;
}
static void artist_reg_write(void *opaque, hwaddr addr, uint64_t val,
unsigned size)
{
ARTISTState *s = opaque;
int width, height;
trace_artist_reg_write(size, addr, artist_reg_name(addr & ~3ULL), val);
switch (addr & ~3ULL) {
case 0x100080:
combine_write_reg(addr, val, size, &s->reg_100080);
break;
case FG_COLOR:
combine_write_reg(addr, val, size, &s->fg_color);
break;
case BG_COLOR:
combine_write_reg(addr, val, size, &s->bg_color);
break;
case VRAM_BITMASK:
combine_write_reg(addr, val, size, &s->vram_bitmask);
break;
case VRAM_WRITE_INCR_Y:
vram_bit_write(s, s->vram_pos, s->vram_char_y++, val, size);
break;
case VRAM_WRITE_INCR_X:
case VRAM_WRITE_INCR_X2:
s->vram_pos = vram_bit_write(s, s->vram_pos, s->vram_char_y, val, size);
break;
case VRAM_IDX:
combine_write_reg(addr, val, size, &s->vram_pos);
s->vram_char_y = 0;
s->draw_line_pattern = 0;
break;
case VRAM_START:
combine_write_reg(addr, val, size, &s->vram_start);
s->draw_line_pattern = 0;
break;
case VRAM_START_TRIGGER:
combine_write_reg(addr, val, size, &s->vram_start);
fill_window(s, artist_get_x(s->vram_start),
artist_get_y(s->vram_start),
artist_get_x(s->blockmove_size),
artist_get_y(s->blockmove_size));
break;
case VRAM_SIZE_TRIGGER:
combine_write_reg(addr, val, size, &s->vram_size);
if (size == 2 && !(addr & 2)) {
height = artist_get_y(s->blockmove_size);
} else {
height = artist_get_y(s->vram_size);
}
if (size == 2 && (addr & 2)) {
width = artist_get_x(s->blockmove_size);
} else {
width = artist_get_x(s->vram_size);
}
fill_window(s, artist_get_x(s->vram_start),
artist_get_y(s->vram_start),
width, height);
break;
case LINE_XY:
combine_write_reg(addr, val, size, &s->line_xy);
if (s->draw_line_pattern) {
draw_line_pattern_next(s);
} else {
draw_line_xy(s, true);
}
break;
case PATTERN_LINE_START:
combine_write_reg(addr, val, size, &s->line_pattern_start);
s->draw_line_pattern = 1;
draw_line_pattern_start(s);
break;
case LINE_SIZE:
combine_write_reg(addr, val, size, &s->line_size);
draw_line_size(s, true);
break;
case LINE_END:
combine_write_reg(addr, val, size, &s->line_end);
draw_line_end(s, true);
break;
case BLOCK_MOVE_SIZE:
combine_write_reg(addr, val, size, &s->blockmove_size);
break;
case BLOCK_MOVE_SOURCE:
combine_write_reg(addr, val, size, &s->blockmove_source);
break;
case BLOCK_MOVE_DEST_TRIGGER:
combine_write_reg(addr, val, size, &s->blockmove_dest);
block_move(s, artist_get_x(s->blockmove_source),
artist_get_y(s->blockmove_source),
artist_get_x(s->blockmove_dest),
artist_get_y(s->blockmove_dest),
artist_get_x(s->blockmove_size),
artist_get_y(s->blockmove_size));
break;
case BLOCK_MOVE_SIZE_TRIGGER:
combine_write_reg(addr, val, size, &s->blockmove_size);