summaryrefslogtreecommitdiff
path: root/hw/kdrive/igs/igsreg.c
blob: d63fce0356c7794e1700b39372bf3c0deebb69f4 (plain)
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
/*
 * $RCSId: $
 *
 * Copyright © 2000 Keith Packard
 *
 * Permission to use, copy, modify, distribute, and sell this software and its
 * documentation for any purpose is hereby granted without fee, provided that
 * the above copyright notice appear in all copies and that both that
 * copyright notice and this permission notice appear in supporting
 * documentation, and that the name of Keith Packard not be used in
 * advertising or publicity pertaining to distribution of the software without
 * specific, written prior permission.  Keith Packard makes no
 * representations about the suitability of this software for any purpose.  It
 * is provided "as is" without express or implied warranty.
 *
 * KEITH PACKARD DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
 * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
 * EVENT SHALL KEITH PACKARD BE LIABLE FOR ANY SPECIAL, INDIRECT OR
 * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
 * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
 * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
 * PERFORMANCE OF THIS SOFTWARE.
 */

#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
#include "igsreg.h"
#include <stdio.h>

#define CR00 IGS_CR+0x00
#define CR01 IGS_CR+0x01
#define CR02 IGS_CR+0x02
#define CR03 IGS_CR+0x03
#define CR04 IGS_CR+0x04
#define CR05 IGS_CR+0x05
#define CR06 IGS_CR+0x06
#define CR07 IGS_CR+0x07
#define CR08 IGS_CR+0x08
#define CR09 IGS_CR+0x09
#define CR0A IGS_CR+0x0A
#define CR0B IGS_CR+0x0B
#define CR0C IGS_CR+0x0C
#define CR0D IGS_CR+0x0D
#define CR0E IGS_CR+0x0E
#define CR0F IGS_CR+0x0F
#define CR10 IGS_CR+0x10
#define CR11 IGS_CR+0x11
#define CR12 IGS_CR+0x12
#define CR13 IGS_CR+0x13
#define CR14 IGS_CR+0x14
#define CR15 IGS_CR+0x15
#define CR16 IGS_CR+0x16
#define CR17 IGS_CR+0x17
#define CR18 IGS_CR+0x18
#define CR19 IGS_CR+0x19
#define CR1A IGS_CR+0x1A
#define CR1B IGS_CR+0x1B
#define CR1C IGS_CR+0x1C
#define CR1D IGS_CR+0x1D
#define CR1E IGS_CR+0x1E
#define CR1F IGS_CR+0x1F
#define CR20 IGS_CR+0x20
#define CR21 IGS_CR+0x21
#define CR22 IGS_CR+0x22
#define CR23 IGS_CR+0x23
#define CR24 IGS_CR+0x24
#define CR25 IGS_CR+0x25
#define CR26 IGS_CR+0x26
#define CR27 IGS_CR+0x27
#define CR28 IGS_CR+0x28
#define CR29 IGS_CR+0x29
#define CR2A IGS_CR+0x2A
#define CR2B IGS_CR+0x2B
#define CR2C IGS_CR+0x2C
#define CR2D IGS_CR+0x2D
#define CR2E IGS_CR+0x2E
#define CR2F IGS_CR+0x2F
#define CR30 IGS_CR+0x30
#define CR31 IGS_CR+0x31
#define CR32 IGS_CR+0x32
#define CR33 IGS_CR+0x33
#define CR34 IGS_CR+0x34
#define CR35 IGS_CR+0x35
#define CR36 IGS_CR+0x36
#define CR37 IGS_CR+0x37
#define CR38 IGS_CR+0x38
#define CR39 IGS_CR+0x39
#define CR3A IGS_CR+0x3A
#define CR3B IGS_CR+0x3B
#define CR3C IGS_CR+0x3C
#define CR3D IGS_CR+0x3D
#define CR3E IGS_CR+0x3E
#define CR3F IGS_CR+0x3F
#define CR40 IGS_CR+0x40
#define CR41 IGS_CR+0x41
#define CR42 IGS_CR+0x42
#define CR43 IGS_CR+0x43
#define CR44 IGS_CR+0x44
#define CR45 IGS_CR+0x45
#define CR46 IGS_CR+0x46
#define CR47 IGS_CR+0x47
#define CR48 IGS_CR+0x48

#define CR_FIRST    CR00
#define CR_LAST	    CR48

