flat assembler
Message board for the users of flat assembler.
Index
> OS Construction > PC Speaker |
Author |
|
bubach 02 Mar 2012, 00:01
can you post your code, maybe we can find something wrong with it or compare to other sources and documents.
|
|||
02 Mar 2012, 00:01 |
|
smiddy 02 Mar 2012, 00:17
Here's a snippet from Using Assembly Language and controlling the speaker:
Code: IN al,61h PUSH ax MOV dx,0Bh Main: MOV bx,477 ; 1,193,180 / 2500 (assume this is timing to frequency) CALL WarbCom MOV cx, 2600h Delay1: LOOP Delay1 MOV bx, 36 1; 1,193,180 / 32767 CALL WarbCom MOV cx,1300h Delay2: LOOP Delay2 DEC dx JNZ Main POP ax OUT 61h,al --------------O/---------- O\ WarbCom: MOV al,10110110b OUT 43h,al MOV ax,bx OUT 42h,al MOV al,ah OUT 42h,al IN al, 61h OR al,00000011b OUT 61h,al RET I haven't tested this. Here is an associate paragraph: Code: This example, which shows how you can control the speaker directly, uses both 8253 timer and the 8255 PPI. The Warble subroutine (the one I typed in first) provides good sound for error routines. BOOP (one I didn't type in) provides a gentle sound when the wrong key is pressed. p. 392 Using Assembly Language 2nd Edition, by Allen L. Wyatt, (C) 1990 |
|||
02 Mar 2012, 00:17 |
|
shutdownall 02 Mar 2012, 11:46
I don't know what OS you use but if it is windows, why not use better the beep function ?
http://msdn.microsoft.com/en-us/library/windows/desktop/ms679277%28v=vs.85%29.aspx Quote:
|
|||
02 Mar 2012, 11:46 |
|
revolution 02 Mar 2012, 11:52
shutdownall wrote: I don't know what OS you use but if it is windows, why not use better the beep function ? |
|||
02 Mar 2012, 11:52 |
|
shutdownall 02 Mar 2012, 12:10
"I put the code in my operating system on a virtual machine but heard nothing."
Hmm - if he is able to construct an own OS with an own virtual machine (for x86 ?) - i assume he wouldn't ask this question at all. I think he maybe missed the wrong section here at the board. |
|||
02 Mar 2012, 12:10 |
|
revolution 02 Mar 2012, 12:21
The remarks section on the Beep function page is interesting:
Quote: A long time ago, all PC computers shared a common 8254 programable interval timer chip for the generation of primitive sounds. The Beep function was written specifically to emit a beep on that piece of hardware. Quote: Windows 95: |
|||
02 Mar 2012, 12:21 |
|
shutdownall 02 Mar 2012, 16:58
On my system (Intel Quad Core + XP Prof) both works fine.
Code: invoke Beep,500,400 invoke Beep,1000,200 invoke Beep,2000,100 invoke Beep,4000,50 invoke MessageBeep,MB_ICONEXCLAMATION |
|||
02 Mar 2012, 16:58 |
|
edfed 02 Mar 2012, 17:35
beep.inc wrote:
this code needs the timer to have a routine int8 with datas named ticks, inc, etc. the beep is quite easy to implement, but the next it more tricky cause you need the timer to control the duration. or use just a delay loop, but a delay loop sucks, better to use at least a timer relative loop. and better would be to set a timer event. because sound needs a really real time synchronisation to be cool. |
|||
02 Mar 2012, 17:35 |
|
smiddy 02 Mar 2012, 17:47
Nice edfed!
|
|||
02 Mar 2012, 17:47 |
|
A$M 03 Mar 2012, 00:12
Ok... the sound include code is:
Code: ; AX - Note frequency speaker_tone: pusha mov cx, ax ; Store note value for now mov al, 182 out 43h, al mov ax, cx ; Set up frequency out 42h, al mov al, ah out 42h, al in al, 61h ; Switch PC speaker on or al, 03h out 61h, al popa ret speaker_off: pusha in al, 61h and al, 0FCh out 61h, al popa ret It's very simple... |
|||
03 Mar 2012, 00:12 |
|
Dex4u 03 Mar 2012, 00:57
You need 3 things for beep
sound on delay sound off |
|||
03 Mar 2012, 00:57 |
|
A$M 03 Mar 2012, 12:39
Ok... I will try this... Thanks.
|
|||
03 Mar 2012, 12:39 |
|
A$M 03 Mar 2012, 12:54
No. Using the delay function not solve the problem, Dex4u.
|
|||
03 Mar 2012, 12:54 |
|
smiddy 03 Mar 2012, 16:00
How long was your delay?
|
|||
03 Mar 2012, 16:00 |
|
A$M 03 Mar 2012, 19:33
I tried 10.000.000 µs (microseconds).
|
|||
03 Mar 2012, 19:33 |
|
Dex4u 03 Mar 2012, 20:54
This very old code used to work, so if it does not its the PC.
Code: org 0x100 use16 start: CBA1: MOV CX,10 MOV [W],10 CBA2: PUSH CX TT4: ADD [W],1000 MOV AX,[W] SAR AX,3 MOV BX,40 MUL BX MOV BX,10000 MUL BX MOV [Hz],DX CALL Sound ; MOV [ms1],1 ; CALL DeLay MOV [ms1],11 CALL DeLay POP CX LOOP CBA2 CALL NoSound XOR AH,AH INT 16h CALL NoSound IN AL,60H CMP AL,1 JNE CBA1 INT 20h ;----------------------------------------------------; ; Sound ; ;----------------------------------------------------; Sound: mov bx,[Hz] mov ax,0x34dd mov dx,0x0012 cmp dx,bx jnc Done1 div bx mov bx,ax in al,0x61 test al,3 jnz A99 or al,3 out 0x61,al mov al,0xb6 out 0x43,al A99: mov al,bl out 0x42,al mov al,bh out 0x42,al Done1: ret ;----------------------------------------------------; ; NoSound ; ;----------------------------------------------------; NoSound: in al,0x61 and al,11111100b out 0x61,al ret ;----------------------------------------------------; ; DeLay ; ;----------------------------------------------------; DeLay: mov cx,[ms1] jcxz A2 A1: call DeLaYoneMS loop A1 A2: ret ;----------------------------------------------------; ; DeLaYoneMS ; ;----------------------------------------------------; DeLaYoneMS: push ecx mov cx,[OneMS] B1: loop B1 pop ecx ret OneMS dw 40000 Hz dw 0 ms1 dw 20 W dw 0 Note: its for dos. I know you said that the game worked, but it could be using PC sound, maybe sound blaster 16 etc. |
|||
03 Mar 2012, 20:54 |
|
DOS386 04 Mar 2012, 07:40
> know you said that the game worked
in DOS ??? Failed to reveal how tested the game and the code ... maybe the game uses PC speaker only if it doesn't find SB. Also, it's a bad idea to test DOS or raw code inside NTVDM. > but it could be using PC sound, maybe sound blaster 16 etc. Right ... if NOT run in DOS. BTW, some PC's (but not those with ISA SB 16) simply have NO PC SPEAKER at all (and don't connect the PIT to the soundcard either) so PC speaker code will NOT WORK ... and there is no way to detect this |
|||
04 Mar 2012, 07:40 |
|
edfed 04 Mar 2012, 10:47
would be really cool to have a fasm function for sound playing.
a sort of channel, using a full segment as buffer, like vga card, would be very very very nice. i'd like to have this kind of code able to play real sounds. and lets play math music! things that no synth can do all over the world, some randomly minded asm code will do easy. |
|||
04 Mar 2012, 10:47 |
|
< Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.