data/full_repos/permissive/521104862/resources/Psychic5_core_ModelSim/Psychic5_cpuboard/Psychic5_sound.v
1: b'%Error: data/full_repos/permissive/521104862/resources/Psychic5_core_ModelSim/Psychic5_cpuboard/Psychic5_sound.v:19: Cannot find include file: Psychic5_emu.svh\n`include "Psychic5_emu.svh" \n         ^~~~~~~~~~~~~~~~~~\n        ... Looked in:\n             data/full_repos/permissive/521104862/resources/Psychic5_core_ModelSim/Psychic5_cpuboard,data/full_repos/permissive/521104862/Psychic5_emu.svh\n             data/full_repos/permissive/521104862/resources/Psychic5_core_ModelSim/Psychic5_cpuboard,data/full_repos/permissive/521104862/Psychic5_emu.svh.v\n             data/full_repos/permissive/521104862/resources/Psychic5_core_ModelSim/Psychic5_cpuboard,data/full_repos/permissive/521104862/Psychic5_emu.svh.sv\n             Psychic5_emu.svh\n             Psychic5_emu.svh.v\n             Psychic5_emu.svh.sv\n             obj_dir/Psychic5_emu.svh\n             obj_dir/Psychic5_emu.svh.v\n             obj_dir/Psychic5_emu.svh.sv\n%Error: Exiting due to 1 error(s)\n'
module Psychic5_sound
(
    input   wire            i_EMU_MCLK,

    input   wire            i_EMU_CLK5MPCEN_n,
    input   wire            i_EMU_CLK5MNCEN_n,
    input   wire            i_EMU_OPNCEN_n,

    input   wire            i_EMU_INITRST_n,

    input   wire            i_SOUNDCPU_FORCE_RST_n,

    input   wire    [7:0]   i_SOUNDCODE,

    output  wire    [15:0]  o_SOUND,

    input   wire    [16:0]  i_EMU_BRAM_ADDR,
    input   wire    [7:0]   i_EMU_BRAM_DATA,
    input   wire            i_EMU_BRAM_WR_n,

    input   wire            i_EMU_BRAM_SOUNDROM_CS_n
);










wire            SOUNDCPU_RST_n = i_EMU_INITRST_n & i_SOUNDCPU_FORCE_RST_n;

wire            SOUNDCPU_CTRL_IORQ_n, SOUNDCPU_CTRL_MREQ_n;
wire            SOUNDCPU_CTRL_RD_n, SOUNDCPU_CTRL_WR_n;

wire    [15:0]  SOUNDCPU_ADDR_BUS;
reg     [7:0]   SOUNDCPU_DATA_READ_BUS;
wire    [7:0]   SOUNDCPU_DATA_WRITE_BUS;

wire            SOUNDCPU_INT_n;

