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

Subversion Repositories sqmusic

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

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

Line No. Rev Author Line
1 3 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
`timescale 1ns / 1ps
18
 
19
module sound1942;
20
  // inputs to Z80
21 4 gryzor
  reg reset_n, clk, int_n, sound_clk;
22 3 gryzor
 
23
  initial begin
24 5 gryzor
/*    $dumpfile("dump.lxt");
25
    $dumpvars(1,pwm0);
26
    $dumpvars(1,pwm1);*/
27 3 gryzor
//              $dumpvars();
28
//    $dumpon;
29
//              $shm_open("1942.shm");
30
//              $shm_probe( sound1942, "ACTFS" );
31
    reset_n=0;
32
    #1500 reset_n=1;
33
                // change finish time depending on song
34 4 gryzor
                //#4e6 $finish;
35 5 gryzor
    #6e9 $finish;
36 3 gryzor
  end
37
 
38
  always begin // main clock
39
    clk=0;
40
    forever clk = #167 ~clk;
41
  end
42
 
43
  always begin // sound clock
44
    sound_clk=0;
45
    forever sound_clk = #334 ~sound_clk;
46
  end
47
 
48
        parameter int_low_time=167*2*80;
49
 
50
  always begin // interrupt clock
51
    int_n=1;
52
    forever begin
53
                        #(4166667-int_low_time) int_n=0; // 240Hz
54
                        //$display("IRQ request @ %t us",$time/1e6);
55
                        #(int_low_time) int_n=1;
56
                end
57
  end
58
 
59 5 gryzor
 
60 4 gryzor
        wire [3:0] ay0_a, ay0_b, ay0_c, ay1_a, ay1_b, ay1_c;
61
  computer_1942 #(0) game( .clk(clk), .sound_clk(sound_clk),
62
    .int_n(int_n), .reset_n(reset_n),
63
    .ay0_a(ay0_a), .ay0_b(ay0_b), .ay0_c(ay0_c),
64
    .ay1_a(ay1_a), .ay1_b(ay1_b), .ay1_c(ay1_c) );
65
  // sound amplifier:
66 5 gryzor
  /*
67 4 gryzor
  wire [15:0] amp0_y, amp1_y;
68
        SQM_AMP amp0( .A(ay0_a), .B(ay0_b), .C(ay0_c), .Y( amp0_y ));
69 5 gryzor
        SQM_AMP amp1( .A(ay1_a), .B(ay1_b), .C(ay1_c), .Y( amp1_y ));
70
        always #22676 $display("%d", amp0_y+amp1_y ); // 44.1kHz sample
71
        */
72
        reg vhf_clk;
73
        always begin
74
          vhf_clk=0;
75
          forever begin
76
            if( vhf_clk ) begin
77
              $display("%d, %d, %d, %d, %d, %d",
78
                pwm0_a, pwm0_b, pwm0_c, pwm1_a, pwm1_b, pwm1_c );
79
            end
80
            #10 vhf_clk <= ~vhf_clk; // 50MHz
81
          end
82
        end
83
 
84
  SQM_PWM_1 a0pwm( .clk(vhf_clk), .reset_n(reset_n), .din(ay0_a), .pwm(pwm0_a) );
85
  SQM_PWM_1 b0pwm( .clk(vhf_clk), .reset_n(reset_n), .din(ay0_b), .pwm(pwm0_b) );
86
  SQM_PWM_1 c0pwm( .clk(vhf_clk), .reset_n(reset_n), .din(ay0_c), .pwm(pwm0_c) );
87 3 gryzor
 
88 5 gryzor
  SQM_PWM_1 a1pwm( .clk(vhf_clk), .reset_n(reset_n), .din(ay1_a), .pwm(pwm1_a) );
89
  SQM_PWM_1 b1pwm( .clk(vhf_clk), .reset_n(reset_n), .din(ay1_b), .pwm(pwm1_b) );
90
  SQM_PWM_1 c1pwm( .clk(vhf_clk), .reset_n(reset_n), .din(ay1_c), .pwm(pwm1_c) );
91
        endmodule
92
 
93 3 gryzor
/////////////////////////////////////////////////////
94 4 gryzor
module computer_1942
95
#(parameter dump_regs=0) // set to 1 to dump sqmusic registers
96
(
97 3 gryzor
  input clk,
98
        input sound_clk,
99
        input reset_n,
100 4 gryzor
        input int_n,
101
        output [3:0] ay0_a,
102
        output [3:0] ay0_b,
103
        output [3:0] ay0_c,
104
        output [3:0] ay1_a,
105
        output [3:0] ay1_b,
106
        output [3:0] ay1_c
107
);
108
  reg wait_n, nmi_n, busrq_n;
109
 
110
  wire [7:0]cpu_in, cpu_out;
111
  wire [15:0]adr;
112
  wire m1_n, mreq_n, iorq_n, rd_n, wr_n, rfsh_n, halt_n, busak_n;
113
  wire bus_error;
114
 
115 3 gryzor
 
116
        wire [3:0] ay0_a, ay0_b, ay0_c, ay1_a, ay1_b, ay1_c;
117
        wire [15:0] amp0_y, amp1_y;
118
 
119
  wire [7:0]ram_out, rom_out, latch_out;
120
  wire rom_enable = adr<16'h4000 ? 1:0;
121
  wire ram_enable = adr>=16'h4000 && adr<16'h4800 ? 1:0;
122
  wire latch_enable = adr==16'h6000 ? 1 : 0;
123
  wire ay_0_enable = adr==16'h8000 || adr==16'h8001 ? 1:0;
124
  wire ay_1_enable = adr==16'hC000 || adr==16'hC001 ? 1:0;
125
  assign bus_error = ~ram_enable & ~rom_enable & ~latch_enable &
126
    ~ay_0_enable & ~ay_1_enable;
127 4 gryzor
  assign cpu_in=ram_out | rom_out | latch_out;
128 3 gryzor
/*
129
        always @(negedge rd_n)
130
                if( !rd_n       && adr==8'h38 )
131
                        $display("IRQ processing started @ %t us",$time/1e6);
132
*/
133 4 gryzor
  initial begin
134
    nmi_n=1;
135
    wait_n=1;
136
  end
137
 
138
  tv80n cpu( //outputs
139
  .m1_n(m1_n), .mreq_n(mreq_n), .iorq_n(iorq_n), .rd_n(rd_n), .wr_n(wr_n),
140
  .rfsh_n(rfsh_n), .halt_n(halt_n), .busak_n(busak_n), .A(adr), .do(cpu_out),
141
  // Inputs
142
  .reset_n(reset_n), .clk(clk), .wait_n(wait_n),
143
  .int_n(int_n), .nmi_n(nmi_n), .busrq_n(busrq_n), .di(cpu_in) );
144
 
145
  RAM ram(.adr(adr[10:0]), .din(cpu_out), .dout(ram_out), .enable( ram_enable ),
146 3 gryzor
    .clk(clk), .wr_n(wr_n), .rd_n(rd_n) );
147
  ROM rom(.adr(adr[13:0]), .data(rom_out), .enable(rom_enable),
148
   .rd_n(rd_n), .clk(clk));
149
  SOUND_LATCH sound_latch( .dout(latch_out), .enable(latch_enable),
150
    .clk(clk), .rd_n(rd_n) );
151
 
152
//      fake_ay ay_0( .adr(adr[0]), .din(din), .clk(clk), .wr_n(~ay_0_enable|wr_n) );
153
 
154 4 gryzor
        AY_3_8910_capcom #(dump_regs,0) ay_0( .reset_n(reset_n), .clk(clk), .sound_clk(sound_clk),
155
                .din(cpu_out), .adr(adr[0]), .wr_n(wr_n), .cs_n(~ay_0_enable),
156 3 gryzor
                .A(ay0_a), .B(ay0_b), .C(ay0_c) );
157 4 gryzor
        AY_3_8910_capcom #(dump_regs,1) ay_1( .reset_n(reset_n), .clk(clk), .sound_clk(sound_clk),
158
                .din(cpu_out), .adr(adr[0]), .wr_n(wr_n), .cs_n(~ay_1_enable),
159 3 gryzor
                .A(ay1_a), .B(ay1_b), .C(ay1_c) );
160
endmodule
161
 
162
//////////////////////////////////////////////////////////
163
// this module is used to check the communication of the
164
// Z80 with the AY-3-8910
165
// only used for debugging
166
module fake_ay(
167
        input adr,
168
  input [7:0] din,
169
  input clk,
170
  input wr_n );
171
 
172
        reg [7:0] contents[1:0];
173
        wire sample = clk & ~wr_n;
174
 
175
        always @(posedge sample) begin
176
//              if( contents[adr] != din ) begin
177
                $display("%t -> %d = %d", $realtime/1e6, adr, din );
178
                if( !adr && din>15 ) $display("AY WARNING");
179
                contents[adr] = din;
180
        end
181
 
182
endmodule
183
 
184
//////////////////////////////////////////////////////////
185
module RAM(
186
  input [10:0] adr,
187
  input [7:0] din,
188
  output reg [7:0] dout,
189
  input enable,
190
  input clk,
191
  input rd_n,
192
  input wr_n );
193
 
194
reg [7:0] contents[2047:0];
195
wire sample = clk & (~rd_n | ~wr_n );
196
 
197
initial dout=0;
198
 
199
always @(posedge sample) begin
200
  if( !enable )
201
    dout=0;
202
  else begin
203
    if( !wr_n ) contents[adr]=din;
204
    if( !rd_n ) dout=contents[adr];
205
  end
206
end
207
endmodule
208
 
209
//////////////////////////////////////////////////////////
210
module ROM(
211
  input  [13:0] adr,
212
  output reg [7:0] data,
213
  input enable,
214
  input rd_n,
215
  input clk );
216
 
217
reg [7:0] contents[16383:0];
218
 
219
wire sample = clk & ~rd_n;
220
 
221
initial begin
222
  $readmemh("../rom/sr-01.c11.hex", contents ); // this is the hex dump of the ROM
223
  data=0;
224
end
225
 
226
always @( posedge sample ) begin
227
  if ( !enable )
228
    data=0;
229
  else
230
    data=contents[ adr ];
231
end
232
endmodule
233
 
234
//////////////////////////////////////////////////////////
235
module SOUND_LATCH(
236
  output reg [7:0] dout,
237
  input enable,
238
  input clk,
239
  input rd_n );
240
 
241
wire sample = clk & ~rd_n;
242
reg [7:0]data;
243
 
244
initial begin
245
        dout=0;
246
        data=0;
247
        #100e6 data=8'h12; // enter the song/sound code here
248
end
249
 
250
always @(posedge sample) begin
251
  if( !enable )
252
                dout=0;
253
  else begin
254
    if( !rd_n ) begin
255
                        // $display("Audio latch read @ %t us", $realtime/1e6 );
256
//                      if( data != 0 ) 
257
//                        $display("Audio latch read (%X) @ %t us", data, $realtime/1e6 );
258
                        dout=data;
259
                end
260
  end
261
end
262
endmodule
263
 

powered by: WebSVN 2.1.0

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