If you can read C code, download the sources of Allegro. May be you can translate it to Pascal. It's a bit complex so may be you should download version 3 instead version 4 (version 3 was DOS only). It uses ASM also but I'm not sure if keyboard used it or was C only.