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_DARK_C64_MUSIC_H
23 #define FREESCAPE_DARK_C64_MUSIC_H
24 
25 #include "audio/sid.h"
26 
27 namespace Freescape {
28 
29 // 3-channel SID music player for Dark Side C64.
30 // Implements the Wally Beben byte-stream sequencer from darkside.prg ($0901).
32 public:
35 
36  void startMusic();
37  void stopMusic();
38  bool isPlaying() const;
39  void initSID();
40  void destroySID();
41 
42 private:
43  SID::SID *_sid;
44 
45  void sidWrite(int reg, uint8 data);
46  void onTimer();
47 
48  // Song setup
49  void setupSong();
50  void silenceAll();
51  void loadNextPattern(int ch);
52  void buildEffectArpeggio(int ch);
53  void loadCurrentFrequency(int ch);
54  void finalizeChannel(int ch);
55 
56  // Per-tick processing
57  void processChannel(int ch, bool newBeat);
58  void parseCommands(int ch);
59  void applyNote(int ch, uint8 note);
60  void applyFrameEffects(int ch);
61  bool applySpecialAttack(int ch);
62  bool applyEnvelopeSequence(int ch);
63  bool applyInstrumentVibrato(int ch);
64  void applyEffectArpeggio(int ch);
65  void applyTimedSlide(int ch);
66  void applyPWModulation(int ch);
67 
68  uint8 readPatByte(int ch);
69 
70  // Global state
71  bool _musicActive;
72  uint8 _speedDiv; // $15A1: speed divider
73  uint8 _speedCounter; // $15A2: frames until next beat
74 
75  // Per-channel state
76  struct ChannelState {
77  const uint8 *orderData;
78  uint8 orderPos; // $15A3
79 
80  const uint8 *patData;
81  int patOffset;
82 
83  uint8 instIdx; // $15F6: instrument# * 8
84  uint8 curNote; // $159C: note index (with transpose)
85  uint8 transpose; // $15C4
86 
87  uint8 freqLo; // $15A6
88  uint8 freqHi; // $15A9
89  uint8 pwLo; // $15AC
90  uint8 pwHi; // $15AF
91 
92  uint8 durReload; // $15B8
93  uint8 durCounter; // $15BB
94 
95  uint8 effectMode; // $15BE: mode 2 keeps effectParam alive across note loads
96  uint8 effectParam; // $15C1
97 
98  uint8 arpPattern; // $15C7
99  uint8 arpParam2; // $15CA
100  uint8 arpSeqPos; // $15D9
101  uint8 arpSeqData[20]; // $160C
102  uint8 arpSeqLen;
103 
104  uint8 noteStepCommand; // $15D0: self-modified INC/DEC opcode for beat step
105  uint8 stepDownCounter; // $15D3: short downward slide counter
106 
107  uint8 vibPhase; // $15DE
108  uint8 vibCounter; // $15E1
109 
110  uint8 pwDirection; // $15D6: 0=up, 1=down
111 
112  uint8 delayValue; // $15E4
113  uint8 delayCounter; // $15E7
114 
115  uint8 envCounter; // $15FC
116  bool gateOffDisabled; // $1606: set when SR release nibble is $F
117  bool gateModeControl; // $1600: flags bit 7
118  bool specialAttack; // flags bit 3
119  bool attackDone; // $1603
120  uint8 waveform; // current instrument ctrl byte
121  uint8 instFlags; // current instrument flags byte
122 
123  void reset();
124  };
125 
126  ChannelState _ch[3];
127 };
128 
129 } // namespace Freescape
130 
131 #endif // FREESCAPE_DARK_C64_MUSIC_H
Definition: area.h:36
Definition: sid.h:44
Definition: c64.music.h:31