Re: [cc65] ca65 question

From: Ullrich von Bassewitz <uz1musoftware.de>
Date: 2008-01-21 21:18:46
Hi!

On Mon, Jan 21, 2008 at 06:12:17PM +0100, silverdr@inet.com.pl wrote:
> I'd say it is somewhat counterintuitive to me but I hope I got it
> correctly in the end?

Yes.

> The question - can I fully rely on this behaviour or are there still
> other factors, which may affect the (re)location of the code upon
> linking?

This behaviour is intentional, you can rely on it.

> Another question - how is it done that compiled and linked C programs
> don't require special care about LOAD pointer bytes? Can I use some
> implicit behaviour to achieve the same or is it part of the c64 (or
> other for other systems) library, which gets linked in the STARTUP
> and actually does similar thing to what I do in the BASICSTUB?

Exactly. What seems like a little bit of magic is nothing more than some code
in the STARTUP segment, that has a BASIC header and calls the actual
initialization code, which in turn calls main(). Since the STARTUP segment
goes always first into RAM (as defined by the linker config), you will always
have the header in the correct location regardless which file it is in.

> >It assumes that zeropage locations
> >are addressed directly.
>
> Could you be so kind as to elaborate still a bit on this?

With "addressed directly" I meant something like

        zp1     := $02
        zp2     := $04

        lda     (zp1),y
        ...

You can use a segment instead:

        .zeropage

        zp1:    .res    2
        zp2:    .res    2

        .code

        lda     (zp1),y
        ...

The latter needs two additions to the linker config:

----------------------------------------------------------------------
MEMORY {
    ZP:  start = $0002, size = $001A, type = rw, define = yes;
    RAM: start = $07FF, size = $C801, file = %O, define = yes;
}
SEGMENTS {
    BASICSTUB: load = RAM, type = ro;
    CODE:      load = RAM, type = ro;
    DATA:      load = RAM, type = rw;
    ZEROPAGE:  load = ZP,  type = zp;
}
----------------------------------------------------------------------

The advantage is that you just need to relink in case of changes, the
disadvantage is that it becomes difficult if you're going to use several zero
page locations in different places (not adjacent).

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 Mon Jan 21 21:19:01 2008

This archive was generated by hypermail 2.1.8 : 2008-01-21 21:19:04 CET