Tari: I am sorry if I cannot read error messages, but I tried very hard on this one and all the stuff about "C99 Mode" is really confusing me :-/


Code:

make
/usr/local/cross/bin/sh3eb-elf-gcc -MMD -MP -MF /home/flyingfisch/Desktop/PrizmSDK-0.3/projects/nyan/build/example.d -Os -Wall -mb -m4a-nofpu -mhitachi -nostdlib   -I/home/flyingfisch/Desktop/PrizmSDK-0.3/projects/nyan/build -I/home/flyingfisch/Desktop/PrizmSDK-0.3/include -c /home/flyingfisch/Desktop/PrizmSDK-0.3/projects/nyan/src/example.c -o example.o
/home/flyingfisch/Desktop/PrizmSDK-0.3/projects/nyan/src/example.c: In function 'main':
/home/flyingfisch/Desktop/PrizmSDK-0.3/projects/nyan/src/example.c:18:2: warning: implicit declaration of function 'AlphaSprite' [-Wimplicit-function-declaration]
/home/flyingfisch/Desktop/PrizmSDK-0.3/projects/nyan/src/example.c:29:2: warning: 'return' with no value, in function returning non-void [-Wreturn-type]
/home/flyingfisch/Desktop/PrizmSDK-0.3/projects/nyan/src/example.c:16:6: warning: unused variable 'color' [-Wunused-variable]
/home/flyingfisch/Desktop/PrizmSDK-0.3/projects/nyan/src/example.c: In function 'CopySprite':
/home/flyingfisch/Desktop/PrizmSDK-0.3/projects/nyan/src/example.c:37:4: error: 'for' loop initial declarations are only allowed in C99 mode
/home/flyingfisch/Desktop/PrizmSDK-0.3/projects/nyan/src/example.c:37:4: note: use option -std=c99 or -std=gnu99 to compile your code
/home/flyingfisch/Desktop/PrizmSDK-0.3/projects/nyan/src/example.c:38:7: error: 'for' loop initial declarations are only allowed in C99 mode
/home/flyingfisch/Desktop/PrizmSDK-0.3/projects/nyan/src/example.c: At top level:
/home/flyingfisch/Desktop/PrizmSDK-0.3/projects/nyan/src/example.c:45:6: warning: conflicting types for 'AlphaSprite' [enabled by default]
/home/flyingfisch/Desktop/PrizmSDK-0.3/projects/nyan/src/example.c:18:2: note: previous implicit declaration of 'AlphaSprite' was here
/home/flyingfisch/Desktop/PrizmSDK-0.3/projects/nyan/src/example.c: In function 'AlphaSprite':
/home/flyingfisch/Desktop/PrizmSDK-0.3/projects/nyan/src/example.c:49:5: error: 'for' loop initial declarations are only allowed in C99 mode
/home/flyingfisch/Desktop/PrizmSDK-0.3/projects/nyan/src/example.c:50:8: error: 'for' loop initial declarations are only allowed in C99 mode
make[1]: *** [example.o] Error 1
make: *** [build] Error 2


And my code:


Code:

#include <display_syscalls.h>
#include <keyboard_syscalls.h>
#include <display_syscalls.h>
#include <display.h>

#include <color.h>

#include "data.h"


#define MAGIC_PINK 0xf81f

int LCD_WIDTH_PX = 384;
int LCD_HEIGHT_PX = 216;

int main(void) {
   int key;
   int color = TEXT_COLOR_BLACK;
   
   AlphaSprite(nyan1, 1, 1, 129, 90, MAGIC_PINK);
   Bdisp_PutDisp_DD();
   
   
   while (1) {
      GetKey(&key);
      switch (key) {
         
      }
   }
 
   return;
}


void CopySprite(const void* datar, int x, int y, int width, int height) {
   color_t*data = (color_t*) datar;
   color_t* VRAM = (color_t*)0xA8000000;
   VRAM += LCD_WIDTH_PX*y + x;
   for(int j=y; j<y+height; j++) {
      for(int i=x; i<x+width; i++) {
         *(VRAM++) = *(data++);
     }
     VRAM += LCD_WIDTH_PX-width;
   }
}

