TMSOUND


TMSOUND ( 5.2) .

5.2. tmsound\tmsound.

// =====================================================

//

//

// (C) ., 1997

//

// E-mail: frolov@glas.apc.org

// WWW: http://www.glasnet.ru/~frolov

//

// http://www.dials.ccas.ru/frolov

// =====================================================

#include <stdio.h>

#include <conio.h>

#include <dos.h>

void sound(int, int);

void tm_sound(int freq, int time);

void tm_delay(int ticks);

//

int mary[] =

{

330, 294, 262, 294, 330, 330, 330,

294, 294, 294, 330, 392, 392,

330, 294, 262, 294, 330, 330, 330, 330,

294, 294, 330, 294, 262, 0

};

//

int del[] =

{

5, 5, 5, 5, 5, 5, 10,

5, 5, 10, 5, 5, 10,

5, 5, 5, 5, 5, 5, 5, 5,

5, 5, 5, 5, 20

};

int main(void)

{

int i;

for(i=0 ;mary[i] != 0 ;i++)

tm_sound(mary[i], del[i]);

return 0;

}

/**

*.Name tm_sound

*.Title

*

*.Descr

*

*

*

*.Proto void tm_sound(int freq, int time);

*

*.Params int freq - ;

* int time -

*

**/

void tm_sound(int freq, int time)

{

int cnt;

// 2

outp(0x43, 0xb6);

//

//

cnt = (int)(1193180L / freq);

// -

// ,

outp(0x42, cnt & 0x00ff);

outp(0x42, (cnt &0xff00) >> 8);

// .

// 2


//

outp(0x61, inp(0x61) | 3);

// .

tm_delay(time);

// .

outp(0x61, inp(0x61) & 0xfc);

}

/**

*.Name tm_delay

*.Title

*

*.Descr ,

*

*

*.Proto void tm_delay(int ticks)

*

*.Params int ticks -

**/

void tm_delay(int ticks)

{

_asm

{

push si

mov si, ticks

mov ah, 0

int 1ah

mov bx, dx

add bx, si

delay_loop:

int 1ah

cmp dx, bx

jne delay_loop

pop si

}

}










Forekc.ru
, , , , , , , , , ,