~jazzva/fakenes/ubuntu

« back to all changes in this revision

Viewing changes to src/include/apu_int.h

  • Committer: Sasa Bodiroza
  • Date: 2007-08-15 05:37:49 UTC
  • Revision ID: jazzva@gmail.com-20070815053749-76l0xj66tzgt290p
Upstream release.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* FakeNES - A free, portable, Open Source NES emulator.
 
2
 
 
3
   apu_int.h: Internal declarations for the APU emulation.
 
4
 
 
5
   Copyright (c) 2001-2007, FakeNES Team.
 
6
   This is free software.  See 'LICENSE' for details.
 
7
   You must read and accept the license prior to use. */
 
8
 
 
9
#ifndef APU_INT_H_INCLUDED
 
10
#define APU_INT_H_INCLUDED
 
11
#include "common.h"
 
12
#include "core.h"
 
13
#include "types.h"
 
14
 
 
15
// Maximum number of channels to send to the DSP (mono = 1, stereo = 2).
 
16
#define APU_MIXER_MAX_CHANNELS 2
 
17
 
 
18
class APUEnvelope {
 
19
public:
 
20
   uint8 timer;
 
21
   uint8 period;
 
22
   uint8 counter;
 
23
   bool fixed;
 
24
   uint8 fixed_volume;
 
25
   bool dirty;
 
26
};
 
27
 
 
28
class APUSweep {
 
29
public:
 
30
   bool enabled;
 
31
   uint8 timer;
 
32
   uint8 period;
 
33
   uint8 shifts;
 
34
   bool invert;
 
35
   bool increment;               // do not save
 
36
   bool dirty;
 
37
};
 
38
 
 
39
class APUChannel {
 
40
public:
 
41
   // General.
 
42
   uint8 output;
 
43
   uint8 volume;                 // do not save for triangle
 
44
   bool looping;
 
45
   bool silence;                 // do not save for triangle
 
46
 
 
47
   // Timer.
 
48
   int16 timer;
 
49
   uint16 period;
 
50
};
 
51
 
 
52
class APUWaveformChannel : public APUChannel {
 
53
public:
 
54
   // Length counter (all except dmc).
 
55
   uint8 length;
 
56
   bool length_disable;
 
57
};
 
58
 
 
59
class APUSquare : public APUWaveformChannel {
 
60
public:
 
61
   // Envelope generator (square/noise).
 
62
   APUEnvelope envelope;
 
63
   // Sweep unit. */
 
64
   APUSweep sweep;
 
65
 
 
66
   // Sequencer (squares/triangle).
 
67
   uint8 sequence_step;
 
68
 
 
69
   // Square wave generator.
 
70
   uint8 duty_cycle;
 
71
};
 
72
 
 
73
class APUTriangle : public APUWaveformChannel {
 
74
public:
 
75
    // Sequencer (squares/triangle).
 
76
   uint8 sequence_step;
 
77
 
 
78
  // Linear counter.
 
79
   uint8 linear_length;
 
80
   bool halt_counter;
 
81
   uint8 cached_linear_length;
 
82
};
 
83
 
 
84
class APUNoise : public APUWaveformChannel {
 
85
public:
 
86
   // Envelope generator (squares/noise).
 
87
   APUEnvelope envelope;
 
88
 
 
89
   // Noise generator.
 
90
   uint16 xor_tap;
 
91
   uint16 shift16;
 
92
};
 
93
 
 
94
class APUDMC : public APUChannel {
 
95
public:
 
96
   // Memory reader.
 
97
   uint16 address;
 
98
   uint16 dma_length;
 
99
   uint16 cached_address;
 
100
   uint16 cached_dmalength;
 
101
 
 
102
   // Sample buffer.
 
103
   uint8 cur_byte;
 
104
   uint8 sample_bits;
 
105
 
 
106
   // Output unit.
 
107
   uint8 counter;
 
108
   uint8 shift_reg;
 
109
 
 
110
   // IRQ generator.
 
111
   bool irq_gen;
 
112
   bool irq_occurred;
 
113
};
 
114
 
 
115
// Mixer environment for the low pass filter.
 
116
typedef struct _APULPFilter {
 
117
   real filter_sample;
 
118
 
 
119
} APULPFilter;
 
120
 
 
121
// Mixer environment for the DC blocking filter.
 
122
typedef struct _APUDCFilter {
 
123
   real timer;
 
124
   real filter_sample;
 
125
   real next_filter_sample;
 
126
   real stepTime;
 
127
   real weightPerStep;
 
128
   real curStep;
 
129
 
 
130
} APUDCFilter;
 
131
 
 
132
class APU {
 
133
public:
 
134
   // Timestamp of the last call to process().
 
135
   cpu_time_t clock_counter;
 
136
 
 
137
   // IRQ prediction.
 
138
   cpu_time_t prediction_timestamp;
 
139
   cpu_time_t prediction_cycles;
 
140
 
 
141
   // Frame sequencer & frame IRQs.
 
142
   int16 sequence_counter;
 
143
   uint8 sequence_step;
 
144
   uint8 sequence_steps;
 
145
   bool frame_irq_gen;
 
146
   bool frame_irq_occurred;
 
147
 
 
148
   // Sound generators.
 
149
   APUSquare square[2];
 
150
   APUTriangle triangle;
 
151
   APUNoise noise;
 
152
   APUDMC dmc;
 
153
 
 
154
   // Delta value for timers.
 
155
   cpu_time_t timer_delta;          // do not save
 
156
 
 
157
   // Mixer.
 
158
   struct {                         // do not save any of this
 
159
      int channels;
 
160
      cpu_time_t delta_cycles;
 
161
      real inputs[APU_MIXER_MAX_CHANNELS];
 
162
      real accumulators[APU_MIXER_MAX_CHANNELS];
 
163
      real sample_cache[APU_MIXER_MAX_CHANNELS];
 
164
      real accumulated_samples;
 
165
      real max_samples;
 
166
 
 
167
      // Filtering environments.
 
168
      APULPFilter lpEnv[APU_MIXER_MAX_CHANNELS];
 
169
      APUDCFilter dcEnv[APU_MIXER_MAX_CHANNELS];
 
170
 
 
171
   } mixer;
 
172
};
 
173
 
 
174
#endif //!APU_INT_H_INCLUDED