Re: [cc65] Overlay Demo: C64 Port ?

From: Ullrich von Bassewitz <uz1musoftware.de>
Date: 2009-10-02 16:19:49
Hi!

On Thu, Oct 01, 2009 at 11:29:18PM +0200, Oliver Schmidt wrote:
> Such a demo makes especially sense because users tend to think in the
> direction of cc65 loadable modules when it comes to overlays, although
> the "single link to multiple output files" approach is way better
> suited to overlays. Right now the demo only works on Apple2 machines
> but I'd really like to see it run at least on the C64 too. Therefore I
> ask for your help...

I cannot really see a problem, but this may be my fault:-) C64 programs are
loaded to the BASIC start address ($801), but the programmer is free to
partition the available memory as he likes. The basic structure would be:


        Program start ($801)    -> +------------+
                                   |  STARTUP   |
                                   +------------+
                                   |  LOWCODE   |
                                   +------------+
                                   |    INIT    |
                                   +------------+
                                   |    CODE    |
                                   +------------+
                                   |   RODATA   |
                                   +------------+
                                   |    DATA    |
                                   +------------+
                                   |    BSS     |
                                   +------------+
                                   | HEAP&STACK |
        Boundary, ie. $A000     -> +------------+
                                   |            |
                                   |  OVERLAYS  |
                                   |            |
        Top of memory ($D000)   -> +------------+


So all that's necessary is to end the RAM memory area at some boundary
determined by the non overlayed code&data size of the program. The memory
above that is shared by the overlays similar to your concept on the apple.

An (untested) linker config for this scenario:

------------------------------------------------------------------------------
MEMORY {
    ZP:       start = $0002, size = $001A, type = rw, define = yes;
    RAM:      start = $07FF, size = $9801, file = %O, define = yes;
    OVLAY1:   start = $A000, size = $3000, file = "overlaydemo.1"; # Added
    OVLAY2:   start = $A000, size = $3000, file = "overlaydemo.2"; # Added
    OVLAY3:   start = $A000, size = $3000, file = "overlaydemo.3"; # Added
}
SEGMENTS {
    STARTUP:  load = RAM,    type = ro;
    LOWCODE:  load = RAM,    type = ro,               optional = yes;
    INIT:     load = RAM,    type = ro, define = yes, optional = yes;
    CODE:     load = RAM,    type = ro;
    OVL1CODE: load = OVLAY1, type = ro, define   = yes; # Added
    OVL2CODE: load = OVLAY2, type = ro, define   = yes; # Added
    OVL3CODE: load = OVLAY3, type = ro, define   = yes; # Added
    RODATA:   load = RAM,    type = ro;
    DATA:     load = RAM,    type = rw;
    ZPSAVE:   load = RAM,    type = bss;
    BSS:      load = RAM,    type = bss, define = yes;
    ZEROPAGE: load = ZP,     type = zp;
}
FEATURES {
    CONDES: segment = INIT,
	    type = constructor,
	    label = __CONSTRUCTOR_TABLE__,
	    count = __CONSTRUCTOR_COUNT__;
    CONDES: segment = RODATA,
	    type = destructor,
	    label = __DESTRUCTOR_TABLE__,
	    count = __DESTRUCTOR_COUNT__;
    CONDES: segment = RODATA,
	    type = interruptor,
	    label = __INTERRUPTOR_TABLE__,
	    count = __INTERRUPTOR_COUNT__;
}
SYMBOLS {
    __STACKSIZE__: value = $0800, weak = yes; # 2k stack
}
------------------------------------------------------------------------------

It should even be possible to define a symbol like "OVERLAY_SIZE" and use this
to determine the boundary between regular and and overlay memory are in the
linker config. If you make this symbol "weak", it can be specified on the
command line. And if its default value is zero, you have the standard linker
config (provided that the linker accepts zero sized memory areas).

Similar linker scripts should also work for the other platforms.

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 Fri Oct 2 16:21:46 2009

This archive was generated by hypermail 2.1.8 : 2009-10-02 16:21:50 CEST