jojo@crystal.UUCP (02/24/87)
I'm currently writing a game in C and want to add sound. The problem is that the all the sound routines I have will play a frequency for some duration. (usually by busy waiting) What I'm looking for is something similar to Turbo Pascal's soundon and soundoff routines. These routines turn the speaker on and have it play a frequency without supervision of the cpu. Does anyone know how to do this? Secondly, I know how int 9 and int 16 work for getting keyboard input, when you press a key, the chip in the keyboard signals a hardware int. through int 9. Int 9 then reads in the scan code, etc from port 60(?) From what I hear, there's another port (61?) which can tell you if a key is being pressed. This would be real handy, if it were true, for moving an object on the screen for as long as the a key is being pressed. I've seen this done in several games and wondered HOW DO THEY DO IT? I'm not talking about the shift keys either since BIOS can tell you if they are pressed. It's the rest of the keypad I want to know about. Does anyone know how this works. thanx in advance, --j -- jon wesener jojo@crys.wisc.edu "Than it struck me, I just might die with a smile on my face after all." --Morrissey
ephram@violet.berkeley.edu.UUCP (02/26/87)
In article <262@crys.WISC.EDU> jojo@crys.WISC.EDU (Jon Wesener) writes: > > I'm currently writing a game in C and want to add sound. The problem >is that the all the sound routines I have will play a frequency for some >duration. (usually by busy waiting) What I'm looking for is something >similar to Turbo Pascal's soundon and soundoff routines. These routines >turn the speaker on and have it play a frequency without supervision of >the cpu. Does anyone know how to do this? > I think the turbo routines do it by attatching to the time of day interupt but I am just stabbing in the dark on this one. >Secondly, I know how int 9 and int 16 work for getting keyboard input, >when you press a key, the chip in the keyboard signals a hardware int. through >int 9. Int 9 then reads in the scan code, etc from port 60(?) From what I >hear, there's another port (61?) which can tell you if a key is being pressed. The keyboard sends out 2 codes for each key. When the key is pressed it sends out the scan code we all know about. In addition, however, the scan code + 80 (hex) is sent when the key is released. I don't think there is another port that tells you about weather (sp?) a key is down or not. > >thanx in advance, >--j > your welcome :-) I hope this is of service. ephram@violet.berkeley.edu
farren@hoptoad.UUCP (02/27/87)
The question was asked: how to put out a sound which will then run without processor intervention. On a standard IBM PC, this is done by placing a divisor value into one of the timer registers, and then enabling the speaker. Once you do this, the speaker will be toggled every time the timer overflows, and the timer will be reset to do the whole process over again. This continues until you explicitly turn off the speaker. Sample assembly code (not tested) for this operation is as follows: ;This routine turns on the speaker with a tone whose frequency is ((1/1193180) * divisor) hertz onspeaker: mov al, 0B6h ;select timer 2 out 043h, al ;Send to mode register in timer mov ax, divisor ;Select frequency out 042h, al ;Send LSB of divisor to timer mov al, ah out 042h, al ;Send MSB of divisor to timer in al, 061h ;Get current contents of control port mov byte ptr save_mode, al ; Save current contents somewhere or al, 03h ;Set bits to turn on speaker out 061h, al ;And do it ; This routine turns off the speaker offspeaker: mov al, byte ptr save_mode ;Get the old contents out 061h, al ;Turn the speaker off Hope this helps some. -- ---------------- "... if the church put in half the time on covetousness Mike Farren that it does on lust, this would be a better world ..." hoptoad!farren Garrison Keillor, "Lake Wobegon Days"