-
Notifications
You must be signed in to change notification settings - Fork 9
/
ym7101.v
7364 lines (5521 loc) · 208 KB
/
ym7101.v
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.
*
*/
module ym7101
(
input MCLK,
input [7:0] SD,
output SE1,
output SE0,
output SC,
output RAS1,
output CAS1,
output WE1,
output WE0,
output OE1,
input [7:0] RD_i,
output [7:0] RD_o,
output RD_d,
output [7:0] DAC_R,
output [7:0] DAC_G,
output [7:0] DAC_B,
input [7:0] AD_i,
output [7:0] AD_o,
output AD_d,
output YS,
input SPA_B_i,
output SPA_B_pull,
output VSYNC,
input CSYNC_i,
output CSYNC_pull,
input HSYNC_i,
output HSYNC_pull,
input HL,
input SEL0,
input PAL,
input RESET,
//input SEL1,
input CLK1_i,
output CLK1_o,
//output CLK1_d,
output SBCR,
output CLK0,
input MCLK_e,
input EDCLK_i,
output EDCLK_o,
output EDCLK_d,
input [15:0] CD_i,
output [15:0] CD_o,
output CD_d,
input [22:0] CA_i,
output [22:0] CA_o,
output CA_d,
output reg [15:0] SOUND,
output INT_pull,
output BR_pull,
input BGACK_i,
output BGACK_pull,
input BG,
input MREQ,
input INTAK,
output IPL1_pull,
output IPL2_pull,
input IORQ,
input RD,
input WR,
input M1,
input AS,
input UDS,
input LDS,
input RW,
input DTACK_i,
output DTACK_pull,
output UWR,
output LWR,
output OE0,
output CAS0,
output RAS0,
output [7:0] RA,
input ext_test_2,
output vdp_hclk1,
output vdp_intfield,
output vdp_de_h,
output vdp_de_v,
output vdp_m5, // md mode
output vdp_rs1, // h32/h40
output vdp_m2, // v28/v30
output vdp_lcb,
output vdp_psg_clk1,
output vdp_hsync2,
input vdp_cramdot_dis,
output vdp_dma_oe_early,
output vdp_dma
);
wire cpu_sel;
wire cpu_as;
wire cpu_uds;
wire cpu_lds;
wire cpu_m1;
wire cpu_rd;
wire cpu_wr;
wire cpu_mreq;
wire cpu_iorq;
wire cpu_rw;
wire cpu_bg;
wire cpu_intak;
wire cpu_bgack;
wire cpu_pal;
wire cpu_pen;
wire cpu_clk0;
wire cpu_clk1;
wire i_csync = ~CSYNC_i;
wire i_hsync = ~HSYNC_i;
wire i_spa = ~SPA_B_i;
wire reset_ext = ~RESET;
wire clk1, clk2;
wire hclk1, hclk2;
wire reset_comb;
wire mclk_and1;
//reg prescaler_dff1 = 1'h0;
//reg prescaler_dff2 = 1'h0;
//reg prescaler_dff3 = 1'h0;
//reg prescaler_dff4 = 1'h0;
//reg prescaler_dff5 = 1'h0;
//reg prescaler_dff6 = 1'h0;
//reg prescaler_dff7 = 1'h0;
//reg prescaler_dff8 = 1'h0;
//reg prescaler_dff9 = 1'h0;
//reg prescaler_dff10 = 1'h0;
//reg prescaler_dff11 = 1'h0;
wire prescaler_dff1_l2;
wire prescaler_dff2_l2;
wire prescaler_dff3_l2;
wire prescaler_dff4_l2;
wire prescaler_dff5_l2;
wire prescaler_dff6_l2;
wire prescaler_dff7_l2;
wire prescaler_dff8_l2;
wire prescaler_dff9_l2;
wire prescaler_dff10_l2;
wire prescaler_dff11_l2;
wire prescaler_dff12_l2;
wire prescaler_dff13_l2;
wire prescaler_dff14_l2;
wire prescaler_dff15_l2;
wire prescaler_dff16_l2;
wire prescaler_dff17_l2;
wire mclk_clk1;
wire mclk_clk2;
wire mclk_clk3;
wire mclk_clk4;
wire mclk_clk5;
wire mclk_sbcr;
wire mclk_cpu_clk0;
wire mclk_cpu_clk1;
wire mclk_dclk;
wire io_m1_dff1_l2;
wire io_m1_dff2_l2;
wire io_m1_dff3_l2;
wire io_m1_dff4_l2;
wire io_m1_s1;
wire io_m1_s2;
wire io_m1_s3;
wire io_m1_s4;
wire io_m1_s5;
reg [22:0] io_address;
wire io_address_22o;
wire io_oe0;
wire w1153;
wire io_cas0;
wire io_ras0;
wire io_lwr;
wire io_uwr;
wire io_wr;
wire io_ipl1;
wire io_ipl2;
reg [15:0] io_data;
wire w1;
wire dff1_l2;
wire dff2_l2;
wire t1;
wire w2;
wire w3;
wire w4;
wire dff3_l2;
wire dff4_l2;
wire t2;
wire t3;
wire t4;
wire w5;
wire l1;
wire l2;
wire l3;
wire w6;
wire l4;
wire w7;
wire l5;
wire w8;
wire l6;
wire l7;
wire l8;
wire w9;
wire w10;
wire w11;
wire w12;
wire w13;
wire w14;
wire w15;
wire w16;
wire w17; // nc
wire w18;
wire w19;
wire w20;
wire w21;
wire w22;
wire w23;
wire w24;
wire w25;
wire dff5_l2;
wire dff6_l2;
wire w26;
wire dff7_l2;
wire w27;
wire w28;
wire dff8_l2;
wire dff9_l2;
wire w29;
wire w30;
wire w31;
wire dff10_l2;
wire dff11_l2;
wire w32;
wire w33;
wire w34;
wire w35;
wire w36;
wire w37;
wire dff12_l2;
wire w38;
wire dff13_l2;
wire dff14_l2;
wire dff15_l2;
wire w39;
wire w40;
wire w41;
wire dff16_l2;
wire dff17_l2;
wire dff18_l2;
wire dff19_l2;
wire dff20_l2;
wire dff21_l2;
wire dff22_l2;
wire w42;
wire dff23_l2;
wire dff24_l2;
wire dff25_l2;
wire dff26_l2;
wire dff27_l2;
wire dff28_l2;
wire dff29_l2;
wire w43;
wire w44;
wire w45;
wire w46;
wire w47;
wire t5;
wire w48;
wire l9;
wire l10;
wire l11;
wire w49;
wire w50;
wire t6;
wire l12;
wire w51;
wire l13;
wire w52;
wire l14;
wire w53;
wire w54;
wire dff30_l2;
wire dff31_l2;
wire w55;
wire dff32_l2;
wire w56;
wire w57;
wire w58;
wire t7;
wire t8;
wire w59;
wire w60;
wire w61;
wire w62;
wire w63;
wire w64;
wire w65;
wire w66;
wire t9;
wire t10;
wire t11;
wire w67;
wire w68;
wire w69;
wire l15;
wire w70;
wire w71;
wire w72;
wire w73;
wire w74;
wire w75;
wire w76;
wire w77;
wire w78;
wire w79;
wire w80;
wire w81;
wire w82;
wire w83;
wire w84;
wire w85;
wire w86;
wire w87;
wire w88;
wire w89;
wire w90;
wire w91;
wire w92;
wire w93;
wire w94;
wire w95;
wire w96;
wire w97;
wire w98;
wire w99;
wire w100;
wire w101;
wire w102;
wire [7:0] w103;
wire w104;
wire [7:0] l16;
wire w105;
wire w106;
wire w107;
wire w108;
wire w109;
wire w110;
wire w111;
wire w112;
wire w113;
wire w114;
wire w115;
wire w116;
wire w117;
wire w118;
wire l17;
wire w119;
wire w120;
wire w121;
wire t12;
wire w122;
wire w123;
wire w124;
wire w125;
wire w126;
wire w127;
wire w128;
wire w129;
wire w130;
wire w131;
wire w132;
wire w133;
wire w134;
wire w135;
wire t13;
wire w136;
wire w137;
wire t14;
wire w138;
wire w139;
wire w140;
wire w141;
wire w142;
wire l18;
wire l19;
wire w143;
wire t15, t15_n;
wire t16, t16_n;
wire t17;
wire w144;
wire w145;
wire t18, t18_n;
wire w146;
wire t19;
wire t20;
wire w147;
wire w148;
wire w149;
wire t21;
wire w150;
wire w151;
wire w152;
wire w153;
wire w154;
wire w155;
wire w156;
wire w157;
wire w158;
wire w159;
wire w160;
wire w161;
wire t22;
wire w162;
wire w163;
wire w164;
wire w165;
wire w166;
wire w167;
wire w168;
wire w169;
wire w170;
wire t23;
wire t24;
wire w171;
wire w172;
wire w173;
wire w174;
wire w175;
wire t25;
wire w176;
wire w177;
wire w178;
wire w179;
wire w180;
wire l20;
wire w181;
wire w182;
wire w183;
wire w184;
wire l21;
wire l22;
wire l23;
wire l24;
wire l25;
wire l26;
wire w185;
wire t26, t26_n;
wire w186;
wire l27;
wire w187;
wire w188;
wire w189;
wire w190;
wire w191;
wire w192;
wire w193;
wire w194;
wire w195;
wire l28;
wire w196;
wire t27;
wire w197;
wire w198;
wire w199;
wire w200;
wire w201;
wire w202;
wire l29;
wire l30;
wire w203;
wire w204;
wire l31;
wire l32;
wire l33;
wire l34;
wire w205;
wire w206;
wire w207;
wire w208;
wire w209;
wire w210;
wire w211;
wire w212;
wire w213;
wire w214;
wire w215;
wire w216;
wire w217;
wire w218;
wire w219;
wire w220;
wire w221;
wire w222;
wire w223;
wire w224;
wire w225;
wire w226;
wire w227;
wire w228;
wire w229;
wire w230;
wire w231;
wire w232;
wire w233;
wire w234;
wire w235;
wire [16:0] l35;
wire [16:0] l36;
wire [16:0] l37;
wire [16:0] l38;
wire [16:0] l39;
wire w244;
wire w245;
wire w246;
wire w247;
wire w248;
wire l40;
wire w249;
wire l41;
wire w250;
wire w251;
wire l42;
wire w252;
wire l43;
wire l44;
wire l45;
wire w253;
wire w254;
wire w255;
wire l46;
wire w256;
wire w257;
wire w258;
wire w259;
wire w260;
wire w261;
wire w262; // nc
wire w263;
wire w264;
wire w265;
wire l47;
wire w266;
wire w267;
wire l48;
wire w268;
wire w269;
wire l49;
wire w270;
wire w271;
wire t28;
wire l50;
wire w272;
wire w273;
wire w274;
wire w275;
wire w276;
wire w277;
wire w278;
wire w279;
wire w280;
wire w281;
wire w282;
wire w283;
wire w284;
wire w285;
wire w286;
wire w287;
wire w288;
wire w289;
wire w290;
wire [1:0] l51;
wire w291;
wire w292;
wire w293;
wire w294;
wire w295;
wire w296;
wire w297;
wire l52;
wire l53;
wire l54;
wire w298;
wire w299;
wire w300;
wire l55;
wire l56;
wire l57;
wire l58;
wire l59;
wire l60;
wire l61;
wire l62;
wire l63;
wire l64;
wire l65;
wire l66;
wire l67;
wire l68;
wire l69;
wire l70;
wire l71;
wire l72;
wire l73;
wire l74;
wire l75;
wire l76;
wire l77;
wire l78;
wire w301;
wire w302;
wire w303;
wire w304;
wire w305;
wire w306;
wire w307;
wire w308;
wire w309;
wire w310;
wire w311;
wire w312;
wire w313;
wire w314;
wire w315;
wire w316;
wire w317;
wire w318;
wire w319;
wire w320;
wire w321;
wire w322;
wire w323;
wire w324;
wire w325;
wire w326;
wire w327;
wire w328;
wire w329;
wire w330;
wire w331;
wire w332;
wire w333;
wire w334;
wire l79;
wire l80;
wire w335;
wire l81;
wire w336;
wire w337;
wire w338;
wire l82;
wire l83;
wire l84;
wire w339;
wire w340;
wire l85;
wire l86;
wire l87;
wire w341;
wire w342;
wire l88;
wire l89;
wire w343;
wire w344;
wire w345;
wire w346;
wire [7:0] l90;
wire [7:0] l91;
wire [7:0] w347;
wire [7:0] w348;
wire [7:0] l92;
wire [7:0] w349;
wire [7:0] l93;
wire [7:0] w350;
wire [7:0] l94;
wire [7:0] l95;
wire [7:0] l96;
wire [7:0] l97;
wire [7:0] w351;
wire [7:0] unk_data;
wire [7:0] l98;
wire [7:0] l99;
wire [7:0] w352;
wire [7:0] l100;
wire [7:0] l101;
wire [7:0] w353;
wire [7:0] l102;
wire [7:0] l103;
wire [7:0] w354;
wire [7:0] l104;
wire [8:0] l105;
wire [9:0] w355;
wire [8:0] l106;
wire l107;
wire l108;
wire l109;
wire l110;
wire w356;
wire w357;
wire w358;
wire w359;
wire w360;
wire l111;
wire l112;
wire w361;
wire w362;
wire w363;
wire [8:0] w364;
wire w365;
wire w366;
wire w367;
wire w368;
wire w369;
wire w370;
wire l113;
wire l114;
wire l115;
wire l116;
wire w371;
wire w372;
wire l117;
wire l118;
wire l119;
wire w373;
wire w374;
wire l120;
wire w375;
wire w376;
wire w377;
wire l121;
wire l122;
wire l123;
wire w378;
wire w379;
wire w380;
wire w381;
wire w382;
wire w383;
wire w384;
wire w385;
wire w386;
wire l124;
wire l125;
wire l126;
wire w387;
wire l127;
wire w388;
wire l128;
wire w389;
wire l129;
wire w390;
wire w391;
wire l130;
wire w392;
wire t29;
wire l131;
wire w393;
wire l132;
wire w394;
wire w395;
wire l133;
wire l134;
wire w396;
wire l135;
wire l136;
wire w397;
wire w398;
wire w399;
wire w400;
wire t30;
wire w401;
wire l137;
wire l138;
wire w402;
wire l139;
wire w403;
wire l140;
wire l141;
wire l142;
wire w404;
wire w405;
wire w406;
wire t31;
wire w407;
wire w408;
wire w409;
wire l143;
wire l144;
wire w410;
wire l145;
wire l146;
wire l147;
wire l148;
wire w411;
wire l149;
wire l150;
wire w412;
wire w413;
wire l151;
wire t32;
wire w414;
wire l152;
wire l153;
wire w415;
wire w416;
wire w417;
wire w418;
wire w419;
wire l154;
wire l155;
wire l156;
wire w420;
wire w421;
wire l157;
wire w422;
wire l158;
wire t33;
wire w423;
wire w424;
wire w425;
wire l159;
wire l160;
wire w426;
wire l161;
wire w427;
wire [8:0] w428;
wire w429;
wire w430;
wire w431;
wire w432;
wire w433;
wire w434;
wire w435;
wire w436;
wire w437;
wire w438;
wire l162;
wire w439;
wire l163;
wire w440;
wire t34;
wire w441;
wire l164;
wire w442;
wire t35;
wire w443;
wire l165;
wire w444;
wire w445;
wire t36;
wire w446;
wire l167;
wire w447;
wire w448;
wire w449;
wire l168;
wire w450;
wire w451;
wire l169;
wire w452;
wire w453;
wire t37;
wire w454;
wire w455;
wire w456;
wire l170;
wire w457;
wire w458;
wire w459;
wire t38;
wire l171;
wire l172;
wire t39;
wire w460;
wire w461;
wire l173;
wire l174;
wire w462;
wire w463;
wire w464;
wire l175;
wire l176;
wire w465;
wire w466;
wire [47:0] pla_vcnt;
wire [62:0] pla_hcnt1;
wire [45:0] pla_hcnt2;
wire w467;
wire w468;
wire w469;
wire w470;
wire w471;
wire w472;
wire w473;
wire w474;
wire w475;
wire w476;
wire w477;
wire w478;
wire w479;
wire w480;
wire w481;
wire w482;
wire w483;
wire w484;
wire w485;
wire w486;
wire w487;
wire w488;
wire w489;
wire w490;
wire w491;
wire w492;
wire w493;
wire w494;
wire w495;
wire w496;
wire w497;
wire w498;
wire w499;
wire w500;
wire w501;
wire w502;
wire w503;
wire w504;
wire w505;
wire w506;
wire w507;
wire w508;
wire w509;
wire w510;
wire w511;
wire w512;
wire l663;
wire w513;
wire l178;
wire w514;
wire [7:0] l179;
wire [10:0] w515; // 11 bits
wire [10:0] l180; // 11 bits
wire [10:0] l181;
wire [2:0] l182;
wire l183;
wire w516;
wire w517;
wire [10:0] l184;
wire [10:0] l185;
wire l186;
wire [10:0] w518;
wire w519;
wire w520;
wire [10:0] w521;
wire [10:0] w522;
wire [1:0] reg_hsz;
wire [1:0] reg_vsz;
wire w523;
wire w524;
wire w525;
wire [6:0] w526;
wire [6:0] w527;
wire [6:0] w528;
wire w529;
wire w530;
wire w531;
wire [3:0] reg_sa;
wire [1:0] reg_nt; // m4