flat assembler
Message board for the users of flat assembler.
Index
> DOS > dos beeps? How do you do dos beeps? - PC speaker issue. |
Author |
|
crc 09 Jul 2004, 11:32
Something like this should work:
Code: mov ah, 2 ; DOS output function mov dl, 7 ; ASCII 7 = Bell int $21 |
|||
09 Jul 2004, 11:32 |
|
comrade 09 Jul 2004, 13:13
i think its also outputting to port 60 or 61
|
|||
09 Jul 2004, 13:13 |
|
windwakr 09 Jul 2004, 16:29
alright thanks for the help....if 7=bell what are the others?
|
|||
09 Jul 2004, 16:29 |
|
windwakr 09 Jul 2004, 16:37
ummm...can someone attach a small example...I cant seem to get it to work
|
|||
09 Jul 2004, 16:37 |
|
ASHLEY4 10 Jul 2004, 14:59
This code is from a game i made, its in tasm, but should be easy to convert.
Code: Beep1 PROC MOV Hz,150h CALL Sound CALL DeLay CALL NoSound RETBeep1 ENDP;------------------------------------------------------------------------------------------------; Beep tone 2;------------------------------------------------------------------------------------------------Beep2 PROC MOV Hz,100h CALL Sound CALL DeLay CALL NoSound RETBeep2 ENDP;------------------------------------------------------------------------------------------------; Sound;------------------------------------------------------------------------------------------------SOUND PROC MOV BX,Hz MOV AX,34DDH MOV DX,0012H CMP DX,BX JNC DONE1 DIV BX MOV BX,AX IN AL,61H TEST AL,3 JNZ A99 OR AL,3 OUT 61H,AL MOV AL,0B6H OUT 43H,ALA99: MOV AL,BL OUT 42H,AL MOV AL,BH OUT 42H,ALDONE1: RETSOUND ENDP;------------------------------------------------------------------------------------------------; Delays;------------------------------------------------------------------------------------------------DeLay PROC MOV CX, MS JCXZ A2A1: CALL DelayOneMS LOOP A1A2: RETDeLay ENDP;------------------------------------------------------------------------------------------------;Delay;------------------------------------------------------------------------------------------------DeLaYoneMS PROC PUSH CX ; Save CX MOV CX, OneMS ; Loop count into CXB1: LOOP B1 ; Wait one millisecond POP CX ; Restore CX RETDeLaYoneMS ENDP;------------------------------------------------------------------------------------------------; Turn sound off;------------------------------------------------------------------------------------------------NOSOUND PROC IN AL,61h AND AL,11111100b OUT 61h,AL RETNOSOUND ENDPHz DW ?MS DW 20 ASHLEY4. |
|||
10 Jul 2004, 14:59 |
|
crc 10 Jul 2004, 15:06
FASM version (assembles, but hasn't been tested since my Laptop lacks a buzzer):
Code: org 100h call Beep1 call Beep2 int 0x20 Beep1: MOV [Hz], 150h CALL Sound CALL DeLay CALL NOSOUND RET ;------------------------------------------------------------------------------------------------ ; Beep tone 2 ;------------------------------------------------------------------------------------------------ Beep2: MOV [Hz],100h CALL Sound CALL DeLay CALL NOSOUND RET ;------------------------------------------------------------------------------------------------ ; Sound ;------------------------------------------------------------------------------------------------ Sound: MOV BX,Hz MOV AX,34DDH MOV DX,0012H CMP DX,BX JNC DONE1 DIV BX MOV BX,AX IN AL,61H TEST AL,3 JNZ A99 OR AL,3 OUT 61H,AL MOV AL,0B6H OUT 43H,AL A99: MOV AL,BL OUT 42H,AL MOV AL,BH OUT 42H,AL DONE1: RET ;------------------------------------------------------------------------------------------------ ; Delays ;------------------------------------------------------------------------------------------------ DeLay: MOV CX, [MilliS] JCXZ A2 A1: CALL DeLaYoneMS LOOP A1 A2: RET ;------------------------------------------------------------------------------------------------ ;Delay ;------------------------------------------------------------------------------------------------ DeLaYoneMS: PUSH CX ; Save CX MOV CX, [MilliS] ; Loop count into CX B1: LOOP B1 ; Wait one millisecond POP CX ; Restore CX RET ;------------------------------------------------------------------------------------------------ ; Turn sound off ;------------------------------------------------------------------------------------------------ NOSOUND: IN AL,61h AND AL,11111100b OUT 61h,AL RET Hz DW ? MilliS DW 20 |
|||
10 Jul 2004, 15:06 |
|
windwakr 10 Jul 2004, 22:42
is it working if i get a click when it starts? If so, Thanks ASHLEY4 and crc
|
|||
10 Jul 2004, 22:42 |
|
ASHLEY4 11 Jul 2004, 19:08
Hi Windwakr
The code that Crc (Thanks Crc) converted works fine, but give the same tone, the part marked "This" needs changing, also the delay was too short. This code for fasm works fine, by changing the Hz you get a higher or lower sound. Let me know if you want the asm game it comes from. Code: org 100hxor ah,ahint 16hcall Beep1xor ah,ahint 16hcall Beep2xor ah,ahint 16hint 0x20Beep1:MOV [Hz],100hCALL SoundCALL DeLayCALL NOSOUNDRET;------------------------------------------------------------------------------------------------; Beep tone 2;------------------------------------------------------------------------------------------------Beep2:MOV [Hz],150hCALL SoundCALL DeLayCALL NOSOUNDRET;------------------------------------------------------------------------------------------------; Sound;------------------------------------------------------------------------------------------------Sound:MOV BX,[Hz] ;ThisMOV AX,34DDHMOV DX,0012HCMP DX,BXJNC DONE1 DIV BXMOV BX,AX IN AL,61HTEST AL,3 JNZ A99OR AL,3 OUT 61H,ALMOV AL,0B6H OUT 43H,AL A99:MOV AL,BL OUT 42H,ALMOV AL,BH OUT 42H,ALDONE1: RET ;------------------------------------------------------------------------------------------------; Delays;------------------------------------------------------------------------------------------------ DeLay:MOV CX, [MilliS] JCXZ A2A1: CALL DeLaYoneMSLOOP A1 A2: RET ;------------------------------------------------------------------------------------------------;Delay;------------------------------------------------------------------------------------------------ DeLaYoneMS: PUSH CX ; Save CXMOV CX, [OneMS] ; Loop count into CX B1:LOOP B1 ; Wait one millisecond POP CX ; Restore CXRET ;------------------------------------------------------------------------------------------------; Turn sound off ;------------------------------------------------------------------------------------------------ NOSOUND:IN AL,61h AND AL,11111100bOUT 61h,AL RET Hz DW ?MilliS DW 200OneMS DW 40000 ASHLEY4. |
|||
11 Jul 2004, 19:08 |
|
crc 11 Jul 2004, 19:22
my only complaint with your source is the odd capitalizations in the function names. They require frequent checks to make sure that calls to them are written properly. It's better to use all lowercase IMO
|
|||
11 Jul 2004, 19:22 |
|
ASHLEY4 11 Jul 2004, 22:19
I take your point Crc, its just to make them more readable, i usually cut & past them.
But i will use lowercase next time. ASHLEY4. |
|||
11 Jul 2004, 22:19 |
|
windwakr 12 Jul 2004, 20:06
I assembled the code you gave and I pressed anybutton and It played a beep then I pressed another button played a beep then it quit...Is that what its susposed to do?....sure I'd like to have the game it came from
|
|||
12 Jul 2004, 20:06 |
|
crc 12 Jul 2004, 20:48
Yes, that's what it is supposed to do
|
|||
12 Jul 2004, 20:48 |
|
ASHLEY4 13 Jul 2004, 00:51
Here is where you can get my game called "pong.zip" with asm code. http://www.falconrybells.co.uk/
Make shore you put the "space.pcx" file in the same dir, as the "pongsst.com" as it as no error checking. Also on that site is the start of my 32bit pmode os, made with fasm that you can have a look at. ASHLEY4. |
|||
13 Jul 2004, 00:51 |
|
windwakr 13 Jul 2004, 16:29
good game......Its quite fun
|
|||
13 Jul 2004, 16:29 |
|
Jaques 13 Jul 2004, 18:37
Where exactly is volume i found freq
|
|||
13 Jul 2004, 18:37 |
|
Matrix 11 Sep 2004, 09:39
Jaques wrote: Where exactly is volume i found freq there is no volume, you can make volume change via pulse width modulation, for example bit patterns 00000000 represent 00% 00100100 represent 25% 10101010 represent 50% 11011011 represent 75% 11111111 represent 100% although loop frequencies differ by cpu clock, and many other things, it might be accurate on a micro controller - if well calculated. MATRIX |
|||
11 Sep 2004, 09:39 |
|
Matrix 15 Sep 2004, 20:17
this is HARDWARE !
non os related, you can work directly with hardware and this generates Hz ! here is a code: Code: org 256 mov ax,440 call sound xor ax,ax int 16h call nosound int 20h nosound: ; Silences the speaker. in al,0x61 and al,0xFC; out 0x61,al ret sound: ; AX = frequency Starts the speaker emiting a sound of a given frequency mov bx,ax ; RETURNS: AX,BX,DX = undefined mov dx,0x12; mov ax,0x34DC div bx mov bl,al mov al,0xB6; out 0x43,al mov al,bl out 0x42,al mov al,ah out 0x42,al in al,0x61 or al,3 out 0x61,al ret i can't imagine someone's thoughts when thinking of : DOS is the computer's brain no its not, its a microsoft code made with who knows what. and they are restricting someone to access the computers hardware ports now for example in xp nice eh? MATRIX |
|||
15 Sep 2004, 20:17 |
|
Matrix 23 Oct 2004, 15:34
Dos beeps is kind of interesting question but the problem is here solved, pc speaker usage:
http://board.flatassembler.net/topic.php?t=2432 |
|||
23 Oct 2004, 15:34 |
|
Jaques 23 Oct 2004, 21:42
MAKE IT PLAY A SCALE
|
|||
23 Oct 2004, 21:42 |
|
< Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2025, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.