-
Notifications
You must be signed in to change notification settings - Fork 1
/
S3Trio64.cpp
2819 lines (2605 loc) · 92.3 KB
/
S3Trio64.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
/* ES40 emulator.
* Copyright (C) 2007-2008 by the ES40 Emulator Project
*
* WWW : http://sourceforge.net/projects/es40
* E-mail : [email protected]
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
* Although this is not required, the author would appreciate being notified of,
* and receiving any modifications you may make to the source code that might serve
* the general public.
*/
/**
* \file
* Contains the code for emulated S3 Trio 64 Video Card device.
*
* $Id: S3Trio64.cpp,v 1.12 2008/02/27 12:04:25 iamcamiel Exp $
*
* X-1.12 Brian Wheeler 27-FEB-2008
* Avoid compiler warnings.
*
* X-1.11 Fang Zhe 08-JAN-2008
* Endianess.
*
* X-1.10 Camiel Vanderhoeven 02-JAN-2008
* Cleanup.
*
* X-1.9 Camiel Vanderhoeven 30-DEC-2007
* Print file id on initialization.
*
* X-1.8 Camiel Vanderhoeven 28-DEC-2007
* Throw exceptions rather than just exiting when errors occur.
*
* X-1.7 Camiel Vanderhoeven 28-DEC-2007
* Keep the compiler happy.
*
* X-1.6 Camiel Vanderhoeven 17-DEC-2007
* SaveState file format 2.1
*
* X-1.5 Brian Wheeler 10-DEC-2007
* Made refresh function name unique.
*
* X-1.4 Camiel Vanderhoeven 10-DEC-2007
* Use new base class VGA.
*
* X-1.3 Camiel Vanderhoeven 7-DEC-2007
* Code cleanup.
*
* X-1.2 Camiel Vanderhoeven/Brian Wheeler 6-DEC-2007
* Changed implementation (with thanks to the Bochs project!!)
*
* X-1.1 Camiel Vanderhoeven 1-DEC-2007
* Initial version in CVS.
*
* X-0.0 [email protected]
* Generated file.
*
* \author Brian Wheeler ([email protected])
**/
#include "StdAfx.h"
#include "S3Trio64.h"
#include "System.h"
#include "AliM1543C.h"
#include "gui/gui.h"
static unsigned old_iHeight = 0, old_iWidth = 0, old_MSL = 0;
static const u8 ccdat[16][4] = {
{ 0x00, 0x00, 0x00, 0x00 },
{ 0xff, 0x00, 0x00, 0x00 },
{ 0x00, 0xff, 0x00, 0x00 },
{ 0xff, 0xff, 0x00, 0x00 },
{ 0x00, 0x00, 0xff, 0x00 },
{ 0xff, 0x00, 0xff, 0x00 },
{ 0x00, 0xff, 0xff, 0x00 },
{ 0xff, 0xff, 0xff, 0x00 },
{ 0x00, 0x00, 0x00, 0xff },
{ 0xff, 0x00, 0x00, 0xff },
{ 0x00, 0xff, 0x00, 0xff },
{ 0xff, 0xff, 0x00, 0xff },
{ 0x00, 0x00, 0xff, 0xff },
{ 0xff, 0x00, 0xff, 0xff },
{ 0x00, 0xff, 0xff, 0xff },
{ 0xff, 0xff, 0xff, 0xff },
};
// Only reference the array if the tile numbers are within the bounds
// of the array. If out of bounds, do nothing.
#define SET_TILE_UPDATED(xtile,ytile,value) \
do { \
if (((xtile) < BX_NUM_X_TILES) && ((ytile) < BX_NUM_Y_TILES)) \
state.vga_tile_updated[(xtile)][(ytile)] = value; \
} while (0)
// Only reference the array if the tile numbers are within the bounds
// of the array. If out of bounds, return 0.
#define GET_TILE_UPDATED(xtile,ytile) \
((((xtile) < BX_NUM_X_TILES) && ((ytile) < BX_NUM_Y_TILES))? \
state.vga_tile_updated[(xtile)][(ytile)] \
: 0)
#if defined(_WIN32)
static HANDLE screen_refresh_handle_s3;
static DWORD WINAPI refresh_proc_s3(LPVOID lpParam)
#else
pthread_t screen_refresh_handle_s3;
static void *refresh_proc_s3(void *lpParam)
#endif
{
CS3Trio64 *c = (CS3Trio64 *) lpParam;
while(1) {
//c->screenrefresh();
// bx_gui->handle_events();
c->update();
bx_gui->flush();
sleep_ms(100); // 10 fps
}
return 0;
}
static size_t rom_max;
static u8 option_rom[65536];
u32 s3_cfg_data[64] = {
/*00*/ 0x88115333, // CFID: vendor + device
/*04*/ 0x011f0000, // CFCS: command + status
/*08*/ 0x03000002, // CFRV: class + revision
/*0c*/ 0x00000000, // CFLT: latency timer + cache line size
/*10*/ 0xf8000000, // BAR0: FB
/*14*/ 0x00000000, // BAR1:
/*18*/ 0x00000000, // BAR2:
/*1c*/ 0x00000000, // BAR3:
/*20*/ 0x00000000, // BAR4:
/*24*/ 0x00000000, // BAR5:
/*28*/ 0x00000000, // CCIC: CardBus
/*2c*/ 0x00000000, // CSID: subsystem + vendor
/*30*/ 0x00000000, // BAR6: expansion rom base
/*34*/ 0x00000000, // CCAP: capabilities pointer
/*38*/ 0x00000000,
/*3c*/ 0x281401ff, // CFIT: interrupt configuration
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
};
u32 s3_cfg_mask[64] = {
/*00*/ 0x00000000, // CFID: vendor + device
/*04*/ 0x0000ffff, // CFCS: command + status
/*08*/ 0x00000000, // CFRV: class + revision
/*0c*/ 0x0000ffff, // CFLT: latency timer + cache line size
/*10*/ 0xfc000000, // BAR0: FB
/*14*/ 0x00000000, // BAR1:
/*18*/ 0x00000000, // BAR2:
/*1c*/ 0x00000000, // BAR3:
/*20*/ 0x00000000, // BAR4:
/*24*/ 0x00000000, // BAR5:
/*28*/ 0x00000000, // CCIC: CardBus
/*2c*/ 0x00000000, // CSID: subsystem + vendor
/*30*/ 0x00000000, // BAR6: expansion rom base
/*34*/ 0x00000000, // CCAP: capabilities pointer
/*38*/ 0x00000000,
/*3c*/ 0x000000ff, // CFIT: interrupt configuration
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
};
/**
* Constructor.
**/
CS3Trio64::CS3Trio64(CConfigurator * cfg, CSystem * c, int pcibus, int pcidev): CVGA(cfg,c,pcibus,pcidev)
{
add_function(0,s3_cfg_data,s3_cfg_mask);
int i;
char *romfile;
c->RegisterClock(this, true);
/* the VGA I/O ports are at 3b0 -> 3df */
add_legacy_io(2,0x3b0,48);
/* we listen for messages from outer space (a.k.a. VGA bios) at port 500. */
add_legacy_io(7,0x500,1);
/* legacy video address space: A0000 -> bffff */
add_legacy_mem(4,0xa0000,128*1024);
ResetPCI();
bios_message_size = 0;
bios_message[0] = '\0';
// use a VGA rom from bochs
romfile=myCfg->get_text_value("vga.rom","vgabios.bin");
FILE *rom=fopen(romfile,"rb");
if(!rom) {
printf("%%VGA-F-ROM: Cannot open %s\n",romfile);
throw((int)1);
}
rom_max=fread(option_rom,1,65536,rom);
fclose(rom);
printf("%%VGA-I-ROMSIZE: ROM is %d bytes.\n",rom_max);
/* Option ROM address space: C0000 */
add_legacy_mem(5,0xc0000,(u32)rom_max);
state.vga_enabled = 1;
state.misc_output.color_emulation = 1;
state.misc_output.enable_ram = 1;
state.misc_output.clock_select = 0;
state.misc_output.select_high_bank = 0;
state.misc_output.horiz_sync_pol = 1;
state.misc_output.vert_sync_pol = 1;
state.attribute_ctrl.mode_ctrl.graphics_alpha = 0;
state.attribute_ctrl.mode_ctrl.display_type = 0;
state.attribute_ctrl.mode_ctrl.enable_line_graphics = 1;
state.attribute_ctrl.mode_ctrl.blink_intensity = 0;
state.attribute_ctrl.mode_ctrl.pixel_panning_compat = 0;
state.attribute_ctrl.mode_ctrl.pixel_clock_select = 0;
state.attribute_ctrl.mode_ctrl.internal_palette_size = 0;
state.line_offset=80;
state.line_compare=1023;
state.vertical_display_end=399;
for (i=0; i<=0x18; i++)
state.CRTC.reg[i] = 0;
state.CRTC.address = 0;
state.CRTC.write_protect = 0;
state.attribute_ctrl.flip_flop = 0;
state.attribute_ctrl.address = 0;
state.attribute_ctrl.video_enabled = 1;
for (i=0; i<16; i++)
state.attribute_ctrl.palette_reg[i] = 0;
state.attribute_ctrl.overscan_color = 0;
state.attribute_ctrl.color_plane_enable = 0x0f;
state.attribute_ctrl.horiz_pel_panning = 0;
state.attribute_ctrl.color_select = 0;
for (i=0; i<256; i++) {
state.pel.data[i].red = 0;
state.pel.data[i].green = 0;
state.pel.data[i].blue = 0;
}
state.pel.write_data_register = 0;
state.pel.write_data_cycle = 0;
state.pel.read_data_register = 0;
state.pel.read_data_cycle = 0;
state.pel.dac_state = 0x01;
state.pel.mask = 0xff;
state.graphics_ctrl.index = 0;
state.graphics_ctrl.set_reset = 0;
state.graphics_ctrl.enable_set_reset = 0;
state.graphics_ctrl.color_compare = 0;
state.graphics_ctrl.data_rotate = 0;
state.graphics_ctrl.raster_op = 0;
state.graphics_ctrl.read_map_select = 0;
state.graphics_ctrl.write_mode = 0;
state.graphics_ctrl.read_mode = 0;
state.graphics_ctrl.odd_even = 0;
state.graphics_ctrl.chain_odd_even = 0;
state.graphics_ctrl.shift_reg = 0;
state.graphics_ctrl.graphics_alpha = 0;
state.graphics_ctrl.memory_mapping = 2; // monochrome text mode
state.graphics_ctrl.color_dont_care = 0;
state.graphics_ctrl.bitmask = 0;
for (i=0; i<4; i++) {
state.graphics_ctrl.latch[i] = 0;
}
state.sequencer.index = 0;
state.sequencer.map_mask = 0;
state.sequencer.reset1 = 1;
state.sequencer.reset2 = 1;
state.sequencer.reg1 = 0;
state.sequencer.char_map_select = 0;
state.sequencer.extended_mem = 1; // display mem greater than 64K
state.sequencer.odd_even = 1; // use sequential addressing mode
state.sequencer.chain_four = 0; // use map mask & read map select
//extname = SIM->get_param_string(BXPN_VGA_EXTENSION)->getptr();
//if ((strlen(extname) == 0) || (!strcmp(extname, "none"))) {
state.memsize = 0x40000;
state.memory = new u8[state.memsize];
memset(state.memory, 0, state.memsize);
//}
state.vga_mem_updated = 0;
for (unsigned y=0; y<480/Y_TILESIZE; y++)
for (unsigned x=0; x<640/X_TILESIZE; x++)
SET_TILE_UPDATED (x, y, 0);
bx_gui->init(state.x_tilesize, state.y_tilesize);
#if !BX_SUPPORT_CLGD54XX
// this->init_systemtimer(timer_handler, vga_param_handler);
#endif // !BX_SUPPORT_CLGD54XX
state.charmap_address = 0;
state.x_dotclockdiv2 = 0;
state.y_doublescan = 0;
state.last_bpp = 8;
#if BX_SUPPORT_VBE
// The following is for the vbe display extension
state.vbe_enabled=0;
state.vbe_8bit_dac=0;
if (!strcmp(extname, "vbe")) {
for (addr=VBE_DISPI_IOPORT_INDEX; addr<=VBE_DISPI_IOPORT_DATA; addr++) {
DEV_register_ioread_handler(this, vbe_read_handler, addr, "vga video", 7);
DEV_register_iowrite_handler(this, vbe_write_handler, addr, "vga video", 7);
}
if (!BX_SUPPORT_PCIUSB || !SIM->get_param_bool(BXPN_USB1_ENABLED)->get()) {
for (addr=VBE_DISPI_IOPORT_INDEX_OLD; addr<=VBE_DISPI_IOPORT_DATA_OLD; addr++) {
DEV_register_ioread_handler(this, vbe_read_handler, addr, "vga video", 7);
DEV_register_iowrite_handler(this, vbe_write_handler, addr, "vga video", 7);
}
}
DEV_register_memory_handlers(theVga, mem_read_handler, mem_write_handler,
VBE_DISPI_LFB_PHYSICAL_ADDRESS,
VBE_DISPI_LFB_PHYSICAL_ADDRESS + VBE_DISPI_TOTAL_VIDEO_MEMORY_BYTES - 1);
if (state.memory == NULL)
state.memory = new u8[VBE_DISPI_TOTAL_VIDEO_MEMORY_BYTES];
memset(state.memory, 0, VBE_DISPI_TOTAL_VIDEO_MEMORY_BYTES);
state.memsize = VBE_DISPI_TOTAL_VIDEO_MEMORY_BYTES;
state.vbe_cur_dispi=VBE_DISPI_ID0;
state.vbe_xres=640;
state.vbe_yres=480;
state.vbe_bpp=8;
state.vbe_bank=0;
state.vbe_curindex=0;
state.vbe_offset_x=0;
state.vbe_offset_y=0;
state.vbe_virtual_xres=640;
state.vbe_virtual_yres=480;
state.vbe_bpp_multiplier=1;
state.vbe_virtual_start=0;
state.vbe_lfb_enabled=0;
state.vbe_get_capabilities=0;
bx_gui->get_capabilities(&max_xres, &max_yres,
&max_bpp);
if (max_xres > VBE_DISPI_MAX_XRES) {
state.vbe_max_xres=VBE_DISPI_MAX_XRES;
} else {
state.vbe_max_xres=max_xres;
}
if (max_yres > VBE_DISPI_MAX_YRES) {
state.vbe_max_yres=VBE_DISPI_MAX_YRES;
} else {
state.vbe_max_yres=max_yres;
}
if (max_bpp > VBE_DISPI_MAX_BPP) {
state.vbe_max_bpp=VBE_DISPI_MAX_BPP;
} else {
state.vbe_max_bpp=max_bpp;
}
this->extension_init = 1;
BX_INFO(("VBE Bochs Display Extension Enabled"));
}
#endif
state.CRTC.reg[0x09] = 16;
state.graphics_ctrl.memory_mapping = 3; // color text mode
state.vga_mem_updated = 1;
#if defined(_WIN32)
screen_refresh_handle_s3 = CreateThread(NULL,0,refresh_proc_s3,this,0,NULL);
#else
pthread_create(&screen_refresh_handle_s3,NULL,refresh_proc_s3,this);
#endif
printf("%s: $Id: S3Trio64.cpp,v 1.12 2008/02/27 12:04:25 iamcamiel Exp $\n",devid_string);
}
CS3Trio64::~CS3Trio64()
{
printf("%%VGA-I-SHUTDOWN: vga console has shut down.\n");
}
u32 CS3Trio64::ReadMem_Legacy(int index, u32 address, int dsize)
{
switch(index)
{
case 2: /* io ports */
return io_read(address, dsize);
case 4: /* legacy memory */
return legacy_read(address, dsize);
case 5: /* rom */
case 6:
return rom_read(address, dsize);
}
return 0;
}
void CS3Trio64::WriteMem_Legacy(int index, u32 address, int dsize, u32 data)
{
switch(index)
{
case 2: /* io port */
io_write(address,dsize,data);
return;
case 4: /* legacy memory */
legacy_write(address,dsize,data);
return;
case 5: /* rom */
case 6:
rom_write(address,dsize,data);
return;
case 7: /* bios message */
bios_message[bios_message_size++] = (char) data & 0xff;
if (((data & 0xff) == 0x0a) || ((data &0xff) == 0x0d))
{
if (bios_message_size>1)
{
bios_message[bios_message_size-1] = '\0';
printf("%%VGA-I-BIOS: %s\n",bios_message);
}
bios_message_size = 0;
}
return;
}
}
u32 CS3Trio64::ReadMem_Bar(int func, int bar, u32 address, int dsize)
{
switch(bar)
{
case 0: /* pci memory */
return mem_read(address, dsize);
}
return 0;
}
void CS3Trio64::WriteMem_Bar(int func, int bar, u32 address, int dsize, u32 data)
{
switch(bar)
{
case 0: /* pci memory */
mem_write(address,dsize,data);
return;
}
}
/**
* Redraw the screen.
**/
int CS3Trio64::DoClock()
{
return 0;
}
static u32 s3_magic1 = 0x53338811;
static u32 s3_magic2 = 0x88115333;
/**
* Save state to a Virtual Machine State file.
**/
int CS3Trio64::SaveState(FILE *f)
{
long ss = sizeof(state);
int res;
if (res = CPCIDevice::SaveState(f))
return res;
fwrite(&s3_magic1,sizeof(u32),1,f);
fwrite(&ss,sizeof(long),1,f);
fwrite(&state,sizeof(state),1,f);
fwrite(&s3_magic2,sizeof(u32),1,f);
printf("%s: %d bytes saved.\n",devid_string,(int)ss);
return 0;
}
/**
* Restore state from a Virtual Machine State file.
**/
int CS3Trio64::RestoreState(FILE *f)
{
long ss;
u32 m1;
u32 m2;
int res;
size_t r;
if (res = CPCIDevice::RestoreState(f))
return res;
r = fread(&m1,sizeof(u32),1,f);
if (r!=1)
{
printf("%s: unexpected end of file!\n",devid_string);
return -1;
}
if (m1 != s3_magic1)
{
printf("%s: MAGIC 1 does not match!\n",devid_string);
return -1;
}
fread(&ss,sizeof(long),1,f);
if (r!=1)
{
printf("%s: unexpected end of file!\n",devid_string);
return -1;
}
if (ss != sizeof(state))
{
printf("%s: STRUCT SIZE does not match!\n",devid_string);
return -1;
}
fread(&state,sizeof(state),1,f);
if (r!=1)
{
printf("%s: unexpected end of file!\n",devid_string);
return -1;
}
r = fread(&m2,sizeof(u32),1,f);
if (r!=1)
{
printf("%s: unexpected end of file!\n",devid_string);
return -1;
}
if (m2 != s3_magic2)
{
printf("%s: MAGIC 1 does not match!\n",devid_string);
return -1;
}
printf("%s: %d bytes restored.\n",devid_string,(int)ss);
return 0;
}
/**
* Read from Framebuffer
*/
u32 CS3Trio64::mem_read(u32 address, int dsize)
{
u32 data = 0;
//printf("S3 mem read: %" LL "x, %d, %" LL "x \n", address, dsize, data);
return data;
}
/**
* Write to Framebuffer
*/
void CS3Trio64::mem_write(u32 address, int dsize, u32 data)
{
//printf("S3 mem write: %" LL "x, %d, %" LL "x \n", address, dsize, data);
switch(dsize) {
case 8:
case 16:
case 32:
break;
}
}
/**
* Read from Legacy Framebuffer
*/
u32 CS3Trio64::legacy_read(u32 address, int dsize)
{
u32 data = 0;
switch (dsize)
{
case 32:
data |= (u64)vga_mem_read(address + 0xA0002) << 16;// (u64)(*((u8*)x))&0xff;
data |= (u64)vga_mem_read(address + 0xA0003) << 24;// (u64)(*((u8*)x))&0xff;
case 16:
data |= (u64)vga_mem_read(address + 0xA0001) << 8;// (u64)(*((u8*)x))&0xff;
case 8:
data |= (u64)vga_mem_read(address + 0xA0000);// (u64)(*((u8*)x))&0xff;
}
// //printf("S3 legacy read: %" LL "x, %d, %" LL "x \n", address, dsize, data);
return data;
}
/**
* Write to Legacy Framebuffer
*/
void CS3Trio64::legacy_write(u32 address, int dsize, u32 data)
{
// //printf("S3 legacy write: %" LL "x, %d, %" LL "x \n", address, dsize, data);
switch(dsize) {
case 32:
vga_mem_write(address+0xA0002, (u8)(data>>16));
vga_mem_write(address+0xA0003, (u8)(data>>24));
case 16:
vga_mem_write(address+0xA0001, (u8)(data>>8));
case 8:
vga_mem_write(address+0xA0000, (u8)(data));
}
}
/**
* Read from Option ROM
*/
u32 CS3Trio64::rom_read(u32 address, int dsize)
{
u32 data = 0x00; // make it easy for the checksummer.
u8 *x=(u8 *)option_rom;
if(address<= rom_max) {
x+=address;
switch (dsize)
{
case 8:
data = (u32)endian_8(*((u8*)x))&0xff;
break;
case 16:
data = (u32)endian_16(*((u16*)x))&0xffff;
break;
case 32:
data = (u32)endian_32(*((u32*)x))&0xffffffff;
break;
}
//printf("S3 rom read: %" LL "x, %d, %" LL "x\n", address, dsize,data);
} else {
//printf("S3 (BAD) rom read: %" LL "x, %d, %" LL "x\n", address, dsize,data);
}
return data;
}
/**
* Write to Option ROM
*/
void CS3Trio64::rom_write(u32 address, int dsize, u32 data)
{
//printf("S3 rom write: %" LL "x, %d, %" LL "x --", address, dsize, data);
}
/**
* Read from I/O Port
*/
u32 CS3Trio64::io_read(u32 address, int dsize)
{
u32 data = 0;
if (dsize !=8)
FAILURE("Unsupported dsize!");
switch(address+VGA_BASE) {
case 0x3c0:
data = read_b_3c0();
break;
case 0x3c1:
data = read_b_3c1();
break;
case 0x3c3:
data = read_b_3c3();
break;
case 0x3c4:
data = read_b_3c4();
break;
case 0x3c5:
data = read_b_3c5();
break;
case 0x3c9:
data = read_b_3c9();
break;
case 0x3cc:
data = read_b_3cc();
break;
case 0x3cf:
data = read_b_3cf();
break;
case 0x3b4:
case 0x3d4:
data = read_b_3d4();
break;
case 0x3b5:
case 0x3d5:
data = read_b_3d5();
break;
case 0x3ba:
case 0x3da:
data = read_b_3da();
break;
//case 0x3d5:
// switch(state.crtc_index) {
// /* registers that are just mirrors of the data. */
// case 0x0a: // cursor start line
// case 0x0b: // cursor end line
// case 0x38: // CR38 Register Lock 1
// case 0x39: // CR39 Register Lock 2
// case 0x46:
// case 0x54: // Extended Memory Control 2 Register
// case 0x56: // External Sync Control 1 Register
// case 0x57:
// data = state.crtc_data[state.crtc_index];
// break;
// /* constant or special registers */
// case 0x2e: //Extended Chip ID
// data = 0x11; // trio 64.
// break;
// case 0x2f: // Revision
// data = 0x00;
// break;
// case 0x36: // CR36 Reset State Read 1
// // 000 1 10 10
// // ^ ^ ^ ^- PCI
// // | | +---- Memory page mode select. EDO
// // | +------ Display memory dedicated
// // +---------- Memory size. 4M
// data = 0x1A;
// break;
// /* catchall */
// default:
// printf("%%VGA-I-CRTC: read unknown crtc index: %x\n",state.crtc_index);
// }
// break;
//case 0x3da: // input status #1 register
// // this tells if there's a retrace in progress. Nope!
// data = 0x00;
// // also resets the 3c0 mode.
// state.reg_3c0_mode = 0;
// break;
default:
printf("%%VGA-W-PORT: Unhandled port %x read\n",address+VGA_BASE);
throw((int)1);
}
//printf("S3 io read: %" LL "x, %d, %" LL "x \n", address+VGA_BASE, dsize, data);
return data;
}
/**
* Write to I/O Port
*/
void CS3Trio64::io_write(u32 address, int dsize, u32 data)
{
// printf("S3 io write: %" LL "x, %d, %" LL "x \n", address+VGA_BASE, dsize, data);
switch(dsize)
{
case 8:
io_write_b(address,(u8)data);
break;
case 16:
io_write_b(address ,(u8) data &0xff);
io_write_b(address + 1,(u8)(data>>8)&0xff);
break;
default:
FAILURE("Weird IO size!");
}
}
void CS3Trio64::io_write_b(u32 address, u8 data)
{
switch(address+VGA_BASE) {
case 0x3c0:
write_b_3c0(data);
break;
case 0x3c2:
write_b_3c2(data);
break;
case 0x3c4:
write_b_3c4(data);
break;
case 0x3c5:
write_b_3c5(data);
break;
case 0x3c6:
write_b_3c6(data);
break;
case 0x3c7:
write_b_3c7(data);
break;
case 0x3c8:
write_b_3c8(data);
break;
case 0x3c9:
write_b_3c9(data);
break;
case 0x3ce:
write_b_3ce(data);
break;
case 0x3cf:
write_b_3cf(data);
break;
case 0x3b4:
case 0x3d4:
write_b_3d4(data);
break;
case 0x3b5:
case 0x3d5:
write_b_3d5(data);
break;
default:
printf("%%VGA-W-PORT: Unhandled port %x write\n",address+VGA_BASE);
throw((int)1);
}
}
void CS3Trio64::write_b_3c0(u8 value)
{
bool prev_video_enabled, prev_line_graphics, prev_int_pal_size;
/* Attribute Controller */
if (state.attribute_ctrl.flip_flop == 0)
{ /* address mode */
prev_video_enabled = state.attribute_ctrl.video_enabled;
state.attribute_ctrl.video_enabled = (value >> 5) & 0x01;
#if defined(DEBUG_VGA)
printf("io write 3c0: video_enabled = %u \n", (unsigned) state.attribute_ctrl.video_enabled);
#endif
if (state.attribute_ctrl.video_enabled == 0)
{
bx_gui->clear_screen();
}
else if (!prev_video_enabled) {
#if defined(DEBUG_VGA)
printf("found enable transition \n");
#endif
redraw_area(0, 0, old_iWidth, old_iHeight);
}
value &= 0x1f; /* address = bits 0..4 */
state.attribute_ctrl.address = value;
switch (value) {
case 0x00: case 0x01: case 0x02: case 0x03:
case 0x04: case 0x05: case 0x06: case 0x07:
case 0x08: case 0x09: case 0x0a: case 0x0b:
case 0x0c: case 0x0d: case 0x0e: case 0x0f:
break;
#if defined(DEBUG_VGA)
default:
printf("io write 3c0: address mode reg=%u \n",(unsigned) value);
#endif
}
}
else { /* data-write mode */
switch (state.attribute_ctrl.address) {
case 0x00: case 0x01: case 0x02: case 0x03:
case 0x04: case 0x05: case 0x06: case 0x07:
case 0x08: case 0x09: case 0x0a: case 0x0b:
case 0x0c: case 0x0d: case 0x0e: case 0x0f:
if (value != state.attribute_ctrl.palette_reg[state.attribute_ctrl.address]) {
state.attribute_ctrl.palette_reg[state.attribute_ctrl.address] = value;
redraw_area(0, 0, old_iWidth, old_iHeight);
}
break;
case 0x10: // mode control register
prev_line_graphics = state.attribute_ctrl.mode_ctrl.enable_line_graphics;
prev_int_pal_size = state.attribute_ctrl.mode_ctrl.internal_palette_size;
state.attribute_ctrl.mode_ctrl.graphics_alpha =
(value >> 0) & 0x01;
state.attribute_ctrl.mode_ctrl.display_type =
(value >> 1) & 0x01;
state.attribute_ctrl.mode_ctrl.enable_line_graphics =
(value >> 2) & 0x01;
state.attribute_ctrl.mode_ctrl.blink_intensity =
(value >> 3) & 0x01;
state.attribute_ctrl.mode_ctrl.pixel_panning_compat =
(value >> 5) & 0x01;
state.attribute_ctrl.mode_ctrl.pixel_clock_select =
(value >> 6) & 0x01;
state.attribute_ctrl.mode_ctrl.internal_palette_size =
(value >> 7) & 0x01;
if (((value >> 2) & 0x01) != prev_line_graphics) {
bx_gui->set_text_charmap( & state.memory[0x20000 + state.charmap_address]);
state.vga_mem_updated = 1;
}
if (((value >> 7) & 0x01) != prev_int_pal_size) {
redraw_area(0, 0, old_iWidth, old_iHeight);
}
#if defined(DEBUG_VGA)
printf("io write 3c0: mode control: %02x h \n", (unsigned) value);
#endif
break;
case 0x11: // Overscan Color Register
state.attribute_ctrl.overscan_color = (value & 0x3f);
#if defined(DEBUG_VGA)
printf("io write 3c0: overscan color = %02x \n",
(unsigned) value);
#endif
break;
case 0x12: // Color Plane Enable Register
state.attribute_ctrl.color_plane_enable = (value & 0x0f);
redraw_area(0, 0, old_iWidth, old_iHeight);
#if defined(DEBUG_VGA)
printf("io write 3c0: color plane enable = %02x \n",
(unsigned) value);
#endif
break;
case 0x13: // Horizontal Pixel Panning Register
state.attribute_ctrl.horiz_pel_panning = (value & 0x0f);
redraw_area(0, 0, old_iWidth, old_iHeight);
#if defined(DEBUG_VGA)
printf("io write 3c0: horiz pel panning = %02x \n",
(unsigned) value);
#endif
break;
case 0x14: // Color Select Register
state.attribute_ctrl.color_select = (value & 0x0f);
redraw_area(0, 0, old_iWidth, old_iHeight);
#if defined(DEBUG_VGA)
printf("io write 3c0: color select = %02x \n",
(unsigned) state.attribute_ctrl.color_select);
#endif
break;
default:
printf("io write 3c0: data-write mode %02x h \n",(unsigned) state.attribute_ctrl.address);
throw((int)1);
}
}
state.attribute_ctrl.flip_flop = !state.attribute_ctrl.flip_flop;
}
void CS3Trio64::write_b_3c2(u8 value)
{
/* Miscellaneous Output Register */
state.misc_output.color_emulation = (value >> 0) & 0x01;
state.misc_output.enable_ram = (value >> 1) & 0x01;
state.misc_output.clock_select = (value >> 2) & 0x03;
state.misc_output.select_high_bank = (value >> 5) & 0x01;
state.misc_output.horiz_sync_pol = (value >> 6) & 0x01;
state.misc_output.vert_sync_pol = (value >> 7) & 0x01;
#if defined(DEBUG_VGA)
printf("io write 3c2: \n");
printf(" color_emulation = %u \n", (unsigned) state.misc_output.color_emulation);
printf(" enable_ram = %u \n",(unsigned) state.misc_output.enable_ram);
printf(" clock_select = %u \n", (unsigned) state.misc_output.clock_select);
printf(" select_high_bank = %u \n", (unsigned) state.misc_output.select_high_bank);
printf(" horiz_sync_pol = %u \n", (unsigned) state.misc_output.horiz_sync_pol);
printf(" vert_sync_pol = %u \n", (unsigned) state.misc_output.vert_sync_pol);
#endif
}
void CS3Trio64::write_b_3c4(u8 value)
{
/* Sequencer Index Register */
state.sequencer.index = value;
}
void CS3Trio64::write_b_3c5(u8 value)
{
unsigned i;
u8 charmap1, charmap2;
/* Sequencer Registers 00..04 */
switch (state.sequencer.index) {
case 0: /* sequencer: reset */
#if defined(DEBUG_VGA)
printf("write 0x3c5: sequencer reset: value=0x%02x \n", (unsigned) value);
#endif
if (state.sequencer.reset1 && ((value & 0x01) == 0))
{
state.sequencer.char_map_select = 0;
state.charmap_address = 0;
bx_gui->set_text_charmap(& state.memory[0x20000 + state.charmap_address]);
state.vga_mem_updated = 1;
}
state.sequencer.reset1 = (value >> 0) & 0x01;
state.sequencer.reset2 = (value >> 1) & 0x01;
break;
case 1: /* sequencer: clocking mode */
#if defined(DEBUG_VGA)
printf("io write 3c5=%02x: clocking mode reg: ignoring \n", (unsigned) value);
#endif
state.sequencer.reg1 = value & 0x3f;
state.x_dotclockdiv2 = ((value & 0x08) > 0);
break;
case 2: /* sequencer: map mask register */
state.sequencer.map_mask = (value & 0x0f);
for (i=0; i<4; i++)
state.sequencer.map_mask_bit[i] = (value >> i) & 0x01;
break;