OK, so for some reason libfxcg doesn't like my code...

main.c:

Code:

#include <fxcg/display.h>
#include <fxcg_display.h>
#include <fxcg/keyboard.h>
#include "routines.c"

/* FUNCTIONS */
// (from routines.c)
void CopySpriteNbit(const unsigned char* data, int x, int y, int width, int height, const color_t* palette, unsigned int bitwidth);
void CopySpriteNbitMasked(const unsigned char* data, int x, int y, int width, int height, const color_t* palette, color_t maskColor, unsigned int bitwidth);
int PRGM_GetKey(void);
void keyupdate(void);
int keydownlast(int basic_keycode);
int keydownhold(int basic_keycode);
void plot(int x0, int y0, int color);
void drawLine(int x1, int y1, int x2, int y2, int color);
void fillArea(int x, int y, int width, int height, int color);
void wait(int ms);

int main() {
   int key;
   Bdisp_AllClr_VRAM();

   while (1) {
      Bdisp_PutDisp_DD();
      GetKey(&key);
   }

   return 1;
}


routines.c

Code:

#include <fxcg/display.h>
#include <fxcg_display.h>
#include <fxcg/keyboard.h>

void CopySpriteNbit(const unsigned char* data, int x, int y, int width, int height, const color_t* palette, unsigned int bitwidth) {
   color_t* VRAM = (color_t*)0xA8000000;
   VRAM += (LCD_WIDTH_PX*y + x);
   int offset = 0;
   unsigned char buf;
   for(int j=y; j<y+height; j++) {
      int availbits = 0;
      for(int i=x; i<x+width;  i++) {
         if (!availbits) {
            buf = data[offset++];
            availbits = 8;
         }
         color_t this = ((color_t)buf>>(8-bitwidth));
         *VRAM = palette[(color_t)this];
         VRAM++;
         buf<<=bitwidth;
         availbits-=bitwidth;
      }
      VRAM += (LCD_WIDTH_PX-width);
   }
}

void CopySpriteNbitMasked(const unsigned char* data, int x, int y, int width, int height, const color_t* palette, color_t maskColor, unsigned int bitwidth) {
   color_t* VRAM = (color_t*)0xA8000000;
   VRAM += (LCD_WIDTH_PX*y + x);
   int offset = 0;
   unsigned char buf;
   for(int j=y; j<y+height; j++) 
   {
      int availbits = 0;
      for(int i=x; i<x+width;  i++) 
      {
         if (!availbits) 
         {
            buf = data[offset++];
            availbits = 8;
         }
         color_t this = ((color_t)buf>>(8-bitwidth));
         color_t color = palette[this];
         if(color != maskColor)
         {
            *VRAM = color;
         }
         VRAM++;
         buf<<=bitwidth;
         availbits-=bitwidth;
      }
      VRAM += (LCD_WIDTH_PX-width);
   }
}

int PRGM_GetKey(void) {
   unsigned char buffer[12];
   PRGM_GetKey_OS( buffer );
   return ( buffer[1] & 0x0F ) * 10 + ( ( buffer[2] & 0xF0 ) >> 4 );
}

const unsigned short* keyboard_register = (unsigned short*)0xA44B0000;
unsigned short lastkey[8];
unsigned short holdkey[8];

void keyupdate(void) {
 memcpy(holdkey, lastkey, sizeof(unsigned short)*8);
 memcpy(lastkey, keyboard_register, sizeof(unsigned short)*8);
}
int keydownlast(int basic_keycode) {
 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));
}
int keydownhold(int basic_keycode) {
 int row, col, word, bit;
 row = basic_keycode%10;
 col = basic_keycode/10-1;
 word = row>>1;
 bit = col + 8*(row&1);
 return (0 != (holdkey[word] & 1<<bit));
}

//draws a point of color color at (x0, y0)
void plot(int x0, int y0, int color) {
   char* VRAM = (char*)0xA8000000;
   VRAM += 2*(y0*LCD_WIDTH_PX + x0);
   *(VRAM++) = (color&0x0000FF00)>>8;
   *(VRAM++) = (color&0x000000FF);
   return;
}

//Uses the Bresenham line algorithm
void drawLine(int x1, int y1, int x2, int y2, int color) {
    signed char ix;
    signed char iy;
 
    // if x1 == x2 or y1 == y2, then it does not matter what we set here
    int delta_x = (x2 > x1?(ix = 1, x2 - x1):(ix = -1, x1 - x2)) << 1;
    int delta_y = (y2 > y1?(iy = 1, y2 - y1):(iy = -1, y1 - y2)) << 1;
 
   plot(x1, y1, color); 
    if (delta_x >= delta_y) {
        int error = delta_y - (delta_x >> 1);        // error may go below zero
        while (x1 != x2) {
            if (error >= 0) {
                if (error || (ix > 0)) {
                    y1 += iy;
                    error -= delta_x;
                }                           // else do nothing
         }                              // else do nothing
            x1 += ix;
            error += delta_y;
            plot(x1, y1, color);
        }
    } else {
        int error = delta_x - (delta_y >> 1);      // error may go below zero
        while (y1 != y2) {
            if (error >= 0) {
                if (error || (iy > 0)) {
                    x1 += ix;
                    error -= delta_y;
                }                           // else do nothing
            }                              // else do nothing
            y1 += iy;
            error += delta_x; 
            plot(x1, y1, color);
        }
    }
}

