flat assembler
Message board for the users of flat assembler.

Index > DOS > how to make quality of sound better?

Author
Thread Post new topic Reply to topic
KIRK



Joined: 05 Dec 2007
Posts: 20
Location: Russia
KIRK 16 Dec 2007, 09:49
how to make frequency changing there was more smoothly?
Code:
   org   $100
   mov   bp,100
   mov   sp,250
   mov   di,bp
   mov   cx,1
b1:call  Beep
   add   di,cx
   cmp   di,sp
   jb    b1
b2:call  Beep
   sub   di,cx
   cmp   di,bp
   ja    b2
   jmp   b1

Beep:
   call  StartBeep
   call  Delay
   call  StopBeep
   ret

StartBeep:
   mov   bx,di
   mov   ax,34ddh
   mov   dx,0012h 
   cmp   dx,bx 
   jnc   DN
   div   bx
   mov   bx,ax
   in    al,61h 
   test  al,3
   jnz   @f
   or    al,3
   out   61h,al
   mov   al,0b6h 
   out   43h,al 
@@:mov   al,bl
   out   42h,al 
   mov   al,bh
   out   42h,al
DN:ret

Delay:
   xor   ax,ax 
   mov   es,ax 
   mov   eax,[es:46ch]
@@:cmp   eax,[es:46ch]
   jnb   @b
   xor   ax,ax
   in    al,60h 
   test  al,10000000b
   jnz   Exit
   ret

StopBeep:
   in    al,61h
   and   al,11111100b
   out   61h,al
   ret

Exit:
   mov   ax,4Ch 
   int   21h    
Post 16 Dec 2007, 09:49
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20451
Location: In your JS exploiting you and your system
revolution 16 Dec 2007, 10:45
Try to use a different register than sp for your counter loop. This won't improve the quality of sound but will reduce your headaches with stack problems when your code becomes larger.
Post 16 Dec 2007, 10:45
View user's profile Send private message Visit poster's website Reply with quote
KIRK



Joined: 05 Dec 2007
Posts: 20
Location: Russia
KIRK 16 Dec 2007, 13:09
I need to carry out only one task - to write a siren =)
Post 16 Dec 2007, 13:09
View user's profile Send private message Reply with quote
DOS386



Joined: 08 Dec 2006
Posts: 1905
DOS386 16 Dec 2007, 13:20
Code:

    org $100
    format binary as "COM"

    mov   di,100

b1: call  Beep
    inc   di
    cmp   di,255
    jne   b1

b2: call  Beep
    dec   di
    cmp   di,100
    jne   b2

    in    al,$61
    and   al,11111100b
    out   $61,al       ; Shut up now !!!

    mov   ax,$4C00
    int   $21

Beep:
    mov   bx,di
    mov   ax,$34DD
    mov   dx,$0012
    div   bx  ; Divident from DX:AX | Quotient in AX
    mov   bx,ax
    in    al,61h
    test  al,3
    jnz   @f
    or    al,3
    out   61h,al
    mov   al,$B6
    out   43h,al

@@: mov   al,bl
    out   42h,al
    mov   al,bh
    out   42h,al

    xor   ax,ax
    mov   es,ax
    mov   eax,[es:$46C]
@@: cmp   eax,[es:$46C]
    jz    @b
    ret
    


Your code was desperately buggy and didn't work at all for me - starts the sound and then aborts using an illegal way while sound remains on Sad

Fixed the SP bug as well as the sound quality bug and many other bugs Shocked

Next time, please comment your code - I have no clue what those various silly instructions in your code were supposed do Confused

_________________
Bug Nr.: 12345

Title: Hello World program compiles to 100 KB !!!

Status: Closed: NOT a Bug
Post 16 Dec 2007, 13:20
View user's profile Send private message Reply with quote
KIRK



Joined: 05 Dec 2007
Posts: 20
Location: Russia
KIRK 16 Dec 2007, 14:22
hey, man, you has gone mad on bugs!
probably there was one bug, but it is no more!

with comments and some changes
Code:
   org   $100
   mov   bp,100  ;initial value of minimal frequency
   mov   sp,250  ;initial value of maximal frequency
   mov   di,bp
   mov   cx,1    ;initial value of step for changing frequency
b1:call  Beep    ;increase frequency
   add   di,cx
   cmp   di,sp
   jb    b1
b2:call  Beep    ;decrease frequency
   sub   di,cx
   cmp   di,bp
   ja    b2
   jmp   b1

Beep:
   mov   bx,di     ;start playing of the sound
   mov   ax,34DDh
   mov   dx,0012h
   div   bx
   mov   bx,ax
   in    al,61h 
   test  al,3
   jnz   @f
   or    al,3
   out   61h,al
   mov   al,0B6h 
   out   43h,al 
@@:mov   al,bl
   out   42h,al 
   mov   al,bh
   out   42h,al
   xor   ax,ax           ;start anything for a small pause
   mov   es,ax 
   mov   eax,[es:46Ch]
@@:cmp   eax,[es:46Ch]
   jnb   @b
   xor   ax,ax           ;check keyboard input
   in    al,60h 
   test  al,10000000b
   jnz   Exit            ;exit if any key was pressed
   in    al,61h          ;stop the sound
   and   al,11111100b
   out   61h,al
   ret

Exit:
   mov   ax,4Ch 
   int   21h
    
Post 16 Dec 2007, 14:22
View user's profile Send private message Reply with quote
DOS386



Joined: 08 Dec 2006
Posts: 1905
DOS386 18 Dec 2007, 18:52
> hey, man, you has gone mad on bugs!

NO. And you re-implemented at least 3 critical bugs I had fixed for you. But there is indeed no help against intentional bugs. Very Happy
Post 18 Dec 2007, 18:52
View user's profile Send private message Reply with quote
edfed



Joined: 20 Feb 2006
Posts: 4353
Location: Now
edfed 19 Dec 2007, 23:28
sp is used by call.
used to tell where to return.
1 very important rule, never use sp/esp as a register

erf erf erf Very Happy Surprised Laughing Razz Twisted Evil Very Happy Laughing
Post 19 Dec 2007, 23:28
View user's profile Send private message Visit poster's website Reply with quote
System86



Joined: 15 Aug 2007
Posts: 77
System86 08 Jan 2008, 02:07
Quote:

sp is used by call.
used to tell where to return.
1 very important rule, never use sp/esp as a register


Right. SP/ESP is actually used/modified by all of the following. So, don't use SP if you plan on using any of the following:
*push
*pop
*pushf
*popf
*pusha
*popa
*call
*ret
*int
*iret
*enter
*leave.

Using any of these (if SP contains data) will overwrite random data somewhere in memory and will change the data in SP.

Even worse, if a hardware interrupt occurs (RTC interrupt, user hitting the keyboard) the return value is saved on the stack, so somewhere in memory data is overwritten, with undefined results. The only way to avoid this is to cli before using SP, but then all I/O must be done with polling the hardware with in/out, since you lost DOS/BIOS (no INT or CALL).

Basically, only change SP/ESP if you want to change the location of the stack.
Post 08 Jan 2008, 02:07
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.