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

Subversion Repositories sqmusic

[/] [sqmusic/] [trunk/] [1942/] [computer_1942.v] - Blame information for rev 6

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

Line No. Rev Author Line
1 6 gryzor
/*
2
        1942 simple board setup in order to test SQMUSIC.
3
 
4
        Requirements:
5
                  TV80, Z80 Verilog module
6
                        Dump of Z80 ROM from 1942 board
7
 
8
  (c) Jose Tejada Gomez, 9th May 2013
9
  You can use this file following the GNU GENERAL PUBLIC LICENSE version 3
10
  Read the details of the license in:
11
  http://www.gnu.org/licenses/gpl.txt
12
 
13
  Send comments to: jose.tejada@ieee.org
14
 
15
*/
16
 
17
module computer_1942
18
#(parameter dump_regs=0) // set to 1 to dump sqmusic registers
19
(
20
  input clk,
21
        input sound_clk,
22
        input reset_n,
23
        input int_n,
24
        output [3:0] ay0_a,
25
        output [3:0] ay0_b,
26
        output [3:0] ay0_c,
27
        output [3:0] ay1_a,
28
        output [3:0] ay1_b,
29
        output [3:0] ay1_c
30
);
31
  reg wait_n, nmi_n, busrq_n;
32
 
33
  wire [7:0]cpu_in, cpu_out;
34
  wire [15:0]adr;
35
  wire m1_n, mreq_n, iorq_n, rd_n, wr_n, rfsh_n, halt_n, busak_n;
36
  wire bus_error;
37
 
38
//      wire [15:0] amp0_y, amp1_y;
39
 
40
  wire [7:0]ram_out, rom_out, latch_out;
41
  wire rom_enable = adr<16'h4000 ? 1:0;
42
  wire ram_enable = adr>=16'h4000 && adr<16'h4800 ? 1:0;
43
  wire latch_enable = adr==16'h6000 ? 1 : 0;
44
  wire ay_0_enable = adr==16'h8000 || adr==16'h8001 ? 1:0;
45
  wire ay_1_enable = adr==16'hC000 || adr==16'hC001 ? 1:0;
46
  assign bus_error = ~ram_enable & ~rom_enable & ~latch_enable &
47
    ~ay_0_enable & ~ay_1_enable;
48
  assign cpu_in=ram_out | rom_out | latch_out;
49
/*
50
        always @(negedge rd_n)
51
                if( !rd_n       && adr==8'h38 )
52
                        $display("IRQ processing started @ %t us",$time/1e6);
53
*/
54
  initial begin
55
    nmi_n=1;
56
    wait_n=1;
57
  end
58
 
59
  tv80n cpu( //outputs
60
  .m1_n(m1_n), .mreq_n(mreq_n), .iorq_n(iorq_n), .rd_n(rd_n), .wr_n(wr_n),
61
  .rfsh_n(rfsh_n), .halt_n(halt_n), .busak_n(busak_n), .A(adr), .do(cpu_out),
62
  // Inputs
63
  .reset_n(reset_n), .clk(clk), .wait_n(wait_n),
64
  .int_n(int_n), .nmi_n(nmi_n), .busrq_n(busrq_n), .di(cpu_in) );
65
 
66
  RAM ram(.adr(adr[10:0]), .din(cpu_out), .dout(ram_out), .enable( ram_enable ),
67
    .clk(clk), .wr_n(wr_n), .rd_n(rd_n) );
68
  ROM rom(.adr(adr[13:0]), .data(rom_out), .enable(rom_enable),
69
   .rd_n(rd_n), .clk(clk));
70
  SOUND_LATCH sound_latch( .dout(latch_out), .enable(latch_enable),
71
    .clk(clk), .rd_n(rd_n) );
72
 
73
//      fake_ay ay_0( .adr(adr[0]), .din(din), .clk(clk), .wr_n(~ay_0_enable|wr_n) );
74
 
75
        AY_3_8910_capcom #(dump_regs,0) ay_0( .reset_n(reset_n), .clk(clk), .sound_clk(sound_clk),
76
                .din(cpu_out), .adr(adr[0]), .wr_n(wr_n), .cs_n(~ay_0_enable),
77
                .A(ay0_a), .B(ay0_b), .C(ay0_c) );
78
        AY_3_8910_capcom #(dump_regs,1) ay_1( .reset_n(reset_n), .clk(clk), .sound_clk(sound_clk),
79
                .din(cpu_out), .adr(adr[0]), .wr_n(wr_n), .cs_n(~ay_1_enable),
80
                .A(ay1_a), .B(ay1_b), .C(ay1_c) );
81
endmodule
82
 
83
//////////////////////////////////////////////////////////
84
// this module is used to check the communication of the
85
// Z80 with the AY-3-8910
86
// only used for debugging
87
module fake_ay(
88
        input adr,
89
  input [7:0] din,
90
  input clk,
91
  input wr_n );
92
 
93
        reg [7:0] contents[1:0];
94
        wire sample = clk & ~wr_n;
95
 
96
        always @(posedge sample) begin
97
//              if( contents[adr] != din ) begin
98
                $display("%t -> %d = %d", $realtime/1e6, adr, din );
99
                if( !adr && din>15 ) $display("AY WARNING");
100
                contents[adr] = din;
101
        end
102
 
103
endmodule
104
 
105
//////////////////////////////////////////////////////////
106
module RAM(
107
  input [10:0] adr,
108
  input [7:0] din,
109
  output reg [7:0] dout,
110
  input enable,
111
  input clk,
112
  input rd_n,
113
  input wr_n );
114
 
115
reg [7:0] contents[2047:0];
116
wire sample = clk & (~rd_n | ~wr_n );
117
 
118
initial dout=0;
119
 
120
always @(posedge sample) begin
121
  if( !enable )
122
    dout=0;
123
  else begin
124
    if( !wr_n ) contents[adr]=din;
125
    if( !rd_n ) dout=contents[adr];
126
  end
127
end
128
endmodule
129
 
130
//////////////////////////////////////////////////////////
131
module ROM(
132
  input  [13:0] adr,
133
  output reg [7:0] data,
134
  input enable,
135
  input rd_n,
136
  input clk );
137
 
138
reg [7:0] contents[16383:0];
139
 
140
wire sample = clk & ~rd_n;
141
 
142
initial begin
143
  $readmemh("../rom/sr-01.c11.hex", contents ); // this is the hex dump of the ROM
144
  data=0;
145
end
146
 
147
always @( posedge sample ) begin
148
  if ( !enable )
149
    data=0;
150
  else
151
    data=contents[ adr ];
152
end
153
endmodule
154
 
155
//////////////////////////////////////////////////////////
156
module SOUND_LATCH(
157
  output reg [7:0] dout,
158
  input enable,
159
  input clk,
160
  input rd_n );
161
 
162
wire sample = clk & ~rd_n;
163
reg [7:0]data;
164
 
165
initial begin
166
        dout=0;
167
        data=0;
168
        #100e6 data=8'h12; // enter the song/sound code here
169
end
170
 
171
always @(posedge sample) begin
172
  if( !enable )
173
                dout=0;
174
  else begin
175
    if( !rd_n ) begin
176
                        // $display("Audio latch read @ %t us", $realtime/1e6 );
177
//                      if( data != 0 ) 
178
//                        $display("Audio latch read (%X) @ %t us", data, $realtime/1e6 );
179
                        dout=data;
180
                end
181
  end
182
end
183
endmodule

powered by: WebSVN 2.1.0

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