-
Notifications
You must be signed in to change notification settings - Fork 6
/
vdp.h
1919 lines (1886 loc) · 32.5 KB
/
vdp.h
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
/*
* Copyright (C) 2023 nukeykt
*
* This file is part of Nuked-MD.
*
* 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.
*
* YM7101 emulator
* Thanks:
* Fritzchens Fritz:
* YM7101 decap and die shot.
* andkorzh:
* YM7101 deroute.
* org (ogamespec):
* early YM7101 decap and die shot.
* HardWareMan:
* help & support.
*
*/
#pragma once
#include "common.h"
#pragma pack(push, 1)
typedef struct {
int l1;
int l2;
} dff_t;
typedef struct {
int pal;
int priority;
int index;
} sprpixel_t;
typedef struct {
int i_clk1;
int i_clk2;
int i_pal;
int i_pen;
int i_sel0;
int i_as;
int i_uds;
int i_lds;
int i_m1;
int i_rd;
int i_wr;
int i_iorq;
int i_mreq;
int i_rw;
int i_cpu_clk0;
int i_cpu_clk1;
int i_bg;
int i_intak;
int i_bgack;
int i_reset;
int i_dtack;
int i_csync;
int i_hsync;
int i_vram_sd;
int i_vram_rd;
int i_vram_ad;
int i_spa;
// int i_data;
// int i_address;
} vdp_i_state_t;
typedef struct {
int mclk;
int i_reset;
int i_test_reset;
int i_clk1;
int i_edclk;
int i_pal;
int i_rs0; //
int i_rs1; //
int i_test_psg; // chip->reg_test1 & 1
//int i_test_dclk; // chip->reg_test1 & 2
} vdp_prescaler_i_state_t;
typedef struct {
vdp_prescaler_i_state_t input, input_old;
dff_t mclk_prescaler_dff1;
dff_t mclk_prescaler_dff2;
int mclk_and1;
dff_t mclk_prescaler_dff3;
dff_t mclk_prescaler_dff4;
int mclk_clk1;
dff_t mclk_prescaler_dff5;
dff_t mclk_prescaler_dff6;
dff_t mclk_prescaler_dff7;
int mclk_clk2;
dff_t mclk_prescaler_dff8;
dff_t mclk_prescaler_dff9;
dff_t mclk_prescaler_dff10;
dff_t mclk_prescaler_dff11;
int mclk_clk3;
dff_t mclk_prescaler_dff12;
dff_t mclk_prescaler_dff13;
dff_t mclk_prescaler_dff14;
int mclk_clk4;
dff_t mclk_prescaler_dff15;
dff_t mclk_prescaler_dff16;
dff_t mclk_prescaler_dff17;
int mclk_clk5;
int mclk_sbcr;
int mclk_cpu_clk0;
int mclk_cpu_clk1;
int mclk_dclk;
int o_clk0;
int o_clk1;
int o_sbcr;
int o_edclk;
} vdp_prescaler_t;
typedef struct {
int i_cpu_clk0;
int i_reset; // reset_comb
int i_write; // w111
int i_data; // io_data;
int i_test; // reg_test0
} vdp_psg_input_t;
typedef struct {
vdp_psg_input_t input, input_old;
int psg_clk1;
int psg_clk2;
int l631[2];
int l632[2];
int w1104;
int w1105;
int l633[2];
int l634;
int psg_hclk1;
int psg_hclk2;
int t43;
int w1106;
int l635[2];
int l636[2];
int l637[2];
int t44;
int l638[2];
int w1107;
int w1108;
int w1109;
int w1110;
int l639[2];
int w1111;
int w1112;
int w1113;
int w1114;
int w1115;
int w1116;
int w1117;
int w1118;
int l640[2];
int w1119;
int w1120;
int l641[2];
int l642[2];
int l643[2];
int l644[2];
int w1121;
int w1122;
int w1123;
int w1124;
int w1125;
int l645[2];
int l646[2];
int l647[2];
int l648[2];
int l649[2];
int w1126;
int w1127;
int w1128;
int w1129;
int w1130;
int w1131;
int l650[2];
int w1132;
int l651[2];
int w1133;
int l652[2];
int l653;
int w1134;
int l654;
int w1135;
int w1136;
int w1137;
int w1138;
int w1139;
int w1140;
int w1141;
int w1142;
int w1143;
int l655;
int l656;
int l657;
int l658;
int w1144;
int l659;
int l660;
int l661;
int l662;
int w1145;
int w1146;
int w1147;
int w1148;
int w1149;
int w1150;
int w1151;
int w1152;
float psg_out;
int o_psg_debug;
} vdp_psg_t;
typedef struct {
int t;
vdp_prescaler_t prescaler;
vdp_psg_t psg;
int dclk_prescaler_l1[2];
int dclk_prescaler_l2;
int dclk_prescaler_l3;
dff_t dclk_prescaler_dff1;
dff_t dclk_prescaler_dff2;
int reset_comb;
int reset_l1[2];
int reset_l2[2];
int reset_pulse;
int reset_ext;
int cpu_bg;
int cpu_intak;
int cpu_pal;
int cpu_pen;
dff_t io_m1_dff1;
dff_t io_m1_dff2;
dff_t io_m1_dff3;
dff_t io_m1_dff4;
int io_address;
int io_address_22o;
//int io_oe0;
//int io_cas0;
//int io_ras0;
//int io_lwr;
//int io_uwr;
//int io_wr;
//int io_ipl1;
//int io_ipl2;
int io_data;
dff_t dff1;
dff_t dff2;
int t1;
//int w3;
//int w4;
dff_t dff3;
dff_t dff4;
int t2;
int t3;
int t4;
//int w5;
int l1[2];
int l2[2];
int l3[2];
//int w6;
int l4[2];
int l5[2];
int l6;
int l7;
int l8;
//int w9;
//int w10;
int w11;
int w12;
//int w14;
//int w16;
//int w17;
//int w18;
//int w19;
//int w20;
//int w21;
//int w22;
//int w23;
//int w24;
dff_t dff5;
dff_t dff6;
//int w26;
dff_t dff7;
//int w28;
dff_t dff8;
dff_t dff9;
//int w29;
//int w30;
//int w31;
dff_t dff10;
dff_t dff11;
//int w32;
//int w33;
//int w34;
//int w35;
//int w36;
//int w37;
dff_t dff12;
//int w38;
dff_t dff13;
dff_t dff14;
dff_t dff15;
//int w39;
//int w40;
//int w41;
dff_t dff16;
dff_t dff17;
dff_t dff18;
dff_t dff19;
dff_t dff20;
dff_t dff21;
dff_t dff22;
int w42;
dff_t dff23;
dff_t dff24;
dff_t dff25;
dff_t dff26;
dff_t dff27;
dff_t dff28;
dff_t dff29;
//int w43;
//int w44;
//int w45;
//int w46;
int w47;
int t5;
//int w48;
int l9[2];
int l10;
int l11;
//int w49;
//int w50;
int t6;
int l12[2];
//int w51;
int l13[2];
int l14;
//int w53;
//int w54;
dff_t dff30;
dff_t dff31;
//int w55;
dff_t dff32;
//int w56;
//int w57;
//int w58;
int t7;
int t8;
//int w59;
//int w60;
//int w61;
//int w62;
//int w63;
int w64;
//int w65;
//int w66;
int t9;
int t10;
int t11;
int cnt1[2];
int l15[2];
//int w70;
int w71;
int w72;
int w73;
//int w74;
//int w75;
//int w76;
//int w77;
//int w78;
//int w79;
//int w80;
//int w81;
//int w82;
//int w83;
//int w84;
//int w85;
int w86;
int w87;
int w88;
int w89;
int w90;
int w91;
int w92;
int w93;
int w94;
int w95;
int w96;
int w97;
int w98;
int w99;
int w100;
//int w101;
//int w102;
//int w103;
//int w104;
int l16;
//int w105;
int w106;
int w107;
int w108;
int w109;
//int w110;
int w111;
//int w112;
//int w113;
int w114;
//int w115;
//int w116;
int w117;
//int w118;
int l17;
//int w119;
//int w120;
//int w121;
int t12;
//int w122;
//int w123;
//int w124;
//int w125;
//int w126;
//int w127;
//int w128;
//int w129;
//int w130;
//int w131;
//int w132;
//int w133;
int w134;
//int w135;
int t13;
//int w136;
//int w137;
int t14;
//int w138;
//int w139;
//int w140;
//int w141;
int w142;
int l18;
int l19;
//int w143;
int t15;
int t15_n;
int t16;
int t16_n;
int t17;
//int w144;
//int w145;
int t18;
int t18_n;
//int w146;
int t19;
int t20;
//int w147;
//int w148;
//int w149;
int t21;
//int w150;
int w151;
//int w152;
//int w153;
//int w154;
//int w155;
//int w156;
//int w157;
//int w158;
//int w159;
int w160;
//int w161;
int t22;
//int w162;
//int w163;
//int w164;
//int w165;
//int w166;
//int w167;
//int w168;
//int w169;
//int w170;
int t23;
int t24;
//int w171;
//int w172;
//int w173;
//int w174;
//int w175;
int t25;
//int w176;
int w178;
int w179;
//int w180;
int l20;
//int w181;
//int w182;
//int w183;
int l21;
int l22;
int l23;
int l24;
int l25;
int l26;
//int w185;
int t26;
int t26_n;
int l27[2];
//int w187;
//int w188;
//int w189;
//int w190;
//int w191;
//int w192;
//int w194;
int w195;
int l28[2];
int t27;
//int w197;
//int w198;
//int w199;
//int w200;
int w201;
//int w202;
int l29[2];
int l30[2];
//int w203;
//int w204;
int l31;
int l32;
int l33[2];
int l34;
//int w210;
//int w211;
//int w212;
//int w213;
//int w214;
//int w215;
//int w216;
//int w217;
int w218;
int w219;
int w220;
int w221;
int w222;
int w223;
int w224;
int w225;
int w226;
//int w227;
//int w228;
//int w229;
int w230;
int w231;
int w232;
int w233;
//int w234;
//int w235;
int l35; // 17 bits
int l36; // 17 bits
int l37; // 17 bits
int l38; // 17 bits
int l39; // 17 bits
#if 0
int w236;
int w237;
int w238;
int w239;
int w240;
int w241;
int w242;
int w243;
#endif
//int w245;
//int w246;
//int w247;
//int w248;
int l40[2];
//int w249;
int l41;
//int w250;
int l42[2];
int w252;
int l43[2];
int l44[2];
int l45[2];
//int w253;
int l46[2];
//int w256;
//int w257;
//int w258;
//int w259;
//int w260;
//int w261;
//int w262; // unused??
int w263;
//int w264;
int w265;
int l47;
int l48[2];
int w267;
//int w268;
int l49[2];
//int w270;
//int w271;
int t28;
int l50[2];
//int w273;
//int w274;
//int w275;
//int w276;
//int w277;
//int w278;
//int w279;
//int w280;
//int w281;
//int w282;
int w283;
int w284;
//int w285;
int w286;
//int w287;
int w288;
//int w289;
//int w290;
int l51[2];
//int w291;
//int w292;
//int w293;
//int w294;
//int w295;
int l52[2];
int l53[2];
int l54[2];
//int w298;
//int w299;
//int w300;
int l55;
int l56;
int l57;
int l58;
int l59;
int l60;
int l61;
int l62;
int l63;
int l64;
int l65;
int l66;
int w301;
int w302;
int w303;
//int w304;
//int w306;
//int w307;
//int w308;
//int w309;
//int w310;
int l67;
int l68;
int l69;
int l70;
int l71;
int l72;
int l73;
int l74;
int l75;
int l76;
int l77;
int l78;
//int w311;
//int w312;
//int w313;
//int w314;
//int w315;
int w316;
int w317;
int w318;
int w319;
int w320;
//int w321;
//int w322;
//int w324;
//int w325;
//int w326;
//int w327;
//int w328;
//int w329;
//int w330;
//int w331;
//int w332;
//int w333;
//int w334;
int l79[2];
int l80[2];
int l81[2];
//int w336;
//int w337;
//int w338;
int l82[2];
int l83[2];
int l84[2];
int l85[2];
int l86[2];
int l87[2];
int l88[2];
int l89[2];
//int w345;
//int w346;
int l90;
int l91;
int w347;
//int w348;
int l92;
//int w349;
int l93;
//int w350;
int l94;
int l95;
int l96;
int l97;
//int unk_data;
int l98;
int l99;
int l100;
int l101;
int l102;
int l103;
int l104[2];
int l105[2]; // v counter
int w355;
int l106[2]; // h counter
int l107[2];
int l108[2];
int l109[2];
int l110[2];
int w356;
int w357;
int w360;
int l111[2];
int l112[2];
int w370;
int l113[2];
int l114[2];
int l115[2];
int l116[2];
int w371;
int w372;
int l117[2];
int l118[2];
int l119[2];
int l120[2];
int l121[2];
int l122[2];
int l123[2];
int w379;
int w380;
int w381;
int w382;
int w383;
int w385;
int l124[2];
int l125[2];
int l126[2];
int l127[2];
int w388;
int l128[2];
int w389;
int l129[2];
int l130[2];
int t29;
int l131[2];
int w393;
int l132[2];
int w394;
int l133[2];
int l134[2];
int l135[2];
int l136[2];
int t30;
int l137[2];
int l138[2];
int w402;
int l139[2];
int l140[2];
int l141[2];
int l142[2];
int t31;
int l143[2];
int l144[2];
int l145[2];
int l146[2];
int l147[2];
int l148[2];
int l149[2];
int l150[2];
int l151[2];
int t32;
int l152[2];
int l153[2];
int w415;
int w417;
int w418;
int w419;
int l154[2];
int l155[2];
int l156[2];
int l157[2];
int w422;
int l158[2];
int t33;
int w423;
int w424;
int l159[2];
int l160[2];
int l161[2];
int l162[2];
int w439;
int l163[2];
int t34;
int l164[2];
int t35;
int l165[2];
int l166[2];
int t36;
int w446;
int l167[2];
int l168[2];
int l169[2];
int t37;
int l170[2];
int w457;
int t38;
int l171[2];
int l172[2];
int t39;
int l173[2];
int l174[2];
int l175[2];
int l176[2];
int l663[2];
int l178[2];
int l179;
int l180; // 11 bits
int l181[2];
int l182[2];
int l183[2];
int l184;
int l185;
int l186[2];
int reg_hsz;
int reg_vsz;
int reg_sa;
int reg_nt; // m4
int reg_sb;
int reg_8e_b0;
int reg_8e_b4;
int reg_wd;
int reg_hs;
int reg_whp;
int reg_rigt;
int reg_wvp;
int reg_down;
int l187;
int l188;
int l189;
int l190;
int reg_88; // m4 scroll
int l191;
int l192;
int l193;
int l194;
int l195;
int l196[2];
int l197[2];
int l198[2];
int l199[2];
int l200[2];
int l201[2];
int l202[2];
int l203[2];
int l204[2];
int l205[2];
int l206[2];
int l207[2];
int l208[2];
int l209[2];
int l210[2];
int l211[2];
int l212[2]; // 6 bits
int l213;
int l214[2];
int l215[2];
int l216[2];
int l217[2];
int l218[2];
int l219;
int l220;
int l221;
int l222;
int l223;
int l224;
int l225;
int l226;
int l227;
int l228[2];
int l229[2];
int l230[2];
int l231[2];
int l232;
int l233;
int l234;
int l235;
int l236;
int l237;
int l238;
int l239;
int l240;
int l241[2];
int l242[2];
int l243;
int l244;
int l245;
int l246;
int l247;
int l248[2];
int l249[2];
int l250[2];
int l251;
int l252[2];
int l253[2];
int l254[2];
int l255;
int l256;
int l257;
int l258;
int l259;
int l260;
int l261;
int l262;
int l263;
int l264;
int l265;
int l266;
int l267[2];
int l268[2];
int l269[2];
int l270[2];
int l271[2];
int l272[2];
int l273[2];
int l274[2];
int l275;
int l276;
int l277;
int l278;
int l279;
int l280;
int l281;
int l282;
int l283;
int l284[2];
int l285[2];
int l286[2];
int l287;
int l288;
int l289;
int l290;
int l291;
int l292;
int l293[2];
int l294;
int l295;
int l296;
int l297;
int l298;
int l299[2];
int l300[2];
int l301[2];
int l302[2];