Kjetil's Information Center: A Blog About My Projects

CP/M Emulator C99 Compatibility

I have made some changes to my "kaytil" Z80 CP/M 2.2 emulator to support compilation on older Linux distributions. This meant removing some C11 specific changes I made and reverting back to C99.

The source files used for the DOS and Windows targets are also affected so that might also be a benefit. The GR-SAKURA and Raspberry Pi Pico target specific source files are not changed since the hardware for those is newer than C11. When compiling for Linux the "_POSIX_C_SOURCE" is also defined since it is required to reach some of the standard library functions with C99.

The biggest change required when going to C99 was the replacement of anonymous structures and unions with named ones. Some additional macros were added to help with this transition. There was a unexpected "bug" appearing when compiling for Linux with C99 as well; the arrival of the SIGALRM signal would result in a program termination. The solution was to change from using signal() to using sigaction() for setting up the signal handler.

I also looked into going as far back as supporting pure C89 and made some minor changes for that as well. But I stopped due to the lack "bit-field" support, which required a lot of changes. The code is compilable with -std=c89 but will give warnings with the -Wpedantic flag set.

Here is a screenshot running on Slackware 11.0 in QEMU and compiled with GCC 3.4.6:

Emulator within an emulator!

The version has been bumped to 0.4 and the new package be found here or gotten from the Git repo.

Topic: Open Source, by Kjetil @ 16/02-2024, Article Link