Subversion Repositories Kolibri OS

Rev

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

  1. ; MIDI PLAYER FOR MENUET v1.0
  2. ; Written in pure assembler by Ivushkin Andrey aka Willow
  3. ;
  4. ;
  5. ; Created:      December 7, 2004
  6. ; Last changed: July 29, 2005
  7. ;
  8. ; COMPILE WITH FASM
  9.  
  10. format binary as ""
  11.  
  12. PLAYLIST_PATH equ '/HD0/1/PLAYLIST.TXT'
  13. ;APP_MEM   equ 150*1024
  14.  
  15. IPC_PLAY  equ 0xa1
  16. IPC_PAUS  equ 0xa2
  17. IPC_TRIG  equ 0xa3
  18. IPC_UPDT  equ 0xb1
  19. IPC_NEXT  equ 0xb2
  20.  
  21. LISTITEMS equ 40
  22. WND_BACK  equ 0x24263c
  23. PLY       equ 63
  24. WND_HEIGHT equ (PLY+9*LISTITEMS+10)+25
  25.  
  26. BTNS_XY   equ 14 shl 16+42
  27. BTNS_SIZE equ 222 shl 16+17
  28.  
  29. BROWSE_X  equ 10 shl 16+8
  30. BROWSE_Y  equ 26 shl 16+8
  31. FN_XY     equ 12 shl 16+15
  32. BAR_WIDTH equ 251
  33. BAR_X     equ 10 shl 16
  34. BAR_Y     equ 29 shl 16+5
  35. TOTALTIME_XY equ 124 shl 16+28
  36. CURTIME_X equ 225 shl 16+40
  37. CURTIME_Y equ 15 shl 16+11
  38. CURTIME_XY equ 236 shl 16+15
  39.  
  40. NONCRITICAL_MSG equ 0
  41. SOUND equ ON;OFF
  42. OUTDUMP equ 0
  43. OUTLINE equ 8
  44. FL_SHUFFLE equ 0x01
  45. FL_REPEAT  equ 0x02
  46. FL_HIDDEN  equ 0x04
  47. FL_MUTE    equ 0x08
  48. FL_REVERSE equ 0x10
  49. FL_ADD     equ 0x20
  50. FL_PLAY    equ 0x40
  51. FL_LOCK    equ 0x80
  52. FL_BOTTRED equ 0x100
  53. FL_MULSEL  equ 0x8000
  54.  
  55. use32
  56.   org    0x0
  57.  
  58.   db     'MENUET01'
  59.   dd     0x01
  60.   dd     START
  61.   dd     IM_END
  62.   dd     I_END ;APP_MEM
  63.   dd     stacktop ;APP_MEM - 1024
  64.   dd     I_PARAM
  65.   dd     cur_dir_path
  66.  
  67. listsel    dd 0
  68. channel dd 0
  69. COLOR_ORDER equ MENUETOS
  70. include '../../../config.inc'           ;for nightbuild
  71. include '../../../macros.inc' ; decrease code size (optional)
  72. include '../../../develop/libraries/box_lib/load_lib.mac'
  73.  
  74. @use_library
  75.  
  76. include 'lang.inc'
  77. ;purge mov
  78. include '../../../debug.inc'
  79. ;include 'dlg.inc'
  80. include 'playlist.inc'
  81. include 'gif_lite.inc'
  82. bottom:
  83.     file 'bottom.gif'
  84. hdrimg:
  85.     file 'hdr.gif'
  86. btns:
  87.     file 'buttons.gif'
  88. START:
  89.         mcall 68, 11
  90.                
  91. load_libraries l_libs_start,end_l_libs
  92.  
  93.     mov  esi,I_PARAM
  94.     cmp  dword[esi],0
  95.     jz @f
  96.     mov edi,filename
  97.     mov ecx,256/4
  98.     rep movsd
  99.     mov byte [edi-1], 0
  100. @@:
  101. ;OpenDialog initialisation
  102.         push    dword OpenDialog_data
  103.         call    [OpenDialog_Init]
  104.  
  105.     or   [flag],FL_BOTTRED;+FL_MUTE
  106.     mov  ecx,ipcarea
  107.     call init_ipc
  108.     mcall 40,1000111b
  109.     mov  esi,btns
  110.     mov  edi,btn_raw
  111.     call ReadGIF
  112.     mov  esi,hdrimg
  113.     mov  edi,hdr_raw
  114.     call ReadGIF
  115.     mov  esi,bottom
  116.     mov  edi,bottom_raw
  117.     call ReadGIF
  118.     call respawn
  119.     mcall 9,prcinfo,-1
  120.     mov  edx,[ebx+30]
  121.     mov  [parentPID],edx
  122.     mov  esi,I_PARAM
  123.     cmp  dword[esi],0
  124.     jnz  .yesparam
  125.     call PL_load
  126.     cmp  [list_count],0
  127.     je   noparam
  128.     mov  eax,[pl_ptr]
  129.     or   word[eax],FL_MULSEL
  130.     jmp  auto_load
  131.   .yesparam:
  132.     mov  al,byte[esi]
  133.     cmp  al,'/'
  134.     je   .defact
  135.     mov  [param],al
  136.     inc  esi
  137.   .defact:
  138.         mov  edi,filename;fnbuf
  139.     mov  ecx,64
  140.     rep  movsd
  141.     jmp  open_file
  142. clearpath:
  143.     newline
  144.     mov  [fname_len],0
  145.   noparam:
  146.     mov  [param],'W'
  147.     or   [flag],FL_ADD
  148. ;---------------------------------------------------------------------
  149. ;OpenDialog_start:
  150. ;       copy_path       open_dialog_name,path,library_path,0
  151.         mov     [OpenDialog_data.type],0        ; Open
  152.         or      [flag],FL_LOCK  
  153.         push    dword OpenDialog_data
  154.         call    [OpenDialog_Start]
  155.         and     [flag],not FL_LOCK
  156. ;       cmp     [OpenDialog_data.status],2 ; OpenDialog does not start
  157. ;       je      .fopen  ;       some kind of alternative, instead OpenDialog
  158.         cmp     [OpenDialog_data.status],1
  159. ;       je      open_file
  160. ;       jmp     still
  161.         jne     still
  162. ;---------------------------------------------------------------------
  163.  
  164. ;.fopen:
  165. ;    call fopen
  166. ;  get_path:
  167. ;    cmp  byte[filename],0
  168. ;    jz  still
  169.   open_file:
  170.     cmp  [param],'W'
  171.     je   .noplay
  172.     cmp  [param],'H'
  173.     jne  .nohidd
  174. ;    or   [flag],FL_PLAY
  175.     or   [flag],FL_HIDDEN
  176.     call draw_window
  177.     and  [flag],not FL_HIDDEN
  178.     call Shade
  179. ;    jmp  .noplay
  180.  
  181.   .nohidd:
  182.     or   [flag],FL_PLAY
  183.   .noplay:
  184.     xor  eax,eax
  185.     mov  [play_area],ax
  186.     mov  [tick_count],eax
  187.     mov  [delta],eax
  188.     mov  [curnote],0x80
  189.     mov  ecx,64
  190.     mov  esi,filename
  191.     mov  edi,I_PARAM
  192.     rep  movsd
  193.     mov  eax,70
  194.     mov  ebx,file_info
  195.     mcall
  196.     add  ebx,workarea
  197.     mov  [midi_limit],ebx
  198.     mov  edi,I_PARAM
  199.     call find_slash
  200.     mov  [fn_ptr],edi
  201.     mov  edi,filename
  202.     call str_len
  203.     mov  [fname_len],eax
  204. midi_kill:
  205.     call kill
  206. include 'midilite.inc'
  207.  
  208. decode_end:
  209. ;    dpd  edi
  210. ;    dps  <13,10,'Notes='>
  211. ;    sub  edi,[midi_limit]
  212. ;    shr  edi,1
  213. ;    dpd  edi
  214.     dps ' Notes: max='
  215.     movzx eax,[max_note]
  216.     dpd  eax
  217.     dps 'min='
  218.     movzx eax,[min_note]
  219.     dpd  eax
  220.     newline
  221. ;    sub  esi,workarea
  222. ;    jmp  _close
  223.   .play:
  224.     call kill
  225.     call respawn
  226.     xor  edx,edx
  227.     mov  esi,[midi_limit]
  228.     mov  [cur_ptr],esi
  229.     mov  [cur_tick],edx
  230.     mov  [delta],edx
  231.   .count_ticks:
  232.     lodsw
  233.     test eax,eax
  234.     jz   .eof
  235.     and  eax,0x7f
  236.     add  edx,eax
  237.     jmp  .count_ticks
  238.   .eof:
  239.     mov  [tick_count],edx
  240.   if OUTDUMP eq 1
  241.     mov  esi,[midi_limit]
  242.     call out_dump
  243.   end if
  244.     and  [flag],not FL_LOCK
  245.     test [flag],FL_PLAY
  246.     jz   .noplay
  247.     call draw_window
  248.     mcall 5,100
  249.     mov  eax,IPC_PLAY
  250.     call ipc_send
  251.   .noplay:
  252.     test [flag],FL_ADD
  253.     jz   red
  254.     mov  esi,filename
  255.     mov  ecx,[fname_len]
  256.     movzx eax,[list_count]
  257.     mov  [play_num],eax
  258.  add_song:
  259.     call PL_add
  260.     and  [flag],not FL_ADD
  261. red:
  262.     call draw_window
  263. still:
  264.     mov  ecx,ipcarea
  265.     call init_ipc
  266.     mov  eax,10
  267.     mcall
  268. prc_event:
  269.     test eax,eax
  270.     jz   still
  271.   .evt:
  272.     cmp  eax,1
  273.     je   red
  274.     cmp  eax,2
  275.     je   key
  276.     cmp  eax,3
  277.     je   button
  278.     cmp  eax,7
  279.     jne  still
  280.     movzx eax,byte[ipcarea+16]
  281.     cmp  eax,IPC_UPDT
  282.     jne  .noupdt
  283.     call draw_bar
  284.     jmp  still
  285.   .noupdt:
  286.     cmp  eax,IPC_NEXT
  287.     jne  still
  288.     cmp  [param],'H'
  289.     je   _close
  290.     xor  edx,edx
  291.     test [flag],FL_SHUFFLE
  292.     jz   .noshuf
  293.     mcall 26,9
  294.     movzx ebx,byte[list_count]
  295.     div  ebx
  296.     mov  eax,edx
  297.     jmp  play_
  298.   .noshuf:
  299.     test [flag],FL_REPEAT
  300.     jnz  decode_end.play
  301.     mov  eax,[play_num]
  302.     inc  eax
  303.     cmp  al,[list_count]
  304.     jb   bList.next
  305.     mov  eax,IPC_PAUS
  306.     call ipc_send
  307.     jmp  red
  308.  
  309. if OUTDUMP eq 1
  310. out_dump:
  311.     mov  ecx,OUTLINE
  312.   .next_byte:
  313.     lodsd
  314.     bswap eax
  315.     dph  eax
  316.     dps  ' '
  317.     lodsd
  318.     bswap eax
  319.     dph  eax
  320.     dps  <13,10>
  321.     loop .next_byte
  322.     ret
  323. end if
  324.  
  325. str_len:
  326. ; in: edi-str ptr
  327. ; out: eax-str length
  328.     push ecx edi
  329.     xor  eax,eax
  330.     mov  ecx,256
  331.     repne scasb
  332.     jecxz .nofn
  333.     sub  edi,[esp]
  334.     mov  eax,edi
  335.   .nofn:
  336.     pop  edi ecx
  337.     ret
  338.  
  339. ;fopen:
  340. ;    or  [flag],FL_LOCK
  341. ;;    opendialog draw_window, ret_path, ret_path, filename
  342. ;ret_path:
  343. ;    and  [flag],not FL_LOCK
  344. ;    ret
  345.  
  346. include 'event.inc'
  347. include "thread.inc"
  348. include "draw.inc"
  349. ; ‡¤¥áì ­ å®¤ïâáï ¤ ­­ë¥ ¯à®£à ¬¬ë:
  350.  
  351.      dd -2 shl 16+4,251,12 shl 16,29 shl 16+5
  352.      dd 21,16
  353. main_coo:
  354.      dd 14 shl 16, 42 shl 16,23 shl 16
  355.      dd 228 shl 16+38
  356.      dd 14 shl 16+10
  357.      dd 236 shl 16+15
  358. btncoords:
  359.      dd 120 shl 16+20, 1 shl 16+15
  360.      dd 149 shl 16+44, 2 shl 16+12
  361.      dd 195 shl 16+26, 2 shl 16+12
  362.  
  363.      dd -2 shl 16+4,54,63 shl 16,6 shl 16+4
  364.      dd 6,6
  365. main_coo2:
  366.      dd 169 shl 16, 4 shl 16,9 shl 16
  367.      dd 121 shl 16+40
  368.      dd 3 shl 16+9
  369.      dd 130 shl 16+4
  370. btncoords2:
  371.      dd 48 shl 16+6, 6
  372.      dd 2000 shl 16+44, 2 shl 16+12
  373.      dd 2000 shl 16+26, 2 shl 16+12
  374. ipcarea    rb 20
  375. ipcarea2   rb 20
  376.  
  377. dots       db ':-'
  378. text       db 'tone>     chnl>  <trk'
  379. text_end:
  380. coo        dd main_coo
  381. play_limit dd playlist
  382. pl_ptr     dd playlist
  383. param      db 'W'
  384. curnote    db 0x80
  385. tick_count dd 0
  386. ;---------------------------------------------------------------------
  387. OpenDialog_data:
  388. .type                   dd 0
  389. .procinfo               dd prcinfo ;+4
  390. .com_area_name          dd communication_area_name ;+8
  391. .com_area               dd 0 ;+12
  392. .opendir_pach           dd temp_dir_pach ;+16
  393. .dir_default_pach       dd communication_area_default_pach ;+20
  394. .start_path             dd open_dialog_path ;+24
  395. .draw_window            dd draw_window ;+28
  396. .status                 dd 0 ;+32
  397. .openfile_pach          dd filename ;+36
  398. .filename_area          dd 0    ;+40
  399. .filter_area            dd Filter
  400. .x:
  401. .x_size                 dw 420 ;+48 ; Window X size
  402. .x_start                dw 10 ;+50 ; Window X position
  403. .y:
  404. .y_size                 dw 320 ;+52 ; Window y size
  405. .y_start                dw 10 ;+54 ; Window Y position
  406.  
  407. communication_area_name:
  408.         db 'FFFFFFFF_open_dialog',0
  409. open_dialog_path:
  410. if __nightbuild eq yes
  411.     db '/sys/MANAGERS/opendial',0
  412. else
  413.     db '/sys/File Managers/opendial',0
  414. end if
  415. communication_area_default_pach:
  416.         db '/rd/1',0
  417.  
  418. Filter:
  419. dd Filter.end - Filter
  420. .1:
  421. db 'MID',0
  422. .end:
  423. db 0
  424. ;---------------------------------------------------------------------
  425. system_dir_ProcLib                      db '/sys/lib/proc_lib.obj',0
  426.  
  427. head_f_i:
  428. head_f_l        db 'error',0
  429. err_message_found_lib2          db 'proc_lib.obj - Not found!',0
  430.  
  431. err_message_import2                     db 'proc_lib.obj - Wrong import!',0
  432.  
  433. ;---------------------------------------------------------------------
  434. align 4
  435. ProcLib_import:
  436. OpenDialog_Init         dd aOpenDialog_Init
  437. OpenDialog_Start        dd aOpenDialog_Start
  438. ;OpenDialog__Version    dd aOpenDialog_Version
  439.         dd      0
  440.         dd      0
  441. aOpenDialog_Init        db 'OpenDialog_init',0
  442. aOpenDialog_Start       db 'OpenDialog_start',0
  443. ;aOpenDialog_Version    db 'Version_OpenDialog',0
  444. ;---------------------------------------------------------------------
  445. l_libs_start:
  446.  
  447. library01  l_libs system_dir_ProcLib+9, cur_dir_path, temp_dir_pach, system_dir_ProcLib, \
  448. err_message_found_lib2, head_f_l, ProcLib_import, err_message_import2, head_f_i
  449.  
  450. end_l_libs:
  451. ;---------------------------------------------------------------------
  452. dir_info:
  453.         dd      1
  454.         dd      0
  455.         dd      0
  456.         dd      1
  457.         dd      dir_table
  458.         db      0
  459.         dd      filename
  460. play_area  dw ?
  461. file_info:
  462.            dd 0
  463.            dd 0
  464.            dd 0
  465. fsize      dd 120*1024  ;APP_MEM-2048-workarea     ; max size
  466.            dd workarea
  467. IM_END: ; ª®­¥æ ¯à®£à ¬¬ë
  468. filename:
  469.            rb 4096 ;1024+16
  470. prcinfo    process_information
  471. I_PARAM    rb 256
  472. childPID   dd ?
  473. parentPID  dd ?
  474. play_num   dd ?
  475. counter    dd ?
  476. flag       dd ?
  477. fname_len  dd ?
  478. fn_ptr     dd ?
  479. delta      dd ?
  480. cur_ptr    dd ?
  481. cur_tick   dd ?
  482. quarter    dd ?
  483. octave     db ?
  484. tempo      dd ?
  485. midi_limit dd ?
  486. track_len  dd ?
  487. list_count db ?
  488. cur_track  db ?
  489. sel_track  db ?
  490. ipcmsg     db ?
  491. fnbuf:
  492.            rb 1024
  493. btn_raw    rb 222*17*3+8
  494. hdr_raw    rb 275*29*3+8
  495. bottom_raw rb 25*378*3+8
  496.            rb 4
  497. playlist   rb 256*LISTITEMS
  498. IncludeUGlobals
  499. ;----------------------------------------------------------------
  500. temp_dir_pach:
  501.         rb 4096
  502. ;----------------------------------------------------------------
  503. cur_dir_path:
  504.         rb 4096
  505. ;----------------------------------------------------------------
  506.         rb 4096
  507. thread_stack:
  508.         rb 4096
  509. stacktop:
  510. ;----------------------------------------------------------------
  511. dir_table:
  512.         rb 32+304
  513. workarea:
  514.         rb 120*1024
  515. I_END:
  516.