OpenCores
URL https://opencores.org/ocsvn/System09/System09/trunk

Subversion Repositories System09

[/] [System09/] [trunk/] [rtl/] [System09_BurchED_B5-X300/] [System09_BurchED_B5-X300.vhd] - Blame information for rev 107

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 19 dilbert57
--===========================================================================----
2
--
3
--  S Y N T H E Z I A B L E    System09 - SOC.
4
--
5
--  www.OpenCores.Org - September 2003
6
--  This core adheres to the GNU public license  
7
--
8
-- File name      : System09.vhd
9
--
10
-- Purpose        : Top level file for 6809 compatible system on a chip
11
--                  Designed with Xilinx XC2S300e Spartan 2+ FPGA.
12
--                  Implemented With BurchED B5-X300 FPGA board,
13
--                  B5-SRAM module, B5-CF module and B5-FPGA-CPU-IO module
14
--
15
-- Dependencies   : ieee.Std_Logic_1164
16
--                  ieee.std_logic_unsigned
17
--                  ieee.std_logic_arith
18
--                  ieee.numeric_std
19
--
20
-- Uses           : 
21
--                  cpu09      (cpu09.vhd)      CPU core
22
--                  mon_rom    (sys09bug_rom2k_b4.vhd) Monitor ROM
23
--                  dat_ram    (datram.vhd)     Dynamic Address Translation
24
--                  acia_6850  (ACIA_6850.vhd) ACIA / MiniUART
25
--                             (ACIA_RX.vhd)
26
--                             (ACIA_TX.vhd)
27
--                  ACIA_Clock (ACIA_Clock.vhd) ACIA Baud Clock Divider
28
--                  keyboard   (keyboard.vhd)   PS/2 Keyboard Interface
29
--                  vdu8       (vdu8.vhd)       80 x 25 Video Display
30
--                  timer      (timer.vhd)      Timer module
31
--                  trap            (trap.vhd)       Bus Trap interrupt
32
--                  ioport     (ioport.vhd)     Parallel I/O port.
33
-- 
34
-- Author         : John E. Kent      
35
--                  dilbert57@opencores.org      
36
--      Memory Map     :
37
-- $E000 - ACIA (SWTPc)
38
-- $E010 - Reserved for FD1771 FDC (SWTPc)
39
-- $E020 - Keyboard
40
-- $E030 - VDU
41
-- $E040 - Compact Flash
42
-- $E050 - Timer
43
-- $E060 - Bus trap
44
-- $E070 - Parallel I/O
45
-- $E080 - Reserved for 6821 PIA (?) (SWTPc)
46
-- $E090 - Reserved for 6840 PTM (?) (SWTPc)
47
--
48
--===========================================================================----
49
--
50
-- Revision History:
51
--===========================================================================--
52
-- Version 0.1 - 20 March 2003
53
-- Version 0.2 - 30 March 2003
54
-- Version 0.3 - 29 April 2003
55
-- Version 0.4 - 29 June 2003
56
--
57
-- Version 0.5 - 19 July 2003
58
-- prints out "Hello World"
59
--
60
-- Version 0.6 - 5 September 2003
61
-- Runs SBUG
62
--
63
-- Version 1.0- 6 Sep 2003 - John Kent
64
-- Inverted SysClk
65
-- Initial release to Open Cores
66
--
67
-- Version 1.1 - 17 Jan 2004 - John Kent
68
-- Updated miniUart.
69
--
70
-- Version 1.2 - 25 Jan 2004 - John Kent
71
-- removed signals "test_alu" and "test_cc" 
72
-- Trap hardware re-instated.
73
--
74
-- Version 1.3 - 11 Feb 2004 - John Kent
75
-- Designed forked off to produce System09_VDU
76
-- Added VDU component
77
--      VDU runs at 25MHz and divides the clock by 2 for the CPU
78
-- UART Runs at 57.6 Kbps
79
--
80
-- Version 1.4 - 21 Nov 2004 - John Kent
81
-- Changes to make compatible with Spartan3 starter kit version
82
-- Designed to run with a 50MHz clock input.
83
-- the VDU divides 50 MHz to generate a 
84
-- 25 MHz VDU Pixel Clock and a 12.5 MHz CPU clock
85
-- Changed Monitor ROM signals to make it look like
86
-- a standard 2K memory block
87
-- Re-assigned I/O port assignments so it is possible to run KBUG9
88
-- $E000 - ACIA
89
-- $E010 - Keyboard
90
-- $E020 - VDU
91
-- $E030 - Compact Flash
92
-- $E040 - Timer
93
-- $E050 - Bus trap
94
-- $E060 - Parallel I/O
95
--
96
-- Version 1.5 - 3rd February 2007 - John Kent
97
-- Changed VDU8 to use external clock divider
98
-- renamed miniUART to ACIA_6850
99
-- Memory decoding of ROM & IO now uses DAT
100
--
101
-- Version 1.6 - 7th Februaury 2007 - John Kent
102
-- Made ACIA Clock generator an external component
103
-- Added Generics to VDU and Keyboard
104
-- Changed decoding
105
--
106
-- Version 1.7 - 20th May 2007 - John Kent
107
-- Added 4 wait states to CF access
108
-- Removed DAT memory map control of ROM & IO
109
-- to allow for full use of RAM as a RAM disk.
110
-- Mapped in all 16 bits of the CF data bus.
111
-- 
112
--===========================================================================
113
--
114
library ieee;
115
   use ieee.std_logic_1164.all;
