extra.c
上传用户:qddsws
上传日期:2022-06-22
资源大小:723k
文件大小:43k
源码类别:

操作系统开发

开发平台:

C/C++

  1. #include <extra/extra.h>
  2. #include "pointer.c"
  3. #include "header.c"
  4. #include <devices/psmouse.h>
  5. #include <devices/rtc.h>
  6. #include <initbuses.h>
  7. #include "dots.c"
  8. #include "zero.c"
  9. #include "one.c"
  10. #include "two.c"
  11. #include "three.c"
  12. #include "four.c"
  13. #include "five.c"
  14. #include "six.c"
  15. #include "seven.c"
  16. #include "eight.c"
  17. #include "nine.c"
  18. #include "memory.c"
  19. #include "dock.c"
  20. #include "write.c"
  21. #include "abouticon.c"
  22. #include "draw.c"
  23. #include "pong.c"
  24. #include "gnu.c"
  25. #include "halt.c"
  26. /* Plans */
  27. static unsigned long* plane_list[MAX_PLANES];
  28. static int last_plane;
  29. static int background_plane;
  30. /* Finestres */
  31. static struct Window root_win;
  32. static struct Window* focus_win;
  33. /* devices */
  34. static struct device* mouse;
  35. static struct device* rtc;
  36. static struct device* keyboard;
  37. void print_shade_plane(int x1, int y1, int x2, int y2, int dir,int plane) {
  38. int color=0x00;
  39. unsigned short* video=(unsigned short*)plane_list[plane];
  40. unsigned short* temp_plane=(unsigned char*)plane_list[plane];
  41.         int col,fil;
  42.         int sizex;
  43.         int sizey;
  44. int act_plane;
  45. int r,g,b;
  46. float factor=0.1;
  47. unsigned short pixel;
  48. (x1>x2)?(sizex=x1-x2):(sizex=x2-x1);
  49. (y1>y2)?(sizey=y1-y2):(sizey=y2-y1);
  50.         for (fil=0;fil<((sizey+y1>SCREEN_HEIGHT)?(SCREEN_HEIGHT-y1):(sizey));fil++)
  51.                 for (col=0;col<sizex*SCREEN_BPP;col=col+SCREEN_BPP) {
  52. act_plane=plane+1;
  53. pixel=ALPHA_COLOR;
  54. while (act_plane<=last_plane&&pixel==ALPHA_COLOR) {
  55. temp_plane=(unsigned short*)plane_list[act_plane];
  56. if (temp_plane!=0){
  57. pixel=(temp_plane[(y1+fil)*SCREEN_WIDTH+x1+col/SCREEN_BPP]);
  58. }
  59. else{
  60. pixel=ALPHA_COLOR;
  61. }
  62. act_plane++;
  63. }
  64. if (dir==LR_SHADE) {
  65. if (fil<(sizey/2)) factor=((float)(1/(float)((sizey/2)))*((sizey/2)-fil));
  66. else factor=((float)(1/(float)((sizey/2)))*(fil-(sizey/2)));
  67. factor=(0.6*factor)+((((float)(1/(float)(sizex*2))*(col))));
  68. factor=factor+0.2;
  69. }
  70. if (dir==TD_SHADE) {
  71. if (col<(sizex)) factor=((float)(1/(float)((sizex)))*((sizex)-col));
  72. else factor=((float)(1/(float)((sizex)))*(col-(sizex)));
  73. factor=(0.6*factor)+((((float)(1/(float)(sizey))*(fil))));
  74. factor=factor+0.2;
  75. }
  76. if (factor>1) factor=1;
  77. r=(pixel>>11)&0x1F;
  78. g=(pixel>>6)&0x1F;
  79. b=pixel&0x1F;
  80. r=r*factor;
  81. g=g*factor;
  82. b=b*factor;
  83. pixel=(r<<11)|(g<<6)|b;
  84. /* Fer transparencia */
  85. color=pixel;
  86. video[(y1+fil)*SCREEN_WIDTH+x1+col/SCREEN_BPP]=pixel;
  87.                 }
  88. }
  89. void init_windows () {
  90. INIT_LIST_HEAD (&(root_win.list));
  91. INIT_LIST_HEAD (&(root_win.events.list));
  92. }
  93. void draw_erase_function (struct Window* win) {
  94. paint_trans_rectangle_plane (win->x,win->y+15,win->x+win->sizex,win->y+win->sizey,win->bkgcolor,win->plane);
  95. paint_rectangle_plane (win->x,win->y+15, win->x+100, win->y+50, 0xFF00,win->plane) ;
  96.         xyprint_plane(win->x+28,win->y+10+15,"ERASE",win->plane);
  97. print_composed_plane_region(win->x,win->y,win->x+win->sizex,win->mousey+win->sizey);
  98. }
  99. void draw_function (struct Window* win) {
  100. paint_rectangle_plane (win->mousex,win->mousey, win->mousex+5, win->mousey+5, 0x0000,win->plane) ;
  101. }
  102. void draw_init_function (struct Window* win) {
  103. struct mouse_event* events;
  104. win->icon=draw_16bpp;
  105. win->iconx=254;
  106. win->icony=545;
  107. /* Event draw function */
  108.         events =(struct mouse_event*)kmalloc(sizeof(struct mouse_event));
  109.         events->x1rel=0;
  110.         events->y1rel=15;
  111.         events->x2rel=win->sizex;
  112.         events->y2rel=win->sizey;
  113.         events->but=2;
  114.         events->function=(void*)&draw_function;
  115.         list_add(&(events->list),&(win->events.list));
  116. /* Event erase function */
  117. paint_rectangle_plane (win->x,win->y+15, win->x+100, win->y+50, 0xFF00,win->plane) ;
  118.         xyprint_plane(win->x+28,win->y+10+15,"ERASE",win->plane);
  119. events =(struct mouse_event*)kmalloc(sizeof(struct mouse_event));
  120.         events->x1rel=0;
  121.         events->y1rel=15;
  122.         events->x2rel=100;
  123.         events->y2rel=50;
  124.         events->but=1;
  125.         events->function=(void*)&draw_erase_function;
  126.         list_add(&(events->list),&(win->events.list));
  127. }
  128. /* PONG */
  129. static int pong_bar_x;
  130. static struct str_buffer* buffer_kbd;
  131. static int ballx, bally,bincx,bincy;
  132. static int points;
  133. void pong_repetitive_function (struct Window* win ) {
  134. //print_composed_plane();
  135. paint_rectangle_plane (win->x+ballx,win->y+bally,win->x+ballx+10,win->y+bally+10,win->bkgcolor,win->plane);
  136. print_composed_plane_region(win->x+ballx,win->y+bally,win->x+ballx+10,win->y+bally+10);
  137. if (ballx>=win->sizex-10) bincx=-2;
  138. if (bally>=win->sizey-10) bincy=-2;
  139. if (ballx<=10) bincx=2;
  140. if (bally<=35) bincy=2;
  141. if (bally>=win->sizey-20-11 && ballx>=pong_bar_x-10&&ballx<=pong_bar_x+30){
  142. bincy=-1;
  143. }
  144. else { 
  145. if (bally>=win->sizey-10) {
  146. bincy=-2;
  147. points--;
  148. char text[20];
  149. paint_rectangle_plane (win->x+20,win->y+25,win->x+100,win->y+35,win->bkgcolor,win->plane);
  150. snprintf (text,"%d",points);
  151. xyprint_plane(win->x+20,win->y+25,text,win->plane);
  152. print_composed_plane_region(win->x+20,win->y+25,win->x+100,win->y+35);
  153. }
  154. }
  155. bally=bally+bincy;
  156. ballx=ballx+bincx;
  157. paint_rectangle_plane (win->x+ballx,win->y+bally,win->x+ballx+10,win->y+bally+10,0x00,win->plane);
  158. print_composed_plane_region(win->x+ballx,win->y+bally,win->x+ballx+10,win->y+bally+10);
  159. if (points==0) delete_self_window(win);
  160. }
  161. void pong_key_function ( struct Window* win ) {
  162. keyboard->command(GET_KBD_BUFFER,buffer_kbd);
  163. paint_rectangle_plane(win->x,win->y+win->sizey-20,win->x+win->sizex,win->y+win->sizey-10,win->bkgcolor,win->plane);
  164. if ( buffer_kbd->buffer[0] == 'a' ) pong_bar_x=pong_bar_x-18;
  165. if ( buffer_kbd->buffer[0] == 's' ) pong_bar_x=pong_bar_x+18;
  166. if (pong_bar_x<0) pong_bar_x=0;
  167. if (pong_bar_x>win->sizex-30) pong_bar_x=win->sizex-30;
  168. paint_rectangle_plane(win->x+pong_bar_x,win->y+win->sizey-20,win->x+pong_bar_x+30,win->y+win->sizey-10,0x0000,win->plane);
  169. print_composed_plane_region(win->x,win->y+win->sizey-20,win->x+win->sizex,win->y+win->sizey-10);
  170. // kprint_plane (buffer_kbd->buffer,focus_win->plane);
  171. }
  172. void pong_init_function (struct Window* win) {
  173. struct mouse_event* events;
  174. char text[20];
  175. points=100;
  176. bincx=-3;
  177. bincy=3;
  178. ballx=40;
  179. bally=40;
  180. win->icon=pong_16bpp;
  181. win->iconx=314;
  182. win->icony=545;
  183. pong_bar_x=(win->sizex/2)-15;
  184. paint_rectangle_plane (win->x,win->y+15,win->x+win->sizex,win->y+win->sizey,win->bkgcolor,win->plane);
  185. buffer_kbd->buffer=(char*)kmalloc(sizeof(char)*100);
  186. win->userwrite=1;
  187. /* Event any key function */
  188. events =(struct mouse_event*)kmalloc(sizeof(struct mouse_event));
  189.         events->x1rel=0;
  190.         events->y1rel=0;
  191.         events->x2rel=0;
  192.         events->y2rel=0;
  193. events->kbd_event=1;
  194.         events->but=0;
  195.         events->function=(void*)&pong_key_function;
  196.         list_add(&(events->list),&(win->events.list));
  197. /* Event repetitive function */
  198. events =(struct mouse_event*)kmalloc(sizeof(struct mouse_event));
  199.         events->x1rel=0;
  200.         events->y1rel=0;
  201.         events->x2rel=0;
  202.         events->y2rel=0;
  203. events->repetitive_event=600;
  204.         events->but=0;
  205.         events->function=(void*)&pong_repetitive_function;
  206.         list_add(&(events->list),&(win->events.list));
  207. paint_rectangle_plane (win->x+20,win->y+25,win->x+100,win->y+35,win->bkgcolor,win->plane);
  208. snprintf (text,"%d",points);
  209. xyprint_plane(win->x+20,win->y+25,text,win->plane);
  210. print_composed_plane_region(win->x+20,win->y+25,win->x+100,win->y+35);
  211. }
  212. /* FI PONG    */
  213. /**************/
  214. #include "small-gnu.c"
  215. #include "gnu-text.c"
  216. void gnu_init_function (struct Window* win) {
  217. char text[200];
  218. win->icon=gnu_16bpp;
  219. win->iconx=494;
  220. win->icony=545;
  221. snprintf (text,"nnnnnnnnn");
  222. kprint_plane(text,win->plane);
  223. snprintf (text,"This program is free software; you can redistribute it n");
  224. kprint_plane(text,win->plane);
  225. snprintf (text,"and/ or modify it under the terms of the GNU General n");
  226. kprint_plane(text,win->plane);
  227. snprintf (text,"Public License as published by  the Free Software n");
  228. kprint_plane(text,win->plane);
  229. snprintf (text,"Foundation; either version 2 of the License, n");
  230. kprint_plane(text,win->plane);
  231. snprintf (text,"or (at your option) any later version. nn");
  232. kprint_plane(text,win->plane);
  233. snprintf (text,"This program is distributed in the hope that it nwill be useful, ");
  234. kprint_plane(text,win->plane);
  235. snprintf (text,"but WITHOUT ANY WARRANTY; nwithout even the implied warranty ");
  236. kprint_plane(text,win->plane);
  237. snprintf (text,"of MERCHANTABILITY nor FITNESS FOR A PARTICULAR PURPOSE.n");
  238. kprint_plane(text,win->plane);
  239. snprintf (text,"See the GNU General Public nLicense for more details. ");
  240. kprint_plane(text,win->plane);
  241. snprintf (text,"nnYou should have received a copy of the GNU Generaln");
  242. kprint_plane(text,win->plane);
  243. snprintf (text,"Public License along with this program;n");
  244. kprint_plane(text,win->plane);
  245. snprintf (text,"if not, write to the Free Software Foundation, Inc.,n");
  246. kprint_plane(text,win->plane);
  247. snprintf (text,"51 Franklin Street, Fifth Floor,n");
  248. kprint_plane(text,win->plane);
  249. snprintf (text,"Boston, MA 02110-1301, USAn");
  250. kprint_plane(text,win->plane);
  251. print_bmp_alpha_plane(win->x+20,win->y+25,small_gnu_16bpp,ALPHA_COLOR,win->plane);
  252. print_bmp_alpha_plane(win->x+100,win->y+25,gnu_text_16bpp,ALPHA_COLOR,win->plane);
  253. }
  254. void notepad_key_function ( struct Window* win ) {
  255. struct str_buffer* buffer_kbd;
  256. buffer_kbd->buffer=(char*)kmalloc(sizeof(char)*100);
  257. keyboard->command(GET_KBD_BUFFER,buffer_kbd);
  258. kprint_plane (buffer_kbd->buffer,focus_win->plane);
  259. }
  260. void notepad_init_function (struct Window* win) {
  261. struct mouse_event* events;
  262. win->userwrite=1;
  263. win->icon=write_16bpp;
  264. win->iconx=194;
  265. win->icony=545;
  266. /* Event any key function */
  267. events =(struct mouse_event*)kmalloc(sizeof(struct mouse_event));
  268.         events->x1rel=0;
  269.         events->y1rel=0;
  270.         events->x2rel=0;
  271.         events->y2rel=0;
  272. events->kbd_event=1;
  273.         events->but=0;
  274.         events->function=(void*)&notepad_key_function;
  275.         list_add(&(events->list),&(win->events.list));
  276. }
  277. void about_init_function (struct Window* win) {
  278. win->icon=abouticon_16bpp;
  279. win->iconx=434;
  280. win->icony=545;
  281. }
  282. void memory_init_function (struct Window* win) {
  283. /* Event any key function */
  284. struct bus_driver* root_bus;
  285. struct bus_driver* p_bus;
  286.         struct list_node_head* p_list;
  287.         struct list_node_head* r_list;
  288. struct device* p_dev;
  289. struct device* a_dev;
  290. char text[200];
  291. win->icon=memory_16bpp;
  292. win->iconx=374;
  293. win->icony=545;
  294. /* List buses */
  295. kprint_plane ("      System Devices nn",win->plane);
  296. kprint_plane ("      -------------- nnn",win->plane);
  297. root_bus=ret_root_bus();
  298. snprintf(text,"Root bus: %sn",root_bus->name);
  299. kprint_plane(text,win->plane);
  300. p_dev=root_bus->dev_root;
  301. snprintf(text,"|     |---vdev: %sn",p_dev->name);
  302. kprint_plane(text,win->plane);
  303. list_for_each(r_list,&(p_dev->dev_list)) {
  304.          a_dev=list_entry(r_list, struct device, dev_list);
  305. if (a_dev!=0){
  306. snprintf(text,"|     |---vdev: %sn",a_dev->name);
  307. kprint_plane(text,win->plane);
  308. }
  309. }
  310.   list_for_each(p_list,&(root_bus->bus_list)) {
  311.          p_bus=list_entry(p_list, struct bus_driver, bus_list);
  312. if (p_bus!=0) {
  313. snprintf(text,"|---bus: %sn",p_bus->name);
  314. kprint_plane(text,win->plane);
  315. p_dev=p_bus->dev_root;
  316. //if (!strcmp(p_bus->name,"ISA0")) {
  317. if (p_dev!=0) {
  318. snprintf(text,"|     |---dev: %sn",p_dev->name);
  319. kprint_plane(text,win->plane);
  320. list_for_each(r_list,&(p_dev->dev_list)) {
  321.                          a_dev=list_entry(r_list, struct device, dev_list);
  322. if (a_dev!=0){
  323. snprintf(text,"|     |---dev: %sn",a_dev->name);
  324. kprint_plane(text,win->plane);
  325. }
  326. }
  327. }
  328. }
  329.         }
  330. kprint_plane("  n",win->plane);
  331. kprint_plane("  n",win->plane);
  332. kprint_plane("  n",win->plane);
  333. extern int avmem;
  334. kprint_plane ("    Memory Info n  n",win->plane);
  335. kprint_plane ("      -------------- n  n  n",win->plane);
  336. snprintf (text,"Installed Ram: %d Mbn",avmem);
  337. kprint_plane (text,win->plane);
  338. }
  339. void move_self_window( struct Window* win) {
  340. set_self_focus( win) ;
  341. if (win->selfcopy==0) {
  342. win->selfcopy=(unsigned short*)kmalloc((win->sizex*win->sizey*SCREEN_BPP)+2);
  343. }
  344. copy_region_plane(win->selfcopy,win->x,win->y,win->x+win->sizex,win->y+win->sizey,win->plane);
  345. win->drag=1;
  346. }
  347.         
  348. void copy_region_plane( unsigned short* area, int x1, int y1, int x2, int y2, int plane) {
  349.         unsigned char* video=(unsigned char*)plane_list[plane];
  350.         int col,fil;
  351.         unsigned short pixel;
  352.         int sizex;
  353.         int sizey;
  354.         (x1>x2)?(sizex=x1-x2):(sizex=x2-x1);
  355.         (y1>y2)?(sizey=y1-y2):(sizey=y2-y1);
  356.         for (fil=0;fil<((sizey+y1>SCREEN_HEIGHT)?(SCREEN_HEIGHT-y1):(sizey));fil++)
  357.                 for (col=0;col<sizex*SCREEN_BPP;col=col+SCREEN_BPP) {
  358. pixel=video[((y1+fil)*SCREEN_WIDTH*SCREEN_BPP)+col+(x1*SCREEN_BPP)]&0xFF;
  359. pixel=pixel|((video[((y1+fil)*SCREEN_WIDTH*SCREEN_BPP)+col+1+(x1*SCREEN_BPP)]<<8)&0xFF00);
  360. area[(sizey-fil-1)*sizex+(col/SCREEN_BPP)+2]=pixel;
  361. }
  362. area[0]=sizex;
  363. area[1]=sizey;
  364. }
  365. void set_self_focus( struct Window* win) {
  366. int act_plane=win->plane;
  367. struct Window* max_win=0;
  368. struct Window* temp_win;
  369.     struct list_node_head *p;
  370.    
  371. if (win!=0) {
  372. /* Buscar quina finestra te el pla == 1 */
  373. list_for_each (p,&(root_win.list)) {
  374. temp_win = (struct Window*)list_entry (p, struct Window, list);
  375. //if (temp_win!=0&&temp_win->plane>0&&temp_win->plane<max_win) {
  376. if (temp_win!=0&&temp_win->plane==1) {
  377. max_win=temp_win;
  378. act_plane=temp_win->plane;
  379. }
  380. }
  381. /*Switch planes*/
  382. /* char text[200];
  383. paint_rectangle_plane(0,500,800,550,0xFFFF,1);
  384. snprintf (text,"Win %d, Max %d, lastplane: %d, backplane: %d",win->plane,max_win->plane,last_plane,background_plane);
  385. xyprint_plane(0,500,text,1);
  386. print_composed_plane_region(0,500,800,600);*/
  387. if (win!=focus_win&&max_win!=0&&max_win->plane<last_plane) {
  388. act_plane=max_win->plane;
  389. unsigned long plane_add;
  390. plane_add=(unsigned long)plane_list[act_plane];
  391. plane_list[act_plane]=plane_list[win->plane];
  392. plane_list[win->plane]=(unsigned long*)plane_add;
  393. max_win->plane=win->plane;
  394. win->plane=act_plane;
  395. print_composed_plane_region(max_win->x,max_win->y,max_win->x+max_win->sizex,max_win->y+max_win->sizey);
  396. }
  397. focus_win=win;
  398. print_composed_plane_region(win->x,win->y,win->x+win->sizex,win->y+win->sizey);
  399. if (focus_win->text_win==1&&focus_win->userwrite==1) {
  400. keyboard->command(POLL_KBD_DEVICE,(void*)0);
  401. keyboard->command(DEL_KBD_BUFFER,(void*)0);
  402. }                       
  403. }
  404. }
  405. void delete_self_window( struct Window* win) {
  406. set_background_plane(ALPHA_COLOR,win->plane);
  407. win->created=0;
  408. if (win->icon!=0) print_bmp_alpha_plane(win->iconx,win->icony,win->icon,ALPHA_COLOR,background_plane-1);
  409. delete_plane (win->plane);
  410. struct Window* temp_win;
  411.     struct list_node_head *p;
  412. list_for_each (p,&(root_win.list)) {
  413. temp_win = (struct Window*)list_entry (p, struct Window, list);
  414. if (temp_win!=0&&temp_win->created==1&&temp_win->plane==1) break;
  415. }
  416. if (temp_win->plane==1) focus_win=temp_win;
  417. else focus_win=0;
  418. // focus_win=0;
  419. /* Delete the window from the list */
  420. list_del(&win->list);
  421. print_composed_plane();
  422. }
  423. void create_window (char* id, int x, int y, int sizex, int sizey, int bkgcolor, int plane, void (*start_function) (struct Window* win) ) {
  424. //char text[200];
  425. struct Window* newwin;
  426. struct mouse_event* events;
  427. struct Window* temp_win;
  428.     struct list_node_head *p;
  429. int new=0;
  430. /* Check if the window exists */
  431. list_for_each (p,&(root_win.list)) {
  432. temp_win = (struct Window*)list_entry (p, struct Window, list);
  433. if (temp_win!=0&&temp_win->id!=0&&!(strncmp(temp_win->id,id,7))){
  434. /* Window already exists */
  435. /* set_background_plane(ALPHA_COLOR,0);
  436. snprintf (text,"CACA: %s == %s",temp_win->id,id);
  437. xyprint_plane(0,10,text,0);
  438. print_composed_plane();*/
  439. new=1;
  440. break ;
  441. }
  442. else temp_win=0;
  443. //if (temp_win!=0&&temp_win->id!=0);// break ;
  444. //snprintf (text,"CACA: %c == %s",(temp_win!=0)?(temp_win->id[0]):("NO"),id);
  445. }
  446. /* Window is not in the list, we can create it */
  447. if (new==0) {
  448. insert_plane(plane);
  449. newwin =(struct Window*)kmalloc(sizeof(struct Window));
  450. newwin->id=(char*)kmalloc(sizeof(char)*strlen(id)+1);
  451. strcpy (newwin->id,id);
  452. newwin->created=1;
  453. newwin->x=x;
  454. newwin->y=y;
  455. newwin->drag=0;
  456. newwin->sizex=sizex;
  457. newwin->sizey=sizey;
  458. newwin->plane=plane;
  459. newwin->cursorx=20;
  460. newwin->initialx=20;
  461. newwin->finalx=sizex-20;
  462. newwin->cursory=20;
  463. newwin->selfcopy=0;
  464. newwin->bkgcolor=bkgcolor;
  465. paint_trans_rectangle_plane (x,y,x+sizex,y+sizey,bkgcolor,plane);
  466. paint_rectangle_plane (x,y,x+sizex,y+15, 0x020F,plane);
  467. paint_rectangle_plane (x+sizex-15,y,x+sizex,y+15, 0xFC00,plane);
  468. xyprint_plane(x+(sizex/2)-(strlen(id)*FONT_W)/2,y+5,newwin->id,plane);
  469. list_add(&(newwin->list),&(root_win.list));
  470. INIT_LIST_HEAD(&(newwin->events.list));
  471. /* Event Close Window*/
  472. events =(struct mouse_event*)kmalloc(sizeof(struct mouse_event));
  473. events->x1rel=newwin->sizex-15;
  474. events->y1rel=0;
  475. events->x2rel=newwin->sizex;
  476. events->y2rel=15;
  477. events->kbd_event=0;
  478. events->but=2;
  479. events->function=(void*)&delete_self_window;
  480. list_add(&(events->list),&(newwin->events.list));
  481. /* Event SetFocus Window*/
  482. events =(struct mouse_event*)kmalloc(sizeof(struct mouse_event));
  483. events->x1rel=0;
  484. events->y1rel=0;
  485. events->x2rel=newwin->sizex;
  486. events->y2rel=15;
  487. events->but=2;
  488. events->kbd_event=0;
  489. events->function=(void*)&set_self_focus;
  490. list_add(&(events->list),&(newwin->events.list));
  491. /* Event Move Window*/
  492. events =(struct mouse_event*)kmalloc(sizeof(struct mouse_event));
  493. events->x1rel=0;
  494. events->y1rel=0;
  495. events->x2rel=newwin->sizex;
  496. events->y2rel=15;
  497. events->but=1;
  498. events->kbd_event=0;
  499. events->function=(void*)&move_self_window;
  500. list_add(&(events->list),&(newwin->events.list));
  501. newwin->text_win=1;
  502. newwin->userwrite=0;
  503. //set_self_focus( newwin) ;
  504. focus_win=newwin;
  505. if (start_function!=0) {
  506. start_function(newwin);
  507. }
  508. //set_self_focus (newwin);
  509. print_composed_plane ();
  510. }
  511. }
  512. static int counter_event;
  513. void mouse_event (int x, int y, int but) {
  514. intoff();
  515. struct list_node_head *p;
  516. struct Window* win;
  517. struct mouse_event* event;
  518. //char text[200];
  519. counter_event++;
  520.          /* Keyboard event */      
  521. if (x==-1&&y==-1) {
  522. win=focus_win;
  523. list_for_each (p,&(win->events.list)) {
  524. event = (struct mouse_event*)list_entry (p, struct mouse_event, list);
  525. if ( event->kbd_event==1 ) {  
  526. event->function(win);
  527. }
  528. }
  529. }
  530. /* Repetitive event */
  531. if (focus_win!=0&&but==0&&focus_win->drag==0) {
  532. win=focus_win;
  533. list_for_each (p,&(win->events.list)) {
  534. event = (struct mouse_event*)list_entry (p, struct mouse_event, list);
  535. if ( event->repetitive_event!=0 && counter_event%event->repetitive_event==0 ) {  
  536. event->function(win);
  537. }
  538. }
  539. }
  540. if (x!=-1&& y!=-1 && but!= 0) {
  541. int plane_id=plane_from_pixel(x,y);
  542. if (focus_win==0||(focus_win!=0&&focus_win->drag==0)) {
  543. list_for_each (p,&(root_win.list)) {
  544.                 win = (struct Window*)list_entry (p, struct Window, list);
  545. if (win->plane==plane_id) break;
  546.          }
  547. if (win->plane==plane_id) {
  548. list_for_each (p,&(win->events.list)) {
  549.                 event = (struct mouse_event*)list_entry (p, struct mouse_event, list);
  550. if ( (but == event->but)&& (x > (event->x1rel+win->x)) && (x < (event->x2rel+win->x)) &&  
  551. (y > (event->y1rel+win->y)) && (y < (event->y2rel+win->y)) ) {
  552. win->mousex=x;
  553. win->mousey=y;
  554. event->function(win);
  555. }
  556. }
  557. }
  558. }
  559. if (but==2&&focus_win!=0&&focus_win->drag==1) {
  560. set_background_plane(ALPHA_COLOR,MOUSE_PLANE);
  561. set_background_plane(ALPHA_COLOR,focus_win->plane);
  562. focus_win->x=x;
  563. focus_win->y=y;
  564. focus_win->drag=0;
  565. print_bmp_alpha_plane(x,y,focus_win->selfcopy,ALPHA_COLOR,focus_win->plane);
  566. print_composed_plane();
  567. }
  568. if (x>194&&x<194+48&&y>545&&y<593) {
  569. circle_fill_plane_alpha(194+24,545+24,21,0xfeca,background_plane-1,0.6);
  570. print_composed_plane_region(175,540,625,600);
  571. create_window("notepad",500,100,300,300,0x0ff0,1,(void*)&notepad_init_function);
  572. }
  573. if (x>374&&x<374+48&&y>545&&y<593) {
  574. circle_fill_plane_alpha(374+24,545+24,21,0xfeca,background_plane-1,0.6);
  575. print_composed_plane_region(175,540,625,600);
  576. create_window("system info",100,100,300,300,0xFC00,1,(void*)&memory_init_function);
  577. }
  578. if (x>434&&x<434+48&&y>545&&y<593) {
  579. circle_fill_plane_alpha(434+24,545+24,21,0xfeca,background_plane-1,0.6);
  580. print_composed_plane_region(175,540,625,600);
  581. create_window("about",300,200,200,350,0xcc0f,1,(void*)&about_init_function);
  582. print_composed_plane();
  583. }
  584. if (x>254&&x<254+48&&y>545&&y<593) {
  585. circle_fill_plane_alpha(254+24,545+24,21,0xfeca,background_plane-1,0.6);
  586. print_composed_plane_region(175,540,625,600);
  587. create_window("draw",150,50,400,200,0x1c1f,1,(void*)&draw_init_function);
  588. }
  589. if (x>314&&x<314+48&&y>545&&y<593) {
  590. circle_fill_plane_alpha(314+24,545+24,21,0xfeca,background_plane-1,0.6);
  591. print_composed_plane_region(175,540,625,600);
  592. create_window("pong",500,100,200,400,0xac1a,1,(void*)&pong_init_function);
  593. }
  594. if (x>494&&x<494+48&&y>545&&y<593) {
  595. circle_fill_plane_alpha(494+24,545+24,21,0xfeca,background_plane-1,0.6);
  596. print_composed_plane_region(175,540,625,600);
  597. create_window("gnu",200,300,500,250,0x7f77,1,(void*)&gnu_init_function);
  598. }
  599. if (x>554&&x<554+48&&y>545&&y<593) {
  600. halt_computer();
  601. }
  602. }
  603. }
  604. #include "bye.c"
  605. void fade_plane(float factor, int plane_id) {
  606. int col,fil;
  607. unsigned short* video;
  608. if (plane_id==-1) video=(unsigned short*)0xD0800000;
  609. else video=(unsigned short*)plane_list[plane_id];
  610. unsigned short pixel;
  611. int r,g,b;
  612. for (fil=0;fil<SCREEN_HEIGHT;fil++)
  613. for (col=0;col<SCREEN_WIDTH;col=col+1) {
  614. pixel=video[fil*SCREEN_WIDTH+col+0];
  615. r=(pixel>>11)&0x1F;
  616. g=(pixel>>6)&0x1F;
  617. b=pixel&0x1F;
  618. r=r*factor;
  619. g=g*factor;
  620. b=b*factor;
  621. pixel=(r<<11)|(g<<6)|b;
  622. video[fil*SCREEN_WIDTH+col+0]=pixel;
  623. }
  624. }
  625. void halt_computer() {
  626. intoff();
  627. set_background_plane(0x0000,0);
  628. print_bmp_plane(250,200,bye_16bpp,ALPHA_COLOR,0);
  629. print_composed_plane();
  630. while (1>0){ 
  631. fade_plane(0.9998,0);
  632. print_composed_plane_region(250,200,550,400);
  633. }
  634. }
  635. /* Returns which plane the pixel belogns */
  636. int plane_from_pixel (int x, int y) {
  637. unsigned long pixel;
  638. unsigned short* plane;
  639. int act_plane=1; 
  640. plane=(unsigned short*)plane_list[act_plane];
  641. pixel=(plane[y*SCREEN_WIDTH+x]);
  642. act_plane++;
  643. while (act_plane<=last_plane&&pixel==ALPHA_COLOR) {
  644. plane=(unsigned short*)plane_list[act_plane];
  645. if (plane!=0){
  646. pixel=(plane[y*SCREEN_WIDTH+x]);
  647. }
  648. act_plane++;
  649. }
  650. if (pixel != ALPHA_COLOR) return act_plane-1;
  651. if (pixel == ALPHA_COLOR) return -1;
  652. return 0;
  653. }
  654. void init_planes () {
  655. int i=0;
  656. for (i=0;i<MAX_PLANES;i++) {
  657. plane_list[i]=0;
  658. }
  659. last_plane=0;
  660. create_plane(0);
  661. create_plane(1);
  662. create_plane(2);
  663. background_plane=2;
  664. }
  665. void delete_plane (int id) {
  666. unsigned long* plane_list_temp[MAX_PLANES];
  667.         int i,j;
  668.         struct list_node_head *p;
  669.         struct Window* win;
  670.         /* Separar tots els plans a partir de id */
  671.         
  672. if (id<last_plane) {
  673.         // kfree(plane_list[id]);
  674.                 j=0;
  675.                 for (i=id+1;i<=last_plane;i++) {
  676.                         plane_list_temp[j]=plane_list[i];
  677.                         j++;
  678.                 }
  679.                 j=0;
  680.                 for (i=id;i<last_plane;i++) {
  681.                         plane_list[i]=plane_list_temp[j];
  682.                         j++;
  683.                 }
  684. list_for_each (p,&(root_win.list)) {
  685.              win = (struct Window*)list_entry (p, struct Window, list);
  686. if (win!=0&&win->plane>=id) {
  687. win->plane=win->plane-1;
  688. }
  689.          }
  690. /* Incrementar last_plane, background_plane, ... */
  691. last_plane--;
  692. background_plane--;
  693. }
  694. }
  695. void insert_plane ( int id ) {
  696. unsigned long* plane_list_temp[MAX_PLANES];
  697. int i,j;
  698. struct list_node_head *p;
  699. struct Window* win;
  700. /* Separar tots els plans a partir de id */
  701. if (id<last_plane) {
  702. j=0;
  703. for (i=id;i<=last_plane;i++) {
  704. plane_list_temp[j]=plane_list[i];
  705. j++;
  706. }
  707. j=0;
  708. for (i=id+1;i<=last_plane+1;i++) {
  709. plane_list[i]=plane_list_temp[j];
  710. j++;
  711. }
  712. plane_list[id]=0;
  713. /* Inicialitzar el pla */
  714. create_plane(id);
  715. /* Canviar tots els plane de les finestres */
  716. list_for_each (p,&(root_win.list)) {
  717.              win = (struct Window*)list_entry (p, struct Window, list);
  718. if (win->plane>=id) {
  719. win->plane=win->plane+1;
  720. }
  721.          }
  722. /* Incrementar last_plane, background_plane, ... */
  723. last_plane++;
  724. background_plane++;
  725. }
  726. //print_composed_plane ();
  727. }
  728. void create_plane ( int id ) {
  729. int x,y;
  730. unsigned short* plane;
  731. plane=(unsigned short*)kmalloc(sizeof (unsigned char)*SCREEN_WIDTH*SCREEN_HEIGHT*SCREEN_BPP);
  732. if (id<MAX_PLANES) {
  733. plane_list[id]=(unsigned long*)plane;
  734. if (id>last_plane) last_plane=id;
  735. for (y=0;y<SCREEN_HEIGHT;y++)
  736. for (x=0;x<SCREEN_WIDTH;x++) 
  737. plane[y*SCREEN_WIDTH+x]=ALPHA_COLOR;
  738. }
  739. }
  740. void print_composed_plane_region (int x1, int y1, int x2, int y2) {
  741. unsigned char* video=(unsigned char*)0xD0800000;
  742.         int col,fil;
  743. unsigned long pixel;
  744. unsigned short* plane;
  745. int act_plane=0; 
  746. int sizex;
  747.         int sizey;
  748. (x1>x2)?(sizex=x1-x2):(sizex=x2-x1);
  749. (y1>y2)?(sizey=y1-y2):(sizey=y2-y1);
  750. plane=(unsigned short*)plane_list[act_plane];
  751. for (fil=0;fil<((sizey+y1>SCREEN_HEIGHT)?(SCREEN_HEIGHT-y1):(sizey));fil++) {
  752. for (col=0;col<sizex*SCREEN_BPP;col=col+SCREEN_BPP) {
  753. pixel=(plane[(y1+fil)*SCREEN_WIDTH+x1+col/SCREEN_BPP]);
  754. act_plane++;
  755. while (act_plane<=last_plane&&pixel==ALPHA_COLOR) {
  756. plane=(unsigned short*)plane_list[act_plane];
  757. if (plane!=0){
  758. pixel=(plane[(y1+fil)*SCREEN_WIDTH+x1+col/SCREEN_BPP]);
  759. }
  760. else{
  761. pixel=ALPHA_COLOR;
  762. }
  763. act_plane++;
  764. }
  765. act_plane=0;
  766. plane=(unsigned short*)plane_list[act_plane];
  767. if (pixel!=ALPHA_COLOR) {
  768. video[((y1+fil)*SCREEN_WIDTH*SCREEN_BPP)+col+x1*2]=pixel&0xFF;
  769. video[((y1+fil)*SCREEN_WIDTH*SCREEN_BPP)+col+1+x1*2]=(pixel>>8)&0xFF;
  770. }
  771. }
  772. }
  773. }
  774. void print_composed_plane () {
  775. unsigned char* video=(unsigned char*)0xD0800000;
  776.         int col,fil;
  777. unsigned long pixel;
  778. unsigned short* plane;
  779. int act_plane=0;
  780. plane=(unsigned short*)plane_list[act_plane];
  781. for (fil=0;fil<SCREEN_HEIGHT;fil++) {
  782. for (col=0;col<SCREEN_WIDTH*SCREEN_BPP;col=col+SCREEN_BPP) {
  783. pixel=(plane[(fil*SCREEN_WIDTH)+col/SCREEN_BPP]);
  784. act_plane++;
  785. while (act_plane<=last_plane&&pixel==ALPHA_COLOR) {
  786. plane=(unsigned short*)plane_list[act_plane];
  787. if (plane!=0){
  788. pixel=(plane[(fil*SCREEN_WIDTH)+col/SCREEN_BPP]);
  789. }
  790. else{
  791. pixel=ALPHA_COLOR;
  792. }
  793. act_plane++;
  794. }
  795. act_plane=0;
  796. plane=(unsigned short*)plane_list[act_plane];
  797. if (pixel!=ALPHA_COLOR) {
  798. video[((fil)*SCREEN_WIDTH*SCREEN_BPP)+col]=pixel&0xFF;
  799. video[((fil)*SCREEN_WIDTH*SCREEN_BPP)+col+1]=(pixel>>8)&0xFF;
  800. }
  801. }
  802. }
  803. }
  804. void print_mouse_plane (int x, int y,int plane) {
  805. print_bmp_alpha_plane (x,y,pointer_16bpp,0xffdf,plane);
  806. }
  807. void print_bmp_alpha_plane (int x, int y, unsigned short* data,unsigned short alpha,int plane) {
  808. unsigned char* video=(unsigned char*)plane_list[plane];
  809.         int col,fil;
  810. unsigned long pixel;
  811. int sizex=data[0];
  812. int sizey=data[1];
  813. //if (y+sizey>SCREEN_HEIGHT) sizey=(y+sizey)-SCREEN_HEIGHT;
  814. for (fil=0;fil<((sizey+y>SCREEN_HEIGHT)?(SCREEN_HEIGHT-y):(sizey));fil++)
  815.          for (col=0;col<sizex*SCREEN_BPP;col=col+SCREEN_BPP) {
  816.                         pixel=(data[((sizey-fil-1)*sizex)+(col/SCREEN_BPP)+2]);
  817. if (pixel != alpha) {
  818.                         video[((y+fil)*SCREEN_WIDTH*SCREEN_BPP)+col+1+(x*SCREEN_BPP)]=(pixel&0xFF00)>>8;
  819.                         video[((y+fil)*SCREEN_WIDTH*SCREEN_BPP)+col+0+(x*SCREEN_BPP)]=pixel&0x00FF;
  820. }
  821.                         
  822.                 }
  823. }
  824. void print_bmp_plane (int x, int y, unsigned short* data,unsigned short alpha,int plane) {
  825. unsigned char* video=(unsigned char*)plane_list[plane];
  826.         int col,fil;
  827. unsigned long pixel;
  828. int sizex=data[0];
  829. int sizey=data[1];
  830. //if (y+sizey>SCREEN_HEIGHT) sizey=(y+sizey)-SCREEN_HEIGHT;
  831. for (fil=0;fil<((sizey+y>SCREEN_HEIGHT)?(SCREEN_HEIGHT-y):(sizey));fil++)
  832.          for (col=0;col<sizex*SCREEN_BPP;col=col+SCREEN_BPP) {
  833.                         pixel=(data[((sizey-fil-1)*sizex)+(col/SCREEN_BPP)+2]);
  834. if (pixel != alpha) {
  835.                         video[((y+fil)*SCREEN_WIDTH*SCREEN_BPP)+col+1+(x*SCREEN_BPP)]=(pixel&0xFF00)>>8;
  836.                         video[((y+fil)*SCREEN_WIDTH*SCREEN_BPP)+col+0+(x*SCREEN_BPP)]=pixel&0x00FF;
  837. }
  838. else {
  839.                         video[((y+fil)*SCREEN_WIDTH*SCREEN_BPP)+col+1+(x*SCREEN_BPP)]=0xFF;
  840.                         video[((y+fil)*SCREEN_WIDTH*SCREEN_BPP)+col+0+(x*SCREEN_BPP)]=0xFF;
  841. }
  842.                         
  843.                 }
  844. }
  845. void set_background_plane (unsigned short color, int plane_id) {
  846.         int col,fil;
  847. unsigned char* video=(unsigned char*)plane_list[plane_id];
  848. for (fil=0;fil<SCREEN_HEIGHT;fil++)
  849. for (col=0;col<SCREEN_WIDTH*2;col=col+2) {
  850. //video[fil*SCREEN_WIDTH+col]=(unsigned long) (color | color<<16);
  851. video[fil*SCREEN_WIDTH*2+col+1]=(unsigned long) ( color>>8)&0xFF;
  852. video[fil*SCREEN_WIDTH*2+col]=(unsigned long) (color)&0xFF;
  853. }
  854.           
  855. }
  856. void paint_trans_rectangle_plane (int x1, int y1, int x2, int y2, unsigned short color,int plane) {
  857. unsigned char* video=(unsigned char*)plane_list[plane];
  858.         int col,fil;
  859.         int sizex;
  860.         int sizey;
  861. unsigned short set_color=color;
  862. (x1>x2)?(sizex=x1-x2):(sizex=x2-x1);
  863. (y1>y2)?(sizey=y1-y2):(sizey=y2-y1);
  864.         for (fil=0;fil<((sizey+y1>SCREEN_HEIGHT)?(SCREEN_HEIGHT-y1):(sizey));fil++)
  865.                 for (col=0;col<sizex*SCREEN_BPP;col=col+SCREEN_BPP) {
  866. if ((fil+col)%5==0) color=ALPHA_COLOR;
  867. else color=set_color;
  868.                 video[((y1+fil)*SCREEN_WIDTH*SCREEN_BPP)+col+1+(x1*SCREEN_BPP)]=(color&0xFF00)>>8;
  869.                 video[((y1+fil)*SCREEN_WIDTH*SCREEN_BPP)+col+0+(x1*SCREEN_BPP)]=color&0x00FF;
  870.                 }
  871. /*paint_rectangle_plane (x1,y1,x2,y1+15, 0x020F,plane);
  872. paint_rectangle_plane (x2-15,y1,x2,y1+15, 0xFC00,plane);*/
  873. }
  874. void paint_rectangle_plane (int x1, int y1, int x2, int y2, unsigned short color,int plane) {
  875. unsigned char* video=(unsigned char*)plane_list[plane];
  876.         int col,fil;
  877.         int sizex;
  878.         int sizey;
  879. (x1>x2)?(sizex=x1-x2):(sizex=x2-x1);
  880. (y1>y2)?(sizey=y1-y2):(sizey=y2-y1);
  881.         for (fil=0;fil<((sizey+y1>SCREEN_HEIGHT)?(SCREEN_HEIGHT-y1):(sizey));fil++)
  882.                 for (col=0;col<sizex*SCREEN_BPP;col=col+SCREEN_BPP) {
  883.                         video[((y1+fil)*SCREEN_WIDTH*SCREEN_BPP)+col+1+(x1*SCREEN_BPP)]=(color&0xFF00)>>8;
  884.                         video[((y1+fil)*SCREEN_WIDTH*SCREEN_BPP)+col+0+(x1*SCREEN_BPP)]=color&0x00FF;
  885.                 }
  886. }
  887. void start_presentacio() {
  888.     struct Ps2Mouse* mousectx;
  889. struct str_buffer* buffer_kbd;
  890.         mouse =((struct bus_driver*)ret_root_bus())->find_dev_in_bus(ISA0_STR,ISA_MOUSE_STR,(struct device*)((struct bus_driver*)ret_root_bus())->dev_root);
  891.         rtc =((struct bus_driver*)ret_root_bus())->find_dev_in_bus(ISA0_STR,ISA_RTC_STR,(struct device*)((struct bus_driver*)ret_root_bus())->dev_root);
  892.         keyboard =((struct bus_driver*)ret_root_bus())->find_dev_in_bus(ISA0_STR,ISA_PSKBD_STR,(struct device*)((struct bus_driver*)ret_root_bus())->dev_root);
  893. /* Proves amb create plane */
  894. init_planes ();
  895.         mousectx=(struct Ps2Mouse*)kmalloc(sizeof(struct Ps2Mouse));
  896.         mousectx->x=0;
  897.         mousectx->y=0;
  898. rtc_time_of_day* rtc_clock=(rtc_time_of_day*)kmalloc(sizeof(rtc_time_of_day));
  899. buffer_kbd=(struct str_buffer*)kmalloc(sizeof(struct str_buffer));
  900. buffer_kbd->buffer=(char*)kmalloc(sizeof(char)*100);
  901. buffer_kbd->size=0;
  902. buffer_kbd->buffer[0]=0;
  903. set_background_plane(0xfffc,background_plane);
  904. print_bmp_alpha_plane (0,0,header_16bpp,0xffdf,background_plane-1);
  905. //print_bmp_alpha_plane (0,0,header_16bpp,0xffdf,0);
  906.    int oldx,oldy,oldbut;
  907. int oldsec;
  908. int counter=0;
  909.         oldx=300;
  910.         oldy=300;
  911. oldbut=0;
  912. // print_composed_plane ();
  913. // Write Draw Pong Memory About GNU halt
  914. print_bmp_alpha_plane(175,540,dock_16bpp,0xffdf,background_plane-1);
  915. print_bmp_alpha_plane(194,545,write_16bpp,0xffdf,background_plane-1);
  916. print_bmp_alpha_plane(254,545,draw_16bpp,0xffdf,background_plane-1);
  917. print_bmp_alpha_plane(314,545,pong_16bpp,0xffdf,background_plane-1);
  918. print_bmp_alpha_plane(374,545,memory_16bpp,0xffdf,background_plane-1);
  919. print_bmp_alpha_plane(434,545,abouticon_16bpp,0xffdf,background_plane-1);
  920. print_bmp_alpha_plane(494,545,gnu_16bpp,0xffdf,background_plane-1);
  921. print_bmp_alpha_plane(554,545,halt_16bpp,0xffdf,background_plane-1);
  922. init_windows();
  923. // create_window("notepad",200,200,300,200,0x0ff0,2);
  924. // create_window("caca",200,50,300,400,0x00f0,3);
  925. print_composed_plane ();
  926.         while (1>0) {
  927.                 intoff();
  928. keyboard->command(POLL_KBD_DEVICE,(void*)0);
  929. if (focus_win!=0&&focus_win->text_win==1&&focus_win->userwrite==1) {
  930. int pos;
  931. keyboard->command(ISEMPTY_KBD_BUFFER,&pos);
  932. if (pos==1) mouse_event(-1,-1,-1);
  933. // kprint_plane (buffer_kbd->buffer,focus_win->plane);
  934. }
  935.                 mouse->command(GET_MOUSE_COORDINATES,mousectx);
  936.  if (counter%20000==0)rtc->command(GET_TIME,rtc_clock);
  937. if ((counter%20000==0)&&(rtc_clock->hour.sec!=oldsec)) {
  938. paint_rectangle_plane(0,100,800,230,ALPHA_COLOR,background_plane-1);
  939. print_bcd_bmp_plane(0,100,rtc_clock->hour.hour,2,background_plane-1);
  940. print_bmp_alpha_plane (200,100,dots_16bpp,ALPHA_COLOR,background_plane-1);
  941. print_bcd_bmp_plane(300,100,rtc_clock->hour.min,2,background_plane-1);
  942. print_bmp_alpha_plane (500,100,dots_16bpp,ALPHA_COLOR,background_plane-1);
  943. print_bcd_bmp_plane(600,100,rtc_clock->hour.sec,2,background_plane-1);
  944. oldsec=rtc_clock->hour.sec;
  945. print_composed_plane_region (0,100,800,230);
  946. }
  947. mouse_event (mousectx->x,mousectx->y,mousectx->buttons);
  948.                 
  949. if ((mousectx->x!=oldx)||(mousectx->y!=oldy)) {
  950. if (focus_win==0|| (focus_win!=0&&focus_win->drag==0)) {
  951. paint_rectangle_plane(oldx,oldy,oldx+30,(oldy+30>=SCREEN_HEIGHT)?(SCREEN_HEIGHT):(oldy+30),ALPHA_COLOR,MOUSE_PLANE);
  952. print_mouse_plane (mousectx->x,mousectx->y,MOUSE_PLANE);
  953. print_composed_plane_region (oldx,oldy,oldx+30,(oldy+30>=SCREEN_HEIGHT)?(SCREEN_HEIGHT):(oldy+30));
  954.                         oldx=mousectx->x;
  955.                         oldy=mousectx->y;
  956. print_composed_plane_region (oldx,oldy,oldx+30,(oldy+30>=SCREEN_HEIGHT)?(SCREEN_HEIGHT):(oldy+30));
  957. }
  958. if ((counter%700==0)&&(focus_win!=0&&focus_win->drag==1)) {
  959. paint_rectangle_plane(oldx,oldy,oldx+focus_win->sizex+20,oldy+focus_win->sizey+20,ALPHA_COLOR,MOUSE_PLANE);
  960. print_bmp_alpha_plane(mousectx->x,mousectx->y,focus_win->selfcopy,ALPHA_COLOR,MOUSE_PLANE);
  961. print_composed_plane_region (oldx,oldy,oldx+focus_win->sizex+20,oldy+focus_win->sizey+20);
  962. print_shade_plane(mousectx->x+focus_win->sizex,mousectx->y,mousectx->x+focus_win->sizex+20,mousectx->y+focus_win->sizey,LR_SHADE,MOUSE_PLANE);
  963. print_shade_plane(mousectx->x,mousectx->y+focus_win->sizey,mousectx->x+focus_win->sizex,mousectx->y+focus_win->sizey+20,TD_SHADE,MOUSE_PLANE);
  964.                         oldx=mousectx->x;
  965.                         oldy=mousectx->y;
  966. // print_composed_plane_region (oldx,oldy,oldx+focus_win->sizex,oldy+focus_win->sizey);
  967. print_composed_plane_region (oldx,oldy,oldx+focus_win->sizex+20,oldy+focus_win->sizey+20);
  968. //print_composed_plane();
  969. }
  970.                 }
  971. //circle_fill_plane(400,300,200, 0xfeca,2) ;
  972. //circle_fast_plane(400,300,300, 0x0000,2) ;
  973. counter++;
  974.                 inton();
  975. int c;
  976. for (c=0;c<800;c++) ;
  977.         }
  978. }
  979. void kprint_plane( char * str , int plane) {
  980.                int i=0;
  981.                 while (str[i]!='' && ((i*FONT_W)+focus_win->cursorx) < focus_win->finalx ) {
  982.                         switch (str[i]) {
  983.                                 case 'n':
  984.                                         str[i]='';
  985.                                         xyprint_plane(focus_win->x+focus_win->cursorx,focus_win->y+focus_win->cursory,str,plane);
  986. print_composed_plane_region (focus_win->x+focus_win->cursorx,focus_win->y+focus_win->cursory,focus_win->x+focus_win->cursorx+(strlen(str)*FONT_W),focus_win->y+focus_win->cursory+FONT_H);
  987.                                         focus_win->cursorx=focus_win->initialx;
  988.                                         focus_win->cursory=focus_win->cursory+FONT_H;
  989.                                         str=str+i+1 ;
  990.                                         i=-1;
  991.                                 break;
  992.                         }
  993.                         i++;
  994.                         if (i*FONT_W+focus_win->cursorx >= focus_win->finalx ) {
  995.                                 str[i]='';
  996.                                 xyprint_plane(focus_win->x+focus_win->cursorx,focus_win->y+focus_win->cursory,str,plane);
  997. print_composed_plane_region (focus_win->x+focus_win->cursorx,focus_win->y+focus_win->cursory,focus_win->x+focus_win->cursorx+(strlen(str)*FONT_W),focus_win->y+focus_win->cursory+FONT_H);
  998.                                 focus_win->cursorx=focus_win->initialx;
  999.                                 focus_win->cursory=focus_win->cursory+FONT_H;
  1000.                                 str=str+i+1 ;
  1001.                                 i=0;
  1002.                         }
  1003.                 }
  1004.                 xyprint_plane(focus_win->x+focus_win->cursorx,focus_win->y+focus_win->cursory,str,plane);
  1005. print_composed_plane_region (focus_win->x+focus_win->cursorx,focus_win->y+focus_win->cursory,focus_win->x+focus_win->cursorx+(strlen(str)*FONT_W),focus_win->y+focus_win->cursory+FONT_H);
  1006.                 focus_win->cursorx=focus_win->cursorx+strlen(str)*FONT_W;
  1007. }
  1008. void xyprint_plane ( int x, int y, char* string, int plane) {
  1009. xyprint_area (string, x,y,0x0000,5,(word*)plane_list[plane]);
  1010. }
  1011. static unsigned short* bmp_numbers[] = { zero_16bpp, one_16bpp, two_16bpp, three_16bpp, four_16bpp, five_16bpp, six_16bpp, seven_16bpp, eight_16bpp, nine_16bpp };
  1012. void print_bcd_bmp_plane (int x, int y, int number, int digits,int plane) {
  1013. int i;
  1014. int k;
  1015. for (i=digits-1;i>0;i--) {
  1016. k=number/pow(10,i);
  1017. print_bmp_alpha_plane (x+((digits-1-i)*100),y,bmp_numbers[k],ALPHA_COLOR,plane);
  1018. }
  1019. k=number%10;
  1020. print_bmp_alpha_plane (x+((digits-i-1)*100),y,bmp_numbers[k],ALPHA_COLOR,plane);
  1021. }
  1022. //x^y
  1023. int pow ( int x, int y) {
  1024. int i;
  1025. if (y==1) return x;
  1026. if (y==0) return 1;
  1027. i=x*pow(x,y-1);
  1028. return i;
  1029. }
  1030. #include "sin_acos_table.c"
  1031. void circle_fill_plane(int x,int y, int radius, unsigned short color,int plane) {
  1032. unsigned short* VIDEO=(unsigned short*)0xD0800000;
  1033. if (plane>-1) VIDEO=(unsigned short*)plane_list[plane];
  1034. unsigned long n=0,invradius=(1/(float)radius)*0x10000L;
  1035.    int dx=0,dy=radius-1,i;
  1036.    while (dx<=dy) {
  1037.      for(i=dy;i>=dx;i--) {
  1038. VIDEO[((y+dy+(i-dy))*SCREEN_WIDTH)+x+dx] = color;  /* octant 0 */
  1039. VIDEO[((y+dy+(i-dy))*SCREEN_WIDTH)+x-dx] = color;  /* octant 0 */
  1040.      VIDEO[((y-dy-(i-dy))*SCREEN_WIDTH)+x-dx] = color;  /* octant 0 */
  1041.      VIDEO[((y-dy-(i-dy))*SCREEN_WIDTH)+x+dx] = color;  /* octant 0 */
  1042. VIDEO[((y-dx)*SCREEN_WIDTH)+x+dy+(i-dy)] = color;  /* octant 0 */
  1043. VIDEO[((y+dx)*SCREEN_WIDTH)+x+dy+(i-dy)] = color;  /* octant 0 */
  1044. VIDEO[((y+dx)*SCREEN_WIDTH)+x-dy-(i-dy)] = color;  /* octant 0 */
  1045. VIDEO[((y-dx)*SCREEN_WIDTH)+x-dy-(i-dy)] = color;  /* octant 0 */
  1046.        }
  1047.      dx++;
  1048.      n+=invradius;
  1049.      dy = (int)((radius * SIN_ACOS[(int)(n>>6)]) >> 16);
  1050.    }
  1051. }
  1052. void circle_fill_plane_alpha(int x,int y, int radius, unsigned short color,int plane, float factor){
  1053. unsigned short* VIDEO=(unsigned short*)0xD0800000;
  1054. if (plane>-1) VIDEO=(unsigned short*)plane_list[plane];
  1055. unsigned long n=0,invradius=(1/(float)radius)*0x10000L;
  1056.    int dx=0,dy=radius-1,i;
  1057. unsigned short orig_color;
  1058. int O_r,O_g,O_b;
  1059. int N_r,N_g,N_b;
  1060. unsigned short new_color;
  1061.         O_r=(color>>11)&0x1F;
  1062.    O_g=(color>>6)&0x1F;
  1063.         O_b=color&0x1F;
  1064. O_r=O_r*(1-factor);
  1065. O_g=O_g*(1-factor);
  1066. O_b=O_b*(1-factor);
  1067.    while (dx<=dy) {
  1068.      for(i=dy;i>=dx;i--) {
  1069. orig_color=VIDEO[((y+dy+(i-dy))*SCREEN_WIDTH)+x+dx];
  1070. N_r=(orig_color>>11)&0x1F;
  1071.    N_g=(orig_color>>6)&0x1F;
  1072.          N_b=orig_color&0x1F;
  1073. N_r=N_r*factor+O_r;
  1074. N_g=N_g*factor+O_g;
  1075. N_b=N_b*factor+O_b;
  1076. new_color=(N_r<<11)|(N_g<<6)|N_b;
  1077. if (dx!=0&&dx!=i)
  1078. VIDEO[((y+dy+(i-dy))*SCREEN_WIDTH)+x+dx] = new_color;  /* octant 0 */
  1079. orig_color= VIDEO[((y+dy+(i-dy))*SCREEN_WIDTH)+x-dx];
  1080. N_r=(orig_color>>11)&0x1F;
  1081.    N_g=(orig_color>>6)&0x1F;
  1082.          N_b=orig_color&0x1F;
  1083. N_r=N_r*factor+O_r;
  1084. N_g=N_g*factor+O_g;
  1085. N_b=N_b*factor+O_b;
  1086. new_color=(N_r<<11)|(N_g<<6)|N_b;
  1087. VIDEO[((y+dy+(i-dy))*SCREEN_WIDTH)+x-dx] = new_color;  /* octant 0 */
  1088. orig_color=VIDEO[((y-dy-(i-dy))*SCREEN_WIDTH)+x-dx];
  1089. N_r=(orig_color>>11)&0x1F;
  1090.    N_g=(orig_color>>6)&0x1F;
  1091.          N_b=orig_color&0x1F;
  1092. N_r=N_r*factor+O_r;
  1093. N_g=N_g*factor+O_g;
  1094. N_b=N_b*factor+O_b;
  1095. new_color=(N_r<<11)|(N_g<<6)|N_b;
  1096. if (dx!=0)
  1097.      VIDEO[((y-dy-(i-dy))*SCREEN_WIDTH)+x-dx] = new_color;  /* octant 0 */
  1098.     
  1099. orig_color=VIDEO[((y-dy-(i-dy))*SCREEN_WIDTH)+x+dx];
  1100. N_r=(orig_color>>11)&0x1F;
  1101.    N_g=(orig_color>>6)&0x1F;
  1102.          N_b=orig_color&0x1F;
  1103. N_r=N_r*factor+O_r;
  1104. N_g=N_g*factor+O_g;
  1105. N_b=N_b*factor+O_b;
  1106. new_color=(N_r<<11)|(N_g<<6)|N_b;
  1107. VIDEO[((y-dy-(i-dy))*SCREEN_WIDTH)+x+dx] = new_color;  /* octant 0 */
  1108. orig_color= VIDEO[((y-dx)*SCREEN_WIDTH)+x+dy+(i-dy)];
  1109. N_r=(orig_color>>11)&0x1F;
  1110.    N_g=(orig_color>>6)&0x1F;
  1111.          N_b=orig_color&0x1F;
  1112. N_r=N_r*factor+O_r;
  1113. N_g=N_g*factor+O_g;
  1114. N_b=N_b*factor+O_b;
  1115. new_color=(N_r<<11)|(N_g<<6)|N_b;
  1116. if (dx!=0&&dx!=i)
  1117. VIDEO[((y-dx)*SCREEN_WIDTH)+x+dy+(i-dy)] = new_color;  /* octant 0 */
  1118. orig_color=VIDEO[((y+dx)*SCREEN_WIDTH)+x+dy+(i-dy)];
  1119. N_r=(orig_color>>11)&0x1F;
  1120.    N_g=(orig_color>>6)&0x1F;
  1121.          N_b=orig_color&0x1F;
  1122. N_r=N_r*factor+O_r;
  1123. N_g=N_g*factor+O_g;
  1124. N_b=N_b*factor+O_b;
  1125. new_color=(N_r<<11)|(N_g<<6)|N_b;
  1126. VIDEO[((y+dx)*SCREEN_WIDTH)+x+dy+(i-dy)] = new_color;  /* octant 0 */
  1127. /* Aquest no va del tot be */
  1128. orig_color=VIDEO[((y+dx)*SCREEN_WIDTH)+x-dy-(i-dy)];
  1129. N_r=(orig_color>>11)&0x1F;
  1130.    N_g=(orig_color>>6)&0x1F;
  1131.          N_b=orig_color&0x1F;
  1132. N_r=N_r*factor+O_r;
  1133. N_g=N_g*factor+O_g;
  1134. N_b=N_b*factor+O_b;
  1135. new_color=(N_r<<11)|(N_g<<6)|N_b;
  1136. if (dx!=i)
  1137. VIDEO[((y+dx)*SCREEN_WIDTH)+x-dy-(i-dy)] = new_color;  /* octant 0 */
  1138. orig_color=VIDEO[((y-dx)*SCREEN_WIDTH)+x-dy-(i-dy)];
  1139. N_r=(orig_color>>11)&0x1F;
  1140.    N_g=(orig_color>>6)&0x1F;
  1141.          N_b=orig_color&0x1F;
  1142. N_r=N_r*factor+O_r;
  1143. N_g=N_g*factor+O_g;
  1144. N_b=N_b*factor+O_b;
  1145. new_color=(N_r<<11)|(N_g<<6)|N_b;
  1146. if (dx!=0&&dx!=i)
  1147. VIDEO[((y-dx)*SCREEN_WIDTH)+x-dy-(i-dy)] = new_color;  /* octant 0 */
  1148.        }
  1149.      dx++;
  1150.      n+=invradius;
  1151.      dy = (int)((radius * SIN_ACOS[(int)(n>>6)]) >> 16);
  1152.    }
  1153. }
  1154. void circle_fast_plane(int x,int y, int radius, unsigned short color, int plane){
  1155. unsigned short* VIDEO=(unsigned short*)0xD0800000;
  1156. if (plane>-1) VIDEO=(unsigned short*)plane_list[plane];
  1157.    unsigned short n=0,invradius=(1/(float)radius)*0x10000L;
  1158. int dx=0,dy=radius-1;
  1159.    while (dx<=dy){
  1160.      VIDEO[((y+dy)*SCREEN_WIDTH)+x+dx] = color;  /* octant 0 */
  1161. VIDEO[((y+dy)*SCREEN_WIDTH)+x-dx] = color;  /* octant 0 */
  1162.      VIDEO[((y-dy)*SCREEN_WIDTH)+x-dx] = color;  /* octant 0 */
  1163.      VIDEO[((y-dy)*SCREEN_WIDTH)+x+dx] = color;  /* octant 0 */
  1164.  
  1165. VIDEO[((y-dx)*SCREEN_WIDTH)+x+dy] = color;  /* octant 0 */
  1166. VIDEO[((y+dx)*SCREEN_WIDTH)+x+dy] = color;  /* octant 0 */
  1167. VIDEO[((y+dx)*SCREEN_WIDTH)+x-dy] = color;  /* octant 0 */
  1168. VIDEO[((y-dx)*SCREEN_WIDTH)+x-dy] = color;  /* octant 0 */
  1169.      dx++;
  1170. n+=invradius;
  1171.      dy = (int)((radius * SIN_ACOS[(int)(n>>6)]) >> 16);
  1172. }
  1173. }