Subversion Repositories Kolibri OS

Rev

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