Subversion Repositories Kolibri OS

Rev

Rev 5098 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed

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