That's just what GetKey does, I think. Add the full color syscall in the while loop and you should be good.
Hmmm... having problems.

This is supposed to plot a trajectory.


Code:


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

#include <keyboard_syscalls.h>

#include <keyboard.hpp>

#include <math.h>

#include <color.h>



short unsigned int heightcolor(float z, float z_min, float z_max);
short unsigned int heightcolor(float z, float z_min, float z_max);
void fillArea(int x, int y, int width, int height, int color);
void fillArea(int x, int y, int width, int height, int color);
int PRGM_GetKey(void);
int PRGM_GetKey(void);
void plot(int x0, int y0, int color);
void plot(int x0, int y0, int color);


int main(void) {
int main(void) {
//program variables
//program variables
int key;
int key;
int done = 0;
int done = 0;


//graphing variables
//graphing variables
float start = 0;
float start = 0;
float t;
float t;
float x;
float x;
float y = 100;
float y = 100;
int h = 2;
int h = 2;
float g = -9.8;
float g = -9.8;
float vy = 0;
float vy = 0;
float vx = 100;
float vx = 100;
char buffer2[10];
char buffer2[10];






for(t=start; t < 2; t += 0.01) {
for(t=start; t < 2; t += 0.01) {
//y = h+0.5*g* t*t + vy*t;
//y = h+0.5*g* t*t + vy*t;
//x = vx*t;
//x = vx*t;


x = vx*t;
x = vx*t;
y += vy;
y += vy;
vy -= 9.8;
vy -= 9.8;


//start debug
//start debug
strcpy(buffer2," ");
strcpy(buffer2," ");
itoa(x, buffer2+2);
itoa(x, buffer2+2);
PrintXY(3, 1, buffer2, TEXT_MODE_NORMAL, TEXT_COLOR_BLACK);
PrintXY(3, 1, buffer2, TEXT_MODE_NORMAL, TEXT_COLOR_BLACK);


strcpy(buffer2," ");
strcpy(buffer2," ");
itoa(x, buffer2+2);
itoa(x, buffer2+2);
PrintXY(3, 2, buffer2, TEXT_MODE_NORMAL, TEXT_COLOR_BLACK);
PrintXY(3, 2, buffer2, TEXT_MODE_NORMAL, TEXT_COLOR_BLACK);


PrintXY(1, 1, " X", TEXT_MODE_NORMAL, TEXT_COLOR_BLACK);
PrintXY(1, 1, " X", TEXT_MODE_NORMAL, TEXT_COLOR_BLACK);
PrintXY(1, 2, " Y", TEXT_MODE_NORMAL, TEXT_COLOR_BLACK);
PrintXY(1, 2, " Y", TEXT_MODE_NORMAL, TEXT_COLOR_BLACK);
//end debug
//end debug


plot(x, LCD_HEIGHT_PX - y, COLOR_BLACK);
plot(x, LCD_HEIGHT_PX - y, COLOR_BLACK);
Bdisp_PutDisp_DD();
Bdisp_PutDisp_DD();
}
}






while(!done) {
while(!done) {
key = PRGM_GetKey();
key = PRGM_GetKey();


switch(key) {
switch(key) {
case KEY_PRGM_MENU:
case KEY_PRGM_MENU:
done = 1;
done = 1;
break;
break;
}
}
}
}


return 1;
return 1;
}





//routines

short unsigned int heightcolor(float z, float z_min, float z_max) {
short unsigned int heightcolor(float z, float z_min, float z_max) {
float frac = ((z-z_min)/(z_max-z_min));
float frac = ((z-z_min)/(z_max-z_min));


//color!
//color!
float r = (0.25f)-frac;
float r = (0.25f)-frac;
float g = (0.5f)-frac;
float g = (0.5f)-frac;
float b = (0.75f)-frac;
float b = (0.75f)-frac;


//calculate the R/G/B values
//calculate the R/G/B values
r = (r>0.f)?r:-r; g = (g>0.f)?g:-g; b = (b>0.f)?b:-b; //absolute value
r = (r>0.f)?r:-r; g = (g>0.f)?g:-g; b = (b>0.f)?b:-b; //absolute value
r = (0.25f)-r; g = (1.f/3.f)-g; b = (0.25f)-b; //invert
r = (0.25f)-r; g = (1.f/3.f)-g; b = (0.25f)-b; //invert
r = (r>0.f)?(6.f*r):0.f; g = (g>0.f)?(6.f*g):0.f; b = (b>0.f)?(6.f*B):0.f; //scale the chromatic triangles
r = (r>0.f)?(6.f*r):0.f; g = (g>0.f)?(6.f*g):0.f; b = (b>0.f)?(6.f*B):0.f; //scale the chromatic triangles
r = (r>1.f)?1.f:r; g = (g>1.f)?1.f:g; b = (b>1.f)?1.f:b; //clip the top of the chromatic triangles
r = (r>1.f)?1.f:r; g = (g>1.f)?1.f:g; b = (b>1.f)?1.f:b; //clip the top of the chromatic triangles
if (frac < 0.25f) r = (r+1.f)/2.f; //adjust the bottom end of the scale so that z_min is red, not black
if (frac < 0.25f) r = (r+1.f)/2.f; //adjust the bottom end of the scale so that z_min is red, not black
if (frac > 0.75f) b = (b+1.f)/2.f; //adjust the top end of the scale so that z_max is blue, not black
if (frac > 0.75f) b = (b+1.f)/2.f; //adjust the top end of the scale so that z_max is blue, not black
return (short unsigned int)(0x0000ffff & (((int)(31.f*r) << 11) | ((int)(63.f*g) << 5) | ((int)(31.f*B)))); //put the bits together
return (short unsigned int)(0x0000ffff & (((int)(31.f*r) << 11) | ((int)(63.f*g) << 5) | ((int)(31.f*B)))); //put the bits together
}



void fillArea(int x, int y, int width, int height, int color) {
void fillArea(int x, int y, int width, int height, int color) {
//only use lower two bytes of color
//only use lower two bytes of color
char* VRAM = (char*)0xA8000000;
char* VRAM = (char*)0xA8000000;
VRAM += 2*(LCD_WIDTH_PX*y + x);
VRAM += 2*(LCD_WIDTH_PX*y + x);
for(int j=y; j<y+height; j++) {
for(int j=y; j<y+height; j++) {
for(int i=x; i<x+width; i++) {
for(int i=x; i<x+width; i++) {
*(VRAM++) = (color&0x0000FF00)>>8;
*(VRAM++) = (color&0x0000FF00)>>8;
*(VRAM++) = (color&0x000000FF);
*(VRAM++) = (color&0x000000FF);
}
}
VRAM += 2*(LCD_WIDTH_PX-width);
VRAM += 2*(LCD_WIDTH_PX-width);
}
}
}
}


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



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


//my routines


Instead, i plot points all over the screen. I think this is float problem, but could someone take a look at it and tell me if they can see anyhting that is obviously wrong?
Why is every line in your source code doubled...?
Hmm.. that was weird, dunno.

anyway, i got it to work, but every time i try to edit it I get random points on the screen.

Is there something i dont know about floats?


Code:

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

short unsigned int heightcolor(float z, float z_min, float z_max);
void fillArea(int x, int y, int width, int height, int color);
int PRGM_GetKey(void);
void plot(int x0, int y0, int color);
void plotBallistics(float start, int startHeight, int endHeight, float vy, float vx, int color);
int PrintMiniFix( int x, int y, const char*Msg, const int flags, const short color, const short bcolor );
void mainGUI(char*cartridge);

int main(void) {
   int key;
   int done = 0;
   
   mainGUI(".22");
   

   
   Bdisp_PutDisp_DD();
   
   while(!done) {
      key = PRGM_GetKey();
   
      switch(key) {
         case KEY_PRGM_MENU:
         done = 1;
         break;
      }
   }
   return 1;
}


//routines
short unsigned int heightcolor(float z, float z_min, float z_max) {
         float frac = ((z-z_min)/(z_max-z_min));
         
         //color!
         float r = (0.25f)-frac;
         float g = (0.5f)-frac;
         float b = (0.75f)-frac;

         //calculate the R/G/B values
         r = (r>0.f)?r:-r; g = (g>0.f)?g:-g; b = (b>0.f)?b:-b;   //absolute value
         r = (0.25f)-r; g = (1.f/3.f)-g; b = (0.25f)-b;   //invert
         r = (r>0.f)?(6.f*r):0.f; g = (g>0.f)?(6.f*g):0.f; b = (b>0.f)?(6.f*b):0.f;   //scale the chromatic triangles
         r = (r>1.f)?1.f:r; g = (g>1.f)?1.f:g; b = (b>1.f)?1.f:b;   //clip the top of the chromatic triangles
         if (frac < 0.25f) r = (r+1.f)/2.f;   //adjust the bottom end of the scale so that z_min is red, not black
         if (frac > 0.75f) b = (b+1.f)/2.f;   //adjust the top end of the scale so that z_max is blue, not black
         return (short unsigned int)(0x0000ffff & (((int)(31.f*r) << 11) | ((int)(63.f*g) << 5) | ((int)(31.f*b))));   //put the bits together
}

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);
    }
 }
 
