home *** CD-ROM | disk | FTP | other *** search
/ Large Pack of OldSkool DOS MOD Trackers / funk108a.zip / FUNK_S.ZIP / FUNKPLAY.ASM < prev    next >
Assembly Source File  |  1995-06-25  |  8KB  |  237 lines

  1. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  2. ;                                                                          ;
  3. ; Funkplay                                                                 ;
  4. ;                                                                          ;
  5. ; FunkTracker by JsNO/SuperReal - 1994,1995                                ;
  6. ;                                                                          ;
  7. ;This thing is a little bit better than the old EXAMPLE.ASM thing i had    ;
  8. ;previously. This program loads two modules and then plays them. It        ;
  9. ;basically demonstrates the use of FUNKOBJ and how to setup funk modules   ;
  10. ;previously loaded in memory. This is a one up from before, as you had     ;
  11. ;to load and play them one at a time (as you may have seen in my Music     ;
  12. ;Contest 3 demo)                                                           ;
  13. ;                                                                          ;
  14. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  15. ideal
  16. p386
  17. model flat
  18. stack  1024
  19. codeseg
  20.  
  21. extrn debug           : near
  22. Zero_Addr             dd ?
  23. Environment_Address   dd ?
  24. PSP_Address           dd ?
  25. _0B8000h              dd ?
  26.  
  27. extrn                 FNK_autodetect : near
  28. extrn                 FNK_card_deinit : near
  29. extrn                 FNK_card_init : near
  30. extrn                 FNK_setup_player : near
  31. extrn                 FNK_PLAY : near
  32. extrn                 FNK_STOP : near
  33. extrn                 FNK_teststatus : near
  34. extrn                 FNK_set_mvolume : near
  35. extrn                 FNK_get_mvolume : near
  36.  
  37. dma_buffer            dd ?
  38. our_songname1         db "c:\topend\songs\jsnork.fnk",0
  39. song_buffer1          dd ?
  40. our_songname2         db "c:\topend\songs\j-dance.fnk",0
  41. song_buffer2          dd ?
  42.  
  43. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  44. ;                                                                         ;
  45. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  46. ;@STDIO MACRO: Modified By Adam Seychell 14/03/94 in V1.02
  47. macro @stdio string
  48. local @@tttext, @@skip
  49.   jmp    @@skip
  50.   ifb    <string>
  51. @@tttext:
  52.   db     "$"
  53.   else
  54. @@tttext:
  55.   db     string, "$"
  56.   endif
  57. @@skip:
  58.   push   eax edx
  59.   lea    edx,[@@tttext]
  60.   mov    ah,9
  61.   int    21h
  62.   pop    edx eax
  63. endm
  64.  
  65. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  66. ;                                                                         ;
  67. ; NB/ i find that these are better for reading the keyboard, as the INT16 ;
  68. ; routines are interrupt executed, and therefore mask and starve our      ;
  69. ; playback code causing cracking and slowness in playback.                ;
  70. ;                                                                         ;
  71. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  72. proc key_pressed2
  73.   push   esi
  74.   mov    esi,[Zero_Addr]
  75.   add    esi,41ah
  76.   mov    ax,[esi]
  77.   cmp    ax,[word esi+2]
  78.   jne    @@l
  79.   pop    esi
  80.   clc
  81.   ret
  82. @@l:
  83.   movzx  eax,ax
  84.   add    eax,400h
  85.   add    eax,[Zero_Addr]
  86.   mov    ax,[word eax]
  87.   pop    esi
  88.   stc
  89.   ret
  90. endp
  91.  
  92. proc get_key
  93. @@l:
  94.   call   key_pressed2
  95.   jnc    @@l
  96.   mov    eax,0
  97.   int    16h
  98.   ret
  99. endp
  100.  
  101. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  102. ;                                                                         ;
  103. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  104. proc load_song
  105.   mov    eax,3d00h                                      ;open file
  106.   int    21h
  107.   jc     @@load_error
  108.   mov    ebx,eax
  109.  
  110.   mov    eax,4202h                                      ;alloc song mem
  111.   xor    edx,edx
  112.   int    21h
  113.   push   eax eax
  114.   mov    eax,4200h
  115.   xor    edx,edx
  116.   int    21h
  117.   pop    edx
  118.   add    edx,1000h
  119.   mov    eax,0EE42h
  120.   Int    31h
  121.   jc     @@mem_alloc_error
  122.   pop    ecx                                            ;read *.FNK file
  123.   mov    ah,3fh
  124.   int    21h
  125.  
  126.   mov    ah,3eh                                         ;close file
  127.   int    21h
  128.   clc
  129.   ret
  130. @@mem_alloc_error:
  131.   @stdio "Memory Error. Program unable to run."
  132.   stc
  133.   ret
  134. @@load_error:
  135.   @stdio "can't find FNK file."
  136.   stc
  137.   ret
  138. endp
  139.  
  140. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  141. ;                                                                         ;
  142. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  143. Start_Funkplay:
  144. ;  call   debug
  145.   cld
  146.   mov    ax,0EE02h
  147.   int    31h
  148.   neg    ebx
  149.   mov    [Zero_Addr],ebx
  150.   add    ebx,0b8000h
  151.   mov    [_0B8000h],ebx
  152.   mov    [Environment_Address],edi
  153.   mov    [PSP_Address],esi
  154.  
  155.   mov    eax,0EE41h                                     ;first things first,
  156.   Int    31h                                            ;DMA memory. Always
  157.   jc     @@mem_alloc_error                              ;alloc it first thing
  158.   mov    [dma_buffer],edx
  159.  
  160.   mov    bl,0ffh                                        ;autodetect card
  161.   call   FNK_autodetect                                 ;BL=FF means accept
  162.   je     @@card_not_found                               ;the first thing that
  163.                                                         ;is detected
  164.  
  165.   mov    eax,[dma_buffer]                               ;fire up mixxer/tracker
  166.   call   FNK_card_init                                  ;code that runs in backround
  167.  
  168.   @stdio "loading song #1..."                           ;load song 1
  169.   mov    edx,offset our_songname1
  170.   call   load_song
  171.   jc     @@load_fail
  172.   mov    [song_buffer1],edx
  173.  
  174.   @stdio "loading song #2..."                           ;load song 2
  175.   mov    edx,offset our_songname2
  176.   call   load_song
  177.   jc     @@load_fail
  178.   mov    [song_buffer2],edx
  179.  
  180. ;;;;;;;;;;
  181.   @stdio "playing song #1...."                          ;play song 1
  182.   mov    eax,[song_buffer1]
  183.   call   FNK_setup_player                               ;setup current song
  184.   call   FNK_PLAY                                       ;play music
  185.  
  186. @@wloop1:                                               ;this would be your
  187.   call   key_pressed2                                   ;demo code here
  188.   jc     @@end1
  189.   call   FNK_teststatus                                 ;exit if music has
  190.   je     @@wloop1                                       ;ended
  191.   jmp    @@enxt
  192. @@end1:
  193.   call   FNK_STOP                                       ;stop music
  194.   call   get_key
  195.  
  196. ;;;;;;;;;;
  197. @@enxt:
  198.   @stdio "playing song #2...."                          ;play song 2
  199.   mov    eax,[song_buffer2]
  200.   call   FNK_setup_player
  201.   call   FNK_PLAY
  202.  
  203. @@wloop2:
  204.   call   key_pressed2
  205.   jc     @@end2
  206.   call   FNK_teststatus
  207.   je     @@wloop2
  208. @@end2:
  209.   call   FNK_STOP
  210.   call   get_key
  211.  
  212. @@load_fail:
  213.   call   FNK_card_deinit                                ;deinit player
  214.  
  215.   @stdio "byeee!..."
  216. @@abort:
  217.   mov    eax,0EE40h                                     ;dealloc DMA memory
  218.   int    31h
  219.   mov    eax,0EE40h                                     ;dealloc song memory 1
  220.   int    31h
  221.   mov    eax,0EE40h                                     ;dealloc song memory 2
  222.   int    31h
  223.   mov    eax,4c00h                                      ;end program
  224.   int    21h
  225. @@card_not_found:
  226.   @stdio "Soundcard not Detected."
  227.   jmp    @@abort
  228. @@mem_alloc_error:
  229.   @stdio "Memory Error. Program unable to run."
  230.   jmp    @@abort
  231. @@load_error:
  232.   @stdio "can't find FNK file."
  233.   jmp    @@abort
  234. ends
  235.  
  236. end Start_Funkplay
  237.