void AlphaSprite(short* data, int x, int y, int width, int height, char alpha) {
    short* VRAM = (short*)0xA8000000;
    int CurColor = 0;
    VRAM += (LCD_WIDTH_PX*y)+x;
    for(int j=y; j<y+height; j++) {
       for(int i=x; i<x+width;  i++) {
         CurColor = (*(VRAM) + (alpha*(*(data++))/256))/2;
         *(VRAM++) = CurColor % (65536);
       }
       VRAM += (LCD_WIDTH_PX-width);
    }
 }
It would be very easy to make this into a .cpp file, adding extern "C"{ at the top and } at the bottom of your source. I had issues setting C99 (or any more for that matter) in gcc for the prizm.
GCC is compiling your code to the ANSI C90 standard, with which the C99 for loop is not compliant. Add this to the CFLAGS variable in your Makefile:


Code:
-std=c99


to fix that one problem. In addition, main returns an int, you're returning nothing as if it were a void. Return 0. You also have to prototype those functions on the bottom of your source.
AHelper wrote:
It would be very easy to make this into a .cpp file, adding extern "C"{ at the top and } at the bottom of your source. I had issues setting C99 (or any more for that matter) in gcc for the prizm.

But i don't understand... what is C99? And why am I having problems? And will making it in C++ make it so I cannot use C code?

EDIT:

Ashbad wrote:
GCC is compiling your code to the ANSI C90 standard, with which the C99 for loop is not compliant. Add this to the CFLAGS variable in your Makefile:


Code:
-std=c99


to fix that one problem. In addition, main returns an int, you're returning nothing as if it were a void. Return 0. You also have to prototype those functions on the bottom of your source.


Oh, prototype them, duh! *facepalm*

I still do not understand this thing about C99 though...
As I told you, your for loops are not C99 standard compliant, you're being compiled with the C90 specs. http://en.wikipedia.org/wiki/C99
Ah, ok. Why then, does PrizmSDK have C90 mode enabled by default?

EDIT:

Ok, I have changed a little of my code and my makefile but I still get an error:


Code:

 make
/usr/local/cross/bin/sh3eb-elf-gcc -MMD -MP -MF /home/flyingfisch/Desktop/PrizmSDK-0.3/projects/nyan/build/example.d -Os -Wall -mb -m4a-nofpu -mhitachi -nostdlib   -I/home/flyingfisch/Desktop/PrizmSDK-0.3/projects/nyan/build -I/home/flyingfisch/Desktop/PrizmSDK-0.3/include -std=c99 -c /home/flyingfisch/Desktop/PrizmSDK-0.3/projects/nyan/src/example.c -o example.o
/home/flyingfisch/Desktop/PrizmSDK-0.3/projects/nyan/src/example.c:13:5: error: expected identifier or '(' before numeric constant
/home/flyingfisch/Desktop/PrizmSDK-0.3/projects/nyan/src/example.c:14:5: error: expected identifier or '(' before numeric constant
/home/flyingfisch/Desktop/PrizmSDK-0.3/projects/nyan/src/example.c: In function 'main':
/home/flyingfisch/Desktop/PrizmSDK-0.3/projects/nyan/src/example.c:23:2: warning: passing argument 1 of 'AlphaSprite' from incompatible pointer type [enabled by default]
/home/flyingfisch/Desktop/PrizmSDK-0.3/projects/nyan/src/example.c:17:6: note: expected 'short int *' but argument is of type 'const char *'
/home/flyingfisch/Desktop/PrizmSDK-0.3/projects/nyan/src/example.c:23:2: warning: overflow in implicit constant conversion [-Woverflow]
make[1]: *** [example.o] Error 1
make: *** [build] Error 2



I don't understand why it doesn't like my variables. And is there something wrong with AlphaSprite?

It sounds to me like it is in one of my header files as well as my program... but I'm not sure.

here is my code:


Code:

#include <display_syscalls.h>
#include <keyboard_syscalls.h>
#include <display_syscalls.h>
#include <display.h>

#include <color.h>

#include "data.h"


#define MAGIC_PINK 0xf81f

int LCD_WIDTH_PX = 384;
int LCD_HEIGHT_PX = 216;

void CopySprite(const void* datar, int x, int y, int width, int height);
void AlphaSprite(short* data, int x, int y, int width, int height, char alpha);


