flat assembler
Message board for the users of flat assembler.

flat assembler > DOS > dos beeps? How do you do dos beeps? - PC speaker issue.

Author
Thread Post new topic Reply to topic
windwakr



Joined: 30 Jun 2004
Posts: 827
Location: Michigan, USA
How do you do dos beeps? In c++ its beep(freq)....I think....how do you do it in FASM?

Thanks

[TopicEdit=from:"dos beeps?" to:"dos beeps? How do you do dos beeps? - PC speaker issue." reason:"Better description of the problem"]Matrix[/TopicEdit]

_________________
----> * <---- My star, won HERE
Post 09 Jul 2004, 02:38
View user's profile Send private message Reply with quote
crc



Joined: 21 Jun 2003
Posts: 637
Location: Penndel, PA [USA]
Something like this should work:

Code:
mov ah, 2     ; DOS output function
mov dl, 7      ; ASCII 7 = Bell
int $21
    

_________________
Charles Childers, Programmer
Post 09 Jul 2004, 11:32
View user's profile Send private message Visit poster's website Reply with quote
comrade



Joined: 16 Jun 2003
Posts: 1135
Location: Russian Federation
i think its also outputting to port 60 or 61

_________________
comrade (comrade64@live.com; http://comrade.ownz.com/)
Post 09 Jul 2004, 13:13
View user's profile Send private message Visit poster's website AIM Address Yahoo Messenger MSN Messenger ICQ Number Reply with quote
windwakr



Joined: 30 Jun 2004
Posts: 827
Location: Michigan, USA
alright thanks for the help....if 7=bell what are the others?
Post 09 Jul 2004, 16:29
View user's profile Send private message Reply with quote
windwakr



Joined: 30 Jun 2004
Posts: 827
Location: Michigan, USA
ummm...can someone attach a small example...I cant seem to get it to work
Post 09 Jul 2004, 16:37
View user's profile Send private message Reply with quote
ASHLEY4



Joined: 28 Apr 2004
Posts: 376
Location: UK
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.
Post 10 Jul 2004, 14:59
View user's profile Send private message Reply with quote
crc



Joined: 21 Jun 2003
Posts: 637
Location: Penndel, PA [USA]
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
    
Post 10 Jul 2004, 15:06
View user's profile Send private message Visit poster's website Reply with quote
windwakr



Joined: 30 Jun 2004
Posts: 827
Location: Michigan, USA
is it working if i get a click when it starts? If so, Thanks ASHLEY4 and crc
Post 10 Jul 2004, 22:42
View user's profile Send private message Reply with quote
ASHLEY4



Joined: 28 Apr 2004
Posts: 376
Location: UK
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.
Post 11 Jul 2004, 19:08
View user's profile Send private message Reply with quote
crc



Joined: 21 Jun 2003
Posts: 637
Location: Penndel, PA [USA]
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 Smile
Post 11 Jul 2004, 19:22
View user's profile Send private message Visit poster's website Reply with quote
ASHLEY4



Joined: 28 Apr 2004
Posts: 376
Location: UK
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.
Post 11 Jul 2004, 22:19
View user's profile Send private message Reply with quote
windwakr



Joined: 30 Jun 2004
Posts: 827
Location: Michigan, USA
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
Post 12 Jul 2004, 20:06
View user's profile Send private message Reply with quote
crc



Joined: 21 Jun 2003
Posts: 637
Location: Penndel, PA [USA]
Yes, that's what it is supposed to do Smile
Post 12 Jul 2004, 20:48
View user's profile Send private message Visit poster's website Reply with quote
ASHLEY4



Joined: 28 Apr 2004
Posts: 376
Location: UK
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.
Post 13 Jul 2004, 00:51
View user's profile Send private message Reply with quote
windwakr



Joined: 30 Jun 2004
Posts: 827
Location: Michigan, USA
good game......Its quite fun
Post 13 Jul 2004, 16:29
View user's profile Send private message Reply with quote
Jaques



Joined: 07 Jun 2004
Posts: 79
Location: Everywhere
Where exactly is volume i found freq
Post 13 Jul 2004, 18:37
View user's profile Send private message Reply with quote
Matrix



Joined: 04 Sep 2004
Posts: 1171
Location: Overflow
Jaques wrote:
Where exactly is volume i found freq


Smile

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
Post 11 Sep 2004, 09:39
View user's profile Send private message Visit poster's website Reply with quote
Matrix



Joined: 04 Sep 2004
Posts: 1171
Location: Overflow
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
Post 15 Sep 2004, 20:17
View user's profile Send private message Visit poster's website Reply with quote
Matrix



Joined: 04 Sep 2004
Posts: 1171
Location: Overflow
Dos beeps is kind of interesting question but the problem is here solved, pc speaker usage:

http://board.flatassembler.net/topic.php?t=2432
Post 23 Oct 2004, 15:34
View user's profile Send private message Visit poster's website Reply with quote
Jaques



Joined: 07 Jun 2004
Posts: 79
Location: Everywhere
MAKE IT PLAY A SCALE
Post 23 Oct 2004, 21:42
View user's profile Send private message Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2019, Tomasz Grysztar.

Powered by rwasa.