Re: [cc65] Newbie question: memcpy

Date view Thread view Subject view

From: MagerValp (MagerValp_at_cling.gu.se)
Date: 2003-01-13 14:08:53


>>>>> "TS" == Tim Schürmann <tischuer_at_web.de> writes:

TS> I try to backup a hires graphic in memory by using malloc/memcpy.
TS> Why does the following code won't work? As you can see, i'm using
TS> loadkoala to exclude any other errors.

The memory that you malloc here:

TS>     /* Allocating mem for backup */
TS>     bitmap_buffer=(unsigned char*)malloc(8000);

Gets overwritten by your copy here:

TS>     memcpy ((void*)0x2000, bitmap_buffer, 8000);

As no special linker config was used for loadkoala, the memory at
$2000 is available to cc65's heap and gets allocated by malloc. To
protect $2000..$3fff, use a linker config like this:

MEMORY {
    ZP: start = $02, size = $1A, type = rw;
    RAM1: start = $7FF, size = $1801, define = yes, file = %O;
    RAM2: start = $4000, size = $9000, define = yes, file = %O;
}
SEGMENTS {
    CODE: load = RAM1, type = wprot;
    RODATA: load = RAM1, type = wprot;
    DATA: load = RAM1, type = rw;
    BSS: load = RAM2, type = bss, define = yes;
    ZEROPAGE: load = ZP, type = zp;
}
FEATURES {
    CONDES: segment = RODATA,
            type = constructor,
            label = __CONSTRUCTOR_TABLE__,
            count = __CONSTRUCTOR_COUNT__;
    CONDES: segment = RODATA,
            type = destructor,
            label = __DESTRUCTOR_TABLE__,
            count = __DESTRUCTOR_COUNT__;
}
SYMBOLS {
    __STACKSIZE__ = $800;       # 2K stack
}

This will use $0800..$1fff for code and $4000..$cfff for the
dynamically allocated data. I *think* :)

-- 
    ___          .     .  .         .       . +  .         .      o   
  _|___|_   +   .  +     .     +         .  Per Olofsson, arkadspelare
    o-o    .      .     .   o         +          MagerValp_at_cling.gu.se
     -       +            +    .     http://www.cling.gu.se/~cl3polof/
----------------------------------------------------------------------
To unsubscribe from the list send mail to majordomo_at_musoftware.de with
the string "unsubscribe cc65" in the body(!) of the mail.


Date view Thread view Subject view

This archive was generated by hypermail 2.1.3 : 2003-01-13 14:10:13 CET