Hey everyone! I'm a student who has recently become interested in coding some programs for my FX-CG50 calculator. I'd like to think I'm pretty good at coding but I have no idea how to code for this thing as my only experience with C++ was using the SFML library. So far I've managed to draw text to the screen using the Intro to Prizm C Programming on the wiki but it seems the drawing sprites section either wasn't finished or the link is broken
Could any of you explain how I should go about drawing sprites to the screen? Do I need to download any extra libraries (I'm currently using libfxcg)? By the way, I'm not looking to have any user input, just trying to make a nice looking effect for now whose code I've already written in lua.
Thanks a lot,
emibudd
There aren't any particularly helpful libraries for display, because it's so simple; just write data to VRAM. Just remember to set the display to 16-bit color unless you want the reduced palette.

WikiPrizm has some good sample functions for displaying things. And remember to call Bdisp_EnableColor(1) to enable 16-bit color. You might also refer to the libfxcg examples.
Tari wrote:
There aren't any particularly helpful libraries for display, because it's so simple; just write data to VRAM. Just remember to set the display to 16-bit color unless you want the reduced palette.

WikiPrizm has some good sample functions for displaying things. And remember to call Bdisp_EnableColor(1) to enable 16-bit color. You might also refer to the libfxcg examples.

Thanks a lot for the help! I've been trying this out and fixing the errors that popped up, but there's a couple I can't seem to figure out. Keep in mind I usually work with high level languages so these are probably really dumb and basic errors caused by me not fully understanding the code.

Code:
#include <fxcg/display.h>
#include <fxcg/keyboard.h>

void CopySprite(const color_t* palette, int x, int y, int width, int height) {
   const color_t* VRAM = GetVRAMAdress();
   VRAM += LCD_WIDTH_PX * y + x;
   for (int j = y; j < y + height; j++) {
      for (int i = x; i < x + height; i++) {
         *(VRAM++) = *(palette++);
      }
      VRAM += LCD_WIDTH_PX - 16;
   }
}

int main() {
   //PrintXY(3, 8, "--Hello World!", TEXT_MODE_NORMAL, TEXT_COLOR_RED);

   const color_t sprite_palette[6] = { 0x0000, 0xff64, 0x194a, 0x042a, 0x0726, 0xfbb5 };

   const unsigned char frog1[256] = {
      0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
      0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
      0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
      0,0,0,1,1,0,0,0,0,1,1,0,0,0,0,0,
      0,0,1,1,1,1,0,0,1,1,1,1,0,0,0,0,
      0,0,1,2,2,1,0,0,1,2,2,1,0,0,0,0,
      0,0,3,1,1,1,3,3,1,1,1,3,0,0,0,0,
      0,4,4,4,4,4,4,4,4,4,4,4,4,0,0,0,
      4,4,4,4,4,4,4,4,4,4,4,4,4,4,0,0,
      4,5,5,4,4,4,4,4,4,4,4,5,5,4,0,0,
      4,5,5,2,4,4,2,2,4,4,2,5,5,4,0,0,
      3,4,4,4,2,2,4,4,2,2,4,4,4,3,0,0,
      3,4,4,4,4,4,4,4,4,4,4,4,4,3,0,0,
      0,3,4,4,4,4,4,4,4,4,4,4,3,0,0,0,
      0,0,3,4,4,4,4,4,4,4,4,3,0,0,0,0,
      0,0,0,3,3,3,3,3,3,3,3,0,0,0,0,0
   };

   CopySprite(sprite_palette, 16, 16, 16, 16);

   int key;
   while (1) GetKey(&key);

   return 0;
}


The error I get is:

Code:
C:/Users/emili/Documents/PrizmSDK-0.3/projects/frogsine/src/main.cpp: In function 'void CopySprite(const color_t*, int, int, int, int)':
C:/Users/emili/Documents/PrizmSDK-0.3/projects/frogsine/src/main.cpp:5:38: error: 'GetVRAMAdress' was not declared in this scope
C:/Users/emili/Documents/PrizmSDK-0.3/projects/frogsine/src/main.cpp:9:27: error: assignment of read-only location '*(VRAM ++)'
C:/Users/emili/Documents/PrizmSDK-0.3/projects/frogsine/src/main.cpp: In function 'int main()':
C:/Users/emili/Documents/PrizmSDK-0.3/projects/frogsine/src/main.cpp:20:22: warning: unused variable 'frog1' [-Wunused-variable]
make[1]: *** [main.o] Error 1
make: *** [build] Error 2


On top of the errors, I don't see how this would draw the image frog1, though I'm guessing that's because I'm doing something wrong on my end. My thought process was, the sample function on the wiki took in a color_t type variable, and the palette for my sprite was a color_t type variable, so I should pass that in. What am I doing wrong?
Add this function ( I found it somewhere, it should be on 1 line):
color_t* GetVRAMAddress() { __asm__("mov.l syscall_adress, r2\n" "mov.l getVRAM, r0\n" "jmp @r2\n" "nop\n" "syscall_adress: .long 0x80020070\n" "getVRAM: .long 0x01E6"); }
And remove const from the line:
const color_t* VRAM = GetVRAMAdress();
MPoupe wrote:
Add this function ( I found it somewhere, it should be on 1 line):
color_t* GetVRAMAddress() { __asm__("mov.l syscall_adress, r2\n" "mov.l getVRAM, r0\n" "jmp @r2\n" "nop\n" "syscall_adress: .long 0x80020070\n" "getVRAM: .long 0x01E6"); }
And remove const from the line:
const color_t* VRAM = GetVRAMAdress();

Removing const and not adding that line fixes one of the errors, so I get this:

Code:
C:/Users/emili/Documents/PrizmSDK-0.3/projects/frogsine/src/main.cpp: In function 'void CopySprite(const color_t*, int, int, int, int)':
C:/Users/emili/Documents/PrizmSDK-0.3/projects/frogsine/src/main.cpp:7:32: error: 'GetVRAMAdress' was not declared in this scope
C:/Users/emili/Documents/PrizmSDK-0.3/projects/frogsine/src/main.cpp: In function 'int main()':
C:/Users/emili/Documents/PrizmSDK-0.3/projects/frogsine/src/main.cpp:22:22: warning: unused variable 'frog1' [-Wunused-variable]


However, adding that lines causes a bunch more to pop up:

Code:
C:/Users/emili/Documents/PrizmSDK-0.3/projects/frogsine/src/main.cpp: In function 'color_t* GetVRAMAddress()':
C:/Users/emili/Documents/PrizmSDK-0.3/projects/frogsine/src/main.cpp:4:25: error: new declaration 'color_t* GetVRAMAddress()'
C:/Users/emili/Documents/PrizmSDK-0.3/include/fxcg/display.h:28:7: error: ambiguates old declaration 'void* GetVRAMAddress()'
C:/Users/emili/Documents/PrizmSDK-0.3/projects/frogsine/src/main.cpp:4:171: warning: no return statement in function returning non-void [-Wreturn-type]
C:/Users/emili/Documents/PrizmSDK-0.3/projects/frogsine/src/main.cpp: In function 'void CopySprite(const color_t*, int, int, int, int)':
C:/Users/emili/Documents/PrizmSDK-0.3/projects/frogsine/src/main.cpp:7:32: error: 'GetVRAMAdress' was not declared in this scope
C:/Users/emili/Documents/PrizmSDK-0.3/projects/frogsine/src/main.cpp: In function 'int main()':
C:/Users/emili/Documents/PrizmSDK-0.3/projects/frogsine/src/main.cpp:22:22: warning: unused variable 'frog1' [-Wunused-variable]


By the way, this is what my code looks like now:

Code:
#include <fxcg/display.h>
#include <fxcg/keyboard.h>

color_t* GetVRAMAddress() { __asm__("mov.l syscall_adress, r2\n" "mov.l getVRAM, r0\n" "jmp @r2\n" "nop\n" "syscall_adress: .long 0x80020070\n" "getVRAM: .long 0x01E6"); }

void CopySprite(const color_t* palette, int x, int y, int width, int height) {
   color_t* VRAM = GetVRAMAdress();
   VRAM += LCD_WIDTH_PX * y + x;
   for (int j = y; j < y + height; j++) {
      for (int i = x; i < x + height; i++) {
         *(VRAM++) = *(palette++);
      }
      VRAM += LCD_WIDTH_PX - 16;
   }
}

int main() {
   const color_t sprite_palette[6] = { 0x0000, 0xff64, 0x194a, 0x042a, 0x0726, 0xfbb5 };

   const unsigned char frog1[256] = {
      0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
      0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
      0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
      0,0,0,1,1,0,0,0,0,1,1,0,0,0,0,0,
      0,0,1,1,1,1,0,0,1,1,1,1,0,0,0,0,
      0,0,1,2,2,1,0,0,1,2,2,1,0,0,0,0,
      0,0,3,1,1,1,3,3,1,1,1,3,0,0,0,0,
      0,4,4,4,4,4,4,4,4,4,4,4,4,0,0,0,
      4,4,4,4,4,4,4,4,4,4,4,4,4,4,0,0,
      4,5,5,4,4,4,4,4,4,4,4,5,5,4,0,0,
      4,5,5,2,4,4,2,2,4,4,2,5,5,4,0,0,
      3,4,4,4,2,2,4,4,2,2,4,4,4,3,0,0,
      3,4,4,4,4,4,4,4,4,4,4,4,4,3,0,0,
      0,3,4,4,4,4,4,4,4,4,4,4,3,0,0,0,
      0,0,3,4,4,4,4,4,4,4,4,3,0,0,0,0,
      0,0,0,3,3,3,3,3,3,3,3,0,0,0,0,0
   };

   CopySprite(sprite_palette, 16, 16, 16, 16);

   int key;
   while (1) GetKey(&key);

   return 0;
}
Update on that last thing, I figured out after a long time that... it didn't work because I spelt address wrong. Anyways, I ran into another error I can't figure out, which is:

Code:
C:/Users/emili/Documents/PrizmSDK-0.3/projects/frogsine/src/main.cpp: In function 'void CopySprite(const color_t*, int, int, int, int)':
C:/Users/emili/Documents/PrizmSDK-0.3/projects/frogsine/src/main.cpp:5:33: error: invalid conversion from 'void*' to 'color_t*' [-fpermissive]
C:/Users/emili/Documents/PrizmSDK-0.3/projects/frogsine/src/main.cpp: In function 'int main()':
C:/Users/emili/Documents/PrizmSDK-0.3/projects/frogsine/src/main.cpp:18:22: warning: unused variable 'frog1' [-Wunused-variable]


My code is:

Code:
#include <fxcg/display.h>
#include <fxcg/keyboard.h>

void CopySprite(const color_t* palette, int x, int y, int width, int height) {
   color_t* VRAM = GetVRAMAddress();
   VRAM += LCD_WIDTH_PX * y + x;
   for (int j = y; j < y + height; j++) {
      for (int i = x; i < x + height; i++) {
         *(VRAM++) = *(palette++);
      }
      VRAM += LCD_WIDTH_PX - 16;
   }
}

int main() {
     const color_t sprite[512] = {
      0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
      0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
      0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
      0x0000,0x0000,0x0000,0xff64,0xff64,0x0000,0x0000,0x0000,0x0000,0xff64,0xff64,0x0000,0x0000,0x0000,0x0000,0x0000,
      0x0000,0x0000,0xff64,0xff64,0xff64,0xff64,0x0000,0x0000,0xff64,0xff64,0xff64,0xff64,0x0000,0x0000,0x0000,0x0000,
      0x0000,0x0000,0xff64,0x194a,0x194a,0xff64,0x0000,0x0000,0xff64,0x194a,0x194a,0xff64,0x0000,0x0000,0x0000,0x0000,
      0x0000,0x0000,0x042a,0xff64,0xff64,0xff64,0x042a,0x042a,0xff64,0xff64,0xff64,0x042a,0x0000,0x0000,0x0000,0x0000,
      0x0000,0x0726,0x0726,0x0726,0x0726,0x0726,0x0726,0x0726,0x0726,0x0726,0x0726,0x0726,0x0726,0x0000,0x0000,0x0000,
      0x0726,0x0726,0x0726,0x0726,0x0726,0x0726,0x0726,0x0726,0x0726,0x0726,0x0726,0x0726,0x0726,0x0726,0x0000,0x0000,
      0x0726,0xfbb5,0xfbb5,0x0726,0x0726,0x0726,0x0726,0x0726,0x0726,0x0726,0x0726,0xfbb5,0xfbb5,0x0726,0x0000,0x0000,
      0x0726,0xfbb5,0xfbb5,0x194a,0x0726,0x0726,0x194a,0x194a,0x0726,0x0726,0x194a,0xfbb5,0xfbb5,0x0726,0x0000,0x0000,
      0x042a,0x0726,0x0726,0x0726,0x194a,0x194a,0x0726,0x0726,0x194a,0x194a,0x0726,0x0726,0x0726,0x042a,0x0000,0x0000,
      0x042a,0x0726,0x0726,0x0726,0x0726,0x0726,0x0726,0x0726,0x0726,0x0726,0x0726,0x0726,0x0726,0x042a,0x0000,0x0000,
      0x0000,0x042a,0x0726,0x0726,0x0726,0x0726,0x0726,0x0726,0x0726,0x0726,0x0726,0x0726,0x042a,0x0000,0x0000,0x0000,
      0x0000,0x0000,0x042a,0x0726,0x0726,0x0726,0x0726,0x0726,0x0726,0x0726,0x0726,0x042a,0x0000,0x0000,0x0000,0x0000,
      0x0000,0x0000,0x0000,0x042a,0x042a,0x042a,0x042a,0x042a,0x042a,0x042a,0x042a,0x0000,0x0000,0x0000,0x0000,0x0000
   };

   CopySprite(sprite_palette, 16, 16, 16, 16);

   int key;
   while (1) GetKey(&key);

   return 0;
}


I don't get why, when I'm declaring VRAM, which I think is a new variable, it treats it like I'm converting it from a void.
emibudd wrote:
Update on that last thing, I figured out after a long time that... it didn't work because I spelt address wrong.
Yes, I noticed that quickly after checking the function should exist and you were including the right header. You don't need to include the implementation MPoupe provided.

Quote:
Anyways, I ran into another error I can't figure out, which is:

Code:
C:/Users/emili/Documents/PrizmSDK-0.3/projects/frogsine/src/main.cpp: In function 'void CopySprite(const color_t*, int, int, int, int)':
C:/Users/emili/Documents/PrizmSDK-0.3/projects/frogsine/src/main.cpp:5:33: error: invalid conversion from 'void*' to 'color_t*' [-fpermissive]
C:/Users/emili/Documents/PrizmSDK-0.3/projects/frogsine/src/main.cpp: In function 'int main()':
C:/Users/emili/Documents/PrizmSDK-0.3/projects/frogsine/src/main.cpp:18:22: warning: unused variable 'frog1' [-Wunused-variable]


You need to cast the return value of GetVRAMAddress because it returns void* since VRAM is just a blob of bytes as far as it cares.

Code:
color_t *VRAM = (color_t*)GetVRAMAddress();
Tari wrote:
emibudd wrote:
Update on that last thing, I figured out after a long time that... it didn't work because I spelt address wrong.
Yes, I noticed that quickly after checking the function should exist and you were including the right header. You don't need to include the implementation MPoupe provided.

Quote:
Anyways, I ran into another error I can't figure out, which is:

Code:
C:/Users/emili/Documents/PrizmSDK-0.3/projects/frogsine/src/main.cpp: In function 'void CopySprite(const color_t*, int, int, int, int)':
C:/Users/emili/Documents/PrizmSDK-0.3/projects/frogsine/src/main.cpp:5:33: error: invalid conversion from 'void*' to 'color_t*' [-fpermissive]
C:/Users/emili/Documents/PrizmSDK-0.3/projects/frogsine/src/main.cpp: In function 'int main()':
C:/Users/emili/Documents/PrizmSDK-0.3/projects/frogsine/src/main.cpp:18:22: warning: unused variable 'frog1' [-Wunused-variable]


You need to cast the return value of GetVRAMAddress because it returns void* since VRAM is just a blob of bytes as far as it cares.

Code:
color_t *VRAM = (color_t*)GetVRAMAddress();


Oh yeah, I tried that before since it said to do that in the WikiPrizm entry but it gives me this error

Code:
main.o: In function `CopySprite(unsigned short const*, int, int, int, int)':
main.cpp:(.text+0x98): undefined reference to `_GetVRAMAddress'


Any idea what the problem could be?
This is now a linker error, so you're not linking libfxcg correctly it seems.
Tari wrote:
This is now a linker error, so you're not linking libfxcg correctly it seems.

That's weird, PrintXY worked perfectly and it's also defined in display.h. Sorry to keep bothering you but, I've only ever used SFML as I've said and I can't find any of the menus I used to link those files. You know any easy stuff I should look out for or tutorials on linking properly? Seriously, thank you so much for all of this.
The stuff I'm asking about has changed a lot so I'm making a new topic!
https://www.cemetech.net/forum/viewtopic.php?p=285075#285075
  
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 1 of 1
» 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