#define SR00 IGS_SR+0x00
#define SR01 IGS_SR+0x01
#define SR02 IGS_SR+0x02
#define SR03 IGS_SR+0x03
#define SR04 IGS_SR+0x04

#define SR_FIRST    SR00
#define SR_LAST	    SR04

#define AR00 IGS_AR+0x00
#define AR01 IGS_AR+0x01
#define AR02 IGS_AR+0x02
#define AR03 IGS_AR+0x03
#define AR04 IGS_AR+0x04
#define AR05 IGS_AR+0x05
#define AR06 IGS_AR+0x06
#define AR07 IGS_AR+0x07
#define AR08 IGS_AR+0x08
#define AR09 IGS_AR+0x09
#define AR0A IGS_AR+0x0A
#define AR0B IGS_AR+0x0B
#define AR0C IGS_AR+0x0C
#define AR0D IGS_AR+0x0D
#define AR0E IGS_AR+0x0E
#define AR0F IGS_AR+0x0F
#define AR10 IGS_AR+0x10
#define AR11 IGS_AR+0x11
#define AR12 IGS_AR+0x12
#define AR13 IGS_AR+0x13
#define AR14 IGS_AR+0x14

#define AR_FIRST    AR00
#define AR_LAST	    AR14

#define GR00 IGS_GR+0x00
#define GR01 IGS_GR+0x01
#define GR02 IGS_GR+0x02
#define GR03 IGS_GR+0x03
#define GR04 IGS_GR+0x04
#define GR05 IGS_GR+0x05
#define GR06 IGS_GR+0x06
#define GR07 IGS_GR+0x07
#define GR08 IGS_GR+0x08
#define GR09 IGS_GR+0x09
#define GR0A IGS_GR+0x0A
#define GR0B IGS_GR+0x0B
#define GR0C IGS_GR+0x0C
#define GR0D IGS_GR+0x0D
#define GR0E IGS_GR+0x0E
#define GR0F IGS_GR+0x0F
#define GR10 IGS_GR+0x10
#define GR11 IGS_GR+0x11
#define GR12 IGS_GR+0x12
#define GR13 IGS_GR+0x13
#define GR14 IGS_GR+0x14
#define GR15 IGS_GR+0x15
#define GR16 IGS_GR+0x16
#define GR17 IGS_GR+0x17
#define GR18 IGS_GR+0x18
#define GR19 IGS_GR+0x19
#define GR1A IGS_GR+0x1A
#define GR1B IGS_GR+0x1B
#define GR1C IGS_GR+0x1C
#define GR1D IGS_GR+0x1D
#define GR1E IGS_GR+0x1E
#define GR1F IGS_GR+0x1F
#define GR20 IGS_GR+0x20
#define GR21 IGS_GR+0x21
#define GR22 IGS_GR+0x22
#define GR23 IGS_GR+0x23
#define GR24 IGS_GR+0x24
#define GR25 IGS_GR+0x25
#define GR26 IGS_GR+0x26
#define GR27 IGS_GR+0x27
#define GR28 IGS_GR+0x28
#define GR29 IGS_GR+0x29
#define GR2A IGS_GR+0x2A
#define GR2B IGS_GR+0x2B
#define GR2C IGS_GR+0x2C
#define GR2D IGS_GR+0x2D
#define GR2E IGS_GR+0x2E
#define GR2F IGS_GR+0x2F
#define GR30 IGS_GR+0x30
#define GR31 IGS_GR+0x31
#define GR32 IGS_GR+0x32
#define GR33 IGS_GR+0x33
#define GR34 IGS_GR+0x34
#define GR35 IGS_GR+0x35
#define GR36 IGS_GR+0x36
#define GR37 IGS_GR+0x37
#define GR38 IGS_GR+0x38
#define GR39 IGS_GR+0x39
#define GR3A IGS_GR+0x3A
#define GR3B IGS_GR+0x3B
#define GR3C IGS_GR+0x3C
#define GR3D IGS_GR+0x3D
#define GR3E IGS_GR+0x3E
#define GR3F IGS_GR+0x3F
#define GR40 IGS_GR+0x40
#define GR41 IGS_GR+0x41
#define GR42 IGS_GR+0x42
#define GR43 IGS_GR+0x43
#define GR44 IGS_GR+0x44
#define GR45 IGS_GR+0x45
#define GR46 IGS_GR+0x46
#define GR47 IGS_GR+0x47
#define GR48 IGS_GR+0x48
#define GR49 IGS_GR+0x49
#define GR4A IGS_GR+0x4A
#define GR4B IGS_GR+0x4B
#define GR4C IGS_GR+0x4C
#define GR4D IGS_GR+0x4D
#define GR4E IGS_GR+0x4E
#define GR4F IGS_GR+0x4F
#define GR50 IGS_GR+0x50
#define GR51 IGS_GR+0x51
#define GR52 IGS_GR+0x52
#define GR53 IGS_GR+0x53
#define GR54 IGS_GR+0x54
#define GR55 IGS_GR+0x55
#define GR56 IGS_GR+0x56
#define GR57 IGS_GR+0x57
#define GR58 IGS_GR+0x58
#define GR59 IGS_GR+0x59
#define GR5A IGS_GR+0x5A
#define GR5B IGS_GR+0x5B
#define GR5C IGS_GR+0x5C
#define GR5D IGS_GR+0x5D
#define GR5E IGS_GR+0x5E
#define GR5F IGS_GR+0x5F
#define GR60 IGS_GR+0x60
#define GR61 IGS_GR+0x61
#define GR62 IGS_GR+0x62
#define GR63 IGS_GR+0x63
#define GR64 IGS_GR+0x64
#define GR65 IGS_GR+0x65
#define GR66 IGS_GR+0x66
#define GR67 IGS_GR+0x67
#define GR68 IGS_GR+0x68
#define GR69 IGS_GR+0x69
#define GR6A IGS_GR+0x6A
#define GR6B IGS_GR+0x6B
#define GR6C IGS_GR+0x6C
#define GR6D IGS_GR+0x6D
#define GR6E IGS_GR+0x6E
#define GR6F IGS_GR+0x6F
#define GR70 IGS_GR+0x70
#define GR71 IGS_GR+0x71
#define GR72 IGS_GR+0x72
#define GR73 IGS_GR+0x73
#define GR74 IGS_GR+0x74
#define GR75 IGS_GR+0x75
#define GR76 IGS_GR+0x76
#define GR77 IGS_GR+0x77
#define GR78 IGS_GR+0x78
#define GR79 IGS_GR+0x79
#define GR7A IGS_GR+0x7A
#define GR7B IGS_GR+0x7B
#define GR7C IGS_GR+0x7C
#define GR7D IGS_GR+0x7D
#define GR7E IGS_GR+0x7E
#define GR7F IGS_GR+0x7F
#define GR80 IGS_GR+0x80
#define GR81 IGS_GR+0x81
#define GR82 IGS_GR+0x82
#define GR83 IGS_GR+0x83
#define GR84 IGS_GR+0x84
#define GR85 IGS_GR+0x85
#define GR86 IGS_GR+0x86
#define GR87 IGS_GR+0x87
#define GR88 IGS_GR+0x88
#define GR89 IGS_GR+0x89
#define GR8A IGS_GR+0x8A
#define GR8B IGS_GR+0x8B
#define GR8C IGS_GR+0x8C
#define GR8D IGS_GR+0x8D
#define GR8E IGS_GR+0x8E
#define GR8F IGS_GR+0x8F
#define GR90 IGS_GR+0x90
#define GR91 IGS_GR+0x91
#define GR92 IGS_GR+0x92
#define GR93 IGS_GR+0x93
#define GR94 IGS_GR+0x94
#define GR95 IGS_GR+0x95
#define GR96 IGS_GR+0x96
#define GR97 IGS_GR+0x97
#define GR98 IGS_GR+0x98
#define GR99 IGS_GR+0x99
#define GR9A IGS_GR+0x9A
#define GR9B IGS_GR+0x9B
#define GR9C IGS_GR+0x9C
#define GR9D IGS_GR+0x9D
#define GR9E IGS_GR+0x9E
#define GR9F IGS_GR+0x9F
#define GRA0 IGS_GR+0xA0
#define GRA1 IGS_GR+0xA1
#define GRA2 IGS_GR+0xA2
#define GRA3 IGS_GR+0xA3
#define GRA4 IGS_GR+0xA4
#define GRA5 IGS_GR+0xA5
#define GRA6 IGS_GR+0xA6
#define GRA7 IGS_GR+0xA7
#define GRA8 IGS_GR+0xA8
#define GRA9 IGS_GR+0xA9
#define GRAA IGS_GR+0xAA
#define GRAB IGS_GR+0xAB
#define GRAC IGS_GR+0xAC
#define GRAD IGS_GR+0xAD
#define GRAE IGS_GR+0xAE
#define GRAF IGS_GR+0xAF
#define GRB0 IGS_GR+0xB0
#define GRB1 IGS_GR+0xB1
#define GRB2 IGS_GR+0xB2
#define GRB3 IGS_GR+0xB3
#define GRB4 IGS_GR+0xB4
#define GRB5 IGS_GR+0xB5
#define GRB6 IGS_GR+0xB6
#define GRB7 IGS_GR+0xB7
#define GRB8 IGS_GR+0xB8
#define GRB9 IGS_GR+0xB9
#define GRBA IGS_GR+0xBA
#define GRBB IGS_GR+0xBB
#define GRBC IGS_GR+0xBC
#define GRBD IGS_GR+0xBD
#define GRBE IGS_GR+0xBE
#define GRBF IGS_GR+0xBF

