~ubuntu-branches/debian/squeeze/stella/squeeze

« back to all changes in this revision

Viewing changes to src/ui/dos/SndDOS.cxx

  • Committer: Bazaar Package Importer
  • Author(s): Tom Lear
  • Date: 1999-11-06 16:41:05 UTC
  • Revision ID: james.westby@ubuntu.com-19991106164105-iygopamo5mpcozvx
Tags: upstream-1.1
ImportĀ upstreamĀ versionĀ 1.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
//============================================================================
 
2
//
 
3
//   SSSS    tt          lll  lll       
 
4
//  SS  SS   tt           ll   ll        
 
5
//  SS     tttttt  eeee   ll   ll   aaaa 
 
6
//   SSSS    tt   ee  ee  ll   ll      aa
 
7
//      SS   tt   eeeeee  ll   ll   aaaaa  --  "An Atari 2600 VCS Emulator"
 
8
//  SS  SS   tt   ee      ll   ll  aa  aa
 
9
//   SSSS     ttt  eeeee llll llll  aaaaa
 
10
//
 
11
// Copyright (c) 1995-1998 by Bradford W. Mott
 
12
//
 
13
// See the file "license" for information on usage and redistribution of
 
14
// this file, and for a DISCLAIMER OF ALL WARRANTIES.
 
15
//
 
16
// $Id: SndDOS.cxx,v 1.1 1998/08/01 21:11:42 bwmott Exp $
 
17
//============================================================================
 
18
 
 
19
#include <unistd.h>
 
20
 
 
21
#include "SndDOS.hxx"
 
22
#include "TIASound.h"
 
23
#include "sbdrv.h"
 
24
 
 
25
/**
 
26
  Compute the buffer size to use based on the given sample rate
 
27
 
 
28
  @param The sample rate to compute the buffer size for
 
29
*/
 
30
static unsigned long computeBufferSize(int sampleRate)
 
31
{
 
32
  int t;
 
33
 
 
34
  for(t = 7; t <= 12; ++t)
 
35
  {
 
36
    if((1 << t) > (sampleRate / 60))
 
37
    {
 
38
      return (1 << (t - 1));
 
39
    }
 
40
  }
 
41
 
 
42
  return 256;
 
43
}
 
44
 
 
45
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
 
46
SoundDOS::SoundDOS()
 
47
{
 
48
  int sampleRate = 15700;
 
49
  int DMABufferSize = computeBufferSize(sampleRate);
 
50
 
 
51
  if(OpenSB(sampleRate, DMABufferSize))
 
52
  {
 
53
    myEnabled = true;
 
54
 
 
55
    // Initialize TIA Sound Library
 
56
    Tia_sound_init(31400, sampleRate);
 
57
 
 
58
    // Start playing audio
 
59
    Start_audio_output(AUTO_DMA, 
 
60
        (void (*)(unsigned char*, short unsigned int))Tia_process);
 
61
  }
 
62
  else
 
63
  {
 
64
    // Oops, couldn't open SB so we're not enabled :-(
 
65
    myEnabled = false;
 
66
    return;
 
67
  }
 
68
}
 
69
 
 
70
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
 
71
SoundDOS::~SoundDOS()
 
72
{
 
73
  if(myEnabled)
 
74
  {
 
75
    CloseSB();
 
76
  }
 
77
}
 
78
 
 
79
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
 
80
void SoundDOS::set(Sound::Register reg, uInt8 value)
 
81
{
 
82
  if(!myEnabled)
 
83
    return;
 
84
 
 
85
  switch(reg) 
 
86
  {
 
87
    case AUDC0:
 
88
      Update_tia_sound(0x15, value);
 
89
      break;
 
90
    
 
91
    case AUDC1:
 
92
      Update_tia_sound(0x16, value);
 
93
      break;
 
94
 
 
95
    case AUDF0:
 
96
      Update_tia_sound(0x17, value);
 
97
      break;
 
98
    
 
99
    case AUDF1:
 
100
      Update_tia_sound(0x18, value);
 
101
      break;
 
102
 
 
103
    case AUDV0:
 
104
      Update_tia_sound(0x19, value);
 
105
      break;
 
106
 
 
107
    case AUDV1:
 
108
      Update_tia_sound(0x1A, value);
 
109
      break;
 
110
 
 
111
    default:
 
112
      break;
 
113
  }
 
114
}
 
115
 
 
116
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
 
117
void SoundDOS::mute(bool state)
 
118
{
 
119
  if(state)
 
120
  {
 
121
    Stop_audio_output();
 
122
  }
 
123
  else
 
124
  {
 
125
    Start_audio_output(AUTO_DMA, 
 
126
        (void (*)(unsigned char*, short unsigned int))Tia_process);
 
127
  }
 
128
}
 
129