Monochrome sprite functions
-
- Member
- Posts: 23
- Joined: Wed Jul 29, 2015 9:07 am
Monochrome sprite functions
Hi everyone,
I?m working on a monochrome game with pixel by pixel movement. I have used SP1 library in all the tests I have made so far. I have accidentally come across the header file games.h and I was wondering if these functions are more suitable than SP1. I?m primarily looking at efficiency in terms of speed and memory usage. Has anyone made any comparison between both libraries?
Cheers,
Javier
I?m working on a monochrome game with pixel by pixel movement. I have used SP1 library in all the tests I have made so far. I have accidentally come across the header file games.h and I was wondering if these functions are more suitable than SP1. I?m primarily looking at efficiency in terms of speed and memory usage. Has anyone made any comparison between both libraries?
Cheers,
Javier
The graphics and 3d library goes pretty much unnoticed but the results are quite good.
The mono sprites take much less memory than sp1 but they are also slower. They operate directly on the screen so you may also have to worry about flicker. I think it's probably more suitable for games that are not live-action.
You should try compiling some of the examples in z88dk/examples/graphics
* chessboard.c, "zcc +zx -vn chessboard.c -o chessboard -lndos -create-app"
Uses putsprite() to draw the chess pieces.
* clock.c, "zcc +zx -oclock -lndos -create-app -lm -llib3d -DDETAILED clock.c"
Uses putsprite() to draw the roman numerals. The clock's hands keep time.
* spritest.c, "zcc +zx -vn spritest.c -o spritest -lndos -create-app"
The mono sprite functions are used to move a pointer around. CAPS+5+6+7+8 to move.
If the program exits right away it's because you're still holding enter when the program starts.
I've committed a fix for that now.
It's not a pretty example but it shows the speed if the sprite is drawn masked with background restore
and moved 1 pixel at a time. Moving faster than 1 pixel would improve things as would using OR sprites.
Masked sprites means two draws of the sprite image (mask then graphics).
* stencil.c, "zcc +zx -vn -lndos -create-app -llib3d stencil.c -o stencil"
Shows how nice the stencil graphics library is. It draws rotated filled shapes on screen very quickly.
Not related to sprites but the rest of the graphics lib deserves some attention too
Stefano can commit further. The graphics lib will be very light on memory requirements; sp1 is heavy so that it can be fast and easy to use at the same time (no flicker and no tv sync). The graphics lib is one thing I would like to personally look at as I'd like to add clipping, optional transformations and draw context (for colour) in a graphics pipeline structure.
The mono sprites take much less memory than sp1 but they are also slower. They operate directly on the screen so you may also have to worry about flicker. I think it's probably more suitable for games that are not live-action.
You should try compiling some of the examples in z88dk/examples/graphics
* chessboard.c, "zcc +zx -vn chessboard.c -o chessboard -lndos -create-app"
Uses putsprite() to draw the chess pieces.
* clock.c, "zcc +zx -oclock -lndos -create-app -lm -llib3d -DDETAILED clock.c"
Uses putsprite() to draw the roman numerals. The clock's hands keep time.
* spritest.c, "zcc +zx -vn spritest.c -o spritest -lndos -create-app"
The mono sprite functions are used to move a pointer around. CAPS+5+6+7+8 to move.
If the program exits right away it's because you're still holding enter when the program starts.
I've committed a fix for that now.
It's not a pretty example but it shows the speed if the sprite is drawn masked with background restore
and moved 1 pixel at a time. Moving faster than 1 pixel would improve things as would using OR sprites.
Masked sprites means two draws of the sprite image (mask then graphics).
* stencil.c, "zcc +zx -vn -lndos -create-app -llib3d stencil.c -o stencil"
Shows how nice the stencil graphics library is. It draws rotated filled shapes on screen very quickly.
Not related to sprites but the rest of the graphics lib deserves some attention too
Stefano can commit further. The graphics lib will be very light on memory requirements; sp1 is heavy so that it can be fast and easy to use at the same time (no flicker and no tv sync). The graphics lib is one thing I would like to personally look at as I'd like to add clipping, optional transformations and draw context (for colour) in a graphics pipeline structure.
The monochrome lib inherits by a root codebase for the z88 but it grew up a lot since then.. my intention was to have a good number of portable functions so now you can compile the same program for different targets with little or no changes, so the color support is almost absent.
My intention was to have all the targets covered soon, so the code in some case slower than necessary (Alvin is right telling it is not suitable for interactive games.. see the "microman.c" demo to see the most you can get). On the other side this minimalistic approach permits to extend the codebase easily and to add a new function on all the targets with very little effort. The element I like most is the "stencil" element, coming from a 3D buffered engine for the MSX by Rafael de Oliveira Jannone which I rewrote in machine code. It permit to use the same graphics set to create convex figures which can be applied over the current screen choosing its "shade" (dithering pattern). I used this element to render some simple SVG file, which can be previously converted to meta-graphics sequences with the z80svg tool.
The lo-rez graphics is in turn specific to the Sinclair machines and a bit cumbersome, but there should be a limited version for the ZX81 too.
My intention was to have all the targets covered soon, so the code in some case slower than necessary (Alvin is right telling it is not suitable for interactive games.. see the "microman.c" demo to see the most you can get). On the other side this minimalistic approach permits to extend the codebase easily and to add a new function on all the targets with very little effort. The element I like most is the "stencil" element, coming from a 3D buffered engine for the MSX by Rafael de Oliveira Jannone which I rewrote in machine code. It permit to use the same graphics set to create convex figures which can be applied over the current screen choosing its "shade" (dithering pattern). I used this element to render some simple SVG file, which can be previously converted to meta-graphics sequences with the z80svg tool.
The lo-rez graphics is in turn specific to the Sinclair machines and a bit cumbersome, but there should be a limited version for the ZX81 too.
http://z88dk.org/wiki/doku.php?id=targets
.. the targets supporting at least some of the B/W graphics functions are more than 30.
I'd say all of them is able to run "dstar", "chessboard" and "coswave".
.. the targets supporting at least some of the B/W graphics functions are more than 30.
I'd say all of them is able to run "dstar", "chessboard" and "coswave".
-
- Member
- Posts: 23
- Joined: Wed Jul 29, 2015 9:07 am
I ahve tried compiling chessboard.c and this is the result:alvin wrote:* chessboard.c, "zcc +zx -vn chessboard.c -o chessboard -lndos -create-app"
Uses putsprite() to draw the chess pieces.
C:\z88dk\trabajos\12. test graphics>zcc +zx -vn chessboard.c -o chessboard -lndos -create-app
1 file(s) copied.
1 file(s) copied.
Warning at module 'chessboard': symbol 'coords' used as 'COORDS'
Warning at module 'chessboard': symbol 'coords' used as 'COORDS'
Warning at file 'C:\Users\Colino\AppData\Local\Temp\s608_1.asm' module 'zx82_crt0': symbol '_Main' used as '_main'
Warning at module 'plotpixel': symbol 'coords' used as 'COORDS'
Error at module 'draw': symbol not defined in expression 'line'
Warning at module 'respixel': symbol 'coords' used as 'COORDS'
Error at module 'undraw': symbol not defined in expression 'line'
2 errors occurred during assembly
Seems like I need an external library?
-
- Member
- Posts: 23
- Joined: Wed Jul 29, 2015 9:07 am
OK, I have downloaded and installed the latest version -http://nightly.z88dk.org/z88dk-win32-latest.zip- and this what I get now when trying to compile:alvin wrote:It looks like you have an old install. Try to update your nightly build.
Code: Select all
C:\z88dk\trabajos\12. test graphics>zcc +zx -vn chessboard.c -o chessboard -lndos -create-app
1 file(s) copied.
1 file(s) copied.
Error at file 'c:\Z88DK\lib\/spec_crt0.asm' line 177: symbol '_main' not defined
1 errors occurred during assembly
Key to filenames:
C:\Users\Colino\AppData\Local\Temp\sj0_.o = chessboard.c
Error at file 'c:\Z88DK\lib\/spec_crt0.asm' line 177: symbol '_main' not defined
^ ---- call _main ; Call user program
I just downloaded the nightly from scratch and compiled without a problem.
The warnings a few posts ago about mixed case names is due to an old version of z80asm. The current error you have with no "_main" means there is no main() function in chessboard.c, which there most certainly is. Could you check your chessboard.c to make sure it has a main()? In case it's something to do with spaces in the path, maybe try compiling again after copying "chessboard.c" and "chessboard.h" up one directory to "C:\z88dk\trabajos\" so that the spaces won't be there.
In case you continue to have problems (which should be solved) here is chessboard compiled with the default pieces:
https://drive.google.com/file/d/0B6XhJJ ... sp=sharing
Microman is probably what you should look at for what mono sprites can do (it's in the examples dir):
https://drive.google.com/file/d/0B6XhJJ ... sp=sharing
The warnings a few posts ago about mixed case names is due to an old version of z80asm. The current error you have with no "_main" means there is no main() function in chessboard.c, which there most certainly is. Could you check your chessboard.c to make sure it has a main()? In case it's something to do with spaces in the path, maybe try compiling again after copying "chessboard.c" and "chessboard.h" up one directory to "C:\z88dk\trabajos\" so that the spaces won't be there.
In case you continue to have problems (which should be solved) here is chessboard compiled with the default pieces:
https://drive.google.com/file/d/0B6XhJJ ... sp=sharing
Microman is probably what you should look at for what mono sprites can do (it's in the examples dir):
https://drive.google.com/file/d/0B6XhJJ ... sp=sharing
-
- Member
- Posts: 23
- Joined: Wed Jul 29, 2015 9:07 am
I found the issue: the main function was written with capital "m" (Main instead of main), thanks for the hint!alvin wrote:The current error you have with no "_main" means there is no main() function in chessboard.c, which there most certainly is. Could you check your chessboard.c to make sure it has a main()?
Now if I want to compile a program (main.c) with the SP1 features using the latest build, I use the following:
Code: Select all
zcc +zx -vn main.c -o main -lndos -lsp1 -lmalloc -create-app
Code: Select all
cpp: line 5, Fatal error: Cannot open include file "sprites/sp1.h"
Code: Select all
C:\z88dk\include\sprites
You must be using an old version of that program. It should look like this in the nightly download:Javi Perez wrote:I found the issue: the main function was written with capital "m" (Main instead of main), thanks for the hint!alvin wrote:The current error you have with no "_main" means there is no main() function in chessboard.c, which there most certainly is. Could you check your chessboard.c to make sure it has a main()?
http://z88dk.cvs.sourceforge.net/viewvc ... xt%2Fplain
Yes for the classic c library, sp1.lib and sp1.h are not made for you. This is because sp1 works for a few more targets (zx81 and ts2068) but only one version can exist at a time so the user is supposed to make the version of sp1 needed. This can be done via the Makefile in z88dk/libsrc (type "make sp1" from there for instructions) but make does not come standard with windows.Now if I want to compile a program (main.c) with the SP1 features using the latest build, I use the following:But it seems the SP1.h file is not found...Code: Select all
zcc +zx -vn main.c -o main -lndos -lsp1 -lmalloc -create-app
In the previous build, sp1.h was located atCode: Select all
cpp: line 5, Fatal error: Cannot open include file "sprites/sp1.h"
Code: Select all
C:\z88dk\include\sprites
You can use this default compiled version for the spectrum to avoid having to make it:
https://drive.google.com/file/d/0B6XhJJ ... sp=sharing
Copy sp1.lib to z88dk/lib/clibs and the header file to z88dk/include/sprites (make the sprites subdir if you have to)
-
- Member
- Posts: 23
- Joined: Wed Jul 29, 2015 9:07 am
Thanks Alvin, now the program compiles successfully using:alvin wrote:You can use this default compiled version for the spectrum to avoid having to make it:
https://drive.google.com/file/d/0B6XhJJ ... sp=sharing
Copy sp1.lib to z88dk/lib/clibs and the header file to z88dk/include/sprites (make the sprites subdir if you have to)
Code: Select all
zcc +zx -vn main.c -o main -lndos -lsp1 -lmalloc -create-app
-
- Member
- Posts: 23
- Joined: Wed Jul 29, 2015 9:07 am
I launched the command in the console and the string "sccz80.exe has stopped working" pops out in a window with the "OK" button.alvin wrote:Is there an error message printed out? zcc will sometimes hang if a function or variable is not found .Javi Perez wrote:However, for some reason an error pops up reporting that "sccz80.exe has stopped working" and the .tap is not generated.