#define GR_FIRST    GR00
#define GR_LAST	    GRBF

#define GREX3C	IGS_GREX+(0x3c-IGS_GREXBASE)

VgaReg igs_h_total[] = {
    CR00,   0, 8,
    VGA_REG_END
};

VgaReg igs_h_de_end[] = {
    CR01,   0, 8,
    VGA_REG_END
};

VgaReg igs_h_bstart[] = {
    CR02,   0, 8,
    VGA_REG_END
};

VgaReg igs_h_bend[] = {
    CR03,   0, 5,
    CR05,   7, 1,
    VGA_REG_END
};

VgaReg igs_de_skew[] = {
    CR03,   5, 2,
    VGA_REG_END
};

VgaReg igs_ena_vr_access[] = {
    CR03,   7, 1,
    VGA_REG_END
};

VgaReg igs_h_rstart[] = {
    CR04,   0, 8,
    VGA_REG_END
};

VgaReg igs_h_rend[] = {
    CR05,   0, 5,
    VGA_REG_END
};

VgaReg igs_h_rdelay[] = {
    CR05,   5, 2,
    VGA_REG_END
};

VgaReg igs_v_total[] = {
    CR06,   0, 8,
    CR07,   0, 1,
    CR07,   5, 1,
    GR11,   0, 1,
    VGA_REG_END
};

