View difference between Paste ID: E4dRNSQ3 and aZdq5KZS
SHOW: | | - or go back to the newest paste.
1-
#include <display_syscalls.h>
1+
#include <display_syscalls.h>
2-
#include <display.h>
2+
#include <display.h>
3-
#include <keyboard_syscalls.h>
3+
#include <keyboard_syscalls.h>
4-
#include <keyboard.hpp>
4+
#include <keyboard.hpp>
5-
#include <math.h>
5+
#include <math.h>
6-
#include <color.h>
6+
#include <color.h>
7-
7+
8-
short unsigned int heightcolor(float z, float z_min, float z_max);
8+
short unsigned int heightcolor(float z, float z_min, float z_max);
9-
void fillArea(int x, int y, int width, int height, int color);
9+
void fillArea(int x, int y, int width, int height, int color);
10-
int PRGM_GetKey(void);
10+
int PRGM_GetKey(void);
11-
void plot(int x0, int y0, int color);
11+
void plot(int x0, int y0, int color);
12-
12+
13-
int main(void) {
13+
int main(void) {
14-
	//program variables
14+
	//program variables
15-
	int key;
15+
	int key;
16-
	int done = 0;
16+
	int done = 0;
17-
	
17+
	
18-
	//graphing variables
18+
	//graphing variables
19-
	float start = 0;
19+
	float start = 0;
20-
	float t;
20+
	float t;
21-
	int x;
21+
	float x;
22-
	int y = 2;
22+
	float y = 100;
23-
	int h = 2;
23+
	int h = 2;
24-
	float g = -9.8;
24+
	float g = -9.8;
25-
	int vy = 0;
25+
	float vy = 0;
26-
	int vx = 100;
26+
	float vx = 100;
27-
	char buffer2[10];
27+
	char buffer2[10];
28-
	
28+
	
29-
29+
30-
	
30+
	
31-
	for(t=start; t < 2; t += 0.01) {
31+
	for(t=start; t < 2; t += 0.01) {
32-
		//y = h+0.5*g* t*t + vy*t;
32+
		//y = h+0.5*g* t*t + vy*t;
33-
		//x = vx*t;
33+
		//x = vx*t;
34-
		
34+
		
35-
		x = vx*t;
35+
		x = vx*t;
36-
		y += vy;
36+
		y += vy;
37-
		vy -= 9.8;
37+
		vy -= 9.8;
38-
		
38+
		
39-
		//start debug
39+
		//start debug
40-
		strcpy(buffer2,"  ");
40+
		strcpy(buffer2,"  ");
41-
		itoa(x, buffer2+2);
41+
		itoa(x, buffer2+2);
42-
		PrintXY(3, 1, buffer2, TEXT_MODE_NORMAL, TEXT_COLOR_BLACK);
42+
		PrintXY(3, 1, buffer2, TEXT_MODE_NORMAL, TEXT_COLOR_BLACK);
43-
		
43+
		
44-
		strcpy(buffer2,"  ");
44+
		strcpy(buffer2,"  ");
45-
		itoa(x, buffer2+2);
45+
		itoa(x, buffer2+2);
46-
		PrintXY(3, 2, buffer2, TEXT_MODE_NORMAL, TEXT_COLOR_BLACK);
46+
		PrintXY(3, 2, buffer2, TEXT_MODE_NORMAL, TEXT_COLOR_BLACK);
47-
		
47+
		
48-
		PrintXY(1, 1, "  X", TEXT_MODE_NORMAL, TEXT_COLOR_BLACK);
48+
		PrintXY(1, 1, "  X", TEXT_MODE_NORMAL, TEXT_COLOR_BLACK);
49-
		PrintXY(1, 2, "  Y", TEXT_MODE_NORMAL, TEXT_COLOR_BLACK);
49+
		PrintXY(1, 2, "  Y", TEXT_MODE_NORMAL, TEXT_COLOR_BLACK);
50-
		//end debug
50+
		//end debug
51-
		
51+
		
52-
		plot(x, LCD_HEIGHT_PX - y, COLOR_BLACK);
52+
		plot(x, LCD_HEIGHT_PX - y, COLOR_BLACK);
53-
		Bdisp_PutDisp_DD();
53+
		Bdisp_PutDisp_DD();
54-
	}
54+
	}
55-
	
55+
	
56-
	
56+
	
57-
	
57+
	
58-
	while(!done) {
58+
	while(!done) {
59-
		key = PRGM_GetKey();
59+
		key = PRGM_GetKey();
60-
	
60+
	
61-
		switch(key) {
61+
		switch(key) {
62-
			case KEY_PRGM_MENU:
62+
			case KEY_PRGM_MENU:
63-
			done = 1;
63+
			done = 1;
64-
			break;
64+
			break;
65-
		}
65+
		}
66-
	}
66+
	}
67-
 
67+
 
68-
	return 1;
68+
	return 1;
69-
}
69+
}
70-
70+
71-
71+
72-
//routines
72+
//routines
73-
short unsigned int heightcolor(float z, float z_min, float z_max) {
73+
short unsigned int heightcolor(float z, float z_min, float z_max) {
74-
         float frac = ((z-z_min)/(z_max-z_min));
74+
         float frac = ((z-z_min)/(z_max-z_min));
75-
         
75+
         
76-
         //color!
76+
         //color!
77-
         float r = (0.25f)-frac;
77+
         float r = (0.25f)-frac;
78-
         float g = (0.5f)-frac;
78+
         float g = (0.5f)-frac;
79-
         float b = (0.75f)-frac;
79+
         float b = (0.75f)-frac;
80-
80+
81-
         //calculate the R/G/B values
81+
         //calculate the R/G/B values
82-
         r = (r>0.f)?r:-r; g = (g>0.f)?g:-g; b = (b>0.f)?b:-b;   //absolute value
82+
         r = (r>0.f)?r:-r; g = (g>0.f)?g:-g; b = (b>0.f)?b:-b;   //absolute value
83-
         r = (0.25f)-r; g = (1.f/3.f)-g; b = (0.25f)-b;   //invert
83+
         r = (0.25f)-r; g = (1.f/3.f)-g; b = (0.25f)-b;   //invert
84-
         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
84+
         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
85-
         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
85+
         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
86-
         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
86+
         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
87-
         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
87+
         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
88-
         return (short unsigned int)(0x0000ffff & (((int)(31.f*r) << 11) | ((int)(63.f*g) << 5) | ((int)(31.f*b))));   //put the bits together
88+
         return (short unsigned int)(0x0000ffff & (((int)(31.f*r) << 11) | ((int)(63.f*g) << 5) | ((int)(31.f*b))));   //put the bits together
89-
}
89+
}
90-
90+
91-
void fillArea(int x, int y, int width, int height, int color) { 
91+
void fillArea(int x, int y, int width, int height, int color) { 
92-
    //only use lower two bytes of color 
92+
    //only use lower two bytes of color 
93-
    char* VRAM = (char*)0xA8000000; 
93+
    char* VRAM = (char*)0xA8000000; 
94-
    VRAM += 2*(LCD_WIDTH_PX*y + x); 
94+
    VRAM += 2*(LCD_WIDTH_PX*y + x); 
95-
    for(int j=y; j<y+height; j++) { 
95+
    for(int j=y; j<y+height; j++) { 
96-
       for(int i=x; i<x+width;  i++) { 
96+
       for(int i=x; i<x+width;  i++) { 
97-
          *(VRAM++) = (color&0x0000FF00)>>8; 
97+
          *(VRAM++) = (color&0x0000FF00)>>8; 
98-
          *(VRAM++) = (color&0x000000FF); 
98+
          *(VRAM++) = (color&0x000000FF); 
99-
       } 
99+
       } 
100-
       VRAM += 2*(LCD_WIDTH_PX-width); 
100+
       VRAM += 2*(LCD_WIDTH_PX-width); 
101-
    } 
101+
    } 
102-
 }
102+
 }