int main(void) {
   int key;
   
   AlphaSprite(nyan1, 1, 1, 129, 90, MAGIC_PINK);
   Bdisp_PutDisp_DD();
   
   
   while (1) {
      GetKey(&key);
      switch (key) {
         
      }
   }
 
   return 0;
}


void CopySprite(const void* datar, int x, int y, int width, int height) {
   color_t*data = (color_t*) datar;
   color_t* VRAM = (color_t*)0xA8000000;
   VRAM += LCD_WIDTH_PX*y + x;
   for(int j=y; j<y+height; j++) {
      for(int i=x; i<x+width; i++) {
         *(VRAM++) = *(data++);
     }
     VRAM += LCD_WIDTH_PX-width;
   }
}

void AlphaSprite(short* data, int x, int y, int width, int height, char alpha) {
    short* VRAM = (short*)0xA8000000;
    int CurColor = 0;
    VRAM += (LCD_WIDTH_PX*y)+x;
    for(int j=y; j<y+height; j++) {
       for(int i=x; i<x+width;  i++) {
         CurColor = (*(VRAM) + (alpha*(*(data++))/256))/2;
         *(VRAM++) = CurColor % (65536);
       }
       VRAM += (LCD_WIDTH_PX-width);
    }
 }

LCD_WIDTH_PX and HEIGHT are already defined IIRC. Put in #undef LCD_HEIGHT_PX and such before making those variables if you want them changed.

Because the preprocessor makes that line into
Code:
int 384= 384;
I got rid of them, now what's wrong?


Code:

flyingfisch@flyingfisch-Office-Computer:~/Desktop/PrizmSDK-0.3/projects/nyan$ make
/usr/local/cross/bin/sh3eb-elf-gcc -MMD -MP -MF /home/flyingfisch/Desktop/PrizmSDK-0.3/projects/nyan/build/example.d -Os -Wall -mb -m4a-nofpu -mhitachi -nostdlib   -I/home/flyingfisch/Desktop/PrizmSDK-0.3/projects/nyan/build -I/home/flyingfisch/Desktop/PrizmSDK-0.3/include -std=c99 -c /home/flyingfisch/Desktop/PrizmSDK-0.3/projects/nyan/src/example.c -o example.o
/home/flyingfisch/Desktop/PrizmSDK-0.3/projects/nyan/src/example.c: In function 'main':
/home/flyingfisch/Desktop/PrizmSDK-0.3/projects/nyan/src/example.c:20:2: warning: passing argument 1 of 'AlphaSprite' from incompatible pointer type [enabled by default]
/home/flyingfisch/Desktop/PrizmSDK-0.3/projects/nyan/src/example.c:14:6: note: expected 'short int *' but argument is of type 'const char *'
/home/flyingfisch/Desktop/PrizmSDK-0.3/projects/nyan/src/example.c:20:2: warning: overflow in implicit constant conversion [-Woverflow]
/usr/local/cross/bin/sh3eb-elf-gcc  example.o -mb -m4a-nofpu -mhitachi -nostdlib -T/home/flyingfisch/Desktop/PrizmSDK-0.3/common/prizm.ld -Wl,-static -Wl,-gc-sections  -L/home/flyingfisch/Desktop/PrizmSDK-0.3/lib -lfxcg -lgcc -o /home/flyingfisch/Desktop/PrizmSDK-0.3/projects/nyan/nyan.bin
mkg3a -n basic:MyAddin -i uns:../unselected.bmp -i sel:../selected.bmp /home/flyingfisch/Desktop/PrizmSDK-0.3/projects/nyan/nyan.bin /home/flyingfisch/Desktop/PrizmSDK-0.3/projects/nyan/nyan.g3a
Well, you have some casting warnings, but you made a .g3a Smile Test it on a Prizm.
Well, it works, but all the colors are inverted Razz
Don't forget about the EnableColors (or w/e) function. Right now, you are in low color mode.
AHelper wrote:
Don't forget about the EnableColors (or w/e) function. Right now, you are in low color mode.


How do i use Bdisp_EnableColor?

I tried doing "Bdisp_EnableColor(1);", but I got an error:

Code:

