Not complete, probably not fully debugged or optimized.
Original version, by Stevens Le Blond and Michael Valkering.