Subversion Repositories Kolibri OS

Rev

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