2016-06-05 14:51:07 +00:00
|
|
|
//
|
|
|
|
// 6560.hpp
|
|
|
|
// Clock Signal
|
|
|
|
//
|
|
|
|
// Created by Thomas Harte on 05/06/2016.
|
|
|
|
// Copyright © 2016 Thomas Harte. All rights reserved.
|
|
|
|
//
|
|
|
|
|
|
|
|
#ifndef _560_hpp
|
|
|
|
#define _560_hpp
|
|
|
|
|
|
|
|
#include "../../Outputs/CRT/CRT.hpp"
|
2016-06-13 23:30:52 +00:00
|
|
|
#include "../../Outputs/Speaker.hpp"
|
2016-06-05 14:51:07 +00:00
|
|
|
|
|
|
|
namespace MOS {
|
|
|
|
|
2016-06-15 00:00:16 +00:00
|
|
|
/*!
|
|
|
|
The 6560 is a video and audio output chip; it therefore vends both a @c CRT and a @c Speaker.
|
2016-06-13 23:30:52 +00:00
|
|
|
|
2016-06-15 00:00:16 +00:00
|
|
|
To run the 6560 for a cycle, the caller should call @c get_address, make the requested bus access
|
|
|
|
and call @c set_graphics_value with the result.
|
2016-06-13 23:30:52 +00:00
|
|
|
|
2016-06-15 00:00:16 +00:00
|
|
|
@c set_register and @c get_register provide register access.
|
|
|
|
*/
|
2016-06-05 14:51:07 +00:00
|
|
|
class MOS6560 {
|
|
|
|
public:
|
|
|
|
MOS6560();
|
|
|
|
Outputs::CRT::CRT *get_crt() { return _crt.get(); }
|
2016-06-13 23:30:52 +00:00
|
|
|
Outputs::Speaker *get_speaker() { return &_speaker; }
|
2016-06-05 14:51:07 +00:00
|
|
|
|
2016-06-15 00:00:16 +00:00
|
|
|
/*!
|
|
|
|
Impliedly runs the 6560 for a single cycle, returning the next address that it puts on the bus.
|
|
|
|
*/
|
2016-06-05 16:11:12 +00:00
|
|
|
uint16_t get_address();
|
2016-06-15 00:00:16 +00:00
|
|
|
|
|
|
|
/*!
|
|
|
|
An owning machine should determine the state of the data bus as a result of the access implied
|
|
|
|
by @c get_address and supply it to set_graphics_value.
|
|
|
|
*/
|
2016-06-05 20:28:06 +00:00
|
|
|
void set_graphics_value(uint8_t value, uint8_t colour_value);
|
2016-06-05 16:11:12 +00:00
|
|
|
|
2016-06-15 00:00:16 +00:00
|
|
|
/*!
|
|
|
|
Causes the 6560 to flush as much pending CRT and speaker communications as possible.
|
|
|
|
*/
|
|
|
|
inline void synchronise() { update_audio(); }
|
2016-06-14 01:49:59 +00:00
|
|
|
|
2016-06-15 00:00:16 +00:00
|
|
|
/*!
|
|
|
|
Writes to a 6560 register.
|
|
|
|
*/
|
2016-06-05 16:11:12 +00:00
|
|
|
void set_register(int address, uint8_t value);
|
2016-06-15 00:00:16 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
Reads from a 6560 register.
|
|
|
|
*/
|
2016-06-07 00:29:39 +00:00
|
|
|
uint8_t get_register(int address);
|
2016-06-05 16:11:12 +00:00
|
|
|
|
2016-06-05 14:51:07 +00:00
|
|
|
private:
|
|
|
|
std::unique_ptr<Outputs::CRT::CRT> _crt;
|
2016-06-15 00:00:16 +00:00
|
|
|
class Speaker: public ::Outputs::Filter<Speaker> {
|
|
|
|
public:
|
|
|
|
Speaker();
|
|
|
|
|
|
|
|
void set_volume(uint8_t volume);
|
|
|
|
void set_control(int channel, uint8_t value);
|
|
|
|
|
|
|
|
void get_samples(unsigned int number_of_samples, int16_t *target);
|
|
|
|
void skip_samples(unsigned int number_of_samples);
|
|
|
|
|
|
|
|
private:
|
|
|
|
unsigned int _counters[4];
|
|
|
|
unsigned int _shift_registers[4];
|
|
|
|
uint8_t _control_registers[4];
|
|
|
|
uint8_t _volume;
|
|
|
|
} _speaker;
|
2016-06-05 18:05:31 +00:00
|
|
|
|
2016-06-12 15:23:57 +00:00
|
|
|
bool _interlaced, _tall_characters;
|
2016-06-05 18:05:31 +00:00
|
|
|
uint8_t _first_column_location, _first_row_location;
|
|
|
|
uint8_t _number_of_columns, _number_of_rows;
|
|
|
|
uint16_t _character_cell_start_address, _video_matrix_start_address;
|
2016-06-07 00:18:24 +00:00
|
|
|
uint8_t _backgroundColour, _borderColour, _auxiliary_colour;
|
2016-06-05 21:06:10 +00:00
|
|
|
bool _invertedCells;
|
|
|
|
|
|
|
|
int _horizontal_counter, _vertical_counter;
|
2016-06-15 01:06:29 +00:00
|
|
|
bool _did_output_graphics;
|
2016-06-05 21:06:10 +00:00
|
|
|
|
|
|
|
int _column_counter, _row_counter;
|
2016-06-06 11:35:35 +00:00
|
|
|
uint16_t _video_matrix_address_counter, _video_matrix_line_address_counter;
|
2016-06-05 21:06:10 +00:00
|
|
|
|
|
|
|
enum State {
|
|
|
|
Sync, ColourBurst, Border, Pixels
|
2016-06-05 22:02:49 +00:00
|
|
|
} _this_state, _output_state;
|
|
|
|
unsigned int _cycles_in_state;
|
|
|
|
|
2016-06-06 11:35:35 +00:00
|
|
|
uint8_t _character_code, _character_colour, _character_value;
|
2016-06-05 22:02:49 +00:00
|
|
|
|
|
|
|
uint8_t *pixel_pointer;
|
|
|
|
|
2016-06-07 00:29:39 +00:00
|
|
|
uint8_t _registers[16];
|
2016-06-12 21:27:57 +00:00
|
|
|
uint8_t _colours[16];
|
2016-06-07 00:29:39 +00:00
|
|
|
|
2016-06-13 02:27:58 +00:00
|
|
|
bool _is_odd_frame;
|
2016-06-12 21:45:25 +00:00
|
|
|
|
2016-06-05 22:02:49 +00:00
|
|
|
void output_border(unsigned int number_of_cycles);
|
2016-06-13 23:30:52 +00:00
|
|
|
|
|
|
|
unsigned int _cycles_since_speaker_update;
|
|
|
|
void update_audio();
|
2016-06-05 14:51:07 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif /* _560_hpp */
|