My guess is that something like FreeDOS, combined with DJGPP as a toolchain, and Allegro as a graphics library might conceivably fit into 512k of flash and still do a reasonable job (I'm assuming you have an x86 which has several Mb of ram here)
But these things are very x86 specific (Allegro is not though).
It is tricky to get a Linux kernel and a useful amount of userspace software inside 512k (but possible to get SOMETHING in)