flat assembler
Message board for the users of flat assembler.

Index > Tutorials and Examples > DOS Sound Effects

Author
Thread Post new topic Reply to topic
Walter



Joined: 26 Jan 2013
Posts: 155
Walter 20 Apr 2013, 02:54
Fone Tone.

A good sound effect.

Orginal was most likely written by Bill Cravener. I've heard that he might hang out over at the "Offset Ptr" forum.
Code:
;****************
;* FoneTone.asm *
;****************

org 0x100
use16

FoneTone:
        cli
        mov     si, 0x2                 ; Two six pulse groups two times.

FoneTone1:
        mov     di, 0x2                 ; Each group (six pulses) two times.

FoneTone2:
        mov     dx, 0x6                 ; Six pulses of each tone.

FoneTone3:
        mov     bx, 2000                ; Frequency of first tone.
        call    SpeakerOn
        mov     [wCount], 0x1
        call    Delay
        mov     bx, 1600                ; Frequency of second tone.
        call    SpeakerOn
        mov     [wCount], 0x1
        call    Delay
        dec     dx
        jnz     FoneTone3
        dec     di
        jnz     FoneTone2
        call    SpeakerOff
        mov     [wCount], 0x1e
        call    Delay
        dec     si
        jnz     FoneTone1
        sti

        mov     ax, 0x4c00
        int     0x21

Delay:
        push    ax
        push    bx
        push    dx
        mov     ah, 0x0
        int     0x1a
        add     dx, [wCount]
        mov     bx, dx

Delay1:
        int     0x1a
        cmp     dl, bl
        jnz     Delay1
        pop     dx
        pop     bx
        pop     ax
        ret

SpeakerOn:
        mov     al, 10110110b                      ; Channel 2.
        out     0x43, al
        mov     ax, bx
        out     0x42, al
        mov     al, ah
        out     0x42, al
        in      al, 0x61
        or      al, 00000011b
        out     0x61, al
        ret

SpeakerOff:
        in      al, 0x61
        and     al, 11111100b
        out     0x61, al
        ret

wCount dw ?
    
Post 20 Apr 2013, 02:54
View user's profile Send private message Reply with quote
HaHaAnonymous



Joined: 02 Dec 2012
Posts: 1178
Location: Unknown
HaHaAnonymous 20 Apr 2013, 16:00
[ Post removed by author. ]


Last edited by HaHaAnonymous on 28 Feb 2015, 21:00; edited 1 time in total
Post 20 Apr 2013, 16:00
View user's profile Send private message Reply with quote
DOS386



Joined: 08 Dec 2006
Posts: 1905
DOS386 28 Apr 2013, 15:02
It works Smile

PS: a version of this had been included with the CC386 compiler for centuries Smile

http://ladsoft.tripod.com/cc386.htm (dead)

http://ladsoft.tripod.com/cc386_compiler.html


Last edited by DOS386 on 02 Jun 2013, 08:02; edited 1 time in total
Post 28 Apr 2013, 15:02
View user's profile Send private message Reply with quote
DOS386



Joined: 08 Dec 2006
Posts: 1905
DOS386 02 Jun 2013, 08:01
Code:
; FONETONE.ASM (optimized and bug-free) 2013-Jun-02

format binary as "COM"
org $0100
use16

        call   group12sub
        mov    cx, $1E            ; 30
        call   delaysub
        call   group12sub

        mov    ax, $4C00
        int    $21                ; F**K OFF
        ;---------

group12sub:
        mov    dx, 12             ; 12 pulses of each tone
@@:     mov    bx, 2000           ; Frequency of first tone
        call   speakerondelsub
        mov    bx, 1600           ; Frequency of second tone
        call   speakerondelsub
        dec    dx
        jnz    short @b

        in     al, $61
        and    al, 252            ; %1111'1100
        out    $61, al            ; Speaker OFF
        ret
        ;----

speakerondelsub:
        mov    al, 182            ; %1011'0110 | Channel 2
        out    $43, al
        xchg   ax, bx             ; Incoming freq in BX (trashed)
        out    $42, al
        mov    al, ah
        out    $42, al
        in     al, $61
        or     al, 3              ; %0000'0011
        out    $61, al            ; Speaker ON
        mov    cx, 1
        ; and pass

delaysub:
        xor    ax, ax             ; MOVNTQ AX, 0
        mov    es, ax             ; MOVNTQ ES, 0

delay_loop:
        mov    al, [es:$046C]     ; BIOS timer
@@:     cmp    al, [es:$046C]     ; BIOS timer
        je     short @b
        loop   short delay_loop   ; Incoming delay in CX (trashed)

        ret                       ; We trashed AX and CX and ES !!!
        ;----
    


FONETONE.COM 80
7F2B'EAAE'360A'7389'E512'E0E2'3242'1273


- Fixed critical BUG with risk of permanent hanging in the delay sub Smile
- Fixed BUG with junk delay on exit Smile
- Simplified code and reduced nested loops Smile
- Reduced bloat from 116 to 80 Byte's Smile
Post 02 Jun 2013, 08:01
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-2025, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.