[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: cc65 / ca65: how to interface C and assembly?



Shawn Jefferson wrote:
Linards Ticmanis <ticmanis@gmx.de>:


One more thing, on the Apple many hardware funktions are activated by accessing certain addresses. It's only the access that matters, the data read or written is irrelevant. But when I use peekpoke.h and say something like "PEEK(0xC030);" without using the result for anything, it gets optimized away. I've settled on "*((char *)0xC030) = __AX__;", which gives a "pure" store, storing whatever is currently in A; but this is problematic for some addresses, since the 6502 accesses an address twice during a write. Some of these "softswitches" are toggle switches, so you need to read them, which produces only one access; writing them toggles them back and forth instead.

Is there any way to get a "pure" load, i.e. make the compiler emit just an LDA (or a BIT, or whatever) but to ignore the result? I mean without resorting to inline assembly. I tried to do it with "volatile" but that doesn't seem to have any effect.


A volatile type would be great.  I have a program that suffers from a
similiar problem, in that I store a value to a memory location to check for
the presence of hardware.  If I check for that value in that location right
after the assignment, the optimizer optimizes it away.  I got around it by
putting the check far enough down in the code from the assignment that the
optimizer doesn't remember it.

A volatile type is a necessity in any optimized language used to
access addresses when the access has side effects.  As noted, the
Apple (and indeed, any 6502 machine) is loaded with such side effects.

One must also make some "policy" decisions about indirect accesses
(through pointers).  Without explicit information to the contrary,
it is best to assume that a pointer *cannot* point to a volatile,
since to do otherwise would eliminate almost all optimizations.

-michael

Music synthesis for 8-bit Apple II's!
Home page:  http://members.aol.com/MJMahon/

"The wastebasket is our most important design
tool--and it is seriously underused."