2016-06-05 10:51:07 -04: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 19:30:52 -04:00
|
|
|
#include "../../Outputs/Speaker.hpp"
|
2016-06-05 10:51:07 -04:00
|
|
|
|
|
|
|
namespace MOS {
|
|
|
|
|
2016-06-14 20:00:16 -04:00
|
|
|
/*!
|
2016-06-19 18:11:37 -04:00
|
|
|
The 6560 Video Interface Chip ('VIC') is a video and audio output chip; it therefore vends both a @c CRT and a @c Speaker.
|
2016-06-13 19:30:52 -04:00
|
|
|
|
2016-06-19 18:11:37 -04:00
|
|
|
To run the VIC for a cycle, the caller should call @c get_address, make the requested bus access
|
2016-06-14 20:00:16 -04:00
|
|
|
and call @c set_graphics_value with the result.
|
2016-06-13 19:30:52 -04:00
|
|
|
|
2016-06-14 20:00:16 -04:00
|
|
|
@c set_register and @c get_register provide register access.
|
|
|
|
*/
|
2016-06-05 10:51:07 -04:00
|
|
|
class MOS6560 {
|
|
|
|
public:
|
|
|
|
MOS6560();
|
2016-07-04 19:33:55 -04:00
|
|
|
std::shared_ptr<Outputs::CRT::CRT> get_crt() { return _crt; }
|
|
|
|
std::shared_ptr<Outputs::Speaker> get_speaker() { return _speaker; }
|
2016-06-05 10:51:07 -04:00
|
|
|
|
2016-06-23 07:32:24 -04:00
|
|
|
enum OutputMode {
|
|
|
|
PAL, NTSC
|
|
|
|
};
|
|
|
|
/*!
|
|
|
|
Sets the output mode to either PAL or NTSC.
|
|
|
|
*/
|
|
|
|
void set_output_mode(OutputMode output_mode);
|
|
|
|
|
2016-06-14 20:00:16 -04:00
|
|
|
/*!
|
|
|
|
Impliedly runs the 6560 for a single cycle, returning the next address that it puts on the bus.
|
|
|
|
*/
|
2016-06-05 12:11:12 -04:00
|
|
|
uint16_t get_address();
|
2016-06-14 20:00:16 -04: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 16:28:06 -04:00
|
|
|
void set_graphics_value(uint8_t value, uint8_t colour_value);
|
2016-06-05 12:11:12 -04:00
|
|
|
|
2016-06-14 20:00:16 -04:00
|
|
|
/*!
|
|
|
|
Causes the 6560 to flush as much pending CRT and speaker communications as possible.
|
|
|
|
*/
|
|
|
|
inline void synchronise() { update_audio(); }
|
2016-06-13 21:49:59 -04:00
|
|
|
|
2016-06-14 20:00:16 -04:00
|
|
|
/*!
|
|
|
|
Writes to a 6560 register.
|
|
|
|
*/
|
2016-06-05 12:11:12 -04:00
|
|
|
void set_register(int address, uint8_t value);
|
2016-06-14 20:00:16 -04:00
|
|
|
|
|
|
|
/*
|
|
|
|
Reads from a 6560 register.
|
|
|
|
*/
|
2016-06-06 20:29:39 -04:00
|
|
|
uint8_t get_register(int address);
|
2016-06-05 12:11:12 -04:00
|
|
|
|
2016-06-05 10:51:07 -04:00
|
|
|
private:
|
2016-07-04 19:33:55 -04:00
|
|
|
std::shared_ptr<Outputs::CRT::CRT> _crt;
|
2016-06-21 22:12:01 -04:00
|
|
|
|
|
|
|
// audio state
|
2016-06-14 20:00:16 -04: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;
|
2016-07-04 19:33:55 -04:00
|
|
|
};
|
|
|
|
std::shared_ptr<Speaker> _speaker;
|
2016-06-21 22:12:01 -04:00
|
|
|
unsigned int _cycles_since_speaker_update;
|
|
|
|
void update_audio();
|
2016-06-05 14:05:31 -04:00
|
|
|
|
2016-06-21 22:12:01 -04:00
|
|
|
// register state
|
|
|
|
struct {
|
|
|
|
bool interlaced, tall_characters;
|
|
|
|
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;
|
|
|
|
uint8_t backgroundColour, borderColour, auxiliary_colour;
|
|
|
|
bool invertedCells;
|
2016-06-05 17:06:10 -04:00
|
|
|
|
2016-06-21 22:12:01 -04:00
|
|
|
uint8_t direct_values[16];
|
|
|
|
} _registers;
|
2016-06-05 17:06:10 -04:00
|
|
|
|
2016-06-21 22:12:01 -04:00
|
|
|
// output state
|
2016-06-05 17:06:10 -04:00
|
|
|
enum State {
|
|
|
|
Sync, ColourBurst, Border, Pixels
|
2016-06-05 18:02:49 -04:00
|
|
|
} _this_state, _output_state;
|
|
|
|
unsigned int _cycles_in_state;
|
|
|
|
|
2016-06-21 22:12:01 -04:00
|
|
|
// counters that cover an entire field
|
2016-06-27 22:12:55 -04:00
|
|
|
int _horizontal_counter, _vertical_counter, _full_frame_counter;
|
2016-06-05 18:02:49 -04:00
|
|
|
|
2016-06-21 22:12:01 -04:00
|
|
|
// latches dictating start and length of drawing
|
|
|
|
bool _vertical_drawing_latch, _horizontal_drawing_latch;
|
|
|
|
int _rows_this_field, _columns_this_line;
|
2016-06-05 18:02:49 -04:00
|
|
|
|
2016-06-21 22:12:01 -04:00
|
|
|
// current drawing position counter
|
2016-06-23 07:32:24 -04:00
|
|
|
int _pixel_line_cycle, _column_counter;
|
2016-06-21 22:12:01 -04:00
|
|
|
int _current_row;
|
|
|
|
uint16_t _current_character_row;
|
2016-06-23 07:32:24 -04:00
|
|
|
uint16_t _video_matrix_address_counter, _base_video_matrix_address_counter;
|
2016-06-21 22:12:01 -04:00
|
|
|
|
|
|
|
// data latched from the bus
|
|
|
|
uint8_t _character_code, _character_colour, _character_value;
|
2016-06-06 20:29:39 -04:00
|
|
|
|
2016-06-12 22:27:58 -04:00
|
|
|
bool _is_odd_frame;
|
2016-06-12 17:45:25 -04:00
|
|
|
|
2016-06-21 22:12:01 -04:00
|
|
|
// lookup table from 6560 colour index to appropriate PAL/NTSC value
|
|
|
|
uint8_t _colours[16];
|
2016-06-13 19:30:52 -04:00
|
|
|
|
2016-06-21 22:12:01 -04:00
|
|
|
uint8_t *pixel_pointer;
|
|
|
|
void output_border(unsigned int number_of_cycles);
|
2016-06-23 07:32:24 -04:00
|
|
|
|
|
|
|
struct {
|
|
|
|
int cycles_per_line;
|
2016-06-27 22:12:55 -04:00
|
|
|
int line_counter_increment_offset;
|
2016-06-23 07:32:24 -04:00
|
|
|
int lines_per_progressive_field;
|
|
|
|
bool supports_interlacing;
|
|
|
|
} _timing;
|
2016-06-05 10:51:07 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif /* _560_hpp */
|