Subversion Repositories Kolibri OS

Rev

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