home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD1.mdf / pascal / library / dos / sound / sbutil / source.exe / CMSDRVR.PAS < prev    next >
Encoding:
Pascal/Delphi Source File  |  1991-04-25  |  7.5 KB  |  278 lines

  1. {**************************************************************************
  2.  
  3.                                CMSDRVR
  4.                           Direct CMS Output
  5.  
  6.                              Date: 4/4/91
  7.                               Version: 1
  8.  
  9. ***************************************************************************
  10.  
  11.                    Copyright (c) 1991, Zackzon Labs.
  12.  
  13.                        Author: Anthony Rumble
  14.  
  15. ==========
  16. Addresses:
  17. ==========
  18. InterNet: c9106510@cc.newcastle.edu
  19. SIGNet:  28:2200/108
  20.  
  21. Snail Mail:
  22.  32 Woolwich Rd.
  23.  Hunters Hill, NSW, 2110
  24.  Australia
  25.  
  26. -------------------------------------------------------------------------
  27.                               HISTORY
  28. -------------------------------------------------------------------------
  29. 1.0 - Works fine so far
  30. ***************************************************************************}
  31.  
  32. unit cmsdrvr;
  33.  
  34. interface
  35.  
  36. {Musical Notes Constants}
  37.  
  38. type
  39.  octave_type = array[1..3] of byte;
  40.  
  41. const
  42.  A  = 3;
  43.  AS = 31;
  44.  BF = AS;
  45.  B  = 58;
  46.  C  = 83;
  47.  CS = 107;
  48.  DF = CS;
  49.  D  = 130;
  50.  DS = 151;
  51.  EP = DS;
  52.  E  = 172;
  53.  F  = 191;
  54.  FS = 209;
  55.  GP = FS;
  56.  G  = 226;
  57.  GS = 242;
  58.  AF = GS;
  59.  octave_null:octave_type = (0,0,0);
  60.  
  61. var
  62.  main_port:word;
  63.  port:word;
  64.  octaves:octave_type;
  65.  sav:byte;
  66.  temp:word;
  67.  
  68. procedure cms_reset;
  69. procedure cms_play(note:byte; ampl, ampr:byte; octave:byte; channel:word);
  70.  
  71. implementation
  72.  
  73. {***************************************************************************
  74.                               CMS_RESET
  75. ---------------------------------------------------------------------------
  76.               Resets all the frequencies and registeres
  77. ***************************************************************************}
  78. procedure cms_reset; assembler;
  79. asm
  80.          { Initial Voice# 1-6 }
  81.  
  82.          mov  dx,[port]  { Address Register for Voice #1-6 }
  83.          inc  dx
  84.          mov  al,0       { Start with regs.address 0}
  85.  
  86. @@label1:  out  dx,al    { Select internal register }
  87.          mov  ah,al      { preserve regs.address }
  88.          dec  dx         { Point to Data Register }
  89.          sub  al,al      { Zero al }
  90.          out  dx,al      { Init to 0 }
  91.          inc  dx         { Point to Address Register again }
  92.          mov  al,ah      { Recover Regs.address }
  93.          inc  al         { Move to next address }
  94.          cmp  al,20h
  95.          jb   @@label1
  96.  
  97.          mov  al,1ch     { Select Frequency reset register }
  98.          out  dx,al
  99.          dec  dx
  100.          mov  al,2
  101.          out  dx,al      { Reset frequency for voice# 7-12 }
  102.  
  103.          { Initial voice# 7-12 }
  104.  
  105.          mov  dx,[port]  { Address register for voice# 7-12 }
  106.          inc  dx
  107.          inc  dx
  108.          inc  dx
  109.          mov  al,0
  110.  
  111. @@label2:  out  dx,al    { Select internal register }
  112.          mov  ah,al      { Preserve regs.address }
  113.          dec  dx         { point to Data Register }
  114.          sub  al,al      { Zero al }
  115.          out  dx,al      { Init to 0 }
  116.          inc  dx         { Point to Address Register Again }
  117.  
  118.          mov  al,ah      { Recover Regs.address }
  119.          inc  al         { move to next address }
  120.          cmp  al,20h
  121.          jb   @@label2
  122.  
  123.          mov  al,1ch     { Select frequency reset register }
  124.          out  dx,al
  125.          dec  dx
  126.          mov  al,2
  127.          out  dx,al      { Reset Frequency register for voice# 7-12 }
  128. end;
  129. {***************************************************************************
  130.                               CMS_PLAY
  131. ---------------------------------------------------------------------------
  132. ***************************************************************************}
  133. procedure cms_play(note:byte; ampl, ampr:byte; octave:byte; channel:word);
  134.  
  135. {---------------------------------------------------------------------------
  136.                               SET_AMP
  137. ---------------------------------------------------------------------------}
  138. procedure set_amp(ampl:byte; channel:byte); assembler;
  139. asm
  140.  
  141. {Set Amplitude}
  142.  
  143.         mov dx,[port]; {Set up the port}
  144.         inc dx
  145.         xor al,al       {Select register 0}
  146.         add al,channel
  147.         out dx,al
  148.  
  149.         dec dx         {Load Data Port}
  150.         mov al,ampl    {Load AX with the amplitude}
  151.         out dx,al      {Set Amplitude}
  152. end;
  153. {---------------------------------------------------------------------------
  154.                               SET_FREQ
  155. ---------------------------------------------------------------------------}
  156. procedure set_freq(note:byte; channel:byte); assembler;
  157. asm
  158.  
  159. {Set Frequency}
  160.  
  161.         mov dx,[port]; {Set up the port}
  162.         inc dx
  163.         mov al,8h       {Select register 8h}
  164.         add al,channel
  165.         out dx,al
  166.  
  167.         dec dx         {Load Data Port}
  168.         mov al,note    {Load AX with the frequency}
  169.         out dx,al      {Set Frequency}
  170. end;
  171. {---------------------------------------------------------------------------
  172.                               SET_OCTAVE
  173. ---------------------------------------------------------------------------}
  174. procedure set_octave(octave:byte; port2:byte); assembler;
  175. asm
  176.  
  177. {Set Octave}
  178.  
  179.         mov dx,[port]; {Set up the port}
  180.         inc dx
  181.         mov al,10h      {Select register 10h}
  182.         add al,port2
  183.         out dx,al
  184.  
  185.         dec dx         {Load Data Port}
  186.         mov al,octave  {Load AX with the octave}
  187.         out dx,al      {Set octave}
  188. end;
  189. {---------------------------------------------------------------------------
  190.                               FREQ_ENABLE
  191. ---------------------------------------------------------------------------}
  192. procedure freq_enable; assembler;
  193. asm
  194.  
  195. {Set FREQ Enable}
  196.  
  197.         mov dx,[port]; {Set up the port}
  198.         inc dx
  199.         mov al,14h     {Select register 14h}
  200.         out dx,al
  201.  
  202.         dec dx         {Load Data Port}
  203.         mov al,3fh     {Load AX with the freq enable}
  204.         out dx,al      {freq enable}
  205.  
  206.         mov dx,[port]; {Set up the port}
  207.         inc dx
  208.         mov al,1ch     {Select register 1ch}
  209.         out dx,al
  210.  
  211.         dec dx         {Load Data Port}
  212.         mov al,01h     {Load AX with the Sound Enable}
  213.         out dx,al      {Sound Enable}
  214. end;
  215.  
  216. begin
  217.  case channel of
  218.    1,7:
  219.    begin
  220.     sav:=octaves[1] AND 112;
  221.     octaves[1]:= octaves[1] OR 7;
  222.     octaves[1]:= octaves[1] AND (octave OR sav);
  223.     set_octave(octaves[1], 0);
  224.    end;
  225.    2,8:
  226.    begin
  227.     sav:=octaves[1] AND 7;
  228.     octaves[1]:=octaves[1] OR 112;
  229.     octaves[1]:=octaves[1] AND ((octave shl 4) OR sav);
  230.     set_octave(octaves[1], 0);
  231.    end;
  232.    3,9:
  233.    begin
  234.     sav:=octaves[2] AND 112;
  235.     octaves[2]:=octaves[2] OR 7;
  236.     octaves[2]:=octaves[2] AND (octave OR sav);
  237.     set_octave(octaves[2], 1);
  238.    end;
  239.    4,10:
  240.    begin
  241.     sav:=octaves[2] AND 7;
  242.     octaves[2]:=octaves[2] OR 112;
  243.     octaves[2]:=octaves[2] AND ((octave shl 4) OR sav);
  244.     set_octave(octaves[2], 1);
  245.    end;
  246.    5,11:
  247.    begin
  248.     sav:=octaves[3] AND 112;
  249.     octaves[3]:=octaves[3] OR 7;
  250.     octaves[3]:=octaves[3] AND (octave OR sav);
  251.     set_octave(octaves[3], 2);
  252.    end;
  253.    6,12:
  254.    begin
  255.     sav:=octaves[3] AND 7;
  256.     octaves[3]:=octaves[3] OR 112;
  257.     octaves[3]:=octaves[3] AND ((octave shl 4) OR sav);
  258.     set_octave(octaves[3], 2);
  259.    end;
  260.  end;
  261.  if channel>6 then
  262.  begin
  263.   port:=main_port+2;
  264.   channel:=channel-6;
  265.  end;
  266.  channel:=channel-1;
  267.  set_freq(note, channel);
  268.  set_amp(ampl+(ampr*16), channel);
  269.  port:=main_port;
  270.  freq_enable;
  271. end;
  272.  
  273.  
  274. begin
  275.  main_port:=$220;
  276.  port:=main_port;
  277.  octaves:=octave_null;
  278. end.