1
0
mirror of https://github.com/TomHarte/CLK.git synced 2024-07-10 12:29:01 +00:00

Eliminates some dangling cases of undefined initial state in the TIA.

This commit is contained in:
Thomas Harte 2017-11-06 22:12:39 -05:00
parent 4b68c372c6
commit 0da78065ce

View File

@ -135,42 +135,27 @@ class TIA {
// objects // objects
template<class T> struct Object { template<class T> struct Object {
// the two programmer-set values // the two programmer-set values
int position; int position = 0;
int motion; int motion = 0;
// motion_step_ is the current motion counter value; motion_time_ is the next time it will fire // motion_step_ is the current motion counter value; motion_time_ is the next time it will fire
int motion_step; int motion_step = 0;
int motion_time; int motion_time = 0;
// indicates whether this object is currently undergoing motion // indicates whether this object is currently undergoing motion
bool is_moving; bool is_moving = false;
Object() : position(0), motion(0), motion_step(0), motion_time(0), is_moving(false) {};
}; };
// player state // player state
struct Player: public Object<Player> { struct Player: public Object<Player> {
Player() : int adder = 4;
adder(4), int copy_flags = 0; // a bit field, corresponding to the first few values of NUSIZ
copy_flags(0), uint8_t graphic[2] = {0, 0}; // the player graphic; 1 = new, 0 = current
graphic{0, 0}, int reverse_mask = false; // 7 for a reflected player, 0 for normal
reverse_mask(false), int graphic_index = 0;
graphic_index(0),
pixel_position(32),
pixel_counter(0),
latched_pixel4_time(-1),
copy_index_(0),
queue_read_pointer_(0),
queue_write_pointer_(0) {}
int adder; int pixel_position = 32, pixel_counter = 0;
int copy_flags; // a bit field, corresponding to the first few values of NUSIZ int latched_pixel4_time = -1;
uint8_t graphic[2]; // the player graphic; 1 = new, 0 = current
int reverse_mask; // 7 for a reflected player, 0 for normal
int graphic_index;
int pixel_position, pixel_counter;
int latched_pixel4_time;
const bool enqueues = true; const bool enqueues = true;
inline void skip_pixels(const int count, int from_horizontal_counter) { inline void skip_pixels(const int count, int from_horizontal_counter) {
@ -219,15 +204,14 @@ class TIA {
} }
private: private:
int copy_index_; int copy_index_ = 0;
struct QueuedPixels { struct QueuedPixels {
int start, end; int start = 0, end = 0;
int pixel_position; int pixel_position = 0;
int adder; int adder = 0;
int reverse_mask; int reverse_mask = false;
QueuedPixels() : start(0), end(0), pixel_position(0), adder(0), reverse_mask(false) {}
} queue_[4]; } queue_[4];
int queue_read_pointer_, queue_write_pointer_; int queue_read_pointer_ = 0, queue_write_pointer_ = 0;
inline void output_pixels(uint8_t *const target, const int count, const uint8_t collision_identity, int output_pixel_position, int output_adder, int output_reverse_mask) { inline void output_pixels(uint8_t *const target, const int count, const uint8_t collision_identity, int output_pixel_position, int output_adder, int output_reverse_mask) {
if(output_pixel_position == 32 || !graphic[graphic_index]) return; if(output_pixel_position == 32 || !graphic[graphic_index]) return;
@ -244,8 +228,8 @@ class TIA {
// common actor for things that appear as a horizontal run of pixels // common actor for things that appear as a horizontal run of pixels
struct HorizontalRun: public Object<HorizontalRun> { struct HorizontalRun: public Object<HorizontalRun> {
int pixel_position; int pixel_position = 0;
int size; int size = 1;
const bool enqueues = false; const bool enqueues = false;
inline void skip_pixels(const int count, int from_horizontal_counter) { inline void skip_pixels(const int count, int from_horizontal_counter) {
@ -268,16 +252,13 @@ class TIA {
void dequeue_pixels(uint8_t *const target, const uint8_t collision_identity, const int time_now) {} void dequeue_pixels(uint8_t *const target, const uint8_t collision_identity, const int time_now) {}
void enqueue_pixels(const int start, const int end, int from_horizontal_counter) {} void enqueue_pixels(const int start, const int end, int from_horizontal_counter) {}
HorizontalRun() : pixel_position(0), size(1) {}
}; };
// missile state // missile state
struct Missile: public HorizontalRun { struct Missile: public HorizontalRun {
bool enabled; bool enabled = false;
bool locked_to_player; bool locked_to_player = false;
int copy_flags; int copy_flags = 0;
inline void output_pixels(uint8_t *const target, const int count, const uint8_t collision_identity, int from_horizontal_counter) { inline void output_pixels(uint8_t *const target, const int count, const uint8_t collision_identity, int from_horizontal_counter) {
if(!pixel_position) return; if(!pixel_position) return;
@ -287,14 +268,12 @@ class TIA {
skip_pixels(count, from_horizontal_counter); skip_pixels(count, from_horizontal_counter);
} }
} }
Missile() : enabled(false), copy_flags(0) {}
} missile_[2]; } missile_[2];
// ball state // ball state
struct Ball: public HorizontalRun { struct Ball: public HorizontalRun {
bool enabled[2]; bool enabled[2] = {false, false};
int enabled_index; int enabled_index = 0;
const int copy_flags = 0; const int copy_flags = 0;
inline void output_pixels(uint8_t *const target, const int count, const uint8_t collision_identity, int from_horizontal_counter) { inline void output_pixels(uint8_t *const target, const int count, const uint8_t collision_identity, int from_horizontal_counter) {
@ -305,8 +284,6 @@ class TIA {
skip_pixels(count, from_horizontal_counter); skip_pixels(count, from_horizontal_counter);
} }
} }
Ball() : enabled{false, false}, enabled_index(0) {}
} ball_; } ball_;
// motion // motion