116
   use IEEE.STD_LOGIC_ARITH.ALL;
117
   use IEEE.STD_LOGIC_UNSIGNED.ALL;
118
   use ieee.numeric_std.all;
119
library unisim;
120
        use unisim.vcomponents.all;
121
 
122
entity System09 is
123
  port(
124
    SysClk      : in  Std_Logic;  -- System Clock input
125
         Reset_n     : in  Std_logic;  -- Master Reset input (active low)
126
    LED         : out std_logic;  -- Diagnostic LED Flasher
127
 
128
    -- Memory Interface signals
129
    ram_csn     : out Std_Logic;
130
    ram_wrln    : out Std_Logic;
131
    ram_wrun    : out Std_Logic;
132
    ram_addr    : out Std_Logic_Vector(16 downto 0);
133
    ram_data    : inout Std_Logic_Vector(15 downto 0);
134
 
135
         -- Stuff on the peripheral board
136
 
137
         -- PS/2 Keyboard
138
         kb_clock    : inout Std_logic;
139
         kb_data     : inout Std_Logic;
140
 
141
         -- PS/2 Mouse interface
142
--       mouse_clock : in  Std_Logic;
143
--       mouse_data  : in  Std_Logic;
144
 
145
         -- Uart Interface
146
    rxbit       : in  Std_Logic;
147
         txbit       : out Std_Logic;
148
    rts_n       : out Std_Logic;
149
    cts_n       : in  Std_Logic;
150
 
151
         -- CRTC output signals
152
         v_drive     : out Std_Logic;
153
    h_drive     : out Std_Logic;
154
    blue_lo     : out std_logic;
155
    blue_hi     : out std_logic;
156
    green_lo    : out std_logic;
157
    green_hi    : out std_logic;
158
    red_lo      : out std_logic;
159
    red_hi      : out std_logic;
160
--         buzzer      : out std_logic;
161
 
162
-- Compact Flash
163
    cf_rst_n     : out std_logic;
164 22 dilbert57
    cf_cs0_n     : out std_logic;
165
    cf_cs1_n     : out std_logic;
166 19 dilbert57
    cf_rd_n      : out std_logic;
167
    cf_wr_n      : out std_logic;
168
    cf_a         : out std_logic_vector(2 downto 0);
169
    cf_d         : inout std_logic_vector(15 downto 0);
170
 
171
-- Parallel I/O port
172
    porta        : inout std_logic_vector(7 downto 0);
173
    portb        : inout std_logic_vector(7 downto 0);
174
 
175
-- CPU bus
176
         bus_clk      : out std_logic;
177
         bus_reset    : out std_logic;
178
         bus_rw       : out std_logic;
179
         bus_cs       : out std_logic;
180
    bus_addr     : out std_logic_vector(15 downto 0);
181
         bus_data     : inout std_logic_vector(7 downto 0);
182
 
183
-- timer
184
    timer_out    : out std_logic
185
         );
186
end System09;
187
 
188
-------------------------------------------------------------------------------
189
-- Architecture for System09
190
-------------------------------------------------------------------------------
191
architecture rtl of System09 is
192
  -----------------------------------------------------------------------------
193
  -- constants
194
  -----------------------------------------------------------------------------
195
  constant SYS_Clock_Frequency  : integer := 50000000;  -- FPGA System Clock
196
  constant PIX_Clock_Frequency  : integer := 25000000;  -- VGA Pixel Clock
197
  constant CPU_Clock_Frequency  : integer := 12500000;  -- CPU Clock
198
  constant BAUD_Rate            : integer := 57600;       -- Baud Rate
199
  constant ACIA_Clock_Frequency : integer := BAUD_Rate * 16;
200
 
201
  type hold_state_type is ( hold_release_state, hold_request_state );
202
 
203
  -----------------------------------------------------------------------------
204
  -- Signals
205
  -----------------------------------------------------------------------------
206
  -- Monitor ROM
207
  signal rom_data_out  : Std_Logic_Vector(7 downto 0);
208
  signal rom_cs        : std_logic;
209
 
210
  -- UART Interface signals
211
  signal uart_data_out : Std_Logic_Vector(7 downto 0);
212
  signal uart_cs       : Std_Logic;
213
  signal uart_irq      : Std_Logic;
214
  signal uart_clk       : Std_Logic;
215
  signal DCD_n         : Std_Logic;
216
 
217
  -- timer
218
  signal timer_data_out : std_logic_vector(7 downto 0);
219
  signal timer_cs    : std_logic;
220
  signal timer_irq   : std_logic;
221
 
222
  -- trap
223
  signal trap_cs         : std_logic;
224
  signal trap_data_out   : std_logic_vector(7 downto 0);
225
  signal trap_irq        : std_logic;
226
 
227
  -- Parallel I/O port
228
  signal ioport_data_out : std_logic_vector(7 downto 0);
229
  signal ioport_cs    : std_logic;
230
 
231
  -- compact flash port
232
  signal cf_data_out : std_logic_vector(7 downto 0);
233
  signal cf_cs       : std_logic;
234
  signal cf_rd       : std_logic;
235
  signal cf_wr       : std_logic;
236
  signal cf_hold     : std_logic;
237
  signal cf_release  : std_logic;
