Re: [cc65] Zeropage Vars

From: Ullrich von Bassewitz <uz1musoftware.de>
Date: 2009-02-05 21:05:55
On Thu, Feb 05, 2009 at 01:16:59PM -0300, Tachdaun wrote:
> The NES library has this zp var defined in [nes.inc]:
> tickcount       = $6b           ;2
>
> Which increments in the NMI interrupt routine ( called each VBlank )
>
> I want to access it from C.
> I've tried this, but it doesn't work, I'm not getting it right:

For a variable to be accessible from C, there must be two conditions met:

  1. The symbol must be .export'ed from an object file somewhere.

  2. The symbol must begin with an underscore, which is automatically
     prepended to all external C identifiers.

The tickcount symbol doesn't meet either condition, so you cannot use it from
C as is.

But there's a simple workaround. Write a small assembler module containing

        .include        "nes.inc"
        _tickcount      := tickcount
        .exportzp       _tickcount

and link the resulting .o file to your application. This will enable you to
use tickcount as described in one of my last mails

> How's the correct way to do this? if it's possible?
> Does #pragma zpsym() create a var in the zp?

No. It does just tell the compiler that a symbol is a zero page symbol, so the
compiler emits a matching .importzp statement. Space has to be allocated
elsewhere.

You can answer questions like this yourself: Just compile your sources using
the "-g" and "-T" command line switches. The former will add debug infos, so
code is attributed with line numbers of the source file, while the latter will
add the actual source file lines to the assembly. Checking the assembly code
will show exactly what code was generated for each C source line.

Regards


        Uz


-- 
Ullrich von Bassewitz                                  uz@musoftware.de
----------------------------------------------------------------------
To unsubscribe from the list send mail to majordomo@musoftware.de with
the string "unsubscribe cc65" in the body(!) of the mail.
Received on Thu Feb 5 21:08:34 2009

This archive was generated by hypermail 2.1.8 : 2009-02-05 21:08:35 CET