Hi Fabio,
There are a few problems with your program:
1) You don't need to call sprite() and colspr() again and again. You only have one pattern (one shape), so you can define that pattern once and use it in every putspr() call.
2) You can only have up to 32 sprites at the same time on the screen.
3) In SCREEN 4, the MSX can only display up to 8 sprites in the same horizontal line. Sprites in lower planes (higher number) won't be displayed.
I've modified your code a bit. I didn't include the first loop in your program because it doesn't show in the screenshot. Notice that now there's only one sprite pattern (shape) and that all the putspr() calls use the same pattern.
#include <stdio.h> #include <glib.h> char spr0Pat[8]={ 0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF }; char spr0Col[8]={ 0x05,0x05,0x05,0x05,0x05,0x05,0x05,0x05 }; int main() { int x,y; ginit(); /*Inizializza graphic subsystem*/ color((TINY)1,(TINY)1,(TINY)1); screen((TINY)4); inispr((TINY)0; sprite((TINY)0, spr0Pat); colspr((TINY)0, spr0Col); for(y=11; y<20; y++) { putspr((TINY)y, 146, 8*(y-11), (TINY)6, (TINY)0); } for(x=22; x<31; x++) { putspr((TINY)x, 150, 8*(y-11), (TINY)6, (TINY)0); } for(x=31; x<40; x++) { /* This loop will only put one sprite on the screen (#31) because there are only 32 sprites. Sprites 32 to 39 will not appear */ putspr((TINY)x, 8*(x-22), 80, (TINY)6, (TINY)0); } }
I compiled the code below, but when I run it, all I got is a black screen. Am I doing something wrong? I'm using openMSX emulating a Turbo R GT. I installed MSX-C following the instructions of Lavandeira's website and it seems to be working fine here. Do I need some updated library or something like that to compile this example?
Hi Fabio,
There are a few problems with your program:
1) You don't need to call sprite() and colspr() again and again. You only have one pattern (one shape), so you can define that pattern once and use it in every putspr() call.
2) You can only have up to 32 sprites at the same time on the screen.
3) In SCREEN 4, the MSX can only display up to 8 sprites in the same horizontal line. Sprites in lower planes (higher number) won't be displayed.
I've modified your code a bit. I didn't include the first loop in your program because it doesn't show in the screenshot. Notice that now there's only one sprite pattern (shape) and that all the putspr() calls use the same pattern.
#include <stdio.h> #include <glib.h> char spr0Pat[8]={ 0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF }; char spr0Col[8]={ 0x05,0x05,0x05,0x05,0x05,0x05,0x05,0x05 }; int main() { int x,y; ginit(); /*Inizializza graphic subsystem*/ color((TINY)1,(TINY)1,(TINY)1); screen((TINY)4); inispr((TINY)0; sprite((TINY)0, spr0Pat); colspr((TINY)0, spr0Col); for(y=11; y<20; y++) { putspr((TINY)y, 146, 8*(y-11), (TINY)6, (TINY)0); } for(x=22; x<31; x++) { putspr((TINY)x, 150, 8*(y-11), (TINY)6, (TINY)0); } for(x=31; x<40; x++) { /* This loop will only put one sprite on the screen (#31) because there are only 32 sprites. Sprites 32 to 39 will not appear */ putspr((TINY)x, 8*(x-22), 80, (TINY)6, (TINY)0); } }
I compiled the code below, but when I run it, all I got is a black screen. Am I doing something wrong?
The following line from the code should give you a hint of what's happening:
color((TINY)1,(TINY)1,(TINY)1);
In other words:
The program doesn't have a wait at the end, so it puts the sprites on the screen (very fast to see) and immediately exits back to MSX-DOS. However, the color() line set both the foreground and background color to black. That's why you can't see a thing. Just type BASIC and Enter to go to the BASIC interpreter and you should see the right colors (then enter CALL SYSTEM to return to MSX-DOS).
Then modify the color() call to something more reasonable, such as:
color((TINY)15,(TINY)1,(TINY)1);
And add the following at the end of the main() function so it waits for a key press before exiting:
getch(); screen((TINY)0);
This is what you should see if you enter the program correctly:
Thanks!
I compiled the code below, but when I run it, all I got is a black screen. Am I doing something wrong?
The following line from the code should give you a hint of what's happening:
color((TINY)1,(TINY)1,(TINY)1);
In other words:
The program doesn't have a wait at the end, so it puts the sprites on the screen (very fast to see) and immediately exits back to MSX-DOS. However, the color() line set both the foreground and background color to black. That's why you can't see a thing. Just type BASIC and Enter to go to the BASIC interpreter and you should see the right colors (then enter CALL SYSTEM to return to MSX-DOS).
Then modify the color() call to something more reasonable, such as:
color((TINY)15,(TINY)1,(TINY)1);
And add the following at the end of the main() function so it waits for a key press before exiting:
getch(); screen((TINY)0);