Taken initially from https://forum.crystalfontz.com/showthread.php?6637-Text-graphic-C-code-for-CFAF320240&p=28164 from user cosmicvoid