When compiling my engine for 128K mode, I need some data to be placed in addresses below 0xC000. This was not a problem until now that I have quite a lot of code: since the standard memory layout is CODE-DATA-BSS (from bottom to top of memory), CODE size has pushed the DATA+BSS sections into the higher end of the memory, putting some data above 0xC000.
Searching for a solution, I saw this link which states:
...which I found quite convenient: my CRT could be really something like "LD SP,XXXX; DI; CALL _main", and then I can manage my data to be in low memory by carefully specifying the list of object files for my program, putting first the data that needs to be in low memory, then the rest of the code. My memory layout would just be the object file order as found by the linker.You don't have to use the library-supplied crts nor do the crts have to be as sophisticated as the above. You may prefer to have something very simple or something with a different memory map. If the compile line contains "-startup=-1" a local file "crt.asm" will be taken as the crt. The crt must set up the environment and call _main at minimum. If no memory map is set up, the output will be a single binary blob with CODE, DATA, BSS items mixed in the order the linker encounters them.
So far I have created the mentioned crt.asm.m4 (crt.asm alone did not work) and changed my compilation line (-startup=-1), but I have got some weird errors about some missing symbols that I believe my program does not use:
It seems that the configuration is not as easy as the docs indicate and the library uses some other CRT...
Code: Select all
[jorgegv@endor rage1]$ cat crt.asm.m4 extern _main start: di ld sp,0x8181 call _main jp start [jorgegv@endor rage1]$ make -fMakefile-48 main.bin Bulding main.bin.... zcc +zx -vn -SO3 --c-code-in-asm --list -s -m -compiler=sdcc -clib=sdcc_iy --max-allocs-per-node200000 -pragma-include zpragma-48.inc -Iengine/include -Ibuild/generated engine/lowmem/bswitch.o engine/lowmem/asmdata.o engine/src/btile.o engine/src/bullet.o engine/src/codeset.o engine/src/collision.o engine/src/controller.o engine/src/dataset.o engine/src/debug.o engine/src/enemy.o engine/src/flow.o engine/src/game_loop.o engine/src/game_state.o engine/src/hero.o engine/src/hotzone.o engine/src/interrupts.o engine/src/inventory.o engine/src/main.o engine/src/map.o engine/src/memory.o engine/src/screen.o engine/src/sp1engine.o engine/src/sprite.o build/game_src/game_functions.o build/game_src/user_functions.o build/generated/game_data.o engine/src/beeper.o -startup=-1 -o main.bin Error at file 'alloc/malloc/z80/asm_heap_init.asm' line 49: symbol 'mtx_plain' not defined Error at file 'threads/mutex/z80/asm_mtx_init.asm' line 57: symbol 'thrd_success' not defined Error at file 'threads/mutex/z80/asm_mtx_init.asm' line 62: symbol 'thrd_error' not defined Errors in source file /home/jorgegv/src/spectrum/z88dk/lib/config//../..//libsrc/_DEVELOPMENT/target/zx/zx_crt.asm.m4: Error at file 'alloc/malloc/z80/asm_heap_init.asm' line 49: symbol 'mtx_plain' not defined Error at file 'threads/mutex/z80/asm_mtx_init.asm' line 57: symbol 'thrd_success' not defined Error at file 'threads/mutex/z80/asm_mtx_init.asm' line 62: symbol 'thrd_error' not defined make: *** [Makefile.common:111: main.bin] Error 1
Do you have any recommendations about this approach? Or should I dive into the wonders of low level CRT configuration? is there a good reference about CRT + memory map configuration?
Thanks in advance