103-
 
103+
 
104-
int PRGM_GetKey(void) {
104+
int PRGM_GetKey(void) {
105-
  unsigned char buffer[12];
105+
  unsigned char buffer[12];
106-
  PRGM_GetKey_OS( buffer );
106+
  PRGM_GetKey_OS( buffer );
107-
  return ( buffer[1] & 0x0F ) * 10 + ( ( buffer[2] & 0xF0 ) >> 4 );
107+
  return ( buffer[1] & 0x0F ) * 10 + ( ( buffer[2] & 0xF0 ) >> 4 );
108-
}
108+
}
109-
109+
110-
void plot(int x0, int y0, int color) { 
110+
void plot(int x0, int y0, int color) { 
111-
    char* VRAM = (char*)0xA8000000; 
111+
    char* VRAM = (char*)0xA8000000; 
112-
    VRAM += 2*(y0*LCD_WIDTH_PX + x0); 
112+
    VRAM += 2*(y0*LCD_WIDTH_PX + x0); 
113-
    *(VRAM++) = (color&0x0000FF00)>>8; 
113+
    *(VRAM++) = (color&0x0000FF00)>>8; 
114-
    *(VRAM++) = (color&0x000000FF); 
114+
    *(VRAM++) = (color&0x000000FF); 
115-
    return; 
115+
    return; 
116-
 }
116+
 }
117-
117+
118
//my routines