//fills a rectangular area of (width,height) with upper-left
//corner at (x,y) with color color
void fillArea(int x, int y, int width, int height, int color) {
   //only use lower two bytes of color
   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++) = (color&0x0000FF00)>>8;
         *(VRAM++) = (color&0x000000FF);
      }
      VRAM += 2*(LCD_WIDTH_PX-width);
   }
}

// wait routine
void wait(int ms) {
   int start_time = RTC_GetTicks();
   int key;
   while ((RTC_GetTicks()-start_time)<ms) {
      // handle [menu]
      if (PRGM_GetKey()==48) {
         GetKey(&key);
      }
   }
}


errors:

Code:

$ make
/usr/local/cross/bin/sh3eb-elf-gcc -MMD -MP -MF /home/flyingfisch/Dropbox/PrizmSDK-libfxcg/projects/15puzzle/build/main.d -Os -Wall -mb -m4a-nofpu -mhitachi -nostdlib   -I/home/flyingfisch/Dropbox/PrizmSDK-libfxcg/projects/15puzzle/build -I/home/flyingfisch/Dropbox/PrizmSDK-libfxcg/include -std=c99 -c /home/flyingfisch/Dropbox/PrizmSDK-libfxcg/projects/15puzzle/src/main.c -o main.o
In file included from /home/flyingfisch/Dropbox/PrizmSDK-libfxcg/include/fxcg_display.h:5:0,
                 from /home/flyingfisch/Dropbox/PrizmSDK-libfxcg/projects/15puzzle/src/main.c:2:
/home/flyingfisch/Dropbox/PrizmSDK-libfxcg/include/color.h:2:3: error: #error Included color.h without minicompat. Use <fxcg/display.h>.
In file included from /home/flyingfisch/Dropbox/PrizmSDK-libfxcg/projects/15puzzle/src/main.c:2:0:
/home/flyingfisch/Dropbox/PrizmSDK-libfxcg/include/fxcg_display.h:40:2: error: unknown type name 'TBdispFillArea'
In file included from /home/flyingfisch/Dropbox/PrizmSDK-libfxcg/projects/15puzzle/src/main.c:4:0:
/home/flyingfisch/Dropbox/PrizmSDK-libfxcg/projects/15puzzle/src/routines.c: In function 'keyupdate':
/home/flyingfisch/Dropbox/PrizmSDK-libfxcg/projects/15puzzle/src/routines.c:67:2: warning: implicit declaration of function 'memcpy' [-Wimplicit-function-declaration]
/home/flyingfisch/Dropbox/PrizmSDK-libfxcg/projects/15puzzle/src/routines.c:67:2: warning: incompatible implicit declaration of built-in function 'memcpy' [enabled by default]
/home/flyingfisch/Dropbox/PrizmSDK-libfxcg/projects/15puzzle/src/routines.c: In function 'wait':
/home/flyingfisch/Dropbox/PrizmSDK-libfxcg/projects/15puzzle/src/routines.c:152:4: warning: implicit declaration of function 'RTC_GetTicks' [-Wimplicit-function-declaration]
make[1]: *** [main.o] Error 1
make: *** [build] Error 2

Those errors seem pretty clear to me...
Code:
/home/flyingfisch/Dropbox/PrizmSDK-libfxcg/include/color.h:2:3: error: #error Included color.h without minicompat. Use <fxcg/display.h>.
but I didn't include color.h, and i did include display.h...
flyingfisch wrote:
but I didn't include color.h, and i did include display.h...
Ah, indeed. That's a weird sort of error. Well, did you take a look at this error and see what file defined the item in question?
Code:
In file included from /home/flyingfisch/Dropbox/PrizmSDK-libfxcg/projects/15puzzle/src/main.c:2:0:
/home/flyingfisch/Dropbox/PrizmSDK-libfxcg/include/fxcg_display.h:40:2: error: unknown type name 'TBdispFillArea'
flyingfisch wrote:

Code:

#include <fxcg/display.h>
#include <fxcg_display.h>
You're mixing legacy and new-style includes. Don't.
Tari wrote:
flyingfisch wrote:

Code:

#include <fxcg/display.h>
#include <fxcg_display.h>
You're mixing legacy and new-style includes. Don't.


???

I'm sorry, I don't understand.
flyingfisch wrote:
Tari wrote:
flyingfisch wrote:

Code:

#include <fxcg/display.h>
#include <fxcg_display.h>
You're mixing legacy and new-style includes. Don't.


???

I'm sorry, I don't understand.


Your mixing / and _ with including .h files
krazylegodrummer56 wrote:
flyingfisch wrote:
Tari wrote:
flyingfisch wrote:

Code:

#include <fxcg/display.h>
#include <fxcg_display.h>
You're mixing legacy and new-style includes. Don't.


???

I'm sorry, I don't understand.


Your mixing / and _ with including .h files


Oh, are we only supposed to use includes from fxcg/* ?
Yes.
OK, now that I have that figured out, I have another question. Is there a PrintXY_fixed command or similar that automatically adds two chars to the beginning of a string and prints it with PrintXY?
Not that I know of, but it is trivial to implement one yourself.
Also note that since it will need to do string manipulation for every string you want to print, it will be a bit slow than just adding two chars at the beginning of a string (in case it's a constant string, of course - if it's something you're printing at run-time, you'd need to add the two chars anyway).
gbl08ma wrote:
Not that I know of, but it is trivial to implement one yourself.
Also note that since it will need to do string manipulation for every string you want to print, it will be a bit slow than just adding two chars at the beginning of a string (in case it's a constant string, of course - if it's something you're printing at run-time, you'd need to add the two chars anyway).


Yeah, I am thinking about generated strings here. Maybe that could be added to libfxcg?
  
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