On Mon, Dec 6, 2010 at 7:57 AM, Dave Dribin <ddribin@gmail.com> wrote: > I'm trying to replicate this bit of assembly code (used on an NES) in C: > > lda $2002 ; Read PPU status to reset the high/low latch > lda #$20 ; Write the high byte of $2000 > sta $2006 ; . > lda #$00 ; Write the low byte of $2000 > sta $2006 ; . > > The addresses $2002 and $2006 correspond to memory mapped registers. > THus, even though the result of the first read is ignore, it still > needs to be performed to put the device in the correct state. Here's > my attempt at the C version: > > Typically the 'volatile' keyword tells the compiler not to perform > this optimization. Since the 'volatile' keyword is parsed, but has no > effect, how do I go about doing this with C in cc65? Read the value to a dummy variable. If there's a better way, I'd like to know also. Btw, Uz, there's a bug in CC65 optimizer which occurs when reading the controller in NES. Like this (_M is a macro to access a byte in memory): _M(0x4016) = 1; _M(0x4016) = 0; // capture the controller state { byte btn_a = _M(0x4016) & 1; // this read is optimized away, the optimizer assumes the value is 1 byte btn_b = _M(0x4016) & 1; byte btn_select = _M(0x4016) & 1; // etc } -thefox ---------------------------------------------------------------------- To unsubscribe from the list send mail to majordomo@musoftware.de with the string "unsubscribe cc65" in the body(!) of the mail.Received on Mon Dec 6 09:40:52 2010
This archive was generated by hypermail 2.1.8 : 2010-12-06 09:40:55 CET