Subversion Repositories Kolibri OS

Rev

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