module glass(
//win1,win2,//window1 and window2
clk,rst,//clock and reset
up,down,// upward or downward action
val,// input referring the present state of the window
mov,tmp,// output registers
posi,// current position ina 2 bit representation
incr,decr// junk registers
);
input /*win1, win2,*/clk,rst;
input up,down;//up or down
input [1:0] val;
output [1:0] mov;
//reg up, down;
output reg [1:0] posi,incr, decr,tmp;
reg [1:0] mov;// for using in case
parameter [1:0] s1=2'b00, s2=2'b01, s3=2'b10, s4=2'b11;
always@(posedge clk) begin
if (rst) begin
mov<=2'b11;
posi<=2'b11;
incr<=2'b11;
decr<=2'b11;
end else if (down) begin
if (posi == 2'b00) begin
posi=2'b00;
end else begin
decr=decr-1;
posi=decr;
end
end else if (up) begin
if (incr == 2'b11) begin
posi=2'b11;
end else begin
incr=incr+1;
posi=incr;
end
end else begin
posi<=val;
end
case(posi)
00:if(up) begin
mov<=01;
end else begin
mov<=00; end
01:if(up) begin
mov<=10;
end else if (down) begin
mov<=00;
end else
mov<=01;
10:if(up) begin
mov<=11;
end else if (down) begin
mov<=01;
end else
mov<=10;
11:if (down) begin
mov<=10;
end else
mov<=11;
default:mov<=posi;
endcase
//end
end
endmodule