home *** CD-ROM | disk | FTP | other *** search
/ Large Pack of OldSkool DOS MOD Trackers / edlb105a.zip / USE / TEST.ASM < prev    next >
Assembly Source File  |  1994-12-20  |  13KB  |  382 lines

  1. ┌──────────────────────────────────────────────────────────────────────────────┐ if 0
  2. │ Test AdLib player v04.00 ............................ by Jens-Christian Huus │
  3. ├──────────────────────────────────────────────────────────────────────────────┤
  4. │ This program demonstrates the use of my AdLib "MPLAYER.OBJ" v04.00. Assemble │
  5. │ this source using Borland Turbo Assembler v4.0 and Turbo Link v6.00. Use the │
  6. │ file "-" as a MakeFile for Borland Make utility.                             │
  7. └──────────────────────────────────────────────────────────────────────────────┘ endif
  8.  
  9. P386
  10.  
  11. IDEAL
  12.  
  13. INCLUDE         "GLOBALS.INC"
  14.  
  15. ASSUME          ss:Stacks,ds:Data,cs:Code
  16.  
  17. ┌──────────────────────────────────────────────────────────────────────────────┐ if 0
  18. │ *** STACK ***                                                                │
  19. └──────────────────────────────────────────────────────────────────────────────┘ endif
  20.  
  21. SEGMENT         Stacks  STACK 'Stack'
  22.  
  23.                 db      100h dup (0)
  24. ENDS
  25.  
  26. ┌──────────────────────────────────────────────────────────────────────────────┐ if 0
  27. │ *** DATA ***                                                                 │
  28. └──────────────────────────────────────────────────────────────────────────────┘ endif
  29.  
  30. SEGMENT         Data    PUBLIC 'Data'
  31.  
  32. FileHandle      dw      0
  33.  
  34. D00name         db      'str_wise.d00',0
  35.  
  36. D00segment      dw      0
  37.  
  38. Counter         dw      0
  39.  
  40. TestMsg         db      'AdLib Player v04.00 Test Program, by JCH/Vibrants.',0ah,0ah,0dh,24h
  41.  
  42. NoAdLib         db      'No OPL2 compatible FM soundchip found.',0ah,0dh,24h
  43.  
  44. DosMsg          db      'Dos reports error AX='
  45. DosVal          db      '0000.',0ah,0dh,24h
  46.  
  47. Loading         db      'Loading D00 file...',24h
  48. Playing         db      'Playing D00 file - press / for main volume and ESC to quit.',24h
  49.  
  50. Fading          db      0dh,'                                                             '
  51.                 db      0dh,'Fading...',24h
  52. Stopped         db      0dh,'Stopped...',0ah,0dh,24h
  53.  
  54. GetBack         db      0dh,24h
  55.  
  56. Old1C           dd      0
  57.  
  58. TestMainVol     db      0
  59.  
  60. Hex             db      '0123456789ABCDEF'
  61.  
  62. ENDS
  63.  
  64. ┌──────────────────────────────────────────────────────────────────────────────┐ if 0
  65. │ *** PROGRAM ***                                                              │
  66. └──────────────────────────────────────────────────────────────────────────────┘ endif
  67.  
  68. SEGMENT         Code    PUBLIC 'Code'
  69.  
  70.                 JUMPS
  71.                 LOCALS
  72. ────────────────────────────────────────────────────────────────────────────────
  73. Start:
  74.                 cld
  75.  
  76.                 mov     ax,Data
  77.                 mov     ds,ax
  78.  
  79.                 push    es
  80.  
  81.                 lea     dx,[TestMsg]            ;Print initial message.
  82.                 mov     ah,09h
  83.                 int     21h
  84.  
  85.                 pop     es
  86.  
  87.                 mov     bx,60000/16             ;SetBlock, reduce program size.
  88.                 mov     ah,4ah
  89.                 int     21h
  90.                 jc      DosError
  91.                 ────────────────────────────────────────────────────────────────
  92.                 mov     ah,06h                  ;Look for an AdLib card.
  93.                 call    Player
  94.                 jnc     @@120
  95.  
  96.                 lea     dx,[NoAdLib]
  97.                 mov     ah,09h
  98.                 int     21h
  99.  
  100.                 jmp     Exit
  101.                 ────────────────────────────────────────────────────────────────
  102. @@120:          lea     dx,[Loading]            ;Loading D00 file.
  103.                 mov     ah,09h
  104.                 int     21h
  105.  
  106.                 call    LoadIt
  107.  
  108.                 pushf
  109.                 push    ax
  110.  
  111.                 lea     dx,[GetBack]            ;Set cursor at start of line.
  112.                 mov     ah,09h
  113.                 int     21h
  114.  
  115.                 pop     ax
  116.                 popf
  117.  
  118.                 jc      DosError                ;Internal load/allocate error.
  119.                 ────────────────────────────────────────────────────────────────
  120.                 xor     ah,ah                   ;Initialize player.
  121.                 mov     bx,[D00segment]
  122.                 xor     cx,cx
  123.                 mov     es,bx                   ;BX:CX = Location of D00 data.
  124.                 mov     di,cx
  125.                 call    Player
  126.  
  127.                 mov     [TestMainVol],00h
  128.  
  129.                 call    SetTimerIrq
  130.  
  131.                 lea     dx,[Playing]
  132.                 mov     ah,09h
  133.                 int     21h
  134.  
  135.                 mov     ah,02h                  ;Start tune #0000h.
  136.                 xor     bx,bx
  137.                 call    Player
  138.                 ────────────────────────────────────────────────────────────────
  139. @@150:          mov     ah,01h                  ;Wait for keypress.
  140.                 int     16h
  141.                 jz      @@150
  142.                 xor     ah,ah
  143.                 int     16h
  144. @@159:
  145.                 cmp     ah,48h                  ;Key "" turns volume up.
  146.                 jne     @@160
  147.                 cmp     [TestMainVol],00h
  148.                 jz      @@150
  149.                 dec     [TestMainVol]
  150.                 jmp     short @@165
  151. @@160:
  152.                 cmp     ah,50h                  ;Key "" turns volume down.
  153.                 jne     @@170
  154.                 cmp     [TestMainVol],3fh
  155.                 jz      @@150
  156.                 inc     [TestMainVol]
  157. @@165:          mov     bh,[TestMainVol]
  158.                 mov     ah,05h                  ;Set main volume (00h-3Fh).
  159.                 xor     bl,bl
  160.                 mov     cl,bl
  161.                 call    Player
  162.                 jmp     @@150
  163. @@170:
  164.                 cmp     ah,01h                  ;Key "ESC" quits.
  165.                 jne     @@150
  166.                 ────────────────────────────────────────────────────────────────
  167.                 lea     dx,[Fading]
  168.                 mov     ah,09h
  169.                 int     21h
  170.  
  171. @@180:          cmp     [TestMainVol],3fh       ;Fade out the music.
  172.                 jz      @@200
  173.  
  174.                 mov     [Counter],-1
  175. @@185:
  176.                 cmp     [Counter],0             ;Wait for timer interrupt.
  177.                 jne     @@185
  178.  
  179.                 inc     [TestMainVol]
  180.                 mov     bh,[TestMainVol]
  181.                 mov     ah,05h                  ;Set main volume (00h-3Fh).
  182.                 xor     bl,bl
  183.                 mov     cl,bl
  184.                 call    Player
  185.                 jmp     short @@180
  186.                 ────────────────────────────────────────────────────────────────
  187. @@200:          lea     dx,[Stopped]
  188.                 mov     ah,09h
  189.                 int     21h
  190.  
  191.                 mov     ah,01h                  ;Stop the player.
  192.                 call    Player
  193.  
  194.                 call    RestoreTimer
  195. ────────────────────────────────────────────────────────────────────────────────
  196. Exit:
  197.                 mov     ax,4c00h
  198.                 int     21h
  199.  
  200. ┌──────────────────────────────────────────────────────────────────────────────┐ if 0
  201. │ *** SUBROUTINES ***                                                          │
  202. └──────────────────────────────────────────────────────────────────────────────┘ endif
  203.  
  204. DosError:                                       ;Handle all DOS errors.
  205.                 lea     di,[DosVal]
  206.                 call    CalcHexWord
  207.  
  208.                 lea     dx,[DosMsg]
  209.                 mov     ah,09h
  210.                 int     21h
  211.  
  212.                 jmp     Exit
  213. ────────────────────────────────────────────────────────────────────────────────
  214. CalcHexWord:                                    ;Prepare to calculate hex WORD.
  215.                 push    ax
  216.                 mov     al,ah
  217.                 call    CalcHexByte
  218.                 pop     ax
  219. CalcHexByte:                                    ;Prepare to calculate hex BYTE.
  220.                 push    ax ds
  221.                 pop     es
  222.                 lea     bx,[Hex]
  223.                 shr     al,4
  224.                 xlat
  225.                 stosb
  226.                 pop     ax
  227.                 and     al,0fh
  228.                 xlat
  229.                 stosb
  230.                 ret
  231. ────────────────────────────────────────────────────────────────────────────────
  232. LoadIt:                                         ;Allocate and load MOD for SB.
  233.                 lea     dx,[D00name]
  234.         mov    ax,3d00h
  235.         int    21h            ;Open file.
  236.                 jnc     @@100
  237.         ret
  238. @@100:
  239.                 mov     [FileHandle],ax
  240.  
  241.         mov    bx,ax            ;Lseek.
  242.         xor    cx,cx
  243.         mov    dx,cx
  244.         mov    ax,4202h        ;Go to end of file, find length.
  245.         int    21h
  246.                 jnc     @@110
  247.         ret
  248. @@110:
  249.                 shrd    ax,dx,4                 ;Allocate for the D00 file.
  250.         mov    bx,ax
  251.         add    bx,10h
  252.         mov    ah,48h
  253.         int    21h
  254.                 jnc     @@120
  255.         ret
  256. @@120:
  257.                 mov     [D00segment],ax
  258.  
  259.                 mov     bx,[FileHandle]         ;Lseek.
  260.                 xor     cx,cx
  261.                 mov     dx,cx
  262.                 mov     ax,4200h                ;Go to the start of file.
  263.                 int     21h
  264.                 jnc     @@130
  265.                 ret
  266. @@130:
  267.                 mov     bx,[FileHandle]
  268.                 mov     cx,-1
  269.                 mov     ds,[D00segment]
  270.                 xor     dx,dx
  271. @@135:
  272.                 mov     ah,3fh                  ;Read.
  273.                 int     21h
  274.                 jnc     @@142
  275.                 ret
  276. @@142:
  277.                 mov     ax,Data
  278.                 mov     ds,ax
  279.  
  280.                 mov     bx,[FileHandle]         ;Close file.
  281.         mov    ah,3eh
  282.         int    21h
  283.                 ret
  284. ────────────────────────────────────────────────────────────────────────────────
  285. SetTimerIRQ:                                    ;Setup the timer interrupt.
  286.                 cli
  287.  
  288.                 mov     es,[D00segment]
  289.                 movzx   bx,[es:8]               ;Usually 70 times a second.
  290.  
  291.         mov    dx,0012h
  292.         mov    ax,34dch        ;The famous 1,193,180 value.
  293.         div    bx
  294.         mov    dx,ax
  295.  
  296.         mov    al,36h
  297.         out    43h,al
  298.         mov    al,dl
  299.         out    40h,al
  300.         nop
  301.         nop
  302.         mov    al,dh
  303.         out    40h,al
  304.  
  305.                 mov     ax,351ch                ;Backup and change IRQ pointer.
  306.         int    21h
  307.                 mov     [word Old1C],bx
  308.                 mov     [word Old1C+2],es
  309.  
  310.         mov    ah,25h
  311.                 push    ds cs
  312.                 pop     ds
  313.                 lea     dx,[TimerIRQ]
  314.                 int     21h
  315.                 pop     ds
  316.  
  317.         sti
  318.                 ret
  319. ────────────────────────────────────────────────────────────────────────────────
  320. RestoreTimer:                                   ;Restore timer interrupt.
  321.                 cli
  322.                 push    ds
  323.  
  324.                 mov     al,36h                  ;Return to 18.2 times a second.
  325.         out    43h,al
  326.         xor    al,al
  327.         out    40h,al
  328.         nop
  329.         nop
  330.         out    40h,al
  331.  
  332.                 mov     ax,251ch                ;Restore old IRQ pointer.
  333.                 lds     dx,[Old1C]
  334.                 int     21h
  335.  
  336.                 pop     ds
  337.                 sti
  338.                 ret
  339. ────────────────────────────────────────────────────────────────────────────────
  340. TimerIRQ:                                       ;Called from interrupt 1Ch.
  341.         pushf
  342.                 pusha
  343.  
  344.                 mov     ax,Data
  345.                 mov     ds,ax
  346.  
  347.                 mov     bl,04h                  ;Turn outscan border red.
  348.                 call    Raster
  349.  
  350.                 mov     ah,03h                  ;Update the player.
  351.                 call    Player
  352.  
  353.                 xor     bl,bl                   ;Restore outscan back to black.
  354.                 call    Raster
  355.  
  356.                 mov     [Counter],0             ;Used when fading music.
  357.  
  358.                 popa
  359.                 popf
  360.         iret
  361. ────────────────────────────────────────────────────────────────────────────────
  362. Raster:                                         ;Set the outscan color.
  363.                 push    ax dx
  364.  
  365.                 mov     dx,3dah
  366.                 in      al,dx
  367.                 nop
  368.                 mov     dx,3c0h
  369.                 in      al,dx
  370.                 mov     al,31h
  371.                 nop
  372.                 out     dx,al
  373.                 mov     al,bl
  374.                 nop
  375.                 out     dx,al
  376.  
  377.                 pop     dx ax
  378.                 ret
  379. ────────────────────────────────────────────────────────────────────────────────
  380. ENDS
  381. END             Start
  382.