calc.c

00001 /***************************************************************************
00002                           calc.c  -  description
00003                           ----------------------
00004     begin                : 
00005     copyright            : (C) 2003 by Dynacube Team
00006     email                : mdshah82@yahoo.com
00007  ***************************************************************************/
00008 
00009 /***************************************************************************
00010  *                                                                         *
00011  *   This program is free software; you can redistribute it and/or modify  *
00012  *   it under the terms of the GNU General Public License as published by  *
00013  *   the Free Software Foundation; either version 2 of the License, or     *
00014  *   (at your option) any later version.                                   *
00015  *                                                                         *
00016  ***************************************************************************/
00017 
00018  #include "common/string.h"
00019  #include "gui/client/client_gui.h"
00020  #include "common/stdlib.h"
00021 
00022  int main()
00023  {
00024   volatile char text[4096];
00025   SDD v1,v2;
00026   boolean oppres,v1pres,v2pres,respres;
00027   DW oper,len;
00028   SDD res;
00029   volatile MSG msg;
00030   CREATE_INFO cr;
00031   COMP_CREATE_INFO cmp;
00032   RESIZE_INFO rs;
00033   SDD ret_val = -1;
00034   DB i,j,k;
00035   DW but_id;
00036   char op[] = "+-*/";
00037   char temp[2];
00038 
00039         v1=v2=0;
00040         oppres= _false;
00041         v1pres = _false;
00042         v2pres = _false;
00043         respres = _true;
00044         
00045     //Creating the window
00046 
00047      msg.length = sizeof(cr);
00048      msg.type   = CREATE;
00049      msg.sub_type = WINDOW;
00050      cr.alias_id = 101;
00051      cr.cntr_id = 0;
00052      cr.height = 250;
00053      cr.width = 160;
00054      cr.style  = W_NORESIZE;
00055      cr.x = 300;
00056      cr.y = 200;
00057      strcpy(cr.title,"Calculator");
00058 
00059      memcpy(msg.msg_buf,&cr,sizeof(cr));
00060 
00061      asm("pushl %0"::"r"(&msg));
00062      asm("pushl %0"::"r"(GUI_PID));
00063 
00064      asm("int $0x30"::"a"(3));
00065 
00066      msg.sub_type = TEXT;
00067      cmp.alias_id = 16;
00068      cmp.cntr_id = 101;
00069      cmp.cnt_type = WIND_TYPE;
00070      cmp.height = 25;
00071      cmp.width = 130;
00072      cmp.x = 10;
00073      cmp.y = 10;
00074      cmp.style = DISABLED;
00075      strcpy(cmp.label,"0");
00076 
00077      memcpy(msg.msg_buf,&cmp,sizeof(cmp));
00078 
00079      asm("pushl %0"::"r"(&msg));
00080      asm("pushl %0"::"r"(GUI_PID));
00081      asm("int $0x30"::"a"(3));
00082 
00083      msg.sub_type = BUTTON;
00084      cmp.cntr_id = 101;
00085      cmp.cnt_type = WIND_TYPE;
00086      cmp.style = 0;
00087      cmp.height = 30;
00088      cmp.width = 30;
00089 
00090 
00091         k=9;
00092         for(i=0;i<3;i++)
00093          {
00094           for(j=0;j<3;j++)
00095            {
00096             cmp.label[0] = ' ';
00097             cmp.label[1] = k +'0';
00098             cmp.label[2] = '\0';
00099 
00100             cmp.alias_id = k+1;
00101             cmp.x = j*35 + 10;
00102             cmp.y = i*35 + 50;
00103 
00104             memcpy(msg.msg_buf,&cmp,sizeof(cmp));
00105 
00106             asm("pushl %0"::"r"(&msg));
00107             asm("pushl %0"::"r"(GUI_PID));
00108             asm("int $0x30"::"a"(3));
00109 
00110             k--;
00111            }
00112          }
00113             cmp.label[0] = ' ';
00114             cmp.label[1] = k +'0';
00115             cmp.label[2] = '\0';
00116 
00117             cmp.alias_id = k+1;
00118             cmp.x = 10;
00119             cmp.y = 3*35 + 50;
00120 
00121             memcpy(msg.msg_buf,&cmp,sizeof(cmp));
00122 
00123             asm("pushl %0"::"r"(&msg));
00124             asm("pushl %0"::"r"(GUI_PID));
00125             asm("int $0x30"::"a"(3));
00126 
00127             k = 11;
00128             cmp.x = 3*35 + 10;
00129 
00130          for(i=0;i<4;i++)
00131          {
00132             cmp.label[0] = ' ';
00133             cmp.label[1] = op[i];
00134             cmp.label[2] = '\0';
00135 
00136             cmp.alias_id = k;
00137             cmp.y = i*35 + 50;
00138 
00139             memcpy(msg.msg_buf,&cmp,sizeof(cmp));
00140 
00141             asm("pushl %0"::"r"(&msg));
00142             asm("pushl %0"::"r"(GUI_PID));
00143             asm("int $0x30"::"a"(3));
00144 
00145             k++;
00146           }
00147 
00148             cmp.label[0] = ' ';
00149             cmp.label[1] ='=';
00150             cmp.label[2] = '\0';
00151 
00152             cmp.alias_id = 15;
00153             cmp.x = 45;
00154             cmp.y = 3*35 + 50;
00155 
00156             memcpy(msg.msg_buf,&cmp,sizeof(cmp));
00157 
00158                 asm("pushl %0"::"r"(&msg));
00159                 asm("pushl %0"::"r"(GUI_PID));
00160                 asm("int $0x30"::"a"(3));
00161 
00162                  msg.type = SHOW;
00163          msg.sub_type = WINDOW;
00164          msg.length   = sizeof(DW);
00165          msg.msg_buf[0] = 101;
00166 
00167          asm("pushl %0"::"r"(&msg));
00168          asm("pushl %0"::"r"(GUI_PID));
00169          asm("int $0x30"::"a"(3));
00170 
00171     while(1)
00172      {
00173        asm("pushl %0"::"r"(&msg));
00174        asm("int $0x30"::"a"(4));
00175 
00176        switch(msg.type)
00177         {
00178          case WM_CLICKED:
00179                 switch(msg.sub_type)
00180                  {
00181                   case BUT_TYPE:
00182                         but_id = *(DW *)msg.msg_buf;
00183                         if(but_id >= 1 && but_id <= 10)
00184                          {
00185                                 if(!oppres)
00186                                 {
00187                                         v1= v1*10+but_id-1;
00188                                         v1pres = _true;
00189                                 }
00190                                 else
00191                                 {
00192                                         v2 = v2 *10 +but_id-1;
00193                                         v2pres = _true;
00194                                 }
00195                                 temp[0] = but_id -1 +'0';
00196                                 temp[1] = '\0';
00197                                 if(strcmp(text,"0") == 0)
00198                                         strcpy(text,temp);
00199                                 else
00200                                         strcat(text,temp);
00201 
00202                                 msg.type     = SET;
00203                                 msg.sub_type = TEXT;
00204                                 msg.length   = 10;//sizeof(DW) + sizeof(DD);
00205                                 *(DW*)msg.msg_buf = 16;
00206                                 *(DD*)(msg.msg_buf+2) = text;
00207 
00208 
00209                                 asm("pushl %0"::"r"(&msg));
00210                                 asm("pushl %0"::"r"(GUI_PID));
00211                                 asm("int $0x30"::"a"(3));
00212                          }
00213                         else if(but_id >= 11 && but_id <= 14)
00214                          {
00215                           if(!v1pres)
00216                            if(respres)
00217                             v1 = res;
00218                           else
00219                             v1 = 0;
00220                          v1pres = _true;
00221                          oper = but_id - 11;
00222                          oppres = _true;
00223                          strcpy(text,"");
00224                          }
00225                         else if(but_id == 15)
00226                          {
00227                                 if(v2pres)
00228                                 {
00229                                 switch(oper)
00230                                 {
00231                                 case 0:
00232                                                 res = v1+v2;
00233                                                 break;
00234                                 case 1:
00235                                                 res = v1-v2;
00236                                                 break;
00237                                 case 2:
00238                                                 res = v1 *v2;
00239                                                 break;
00240                                 case 3:
00241                                                 if(v2 != 0)
00242                                                 res = v1 / v2;
00243                                                 else
00244                                                 res = 0;
00245                                                 break;
00246                                 }
00247                                 }
00248                                 else
00249                                 {
00250                                 if(v1pres)
00251                                 res = v1;
00252                                 else if(respres)
00253                                 res = res;
00254                                 else
00255                                 res = 0;
00256                                 }
00257 
00258                                 if(res < 0)
00259                                 strcpy(text,"-");
00260                                 else
00261                                 strcpy(text,"");
00262 
00263                                 strcat(text,itoa(abs(res),10));
00264 
00265                                 msg.type     = SET;
00266                                 msg.sub_type = TEXT;
00267                                 msg.length   = 10;//sizeof(DW) + sizeof(DD);
00268                                 *(DW*)msg.msg_buf = 16;
00269                                 *(DD*)(msg.msg_buf+2) = text;
00270 
00271 
00272                                 asm("pushl %0"::"r"(&msg));
00273                                 asm("pushl %0"::"r"(GUI_PID));
00274                                 asm("int $0x30"::"a"(3));
00275 
00276                                 v1=v2=0;
00277                                 respres = _true;
00278                                 v1pres = v2pres = _false;
00279                                 oppres= _false;
00280                                 strcpy(text,"");
00281                          }
00282                         msg.type     = FINISHED;
00283                         msg.sub_type = BUT_TYPE;
00284                         msg.length   = sizeof(DD);
00285                         *(DW *)msg.msg_buf = but_id;
00286 
00287 
00288                         asm("pushl %0"::"r"(&msg));
00289                         asm("pushl %0"::"r"(GUI_PID));
00290                         asm("int $0x30"::"a"(3));
00291                         break;
00292                 }
00293         }
00294      }
00295 }
00296 

Generated on Thu Jul 27 23:52:25 2006 for Dynacube by  doxygen 1.4.7