238
  signal cf_count    : std_logic_vector(3 downto 0);
239
  signal cf_hold_state : hold_state_type;
240
 
241
  -- keyboard port
242
  signal keyboard_data_out : std_logic_vector(7 downto 0);
243
  signal keyboard_cs       : std_logic;
244
  signal keyboard_irq      : std_logic;
245
 
246
  -- RAM
247
  signal ram_cs      : std_logic; -- memory chip select
248
  signal ram_wrl     : std_logic; -- memory write lower
249
  signal ram_wru     : std_logic; -- memory write upper
250
  signal ram_data_out    : std_logic_vector(7 downto 0);
251
 
252
  -- CPU Interface signals
253
  signal cpu_reset    : Std_Logic;
254
  signal cpu_clk      : Std_Logic;
255
  signal cpu_rw       : std_logic;
256
  signal cpu_vma      : std_logic;
257
  signal cpu_halt     : std_logic;
258
  signal cpu_hold     : std_logic;
259
  signal cpu_firq     : std_logic;
260
  signal cpu_irq      : std_logic;
261
  signal cpu_nmi      : std_logic;
262
  signal cpu_addr     : std_logic_vector(15 downto 0);
263
  signal cpu_data_in  : std_logic_vector(7 downto 0);
264
  signal cpu_data_out : std_logic_vector(7 downto 0);
265
 
266
  -- Dynamic address translation
267
  signal dat_cs       : std_logic;
268
  signal dat_addr     : std_logic_vector(7 downto 0);
269
 
270
  -- Video Display Unit
271
  signal pix_clk      : std_logic;
272
  signal vdu_cs       : std_logic;
273
  signal vdu_data_out : std_logic_vector(7 downto 0);
274
  signal vga_red      : std_logic;
275
  signal vga_green    : std_logic;
276
  signal vga_blue     : std_logic;
277
 
278
  -- Flashing Led test signals
279
  signal countL      : std_logic_vector(23 downto 0);
280
  signal clock_div   : std_logic_vector(1 downto 0);
281
 
282
-----------------------------------------------------------------
283
--
284
-- CPU09 CPU core
285
--
286
-----------------------------------------------------------------
287
 
288
component cpu09
289
  port (
290
         clk:        in std_logic;
291
    rst:      in        std_logic;
292
    rw:      out        std_logic;              -- Asynchronous memory interface
293
    vma:             out        std_logic;
294
    address:  out       std_logic_vector(15 downto 0);
295
    data_in:  in        std_logic_vector(7 downto 0);
296
         data_out: out std_logic_vector(7 downto 0);
297
         halt:     in  std_logic;
298
         hold:     in  std_logic;
299
         irq:      in  std_logic;
300
         nmi:      in  std_logic;
301
         firq:     in  std_logic
302
  );
303
end component;
304
 
305
 
306
----------------------------------------
307
--
308
-- SBUG Block RAM Monitor ROM
309
--
310
----------------------------------------
311
component mon_rom
312
    port (
313
       clk   : in  std_logic;
314
       rst   : in  std_logic;
315
       cs    : in  std_logic;
316
       rw    : in  std_logic;
317
       addr  : in  std_logic_vector (10 downto 0);
318
       wdata : in  std_logic_vector (7 downto 0);
319
       rdata : out std_logic_vector (7 downto 0)
320
    );
321
end component;
322
 
323
 
324
----------------------------------------
325
--
326
-- Dynamic Address Translation Registers
327
--
328
----------------------------------------
329
component dat_ram
330
  port (
331
    clk:      in  std_logic;
332
         rst:      in  std_logic;
333
         cs:       in  std_logic;
334
         rw:       in  std_logic;
335
         addr_lo:  in  std_logic_vector(3 downto 0);
336
         addr_hi:  in  std_logic_vector(3 downto 0);
337
    data_in:  in  std_logic_vector(7 downto 0);
338
         data_out: out std_logic_vector(7 downto 0)
339
         );
340
end component;
341
 
342
-----------------------------------------------------------------
343
--
344
-- 6850 ACIA/UART
345
--
346
-----------------------------------------------------------------
347
 
348
component ACIA_6850
349
  port (
350
     clk      : in  Std_Logic;  -- System Clock
351
     rst      : in  Std_Logic;  -- Reset input (active high)
352
     cs       : in  Std_Logic;  -- miniUART Chip Select
353
     rw       : in  Std_Logic;  -- Read / Not Write
354
     irq      : out Std_Logic;  -- Interrupt
355
     Addr     : in  Std_Logic;  -- Register Select
356
     DataIn   : in  Std_Logic_Vector(7 downto 0); -- Data Bus In 
357
     DataOut  : out Std_Logic_Vector(7 downto 0); -- Data Bus Out
358
     RxC      : in  Std_Logic;  -- Receive Baud Clock
359
     TxC      : in  Std_Logic;  -- Transmit Baud Clock
360
     RxD      : in  Std_Logic;  -- Receive Data
361
     TxD      : out Std_Logic;  -- Transmit Data
362
          DCD_n    : in  Std_Logic;  -- Data Carrier Detect
363
     CTS_n    : in  Std_Logic;  -- Clear To Send
364
     RTS_n    : out Std_Logic );  -- Request To send
365
end component;
366
 
367
-----------------------------------------------------------------
368
--
369
-- ACIA Clock divider
370
--
371
-----------------------------------------------------------------
372
 
