flat assembler
Message board for the users of flat assembler.
 Home   FAQ   Search   Register 
 Profile   Log in to check your private messages   Log in 
flat assembler > Examples and Tutorials > DOS Sound Effects

Author
Thread Post new topic Reply to topic
Walter



Joined: 26 Jan 2013
Posts: 51
DOS Sound Effects
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     si0x2                 ; Two six pulse groups two times.

FoneTone1:
        mov     di0x2                 ; Each group (six pulses) two times.

FoneTone2:
        mov     dx0x6                 ; Six pulses of each tone.

FoneTone3:
        mov     bx2000                ; Frequency of first tone.
        call    SpeakerOn
        mov     [wCount], 0x1
        call    Delay
        mov     bx1600                ; 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     ax0x4c00
        int     0x21

Delay:
        push    ax
        push    bx
        push    dx
        mov     ah0x0
        int     0x1a
        add     dx, [wCount]
        mov     bxdx

Delay1:
        int     0x1a
        cmp     dlbl
        jnz     Delay1
        pop     dx
        pop     bx
        pop     ax
        ret

SpeakerOn:
        mov     al10110110b                      ; Channel 2.
        out     0x43al
        mov     axbx
        out     0x42al
        mov     alah
        out     0x42al
        in      al0x61
        or      al00000011b
        out     0x61al
        ret

SpeakerOff:
        in      al0x61
        and     al11111100b
        out     0x61al
        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: 1005
Location: Unknown
Finally a decent DOS example!

Thanks, Walter!
Post 20 Apr 2013, 16:00
View user's profile Send private message Reply with quote
DOS386



Joined: 08 Dec 2006
Posts: 1824
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: 1824

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    dx12             ; 12 pulses of each tone
@@:     mov    bx2000           ; Frequency of first tone
        call   speakerondelsub
        mov    bx1600           ; Frequency of second tone
        call   speakerondelsub
        dec    dx
        jnz    short @b

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

speakerondelsub:
        mov    al182            ; %1011'0110 | Channel 2
        out    $43al
        xchg   axbx             ; Incoming freq in BX (trashed)
        out    $42al
        mov    alah
        out    $42al
        in     al$61
        or     al3              ; %0000'0011
        out    $61al            ; Speaker ON
        mov    cx1
        ; and pass

delaysub:
        xor    axax             ; MOVNTQ AX, 0
        mov    esax             ; 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 cannot download files in this forum


Powered by phpBB © 2001-2005 phpBB Group.

Main index   Download   Documentation   Examples   Message board
Copyright © 2004-2013, Tomasz Grysztar.