int PRGM_GetKey(void) {
  unsigned char buffer[12];
  PRGM_GetKey_OS( buffer );
  return ( buffer[1] & 0x0F ) * 10 + ( ( buffer[2] & 0xF0 ) >> 4 );
}

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;
 }

int PrintMiniFix( int x, int y, const char*Msg, const int flags, const short color, const short bcolor ){
int i = 0, dx;
int empty;
unsigned short width;
void*p;

   while ( Msg[ i ] ){
      p = GetMiniGlyphPtr( Msg[ i ], &width );
      dx = ( 12 - width ) / 2;
      if ( dx > 0 ) {
         PrintMiniGlyph( x, y, (void*)empty, flags, dx, 0, 0, 0, 0, color, bcolor, 0 );
      }else dx = 0;
      PrintMiniGlyph( x+dx, y, p, flags, width, 0, 0, 0, 0, color, bcolor, 0 );
      if ( width+dx < 12 ){
         PrintMiniGlyph( x+width+dx, y, (void*)empty, flags, 12-width-dx, 0, 0, 0, 0, color, bcolor, 0 );
      }
      x += 12;
      i++;
   }
   return x;
}
const short empty[18] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };


//my routines
void mainGUI(char*cartridge) {
   //background
   fillArea(0, 0, LCD_WIDTH_PX, LCD_HEIGHT_PX, (color_t)0x3333);
   //graph
   plotBallistics(0, 100, 40, 0, 300, COLOR_ORANGE);
   //bars
   //bottom
   fillArea(0, LCD_HEIGHT_PX - 50, LCD_WIDTH_PX, 50, COLOR_BLACK);
   fillArea(0, LCD_HEIGHT_PX - 51, LCD_WIDTH_PX, 1, COLOR_GRAY);
   //top
   fillArea(0, 0, LCD_WIDTH_PX, 25, COLOR_DARKBLUE);
   fillArea(0, 25, LCD_WIDTH_PX, 1, COLOR_GRAY);
   //buttons
   //cartridge
   fillArea(5, LCD_HEIGHT_PX - 40, 100, 30, COLOR_DARKRED);
   PrintMiniFix(7, LCD_HEIGHT_PX - 55, cartridge, 0, COLOR_WHITE, COLOR_DARKRED);
   //go
   fillArea(LCD_WIDTH_PX - 55, LCD_HEIGHT_PX - 40, 50, 30, COLOR_DARKGREEN);
   PrintMiniFix(LCD_WIDTH_PX - 45, LCD_HEIGHT_PX - 55, "GO", 0, COLOR_WHITE, COLOR_DARKGREEN);
}

void plotBallistics(float start, int startHeight, int endHeight, float vy, float vx, int color) {
   float t;
   float x;
   float y = startHeight;
   for(t=start; t < 2; t += 0.01) {
      //y = h+0.5*g* t*t + vy*t;
      //x = vx*t;
      
      x = vx*t;
      //x /= 10;
      
   
      y += vy;
      vy -= 9.8*t;
      
      if(y<0) {
         break;
      }
      
      y += endHeight;
      
      plot(x, LCD_HEIGHT_PX - y, color);
      fillArea(x, LCD_HEIGHT_PX - y, 4, 4, color);
   }
}
   
  
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 6 of 6
» All times are GMT - 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