373
component ACIA_Clock
374
  generic (
375
     SYS_Clock_Frequency  : integer :=  SYS_Clock_Frequency;
376
          ACIA_Clock_Frequency : integer := ACIA_Clock_Frequency
377
  );
378
  port (
379
     clk      : in  Std_Logic;  -- System Clock Input
380
          ACIA_clk : out Std_logic   -- ACIA Clock output
381
  );
382
end component;
383
 
384
----------------------------------------
385
--
386
-- Timer module
387
--
388
----------------------------------------
389
 
390
component timer
391
  port (
392
     clk       : in std_logic;
393
     rst       : in std_logic;
394
     cs        : in std_logic;
395
     rw        : in std_logic;
396
     addr      : in std_logic;
397
     data_in   : in std_logic_vector(7 downto 0);
398
          data_out  : out std_logic_vector(7 downto 0);
399
          irq       : out std_logic;
400
     timer_in  : in std_logic;
401
          timer_out : out std_logic
402
          );
403
end component;
404
 
405
------------------------------------------------------------
406
--
407
-- Bus Trap logic
408
--
409
------------------------------------------------------------
410
 
411
component trap
412
        port (
413
         clk        : in  std_logic;
414
    rst        : in  std_logic;
415
    cs         : in  std_logic;
416
    rw         : in  std_logic;
417
    vma        : in  std_logic;
418
    addr       : in  std_logic_vector(15 downto 0);
419
    data_in    : in  std_logic_vector(7 downto 0);
420
         data_out   : out std_logic_vector(7 downto 0);
421
         irq        : out std_logic
422
  );
423
end component;
424
 
425
----------------------------------------
426
--
427
-- Dual 8 bit Parallel I/O module
428
--
429
----------------------------------------
430
component ioport
431
        port (
432
         clk       : in  std_logic;
433
    rst       : in  std_logic;
434
    cs        : in  std_logic;
435
    rw        : in  std_logic;
436
    addr      : in  std_logic_vector(1 downto 0);
437
    data_in   : in  std_logic_vector(7 downto 0);
438
         data_out  : out std_logic_vector(7 downto 0);
439
         porta_io  : inout std_logic_vector(7 downto 0);
440
         portb_io  : inout std_logic_vector(7 downto 0)
441
         );
442
end component;
443
 
444
----------------------------------------
445
--
446
-- PS/2 Keyboard
447
--
448
----------------------------------------
449
 
450
component keyboard
451
  generic(
452
  KBD_Clock_Frequency : integer := CPU_Clock_Frequency
453
  );
454
  port(
455
  clk             : in    std_logic;
456
  rst             : in    std_logic;
457
  cs              : in    std_logic;
458
  rw              : in    std_logic;
459
  addr            : in    std_logic;
460
  data_in         : in    std_logic_vector(7 downto 0);
461
  data_out        : out   std_logic_vector(7 downto 0);
462
  irq             : out   std_logic;
463
  kbd_clk         : inout std_logic;
464
  kbd_data        : inout std_logic
465
  );
466
end component;
467
 
468
----------------------------------------
469
--
470
-- Video Display Unit.
471
--
472
----------------------------------------
473
component vdu8
474
      generic(
475
        VDU_CLOCK_FREQUENCY    : integer := CPU_Clock_Frequency; -- HZ
476
        VGA_CLOCK_FREQUENCY    : integer := PIX_Clock_Frequency; -- HZ
477
             VGA_HOR_CHARS          : integer := 80; -- CHARACTERS
478
             VGA_VER_CHARS          : integer := 25; -- CHARACTERS
479
             VGA_PIXELS_PER_CHAR    : integer := 8;  -- PIXELS
480
             VGA_LINES_PER_CHAR     : integer := 16; -- LINES
481
             VGA_HOR_BACK_PORCH     : integer := 40; -- PIXELS
482
             VGA_HOR_SYNC           : integer := 96; -- PIXELS
483
             VGA_HOR_FRONT_PORCH    : integer := 24; -- PIXELS
484
             VGA_VER_BACK_PORCH     : integer := 13; -- LINES
485
             VGA_VER_SYNC           : integer := 1;  -- LINES
486
             VGA_VER_FRONT_PORCH    : integer := 36  -- LINES
487
      );
488
      port(
489
                -- control register interface
490
      vdu_clk      : in  std_logic;      -- CPU Clock - 12.5MHz
491
      vdu_rst      : in  std_logic;
492
                vdu_cs       : in  std_logic;
493
                vdu_rw       : in  std_logic;
494
                vdu_addr     : in  std_logic_vector(2 downto 0);
495
      vdu_data_in  : in  std_logic_vector(7 downto 0);
496
      vdu_data_out : out std_logic_vector(7 downto 0);
497
 
498
      -- vga port connections
499
                vga_clk      : in  std_logic;   -- VGA Pixel Clock - 25 MHz
500
      vga_red_o    : out std_logic;
501
      vga_green_o  : out std_logic;
502
      vga_blue_o   : out std_logic;
503
      vga_hsync_o  : out std_logic;
504
      vga_vsync_o  : out std_logic
505
   );
506
end component;
507
 
508
 
509
component BUFG
510
  port (
511
                i: in  std_logic;
512
                o: out std_logic
513
  );
514
end component;
515
 
516
begin
517
  -----------------------------------------------------------------------------
518
  -- Instantiation of internal components
