Subversion Repositories Kolibri OS

Rev

Go to most recent revision | Blame | Last modification | View Log | Download | RSS feed

  1. //stuff for loading images via MeView via IPC by Nable. 2008
  2. //Last changed 13.11.2008
  3.  
  4. inline fastcall void registerIPCbuffer(dword ECX, dword EDX)
  5. //ecx - pointer to buffer, edx - buffer size
  6. {
  7.    EAX=60;
  8.    EBX=1;
  9.    $int 0x40
  10. }
  11.  
  12. inline fastcall void build_param_string(dword ESI, dword EDI)
  13. //first parameter - pointer to filename string, second - pointer to
  14. //the output area for commandline for MeView
  15. proc_info _p_info;
  16. {
  17.    _p_info.GetInfo(SelfInfo);
  18.    EBX = _p_info.ID;
  19.    EAX = 'NCPI';  //'IPCN' in reversed byte order
  20.    $STOSD
  21.    ECX = 8;
  22.  
  23. ___NEW_SYMBOL_OF_PID:
  24.    $ROL  EBX,4
  25.  
  26.    EAX =  EBX;
  27.    EAX &= 0xF;
  28.    EAX += '0';
  29.  
  30.    $CMP  AL,'9'
  31.    $JBE  ___NEW_SYMBOL_OF_PID_PRINT
  32.    $ADD  AL,7                       //('A'-'0'-10)
  33. ___NEW_SYMBOL_OF_PID_PRINT:
  34.    $STOSB
  35.    $LOOP ___NEW_SYMBOL_OF_PID
  36.  
  37. ___NEW_SYMBOL_OF_PATH_COPY:
  38.    $LODSB
  39.    $STOSB
  40.    $OR   AL,AL
  41.    $JNE  ___NEW_SYMBOL_OF_PATH_COPY
  42. }
  43.  
  44. char _Path2MeView[]="/sys/mv";
  45.  
  46. inline int RunMV(char* parameters)
  47. f70 _run_struct;
  48. {
  49.    _run_struct.func   = 7;
  50.    _run_struct.param1 = 0;
  51.    _run_struct.param2 = parameters;
  52.    _run_struct.param3 =
  53.    _run_struct.param4 =
  54.    _run_struct.rezerv = 0;
  55.    _run_struct.name   = #_Path2MeView;
  56.  
  57.    EAX=70;
  58.    EBX=#_run_struct;
  59.    $int 0x40
  60.    //EAX (return code) will contain positive PID of new process or negative error code.
  61. }
  62.  
  63.  
  64. int loadimage_viaIPC(char* file_name_to_load, int initial_values)
  65. //really it must be IMAGE_INFO* initial_values, but compiler rejected
  66. //this, so I had to use 'int initial_values'
  67. char param_string[255];
  68. unsigned int _FrameCountTemp;
  69. int temp0; //scratch variable
  70. int came_size; //sizeof data that came. It's used to shrink unneeded IPC data
  71. //added by Nable 13.11.2008 3.36am (begin)
  72. int MVsPID; //no comments
  73. int MVsSlot; //no comments
  74. proc_info _p_info; //this structure will be used to test if MV is alive
  75. //added by Nable 13.11.2008 3.36am (end)
  76. {
  77.    int pIPCbuffer = malloc(64); //IPC buffer for the first message can be
  78.                             //rather small but >= 8+8+24
  79.  
  80.    /*Here you can add error checking code, i.e. if(!pIPCbuffer)
  81.    { ErrorExit("OUT OF MEMORY!"); }; */
  82.  
  83.    registerIPCbuffer(pIPCbuffer,64);
  84.    DSDWORD[pIPCbuffer+4]=8; //at +4 in IPC buffer is a relative pointer to free place
  85.  
  86.    build_param_string(file_name_to_load, #param_string);
  87.  
  88.    DSDWORD[pIPCbuffer]=0; //unlock the buffer
  89.  
  90.    SetEventMask(01000000b); // 1 << (evIPC-1)
  91. //13.11.2008 3.45am Nable's fixes (begin1)
  92.         MVsPID = RunMV(#param_string); //you can use here your function but don't forget
  93.         //about parameters (param_string).
  94.         MVsSlot = PIDtoSlot(MVsPID);
  95.  
  96.         WHILE(!(WaitEventTimeout(100))){
  97.                 //we have only one event - evIPC so return value may be 0 or evIPC but if received 0 it can mean
  98.                 //either MV terminated silently or it just hasn't done the work and we should wait. Test for it
  99.                         _p_info.GetInfo(MVsSlot);
  100.                         IF((_p_info.status_slot > 2)||(_p_info.ID != MVsPID)) return 0;
  101.         }
  102. //13.11.2008 4.26am Nable's fixes ( end1)  
  103.  
  104. //else we got the message. Process it.
  105.    DSDWORD[pIPCbuffer] |= -1; //lock the buffer
  106.  
  107.    //the first dword of the message is frame count
  108.    _FrameCountTemp = DSDWORD[pIPCbuffer+16]; //note that data of the first
  109.    //message is located at offset 16 in IPC buffer;
  110.  
  111.    IF(_FrameCountTemp <= 1)  //see docs
  112.     {
  113.      ESI = pIPCbuffer+16+12;
  114.      EDI = initial_values; //offset of CurrentImage structure
  115.  
  116.      //Left and top corner's coords (not used in many cases but who knows?)
  117.      $MOVSD
  118.      //Width and height
  119.      $MOVSD
  120.      //bpp
  121.      $LODSD
  122.      $movzx eax,ax
  123.      CurrentImage.BitsPerPixel = EAX;
  124.     }
  125.    //see docs
  126.    came_size = DSDWORD[pIPCbuffer+24]; //amount of useful data
  127.    temp0 = came_size + 4096; //+4096 - some reserve
  128.    realloc(temp0+4096, pIPCbuffer); //+4096 - some reserve
  129.    registerIPCbuffer(pIPCbuffer, temp0); //re-register IPC buffer with a new size
  130.  
  131.    DSDWORD[pIPCbuffer+4]=8; //delete first message, at +4 in IPC buffer is a
  132.    //relative pointer to free place
  133.  
  134.    DSDWORD[pIPCbuffer]=0; //unlock the buffer to receive second msg
  135.  
  136. //13.11.2008 4.26am Nable's fixes ( begin2)  
  137.         WHILE(!(WaitEventTimeout(100))){
  138.                 //we have only one event - evIPC so return value may be 0 or evIPC but if received 0 it can mean
  139.                 //either MV terminated silently or it just hasn't done the work and we should wait. Test for it
  140.                         _p_info.GetInfo(MVsSlot);
  141.                         IF((_p_info.status_slot > 2)||(_p_info.ID != MVsPID)) return 0;
  142.         }
  143. //13.11.2008 4.26am Nable's fixes ( end2)  
  144.  
  145. //if we are here, then we received the second message. if FrameCount==1 then
  146. //it's a pure image data (if BitsPerPixel==15, 16, 24 or 32) or
  147. //(dword)sizeof(palette[]) then palette[] and then the image.
  148. //Parse it as you like, here's my way:
  149.  
  150.    registerIPCbuffer(pIPCbuffer, 0); // there are no function 'unregister
  151.    //IPC buffer' in Kolibri - so I have to use 'dark power'
  152.  
  153.    //shrink unneeded IPC data
  154.    ECX = came_size;
  155.    $SHR ECX,2
  156.    ECX++; //ECX = number of useful dwords
  157.    EDI = pIPCbuffer;
  158.    ESI = EDI + 16;
  159.    $CLD
  160.    $REP $MOVSD
  161.  
  162.    //now we must interpret second message
  163.    EDI = initial_values;
  164.    IF(_FrameCountTemp <= 1)
  165.     {
  166.      IF(DSDWORD[EDI+24] > 8) //CurrentImage.BitsPerPixel
  167.       {
  168.        DSDWORD[EDI+20] = 0; //CurrentImage.pPalette=0
  169.        DSDWORD[EDI+16] = pIPCbuffer; //CurrentImage.StartOfImage=pIPCbuffer
  170.       }
  171.      ELSE
  172.       {
  173.        EAX = pIPCbuffer + 4;
  174.        DSDWORD[EDI+20] = EAX; //CurrentImage.pPalette=EAX
  175.        EAX += DSDWORD[EAX-4];
  176.        DSDWORD[EDI+16] = EAX; //CurrentImage.StartOfImage = EAX;
  177.       };
  178.     }
  179.    ELSE
  180.     {
  181.      GetNthImageInfo(pIPCbuffer,EDI,0);
  182.     };
  183.  
  184.    EBX = _FrameCountTemp;
  185.    return pIPCbuffer;
  186. }
  187.