In conventional internal combustion engines, valves are opened and closed using a cam surface. The cam is kinematically related to the piston positions through the crankshaft and timing belt. In contrast, there is no crankshaft or kinematic cam surface in a free-piston engine to physically realize this mechanism. As a consequence, a free-piston engine has variable stroke lengths, which presents a challenge for active piston motion and precise stroke length control. This paper presents a virtual-cam based approach to relate free-piston motion to actuated engine valve control within a clear and familiar intuitive physical context. The primary functionality of the virtual cam control framework is to create a variable index, which is adjustable from cycle to cycle, for the exhaust/injection valves and spark timing similar to the function of physical cams in conventional engines. Since the cam is virtually created, it can be dynamically rebuilt to comply with cycle-to-cycle variations such as amount of the air/fuel supply, engine load and stroke length. This index rebuilding process is based on a cycle-to-cycle adaptive control method that uses the knowledge obtained from previous cycles to adjust the cam parameters. Preliminary experimental results are presented for a novel liquid-piston free-piston engine intended as a compact and efficient energy source for untethered power dense pneumatic systems such as untethered robots.