libdragon
Loading...
Searching...
No Matches
ay8910.h
Go to the documentation of this file.
1
5#ifndef __LIBDRAGON_AY8910_H
6#define __LIBDRAGON_AY8910_H
7
8#include <stdbool.h>
9#include <stdint.h>
10
11#ifdef __cplusplus
12extern "C" {
13#endif
14
26#define AY8910_DECIMATE 3
27
34#define AY8910_OUTPUT_STEREO 1
35
41#define AY8910_VOLUME_ATTENUATE 0.8
42
56#define AY8910_CENTER_SILENCE 1
57
59typedef struct {
60 uint16_t tone_period;
61 uint8_t tone_vol;
62 uint8_t tone_en;
63 uint8_t noise_en;
64
65 uint16_t count;
66 uint8_t out;
67} AYChannel;
68
70typedef struct {
71 uint16_t period;
72 uint8_t shape;
73
74 uint8_t attack;
75 uint8_t alternate;
76 uint8_t hold;
77
78 uint16_t count;
79 int16_t step;
80 uint8_t vol;
81 uint8_t holding;
83
85typedef struct {
86 uint8_t period;
87
88 uint8_t count;
89 uint32_t out;
90} AYNoise;
91
104typedef struct {
105 uint8_t (*PortRead)(int idx);
106 void (*PortWrite)(int idx, uint8_t val);
107 uint8_t addr;
108 uint8_t regs[16];
109 AYChannel ch[3];
112} AY8910;
113
115void ay8910_reset(AY8910 *ay);
116
118void ay8910_set_ports(AY8910 *ay, uint8_t (*PortRead)(int), void (*PortWrite)(int, uint8_t));
119
121void ay8910_write_addr(AY8910 *ay, uint8_t addr);
122
124void ay8910_write_data(AY8910 *ay, uint8_t val);
125
127uint8_t ay8910_read_data(AY8910 *ay);
128
130bool ay8910_is_mute(AY8910 *ay);
131
137int ay8910_gen(AY8910 *ay, int16_t *out, int nsamples);
138
139#ifdef __cplusplus
140}
141#endif
142
143#endif
void ay8910_set_ports(AY8910 *ay, uint8_t(*PortRead)(int), void(*PortWrite)(int, uint8_t))
Configure the I/O port callbacks.
Definition ay8910.c:495
void ay8910_write_addr(AY8910 *ay, uint8_t addr)
Write to the AY8910 address line.
Definition ay8910.c:507
uint8_t holding
True if the envelope is currently holding.
Definition ay8910.h:81
uint32_t out
Current output value.
Definition ay8910.h:89
void ay8910_reset(AY8910 *ay)
Reset the AY8910 emulator.
Definition ay8910.c:479
bool ay8910_is_mute(AY8910 *ay)
Return true if ay8910 is currently muted (all channels disabled)
Definition ay8910.c:500
uint8_t shape
Shape of the envelope (jigsaw, etc.)
Definition ay8910.h:72
uint16_t count
Current tick count for the period.
Definition ay8910.h:78
int ay8910_gen(AY8910 *ay, int16_t *out, int nsamples)
Generate audio for the specified number of samples.
Definition ay8910.c:169
uint8_t alternate
True if attack and release alternate (jigsaw)
Definition ay8910.h:75
uint8_t out
Current output value for this channel.
Definition ay8910.h:66
uint16_t tone_period
Period (in ticks) of the current tone.
Definition ay8910.h:60
uint16_t period
Period (in ticks) of the envelope.
Definition ay8910.h:71
uint8_t tone_en
Enable flag of the tone (0 is enabled)
Definition ay8910.h:62
uint8_t ay8910_read_data(AY8910 *ay)
Read from the AY8910 data line.
Definition ay8910.c:511
int16_t step
Current step of the envelope.
Definition ay8910.h:79
uint8_t tone_vol
Volume of the tone (0x10 -> use envelope)
Definition ay8910.h:61
uint8_t vol
Current output volume.
Definition ay8910.h:80
uint8_t attack
0x0 if in attack, 0xF if in the release
Definition ay8910.h:74
uint8_t count
Current tick count for the period.
Definition ay8910.h:88
uint16_t count
Current tick count for the period.
Definition ay8910.h:65
uint8_t hold
True if the envelope holds after attack.
Definition ay8910.h:76
void ay8910_write_data(AY8910 *ay, uint8_t val)
Write to the AY8910 data line.
Definition ay8910.c:524
uint8_t noise_en
Enable flag of the noise for this channel (0 is enabled)
Definition ay8910.h:63
uint8_t period
Period (in ticks) of the noise.
Definition ay8910.h:86
A AY-3-8910 channel.
Definition ay8910.h:59
Envelope of AY-3-8910.
Definition ay8910.h:70
Noise of AY-3-8910.
Definition ay8910.h:85
A AY-3-8910 emulator.
Definition ay8910.h:104
AYNoise ns
Configuration and state of the noise.
Definition ay8910.h:110
uint8_t addr
Current value on the address line.
Definition ay8910.h:107
AYEnvelope env
Configuration and state of the envelope.
Definition ay8910.h:111