Subversion Repositories Kolibri OS

Rev

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