Rev 1005 | Rev 2870 | Go to most recent revision | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 1005 | Rev 1764 | ||
---|---|---|---|
1 | #include "func.h" |
1 | #include "func.h" |
2 | #include "parser.h" |
2 | #include "parser.h" |
3 | #include "kolibri.h" |
3 | #include "kolibri.h" |
4 | #include "use_library.h" |
4 | #include "use_library.h" |
5 | 5 | ||
6 | const char header[] = "Graph"; |
6 | const char header[] = "Graph"; |
7 | const char empty_text[] = "No function loaded. Type file name and press Enter. "; |
7 | const char empty_text[] = "No function loaded. Type file name and press Enter. "; |
8 | const char er_file_not_found[] = "Cannot open file. "; |
8 | const char er_file_not_found[] = "Cannot open file. "; |
9 | const char str_filename[]="Filename:"; |
9 | const char str_filename[]="Filename:"; |
10 | const char str_editfile[]="Edit"; |
10 | const char str_editfile[]="Edit"; |
11 | 11 | ||
12 | // íà÷àëüíûå ðàçìåðû |
12 | // íà÷àëüíûå ðàçìåðû |
13 | #define WND_W 400 |
13 | #define WND_W 400 |
14 | #define WND_H 300 |
14 | #define WND_H 300 |
15 | 15 | ||
16 | #define LIGHTGREEN 0xff0000 |
16 | #define LIGHTGREEN 0xff0000 |
17 | #define WHITE 0xffffff |
17 | #define WHITE 0xffffff |
18 | #define BLACK 0x0 |
18 | #define BLACK 0x0 |
19 | #define LIGHTBLUE 0x0000ff |
19 | #define LIGHTBLUE 0x0000ff |
20 | #define LIGHTRED 0xff0000 |
20 | #define LIGHTRED 0xff0000 |
21 | 21 | ||
22 | // font colors |
22 | // font colors |
23 | #define BIGFONTCOLOR BLACK |
23 | #define BIGFONTCOLOR BLACK |
24 | #define SMALLFONTCOLOR BLACK |
24 | #define SMALLFONTCOLOR BLACK |
25 | 25 | ||
26 | #define THREE 3.0 |
26 | #define THREE 3.0 |
27 | // minimum space: 3 pixels |
27 | // minimum space: 3 pixels |
28 | 28 | ||
29 | #define BIG_HEIGHT 4.0 |
29 | #define BIG_HEIGHT 4.0 |
30 | #define SMALL_HEIGHT 2.0 |
30 | #define SMALL_HEIGHT 2.0 |
31 | #define TEXT_X 15.0 |
31 | #define TEXT_X 15.0 |
32 | // numeric format for output |
32 | // numeric format for output |
33 | #define FORMAT "%f" |
33 | #define FORMAT "%f" |
34 | // format for two coords |
34 | // format for two coords |
35 | #define FORMAT_COORD "(%f,%f)" |
35 | #define FORMAT_COORD "(%f,%f)" |
36 | // special value to text if enough space |
36 | // special value to text if enough space |
37 | #define FORMAT_TEST "0.00" |
37 | #define FORMAT_TEST "0.00" |
38 | 38 | ||
39 | #define DELTA_BIG 1.0 |
39 | #define DELTA_BIG 1.0 |
40 | #define DELTA_SMALL 0.1 |
40 | #define DELTA_SMALL 0.1 |
41 | 41 | ||
42 | double *points; |
42 | double *points; |
43 | Dword point_count = 0; |
43 | Dword point_count = 0; |
44 | double x1,y1,x2,y2; |
44 | double x1,y1,x2,y2; |
45 | char *funct = NULL; |
45 | char *funct = NULL; |
46 | 46 | ||
47 | char edit_path[256]; |
47 | char edit_path[256]; |
48 | //Dword editbox_y = WND_H - 16, editbox_w = WND_W - 70; |
48 | //Dword editbox_y = WND_H - 16, editbox_w = WND_W - 70; |
49 | edit_box mybox = {0,9*8-5,WND_H - 16-32,0xffffff,0x6a9480,0,0x808080,0,99,(dword)&edit_path,0}; |
49 | edit_box mybox = {0,9*8-5,WND_H - 16-32,0xffffff,0x6a9480,0,0x808080,0,99,(dword)&edit_path,0}; |
50 | 50 | ||
51 | char *full_head; |
51 | char *full_head; |
52 | 52 | ||
53 | char *HugeBuf = NULL; |
53 | char *HugeBuf = NULL; |
54 | 54 | ||
55 | //char fuck[64] = "$this is a fucking marker$"; |
55 | //char fuck[64] = "$this is a fucking marker$"; |
56 | // ïàðàìåòðû êîìàíäíîé ñòðîêè |
56 | // ïàðàìåòðû êîìàíäíîé ñòðîêè |
57 | char params[1024] = "_FIND_ME_"; |
57 | #ifdef AUTOBUILD |
- | 58 | extern char params[1024]; |
|
- | 59 | char params[1024]; |
|
- | 60 | #else |
|
- | 61 | char params[1024] = "_FIND_ME_"; |
|
58 | 62 | #endif |
|
- | 63 | ||
59 | /* |
64 | /* |
60 | 65 | ||
61 | fucking piece of shit |
66 | fucking piece of shit |
62 | 67 | ||
63 | */ |
68 | */ |
64 | 69 | ||
65 | // constructor of TCoord |
70 | // constructor of TCoord |
66 | TCoord coord(double x, double y) |
71 | TCoord coord(double x, double y) |
67 | { |
72 | { |
68 | TCoord r; |
73 | TCoord r; |
69 | r.x = x; |
74 | r.x = x; |
70 | r.y = y; |
75 | r.y = y; |
71 | return r; |
76 | return r; |
72 | } |
77 | } |
73 | 78 | ||
74 | // move and scale mathematical coords to fit screen coords |
79 | // move and scale mathematical coords to fit screen coords |
75 | TCoord mat2Graf(TCoord c, TCoord scrMin, TCoord scrMax, TCoord mMin, TCoord mMax) |
80 | TCoord mat2Graf(TCoord c, TCoord scrMin, TCoord scrMax, TCoord mMin, TCoord mMax) |
76 | { |
81 | { |
77 | TCoord r; |
82 | TCoord r; |
78 | if (c.x > mMax.x) |
83 | if (c.x > mMax.x) |
79 | c.x = mMax.x; |
84 | c.x = mMax.x; |
80 | if (c.x < mMin.x) |
85 | if (c.x < mMin.x) |
81 | c.x = mMin.x; |
86 | c.x = mMin.x; |
82 | if (c.y > mMax.y) |
87 | if (c.y > mMax.y) |
83 | c.y = mMax.y; |
88 | c.y = mMax.y; |
84 | if (c.y < mMin.y) |
89 | if (c.y < mMin.y) |
85 | c.y = mMin.y; |
90 | c.y = mMin.y; |
86 | r.x = (scrMax.x - scrMin.x) / (mMax.x - mMin.x) * (c.x - mMin.x) + scrMin.x; |
91 | r.x = (scrMax.x - scrMin.x) / (mMax.x - mMin.x) * (c.x - mMin.x) + scrMin.x; |
87 | r.y = (scrMax.y - scrMin.y) / (mMax.y - mMin.y) * (mMax.y - c.y) + scrMin.y; |
92 | r.y = (scrMax.y - scrMin.y) / (mMax.y - mMin.y) * (mMax.y - c.y) + scrMin.y; |
88 | 93 | ||
89 | return r; |
94 | return r; |
90 | } |
95 | } |
91 | 96 | ||
92 | // double-îáåðòêè |
97 | // double-îáåðòêè |
93 | void line_d( double x1, double y1, double x2, double y2) |
98 | void line_d( double x1, double y1, double x2, double y2) |
94 | { |
99 | { |
95 | line(di(x1), di(y1), di(x2), di(y2)); |
100 | line(di(x1), di(y1), di(x2), di(y2)); |
96 | } |
101 | } |
97 | 102 | ||
98 | void outtextxy_d( double x, double y, char * text, int len) |
103 | void outtextxy_d( double x, double y, char * text, int len) |
99 | { |
104 | { |
100 | outtextxy(di(x), di(y), text, len); |
105 | outtextxy(di(x), di(y), text, len); |
101 | } |
106 | } |
102 | 107 | ||
103 | // huge function to draw all the stuff except the function itself |
108 | // huge function to draw all the stuff except the function itself |
104 | void drawAxis( TCoord scrMin, TCoord scrMax, TCoord mMin, TCoord mMax) |
109 | void drawAxis( TCoord scrMin, TCoord scrMax, TCoord mMin, TCoord mMax) |
105 | { |
110 | { |
106 | TCoord cZero={0.0,0.0}, |
111 | TCoord cZero={0.0,0.0}, |
107 | gMin, gMax, gZero, step; |
112 | gMin, gMax, gZero, step; |
108 | TCoord from, to; |
113 | TCoord from, to; |
109 | double i=0.0; |
114 | double i=0.0; |
110 | int j; |
115 | int j; |
111 | double xmin, xmin2, ymin, ymin2; |
116 | double xmin, xmin2, ymin, ymin2; |
112 | char buf[30]=""; |
117 | char buf[30]=""; |
113 | 118 | ||
114 | 119 | ||
115 | // scr means Screen(bounding rect) |
120 | // scr means Screen(bounding rect) |
116 | // m means Mathematical |
121 | // m means Mathematical |
117 | // g means Graphic(real screen position) |
122 | // g means Graphic(real screen position) |
118 | 123 | ||
119 | //rtlDebugOutString("draw axis called\n"); |
124 | //rtlDebugOutString("draw axis called\n"); |
120 | 125 | ||
121 | //format(debuf, 30, "test: %f,%f,%f,%f\n", 123.45, 1.0, -0.9, 12.57); |
126 | //format(debuf, 30, "test: %f,%f,%f,%f\n", 123.45, 1.0, -0.9, 12.57); |
122 | //rtlDebugOutString(debuf); |
127 | //rtlDebugOutString(debuf); |
123 | 128 | ||
124 | gMin = mat2Graf(mMin, scrMin, scrMax, mMin, mMax); |
129 | gMin = mat2Graf(mMin, scrMin, scrMax, mMin, mMax); |
125 | gMax = mat2Graf(mMax, scrMin, scrMax, mMin, mMax); |
130 | gMax = mat2Graf(mMax, scrMin, scrMax, mMin, mMax); |
126 | gZero = mat2Graf(cZero, scrMin, scrMax, mMin, mMax); |
131 | gZero = mat2Graf(cZero, scrMin, scrMax, mMin, mMax); |
127 | 132 | ||
128 | // clear |
133 | // clear |
129 | // setcolor(WHITE); |
134 | // setcolor(WHITE); |
130 | //rectangle(di(gMin.x), di(gMin.y), di(gMax.x), di(gMax.y)); |
135 | //rectangle(di(gMin.x), di(gMin.y), di(gMax.x), di(gMax.y)); |
131 | // ftopku |
136 | // ftopku |
132 | 137 | ||
133 | setcolor(BLACK); |
138 | setcolor(BLACK); |
134 | // osy X |
139 | // osy X |
135 | line_d(gMin.x, gZero.y ,gMax.x, gZero.y); |
140 | line_d(gMin.x, gZero.y ,gMax.x, gZero.y); |
136 | // osy Y |
141 | // osy Y |
137 | line_d(gZero.x, gMin.y, gZero.x, gMax.y); |
142 | line_d(gZero.x, gMin.y, gZero.x, gMax.y); |
138 | // bounding rect |
143 | // bounding rect |
139 | line_d(gMin.x, gMin.y, gMax.x, gMin.y); |
144 | line_d(gMin.x, gMin.y, gMax.x, gMin.y); |
140 | line_d(gMin.x, gMax.y, gMax.x, gMax.y); |
145 | line_d(gMin.x, gMax.y, gMax.x, gMax.y); |
141 | 146 | ||
142 | line_d(gMin.x, gMin.y, gMin.x, gMax.y); |
147 | line_d(gMin.x, gMin.y, gMin.x, gMax.y); |
143 | line_d(gMax.x, gMin.y, gMax.x, gMax.y); |
148 | line_d(gMax.x, gMin.y, gMax.x, gMax.y); |
144 | 149 | ||
145 | // coords of the rect : lower left |
150 | // coords of the rect : lower left |
146 | format(buf, 30, FORMAT_COORD, x1, y1); |
151 | format(buf, 30, FORMAT_COORD, x1, y1); |
147 | //rtlDebugOutString(buf); |
152 | //rtlDebugOutString(buf); |
148 | outtextxy_d(gMin.x, gMin.y + textheight(buf, 20), buf, 20); |
153 | outtextxy_d(gMin.x, gMin.y + textheight(buf, 20), buf, 20); |
149 | // upper left |
154 | // upper left |
150 | format(buf, 30, FORMAT_COORD, x1, y2); |
155 | format(buf, 30, FORMAT_COORD, x1, y2); |
151 | outtextxy_d(gMin.x, gMax.y - textheight(buf, 20), buf, 20); |
156 | outtextxy_d(gMin.x, gMax.y - textheight(buf, 20), buf, 20); |
152 | // lower right |
157 | // lower right |
153 | format(buf, 30, FORMAT_COORD, x2, y1); |
158 | format(buf, 30, FORMAT_COORD, x2, y1); |
154 | outtextxy_d(gMax.x - textwidth(buf, 20), gMin.y + textheight(buf, 20), buf, 20); |
159 | outtextxy_d(gMax.x - textwidth(buf, 20), gMin.y + textheight(buf, 20), buf, 20); |
155 | // upper right |
160 | // upper right |
156 | format(buf, 30, FORMAT_COORD, x2, y2); |
161 | format(buf, 30, FORMAT_COORD, x2, y2); |
157 | outtextxy_d(gMax.x - textwidth(buf, 20), gMax.y - textheight(buf, 20), buf, 20); |
162 | outtextxy_d(gMax.x - textwidth(buf, 20), gMax.y - textheight(buf, 20), buf, 20); |
158 | 163 | ||
159 | //rtlDebugOutString("some lines painted\n"); |
164 | //rtlDebugOutString("some lines painted\n"); |
160 | 165 | ||
161 | 166 | ||
162 | step.x = (mMax.x - mMin.x) / (scrMax.x - scrMin.x); |
167 | step.x = (mMax.x - mMin.x) / (scrMax.x - scrMin.x); |
163 | step.y = (mMax.y - mMin.y) / (scrMax.y - scrMin.y); |
168 | step.y = (mMax.y - mMin.y) / (scrMax.y - scrMin.y); |
164 | 169 | ||
165 | // round values |
170 | // round values |
166 | xmin = id(di((mMin.x / DELTA_BIG) * DELTA_BIG)); |
171 | xmin = id(di((mMin.x / DELTA_BIG) * DELTA_BIG)); |
167 | ymin = id(di((mMin.y / DELTA_BIG) * DELTA_BIG)); |
172 | ymin = id(di((mMin.y / DELTA_BIG) * DELTA_BIG)); |
168 | 173 | ||
169 | // (0,0) |
174 | // (0,0) |
170 | 175 | ||
171 | if ((x1 * x2 <= 0.0) && (y1 * y2 <= 0.0)) |
176 | if ((x1 * x2 <= 0.0) && (y1 * y2 <= 0.0)) |
172 | { |
177 | { |
173 | from.x=0.0; |
178 | from.x=0.0; |
174 | from.y=0.0; |
179 | from.y=0.0; |
175 | from = mat2Graf(from, scrMin, scrMax, mMin, mMax); |
180 | from = mat2Graf(from, scrMin, scrMax, mMin, mMax); |
176 | setcolor(BLACK); |
181 | setcolor(BLACK); |
177 | format(buf, 30, FORMAT, 0.0); |
182 | format(buf, 30, FORMAT, 0.0); |
178 | outtextxy_d(from.x - textwidth(buf, 20), from.y + textheight(buf, 20), buf, 20); |
183 | outtextxy_d(from.x - textwidth(buf, 20), from.y + textheight(buf, 20), buf, 20); |
179 | } |
184 | } |
180 | 185 | ||
181 | 186 | ||
182 | // big marks on X |
187 | // big marks on X |
183 | //settextstyle(0, 0, 1); |
188 | //settextstyle(0, 0, 1); |
184 | if (DELTA_BIG / step.x > THREE) |
189 | if (DELTA_BIG / step.x > THREE) |
185 | { |
190 | { |
186 | for (i = xmin; i <= mMax.x; i += DELTA_BIG) |
191 | for (i = xmin; i <= mMax.x; i += DELTA_BIG) |
187 | { |
192 | { |
188 | if (i != 0.0) |
193 | if (i != 0.0) |
189 | { |
194 | { |
190 | from.x = i; |
195 | from.x = i; |
191 | to.x = from.x; |
196 | to.x = from.x; |
192 | from.y = -BIG_HEIGHT * step.y; |
197 | from.y = -BIG_HEIGHT * step.y; |
193 | to.y = BIG_HEIGHT * step.y; |
198 | to.y = BIG_HEIGHT * step.y; |
194 | from = mat2Graf(from, scrMin, scrMax, mMin, mMax); |
199 | from = mat2Graf(from, scrMin, scrMax, mMin, mMax); |
195 | to = mat2Graf(to, scrMin, scrMax, mMin, mMax); |
200 | to = mat2Graf(to, scrMin, scrMax, mMin, mMax); |
196 | setcolor(BLACK); |
201 | setcolor(BLACK); |
197 | line_d(from.x, from.y, to.x, to.y); |
202 | line_d(from.x, from.y, to.x, to.y); |
198 | // write number |
203 | // write number |
199 | format(buf, 30, FORMAT, i); |
204 | format(buf, 30, FORMAT, i); |
200 | // if it fits in the GAP, then write it |
205 | // if it fits in the GAP, then write it |
201 | if (from.y > scrMin.y && (DELTA_BIG > (textwidth(buf, 20) + 1.0) * step.x)) |
206 | if (from.y > scrMin.y && (DELTA_BIG > (textwidth(buf, 20) + 1.0) * step.x)) |
202 | { |
207 | { |
203 | setcolor(BIGFONTCOLOR); |
208 | setcolor(BIGFONTCOLOR); |
204 | outtextxy_d(from.x - textwidth(buf, 20) / 2.0, to.y - textheight(buf, 20), buf, 20); |
209 | outtextxy_d(from.x - textwidth(buf, 20) / 2.0, to.y - textheight(buf, 20), buf, 20); |
205 | } |
210 | } |
206 | } |
211 | } |
207 | } |
212 | } |
208 | } |
213 | } |
209 | //rtlDebugOutString("big marks x painted\n"); |
214 | //rtlDebugOutString("big marks x painted\n"); |
210 | 215 | ||
211 | // big marks on Y |
216 | // big marks on Y |
212 | if (DELTA_BIG / step.y > THREE) |
217 | if (DELTA_BIG / step.y > THREE) |
213 | { |
218 | { |
214 | for (i = ymin; i <= mMax.y; i += DELTA_BIG) |
219 | for (i = ymin; i <= mMax.y; i += DELTA_BIG) |
215 | { |
220 | { |
216 | if (i != 0.0) |
221 | if (i != 0.0) |
217 | { |
222 | { |
218 | from.y = i; |
223 | from.y = i; |
219 | to.y = from.y; |
224 | to.y = from.y; |
220 | from.x = -BIG_HEIGHT * step.x; |
225 | from.x = -BIG_HEIGHT * step.x; |
221 | to.x = BIG_HEIGHT * step.x; |
226 | to.x = BIG_HEIGHT * step.x; |
222 | from = mat2Graf(from, scrMin, scrMax, mMin, mMax); |
227 | from = mat2Graf(from, scrMin, scrMax, mMin, mMax); |
223 | to = mat2Graf(to, scrMin, scrMax, mMin, mMax); |
228 | to = mat2Graf(to, scrMin, scrMax, mMin, mMax); |
224 | setcolor(BLACK); |
229 | setcolor(BLACK); |
225 | line_d(from.x, from.y, to.x, to.y); |
230 | line_d(from.x, from.y, to.x, to.y); |
226 | format(buf, 30, FORMAT, i); |
231 | format(buf, 30, FORMAT, i); |
227 | if (from.x > scrMin.x && (DELTA_BIG > textheight(buf, 20) * step.y)) |
232 | if (from.x > scrMin.x && (DELTA_BIG > textheight(buf, 20) * step.y)) |
228 | { |
233 | { |
229 | setcolor(BIGFONTCOLOR); |
234 | setcolor(BIGFONTCOLOR); |
230 | outtextxy_d(from.x + TEXT_X, to.y - textheight(buf, 20) / 2.0, buf, 20); |
235 | outtextxy_d(from.x + TEXT_X, to.y - textheight(buf, 20) / 2.0, buf, 20); |
231 | } |
236 | } |
232 | } |
237 | } |
233 | } |
238 | } |
234 | } |
239 | } |
235 | 240 | ||
236 | xmin2 = id(di(mMin.x / DELTA_SMALL)) * DELTA_SMALL; |
241 | xmin2 = id(di(mMin.x / DELTA_SMALL)) * DELTA_SMALL; |
237 | ymin2 = id(di(mMin.y / DELTA_SMALL)) * DELTA_SMALL; |
242 | ymin2 = id(di(mMin.y / DELTA_SMALL)) * DELTA_SMALL; |
238 | 243 | ||
239 | if (DELTA_SMALL / step.x > THREE) |
244 | if (DELTA_SMALL / step.x > THREE) |
240 | { |
245 | { |
241 | j = di((( - xmin + xmin2 ) / DELTA_SMALL)); |
246 | j = di((( - xmin + xmin2 ) / DELTA_SMALL)); |
242 | for (i = xmin2; i <= mMax.x; i += DELTA_SMALL, j++) |
247 | for (i = xmin2; i <= mMax.x; i += DELTA_SMALL, j++) |
243 | { |
248 | { |
244 | if (j % 10 == 0) |
249 | if (j % 10 == 0) |
245 | { |
250 | { |
246 | // we need to skip every tenth mark, to avoid overwriting big marks |
251 | // we need to skip every tenth mark, to avoid overwriting big marks |
247 | j = 0; |
252 | j = 0; |
248 | continue; |
253 | continue; |
249 | } |
254 | } |
250 | from.x = i; |
255 | from.x = i; |
251 | to.x = from.x; |
256 | to.x = from.x; |
252 | from.y = -SMALL_HEIGHT * step.y; |
257 | from.y = -SMALL_HEIGHT * step.y; |
253 | to.y = SMALL_HEIGHT * step.y; |
258 | to.y = SMALL_HEIGHT * step.y; |
254 | from = mat2Graf(from, scrMin, scrMax, mMin, mMax); |
259 | from = mat2Graf(from, scrMin, scrMax, mMin, mMax); |
255 | to = mat2Graf(to, scrMin, scrMax, mMin, mMax); |
260 | to = mat2Graf(to, scrMin, scrMax, mMin, mMax); |
256 | setcolor(BLACK); |
261 | setcolor(BLACK); |
257 | line_d(from.x, from.y, to.x, to.y); |
262 | line_d(from.x, from.y, to.x, to.y); |
258 | format(buf, 30, FORMAT, i); |
263 | format(buf, 30, FORMAT, i); |
259 | 264 | ||
260 | if (from.y > scrMin.y && (DELTA_SMALL > textwidth(buf, 20) * step.x)) |
265 | if (from.y > scrMin.y && (DELTA_SMALL > textwidth(buf, 20) * step.x)) |
261 | { |
266 | { |
262 | setcolor(SMALLFONTCOLOR); |
267 | setcolor(SMALLFONTCOLOR); |
263 | outtextxy_d(from.x - textwidth(buf, 20) / 2.0, to.y - textheight(buf, 20), buf, 20); |
268 | outtextxy_d(from.x - textwidth(buf, 20) / 2.0, to.y - textheight(buf, 20), buf, 20); |
264 | } |
269 | } |
265 | 270 | ||
266 | 271 | ||
267 | } |
272 | } |
268 | 273 | ||
269 | } |
274 | } |
270 | 275 | ||
271 | // finally small marks on Y |
276 | // finally small marks on Y |
272 | if (DELTA_SMALL / step.y > THREE) |
277 | if (DELTA_SMALL / step.y > THREE) |
273 | { |
278 | { |
274 | //rtlDebugOutString("really small marks y painted\n"); |
279 | //rtlDebugOutString("really small marks y painted\n"); |
275 | j = di((( - ymin + ymin2) / DELTA_SMALL)); |
280 | j = di((( - ymin + ymin2) / DELTA_SMALL)); |
276 | for (i = ymin2; i <= mMax.y; i += DELTA_SMALL, j++) |
281 | for (i = ymin2; i <= mMax.y; i += DELTA_SMALL, j++) |
277 | { |
282 | { |
278 | if (j % 10 == 0) |
283 | if (j % 10 == 0) |
279 | { |
284 | { |
280 | // we need to skip every tenth, to avoid overwriting |
285 | // we need to skip every tenth, to avoid overwriting |
281 | j = 0; |
286 | j = 0; |
282 | continue; |
287 | continue; |
283 | } |
288 | } |
284 | from.y = i; |
289 | from.y = i; |
285 | to.y = from.y; |
290 | to.y = from.y; |
286 | from.x = -SMALL_HEIGHT * step.x; |
291 | from.x = -SMALL_HEIGHT * step.x; |
287 | to.x = SMALL_HEIGHT * step.x; |
292 | to.x = SMALL_HEIGHT * step.x; |
288 | from = mat2Graf(from, scrMin, scrMax, mMin, mMax); |
293 | from = mat2Graf(from, scrMin, scrMax, mMin, mMax); |
289 | to = mat2Graf(to, scrMin, scrMax, mMin, mMax); |
294 | to = mat2Graf(to, scrMin, scrMax, mMin, mMax); |
290 | setcolor(BLACK); |
295 | setcolor(BLACK); |
291 | line_d(from.x, from.y, to.x, to.y); |
296 | line_d(from.x, from.y, to.x, to.y); |
292 | format(buf, 30, FORMAT, i); |
297 | format(buf, 30, FORMAT, i); |
293 | if (from.x > scrMin.x && (DELTA_SMALL > textheight(buf, 20) * step.y)) |
298 | if (from.x > scrMin.x && (DELTA_SMALL > textheight(buf, 20) * step.y)) |
294 | { |
299 | { |
295 | setcolor(SMALLFONTCOLOR); |
300 | setcolor(SMALLFONTCOLOR); |
296 | outtextxy_d(from.x + TEXT_X, from.y - textheight(buf, 20) / 2.0, buf, 20); |
301 | outtextxy_d(from.x + TEXT_X, from.y - textheight(buf, 20) / 2.0, buf, 20); |
297 | } |
302 | } |
298 | } |
303 | } |
299 | } |
304 | } |
300 | 305 | ||
301 | } |
306 | } |
302 | 307 | ||
303 | /* |
308 | /* |
304 | ends fucking piece of shit |
309 | ends fucking piece of shit |
305 | */ |
310 | */ |
306 | 311 | ||
307 | void drawFunction( function_t fi, TCoord scrMin, TCoord scrMax, |
312 | void drawFunction( function_t fi, TCoord scrMin, TCoord scrMax, |
308 | TCoord mMin, TCoord mMax, DWORD color) |
313 | TCoord mMin, TCoord mMax, DWORD color) |
309 | { |
314 | { |
310 | double x; |
315 | double x; |
311 | double y; |
316 | double y; |
312 | int firstPoint = 1; |
317 | int firstPoint = 1; |
313 | TCoord p, p0 = {0.0, 0.0}, step; |
318 | TCoord p, p0 = {0.0, 0.0}, step; |
314 | 319 | ||
315 | drawAxis(scrMin, scrMax, mMin, mMax); |
320 | drawAxis(scrMin, scrMax, mMin, mMax); |
316 | 321 | ||
317 | setcolor(color); |
322 | setcolor(color); |
318 | step.x = (mMax.x - mMin.x) / (scrMax.x - scrMin.x); |
323 | step.x = (mMax.x - mMin.x) / (scrMax.x - scrMin.x); |
319 | 324 | ||
320 | for (x = mMin.x; x < mMax.x; x += step.x) |
325 | for (x = mMin.x; x < mMax.x; x += step.x) |
321 | { |
326 | { |
322 | y = fi(x); |
327 | y = fi(x); |
323 | // function is defined here and gets in the range |
328 | // function is defined here and gets in the range |
324 | if (1) // òóò áûëî óñëîâèå, ÷òî ôóíêöèÿ ïðàâèëüíî âû÷èñëåíà |
329 | if (1) // òóò áûëî óñëîâèå, ÷òî ôóíêöèÿ ïðàâèëüíî âû÷èñëåíà |
325 | { |
330 | { |
326 | if ((y > mMin.y) && (y < mMax.y)) |
331 | if ((y > mMin.y) && (y < mMax.y)) |
327 | { |
332 | { |
328 | p = mat2Graf(coord(x, y), scrMin, scrMax, mMin, mMax); |
333 | p = mat2Graf(coord(x, y), scrMin, scrMax, mMin, mMax); |
329 | // if it's our first point, only remember its coords |
334 | // if it's our first point, only remember its coords |
330 | // otherwise, draw a line_d from prev to current |
335 | // otherwise, draw a line_d from prev to current |
331 | if (firstPoint == 0) |
336 | if (firstPoint == 0) |
332 | { |
337 | { |
333 | line_d(p0.x, p0.y, p.x, p.y); |
338 | line_d(p0.x, p0.y, p.x, p.y); |
334 | } |
339 | } |
335 | else |
340 | else |
336 | firstPoint = 0; |
341 | firstPoint = 0; |
337 | 342 | ||
338 | p0 = p; |
343 | p0 = p; |
339 | } |
344 | } |
340 | else // too big/small |
345 | else // too big/small |
341 | { |
346 | { |
342 | firstPoint = 1; |
347 | firstPoint = 1; |
343 | } |
348 | } |
344 | } |
349 | } |
345 | else // no value |
350 | else // no value |
346 | { |
351 | { |
347 | firstPoint = 1; |
352 | firstPoint = 1; |
348 | } |
353 | } |
349 | } |
354 | } |
350 | 355 | ||
351 | } |
356 | } |
352 | 357 | ||
353 | struct kosBDVK |
358 | struct kosBDVK |
354 | { |
359 | { |
355 | Dword attrib; |
360 | Dword attrib; |
356 | Dword name_type; |
361 | Dword name_type; |
357 | Dword create_time; |
362 | Dword create_time; |
358 | Dword create_date; |
363 | Dword create_date; |
359 | Dword access_time; |
364 | Dword access_time; |
360 | Dword access_date; |
365 | Dword access_date; |
361 | Dword modify_time; |
366 | Dword modify_time; |
362 | Dword modify_date; |
367 | Dword modify_date; |
363 | Dword size_low; |
368 | Dword size_low; |
364 | Dword size_high; |
369 | Dword size_high; |
365 | }; |
370 | }; |
366 | 371 | ||
367 | // èòîãîâàÿ âåðñèÿ ÷èòàëêè òåêñòîâûõ ôàéëîâ |
372 | // èòîãîâàÿ âåðñèÿ ÷èòàëêè òåêñòîâûõ ôàéëîâ |
368 | int load_points3() |
373 | int load_points3() |
369 | { |
374 | { |
370 | kosFileInfo fileInfo; |
375 | kosFileInfo fileInfo; |
371 | kosBDVK bdvk; |
376 | kosBDVK bdvk; |
372 | int filePointer = 0; |
377 | int filePointer = 0; |
373 | 378 | ||
374 | Dword count; |
379 | Dword count; |
375 | int i,j,k; |
380 | int i,j,k; |
376 | double d; |
381 | double d; |
377 | Dword filesize, num_number; |
382 | Dword filesize, num_number; |
378 | 383 | ||
379 | double *p2; |
384 | double *p2; |
380 | 385 | ||
381 | if (edit_path[0] == '\0') |
386 | if (edit_path[0] == '\0') |
382 | return 0; |
387 | return 0; |
383 | 388 | ||
384 | // get file size |
389 | // get file size |
385 | strcpy(fileInfo.fileURL,edit_path); |
390 | strcpy(fileInfo.fileURL,edit_path); |
386 | fileInfo.OffsetLow = 0; |
391 | fileInfo.OffsetLow = 0; |
387 | fileInfo.OffsetHigh = 0; |
392 | fileInfo.OffsetHigh = 0; |
388 | fileInfo.dataCount = 0; |
393 | fileInfo.dataCount = 0; |
389 | fileInfo.rwMode = 5; |
394 | fileInfo.rwMode = 5; |
390 | fileInfo.bufferPtr = (Byte *)&bdvk; |
395 | fileInfo.bufferPtr = (Byte *)&bdvk; |
391 | Dword rr = kos_FileSystemAccess( &(fileInfo) ); // â CKosFile íåò îïðåäåëåíèÿ ðàçìåðà |
396 | Dword rr = kos_FileSystemAccess( &(fileInfo) ); // â CKosFile íåò îïðåäåëåíèÿ ðàçìåðà |
392 | sprintf(debuf, "getsize: %U\n", rr); |
397 | sprintf(debuf, "getsize: %U\n", rr); |
393 | rtlDebugOutString(debuf); |
398 | rtlDebugOutString(debuf); |
394 | if (rr != 0) |
399 | if (rr != 0) |
395 | { |
400 | { |
396 | kos_WriteTextToWindow(10,10,0,0x00,(char*)er_file_not_found,strlen(er_file_not_found)); |
401 | kos_WriteTextToWindow(10,10,0,0x00,(char*)er_file_not_found,strlen(er_file_not_found)); |
397 | return 0; |
402 | return 0; |
398 | } |
403 | } |
399 | 404 | ||
400 | filesize = bdvk.size_low; |
405 | filesize = bdvk.size_low; |
401 | num_number = filesize / 2; |
406 | num_number = filesize / 2; |
402 | 407 | ||
403 | HugeBuf = (char *)allocmem(filesize + 1); // ðàçáèðàåì êàê ñòðîêó, îòñþäà òåðìèíàòîð \0 |
408 | HugeBuf = (char *)allocmem(filesize + 1); // ðàçáèðàåì êàê ñòðîêó, îòñþäà òåðìèíàòîð \0 |
404 | 409 | ||
405 | for (i=0;i |
410 | for (i=0;i |
406 | HugeBuf[i] = 0; |
411 | HugeBuf[i] = 0; |
407 | 412 | ||
408 | strcpy(fileInfo.fileURL,edit_path); |
413 | strcpy(fileInfo.fileURL,edit_path); |
409 | fileInfo.OffsetLow = 0; |
414 | fileInfo.OffsetLow = 0; |
410 | 415 | ||
411 | fileInfo.OffsetHigh = 0; |
416 | fileInfo.OffsetHigh = 0; |
412 | fileInfo.dataCount = filesize; |
417 | fileInfo.dataCount = filesize; |
413 | fileInfo.rwMode = 0; |
418 | fileInfo.rwMode = 0; |
414 | fileInfo.bufferPtr = (Byte *)HugeBuf; |
419 | fileInfo.bufferPtr = (Byte *)HugeBuf; |
415 | rr = kos_FileSystemAccess( &(fileInfo) ); // êàêàÿ-òî ïðîáëåìà ñ hands.dll, CKosFile íå ðàáîòàë |
420 | rr = kos_FileSystemAccess( &(fileInfo) ); // êàêàÿ-òî ïðîáëåìà ñ hands.dll, CKosFile íå ðàáîòàë |
416 | 421 | ||
417 | sprintf(debuf, "read3: %U\n", rr); |
422 | sprintf(debuf, "read3: %U\n", rr); |
418 | rtlDebugOutString(debuf); |
423 | rtlDebugOutString(debuf); |
419 | 424 | ||
420 | strcpy(full_head, header); |
425 | strcpy(full_head, header); |
421 | strcpy(full_head+strlen(full_head), " - "); |
426 | strcpy(full_head+strlen(full_head), " - "); |
422 | strcpy(full_head+strlen(full_head), edit_path); // bad code |
427 | strcpy(full_head+strlen(full_head), edit_path); // bad code |
423 | 428 | ||
424 | // à òåïåðü ðàçîáðàòüñÿ â ýòîì |
429 | // à òåïåðü ðàçîáðàòüñÿ â ýòîì |
425 | 430 | ||
426 | i=0; |
431 | i=0; |
427 | k=0; |
432 | k=0; |
428 | while (i < filesize) |
433 | while (i < filesize) |
429 | { |
434 | { |
430 | 435 | ||
431 | while (isalpha(HugeBuf[i]) && i |
436 | while (isalpha(HugeBuf[i]) && i |
432 | if (i == filesize) break; |
437 | if (i == filesize) break; |
433 | if (k==4 && HugeBuf[i] == '=') |
438 | if (k==4 && HugeBuf[i] == '=') |
434 | { |
439 | { |
435 | //sprintf(debuf,"function: %S",HugeBuf + i); |
440 | //sprintf(debuf,"function: %S",HugeBuf + i); |
436 | //rtlDebugOutString(debuf); |
441 | //rtlDebugOutString(debuf); |
437 | // we have a function here |
442 | // we have a function here |
438 | //HugeBuf[0] = ' '; |
443 | //HugeBuf[0] = ' '; |
439 | funct = HugeBuf + i + 1; |
444 | funct = HugeBuf + i + 1; |
440 | strcpy(full_head+strlen(full_head), ". Function y="); |
445 | strcpy(full_head+strlen(full_head), ". Function y="); |
441 | strcpy(full_head+strlen(full_head), funct); |
446 | strcpy(full_head+strlen(full_head), funct); |
442 | return 1; |
447 | return 1; |
443 | } |
448 | } |
444 | 449 | ||
445 | d = convert(HugeBuf+i, &j); |
450 | d = convert(HugeBuf+i, &j); |
446 | if (d == ERROR) |
451 | if (d == ERROR) |
447 | { |
452 | { |
448 | sprintf(debuf, "Error in input file, byte %U, count %U\n", i, k); |
453 | sprintf(debuf, "Error in input file, byte %U, count %U\n", i, k); |
449 | rtlDebugOutString(debuf); |
454 | rtlDebugOutString(debuf); |
450 | kos_WriteTextToWindow(10, 10, 0, 0x00, (char*)debuf, strlen(debuf)); |
455 | kos_WriteTextToWindow(10, 10, 0, 0x00, (char*)debuf, strlen(debuf)); |
451 | return 0; |
456 | return 0; |
452 | } |
457 | } |
453 | if (d == ERROR_END) |
458 | if (d == ERROR_END) |
454 | { |
459 | { |
455 | rtlDebugOutString("EOF :)!\n"); |
460 | rtlDebugOutString("EOF :)!\n"); |
456 | break; |
461 | break; |
457 | } |
462 | } |
458 | 463 | ||
459 | i+=j; |
464 | i+=j; |
460 | switch (k) |
465 | switch (k) |
461 | { |
466 | { |
462 | case 0: |
467 | case 0: |
463 | x1=d; |
468 | x1=d; |
464 | break; |
469 | break; |
465 | case 1: |
470 | case 1: |
466 | x2=d; |
471 | x2=d; |
467 | break; |
472 | break; |
468 | case 2: |
473 | case 2: |
469 | y1=d; |
474 | y1=d; |
470 | break; |
475 | break; |
471 | case 3: |
476 | case 3: |
472 | y2=d; |
477 | y2=d; |
473 | break; |
478 | break; |
474 | default: |
479 | default: |
475 | { |
480 | { |
476 | if (p2 == NULL) |
481 | if (p2 == NULL) |
477 | p2 = (double *)allocmem(num_number * 8); |
482 | p2 = (double *)allocmem(num_number * 8); |
478 | p2[k-4]=d; |
483 | p2[k-4]=d; |
479 | } |
484 | } |
480 | } |
485 | } |
481 | k++; |
486 | k++; |
482 | } |
487 | } |
483 | // format(debuf, 30, "(%f,%f)-(%f,%f)",x1,y1,x2,y2); |
488 | // format(debuf, 30, "(%f,%f)-(%f,%f)",x1,y1,x2,y2); |
484 | // rtlDebugOutString(debuf); |
489 | // rtlDebugOutString(debuf); |
485 | point_count=(k - 4)/2; |
490 | point_count=(k - 4)/2; |
486 | 491 | ||
487 | // |
492 | // |
488 | points = (double *)allocmem(point_count * 2 * 8); |
493 | points = (double *)allocmem(point_count * 2 * 8); |
489 | for (i = 0; i < point_count * 2; i++) |
494 | for (i = 0; i < point_count * 2; i++) |
490 | points[i] = p2[i]; |
495 | points[i] = p2[i]; |
491 | freemem(p2); |
496 | freemem(p2); |
492 | // sprintf(debuf, "count: %U\n", point_count); |
497 | // sprintf(debuf, "count: %U\n", point_count); |
493 | // rtlDebugOutString(debuf); |
498 | // rtlDebugOutString(debuf); |
494 | sprintf(debuf, ". Number of points: %U.", point_count); |
499 | sprintf(debuf, ". Number of points: %U.", point_count); |
495 | strcpy(full_head+strlen(full_head), debuf); |
500 | strcpy(full_head+strlen(full_head), debuf); |
496 | freemem(HugeBuf); |
501 | freemem(HugeBuf); |
497 | HugeBuf = NULL; |
502 | HugeBuf = NULL; |
498 | return 1; |
503 | return 1; |
499 | } |
504 | } |
500 | 505 | ||
501 | void LaunchTinypad() |
506 | void LaunchTinypad() |
502 | { |
507 | { |
503 | kosFileInfo fileInfo; |
508 | kosFileInfo fileInfo; |
504 | 509 | ||
505 | strcpy(fileInfo.fileURL,"/sys/tinypad"); |
510 | strcpy(fileInfo.fileURL,"/sys/tinypad"); |
506 | fileInfo.OffsetLow = 0; |
511 | fileInfo.OffsetLow = 0; |
507 | fileInfo.OffsetHigh = (Dword)edit_path; |
512 | fileInfo.OffsetHigh = (Dword)edit_path; |
508 | fileInfo.rwMode = 7; // launch |
513 | fileInfo.rwMode = 7; // launch |
509 | kos_FileSystemAccess(&fileInfo); |
514 | kos_FileSystemAccess(&fileInfo); |
510 | 515 | ||
511 | } |
516 | } |
512 | 517 | ||
513 | // âû÷èñëèòü çàäàííóþ ôóíêöèþ èëè êóñî÷íî-ëèíåéíóþ ìåæäó òî÷êàìè |
518 | // âû÷èñëèòü çàäàííóþ ôóíêöèþ èëè êóñî÷íî-ëèíåéíóþ ìåæäó òî÷êàìè |
514 | double fu(double x) |
519 | double fu(double x) |
515 | { |
520 | { |
516 | int i; |
521 | int i; |
517 | double res; |
522 | double res; |
518 | 523 | ||
519 | 524 | ||
520 | if (funct) |
525 | if (funct) |
521 | { |
526 | { |
522 | set_exp(funct,x); |
527 | set_exp(funct,x); |
523 | get_exp(&res); // ïàðñèòü äëÿ êàæäîãî çíà÷åíèÿ õ? äà ÿ ñ óìà ñîøåë. |
528 | get_exp(&res); // ïàðñèòü äëÿ êàæäîãî çíà÷åíèÿ õ? äà ÿ ñ óìà ñîøåë. |
524 | return res; |
529 | return res; |
525 | } |
530 | } |
526 | 531 | ||
527 | if (point_count == 0) |
532 | if (point_count == 0) |
528 | { |
533 | { |
529 | return 0.0; |
534 | return 0.0; |
530 | } |
535 | } |
531 | 536 | ||
532 | if (x <= points[0]) |
537 | if (x <= points[0]) |
533 | return points[1]; |
538 | return points[1]; |
534 | if (x >= points[(point_count-1) * 2]) |
539 | if (x >= points[(point_count-1) * 2]) |
535 | return points[(point_count-1) * 2 + 1]; |
540 | return points[(point_count-1) * 2 + 1]; |
536 | 541 | ||
537 | for (i = 0; i < point_count; i++) |
542 | for (i = 0; i < point_count; i++) |
538 | { |
543 | { |
539 | if ((x >= points[2 * i]) && (x < points[2 * (i + 1)])) |
544 | if ((x >= points[2 * i]) && (x < points[2 * (i + 1)])) |
540 | break; |
545 | break; |
541 | } |
546 | } |
542 | 547 | ||
543 | return (x - points[2 * i]) / (points[2 * (i + 1)] - points[2 * i]) |
548 | return (x - points[2 * i]) / (points[2 * (i + 1)] - points[2 * i]) |
544 | * (points[2 * (i + 1) + 1] - points[2 * i + 1]) + points[2 * i + 1]; |
549 | * (points[2 * (i + 1) + 1] - points[2 * i + 1]) + points[2 * i + 1]; |
545 | 550 | ||
546 | } |
551 | } |
547 | 552 | ||
548 | void draw_window(void) |
553 | void draw_window(void) |
549 | { |
554 | { |
550 | char str[80]; |
555 | char str[80]; |
551 | int i; |
556 | int i; |
552 | double xx0=0.0, yy0=0.0, xx,yy; |
557 | double xx0=0.0, yy0=0.0, xx,yy; |
553 | sProcessInfo info; |
558 | sProcessInfo info; |
554 | Dword wi, he; |
559 | Dword wi, he; |
555 | void *p; |
560 | void *p; |
556 | 561 | ||
557 | for (i = 0; i < 1024; i++) |
562 | for (i = 0; i < 1024; i++) |
558 | info.rawData[i] = 0; |
563 | info.rawData[i] = 0; |
559 | kos_ProcessInfo(&info, 0xFFFFFFFF); |
564 | kos_ProcessInfo(&info, 0xFFFFFFFF); |
560 | 565 | ||
561 | p = info.rawData + 42; // magic |
566 | p = info.rawData + 42; // magic |
562 | wi = *(Dword *)(p); |
567 | wi = *(Dword *)(p); |
563 | he = *(Dword *)((Byte *)p + 4); |
568 | he = *(Dword *)((Byte *)p + 4); |
564 | 569 | ||
565 | if (wi == 0) |
570 | if (wi == 0) |
566 | wi = WND_W; |
571 | wi = WND_W; |
567 | if (he == 0) |
572 | if (he == 0) |
568 | he = WND_H; |
573 | he = WND_H; |
569 | 574 | ||
570 | mybox.top = he - 45; |
575 | mybox.top = he - 45; |
571 | mybox.width = wi - mybox.left - 80; |
576 | mybox.width = wi - mybox.left - 80; |
572 | 577 | ||
573 | // start redraw |
578 | // start redraw |
574 | kos_WindowRedrawStatus(1); |
579 | kos_WindowRedrawStatus(1); |
575 | kos_DefineAndDrawWindow(10,40,WND_W,WND_H, |
580 | kos_DefineAndDrawWindow(10,40,WND_W,WND_H, |
576 | 0x33,0xFFFFFF,0,0,(Dword)full_head); |
581 | 0x33,0xFFFFFF,0,0,(Dword)full_head); |
577 | 582 | ||
578 | rtlDebugOutString("entering draw_window\n"); |
583 | rtlDebugOutString("entering draw_window\n"); |
579 | 584 | ||
580 | if (point_count == 0 && funct == NULL) |
585 | if (point_count == 0 && funct == NULL) |
581 | { |
586 | { |
582 | kos_WriteTextToWindow((wi - 6 * strlen(empty_text))/2,he/2,0,0x000000,(char *)empty_text,strlen(empty_text)); |
587 | kos_WriteTextToWindow((wi - 6 * strlen(empty_text))/2,he/2,0,0x000000,(char *)empty_text,strlen(empty_text)); |
583 | } |
588 | } |
584 | else |
589 | else |
585 | { |
590 | { |
586 | drawFunction(&fu, coord(10, 20), coord(id(wi - 20), id(he - 70)), |
591 | drawFunction(&fu, coord(10, 20), coord(id(wi - 20), id(he - 70)), |
587 | coord(x1,y1), coord(x2,y2), 0x00ff0000); |
592 | coord(x1,y1), coord(x2,y2), 0x00ff0000); |
588 | 593 | ||
589 | } |
594 | } |
590 | 595 | ||
591 | kos_WriteTextToWindow(4, mybox.top + 4, 0, 0, (char*)str_filename, strlen(str_filename)); |
596 | kos_WriteTextToWindow(4, mybox.top + 4, 0, 0, (char*)str_filename, strlen(str_filename)); |
592 | 597 | ||
593 | if ((void*)edit_box_draw != NULL) |
598 | if ((void*)edit_box_draw != NULL) |
594 | edit_box_draw((DWORD)&mybox); |
599 | edit_box_draw((DWORD)&mybox); |
595 | 600 | ||
596 | kos_DefineButton(wi - 70, mybox.top, 50, 12, 5, 0xc0c0c0); |
601 | kos_DefineButton(wi - 70, mybox.top, 50, 12, 5, 0xc0c0c0); |
597 | kos_WriteTextToWindow(wi - 58, mybox.top + 4, 0, 0, (char*)str_editfile, strlen(str_editfile)); |
602 | kos_WriteTextToWindow(wi - 58, mybox.top + 4, 0, 0, (char*)str_editfile, strlen(str_editfile)); |
598 | 603 | ||
599 | // end redraw |
604 | // end redraw |
600 | kos_WindowRedrawStatus(2); |
605 | kos_WindowRedrawStatus(2); |
601 | } |
606 | } |
602 | 607 | ||
603 | void kos_Main() |
608 | void kos_Main() |
604 | { |
609 | { |
605 | kos_InitHeap(); |
610 | kos_InitHeap(); |
606 | full_head = (char*)allocmem(300); |
611 | full_head = (char*)allocmem(300); |
607 | strcpy(full_head, "Graph"); |
612 | strcpy(full_head, "Graph"); |
608 | load_edit_box(); |
613 | load_edit_box(); |
609 | if (params[0]) // fuck[0] for debug |
614 | if (params[0]) // fuck[0] for debug |
610 | { |
615 | { |
611 | rtlDebugOutString("launched with params"); |
616 | rtlDebugOutString("launched with params"); |
612 | rtlDebugOutString((char*)params); |
617 | rtlDebugOutString((char*)params); |
613 | strcpy(edit_path, params); |
618 | strcpy(edit_path, params); |
614 | //rtlDebugOutString((char*)edit_path); |
619 | //rtlDebugOutString((char*)edit_path); |
615 | load_points3(); |
620 | load_points3(); |
616 | } |
621 | } |
617 | rtlDebugOutString("data loaded.\n"); |
622 | rtlDebugOutString("data loaded.\n"); |
618 | draw_window(); |
623 | draw_window(); |
619 | for (;;) |
624 | for (;;) |
620 | { |
625 | { |
621 | edit_box_mouse((dword)&mybox); |
626 | edit_box_mouse((dword)&mybox); |
622 | switch (kos_WaitForEvent()) |
627 | switch (kos_WaitForEvent()) |
623 | { |
628 | { |
624 | case 1: |
629 | case 1: |
625 | draw_window(); |
630 | draw_window(); |
626 | break; |
631 | break; |
627 | case 2: |
632 | case 2: |
628 | // key pressed, read it |
633 | // key pressed, read it |
629 | Byte keyCode; |
634 | Byte keyCode; |
630 | kos_GetKey(keyCode); |
635 | kos_GetKey(keyCode); |
631 | 636 | ||
632 | switch (keyCode) |
637 | switch (keyCode) |
633 | { |
638 | { |
634 | case 0x0D: |
639 | case 0x0D: |
635 | if (HugeBuf!=NULL) |
640 | if (HugeBuf!=NULL) |
636 | { |
641 | { |
637 | //sprintf(debuf, "freemem: HugeBuf = %X", HugeBuf); |
642 | //sprintf(debuf, "freemem: HugeBuf = %X", HugeBuf); |
638 | //rtlDebugOutString(debuf); |
643 | //rtlDebugOutString(debuf); |
639 | freemem((void*)HugeBuf); // ÷òî çà áàã - ïîíÿòü íå ìîãó. |
644 | freemem((void*)HugeBuf); // ÷òî çà áàã - ïîíÿòü íå ìîãó. |
640 | HugeBuf = NULL; |
645 | HugeBuf = NULL; |
641 | funct = NULL; |
646 | funct = NULL; |
642 | } |
647 | } |
643 | if (points!=NULL) |
648 | if (points!=NULL) |
644 | { |
649 | { |
645 | //sprintf(debuf, "freemem: points = %X", points); |
650 | //sprintf(debuf, "freemem: points = %X", points); |
646 | //rtlDebugOutString(debuf); |
651 | //rtlDebugOutString(debuf); |
647 | freemem((void*)points); // è òóò. íó íå îáðàùàþñü ÿ ê ýòîìó óêàçàòåëþ, òîëüêî ïàìÿòü â íåãî |
652 | freemem((void*)points); // è òóò. íó íå îáðàùàþñü ÿ ê ýòîìó óêàçàòåëþ, òîëüêî ïàìÿòü â íåãî |
648 | // ïîòîì ñíîâà âûäåëÿþ |
653 | // ïîòîì ñíîâà âûäåëÿþ |
649 | points = NULL; |
654 | points = NULL; |
650 | } |
655 | } |
651 | point_count = 0; |
656 | point_count = 0; |
652 | kos_DrawBar(10,10,200,20,0xFFFFFF); // ôîí äëÿ ñîîáùåíèé îá îøèáêàõ |
657 | kos_DrawBar(10,10,200,20,0xFFFFFF); // ôîí äëÿ ñîîáùåíèé îá îøèáêàõ |
653 | if (load_points3()) |
658 | if (load_points3()) |
654 | draw_window(); |
659 | draw_window(); |
655 | break; |
660 | break; |
656 | default: |
661 | default: |
657 | { |
662 | { |
658 | __asm |
663 | __asm |
659 | { |
664 | { |
660 | mov ah, keyCode |
665 | mov ah, keyCode |
661 | } |
666 | } |
662 | edit_box_key((dword)&mybox); |
667 | edit_box_key((dword)&mybox); |
663 | } |
668 | } |
664 | } |
669 | } |
665 | break; |
670 | break; |
666 | 671 | ||
667 | 672 | ||
668 | case 3: |
673 | case 3: |
669 | // button pressed; we have only one button, close |
674 | // button pressed; we have only one button, close |
670 | Dword button; |
675 | Dword button; |
671 | kos_GetButtonID(button); |
676 | kos_GetButtonID(button); |
672 | if (button == 1) |
677 | if (button == 1) |
673 | kos_ExitApp(); |
678 | kos_ExitApp(); |
674 | else if (button == 5) |
679 | else if (button == 5) |
675 | { |
680 | { |
676 | LaunchTinypad(); |
681 | LaunchTinypad(); |
677 | } |
682 | } |
678 | } |
683 | } |
679 | } |
684 | } |
680 | }>>>=>>> |
685 | }>>>=>>> |
681 | >>>=>=>=>=>=>=>>> |
686 | >>>=>=>=>=>=>=>>> |