Page 1 of 1

Confusion on bootsector

Posted: Wed Mar 12, 2008 11:13 am
by Ruxbin
Hi,all
We all know that the bootsector often dump some text like "booting..."on the screen. I'm thinking about adding some sounds while booting. So I googled and found http://www.delphi3000.com/articles/article_3773.asp?SK= useful.Using 8253/8254 channel2 ,PPI and speaker can produce sounds :roll:.After compiling,I use bochs to test the codes. But there is no sound at all :( . I use bochs to trace every lines of codes and found that the codes themselves should be all right(no errors like write %ax to (%ax))
Anyone know the reason? Thanks!
Here are my codes:(at&t style)
#bootsect.s

Code: Select all

.text
	.global start
	.code16
Freq=100
start:
	mov $0x0b6,%al
	out %al,$0x43
	mov $0x14,%dx
	mov $0x4f38,%ax 	 #dx:ax=0x144f38=1331000
	mov $Freq,%bx
	div %bx				   #ax=1331000/Freq
	out %al,$0x42		  #write low byte
	mov %ah,%al
	out %al,$0x42		 #write high byte

	mov $100,%dx		   #dx is the loop times
	in $0x61,%al		  #read the PPI's state
	and $0xfd,%al	     #do some bits operation
							           #set bit 0-->use the 8253/8254
							          #clear bit 1-->turn speaker off
sound:
	xor $2,%al			         #converse bit 1
	out %al,$0x61
	mov $0x140,%cx                 #loop some time
wait:
	loop wait
	dec %dx
	jne sound
end:jmp end
.org 0x1fe,0x90
.word 0xaa55
and the link scripts :ld--oformat binary -s -x -N -e start -Ttext 0x7c00 bootsect.o -o bootsect :idea:

Posted: Wed Mar 12, 2008 11:20 am
by Ruxbin
I am in China. And the time is 1:18 am :shock:
need some sleep now :D
Hope when I wake up my problem will be fixed. :lol:

Posted: Wed Mar 12, 2008 11:59 am
by Combuster
Ruxbin wrote:I am in China. And the time is 1:18 am :shock:
need some sleep now :D
Hope when I wake up my problem will be fixed. :lol:
Apparently you didn't read the rules - otherwise you'd know posting this is a _bad_ idea

Posted: Wed Mar 12, 2008 3:41 pm
by 01000101

Code: Select all

    outportb(0x43, 0xB6);
    Freq = 0x1D4C0/Freq;
    Freq_Hi = (Freq >> 8) & 0x00FF;
    Freq_Lo = Freq & 0x00FF;
    outportb(0x42, Freq_Hi);
    outportb(0x42, Freq_Lo);

    /* Turn the speaker on */
    outportb(0x61, inportb(0x61) | 3 );

Posted: Wed Mar 12, 2008 8:00 pm
by Ruxbin
Combuster wrote:
Ruxbin wrote:I am in China. And the time is 1:18 am :shock:
need some sleep now :D
Hope when I wake up my problem will be fixed. :lol:
Apparently you didn't read the rules - otherwise you'd know posting this is a _bad_ idea
:P yes,you are right. All these words are useless and I'm sorry about that.They don't relate to OS development.
Still I want some help. 8)

Posted: Wed Mar 12, 2008 8:14 pm
by Brendan
Hi,

Here's some code from my boot loader:

Code: Select all

;Note: The frequency of "middle C" is 261.63 Hz, so the timer count is set to
;      [i1193180 / 261.63] to get this tone (middle C was chosen as it's in the middle
;      of the audible frequency range). This works out to a count of 4561, or 0x11D1.

	mov al,10110110b			;al = counter 2, low then high, square wave, 16 bit
	cli
	out 0x43,al				;Set timer channel 2 mode
	jmp $+2
	jmp $+2
	mov al,0xD1				;al = low count
	out 0x42,al				;Set timer channel 2 low count
	jmp $+2
	jmp $+2
	mov al,0x11				;al = high count
	out 0x42,al				;Set timer channel 2 high count
	sti

	in al,0x61				;al = system control port
	or al,00000011b				;Set speaker enable and PIT to speaker enable bits
	out 0x61,al				;Set system control port
If you compare my code, 01000101's code and your code you'll notice a few differences...

Note: I run Bochs on a server that doesn't have any sound card, so I don't know if this works on Bochs or not. I do know my code works on all real machines I've tried it on...


Cheers,

Brendan

Posted: Wed Mar 12, 2008 8:29 pm
by Ruxbin
01000101 wrote:

Code: Select all

    outportb(0x43, 0xB6);
    Freq = 0x1D4C0/Freq;
    Freq_Hi = (Freq >> 8) & 0x00FF;
    Freq_Lo = Freq & 0x00FF;
    outportb(0x42, Freq_Hi);
    outportb(0x42, Freq_Lo);

    /* Turn the speaker on */
    outportb(0x61, inportb(0x61) | 3 );
Thanks.
I've tried your code. But still there is no sound. Is that because Vmware or Bochs dosen't support this raw method to generate some sounds?

Posted: Wed Mar 12, 2008 8:54 pm
by Ruxbin
to Brendan:
Thanks a lot for your help.:D
I've tried out your codes and bochs still doesn't responded to them. :(
I doubt this may be bochs's problem. Thanks anyway and I'll try the codes in real machine. 8)

Posted: Thu Mar 13, 2008 2:07 am
by 01000101
yeah the code above has only been tested by me on a real machine.

Posted: Thu Mar 13, 2008 2:46 am
by zaleschiemilgabriel
Are you by any chance trying to make an alarm clock? :)

Posted: Thu Mar 13, 2008 4:23 am
by Ruxbin
zaleschiemilgabriel wrote:Are you by any chance trying to make an alarm clock? :)
yes,my system has timer interrupt and it is generated by 8253. Here I use 8254 to control the speaker. I've tried all the codes in real machine and everything went on quite well. :D