519
  -----------------------------------------------------------------------------
520
 
521
----------------------------------------
522
--
523
-- CPU09 CPU Core
524
--
525
----------------------------------------
526
my_cpu : cpu09  port map (
527
         clk         => cpu_clk,
528
    rst       => cpu_reset,
529
    rw       => cpu_rw,
530
    vma       => cpu_vma,
531
    address   => cpu_addr(15 downto 0),
532
    data_in   => cpu_data_in,
533
         data_out  => cpu_data_out,
534
         halt      => cpu_halt,
535
         hold      => cpu_hold,
536
         irq       => cpu_irq,
537
         nmi       => cpu_nmi,
538
         firq      => cpu_firq
539
  );
540
 
541
----------------------------------------
542
--
543
-- SBUG / KBUG / SYS09BUG Monitor ROM
544
--
545
----------------------------------------
546
my_rom : mon_rom port map (
547
       clk   => cpu_clk,
548
                 rst   => cpu_reset,
549
                 cs    => rom_cs,
550
                 rw    => '1',
551
       addr  => cpu_addr(10 downto 0),
552
                 wdata => cpu_data_out,
553
       rdata => rom_data_out
554
    );
555
 
556
----------------------------------------
557
--
558
-- Dynamic Address Translation Registers
559
--
560
----------------------------------------
561
my_dat : dat_ram port map (
562
    clk        => cpu_clk,
563
         rst        => cpu_reset,
564
         cs         => dat_cs,
565
         rw         => cpu_rw,
566
         addr_hi    => cpu_addr(15 downto 12),
567
         addr_lo    => cpu_addr(3 downto 0),
568
    data_in    => cpu_data_out,
569
         data_out   => dat_addr(7 downto 0)
570
         );
571
 
572
----------------------------------------
573
--
574
-- ACIA/UART Serial interface
575
--
576
----------------------------------------
577
my_ACIA  : ACIA_6850 port map (
578
         clk         => cpu_clk,
579
         rst       => cpu_reset,
580
    cs        => uart_cs,
581
         rw        => cpu_rw,
582
    irq       => uart_irq,
583
    Addr      => cpu_addr(0),
584
         Datain    => cpu_data_out,
585
         DataOut   => uart_data_out,
586
         RxC       => uart_clk,
587
         TxC       => uart_clk,
588
         RxD       => rxbit,
589
         TxD       => txbit,
590
         DCD_n     => dcd_n,
591
         CTS_n     => cts_n,
592
         RTS_n     => rts_n
593
         );
594
 
595
----------------------------------------
596
--
597
-- ACIA Clock
598
--
599
----------------------------------------
600
my_ACIA_Clock : ACIA_Clock
601
  generic map(
602
    SYS_Clock_Frequency  => SYS_Clock_Frequency,
603
         ACIA_Clock_Frequency => ACIA_Clock_Frequency
604
  )
605
  port map(
606
    clk        => SysClk,
607
    acia_clk   => uart_clk
608
  );
609
 
610
----------------------------------------
611
--
612
-- PS/2 Keyboard Interface
613
--
614
----------------------------------------
615
my_keyboard : keyboard
616
   generic map (
617
        KBD_Clock_Frequency => CPU_Clock_frequency
618
        )
619
   port map(
620
        clk          => cpu_clk,
621
        rst          => cpu_reset,
622
        cs           => keyboard_cs,
623
        rw           => cpu_rw,
624
        addr         => cpu_addr(0),
625
        data_in      => cpu_data_out(7 downto 0),
626
        data_out     => keyboard_data_out(7 downto 0),
627
        irq          => keyboard_irq,
628
        kbd_clk      => kb_clock,
629
        kbd_data     => kb_data
630
        );
631
 
632
----------------------------------------
633
--
634
-- Video Display Unit instantiation
635
--
636
----------------------------------------
637
my_vdu : vdu8
638
  generic map(
639
      VDU_CLOCK_FREQUENCY    => CPU_Clock_Frequency, -- HZ
640
      VGA_CLOCK_FREQUENCY    => PIX_Clock_Frequency, -- HZ
641
           VGA_HOR_CHARS          => 80, -- CHARACTERS
642
           VGA_VER_CHARS          => 25, -- CHARACTERS
643
           VGA_PIXELS_PER_CHAR    => 8,  -- PIXELS
644
           VGA_LINES_PER_CHAR     => 16, -- LINES
645
           VGA_HOR_BACK_PORCH     => 40, -- PIXELS
646
           VGA_HOR_SYNC           => 96, -- PIXELS
647
           VGA_HOR_FRONT_PORCH    => 24, -- PIXELS
648
           VGA_VER_BACK_PORCH     => 13, -- LINES
649
           VGA_VER_SYNC           => 1,  -- LINES
650
           VGA_VER_FRONT_PORCH    => 36  -- LINES
651
  )
652
  port map(
653
 
654
                -- Control Registers
655
                vdu_clk       => cpu_clk,                                        -- 12.5 MHz System Clock in
656
      vdu_rst       => cpu_reset,
657
                vdu_cs        => vdu_cs,
658
                vdu_rw        => cpu_rw,
659
                vdu_addr      => cpu_addr(2 downto 0),
660
                vdu_data_in   => cpu_data_out,
661
                vdu_data_out  => vdu_data_out,
662
 
663
      -- vga port connections
664
      vga_clk       => pix_clk,                                  -- 25 MHz VDU pixel clock
665
      vga_red_o     => vga_red,
666
      vga_green_o   => vga_green,
667
      vga_blue_o    => vga_blue,
668
      vga_hsync_o   => h_drive,
669
      vga_vsync_o   => v_drive
670
   );