VgaReg igs_v_rstart[] = {
    CR10,   0, 8,
    CR07,   2, 1,
    CR07,   7, 1,
    GR11,   2, 1,
    VGA_REG_END
};

VgaReg igs_v_rend[] = {
    CR11,   0, 4,
    VGA_REG_END
};

VgaReg igs_clear_v_int[] = {
    CR11,   4, 1,
    VGA_REG_END
};

VgaReg igs_disable_v_int[] = {
    CR11,   5, 1,
    VGA_REG_END
};

VgaReg igs_bandwidth[] = {
    CR11,   6, 1,
    VGA_REG_END
};

VgaReg igs_crt_protect[] = {
    CR11,   7, 1,
    VGA_REG_END
};

VgaReg igs_v_de_end[] = {
    CR12,   0, 8,
    CR07,   1, 1,
    CR07,   6, 1,
    GR11,   1, 1,
    VGA_REG_END
};

VgaReg igs_offset[] = {
    CR13,   0, 8,
    GR15,   4, 2,
    VGA_REG_END
};

VgaReg igs_v_bstart[] = {
    CR15,   0, 8,
    CR07,   3, 1,
    CR09,   5, 1,
    GR11,   3, 1,
    VGA_REG_END
};

VgaReg igs_v_bend[] = {
    CR16,   0, 7,
    VGA_REG_END
};

VgaReg igs_linecomp[] = {
    CR18,   0, 8,
    CR07,   4, 1,
    CR09,   6, 1,
    GR11,   4, 1,
    VGA_REG_END
};

VgaReg igs_ivideo[] = {
    GR11,   5, 1,
    VGA_REG_END
};

VgaReg igs_num_fetch[] = {
    GR14,   0, 8,
    GR15,   0, 2,
    VGA_REG_END
};

VgaReg igs_wcrt0[] = {
    CR1F, 0, 1,
    VGA_REG_END
};

VgaReg igs_wcrt1[] = {
    CR1F, 1, 1,
    VGA_REG_END
};

VgaReg igs_rcrts1[] = {
    CR1F, 4, 1,
    VGA_REG_END
};

