-
Notifications
You must be signed in to change notification settings - Fork 13
/
ep994a.vhd
1613 lines (1445 loc) · 67.4 KB
/
ep994a.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
----------------------------------------------------------------------------------
-- ep994a.vhd
--
-- Toplevel module. The design is intended for the Saanlima electronics Pepino
-- FPGA board. The extension pins on that board are connected to an external
-- board (prototype board as of 2016-10-30) housing a TMS99105 microprocessor,
-- it's clock oscillator and a 74LVC245 buffer chip. See schematics for details.
--
-- This file is part of the ep994a design, a TI-99/4A clone
-- designed by Erik Piehl in October 2016.
-- Erik Piehl, Kauniainen, Finland, speccery@gmail.com
--
-- This is copyrighted software.
-- Please see the file LICENSE for license terms.
--
-- NO WARRANTY, THE SOURCE CODE IS PROVIDED "AS IS".
-- THE SOURCE IS PROVIDED WITHOUT ANY GUARANTEE THAT IT WILL WORK
-- FOR ANY PARTICULAR USE. IN NO EVENT IS THE AUTHOR LIABLE FOR ANY
-- DIRECT OR INDIRECT DAMAGE CAUSED BY THE USE OF THE SOFTWARE.
--
-- Synthesized with Xilinx ISE 14.7.
----------------------------------------------------------------------------------
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;
-- Uncomment the following library declaration if using
-- arithmetic functions with Signed or Unsigned values
use IEEE.NUMERIC_STD.ALL;
-- Uncomment the following library declaration if instantiating
-- any Xilinx primitives in this code.
--library UNISIM;
--use UNISIM.VComponents.all;
--0000..1FFF Console ROM
--2000..3FFF (8K, part of 32K RAM expansion)
--4000..5FFF (Peripheral cards ROM)
--6000..7FFF Cartridge ROM (module port)
--8000..83FF Scratchpad RAM (256 bytes, mirrored (partially decoded) across 8000..83FF)
--8400..87FF Sound chip write
--8800..8BFF VDP Read (8800 read, 8802 status)
--8C00..8FFF VDP Write (8C00 write, 8C02 set address)
--9800..9BFF GROM Read (9800 read, 9802 read addr+1)
--9C00..9FFF GROM Write (9C00 write data, 9C02 write address)
--A000..FFFF (24K, part of 32K RAM expansion)
----------------------------------------------------------------------------------
-- CRU map of the TI-99/4A
--0000..0FFE Internal use
--1000..10FE Unassigned
--1100..11FE Disk controller card
--1200..12FE Modems
--1300..13FE RS232 (primary)
--1400..14FE Unassigned
--1500..15FE RS232 (secondary)
--1600..16FE Unassigned
--...
----------------------------------------------------------------------------------
entity ep994a is
generic (
compat_rgb_g : integer := 0
);
port (
-- Global Interface -------------------------------------------------------
clk_i : in std_logic;
clk_en_10m7_i : in std_logic;
reset_n_i : in std_logic;
por_n_o : out std_logic;
-- Controller Interface ---------------------------------------------------
-- GPIO port
epGPIO_i : in std_logic_vector(7 downto 0);
epGPIO_o : out std_logic_vector(8 downto 0);
-- CPU RAM Interface ------------------------------------------------------
cpu_ram_a_o : out std_logic_vector(24 downto 0);
cpu_ram_ce_n_o : out std_logic;
cpu_ram_we_n_o : out std_logic;
cpu_ram_be_n_o : out std_logic_vector( 1 downto 0);
cpu_ram_d_i : in std_logic_vector(15 downto 0);
cpu_ram_d_o : out std_logic_vector(15 downto 0);
-- Video RAM Interface ----------------------------------------------------
vram_a_o : out std_logic_vector(13 downto 0);
vram_we_o : out std_logic;
vram_d_o : out std_logic_vector( 7 downto 0);
vram_d_i : in std_logic_vector( 7 downto 0);
-- RGB Video Interface ----------------------------------------------------
col_o : out std_logic_vector( 3 downto 0);
rgb_r_o : out std_logic_vector( 7 downto 0);
rgb_g_o : out std_logic_vector( 7 downto 0);
rgb_b_o : out std_logic_vector( 7 downto 0);
hsync_n_o : out std_logic;
vsync_n_o : out std_logic;
blank_n_o : out std_logic;
hblank_o : out std_logic;
vblank_o : out std_logic;
comp_sync_n_o : out std_logic;
-- Disk interface ---------------------------------------------------------
myarcfdc_en : in std_logic;
myarc80 : in std_logic;
fdc_turbo : in std_logic;
myarcSwitches : in std_logic_vector( 2 downto 0);
img_mounted : in std_logic_vector( 2 downto 0);
img_wp : in std_logic_vector( 2 downto 0);
img_size : in std_logic_vector(31 downto 0); -- in bytes
sd_lba_fd0 : out std_logic_vector(31 downto 0); -- Not doing Arrays in VDHL...they are pissing me off
sd_lba_fd1 : out std_logic_vector(31 downto 0);
sd_lba_fd2 : out std_logic_vector(31 downto 0);
sd_rd : out std_logic_vector( 2 downto 0);
sd_wr : out std_logic_vector( 2 downto 0);
sd_ack : in std_logic_vector( 2 downto 0); -- Saving for later when updating to newer framework
sd_buff_addr : in std_logic_vector( 8 downto 0);
sd_dout : in std_logic_vector( 7 downto 0);
sd_din_fd0 : out std_logic_vector( 7 downto 0); -- Not doing Arrays in VDHL...they are pissing me off
sd_din_fd1 : out std_logic_vector( 7 downto 0);
sd_din_fd2 : out std_logic_vector( 7 downto 0);
sd_dout_strobe : in std_logic;
-- Tipi Interface ---------------------------------------------------------
tipi_crubase : in std_logic_vector( 3 downto 0) := "0000";
tipi_en : in std_logic := '0';
rpi_clk : in std_logic := '0'; -- PI-31
-- 0 = Data or 1 = Control byte selection
rpi_cd : in std_logic := '0'; -- PI-40
rpi_dout : in std_logic := '0'; -- PI-36
rpi_le : in std_logic := '0'; -- PI-35
-- R|T 0 = RPi or 1 = TI originating data
rpi_rt : in std_logic := '0'; -- PI-33
rpi_din : out std_logic := '0'; -- PI-38
rpi_reset : out std_logic := '0'; -- PI-37
-- PCODE Interface --------------------------------------------------------
pcode_en : in std_logic := '0';
-- Audio Interface --------------------------------------------------------
audio_total_o : out std_logic_vector(10 downto 0);
speech_model : in std_logic_vector( 1 downto 0);
sr_re_o : out std_logic;
sr_addr_o : out std_logic_vector(14 downto 0);
sr_data_i : in std_logic_vector( 7 downto 0);
-- Cassette Data ----------------------------------------------------------
cassette_bit_i : in std_logic;
cassette_bit_o : out std_logic;
tape_audio_en : in std_logic;
scratch_1k_i : in std_logic;
cart_type_i : in std_logic_vector( 3 downto 0);
optSWI : in std_logic_vector( 2 downto 0);
rommask_i : in std_logic_vector(6 downto 1) := "000111";
flashloading_i : in std_logic;
turbo_i : in std_logic;
drive_led : out std_logic;
pause_i : in std_logic;
sams_en_i : in std_logic;
cart_8k_banks : in std_logic_vector(11 downto 0);
is_pal_g : in boolean
);
end ep994a;
-- pragma translate_off
use std.textio.all;
-- pragma translate_on
use work.tispeechsyn;
architecture Behavioral of ep994a is
component fdc1772 is
generic (
CLK : integer := 42954540; -- old values tried with different ram/success : 42666000 42800000 42680000 42856000
-- CLK_EN : integer := 8500;
SECTOR_SIZE_CODE : integer := 1 -- 256 bytes/sector
);
port (
clkcpu : in std_logic;
clk8m_en : in std_logic;
fd1771 : in std_logic;
dden : in std_logic;
turbo : in std_logic;
fd80 : in std_logic;
floppy_drive : in std_logic_vector( 3 downto 0);
floppy_side : in std_logic;
floppy_reset : in std_logic;
irq : out std_logic;
drq : out std_logic;
cpu_addr : in std_logic_vector( 1 downto 0);
cpu_sel : in std_logic;
cpu_rw : in std_logic;
cpu_din : in std_logic_vector( 7 downto 0);
cpu_dout : out std_logic_vector( 7 downto 0);
img_mounted : in std_logic_vector( 2 downto 0);
img_wp : in std_logic_vector( 2 downto 0);
img_ds : in std_logic;
img_size : in std_logic_vector(31 downto 0); -- in bytes
sd_lba_fd0 : out std_logic_vector(31 downto 0);
sd_lba_fd1 : out std_logic_vector(31 downto 0);
sd_lba_fd2 : out std_logic_vector(31 downto 0);
sd_rd : out std_logic_vector( 2 downto 0);
sd_wr : out std_logic_vector( 2 downto 0);
sd_ack : in std_logic_vector( 2 downto 0);
sd_buff_addr : in std_logic_vector( 8 downto 0);
sd_dout : in std_logic_vector( 7 downto 0);
sd_din_fd0 : out std_logic_vector( 7 downto 0);
sd_din_fd1 : out std_logic_vector( 7 downto 0);
sd_din_fd2 : out std_logic_vector( 7 downto 0);
sd_dout_strobe : in std_logic;
drive_led : out std_logic
);
end component ;
component tipi_top is
port
(
-- START USER PORT CONNECTION
r_clk : in std_logic;
-- 0 = Data or 1 = Control byte selection
r_cd : in std_logic;
r_dout : in std_logic;
r_le : in std_logic;
-- R|T 0 = RPi or 1 = TI originating data
r_rt : in std_logic;
r_din : out std_logic;
r_reset : out std_logic;
-- END USER PORT CONNECTION
ti_dbin : in std_logic; -- TMS9900 CPU_RD - request for data from bus
ti_memen : in std_logic;
ti_we : in std_logic; -- TMS9900 NOT CPU_WR
cru_state : in std_logic_vector( 3 downto 0);
ti_a : in std_logic_vector( 15 downto 0);
tp_d_i : in std_logic_vector( 7 downto 0);
tp_d_o : out std_logic_vector( 7 downto 0)
);
end component;
-- TIPI TEMPORARY SIGNALS
signal tipi_data : std_logic_vector(7 downto 0);
signal tipi_dsr_data : std_logic_vector(15 downto 0);
signal tipi_dsr_en : std_logic := '0';
component sprom is
generic
(
init_file : string := "";
awidth : integer := 14
);
port
(
clock : in std_logic;
address : in std_logic_vector (awidth-1 downto 0);
q : out std_logic_vector (15 downto 0)
);
end component;
signal funky_reset : std_logic_vector(15 downto 0) := (others => '0');
signal real_reset : std_logic;
signal real_reset_n : std_logic;
signal mem_addr : std_logic_vector(31 downto 0);
signal mem_read_rq : std_logic;
signal mem_write_rq : std_logic;
-- SRAM memory controller state machine
type mem_state_type is (
idle,
wr0, wr1, wr2,
rd0, rd1, rd2,
grace,
cpu_wr0, cpu_wr1, cpu_wr2,
cpu_rd0, cpu_rd1, cpu_rd2
);
signal mem_state : mem_state_type := idle;
type ctrl_state_type is (
idle, control_write, control_read, ack_end
);
signal ctrl_state : ctrl_state_type := idle;
signal debug_sram_ce0 : std_logic;
signal debug_sram_we : std_logic;
signal sram_addr_bus : std_logic_vector(24 downto 0);
signal sram_16bit_read_bus : std_logic_vector(15 downto 0); -- choose between (31..16) and (15..0) during reads.
signal por_n_s : std_logic;
signal reset_n_s : std_logic;
signal switch : std_logic;
signal clk : std_logic; -- output primary clock
signal clk_en_3m58_s : std_logic;
signal clk_en_cpu_s : std_logic;
-- TMS99105 control signals
signal cpu_addr : std_logic_vector(15 downto 0);
signal data_to_cpu : std_logic_vector(15 downto 0); -- data to CPU
signal data_from_cpu : std_logic_vector(15 downto 0); -- data from CPU
signal wr_sampler : std_logic_vector(3 downto 0);
signal rd_sampler : std_logic_vector(3 downto 0);
signal cruclk_sampler : std_logic_vector(3 downto 0);
signal cpu_access : std_logic; -- when '1' CPU owns the SRAM memory bus
-- VDP read and write signals
signal vdp_wr : std_logic;
signal vdp_rd : std_logic;
signal vdp_data_out : std_logic_vector(15 downto 0);
signal vdp_interrupt : std_logic; --low true
-- GROM signals
signal grom_data_out : std_logic_vector(7 downto 0);
signal grom_rd_inc : std_logic;
signal grom_we : std_logic;
signal grom_ram_addr : std_logic_vector(19 downto 0);
signal grom_selected : std_logic;
signal grom_rd : std_logic;
-- Keyboard control
signal cru9901 : std_logic_vector(31 downto 0) := x"00000000"; -- 32 write bits to 9901, when cru9901(0)='0'
signal cru9901IntMask: std_logic_vector(15 downto 0) := x"0000"; -- 16 bit Interrupt Mask for 9901
type keyboard_array is array (7 downto 0, 7 downto 0) of std_logic;
signal cru_read_bit : std_logic;
-- Reset control
signal cpu_reset_ctrl : std_logic_vector(7 downto 0); -- 8 control signals, bit 0 = reset, bit 1=rom bank reset, bit 2=mask interrupts when cleared
signal cpu_single_step : std_logic_vector(7 downto 0) := x"00"; -- single stepping. bit 0=1 single step mode, bit 1=1 advance one instruction
-- Module port banking
signal basic_rom_bank : std_logic_vector(6 downto 1) := "000000"; -- latch ROM selection, 512K ROM support
signal cartridge_cs : std_logic; -- 0x6000..0x7FFF
signal mbx_rom_bank : std_logic_vector(1 downto 0);
signal uber_rom_bank : std_logic_vector(11 downto 0);
signal cart_mask : std_logic_vector(11 downto 0);
-- audio subsystem
signal dac_data : std_logic_vector(7 downto 0); -- data from TMS9919 to DAC input
--signal dac_out_bit : std_logic; -- output to pin
-- SN76489 signal
signal psg_ready_s : std_logic;
signal tms9919_we : std_logic; -- write enable pulse for the audio "chip"
signal audio_data_out: std_logic_vector(7 downto 0);
signal audio_o : std_logic_vector( 7 downto 0);
-- cassette/tape system
signal timer9901Read : std_logic_vector(13 downto 0); -- TMS 9901 Timer READ Register paused for CRU reading.
signal timer9901Load: std_logic_vector(13 downto 0); -- TMS 9901 Clock Register
signal timer9901 : std_logic_vector(13 downto 0); -- TMS 9901 Timer countdown
signal tms9901Counter : integer; -- simple counter to track 64 clock cycles @ 3Mhz (916 @ 42.9)
constant tms9901NumCycles : integer := 916; -- Calc: CORE_CLK_MHZ / 3MHZ * 64 -- (42954540/3000000) = 14.318 X 64 = 916.36352 (x394), subtract 1 for range 0-393
signal tms9901IntReq_n : std_logic;
signal tape_audio : std_logic;
-- disk subsystem
signal tifdc_en : std_logic := '0'; -- EITHER tifdc_en OR myarcfdc_en can be enabled at a time.
signal fdc_en : std_logic := '1';
signal cru1100_regs : std_logic_vector(7 downto 0); -- disk controller CRU select
signal m80_tracks : std_logic; -- For 80 Track capable MyArc FDC, Force 80 Track mode for 360K images.
alias disk_page_ena : std_logic is cru1100_regs(0);
alias disk_motor_clk : std_logic is cru1100_regs(1);
alias disk_wait_en : std_logic is cru1100_regs(2);
alias disk_hlt : std_logic is cru1100_regs(3);
alias disk_sel : std_logic_vector(2 downto 0) is cru1100_regs(6 downto 4);
-- alias disk_side : std_logic is cru1100_regs(7);
signal disk_side : std_logic;
signal disk_ds : std_logic;
signal disk_motor_clk_d : std_logic;
signal disk_motor : std_logic;
signal disk_motor_cnt: integer := 0;
signal disk_clk_en : std_logic;
signal disk_clk_cnt : unsigned(4 downto 0);
signal disk_cs : std_logic;
signal disk_rw : std_logic;
signal disk_rd : std_logic;
signal disk_wr : std_logic;
signal disk_rdy : std_logic;
signal disk_proceed : std_logic;
signal disk_irq : std_logic;
signal disk_drq : std_logic;
signal disk_atn : std_logic;
signal disk_din : std_logic_vector(7 downto 0);
signal disk_dout : std_logic_vector(7 downto 0);
signal floppy_reset : std_logic;
signal floppy_addr : std_logic_vector(1 downto 0);
signal rst_sampler : std_logic_vector(3 downto 0) := "0000";
signal dden : std_logic;
-- Speech signals
signal speech_data_out : std_logic_vector(7 downto 0);
signal speech_o : signed(7 downto 0);
signal speech_conv : unsigned(10 downto 0);
signal speech_i : std_logic;
signal speech_ready : std_logic;
-- SAMS memory extension
signal sams_regs : std_logic_vector(7 downto 0) := x"00";
signal pager_data_in : std_logic_vector(15 downto 0);
signal pager_data_out : std_logic_vector(15 downto 0);
signal translated_addr : std_logic_vector(15 downto 0);
signal paging_enable : std_logic := '0';
signal paging_registers : std_logic;
signal paging_wr_enable : std_logic;
signal page_reg_read : std_logic;
signal paging_enable_cs : std_logic; -- access to some registers to enable paging etc.
signal paging_regs_visible : std_logic; -- when 1 page registers can be accessed
-- TIPI
signal tipi_regs : std_logic_vector(3 downto 0) := "0000";
-- PCODE
signal pcode_regs : std_logic_vector(1 downto 0) := "00";
-- signal pcode_dsr_data : std_logic_vector(15 downto 0);
signal pcode_dsr_bank : std_logic := '0';
-- PCODE-GROM signals
signal pcode_grom_data_out : std_logic_vector(7 downto 0);
signal pcode_grom_rd_inc : std_logic;
signal pcode_grom_we : std_logic;
signal pcode_grom_ram_addr : std_logic_vector(19 downto 0);
signal pcode_grom_selected : std_logic;
signal pcode_grom_rd : std_logic;
-- TMS99105 Shield control latch signals (written to control latch during control cycle)
signal conl_int : std_logic; -- IO2P - indata[1]
-- TMS99105 Shield control signal buffer read signals (read during control control cycle)
signal WE_n : std_logic; -- IO1N - indata[8]
signal MEM_n : std_logic; -- IO2N - indata[9]
signal BST1 : std_logic; -- IO6N - indata[13]
signal BST2 : std_logic; -- IO7N - indata[14]
signal BST3 : std_logic; -- IO8N - indata[15]
-- when to write to places
signal go_write : std_logic;
signal cpu_mem_write_pending : std_logic;
-- counter of alatch pulses to produce a sign of life of the CPU
signal alatch_counter : std_logic_vector(19 downto 0);
signal go_cruclk : std_logic; -- CRUCLK write pulses from the soft TMS9900 core
-------------------------------------------------------------------------------
-- SRAM debug signals with FPGA CPU
signal sram_capture : boolean := False;
-------------------------------------------------------------------------------
-- Signals from FPGA CPU
-------------------------------------------------------------------------------
signal RD_n : std_logic;
signal cpu_rd : std_logic;
signal cpu_wr : std_logic;
signal cpu_ready : std_logic;
signal cpu_iaq : std_logic;
signal cpu_as : std_logic;
signal cpu_cruin : std_logic;
signal cpu_cruout : std_logic;
signal cpu_cruclk : std_logic;
signal cpu_stuck : std_logic;
signal cpu_hold : std_logic;
signal cpu_holda : std_logic;
signal cpu_reset : std_logic;
signal cpu_int_req : std_logic;
-- signal cpu_ic03 : std_logic_vector(3 downto 0) := "0001";
signal cpu_int_ack : std_logic;
signal waits : std_logic_vector(7 downto 0);
-------------------------------------------------------------------------------
-- Signals for SPI Flash controller
-------------------------------------------------------------------------------
signal clk8 : std_logic := '0'; -- about 8 MHz clock, i.e. 100MHz divided by 12 which is 8.3MHz
signal clk8_divider : integer range 0 to 15 := 0;
signal romLoaded : std_logic;
signal flashAddrOut : STD_LOGIC_VECTOR (19 downto 0);
signal flashLoading : std_logic;
signal lastFlashLoading : std_logic; -- last state of flashLoading
-------------------------------------------------------------------------------
-- Signals for LPC1343 SPI controller receiver
-------------------------------------------------------------------------------
signal lastLPC_CLK : std_logic;
signal lastLPC_CS : std_logic_vector(7 downto 0) := x"00";
signal spiLPC_rx : std_logic_vector(7 downto 0);
signal spiLPC_tx : std_logic_vector(7 downto 0);
signal spi_bitcount : integer range 0 to 7;
signal spi_ready : boolean := false;
signal spi_test_toggle : boolean := false;
signal spi_test_count : integer range 0 to 255 := 0;
signal spi_clk_sampler : std_logic_vector(2 downto 0) := "000";
signal spi_rx_bit : std_logic;
signal wait_clock : boolean := false;
-------------------------------------------------------------------------------
COMPONENT tms9900
GENERIC (cycle_clks_g : integer);
PORT(
clk : IN std_logic;
reset : IN std_logic;
addr_out : OUT std_logic_vector(15 downto 0);
data_in : IN std_logic_vector(15 downto 0);
data_out : OUT std_logic_vector(15 downto 0);
rd : OUT std_logic;
wr : OUT std_logic;
ready : IN std_logic := '1';
iaq : OUT std_logic;
as : OUT std_logic;
alu_debug_arg1 : OUT std_logic_vector(15 downto 0);
alu_debug_arg2 : OUT std_logic_vector(15 downto 0);
int_req : in STD_LOGIC; -- interrupt request, active high
ic03 : in STD_LOGIC_VECTOR(3 downto 0); -- interrupt priority for the request, 0001 is the highest (0000 is reset)
int_ack : out STD_LOGIC; -- does not exist on the TMS9900, when high CPU vectors to interrupt
cpu_debug_out : out STD_LOGIC_VECTOR (95 downto 0);
cruin : in STD_LOGIC;
cruout : out STD_LOGIC;
cruclk : out STD_LOGIC;
hold : in STD_LOGIC;
holda : out STD_LOGIC;
waits : in STD_LOGIC_VECTOR(7 downto 0);
scratch_en : in STD_LOGIC; -- when 1 in-core scratchpad RAM is enabled
stuck : OUT std_logic;
turbo : in STD_LOGIC
);
END COMPONENT;
-------------------------------------------------------------------------------
component pager612
port ( clk : in STD_LOGIC;
abus_high : in STD_LOGIC_VECTOR (15 downto 12);
abus_low : in STD_LOGIC_VECTOR (3 downto 0);
dbus_in : in STD_LOGIC_VECTOR (15 downto 0);
dbus_out : out STD_LOGIC_VECTOR (15 downto 0);
mapen : in STD_LOGIC; -- 1 = enable mapping
write_enable : in STD_LOGIC; -- 0 = write to register when sel_regs = 1
page_reg_read : in STD_LOGIC; -- 0 = read from register when sel_regs = 1
translated_addr : out STD_LOGIC_VECTOR (15 downto 0);
access_regs : in STD_LOGIC -- 1 = read/write registers
);
end component;
-------------------------------------------------------------------------------
component gromext is
Port ( din : in STD_LOGIC_VECTOR (7 downto 0); -- data in, write bus for addresses
dout : out STD_LOGIC_VECTOR (7 downto 0); -- data out, read bus
clk : in STD_LOGIC;
we : in STD_LOGIC; -- write enable, 1 cycle long
rd : in STD_LOGIC; -- read signal, may be up for multiple cycles
selected : out STD_LOGIC; -- high when this GROM is enabled during READ
-- when high, databus should be driven
mode : in STD_LOGIC_VECTOR(4 downto 0); -- A5..A1 (4 bits for GROM base select, 1 bit for register select)
reset : in STD_LOGIC;
addr : out STD_LOGIC_VECTOR(19 downto 0) -- 1 megabyte GROM address out
);
end component;
begin
-----------------------------------------------------------------------------
-- Reset generation
-----------------------------------------------------------------------------
por_b : work.cv_por
port map (
clk_i => clk_i,
por_n_o => por_n_s
);
por_n_o <= por_n_s;
reset_n_s <= reset_n_i;--por_n_s and reset_n_i;
-----------------------------------------------------------------------------
-- Clock generation
-----------------------------------------------------------------------------
clock_b : work.cv_clock
port map (
clk_i => clk_i,
clk_en_10m7_i => clk_en_10m7_i,
reset_n_i => reset_n_s,
clk_en_3m58_p_o => clk_en_3m58_s
);
clk <= clk_i;
-------------------------------------
-- Use all 32 bits of RAM, we use CE0 and CE1 to control what chip is active.
-- The byte enables are driven the same way for both chips.
cpu_ram_be_n_o <= "00" when cpu_access = '1' else -- or flashLoading = '1' else -- TMS99105 is always 16-bit, use CE
--"10" when mem_addr(0) = '1' else -- lowest byte
"01"; -- second lowest byte
cpu_ram_a_o <= sram_addr_bus;
-- broadcast on 16-bit wide lanes when CPU is writing
-- cpu_ram_d_o <= data_from_cpu when cpu_access='1' and MEM_n='0' and WE_n = '0' else (others => 'Z');
cpu_ram_d_o <= data_from_cpu when cpu_access='1' and MEM_n='0' and WE_n = '0';
sram_16bit_read_bus <= cpu_ram_d_i; --SRAM_DAT(15 downto 0) when sram_addr_bus(0)='0' else SRAM_DAT(31 downto 16);
process(clk, switch)
begin
if rising_edge(clk) then
if cpu_access = '0' then
cpu_ram_ce_n_o <= debug_sram_ce0;
cpu_ram_we_n_o <= debug_sram_we;
else
cpu_ram_ce_n_o <= MEM_n;
if MEM_n = '0' and WE_n = '0'
and cpu_addr(15 downto 12) /= x"9" -- 9XXX addresses don't go to RAM
and cpu_addr(15 downto 11) /= x"8" & '1' -- 8800-8FFF don't go to RAM
and cpu_addr(15 downto 13) /= "000" -- 0000-1FFF don't go to RAM
and ((tifdc_en = '1' and cpu_addr(15 downto 13) /= "010") or -- 4000-5FFF don't go to RAM (DISK DSR)
(myarcfdc_en = '1' and cpu_addr(15 downto 12) /= "0100") ) -- 4000-5FFF don't go to RAM (DISK DSR)
and (cartridge_cs='0' -- writes to cartridge region do not go to RAM, unless:
or (cart_type_i = 1 and cpu_addr(15 downto 10) = "011011") -- MBX cart is loaded, we allow writes to 6C00+
or (cart_type_i = 5 and cpu_addr(15 downto 12) = "0111") ) -- Mini Mem Cart is loaded, we allow writes to 7000-7FFF
then
cpu_ram_we_n_o <= '0';
else
cpu_ram_we_n_o <= '1';
end if;
end if;
end if;
end process;
--Flandango-Cart Rom Masking
cart_mask <= x"FFF" when cart_8k_banks(11)='1' else
x"7FF" when cart_8k_banks(10)='1' else
x"3FF" when cart_8k_banks(9) ='1' else
x"1FF" when cart_8k_banks(8) ='1' else
x"0FF" when cart_8k_banks(7) ='1' else
x"07F" when cart_8k_banks(6) ='1' else
x"03F" when cart_8k_banks(5) ='1' else
x"01F" when cart_8k_banks(4) ='1' else
x"00F" when cart_8k_banks(3) ='1' else
x"007" when cart_8k_banks(2) ='1' else
x"003" when cart_8k_banks(1) ='1' else
x"001" when cart_8k_banks(0) ='1';
-------------------------------------size
-- CPU reset out. If either cpu_reset_ctrl(0) or funky_reset(MSB) is zero, put CPU to reset.
real_reset <= funky_reset(funky_reset'length-1);
real_reset_n <= not real_reset;
cpu_access <= not cpu_holda; -- CPU owns the bus except when in hold
-- cpu_ready <= '1';
-------------------------------------
-- vdp interrupt & Timer Interrupt
conl_int <= '0' when (tms9901IntReq_n = '0' and cru9901IntMask(3) = '1' and timer9901Load /= 0) or (vdp_interrupt = '0' and cru9901IntMask(2) = '1') else '1';
-- cartridge memory select
cartridge_cs <= '1' when MEM_n = '0' and cpu_addr(15 downto 13) = "011" else '0'; -- cartridge_cs >6000..>7FFF
-------------------------------------
-- For the column decoder, rely on pull-ups to bring the row selectors high
epGPIO_o(8) <= cru9901(21); -- alpha-lock
epGPIO_o(7) <= '0' when cru9901(20 downto 18) = "011" else '1'; -- col#3
epGPIO_o(6) <= '0' when cru9901(20 downto 18) = "010" else '1'; -- col#2
epGPIO_o(5) <= '0' when cru9901(20 downto 18) = "001" else '1'; -- col#1
epGPIO_o(4) <= '0' when cru9901(20 downto 18) = "000" else '1'; -- col#0
epGPIO_o(3) <= '0' when cru9901(20 downto 18) = "100" else '1'; -- col#4
epGPIO_o(2) <= '0' when cru9901(20 downto 18) = "101" else '1'; -- col#5
epGPIO_o(1) <= '0' when cru9901(20 downto 18) = "110" else '1'; -- col#6
epGPIO_o(0) <= '0' when cru9901(20 downto 18) = "111" else '1'; -- col#7
-------------------------------------
speech_i <= '0' when speech_model = "11" else '1';
switch <= not reset_n_s;
mem_read_rq <= '0';
mem_write_rq <= '0';
mem_addr <= (others => '0');
flashloading <= flashloading_i;--'0';
process(clk, switch)
variable ki : integer range 0 to 7;
begin
if rising_edge(clk) then -- our 100 MHz clock
-- reset generation
if switch = '1' then
funky_reset <= (others => '0'); -- button on the FPGA board pressed
else
funky_reset <= funky_reset(funky_reset'length-2 downto 0) & '1';
end if;
-- reset processing
if funky_reset(funky_reset'length-1) = '0' then
-- reset activity here
mem_state <= idle;
ctrl_state <= idle;
debug_sram_ce0 <= '1';
debug_sram_WE <= '1';
cru9901 <= x"00000000";
cru9901IntMask <= x"0000";
cru1100_regs <= (others => '0');
sams_regs <= (others => '0');
tipi_regs <= (others => '0');
pcode_regs <= (others => '0');
pcode_dsr_bank <= '0';
alatch_counter <= (others => '0');
cpu_mem_write_pending <= '0';
sram_capture <= True;
cpu_single_step <= x"00";
waits <= (others => '0');
timer9901Load <= (others => '0');
timer9901 <= (others => '0');
tms9901Counter <= 0;
tms9901IntReq_n <= '1';
timer9901Read <= (others => '0');
else
-- processing of normal clocks here. We run at 100MHz.
-- First manage CPU wait states
-- if switch 2 is set we run at 63 wait states
-- if switch 1 is set we run at 31 wait states
-- if switch 0 is set we run at 8 wait states
-- else we run at zero wait states
if optSWI(2)='1' then
if cpu_as='1' then
-- setup number of wait states depending on address accessed
case cpu_addr(15 downto 12) is
when x"0" => waits <= x"60"; -- ROM an scratchpad 640 ns
when x"1" => waits <= x"60";
when x"8" => waits <= x"60"; -- scratchpad and I/O
when others =>
waits <= x"F0"; -- 196, i.e. 200, i.e. 2000ns
end case;
end if;
elsif optSWI(1)='1' then
waits <= x"1F";
elsif optSWI(0)='1' then
waits <= x"08";
else
waits <= (others => '0');
end if;
-- If SWI(0) is set then automatically bring CPU out of reset once FPGA has moved
-- data from flash memory to SRAM.
cpu_reset <= not (cpu_reset_ctrl(0) and real_reset and not flashLoading);
lastFlashLoading <= flashLoading;
if flashLoading='1' then
cpu_reset_ctrl <= x"FC"; -- during flash loading force reset on
basic_rom_bank <= (others => '0');
mbx_rom_bank <= (others => '0');
uber_rom_bank <= (others => '0');
sams_regs <= x"00";
tipi_regs <= "0000";
pcode_regs <= (others => '0');
pcode_dsr_bank <= '0';
end if;
if flashLoading='0' and lastFlashLoading='1' then
-- flash loading just stopped. Bring CPU out of reset.
cpu_reset_ctrl <= x"FF";
end if;
-- Enable/Disable Floppy Drive Controller based on TIPI CRU Base
if(tipi_en = '1' and tipi_crubase = "0001") then fdc_en <= '0';
else fdc_en <= '1';
end if;
---------------------------------------------------------
-- SRAM map (1 mega byte, 0..FFFFF, 20 bit address space)
---------------------------------------------------------
-- 00000..7FFFF - Cartridge module port, paged, 512K, to support the TI megademo :)
-- 80000..9FFFF - GROM mapped to this area, 128K (was at 30000)
-- A0000..AFFFF - Not used currently
-- B0000..BCFFF - DSR area, 52K reserved (was at 60000)
-- B0000..B7FFF - 32k For Disk roms (TI-FDC = 8k, CC=16K)
-- B8000..B8FFF - 4K For Tipi DSR (Currently File is 32K but only 4K DSR Padded with 0s)
-- B9000..CBFFF - 76K For PCode DSR+Grom
-- B9000..BBFFF - 12k PCode DSR 8K + 4K banked
-- BC000..CBFFF - 64k PCode Private Grom
-- FD000..FDFFF - Scratchpad (was at 68000)
-- FE000..FFFFF - Boot ROM remapped (was at 0)
-- 100000..1FFFFF - SAMS SRAM 1M (i.e. the "normal" CPU RAM paged with the SAMS system)
-- 200000 and above - Cartridge ROM Space for anything above 512K (Currently up to 32Megs)
---------------------------------------------------------
-- The SAMS control bits are set to zero on reset.
-- sams_regs(0) CRU 1E00: when set, paging registers appear at DSR space >4000..
-- sams_regs(1) CRU 1E02: when set, paging is enabled
-- sams_regs(2) CRU 1E04: unused
-- sams_regs(3) CRU 1E06: unused
-- The memory paging CRU register control bits can be used
-- to remove devices from the CPU's address space, revealing the
-- underlying pageable RAM:
-- sams_regs(4) CRU 1E08: when set, ROM is out and pageable RAM instead is available
-- sams_regs(5) CRU 1E0A: when set, cartridge is out and pageable RAM instead is available
-- Also writes to cartridge area do not change the cartridge page during this time.
-- sams_regs(6) CRU 1E0C: when set I/O devices are out and pageable RAM instead is available
-- sams_regs(7) CRU 1E0E: unused
-- Also, when disk DSR ROM are not mapped (CRU >1100=0) or SAMS page registers visible (>1E00=0)
-- the pageable RAM "under" the DSR space is available.
-- Thus the entire 64K is pageable.
---------------------------------------------------------
-- Drive SRAM addresses outputs synchronously
if cpu_access = '1' then
if cpu_addr(15 downto 8) = x"98" and cpu_addr(1)='0' then
sram_addr_bus <= "000000" & x"8" & grom_ram_addr(15 downto 1); -- 0x80000 GROM
-- sram_addr_bus <= "0" & x"4" & grom_ram_addr(16 downto 1); -- 0x80000 GROM
elsif cpu_addr(15 downto 0) = x"5BFC" and pcode_en = '1' and pcode_grom_selected = '1' then
sram_addr_bus <= "00000" & (x"5E000" + pcode_grom_ram_addr(15 downto 1)); -- 0xBC000..CBFFF PCode GROM
elsif cartridge_cs = '1' and cart_type_i = 1 and cpu_addr(12 downto 10) = "011" then
-- MBX 6c00-6FFF - RAM
sram_addr_bus <= "0000000000010" & cpu_addr(12 downto 1);
elsif cartridge_cs = '1' and (cart_type_i = 1 or cart_type_i = 2) and cpu_addr(12) = '1' then
-- MBX 7000-7FFF - bank switched area
sram_addr_bus <= "000000000000" & mbx_rom_bank & cpu_addr(11 downto 1);
elsif cartridge_cs = '1' and sams_regs(5) = '0' and (cart_type_i = 3 or cart_type_i = 4) then
-- UberGrom 6000-7FFF - bank switched area
if uber_rom_bank(11 downto 6) = 0 then
sram_addr_bus <= "0000000" & uber_rom_bank(5 downto 0) & cpu_addr(12 downto 1);
else -- Any cart address over 512K is above the SAMS reserved area (100000..1FFFFF) so we add 0xC0000 to the right shifted address.
sram_addr_bus <= std_logic_vector(to_unsigned(786432+to_integer(unsigned(uber_rom_bank(11 downto 0) & cpu_addr(12 downto 1))),25));
end if;
elsif cartridge_cs = '1' and sams_regs(5) = '0' then
-- Handle paging of module port at 0x6000 unless sams_regs(5) is set (1E0A)
sram_addr_bus <= "0000000" & (basic_rom_bank and rommask_i) & cpu_addr(12 downto 1); -- mapped to 0x00000..0x7FFFF
--Flandango: Handle the two different FDC.
elsif disk_page_ena='1' and tifdc_en='1' and cpu_addr(15 downto 13) = "010" then
-- DSR's for disk system (TI-FDC) 0x4000..0x5FFF
sram_addr_bus <= "000000" & x"B" & "000" & cpu_addr(12 downto 1); -- mapped to 0xB0000..0xB7FFF
elsif disk_page_ena='1' and myarcfdc_en='1' and cpu_addr(15 downto 12) = "0100" then
-- DSR's for disk system (MYARC-FDC) 0x4000..0x4FFF (2 pages of 4k)
sram_addr_bus <= "000000" & x"B" & "000" & cru1100_regs(3) & cpu_addr(11 downto 1); -- mapped to 0xB0000..0xB0FFF
elsif disk_page_ena='1' and myarcfdc_en='1' and cpu_addr(15 downto 12) = "0101" then
-- MYARC's FDC SDRAM 0x5000..0x5FFF shift it by 0x1000 since DSR is two banks of 4K
sram_addr_bus <= "000000" & x"B" & "0010" & cpu_addr(11 downto 1); -- mapped to 0xB2000..0xB2FFF
elsif tipi_regs(0)='1' and cpu_addr(15 downto 13) = "010" then
-- DSR's for Tipi system
sram_addr_bus <= "000000" & x"B" & "100" & cpu_addr(12 downto 1); -- mapped to 0xB8000..0xB8FFF
elsif pcode_regs(0)='1' and cpu_addr(15 downto 13) = "010" then -- PCode DSR mapped to 0XB9000..0xBBFFF
if cpu_addr(12) = '1' then sram_addr_bus <= "00000" & (x"5D000" + (pcode_dsr_bank & cpu_addr(11 downto 1))); -- 2 banks for 0x5000..0x5FFF @ 0xBA000..0xBBFFF
else sram_addr_bus <= "00000" & (x"5C800" + cpu_addr(12 downto 1)); -- 0x4000..0x4FFF @ 0xB9000..0xB9FFF
end if;
-- DSR's for PCode system
-- sram_addr_bus <= "0" & (x"5C800" + (pcode_dsr_bank & cpu_addr(12 downto 1))); -- mapped to 0xB9000..0xBBFFF
elsif cpu_addr(15 downto 13) = "000" and sams_regs(4) = '0' then
-- ROM at the bottom of address space not paged unless sams_regs(4) is set (1E08)
sram_addr_bus <= "000000" & x"F" & "111" & cpu_addr(12 downto 1); -- mapped to 0xFE000
elsif cpu_addr(15 downto 10) = "100000" then
-- now that paging is introduced we need to move scratchpad (1k here)
-- out of harm's way. Scartchpad at FD000 to keep it safe from paging.
if scratch_1k_i='1' then
sram_addr_bus <= "000000" & x"FD" & "00" & cpu_addr(9 downto 1);
else
sram_addr_bus <= "000000" & x"FD" & X"3" & cpu_addr(7 downto 1);
end if;
else
-- regular RAM access
-- Top 256K is CPU SAMS RAM for now, so we have 18 bit memory addresses for RAM
sram_addr_bus <= "000001" & translated_addr(7 downto 0) & cpu_addr(11 downto 1);
end if;
end if;
if MEM_n = '0' and go_write = '1'
and cpu_addr(15 downto 12) /= x"9" -- 9XXX addresses don't go to RAM
and cpu_addr(15 downto 11) /= x"8" & '1' -- 8800-8FFF don't go to RAM
and cpu_addr(15 downto 13) /= "000" -- 0000-1FFF don't go to RAM
and ((tifdc_en = '1' and cpu_addr(15 downto 13) /= "010") or -- 4000-5FFF don't go to RAM (DISK DSR)
(myarcfdc_en = '1' and cpu_addr(15 downto 12) /= "0100") ) -- 4000-fFFF don't go to RAM (DISK DSR)
and (cartridge_cs='0' -- writes to cartridge region do not go to RAM
or (cart_type_i = 1 and cpu_addr(15 downto 10) = "011011") -- MBX Cart
or (cart_type_i = 5 and cpu_addr(15 downto 12) = "0111")) -- MiniMem Cart
then
cpu_mem_write_pending <= '1';
end if;
if cpu_single_step(1 downto 0)="11" and cpu_holda = '0' then
-- CPU single step is desired, and CPU is out of hold despite cpu_singe_step(0) being '1'.
-- This must mean that the CPU is started to execute an instruction, so zero out bit 1
-- which controls the stepping.
cpu_single_step(1) <= '0';
end if;
-- memory controller state machine
case mem_state is
when idle =>
debug_sram_ce0 <= '1';
debug_sram_WE <= '1';
if mem_write_rq = '1' and mem_addr(20)='0' and cpu_holda='1' then
-- normal memory write
sram_addr_bus <= "0000" & mem_addr(21 downto 1); -- setup address
mem_state <= wr0;
elsif mem_read_rq = '1' and mem_addr(20)='0' and cpu_holda='1' then
sram_addr_bus <= "0000" & mem_addr(21 downto 1); -- setup address
mem_state <= rd0;
elsif MEM_n = '0' and rd_sampler(1 downto 0) = "10" then
-- init CPU read cycle
mem_state <= cpu_rd0;
debug_sram_ce0 <= '0'; -- init read cycle
elsif cpu_mem_write_pending = '1' then
-- init CPU write cycle
mem_state <= cpu_wr1; -- EPEP jump directly to state 1!!!
debug_sram_ce0 <= '0'; -- initiate write cycle
debug_sram_WE <= '0';
cpu_mem_write_pending <= '0';
end if;
when wr0 =>
debug_sram_ce0 <= '0'; -- issue write strobes
debug_sram_WE <= '0';
mem_state <= wr1;
when wr1 => mem_state <= wr2; -- waste time
when wr2 => -- terminate memory write cycle
debug_sram_WE <= '1';
debug_sram_ce0 <= '1';
mem_state <= grace;
-- states to handle read cycles
when rd0 =>
debug_sram_ce0 <= '0'; -- init read cycle
mem_state <= rd1;
when rd1 => mem_state <= rd2; -- waste some time
when rd2 =>
debug_sram_ce0 <= '1';
mem_state <= grace;
when grace => -- one cycle grace period before going idle.
mem_state <= idle; -- thus one cycle when mem_write_rq is not sampled after write.
-- CPU read cycle
when cpu_rd0 => mem_state <= cpu_rd1;
when cpu_rd1 =>
mem_state <= cpu_rd2;
if sram_capture then
sram_capture <= False;
end if;
when cpu_rd2 =>
debug_sram_ce0 <= '1';
mem_state <= grace;
-- CPU write cycle
when cpu_wr0 => mem_state <= cpu_wr1;
when cpu_wr1 => mem_state <= cpu_wr2;
when cpu_wr2 =>
mem_state <= grace;
debug_sram_WE <= '1';
debug_sram_ce0 <= '1';
mem_state <= grace;
end case;
-- Handle control state transfer is a separate
-- state machine in order not to disturb the TMS99105.
case ctrl_state is
when idle =>
if mem_read_rq = '1' and mem_addr(20)='1' then
ctrl_state <= control_read;
elsif mem_write_rq = '1' and mem_addr(20)='1' then
ctrl_state <= control_write;
end if;
when control_read =>
ctrl_state <= ack_end;
when ack_end =>
ctrl_state <= idle;
when control_write =>
ctrl_state <= ack_end;
end case;
if cpu_reset_ctrl(1)='0' then
basic_rom_bank <= "000000"; -- Reset ROM bank selection
mbx_rom_bank <= "00";
uber_rom_bank <= (others => '0');
end if;
-- CPU signal samplers
if cpu_as='1' then
alatch_counter <= std_logic_vector(to_unsigned(1+to_integer(unsigned(alatch_counter)), alatch_counter'length));
end if;
wr_sampler <= wr_sampler(wr_sampler'length-2 downto 0) & WE_n;
rd_sampler <= rd_sampler(rd_sampler'length-2 downto 0) & RD_n;
if myarcfdc_en = '1' and disk_page_ena = '1' then
rst_sampler <= rst_sampler(rst_sampler'length-2 downto 0) & cru1100_regs(1);
end if;
cruclk_sampler <= cruclk_sampler(cruclk_sampler'length-2 downto 0) & cpu_cruclk;
if (clk_en_10m7_i = '1') then
vdp_wr <= '0';
vdp_rd <= '0';
end if;
grom_we <= '0';
pcode_grom_we <= '0';
if (psg_ready_s = '1') then
tms9919_we <= '0';