Subversion Repositories Kolibri OS

Rev

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