Jump to content



Photo
- - - - -

General Prizmsdk Help Thread


  • Please log in to reply
5 replies to this topic

#1 flyingfisch

flyingfisch

    Casio Maniac

  • Deputy
  • PipPipPipPipPipPipPipPip
  • 1891 posts
  • Gender:Male
  • Location:OH,USA
  • Interests:Aviation, Skiing, Programming, Mountain Biking.

  • Calculators:
    fx-9860GII
    fx-CG10 PRIZM

Posted 10 May 2012 - 01:00 PM

I decided to make a help thread so anyone can post questions about the PrizmSDK/C when they need to.

#2 flyingfisch

flyingfisch

    Casio Maniac

  • Deputy
  • PipPipPipPipPipPipPipPip
  • 1891 posts
  • Gender:Male
  • Location:OH,USA
  • Interests:Aviation, Skiing, Programming, Mountain Biking.

  • Calculators:
    fx-9860GII
    fx-CG10 PRIZM

Posted 29 June 2012 - 01:56 PM

OK, need help.


My code:

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

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 main(void) {
	int ix;
	int key;
	int color;
	int done = 0;
	
	for (ix=1; LCD_WIDTH_PX; 1) {
		color = heightcolor(ix, 0, LCD_WIDTH_PX);
		fillArea(ix, 0, 1, LCD_HEIGHT_PX, color);
		Bdisp_PutDisp_DD();
	}
	
	while(!done) {
		GetKey(&key);
	
		switch(key) {
			case KEY_CTRL_MENU:
			done = 1;
			break;
		}
	}

	return 1;
}

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*<img src='/dot/public/style_emoticons/<#EMO_DIR#>/cool.png' class='bbc_emoticon' alt='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*<img src='/dot/public/style_emoticons/<#EMO_DIR#>/cool.png' class='bbc_emoticon' alt='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); 
    } 
 }


It's supposed to draw a rainbow across the screen but all it succeeds in doing is freezing my calc. why?

#3 MicroPro

MicroPro

    Casio Overlord

  • Deputy
  • PipPipPipPipPipPipPip
  • 640 posts
  • Gender:Male
  • Location:Iran

  • Calculators:
    Casio ClassPad 300

Posted 29 June 2012 - 02:11 PM

From answer on IRC channel:

(6:32:55 PM) MicroPro: ffisch: Were you programming in BASIC recently?
(6:32:58 PM) MicroPro: for (ix=1; LCD_WIDTH_PX; 1)
(6:33:00 PM) MicroPro: should be
(6:33:05 PM) MicroPro: for (ix=1; ix < LCD_WIDTH_PX; ix++)
...
(6:33:52 PM) ffisch: and actually, i was programming in lua recently �4z

#4 flyingfisch

flyingfisch

    Casio Maniac

  • Deputy
  • PipPipPipPipPipPipPipPip
  • 1891 posts
  • Gender:Male
  • Location:OH,USA
  • Interests:Aviation, Skiing, Programming, Mountain Biking.

  • Calculators:
    fx-9860GII
    fx-CG10 PRIZM

Posted 29 June 2012 - 07:58 PM

Hmmm... having problems.

This is supposed to plot a trajectory.


#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*<img src='/dot/public/style_emoticons/<#EMO_DIR#>/cool.png' class='bbc_emoticon' alt='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*<img src='/dot/public/style_emoticons/<#EMO_DIR#>/cool.png' class='bbc_emoticon' alt='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*<img src='/dot/public/style_emoticons/<#EMO_DIR#>/cool.png' class='bbc_emoticon' alt='B)' />))); //put the bits together
return (short unsigned int)(0x0000ffff & (((int)(31.f*r) << 11) | ((int)(63.f*g) << 5) | ((int)(31.f*<img src='/dot/public/style_emoticons/<#EMO_DIR#>/cool.png' class='bbc_emoticon' alt='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?

#5 flyingfisch

flyingfisch

    Casio Maniac

  • Deputy
  • PipPipPipPipPipPipPipPip
  • 1891 posts
  • Gender:Male
  • Location:OH,USA
  • Interests:Aviation, Skiing, Programming, Mountain Biking.

  • Calculators:
    fx-9860GII
    fx-CG10 PRIZM

Posted 01 July 2012 - 06:37 PM

hmm, i am still working on this.

I think there is something i dont know about floats.

can you see a math error in function plotBallistics?


#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*<img src='/dot/public/style_emoticons/<#EMO_DIR#>/cool.png' class='bbc_emoticon' alt='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*<img src='/dot/public/style_emoticons/<#EMO_DIR#>/cool.png' class='bbc_emoticon' alt='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);
}
}



#6 MicroPro

MicroPro

    Casio Overlord

  • Deputy
  • PipPipPipPipPipPipPip
  • 640 posts
  • Gender:Male
  • Location:Iran

  • Calculators:
    Casio ClassPad 300

Posted 06 July 2012 - 12:01 PM

floats' precision is usually enough for these small number so no need to worry. ;)
There is, as you guessed, an error in plotBallistics. You are adding 140 to y in each iteration:

Instead of:
y += endHeight;
plot(x, LCD_HEIGHT_PX - y, color);
fillArea(x, LCD_HEIGHT_PX - y, 4, 4, color);

you should have:
//y += endHeight;
plot(x, LCD_HEIGHT_PX - (y + endHeight), color);
fillArea(x, LCD_HEIGHT_PX - (y + endHeight), 4, 4, color);





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users