VgaReg igs_selwk[] = {
    CR1F, 6, 1,
    VGA_REG_END
};

VgaReg igs_dot_clock_8[] = {
    SR01, 0, 1,
    VGA_REG_END
};

VgaReg igs_screen_off[] = {
    SR01, 5, 1,
    VGA_REG_END
};

VgaReg igs_enable_write_plane[] = {
    SR02, 0, 4,
    VGA_REG_END
};

VgaReg igs_mexhsyn[] = {
    GR16,   0, 2,
    VGA_REG_END
};

VgaReg igs_mexvsyn[] = {
    GR16,   2, 2,
    VGA_REG_END
};

VgaReg igs_pci_burst_write[] = {
    GR30,   5, 1,
    VGA_REG_END
};

VgaReg igs_pci_burst_read[] = {
    GR30,   7, 1,
    VGA_REG_END
};

VgaReg	igs_iow_retry[] = {
    GREX3C, 0, 1,
    VGA_REG_END
};

VgaReg  igs_mw_retry[] = {
    GREX3C, 1, 1,
    VGA_REG_END
};

VgaReg  igs_mr_retry[] = {
    GREX3C, 2, 1,
    VGA_REG_END
};



VgaReg	igs_biga22en[] = {
    GR3D,   4, 1,
    VGA_REG_END
};

VgaReg	igs_biga24en[] = {
    GR3D,   5, 1,
    VGA_REG_END
};

VgaReg	igs_biga22force[] = {
    GR3D,   6, 1,
    VGA_REG_END
};

VgaReg	igs_bigswap[] = {
    GR3F,   0, 6,
    VGA_REG_END
};

/* #define IGS_BIGSWAP_8	0x3f */
/* #define IGS_BIGSWAP_16	0x2a */
/* #define IGS_BIGSWAP_32	0x00 */

VgaReg  igs_sprite_x[] = {
    GR50,   0, 8,
    GR51,   0, 3,
    VGA_REG_END
};

VgaReg  igs_sprite_preset_x[] = {
    GR52,   0, 6,
    VGA_REG_END
};

VgaReg  igs_sprite_y[] = {
    GR53,   0, 8,
    GR54,   0, 3,
    VGA_REG_END
};

VgaReg  igs_sprite_preset_y[] = {
    GR55,   0, 6,
    VGA_REG_END
};

VgaReg	igs_sprite_visible[] = {
    GR56,   0, 1,
    VGA_REG_END
};

VgaReg  igs_sprite_64x64[] = {
    GR56,   1, 1,
    VGA_REG_END
};

VgaReg  igs_mgrext[] = {
    GR57,   0, 1,
    VGA_REG_END
};

VgaReg  igs_hcshf[] = {
    GR57,   4, 2,
    VGA_REG_END
};

VgaReg	igs_mbpfix[] = {
    GR57,   6, 2,
    VGA_REG_END
};

VgaReg igs_overscan_red[] = {
    GR58, 0, 8,
    VGA_REG_END
};

VgaReg igs_overscan_green[] = {
    GR59, 0, 8,
    VGA_REG_END
};

VgaReg igs_overscan_blue[] = {
    GR5A, 0, 8,
    VGA_REG_END
};

VgaReg igs_memgopg[] = {
    GR73,   2, 1,
    VGA_REG_END
};

VgaReg igs_memr2wpg[] = {
    GR73,   1, 1,
    VGA_REG_END
};

VgaReg igs_crtff16[] = {
    GR73,   3, 1,
    VGA_REG_END
};

VgaReg igs_fifomust[] = {
    GR74,   0, 5,
    VGA_REG_END
};

VgaReg igs_fifogen[] = {
    GR75,   0, 5,
    VGA_REG_END
};

VgaReg igs_mode_sel[] = {
    GR77,   0, 4,
    VGA_REG_END
};

/* #define IGS_MODE_TEXT	0 */
/* #define IGS_MODE_8	1 */
/* #define IGS_MODE_565	2 */
/* #define IGS_MODE_5551	6 */
/* #define IGS_MODE_8888	3 */
/* #define IGS_MODE_888	4 */
/* #define IGS_MODE_332	9 */
/* #define IGS_MODE_4444	10 */

VgaReg  igs_sprite_addr[] = {
    GR7E,   0, 8,
    GR7F,   0, 4,
    VGA_REG_END
};

