Subversion Repositories Kolibri OS

Rev

Rev 141 | 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     I_END
  60.   dd     APP_MEM
  61.   dd     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. lang fix en
  68. ;purge mov
  69. include 'debug.inc'
  70. include 'dlg.inc'
  71. include 'playlist.inc'
  72. include 'gif_lite.inc'
  73. bottom:
  74.     file 'bottom.gif'
  75. hdrimg:
  76.     file 'hdr.gif'
  77. btns:
  78.     file 'buttons.gif'
  79. START:
  80.     or   [flag],FL_BOTTRED;+FL_MUTE
  81.     mov  ecx,ipcarea
  82.     call init_ipc
  83.     mcall 40,1000111b
  84.     mov  esi,btns
  85.     mov  edi,btn_raw
  86.     mov  eax,hash_table
  87.     call ReadGIF
  88.     mov  esi,hdrimg
  89.     mov  edi,hdr_raw
  90.     mov  eax,hash_table
  91.     call ReadGIF
  92.     mov  esi,bottom
  93.     mov  edi,bottom_raw
  94.     mov  eax,hash_table
  95.     call ReadGIF
  96.     call respawn
  97.     mcall 9,prcinfo,-1
  98.     mov  edx,[ebx+30]
  99.     mov  [parentPID],edx
  100.     mov  esi,I_PARAM
  101.     cmp  dword[esi],0
  102.     jnz  .yesparam
  103.     call PL_load
  104.     cmp  [list_count],0
  105.     je   noparam
  106.     mov  eax,[pl_ptr]
  107.     or   word[eax],FL_MULSEL
  108.     jmp  auto_load
  109.   .yesparam:
  110.     mov  al,byte[esi]
  111.     cmp  al,'/'
  112.     je   .defact
  113.     mov  [param],al
  114.     inc  esi
  115.   .defact:
  116.     mov  edi,filename;fnbuf
  117.     mov  ecx,64
  118.     rep  movsd
  119.     jmp  open_file
  120. clearpath:
  121.     newline
  122.     mov  [fname_len],0
  123.   noparam:
  124.     mov  [param],'W'
  125.     or   [flag],FL_ADD
  126.     call fopen
  127.   get_path:
  128.     cmp  byte[filename],0
  129.     jz   still
  130.   open_file:
  131.     cmp  [param],'W'
  132.     je   .noplay
  133.     cmp  [param],'H'
  134.     jne  .nohidd
  135. ;    or   [flag],FL_PLAY
  136.     or   [flag],FL_HIDDEN
  137.     call draw_window
  138.     and  [flag],not FL_HIDDEN
  139.     call Shade
  140. ;    jmp  .noplay
  141.  
  142.   .nohidd:
  143.     or   [flag],FL_PLAY
  144.   .noplay:
  145.     xor  eax,eax
  146.     mov  [play_area],ax
  147.     mov  [tick_count],eax
  148.     mov  [delta],eax
  149.     mov  [curnote],0x80
  150.     mov  ecx,64
  151.     mov  esi,filename
  152.     mov  edi,I_PARAM
  153.     rep  movsd
  154.     mov  eax,70
  155.     mov  ebx,file_info
  156.     int  0x40
  157.     add  ebx,workarea
  158.     mov  [midi_limit],ebx
  159.     mov  edi,I_PARAM
  160.     call find_slash
  161.     mov  [fn_ptr],edi
  162.     mov  edi,filename
  163.     call str_len
  164.     mov  [fname_len],eax
  165. midi_kill:
  166.     call kill
  167. include 'midilite.inc'
  168.  
  169. decode_end:
  170. ;    dpd  edi
  171. ;    dps  <13,10,'Notes='>
  172. ;    sub  edi,[midi_limit]
  173. ;    shr  edi,1
  174. ;    dpd  edi
  175.     dps ' Notes: max='
  176.     movzx eax,[max_note]
  177.     dpd  eax
  178.     dps 'min='
  179.     movzx eax,[min_note]
  180.     dpd  eax
  181.     newline
  182. ;    sub  esi,workarea
  183. ;    jmp  _close
  184.   .play:
  185.     call kill
  186.     call respawn
  187.     xor  edx,edx
  188.     mov  esi,[midi_limit]
  189.     mov  [cur_ptr],esi
  190.     mov  [cur_tick],edx
  191.     mov  [delta],edx
  192.   .count_ticks:
  193.     lodsw
  194.     test eax,eax
  195.     jz   .eof
  196.     and  eax,0x7f
  197.     add  edx,eax
  198.     jmp  .count_ticks
  199.   .eof:
  200.     mov  [tick_count],edx
  201.   if OUTDUMP eq 1
  202.     mov  esi,[midi_limit]
  203.     call out_dump
  204.   end if
  205.     and  [flag],not FL_LOCK
  206.     test [flag],FL_PLAY
  207.     jz   .noplay
  208.     call draw_window
  209.     mcall 5,100
  210.     mov  eax,IPC_PLAY
  211.     call ipc_send
  212.   .noplay:
  213.     test [flag],FL_ADD
  214.     jz   red
  215.     mov  esi,filename
  216.     mov  ecx,[fname_len]
  217.     movzx eax,[list_count]
  218.     mov  [play_num],eax
  219.  add_song:
  220.     call PL_add
  221.     and  [flag],not FL_ADD
  222. red:
  223.     call draw_window
  224. still:
  225.     mov  ecx,ipcarea
  226.     call init_ipc
  227.     mov  eax,10
  228.     int  0x40
  229. prc_event:
  230.     test eax,eax
  231.     jz   still
  232.   .evt:
  233.     cmp  eax,1
  234.     je   red
  235.     cmp  eax,2
  236.     je   key
  237.     cmp  eax,3
  238.     je   button
  239.     cmp  eax,7
  240.     jne  still
  241.     movzx eax,byte[ipcarea+16]
  242.     cmp  eax,IPC_UPDT
  243.     jne  .noupdt
  244.     call draw_bar
  245.     jmp  still
  246.   .noupdt:
  247.     cmp  eax,IPC_NEXT
  248.     jne  still
  249.     cmp  [param],'H'
  250.     je   _close
  251.     xor  edx,edx
  252.     test [flag],FL_SHUFFLE
  253.     jz   .noshuf
  254.     mcall 26,9
  255.     movzx ebx,byte[list_count]
  256.     div  ebx
  257.     mov  eax,edx
  258.     jmp  play_
  259.   .noshuf:
  260.     test [flag],FL_REPEAT
  261.     jnz  decode_end.play
  262.     mov  eax,[play_num]
  263.     inc  eax
  264.     cmp  al,[list_count]
  265.     jb   bList.next
  266.     mov  eax,IPC_PAUS
  267.     call ipc_send
  268.     jmp  red
  269.  
  270. if OUTDUMP eq 1
  271. out_dump:
  272.     mov  ecx,OUTLINE
  273.   .next_byte:
  274.     lodsd
  275.     bswap eax
  276.     dph  eax
  277.     dps  ' '
  278.     lodsd
  279.     bswap eax
  280.     dph  eax
  281.     dps  <13,10>
  282.     loop .next_byte
  283.     ret
  284. end if
  285.  
  286. str_len:
  287. ; in: edi-str ptr
  288. ; out: eax-str length
  289.     push ecx edi
  290.     xor  eax,eax
  291.     mov  ecx,256
  292.     repne scasb
  293.     jecxz .nofn
  294.     sub  edi,[esp]
  295.     mov  eax,edi
  296.   .nofn:
  297.     pop  edi ecx
  298.     ret
  299.  
  300. fopen:
  301.     or   [flag],FL_LOCK
  302.     opendialog draw_window, ret_path, ret_path, filename
  303. ret_path:
  304.     and  [flag],not FL_LOCK
  305.     ret
  306.  
  307. include 'event.inc'
  308. include "thread.inc"
  309. include "draw.inc"
  310. ; ‡¤¥áì ­ å®¤ïâáï ¤ ­­ë¥ ¯à®£à ¬¬ë:
  311.  
  312.      dd -2 shl 16+4,251,12 shl 16,29 shl 16+5
  313.      dd 21,16
  314. main_coo:
  315.      dd 14 shl 16, 42 shl 16,23 shl 16
  316.      dd 228 shl 16+38
  317.      dd 14 shl 16+10
  318.      dd 236 shl 16+15
  319. btncoords:
  320.      dd 120 shl 16+20, 1 shl 16+15
  321.      dd 149 shl 16+44, 2 shl 16+12
  322.      dd 195 shl 16+26, 2 shl 16+12
  323.  
  324.      dd -2 shl 16+4,54,63 shl 16,6 shl 16+4
  325.      dd 6,6
  326. main_coo2:
  327.      dd 169 shl 16, 4 shl 16,9 shl 16
  328.      dd 121 shl 16+40
  329.      dd 3 shl 16+9
  330.      dd 130 shl 16+4
  331. btncoords2:
  332.      dd 48 shl 16+6, 6
  333.      dd 2000 shl 16+44, 2 shl 16+12
  334.      dd 2000 shl 16+26, 2 shl 16+12
  335. ipcarea    rb 20
  336. ipcarea2   rb 20
  337.  
  338. dots       db ':-'
  339. text       db 'tone>     chnl>  <trk'
  340. text_end:
  341. coo        dd main_coo
  342. play_limit dd playlist
  343. pl_ptr     dd playlist
  344. param      db 'W'
  345. curnote    db 0x80
  346. tick_count dd 0
  347. dir_info:
  348.         dd      1
  349.         dd      0
  350.         dd      0
  351.         dd      1
  352.         dd      dir_table
  353.         db      0
  354.         dd      filename
  355. play_area  dw ?
  356. file_info:
  357.            dd 0
  358.            dd 0
  359.            dd 0
  360. fsize      dd APP_MEM-2048-workarea     ; max size
  361.            dd workarea
  362. I_END:  ; ª®­¥æ ¯à®£à ¬¬ë
  363. filename:
  364.            rb 1024+16
  365. prcinfo    process_information
  366. I_PARAM    rb 256
  367. childPID   dd ?
  368. parentPID  dd ?
  369. play_num   dd ?
  370. counter    dd ?
  371. flag       dd ?
  372. fname_len  dd ?
  373. fn_ptr     dd ?
  374. delta      dd ?
  375. cur_ptr    dd ?
  376. cur_tick   dd ?
  377. quarter    dd ?
  378. octave     db ?
  379. tempo      dd ?
  380. midi_limit dd ?
  381. track_len  dd ?
  382. list_count db ?
  383. cur_track  db ?
  384. sel_track  db ?
  385. ipcmsg     db ?
  386. fnbuf:
  387.            rb 1024
  388. btn_raw    rb 222*17*3+12
  389. hdr_raw    rb 275*29*3+12
  390. bottom_raw rb 25*378*3+12
  391.            rb 4
  392. playlist   rb 256*LISTITEMS
  393. hash_table:
  394.            rd 4096
  395. dir_table  rb 32+304
  396. workarea:
  397.