Subversion Repositories Kolibri OS

Rev

Rev 4874 | Blame | Compare with Previous | Last modification | View Log | RSS feed

  1.  
  2. STACK_SIZE  equ 4096
  3.  
  4. include "include/app.inc"
  5.  
  6. align 8
  7. main:
  8. .argc   equ     ebp+8
  9. .argv   equ     ebp+12
  10. .envp   equ     ebp+16
  11.  
  12.      ;   int3
  13.         push    ebp
  14.         mov     ebp, esp
  15.         push    ebx
  16.  
  17.         mov     eax, [.argc]
  18.         cmp     eax, 2
  19.         jae     @F
  20.  
  21.         call    _get_moviefile
  22.         mov     [input_file], eax
  23.  
  24. @@:
  25.         call    [mpg123_init]
  26.         test    eax, eax
  27.         jz      @F
  28.  
  29.         push    eax
  30.         call    [mpg123_plain_strerror]
  31.  
  32.         mov     [esp], eax
  33.         push    msg_init_fail
  34.         call    [_printf]
  35.         add     esp, 4
  36.         jmp     .fail
  37. @@:
  38.         push    dword error
  39.         push    0
  40.         call    [mpg123_new]
  41.         add     esp, 8
  42.  
  43.         mov     [mh], eax
  44.         mov     ebx, eax
  45.         test    eax, eax
  46.         jz      .err_1
  47.  
  48.         push    [input_file]
  49.         push    eax
  50.         call    [mpg123_open]
  51.         add     esp, 8
  52.  
  53.         test    eax, eax
  54.         jnz     .err_1
  55.  
  56.         push    encoding
  57.         push    channels
  58.         push    rate
  59.         push    ebx
  60.         call    [mpg123_getformat]
  61.         add     esp, 16
  62.  
  63.         test    eax, eax
  64.         jnz     .err_1
  65.  
  66.         push    ebx
  67.         call    [mpg123_scan]
  68.         test    eax, eax
  69.         jz      @F
  70.  
  71.         call    [mpg123_strerror]
  72.         mov     [esp], eax
  73.         push    msg_print
  74.         call    [_printf]
  75.         add     esp, 8
  76.         jmp     .fail
  77.  
  78. @@:
  79.         call    [mpg123_format_none]
  80.         mov     ecx, [encoding]
  81.         mov     [esp], ecx
  82.         push    [channels]
  83.         push    [rate]
  84.         push    ebx
  85.         call    [mpg123_format]
  86.         add     esp, 16
  87.  
  88.         push    error
  89.         stdcall InitSound
  90.         test    eax, eax
  91.         jz      @F
  92.  
  93.         cinvoke _printf, msg_sound
  94.         jmp     .fail
  95. @@:
  96.         mov     eax, [rate]
  97.         mov     ecx, [channels]
  98.  
  99.         mov     [whdr.riff_id], 0x46464952
  100.         mov     [whdr.riff_format], 0x45564157
  101.         mov     [whdr.wFormatTag], 0x01
  102.         mov     [whdr.nSamplesPerSec], eax
  103.         mov     [whdr.nChannels], cx
  104.         mov     [whdr.wBitsPerSample], 16
  105.  
  106.         stdcall test_wav, whdr
  107.         stdcall CreateBuffer, eax, 0, hBuff
  108.         test    eax, eax
  109.         jz      @F
  110.  
  111.         cinvoke _printf, msg_buffer
  112.         jmp     .fail
  113. @@:
  114.         mov     eax, [hBuff]
  115.         push    esi
  116.         push    edi
  117.  
  118.         mov     ecx, 0x40000
  119.         mov     eax, 68
  120.         mov     ebx, 12
  121.         int     0x40
  122.  
  123.         push    eax                  ;buffer esp+16
  124.         push    count                ;&count esp+12
  125.         push    0x40000              ;remain esp+8
  126.         push    eax                  ;outPtr esp+4
  127.         push    [mh]                 ;mh     esp
  128.  
  129.         xor     ebx, ebx             ;totalcount
  130.  
  131. .inner:
  132.     ;    int3
  133.         mov     [count], 0
  134.         call    [mpg123_read]
  135.         mov     ebx, [count]
  136.         test    eax, eax
  137.         jz      @F
  138.         test    ebx, ebx
  139.         jz      .done
  140. @@:
  141. .write_out:
  142.         add     ebx, 4095
  143.         and     ebx, -4096
  144.         mov     esi, [esp+16]
  145.         stdcall WaveOut, [hBuff], esi, ebx
  146.         mov     [esp+8], dword 0x40000
  147.         mov     edi, [esp+16]
  148.         mov     [esp+4], edi
  149.         jmp     .inner
  150. .done:
  151.         mov     edi, [esp+16]
  152.         mov     ecx, 4096
  153.         xor     eax, eax
  154.         rep     stosd
  155.         mov     esi, [esp+16]
  156.         stdcall WaveOut, [hBuff], esi, 16384
  157.         add     esp, 20
  158.         pop     edi
  159.         pop     esi
  160.  
  161.         xor     eax, eax
  162.         pop     ebx
  163.         mov     esp, ebp
  164.         pop     ebp
  165.         ret
  166.  
  167. .err_1:
  168.         test    ebx, ebx
  169.         jnz     @F
  170.  
  171.         push    [error]
  172.         call    [mpg123_plain_strerror]
  173.         jmp     .err_2
  174. @@:
  175.         push    ebx
  176.         call    [mpg123_strerror]
  177. .err_2:
  178.         mov     [esp], eax
  179.         push    msg_trouble
  180.         call    [_printf]
  181.         add     esp, 8
  182. .fail:
  183.         mov     eax, -1
  184.         pop     ebx
  185.         mov     esp, ebp
  186.         pop     ebp
  187.         ret
  188.  
  189. align 4
  190. getprocaddress:
  191.         mov     edx, [esp + 8] ; hlib
  192.         xor     eax, eax
  193.         test    edx, edx ; If hlib = 0 then goto .end
  194.         jz      .end
  195.  
  196. .next:
  197.         cmp     [edx], dword 0 ; If end of export table then goto .end
  198.         jz      .end
  199.  
  200.         xor     eax, eax
  201.         mov     esi, [edx]
  202.         mov     edi, [esp + 4] ; name
  203.  
  204. .next_:
  205.         lodsb
  206.         scasb
  207.         jne     .fail
  208.         or      al, al
  209.         jnz     .next_
  210.         jmp     .ok
  211. .fail:
  212.         add     edx, 8
  213.         jmp     .next
  214.  
  215. .ok:                  ; return address
  216.         mov eax, [edx + 4]
  217. .end:
  218.         ret 8
  219.  
  220.  
  221. align 8
  222. _get_moviefile:
  223.  
  224.         pushad
  225.         mov     eax, 68
  226.         mov     ebx, 19
  227.         mov     ecx, sz_proc_lib
  228.         int     0x40
  229.         mov     [proclib], eax
  230.         test    eax, eax
  231.         jz      .fail
  232.  
  233.         push    [proclib]
  234.         push    sz_OpenDialog_init
  235.         call    getprocaddress
  236.         mov     [opendialog_init], eax
  237.  
  238.         push    dword[proclib]
  239.         push    sz_OpenDialog_start
  240.         call    getprocaddress
  241.         mov     [opendialog_start], eax
  242.  
  243.         mov     eax, 68
  244.         mov     ebx, 12
  245.         mov     ecx, 4096*3
  246.         int     0x40
  247.  
  248.         mov     [od.procinfo], eax
  249.  
  250.         add     eax, 1024
  251.         mov     [od.filename_area], eax
  252.  
  253.         add     eax, 3072
  254.         mov     [od.opendir_path], eax
  255.  
  256.         add     eax, 4096
  257.         mov     [od.openfile_path], eax
  258.  
  259.         push    od
  260.         call    [opendialog_init]
  261.  
  262.         mov     eax, [od.openfile_path]
  263.         mov     [eax], byte 0          ; end of ASCIIZ-string(may be don't need?)
  264.  
  265.         push    od
  266.         call    [opendialog_start]
  267.  
  268.         popad
  269.         mov     eax, [od.openfile_path]; selected filePath
  270.  
  271.         ret
  272. .fail:
  273.         xor     eax, eax
  274.         ret
  275.  
  276. align 4
  277. fake_on_redraw:
  278.         ret
  279.  
  280.  
  281. SRV_GETVERSION      equ 0
  282. SND_CREATE_BUFF     equ 1
  283. SND_DESTROY_BUFF    equ 2
  284. SND_SETFORMAT       equ 3
  285. SND_GETFORMAT       equ 4
  286. SND_RESET           equ 5
  287. SND_SETPOS          equ 6
  288. SND_GETPOS          equ 7
  289. SND_SETBUFF         equ 8
  290. SND_OUT             equ 9
  291. SND_PLAY            equ 10
  292. SND_STOP            equ 11
  293. SND_SETVOLUME       equ 12
  294. SND_GETVOLUME       equ 13
  295. SND_SETPAN          equ 14
  296. SND_GETPAN          equ 15
  297. SND_GETBUFFSIZE     equ 16
  298. SND_GETFREESPACE    equ 17
  299. SND_SETTIMEBASE     equ 18
  300. SND_GETTIMESTAMP    equ 19
  301.  
  302.  
  303. align 4
  304. InitSound:       ;p_ver:dword
  305.  
  306.            push ebx
  307.            push ecx
  308.  
  309.            mov eax, 68
  310.            mov ebx, 16
  311.            mov ecx, szInfinity
  312.            int 0x40
  313.            mov [hSound], eax
  314.            test eax, eax
  315.            jz .fail
  316.  
  317.            mov eax, 68
  318.            mov ebx, 16
  319.            mov ecx, szSound
  320.            int 0x40
  321.            mov [hrdwSound], eax
  322.  
  323.            lea eax, [esp+12]   ;p_ver
  324.            xor ebx, ebx
  325.  
  326.            push 4              ;.out_size
  327.            push eax            ;.output
  328.            push ebx            ;.inp_size
  329.            push ebx            ;.input
  330.            push SRV_GETVERSION ;.code
  331.            push [hSound]       ;.handle
  332.  
  333.            mov eax, 68
  334.            mov ebx, 17
  335.            mov ecx, esp        ;[handle]
  336.            int 0x40
  337.            add esp, 24
  338.            pop ecx
  339.            pop ebx
  340.            ret 4
  341. .fail:
  342.            or eax, -1
  343.            pop ecx
  344.            pop ebx
  345.            ret 4
  346.  
  347.  
  348. align 4
  349. CreateBuffer:   ;format:dword,size:dword,p_str:dword
  350.  
  351.            push ebx
  352.            push ecx
  353.            lea eax, [esp+20]   ;p_str
  354.            lea ebx, [esp+12]   ;format
  355.  
  356.            push 4              ;.out_size
  357.            push eax            ;.output
  358.            push 8              ;.inp_size
  359.            push ebx            ;.input
  360.            push SND_CREATE_BUFF;.code
  361.            push [hSound]       ;.handle
  362.  
  363.            mov eax, 68
  364.            mov ebx, 17
  365.            mov ecx, esp
  366.            int 0x40
  367.            add esp, 24       ;io_cintrol
  368.            pop ecx
  369.            pop ebx
  370.            ret 12
  371.  
  372. align 4
  373. proc test_wav stdcall, hdr:dword
  374.  
  375.            mov eax, [hdr]
  376.            cmp dword [eax], 0x46464952
  377.            jne .fail
  378.  
  379.            cmp dword [eax+8], 0x45564157
  380.            jne .fail
  381.  
  382.            cmp word [eax+20], 1
  383.            jne .fail
  384.  
  385.            mov ecx, dword [eax+24]
  386.            mov edx, 22050
  387.            cmp ecx, edx
  388.            ja .high
  389.            je .l_22
  390.  
  391.            cmp ecx, 8000
  392.            je .l_8
  393.  
  394.            cmp ecx, 11025
  395.            je .l_11
  396.  
  397.            cmp ecx, 12000
  398.            je .l_12
  399.  
  400.            cmp ecx, 16000
  401.            je .l_16
  402. .fail:
  403.            xor eax, eax
  404.            ret
  405. .high:
  406.            cmp ecx, 24000
  407.            je .LN56
  408.            cmp ecx, 32000
  409.            je .LN65
  410.            cmp ecx, 44100
  411.            je .LN74
  412.            cmp ecx, 48000
  413.            jne .fail
  414.  
  415.            movzx ecx, word [eax+22]
  416.            dec ecx
  417.            je .LN79
  418.            dec ecx
  419.            jne .LN74
  420.  
  421.            mov edx, 19
  422.            jmp .done
  423. .LN79:
  424.            mov edx, 20
  425.            jmp .done
  426. .LN74:
  427.            movzx ecx, word [eax+22]
  428.            dec ecx
  429.            je .LN70
  430.            dec ecx
  431.            jne .LN65
  432.  
  433.            mov edx, 21
  434.            jmp .done
  435. .LN70:
  436.            mov edx, 22
  437.            jmp .done
  438. .LN65:
  439.            movzx ecx, word [eax+22]
  440.            dec ecx
  441.            je .LN61
  442.            dec ecx
  443.            jne .LN56
  444.  
  445.            mov edx, 23
  446.            jmp .done
  447. .LN61:
  448.            mov edx, 24
  449.            jmp .done
  450. .LN56:
  451.            movzx ecx, word [eax+22]
  452.            dec ecx
  453.            je .LN52
  454.            dec ecx
  455.            je .LN50
  456. .l_22:
  457.            movzx ecx, word [eax+22]
  458.            dec ecx
  459.            je .LN43
  460.            dec ecx
  461.            je .LN41
  462. .l_16:
  463.            movzx ecx, word [eax+22]
  464.            dec ecx
  465.            je .LN34
  466.            dec ecx
  467.            je .LN32
  468. .l_12:
  469.            movzx ecx, word [eax+22]
  470.            dec ecx
  471.            je .LN25
  472.            dec ecx
  473.            je .LN23
  474. .l_11:
  475.            movzx ecx, word [eax+22]
  476.            dec ecx
  477.            je .LN16
  478.            dec ecx
  479.            je .LN14
  480. .l_8:
  481.            movzx ecx, word [eax+22]
  482.            dec ecx
  483.            je .LN7
  484.            dec ecx
  485.            jne .fail
  486.  
  487.            mov edx, 35
  488.            jmp .done
  489. .LN7:
  490.            mov edx, 36
  491.            jmp .done
  492. .LN14:
  493.            mov edx, 33
  494.            jmp .done
  495. .LN16:
  496.            mov edx, 34
  497.            jmp .done
  498. .LN23:
  499.            mov edx, 31
  500.            jmp .done
  501. .LN25:
  502.            mov edx, 32
  503.            jmp .done
  504. .LN32:
  505.            mov edx, 29
  506.            jmp .done
  507. .LN34:
  508.            mov edx, 30
  509.            jmp .done
  510. .LN41:
  511.            mov edx, 27
  512.            jmp .done
  513. .LN43:
  514.            mov edx, 28
  515.            jmp .done
  516. .LN50:
  517.            mov edx, 25
  518.            jmp .done
  519. .LN52:
  520.            mov edx, 26
  521. .done:
  522.            xor ecx, ecx
  523.            cmp word [eax+34], 16
  524.            setne cl
  525.            dec ecx
  526.            and ecx, -18
  527.            add ecx, edx
  528.            mov eax, ecx
  529.            ret
  530. endp
  531.  
  532. align 4
  533. WaveOut:        ;str:dword, src:dword, size:dword
  534.            push ebx
  535.            push ecx
  536.  
  537.            xor eax, eax
  538.            lea ebx, [esp+12]   ;[stream]
  539.  
  540.            push eax            ;.out_size
  541.            push eax            ;.output
  542.            push 12             ;.inp_size
  543.            push ebx            ;.input
  544.            push SND_OUT        ;.code
  545.            push dword [hSound] ;.handle
  546.  
  547.            mov eax, 68
  548.            mov ebx, 17
  549.            mov ecx, esp
  550.            int 0x40
  551.            add esp, 24
  552.            pop ecx
  553.            pop ebx
  554.            ret 12
  555.  
  556. align 4
  557. hSound      dd ?
  558. hrdwSound   dd ?
  559.  
  560. szInfinity  db 'INFINITY',0
  561. szSound     db 'SOUND',0
  562.  
  563. align 4
  564. od:
  565.     .mode             dd 0
  566.     .procinfo         dd 0
  567.     .com_area_name    dd sz_com_area_name
  568.     .com_area         dd 0
  569.     .opendir_path     dd 0
  570.     .dir_default_path dd sz_dir_default_path
  571.     .start_path       dd sz_start_path
  572.     .draw_window      dd fake_on_redraw
  573.     .status           dd 0
  574.     .openfile_path    dd 0
  575.     .filename_area    dd 0
  576.     .filter_area      dd filefilter
  577.     .x_size           dw 512
  578.     .x_start          dw 512
  579.     .y_size           dw 512
  580.     .y_start          dw 512
  581.  
  582. filefilter:
  583. dd filefilter.end - filefilter
  584.     db 'mp3',0
  585. ;    db 'flv',0
  586. ;    db 'mov',0
  587. ;    db 'mpg',0
  588. ;    db 'mpeg',0
  589. ;    db 'mkv',0
  590. ;    db 'mp4',0
  591. ;    db 'webm',0
  592. ;    db 'wmv',0
  593. .end:
  594.     db 0
  595.  
  596.  
  597.  
  598.  
  599. sz_proc_lib         db "/sys/lib/proc_lib.obj",0
  600. sz_OpenDialog_init  db "OpenDialog_init",0
  601. sz_OpenDialog_start db "OpenDialog_start",0
  602. sz_com_area_name    db "FFFFFFFF_open_dialog",0
  603. sz_dir_default_path db "/sys",0
  604. sz_start_path       db "/sys/File managers/opendial",0
  605.  
  606. msg_print       db '%s',0x0D,0x0A,0
  607. msg_init_fail   db 'Cannot initialize mpg123 library: %s', 0x0D,0x0A,0
  608. msg_trouble     db 'Trouble with mpg123: %s', 0x0D,0x0A,0
  609. msg_sound       db 'Sound service not installed', 0x0D,0x0A,0
  610. msg_buffer      db 'Unable to create a sound buffer',0x0D,0x0A,0
  611.  
  612. align 16
  613. __idata_start:
  614.  
  615.   library libc,'libc.dll',      \
  616.           libmpg123, 'libmpg123.dll'
  617.  
  618. include 'include/libc.inc'
  619. include 'include/libmpg123.inc'
  620.  
  621. __idata_end:
  622. __iend:
  623.  
  624. align 4
  625. whdr:
  626.     .riff_id            rd 1
  627.     .riff_size          rd 1
  628.     .riff_format        rd 1
  629.  
  630.     .fmt_id             rd 1
  631.     .fmt_size           rd 1
  632.  
  633.     .wFormatTag         rw 1
  634.     .nChannels          rw 1
  635.     .nSamplesPerSec     rd 1
  636.     .nAvgBytesPerSec    rd 1
  637.     .nBlockAlign        rw 1
  638.     .wBitsPerSample     rw 1
  639.     .data_id            rd 1
  640.     .data_size          rd 1
  641.  
  642. proclib          rd 1
  643. opendialog_init  rd 1
  644. opendialog_start rd 1
  645.  
  646. input_file rd 1
  647.  
  648. mh         rd 1
  649. encoding   rd 1
  650. channels   rd 1
  651. rate       rd 1
  652.  
  653. hBuff      rd 1
  654. count      rd 1
  655.  
  656. done       rd 1
  657.  
  658. error      rd 1
  659.  
  660.  
  661. __cmdline: rb 256
  662. __pgmname: rb 1024
  663.            rb 16
  664. __stack:
  665. __bssend:
  666.  
  667.  
  668.