home *** CD-ROM | disk | FTP | other *** search
- { -----------------------------------------------------------------------------
-
- NOTICE:
-
- THESE MATERIALS are UNSUPPORTED by OSS! If you do not understand how to
- use them do not contact OSS for help! We will not teach you how to
- program in Pascal. If you find an error in these materials, feel free
- to SEND US A LETTER explaining the error, and how to fix it.
-
- THE BOTTOM LINE:
-
- Use it, enjoy it, but you are on your own when using these materials!
-
-
- DISCLAIMER:
-
- OSS makes no representations or warranties with respect to the contents
- hereof and specifically disclaim all warranties of merchantability or
- fitness for any particular purpose. This document is subject to change
- without notice.
-
- OSS provides these materials for use with Personal Pascal. Use them in
- any way you wish.
-
- -------------------------------------------------------------------------- }
-
-
- (* sound_demo - A simple Personal Pascal sound demo program.
-
- You must turn off key-clicks using the control panel before running this
- program, as the key-click routine in the OS will mess up your sound! We
- hope soon to add to this demo an XBIOS call to turn off the keyclicks. *)
-
- PROGRAM sound_demo ;
-
- CONST
- cmd_write = 128 ;
- cmd_read = 0 ;
- chana_lo = 0 ;
- chana_hi = 1 ;
- chana_vol = 8 ;
- chan_enable = 7 ;
- enable_sound = 7 ;
-
- TYPE
- channel = 0..2 ;
-
- VAR
- volume, note : integer ;
-
-
-
- (* Two XBIOS functions (actually one call with two definitions!) needed to
- access the General Instruments sound chip. *)
-
- FUNCTION gia_read( data, register : integer ) : integer ;
- XBIOS( 28 ) ;
-
- PROCEDURE gia_write( data, register : integer ) ;
- XBIOS( 28 ) ;
-
-
-
- (* Call this routine to enable sound to be generated. *)
-
- PROCEDURE Sound_Init ;
-
- VAR
- port_state : integer ;
-
- BEGIN
- port_state := gia_read( 0, chan_enable+cmd_read ) ;
- gia_write( port_state&(~enable_sound), chan_enable+cmd_write ) ;
- END ;
-
-
-
- (* This routine turns on a particular note on one of the three channels. *)
-
- PROCEDURE Sound( ch : channel ; pitch : integer ; vol : integer ) ;
-
- BEGIN
- gia_write( vol, chana_vol+ch+cmd_write ) ;
- gia_write( pitch&$FF, chana_lo+ch*2+cmd_write ) ;
- gia_write( shr(pitch,8), chana_hi+ch*2+cmd_write ) ;
- END ;
-
-
-
- (* Call this routine to turn off sound after you're finished. *)
-
- PROCEDURE Sound_Off ;
-
- VAR
- port_state : integer ;
-
- BEGIN
- Sound( 0, 0, 0 ) ; (* First, make sure all volumes are zero. *)
- Sound( 1, 0, 0 ) ;
- Sound( 2, 0, 0 ) ;
- (* Now disable sound production on all three channels. *)
- port_state := gia_read( 0, chan_enable+cmd_read ) ;
- gia_write( port_state|enable_sound, chan_enable+cmd_write ) ;
- END ;
-
-
- BEGIN
- (* Main program loop-- ask user for a volume to use... should be 0-15. *)
- LOOP
- write( 'volume: ' ) ;
- readln( volume ) ;
-
- EXIT IF volume = 0 ;
-
- sound_init ; (* Enable sound. *)
-
- (* Sub-loop-- keep generating notes until user enters 0 as a pitch. *)
- LOOP
- write( 'note: ' ) ;
- readln( note ) ;
- EXIT IF note = 0 ;
- sound( 0, note, volume ) ;
- END ;
-
- sound_off ; (* Disable the sound. *)
- END ;
- END.
-