Subversion Repositories Kolibri OS

Rev

Rev 1004 | Rev 1040 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed

  1. use32
  2. org 0x0
  3.  
  4. db 'MENUET01'
  5. dd 0x01, START, I_END, 0x4000, 0x4000, @PARAMS, 0x0
  6.  
  7. ;-----------------------------------------------------------------------------
  8.  
  9. FALSE = 0
  10. TRUE  = 1
  11.  
  12. include '../../../../../proc32.inc'
  13. include '../../../../../macros.inc'
  14. include 'dll.inc'
  15.  
  16. include '../../../develop/libraries/libs-dev/libio/libio.inc'
  17. include '../../../develop/libraries/libs-dev/libimg/libimg.inc'
  18.  
  19. ;-----------------------------------------------------------------------------
  20.  
  21. START:
  22.         mcall   68, 11
  23.  
  24.         stdcall dll.Load, @IMPORT
  25.         or      eax, eax
  26.         jnz     exit
  27.  
  28.         invoke  sort.START, 1
  29.  
  30.         mov     ecx, 1  ; for 15.4: 1 = tile
  31.         cmp     word [@PARAMS], '\T'
  32.         jz      set_bgr
  33.         inc     ecx     ; for 15.4: 2 = stretch
  34.         cmp     word [@PARAMS], '\S'
  35.         jz      set_bgr
  36.  
  37.         cmp     byte [@PARAMS], 0
  38.         jnz     params_given
  39.  
  40.         call    opendialog
  41.         jc      exit
  42.         mov     esi, path
  43.         mov     edi, @PARAMS
  44.         mov     ecx, 512/4
  45.         rep     movsd
  46.         mov     byte [edi-1], 0
  47.         jmp     params_given
  48.  
  49. set_bgr:
  50.         mcall   15, 4
  51.         mov     eax, @PARAMS + 4
  52.         call    load_image
  53.         jc      exit
  54.  
  55.         call    set_as_bgr
  56.         jmp     exit
  57.  
  58. params_given:
  59.  
  60.         mov     eax, @PARAMS
  61.         call    load_image
  62.         jc      exit
  63.  
  64. ;-----------------------------------------------------------------------------
  65.  
  66. red:
  67.         call    draw_window
  68.  
  69. still:
  70.         mcall   10
  71.         dec     eax
  72.         jz      red
  73.         dec     eax
  74.         jnz     button
  75.  
  76.   key:
  77.         mcall   2
  78.         jmp     still
  79.  
  80.   button:
  81.         mcall   17
  82.         shr     eax, 8
  83.  
  84.         ; flip horizontally
  85.         cmp     eax, 'flh'
  86.         jne     @f
  87.  
  88.         invoke  img.flip, [image], FLIP_HORIZONTAL
  89.         jmp     redraw_image
  90.  
  91.         ; flip vertically
  92.     @@: cmp     eax, 'flv'
  93.         jne     @f
  94.  
  95.         invoke  img.flip, [image], FLIP_VERTICAL
  96.         jmp     redraw_image
  97.  
  98.         ; flip both horizontally and vertically
  99.     @@: cmp     eax, 'flb'
  100.         jne     @f
  101.  
  102.         invoke  img.flip, [image], FLIP_BOTH
  103.         jmp     redraw_image
  104.  
  105.         ; rotate left
  106.     @@: cmp     eax, 'rtl'
  107.         jne     @f
  108.  
  109.         push    ROTATE_90_CCW
  110. .rotate_common:
  111.         invoke  img.rotate, [image]
  112.         mov     eax, [image]
  113.         test    eax, eax        ; clear ZF flag
  114.         call    update_image_sizes
  115.         jmp     redraw_image
  116.  
  117.         ; rotate right
  118.     @@: cmp     eax, 'rtr'
  119.         jne     @f
  120.  
  121.         push    ROTATE_90_CW
  122.         jmp     .rotate_common
  123.  
  124.         ; open new file
  125.     @@: cmp     eax, 'opn'
  126.         jne     @f
  127.        
  128.         call    opendialog
  129.         jc      still
  130.         push    [image]
  131.         mov     eax, path
  132.         call    load_image
  133.         jc      .restore_old
  134.         mov     esi, path
  135.         mov     edi, @PARAMS
  136.         mov     ecx, 512/4
  137.         rep     movsd
  138.         mov     byte [edi-1], 0
  139.         invoke  img.destroy
  140.         call    free_directory
  141.         jmp     red
  142.     .restore_old:
  143.         pop     [image]
  144.         jmp     still
  145.  
  146.         ; set background
  147.     @@:
  148.         cmp     eax, 'bgr'
  149.         jne     @f
  150.  
  151.         call    set_as_bgr
  152.         jmp     still
  153.  
  154.     @@:
  155.  
  156.         cmp     eax, 'bck'
  157.         jnz     @f
  158.         call    prev_image
  159.         jmp     still
  160.     @@:
  161.         cmp     eax, 'fwd'
  162.         jnz     @f
  163.         call    next_image
  164.         jmp     still
  165.     @@:
  166.  
  167.         cmp     eax, 1
  168.         jne     still
  169.  
  170.   exit:
  171.         mcall   -1
  172.  
  173.   redraw_image = red
  174.  
  175. load_image:
  176.         and     [img_data], 0
  177.         push    eax
  178.         invoke  file.open, eax, O_READ
  179.         or      eax, eax
  180.         jz      .error_pop
  181.         mov     [fh], eax
  182.         invoke  file.size
  183.         mov     [img_data_len], ebx
  184.         stdcall mem.Alloc, ebx
  185.         test    eax, eax
  186.         jz      .error_close
  187.         mov     [img_data], eax
  188.         invoke  file.read, [fh], eax, [img_data_len]
  189.         cmp     eax, -1
  190.         jz      .error_close
  191.         cmp     eax, [img_data_len]
  192.         jnz     .error_close
  193.         invoke  file.close, [fh]
  194.         inc     eax
  195.         jz      .error
  196.  
  197. ; img.decode checks for img.is_img
  198. ;       invoke  img.is_img, [img_data], [img_data_len]
  199. ;       or      eax, eax
  200. ;       jz      exit
  201.         invoke  img.decode, [img_data], [img_data_len]
  202.         or      eax, eax
  203.         jz      .error
  204.         cmp     [image], 0
  205.         mov     [image], eax
  206.         call    update_image_sizes
  207.         call    free_img_data
  208.         clc
  209.         ret
  210.  
  211. .error_free:
  212.         invoke  img.destroy, [image]
  213.         jmp     .error
  214.  
  215. .error_pop:
  216.         pop     eax
  217.         jmp     .error
  218. .error_close:
  219.         invoke  file.close, [fh]
  220. .error:
  221.         call    free_img_data
  222.         stc
  223.         ret
  224.  
  225. free_img_data:
  226.         mov     eax, [img_data]
  227.         test    eax, eax
  228.         jz      @f
  229.         stdcall mem.Free, eax
  230. @@:
  231.         ret
  232.  
  233. update_image_sizes:
  234.         pushf
  235.         mov     edx, [eax + Image.Width]
  236.         add     edx, 19
  237.         cmp     edx, 40 + 25*9
  238.         jae     @f
  239.         mov     edx, 40 + 25*9
  240. @@:
  241.         mov     [wnd_width], edx
  242.         mov     esi, [eax + Image.Height]
  243.         add     esi, 44
  244.         mov     [wnd_height], esi
  245.         popf
  246.         jz      .no_resize
  247.         mcall   48, 4
  248.         add     esi, eax
  249.         mcall   67,-1,-1
  250. .no_resize:
  251.         ret
  252.  
  253. set_as_bgr:
  254.         mov     esi, [image]
  255.         mov     ecx, [esi + Image.Width]
  256.         mov     edx, [esi + Image.Height]
  257.         mcall   15, 1
  258.  
  259.         mcall   15, 6
  260.         test    eax, eax
  261.         jz      @f
  262.  
  263.         push    eax
  264.         invoke  img.to_rgb2, esi, eax
  265.         pop     ecx
  266.         mcall   15, 7
  267.  
  268. @@:
  269.         mcall   15, 3
  270.         ret
  271.  
  272. prev_image:
  273.         call    load_directory
  274.         cmp     [directory_ptr], 0
  275.         jz      .ret
  276.         mov     ebx, [directory_ptr]
  277.         mov     eax, [cur_file_idx]
  278.         cmp     eax, -1
  279.         jnz     @f
  280.         mov     eax, [ebx+4]
  281. @@:
  282.         push    [image]
  283. .scanloop:
  284.         dec     eax
  285.         jns     @f
  286.         mov     eax, [ebx+4]
  287.         dec     eax
  288.         cmp     [cur_file_idx], -1
  289.         jz      .notfound
  290. @@:
  291.         cmp     eax, [cur_file_idx]
  292.         jz      .notfound
  293.         push    eax
  294.         imul    esi, eax, 304
  295.         add     esi, [directory_ptr]
  296.         add     esi, 32 + 40
  297.         mov     edi, curdir
  298. @@:
  299.         inc     edi
  300.         cmp     byte [edi-1], 0
  301.         jnz     @b
  302.         mov     byte [edi-1], '/'
  303. @@:
  304.         lodsb
  305.         stosb
  306.         test    al, al
  307.         jnz     @b
  308.         mov     eax, curdir
  309.         call    load_image
  310.         pop     eax
  311.         jc      .scanloop
  312.         mov     [cur_file_idx], eax
  313.         invoke  img.destroy
  314.         mov     esi, curdir
  315.         mov     edi, @PARAMS
  316.         mov     ecx, 512/4
  317.         rep     movsd
  318.         mov     byte [edi-1], 0
  319. .ret:
  320.         ret
  321. .notfound:
  322.         pop     [image]
  323.         ret
  324.  
  325. next_image:
  326.         call    load_directory
  327.         cmp     [directory_ptr], 0
  328.         jz      .ret
  329.         mov     ebx, [directory_ptr]
  330.         mov     eax, [cur_file_idx]
  331.         push    [image]
  332. .scanloop:
  333.         inc     eax
  334.         cmp     eax, [ebx+4]
  335.         jb      @f
  336.         xor     eax, eax
  337.         cmp     [cur_file_idx], -1
  338.         jz      .notfound
  339. @@:
  340.         cmp     eax, [cur_file_idx]
  341.         jz      .notfound
  342.         push    eax ebx
  343.         imul    esi, eax, 304
  344.         add     esi, [directory_ptr]
  345.         add     esi, 32 + 40
  346.         mov     edi, curdir
  347. @@:
  348.         inc     edi
  349.         cmp     byte [edi-1], 0
  350.         jnz     @b
  351.         mov     byte [edi-1], '/'
  352. @@:
  353.         lodsb
  354.         stosb
  355.         test    al, al
  356.         jnz     @b
  357.         mov     eax, curdir
  358.         call    load_image
  359.         pop     ebx eax
  360.         jc      .scanloop
  361.         mov     [cur_file_idx], eax
  362.         invoke  img.destroy
  363.         mov     esi, curdir
  364.         push    esi
  365.         mov     edi, @PARAMS
  366.         mov     ecx, 512/4
  367.         rep     movsd
  368.         mov     byte [edi-1], 0
  369.         pop     esi
  370. @@:
  371.         lodsb
  372.         test    al, al
  373.         jnz     @b
  374. @@:
  375.         dec     esi
  376.         cmp     byte [esi], '/'
  377.         jnz     @b
  378.         mov     byte [esi], 0
  379. .ret:
  380.         ret
  381. .notfound:
  382.         pop     [image]
  383.         ret
  384.  
  385. load_directory:
  386.         cmp     [directory_ptr], 0
  387.         jnz     .ret
  388.         mov     esi, @PARAMS
  389.         mov     ecx, esi
  390. @@:
  391.         lodsb
  392.         test    al, al
  393.         jnz     @b
  394. @@:
  395.         dec     esi
  396.         cmp     byte [esi], '/'
  397.         jnz     @b
  398.         mov     [last_name_component], esi
  399.         sub     esi, ecx
  400.         xchg    ecx, esi
  401.         mov     edi, curdir
  402.         rep     movsb
  403.         mov     byte [edi], 0
  404.         mcall   68, 12, 0x1000
  405.         test    eax, eax
  406.         jz      .ret
  407.         mov     ebx, readdir_fileinfo
  408.         mov     dword [ebx+12], (0x1000 - 32) / 304
  409.         mov     dword [ebx+16], eax
  410.         mcall   70
  411.         cmp     eax, 6
  412.         jz      .dirok
  413.         test    eax, eax
  414.         jnz     free_directory
  415.         mov     edx, [directory_ptr]
  416.         mov     ecx, [edx+8]
  417.         mov     [readblocks], ecx
  418.         imul    ecx, 304
  419.         add     ecx, 32
  420.         mcall   68, 20
  421.         test    eax, eax
  422.         jz      free_directory
  423.         mov     [directory_ptr], eax
  424.         mcall   70, readdir_fileinfo
  425. .dirok:
  426.         cmp     ebx, 0
  427.         jle     free_directory
  428.         mov     eax, [directory_ptr]
  429.         add     eax, 32
  430.         mov     edi, eax
  431.         push    0
  432. .dirskip:
  433.         push    eax
  434.         test    byte [eax], 18h
  435.         jnz     .nocopy
  436.         lea     esi, [eax+40]
  437.         mov     ecx, esi
  438. @@:
  439.         lodsb
  440.         test    al, al
  441.         jnz     @b
  442. @@:
  443.         dec     esi
  444.         cmp     esi, ecx
  445.         jb      .noext
  446.         cmp     byte [esi], '.'
  447.         jnz     @b
  448.         inc     esi
  449.         mov     ecx, [esi]
  450.         or      ecx, 0x202020
  451.         cmp     ecx, 'jpg'
  452.         jz      .copy
  453.         cmp     ecx, 'bmp'
  454.         jz      .copy
  455.         cmp     ecx, 'gif'
  456.         jz      .copy
  457.         cmp     ecx, 'png'
  458.         jz      .copy
  459.         cmp     ecx, 'jpe'
  460.         jz      .copy
  461.         cmp     ecx, 'jpeg'
  462.         jz      @f
  463.         cmp     ecx, 'jpeG'
  464.         jnz     .nocopy
  465. @@:
  466.         cmp     byte [esi+4], 0
  467.         jnz     .nocopy
  468. .copy:
  469.         mov     esi, [esp]
  470.         mov     ecx, 304 / 4
  471.         rep     movsd
  472.         inc     dword [esp+4]
  473. .nocopy:
  474. .noext:
  475.         pop     eax
  476.         add     eax, 304
  477.         dec     ebx
  478.         jnz     .dirskip
  479.         mov     eax, [directory_ptr]
  480.         pop     ebx
  481.         mov     [eax+4], ebx
  482.         test    ebx, ebx
  483.         jz      free_directory
  484.         push    0       ; sort mode
  485.         push    ebx
  486.         add     eax, 32
  487.         push    eax
  488.         call    [SortDir]
  489.         xor     eax, eax
  490.         mov     edi, [directory_ptr]
  491.         add     edi, 32 + 40
  492. .scan:
  493.         mov     esi, [last_name_component]
  494.         inc     esi
  495.         push    edi
  496.         invoke  strcmpi
  497.         pop     edi
  498.         jz      .found
  499.         inc     eax
  500.         add     edi, 304
  501.         dec     ebx
  502.         jnz     .scan
  503.         or      eax, -1
  504. .found:
  505.         mov     [cur_file_idx], eax
  506. .ret:
  507.         ret
  508.  
  509. free_directory:
  510.         mcall   68, 13, [directory_ptr]
  511.         and     [directory_ptr], 0
  512.         ret
  513.  
  514. draw_window:
  515.         mcall   48, 4
  516.         mov     ebp, eax        ; save skin height
  517.         add     eax, [wnd_height]
  518.         __mov   ebx, 100, 0
  519.         add     ebx, [wnd_width]
  520.         lea     ecx, [100*65536 + eax]
  521.         mcall   0, , , 0x73FFFFFF, , s_header
  522.  
  523.         mcall   9, procinfo, -1
  524.  
  525.         mov     ebx, [procinfo + 62]
  526.         inc     ebx
  527.         mcall   13, , <0, 35>, 0xFFFFFF
  528.         mov     ecx, [procinfo + 66]
  529.         sub     ecx, 4
  530.         shl     ecx, 16
  531.         mov     cl, 5
  532.         mcall
  533.         mov     cl, 35
  534.         ror     ecx, 16
  535.         sub     cx, 35
  536.         mov     ebx, 5
  537.         mcall
  538. ; 5 pixels for indentation, [image.Width] pixels for image
  539. ; client_width - 5 - [image.Width] pixels must be white
  540.         mov     ebx, [image]
  541.         mov     esi, [procinfo + 62]
  542.         inc     esi
  543.         push    esi
  544.         mov     ebx, [ebx + Image.Width]
  545.         sub     esi, 5
  546.         sub     esi, ebx
  547.         pop     ebx
  548.         sub     ebx, esi
  549.         shl     ebx, 16
  550.         add     ebx, esi
  551.         mcall
  552.  
  553.         mov     ebx, [procinfo + 62]
  554.         push    ebx
  555.         mcall   38, , <30, 30>, 0x007F7F7F
  556.         mcall   , <5 + 25 * 1, 5 + 25 * 1>, <0, 30>
  557.         mcall   , <10 + 25 * 3, 10 + 25 * 3>
  558.         mcall   , <15 + 25 * 4, 15 + 25 * 4>
  559.         pop     ebx
  560.         sub     ebx, 25 * 5 + 10
  561.         push    ebx
  562.         imul    ebx, 10001h
  563.         mcall
  564.  
  565.         mcall   8, <5 + 25 * 0, 20>, <5, 20>, 'opn'+40000000h
  566.         mcall   , <10 + 25 * 1, 20>, , 'bck'+40000000h
  567.         mcall   , <10 + 25 * 2, 20>, , 'fwd'+40000000h
  568.         mcall   , <15 + 25 * 3, 20>, , 'bgr'+40000000h
  569.         pop     ebx
  570.         add     ebx, 5
  571.         shl     ebx, 16
  572.         mov     bl, 20
  573.         mcall   , , , 'flh'+40000000h
  574.         add     ebx, 25 * 65536
  575.         mcall   , , , 'flv'+40000000h
  576.         add     ebx, 30 * 65536
  577.         mcall   , , , 'rtr'+40000000h
  578.         add     ebx, 25 * 65536
  579.         mcall   , , , 'rtl'+40000000h
  580.         add     ebx, 25 * 65536
  581.         mcall   , , , 'flb'+40000000h
  582.  
  583.         mov     ebp, (numimages-1)*20
  584.  
  585.         mcall   65, buttons+openbtn*20, <20, 20>, <5 + 25 * 0, 5>, 8, palette
  586.         mcall   , buttons+backbtn*20, , <10 + 25 * 1, 5>
  587.         mcall   , buttons+forwardbtn*20, , <10 + 25 * 2, 5>
  588.         mcall   , buttons+bgrbtn*20, , <15 + 25 * 3, 5>
  589.         mov     edx, [procinfo + 62]
  590.         sub     edx, 25 * 5 + 4
  591.         shl     edx, 16
  592.         mov     dl, 5
  593.         mcall   , buttons+fliphorzbtn*20
  594.         add     edx, 25 * 65536
  595.         mcall   , buttons+flipvertbtn*20
  596.         add     edx, 30 * 65536
  597.         mcall   , buttons+rotcwbtn*20
  598.         add     edx, 25 * 65536
  599.         mcall   , buttons+rotccwbtn*20
  600.         add     edx, 25 * 65536
  601.         mcall   , buttons+rot180btn*20
  602.  
  603.         mov     ebx, [image]
  604.         mov     ecx, [ebx + Image.Width]
  605.         shl     ecx, 16
  606.         add     ecx, [ebx + Image.Height]
  607.         __mov   edx, 5, 35
  608.         mov     esi, 8
  609.         cmp     [ebx + Image.Type], Image.bpp8
  610.         jz      @f
  611.         mov     esi, 24
  612.         cmp     [ebx + Image.Type], Image.bpp24
  613.         jz      @f
  614.         mov     esi, 32
  615. @@:
  616.         mov     edi, [ebx + Image.Palette]
  617.         mov     ebx, [ebx + Image.Data]
  618.         xor     ebp, ebp
  619.         mcall   65
  620.  
  621.         ret
  622.  
  623. ; void* __stdcall mem.Alloc(unsigned size);
  624. mem.Alloc:
  625.         push    ebx ecx
  626.         mov     ecx, [esp+12]
  627.         mcall   68, 12
  628.         pop     ecx ebx
  629.         ret     4
  630.  
  631. ; void* __stdcall mem.ReAlloc(void* mptr, unsigned size);
  632. mem.ReAlloc:
  633.         push    ebx ecx edx
  634.         mov     edx, [esp+16]
  635.         mov     ecx, [esp+20]
  636.         mcall   68, 20
  637.         pop     edx ecx ebx
  638.         ret     8
  639.  
  640. ; void __stdcall mem.Free(void* mptr);
  641. mem.Free:
  642.         push    ebx ecx
  643.         mov     ecx, [esp+12]
  644.         mcall   68, 13
  645.         pop     ecx ebx
  646.         ret     4
  647.  
  648. ;-----------------------------------------------------------------------------
  649.  
  650. s_header db 'Kolibri Image Viewer', 0
  651.  
  652. ;-----------------------------------------------------------------------------
  653.  
  654. opendialog:
  655. ;
  656. ; STEP 1 Run SYSXTREE with parametrs MYPID 4 bytes in dec,
  657. ; 1 byte space, 1 byte type of dialog (O - Open ,S - Save)
  658. ;
  659.  
  660. ;;    mov esi,path
  661.     mov edi,path
  662.     xor eax,eax
  663.     mov ecx,(1024+16)/4
  664.     rep stosd
  665.  
  666. ;mov [get_loops],0
  667. mov [dlg_pid_get],0
  668.  
  669. ; Get my PID in dec format 4 bytes
  670.     mov eax,9
  671.     mov ebx,procinfo
  672.     or  ecx,-1
  673.     mcall
  674.  
  675. ; convert eax bin to param dec
  676.     mov eax,dword [procinfo+30]  ;offset of myPID
  677.     mov edi,param+4-1            ;offset to 4 bytes
  678.     mov ecx,4
  679.     mov ebx,10
  680. new_d:
  681.     xor edx,edx
  682.     div ebx
  683.     add dl,'0'
  684.     mov [edi],dl
  685.     dec edi
  686.     loop new_d
  687.  
  688. ; wirite 1 byte space to param
  689.     mov [param+4],byte 32    ;Space for next parametr
  690. ; and 1 byte type of dialog to param
  691.     mov [param+5],byte 'O'   ;Get Open dialog (Use 'S' for Save dialog)
  692.  
  693. ;
  694. ; STEP2 prepare IPC area for get messages
  695. ;
  696.  
  697. ; prepare IPC area
  698.     mov [path],dword 0
  699.     mov [path+4],dword 8
  700.  
  701. ; define IPC memory
  702.     mov eax,60
  703.     mov ebx,1        ; define IPC
  704.     mov ecx,path     ; offset of area
  705.     mov edx,1024+16  ; size
  706.     mcall
  707.  
  708. ; change wanted events list 7-bit IPC event
  709.     mov eax,40
  710.     mov ebx,01000111b
  711.         cmp     [image], 0
  712.         jnz     @f
  713.         mov     bl, 01000110b
  714. @@:
  715.     mcall
  716.  
  717. ;
  718. ; STEP 3 run SYSTEM XTREE with parameters
  719. ;
  720.  
  721.     mov eax,70
  722.     mov ebx,run_fileinfo
  723.     mcall
  724.  
  725.     mov [get_loops],0
  726. getmesloop:
  727.     mov eax,23
  728.     mov ebx,50     ;0.5 sec
  729.     mcall
  730.         dec     eax
  731.         jz      mred
  732.         dec     eax
  733.         jz      mkey
  734.         dec     eax
  735.         jz      mbutton
  736.         cmp     al, 7-3
  737.         jz      mgetmes
  738.  
  739. ; Get number of procces
  740.     mov ebx,procinfo
  741.     mov ecx,-1
  742.     mov eax,9
  743.     mcall
  744.     mov ebp,eax
  745.  
  746. loox:
  747.     mov eax,9
  748.     mov ebx,procinfo
  749.     mov ecx,ebp
  750.     mcall
  751.     mov eax,[DLGPID]
  752.     cmp [procinfo+30],eax    ;IF Dialog find
  753.     je  dlg_is_work          ;jmp to dlg_is_work
  754.     dec ebp
  755.     jnz loox
  756.  
  757.     jmp erroff
  758.  
  759. dlg_is_work:
  760.     cmp [procinfo+50],word 9 ;If slot state 9 - dialog is terminated
  761.     je  erroff                 ;TESTODP2 terminated too
  762.  
  763.     cmp [dlg_pid_get],dword 1
  764.     je  getmesloop
  765.     inc [get_loops]
  766.     cmp [get_loops],4  ;2 sec if DLG_PID not get, TESTOP2  terminated
  767.     jae erroff
  768.     jmp getmesloop
  769.  
  770. mred:
  771.         cmp     [image], 0
  772.         jz      getmesloop
  773.     call draw_window
  774.     jmp  getmesloop
  775. mkey:
  776.     mov  eax,2
  777.     mcall                       ; read (eax=2)
  778.     jmp  getmesloop
  779. mbutton:
  780.     mov  eax,17                 ; get id
  781.     mcall
  782.     cmp  ah,1                   ; button id=1 ?
  783.     jne  getmesloop
  784.     mov  eax,-1                 ; close this program
  785.     mcall
  786. mgetmes:
  787.  
  788. ; If dlg_pid_get then second message get jmp to still
  789.     cmp  [dlg_pid_get],dword 1
  790.     je   ready
  791.  
  792. ; First message is number of PID SYSXTREE dialog
  793.  
  794. ; convert PID dec to PID bin
  795.     movzx eax,byte [path+16]
  796.     sub eax,48
  797.     imul eax,10
  798.     movzx ebx,byte [path+16+1]
  799.     add eax,ebx
  800.     sub eax,48
  801.     imul eax,10
  802.     movzx ebx,byte [path+16+2]
  803.     add eax,ebx
  804.     sub eax,48
  805.     imul eax,10
  806.     movzx ebx,byte [path+16+3]
  807.     add eax,ebx
  808.     sub eax,48
  809.     mov [DLGPID],eax
  810.  
  811. ; Claear and prepare IPC area for next message
  812.     mov [path],dword 0
  813.     mov [path+4],dword 8
  814.     mov [path+8],dword 0
  815.     mov [path+12],dword 0
  816.     mov [path+16],dword 0
  817.  
  818. ; Set dlg_pid_get for get next message
  819.     mov [dlg_pid_get],dword 1
  820.         cmp     [image], 0
  821.         jz      getmesloop
  822.     call draw_window
  823.     jmp  getmesloop
  824.  
  825. ready:
  826. ;
  827. ; The second message get
  828. ; Second message is 100 bytes path to SAVE/OPEN file
  829. ; shl path string on 16 bytes
  830. ;
  831.     mov esi,path+16
  832.     mov edi,path
  833.     mov ecx,1024/4
  834.     rep movsd
  835.     mov [edi],byte 0
  836.  
  837. openoff:
  838.         mcall   40, 7
  839.         clc
  840.         ret
  841.  
  842. erroff:
  843.         mcall   40, 7
  844.         stc
  845.         ret
  846.  
  847. ;-----------------------------------------------------------------------------
  848.  
  849. align 4
  850. @IMPORT:
  851.  
  852. library                         \
  853.         libio  , 'libio.obj'  , \
  854.         libgfx , 'libgfx.obj' , \
  855.         libimg , 'libimg.obj' , \
  856.         sort   , 'sort.obj'
  857.  
  858. import  libio                     , \
  859.         libio.init , 'lib_init'   , \
  860.         file.size  , 'file.size'  , \
  861.         file.open  , 'file.open'  , \
  862.         file.read  , 'file.read'  , \
  863.         file.close , 'file.close'
  864.  
  865. import  libgfx                          , \
  866.         libgfx.init   , 'lib_init'      , \
  867.         gfx.open      , 'gfx.open'      , \
  868.         gfx.close     , 'gfx.close'     , \
  869.         gfx.pen.color , 'gfx.pen.color' , \
  870.         gfx.line      , 'gfx.line'
  871.  
  872. import  libimg                     , \
  873.         libimg.init , 'lib_init'   , \
  874.         img.is_img  , 'img.is_img' , \
  875.         img.to_rgb2 , 'img.to_rgb2', \
  876.         img.decode  , 'img.decode' , \
  877.         img.flip    , 'img.flip'   , \
  878.         img.rotate  , 'img.rotate' , \
  879.         img.destroy , 'img.destroy'
  880.  
  881. import  sort, sort.START, 'START', SortDir, 'SortDir', strcmpi, 'strcmpi'
  882.  
  883. ;-----------------------------------------------------------------------------
  884.  
  885. virtual at 0
  886. file 'kivicons.bmp':0xA,4
  887. load offbits dword from 0
  888. end virtual
  889. numimages = 9
  890. openbtn = 0
  891. backbtn = 1
  892. forwardbtn = 2
  893. bgrbtn = 3
  894. fliphorzbtn = 4
  895. flipvertbtn = 5
  896. rotcwbtn = 6
  897. rotccwbtn = 7
  898. rot180btn = 8
  899.  
  900. palette:
  901.         file 'kivicons.bmp':0x36,offbits-0x36
  902. buttons:
  903.         file 'kivicons.bmp':offbits
  904. repeat 10
  905. y = % - 1
  906. z = 20 - %
  907. repeat numimages*5
  908. load a dword from $ - numimages*20*20 + numimages*20*y + (%-1)*4
  909. load b dword from $ - numimages*20*20 + numimages*20*z + (%-1)*4
  910. store dword a at $ - numimages*20*20 + numimages*20*z + (%-1)*4
  911. store dword b at $ - numimages*20*20 + numimages*20*y + (%-1)*4
  912. end repeat
  913. end repeat
  914.  
  915. ; DATA AREA
  916. get_loops   dd 0
  917. dlg_pid_get dd 0
  918. DLGPID      dd 0
  919.  
  920. param:
  921.    dd 0    ; My dec PID
  922.    dd 0,0  ; Type of dialog
  923.  
  924. run_fileinfo:
  925.  dd 7
  926.  dd 0
  927.  dd param
  928.  dd 0
  929.  dd 0
  930. ;run_filepath
  931.  db '/sys/SYSXTREE',0
  932.  
  933. readdir_fileinfo:
  934.         dd      1
  935.         dd      0
  936.         dd      0
  937. readblocks dd   0
  938. directory_ptr   dd      0
  939.  
  940. ;-----------------------------------------------------------------------------
  941.  
  942. I_END:
  943.  
  944. curdir          rb      1024
  945.  
  946. align 4
  947. img_data     dd ?
  948. img_data_len dd ?
  949. fh           dd ?
  950. image        dd ?
  951. wnd_width       dd      ?
  952. wnd_height      dd      ?
  953. last_name_component     dd      ?
  954. cur_file_idx    dd      ?
  955.  
  956. ctx dd ?
  957.  
  958. procinfo:       rb      1024
  959. path:           rb      1024+16
  960.  
  961. @PARAMS rb 512
  962.