I have some 6502 machine-language routines that I'd like to be as portable as possible across all, or as many as possible, Commodore 8-bit machines, including the PET (BASIC 1.0, 2.0, 4.0), VIC-20 and C64 (BASIC 2.0), C16, C116 and Plus/4 TED machines (BASIC 3.5) and the C128 (BASIC 7.0).

I sometimes require temporary zero-page storage just for the duration of my routine. (Indirect addressing modes on the 6502 are available only through zero-page locations, so storage elsewhere is not an option for those.) The criteria for an ideal temporary location are as below, roughly in order of importance.

It's probable that there are few or even no locations for which all all criteria can be satisfied for all machines; don't let that stop you from proposing locations that satisfy as many of them as you can manage. Answers should discuss any limitations of proposed memory locations, including what machines they won't work on, which of the criteria below are not being met, under what circumstances the routines using those locations would be unsafe to call, and anything else that might be relevant to making an engineering decision about using those locations in the a particular application. To be clear, I am not seeking perfection here, and answers and comments saying "this can't be done perfectly" are unhelpful.

  1. The locations are not used by anything run during interrupt service, so they will not be changed under me as my routine runs.

  2. Changing the locations will not break the KERNAL, including not interfering with ongoing I/O that might be in progress by my callers.

  3. If my routine is being called from a running BASIC program, changing the locations will not interfere with the running program. If it's being called from the machine-language monitor (for those models that have it), changing the locations will not interfere with the monitor.

  4. If the locations are used in interactive mode between program runs (i.e. at the BASIC prompt), BASIC re-initialises them when it needs those locations so that I can safely leave my trash in them after my routine exits.

  5. The locations are not obvious "popular" locations (such as $FB-$FE on the C64) that other routines I didn't write are likely to want to use for long-term storage.

Ideal locations would be ones that are used by ROM routines strictly for very short-term storage (i.e., only while the routine is running) and not used by any code that could be called from interrupts. (The known use by ROM routines would ensure that user-written machine-language routines will not be using those locations for long-term storage.)

These sorts of locations seem to be fairly easy to find for individual systems (e.g., $03-$06 "storage for RENUMBER," according to the Plus/4 PRG), but looking through various individual memory maps for the PET, C64 and Plus/4 there seem to be a lot of differences, enough that it's hard to find locations satisfying the criteria above.

I'd also be interested in any references to zero-page memory maps that cover multiple systems, rather than just particular computers (e.g. C64) or particular families (e.g., TED series).

  • 2
    Good question. Frankly, I think #5 kills it. There are so few "free" addresses to choose from that its practically guaranteed that something else will (eventually) conflict with your usage. Best solution might be to restore what you use, modulo #1, so you don't have to disable interrupts too.
    – Brian H
    May 23, 2022 at 18:14
  • Might be hard. If it's about temporary use as pointers, the floating point accumulators are a good bet - unless your routine gets called during expression evaluation. Then again, if it's just for a pointer or two, then saving the original value from FAC* to an area within your program and back might as well work.
    – Raffzahn
    May 23, 2022 at 18:18
  • @BrianH Neither #5 nor any of the other criteria can "kill" it; I've updated the question to clarify this. I'm not clear on what you mean by "free" addresses, but if you mean those not used by the KERNAL or BASIC, the point of #5 is that I'm trying to avoid those. Ideally I want locations that are used by other routines, but with whom I can safety share use of that space. (Locations used by the ROM strictly for short-term temporary variables would be ideal.)
    – cjs
    May 24, 2022 at 2:09
  • 4
    I have the sneaking suspicion that this Venn diagram has no intersection.
    – Joe
    May 24, 2022 at 2:54
  • 1
    @MichaelGraf No need to "suspect"; when I said "all, or as many as possible" machines I had (perhaps mistakenly) thought that it was clear that the end users of this information (who I am presuming are not just me) would be making the usual engineering decisions based on their particular requirements and the trade-offs they're willing to make. I have updated the question to try to clarify this.
    – cjs
    May 24, 2022 at 5:45


You must log in to answer this question.

Browse other questions tagged .