home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
ARM Club 3
/
TheARMClub_PDCD3.iso
/
programs
/
emulaton
/
at2600
/
!v2600
/
c
/
arc_sound
< prev
next >
Wrap
Text File
|
1998-04-10
|
3KB
|
129 lines
/****************************************************************************
This file is part of x2600, the Atari 2600 Emulator
===================================================
Copyright 1996 Alex Hornby. For contributions see the file CREDITS.
This software is distributed under the terms of the GNU General Public
License. This is free software with ABSOLUTELY NO WARRANTY.
See the file COPYING for details.
$Id: dos_sound.c,v 1.1 1997/02/23 20:39:29 ahornby Exp $
****************************************************************************/
#include "config.h"
#include "swis.h"
#include <stdio.h>
#include <stdlib.h>
#include "types.h"
#include "options.h"
#include "vmachine.h"
#include "tiasound.h"
#define S_BUFMAX 314*4
#define SAMPLE_RATE 20833
#define AUDIO_CLOCK 31400
static int sound_change;
static int sndbufsize = S_BUFMAX;
static BYTE *buffer, *bufpt;
int sound_available;
int sound_channel;
int sound_area;
/* Turn on the sound */
void sound_init (void){
int temp;
char chandat[255];
_swi(0x44393,_IN(0)|_OUT(0), 0xC26, &sound_channel);
if(sound_channel != 0){
Tia_sound_init(AUDIO_CLOCK, SAMPLE_RATE);
_swi(OS_DynamicArea, _INR(0,8)|_OUT(1)|_OUT(3), 0, -1, S_BUFMAX, -1,
0x30, S_BUFMAX, 0, 0, "v2600 sound buffer", &sound_area, &buffer);
bufpt = buffer;
_swi(0x44386,_IN(0)|_IN(1)|_IN(2), sound_channel, bufpt, bufpt+S_BUFMAX);
_swi(0x4438E,_IN(0)|_IN(1)|_OUT(0), 1000000/SAMPLE_RATE, 0, &temp);
_swi(0x44380,_IN(0)|_IN(1), sound_channel, 1);
_swi(0x44381,_IN(0)|_IN(1), sound_channel, 1);
_swi(0x44382,_IN(0)|_IN(1), sound_channel, temp);
/* read what channel was before */
sprintf(chandat, "channelvoice %d DataVox-Voice", sound_channel);
system(chandat);
}
}
void sound_update(void){
if(sound_channel != 0){
if(sound_change){
Tia_process(bufpt, sndbufsize);
_swi(Sound_Control, _INR(0,3), sound_channel, 0xFFF1, 0x4000, 0xFF);
sound_change=0;
}
}
}
/* Turn off the sound */
void
sound_close (void){
if(sound_channel != 0){
_swi(0x44390, _IN(0), sound_channel); /* Unset datavox channel */
_swi(0x44394, _IN(0)|_IN(1), sound_channel, 0xC26); /* deregister it */
_swi(OS_DynamicArea, _IN(0)|_IN(1), 1, sound_area); /* dealloc memory*/
/* set channel to what it was before loaded.*/
}
}
void
sound_freq(int channel, BYTE freq)
{
static BYTE last[2];
if(last[channel]!=freq)
{
Update_tia_sound(0x17 + channel, freq);
sound_change=1;
last[channel]=freq;
}
}
void
sound_volume(int channel, BYTE vol)
{
static BYTE last[2];
if(last[channel]!=vol)
{
Update_tia_sound(0x19 + channel, vol);
sound_change=1;
last[channel]=vol;
}
}
void
sound_waveform(int channel, BYTE value)
{
static BYTE last[2];
if(last[channel]!=value)
{
Update_tia_sound(0x15 + channel, value);
sound_change=1;
last[channel]=value;
}
}