-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathAY8910.h
42 lines (36 loc) · 1023 Bytes
/
AY8910.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#pragma once
#include <stdint.h>
#include <stdbool.h>
class AY8910 {
public:
AY8910();
void reset();
void writeReg(uint8_t r, uint8_t v);
uint8_t readReg(uint8_t r);
void render(uint16_t abc[3]);
private:
struct ToneGenerator {
uint16_t period;
uint8_t volume;
int32_t count;
uint8_t output;
};
struct Envelope {
uint32_t period;
uint32_t count;
int8_t step;
uint8_t volume;
bool hold;
bool alternate;
uint8_t attack;
bool holding;
};
uint8_t regs[16]; // Registers
ToneGenerator toneGen[3]; // Tone generator state
Envelope envelope; // Envelope generator state
uint8_t prescaleNoise; // Noise prescaler
uint8_t noiseCnt; // Noise period counter
uint32_t rng; // RNG LFSR state
uint8_t value[3]; // Current channel value (either 0 or 1)
friend class UI;
};