Subversion Repositories Kolibri OS

Rev

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