Hey since my last topic got overun with others and my disuse I'd figure I would make a new one.
So I'm am attempted to display a picture on the screen but I keep getting reboot errors, so I thought I'd ask.
Here is my code:

Code:

#include "color.h"   
#include "display.h"
#include "display_syscalls.h"
#include "keyboard.hpp"   
#include "keyboard_syscalls.h"   
#include "Title.h"

void keymenu();
int PRGM_GetKey();
int keydown(int basic_keycode);
void CopySprite(char* data, int x, int y, int width, int height);
int true=1;

int main(void) {
while(true) {     
    if(PRGM_GetKey() == KEY_PRGM_MENU) {   
      keymenu();
    }
   void CopySprite(unsigned short title[11656], 0, 0, 94, 62)
   
   }
 return 0;   

:::::Function code:::::::

Pic data is from sourcecoder. Am I doing something wrong?
Okay I figured that last one out, go figure I was misusing my size boundaries. They were off. But now I have another question tho.
Say I wanted to make a Sprite Table and label an offset to chose what sprite to display, would I do it like this?:

Code:

Sprite 1 data
Sprite 2 data
Sprite 3 data
offset=1; //signifying sprite one
XORSprite( Main_Char_Sprite[offset*byte], int x, int y, int width, int height);
//byte is sprite data in bytes where all sprites are same byte count

I think that should work becuase I don't want to do this:

Code:

If sprite==1 XORSprite( sprite 1...
If sprite==2 XORSprite( sprite 2...
etc

If anyone can help that would be great.
Please remember not to double-post, Zeldaking, and be sure to proofread ("go figure:", "though", "because",...).

You have the right idea, but it would look like this. Declarations:

Code:
const color_t sprite1 = {...};
const color_t sprite2[] = {...};
const color_t sprite3[] = {...};
const color_t[] sprite_ptrs[3] = {sprite1, sprite2, sprite3};

// Function prototype
XORSprite( const color_t sprite[], int x, int y, int width, int height);

Calling the XORSprite function:

Code:
    ...blah...
    offset = 0; //or 1 or 2
    XORSprite(sprite_ptrs[offset], my_x, my_y, some_width, some_height);
Okay so I changed some code around, and not it won't compile with KermM's code...
Errors/warnings:

Code:

C:/PrizmSDK-0.3/projects/Electric_Moon/src/E_Moon.c:17:14: error: expected identifier or '(' before '[' token
C:/PrizmSDK-0.3/projects/Electric_Moon/src/E_Moon.c: In function 'main':
C:/PrizmSDK-0.3/projects/Electric_Moon/src/E_Moon.c:39:15: error: 'sprite_ptrs' undeclared (first use in this function)
C:/PrizmSDK-0.3/projects/Electric_Moon/src/E_Moon.c:39:15: note: each undeclared identifier is reported only once for each function it appears in
C:/PrizmSDK-0.3/projects/Electric_Moon/src/E_Moon.c: At top level:
C:/PrizmSDK-0.3/projects/Electric_Moon/src/E_Moon.c:96:6: error: conflicting types for 'XORSprite'

Edit:
It seems to be throwing the error on the XORSprite declaration becuase in the function it uses data from char * data which was replaced with const color_t sprite[] what can I replace the data++ with?
Hard to tell if we can't map line numbers to anything. Just guessing, but maybe Kerm has not-C on the brain (but maybe what he said is actually valid for the array declaration).

Code:
const color_t * const sprite_ptrs[3] = {sprite1, sprite2, sprite3};
If all your sprites are the same known size, it'll be slightly more efficient to make a 2d rather than jagged array:
Code:
const color_t sprites[SPRITE_SIZE_PX][3] = {
    { /* data here, etc */ }
};


Similarly, that's a wonky function prototype (where's the return type?!).

Code:
void XORSprite(const color_t *sprite, int x, int y, int w, int h);
Your implementation of course needs to agree with this signature, which it sounds like it doesn't. We'll need to know more about your code to really be able to help.
Yeah Kerm's code isn't working correctly as I keep getting rebooted, well actually it won't even compile any more Razz Here is my code:

Code:

#include <display_syscalls.h>
#include <keyboard_syscalls.h>
#include <display.h>
#include "color.h"
#include "keyboard.hpp"
//#include "Title.h"
#include "Sprites.h"

//#define LCD_WIDTH_PX 396     
//#define LCD_HEIGHT_PX 224   
#define KEY_PRGM_MENU 48

void keymenu();
void XORSprite( const color_t sprite[], int x, int y, int width, int height);
void title();
const color_t[] sprite_ptrs[4] = {sprite1, sprite2, sprite3, sprite4};
int PRGM_GetKey();
int keydown(int basic_keycode);
int offset=0;
int true=1;
int Mode=0;
int Sprite_X=45;
int Sprite_Y=45;
//dir 0-u 1-r 2-d 3-l
int S_dir=0;
int update=1;


int main(void) {
   while(true) {     
      if(PRGM_GetKey() == KEY_PRGM_MENU) {   
      keymenu();
      }
      if (keydown(KEY_PRGM_F1)) Mode=0;
      if (Mode==0) Bdisp_PutDisp_DD();
      if (keydown(KEY_PRGM_F2)) Mode=1;
      if ((keydown(KEY_PRGM_F3)) & (offset!=4) & (Mode==2)) {
         XORSprite( sprite_ptrs[offset], Sprite_X, Sprite_Y, 19, 29);
         offset++;
         update=1;
      }
      if ((keydown(KEY_PRGM_F4)) & (offset!=1) & (Mode==2)) {
         XORSprite( sprite_ptrs[offset], Sprite_X, Sprite_Y, 19, 29);
         offset--;
         update=1;
      }
      if (Mode==1) {
         if ((keydown(KEY_PRGM_UP)) & (Sprite_Y>0) & (update==0)) {
            XORSprite( sprite_ptrs[offset], Sprite_X, Sprite_Y, 19, 29);
            update=1;
            Sprite_Y=Sprite_Y-2;
         }
         if ((keydown(KEY_PRGM_DOWN)) & (Sprite_Y<224-29) & (update==0)) {
            XORSprite( sprite_ptrs[offset], Sprite_X, Sprite_Y, 19, 29);
            update=1;
            Sprite_Y=Sprite_Y+2;
         }
         if ((keydown(KEY_PRGM_LEFT)) & (Sprite_X>0) & (update==0)) {
            XORSprite( sprite_ptrs[offset], Sprite_X, Sprite_Y, 19, 29);
            update=1;
            Sprite_X=Sprite_X-2;
         }
         if ((keydown(KEY_PRGM_RIGHT)) & (Sprite_X<396-19) & (update==0)) {
            XORSprite( sprite_ptrs[offset], Sprite_X, Sprite_Y, 19, 29);
            update=1;
            Sprite_X=Sprite_X+2;
         }
      if (update==1) {
         XORSprite( sprite_ptrs[offset], Sprite_X, Sprite_Y, 19, 29);
         Bdisp_PutDisp_DD();
         update=0;
         }
      }
   }
 return 0;   

void keymenu(void) {   
   int key = KEY_PRGM_MENU;   
   GetKey(&key);   
}
int PRGM_GetKey(){ 
   unsigned char buffer[12]; 
   PRGM_GetKey_OS( buffer ); 
   return ( buffer[1] & 0x0F ) * 10 + ( ( buffer[2] & 0xF0 ) >> 4 ); 
}
int keydown(int basic_keycode) { 
   const unsigned short* lastkey = (unsigned short*)0xA44B0000; 
   int row, col, word, bit;     
   row = basic_keycode%10;     
   col = basic_keycode/10-1;     
   word = row>>1;     
   bit = col + 8*(row&1);     
   return (0 != (lastkey[word] & 1<<bit));     
}
void XORSprite(char* data, int x, int y, int width, int height) { 
   char* VRAM = (char*)0xA8000000; 
   VRAM += 2*(LCD_WIDTH_PX*y + x); 
   for(int j=y; j<y+height; j++) { 
      for(int i=x; i<x+width;  i++) { 
         *(VRAM++) ^= *(data++); 
         *(VRAM++) ^= *(data++); 
      } 
      VRAM += 2*(LCD_WIDTH_PX-width); 
   } 
}

Thanks for your help.
It wasn't meant to be fully-functioning code, more to give you the general idea of what you should be doing with the array of sprite pointers. Smile The XORSprite() declaration was just to show that you can't have math in the arguments line as Zelda's original code did.
  
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