Duck Shoot Game

J

jacko

I have the following code which uses di, do duck in duck out to
represent a duck in the sights of a gun. Load save provide loading and
saving, run runs the process, rw, sel control selection as write
gating, comde controls compute an reverses it, busy signals that do is
not valid or r/w etc should not be done yrt.

It simulates a duck in the sights from a duck pond. The fast 0 ducks
are less likly to be in the sights than a 1 or slow duck. The bias of
expected ducks fast being harder to target is the goal.

It's BSD licence and free non comercial use. I'm looking to get a
better bias to slow ducks in the sights. The process must be
reversable for practical reasons. Any comments and suggestions are
most welcome.


-- (C)2008 K Ring Technologies Semiconductor
-- BSD http://nibz.googlecode.com (no support)
-- Comercial licencing available
-- Tel: +44 796 797 3001 (a real space odessy)
-- Maintained by Simon Jackson, BEng.
-- E-mail: (e-mail address removed)

-- Hardware support kodek for nibz

library ieee;
-- library altera;

use ieee.std_logic_1164.all;
use ieee.std_logic_arith.all;

entity k is
port (
do : buffer std_Logic;
di : in std_logic;
busy : buffer std_logic;
comde : std_logic;
clk : in std_logic;
-- a rising edge signal (run)
run : in std_logic;
-- for setting the prbs
-- may be of use as a general prbs ...
load : in std_logic_vector(15 downto 0);
save : buffer std_logic_vector(15 downto 0);
rw : in std_logic;
sel : in std_logic
);
end entity;

architecture rtl of k is
signal asymproc : std_logic;
signal which : std_logic;
type s is (action,motion);
signal state : s;
-- intermediates
signal wind : std_logic_vector(4 downto 0);
signal procp : std_logic_vector(1 downto 0);
signal tapx : std_logic;
signal ends : std_logic;
-- process control flags
signal procdo : std_logic;
signal winddo : std_logic;
signal modo : std_logic;
signal runlast : std_logic;
constant tap : natural := 3;
signal pmux : std_logic_vector(15 downto 0);
begin
process(clk)
-- prbs
begin

end process;

procp <= pmux(1 downto 0);
procdo <= procp(1) and procp(0);
-- set motion velocities via probability switching
modo <= procdo xor which xor do xor '1';
-- set sampling window
wind <= pmux(7 downto 3);
winddo <= wind(4) and wind(3) and wind(2) and
wind(1) and wind(0);

process(clk)
-- k state machine
begin
if(rising_edge(clk)) then
runlast <= run;
end if;
if(rising_edge(clk) and busy = '1') then
case state is
when motion =>
asymproc <= asymproc xor modo;
state <= action;
when action =>
if(asymproc = '0') then
if(which = '0') then
-- sample
if(winddo = '1') then
busy <= '0';
-- sample do
end if;
else
-- random
do <= do xor procp(0);
end if;
else
which <= which xor procdo;
end if;
state <= motion;
end case;
-- NB. if 2nd rising edge run before busy zero
-- then ignored
elsif(rising_edge(clk) and runlast = '0' and run = '1') then
-- set busy, cleared by kodek finish bit
busy <= '1';
do <= di;
end if;
-- prbs
if(comde = '1') then
ends <= save(15);
else
ends <= save(0);
end if;
tapx <= save(tap) xor ends;
if(rising_edge(clk) and busy = '1') then
if(comde = '1') then
save <= save(14 downto 0)&tapx;
else
save <= tapx&save(15 downto 1);
end if;
end if;
if(comde = '1') then
pmux <= save;
else
pmux <= tapx&save(15 downto 1);
end if;
-- load
if(rising_edge(clk) and sel = '1' and rw = '0') then
-- NB. a load while busy can be a random number gen
-- but not much use in general operation
-- do a kind of reset
asymproc <= '0'; -- rand/samp side
which <= '0'; -- samp side
state <= motion; -- perform motion methods first
-- (begin and end on them)
-- assign essentials
save <= load;
end if;
end process;
end rtl;
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,743
Messages
2,569,478
Members
44,898
Latest member
BlairH7607

Latest Threads

Top