The cc65 cross-compiler is my compiler of choice for my Apple II projects. It ships with a very good and complete runtime for Apple II computers; but so far, it had one drawback: it could either build for apple2
or apple2enh
targets, with the latter using 65c02
opcodes, and hence being only usable on Apple II computers with a ‘c02. If one wanted to support the good old 6502, one had to build for apple2
.
Inconveniently, so far, the cc65 runtime made assumptions about what was possible for a given Apple II based on that build target: apple2enh
got support for 80 columns, lowercase characters, MouseText characters, and Up/Down/Del and Open-Apple keys. apple2
did not. Users of non-enhanced Apple //e computers were missing on these:
cc65 target | 80 columns | Lowercase | MouseText | Up/Down/… | Runs on: |
apple2 | NO | NO | NO | NO | Apple ][+ Apple //e Enhanced //e //c //c+ IIgs |
apple2enh | YES | YES | YES | YES | Enhanced //e //c //c+ IIgs |
Also, the apple2enh
target did make an assumption that a 80-columns card was present, which is not necessarily the case on an Enhanced //e.
I’ve recently put in a bit of work so that when building for apple2
, every one of those features could be dynamically tested and enabled if possible. The new compatibility matrix is as follows:
cc65 target | 80 columns | Lowercase | MouseText | Up/Down/… | Runs on: |
apple2 | YES if present (//e or greater) | YES if present (//e or greater) | YES if present (Enhanced //e or greater) | YES if present (//e or greater) | Apple ][+ Apple //e Enhanced //e //c //c+ IIgs |
apple2enh | YES if present | YES | YES | YES | Enhanced //e //c //c+ IIgs |
This will allow motivated cc65 users (like me!) to target apple2
and still use these features, with two advantages:
- A single binary/floppy image to ship and still support all Apple II computers
- More features for users of the non-enhanced, 6502-based Apple //e.
How to check whether a feature is available on the computer your program runs on?
- For 80 columns support: call
videomode(VIDEOMODE_80COL)
. If it returns -1, there is no 80-columns hardware. - For lowercase text: Just use lowercase in your program, cc65 will uppercase everything if running on an Apple ][+.
- For MouseText characters: check that
get_ostype() >= APPLE_IIEENH
. MouseText characters are also used forchline
,cvline
and the various box-drawing characters. You can#define DYN_BOX_DRAW
to have the runtime automatically adapt. - For Up/Down/Del/Open-Apple characters: check that
get_ostype() >= APPLE_IIE
(or check nothing, but have alternate keys for Up/Down in your code).
Memory usage and program size:
Of course, dynamically checking things does have a cost in terms of memory and program size.
Program size and memory usage does not change for binaries built for apple2enh
(apart for videomode() users, where the hardware’s presence is now checked at startup and costs 45 bytes on disk, and 1 byte in memory after that).
apple2
binaries get bigger by about 190 bytes on disk, and about 100 of those stay in memory after startup.
The biggest increase of memory usage will be if your program uses different strings dynamically, depending on the availability of a 80 columns card: basically embedding two versions of your TUI in a single binary will have a memory cost!