[cmds] Add paint program for IA16, OWC and C86 by ghaerr · Pull Request #2259 · ghaerr/elks (original) (raw)
Adds paint program for drawing and saving images on ELKS. Compiles using any of ELKS compiler toolchains including
IA16, OpenWatcom, and C86.
To run, type paint at the ELKS prompt with MOUSE_PORT= set to the mouse serial. QEMU should work out of the box. Some special keys are 'f' for flood fill, 'c' to clear and 'q' to quit; the brush sizes colors and clear/exit are also available on the control panel. The final painted image can be saved as a .bmp file by clicking the 'floppy' icon, but beware, as the image is likely not able to fit on a 1440k disk, as it requires 232k (!).
The original application source came from the cool TomentPainter program which was written for SDL2. The application was then rewritten to optionally use floating point if available, and use an enhanced version of the ELKS graphics routines from 8086-toolchain/examples/graphics.c also with the portable event handling routines from there and the mouse/cursor display routines from Nano-X. All were enhanced to run on ia16-elf-gcc, OpenWatcom, or C86. The OpenWatcom graphics ASM code was originally written by @rafael2k.
Currently, the paint application is fairly small, and ranges from 12k-22k depending on compiler and whether floating point emulation is included. It runs standalone, outside of Nano-X.
The plan, suggested originally by @toncho11, will be to add the graphics, event management, and mouse routines into the ELKS C library, supported for all three compilers.
There's a lot of cool stuff happening behind the scenes that was required to get paint operational. A graphics cursor had to be implemented that follows the mouse input and displays a cursor on the screen. This turned out to be faster than Nano-X, and thus the larger 16x16 cursor is being shown. Various icons are also displayed on the control panel, and it was decided that unlike Nano-X, the images should not be loaded into memory, but read from a file and displayed scanline-by-scanline, in order to allow images in any compiler model and use only a 640 bytes of memory, at the expense of having to open a file each time the image is displayed. (The OWC build is still large model for now, but C86 and IA16 are small model).
The program source is in elkscmd/gui, and the IA16 version is automatically built and fits onto the 1440k image. If the WATCOM= or C86= environment variables are set, then typing "make" in that directory will also build the those versions, which are named opaint and cpaint respectiviely. This is useful for compiler portability testing as well as observing code size. A new C86 compiler bug was found and "flood fill" won't compile for the time being.
This project is also a precursor to allow new programs to be added to the ELKS source tree and compiled by either the GCC/IA16, OWC or C86 compilers. As such, three template makefiles (Makefile.gcc, Makefile.owc and Makefile.c86) are included which should be be used as templates to allow for future easy integration. More work coming on that.
