refactor text/lores drawing routines to C