VgaReg  igs_fastmpie[] = {
    GR9E,   0, 1,
    VGA_REG_END
};

VgaReg  igs_vclk_m[] = {
    GRB0,   0, 8,
    GRBA,   0, 3,
    VGA_REG_END
};

VgaReg  igs_vclk_n[] = {
    GRB1,   0, 5,
    GRBA,   3, 3,
    VGA_REG_END
};

VgaReg  igs_vfsel[] = {
    GRB1,   5, 1,
    VGA_REG_END
};

VgaReg  igs_vclk_p[] = {
    GRB1,   6, 2,
    GRBA,   6, 1,
    VGA_REG_END
};

VgaReg  igs_frqlat[] = {
    GRB9, 7, 1,
    VGA_REG_END
};


VgaReg igs_dac_mask[] = {
    IGS_DAC + 0,	0, 8,
    VGA_REG_END
};

VgaReg igs_dac_read_index[] = {
    IGS_DAC + 1, 0, 8,
    VGA_REG_END
};

VgaReg igs_dac_write_index[] = {
    IGS_DAC + 2, 0, 8,
    VGA_REG_END
};

VgaReg igs_dac_data[] = {
    IGS_DAC + 3, 0, 8,
    VGA_REG_END
};

VgaReg	igs_rampwdn[] = {
    IGS_DACEX + 0,   0, 1,
    VGA_REG_END
};

VgaReg	igs_dac6_8[] = {
    IGS_DACEX + 0,   1, 1,
    VGA_REG_END
};

VgaReg  igs_ramdacbypass[] = {
    IGS_DACEX + 0,   4, 1,
    VGA_REG_END
};

VgaReg	igs_dacpwdn[] = {
    IGS_DACEX + 0,   6, 1,
    VGA_REG_END
};

VgaReg	igs_cursor_read_index[] = {
    IGS_DACEX + 1, 0, 8,
    VGA_REG_END
};

VgaReg igs_cursor_write_index[] = {
    IGS_DACEX + 2, 0, 8,
    VGA_REG_END
};

VgaReg igs_cursor_data[] = {
    IGS_DACEX + 3, 0, 8,
    VGA_REG_END
};

VGA8
_igsInb (VgaCard *card, VGA16 port)
{
    VGAVOL8 *reg;
    
    if (card->closure)
	return VgaReadMemb ((VGA32) card->closure + port);
    else
	return VgaInb (port);
}

void
_igsOutb (VgaCard *card, VGA8 value, VGA16 port)
{
    if (card->closure)
	VgaWriteMemb (value, (VGA32) card->closure + port);
    else
	VgaOutb (value, port);
}

