forked from tonioni/WinUAE
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gfxboard.cpp
3138 lines (2929 loc) · 88.3 KB
/
gfxboard.cpp
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
/*
* UAE - The Un*x Amiga Emulator
*
* Cirrus Logic based graphics board emulation
*
* Copyright 2013 Toni Wilen
*
*/
#define VRAMLOG 0
#define MEMLOGR 0
#define MEMLOGW 0
#define MEMLOGINDIRECT 0
#define REGDEBUG 0
#define MEMDEBUG 0
#define MEMDEBUGMASK 0x7fffff
#define MEMDEBUGTEST 0x3fc000
#define MEMDEBUGCLEAR 0
#define PICASSOIV_DEBUG_IO 0
#if MEMLOGR
static bool memlogr = true;
static bool memlogw = true;
#endif
#define BYTESWAP_WORD -1
#define BYTESWAP_LONG 1
#include "sysconfig.h"
#include "sysdeps.h"
#include "options.h"
#include "uae.h"
#include "memory.h"
#include "debug.h"
#include "custom.h"
#include "newcpu.h"
#include "picasso96.h"
#include "statusline.h"
#include "rommgr.h"
#include "zfile.h"
#include "gfxboard.h"
#include "rommgr.h"
#include "xwin.h"
#include "devices.h"
#include "qemuvga/qemuuaeglue.h"
#include "qemuvga/vga.h"
#define MONITOR_SWITCH_DELAY 25
#define GFXBOARD_AUTOCONFIG_SIZE 131072
#define BOARD_REGISTERS_SIZE 0x00010000
#define BOARD_MANUFACTURER_PICASSO 2167
#define BOARD_MODEL_MEMORY_PICASSOII 11
#define BOARD_MODEL_REGISTERS_PICASSOII 12
#define BOARD_MODEL_MEMORY_PICASSOIV 24
#define BOARD_MODEL_REGISTERS_PICASSOIV 23
#define PICASSOIV_REG 0x00600000
#define PICASSOIV_IO 0x00200000
#define PICASSOIV_VRAM1 0x01000000
#define PICASSOIV_VRAM2 0x00800000
#define PICASSOIV_ROM_OFFSET 0x0200
#define PICASSOIV_FLASH_OFFSET 0x8000
#define PICASSOIV_FLASH_BANK 0x8000
#define PICASSOIV_MAX_FLASH (GFXBOARD_AUTOCONFIG_SIZE - 32768)
#define PICASSOIV_BANK_UNMAPFLASH 2
#define PICASSOIV_BANK_MAPRAM 4
#define PICASSOIV_BANK_FLASHBANK 128
#define PICASSOIV_INT_VBLANK 128
#define BOARD_MANUFACTURER_PICCOLO 2195
#define BOARD_MODEL_MEMORY_PICCOLO 5
#define BOARD_MODEL_REGISTERS_PICCOLO 6
#define BOARD_MODEL_MEMORY_PICCOLO64 10
#define BOARD_MODEL_REGISTERS_PICCOLO64 11
#define BOARD_MANUFACTURER_SPECTRUM 2193
#define BOARD_MODEL_MEMORY_SPECTRUM 1
#define BOARD_MODEL_REGISTERS_SPECTRUM 2
struct gfxboard
{
const TCHAR *name;
const TCHAR *manufacturername;
const TCHAR *configname;
int manufacturer;
int model_memory;
int model_registers;
int serial;
int vrammin;
int vrammax;
int banksize;
int chiptype;
int configtype;
int irq;
bool swap;
uae_u32 romtype;
uae_u8 er_type;
struct gfxboard_func *func;
};
#define ISP4() (gb->rbc->rtgmem_type == GFXBOARD_PICASSO4_Z2 || gb->rbc->rtgmem_type == GFXBOARD_PICASSO4_Z3)
// Picasso II: 8* 4x256 (1M) or 16* 4x256 (2M)
// Piccolo: 8* 4x256 + 2* 16x256 (2M)
static const struct gfxboard boards[] =
{
{
_T("Picasso II"), _T("Village Tronic"), _T("PicassoII"),
BOARD_MANUFACTURER_PICASSO, BOARD_MODEL_MEMORY_PICASSOII, BOARD_MODEL_REGISTERS_PICASSOII,
0x00020000, 0x00100000, 0x00200000, 0x00200000, CIRRUS_ID_CLGD5426, 2, 0, false
},
{
_T("Picasso II+"), _T("Village Tronic"), _T("PicassoII+"),
BOARD_MANUFACTURER_PICASSO, BOARD_MODEL_MEMORY_PICASSOII, BOARD_MODEL_REGISTERS_PICASSOII,
0x00100000, 0x00100000, 0x00200000, 0x00200000, CIRRUS_ID_CLGD5428, 2, 2, false
},
{
_T("Piccolo Zorro II"), _T("Ingenieurbüro Helfrich"), _T("Piccolo_Z2"),
BOARD_MANUFACTURER_PICCOLO, BOARD_MODEL_MEMORY_PICCOLO, BOARD_MODEL_REGISTERS_PICCOLO,
0x00000000, 0x00100000, 0x00200000, 0x00200000, CIRRUS_ID_CLGD5426, 2, 6, true
},
{
_T("Piccolo Zorro III"), _T("Ingenieurbüro Helfrich"), _T("Piccolo_Z3"),
BOARD_MANUFACTURER_PICCOLO, BOARD_MODEL_MEMORY_PICCOLO, BOARD_MODEL_REGISTERS_PICCOLO,
0x00000000, 0x00100000, 0x00200000, 0x00200000, CIRRUS_ID_CLGD5426, 3, 6, true
},
{
_T("Piccolo SD64 Zorro II"), _T("Ingenieurbüro Helfrich"), _T("PiccoloSD64_Z2"),
BOARD_MANUFACTURER_PICCOLO, BOARD_MODEL_MEMORY_PICCOLO64, BOARD_MODEL_REGISTERS_PICCOLO64,
0x00000000, 0x00200000, 0x00400000, 0x00400000, CIRRUS_ID_CLGD5434, 2, 6, true
},
{
_T("Piccolo SD64 Zorro III"), _T("Ingenieurbüro Helfrich"), _T("PiccoloSD64_Z3"),
BOARD_MANUFACTURER_PICCOLO, BOARD_MODEL_MEMORY_PICCOLO64, BOARD_MODEL_REGISTERS_PICCOLO64,
0x00000000, 0x00200000, 0x00400000, 0x01000000, CIRRUS_ID_CLGD5434, 3, 6, true
},
{
_T("Spectrum 28/24 Zorro II"), _T("Great Valley Products"), _T("Spectrum28/24_Z2"),
BOARD_MANUFACTURER_SPECTRUM, BOARD_MODEL_MEMORY_SPECTRUM, BOARD_MODEL_REGISTERS_SPECTRUM,
0x00000000, 0x00100000, 0x00200000, 0x00200000, CIRRUS_ID_CLGD5428, 2, 6, true
},
{
_T("Spectrum 28/24 Zorro III"), _T("Great Valley Products"), _T("Spectrum28/24_Z3"),
BOARD_MANUFACTURER_SPECTRUM, BOARD_MODEL_MEMORY_SPECTRUM, BOARD_MODEL_REGISTERS_SPECTRUM,
0x00000000, 0x00100000, 0x00200000, 0x00200000, CIRRUS_ID_CLGD5428, 3, 6, true
},
{
_T("Picasso IV Zorro II"), _T("Village Tronic"), _T("PicassoIV_Z2"),
BOARD_MANUFACTURER_PICASSO, BOARD_MODEL_MEMORY_PICASSOIV, BOARD_MODEL_REGISTERS_PICASSOIV,
0x00000000, 0x00200000, 0x00400000, 0x00400000, CIRRUS_ID_CLGD5446, 2, 2, false,
ROMTYPE_PICASSOIV
},
{
// REG:00600000 IO:00200000 VRAM:01000000
_T("Picasso IV Zorro III"), _T("Village Tronic"), _T("PicassoIV_Z3"),
BOARD_MANUFACTURER_PICASSO, BOARD_MODEL_MEMORY_PICASSOIV, 0,
0x00000000, 0x00400000, 0x00400000, 0x02000000, CIRRUS_ID_CLGD5446, 3, 2, false,
ROMTYPE_PICASSOIV
},
{
_T("A2410"), _T("Commodore"), _T("A2410"),
1030, 0, 0,
0x00000000, 0x00200000, 0x00200000, 0x10000, 0, 0, 2, false,
0, 0xc1, &a2410_func
},
#if 0
{
_T("Resolver"), _T("DMI"), _T("Resolver"),
2129, 1, 0,
0x00000000, 0x00200000, 0x00200000, 0x10000, 0, 0, 2, false,
0, 0xc1, &a2410_func
},
#endif
{
_T("x86 bridgeboard VGA"), _T("x86"), _T("VGA"),
0, 0, 0,
0x00000000, 0x00100000, 0x00200000, 0x00000000, CIRRUS_ID_CLGD5426, 0, 0, false,
ROMTYPE_x86_VGA
},
{
_T("Harlequin"), _T("ACS"), _T("Harlequin_PAL"),
2118, 100, 0,
0x00000000, 0x00200000, 0x00200000, 0x10000, 0, 0, 2, false,
ROMTYPE_HARLEQUIN, 0xc2, &harlequin_func
},
{
NULL
}
};
struct rtggfxboard
{
bool active;
int rtg_index;
int monitor_id;
struct rtgboardconfig *rbc;
TCHAR memorybankname[40];
TCHAR memorybanknamenojit[40];
TCHAR wbsmemorybankname[40];
TCHAR lbsmemorybankname[40];
TCHAR regbankname[40];
int configured_mem, configured_regs;
const struct gfxboard *board;
uae_u8 expamem_lo;
uae_u8 *automemory;
uae_u32 banksize_mask;
uaecptr io_start, io_end;
uaecptr mem_start[2], mem_end[2];
uae_u8 picassoiv_bank, picassoiv_flifi;
uae_u8 p4autoconfig[256];
struct zfile *p4rom;
bool p4z2;
uae_u32 p4_mmiobase;
uae_u32 p4_special_mask;
uae_u32 p4_vram_bank[2];
CirrusVGAState vga;
uae_u8 *vram, *vramend, *vramrealstart;
int vram_start_offset;
uae_u32 gfxboardmem_start;
bool monswitch_current, monswitch_new;
bool monswitch_keep_trying;
bool monswitch_reset;
int monswitch_delay;
int fullrefresh;
bool modechanged;
uae_u8 *gfxboard_surface, *fakesurface_surface;
bool gfxboard_vblank;
bool gfxboard_intena;
bool vram_enabled, vram_offset_enabled;
hwaddr vram_offset[2];
uae_u8 cirrus_pci[0x44];
uae_u8 p4i2c;
uae_u8 p4_pci[0x44];
int vga_width, vga_height;
bool vga_refresh_active;
bool vga_changed;
int device_settings;
uae_u32 vgaioregionptr, vgavramregionptr, vgabank0regionptr, vgabank1regionptr;
const MemoryRegionOps *vgaio, *vgaram, *vgalowram, *vgammio;
MemoryRegion vgaioregion, vgavramregion;
DisplaySurface gfxsurface, fakesurface;
addrbank gfxboard_bank_memory;
addrbank gfxboard_bank_memory_nojit;
addrbank gfxboard_bank_wbsmemory;
addrbank gfxboard_bank_lbsmemory;
addrbank gfxboard_bank_nbsmemory;
addrbank gfxboard_bank_registers;
addrbank gfxboard_bank_special;
addrbank *gfxmem_bank;
uae_u8 *vram_back;
struct autoconfig_info *aci;
struct gfxboard_func *func;
void *userdata;
};
static struct rtggfxboard rtggfxboards[MAX_RTG_BOARDS];
static struct rtggfxboard *only_gfx_board;
static int rtg_visible[MAX_AMIGADISPLAYS];
static int rtg_initial[MAX_AMIGADISPLAYS];
static int total_active_gfx_boards;
static int vram_ram_a8;
static DisplaySurface fakesurface;
DECLARE_MEMORY_FUNCTIONS(gfxboard);
DECLARE_MEMORY_FUNCTIONS_WITH_SUFFIX(gfxboard, mem);
DECLARE_MEMORY_FUNCTIONS_WITH_SUFFIX(gfxboard, mem_nojit);
DECLARE_MEMORY_FUNCTIONS_WITH_SUFFIX(gfxboard, bsmem);
DECLARE_MEMORY_FUNCTIONS_WITH_SUFFIX(gfxboard, wbsmem);
DECLARE_MEMORY_FUNCTIONS_WITH_SUFFIX(gfxboard, lbsmem);
DECLARE_MEMORY_FUNCTIONS_WITH_SUFFIX(gfxboard, nbsmem);
DECLARE_MEMORY_FUNCTIONS_WITH_SUFFIX(gfxboard, regs);
DECLARE_MEMORY_FUNCTIONS_WITH_SUFFIX(gfxboards, regs);
static const addrbank tmpl_gfxboard_bank_memory = {
gfxboard_lget_mem, gfxboard_wget_mem, gfxboard_bget_mem,
gfxboard_lput_mem, gfxboard_wput_mem, gfxboard_bput_mem,
gfxboard_xlate, gfxboard_check, NULL, NULL, NULL,
gfxboard_lget_mem, gfxboard_wget_mem,
ABFLAG_RAM | ABFLAG_THREADSAFE | ABFLAG_CACHE_ENABLE_ALL, 0, 0
};
static const addrbank tmpl_gfxboard_bank_memory_nojit = {
gfxboard_lget_mem_nojit, gfxboard_wget_mem_nojit, gfxboard_bget_mem_nojit,
gfxboard_lput_mem_nojit, gfxboard_wput_mem_nojit, gfxboard_bput_mem_nojit,
gfxboard_xlate, gfxboard_check, NULL, NULL, NULL,
gfxboard_lget_mem_nojit, gfxboard_wget_mem_nojit,
ABFLAG_RAM | ABFLAG_THREADSAFE | ABFLAG_CACHE_ENABLE_ALL, S_READ, S_WRITE
};
static const addrbank tmpl_gfxboard_bank_wbsmemory = {
gfxboard_lget_wbsmem, gfxboard_wget_wbsmem, gfxboard_bget_wbsmem,
gfxboard_lput_wbsmem, gfxboard_wput_wbsmem, gfxboard_bput_wbsmem,
gfxboard_xlate, gfxboard_check, NULL, NULL, NULL,
gfxboard_lget_wbsmem, gfxboard_wget_wbsmem,
ABFLAG_RAM | ABFLAG_THREADSAFE | ABFLAG_PPCIOSPACE | ABFLAG_CACHE_ENABLE_ALL, S_READ, S_WRITE
};
static const addrbank tmpl_gfxboard_bank_lbsmemory = {
gfxboard_lget_lbsmem, gfxboard_wget_lbsmem, gfxboard_bget_lbsmem,
gfxboard_lput_lbsmem, gfxboard_wput_lbsmem, gfxboard_bput_lbsmem,
gfxboard_xlate, gfxboard_check, NULL, NULL, NULL,
gfxboard_lget_lbsmem, gfxboard_wget_lbsmem,
ABFLAG_RAM | ABFLAG_THREADSAFE | ABFLAG_PPCIOSPACE | ABFLAG_CACHE_ENABLE_ALL, S_READ, S_WRITE
};
static const addrbank tmpl_gfxboard_bank_nbsmemory = {
gfxboard_lget_nbsmem, gfxboard_wget_nbsmem, gfxboard_bget_bsmem,
gfxboard_lput_nbsmem, gfxboard_wput_nbsmem, gfxboard_bput_bsmem,
gfxboard_xlate, gfxboard_check, NULL, NULL, _T("Picasso IV banked VRAM"),
gfxboard_lget_nbsmem, gfxboard_wget_nbsmem,
ABFLAG_RAM | ABFLAG_THREADSAFE | ABFLAG_PPCIOSPACE | ABFLAG_CACHE_ENABLE_ALL, S_READ, S_WRITE
};
static const addrbank tmpl_gfxboard_bank_registers = {
gfxboard_lget_regs, gfxboard_wget_regs, gfxboard_bget_regs,
gfxboard_lput_regs, gfxboard_wput_regs, gfxboard_bput_regs,
default_xlate, default_check, NULL, NULL, NULL,
dummy_lgeti, dummy_wgeti,
ABFLAG_IO | ABFLAG_SAFE, S_READ, S_WRITE
};
static const addrbank tmpl_gfxboard_bank_special = {
gfxboards_lget_regs, gfxboards_wget_regs, gfxboards_bget_regs,
gfxboards_lput_regs, gfxboards_wput_regs, gfxboards_bput_regs,
default_xlate, default_check, NULL, NULL, _T("Picasso IV MISC"),
dummy_lgeti, dummy_wgeti,
ABFLAG_IO | ABFLAG_SAFE, S_READ, S_WRITE
};
static void ew(struct rtggfxboard *gb, int addr, uae_u32 value)
{
addr &= 0xffff;
if (addr == 00 || addr == 02 || addr == 0x40 || addr == 0x42) {
gb->automemory[addr] = (value & 0xf0);
gb->automemory[addr + 2] = (value & 0x0f) << 4;
} else {
gb->automemory[addr] = ~(value & 0xf0);
gb->automemory[addr + 2] = ~((value & 0x0f) << 4);
}
}
int gfxboard_get_devnum(struct uae_prefs *p, int index)
{
int devnum = 0;
uae_u32 romtype = gfxboard_get_romtype(&p->rtgboards[index]);
if (!romtype)
return devnum;
for (int i = 0; i < index; i++) {
if (gfxboard_get_romtype(&p->rtgboards[i]) == romtype)
devnum++;
}
return devnum;
}
void gfxboard_get_a8_vram(int index)
{
addrbank *ab = gfxmem_banks[index];
if (vram_ram_a8 > 0) {
addrbank *prev = gfxmem_banks[vram_ram_a8 - 1];
ab->baseaddr = prev->baseaddr;
} else {
mapped_malloc(ab);
vram_ram_a8 = index + 1;
}
}
void gfxboard_free_vram(int index)
{
addrbank *ab = gfxmem_banks[index];
if (vram_ram_a8 - 1 == index || vram_ram_a8 == 0) {
mapped_free(ab);
}
if (vram_ram_a8 - 1 == index)
vram_ram_a8 = 0;
}
static void gfxboard_hsync_handler(void)
{
for (int i = 0; i < MAX_RTG_BOARDS; i++) {
struct rtggfxboard *gb = &rtggfxboards[i];
if (gb->func && gb->userdata) {
gb->func->hsync(gb->userdata);
}
}
}
static void init_board (struct rtggfxboard *gb)
{
struct rtgboardconfig *rbc = gb->rbc;
int vramsize = gb->board->vrammax;
int chiptype = gb->board->chiptype;
if (gb->board->romtype == ROMTYPE_x86_VGA) {
struct romconfig *rc = get_device_romconfig(&currprefs, gb->board->romtype, 0);
chiptype = CIRRUS_ID_CLGD5426;
if (rc && rc->device_settings == 1) {
chiptype = CIRRUS_ID_CLGD5429;
}
}
gb->active = true;
gb->vga_width = 0;
gb->vga_height = 0;
mapped_free(gb->gfxmem_bank);
gb->vram_start_offset = 0;
if (ISP4() && !gb->p4z2) { // JIT direct compatibility hack
gb->vram_start_offset = 0x01000000;
}
vramsize += gb->vram_start_offset;
xfree (gb->fakesurface_surface);
gb->fakesurface_surface = xmalloc (uae_u8, 4 * 10000);
gb->vram_offset[0] = gb->vram_offset[1] = 0;
gb->vram_enabled = true;
gb->vram_offset_enabled = false;
gb->gfxmem_bank->reserved_size = vramsize;
gb->gfxmem_bank->start = gb->gfxboardmem_start;
if (gb->board->manufacturer) {
gb->gfxmem_bank->label = _T("*");
mapped_malloc(gb->gfxmem_bank);
} else {
gb->gfxmem_bank->label = _T("*");
gb->vram_back = xmalloc(uae_u8, vramsize);
if (&get_mem_bank(0x800000) == &dummy_bank)
gb->gfxmem_bank->start = 0x800000;
else
gb->gfxmem_bank->start = 0xa00000;
gfxboard_get_a8_vram(gb->rbc->rtg_index);
}
gb->vram = gb->gfxmem_bank->baseaddr;
gb->vramend = gb->gfxmem_bank->baseaddr + vramsize;
gb->vramrealstart = gb->vram;
gb->vram += gb->vram_start_offset;
gb->vramend += gb->vram_start_offset;
//gb->gfxmem_bank->baseaddr = gb->vram;
// restore original value because this is checked against
// configured size in expansion.cpp
gb->gfxmem_bank->allocated_size = rbc->rtgmem_size;
gb->gfxmem_bank->reserved_size = rbc->rtgmem_size;
gb->vga.vga.vram_size_mb = rbc->rtgmem_size >> 20;
gb->vgaioregion.opaque = &gb->vgaioregionptr;
gb->vgaioregion.data = gb;
gb->vgavramregion.opaque = &gb->vgavramregionptr;
gb->vgavramregion.data = gb;
gb->vga.vga.vram.opaque = &gb->vgavramregionptr;
gb->vga.vga.vram.data = gb;
gb->vga.cirrus_vga_io.data = gb;
gb->vga.low_mem_container.data = gb;
gb->vga.low_mem.data = gb;
gb->vga.cirrus_bank[0].data = gb;
gb->vga.cirrus_bank[1].data = gb;
gb->vga.cirrus_linear_io.data = gb;
gb->vga.cirrus_linear_bitblt_io.data = gb;
gb->vga.cirrus_mmio_io.data = gb;
gb->gfxsurface.data = gb;
gb->fakesurface.data = gb;
vga_common_init(&gb->vga.vga);
gb->vga.vga.con = (void*)gb;
cirrus_init_common(&gb->vga, chiptype, 0, NULL, NULL, gb->board->manufacturer == 0, gb->board->romtype == ROMTYPE_x86_VGA);
picasso_allocatewritewatch(gb->rbc->rtg_index, gb->rbc->rtgmem_size);
device_add_hsync(gfxboard_hsync_handler);
}
static int GetBytesPerPixel(RGBFTYPE RGBfmt)
{
switch (RGBfmt)
{
case RGBFB_CLUT:
return 1;
case RGBFB_A8R8G8B8:
case RGBFB_A8B8G8R8:
case RGBFB_R8G8B8A8:
case RGBFB_B8G8R8A8:
return 4;
case RGBFB_B8G8R8:
case RGBFB_R8G8B8:
return 3;
case RGBFB_R5G5B5:
case RGBFB_R5G6B5:
case RGBFB_R5G6B5PC:
case RGBFB_R5G5B5PC:
case RGBFB_B5G6R5PC:
case RGBFB_B5G5R5PC:
return 2;
}
return 0;
}
static bool gfxboard_setmode(struct rtggfxboard *gb, struct gfxboard_mode *mode)
{
struct amigadisplay *ad = &adisplays[gb->monitor_id];
struct picasso96_state_struct *state = &picasso96_state[gb->monitor_id];
state->Width = mode->width;
state->Height = mode->height;
int bpp = GetBytesPerPixel(mode->mode);
state->BytesPerPixel = bpp;
state->RGBFormat = mode->mode;
write_log(_T("GFXBOARD %dx%dx%d\n"), mode->width, mode->height, bpp);
if (!ad->picasso_requested_on && !ad->picasso_on) {
ad->picasso_requested_on = true;
set_config_changed();
}
return true;
}
static void gfxboard_free_slot2(struct rtggfxboard *gb)
{
struct amigadisplay *ad = &adisplays[gb->monitor_id];
gb->active = false;
if (rtg_visible[gb->monitor_id] == gb->rtg_index) {
rtg_visible[gb->monitor_id] = -1;
ad->picasso_requested_on = false;
set_config_changed();
}
gb->userdata = NULL;
gb->func = NULL;
xfree(gb->automemory);
gb->automemory = NULL;
}
bool gfxboard_allocate_slot(int board, int idx)
{
struct rtggfxboard *gb = &rtggfxboards[idx];
gb->active = true;
gb->rtg_index = idx;
const struct gfxboard *gfxb = &boards[board - GFXBOARD_HARDWARE];
gb->board = gfxb;
return true;
}
void gfxboard_free_slot(int idx)
{
struct rtggfxboard *gb = &rtggfxboards[idx];
gfxboard_free_slot2(gb);
}
static int gfx_temp_bank_idx;
static uae_u32 REGPARAM2 gtb_wget(uaecptr addr)
{
struct rtggfxboard *gb = &rtggfxboards[gfx_temp_bank_idx];
addr &= gb->banksize_mask;
return 0;
}
static uae_u32 REGPARAM2 gtb_bget(uaecptr addr)
{
struct rtggfxboard *gb = &rtggfxboards[gfx_temp_bank_idx];
addr &= gb->banksize_mask;
if (addr < GFXBOARD_AUTOCONFIG_SIZE)
return gb->automemory[addr];
return 0xff;
}
static void REGPARAM2 gtb_bput(uaecptr addr, uae_u32 b)
{
struct rtggfxboard *gb = &rtggfxboards[gfx_temp_bank_idx];
b &= 0xff;
addr &= gb->banksize_mask;
if (addr == 0x48) {
gfx_temp_bank_idx++;
map_banks_z2(gb->gfxmem_bank, expamem_board_pointer >> 16, expamem_board_size >> 16);
gb->func->configured(gb->userdata, expamem_board_pointer);
expamem_next(gb->gfxmem_bank, NULL);
return;
}
if (addr == 0x4c) {
expamem_shutup(gb->gfxmem_bank);
return;
}
}
static void REGPARAM2 gtb_wput(uaecptr addr, uae_u32 b)
{
struct rtggfxboard *gb = &rtggfxboards[gfx_temp_bank_idx];
b &= 0xffff;
addr &= gb->banksize_mask;
if (addr == 0x44) {
gfx_temp_bank_idx++;
map_banks_z3(gb->gfxmem_bank, expamem_board_pointer >> 16, expamem_board_size >> 16);
gb->func->configured(gb->userdata, expamem_board_pointer);
expamem_next(gb->gfxmem_bank, NULL);
return;
}
}
static addrbank gfx_temp_bank =
{
gtb_wget, gtb_wget, gtb_bget,
gtb_wput, gtb_wput, gtb_bput,
default_xlate, default_check, NULL, NULL, _T("GFXBOARD_AUTOCONFIG"),
gtb_wget, gtb_wget,
ABFLAG_IO, S_READ, S_WRITE
};
bool gfxboard_init_board(struct autoconfig_info *aci)
{
const struct gfxboard *gfxb = &boards[aci->prefs->rtgboards[aci->devnum].rtgmem_type - GFXBOARD_HARDWARE];
struct rtggfxboard *gb = &rtggfxboards[aci->devnum];
gb->func = gfxb->func;
gb->monitor_id = aci->prefs->rtgboards[aci->devnum].monitor_id;
memset(aci->autoconfig_bytes, 0xff, sizeof aci->autoconfig_bytes);
if (!gb->automemory)
gb->automemory = xmalloc(uae_u8, GFXBOARD_AUTOCONFIG_SIZE);
memset(gb->automemory, 0xff, GFXBOARD_AUTOCONFIG_SIZE);
ew(gb, 0x00, gfxb->er_type);
ew(gb, 0x04, gfxb->model_memory);
ew(gb, 0x10, (gfxb->manufacturer >> 8) & 0xff);
ew(gb, 0x14, (gfxb->manufacturer >> 0) & 0xff);
ew(gb, 0x18, (gfxb->serial >> 24) & 0xff);
ew(gb, 0x1c, (gfxb->serial >> 16) & 0xff);
ew(gb, 0x20, (gfxb->serial >> 8) & 0xff);
ew(gb, 0x24, (gfxb->serial >> 0) & 0xff);
memcpy(aci->autoconfig_raw, gb->automemory, sizeof aci->autoconfig_raw);
if (!gb->func->init(aci))
return false;
for(int i = 0; i < sizeof aci->autoconfig_bytes; i++) {
if (aci->autoconfig_bytes[i] != 0xff)
ew(gb, i * 4, aci->autoconfig_bytes[i]);
}
memcpy(aci->autoconfig_raw, gb->automemory, sizeof aci->autoconfig_raw);
if (!aci->doinit)
return true;
gb->banksize_mask = gfxb->banksize - 1;
gb->userdata = aci->userdata;
gb->active = true;
gb->rtg_index = aci->devnum;
gb->board = gfxb;
gfx_temp_bank_idx = aci->devnum;
gb->gfxmem_bank = aci->addrbank;
aci->addrbank = &gfx_temp_bank;
return true;
}
static void vga_update_size(struct rtggfxboard *gb)
{
// this forces qemu_console_resize() call
gb->vga.vga.graphic_mode = -1;
gb->vga.vga.monid = gb->monitor_id;
gb->vga.vga.hw_ops->gfx_update(&gb->vga);
}
static bool gfxboard_setmode_qemu(struct rtggfxboard *gb)
{
int bpp = gb->vga.vga.get_bpp(&gb->vga.vga);
if (bpp == 0)
bpp = 8;
vga_update_size(gb);
if (gb->vga_width <= 16 || gb->vga_height <= 16)
return false;
struct gfxboard_mode mode;
mode.width = gb->vga_width;
mode.height = gb->vga_height;
mode.mode = RGBFB_NONE;
for (int i = 0; i < RGBFB_MaxFormats; i++) {
RGBFTYPE t = (RGBFTYPE)i;
if (GetBytesPerPixel(t) == bpp / 8) {
mode.mode = t;
break;
}
}
gfxboard_setmode(gb, &mode);
gfx_set_picasso_modeinfo(gb->monitor_id, mode.mode);
gb->fullrefresh = 2;
gb->vga_changed = false;
return true;
}
bool gfxboard_set(int monid, bool rtg)
{
bool r;
struct amigadisplay *ad = &adisplays[monid];
r = ad->picasso_on;
if (rtg) {
ad->picasso_requested_on = 1;
} else {
ad->picasso_requested_on = 0;
}
set_config_changed();
return r;
}
void gfxboard_rtg_disable(int monid, int index)
{
if (monid > 0)
return;
if (index == rtg_visible[monid] && rtg_visible[monid] >= 0) {
struct rtggfxboard *gb = &rtggfxboards[index];
if (rtg_visible[monid] >= 0 && gb->func) {
gb->func->toggle(gb->userdata, 0);
}
rtg_visible[monid] = -1;
}
}
bool gfxboard_rtg_enable_initial(int monid, int index)
{
struct amigadisplay *ad = &adisplays[monid];
// if some RTG already enabled and located in monitor 0, don't override
if ((rtg_visible[monid] >= 0 || rtg_initial[monid] >= 0) && !monid)
return false;
if (ad->picasso_on)
return false;
rtg_initial[monid] = index;
gfxboard_toggle(monid, index, false);
// check_prefs_picasso() calls gfxboard_toggle when ready
return true;
}
int gfxboard_toggle(int monid, int index, int log)
{
bool initial = false;
if (rtg_visible[monid] < 0 && rtg_initial[monid] >= 0 && rtg_initial[monid] < MAX_RTG_BOARDS) {
index = rtg_initial[monid];
initial = true;
}
gfxboard_rtg_disable(monid, rtg_visible[monid]);
rtg_visible[monid] = -1;
if (index < 0)
goto end;
struct rtggfxboard *gb = &rtggfxboards[index];
if (!gb->active)
goto end;
if (gb->func) {
bool r = gb->func->toggle(gb->userdata, 1);
if (r) {
rtg_initial[monid] = MAX_RTG_BOARDS;
rtg_visible[monid] = gb->rtg_index;
if (log && !monid)
statusline_add_message(STATUSTYPE_DISPLAY, _T("RTG %d: %s"), index + 1, gb->board->name);
return index;
}
goto end;
}
if (gb->vram == NULL)
return -1;
vga_update_size(gb);
if (gb->vga_width > 16 && gb->vga_height > 16) {
if (!gfxboard_setmode_qemu(gb))
goto end;
rtg_initial[monid] = MAX_RTG_BOARDS;
rtg_visible[monid] = gb->rtg_index;
gb->monswitch_new = true;
gb->monswitch_delay = 1;
if (log && !monid)
statusline_add_message(STATUSTYPE_DISPLAY, _T("RTG %d: %s"), index + 1, gb->board->name);
return index;
}
end:
if (initial) {
rtg_initial[monid] = -1;
return -2;
}
return -1;
}
static bool gfxboard_checkchanged(struct rtggfxboard *gb)
{
struct picasso96_state_struct *state = &picasso96_state[gb->monitor_id];
int bpp = gb->vga.vga.get_bpp (&gb->vga.vga);
if (bpp == 0)
bpp = 8;
if (gb->vga_width <= 16 || gb->vga_height <= 16)
return false;
if (state->Width != gb->vga_width ||
state->Height != gb->vga_height ||
state->BytesPerPixel != bpp / 8)
return true;
return false;
}
DisplaySurface *qemu_console_surface(QemuConsole *con)
{
struct rtggfxboard *gb = (struct rtggfxboard*)con;
return &gb->gfxsurface;
}
void qemu_console_resize(QemuConsole *con, int width, int height)
{
struct rtggfxboard *gb = (struct rtggfxboard*)con;
if (width != gb->vga_width || gb->vga_height != height)
gb->vga_changed = true;
gb->vga_width = width;
gb->vga_height = height;
}
void linear_memory_region_set_dirty(MemoryRegion *mr, hwaddr addr, hwaddr size)
{
}
void vga_memory_region_set_dirty(MemoryRegion *mr, hwaddr addr, hwaddr size)
{
struct rtggfxboard *gb = (struct rtggfxboard*)mr->data;
if (gb->vga.vga.graphic_mode != 1)
return;
if (!gb->fullrefresh)
gb->fullrefresh = 1;
}
#if 0
static uae_u8 pal64 (uae_u8 v)
{
v = (v << 2) | ((v >> 2) & 3);
return v;
}
#endif
DisplaySurface* qemu_create_displaysurface_from(int width, int height, int bpp,
int linesize, uint8_t *data,
bool byteswap)
{
struct rtggfxboard *gb;
for (int i = 0; i < MAX_RTG_BOARDS; i++) {
gb = &rtggfxboards[i];
if (data >= gb->vram && data < gb->vramend) {
gb->modechanged = true;
return &gb->fakesurface;
}
}
return NULL;
}
int surface_bits_per_pixel(DisplaySurface *s)
{
struct rtggfxboard *gb = (struct rtggfxboard*)s->data;
if (rtg_visible[gb->monitor_id] < 0)
return 32;
if (s == &gb->fakesurface)
return 32;
struct picasso_vidbuf_description *vidinfo = &picasso_vidinfo[gb->monitor_id];
return vidinfo->pixbytes * 8;
}
int surface_bytes_per_pixel(DisplaySurface *s)
{
struct rtggfxboard *gb = (struct rtggfxboard*)s->data;
if (rtg_visible[gb->monitor_id] < 0)
return 4;
if (s == &gb->fakesurface)
return 4;
struct picasso_vidbuf_description *vidinfo = &picasso_vidinfo[gb->monitor_id];
return vidinfo->pixbytes;
}
int surface_stride(DisplaySurface *s)
{
struct rtggfxboard *gb = (struct rtggfxboard*)s->data;
if (rtg_visible[gb->monitor_id] < 0)
return 0;
if (s == &gb->fakesurface || !gb->vga_refresh_active)
return 0;
if (gb->gfxboard_surface == NULL)
gb->gfxboard_surface = gfx_lock_picasso(gb->monitor_id, false, false);
struct picasso_vidbuf_description *vidinfo = &picasso_vidinfo[gb->monitor_id];
return vidinfo->rowbytes;
}
uint8_t *surface_data(DisplaySurface *s)
{
struct rtggfxboard *gb = (struct rtggfxboard*)s->data;
if (!gb)
return NULL;
if (rtg_visible[gb->monitor_id] < 0)
return NULL;
if (gb->vga_changed)
return NULL;
if (s == &gb->fakesurface || !gb->vga_refresh_active)
return gb->fakesurface_surface;
if (gb->gfxboard_surface == NULL)
gb->gfxboard_surface = gfx_lock_picasso(gb->monitor_id, false, false);
return gb->gfxboard_surface;
}
void gfxboard_refresh(int monid)
{
if (monid >= 0) {
for (int i = 0; i < MAX_RTG_BOARDS; i++) {
struct rtgboardconfig *rbc = &currprefs.rtgboards[i];
if (rbc->monitor_id == monid && rbc->rtgmem_size) {
if (rbc->rtgmem_type >= GFXBOARD_HARDWARE) {
struct rtggfxboard *gb = &rtggfxboards[i];
gb->fullrefresh = 2;
} else {
picasso_refresh(monid);
}
}
}
} else {
for (int i = 0; i < MAX_RTG_BOARDS; i++) {
struct rtgboardconfig *rbc = &currprefs.rtgboards[i];
if (rbc->rtgmem_size) {
gfxboard_refresh(rbc->monitor_id);
}
}
}
}
void gfxboard_vsync_handler(bool full_redraw_required, bool redraw_required)
{
for (int i = 0; i < MAX_RTG_BOARDS; i++) {
struct rtggfxboard *gb = &rtggfxboards[i];
struct amigadisplay *ad = &adisplays[gb->monitor_id];
struct picasso96_state_struct *state = &picasso96_state[gb->monitor_id];
if (gb->func) {
if (gb->userdata) {
struct gfxboard_mode mode = { 0 };
mode.redraw_required = full_redraw_required;
gb->func->vsync(gb->userdata, &mode);
if (mode.mode && mode.width && mode.height) {
if (state->Width != mode.width ||
state->Height != mode.height ||
state->RGBFormat != mode.mode ||
!ad->picasso_on) {
if (mode.width && mode.height && mode.mode) {
gfxboard_setmode(gb, &mode);
gfx_set_picasso_modeinfo(gb->monitor_id, mode.mode);
}
}
}
}
} else if (gb->configured_mem > 0 && gb->configured_regs > 0) {
if (gb->monswitch_keep_trying) {
vga_update_size(gb);
if (gb->vga_width > 16 && gb->vga_height > 16) {
gb->monswitch_keep_trying = false;
gb->monswitch_new = true;
gb->monswitch_delay = 0;
}
}
if (gb->monswitch_new != gb->monswitch_current) {
if (gb->monswitch_delay > 0)
gb->monswitch_delay--;
if (gb->monswitch_delay == 0) {
if (!gb->monswitch_new && rtg_visible[gb->monitor_id] == i) {
gfxboard_rtg_disable(gb->monitor_id, i);
}
gb->monswitch_current = gb->monswitch_new;
vga_update_size(gb);
write_log(_T("GFXBOARD %d MONITOR=%d ACTIVE=%d\n"), i, gb->monitor_id, gb->monswitch_current);
if (gb->monitor_id > 0) {
if (gb->monswitch_new)
gfxboard_toggle(gb->monitor_id, i, 0);
} else {
if (gb->monswitch_current) {
if (!gfxboard_rtg_enable_initial(gb->monitor_id, i)) {
// Nothing visible? Re-enable our display.
if (rtg_visible[gb->monitor_id] < 0) {
gfxboard_toggle(gb->monitor_id, i, 0);
}
}
} else {
if (ad->picasso_requested_on) {
ad->picasso_requested_on = false;
set_config_changed();
}
}
}
}
} else {
gb->monswitch_delay = 0;
}
// Vertical Sync End Register, 0x20 = Disable Vertical Interrupt, 0x10 = Clear Vertical Interrupt.
if (gb->board->irq) {
if ((!(gb->vga.vga.cr[0x11] & 0x20) && (gb->vga.vga.cr[0x11] & 0x10) && !(gb->vga.vga.gr[0x17] & 4))) {
if (gb->gfxboard_intena) {
gb->gfxboard_vblank = true;
//write_log(_T("VGA interrupt %d\n"), gb->board->irq);
if (gb->board->irq == 2)
INTREQ(0x8000 | 0x0008);
else
INTREQ(0x8000 | 0x2000);
}