The sm array in your program is a local variable. Such variables are allocated on the stack. They are also uninitialized, and this explains why the first program did not work. You could simply make it static to allocate it in the data segment. But if you do so, the compiler is going to complain that there is no space to allocate a contiguous array of 38kb. A simple fix would be to make it an array of chars instead of ints. Another fix would be to make it a bitmap: See the _bitset_xxx() functions of the glcc c library. Declarations in <gigatron/libc.h>, implementation at https://github.com/lb3361/gigatron-lcc/ ... /_bitset.c
The stack is not checked: it can grow over the data or even the program. Checking would be far too expensive. You can use option --frags to know where program and data live. The malloc heap and the stack then share the rest. If you do not use malloc, the --frags option tells you what you have. If you use malloc, the map file still reserves a little bit of space for he stack. For --map=64, the stack grows downwards from 0xfffc and space is reserved until 0xfc00. The last scanline of the screen memory is at 0x7f00-0x7f9f. That leaves a maximum of 32860 bytes for the stack. For map=-32k, do not expect the stack to have more than 256 bytes!
The map files define all this. For instance the 64k map, https://github.com/lb3361/gigatron-lcc/ ... 64k/map.py, defines all the usable segments with
Code: Select all
# ------------size----addr----step----end---- flags (1=nocode, 2=nodata, 4=noheap) segments = [ (0x0060, 0x08a0, 0x0100, 0x80a0, 0), (0x00fa, 0x0200, 0x0100, 0x0500, 0), (0x0200, 0x0500, None, None, 0), (0x0100, 0x8100, None, None, 0), (0x79c0, 0x8240, None, None, 0) ] initsp = 0xfffc