671
 
672
----------------------------------------
673
--
674
-- Timer Module
675
--
676
----------------------------------------
677
my_timer  : timer port map (
678
    clk       => cpu_clk,
679
         rst       => cpu_reset,
680
    cs        => timer_cs,
681
         rw        => cpu_rw,
682
    addr      => cpu_addr(0),
683
         data_in   => cpu_data_out,
684
         data_out  => timer_data_out,
685
    irq       => timer_irq,
686
         timer_in  => CountL(5),
687
         timer_out => timer_out
688
    );
689
 
690
----------------------------------------
691
--
692
-- Bus Trap Interrupt logic
693
--
694
----------------------------------------
695
my_trap : trap port map (
696
         clk        => cpu_clk,
697
    rst        => cpu_reset,
698
    cs         => trap_cs,
699
    rw         => cpu_rw,
700
         vma        => cpu_vma,
701
    addr       => cpu_addr,
702
    data_in    => cpu_data_out,
703
         data_out   => trap_data_out,
704
         irq        => trap_irq
705
    );
706
 
707
----------------------------------------
708
--
709
-- Parallel I/O Port
710
--
711
----------------------------------------
712
my_ioport  : ioport port map (
713
         clk       => cpu_clk,
714
    rst       => cpu_reset,
715
    cs        => ioport_cs,
716
    rw        => cpu_rw,
717
    addr      => cpu_addr(1 downto 0),
718
    data_in   => cpu_data_out,
719
         data_out  => ioport_data_out,
720
         porta_io  => porta,
721
         portb_io  => portb
722
         );
723
 
724
--
725
-- 12.5 MHz CPU clock
726
--
727
cpu_clk_buffer : BUFG port map(
728
    i => clock_div(1),
729
         o => cpu_clk
730
    );
731
 
732
--
733
-- 25 MHz VGA Pixel clock
734
--
735
vga_clk_buffer : BUFG port map(
736
    i => clock_div(0),
737
         o => pix_clk
738
    );
739
 
740
----------------------------------------------------------------------
741
--
742
-- Process to decode memory map
743
--
744
----------------------------------------------------------------------
745
 
746
mem_decode: process( cpu_clk, Reset_n, dat_addr,
747
                     cpu_addr, cpu_rw, cpu_vma,
748
                                              rom_data_out,
749
                                                        ram_data_out,
750
                                              cf_data_out,
751
                                                   timer_data_out,
752
                                                        trap_data_out,
753
                                                        ioport_data_out,
754
                                                   uart_data_out,
755
                                                        keyboard_data_out,
756
                                                        vdu_data_out,
757
                                                        bus_data )
758
variable decode_addr : std_logic_vector(4 downto 0);
759
begin
760
    decode_addr := dat_addr(3 downto 0) & cpu_addr(11);
761
--    decode_addr := cpu_addr(15 downto 11);
762
 
763
    if cpu_addr( 15 downto 8 ) = "11111111" then
764
                        cpu_data_in <= rom_data_out;
765
                        rom_cs      <= cpu_vma;              -- read ROM
766
                        dat_cs      <= cpu_vma;              -- write DAT
767
                        ram_cs      <= '0';
768
                        uart_cs     <= '0';
769
                        cf_cs       <= '0';
770
                        timer_cs    <= '0';
771
                        trap_cs     <= '0';
772
                        ioport_cs   <= '0';
773
                        keyboard_cs <= '0';
774
                        vdu_cs      <= '0';
775
                        bus_cs      <= '0';
776
         else
777
      case decode_addr is
778
           --
779
                -- SBUG/KBUG/SYS09BUG Monitor ROM $F800 - $FFFF
780
                --
781
                when "11111" => -- $F800 - $FFFF
782
                   cpu_data_in <= rom_data_out;
783
                        rom_cs      <= cpu_vma;              -- read ROM
784
                        dat_cs      <= '0';
785
                        ram_cs      <= '0';
786
                        uart_cs     <= '0';
787
                        cf_cs       <= '0';
788
                        timer_cs    <= '0';
789
                        trap_cs     <= '0';
790
                        ioport_cs   <= '0';
791
                        keyboard_cs <= '0';
792
                        vdu_cs      <= '0';
793
                        bus_cs      <= '0';
794
 
795
      --
796
                -- IO Devices $E000 - $E7FF
797
                --
798
                when "11100" => -- $E000 - $E7FF
799
                        rom_cs    <= '0';
800
                   dat_cs    <= '0';
801
                        ram_cs    <= '0';
802
                   case cpu_addr(7 downto 4) is
803
                        --
804
                        -- UART / ACIA $E000
805
                        --
806
                        when "0000" => -- $E000
807
                     cpu_data_in <= uart_data_out;
808
                          uart_cs     <= cpu_vma;
809
                          cf_cs       <= '0';
810
                          timer_cs    <= '0';
811
                          trap_cs     <= '0';
812
                          ioport_cs   <= '0';
813
                          keyboard_cs <= '0';
814
                          vdu_cs      <= '0';
815
                          bus_cs      <= '0';
816
 
817
                        --