T80pa soundcpu (
    .RESET_n                    (SOUNDCPU_RST_n             ),
    .CLK                        (i_EMU_MCLK                 ),
    .CEN_p                      (~i_EMU_CLK5MPCEN_n         ),
    .CEN_n                      (~i_EMU_CLK5MNCEN_n         ),
    .WAIT_n                     (1'b1                       ),
    .INT_n                      (SOUNDCPU_INT_n             ),
    .NMI_n                      (1'b1                       ),
    .RD_n                       (SOUNDCPU_CTRL_RD_n         ),
    .WR_n                       (SOUNDCPU_CTRL_WR_n         ),
    .A                          (SOUNDCPU_ADDR_BUS          ),
    .DI                         (SOUNDCPU_DATA_READ_BUS     ),
    .DO                         (SOUNDCPU_DATA_WRITE_BUS    ),
    .IORQ_n                     (SOUNDCPU_CTRL_IORQ_n       ),
    .M1_n                       (                           ),
    .MREQ_n                     (SOUNDCPU_CTRL_MREQ_n       ),
    .BUSRQ_n                    (1'b1                       ),
    .BUSAK_n                    (                           ),
    .RFSH_n                     (                           ),
    .out0                       (1'b0                       ),
    .HALT_n                     (                           )
);















wire            soundprog_cs_n =    (SOUNDCPU_ADDR_BUS[15] == 1'b0) ? SOUNDCPU_CTRL_MREQ_n :
                                    (SOUNDCPU_ADDR_BUS[14] == 1'b0) ? SOUNDCPU_CTRL_MREQ_n : 1'b1;
wire            soundram_cs_n  =    (SOUNDCPU_ADDR_BUS[15:13] == 3'b110) ? SOUNDCPU_CTRL_MREQ_n : 1'b1;
wire            soundcode_cs_n =    (SOUNDCPU_ADDR_BUS[15:13] == 3'b111) ? SOUNDCPU_CTRL_MREQ_n : 1'b1;


wire            sound_opn1_cs_n = (SOUNDCPU_ADDR_BUS[7] == 1'b0) ? SOUNDCPU_CTRL_IORQ_n : 1'b1;
wire            sound_opn2_cs_n = (SOUNDCPU_ADDR_BUS[7] == 1'b1) ? SOUNDCPU_CTRL_IORQ_n : 1'b1;













wire    [7:0]       soundprog_dout;


`ifdef FASTBOOT
PROM #(.aw( 15 ), .dw( 8 ), .pol( 1 ), .simhexfile("roms/rom_2b.txt")) ROM_2B
(
    .i_EMU_PROG_CLK             (                           ),
    .i_EMU_PROG_ADDR            (                           ),
    .i_EMU_PROG_DIN             (                           ),
    .i_EMU_PROG_CS_n            (1'b1                       ),
    .i_EMU_PROG_WR_n            (                           ),
    
    .i_MCLK                     (i_EMU_MCLK                 ),
    .i_ADDR                     (SOUNDCPU_ADDR_BUS[14:0]    ),
    .o_DOUT                     (soundprog_dout             ),
    .i_CS_n                     (soundprog_cs_n             ),
    .i_RD_n                     (1'b0                       )
);

`else
PROM #(.aw( 15 ), .dw( 8 ), .pol( 1 ), .simhexfile()) ROM_2B
(
    .i_EMU_PROG_CLK             (i_EMU_MCLK                 ),
    .i_EMU_PROG_ADDR            (i_EMU_BRAM_ADDR[14:0]      ),
    .i_EMU_PROG_DIN             (i_EMU_BRAM_DATA            ),
    .i_EMU_PROG_CS_n            (i_EMU_BRAM_SOUNDROM_CS_n   ),
    .i_EMU_PROG_WR_n            (i_EMU_BRAM_WR_n            ),
    
    .i_MCLK                     (i_EMU_MCLK                 ),
    .i_ADDR                     (SOUNDCPU_ADDR_BUS[14:0]    ),
    .o_DOUT                     (soundprog_dout             ),
    .i_CS_n                     (soundprog_cs_n             ),
    .i_RD_n                     (1'b0                       )
);

`endif








wire    [7:0]       soundram_dout;

SRAM #(.aw( 11 ), .dw( 8 ), .pol( 1 ), .simhexfile()) MAINRAM
(
    .i_MCLK                     (i_EMU_MCLK                 ),
    .i_ADDR                     (SOUNDCPU_ADDR_BUS[10:0]    ),
    .i_DIN                      (SOUNDCPU_DATA_WRITE_BUS    ),
    .o_DOUT                     (soundram_dout              ),
    .i_CS_n                     (soundram_cs_n              ),
    .i_RD_n                     (SOUNDCPU_CTRL_RD_n         ),
    .i_WR_n                     (SOUNDCPU_CTRL_WR_n         )
);









wire    [7:0]   opn1_dout, opn2_dout;

wire            [9:0]   opn1_psg, opn2_psg;
wire    signed  [15:0]  opn1_fm, opn2_fm;

jt03 opn1 (
    .rst                        (~SOUNDCPU_RST_n            ),
    .clk                        (i_EMU_MCLK                 ),
    .cen                        (~i_EMU_OPNCEN_n            ),
    .din                        (SOUNDCPU_DATA_WRITE_BUS    ),
    .addr                       (SOUNDCPU_ADDR_BUS[0]       ),
    .cs_n                       (sound_opn1_cs_n            ),
    .wr_n                       (SOUNDCPU_CTRL_WR_n         ),

    .dout                       (opn1_dout                  ),
    .irq_n                      (SOUNDCPU_INT_n        ),


    .IOA_in                     (8'hFF                      ),
    .IOB_in                     (8'hFF                      ),


    .psg_A                      (                           ),
    .psg_B                      (                           ),
    .psg_C                      (                           ),
    .fm_snd                     (opn1_fm                    ),


    .psg_snd                    (opn1_psg                   ),
    .snd                        (                           ),
    .snd_sample                 (                           ),


    .debug_view                 (                           )
);

jt03 opn2 (
    .rst                        (~SOUNDCPU_RST_n            ),
    .clk                        (i_EMU_MCLK                 ),
    .cen                        (~i_EMU_OPNCEN_n            ),
    .din                        (SOUNDCPU_DATA_WRITE_BUS    ),
    .addr                       (SOUNDCPU_ADDR_BUS[0]       ),
    .cs_n                       (sound_opn2_cs_n            ),
    .wr_n                       (SOUNDCPU_CTRL_WR_n         ),

    .dout                       (opn2_dout                  ),
    .irq_n                      (                           ),


    .IOA_in                     (8'hFF                      ),
    .IOB_in                     (8'hFF                      ),


    .psg_A                      (                           ),
    .psg_B                      (                           ),
    .psg_C                      (                           ),
    .fm_snd                     (opn2_fm                    ),


    .psg_snd                    (opn2_psg                   ),
    .snd                        (                           ),
    .snd_sample                 (                           ),


    .debug_view                 (                           )
);








always @(*)
begin
    if(!SOUNDCPU_CTRL_RD_n)
    begin
        if(!SOUNDCPU_CTRL_MREQ_n)
        begin
            case({soundprog_cs_n, soundram_cs_n, soundcode_cs_n})
                3'b011: SOUNDCPU_DATA_READ_BUS <= soundprog_dout;
                3'b101: SOUNDCPU_DATA_READ_BUS <= soundram_dout;
                3'b110: SOUNDCPU_DATA_READ_BUS <= i_SOUNDCODE;
                default: SOUNDCPU_DATA_READ_BUS <= 8'hFF;
            endcase
        end
        else if(!SOUNDCPU_CTRL_IORQ_n)
        begin
            case({sound_opn1_cs_n, sound_opn2_cs_n})
                2'b01: SOUNDCPU_DATA_READ_BUS <= opn1_dout;
                2'b10: SOUNDCPU_DATA_READ_BUS <= opn2_dout;
                default: SOUNDCPU_DATA_READ_BUS <= 8'hFF;
            endcase
        end
        else
        begin
            SOUNDCPU_DATA_READ_BUS <= 8'hFF;
        end
    end
    else 
    begin
        SOUNDCPU_DATA_READ_BUS <= 8'hFF;
    end
end














reg     [2:0]   mixer_rc = 3'b110;
always @(posedge i_EMU_MCLK) begin
    if(!i_EMU_INITRST_n) begin
        mixer_rc <= 3'b110;
    end
    else begin
        mixer_rc[0] <= mixer_rc[2];
        mixer_rc[2:1] <= mixer_rc[1:0];
    end
end

reg     signed  [15:0]  st1_opn1_psg, st1_opn2_psg, st1_opn1_fm, st1_opn2_fm;
reg     signed  [15:0]  st2_opn1_snd, st2_opn2_snd;
reg     signed  [16:0]  st3_mixed_snd;
assign  o_SOUND = {st3_mixed_snd[16], st3_mixed_snd[14:0]};

always @(posedge i_EMU_MCLK) begin
    if(!i_EMU_INITRST_n) begin
        st1_opn1_psg <= 16'sd0; st1_opn2_psg <= 16'sd0; st1_opn1_fm <= 16'sd0; st1_opn2_fm <= 16'sd0;
        st2_opn1_snd <= 16'sd0; st2_opn2_snd <= 16'sd0;
        st3_mixed_snd <= 16'sd0;
    end
    else begin
        if(!mixer_rc[0]) begin
            st1_opn1_psg <= $signed({1'b0, opn1_psg * 5'd6});
            st1_opn2_psg <= $signed({1'b0, opn2_psg * 5'd6});
            st1_opn1_fm <= opn1_fm * 16'sd1;
            st1_opn2_fm <= opn2_fm * 16'sd1;
        end
        else if(!mixer_rc[1]) begin
            st2_opn1_snd <= st1_opn1_psg + st1_opn1_fm;
            st2_opn2_snd <= st1_opn2_psg + st1_opn2_fm;
        end
        else if(!mixer_rc[2]) begin
            st3_mixed_snd <= st2_opn1_snd + st2_opn2_snd;
        end
    end
end


endmodule
module Psychic5_sound
(
    input   wire            i_EMU_MCLK,

    input   wire            i_EMU_CLK5MPCEN_n,
    input   wire            i_EMU_CLK5MNCEN_n,
    input   wire            i_EMU_OPNCEN_n,

    input   wire            i_EMU_INITRST_n,

    input   wire            i_SOUNDCPU_FORCE_RST_n,

    input   wire    [7:0]   i_SOUNDCODE,

    output  wire    [15:0]  o_SOUND,

    input   wire    [16:0]  i_EMU_BRAM_ADDR,
    input   wire    [7:0]   i_EMU_BRAM_DATA,
    input   wire            i_EMU_BRAM_WR_n,

    input   wire            i_EMU_BRAM_SOUNDROM_CS_n
);











wire            SOUNDCPU_RST_n = i_EMU_INITRST_n & i_SOUNDCPU_FORCE_RST_n;

wire            SOUNDCPU_CTRL_IORQ_n, SOUNDCPU_CTRL_MREQ_n;
wire            SOUNDCPU_CTRL_RD_n, SOUNDCPU_CTRL_WR_n;

wire    [15:0]  SOUNDCPU_ADDR_BUS;
reg     [7:0]   SOUNDCPU_DATA_READ_BUS;
wire    [7:0]   SOUNDCPU_DATA_WRITE_BUS;

wire            SOUNDCPU_INT_n;

T80pa soundcpu (
    .RESET_n                    (SOUNDCPU_RST_n             ),
    .CLK                        (i_EMU_MCLK                 ),
    .CEN_p                      (~i_EMU_CLK5MPCEN_n         ),
    .CEN_n                      (~i_EMU_CLK5MNCEN_n         ),
    .WAIT_n                     (1'b1                       ),
    .INT_n                      (SOUNDCPU_INT_n             ),
    .NMI_n                      (1'b1                       ),
    .RD_n                       (SOUNDCPU_CTRL_RD_n         ),
    .WR_n                       (SOUNDCPU_CTRL_WR_n         ),
    .A                          (SOUNDCPU_ADDR_BUS          ),
    .DI                         (SOUNDCPU_DATA_READ_BUS     ),
    .DO                         (SOUNDCPU_DATA_WRITE_BUS    ),
    .IORQ_n                     (SOUNDCPU_CTRL_IORQ_n       ),
    .M1_n                       (                           ),
    .MREQ_n                     (SOUNDCPU_CTRL_MREQ_n       ),
    .BUSRQ_n                    (1'b1                       ),
    .BUSAK_n                    (                           ),
    .RFSH_n                     (                           ),
    .out0                       (1'b0                       ),
    .HALT_n                     (                           )
);















wire            soundprog_cs_n =    (SOUNDCPU_ADDR_BUS[15] == 1'b0) ? SOUNDCPU_CTRL_MREQ_n :
                                    (SOUNDCPU_ADDR_BUS[14] == 1'b0) ? SOUNDCPU_CTRL_MREQ_n : 1'b1;
wire            soundram_cs_n  =    (SOUNDCPU_ADDR_BUS[15:13] == 3'b110) ? SOUNDCPU_CTRL_MREQ_n : 1'b1;
wire            soundcode_cs_n =    (SOUNDCPU_ADDR_BUS[15:13] == 3'b111) ? SOUNDCPU_CTRL_MREQ_n : 1'b1;


wire            sound_opn1_cs_n = (SOUNDCPU_ADDR_BUS[7] == 1'b0) ? SOUNDCPU_CTRL_IORQ_n : 1'b1;
wire            sound_opn2_cs_n = (SOUNDCPU_ADDR_BUS[7] == 1'b1) ? SOUNDCPU_CTRL_IORQ_n : 1'b1;













wire    [7:0]       soundprog_dout;


`ifdef FASTBOOT
PROM #(.aw( 15 ), .dw( 8 ), .pol( 1 ), .simhexfile("roms/rom_2b.txt")) ROM_2B
(
    .i_EMU_PROG_CLK             (                           ),
    .i_EMU_PROG_ADDR            (                           ),
    .i_EMU_PROG_DIN             (                           ),
    .i_EMU_PROG_CS_n            (1'b1                       ),
    .i_EMU_PROG_WR_n            (                           ),
    
    .i_MCLK                     (i_EMU_MCLK                 ),
    .i_ADDR                     (SOUNDCPU_ADDR_BUS[14:0]    ),
    .o_DOUT                     (soundprog_dout             ),
    .i_CS_n                     (soundprog_cs_n             ),
    .i_RD_n                     (1'b0                       )
);

`else
PROM #(.aw( 15 ), .dw( 8 ), .pol( 1 ), .simhexfile()) ROM_2B
(
    .i_EMU_PROG_CLK             (i_EMU_MCLK                 ),
    .i_EMU_PROG_ADDR            (i_EMU_BRAM_ADDR[14:0]      ),
    .i_EMU_PROG_DIN             (i_EMU_BRAM_DATA            ),
    .i_EMU_PROG_CS_n            (i_EMU_BRAM_SOUNDROM_CS_n   ),
    .i_EMU_PROG_WR_n            (i_EMU_BRAM_WR_n            ),
    
    .i_MCLK                     (i_EMU_MCLK                 ),
    .i_ADDR                     (SOUNDCPU_ADDR_BUS[14:0]    ),
    .o_DOUT                     (soundprog_dout             ),
    .i_CS_n                     (soundprog_cs_n             ),
    .i_RD_n                     (1'b0                       )
);

`endif








wire    [7:0]       soundram_dout;

SRAM #(.aw( 11 ), .dw( 8 ), .pol( 1 ), .simhexfile()) MAINRAM
(
    .i_MCLK                     (i_EMU_MCLK                 ),
    .i_ADDR                     (SOUNDCPU_ADDR_BUS[10:0]    ),
    .i_DIN                      (SOUNDCPU_DATA_WRITE_BUS    ),
    .o_DOUT                     (soundram_dout              ),
    .i_CS_n                     (soundram_cs_n              ),
    .i_RD_n                     (SOUNDCPU_CTRL_RD_n         ),
    .i_WR_n                     (SOUNDCPU_CTRL_WR_n         )
);









wire    [7:0]   opn1_dout, opn2_dout;

wire            [9:0]   opn1_psg, opn2_psg;
wire    signed  [15:0]  opn1_fm, opn2_fm;

jt03 opn1 (
    .rst                        (~SOUNDCPU_RST_n            ),
    .clk                        (i_EMU_MCLK                 ),
    .cen                        (~i_EMU_OPNCEN_n            ),
    .din                        (SOUNDCPU_DATA_WRITE_BUS    ),
    .addr                       (SOUNDCPU_ADDR_BUS[0]       ),
    .cs_n                       (sound_opn1_cs_n            ),
    .wr_n                       (SOUNDCPU_CTRL_WR_n         ),

    .dout                       (opn1_dout                  ),
    .irq_n                      (SOUNDCPU_INT_n        ),


    .IOA_in                     (8'hFF                      ),
    .IOB_in                     (8'hFF                      ),


    .psg_A                      (                           ),
    .psg_B                      (                           ),
    .psg_C                      (                           ),
    .fm_snd                     (opn1_fm                    ),


    .psg_snd                    (opn1_psg                   ),
    .snd                        (                           ),
    .snd_sample                 (                           ),


    .debug_view                 (                           )
);

jt03 opn2 (
    .rst                        (~SOUNDCPU_RST_n            ),
    .clk                        (i_EMU_MCLK                 ),
    .cen                        (~i_EMU_OPNCEN_n            ),
    .din                        (SOUNDCPU_DATA_WRITE_BUS    ),
    .addr                       (SOUNDCPU_ADDR_BUS[0]       ),
    .cs_n                       (sound_opn2_cs_n            ),
    .wr_n                       (SOUNDCPU_CTRL_WR_n         ),

    .dout                       (opn2_dout                  ),
    .irq_n                      (                           ),


    .IOA_in                     (8'hFF                      ),
    .IOB_in                     (8'hFF                      ),


    .psg_A                      (                           ),
    .psg_B                      (                           ),
    .psg_C                      (                           ),
    .fm_snd                     (opn2_fm                    ),


    .psg_snd                    (opn2_psg                   ),
    .snd                        (                           ),
    .snd_sample                 (                           ),


    .debug_view                 (                           )
);








always @(*)
begin
    if(!SOUNDCPU_CTRL_RD_n)
    begin
        if(!SOUNDCPU_CTRL_MREQ_n)
        begin
            case({soundprog_cs_n, soundram_cs_n, soundcode_cs_n})
                3'b011: SOUNDCPU_DATA_READ_BUS <= soundprog_dout;
                3'b101: SOUNDCPU_DATA_READ_BUS <= soundram_dout;
                3'b110: SOUNDCPU_DATA_READ_BUS <= i_SOUNDCODE;
                default: SOUNDCPU_DATA_READ_BUS <= 8'hFF;
            endcase
        end
        else if(!SOUNDCPU_CTRL_IORQ_n)
        begin
            case({sound_opn1_cs_n, sound_opn2_cs_n})
                2'b01: SOUNDCPU_DATA_READ_BUS <= opn1_dout;
                2'b10: SOUNDCPU_DATA_READ_BUS <= opn2_dout;
                default: SOUNDCPU_DATA_READ_BUS <= 8'hFF;
            endcase
        end
        else
        begin
            SOUNDCPU_DATA_READ_BUS <= 8'hFF;
        end
    end
    else 
    begin
        SOUNDCPU_DATA_READ_BUS <= 8'hFF;
    end
end














reg     [2:0]   mixer_rc = 3'b110;
always @(posedge i_EMU_MCLK) begin
    if(!i_EMU_INITRST_n) begin
        mixer_rc <= 3'b110;
    end
    else begin
        mixer_rc[0] <= mixer_rc[2];
        mixer_rc[2:1] <= mixer_rc[1:0];
    end
end

reg     signed  [15:0]  st1_opn1_psg, st1_opn2_psg, st1_opn1_fm, st1_opn2_fm;
reg     signed  [15:0]  st2_opn1_snd, st2_opn2_snd;
reg     signed  [16:0]  st3_mixed_snd;
assign  o_SOUND = {st3_mixed_snd[16], st3_mixed_snd[14:0]};

always @(posedge i_EMU_MCLK) begin
    if(!i_EMU_INITRST_n) begin
        st1_opn1_psg <= 16'sd0; st1_opn2_psg <= 16'sd0; st1_opn1_fm <= 16'sd0; st1_opn2_fm <= 16'sd0;
        st2_opn1_snd <= 16'sd0; st2_opn2_snd <= 16'sd0;
        st3_mixed_snd <= 16'sd0;
    end
    else begin
        if(!mixer_rc[0]) begin
            st1_opn1_psg <= $signed({1'b0, opn1_psg * 5'd6});
            st1_opn2_psg <= $signed({1'b0, opn2_psg * 5'd6});
            st1_opn1_fm <= opn1_fm * 16'sd1;
            st1_opn2_fm <= opn2_fm * 16'sd1;
        end
        else if(!mixer_rc[1]) begin
            st2_opn1_snd <= st1_opn1_psg + st1_opn1_fm;
            st2_opn2_snd <= st1_opn2_psg + st1_opn2_fm;
        end
        else if(!mixer_rc[2]) begin
            st3_mixed_snd <= st2_opn1_snd + st2_opn2_snd;
        end
    end
end


endmodule