Subversion Repositories ngs

Rev

Rev 88 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed

  1. // part of NeoGS project (c) 2007-2008 NedoPC
  2. //
  3.  
  4. // ports $00-$3f are in FPGA, $40-$ff are in CPLD
  5.  
  6. module ports(
  7.  
  8.         input  wire rst_n,
  9.         input  wire cpu_clock, // Z80 CPU clock (clk_fpga on schematics)
  10.  
  11.  
  12.         input  wire [ 7:0] din,   // NGS z80 cpu DATA BUS inputs
  13.         output reg  [ 7:0] dout,  // NGS z80 cpu DATA BUS outputs
  14.         output reg         busin, // direction of bus: =1 - input, =0 - output
  15.         input  wire [15:0] a,     // NSG z80 cpu ADDRESS BUS
  16.  
  17.         input  wire iorq_n,
  18.         input  wire mreq_n,
  19.         input  wire rd_n,
  20.         input  wire wr_n, // NGS z80 cpu control signals
  21.  
  22.         input  wire [ 7:0] data_port_input, // data_port input from zxbus module (async)
  23.         output reg  [ 7:0] data_port_output, // data_port output to zxbus module (async to zxbus, sync here)
  24.         input  wire [ 7:0] command_port_input, // command_port input from zxbus (async)
  25.  
  26.         input  wire data_bit_input, // data_bit from zxbus module (sync)
  27.         input  wire command_bit_input, // --//-- (sync)
  28.  
  29.         output reg  data_bit_output, // output to zxbus module
  30.         output reg  command_bit_output,
  31.  
  32.         output reg  data_bit_wr, // strobes (positive) to zxbus module, synchronous
  33.         output reg  command_bit_wr,
  34.  
  35.  
  36.         output reg  mode_8chans, // mode outputs for sound_main module
  37.         output reg  mode_pan4ch, //
  38.         output reg  mode_inv7b,  //
  39.  
  40.         output reg  mode_ramro, // mode outputs for memmap module
  41.         output reg  mode_norom,
  42.  
  43.         output reg  [7:0] mode_pg0, // page registers for memmap module
  44.         output reg  [7:0] mode_pg1,
  45.         output reg  [7:0] mode_pg2,
  46.         output reg  [7:0] mode_pg3,
  47.  
  48.  
  49.         output reg  clksel0, // clock select (output from FPGA)
  50.         output reg  clksel1,
  51.  
  52.  
  53.         output reg         snd_wrtoggle, // toggle to write sound data to sound system memory
  54.         output reg         snd_datnvol,  // whether it's for volume (=0) or for samples (=1)
  55.         output reg  [ 2:0] snd_addr,     // address: which channel to be written (0-7)
  56.         output reg  [ 7:0] snd_data,     // actual 8-bit data to be written
  57.  
  58.  
  59.         output wire [ 7:0] md_din, // mp3 data interface
  60.         output wire        md_start,
  61.         input  wire        md_dreq,
  62.         output reg         md_halfspeed,
  63.  
  64.         output reg         mc_ncs, // mp3 control interface
  65.         output reg         mc_xrst,
  66.         input  wire [ 7:0] mc_dout,
  67.         output wire [ 7:0] mc_din,
  68.         output wire        mc_start,
  69.         output reg  [ 1:0] mc_speed,
  70.         input  wire        mc_rdy,
  71.  
  72.         output reg         sd_ncs, // SD card interface
  73.         input  wire [ 7:0] sd_dout,
  74.         output wire [ 7:0] sd_din,
  75.         output wire        sd_start,
  76.         input  wire        sd_det,
  77.         input  wire        sd_wp,
  78.  
  79.         output reg  led, // LED control
  80.         input  wire led_toggle,
  81.  
  82.  
  83.         output reg  [7:0] dma_din_modules, // DMA control
  84.         //
  85.         output reg        dma_select_zx,
  86.         input  wire [7:0] dma_dout_zx,
  87.         //
  88.         output reg        dma_wrstb,
  89.         output reg  [1:0] dma_regsel,
  90.  
  91.  
  92.         // timer freq selector
  93.         output reg  [2:0] timer_rate,
  94.  
  95.         // intena/intreq related
  96.         output wire       intena_wr,
  97.         output wire       intreq_wr,
  98.         input  wire [7:0] intreq_rd
  99.  
  100. );
  101.  
  102.  
  103.         localparam MPAG      = 6'h00;
  104.         localparam MPAGEX    = 6'h10;
  105.  
  106.         localparam ZXCMD     = 6'h01;
  107.         localparam ZXDATRD   = 6'h02;
  108.         localparam ZXDATWR   = 6'h03;
  109.         localparam ZXSTAT    = 6'h04;
  110.         localparam CLRCBIT   = 6'h05;
  111.  
  112.         localparam VOL1      = 6'h06;
  113.         localparam VOL2      = 6'h07;
  114.         localparam VOL3      = 6'h08;
  115.         localparam VOL4      = 6'h09;
  116.         localparam VOL5      = 6'h16;
  117.         localparam VOL6      = 6'h17;
  118.         localparam VOL7      = 6'h18;
  119.         localparam VOL8      = 6'h19;
  120.  
  121.         localparam DAMNPORT1 = 6'h0a;
  122.         localparam DAMNPORT2 = 6'h0b;
  123.  
  124.         localparam LEDCTR    = 6'h01;
  125.  
  126.         localparam GSCFG0    = 6'h0f;
  127.  
  128.         localparam SCTRL     = 6'h11;
  129.         localparam SSTAT     = 6'h12;
  130.  
  131.         localparam SD_SEND   = 6'h13;
  132.         localparam SD_READ   = 6'h13;
  133.         localparam SD_RSTR   = 6'h14;
  134.  
  135.         localparam MD_SEND   = 6'h14; // same as SD_RSTR!!!
  136.  
  137.         localparam MC_SEND   = 6'h15;
  138.         localparam MC_READ   = 6'h15;
  139.  
  140.         localparam DMA_MOD   = 6'h1b; // read/write
  141.         localparam DMA_HAD   = 6'h1c; // LSB bits 1:0 are 00 // read/write all
  142.         localparam DMA_MAD   = 6'h1d; //                  01
  143.         localparam DMA_LAD   = 6'h1e; //                  10
  144.         localparam DMA_CST   = 6'h1f; //                  11
  145.  
  146.         localparam DMA_PORTS = 6'h1c; // mask for _HAD, _MAD, _LAD and _CST ports, two LSBs must be zero
  147.  
  148.         localparam TIM_FREQ  = 6'h0e;
  149.  
  150.         localparam INTENA    = 6'h0c;
  151.         localparam INTREQ    = 6'h0d;
  152.  
  153.         localparam PG0       = 6'h20;
  154.         localparam PG1       = 6'h21;
  155.         localparam PG2       = 6'h22;
  156.         localparam PG3       = 6'h23;
  157.  
  158.         // FREE PORT ADDRESSES: $1A, $24-$3F
  159.  
  160.  
  161.  
  162. // internal regs & wires
  163.  
  164.         reg mode_expag; // extended paging mode register
  165.  
  166.         reg port09_bit5;
  167.  
  168.         wire port_enabled; // =1 when port address is in enabled region ($00-$3f)
  169.         wire mem_enabled; // =1 when memory mapped sound regs are addressed ($6000-$7FFF)
  170.         reg volports_enabled; // when volume ports are addressed (6-9 and $16-$19)
  171.  
  172.         reg iowrn_reg; // registered io write signal (all positive edge!)
  173.         reg iordn_reg; // --//--
  174.         reg merdn_reg; // --//--
  175.  
  176.  
  177.         reg port_wr; // synchronous positive write pulse (write from z80 to fpga regs)
  178.         reg port_rd;  // synchronous positive read pulse (read done from fpga regs to z80)
  179.  
  180.         reg memreg_rd; // when memory-mapped sound regs are read
  181.  
  182.  
  183.  
  184.  
  185.  
  186.  
  187.         wire port00_wr;   // specific write and read strobes (1 clock cycle long positive)
  188.         wire p_ledctr_wr;
  189.         wire port02_rd;
  190.         wire port03_wr;
  191.         wire port05_wrrd;
  192.         wire port09_wr;
  193.         wire port0a_wrrd;
  194.         wire port0b_wrrd;
  195.         wire port0f_wr;
  196.         wire port10_wr;
  197.  
  198. //      wire p_sstat_rd;
  199. //      wire p_sctrl_rd;
  200.         wire p_sctrl_wr;
  201.         wire p_sdsnd_wr;
  202. //      wire p_sdrd_rd;
  203.         wire p_sdrst_rd;
  204.         wire p_mdsnd_wr;
  205.         wire p_mcsnd_wr;
  206. //      wire p_mcrd_rd;
  207.  
  208.         wire p_dmamod_wr;
  209.         wire p_dmaports_wr;
  210.  
  211.         wire p_timfreq_wr;
  212.  
  213.         wire pg0_wr;
  214.         wire pg1_wr;
  215.         wire pg2_wr;
  216.         wire pg3_wr;
  217.  
  218.  
  219.  
  220.         reg [2:0] volnum; // volume register number from port address
  221.  
  222.  
  223.         reg [2:0] dma_module_select; // which dma module selected: zero - none selected
  224.         localparam DMA_NONE_SELECTED = 3'd0;
  225.         localparam DMA_MODULE_ZX     = 3'd1;
  226. //      localparam DMA_MODULE_...    = 3'd2;
  227.  
  228.         reg [7:0] dma_dout_modules; // select in data from different modules
  229.  
  230.  
  231. // actual code
  232.  
  233.         //enabled ports
  234.         assign port_enabled = ~(a[7] | a[6]); // $00-$3F
  235.  
  236.         //enabled mem
  237.         assign mem_enabled = (~a[15]) & a[14] & a[13]; // $6000-$7FFF
  238.  
  239.         // volume ports enabled
  240.         always @*
  241.         begin
  242.                 if( a[5:0]==VOL1 ||
  243.                     a[5:0]==VOL2 ||
  244.                     a[5:0]==VOL3 ||
  245.                     a[5:0]==VOL4 ||
  246.                     a[5:0]==VOL5 ||
  247.                     a[5:0]==VOL6 ||
  248.                     a[5:0]==VOL7 ||
  249.                     a[5:0]==VOL8 )
  250.  
  251.                         volports_enabled <= 1'b1;
  252.                 else
  253.                         volports_enabled <= 1'b0;
  254.         end
  255.  
  256.  
  257.  
  258.         //when data bus outputs
  259.         always @*
  260.         begin
  261.                 if( port_enabled && (!iorq_n) && (!rd_n) )
  262.                         busin <= 1'b0; // bus outputs
  263.                 else
  264.                         busin <= 1'b1; // bus inputs
  265.         end
  266.  
  267.  
  268.  
  269.         // rd/wr/iorq syncing in and pulses - old gen
  270.         always @(posedge cpu_clock)
  271.         begin
  272.                 iowrn_reg <= iorq_n | wr_n;
  273.                 iordn_reg <= iorq_n | rd_n;
  274.  
  275.                 if( port_enabled && (!iorq_n) && (!wr_n) && iowrn_reg )
  276.                         port_wr <= 1'b1;
  277.                 else
  278.                         port_wr <= 1'b0;
  279.  
  280.                 if( port_enabled && (!iorq_n) && (!rd_n) && iordn_reg )
  281.                         port_rd <= 1'b1;
  282.                 else
  283.                         port_rd <= 1'b0;
  284.  
  285.         end
  286.  
  287. /*
  288.         // new gen of port_rd and port_wr
  289.         reg [2:0] rd_sync;
  290.         reg [2:0] wr_sync;
  291.         always @(posedge cpu_clock)
  292.         begin
  293.                 rd_sync[2:0] <= { rd_sync[1:0], port_enabled&(~iorq_n)&(~rd_n) };
  294.                 wr_sync[2:0] <= { wr_sync[1:0], port_enabled&(~iorq_n)&(~wr_n) };
  295.  
  296.                 port_wr <= (wr_sync[1:0]==2'b01);
  297.                 port_rd <= (rd_sync[1:0]==2'b01);
  298.  
  299.         end
  300. */
  301.  
  302.         // mreq syncing and mem read pulse
  303.         always @(negedge cpu_clock)
  304.         begin
  305.                 merdn_reg <= mreq_n | rd_n;
  306.  
  307.                 if( mem_enabled && (!mreq_n) && (!rd_n) && merdn_reg )
  308.                         memreg_rd <= 1'b1;
  309.                 else
  310.                         memreg_rd <= 1'b0;
  311.  
  312.         end
  313.  
  314.  
  315.         // specific ports strobes
  316.         assign port00_wr   = ( a[5:0]==MPAG      && port_wr            );
  317.         assign port02_rd   = ( a[5:0]==ZXDATRD   && port_rd            );
  318.         assign port03_wr   = ( a[5:0]==ZXDATWR   && port_wr            );
  319.         assign port05_wrrd = ( a[5:0]==CLRCBIT   && (port_wr||port_rd) );
  320.         assign port09_wr   = ( a[5:0]==VOL4      && port_wr            );
  321.         assign port0a_wrrd = ( a[5:0]==DAMNPORT1 && (port_wr||port_rd) );
  322.         assign port0b_wrrd = ( a[5:0]==DAMNPORT2 && (port_wr||port_rd) );
  323.         assign port0f_wr   = ( a[5:0]==GSCFG0    && port_wr            );
  324.         assign port10_wr   = ( a[5:0]==MPAGEX    && port_wr            );
  325.  
  326.  
  327. //      assign p_sctrl_rd = ( a[5:0]==SCTRL  && port_rd );
  328.         assign p_sctrl_wr = ( a[5:0]==SCTRL  && port_wr );
  329. //      assign p_sstat_rd = ( a[5:0]==SSTAT  && port_rd );
  330.         assign p_sdsnd_wr = ( a[5:0]==SD_SEND && port_wr );
  331. //      assign p_sdrd_rd  = ( a[5:0]==SD_READ && port_rd );
  332.         assign p_sdrst_rd = ( a[5:0]==SD_RSTR && port_rd );
  333.         assign p_mdsnd_wr = ( a[5:0]==MD_SEND && port_wr );
  334.         assign p_mcsnd_wr = ( a[5:0]==MC_SEND && port_wr );
  335. //      assign p_mcrd_rd  = ( a[5:0]==MC_READ && port_rd );
  336.  
  337.         assign p_ledctr_wr = ( a[5:0]==LEDCTR && port_wr );
  338.  
  339.         assign p_dmamod_wr   = ( a[5:0]==DMA_MOD && port_wr );
  340.         assign p_dmaports_wr = ( {a[5:2],2'b00}==DMA_PORTS && port_wr );
  341.  
  342.         assign p_timfreq_wr = ( a[5:0]==TIM_FREQ && port_wr );
  343.  
  344.         assign intena_wr = ( a[5:0]==INTENA && port_wr );
  345.         assign intreq_wr = ( a[5:0]==INTREQ && port_wr );
  346.  
  347.         assign pg0_wr = ( a[5:0]==PG0 && port_wr );
  348.         assign pg1_wr = ( a[5:0]==PG1 && port_wr );
  349.         assign pg2_wr = ( a[5:0]==PG2 && port_wr );
  350.         assign pg3_wr = ( a[5:0]==PG3 && port_wr );
  351.  
  352.  
  353.         // read from fpga to Z80
  354.         always @*
  355.         begin
  356.                 case( a[5:0] )
  357.                 ZXCMD: // command register
  358.                         dout <= command_port_input;
  359.                 ZXDATRD: // data register
  360.                         dout <= data_port_input;
  361.                 ZXSTAT: // status bits
  362.                         dout <= { data_bit_input, 6'bXXXXXX, command_bit_input };
  363.                 GSCFG0: // config register #0F
  364.                         dout <= { mode_inv7b, mode_pan4ch, clksel1, clksel0, mode_expag, mode_8chans, mode_ramro, mode_norom };
  365.  
  366.                 SSTAT:
  367.                         dout <= { 4'd0, mc_rdy, sd_wp, sd_det, md_dreq };
  368.                 SCTRL:
  369.                         dout <= { 2'd0, mc_speed[1], md_halfspeed, mc_speed[0], mc_xrst, mc_ncs, sd_ncs };
  370.                 SD_READ:
  371.                         dout <= sd_dout;
  372.                 SD_RSTR:
  373.                         dout <= sd_dout;
  374.                 MC_READ:
  375.                         dout <= mc_dout;
  376.  
  377.                 INTREQ:
  378.                         dout <= intreq_rd;
  379.  
  380.  
  381.                 DMA_MOD:
  382.                         dout <= { 5'd0, dma_module_select };
  383.                 DMA_HAD:
  384.                         dout <= dma_dout_modules;
  385.                 DMA_MAD:
  386.                         dout <= dma_dout_modules;
  387.                 DMA_LAD:
  388.                         dout <= dma_dout_modules;
  389.                 DMA_CST:
  390.                         dout <= dma_dout_modules;
  391.  
  392.  
  393.                 default:
  394.                         dout <= 8'bXXXXXXXX;
  395.                 endcase
  396.         end
  397.  
  398.  
  399.  
  400.  
  401.  
  402.         // write to $00 and $10 ports -- old mem mapping control,
  403.         // also new mapping control (pg2 and pg3 ports)
  404.         always @(posedge cpu_clock)
  405.         if( port00_wr ) // port 00
  406.         begin
  407.                 if( !mode_expag ) // normal paging
  408.                         mode_pg2[7:0] <= { din[6:0], 1'b0 };
  409.                 else // extended paging
  410.                         mode_pg2[7:0] <= { din[6:0], din[7] };
  411.         end
  412.         else if( pg2_wr )
  413.                 mode_pg2 <= din;
  414.         //
  415.         always @(posedge cpu_clock)
  416.         if( !mode_expag && port00_wr ) // port 10 (when in normal mode, part of port 00)
  417.                 mode_pg3[7:0] <= { din[6:0], 1'b1 };
  418.         else if( mode_expag && port10_wr )
  419.                 mode_pg3[7:0] <= { din[6:0], din[7] };
  420.         else if( pg3_wr )
  421.                 mode_pg3 <= din;
  422.  
  423.         // write to pg0 and pg1 ports
  424.         always @(posedge cpu_clock, negedge rst_n)
  425.         if( !rst_n )
  426.                 mode_pg0 <= 8'b00000000;
  427.         else if( pg0_wr )
  428.                 mode_pg0 <= din;
  429.         //
  430.         always @(posedge cpu_clock, negedge rst_n)
  431.         if( !rst_n )
  432.                 mode_pg1 <= 8'b00000011;
  433.         else if( pg1_wr )
  434.                 mode_pg1 <= din;
  435.  
  436.  
  437.         // port $03 write ++
  438.         always @(posedge cpu_clock)
  439.         begin
  440.                 if( port03_wr==1'b1 )
  441.                         data_port_output <= din;
  442.         end
  443.  
  444.         // port $09 bit tracing
  445.         always @(posedge cpu_clock)
  446.         begin
  447.                 if( port09_wr==1'b1 )
  448.                         port09_bit5 <= din[5];
  449.         end
  450.  
  451.         // write and reset of port $0F ++
  452.         always @(posedge cpu_clock,negedge rst_n)
  453.         begin
  454.                 if( rst_n==1'b0 ) // reset!
  455.                         { mode_inv7b, mode_pan4ch, clksel1, clksel0, mode_expag, mode_8chans, mode_ramro, mode_norom } <= 8'b00110000;
  456.                 else // write to port
  457.                 begin
  458.                         if( port0f_wr == 1'b1 )
  459.                         begin
  460.                                 { mode_inv7b, mode_pan4ch, clksel1, clksel0, mode_expag, mode_8chans, mode_ramro, mode_norom } <= din[7:0];
  461.                         end
  462.                 end
  463.         end
  464.  
  465.         // data bit handling
  466.         always @*
  467.         case( {port02_rd,port03_wr,port0a_wrrd} )
  468.                 3'b100:
  469.                 begin
  470.                         data_bit_output <= 1'b0;
  471.                         data_bit_wr <= 1'b1;
  472.                 end
  473.  
  474.                 3'b010:
  475.                 begin
  476.                         data_bit_output <= 1'b1; // ++
  477.                         data_bit_wr <= 1'b1;
  478.                 end
  479.  
  480.                 3'b001:
  481.                 begin
  482.                         data_bit_output <= ~mode_pg2[0];
  483.                         data_bit_wr <= 1'b1;
  484.                 end
  485.  
  486.                 default:
  487.                 begin
  488.                         data_bit_output <= 1'bX;
  489.                         data_bit_wr <= 1'b0;
  490.                 end
  491.         endcase
  492.  
  493.         // command bit handling
  494.         always @*
  495.         case( {port05_wrrd,port0b_wrrd} )
  496.                 2'b10:
  497.                 begin
  498.                         command_bit_output <= 1'b0;
  499.                         command_bit_wr <= 1'b1;
  500.                 end
  501.  
  502.                 2'b01:
  503.                 begin
  504.                         command_bit_output <= port09_bit5;
  505.                         command_bit_wr <= 1'b1;
  506.                 end
  507.  
  508.                 default:
  509.                 begin
  510.                         command_bit_output <= 1'bX;
  511.                         command_bit_wr <= 1'b0;
  512.                 end
  513.         endcase
  514.  
  515.         // handle data going to sound module (volume and samples values)
  516.         always @*
  517.         begin
  518.                 case( a[5:0] ) // port addresses to volume register numbers
  519.                 VOL1:
  520.                         volnum <= 3'd0;
  521.                 VOL2:
  522.                         volnum <= 3'd1;
  523.                 VOL3:
  524.                         volnum <= 3'd2;
  525.                 VOL4:
  526.                         volnum <= 3'd3;
  527.                 VOL5:
  528.                         volnum <= 3'd4;
  529.                 VOL6:
  530.                         volnum <= 3'd5;
  531.                 VOL7:
  532.                         volnum <= 3'd6;
  533.                 VOL8:
  534.                         volnum <= 3'd7;
  535.                 default:
  536.                         volnum <= 3'bXXX;
  537.                 endcase
  538.         end
  539.  
  540.         // handling itself (sending data to sound module)
  541.         always @(posedge cpu_clock)
  542.         begin
  543.                 if( memreg_rd ) // memory read - sample data write
  544.                 begin
  545.                         snd_wrtoggle <= ~snd_wrtoggle;
  546.                         snd_datnvol  <= 1'b1; // sample data
  547.  
  548.                         if( !mode_8chans ) // 4 channel mode
  549.                                 snd_addr <= { 1'b0, a[9:8] };
  550.                         else // 8 channel mode
  551.                                 snd_addr <= a[10:8];
  552.  
  553.                         snd_data <= din;
  554.                 end
  555.                 else if( volports_enabled && port_wr )
  556.                 begin
  557.                         snd_wrtoggle <= ~snd_wrtoggle;
  558.                         snd_datnvol  <= 1'b0; // volume data
  559.                         snd_addr <= volnum;
  560.                         snd_data <= din;
  561.                 end
  562.         end
  563.  
  564.  
  565.  
  566.  
  567.  
  568.  
  569.         //SPI (mp3, SD) interfaces
  570.  
  571.         assign sd_din = (a[5:0]==SD_RSTR) ? 8'hFF : din;
  572.         assign mc_din = din;
  573.         assign md_din = din;
  574.  
  575.  
  576.         assign sd_start = p_sdsnd_wr | p_sdrst_rd;
  577.         assign mc_start = p_mcsnd_wr;
  578.         assign md_start = p_mdsnd_wr;
  579.  
  580.  
  581.       always @(posedge cpu_clock, negedge rst_n)
  582.       begin
  583.                 if( !rst_n ) // async reset
  584.                 begin
  585.                         md_halfspeed <= 1'b0;
  586.                         mc_speed     <= 2'b01;
  587.                         mc_xrst      <= 1'b0;
  588.                         mc_ncs       <= 1'b1;
  589.                         sd_ncs       <= 1'b1;
  590.                 end
  591.                 else // clock
  592.                 begin
  593.                         if( p_sctrl_wr )
  594.                         begin
  595.                                 if( din[0] )
  596.                                         sd_ncs       <= din[7];
  597.  
  598.                                 if( din[1] )
  599.                                         mc_ncs       <= din[7];
  600.  
  601.                                 if( din[2] )
  602.                                         mc_xrst      <= din[7];
  603.  
  604.                                 if( din[3] )
  605.                                         mc_speed[0]  <= din[7];
  606.  
  607.                                 if( din[4] )
  608.                                         md_halfspeed <= din[7];
  609.  
  610.                                 if( din[5] )
  611.                                         mc_speed[1]  <= din[7];
  612.  
  613.                         end
  614.                 end
  615.       end
  616.  
  617.  
  618.         // LED control
  619.         always @(posedge cpu_clock, negedge rst_n)
  620.         begin
  621.                 if( !rst_n )
  622.                         led <= 1'b0;
  623.                 else
  624.                 begin
  625.                         if( p_ledctr_wr )
  626.                                 led <= din[0];
  627.                         else if( led_toggle )
  628.                                 led <= ~led;
  629.                 end
  630.  
  631.         end
  632.  
  633.  
  634.  
  635.  
  636.         // DMA control
  637.         //
  638.         always @(posedge cpu_clock, negedge rst_n) // selection of modules
  639.         begin
  640.                 if( !rst_n )
  641.                         dma_module_select <= DMA_NONE_SELECTED;
  642.                 else if( p_dmamod_wr )
  643.                         dma_module_select <= din[2:0];
  644.         end
  645.         //
  646.         always @* dma_din_modules = din; // translate Z80 bus out to all DMA modules
  647.         //
  648.         always @* // select modules by individual signals
  649.         begin
  650.                 dma_select_zx = 1'b0;
  651.                 //dma_select_... = 1'b0;
  652.  
  653.                 case( dma_module_select )
  654.                 DMA_MODULE_ZX:
  655.                         dma_select_zx = 1'b1;
  656.                 //DMA_MODULE_...:
  657.                 //      dma_select_... = 1'b1;
  658.                 endcase
  659.         end
  660.         //
  661.         always @* dma_wrstb = p_dmaports_wr; // translate dma write strobe
  662.         //
  663.         always @* dma_regsel = a[1:0];
  664.         //
  665.         always @* // route data from modules to the common module bus
  666.         begin
  667.                 case( dma_regsel )
  668.                 DMA_MODULE_ZX:
  669.                         dma_dout_modules <= dma_dout_zx;
  670.                 //DMA_MODULE_...:
  671.                 //      dma_dout_modules <= dma_dout_...;
  672.                 default:
  673.                         dma_dout_modules <= 8'bxxxxxxxx;
  674.                 endcase
  675.         end
  676.  
  677.  
  678.  
  679.         // timer rate
  680.         //
  681.         always @(posedge cpu_clock,negedge rst_n)
  682.         if( !rst_n )
  683.                 timer_rate <= 3'b000;
  684.         else if( p_timfreq_wr )
  685.                 timer_rate <= din[2:0];
  686.  
  687.  
  688. endmodule
  689.  
  690.