Éste puede ser difícil para la traducción automática así que el inglés original aparecerá debajo del español traducido.
saimazoom escribió:Estoy intentando separar en mi juego el código del motor y de las fases. La intención es paginar en 128Kb las fases pero manteniendo el motor por debajo de la 0xC000. He intentado lo siguente:
Hay una manera mucho mejor de hacer esto usando SECTIONs que voy a explicar en el próximo post, pero primero algunos comentarios sobre lo que está haciendo.
1) Primero compilo el motor
Código: Seleccionar todo
zcc +zx ..\libgfx\libgfx.c parser.c juego_compressed.c -o juego.bin -vn -O3 -startup=31 -lfzx -lfzxfonts_utz -m -lzx7
Hay una cierta confusión aquí. "-startup = 31" sólo funciona con la nueva biblioteca C en Z88DK y la nueva biblioteca C sólo se selecciona si aparece "-clib = new", "-clib = sdcc_ix" o "-clib = sdcc_iy" en la línea de compilación. En la nueva librería c, "-startup = 31" elige el código de inicio sin ningún terminal conectado a stdin, stdout, stderr, que es lo que normalmente quieres para juegos.
La nueva biblioteca C y la biblioteca C clásica existen separadamente en z88dk. Cada uno tiene su propio código de puesta en marcha y su propio código de biblioteca. La nueva biblioteca c también contiene FZX, ZX7 y todas las fuentes FZX (incluyendo UTZ) ya, por lo que no es necesario vincularlos o proporcionarlos por separado. Por otro lado, la biblioteca clásica sólo tiene ZX7 y debe ser proporcionado con el resto por separado.
En la compilación anterior está utilizando la clásica biblioteca C y que no define "-startup = 31". No estoy seguro de cómo lo está haciendo funcionar sin errores? La biblioteca C clásica no tiene la opción de desconectar terminales, pero el código de terminal es también muy pequeño cuando no se utilizan.
There is some confusion here. "-startup=31" only works with the new C library in Z88DK and the new C library is only selected if "-clib=new", "-clib=sdcc_ix" or "-clib=sdcc_iy" appears on the compile line. In the new c library, "-startup=31" chooses start up code without any terminals attached to stdin, stdout, stderr which is what you usually want for games.
The new C library and the classic C library exist separately within z88dk. They each have their own start up code and their own library code. The new c library also contains FZX, ZX7 and all the FZX fonts (including UTZ's) already so it's not necessary to link or provide those separately. On the other hand, the classic library only has ZX7 and must be provided with the rest separately.
In the compile above you are using the classic C library and that does not define "-startup=31". I'm not sure how you are getting it to work without errors? The classic C library does not have an option to switch off terminals but the terminal code is also very small when they are not used.
===
Dicho esto, vamos a compilar con la biblioteca clásica. El primer paso es que desea hacer un binario que contiene su motor solamente.
Para hacer eso:
zcc +zx --no-crt ..\libgfx\libgfx.c parser.c juego_compressed.c -o juego.bin -vn -O3 -lfzx -lfzxfonts_utz -lzx7 -gp -m
Necesitará una versión muy reciente de z88dk para usar "-gp" ya que esta característica apareció después de 1.99B. O bien una
nightly build o una actualización a través de
github. Si ejecuta "zcc -h" debería ver "-g Genera un archivo defc global del ejecutable final (-g, -gp, -gpf nombrearchivo)" en las opciones listadas.
"--no-crt" significa que no habrá c código de inicio en la salida. No habrá llamada a main () pero tampoco inicialización de variables. Puesto que está compilando en ram todas las variables que ha definido deben tener sus valores iniciales correctos. Si usted o la biblioteca necesita ejecutar el código de inicialización, tendrá que escribir una función de inicialización por separado suministrando un CRT o una rutina separada para hacerlo.
"-gp" producirá un archivo especial ".def" con símbolos. Éste define todos los símbolos públicos con las exportaciones ("PUBLIC foo; defc foo = ...") que está listo para su uso en otras compilaciones.
No querrá que se exporten todos esos símbolos. Así que usted querrá especificar cuáles desea mantener. Puede hacerlo suministrando un "archivo de coincidencia" que contiene una lista de expresiones regulares, una por línea.
zcc coincidirá con los nombres de los símbolos con ese archivo para determinar cuáles desea en el archivo .def.
Como ejemplo, le mostraré un simple archivo "match.txt" que contiene una expresión regular por línea:
"match.txt"
Las líneas que comienzan con "+" significan aceptar, "-" significan rechazar y ";" Significa ignorar
Las dos primeras líneas aceptarán sólo el símbolo "_printf". La cuarta línea aceptará cualquier símbolo que comience con "asm" y la última línea rechazará todo lo demás.
ZCC pasará por esas reglas para cada símbolo y se detendrá cuando encuentre una coincidencia.
Para utilizar este archivo de reglas:
zcc +zx --no-crt ..\libgfx\libgfx.c parser.c juego_compressed.c -o juego.bin -vn -O3 -lfzx -lfzxfonts_utz -lzx7 -gpf match.txt -m
Ahora verá que el archivo .def se elimina sólo a los símbolos que desea exportar.
That said, let's compile with the classic library. The first step is you want to make a binary containing your engine only.
To do that:
zcc +zx --no-crt ..\libgfx\libgfx.c parser.c juego_compressed.c -o juego.bin -vn -O3 -lfzx -lfzxfonts_utz -lzx7 -gp -m
You will need a very recent version of z88dk to use "-gp" since this feature appeared after 1.99B. Either a
nightly build or update via
github. If you run "zcc -h" you should see "-g Generate a global defc file of the final executable (-g, -gp, -gpf filename)" in the listed options.
"--no-crt" means there will be no c start up code in the output. There will be no call to main() but also no initialization of variables. Since you are compiling into ram any variables you have defined should have their correct initial values. If you or the library needs to run initialization code, you will have to write a separate initialization function by either supplying a CRT or a separate routine to do so.
"-gp" will produce a special ".def" file with symbols. This one defines all your public symbols with exports ("PUBLIC foo ; defc foo = ...") that is ready for use in other compiles.
You won't want all those symbols exported. So you will want to specify which ones you want to keep. You can do that by supplying a "match file" that contains a list of regular expressions, one per line.
zcc will match symbol names to that file to determine which ones you want in the .def file.
As an example, I will show you a simple "match.txt" file containing one regular expression per line:
"match.txt"
Lines beginning with "+" mean accept, "-" mean reject and ";" mean ignore.
The first two lines will accept the "_printf" symbol only. The fourth line will accept any symbols beginning with "asm" and the last line will reject everything else.
ZCC will go through those rules in order for each symbol and stop when it finds a match.
To use this rule file:
zcc +zx --no-crt ..\libgfx\libgfx.c parser.c juego_compressed.c -o juego.bin -vn -O3 -lfzx -lfzxfonts_utz -lzx7 -gpf match.txt -m
Now you will see the .def file is pruned down to only the symbols you want to export.
2) Luego intento compilar la fase, pero me devuelve el error de que no existe el símbolo de _main y el resto de símbolos de las funciones del motor.
Código: Seleccionar todo
zcc +zx juego_pagina0_compressed.c -o juego_pagina0_.bin -vn -O3
Para compilar contra esos símbolos, agregue el archivo .def a la compilación como un archivo asm (debe cambiar el nombre del archivo con la extensión .asm):
zcc +zx juego_pagina0_compressed.c juego.def.asm -o juego_pagina0_.bin -vn -O3
Sin embargo, como he dicho esto no es la mejor manera de hacer esto. Use SECTIONs en su lugar (próxima entrada si tengo tiempo esta noche).