2021-06-15 02:19:25 +00:00
|
|
|
//
|
|
|
|
// Nick.hpp
|
|
|
|
// Clock Signal
|
|
|
|
//
|
|
|
|
// Created by Thomas Harte on 14/06/2021.
|
|
|
|
// Copyright © 2021 Thomas Harte. All rights reserved.
|
|
|
|
//
|
|
|
|
|
|
|
|
#ifndef Nick_hpp
|
|
|
|
#define Nick_hpp
|
|
|
|
|
|
|
|
#include <cstdint>
|
|
|
|
#include "../../ClockReceiver/ClockReceiver.hpp"
|
2021-06-15 03:11:48 +00:00
|
|
|
#include "../../Outputs/CRT/CRT.hpp"
|
2021-06-15 02:19:25 +00:00
|
|
|
|
|
|
|
namespace Enterprise {
|
|
|
|
|
|
|
|
class Nick {
|
|
|
|
public:
|
2021-06-15 21:43:13 +00:00
|
|
|
Nick(const uint8_t *ram);
|
2021-06-15 03:11:48 +00:00
|
|
|
|
2021-06-15 02:19:25 +00:00
|
|
|
void write(uint16_t address, uint8_t value);
|
|
|
|
uint8_t read(uint16_t address);
|
|
|
|
|
2021-06-18 02:30:24 +00:00
|
|
|
void run_for(Cycles);
|
2021-06-27 21:13:07 +00:00
|
|
|
Cycles get_time_until_z80_slot(Cycles after_period) const;
|
2021-06-15 03:11:48 +00:00
|
|
|
|
|
|
|
void set_scan_target(Outputs::Display::ScanTarget *scan_target);
|
|
|
|
Outputs::Display::ScanStatus get_scaled_scan_status() const;
|
|
|
|
|
2021-06-27 20:28:01 +00:00
|
|
|
Cycles get_next_sequence_point() const;
|
2021-06-18 02:30:24 +00:00
|
|
|
|
|
|
|
/*!
|
|
|
|
@returns The current state of the interrupt line — @c true for active;
|
|
|
|
@c false for inactive.
|
|
|
|
*/
|
2021-06-28 01:37:11 +00:00
|
|
|
inline bool get_interrupt_line() const {
|
2021-06-18 02:30:24 +00:00
|
|
|
return interrupt_line_;
|
|
|
|
}
|
|
|
|
|
2021-06-15 03:11:48 +00:00
|
|
|
private:
|
|
|
|
Outputs::CRT::CRT crt_;
|
2021-06-15 21:43:13 +00:00
|
|
|
const uint8_t *const ram_;
|
|
|
|
|
2021-06-15 22:57:14 +00:00
|
|
|
// CPU-provided state.
|
2021-06-15 21:43:13 +00:00
|
|
|
uint8_t line_parameter_control_ = 0xc0;
|
|
|
|
uint16_t line_parameter_base_ = 0x0000;
|
2021-06-16 00:55:58 +00:00
|
|
|
uint16_t border_colour_ = 0;
|
2021-06-15 22:57:14 +00:00
|
|
|
|
|
|
|
// Ephemerals, related to current video position.
|
2021-06-15 21:43:13 +00:00
|
|
|
int horizontal_counter_ = 0;
|
2021-06-15 22:57:14 +00:00
|
|
|
uint16_t line_parameter_pointer_ = 0x0000;
|
2021-06-18 21:44:17 +00:00
|
|
|
bool should_reload_line_parameters_ = true;
|
2021-06-16 00:55:58 +00:00
|
|
|
uint16_t line_data_pointer_[2];
|
2021-06-24 22:34:21 +00:00
|
|
|
uint16_t start_line_data_pointer_[2];
|
2021-06-15 22:57:14 +00:00
|
|
|
|
|
|
|
// Current mode line parameters.
|
|
|
|
uint8_t lines_remaining_ = 0x00;
|
2021-06-20 01:57:26 +00:00
|
|
|
uint8_t two_colour_mask_ = 0xff;
|
2021-06-16 00:55:58 +00:00
|
|
|
int left_margin_ = 0, right_margin_ = 0;
|
2021-06-19 17:04:18 +00:00
|
|
|
const uint16_t *alt_ind_palettes[4];
|
2021-06-16 00:55:58 +00:00
|
|
|
enum class Mode {
|
|
|
|
Vsync,
|
|
|
|
Pixel,
|
|
|
|
Attr,
|
|
|
|
CH256,
|
|
|
|
CH128,
|
|
|
|
CH64,
|
|
|
|
Unused,
|
|
|
|
LPixel,
|
|
|
|
} mode_ = Mode::Vsync;
|
2021-06-24 22:34:21 +00:00
|
|
|
bool is_sync_or_pixels_ = false;
|
2021-06-17 00:43:22 +00:00
|
|
|
int bpp_ = 0;
|
|
|
|
int column_size_ = 0;
|
2021-06-18 02:30:24 +00:00
|
|
|
bool interrupt_line_ = true;
|
2021-06-20 18:31:02 +00:00
|
|
|
int line_data_per_column_increments_[2] = {0, 0};
|
2021-06-24 22:34:21 +00:00
|
|
|
bool vres_ = false;
|
|
|
|
bool reload_line_parameter_pointer_ = false;
|
2021-06-16 00:55:58 +00:00
|
|
|
|
|
|
|
// An accumulator for border output regions.
|
|
|
|
int border_duration_ = 0;
|
2021-06-16 02:03:41 +00:00
|
|
|
|
|
|
|
// The destination for new pixels.
|
2021-06-28 23:00:51 +00:00
|
|
|
static constexpr int allocation_size = 336;
|
2021-06-17 00:43:22 +00:00
|
|
|
static_assert((allocation_size % 16) == 0, "Allocation size must be a multiple of 16");
|
2021-06-16 02:03:41 +00:00
|
|
|
uint16_t *pixel_pointer_ = nullptr, *allocated_pointer_ = nullptr;
|
2021-06-24 22:34:21 +00:00
|
|
|
|
|
|
|
// Output transitions.
|
|
|
|
enum class OutputType {
|
|
|
|
Sync, Blank, Pixels, Border, ColourBurst
|
|
|
|
};
|
|
|
|
void set_output_type(OutputType, bool force_flush = false);
|
|
|
|
int output_duration_ = 0;
|
|
|
|
OutputType output_type_ = OutputType::Sync;
|
2021-06-17 00:43:22 +00:00
|
|
|
|
|
|
|
// Current palette.
|
|
|
|
uint16_t palette_[16]{};
|
|
|
|
|
|
|
|
// Specific outputters.
|
2021-06-28 23:00:51 +00:00
|
|
|
template <int bpp, bool is_lpixel> void output_pixel(uint16_t *target, int columns) const;
|
|
|
|
template <int bpp, int index_bits> void output_character(uint16_t *target, int columns) const;
|
|
|
|
template <int bpp> void output_attributed(uint16_t *target, int columns) const;
|
2021-06-15 02:19:25 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif /* Nick_hpp */
|