]> Shamusworld >> Repos - apple2/blob - src/vay8910.h
4eb0fe94957fbbbb12ecd50d17c2bde3af9c37fb
[apple2] / src / vay8910.h
1 //
2 // Virtual AY-3-8910 Emulator
3 //
4 // by James Hammons
5 // (C) 2018 Underground Software
6 //
7
8 #ifndef VAY8910_H
9 #define VAY8910_H
10
11 #include <stdint.h>
12
13 struct VAY_3_8910
14 {
15         // User visible registers
16         uint16_t period[3];             // Channel A-C period
17         int16_t volume[3];              // Channel A-C volume (non-envelope mode)
18         bool envEnable[3];              // Channel A-C envelope enable
19         bool toneEnable[3];             // Channel A-C tone enable
20         bool noiseEnable[3];    // Channel A-C noise enable
21         uint16_t noisePeriod;   // Noise period (5 bits * 16)
22         uint32_t envPeriod;             // Envelope period (16 bits * 256)
23         bool envAttack;                 // Envelope Attack bit
24         bool envAlternate;              // Envelope Alternate bit
25         bool envHold;                   // Envelope Hold bit
26         // Internal registers
27         uint16_t count[3];              // Channel A-C current count
28         bool state[3];                  // Channel A-C current state
29         uint16_t noiseCount;    // Noise current count
30         bool noiseState;                // Noise state
31         uint32_t envCount[3];   // Envelope current count
32         int16_t envDirection[3];// Envelope direction (rising, 0, or falling)
33         uint32_t prng;                  // Psuedo RNG (17 bits)
34         uint8_t regLatch;               // Register latch (written by 6522VIA)
35         uint8_t data;                   // Data lines (written by 6522VIA)
36         uint8_t id;                             // Chip ID (optional)
37
38         VAY_3_8910();
39         void Reset(void);
40         void WriteControl(uint8_t);
41         void WriteData(uint8_t);
42         void SetRegister(void);
43         uint16_t GetSample(void);
44
45         // Class variables
46
47         // Maximum volume that can be generated by one voice
48         static float maxVolume;
49         // Normalized volumes (zero to one) for AY-3-8910 output, in 16 steps
50         static float normalizedVolume[16];
51 };
52
53 // Exported variables
54 extern bool logAYInternal;
55
56 #endif  // VAY8910_H
57