818
                        -- WD1771 FDC sites at $E010-$E01F
819
                        --
820
 
821
         --
822
         -- Keyboard port $E020 - $E02F
823
                        --
824
                        when "0010" => -- $E020
825
           cpu_data_in <= keyboard_data_out;
826
                          uart_cs     <= '0';
827
                          cf_cs       <= '0';
828
           timer_cs    <= '0';
829
                          trap_cs     <= '0';
830
                          ioport_cs   <= '0';
831
                          keyboard_cs <= cpu_vma;
832
                          vdu_cs      <= '0';
833
                          bus_cs      <= '0';
834
 
835
         --
836
         -- VDU port $E030 - $E03F
837
                        --
838
                        when "0011" => -- $E030
839
           cpu_data_in <= vdu_data_out;
840
                          uart_cs     <= '0';
841
                          cf_cs       <= '0';
842
           timer_cs    <= '0';
843
                          trap_cs     <= '0';
844
                          ioport_cs   <= '0';
845
                          keyboard_cs <= '0';
846
                          vdu_cs      <= cpu_vma;
847
                          bus_cs      <= '0';
848
 
849
         --
850
                        -- Compact Flash $E040 - $E04F
851
                        --
852
                        when "0100" => -- $E040
853
           cpu_data_in <= cf_data_out;
854
                          uart_cs     <= '0';
855
           cf_cs       <= cpu_vma;
856
                          timer_cs    <= '0';
857
                          trap_cs     <= '0';
858
                          ioport_cs   <= '0';
859
                          keyboard_cs <= '0';
860
                          vdu_cs      <= '0';
861
                          bus_cs      <= '0';
862
 
863
         --
864
         -- Timer $E050 - $E05F
865
                        --
866
                        when "0101" => -- $E050
867
           cpu_data_in <= timer_data_out;
868
                          uart_cs     <= '0';
869
                          cf_cs       <= '0';
870
           timer_cs    <= cpu_vma;
871
                          trap_cs     <= '0';
872
                          ioport_cs   <= '0';
873
                          keyboard_cs <= '0';
874
                          vdu_cs      <= '0';
875
                          bus_cs      <= '0';
876
 
877
         --
878
         -- Bus Trap Logic $E060 - $E06F
879
                        --
880
                        when "0110" => -- $E060
881
           cpu_data_in <= trap_data_out;
882
                          uart_cs     <= '0';
883
                          cf_cs       <= '0';
884
           timer_cs    <= '0';
885
                          trap_cs     <= cpu_vma;
886
                          ioport_cs   <= '0';
887
                          keyboard_cs <= '0';
888
                          vdu_cs      <= '0';
889
                          bus_cs      <= '0';
890
 
891
         --
892
         -- I/O port $E070 - $E07F
893
                        --
894
                        when "0111" => -- $E070
895
           cpu_data_in <= ioport_data_out;
896
                          uart_cs     <= '0';
897
                          cf_cs       <= '0';
898
           timer_cs    <= '0';
899
                          trap_cs     <= '0';
900
                          ioport_cs   <= cpu_vma;
901
                          keyboard_cs <= '0';
902
                          vdu_cs      <= '0';
903
                          bus_cs      <= '0';
904
 
905
                        when others => -- $E080 to $E7FF
906
           cpu_data_in <= bus_data;
907
                          uart_cs     <= '0';
908
                          cf_cs       <= '0';
909
                          timer_cs    <= '0';
910
                          trap_cs     <= '0';
911
                          ioport_cs   <= '0';
912
                          keyboard_cs <= '0';
913
                          vdu_cs      <= '0';
914
                          bus_cs      <= cpu_vma;
915
                   end case;
916
                --
917
                -- Everything else is RAM
918
                --
919
                when others =>
920
                  cpu_data_in <= ram_data_out;
921
                  rom_cs      <= '0';
922
                  dat_cs      <= '0';
923
                  ram_cs      <= cpu_vma;
924
                  uart_cs     <= '0';
925
                  cf_cs       <= '0';
926
                  timer_cs    <= '0';
927
                  trap_cs     <= '0';
928
                  ioport_cs   <= '0';
929
                  keyboard_cs <= '0';
930
                  vdu_cs      <= '0';
931
                  bus_cs      <= '0';
932
                end case;
933
        end if;
934
end process;
935
 
936
 
937
--
938
-- B5-SRAM Control
939
-- Processes to read and write memory based on bus signals
940
--
941
ram_process: process( cpu_clk, Reset_n,
942
                      cpu_addr, cpu_rw, cpu_vma, cpu_data_out,
943
                                               dat_addr,
944
                      ram_cs, ram_wrl, ram_wru, ram_data_out )
945
begin
946
    ram_csn <= not( ram_cs and Reset_n );
947
         ram_wrl  <= (not cpu_addr(0)) and (not cpu_rw) and cpu_clk;
948
         ram_wrln <= not (ram_wrl);
949
    ram_wru  <= cpu_addr(0) and (not cpu_rw) and cpu_clk;
950
         ram_wrun <= not (ram_wru);
951
         ram_addr(16 downto 11) <= dat_addr(5 downto 0);
952
         ram_addr(10 downto 0) <= cpu_addr(11 downto 1);
953
 
954
    if ram_wrl = '1' then
955
                ram_data(7 downto 0) <= cpu_data_out;
956
         else
