-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathcoco3fpga_dw.v
4024 lines (3905 loc) · 90.8 KB
/
coco3fpga_dw.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
////////////////////////////////////////////////////////////////////////////////
// Project Name: CoCo3FPGA Version 3.0
// File Name: coco3fpga.v
//
// CoCo3 in an FPGA
//
// Revision: 3.0 08/15/15
////////////////////////////////////////////////////////////////////////////////
//
// CPU section copyrighted by John Kent
// The FDC co-processor copyrighted Daniel Wallner.
//
////////////////////////////////////////////////////////////////////////////////
//
// Color Computer 3 compatible system on a chip
//
// Version : 3.0
//
// Copyright (c) 2008 Gary Becker ([email protected])
//
// All rights reserved
//
// Redistribution and use in source and synthezised forms, with or without
// modification, are permitted provided that the following conditions are met:
//
// Redistributions of source code must retain the above copyright notice,
// this list of conditions and the following disclaimer.
//
// Redistributions in synthesized form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the distribution.
//
// Neither the name of the author nor the names of other contributors may
// be used to endorse or promote products derived from this software without
// specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
// THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE
// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
//
// Please report bugs to the author, but before you do so, please
// make sure that this is not a derivative work and that
// you have the latest version of this file.
//
// The latest version of this file can be found at:
// http://groups.yahoo.com/group/CoCo3FPGA
//
// File history :
//
// 1.0 Full Release
// 2.0 Partial Release
// 3.0 Full Release
////////////////////////////////////////////////////////////////////////////////
// Gary Becker
////////////////////////////////////////////////////////////////////////////////
// RS232 PAK Hardware included
`define RS232PAK
// New vs Old SRAM
//`define NEW_SRAM
// SPI Bus Analyzer
//`define BUSA
// Only one of the next three
// Floppy Debug
// `define FLPY_DEBUG
// SD Card Degug 7 Segment LEDs and Green LEDs
//`define SD_DEBUG
// No Debug
`define NO_DEBUG
module coco3fpga_dw(
// Input Clocks
CLK50MHZ,
CLK24MHZ,
CLK24MHZ_2,
CLK27MHZ,
CLK27MHZ_2,
CLK3_57MHZ,
// RAM and ROM
RAM0_DATA, // 16 bit data bus to RAM 0
RAM0_ADDRESS,
RAM0_RW_N,
RAM0_CS_N, // Chip Select for RAM 0
RAM0_BE0_N, // Byte Enable for RAM 0
RAM0_BE1_N, // Byte Enable for RAM 0
RAM0_OE_N,
RAM1_ADDRESS,
RAM1_DATA,
RAM1_BE0_N,
RAM1_BE1_N,
RAM1_CS_N,
RAM1_RW_N,
FLASH_ADDRESS,
FLASH_DATA,
FLASH_WE_N,
FLASH_RESET_N,
FLASH_CE_N,
FLASH_OE_N,
// VGA
RED3,
GREEN3,
BLUE3,
RED2,
GREEN2,
BLUE2,
RED1,
GREEN1,
BLUE1,
RED0,
GREEN0,
BLUE0,
H_SYNC,
V_SYNC,
// PS/2
ps2_clk,
ps2_data,
ms_clk,
ms_data,
//Serial Ports
DE1TXD,
DE1RXD,
OPTTXD,
OPTRXD,
// I2C
I2C_SCL,
I2C_DAT,
//Codec
AUD_XCK,
AUD_BCLK,
AUD_DACDAT,
AUD_DACLRCK,
AUD_ADCDAT,
AUD_ADCLRCK,
// 7 Segment Display
SEGMENT0_N,
SEGMENT1_N,
SEGMENT2_N,
SEGMENT3_N,
// LEDs
LEDG,
LEDR,
// CoCo Joystick
PADDLE_MCLK,
PADDLE_CLK,
P_SWITCH,
//SPI for SD Card
MOSI,
MISO,
SPI_CLK,
SPI_SS_N,
// Debug Test Points
TEST_1,
TEST_2,
TEST_3,
TEST_4,
// Buttons and Switches
SWITCH,
BUTTON_N
);
input CLK50MHZ;
input CLK24MHZ;
input CLK24MHZ_2;
input CLK27MHZ;
input CLK27MHZ_2;
output CLK3_57MHZ;
// DE1 RAM Common
//output [17:0] RAM0_ADDRESS; // 512kb SRAM
//reg [17:0] RAM0_ADDRESS;
output [19:0] RAM0_ADDRESS; // 2MB SRAM. Bit 19 unconnected on DE1, gives 1MB
reg [19:0] RAM0_ADDRESS;
output RAM0_RW_N;
reg RAM0_RW_N;
// DE1 RAM bank 0
inout [15:0] RAM0_DATA;
reg [15:0] RAM0_DATA;
output RAM0_CS_N;
wire RAM0_CS; // DATA_IN Mux select
output RAM0_BE0_N;
reg RAM0_BE0_N;
output RAM0_BE1_N;
reg RAM0_BE1_N;
output RAM0_OE_N;
wire RAM0_BE0;
wire RAM0_BE1;
// Analog Board RAM Common
output [17:0] RAM1_ADDRESS;
output RAM1_RW_N;
// Ananlog SRAM bank 1
inout [15:0] RAM1_DATA;
output RAM1_BE0_N;
output RAM1_BE1_N;
output RAM1_CS_N;
//Flash ROM
output [21:0] FLASH_ADDRESS;
input [7:0] FLASH_DATA;
output FLASH_WE_N;
output FLASH_RESET_N;
output FLASH_CE_N;
output FLASH_OE_N;
// VGA
output RED3;
reg RED3;
output GREEN3;
reg GREEN3;
output BLUE3;
reg BLUE3;
output RED2;
reg RED2;
output GREEN2;
reg GREEN2;
output BLUE2;
reg BLUE2;
output RED1;
reg RED1;
output GREEN1;
reg GREEN1;
output BLUE1;
reg BLUE1;
output RED0;
reg RED0;
output GREEN0;
reg GREEN0;
output BLUE0;
reg BLUE0;
output H_SYNC;
output V_SYNC;
wire HBLANK;
wire VBLANK;
// PS/2
input ps2_clk;
input ps2_data;
input ms_clk;
input ms_data;
// Serial Ports
output DE1TXD;
input DE1RXD;
output OPTTXD;
input OPTRXD;
// I2C
output I2C_SCL;
inout I2C_DAT;
//Codec
output AUD_XCK;
input AUD_BCLK;
output AUD_DACDAT;
reg AUD_DACDAT;
input AUD_DACLRCK;
input AUD_ADCDAT;
input AUD_ADCLRCK;
// Display
output [6:0] SEGMENT0_N;
output [6:0] SEGMENT1_N;
output [6:0] SEGMENT2_N;
output [6:0] SEGMENT3_N;
`ifdef SD_DEBUG
reg [6:0] SEGMENT0_N;
reg [6:0] SEGMENT1_N;
reg [6:0] SEGMENT2_N;
reg [6:0] SEGMENT3_N;
wire [6:0] SEGMENT_N;
reg [3:0] DIGIT_N;
`endif
// LEDs
output [7:0] LEDG;
//output [9:0] LEDR;
output [8:0] LEDR; // LEDR9 = A18 of 1MB SRAM
// CoCo Perpherial
output PADDLE_MCLK;
input [3:0] PADDLE_CLK;
input [3:0] P_SWITCH;
//SPI
output MOSI;
input MISO;
output SPI_CLK;
output SPI_SS_N;
// Extra Buttons and Switches
input [9:0] SWITCH; // 9 UART / DriveWire
// Off - DE1 Port is DriveWire and Analog Board is RS232 PAK
// on - DE1 Port is RS232 PAK and Analog Board is DriveWire
// 9 SG4 / SG6 ????????
// 8 Serial Port Speed[1]
// 7 Serial Port Speed[0]
// [1] [0]
// OFF OFF - 115200 // Swap UART / DriveWire
// OFF ON - 230400
// ON OFF - 460800 // Fastest for the DE1 Port
// ON ON - 921600
// 6 SD Card Presence / Write Protect
// Off - Use card signals
// On - Ignore Signals
// 5 SG4 / SG6 mode select
// Off - SG4
// On - SG6
// 4 Cartridge Interrupt disabled except Disk
// 3 Video Odd line black
// Off - Normal video
// On - Odd lines black
// 2 MPI [1]
// 1 MPI [0]
// [1] [0]
// OFF OFF - Slot 1
// OFF ON - Slot 2
// ON OFF - Slot 3
// ON ON - Slot 4
// 0 CPU Turbo Speed
// Off - Normal 1.78 MHz
// On - 25 MHz or 8.33 MHz (Old or New SRAM)
input [3:0] BUTTON_N; // 3 RESET
// 2 SD Card Inserted (0=Inserted) wired to switche on the SD card
// 1 SD Write Protect (1=Protected) wired to switche on the SD card
// 0 Easter Egg
output TEST_1; // Debug Test Points
output TEST_2;
output TEST_3;
output TEST_4;
wire PH_2;
reg PH_2_RAW;
reg RESET_N;
reg [13:0] RESET_SM;
reg CPU_RESET;
wire RESET;
wire RESET_P;
wire [15:0] ADDRESS;
wire [7:0] BLOCK_ADDRESS; // 5:0 for 512kb
wire RW_N;
wire [7:0] DATA_IN;
wire [7:0] DATA_OUT;
wire VMA;
reg [5:0] CLK;
// Gime Regs
reg [1:0] ROM;
reg RAM;
reg ST_SCS;
reg VEC_PAG_RAM;
reg GIME_FIRQ;
reg GIME_IRQ;
reg MMU_EN;
reg COCO1;
reg [2:0] V;
reg [6:0] VERT;
reg RATE;
reg TIMER_INS;
reg MMU_TR;
reg IRQ_TMR;
reg IRQ_HBORD;
reg IRQ_VBORD;
reg IRQ_KEY;
reg IRQ_CART;
reg FIRQ_TMR;
reg FIRQ_HBORD;
reg FIRQ_VBORD;
reg FIRQ_KEY;
reg FIRQ_CART;
reg [3:0] TMR_MSB;
reg [7:0] TMR_LSB;
reg TMR_ENABLE;
reg TIMER_N;
reg [1:0] TIMER_STATE;
wire TIMER_R;
reg [15:0] VIDEO_BUFFER;
reg GRMODE;
reg DESCEN;
reg BLINK;
reg MONO;
reg HLPR;
reg [2:0] LPR;
reg [1:0] LPF;
reg [3:0] HRES;
reg [1:0] CRES;
reg [3:0] VERT_FIN_SCRL;
reg [1:0] SCRN_START_HSB; // 2 extra bits for 2MB
reg [7:0] SCRN_START_MSB;
reg [7:0] SCRN_START_LSB;
reg [6:0] HOR_OFFSET;
reg HVEN;
reg [11:0] PALETTE [16:0];
wire [8:0] COLOR;
reg HSYNC_INT;
reg HSYNC_POL;
reg [1:0] SEL;
reg [7:0] KEY_COLUMN;
reg VSYNC_INT;
reg VSYNC_POL;
reg [3:0] VDG_CONTROL;
reg CSS;
reg CART_INT;
reg CART_POL;
reg CD_INT;
reg CD_POL;
reg CAS_MTR;
reg SOUND_EN;
wire [19:0] VIDEO_ADDRESS; // 2MB 17:0 for 512kb
wire ROM_RW;
wire FLASH_CE_S;
wire ENA_DSK;
wire ENA_ORCC;
wire ENA_LOAD;
wire ENA_PAK;
wire HDD_EN;
wire HDD_EN_DATA;
reg [1:0] MPI_SCS; // IO select
reg [1:0] MPI_CTS; // ROM select
reg [1:0] W_PROT;
reg SBS;
reg [7:0] SAM00; // 2MB 5:0 for 512kb
reg [7:0] SAM01;
reg [7:0] SAM02;
reg [7:0] SAM03;
reg [7:0] SAM04;
reg [7:0] SAM05;
reg [7:0] SAM06;
reg [7:0] SAM07;
reg [7:0] SAM10;
reg [7:0] SAM11;
reg [7:0] SAM12;
reg [7:0] SAM13;
reg [7:0] SAM14;
reg [7:0] SAM15;
reg [7:0] SAM16;
reg [7:0] SAM17;
wire [55:0] KEY;
wire SHIFT_OVERRIDE;
wire SHIFT;
wire [7:0] KEYBOARD_IN;
reg DDR1;
reg DDR2;
reg DDR3;
reg DDR4;
wire [7:0] DATA_REG1;
wire [7:0] DATA_REG2;
wire [7:0] DATA_REG3;
wire [7:0] DATA_REG4;
reg [7:0] DD_REG1;
reg [7:0] DD_REG2;
reg [7:0] DD_REG3;
reg [7:0] DD_REG4;
wire ROM_SEL;
reg [5:0] DTOA_CODE;
reg [5:0] SOUND_DTOA;
wire [7:0] SOUND;
wire [18:0] DAC_LEFT;
wire [18:0] DAC_RIGHT;
wire [7:0] VU;
wire [7:0] VUM;
reg [18:0] LEFT;
reg [18:0] RIGHT;
reg [7:0] ORCH_LEFT;
reg [7:0] ORCH_RIGHT;
reg [7:0] ORCH_LEFT_EXT;
reg [7:0] ORCH_RIGHT_EXT;
reg DACLRCLK;
reg ADCLRCLK;
reg [5:0] DAC_STATE;
wire H_FLAG;
reg [1:0] SWITCH_L;
wire KEY_INT_RAW;
reg HS_INT;
reg H_SYNC_IRQ_N;
reg [1:0] HS_INT_SM;
reg VS_INT;
reg V_SYNC_IRQ_N;
reg [1:0] VS_INT_SM;
reg CART1_INT;
reg [1:0] CART1_INT_SM;
reg TMR_INT;
reg [1:0] TMR_INT_SM;
reg HBORD_INT;
reg [1:0] HBORD_INT_SM;
reg VBORD_INT;
reg [1:0] VBORD_INT_SM;
reg KEY_INT;
reg [1:0] KEY_INT_SM;
reg CAR_INT;
reg [1:0] CAR_INT_SM;
reg TMR_FINT;
reg [1:0] TMR_FINT_SM;
reg HBORD_FINT;
reg [1:0] HBORD_FINT_SM;
reg VBORD_FINT;
reg [1:0] VBORD_FINT_SM;
reg KEY_FINT;
reg [1:0] KEY_FINT_SM;
reg CAR_FINT;
reg [1:0] CAR_FINT_SM;
wire CPU_IRQ;
wire CPU_FIRQ;
reg [2:0] DIV_7;
reg DIV_14;
reg [12:0] TIMER;
wire TMR_CLK;
wire SER_IRQ;
reg CART_IRQ;
reg [4:0] COM1_STATE;
reg [12:0] COM2_STATE;
reg COM1_CLOCK_X;
reg COM1_CLOCK;
reg [2:0] COM1_CLK;
wire [7:0] DATA_HDD;
wire RS232_EN;
wire RX_CLK2;
wire [7:0] DATA_RS232;
reg [2:0] ROM_BANK;
reg [1:0] BANK_SIZE;
reg [6:0] BANK0;
reg [6:0] BANK1;
reg [6:0] BANK2;
reg [6:0] BANK3;
reg [6:0] BANK4;
reg [6:0] BANK5;
reg [6:0] BANK6;
reg [6:0] BANK7;
wire SLOT3_HW;
wire UART51_TXD;
wire UART51_RXD;
wire UART51_RTS;
wire UART51_DTR;
wire UART50_TXD;
wire UART50_RXD;
wire UART50_RTS;
// Clock
reg [4:0] CENT;
reg [6:0] YEAR;
reg [3:0] MNTH;
reg [4:0] DMTH;
reg [2:0] DWK;
reg [4:0] HOUR;
reg [5:0] MIN;
reg [5:0] SEC;
reg [5:0] CLICK;
reg TICK0;
reg TICK1;
reg TICK2;
// Joystick
reg [12:0] JOY_CLK;
reg [9:0] PADDLE_ZERO_0;
reg [9:0] PADDLE_ZERO_1;
reg [9:0] PADDLE_ZERO_2;
reg [9:0] PADDLE_ZERO_3;
reg [11:0] PADDLE_VAL_0;
reg [11:0] PADDLE_VAL_1;
reg [11:0] PADDLE_VAL_2;
reg [11:0] PADDLE_VAL_3;
reg [11:0] PADDLE_LATCH_0;
reg [11:0] PADDLE_LATCH_1;
reg [11:0] PADDLE_LATCH_2;
reg [11:0] PADDLE_LATCH_3;
reg [1:0] PADDLE_STATE_0;
reg [1:0] PADDLE_STATE_1;
reg [1:0] PADDLE_STATE_2;
reg [1:0] PADDLE_STATE_3;
reg [5:0] JOY1_COUNT;
reg [5:0] JOY2_COUNT;
reg [5:0] JOY3_COUNT;
reg [5:0] JOY4_COUNT;
reg JOY_TRIGGER;
wire JSTICK;
wire JOY1;
wire JOY2;
wire JOY3;
wire JOY4;
reg MOTOR;
reg WRT_PREC;
reg DENSITY;
reg HALT_EN;
reg [7:0] COMMAND;
reg [7:0] SECTOR;
reg [7:0] DATA_EXT;
reg [7:0] STATUS;
reg IRQ_02_N;
reg IRQ_02_BUF0_N;
reg IRQ_02_BUF1_N;
wire IRQ_02_UART;
wire NMI_09;
reg HALT_BUF0;
reg HALT_BUF1;
reg HALT_BUF2;
reg HALT_SIG_BUF0;
reg HALT_SIG_BUF1;
reg [6:0] HALT_STATE;
wire PH2_02;
wire [15:0] ADDRESS_02;
wire [7:0] CPU_BANK;
wire [7:0] DATA_OUT_02;
wire [7:0] DATA_IN_02;
wire [7:0] DATA_COM1;
reg [8:0] BUFF_ADD;
reg ADDR_RESET_N;
reg IMM_HALT_09;
wire COM1_EN;
reg [7:0] TRACK_REG_R;
reg [7:0] TRACK_REG_W;
reg [7:0] TRACK_EXT_R;
reg [7:0] TRACK_EXT_W;
reg NMI_09_EN;
wire IRQ_09;
reg IRQ_RESET;
reg BUSY0;
reg BUSY1;
reg [7:0] DRIVE_SEL_EXT;
wire [3:0] HEXX;
wire HALT;
reg FORCE_NMI_09_BUF0;
reg FORCE_NMI_09_BUF1;
reg ADDR_RST_BUFF0_N;
reg ADDR_RST_BUFF1_N;
reg [7:0] TRACE;
reg HALT_100_09;
reg IRQ_09_EN;
reg ADDR_100_BUF0;
reg ADDR_100_BUF1;
reg IRQ_09_BUF0;
reg IRQ_09_BUF1;
reg IRQ_09_BUF2;
reg CMD_RST;
reg WAIT_HALT;
reg CMD_RST_BUF0;
reg CMD_RST_BUF1;
wire CPU_RESET_N;
wire RW_02_N;
wire DISKBUF_02;
wire [7:0] DISK_BUF_Q;
reg [7:0] DATA_REG;
wire HALT_CODE;
wire RAM02_00_EN;
wire [7:0] DATAO_02_HDD;
wire [7:0] DATAO_09_HDD;
wire FFF0_EN;
wire [7:0] DATAO_FFF0;
reg [7:0] TRACK1;
reg [7:0] TRACK2;
reg [7:0] HEADS;
wire RDFIFO_RDREQ;
wire RDFIFO_WRREQ;
wire WRFIFO_RDREQ;
wire WRFIFO_WRREQ;
wire [7:0] RDFIFO_DATA;
wire [7:0] WRFIFO_DATA;
wire RDFIFO_RDEMPTY;
wire RDFIFO_WRFULL;
wire WRFIFO_RDEMPTY;
wire WRFIFO_WRFULL;
reg BI_IRQ_EN;
wire UART1_CLK;
reg [11:0] MCLOCK;
wire I2C_SCL_EN;
wire I2C_DAT_EN;
reg [7:0] I2C_DEVICE;
reg [7:0] I2C_REG;
wire [7:0] I2C_DATA_IN;
reg [7:0] I2C_DATA_OUT;
wire I2C_DONE;
reg [1:0] I2C_DONE_BUF;
wire I2C_FAIL;
reg I2C_START;
wire [7:0] SPI_DATA;
wire SPI_EN;
wire act_led_n;
wire IRQ_SPI_N;
`ifdef SD_DEBUG
wire SPI_TRACE;
reg [7:0] SPI_T;
reg [7:0] SPI_IN;
reg [7:0] SPI_OUT;
`endif
wire EF;
wire VDA;
wire MF;
wire VPA;
wire ML_N;
wire XF;
wire SYNC;
wire VP_N;
reg ODD_LINE;
wire SPI_HALT;
reg [20:0] GART_WRITE; // 2MB 18:0 for 512kb
reg [20:0] GART_READ;
reg [1:0] GART_INC;
`ifdef FLPY_DEBUG
assign LEDG = TRACE; // Floppy Trace
`endif
`ifdef SD_DEBUG
assign LEDG = SPI_T;
`endif // SD Trace
`ifdef NO_DEBUG
//assign LEDG = {COCO1, V, VDG_CONTROL};
assign LEDG[0]= (RAM0_CS & RAM0_BE0);
assign LEDG[1]= (RAM0_CS & RAM0_BE1);
assign LEDG[2]= FLASH_CE_S;
assign LEDG[3]= HDD_EN;
assign LEDG[4]= HALT_BUF2;
assign LEDG[5]= RS232_EN;
assign LEDG[6]= SPI_EN;
assign LEDG[7]= KEY[55];
`endif
assign LEDR[0] = DRIVE_SEL_EXT[0] & MOTOR;
assign LEDR[1] = DRIVE_SEL_EXT[1] & MOTOR;
assign LEDR[2] = DRIVE_SEL_EXT[2] & MOTOR;
assign LEDR[3] = DRIVE_SEL_EXT[3] & MOTOR;
assign LEDR[4] = ~UART50_TXD;
assign LEDR[5] = ~UART50_RXD;
assign LEDR[6] = !RESET_N;
assign LEDR[7] = !BUTTON_N[2] & (BUTTON_N[1] | SWITCH[6]); // SD Card Write Protected when SD Card Inserted
assign LEDR[8] = !BUTTON_N[2]; // SD Card inserted
//assign LEDR[9] = !act_led_n; A18 of 1MB SRAM
`ifdef BUSA
assign TEST_1 = MOSI;
assign TEST_2 = MISO;
assign TEST_3 = SPI_CLK;
assign TEST_4 = SPI_SS_N;
`else
assign TEST_1 = CPU_IRQ;
assign TEST_2 = CPU_FIRQ;
`endif
//Master clock divider chain
// MCLOCK[0] = 50/2 = 25 MHz
// MCLOCK[1] = 50/4 = 12.5 MHz
// MCLOCK[2] = 50/8 = 6.25 MHz
// MCLOCK[3] = 50/16 = 3.125 MHz
// MCLOCK[4] = 50/32 = 1.5625 MHz
// MCLOCK[5] = 50/64 = 781.25 KHz
// MCLOCK[6] = 50/128 = 390.625 KHz
// MCLOCK[7] = 50/256 = 195.125 KHz
// MCLOCK[8] = 50/512 = 97.65625 KHz
// MCLOCK[9] = 50/1024 = 48.828125 KHz
// MCLOCK[10] = 50/2048 = 24.4140625 KHz
// MCLOCK[11] = 50/4096 = 12.20703125 KHz
always @ (negedge CLK50MHZ) //50 MHz
MCLOCK <= MCLOCK + 1'b1;
`ifndef SD_DEBUG
assign SEGMENT0_N = {7'b0100011}; //o
assign SEGMENT1_N = {7'b1000110}; //C
assign SEGMENT2_N = {7'b0100011}; //o
assign SEGMENT3_N = {7'b1000110}; //C
`else
always @ (negedge V_SYNC) // Anything > 200 HZ
case(DIGIT_N)
4'b1110: DIGIT_N <= 4'b1101;
4'b1101: DIGIT_N <= 4'b1011;
4'b1011: DIGIT_N <= 4'b0111;
default: DIGIT_N <= 4'b1110;
endcase
always @ (negedge V_SYNC)
begin
case (DIGIT_N)
4'b1110:
SEGMENT0_N <= SEGMENT_N;
4'b1101:
SEGMENT1_N <= SEGMENT_N;
4'b1011:
SEGMENT2_N <= SEGMENT_N;
default:
SEGMENT3_N <= SEGMENT_N;
endcase
end
assign SEGMENT_N = (HEXX == 4'h0) ? {7'b1000000}: //0
(HEXX == 4'h1) ? {7'b1111001}: //1
(HEXX == 4'h2) ? {7'b0100100}: //2
(HEXX == 4'h3) ? {7'b0110000}: //3
(HEXX == 4'h4) ? {7'b0011001}: //4
(HEXX == 4'h5) ? {7'b0010010}: //5
(HEXX == 4'h6) ? {7'b0000010}: //6
(HEXX == 4'h7) ? {7'b1111000}: //7
(HEXX == 4'h8) ? {7'b0000000}: //8
(HEXX == 4'h9) ? {7'b0011000}: //9
(HEXX == 4'hA) ? {7'b0001000}: //A
(HEXX == 4'hB) ? {7'b0000011}: //B
(HEXX == 4'hC) ? {7'b1000110}: //C
(HEXX == 4'hD) ? {7'b0100001}: //D
(HEXX == 4'hE) ? {7'b0000110}: //E
{7'b0001110}; //F
assign HEXX = ({DIGIT_N} == 4'b1110) ? SPI_IN[3:0]:
({DIGIT_N} == 4'b1101) ? SPI_IN[7:4]:
({DIGIT_N} == 4'b1011) ? SPI_OUT[3:0]:
SPI_OUT[7:4];
`endif
/*****************************************************************************
* RAM signals
******************************************************************************/
assign RAM0_BE0 = (ADDRESS == 16'hFF73) ? !GART_READ[0]:
!ADDRESS[0]; // Not SRAM signls
assign RAM0_BE1 = (ADDRESS == 16'hFF73) ? GART_READ[0]:
ADDRESS[0];
assign BLOCK_ADDRESS = ({MMU_EN, MMU_TR, ADDRESS[15:13]} == 5'b10000) ? SAM00: // 10 000X 0000-1FFF
({MMU_EN, MMU_TR, ADDRESS[15:13]} == 5'b10001) ? SAM01: // 10 001X 2000-3FFF
({MMU_EN, MMU_TR, ADDRESS[15:13]} == 5'b10010) ? SAM02: // 10 010X 4000-5FFF
({MMU_EN, MMU_TR, ADDRESS[15:13]} == 5'b10011) ? SAM03: // 10 011X 6000-7FFF
({ROM_SEL, MMU_EN, MMU_TR, ADDRESS[15:13]} == 6'b010100) ? SAM04: //010 100X 8000-9FFF
({ROM_SEL, MMU_EN, MMU_TR, ADDRESS[15:13]} == 6'b010101) ? SAM05: //010 101X A000-BFFF
({ROM_SEL, MMU_EN, MMU_TR, ADDRESS[15:13]} == 6'b010110) ? SAM06: //010 110X C000-DFFF
({ROM_SEL, MMU_EN, MMU_TR, ADDRESS[15:12]} == 7'b0101110) ? SAM07: //010 1110 X E000-EFFF
({ROM_SEL, MMU_EN, MMU_TR, ADDRESS[15:11]} == 8'b01011110) ? SAM07: //010 1111 0X F000-F7FF
({ROM_SEL, MMU_EN, MMU_TR, ADDRESS[15:10]} == 9'b010111110) ? SAM07: //010 1111 10X F800-FBFF
({ROM_SEL, MMU_EN, MMU_TR, ADDRESS[15:9]} == 10'b0101111110)? SAM07: //010 1111 110X FC00-FDFF
({VEC_PAG_RAM, MMU_EN, MMU_TR, ADDRESS[15:8]} == 11'b01011111110) ? SAM07: //010 1111 1110 X FE00-FEFF Vector page as RAM
({MMU_EN, MMU_TR, ADDRESS[15:13]} == 5'b11000) ? SAM10: // 11 000X
({MMU_EN, MMU_TR, ADDRESS[15:13]} == 5'b11001) ? SAM11: // 11 001X
({MMU_EN, MMU_TR, ADDRESS[15:13]} == 5'b11010) ? SAM12: // 11 010X
({MMU_EN, MMU_TR, ADDRESS[15:13]} == 5'b11011) ? SAM13: //011 011X
({ROM_SEL, MMU_EN, MMU_TR, ADDRESS[15:13]} == 6'b011100) ? SAM14: //011 100X
({ROM_SEL, MMU_EN, MMU_TR, ADDRESS[15:13]} == 6'b011101) ? SAM15: //011 101X
({ROM_SEL, MMU_EN, MMU_TR, ADDRESS[15:13]} == 6'b011110) ? SAM16: //011 110X
({ROM_SEL, MMU_EN, MMU_TR, ADDRESS[15:12]} == 7'b0111110) ? SAM17: //011 1110 X E000-EFFF
({ROM_SEL, MMU_EN, MMU_TR, ADDRESS[15:11]} == 8'b01111110) ? SAM17: //011 1111 0X F000-F7FF
({ROM_SEL, MMU_EN, MMU_TR, ADDRESS[15:10]} == 9'b011111110) ? SAM17: //011 1111 10X F800-FBFF
({ROM_SEL, MMU_EN, MMU_TR, ADDRESS[15:9]} == 10'b0111111110)? SAM17: //011 1111 110X FC00-FDFF
({VEC_PAG_RAM, MMU_EN, MMU_TR, ADDRESS[15:8]} == 11'b01111111110) ? SAM17: //011 1111 1110 X FE00-FEFF Vector page as RAM
{5'b00111,ADDRESS[15:13]}; // {3'b111,ADDRESS[15:13]} on 512kb
//CS and OE hardcoded low for WRITE CYCLE #3 in EDBLL datasheet
// Same for both SRAM chips
assign RAM0_CS_N = 1'b0; // Actual RAM CS is always enabled
assign RAM0_OE_N = 1'b0;
assign RAM0_CS = (ROM_SEL) ? 1'b0: // Any slot
({RAM, ADDRESS[15:14]} == 3'b010) ? 1'b0: // ROM (8000-BFFF)
({RAM, ADDRESS[15:13]} == 4'b0110) ? 1'b0: // ROM (C000-DFFF)
({RAM, ADDRESS[15:12]} == 5'b01110) ? 1'b0: // ROM (E000-EFFF)
({RAM, ADDRESS[15:11]} == 6'b011110) ? 1'b0: // ROM (F000-F8FF)
({RAM, ADDRESS[15:10]} == 7'b0111110) ? 1'b0: // ROM (F800-FBFF)
({RAM, ADDRESS[15:9]} == 8'b01111110) ? 1'b0: // ROM (FC00-FDFF)
// FE00-FEFF enabled unless turned off by BLOCK_ADDRESS[6]=1
({ADDRESS[15:0]}== 16'hFF73) ? 1'b1: // GART
({ADDRESS[15:8]}== 8'hFF) ? 1'b0: // Hardware (FF00-FFFF)
1'b1; // 0K - 512K
/*****************************************************************************
* ROM signals
******************************************************************************/
// ROM_SEL is 1 when the system is accessing any cartridge "ROM" meaning the
// 4 slots of the MPI, this is:
// Slot 1 RS232 ROM
// Slot 2 Cart loader ROM
// Slot 3 Cart slot
// Slot 4 Disk Controller ROM
assign ROM_SEL =( RAM == 1'b1) ? 1'b0: // All RAM Mode
( ROM == 2'b10) ? 1'b0: // All Internal
({ROM[1], ADDRESS[15:14]} == 3'b010) ? 1'b0: // Lower (Internal) 16 Internal+16 external
( ADDRESS[15] == 1'b0) ? 1'b0: // Lower 32K
( ADDRESS[15:8] == 8'hFE) ? 1'b0: // Vector space
( ADDRESS[15:8] == 8'hFF) ? 1'b0: // Hardware space
1'b1;
//ROM
//00 16 Internal + 16 External
//01 16 Internal + 16 External
//10 32 Internal
//11 32 External
assign FLASH_ADDRESS = ENA_DSK ? {9'b000000100, ADDRESS[12:0]}: //8K Disk BASIC 8K Slot 4
ENA_LOAD ? {8'b00000011, ADDRESS[13:0]}: //ROM Loader 16K Slot 2 or maybe SDCard Boot
ENA_ORCC ? {9'b000000101, ADDRESS[12:0]}: //8K Orchestra 8K 90CC Slot 1
// Slot 3 ROMPak
({ENA_PAK,BANK_SIZE,ROM_BANK}== 6'b100000) ? {BANK0, ADDRESS[14:0]}:
({ENA_PAK,BANK_SIZE,ROM_BANK}== 6'b110000) ? {BANK0, ADDRESS[14:0]}:
({ENA_PAK,BANK_SIZE,ROM_BANK}== 6'b101000) ? {BANK0,1'b0,ADDRESS[13:0]}:
({ENA_PAK,BANK_SIZE,ROM_BANK}== 6'b111000) ? {BANK0,1'b1,ADDRESS[13:0]}:
({ENA_PAK,BANK_SIZE,ROM_BANK}== 6'b100001) ? {BANK1, ADDRESS[14:0]}:
({ENA_PAK,BANK_SIZE,ROM_BANK}== 6'b110001) ? {BANK1, ADDRESS[14:0]}:
({ENA_PAK,BANK_SIZE,ROM_BANK}== 6'b101001) ? {BANK1,1'b0,ADDRESS[13:0]}:
({ENA_PAK,BANK_SIZE,ROM_BANK}== 6'b111001) ? {BANK1,1'b1,ADDRESS[13:0]}:
({ENA_PAK,BANK_SIZE,ROM_BANK}== 6'b100010) ? {BANK2, ADDRESS[14:0]}:
({ENA_PAK,BANK_SIZE,ROM_BANK}== 6'b110010) ? {BANK2, ADDRESS[14:0]}:
({ENA_PAK,BANK_SIZE,ROM_BANK}== 6'b101010) ? {BANK2,1'b0,ADDRESS[13:0]}:
({ENA_PAK,BANK_SIZE,ROM_BANK}== 6'b111010) ? {BANK2,1'b1,ADDRESS[13:0]}:
({ENA_PAK,BANK_SIZE,ROM_BANK}== 6'b100011) ? {BANK3, ADDRESS[14:0]}:
({ENA_PAK,BANK_SIZE,ROM_BANK}== 6'b110011) ? {BANK3, ADDRESS[14:0]}:
({ENA_PAK,BANK_SIZE,ROM_BANK}== 6'b101011) ? {BANK3,1'b0,ADDRESS[13:0]}:
({ENA_PAK,BANK_SIZE,ROM_BANK}== 6'b111011) ? {BANK3,1'b1,ADDRESS[13:0]}:
({ENA_PAK,BANK_SIZE,ROM_BANK}== 6'b100100) ? {BANK4, ADDRESS[14:0]}:
({ENA_PAK,BANK_SIZE,ROM_BANK}== 6'b110100) ? {BANK4, ADDRESS[14:0]}:
({ENA_PAK,BANK_SIZE,ROM_BANK}== 6'b101100) ? {BANK4,1'b0,ADDRESS[13:0]}:
({ENA_PAK,BANK_SIZE,ROM_BANK}== 6'b111100) ? {BANK4,1'b1,ADDRESS[13:0]}:
({ENA_PAK,BANK_SIZE,ROM_BANK}== 6'b100101) ? {BANK5, ADDRESS[14:0]}:
({ENA_PAK,BANK_SIZE,ROM_BANK}== 6'b110101) ? {BANK5, ADDRESS[14:0]}:
({ENA_PAK,BANK_SIZE,ROM_BANK}== 6'b101101) ? {BANK5,1'b0,ADDRESS[13:0]}:
({ENA_PAK,BANK_SIZE,ROM_BANK}== 6'b111101) ? {BANK5,1'b1,ADDRESS[13:0]}:
({ENA_PAK,BANK_SIZE,ROM_BANK}== 6'b100110) ? {BANK6, ADDRESS[14:0]}:
({ENA_PAK,BANK_SIZE,ROM_BANK}== 6'b110110) ? {BANK6, ADDRESS[14:0]}:
({ENA_PAK,BANK_SIZE,ROM_BANK}== 6'b101110) ? {BANK6,1'b0,ADDRESS[13:0]}:
({ENA_PAK,BANK_SIZE,ROM_BANK}== 6'b111110) ? {BANK6,1'b1,ADDRESS[13:0]}:
({ENA_PAK,BANK_SIZE,ROM_BANK}== 6'b100111) ? {BANK7, ADDRESS[14:0]}:
({ENA_PAK,BANK_SIZE,ROM_BANK}== 6'b110111) ? {BANK7, ADDRESS[14:0]}:
({ENA_PAK,BANK_SIZE,ROM_BANK}== 6'b101111) ? {BANK7,1'b0,ADDRESS[13:0]}:
({ENA_PAK,BANK_SIZE,ROM_BANK}== 6'b111111) ? {BANK7,1'b1,ADDRESS[13:0]}:
{7'b0000000, ADDRESS[14:0]};
assign FLASH_WE_N = 1'b1;
assign FLASH_CE_N = 1'b0;
assign FLASH_OE_N = 1'b0;
assign FLASH_CE_S = ({RAM, ROM[1], ADDRESS[15:14]} == 4'b0010) ? 1'b1: // Internal 32K ROM 8000-BFFF
({RAM, ROM, ADDRESS[15:13]} == 6'b010110) ? 1'b1: // Internal 32K ROM C000-DFFF
({RAM, ROM, ADDRESS[15:12]} == 7'b0101110) ? 1'b1: // Internal 32K ROM E000-EFFF
({RAM, ROM, ADDRESS[15:11]} == 8'b01011110) ? 1'b1: // Internal 32K ROM F000-F7FF
({RAM, ROM, ADDRESS[15:14]} == 5'b01010) ? 1'b1: // Internal 16K ROM 8000-B7FF
({RAM, ROM, ADDRESS[15:10]} == 9'b010111110) ? 1'b1: // Internal ROM F800-F8FF
({RAM, ROM, ADDRESS[15:8]} == 11'b01011111100) ? 1'b1: // Internal ROM FC00-FCFF
({RAM, ROM, ADDRESS[15:8]} == 11'b01011111101) ? 1'b1: // Internal ROM FD00-FDFF
ENA_DSK ? 1'b1:
ENA_PAK ? 1'b1:
ENA_LOAD ? 1'b1:
ENA_ORCC ? 1'b1:
1'b0;
assign FFF0_EN = ({ADDRESS[15:4]} == 12'b111111111111) ? 1'b1: // Vectors
1'b0;
assign FLASH_RESET_N = RESET_N;
assign ENA_DSK = ({ROM_SEL, MPI_CTS, ADDRESS[15:13]} == 6'b111110) ? 1'b1: // Disk C000-DFFF Slot 4
1'b0;
assign ENA_ORCC = ({ROM_SEL, MPI_CTS, ADDRESS[15:13]} == 6'b100110) ? 1'b1: // Orchestra-90CC C000-DFFF Slot 1
1'b0;
assign ENA_LOAD = ({ROM_SEL, MPI_CTS, ADDRESS[15:13]} == 6'b001110) ? 1'b1: // ROM Loader C000-DFFF Slot 2
1'b0;
assign ENA_PAK = ({ROM_SEL, MPI_CTS, ADDRESS[15]} == 4'b1101) ? 1'b1: // ROM SLOT 3
1'b0;
assign HDD_EN = ({MPI_SCS, ADDRESS[15:4]} == 14'b11111111110100) ? 1'b1: //FF40-FF4F with MPI switch = 4
1'b0;
`ifdef RS232PAK
assign RS232_EN = (ADDRESS[15:2] == 14'b11111111011010) ? 1'b1: //FF68-FF6B
`else
assign RS232_EN =
`endif
1'b0;
assign SPI_EN = (ADDRESS[15:1] == 15'b111111110110010); // SPI FF64-FF65
`ifdef SD_DEBUG
assign SPI_TRACE = (ADDRESS[15:1] == 15'b111111110110011); // SPI FF66-FF67
`endif
assign SLOT3_HW = ({MPI_SCS, ADDRESS[15:5]} == 13'b1011111111010) ? 1'b1: // FF40-FF5F
1'b0;
always @(negedge PH_2 or negedge RESET_N)
begin
if(!RESET_N)
begin
ROM_BANK <= 3'b000;
end
else
begin
if({SLOT3_HW, RW_N} == 2'b10)
case (ADDRESS[4:0])
5'h00:
begin
ROM_BANK <= DATA_OUT[2:0];
end
5'h02:
begin
BANK0 <= DATA_OUT[6:0];
end
5'h03:
begin