Subversion Repositories Kolibri OS

Rev

Rev 1143 | Rev 1422 | 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     red
  193.     @@:
  194.         cmp     eax, 'fwd'
  195.         jnz     @f
  196.         call    next_image
  197.         jmp     red
  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], 0
  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, 'ico'
  517.         jz      .copy
  518.         cmp     ecx, 'cur'
  519.         jz      .copy
  520.         cmp     ecx, 'jpeg'
  521.         jz      @f
  522.         cmp     ecx, 'jpeG'
  523.         jnz     .nocopy
  524. @@:
  525.         cmp     byte [esi+4], 0
  526.         jnz     .nocopy
  527. .copy:
  528.         mov     esi, [esp]
  529.         mov     ecx, 304 / 4
  530.         rep     movsd
  531.         inc     dword [esp+4]
  532. .nocopy:
  533. .noext:
  534.         pop     eax
  535.         add     eax, 304
  536.         dec     ebx
  537.         jnz     .dirskip
  538.         mov     eax, [directory_ptr]
  539.         pop     ebx
  540.         mov     [eax+4], ebx
  541.         test    ebx, ebx
  542.         jz      free_directory
  543.         push    0       ; sort mode
  544.         push    ebx
  545.         add     eax, 32
  546.         push    eax
  547.         call    [SortDir]
  548.         xor     eax, eax
  549.         mov     edi, [directory_ptr]
  550.         add     edi, 32 + 40
  551. .scan:
  552.         mov     esi, [last_name_component]
  553.         inc     esi
  554.         push    edi
  555.         invoke  strcmpi
  556.         pop     edi
  557.         jz      .found
  558.         inc     eax
  559.         add     edi, 304
  560.         dec     ebx
  561.         jnz     .scan
  562.         or      eax, -1
  563. .found:
  564.         mov     [cur_file_idx], eax
  565. .ret:
  566.         ret
  567.  
  568. free_directory:
  569.         mcall   68, 13, [directory_ptr]
  570.         and     [directory_ptr], 0
  571.         ret
  572.  
  573. init_frame:
  574.         push    eax
  575.         mov     eax, [image]
  576.         mov     [cur_frame], eax
  577.         test    byte [eax + Image.Flags], Image.IsAnimated
  578.         jz      @f
  579.         push    ebx
  580.         mcall   26, 9
  581.         pop     ebx
  582.         mov     [cur_frame_time], eax
  583. @@:
  584.         pop     eax
  585.         ret
  586.  
  587. draw_window:
  588.         cmp     [bFirstDraw], 0
  589.         jz      .posok
  590.         or      ecx, -1
  591.         mcall   9, procinfo
  592.  
  593.         cmp     dword [ebx + 66], 0
  594.         jle     .posok
  595.  
  596.         mov     edx, ecx
  597.         mov     esi, ecx
  598.         cmp     dword [ebx + 42], 40 + 25 * 9
  599.         jae     @f
  600.         mov     edx, 40 + 25 * 9
  601. @@:
  602.         cmp     dword [ebx + 46], 70
  603.         jae     @f
  604.         mov     esi, 70
  605. @@:
  606.         mov     eax, edx
  607.         and     eax, esi
  608.         cmp     eax, -1
  609.         jz      @f
  610.         mov     ebx, ecx
  611.         mcall   67
  612. @@:
  613.  
  614. .posok:
  615.         mcall   12, 1
  616.         mcall   48, 4
  617.         mov     ebp, eax        ; save skin height
  618.         add     eax, [wnd_height]
  619.         __mov   ebx, 100, 0
  620.         add     ebx, [wnd_width]
  621.         lea     ecx, [100*65536 + eax]
  622.         mcall   0, , , 0x73FFFFFF, , s_header
  623.  
  624.         mcall   9, procinfo, -1
  625.         mov     [bFirstDraw], 1
  626.         cmp     dword [ebx + 66], 0
  627.         jle     .nodraw
  628.         mov     ebx, [ebx + 62]
  629.         inc     ebx
  630.         mcall   13, , <0, 35>, 0xFFFFFF
  631.         mov     ecx, [procinfo + 66]
  632.         inc     ecx
  633.         mov     esi, [draw_height]
  634.         add     esi, 35
  635.         sub     ecx, esi
  636.         jbe     @f
  637.         push    esi
  638.         shl     esi, 16
  639.         add     ecx, esi
  640.         pop     esi
  641.         mcall
  642.         xor     ecx, ecx
  643. @@:
  644.         add     ecx, esi
  645.         add     ecx, 35*10000h - 35
  646.         __mov   ebx, 0, 5
  647.         mcall
  648.         mov     esi, [draw_width]
  649.         add     esi, ebx
  650.         mov     ebx, [procinfo+62]
  651.         inc     ebx
  652.         sub     ebx, esi
  653.         jbe     @f
  654.         shl     esi, 16
  655.         add     ebx, esi
  656.         mcall
  657. @@:
  658.  
  659.         mov     ebx, [procinfo + 62]
  660.         push    ebx
  661.         mcall   38, , <30, 30>, 0x007F7F7F
  662.         mcall   , <5 + 25 * 1, 5 + 25 * 1>, <0, 30>
  663.         mcall   , <10 + 25 * 3, 10 + 25 * 3>
  664.         mcall   , <15 + 25 * 4, 15 + 25 * 4>
  665.         pop     ebx
  666.         sub     ebx, 25 * 5 + 10
  667.         push    ebx
  668.         imul    ebx, 10001h
  669.         mcall
  670.  
  671.         mcall   8, <5 + 25 * 0, 20>, <5, 20>, 'opn'+40000000h
  672.         mcall   , <10 + 25 * 1, 20>, , 'bck'+40000000h
  673.         mcall   , <10 + 25 * 2, 20>, , 'fwd'+40000000h
  674.         mcall   , <15 + 25 * 3, 20>, , 'bgr'+40000000h
  675.         pop     ebx
  676.         add     ebx, 5
  677.         shl     ebx, 16
  678.         mov     bl, 20
  679.         mcall   , , , 'flh'+40000000h
  680.         add     ebx, 25 * 65536
  681.         mcall   , , , 'flv'+40000000h
  682.         add     ebx, 30 * 65536
  683.         mcall   , , , 'rtr'+40000000h
  684.         add     ebx, 25 * 65536
  685.         mcall   , , , 'rtl'+40000000h
  686.         add     ebx, 25 * 65536
  687.         mcall   , , , 'flb'+40000000h
  688.  
  689.         mov     ebp, (numimages-1)*20
  690.  
  691.         mcall   65, buttons+openbtn*20, <20, 20>, <5 + 25 * 0, 5>, 8, palette
  692.         mcall   , buttons+backbtn*20, , <10 + 25 * 1, 5>
  693.         mcall   , buttons+forwardbtn*20, , <10 + 25 * 2, 5>
  694.         mcall   , buttons+bgrbtn*20, , <15 + 25 * 3, 5>
  695.         mov     edx, [procinfo + 62]
  696.         sub     edx, 25 * 5 + 4
  697.         shl     edx, 16
  698.         mov     dl, 5
  699.         mcall   , buttons+fliphorzbtn*20
  700.         add     edx, 25 * 65536
  701.         mcall   , buttons+flipvertbtn*20
  702.         add     edx, 30 * 65536
  703.         mcall   , buttons+rotcwbtn*20
  704.         add     edx, 25 * 65536
  705.         mcall   , buttons+rotccwbtn*20
  706.         add     edx, 25 * 65536
  707.         mcall   , buttons+rot180btn*20
  708.  
  709.         call    draw_cur_frame
  710.  
  711. .nodraw:
  712.         mcall   12, 2
  713.  
  714.         ret
  715.  
  716. draw_cur_frame:
  717.         push    0       ; ypos
  718.         push    0       ; xpos
  719.         mov     eax, [procinfo+66]
  720.         sub     eax, 34
  721.         push    eax     ; max height
  722.         mov     eax, [procinfo+62]
  723.         sub     eax, 4
  724.         push    eax     ; max width
  725.         push    35      ; y
  726.         push    5       ; x
  727.         push    [cur_frame]
  728.         call    [img.draw]
  729.         mov     eax, [image]
  730.         test    [eax + Image.Flags], Image.IsAnimated
  731.         jnz     .done
  732.         cmp     [eax + Image.Next], 0
  733.         jnz     .additional_frames
  734. .done:
  735.         ret
  736. .additional_frames:
  737.         mov     ebx, [procinfo+62]
  738.         sub     ebx, 4
  739.         jbe     .done
  740.         push    5
  741.         pop     esi
  742. .afloop:
  743.         sub     ebx, [eax + Image.Width]
  744.         jbe     .done
  745.         dec     ebx
  746.         jz      .done
  747.         add     esi, [eax + Image.Width]
  748.         mov     eax, [eax + Image.Next]
  749.         push    eax
  750.         inc     esi
  751.         push    0       ; ypos
  752.         push    0       ; xpos
  753.         mov     ecx, [procinfo+66]
  754.         sub     ecx, 34
  755.         push    ecx     ; max height
  756.         push    ebx     ; max width
  757.         push    35      ; y
  758.         push    esi     ; x
  759.         push    eax     ; image
  760.         call    [img.draw]
  761.         pop     eax
  762.         cmp     [eax + Image.Next], 0
  763.         jnz     .afloop
  764.         ret
  765.  
  766. ; void* __stdcall mem.Alloc(unsigned size);
  767. mem.Alloc:
  768.         push    ebx ecx
  769.         mov     ecx, [esp+12]
  770.         mcall   68, 12
  771.         pop     ecx ebx
  772.         ret     4
  773.  
  774. ; void* __stdcall mem.ReAlloc(void* mptr, unsigned size);
  775. mem.ReAlloc:
  776.         push    ebx ecx edx
  777.         mov     edx, [esp+16]
  778.         mov     ecx, [esp+20]
  779.         mcall   68, 20
  780.         pop     edx ecx ebx
  781.         ret     8
  782.  
  783. ; void __stdcall mem.Free(void* mptr);
  784. mem.Free:
  785.         push    ebx ecx
  786.         mov     ecx, [esp+12]
  787.         mcall   68, 13
  788.         pop     ecx ebx
  789.         ret     4
  790.  
  791. ;-----------------------------------------------------------------------------
  792.  
  793. s_header db 'Kolibri Image Viewer', 0
  794.  
  795. ;-----------------------------------------------------------------------------
  796.  
  797. opendialog:
  798. ;
  799. ; STEP 1 Run SYSXTREE with parametrs MYPID 4 bytes in dec,
  800. ; 1 byte space, 1 byte type of dialog (O - Open ,S - Save)
  801. ;
  802.  
  803. ;;    mov esi,path
  804.     mov edi,path
  805.     xor eax,eax
  806.     mov ecx,(1024+16)/4
  807.     rep stosd
  808.  
  809. ;mov [get_loops],0
  810. mov [dlg_pid_get],0
  811.  
  812. ; Get my PID in dec format 4 bytes
  813.     mov eax,9
  814.     mov ebx,procinfo
  815.     or  ecx,-1
  816.     mcall
  817.  
  818. ; convert eax bin to param dec
  819.     mov eax,dword [procinfo+30]  ;offset of myPID
  820.     mov edi,param+4-1            ;offset to 4 bytes
  821.     mov ecx,4
  822.     mov ebx,10
  823. new_d:
  824.     xor edx,edx
  825.     div ebx
  826.     add dl,'0'
  827.     mov [edi],dl
  828.     dec edi
  829.     loop new_d
  830.  
  831. ; wirite 1 byte space to param
  832.     mov [param+4],byte 32    ;Space for next parametr
  833. ; and 1 byte type of dialog to param
  834.     mov [param+5],byte 'O'   ;Get Open dialog (Use 'S' for Save dialog)
  835.  
  836. ;
  837. ; STEP2 prepare IPC area for get messages
  838. ;
  839.  
  840. ; prepare IPC area
  841.     mov [path],dword 0
  842.     mov [path+4],dword 8
  843.  
  844. ; define IPC memory
  845.     mov eax,60
  846.     mov ebx,1        ; define IPC
  847.     mov ecx,path     ; offset of area
  848.     mov edx,1024+16  ; size
  849.     mcall
  850.  
  851. ; change wanted events list 7-bit IPC event
  852.     mov eax,40
  853.     mov ebx,01000111b
  854.         cmp     [image], 0
  855.         jnz     @f
  856.         mov     bl, 01000110b
  857. @@:
  858.     mcall
  859.  
  860. ;
  861. ; STEP 3 run SYSTEM XTREE with parameters
  862. ;
  863.  
  864.     mov eax,70
  865.     mov ebx,run_fileinfo
  866.     mcall
  867.  
  868.     mov [get_loops],0
  869. getmesloop:
  870.     mov eax,23
  871.     mov ebx,50     ;0.5 sec
  872.     mcall
  873.         dec     eax
  874.         jz      mred
  875.         dec     eax
  876.         jz      mkey
  877.         dec     eax
  878.         jz      mbutton
  879.         cmp     al, 7-3
  880.         jz      mgetmes
  881.  
  882. ; Get number of procces
  883.     mov ebx,procinfo
  884.     mov ecx,-1
  885.     mov eax,9
  886.     mcall
  887.     mov ebp,eax
  888.  
  889. loox:
  890.     mov eax,9
  891.     mov ebx,procinfo
  892.     mov ecx,ebp
  893.     mcall
  894.     mov eax,[DLGPID]
  895.     cmp [procinfo+30],eax    ;IF Dialog find
  896.     je  dlg_is_work          ;jmp to dlg_is_work
  897.     dec ebp
  898.     jnz loox
  899.  
  900.     jmp erroff
  901.  
  902. dlg_is_work:
  903.     cmp [procinfo+50],word 9 ;If slot state 9 - dialog is terminated
  904.     je  erroff                 ;TESTODP2 terminated too
  905.  
  906.     cmp [dlg_pid_get],dword 1
  907.     je  getmesloop
  908.     inc [get_loops]
  909.     cmp [get_loops],4  ;2 sec if DLG_PID not get, TESTOP2  terminated
  910.     jae erroff
  911.     jmp getmesloop
  912.  
  913. mred:
  914.         cmp     [image], 0
  915.         jz      getmesloop
  916.     call draw_window
  917.     jmp  getmesloop
  918. mkey:
  919.     mov  eax,2
  920.     mcall                       ; read (eax=2)
  921.     jmp  getmesloop
  922. mbutton:
  923.     mov  eax,17                 ; get id
  924.     mcall
  925.     cmp  ah,1                   ; button id=1 ?
  926.     jne  getmesloop
  927.     mov  eax,-1                 ; close this program
  928.     mcall
  929. mgetmes:
  930.  
  931. ; If dlg_pid_get then second message get jmp to still
  932.     cmp  [dlg_pid_get],dword 1
  933.     je   ready
  934.  
  935. ; First message is number of PID SYSXTREE dialog
  936.  
  937. ; convert PID dec to PID bin
  938.     movzx eax,byte [path+16]
  939.     sub eax,48
  940.     imul eax,10
  941.     movzx ebx,byte [path+16+1]
  942.     add eax,ebx
  943.     sub eax,48
  944.     imul eax,10
  945.     movzx ebx,byte [path+16+2]
  946.     add eax,ebx
  947.     sub eax,48
  948.     imul eax,10
  949.     movzx ebx,byte [path+16+3]
  950.     add eax,ebx
  951.     sub eax,48
  952.     mov [DLGPID],eax
  953.  
  954. ; Claear and prepare IPC area for next message
  955.     mov [path],dword 0
  956.     mov [path+4],dword 8
  957.     mov [path+8],dword 0
  958.     mov [path+12],dword 0
  959.     mov [path+16],dword 0
  960.  
  961. ; Set dlg_pid_get for get next message
  962.     mov [dlg_pid_get],dword 1
  963.         cmp     [image], 0
  964.         jz      getmesloop
  965.     call draw_window
  966.     jmp  getmesloop
  967.  
  968. ready:
  969. ;
  970. ; The second message get
  971. ; Second message is 100 bytes path to SAVE/OPEN file
  972. ; shl path string on 16 bytes
  973. ;
  974.     mov esi,path+16
  975.     mov edi,path
  976.     mov ecx,1024/4
  977.     rep movsd
  978.     mov [edi],byte 0
  979.  
  980. openoff:
  981.         mcall   40, 7
  982.         clc
  983.         ret
  984.  
  985. erroff:
  986.         mcall   40, 7
  987.         stc
  988.         ret
  989.  
  990. ;-----------------------------------------------------------------------------
  991.  
  992. align 4
  993. @IMPORT:
  994.  
  995. library                         \
  996.         libio  , 'libio.obj'  , \
  997.         libgfx , 'libgfx.obj' , \
  998.         libimg , 'libimg.obj' , \
  999.         sort   , 'sort.obj'
  1000.  
  1001. import  libio                     , \
  1002.         libio.init , 'lib_init'   , \
  1003.         file.size  , 'file_size'  , \
  1004.         file.open  , 'file_open'  , \
  1005.         file.read  , 'file_read'  , \
  1006.         file.close , 'file_close'
  1007.  
  1008. import  libgfx                          , \
  1009.         libgfx.init   , 'lib_init'      , \
  1010.         gfx.open      , 'gfx_open'      , \
  1011.         gfx.close     , 'gfx_close'     , \
  1012.         gfx.pen.color , 'gfx_pen_color' , \
  1013.         gfx.line      , 'gfx_line'
  1014.  
  1015. import  libimg                     , \
  1016.         libimg.init , 'lib_init'   , \
  1017.         img.is_img  , 'img_is_img' , \
  1018.         img.to_rgb2 , 'img_to_rgb2', \
  1019.         img.decode  , 'img_decode' , \
  1020.         img.flip    , 'img_flip'   , \
  1021.         img.rotate  , 'img_rotate' , \
  1022.         img.destroy , 'img_destroy', \
  1023.         img.draw    , 'img_draw'
  1024.  
  1025. import  sort, sort.START, 'START', SortDir, 'SortDir', strcmpi, 'strcmpi'
  1026.  
  1027. bFirstDraw      db      0
  1028. ;-----------------------------------------------------------------------------
  1029.  
  1030. virtual at 0
  1031. file 'kivicons.bmp':0xA,4
  1032. load offbits dword from 0
  1033. end virtual
  1034. numimages = 9
  1035. openbtn = 0
  1036. backbtn = 1
  1037. forwardbtn = 2
  1038. bgrbtn = 3
  1039. fliphorzbtn = 4
  1040. flipvertbtn = 5
  1041. rotcwbtn = 6
  1042. rotccwbtn = 7
  1043. rot180btn = 8
  1044.  
  1045. palette:
  1046.         file 'kivicons.bmp':0x36,offbits-0x36
  1047. buttons:
  1048.         file 'kivicons.bmp':offbits
  1049. repeat 10
  1050. y = % - 1
  1051. z = 20 - %
  1052. repeat numimages*5
  1053. load a dword from $ - numimages*20*20 + numimages*20*y + (%-1)*4
  1054. load b dword from $ - numimages*20*20 + numimages*20*z + (%-1)*4
  1055. store dword a at $ - numimages*20*20 + numimages*20*z + (%-1)*4
  1056. store dword b at $ - numimages*20*20 + numimages*20*y + (%-1)*4
  1057. end repeat
  1058. end repeat
  1059.  
  1060. ; DATA AREA
  1061. get_loops   dd 0
  1062. dlg_pid_get dd 0
  1063. DLGPID      dd 0
  1064.  
  1065. param:
  1066.    dd 0    ; My dec PID
  1067.    dd 0,0  ; Type of dialog
  1068.  
  1069. run_fileinfo:
  1070.  dd 7
  1071.  dd 0
  1072.  dd param
  1073.  dd 0
  1074.  dd 0
  1075. ;run_filepath
  1076.  db '/sys/SYSXTREE',0
  1077.  
  1078. readdir_fileinfo:
  1079.         dd      1
  1080.         dd      0
  1081.         dd      0
  1082. readblocks dd   0
  1083. directory_ptr   dd      0
  1084.  
  1085. ;-----------------------------------------------------------------------------
  1086.  
  1087. I_END:
  1088.  
  1089. curdir          rb      1024
  1090.  
  1091. align 4
  1092. img_data     dd ?
  1093. img_data_len dd ?
  1094. fh           dd ?
  1095. image        dd ?
  1096. wnd_width       dd      ?
  1097. wnd_height      dd      ?
  1098. draw_width      dd      ?
  1099. draw_height     dd      ?
  1100. last_name_component     dd      ?
  1101. cur_file_idx    dd      ?
  1102. cur_frame_time  dd      ?
  1103. cur_frame       dd      ?
  1104.  
  1105. ctx dd ?
  1106.  
  1107. procinfo:       rb      1024
  1108. path:           rb      1024+16
  1109.  
  1110. @PARAMS rb 512
  1111.