void
_igsRegMap (VgaCard *card, VGA16 reg, VgaMap *map, VGABOOL write)
{
    if (reg < IGS_SR + IGS_NSR)
    {
	map->access = VgaAccessIndIo;
	map->port = 0x3c4;
	map->addr = 0;
	map->value = 1;
	map->index = reg - IGS_SR;
    }
    else if (reg < IGS_GR + IGS_NGR)
    {
	map->access = VgaAccessIndIo;
	map->port = 0x3ce;
	map->addr = 0;
	map->value = 1;
	map->index = reg - IGS_GR;
    }
    else if (reg < IGS_GREX + IGS_NGREX)
    {
	VGA8	gr33;

	map->access = VgaAccessDone;
	_igsOutb (card, 0x33, 0x3ce);
	gr33 = _igsInb (card, 0x3cf);
	_igsOutb (card, gr33 | 0x40, 0x3cf);
	_igsOutb (card, IGS_GREXBASE + reg - IGS_GREX, 0x3ce);
	if (write)
	    _igsOutb (card, map->value, 0x3cf);
	else
	    map->value = _igsInb (card, 0x3cf);
	_igsOutb (card, 0x33, 0x3ce);
	_igsOutb (card, gr33, 0x3cf);
	return;
    }
    else if (reg < IGS_AR + IGS_NAR)
    {
	reg -= IGS_AR;
	map->access = VgaAccessDone;
	/* reset AFF to index */
	(void) _igsInb (card, 0x3da);
	if (reg >= 16)
	    reg |= 0x20;
	_igsOutb (card, reg, 0x3c0);
	if (write)
	    _igsOutb (card, map->value, 0x3c0);
	else
	    map->value = _igsInb (card, 0x3c1);
	if (!(reg & 0x20))
	{
	    /* enable video display again */
	    (void) _igsInb (card, 0x3da);
	    _igsOutb (card, 0x20, 0x3c0);
	}
	return;
    }
    else if (reg < IGS_CR + IGS_NCR)
    {
	map->access = VgaAccessIndIo;
	map->port = 0x3d4;
	map->addr = 0;
	map->value = 1;
	map->index = reg - IGS_CR;
    }
    else if (reg < IGS_DAC + IGS_NDAC)
    {
	map->access = VgaAccessIo;
	map->port = 0x3c6 + reg - IGS_DAC;
    }
    else if (reg < IGS_DACEX + IGS_NDACEX)
    {
	VGA8	gr56;
	reg = 0x3c6 + reg - IGS_DACEX;
	map->access = VgaAccessDone;
	_igsOutb (card, 0x56, 0x3ce);
	gr56 = _igsInb (card, 0x3cf);
	_igsOutb (card, gr56 | 4, 0x3cf);
	if (write)
	    _igsOutb (card, map->value, reg);
	else
	    map->value = _igsInb (card, reg);
	_igsOutb (card, gr56, 0x3cf);
	return;
    }
    else switch (reg) {
    case IGS_MISC_OUT:
	map->access = VgaAccessIo;
	if (write)
	    map->port = 0x3c2;
	else
	    map->port = 0x3cc;
	break;
    case IGS_INPUT_STATUS_1:
	map->access = VgaAccessIo;
	map->port = 0x3da;
	break;
    }
    if (card->closure)
    {
	map->port = map->port + (VGA32) card->closure;
	if (map->access == VgaAccessIo)
	    map->access = VgaAccessMem;
	if (map->access == VgaAccessIndIo)
	    map->access = VgaAccessIndMem;
    }
}

VgaSave	    igsSaves[] = {
    CR00, CR18,
    SR01, SR02,
    GR11, GRBA,
    IGS_MISC_OUT, IGS_MISC_OUT,
    VGA_SAVE_END
};

void
igsRegInit (IgsVga *igsvga, VGAVOL8 *mmio)
{
    igsvga->card.map = _igsRegMap;
    igsvga->card.closure = (void *) mmio;
    igsvga->card.max = IGS_NREG;
    igsvga->card.values = igsvga->values;
    igsvga->card.saves = igsSaves;
}

void
igsSave (IgsVga *igsvga)
{
    igsSetImm (igsvga, igs_wcrt0, 1);
    igsSetImm (igsvga, igs_wcrt1, 1);
    igsSetImm (igsvga, igs_rcrts1, 1);
    igsSetImm (igsvga, igs_selwk, 1);
    VgaPreserve (&igsvga->card);
}

void
igsReset (IgsVga *igsvga)
{
    VgaRestore (&igsvga->card);
    igsSetImm (igsvga, igs_frqlat, 0);
    igsSetImm (igsvga, igs_frqlat, 1);
    igsSetImm (igsvga, igs_frqlat, 0);    
    VgaFinish (&igsvga->card);
}

char *
igsRegName(char *buf, VGA16 reg)
{
    if (reg < IGS_SR + IGS_NSR)
    {
	sprintf (buf, "  SR%02X", reg - IGS_SR);
    }
    else if (reg < IGS_GR + IGS_NGR)
    {
	sprintf (buf, "  GR%02X", reg - IGS_GR);
    }
    else if (reg < IGS_GREX + IGS_NGREX)
    {
	sprintf (buf, " GRX%02X", reg - IGS_GREX + IGS_GREXBASE);
    }
    else if (reg < IGS_AR + IGS_NAR)
    {
	sprintf (buf, "  AR%02X", reg - IGS_AR);
    }
    else if (reg < IGS_CR + IGS_NCR)
    {
	sprintf (buf, "  CR%02X", reg - IGS_CR);
    }
    else if (reg < IGS_DAC + IGS_NDAC)
    {
	sprintf (buf, " DAC%02X", reg - IGS_DAC);
    }
    else if (reg < IGS_DACEX + IGS_NDACEX)
    {
	sprintf (buf, "DACX%02X", reg - IGS_DACEX);
    }
    else switch (reg) {
    case IGS_MISC_OUT:
	sprintf (buf, "MISC_O");
	break;
    case IGS_INPUT_STATUS_1:
	sprintf (buf, "IN_S_1");
	break;
    }
    return buf;
}