-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsharpmz.vhd
1634 lines (1496 loc) · 97.4 KB
/
sharpmz.vhd
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
---------------------------------------------------------------------------------------------------------
--
-- Name: sharpmz.vhd
-- Created: June 2018
-- Author(s): Philip Smart
-- Description: Sharp MZ series compatible logic.
--
-- This module is the main (top level) container for the Emulation.
--
-- The design tries to work from top-down, where components which are common
-- to the Business and Personal MZ series are at the top (ie. main memory,
-- ROM, CPU), drilling down two trees, MZ-80B (Business), MZ-80C (Personal)
-- to the machine specific modules and components. Some components are common
-- by their nature (ie. 8255 PIO) but these are instantiated within the lower
-- tree branch as their design use is less generic.
--
-- The tree is as follows;-
--
-- (emu) sharpmz.vhd (mz80c) -> mz80c.vhd
-- |
-- |
-- | -> cmt.vhd (common)
-- | -> keymatrix.vhd (common)
-- | -> pll.v (common)
-- | -> clkgen.vhd (common)
-- | -> T80 (common)
-- | -> i8255 (common)
-- sys_top.sv (emu) -> (emu) sharpmz.vhd (hps_io) -> hps_io.sv
-- | -> i8253 (common)
-- | -> dpram.vhd (common)
-- | -> dprom.vhd (common)
-- | -> mctrl.vhd (common)
-- | -> video.vhd (common)
-- |
-- |
-- (emu) sharpmz.vhd (mz80b) -> mz80b.vhd
--
-- The idea of the design is to keep the emulation as independent of the HPS
-- as possible (so it works standalone), only needing the HPS to set control registers,
-- load tape ram and overlay the menu system. This in theory should allow easier
-- porting if someone wants to port this emulator to another platform or even
-- target an non-HPS Cyclone chip and instantiate another CPU as the menu control.
--
-- As the Cyclone V SE on the Terasic DE10 has 5.5Mbits of memory, nearly all the RAM used
-- by the emulation is on the FPGA. The Floppy Disk Controller may use HPS memory (or the
-- external SDRAM) depending on wether I decide to cache entire Floppy Disks as per the CMT
-- unit.
--
-- Credits: Credit to Nibbles Lab. 2012-2016, as I was originally going to port his mz80c_de0 emulator
-- based on a Terasic DE0 board. He used external memory and an instantiated NIOSII CPU
-- to provide a menu/control system. Some snippets of his code, such as the keyboard matrix
-- have been re-used in this emulation.
-- Copyright: (c) 2018 Philip Smart <[email protected]>
--
-- History: June 2018 - Initial creation.
--
---------------------------------------------------------------------------------------------------------
-- This source file 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 3 of the License, or
-- (at your option) any later version.
--
-- This source file 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, see <http:--www.gnu.org-licenses->.
---------------------------------------------------------------------------------------------------------
library ieee;
library pkgs;
use ieee.std_logic_1164.all;
use ieee.std_logic_unsigned.all;
use pkgs.config_pkg.all;
use pkgs.clkgen_pkg.all;
use pkgs.mctrl_pkg.all;
entity sharpmz is
port(
-------------------- Clock Input ----------------------------
CLKMASTER : in std_logic; -- Master Clock(50MHz)
CLKSYS : out std_logic; -- System clock.
CLKVID : out std_logic; -- Pixel base clock of video.
-------------------- Reset ----------------------------
COLD_RESET : in std_logic;
WARM_RESET : in std_logic;
-------------------- main_leds ----------------------------
MAIN_LEDS : out std_logic_vector(7 downto 0); -- main_leds Green[7:0]
-------------------- PS2 ----------------------------
PS2_KEY : in std_logic_vector(10 downto 0); -- PS2 Key data.
-------------------- VGA ----------------------------
VGA_HB_O : out std_logic; -- VGA Horizontal Blank
VGA_VB_O : out std_logic; -- VGA Vertical Blank
VGA_HS_O : out std_logic; -- VGA H_SYNC
VGA_VS_O : out std_logic; -- VGA V_SYNC
VGA_R_O : out std_logic_vector(7 downto 0); -- VGA Red[3:0], [7:4] = 0
VGA_G_O : out std_logic_vector(7 downto 0); -- VGA Green[3:0]
VGA_B_O : out std_logic_vector(7 downto 0); -- VGA Blue[3:0]
-------------------- AUDIO ------------------------------
AUDIO_L_O : out std_logic;
AUDIO_R_O : out std_logic;
-------------------- HPS Interface ------------------------------
IOCTL_DOWNLOAD : in std_logic; -- Downloading to FPGA.
IOCTL_UPLOAD : in std_logic; -- Uploading from FPGA.
IOCTL_CLK : in std_logic; -- I/O Clock.
IOCTL_WR : in std_logic; -- Write Enable to FPGA.
IOCTL_RD : in std_logic; -- Read Enable from FPGA.
IOCTL_ADDR : in std_logic_vector(24 downto 0); -- Address in FPGA to write into.
IOCTL_DOUT : in std_logic_vector(31 downto 0); -- Data to be written into FPGA.
IOCTL_DIN : out std_logic_vector(31 downto 0) -- Data to be read into HPS.
);
end sharpmz;
architecture rtl of sharpmz is
-- Parent signals brought out onto wires.
--
signal MZ_PS2_KEY : std_logic_vector(10 downto 0);
--
-- Keyboard
--
signal MZ_KEYB_SCAN : std_logic_vector(3 downto 0);
signal MZ_KEYB_DATA : std_logic_vector(7 downto 0);
signal MZ_KEYB_STALL : std_logic;
signal MZ_KEYB_BREAKDETECT : std_logic;
--
-- Master Control signals and configuration.
--
signal MZ_SYSTEM_RESET : std_logic;
signal MZ_MEMWR : std_logic;
--
-- Signal BUS's
--
signal CLKBUS : std_logic_vector(CLKBUS_WIDTH);
signal CONFIG : std_logic_vector(CONFIG_WIDTH);
signal DEBUG : std_logic_vector(DEBUG_WIDTH);
signal MZ_CMT_BUS_OUT : std_logic_vector(CMT_BUS_OUT_WIDTH);
--
-- HPS Control.
--
signal MZ_IOCTL_DOWNLOAD : std_logic;
signal MZ_IOCTL_UPLOAD : std_logic;
signal MZ_IOCTL_CLK : std_logic;
signal MZ_IOCTL_WR : std_logic;
signal MZ_IOCTL_RD : std_logic;
signal MZ_IOCTL_ADDR : std_logic_vector(24 downto 0);
signal MZ_IOCTL_DOUT : std_logic_vector(31 downto 0);
signal MZ_IOCTL_DIN_SYSROM : std_logic_vector(7 downto 0);
signal MZ_IOCTL_DIN_SYSRAM : std_logic_vector(7 downto 0);
signal MZ_IOCTL_DIN_VIDEO : std_logic_vector(31 downto 0);
signal MZ_IOCTL_DIN_MZ80C : std_logic_vector(31 downto 0);
signal MZ_IOCTL_DIN_MZ80B : std_logic_vector(31 downto 0);
signal MZ_IOCTL_DIN_MCTRL : std_logic_vector(31 downto 0);
signal MZ_IOCTL_DIN_CMT : std_logic_vector(31 downto 0);
signal MZ_IOCTL_DIN_KEY : std_logic_vector(31 downto 0);
signal MZ_IOCTL_WENROM : std_logic;
signal MZ_IOCTL_WENRAM : std_logic;
signal MZ_IOCTL_RENROM : std_logic;
signal MZ_IOCTL_RENRAM : std_logic;
--
-- T80 for MZ80C
--
signal MZ80C_BUSRQ_n : std_logic;
signal MZ80C_MWR_n : std_logic;
signal MZ80C_MRD_n : std_logic;
signal MZ80C_IWR_n : std_logic;
signal MZ80C_WAIT_n : std_logic;
signal MZ80C_INT_n : std_logic;
signal MZ80C_DI : std_logic_vector(7 downto 0);
signal MZ80C_NMI_n : std_logic;
--
-- Tape Control
--
signal MZ80C_CMT_BUS_IN : std_logic_vector(CMT_BUS_IN_WIDTH);
--
-- Keyboard
--
signal MZ80C_KEYB_SCAN : std_logic_vector(3 downto 0);
signal MZ80C_KEYB_STALL : std_logic;
--
-- Video
--
signal MZ_R : std_logic_vector(7 downto 0);
signal MZ_B : std_logic_vector(7 downto 0);
signal MZ_G : std_logic_vector(7 downto 0);
signal MZ_VGATE_n : std_logic;
signal MZ_DISPLAY_INVERT_n : std_logic;
signal MZ_DISPLAY_CHAR80 : std_logic;
signal MZ_HSYNC_n : std_logic;
signal MZ_VSYNC_n : std_logic;
signal MZ_HBLANK : std_logic;
signal MZ_VBLANK : std_logic;
--
-- Selects for MZ80C.
--
signal MZ80C_CS_ROM_n : std_logic;
signal MZ80C_CS_RAM_n : std_logic;
signal MZ80C_CS_VRAM_n : std_logic;
signal MZ80C_CS_MEM_G_n : std_logic;
signal MZ80C_CS_GRAM_n : std_logic;
signal MZ80C_CS_GRAM_80B_n : std_logic;
signal MZ80C_CS_IO_GFB_n : std_logic;
--
-- Audio for MZ80C
--
signal MZ80C_AUDIO_L : std_logic;
signal MZ80C_AUDIO_R : std_logic;
--
-- Video signals for MZ80C
--
signal MZ80C_VGATE_n : std_logic;
--
-- Debug for MZ80C
--
signal MZ80C_DEBUG_LEDS : std_logic_vector(111 downto 0);
--
-- T80 for MZ80B
--
signal MZ80B_BUSRQ_n : std_logic;
signal MZ80B_MWR_n : std_logic;
signal MZ80B_MRD_n : std_logic;
signal MZ80B_IWR_n : std_logic;
signal MZ80B_WAIT_n : std_logic;
signal MZ80B_INT_n : std_logic;
signal MZ80B_DI : std_logic_vector(7 downto 0);
signal MZ80B_NMI_n : std_logic;
--
-- Selects for MZ80B.
--
signal MZ80B_CS_ROM_n : std_logic;
signal MZ80B_CS_RAM_n : std_logic;
signal MZ80B_CS_VRAM_n : std_logic;
signal MZ80B_CS_GRAM_n : std_logic;
signal MZ80B_CS_IO_GFB_n : std_logic;
signal MZ80B_CS_IO_G_n : std_logic;
--
-- Audio for MZ80B
--
signal MZ80B_AUDIO_L : std_logic;
signal MZ80B_AUDIO_R : std_logic;
--
-- Video signals for MZ80B
--
signal MZ80B_VGATE_n : std_logic;
--
-- Tape Control
--
signal MZ80B_CMT_BUS_IN : std_logic_vector(CMT_BUS_IN_WIDTH);
--
-- Keyboard
--
signal MZ80B_KEYB_SCAN : std_logic_vector(3 downto 0);
signal MZ80B_KEYB_STALL : std_logic;
--
-- Debug for MZ80B
--
signal MZ80B_DEBUG_LEDS : std_logic_vector(111 downto 0);
--
-- T80
--
signal T80_RST_n : std_logic;
signal T80_MREQ_n : std_logic;
signal T80_BUSRQ_n : std_logic;
signal T80_IORQ_n : std_logic;
signal T80_WR_n : std_logic;
signal T80_RD_n : std_logic;
signal T80_WAIT_n : std_logic;
signal T80_M1_n : std_logic;
signal T80_RFSH_n : std_logic;
signal T80_A16 : std_logic_vector(15 downto 0);
signal T80_INT_n : std_logic;
signal T80_DO : std_logic_vector(7 downto 0);
signal T80_DI : std_logic_vector(7 downto 0);
signal T80_BUSAK_n : std_logic;
signal T80_NMI_n : std_logic;
signal T80_HALT_n : std_logic;
--
-- Decodes, control, misc
--
signal WENSYSRAM : std_logic;
--
-- Monitor ROM
--
signal SYSROM_DO : std_logic_vector(7 downto 0);
signal MZ_CS_ROM_n : std_logic;
signal MROM_BANK : std_logic_vector(5 downto 0);
--
-- Static RAM
--
signal SYSRAM_DO : std_logic_vector(7 downto 0);
signal MZ_CS_RAM_n : std_logic;
signal MZ_SYSMEM_A16 : std_logic_vector(15 downto 0);
signal MZ_SWP_MEM_BANK_n : std_logic;
--
-- Graphics RAM control signals.
--
signal VRAM_DO : std_logic_vector(7 downto 0);
signal MZ_CS_VRAM_n : std_logic;
signal MZ_CS_MEM_G_n : std_logic;
signal MZ_CS_GRAM_n : std_logic;
signal MZ_CS_GRAM_80B_n : std_logic;
signal MZ_CS_IO_GFB_n : std_logic;
signal MZ_CS_IO_G_n : std_logic;
signal VIDEO_WAIT_n : std_logic;
--
-- Tape Control
--
signal MZ_CMT_BUS_IN : std_logic_vector(CMT_BUS_IN_WIDTH);
signal MZ_CMT_DEBUG_LEDS : std_logic_vector(31 downto 0);
--
-- Debug and internal process signals.
--
signal debug_counter : integer range 0 to 13 := 0;
signal flip_counter : integer range 0 to 10000000 := 0;
signal block_flip : integer range 0 to 800000 := 0;
signal bank_flip : integer range 0 to 10000000 := 0;
--
-- Components
--
component clkgen
Port (
RST : in std_logic; -- Reset
-- Clocks
CKBASE : in std_logic; -- Base system main clock.
CLKBUS : out std_logic_vector(CLKBUS_WIDTH); -- Clock signals created by this module.
-- Different operations modes.
CONFIG : in std_logic_vector(CONFIG_WIDTH);
-- Debug modes.
DEBUG : in std_logic_vector(DEBUG_WIDTH)
);
end component;
component T80se
generic (
Mode : integer := 0; -- 0 => Z80, 1 => Fast Z80, 2 => 8080, 3 => GB
T2Write : integer := 1; -- 0 => WR_n active in T3, /=0 => WR_n active in T2
IOWait : integer := 1 -- 0 => Single cycle I/O, 1 => Std I/O cycle
);
Port (
RESET_n : in std_logic;
CLK_n : in std_logic; -- NB. Clock is high active.
CLKEN : in std_logic;
WAIT_n : in std_logic;
INT_n : in std_logic;
NMI_n : in std_logic;
BUSRQ_n : in std_logic;
M1_n : out std_logic;
MREQ_n : out std_logic;
IORQ_n : out std_logic;
RD_n : out std_logic;
WR_n : out std_logic;
RFSH_n : out std_logic;
HALT_n : out std_logic;
BUSAK_n : out std_logic;
A : out std_logic_vector(15 downto 0);
DI : in std_logic_vector(7 downto 0);
DO : out std_logic_vector(7 downto 0)
);
end component;
component dpram
generic (
init_file : string;
widthad_a : natural;
width_a : natural;
widthad_b : natural;
width_b : natural;
outdata_reg_a : string := "UNREGISTERED";
outdata_reg_b : string := "UNREGISTERED"
);
Port (
clock_a : in std_logic := '1';
clocken_a : in std_logic := '1';
address_a : in std_logic_vector (widthad_a-1 downto 0);
data_a : in std_logic_vector (width_a-1 downto 0);
wren_a : in std_logic := '0';
q_a : out std_logic_vector (width_a-1 downto 0);
clock_b : in std_logic;
clocken_b : in std_logic := '1';
address_b : in std_logic_vector (widthad_b-1 downto 0);
data_b : in std_logic_vector (width_b-1 downto 0);
wren_b : in std_logic := '0';
q_b : out std_logic_vector (width_b-1 downto 0)
);
end component;
component mctrl
Port (
-- Clock signals used by this module.
CLKBUS : in std_logic_vector(CLKBUS_WIDTH);
-- Reset's
COLD_RESET : in std_logic;
WARM_RESET : in std_logic;
SYSTEM_RESET : out std_logic;
-- HPS Interface
IOCTL_CLK : in std_logic; -- HPS I/O Clock
IOCTL_WR : in std_logic; -- HPS Write Enable to FPGA.
IOCTL_RD : in std_logic; -- HPS Read Enable from FPGA.
IOCTL_ADDR : in std_logic_vector(24 downto 0); -- HPS Address in FPGA to write into.
IOCTL_DOUT : in std_logic_vector(31 downto 0); -- HPS Data to be written into FPGA.
IOCTL_DIN : out std_logic_vector(31 downto 0); -- HPS Data to be read into HPS.
-- Different operations modes.
CONFIG : out std_logic_vector(CONFIG_WIDTH);
-- Cassette magnetic tape signals.
CMT_BUS_OUT : in std_logic_vector(CMT_BUS_OUT_WIDTH);
CMT_BUS_IN : in std_logic_vector(CMT_BUS_IN_WIDTH);
-- MZ80B series can dynamically change the video frequency to attain 40/80 character display.
CONFIG_CHAR80 : in std_logic;
-- Debug modes.
DEBUG : out std_logic_vector(DEBUG_WIDTH)
);
end component;
component video is
Port (
RST_n : in std_logic; -- Reset
-- Different operations modes.
CONFIG : in std_logic_vector(CONFIG_WIDTH);
-- Clocks
CLKBUS : in std_logic_vector(CLKBUS_WIDTH); -- Clock signals created by clkgen module.
-- CPU Signals
T80_A : in std_logic_vector(13 downto 0); -- CPU Address Bus
T80_RD_n : in std_logic; -- CPU Read Signal
T80_WR_n : in std_logic; -- CPU Write Signal
T80_MREQ_n : in std_logic; -- CPU Memory Request
T80_BUSACK_n : in std_logic; -- CPU Bus Acknowledge
T80_WAIT_n : out std_logic; -- CPU Wait Request
T80_DI : in std_logic_vector(7 downto 0); -- CPU Data Bus in
T80_DO : out std_logic_vector(7 downto 0); -- CPU Data Bus out
-- Selects.
CS_VRAM_n : in std_logic; -- VRAM Select
CS_MEM_G_n : in std_logic; -- Peripherals Select
CS_GRAM_n : in std_logic; -- Colour GRAM Select
CS_GRAM_80B_n : in std_logic; -- MZ80B GRAM Select
CS_IO_GFB_n : in std_logic; -- Graphics FB IO Select range
CS_IO_G_n : in std_logic; -- Graphics Options IO Select range
-- Video Signals
VGATE_n : in std_logic; -- Video Output Control
INVERSE_n : in std_logic; -- Invert video display.
CONFIG_CHAR80 : in std_logic; -- 40 Char = 0, 80 Char = 1 select.
HBLANK : out std_logic; -- Horizontal Blanking
VBLANK : out std_logic; -- Vertical Blanking
HSYNC_n : out std_logic; -- Horizontal Sync
VSYNC_n : out std_logic; -- Vertical Sync
ROUT : out std_logic_vector(7 downto 0); -- Red Output
GOUT : out std_logic_vector(7 downto 0); -- Green Output
BOUT : out std_logic_vector(7 downto 0); -- Green Output
-- HPS Interface
IOCTL_DOWNLOAD : in std_logic; -- HPS Downloading to FPGA.
IOCTL_UPLOAD : in std_logic; -- HPS Uploading from FPGA.
IOCTL_CLK : in std_logic; -- HPS I/O Clock.
IOCTL_WR : in std_logic; -- HPS Write Enable to FPGA.
IOCTL_RD : in std_logic; -- HPS Read Enable to FPGA.
IOCTL_ADDR : in std_logic_vector(24 downto 0); -- HPS Address in FPGA to write into.
IOCTL_DOUT : in std_logic_vector(31 downto 0); -- HPS Data to be written into FPGA.
IOCTL_DIN : out std_logic_vector(31 downto 0) -- HPS Data to be read into HPS.
);
end component;
component keymatrix
Port (
RST_n : in std_logic;
-- i8255
PA : in std_logic_vector(3 downto 0);
PB : out std_logic_vector(7 downto 0);
STALL : in std_logic;
BREAKDETECT : out std_logic;
-- PS/2 Keyboard Data
PS2_KEY : in std_logic_vector(10 downto 0); -- PS2 Key data.
-- Different operations modes.
CONFIG : in std_logic_vector(CONFIG_WIDTH);
-- Clock signals created by this module.
CLKBUS : in std_logic_vector(CLKBUS_WIDTH);
-- HPS Interface
IOCTL_DOWNLOAD : in std_logic; -- HPS Downloading to FPGA.
IOCTL_UPLOAD : in std_logic; -- HPS Uploading from FPGA.
IOCTL_CLK : in std_logic; -- HPS I/O Clock.
IOCTL_WR : in std_logic; -- HPS Write Enable to FPGA.
IOCTL_RD : in std_logic; -- HPS Read Enable to FPGA.
IOCTL_ADDR : in std_logic_vector(24 downto 0); -- HPS Address in FPGA to write into.
IOCTL_DOUT : in std_logic_vector(31 downto 0); -- HPS Data to be written into FPGA.
IOCTL_DIN : out std_logic_vector(31 downto 0) -- HPS Data to be read into HPS.
);
end component;
component cmt
Port (
-- HPS Bus
RST : in std_logic;
-- Clock signals created by this module.
CLKBUS : in std_logic_vector(CLKBUS_WIDTH);
-- Different operations modes.
CONFIG : in std_logic_vector(CONFIG_WIDTH);
-- Cassette magnetic tape signals.
CMT_BUS_OUT : out std_logic_vector(CMT_BUS_OUT_WIDTH);
CMT_BUS_IN : in std_logic_vector(CMT_BUS_IN_WIDTH);
-- HPS Interface
IOCTL_DOWNLOAD : in std_logic; -- HPS Downloading to FPGA.
IOCTL_UPLOAD : in std_logic; -- HPS Uploading from FPGA.
IOCTL_CLK : in std_logic; -- HPS I/O Clock.
IOCTL_WR : in std_logic; -- HPS Write Enable to FPGA.
IOCTL_RD : in std_logic; -- HPS Read Enable from FPGA.
IOCTL_ADDR : in std_logic_vector(24 downto 0); -- HPS Address in FPGA to write into.
IOCTL_DOUT : in std_logic_vector(31 downto 0); -- HPS Data to be written into FPGA.
IOCTL_DIN : out std_logic_vector(31 downto 0); -- HPS Data to be read into HPS.
-- Debug Status Leds
DEBUG_STATUS_LEDS : out std_logic_vector(31 downto 0) -- 24 leds to display cmt internal status.
);
end component;
component mz80c
PORT (
-- Clocks
CLKBUS : in std_logic_vector(CLKBUS_WIDTH); -- Clock signals created by this module.
-- Resets.
COLD_RESET : in std_logic;
SYSTEM_RESET : in std_logic;
-- Z80 CPU
T80_RST_n : in std_logic;
T80_WAIT_n : out std_logic;
T80_INT_n : out std_logic;
T80_NMI_n : out std_logic;
T80_BUSRQ_n : out std_logic;
T80_M1_n : in std_logic;
T80_MREQ_n : in std_logic;
T80_IORQ_n : in std_logic;
T80_RD_n : in std_logic;
T80_WR_n : in std_logic;
T80_RFSH_n : in std_logic;
T80_HALT_n : in std_logic;
T80_BUSAK_n : in std_logic;
T80_A16 : in std_logic_vector(15 downto 0);
T80_DI : out std_logic_vector(7 downto 0);
T80_DO : in std_logic_vector(7 downto 0);
-- Chip selects to common resources.
CS_ROM_n : out std_logic;
CS_RAM_n : out std_logic;
CS_VRAM_n : out std_logic; -- VRAM Select
CS_MEM_G_n : out std_logic; -- Memory mapped Peripherals Select
CS_GRAM_n : out std_logic; -- Colour GRAM Select
CS_IO_GFB_n : out std_logic; -- Graphics FB IO Select range
-- Audio.
AUDIO_L : out std_logic;
AUDIO_R : out std_logic;
-- Different operations modes.
CONFIG : in std_logic_vector(CONFIG_WIDTH);
-- I/O -- I/O down to the core.
KEYB_SCAN : out std_logic_vector(3 downto 0); -- Keyboard scan lines out.
KEYB_DATA : in std_logic_vector(7 downto 0); -- Keyboard scan data in.
KEYB_STALL : out std_logic; -- Keyboard Stall out.
-- Cassette magnetic tape signals.
CMT_BUS_OUT : in std_logic_vector(CMT_BUS_OUT_WIDTH);
CMT_BUS_IN : out std_logic_vector(CMT_BUS_IN_WIDTH);
-- Video
VGATE_n : out std_logic;
HBLANK : in std_logic; -- Horizontal Blanking Signal
VBLANK : in std_logic; -- Vertical Blanking Signal
-- HPS Interface
IOCTL_DOWNLOAD : in std_logic; -- HPS Downloading to FPGA.
IOCTL_UPLOAD : in std_logic; -- HPS Uploading from FPGA.
IOCTL_CLK : in std_logic; -- HPS I/O Clock
IOCTL_WR : in std_logic; -- HPS Write Enable to FPGA.
IOCTL_RD : in std_logic; -- HPS Read Enable from FPGA.
IOCTL_ADDR : in std_logic_vector(24 downto 0); -- HPS Address in FPGA to write into.
IOCTL_DOUT : in std_logic_vector(31 downto 0); -- HPS Data to be written into FPGA.
IOCTL_DIN : out std_logic_vector(31 downto 0); -- HPS Data to be read into HPS.
-- Debug Status Leds
DEBUG_STATUS_LEDS : out std_logic_vector(111 downto 0) -- 112 leds to display status.
);
end component;
component mz80b
PORT (
-- Clocks
CLKBUS : in std_logic_vector(CLKBUS_WIDTH); -- Clock signals created by this module.
-- Resets.
COLD_RESET : in std_logic;
SYSTEM_RESET : in std_logic;
-- Z80 CPU
T80_RST_n : in std_logic;
T80_WAIT_n : out std_logic;
T80_INT_n : out std_logic;
T80_NMI_n : out std_logic;
T80_BUSRQ_n : out std_logic;
T80_M1_n : in std_logic;
T80_MREQ_n : in std_logic;
T80_IORQ_n : in std_logic;
T80_RD_n : in std_logic;
T80_WR_n : in std_logic;
T80_RFSH_n : in std_logic;
T80_HALT_n : in std_logic;
T80_BUSAK_n : in std_logic;
T80_A16 : in std_logic_vector(15 downto 0);
T80_DI : out std_logic_vector(7 downto 0);
T80_DO : in std_logic_vector(7 downto 0);
-- Chip selects to common resources.
CS_ROM_n : out std_logic;
CS_RAM_n : out std_logic;
CS_VRAM_n : out std_logic; -- VRAM Select
CS_GRAM_n : out std_logic; -- Colour GRAM Select
CS_GRAM_80B_n : out std_logic; -- MZ80B GRAM Select
CS_IO_GFB_n : out std_logic; -- Graphics FB IO Select range
CS_IO_G_n : out std_logic; -- Graphics Options IO Select range
CS_SWP_MEMBANK_n : out std_logic; -- Move lower 32K into upper block.
-- Audio.
AUDIO_L : out std_logic;
AUDIO_R : out std_logic;
-- Different operations modes.
CONFIG : in std_logic_vector(CONFIG_WIDTH);
-- I/O -- I/O down to the core.
KEYB_SCAN : out std_logic_vector(3 downto 0); -- Keyboard scan lines out.
KEYB_DATA : in std_logic_vector(7 downto 0); -- Keyboard scan data in.
KEYB_STALL : out std_logic; -- Keyboard Stall out.
KEYB_BREAKDETECT : in std_logic; -- Keyboard break detect.
-- Cassette magnetic tape signals.
CMT_BUS_OUT : in std_logic_vector(CMT_BUS_OUT_WIDTH);
CMT_BUS_IN : out std_logic_vector(CMT_BUS_IN_WIDTH);
-- Video
VGATE_n : out std_logic;
INVERSE_n : out std_logic; -- Invert video display.
CONFIG_CHAR80 : out std_logic; -- 40 Char = 0, 80 Char = 1 select.
HBLANK : in std_logic; -- Horizontal Blanking Signal
VBLANK : in std_logic; -- Vertical Blanking Signal
-- HPS Interface
IOCTL_DOWNLOAD : in std_logic; -- HPS Downloading to FPGA.
IOCTL_UPLOAD : in std_logic; -- HPS Uploading from FPGA.
IOCTL_CLK : in std_logic; -- HPS I/O Clock
IOCTL_WR : in std_logic; -- HPS Write Enable to FPGA.
IOCTL_RD : in std_logic; -- HPS Read Enable from FPGA.
IOCTL_ADDR : in std_logic_vector(24 downto 0); -- HPS Address in FPGA to write into.
IOCTL_DOUT : in std_logic_vector(31 downto 0); -- HPS Data to be written into FPGA.
IOCTL_DIN : out std_logic_vector(31 downto 0); -- HPS Data to be read into HPS.
-- Debug Status Leds
DEBUG_STATUS_LEDS : out std_logic_vector(111 downto 0) -- 112 leds to display status.
);
end component;
begin
--
-- Instantiation
--
CLKGEN0 : clkgen port map (
RST => cold_reset, -- Reset
-- Clocks
CKBASE => CLKMASTER, -- Input clocks from top level.
CLKBUS => CLKBUS, -- Clock signals created by this module.
-- Different operations modes.
CONFIG => CONFIG,
-- Debug modes.
DEBUG => DEBUG
);
CPU0 : T80se
generic map (
Mode => 0, -- 0 => Z80, 1 => Fast Z80, 2 => 8080, 3 => GB
T2Write => 1, -- 0 => WR_n active in T3, /=0 => WR_n active in T2
IOWait => 1 -- 0 => Single cycle I/O, 1 => Std I/O cycle
)
port map (
RESET_n => T80_RST_n, -- Reset signal.
CLK_n => CLKBUS(CKMASTER), -- T80se uses positive level clock.
CLKEN => CLKBUS(CKENCPU), -- Pulse the master clock at the required CPU frequency.
WAIT_n => T80_WAIT_n, -- WAIT_n signal into the CPU to prolong a memory cycle.
INT_n => T80_INT_n, -- INT_n signal for maskable interrupts.
NMI_n => T80_NMI_n, -- NMI_n non maskable interrupt input.
BUSRQ_n => T80_BUSRQ_n, -- BUSRQ_n signal to request CPU go into tristate and relinquish bus.
M1_n => T80_M1_n, -- M1_n Machine Cycle 1 signal. M1 and MREQ active = opcode fetch, M1 and IORQ active = interrupt, vector can be read from D0-D7.
MREQ_n => T80_MREQ_n, -- MREQ_n signal indicates that the address bus holds a valid address for reading or writing memory.
IORQ_n => T80_IORQ_n, -- IORQ_n signal indicates that the address bus (A0-A7) holds a valid address for reading or writing and I/O device.
RD_n => T80_RD_n, -- RD_n signal indicates that data is ready to be read from a memory or I/O device to the CPU.
WR_n => T80_WR_n, -- WR_n signal indicates that data is going to be written from the CPU data bus to a memory or I/O device.
RFSH_n => T80_RFSH_n, -- RFSH_n signal to indicate dynamic memory refresh can take place.
HALT_n => T80_HALT_n, -- HALT_n signal indicates that the CPU has executed a "HALT" instruction.
BUSAK_n => T80_BUSAK_n, -- BUSAK_n signal indicates that the CPU address bus, data bus, and control signals have entered their HI-Z states, and that the external circuitry can now control these lines.
A => T80_A16, -- 16 bit address lines.
DI => T80_DI, -- 8 bit data input bus.
DO => T80_DO -- 8 bit data output bus.
);
-- MZ80 System RAM
--
SYSRAM : dpram
generic map (
init_file => "./software/mif/combined_mainmemory.mif",
widthad_a => 16,
width_a => 8,
widthad_b => 16,
width_b => 8,
outdata_reg_a => "UNREGISTERED",
outdata_reg_b => "UNREGISTERED"
)
port map (
clock_a => CLKBUS(CKMASTER), --CLKBUS(CKMEM),
clocken_a => CLKBUS(CKENCPU), --'1',
address_a => MZ_SYSMEM_A16,
data_a => T80_DO,
wren_a => WENSYSRAM, -- Pulse width controlled according to Master Clock.
q_a => SYSRAM_DO,
clock_b => MZ_IOCTL_CLK,
clocken_b => '1',
address_b => MZ_IOCTL_ADDR(15 downto 0),
data_b => MZ_IOCTL_DOUT(7 downto 0),
wren_b => MZ_IOCTL_WENRAM,
q_b => MZ_IOCTL_DIN_SYSRAM
);
-- MZ Monitor ROM
-- 0 = 80K MROM 4KBytes -> 0000:0fff 0000 bytes padding
-- 1 = 80x25 80K MROM 4KBytes -> 1000:1fff 0000 bytes padding
-- 2 = 80C MROM 4KBytes -> 2000:2fff 0000 bytes padding
-- 3 = 80x25 80C MROM 4KBytes -> 3000:3fff 0000 bytes padding
-- 4 = 1200 MROM 4KBytes -> 4000:4fff 0000 bytes padding
-- 5 = 80x25 1200 MROM 4KBytes -> 5000:5fff 0000 bytes padding
-- 6 = 80A MROM 4KBytes -> 6000:6fff 0000 bytes padding
-- 7 = 80x25 80A MROM 4KBytes -> 7000:7fff 0000 bytes padding
-- 8 = 700 MROM 4KBytes -> 8000:8fff 0000 bytes padding
-- 9 = 80x25 700 MROM 4KBytes -> 9000:9fff 0000 bytes padding
-- 10 = 80B MROM 2KBytes -> a000:afff 0800 bytes padding
-- 11 = 80x25 80B MROM 2KBytes -> b000:bfff 0800 bytes padding
--
--SYSROM : dprom
SYSROM : dpram
generic map (
init_file => "./software/mif/combined_mrom.mif",
widthad_a => 17,
width_a => 8,
widthad_b => 17,
width_b => 8,
outdata_reg_a => "UNREGISTERED",
outdata_reg_b => "UNREGISTERED"
)
port map (
clock_a => CLKBUS(CKMASTER), -- CLKBUS(CKMEM),
clocken_a => CLKBUS(CKENCPU), --'1',
address_a => MROM_BANK & T80_A16(10 downto 0),
data_a => T80_DO,
wren_a => '0', -- Block writes from Z80 to ROM.
q_a => SYSROM_DO,
clock_b => MZ_IOCTL_CLK,
clocken_b => '1',
address_b => MZ_IOCTL_ADDR(16 downto 0),
data_b => MZ_IOCTL_DOUT(7 downto 0),
wren_b => MZ_IOCTL_WENROM,
q_b => MZ_IOCTL_DIN_SYSROM
);
CTRL0 : mctrl
port map (
-- Clock
CLKBUS => CLKBUS,
-- Reset's
COLD_RESET => cold_reset,
WARM_RESET => warm_reset,
SYSTEM_RESET => MZ_SYSTEM_RESET,
-- HPS Interface
IOCTL_CLK => MZ_IOCTL_CLK, -- HPS I/O Clock
IOCTL_WR => MZ_IOCTL_WR,
IOCTL_RD => MZ_IOCTL_RD,
IOCTL_ADDR => MZ_IOCTL_ADDR,
IOCTL_DOUT => MZ_IOCTL_DOUT,
IOCTL_DIN => MZ_IOCTL_DIN_MCTRL,
-- Different operations modes.
CONFIG => CONFIG,
-- Cassette magnetic tape signals.
CMT_BUS_OUT => MZ_CMT_BUS_OUT,
CMT_BUS_IN => MZ_CMT_BUS_IN,
-- MZ80B series can dynamically change the video frequency to attain 40/80 character display.
CONFIG_CHAR80 => MZ_DISPLAY_CHAR80,
-- Debug modes.
DEBUG => DEBUG
);
VIDEO0 : video
port map (
RST_n => T80_RST_n, -- Reset
-- Different operations modes.
CONFIG => CONFIG,
-- Clocks
CLKBUS => CLKBUS, -- Clock signals created by clkgen module.
-- CPU Signals
T80_A => T80_A16(13 downto 0), -- CPU Address Bus
T80_RD_n => T80_RD_n, -- CPU Read Signal
T80_WR_n => T80_WR_n, -- CPU Write Signal
T80_MREQ_n => T80_MREQ_n, -- CPU Memory Request
T80_BUSACK_n => T80_BUSAK_n, -- CPU Bus Acknowledge
T80_WAIT_n => VIDEO_WAIT_n, -- Wait Request to CPU from Video circuitry.
T80_DI => T80_DO, -- CPU Data Bus(in)
T80_DO => VRAM_DO, -- CPU Data Bus(out)
-- Selects.
CS_VRAM_n => MZ_CS_VRAM_n, -- VRAM Select
CS_MEM_G_n => MZ_CS_MEM_G_n, -- Peripherals Select
CS_GRAM_n => MZ_CS_GRAM_n, -- Colour GRAM Select
CS_GRAM_80B_n => MZ_CS_GRAM_80B_n, -- MZ80B GRAM Select
CS_IO_GFB_n => MZ_CS_IO_GFB_n, -- Graphics FB IO Select range
CS_IO_G_n => MZ_CS_IO_G_n, -- Graphics Options IO Select range
-- Video Signals
VGATE_n => MZ_VGATE_n, -- Video Output Control
INVERSE_n => MZ_DISPLAY_INVERT_n, -- Invert video output.
CONFIG_CHAR80 => MZ_DISPLAY_CHAR80, -- 40 Char = 0, 80 Char = 1 select.
HBLANK => MZ_HBLANK, -- Horizontal Blanking
VBLANK => MZ_VBLANK, -- Vertical Blanking
HSYNC_n => MZ_HSYNC_n, -- Horizontal Sync
VSYNC_n => MZ_VSYNC_n, -- Vertical Sync
ROUT => MZ_R, -- Red Output
GOUT => MZ_G, -- Green Output
BOUT => MZ_B, -- Blue Output
-- HPS Interface
IOCTL_DOWNLOAD => MZ_IOCTL_DOWNLOAD,
IOCTL_UPLOAD => MZ_IOCTL_UPLOAD,
IOCTL_CLK => MZ_IOCTL_CLK, -- HPS I/O Clock.
IOCTL_WR => MZ_IOCTL_WR, -- HPS Write Enable to FPGA.
IOCTL_RD => MZ_IOCTL_RD, -- HPS Read Enable to FPGA.
IOCTL_ADDR => MZ_IOCTL_ADDR, -- HPS Address in FPGA to write into.
IOCTL_DOUT => MZ_IOCTL_DOUT, -- HPS Data to be written into FPGA.
IOCTL_DIN => MZ_IOCTL_DIN_VIDEO -- HPS Data to be sent to HPS.
);
TAPE0 : cmt
port map (
RST => MZ_SYSTEM_RESET,
-- Clock signals needed by this module.
CLKBUS => CLKBUS,
-- Different operations modes.
CONFIG => CONFIG,
-- Cassette magnetic tape signals.
CMT_BUS_OUT => MZ_CMT_BUS_OUT, -- Output is fed from CMT into MCTRL and MZ..
CMT_BUS_IN => MZ_CMT_BUS_IN, -- Input is fed from MCTRL/MZ into CMT.
-- HPS Interface
IOCTL_DOWNLOAD => MZ_IOCTL_DOWNLOAD, -- HPS Downloading to FPGA.
IOCTL_UPLOAD => MZ_IOCTL_UPLOAD, -- HPS Uploading from FPGA.
IOCTL_CLK => MZ_IOCTL_CLK, -- HPS I/O Clock.
IOCTL_WR => MZ_IOCTL_WR, -- HPS Write Enable to FPGA.
IOCTL_RD => MZ_IOCTL_RD, -- HPS Read Enable from FPGA.
IOCTL_ADDR => MZ_IOCTL_ADDR, -- HPS Address in FPGA to write into.
IOCTL_DOUT => MZ_IOCTL_DOUT, -- HPS Data to be written into FPGA.
IOCTL_DIN => MZ_IOCTL_DIN_CMT, -- HPS Data to be sent to HPS.
-- Debug Status Leds
DEBUG_STATUS_LEDS=> MZ_CMT_DEBUG_LEDS(31 downto 0) -- 24 leds to display cmt internal status.
);
KEYS : keymatrix
port map (
RST_n => T80_RST_n,
-- i8255
PA => MZ_KEYB_SCAN,
PB => MZ_KEYB_DATA,
STALL => MZ_KEYB_STALL,
BREAKDETECT => MZ_KEYB_BREAKDETECT,
-- PS/2 Keyboard Data
PS2_KEY => MZ_PS2_KEY, -- PS2 Key data.
-- Different operations modes.
CONFIG => CONFIG,
-- Clock signals created by this module.
CLKBUS => CLKBUS,
-- HPS Interface
IOCTL_DOWNLOAD => MZ_IOCTL_DOWNLOAD, -- HPS Downloading to FPGA.
IOCTL_UPLOAD => MZ_IOCTL_UPLOAD, -- HPS Uploading from FPGA.
IOCTL_CLK => MZ_IOCTL_CLK, -- HPS I/O Clock.
IOCTL_WR => MZ_IOCTL_WR, -- HPS Write Enable to FPGA.
IOCTL_RD => MZ_IOCTL_RD, -- HPS Read Enable from FPGA.
IOCTL_ADDR => MZ_IOCTL_ADDR, -- HPS Address in FPGA to write into.
IOCTL_DOUT => MZ_IOCTL_DOUT, -- HPS Data to be written into FPGA.
IOCTL_DIN => MZ_IOCTL_DIN_KEY -- HPS Data to be sent to HPS.
);
MZ80HW : mz80c
port map (
-- Clocks
CLKBUS => CLKBUS, -- Clock signals created by this module.
-- Resets.
COLD_RESET => cold_reset, -- Cold reset, one time reset on power up.
SYSTEM_RESET => MZ_SYSTEM_RESET, -- Reset generated by system based on Cold/Warm or trigger.
-- Z80 CPU
T80_RST_n => T80_RST_n,
T80_WAIT_n => MZ80C_WAIT_n,
T80_INT_n => MZ80C_INT_n,
T80_NMI_n => MZ80C_NMI_n,
T80_BUSRQ_n => MZ80C_BUSRQ_n,
T80_M1_n => T80_M1_n,
T80_MREQ_n => T80_MREQ_n,
T80_IORQ_n => T80_IORQ_n,
T80_RD_n => T80_RD_n,
T80_WR_n => T80_WR_n,
T80_RFSH_n => T80_RFSH_n, --RFSH_n
T80_HALT_n => T80_HALT_n,
T80_BUSAK_n => T80_BUSAK_n,
T80_A16 => T80_A16,
T80_DI => MZ80C_DI,
T80_DO => T80_DO,
-- Chip selects to common resources.
CS_ROM_n => MZ80C_CS_ROM_n,
CS_RAM_n => MZ80C_CS_RAM_n,
CS_VRAM_n => MZ80C_CS_VRAM_n, -- VRAM Select
CS_MEM_G_n => MZ80C_CS_MEM_G_n, -- Memory mapped Peripherals Select
CS_GRAM_n => MZ80C_CS_GRAM_n, -- Colour GRAM Select
CS_IO_GFB_n => MZ80C_CS_IO_GFB_n, -- Graphics FB IO Select range
-- Audio.
AUDIO_L => MZ80C_AUDIO_L,
AUDIO_R => MZ80C_AUDIO_R,
-- Different operations modes.
CONFIG => CONFIG,
-- Keyboard.
KEYB_SCAN => MZ80C_KEYB_SCAN, -- Keyboard scan lines out.
KEYB_DATA => MZ_KEYB_DATA, -- Keyboard scan data in.
KEYB_STALL => MZ80C_KEYB_STALL, -- Keyboard Stall out.
-- CMT status signals.
CMT_BUS_OUT => MZ_CMT_BUS_OUT,
CMT_BUS_IN => MZ80C_CMT_BUS_IN,
-- Video signals.
VGATE_n => MZ80C_VGATE_n,
HBLANK => MZ_HBLANK,
VBLANK => MZ_VBLANK,
-- HPS Interface
IOCTL_DOWNLOAD => MZ_IOCTL_DOWNLOAD,