ScummVM API documentation
c64.music.h
1 /* ScummVM - Graphic Adventure Engine
2  *
3  * ScummVM is the legal property of its developers, whose names
4  * are too numerous to list here. Please refer to the COPYRIGHT
5  * file distributed with this source distribution.
6  *
7  * This program is free software: you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation, either version 3 of the License, or
10  * (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program. If not, see <http://www.gnu.org/licenses/>.
19  *
20  */
21 
22 #ifndef FREESCAPE_ECLIPSE_C64_MUSIC_H
23 #define FREESCAPE_ECLIPSE_C64_MUSIC_H
24 
25 #include "audio/sid.h"
26 #include "common/array.h"
27 
28 namespace Freescape {
29 
31 public:
34 
35  void startMusic();
36  void stopMusic();
37  bool isPlaying() const;
38  void initSID();
39  void destroySID();
40 
41 private:
42  static const uint16 kLoadAddress = 0x0410;
43  static const uint16 kOrderPointerTable = 0x1041;
44  static const uint16 kInstrumentTable = 0x1047;
45  static const uint16 kPatternPointerLowTable = 0x10A7;
46  static const uint16 kPatternPointerHighTable = 0x10C6;
47  static const uint16 kFrequencyHighTable = 0x0F5F;
48  static const uint16 kFrequencyLowTable = 0x0FBE;
49  static const uint16 kArpeggioIntervalTable = 0x148B;
50 
51  static const byte kChannelCount = 3;
52  static const byte kInstrumentCount = 12;
53  static const byte kPatternCount = 31;
54  static const byte kMaxNote = 94;
55 
56  struct ChannelState {
57  uint16 orderAddr;
58  byte orderPos;
59 
60  uint16 patternAddr;
61  byte patternOffset;
62 
63  byte instrumentOffset;
64  byte currentNote;
65  byte transpose;
66 
67  byte frequencyLow;
68  byte frequencyHigh;
69  byte pulseWidthLow;
70  byte pulseWidthHigh;
71 
72  byte durationReload;
73  byte durationCounter;
74 
75  byte effectMode;
76  byte effectParam;
77  byte arpeggioTarget;
78  byte arpeggioParam;
79  byte arpeggioSequencePos;
80  byte arpeggioSequence[9];
81  byte arpeggioSequenceLen;
82 
83  byte noteStepCommand;
84  byte stepDownCounter;
85 
86  byte vibratoPhase;
87  byte vibratoCounter;
88  byte pulseWidthDirection;
89 
90  byte delayValue;
91  byte delayCounter;
92 
93  byte waveform;
94  byte instrumentFlags;
95  bool gateOffDisabled;
96 
97  void reset();
98  };
99 
100  SID::SID *_sid;
101  Common::Array<byte> _musicData;
102  byte _arpeggioIntervals[8];
103  bool _musicActive;
104  byte _speedDivider;
105  byte _speedCounter;
106  ChannelState _channels[kChannelCount];
107 
108  byte readByte(uint16 address) const;
109  uint16 readWordLE(uint16 address) const;
110  uint16 readPatternPointer(byte index) const;
111  byte readInstrumentByte(byte instrumentOffset, byte field) const;
112  byte readPatternByte(int channel);
113  byte clampNote(byte note) const;
114 
115  void sidWrite(int reg, byte data);
116  void onTimer();
117  void silenceAll();
118  void setupSong();
119  void loadNextPattern(int channel);
120  void buildEffectArpeggio(int channel);
121  void loadCurrentFrequency(int channel);
122  void finalizeChannel(int channel);
123  void processChannel(int channel, bool newBeat);
124  void parseCommands(int channel);
125  void applyNote(int channel, byte note);
126  void applyFrameEffects(int channel);
127  bool applyInstrumentVibrato(int channel);
128  void applyEffectArpeggio(int channel);
129  void applyTimedSlide(int channel);
130  void applyPulseWidthModulation(int channel);
131 };
132 
133 } // namespace Freescape
134 
135 #endif
Definition: area.h:36
Definition: c64.music.h:30
Definition: sid.h:44