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 #include "freescape/music.h"
28 
29 namespace Freescape {
30 
32 public:
35 
36  void startMusic() override;
37  void stopMusic() override;
38  bool isPlaying() const override;
39 
40 private:
41  static const uint16 kLoadAddress = 0x0410;
42  static const uint16 kOrderPointerTable = 0x1041;
43  static const uint16 kInstrumentTable = 0x1047;
44  static const uint16 kPatternPointerLowTable = 0x10A7;
45  static const uint16 kPatternPointerHighTable = 0x10C6;
46  static const uint16 kFrequencyHighTable = 0x0F5F;
47  static const uint16 kFrequencyLowTable = 0x0FBE;
48  static const uint16 kArpeggioIntervalTable = 0x148B;
49 
50  static const byte kChannelCount = 3;
51  static const byte kInstrumentCount = 12;
52  static const byte kPatternCount = 31;
53  static const byte kMaxNote = 94;
54 
55  struct ChannelState {
56  uint16 orderAddr;
57  byte orderPos;
58 
59  uint16 patternAddr;
60  byte patternOffset;
61 
62  byte instrumentOffset;
63  byte currentNote;
64  byte transpose;
65 
66  byte frequencyLow;
67  byte frequencyHigh;
68  byte pulseWidthLow;
69  byte pulseWidthHigh;
70 
71  byte durationReload;
72  byte durationCounter;
73 
74  byte effectMode;
75  byte effectParam;
76  byte arpeggioTarget;
77  byte arpeggioParam;
78  byte arpeggioSequencePos;
79  byte arpeggioSequence[9];
80  byte arpeggioSequenceLen;
81 
82  byte noteStepCommand;
83  byte stepDownCounter;
84 
85  byte vibratoPhase;
86  byte vibratoCounter;
87  byte pulseWidthDirection;
88 
89  byte delayValue;
90  byte delayCounter;
91 
92  byte waveform;
93  byte instrumentFlags;
94  bool gateOffDisabled;
95 
96  void reset();
97  };
98 
99  SID::SID *_sid;
100  Common::Array<byte> _musicData;
101  byte _arpeggioIntervals[8];
102  bool _musicActive;
103  byte _speedDivider;
104  byte _speedCounter;
105  ChannelState _channels[kChannelCount];
106 
107  byte readByte(uint16 address) const;
108  uint16 readWordLE(uint16 address) const;
109  uint16 readPatternPointer(byte index) const;
110  byte readInstrumentByte(byte instrumentOffset, byte field) const;
111  byte readPatternByte(int channel);
112  byte clampNote(byte note) const;
113 
114  void sidWrite(int reg, byte data);
115  void onTimer();
116  void silenceAll();
117  void setupSong();
118  void loadNextPattern(int channel);
119  void buildEffectArpeggio(int channel);
120  void loadCurrentFrequency(int channel);
121  void finalizeChannel(int channel);
122  void processChannel(int channel, bool newBeat);
123  void parseCommands(int channel);
124  void applyNote(int channel, byte note);
125  void applyFrameEffects(int channel);
126  bool applyInstrumentVibrato(int channel);
127  void applyEffectArpeggio(int channel);
128  void applyTimedSlide(int channel);
129  void applyPulseWidthModulation(int channel);
130 
131  void initSID();
132  void destroySID();
133 };
134 
135 } // namespace Freescape
136 
137 #endif
Definition: area.h:36
Definition: c64.music.h:31
Definition: sid.h:44
Definition: music.h:29