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

Subversion Repositories sqmusic

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

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

powered by: WebSVN 2.1.0

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