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

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



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.

-- 
Shawn Jefferson
(fix reply to for email)