Page MenuHomePhorge

Head.vhd
No OneTemporary

Size
3 KB
Referenced Files
None
Subscribers
None

Head.vhd

library IEEE;use IEEE.STD_LOGIC_1164.all;use IEEE.NUMERIC_STD.all;use work.local_types.all;entity Head is generic(AREAWIDTH:natural:=64;AREAHEIGHT:natural:=48);port(clk:in std_ulogic;run_head:in std_ulogic;head_done:out std_ulogic;head_death:out std_ulogic;reset:in std_ulogic;tile_coord:out coordinate_t;tile_from_GA:in game_tile;tile_to_GA:out game_tile;set_tile:out std_ulogic;head_pos:in coordinate_t;direction:in direction_t);end Head;architecture asdj1928 of Head is type stDK1923 is(stA1b2c3d,stE4f5g6h,stI7j8k9l,stM0n1o2p,stQ3r4s5t,stU6v7w8x,stY9z0a1b,stC2d3e4f,stG5h6i7j,stK8l9m0n,stO1p2q3r,stS4t5u6v,stW7x8y9z);signal sgCrtSt,sgNxtSt:stDK1923;signal sgLstDr:direction_t;signal sgNxtDr:direction_t;signal sgNxtHd:coordinate_t;signal sgLstHd:coordinate_t;signal sgHdTl:game_tile;signal sgBdTl:game_tile;signal sgNxtX:integer;signal sgNxtY:integer;function fnOppo(argDr:direction_t)return direction_t is begin case argDr is when UP=>return DOWN;when DOWN=>return UP;when LEFT=>return RIGHT;when RIGHT=>return LEFT;end case;end function;constant csOrg:coordinate_t:=(x=>(others=>'0'),y=>(others=>'0'));constant csEmp:game_tile:=(is_tail=>'0',is_head=>'0',is_apple=>'0',is_body=>'0',parent=>csOrg);begin sgHdTl.is_head<='1';sgHdTl.is_tail<='0';sgHdTl.is_apple<='0';sgHdTl.is_body<='0';sgHdTl.parent.y<="000000";sgHdTl.parent.x<="000000";sgBdTl.is_head<='0';sgBdTl.is_tail<='0';sgBdTl.is_apple<='0';sgBdTl.is_body<='1';prcRg:process(clk)begin if reset='1'then sgCrtSt<=stA1b2c3d;sgLstDr<=UP;elsif rising_edge(clk)then sgCrtSt<=sgNxtSt;if sgCrtSt=stK8l9m0n then sgLstDr<=sgNxtDr;elsif sgCrtSt=stI7j8k9l then if direction=fnOppo(sgLstDr)then sgNxtDr<=sgLstDr;else sgNxtDr<=direction;end if;elsif sgCrtSt=stM0n1o2p then if sgNxtDr=UP then sgNxtX<=to_integer(unsigned(head_pos.x));sgNxtY<=to_integer(unsigned(head_pos.y))-1;elsif sgNxtDr=DOWN then sgNxtX<=to_integer(unsigned(head_pos.x));sgNxtY<=to_integer(unsigned(head_pos.y))+1;elsif sgNxtDr=LEFT then sgNxtX<=to_integer(unsigned(head_pos.x))-1;sgNxtY<=to_integer(unsigned(head_pos.y));elsif sgNxtDr=RIGHT then sgNxtX<=to_integer(unsigned(head_pos.x))+1;sgNxtY<=to_integer(unsigned(head_pos.y));end if;elsif sgCrtSt=stQ3r4s5t then sgNxtHd.x<=std_ulogic_vector(to_unsigned(sgNxtX,6));sgNxtHd.y<=std_ulogic_vector(to_unsigned(sgNxtY,6));sgLstHd<=head_pos;elsif sgCrtSt=stG5h6i7j then sgBdTl.parent.x<=sgNxtHd.x;sgBdTl.parent.y<=sgNxtHd.y;end if;end if;end process;prcNs:process(sgCrtSt,run_head,direction,tile_from_GA)begin case sgCrtSt is when stA1b2c3d=>sgNxtSt<=stE4f5g6h;when stE4f5g6h=>if run_head='1'then sgNxtSt<=stI7j8k9l;else sgNxtSt<=stE4f5g6h;end if;when stI7j8k9l=>sgNxtSt<=stM0n1o2p;when stM0n1o2p=>sgNxtSt<=stQ3r4s5t;when stQ3r4s5t=>if sgNxtX>(AREAWIDTH-1)or sgNxtY>(AREAHEIGHT-1)or sgNxtX<0 or sgNxtY<0 then sgNxtSt<=stW7x8y9z;else sgNxtSt<=stU6v7w8x;end if;when stU6v7w8x=>sgNxtSt<=stY9z0a1b;when stY9z0a1b=>sgNxtSt<=stC2d3e4f;when stC2d3e4f=>sgNxtSt<=stG5h6i7j;when stG5h6i7j=>if tile_from_GA.is_body='1'or tile_from_GA.is_tail='1'then sgNxtSt<=stW7x8y9z;else sgNxtSt<=stK8l9m0n;end if;when stK8l9m0n=>sgNxtSt<=stO1p2q3r;when stO1p2q3r=>sgNxtSt<=stS4t5u6v;when stW7x8y9z=>sgNxtSt<=stE4f5g6h;when stS4t5u6v=>sgNxtSt<=stE4f5g6h;end case;end process;prcOp:process(sgCrtSt)begin tile_to_GA<=csEmp;head_done<='0';head_death<='0';set_tile<='0';tile_coord.x<=csOrg.x;tile_coord.y<=csOrg.y;case sgCrtSt is when stA1b2c3d=>null;when stE4f5g6h=>null;when stI7j8k9l=>null;when stM0n1o2p=>null;when stQ3r4s5t=>null;when stG5h6i7j=>null;when stU6v7w8x=>tile_coord<=sgNxtHd;when stY9z0a1b=>tile_coord<=sgNxtHd;when stC2d3e4f=>tile_coord<=sgNxtHd;when stK8l9m0n=>tile_coord<=sgNxtHd;set_tile<='1';tile_to_GA<=sgHdTl;when stO1p2q3r=>tile_coord<=sgLstHd;set_tile<='1';tile_to_GA<=sgBdTl;when stW7x8y9z=>head_death<='1';when stS4t5u6v=>head_done<='1';end case;end process;end asdj1928;

File Metadata

Mime Type
text/plain
Expires
Sat, May 30, 11:49 PM (23 h, 31 s)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
329979
Default Alt Text
Head.vhd (3 KB)

Event Timeline