When I build the below code, I get the following error.
While this code is a obviously a construed example, I have games where this error is actually occurring due to the build up of the memory use in the zp over a number of various valid functions.
sdcc -mmos6502 --opt-code-speed --max-allocs-per-node 10000 --data-loc 0x0001 --code-loc 0x4000 zptest.c -o zptest.ihx
?ASlink-Warning-Paged Area ZP Length Error
#include <stdint.h>
uint8_t buffer[64];
///< Hold three pointers and a 16 bit total live across a call to the next one
///< down, so the spill slots of the two cannot be overlaid
#define ZP_SPILL_FUNCTION( name, next ) \
uint8_t name( uint8_t *a, uint8_t *b, uint8_t *c, uint8_t i ) { \
\
uint8_t *p = a + i; \
uint8_t *q = b + i; \
uint8_t *r = c + i; \
uint16_t total = 0; \
\
while ( i-- ) { \
\
total += *p++; \
*q++ = total >> 8; \
*r++ = total; \
} \
\
return total + *p + *q + *r + next( a, b, c, 3 ); \
}
///< Ten of them at a time, named zp_spill_<ten>0 to zp_spill_<ten>9 and each
///< calling the one before it. "below" is what the first of the ten calls, so
///< passing the last of the previous ten carries the chain on across the groups
#define ZP_SPILL_DECADE( ten, below ) \
ZP_SPILL_FUNCTION( zp_spill_##ten##0, below ) \
ZP_SPILL_FUNCTION( zp_spill_##ten##1, zp_spill_##ten##0 ) \
ZP_SPILL_FUNCTION( zp_spill_##ten##2, zp_spill_##ten##1 ) \
ZP_SPILL_FUNCTION( zp_spill_##ten##3, zp_spill_##ten##2 ) \
ZP_SPILL_FUNCTION( zp_spill_##ten##4, zp_spill_##ten##3 ) \
ZP_SPILL_FUNCTION( zp_spill_##ten##5, zp_spill_##ten##4 ) \
ZP_SPILL_FUNCTION( zp_spill_##ten##6, zp_spill_##ten##5 ) \
ZP_SPILL_FUNCTION( zp_spill_##ten##7, zp_spill_##ten##6 ) \
ZP_SPILL_FUNCTION( zp_spill_##ten##8, zp_spill_##ten##7 ) \
ZP_SPILL_FUNCTION( zp_spill_##ten##9, zp_spill_##ten##8 )
///< Bottom of the chain, keeps nothing live
uint8_t zp_spill_leaf( uint8_t *a, uint8_t *b, uint8_t *c, uint8_t i ) {
(void)b;
(void)c;
return a[i];
}
ZP_SPILL_DECADE( 0, zp_spill_leaf )
ZP_SPILL_DECADE( 1, zp_spill_09 )
ZP_SPILL_DECADE( 2, zp_spill_19 )
ZP_SPILL_DECADE( 3, zp_spill_29 )
///< Enter at the top, so the whole chain is reachable and nothing is dropped
int main( void ) {
return zp_spill_39( buffer, buffer + 8, buffer + 16, 4 );
}
Looking at the map, REGTEMP starts at 169h, then fills from there. I'd like to request adding the variables filling the ZP before REGTEMP to the map file so it's possible to see what's causing the problem.
ZP 00000001 00000170 = 368. bytes (REL,CON,PAG)
Value Global Global Defined In Module
00000169 REGTEMP __sdcc_regs
00000169 ___SDCC_m6502_ret0 __sdcc_regs
....
$ sdcc -v
SDCC : z80/sm83/ez80/z80n/mos6502/mos65c02 4.6.2 #16701 (Linux)