957
      ram_data(7 downto 0)  <= "ZZZZZZZZ";
958
         end if;
959
 
960
         if ram_wru = '1' then
961
                ram_data(15 downto 8) <= cpu_data_out;
962
         else
963
      ram_data(15 downto 8)  <= "ZZZZZZZZ";
964
    end if;
965
 
966
         if cpu_addr(0) = '1' then
967
      ram_data_out <= ram_data(15 downto 8);
968
         else
969
      ram_data_out <= ram_data(7 downto 0);
970
    end if;
971
end process;
972
 
973
--
974
-- Compact Flash Control
975
--
976
compact_flash: process( Reset_n,
977
                 cpu_addr, cpu_rw, cpu_vma, cpu_data_out,
978
                                          cf_cs, cf_rd, cf_wr, cf_d )
979
begin
980
         cf_rst_n  <= Reset_n;
981
         cf_cs0_n  <= not( cf_cs ) or cpu_addr(3);
982
         cf_cs1_n  <= not( cf_cs and cpu_addr(3));
983
         cf_wr     <= cf_cs and (not cpu_rw);
984
         cf_rd     <= cf_cs and cpu_rw;
985
         cf_wr_n   <= not cf_wr;
986
         cf_rd_n   <= not cf_rd;
987
         cf_a      <= cpu_addr(2 downto 0);
988
         if cf_wr = '1' then
989 22 dilbert57
           cf_d(7 downto 0)  <= cpu_data_out;
990
         cf_d(15 downto 8) <= (others => '0');
991 19 dilbert57
         else
992 22 dilbert57
           cf_d(7 downto 0)  <= (others => 'Z');
993
         cf_d(15 downto 8) <= (others => 'Z');
994 19 dilbert57
         end if;
995
         cf_data_out <= cf_d(7 downto 0);
996
end process;
997
 
998
--
999
-- Hold CF access       for a few cycles
1000
--
1001
cf_hold_proc: process( cpu_clk, Reset_n )
1002
begin
1003
    if Reset_n = '0' then
1004
                 cf_release    <= '0';
1005
                 cf_count      <= "0000";
1006
            cf_hold_state <= hold_release_state;
1007
         elsif cpu_clk'event and cpu_clk='0' then
1008
            case cf_hold_state is
1009
                 when hold_release_state =>
1010
          cf_release <= '0';
1011
                    if cf_cs = '1' then
1012
                            cf_count      <= "0011";
1013
                                 cf_hold_state <= hold_request_state;
1014
                         end if;
1015
 
1016
                 when hold_request_state =>
1017
                    cf_count <= cf_count - "0001";
1018
                         if cf_count = "0000" then
1019
             cf_release    <= '1';
1020
                                 cf_hold_state <= hold_release_state;
1021
                         end if;
1022
       when others =>
1023
                    null;
1024
       end case;
1025
         end if;
1026
end process;
1027
 
1028
--
1029
-- Interrupts and other bus control signals
1030
--
1031
interrupts : process( Reset_n,
1032
                                                         cf_cs, cf_hold, cf_release,
1033
                      uart_irq, trap_irq, timer_irq, keyboard_irq
1034
                                                         )
1035
begin
1036
    cf_hold   <= cf_cs and (not cf_release);
1037
         cpu_reset <= not Reset_n; -- CPU reset is active high
1038
    cpu_irq   <= uart_irq or keyboard_irq;
1039
         cpu_nmi   <= trap_irq;
1040
         cpu_firq  <= timer_irq;
1041
         cpu_halt  <= '0';
1042
         cpu_hold  <= cf_hold;
1043
end process;
1044
 
1045
--
1046
-- CPU bus signals
1047
--
1048
my_bus : process( cpu_clk, cpu_reset, cpu_rw, cpu_addr, cpu_data_out )
1049
begin
1050
        bus_clk   <= cpu_clk;
1051
   bus_reset <= cpu_reset;
1052
        bus_rw    <= cpu_rw;
1053
   bus_addr  <= cpu_addr;
1054
        if( cpu_rw = '1' ) then
1055
           bus_data <= "ZZZZZZZZ";
1056
   else
1057
           bus_data <= cpu_data_out;
1058
   end if;
1059
end process;
1060
 
1061
  --
1062
  -- flash led to indicate code is working
1063
  --
1064
my_LED_Flasher: process (cpu_clk, CountL )
1065
begin
1066
    if(cpu_clk'event and cpu_clk = '0') then
1067
      countL <= countL + 1;
1068
    end if;
1069
         LED <= countL(23);
1070
         dcd_n <= '0';
1071
end process;
1072
 
1073
--
1074
-- Clock divider
1075
--
1076
my_clock_divider: process( SysClk )
1077
begin
1078
        if SysClk'event and SysClk='0' then
1079
                clock_div <= clock_div + "01";
1080
        end if;
1081
end process;
1082
--
1083
-- Assign VDU VGA colour output
1084
-- only 8 colours are handled.
1085
--
1086
my_vga_out: process( vga_red, vga_green, vga_blue )
1087
begin
1088
           red_lo   <= vga_red;
1089
      red_hi   <= vga_red;
1090
      green_lo <= vga_green;
1091
      green_hi <= vga_green;
1092
      blue_lo  <= vga_blue;
1093
      blue_hi  <= vga_blue;
1094
end process;
1095
 
1096
end rtl; --===================== End of architecture =======================--
1097
 

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.