Subversion Repositories Kolibri OS

Rev

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