FUNCTION tick_cnt (get_ticket1, get_ticket2, clk) 
RETURNS (ticket[3..0]);

FUNCTION time_cnt (enable, clk) 
RETURNS (time[7..0]);

FUNCTION speed_ch (accel_in, reset, clk) 
RETURNS (get_ticket);

FUNCTION auto_max (dir[1..0], accel, clk, reset) 
RETURNS (speed_too_fast, at_altera, get_ticket);

SUBDESIGN chiptrip
(
	dir[1..0]		: INPUT;
	accel			: INPUT;
	clock			: INPUT;
	reset			: INPUT;
	enable			: INPUT;

	time[7..0]		: OUTPUT;
	at_altera		: OUTPUT;
	ticket[3..0]	: OUTPUT;
)
VARIABLE
	tick			: tick_cnt;
	time_c			: time_cnt;
	speed			: speed_ch;
	auto			: auto_max;

BEGIN
	auto.clk = GLOBAL(clock);
	time_c.clk = GLOBAL(clock);
	speed.clk = GLOBAL(clock);
	tick.clk = GLOBAL(clock);

	auto.reset = reset;
	speed.reset = reset;

	auto.(dir[1..0]) =	dir[1..0];
	auto.accel = accel;

	time_c.enable = enable;

	tick.get_ticket1 = auto.get_ticket;
	tick.get_ticket2 = speed.get_ticket;

	speed.accel_in = auto.speed_too_fast;

	time[7..0] = time_c.time[7..0];

	at_altera = auto.at_altera;

	ticket[3..0] = tick.ticket[3..0];

END;