/home/flyingfisch/Desktop/PrizmSDK-0.3/projects/nyan/src/example.c:16:19: error: expected declaration specifiers or '...' before numeric constant


EDIT:

here is my code:


Code:

#include <display_syscalls.h>
#include <keyboard_syscalls.h>
#include <display_syscalls.h>
#include <display.h>
#include <keyboard.hpp>
#include <color.h>

#include "data.h"


#define MAGIC_PINK 0xf81f

void CopySprite(const void* datar, int x, int y, int width, int height);
void AlphaSprite(short* data, int x, int y, int width, int height, char alpha);

Bdisp_EnableColor(1);

int main(void) {
   int key;

   SetBackGround(COLOR_DARKBLUE);
   AlphaSprite(nyan1, 1, 1, 129, 90, MAGIC_PINK);
   Bdisp_PutDisp_DD();
   
   
   while (1) {
      GetKey(&key);
      switch (key) {
      }
   }
   
   return 0;
}


void CopySprite(const void* datar, int x, int y, int width, int height) {
   color_t*data = (color_t*) datar;
   color_t* VRAM = (color_t*)0xA8000000;
   VRAM += LCD_WIDTH_PX*y + x;
   for(int j=y; j<y+height; j++) {
      for(int i=x; i<x+width; i++) {
         *(VRAM++) = *(data++);
     }
     VRAM += LCD_WIDTH_PX-width;
   }
}

void AlphaSprite(short* data, int x, int y, int width, int height, char alpha) {
    short* VRAM = (short*)0xA8000000;
    int CurColor = 0;
    VRAM += (LCD_WIDTH_PX*y)+x;
    for(int j=y; j<y+height; j++) {
       for(int i=x; i<x+width;  i++) {
         CurColor = (*(VRAM) + (alpha*(*(data++))/256))/2;
         *(VRAM++) = CurColor % (65536);
       }
       VRAM += (LCD_WIDTH_PX-width);
    }
 }

You didn't call it in the main function.
Ashbad wrote:
You didn't call it in the main function.


I feel so stupid...


But why does the sprite still have all the colors inverted?

When I use CopySprite, it doesn't do that...
Are colors inverted or just in 16-colors mode ?
Have you checked your encoded data ?
That AlphaSprite routine you're using, that I think I made probably over a year ago, is complete crap. This one I wrote much more recently works like a charm: http://www.cemetech.net/forum/viewtopic.php?t=6114&start=124
About this routine, I modified it for Gravity Duck, but I wonder why do you add 0x8010 and 0x0400 ? It works perfectly without. And in the second line, you must do >>5 too, not 6.

I made :
Code:
*base = ((((palette[*bitmap] & 0xF81F) * alpha + (*base & 0xF81F) * (32-alpha)) >> 5) & 0xF81F) |
        ((((palette[*bitmap] & 0x07E0) * alpha + (*base & 0x07E0) * (32-alpha)) >> 5) & 0x07E0);
I'm not sure why I did that addition, but IIRC the >> 6 was because the green channel is 6 bits, and I try to treat it like that instead of making only the top 5 bits of it have the only meaning when rendered. But, if your modification of the routine works, then I went slightly wrong somewhere Smile
i shearched in documentation and there are any way to set the background color without using sprites?

sorry im new with prizm, i have C/C++ skills i only need know more the calc

Code:
memset(VRAM, 0, 384*216*2);

Blanks the screen, needs further trickiness if you want anything other than black or white for the most part.
See also, WikiPrizm's page on the display.

This will probably be a bit (up to 4 times) faster than memset and can take a whole 16-bit color:

Code:
void bgfill(unsigned short color) {
    for (unsigned x = 0; x < 384*216/2; x++)
        VRAM[x] = color + (color << 16);
}
  
Register to Join the Conversation
Have your own thoughts to add to this or any other topic? Want to ask a question, offer a suggestion, share your own programs and projects, upload a file to the file archives, get help with calculator and computer programming, or simply chat with like-minded coders and tech and calculator enthusiasts via the site-wide AJAX SAX widget? Registration for a free Cemetech account only takes a minute.

» Go to Registration page
Page 5 of 5
» All times are UTC - 5 Hours
 
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum

 

Advertisement