2016-10-15 01:18:03 +00:00
|
|
|
//
|
|
|
|
// AY-3-8910.hpp
|
|
|
|
// Clock Signal
|
|
|
|
//
|
|
|
|
// Created by Thomas Harte on 14/10/2016.
|
|
|
|
// Copyright © 2016 Thomas Harte. All rights reserved.
|
|
|
|
//
|
|
|
|
|
|
|
|
#ifndef AY_3_8910_hpp
|
|
|
|
#define AY_3_8910_hpp
|
|
|
|
|
|
|
|
#include "../../Outputs/Speaker.hpp"
|
|
|
|
|
|
|
|
namespace GI {
|
|
|
|
|
2016-10-20 02:47:44 +00:00
|
|
|
/*!
|
|
|
|
Provides emulation of an AY-3-8910 / YM2149, which is a three-channel sound chip with a
|
|
|
|
noise generator and a volume envelope generator, which also provides two bidirectional
|
|
|
|
interface ports.
|
|
|
|
*/
|
2016-10-15 01:18:03 +00:00
|
|
|
class AY38910: public ::Outputs::Filter<AY38910> {
|
|
|
|
public:
|
2016-10-20 02:47:44 +00:00
|
|
|
/// Creates a new AY38910.
|
2016-10-15 01:18:03 +00:00
|
|
|
AY38910();
|
|
|
|
|
2016-10-20 02:47:44 +00:00
|
|
|
/// Sets the clock rate at which this AY38910 will be run.
|
|
|
|
void set_clock_rate(double clock_rate);
|
2016-10-15 01:18:03 +00:00
|
|
|
|
2016-10-18 23:32:15 +00:00
|
|
|
enum ControlLines {
|
|
|
|
BC1 = (1 << 0),
|
|
|
|
BC2 = (1 << 1),
|
2017-08-01 21:06:57 +00:00
|
|
|
BDIR = (1 << 2)
|
2016-10-18 23:32:15 +00:00
|
|
|
};
|
2016-10-20 02:47:44 +00:00
|
|
|
|
|
|
|
/// Sets the value the AY would read from its data lines if it were not outputting.
|
2016-10-18 23:32:15 +00:00
|
|
|
void set_data_input(uint8_t r);
|
2016-10-20 02:47:44 +00:00
|
|
|
|
|
|
|
/// Gets the value that would appear on the data lines if only the AY is outputting.
|
2016-10-18 23:32:15 +00:00
|
|
|
uint8_t get_data_output();
|
2016-10-20 02:47:44 +00:00
|
|
|
|
2017-08-01 21:01:36 +00:00
|
|
|
/// Sets the current control line state, as a bit field.
|
2016-10-18 23:32:15 +00:00
|
|
|
void set_control_lines(ControlLines control_lines);
|
2016-10-15 01:18:03 +00:00
|
|
|
|
2016-10-20 02:47:44 +00:00
|
|
|
/*!
|
|
|
|
Gets the value that would appear on the requested interface port if it were in output mode.
|
|
|
|
@parameter port_b @c true to get the value for Port B, @c false to get the value for Port A.
|
|
|
|
*/
|
2016-10-15 01:44:15 +00:00
|
|
|
uint8_t get_port_output(bool port_b);
|
|
|
|
|
2017-08-01 22:04:51 +00:00
|
|
|
/*!
|
|
|
|
Sets the value that would appear on the requested interface port if it were in output mode.
|
|
|
|
@parameter port_b @c true to get the value for Port B, @c false to get the value for Port A.
|
|
|
|
*/
|
|
|
|
void set_port_input(bool port_b, uint8_t value);
|
|
|
|
|
2016-10-20 02:47:44 +00:00
|
|
|
// to satisfy ::Outputs::Speaker (included via ::Outputs::Filter; not for public consumption
|
|
|
|
void get_samples(unsigned int number_of_samples, int16_t *target);
|
|
|
|
|
2016-10-15 01:18:03 +00:00
|
|
|
private:
|
2016-12-03 15:51:09 +00:00
|
|
|
int selected_register_;
|
|
|
|
uint8_t registers_[16], output_registers_[16];
|
2017-08-07 23:01:18 +00:00
|
|
|
uint8_t port_inputs_[2];
|
2016-10-15 01:18:03 +00:00
|
|
|
|
2016-12-03 15:51:09 +00:00
|
|
|
int master_divider_;
|
2016-10-24 00:42:49 +00:00
|
|
|
|
2016-12-03 15:51:09 +00:00
|
|
|
int tone_periods_[3];
|
|
|
|
int tone_counters_[3];
|
|
|
|
int tone_outputs_[3];
|
2016-10-20 01:13:22 +00:00
|
|
|
|
2016-12-03 15:51:09 +00:00
|
|
|
int noise_period_;
|
|
|
|
int noise_counter_;
|
|
|
|
int noise_shift_register_;
|
|
|
|
int noise_output_;
|
2016-10-20 01:13:22 +00:00
|
|
|
|
2016-12-03 15:51:09 +00:00
|
|
|
int envelope_period_;
|
|
|
|
int envelope_divider_;
|
|
|
|
int envelope_position_;
|
|
|
|
int envelope_shapes_[16][32];
|
|
|
|
int envelope_overflow_masks_[16];
|
2016-10-18 23:32:15 +00:00
|
|
|
|
2016-12-03 15:51:09 +00:00
|
|
|
int volumes_[16];
|
2016-10-24 00:42:49 +00:00
|
|
|
|
2016-10-18 23:32:15 +00:00
|
|
|
enum ControlState {
|
|
|
|
Inactive,
|
|
|
|
LatchAddress,
|
|
|
|
Read,
|
|
|
|
Write
|
2016-12-03 15:51:09 +00:00
|
|
|
} control_state_;
|
2016-10-18 23:32:15 +00:00
|
|
|
|
|
|
|
void select_register(uint8_t r);
|
|
|
|
void set_register_value(uint8_t value);
|
|
|
|
uint8_t get_register_value();
|
|
|
|
|
2016-12-03 15:51:09 +00:00
|
|
|
uint8_t data_input_, data_output_;
|
2016-10-22 00:05:38 +00:00
|
|
|
|
2016-12-03 15:51:09 +00:00
|
|
|
int16_t output_volume_;
|
2016-10-24 00:42:49 +00:00
|
|
|
inline void evaluate_output_volume();
|
2017-08-02 23:45:58 +00:00
|
|
|
|
|
|
|
inline void update_bus();
|
2016-10-15 01:18:03 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif /* AY_3_8910_hpp */
|