mirror of
https://github.com/TomHarte/CLK.git
synced 2024-11-29 12:50:28 +00:00
Improve const correctness, simplify inheritance.
This commit is contained in:
parent
71598250ea
commit
11542e7a7f
@ -671,7 +671,7 @@ void TMS9918<personality>::write(int address, uint8_t value) {
|
||||
}
|
||||
|
||||
template <Personality personality>
|
||||
uint8_t TMS9918<personality>::get_current_line() {
|
||||
uint8_t TMS9918<personality>::get_current_line() const {
|
||||
// Determine the row to return.
|
||||
constexpr int row_change_position = 63; // This is the proper Master System value; substitute if any other VDPs turn out to have this functionality.
|
||||
int source_row =
|
||||
@ -706,7 +706,7 @@ uint8_t TMS9918<personality>::get_current_line() {
|
||||
}
|
||||
|
||||
template <Personality personality>
|
||||
uint8_t TMS9918<personality>::get_latched_horizontal_counter() {
|
||||
uint8_t TMS9918<personality>::get_latched_horizontal_counter() const {
|
||||
// Translate from internal numbering, which puts pixel output
|
||||
// in the final 256 pixels of 342, to the public numbering,
|
||||
// which makes the 256 pixels the first 256 spots, but starts
|
||||
@ -741,12 +741,12 @@ uint8_t TMS9918<personality>::read(int address) {
|
||||
}
|
||||
|
||||
template <Personality personality>
|
||||
HalfCycles Base<personality>::half_cycles_before_internal_cycles(int internal_cycles) {
|
||||
HalfCycles Base<personality>::half_cycles_before_internal_cycles(int internal_cycles) const {
|
||||
return HalfCycles(((internal_cycles << 2) + (2 - cycles_error_)) / 3);
|
||||
}
|
||||
|
||||
template <Personality personality>
|
||||
HalfCycles TMS9918<personality>::get_next_sequence_point() {
|
||||
HalfCycles TMS9918<personality>::get_next_sequence_point() const {
|
||||
if(!this->generate_interrupts_ && !this->enable_line_interrupts_) return HalfCycles::max();
|
||||
if(get_interrupt_line()) return HalfCycles::max();
|
||||
|
||||
@ -819,7 +819,7 @@ HalfCycles TMS9918<personality>::get_time_until_line(int line) {
|
||||
}
|
||||
|
||||
template <Personality personality>
|
||||
bool TMS9918<personality>::get_interrupt_line() {
|
||||
bool TMS9918<personality>::get_interrupt_line() const {
|
||||
return
|
||||
((this->status_ & StatusInterrupt) && this->generate_interrupts_) ||
|
||||
(this->enable_line_interrupts_ && this->line_interrupt_pending_);
|
||||
|
@ -55,7 +55,7 @@ namespace TMS {
|
||||
These chips have only one non-on-demand interaction with the outside world: an interrupt line.
|
||||
See get_time_until_interrupt and get_interrupt_line for asynchronous operation options.
|
||||
*/
|
||||
template <Personality personality> class TMS9918: public Base<personality> {
|
||||
template <Personality personality> class TMS9918: private Base<personality> {
|
||||
public:
|
||||
/*! Constructs an instance of the VDP that behaves according to the templated personality. */
|
||||
TMS9918();
|
||||
@ -93,10 +93,10 @@ template <Personality personality> class TMS9918: public Base<personality> {
|
||||
uint8_t read(int address);
|
||||
|
||||
/*! Gets the current scan line; provided by the Sega VDPs only. */
|
||||
uint8_t get_current_line();
|
||||
uint8_t get_current_line() const;
|
||||
|
||||
/*! Gets the current latched horizontal counter; provided by the Sega VDPs only. */
|
||||
uint8_t get_latched_horizontal_counter();
|
||||
uint8_t get_latched_horizontal_counter() const;
|
||||
|
||||
/*! Latches the current horizontal counter. */
|
||||
void latch_horizontal_counter();
|
||||
@ -108,7 +108,7 @@ template <Personality personality> class TMS9918: public Base<personality> {
|
||||
If get_interrupt_line is true now of if get_interrupt_line would
|
||||
never return true, returns HalfCycles::max().
|
||||
*/
|
||||
HalfCycles get_next_sequence_point();
|
||||
HalfCycles get_next_sequence_point() const;
|
||||
|
||||
/*!
|
||||
Returns the amount of time until the nominated line interrupt position is
|
||||
@ -123,7 +123,7 @@ template <Personality personality> class TMS9918: public Base<personality> {
|
||||
/*!
|
||||
@returns @c true if the interrupt line is currently active; @c false otherwise.
|
||||
*/
|
||||
bool get_interrupt_line();
|
||||
bool get_interrupt_line() const;
|
||||
};
|
||||
|
||||
}
|
||||
|
@ -121,9 +121,11 @@ struct LineBufferPointer {
|
||||
int row, column;
|
||||
};
|
||||
|
||||
template <Personality personality> class Base {
|
||||
public:
|
||||
static uint32_t palette_pack(uint8_t r, uint8_t g, uint8_t b) {
|
||||
template <Personality personality> struct Base {
|
||||
static constexpr int output_lag = 11; // i.e. pixel output will occur 11 cycles
|
||||
// after corresponding data read.
|
||||
|
||||
static constexpr uint32_t palette_pack(uint8_t r, uint8_t g, uint8_t b) {
|
||||
uint32_t result = 0;
|
||||
uint8_t *const result_ptr = reinterpret_cast<uint8_t *>(&result);
|
||||
result_ptr[0] = r;
|
||||
@ -133,9 +135,6 @@ template <Personality personality> class Base {
|
||||
return result;
|
||||
}
|
||||
|
||||
protected:
|
||||
static constexpr int output_lag = 11; // i.e. pixel output will occur 11 cycles after corresponding data read.
|
||||
|
||||
// The default TMS palette.
|
||||
const uint32_t palette[16] = {
|
||||
palette_pack(0, 0, 0),
|
||||
@ -213,7 +212,7 @@ template <Personality personality> class Base {
|
||||
// internally at 5.37Mhz. The following two help to maintain a lossless conversion
|
||||
// from the one to the other.
|
||||
int cycles_error_ = 0;
|
||||
HalfCycles half_cycles_before_internal_cycles(int internal_cycles);
|
||||
HalfCycles half_cycles_before_internal_cycles(int internal_cycles) const;
|
||||
|
||||
// Internal mechanisms for position tracking.
|
||||
int latched_column_ = 0;
|
||||
|
Loading…
Reference in New Issue
Block a user