Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
import synthesijer.rt.*;
public class Sjr_Block
{
private static final int LINE_WIDTH = 64;
private static final int STAGE_WIDTH = 32;
private static final int VRAM_WIDTH = 40;
private static final int VRAM_HEIGHT = 30;
private static final byte BALL_COLOR = (byte)255;
private static final byte WALL_COLOR = (byte)109;
private static final byte NONE_COLOR = (byte)0;
private static final int BALL_NUM = 4;
private static final int BLOCK_NUM = 30;
private static final int STATE_GAMEOVER = 0;
private static final int STATE_PLAYING = 1;
private static final int STATE_CLEAR = 2;
private static final int BOARD_KEY0 = 1;
private static final int BOARD_KEY1 = 2;
private static final int BOARD_KEY2 = 4;
private static final int BOARD_KEY3 = 8;
private static final int DEFAULT_GAMESPEED = 4;
private static final int DEFAULT_PADDLESIZE = 5;
private static final int MIN_GAMESPEED = 1;
private static final int MIN_PADDLESIZE = 3;
private static final int SHOTBALLTIME = 45;
private int random = -59634649;
private final VgaVram8 vram = new VgaVram8();
private final SoundGenerator psg = new SoundGenerator();
private final HexLED hexLED = new HexLED();
private final RedLED redLED = new RedLED();
private final BoardSwitch boardSW = new BoardSwitch();
private final BoardKey boardKey = new BoardKey(); // Game
private final byte[] blockColor = new byte[120];
private final boolean[] blockEnable = new boolean[120];
private final boolean[] blockWall = new boolean[120];
private final int[] ballX = new int[4];
private final int[] ballY = new int[4];
private final int[] ballDx = new int[4];
private final int[] ballDy = new int[4];
private final boolean[] ballEnable = new boolean[4];
private int paddleX = 16;
private int paddleY = 28;
private int paddleSize;
private int gameSpeed;
private int ballCount = 4;
private int stageState = 0;
private int ballOnStage = 0;
private int shotBallTimer = 0;
private int score = 0;
private int stageScore = 0;
private int sleepCount = 0; // Sequencer
private final int[] seqTime = new int[64];
private final int[] seqDuration = new int[64];
private final int[] seqChannel = new int[64];
private final int[] seqNote = new int[64];
private final int[] seqOctave = new int[64];
private int seqStartSample;
private int seqPointer = 0;
private int seqMusicLength;
private int rand()
{
int r = random;
r = r ^ (r << 13);
r = r ^ (r >>> 17);
r = r ^ (r << 5);
random = r;
return r;
}
// out
if (ny > paddleY)
{
psg.play(3);
ballEnable[i] = false;
ballCount--;
if (ballCount == 0)
{
stageState = STATE_GAMEOVER;
}
}
}
i++;
}
}
private void fillRect(int x, int y, int width, int height, byte color)
{
int iy = y << 6 /*LINE_WIDTH_IN_BITS*/;
int iye = (y + height) << 6 /*LINE_WIDTH_IN_BITS*/;
int ixe = x + width;
while (iy < iye)
{
int ix = x;
while (ix < ixe)
{
vram.data[ix + iy] = color;
ix++;
}
iy += LINE_WIDTH;
}
}
private void drawBlock(int id)
{
byte color;
if (blockEnable[id] == true)
{
color = blockColor[id];
}
else
{
color = NONE_COLOR;
}
int x = id & 7;
int y = id >>> 3;
fillRect(x << 2, y << 1, 4, 2, color);
}
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
public class SoundGenerator extends Thread
{
public int sample = 0;
private static final int CHANNELS = 4;
private static final int ZERO = 0;
private final AudioOutput audio = new AudioOutput(); // 以下のフィールドは親スレッドから書き換えられるので run() 内ではread only
private final int[] freq = new int[4];
private final int[] pitchBend = new int[4];
private final int[] vol_R = new int[4];
private final int[] vol_L = new int[4];
private final int[] gateTime = new int[4];
private final int[] decay = new int[4]; // 以下のフィールドは run() 内で読み書き可
private final int[] localFreq = new int[4];
private final int[] localVol_R = new int[4];
private final int[] localVol_L = new int[4];
private final int[] localGateTime = new int[4];
private final int[] localDecay = new int[4];
private final int[] localFreqCounter = new int[4];
private final int[] noteData = new int[12]; // 両方から読み書きするフィールド
private final boolean[] playFlag = new boolean[4];
private final boolean[] stopFlag = new boolean[4];
public void setParameter(int channel, int note_in, int octave_in, int pitchBend_in, int vol_R_in, int vol_L_in, int gateTime_in, int decay_in)
{
freq[channel] = noteData[note_in] >>> (8 - octave_in);
pitchBend[channel] = pitchBend_in;
vol_R[channel] = vol_R_in;
vol_L[channel] = vol_L_in;
gateTime[channel] = gateTime_in;
decay[channel] = decay_in;
}
public void play(int channel)
{
playFlag[channel] = true;
}
public void stop(int channel)
{
stopFlag[channel] = true;
}
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
always @(posedge clk)
begin
if (reset == 1'b1)
begin
toggle <= 1'b0;
data_in <= 1'd0;
toggle_prev <= 1'b0;
end
else
begin
toggle <= valid_toggle;
data_in <= data;
toggle_prev <= toggle;
end
end
always @(posedge ext_clka)
begin
if (ext_reseta == 1'b1)
begin
sample_sum_r_ca <= 1'd0;
sample_sum_l_ca <= 1'd0;
data_valid_ca <= 1'b0;
data_out_reg_ca <= 1'd0;
read_freq_counter <= 1'd0;
end
else
begin // read data delays 1 cycle
data_valid_ca <= req_ca;
if (data_valid_ca)
begin
data_out_reg_ca <= data_out_ca;
end // delta sigma
sample_sum_r_ca <= sample_sum_r_ca[15:0] + data_out_reg_ca[31:16];
sample_sum_l_ca <= sample_sum_l_ca[15:0] + data_out_reg_ca[15:0]; // read data once per READ_FREQ+1 cycles
if (read_freq_counter == 9'd0)
begin
read_freq_counter <= READ_FREQ;
end
else
begin
read_freq_counter <= read_freq_counter - 1'd1;
end
end
end
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
always @(posedge clk_cr)
begin
if ((req_cr == 1'b1) && (empty_cr == 1'b0))
begin
addr_r_cr <= addr_r_next_cr;
addr_r_gray_cr <= bin2gray(addr_r_next_cr);
end
end
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
always @(posedge clk_out)
begin
data_out_d2 <= data_out_d1;
data_out_d1 <= data_in;
end
assign data_out = data_out_d2;
endmodule
cdc_synchronizer.v : 同期化回路
/*
Copyright (c) 2015-2016, miya
All rights reserved.
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
// latency: 2 clk_in cycles + 3 clk_out cycles // data_in value must be held for 4 clk_out cycles
module cdc_synchronizer
#(
parameter DATA_WIDTH=8
)
(
input clk_in,
input clk_out,
input [(DATA_WIDTH-1):0] data_in,
output [(DATA_WIDTH-1):0] data_out,
input reset_in
);
always @(posedge clk_in)
begin
if (reset_in == 1'b1)
begin
change_flag_in <= 1'b0;
end
else if (data_in_reg != data_in)
begin
change_flag_in <= ~change_flag_in;
end
data_in_reg <= data_in;
end
always @(posedge clk_out)
begin
if (change_flag_out[2] == change_flag_out[1])
begin
data_out_reg[2] <= data_out_reg[1];
end
end
always @(posedge clk_out)
begin
change_flag_out <= {change_flag_out[1:0], change_flag_in};
data_out_reg[1] <= data_out_reg[0];
data_out_reg[0] <= data_in_reg;
end