1
0
mirror of https://github.com/TomHarte/CLK.git synced 2024-10-04 17:56:29 +00:00

Standardised curly bracket placement across the Atari.

This commit is contained in:
Thomas Harte 2017-03-23 21:59:16 -04:00
parent a4c5eebd1e
commit 3229502fa1
5 changed files with 136 additions and 282 deletions

View File

@ -57,8 +57,7 @@ class Machine:
std::unique_ptr<Bus> bus_; std::unique_ptr<Bus> bus_;
// output frame rate tracker // output frame rate tracker
struct FrameRecord struct FrameRecord {
{
unsigned int number_of_frames; unsigned int number_of_frames;
unsigned int number_of_unexpected_vertical_syncs; unsigned int number_of_unexpected_vertical_syncs;

View File

@ -15,13 +15,11 @@ namespace Atari2600 {
class PIA: public MOS::MOS6532<PIA> { class PIA: public MOS::MOS6532<PIA> {
public: public:
inline uint8_t get_port_input(int port) inline uint8_t get_port_input(int port) {
{
return port_values_[port]; return port_values_[port];
} }
inline void update_port_input(int port, uint8_t mask, bool set) inline void update_port_input(int port, uint8_t mask, bool set) {
{
if(set) port_values_[port] &= ~mask; else port_values_[port] |= mask; if(set) port_values_[port] &= ~mask; else port_values_[port] |= mask;
set_port_did_change(port); set_port_did_change(port);
} }

View File

@ -16,23 +16,20 @@ Atari2600::Speaker::Speaker() :
poly9_counter_{0x1ff, 0x1ff} poly9_counter_{0x1ff, 0x1ff}
{} {}
void Atari2600::Speaker::set_volume(int channel, uint8_t volume) void Atari2600::Speaker::set_volume(int channel, uint8_t volume) {
{
enqueue([=]() { enqueue([=]() {
volume_[channel] = volume & 0xf; volume_[channel] = volume & 0xf;
}); });
} }
void Atari2600::Speaker::set_divider(int channel, uint8_t divider) void Atari2600::Speaker::set_divider(int channel, uint8_t divider) {
{
enqueue([=]() { enqueue([=]() {
divider_[channel] = divider & 0x1f; divider_[channel] = divider & 0x1f;
divider_counter_[channel] = 0; divider_counter_[channel] = 0;
}); });
} }
void Atari2600::Speaker::set_control(int channel, uint8_t control) void Atari2600::Speaker::set_control(int channel, uint8_t control) {
{
enqueue([=]() { enqueue([=]() {
control_[channel] = control & 0xf; control_[channel] = control & 0xf;
}); });
@ -42,17 +39,13 @@ void Atari2600::Speaker::set_control(int channel, uint8_t control)
#define advance_poly5(c) poly5_counter_[channel] = (poly5_counter_[channel] >> 1) | (((poly5_counter_[channel] << 4) ^ (poly5_counter_[channel] << 2))&0x010) #define advance_poly5(c) poly5_counter_[channel] = (poly5_counter_[channel] >> 1) | (((poly5_counter_[channel] << 4) ^ (poly5_counter_[channel] << 2))&0x010)
#define advance_poly9(c) poly9_counter_[channel] = (poly9_counter_[channel] >> 1) | (((poly9_counter_[channel] << 4) ^ (poly9_counter_[channel] << 8))&0x100) #define advance_poly9(c) poly9_counter_[channel] = (poly9_counter_[channel] >> 1) | (((poly9_counter_[channel] << 4) ^ (poly9_counter_[channel] << 8))&0x100)
void Atari2600::Speaker::get_samples(unsigned int number_of_samples, int16_t *target) void Atari2600::Speaker::get_samples(unsigned int number_of_samples, int16_t *target) {
{ for(unsigned int c = 0; c < number_of_samples; c++) {
for(unsigned int c = 0; c < number_of_samples; c++)
{
target[c] = 0; target[c] = 0;
for(int channel = 0; channel < 2; channel++) for(int channel = 0; channel < 2; channel++) {
{
divider_counter_[channel] ++; divider_counter_[channel] ++;
int level = 0; int level = 0;
switch(control_[channel]) switch(control_[channel]) {
{
case 0x0: case 0xb: // constant 1 case 0x0: case 0xb: // constant 1
level = 1; level = 1;
break; break;
@ -75,8 +68,7 @@ void Atari2600::Speaker::get_samples(unsigned int number_of_samples, int16_t *ta
case 0x1: // 4-bit poly case 0x1: // 4-bit poly
level = poly4_counter_[channel]&1; level = poly4_counter_[channel]&1;
if(divider_counter_[channel] == divider_[channel]+1) if(divider_counter_[channel] == divider_[channel]+1) {
{
divider_counter_[channel] = 0; divider_counter_[channel] = 0;
advance_poly4(channel); advance_poly4(channel);
} }
@ -84,18 +76,15 @@ void Atari2600::Speaker::get_samples(unsigned int number_of_samples, int16_t *ta
case 0x2: // 4-bit poly div31 case 0x2: // 4-bit poly div31
level = poly4_counter_[channel]&1; level = poly4_counter_[channel]&1;
if(divider_counter_[channel]%(30*(divider_[channel]+1)) == 18) if(divider_counter_[channel]%(30*(divider_[channel]+1)) == 18) {
{
advance_poly4(channel); advance_poly4(channel);
} }
break; break;
case 0x3: // 5/4-bit poly case 0x3: // 5/4-bit poly
level = output_state_[channel]; level = output_state_[channel];
if(divider_counter_[channel] == divider_[channel]+1) if(divider_counter_[channel] == divider_[channel]+1) {
{ if(poly5_counter_[channel]&1) {
if(poly5_counter_[channel]&1)
{
output_state_[channel] = poly4_counter_[channel]&1; output_state_[channel] = poly4_counter_[channel]&1;
advance_poly4(channel); advance_poly4(channel);
} }
@ -105,8 +94,7 @@ void Atari2600::Speaker::get_samples(unsigned int number_of_samples, int16_t *ta
case 0x7: case 0x9: // 5-bit poly case 0x7: case 0x9: // 5-bit poly
level = poly5_counter_[channel]&1; level = poly5_counter_[channel]&1;
if(divider_counter_[channel] == divider_[channel]+1) if(divider_counter_[channel] == divider_[channel]+1) {
{
divider_counter_[channel] = 0; divider_counter_[channel] = 0;
advance_poly5(channel); advance_poly5(channel);
} }
@ -114,8 +102,7 @@ void Atari2600::Speaker::get_samples(unsigned int number_of_samples, int16_t *ta
case 0xf: // 5-bit poly div6 case 0xf: // 5-bit poly div6
level = poly5_counter_[channel]&1; level = poly5_counter_[channel]&1;
if(divider_counter_[channel] == (divider_[channel]+1)*3) if(divider_counter_[channel] == (divider_[channel]+1)*3) {
{
divider_counter_[channel] = 0; divider_counter_[channel] = 0;
advance_poly5(channel); advance_poly5(channel);
} }
@ -123,8 +110,7 @@ void Atari2600::Speaker::get_samples(unsigned int number_of_samples, int16_t *ta
case 0x8: // 9-bit poly case 0x8: // 9-bit poly
level = poly9_counter_[channel]&1; level = poly9_counter_[channel]&1;
if(divider_counter_[channel] == divider_[channel]+1) if(divider_counter_[channel] == divider_[channel]+1) {
{
divider_counter_[channel] = 0; divider_counter_[channel] = 0;
advance_poly9(channel); advance_poly9(channel);
} }

View File

@ -30,23 +30,20 @@ TIA::TIA(bool create_crt) :
horizontal_blank_extend_(false), horizontal_blank_extend_(false),
collision_flags_(0) collision_flags_(0)
{ {
if(create_crt) if(create_crt) {
{
crt_.reset(new Outputs::CRT::CRT(cycles_per_line * 2 - 1, 1, Outputs::CRT::DisplayType::NTSC60, 1)); crt_.reset(new Outputs::CRT::CRT(cycles_per_line * 2 - 1, 1, Outputs::CRT::DisplayType::NTSC60, 1));
crt_->set_output_device(Outputs::CRT::Television); crt_->set_output_device(Outputs::CRT::Television);
set_output_mode(OutputMode::NTSC); set_output_mode(OutputMode::NTSC);
} }
for(int c = 0; c < 256; c++) for(int c = 0; c < 256; c++) {
{
reverse_table[c] = (uint8_t)( reverse_table[c] = (uint8_t)(
((c & 0x01) << 7) | ((c & 0x02) << 5) | ((c & 0x04) << 3) | ((c & 0x08) << 1) | ((c & 0x01) << 7) | ((c & 0x02) << 5) | ((c & 0x04) << 3) | ((c & 0x08) << 1) |
((c & 0x10) >> 1) | ((c & 0x20) >> 3) | ((c & 0x40) >> 5) | ((c & 0x80) >> 7) ((c & 0x10) >> 1) | ((c & 0x20) >> 3) | ((c & 0x40) >> 5) | ((c & 0x80) >> 7)
); );
} }
for(int c = 0; c < 64; c++) for(int c = 0; c < 64; c++) {
{
bool has_playfield = c & (int)(CollisionType::Playfield); bool has_playfield = c & (int)(CollisionType::Playfield);
bool has_ball = c & (int)(CollisionType::Ball); bool has_ball = c & (int)(CollisionType::Ball);
bool has_player0 = c & (int)(CollisionType::Player0); bool has_player0 = c & (int)(CollisionType::Player0);
@ -80,21 +77,18 @@ TIA::TIA(bool create_crt) :
colour_mask_by_mode_collision_flags_[(int)ColourMode::OnTop][c] = (uint8_t)ColourIndex::Background; colour_mask_by_mode_collision_flags_[(int)ColourMode::OnTop][c] = (uint8_t)ColourIndex::Background;
// test 1 for standard priority: if there is a playfield or ball pixel, plot that colour // test 1 for standard priority: if there is a playfield or ball pixel, plot that colour
if(has_playfield || has_ball) if(has_playfield || has_ball) {
{
colour_mask_by_mode_collision_flags_[(int)ColourMode::Standard][c] = (uint8_t)ColourIndex::PlayfieldBall; colour_mask_by_mode_collision_flags_[(int)ColourMode::Standard][c] = (uint8_t)ColourIndex::PlayfieldBall;
} }
// test 1 for score mode: if there is a ball pixel, plot that colour // test 1 for score mode: if there is a ball pixel, plot that colour
if(has_ball) if(has_ball) {
{
colour_mask_by_mode_collision_flags_[(int)ColourMode::ScoreLeft][c] = colour_mask_by_mode_collision_flags_[(int)ColourMode::ScoreLeft][c] =
colour_mask_by_mode_collision_flags_[(int)ColourMode::ScoreRight][c] = (uint8_t)ColourIndex::PlayfieldBall; colour_mask_by_mode_collision_flags_[(int)ColourMode::ScoreRight][c] = (uint8_t)ColourIndex::PlayfieldBall;
} }
// test 1 for on-top mode, test 2 for everbody else: if there is a player 1 or missile 1 pixel, plot that colour // test 1 for on-top mode, test 2 for everbody else: if there is a player 1 or missile 1 pixel, plot that colour
if(has_player1 || has_missile1) if(has_player1 || has_missile1) {
{
colour_mask_by_mode_collision_flags_[(int)ColourMode::Standard][c] = colour_mask_by_mode_collision_flags_[(int)ColourMode::Standard][c] =
colour_mask_by_mode_collision_flags_[(int)ColourMode::ScoreLeft][c] = colour_mask_by_mode_collision_flags_[(int)ColourMode::ScoreLeft][c] =
colour_mask_by_mode_collision_flags_[(int)ColourMode::ScoreRight][c] = colour_mask_by_mode_collision_flags_[(int)ColourMode::ScoreRight][c] =
@ -102,14 +96,12 @@ TIA::TIA(bool create_crt) :
} }
// in the right-hand side of score mode, the playfield has the same priority as player 1 // in the right-hand side of score mode, the playfield has the same priority as player 1
if(has_playfield) if(has_playfield) {
{
colour_mask_by_mode_collision_flags_[(int)ColourMode::ScoreRight][c] = (uint8_t)ColourIndex::PlayerMissile1; colour_mask_by_mode_collision_flags_[(int)ColourMode::ScoreRight][c] = (uint8_t)ColourIndex::PlayerMissile1;
} }
// next test for everybody: if there is a player 0 or missile 0 pixel, plot that colour instead // next test for everybody: if there is a player 0 or missile 0 pixel, plot that colour instead
if(has_player0 || has_missile0) if(has_player0 || has_missile0) {
{
colour_mask_by_mode_collision_flags_[(int)ColourMode::Standard][c] = colour_mask_by_mode_collision_flags_[(int)ColourMode::Standard][c] =
colour_mask_by_mode_collision_flags_[(int)ColourMode::ScoreLeft][c] = colour_mask_by_mode_collision_flags_[(int)ColourMode::ScoreLeft][c] =
colour_mask_by_mode_collision_flags_[(int)ColourMode::ScoreRight][c] = colour_mask_by_mode_collision_flags_[(int)ColourMode::ScoreRight][c] =
@ -117,14 +109,12 @@ TIA::TIA(bool create_crt) :
} }
// if this is the left-hand side of score mode, the playfield has the same priority as player 0 // if this is the left-hand side of score mode, the playfield has the same priority as player 0
if(has_playfield) if(has_playfield) {
{
colour_mask_by_mode_collision_flags_[(int)ColourMode::ScoreLeft][c] = (uint8_t)ColourIndex::PlayerMissile0; colour_mask_by_mode_collision_flags_[(int)ColourMode::ScoreLeft][c] = (uint8_t)ColourIndex::PlayerMissile0;
} }
// a final test for 'on top' priority mode: if the playfield or ball are visible, prefer that colour to all others // a final test for 'on top' priority mode: if the playfield or ball are visible, prefer that colour to all others
if(has_playfield || has_ball) if(has_playfield || has_ball) {
{
colour_mask_by_mode_collision_flags_[(int)ColourMode::OnTop][c] = (uint8_t)ColourIndex::PlayfieldBall; colour_mask_by_mode_collision_flags_[(int)ColourMode::OnTop][c] = (uint8_t)ColourIndex::PlayfieldBall;
} }
} }
@ -132,17 +122,14 @@ TIA::TIA(bool create_crt) :
TIA::TIA() : TIA(true) {} TIA::TIA() : TIA(true) {}
TIA::TIA(std::function<void(uint8_t *output_buffer)> line_end_function) : TIA(false) TIA::TIA(std::function<void(uint8_t *output_buffer)> line_end_function) : TIA(false) {
{
line_end_function_ = line_end_function; line_end_function_ = line_end_function;
} }
void TIA::set_output_mode(Atari2600::TIA::OutputMode output_mode) void TIA::set_output_mode(Atari2600::TIA::OutputMode output_mode) {
{
Outputs::CRT::DisplayType display_type; Outputs::CRT::DisplayType display_type;
if(output_mode == OutputMode::NTSC) if(output_mode == OutputMode::NTSC) {
{
crt_->set_composite_sampling_function( crt_->set_composite_sampling_function(
"float composite_sample(usampler2D texID, vec2 coordinate, vec2 iCoordinate, float phase, float amplitude)" "float composite_sample(usampler2D texID, vec2 coordinate, vec2 iCoordinate, float phase, float amplitude)"
"{" "{"
@ -154,9 +141,7 @@ void TIA::set_output_mode(Atari2600::TIA::OutputMode output_mode)
"return mix(float(y) / 14.0, step(1, iPhase) * cos(phase + phaseOffset), amplitude);" "return mix(float(y) / 14.0, step(1, iPhase) * cos(phase + phaseOffset), amplitude);"
"}"); "}");
display_type = Outputs::CRT::DisplayType::NTSC60; display_type = Outputs::CRT::DisplayType::NTSC60;
} } else {
else
{
crt_->set_composite_sampling_function( crt_->set_composite_sampling_function(
"float composite_sample(usampler2D texID, vec2 coordinate, vec2 iCoordinate, float phase, float amplitude)" "float composite_sample(usampler2D texID, vec2 coordinate, vec2 iCoordinate, float phase, float amplitude)"
"{" "{"
@ -183,56 +168,46 @@ void TIA::set_output_mode(Atari2600::TIA::OutputMode output_mode)
void TIA::run_for_cycles(int number_of_cycles) void TIA::run_for_cycles(int number_of_cycles)
{ {
// if part way through a line, definitely perform a partial, at most up to the end of the line // if part way through a line, definitely perform a partial, at most up to the end of the line
if(horizontal_counter_) if(horizontal_counter_) {
{
int cycles = std::min(number_of_cycles, cycles_per_line - horizontal_counter_); int cycles = std::min(number_of_cycles, cycles_per_line - horizontal_counter_);
output_for_cycles(cycles); output_for_cycles(cycles);
number_of_cycles -= cycles; number_of_cycles -= cycles;
} }
// output full lines for as long as possible // output full lines for as long as possible
while(number_of_cycles >= cycles_per_line) while(number_of_cycles >= cycles_per_line) {
{
output_line(); output_line();
number_of_cycles -= cycles_per_line; number_of_cycles -= cycles_per_line;
} }
// partly start a new line if necessary // partly start a new line if necessary
if(number_of_cycles) if(number_of_cycles) {
{
output_for_cycles(number_of_cycles); output_for_cycles(number_of_cycles);
} }
} }
void TIA::set_sync(bool sync) void TIA::set_sync(bool sync) {
{
output_mode_ = (output_mode_ & ~sync_flag) | (sync ? sync_flag : 0); output_mode_ = (output_mode_ & ~sync_flag) | (sync ? sync_flag : 0);
} }
void TIA::set_blank(bool blank) void TIA::set_blank(bool blank) {
{
output_mode_ = (output_mode_ & ~blank_flag) | (blank ? blank_flag : 0); output_mode_ = (output_mode_ & ~blank_flag) | (blank ? blank_flag : 0);
} }
void TIA::reset_horizontal_counter() void TIA::reset_horizontal_counter() {
{
} }
int TIA::get_cycles_until_horizontal_blank(unsigned int from_offset) int TIA::get_cycles_until_horizontal_blank(unsigned int from_offset) {
{
return (cycles_per_line - (horizontal_counter_ + (int)from_offset) % cycles_per_line) % cycles_per_line; return (cycles_per_line - (horizontal_counter_ + (int)from_offset) % cycles_per_line) % cycles_per_line;
} }
void TIA::set_background_colour(uint8_t colour) void TIA::set_background_colour(uint8_t colour) {
{
colour_palette_[(int)ColourIndex::Background] = colour; colour_palette_[(int)ColourIndex::Background] = colour;
} }
void TIA::set_playfield(uint16_t offset, uint8_t value) void TIA::set_playfield(uint16_t offset, uint8_t value) {
{
assert(offset >= 0 && offset < 3); assert(offset >= 0 && offset < 3);
switch(offset) switch(offset) {
{
case 0: case 0:
background_[1] = (background_[1] & 0x0ffff) | ((uint32_t)reverse_table[value & 0xf0] << 16); background_[1] = (background_[1] & 0x0ffff) | ((uint32_t)reverse_table[value & 0xf0] << 16);
background_[0] = (background_[0] & 0xffff0) | (uint32_t)(value >> 4); background_[0] = (background_[0] & 0xffff0) | (uint32_t)(value >> 4);
@ -248,11 +223,9 @@ void TIA::set_playfield(uint16_t offset, uint8_t value)
} }
} }
void TIA::set_playfield_control_and_ball_size(uint8_t value) void TIA::set_playfield_control_and_ball_size(uint8_t value) {
{
background_half_mask_ = value & 1; background_half_mask_ = value & 1;
switch(value & 6) switch(value & 6) {
{
case 0: case 0:
playfield_priority_ = PlayfieldPriority::Standard; playfield_priority_ = PlayfieldPriority::Standard;
break; break;
@ -268,17 +241,14 @@ void TIA::set_playfield_control_and_ball_size(uint8_t value)
ball_.size = 1 << ((value >> 4)&3); ball_.size = 1 << ((value >> 4)&3);
} }
void TIA::set_playfield_ball_colour(uint8_t colour) void TIA::set_playfield_ball_colour(uint8_t colour) {
{
colour_palette_[(int)ColourIndex::PlayfieldBall] = colour; colour_palette_[(int)ColourIndex::PlayfieldBall] = colour;
} }
void TIA::set_player_number_and_size(int player, uint8_t value) void TIA::set_player_number_and_size(int player, uint8_t value) {
{
assert(player >= 0 && player < 2); assert(player >= 0 && player < 2);
int size = 0; int size = 0;
switch(value & 7) switch(value & 7) {
{
case 0: case 1: case 2: case 3: case 4: case 0: case 1: case 2: case 3: case 4:
player_[player].copy_flags = value & 7; player_[player].copy_flags = value & 7;
break; break;
@ -300,28 +270,24 @@ void TIA::set_player_number_and_size(int player, uint8_t value)
player_[player].adder = 4 >> size; player_[player].adder = 4 >> size;
} }
void TIA::set_player_graphic(int player, uint8_t value) void TIA::set_player_graphic(int player, uint8_t value) {
{
assert(player >= 0 && player < 2); assert(player >= 0 && player < 2);
player_[player].graphic[1] = value; player_[player].graphic[1] = value;
player_[player^1].graphic[0] = player_[player^1].graphic[1]; player_[player^1].graphic[0] = player_[player^1].graphic[1];
if(player) ball_.enabled[0] = ball_.enabled[1]; if(player) ball_.enabled[0] = ball_.enabled[1];
} }
void TIA::set_player_reflected(int player, bool reflected) void TIA::set_player_reflected(int player, bool reflected) {
{
assert(player >= 0 && player < 2); assert(player >= 0 && player < 2);
player_[player].reverse_mask = reflected ? 7 : 0; player_[player].reverse_mask = reflected ? 7 : 0;
} }
void TIA::set_player_delay(int player, bool delay) void TIA::set_player_delay(int player, bool delay) {
{
assert(player >= 0 && player < 2); assert(player >= 0 && player < 2);
player_[player].graphic_index = delay ? 0 : 1; player_[player].graphic_index = delay ? 0 : 1;
} }
void TIA::set_player_position(int player) void TIA::set_player_position(int player) {
{
assert(player >= 0 && player < 2); assert(player >= 0 && player < 2);
// players have an extra clock of delay before output and don't display upon reset; // players have an extra clock of delay before output and don't display upon reset;
// both aims are achieved by setting to -1 because: (i) it causes the clock to be // both aims are achieved by setting to -1 because: (i) it causes the clock to be
@ -331,91 +297,76 @@ void TIA::set_player_position(int player)
player_[player].position = -1; player_[player].position = -1;
} }
void TIA::set_player_motion(int player, uint8_t motion) void TIA::set_player_motion(int player, uint8_t motion) {
{
assert(player >= 0 && player < 2); assert(player >= 0 && player < 2);
player_[player].motion = (motion >> 4)&0xf; player_[player].motion = (motion >> 4)&0xf;
} }
void TIA::set_player_missile_colour(int player, uint8_t colour) void TIA::set_player_missile_colour(int player, uint8_t colour) {
{
assert(player >= 0 && player < 2); assert(player >= 0 && player < 2);
colour_palette_[(int)ColourIndex::PlayerMissile0 + player] = colour; colour_palette_[(int)ColourIndex::PlayerMissile0 + player] = colour;
} }
void TIA::set_missile_enable(int missile, bool enabled) void TIA::set_missile_enable(int missile, bool enabled) {
{
assert(missile >= 0 && missile < 2); assert(missile >= 0 && missile < 2);
missile_[missile].enabled = enabled; missile_[missile].enabled = enabled;
} }
void TIA::set_missile_position(int missile) void TIA::set_missile_position(int missile) {
{
assert(missile >= 0 && missile < 2); assert(missile >= 0 && missile < 2);
missile_[missile].position = 0; missile_[missile].position = 0;
} }
void TIA::set_missile_position_to_player(int missile, bool lock) void TIA::set_missile_position_to_player(int missile, bool lock) {
{
assert(missile >= 0 && missile < 2); assert(missile >= 0 && missile < 2);
missile_[missile].locked_to_player = lock; missile_[missile].locked_to_player = lock;
player_[missile].latched_pixel4_time = -1; player_[missile].latched_pixel4_time = -1;
} }
void TIA::set_missile_motion(int missile, uint8_t motion) void TIA::set_missile_motion(int missile, uint8_t motion) {
{
assert(missile >= 0 && missile < 2); assert(missile >= 0 && missile < 2);
missile_[missile].motion = (motion >> 4)&0xf; missile_[missile].motion = (motion >> 4)&0xf;
} }
void TIA::set_ball_enable(bool enabled) void TIA::set_ball_enable(bool enabled) {
{
ball_.enabled[1] = enabled; ball_.enabled[1] = enabled;
} }
void TIA::set_ball_delay(bool delay) void TIA::set_ball_delay(bool delay) {
{
ball_.enabled_index = delay ? 0 : 1; ball_.enabled_index = delay ? 0 : 1;
} }
void TIA::set_ball_position() void TIA::set_ball_position() {
{
ball_.position = 0; ball_.position = 0;
// setting the ball position also triggers a draw // setting the ball position also triggers a draw
ball_.reset_pixels(0); ball_.reset_pixels(0);
} }
void TIA::set_ball_motion(uint8_t motion) void TIA::set_ball_motion(uint8_t motion) {
{
ball_.motion = (motion >> 4) & 0xf; ball_.motion = (motion >> 4) & 0xf;
} }
void TIA::move() void TIA::move() {
{
horizontal_blank_extend_ = true; horizontal_blank_extend_ = true;
player_[0].is_moving = player_[1].is_moving = missile_[0].is_moving = missile_[1].is_moving = ball_.is_moving = true; player_[0].is_moving = player_[1].is_moving = missile_[0].is_moving = missile_[1].is_moving = ball_.is_moving = true;
player_[0].motion_step = player_[1].motion_step = missile_[0].motion_step = missile_[1].motion_step = ball_.motion_step = 15; player_[0].motion_step = player_[1].motion_step = missile_[0].motion_step = missile_[1].motion_step = ball_.motion_step = 15;
player_[0].motion_time = player_[1].motion_time = missile_[0].motion_time = missile_[1].motion_time = ball_.motion_time = (horizontal_counter_ + 3) & ~3; player_[0].motion_time = player_[1].motion_time = missile_[0].motion_time = missile_[1].motion_time = ball_.motion_time = (horizontal_counter_ + 3) & ~3;
} }
void TIA::clear_motion() void TIA::clear_motion() {
{
player_[0].motion = player_[1].motion = missile_[0].motion = missile_[1].motion = ball_.motion = 0; player_[0].motion = player_[1].motion = missile_[0].motion = missile_[1].motion = ball_.motion = 0;
} }
uint8_t TIA::get_collision_flags(int offset) uint8_t TIA::get_collision_flags(int offset) {
{
return (uint8_t)((collision_flags_ >> (offset << 1)) << 6) & 0xc0; return (uint8_t)((collision_flags_ >> (offset << 1)) << 6) & 0xc0;
} }
void TIA::clear_collision_flags() void TIA::clear_collision_flags() {
{
collision_flags_ = 0; collision_flags_ = 0;
} }
void TIA::output_for_cycles(int number_of_cycles) void TIA::output_for_cycles(int number_of_cycles) {
{
/* /*
Line timing is oriented around 0 being the start of the right-hand side vertical blank; Line timing is oriented around 0 being the start of the right-hand side vertical blank;
a wsync synchronises the CPU to horizontal_counter_ = 0. All timing below is in terms of the a wsync synchronises the CPU to horizontal_counter_ = 0. All timing below is in terms of the
@ -434,8 +385,7 @@ void TIA::output_for_cycles(int number_of_cycles)
horizontal_counter_ += number_of_cycles; horizontal_counter_ += number_of_cycles;
bool is_reset = output_cursor < 224 && horizontal_counter_ >= 224; bool is_reset = output_cursor < 224 && horizontal_counter_ >= 224;
if(!output_cursor) if(!output_cursor) {
{
if(line_end_function_) line_end_function_(collision_buffer_); if(line_end_function_) line_end_function_(collision_buffer_);
memset(collision_buffer_, 0, sizeof(collision_buffer_)); memset(collision_buffer_, 0, sizeof(collision_buffer_));
@ -459,23 +409,18 @@ void TIA::output_for_cycles(int number_of_cycles)
// convert to television signals // convert to television signals
#define Period(function, target) \ #define Period(function, target) \
if(output_cursor < target) \ if(output_cursor < target) { \
{ \ if(horizontal_counter_ <= target) { \
if(horizontal_counter_ <= target) \
{ \
if(crt_) crt_->function((unsigned int)((horizontal_counter_ - output_cursor) * 2)); \ if(crt_) crt_->function((unsigned int)((horizontal_counter_ - output_cursor) * 2)); \
horizontal_counter_ %= cycles_per_line; \ horizontal_counter_ %= cycles_per_line; \
return; \ return; \
} \ } else { \
else \
{ \
if(crt_) crt_->function((unsigned int)((target - output_cursor) * 2)); \ if(crt_) crt_->function((unsigned int)((target - output_cursor) * 2)); \
output_cursor = target; \ output_cursor = target; \
} \ } \
} }
switch(output_mode_) switch(output_mode_) {
{
default: default:
Period(output_blank, 16) Period(output_blank, 16)
Period(output_sync, 32) Period(output_sync, 32)
@ -493,10 +438,8 @@ void TIA::output_for_cycles(int number_of_cycles)
#undef Period #undef Period
if(output_mode_ & blank_flag) if(output_mode_ & blank_flag) {
{ if(pixel_target_) {
if(pixel_target_)
{
output_pixels(pixels_start_location_, output_cursor); output_pixels(pixels_start_location_, output_cursor);
if(crt_) crt_->output_data((unsigned int)(output_cursor - pixels_start_location_) * 2, 2); if(crt_) crt_->output_data((unsigned int)(output_cursor - pixels_start_location_) * 2, 2);
pixel_target_ = nullptr; pixel_target_ = nullptr;
@ -504,11 +447,8 @@ void TIA::output_for_cycles(int number_of_cycles)
} }
int duration = std::min(228, horizontal_counter_) - output_cursor; int duration = std::min(228, horizontal_counter_) - output_cursor;
if(crt_) crt_->output_blank((unsigned int)(duration * 2)); if(crt_) crt_->output_blank((unsigned int)(duration * 2));
} } else {
else if(!pixels_start_location_ && crt_) {
{
if(!pixels_start_location_ && crt_)
{
pixels_start_location_ = output_cursor; pixels_start_location_ = output_cursor;
pixel_target_ = crt_->allocate_write_area(160); pixel_target_ = crt_->allocate_write_area(160);
} }
@ -517,14 +457,12 @@ void TIA::output_for_cycles(int number_of_cycles)
if(pixel_target_) output_pixels(output_cursor, horizontal_counter_); if(pixel_target_) output_pixels(output_cursor, horizontal_counter_);
// accumulate collision flags // accumulate collision flags
while(output_cursor < horizontal_counter_) while(output_cursor < horizontal_counter_) {
{
collision_flags_ |= collision_flags_by_buffer_vaules_[collision_buffer_[output_cursor - first_pixel_cycle]]; collision_flags_ |= collision_flags_by_buffer_vaules_[collision_buffer_[output_cursor - first_pixel_cycle]];
output_cursor++; output_cursor++;
} }
if(horizontal_counter_ == cycles_per_line && crt_) if(horizontal_counter_ == cycles_per_line && crt_) {
{
crt_->output_data((unsigned int)(output_cursor - pixels_start_location_) * 2, 2); crt_->output_data((unsigned int)(output_cursor - pixels_start_location_) * 2, 2);
pixel_target_ = nullptr; pixel_target_ = nullptr;
pixels_start_location_ = 0; pixels_start_location_ = 0;
@ -536,43 +474,34 @@ void TIA::output_for_cycles(int number_of_cycles)
horizontal_counter_ %= cycles_per_line; horizontal_counter_ %= cycles_per_line;
} }
void TIA::output_pixels(int start, int end) void TIA::output_pixels(int start, int end) {
{
start = std::max(start, pixels_start_location_); start = std::max(start, pixels_start_location_);
int target_position = start - pixels_start_location_; int target_position = start - pixels_start_location_;
if(start < first_pixel_cycle+8 && horizontal_blank_extend_) if(start < first_pixel_cycle+8 && horizontal_blank_extend_) {
{ while(start < end && start < first_pixel_cycle+8) {
while(start < end && start < first_pixel_cycle+8)
{
pixel_target_[target_position] = 0; pixel_target_[target_position] = 0;
start++; start++;
target_position++; target_position++;
} }
} }
if(playfield_priority_ == PlayfieldPriority::Score) if(playfield_priority_ == PlayfieldPriority::Score) {
{ while(start < end && start < first_pixel_cycle + 80) {
while(start < end && start < first_pixel_cycle + 80)
{
uint8_t buffer_value = collision_buffer_[start - first_pixel_cycle]; uint8_t buffer_value = collision_buffer_[start - first_pixel_cycle];
pixel_target_[target_position] = colour_palette_[colour_mask_by_mode_collision_flags_[(int)ColourMode::ScoreLeft][buffer_value]]; pixel_target_[target_position] = colour_palette_[colour_mask_by_mode_collision_flags_[(int)ColourMode::ScoreLeft][buffer_value]];
start++; start++;
target_position++; target_position++;
} }
while(start < end) while(start < end) {
{
uint8_t buffer_value = collision_buffer_[start - first_pixel_cycle]; uint8_t buffer_value = collision_buffer_[start - first_pixel_cycle];
pixel_target_[target_position] = colour_palette_[colour_mask_by_mode_collision_flags_[(int)ColourMode::ScoreRight][buffer_value]]; pixel_target_[target_position] = colour_palette_[colour_mask_by_mode_collision_flags_[(int)ColourMode::ScoreRight][buffer_value]];
start++; start++;
target_position++; target_position++;
} }
} } else {
else
{
int table_index = (int)((playfield_priority_ == PlayfieldPriority::Standard) ? ColourMode::Standard : ColourMode::OnTop); int table_index = (int)((playfield_priority_ == PlayfieldPriority::Standard) ? ColourMode::Standard : ColourMode::OnTop);
while(start < end) while(start < end) {
{
uint8_t buffer_value = collision_buffer_[start - first_pixel_cycle]; uint8_t buffer_value = collision_buffer_[start - first_pixel_cycle];
pixel_target_[target_position] = colour_palette_[colour_mask_by_mode_collision_flags_[table_index][buffer_value]]; pixel_target_[target_position] = colour_palette_[colour_mask_by_mode_collision_flags_[table_index][buffer_value]];
start++; start++;
@ -581,18 +510,15 @@ void TIA::output_pixels(int start, int end)
} }
} }
void TIA::output_line() void TIA::output_line() {
{ switch(output_mode_) {
switch(output_mode_)
{
default: default:
// TODO: optimise special case // TODO: optimise special case
output_for_cycles(cycles_per_line); output_for_cycles(cycles_per_line);
break; break;
case sync_flag: case sync_flag:
case sync_flag | blank_flag: case sync_flag | blank_flag:
if(crt_) if(crt_) {
{
crt_->output_sync(32); crt_->output_sync(32);
crt_->output_blank(32); crt_->output_blank(32);
crt_->output_sync(392); crt_->output_sync(392);
@ -600,8 +526,7 @@ void TIA::output_line()
horizontal_blank_extend_ = false; horizontal_blank_extend_ = false;
break; break;
case blank_flag: case blank_flag:
if(crt_) if(crt_) {
{
crt_->output_blank(32); crt_->output_blank(32);
crt_->output_sync(32); crt_->output_sync(32);
crt_->output_default_colour_burst(32); crt_->output_default_colour_burst(32);
@ -614,8 +539,7 @@ void TIA::output_line()
#pragma mark - Playfield output #pragma mark - Playfield output
void TIA::draw_playfield(int start, int end) void TIA::draw_playfield(int start, int end) {
{
// don't do anything if this window ends too early // don't do anything if this window ends too early
if(end < first_pixel_cycle) return; if(end < first_pixel_cycle) return;
@ -625,8 +549,7 @@ void TIA::draw_playfield(int start, int end)
// proceed along four-pixel boundaries, plotting four pixels at a time // proceed along four-pixel boundaries, plotting four pixels at a time
int aligned_position = (start + 3)&~3; int aligned_position = (start + 3)&~3;
while(aligned_position < end) while(aligned_position < end) {
{
int offset = (aligned_position - first_pixel_cycle) >> 2; int offset = (aligned_position - first_pixel_cycle) >> 2;
uint32_t value = ((background_[(offset/20)&background_half_mask_] >> (offset%20))&1) * 0x01010101; uint32_t value = ((background_[(offset/20)&background_half_mask_] >> (offset%20))&1) * 0x01010101;
*(uint32_t *)&collision_buffer_[aligned_position - first_pixel_cycle] |= value; *(uint32_t *)&collision_buffer_[aligned_position - first_pixel_cycle] |= value;
@ -636,12 +559,10 @@ void TIA::draw_playfield(int start, int end)
#pragma mark - Motion #pragma mark - Motion
template<class T> void TIA::perform_motion_step(T &object) template<class T> void TIA::perform_motion_step(T &object) {
{ if((object.motion_step ^ (object.motion ^ 8)) == 0xf) {
if((object.motion_step ^ (object.motion ^ 8)) == 0xf)
object.is_moving = false; object.is_moving = false;
else } else {
{
if(object.position == 159) object.reset_pixels(0); if(object.position == 159) object.reset_pixels(0);
else if(object.position == 15 && object.copy_flags&1) object.reset_pixels(1); else if(object.position == 15 && object.copy_flags&1) object.reset_pixels(1);
else if(object.position == 31 && object.copy_flags&2) object.reset_pixels(2); else if(object.position == 31 && object.copy_flags&2) object.reset_pixels(2);
@ -653,21 +574,18 @@ template<class T> void TIA::perform_motion_step(T &object)
} }
} }
template<class T> void TIA::perform_border_motion(T &object, int start, int end) template<class T> void TIA::perform_border_motion(T &object, int start, int end) {
{
while(object.is_moving && object.motion_time < end) while(object.is_moving && object.motion_time < end)
perform_motion_step<T>(object); perform_motion_step<T>(object);
} }
template<class T> void TIA::draw_object(T &object, const uint8_t collision_identity, int start, int end) template<class T> void TIA::draw_object(T &object, const uint8_t collision_identity, int start, int end) {
{
int first_pixel = first_pixel_cycle - 4 + (horizontal_blank_extend_ ? 8 : 0); int first_pixel = first_pixel_cycle - 4 + (horizontal_blank_extend_ ? 8 : 0);
object.dequeue_pixels(collision_buffer_, collision_identity, end - first_pixel_cycle); object.dequeue_pixels(collision_buffer_, collision_identity, end - first_pixel_cycle);
// movement works across the entire screen, so do work that falls outside of the pixel area // movement works across the entire screen, so do work that falls outside of the pixel area
if(start < first_pixel) if(start < first_pixel) {
{
perform_border_motion<T>(object, start, std::max(end, first_pixel)); perform_border_motion<T>(object, start, std::max(end, first_pixel));
} }
@ -677,47 +595,38 @@ template<class T> void TIA::draw_object(T &object, const uint8_t collision_ident
if(start >= end) return; if(start >= end) return;
// perform the visible part of the line, if any // perform the visible part of the line, if any
if(start < 224) if(start < 224) {
{
draw_object_visible<T>(object, collision_identity, start - first_pixel_cycle + 4, std::min(end - first_pixel_cycle + 4, 160), end - first_pixel_cycle); draw_object_visible<T>(object, collision_identity, start - first_pixel_cycle + 4, std::min(end - first_pixel_cycle + 4, 160), end - first_pixel_cycle);
} }
// move further if required // move further if required
if(object.is_moving && end >= 224 && object.motion_time < end) if(object.is_moving && end >= 224 && object.motion_time < end) {
{
perform_motion_step<T>(object); perform_motion_step<T>(object);
} }
} }
template<class T> void TIA::draw_object_visible(T &object, const uint8_t collision_identity, int start, int end, int time_now) template<class T> void TIA::draw_object_visible(T &object, const uint8_t collision_identity, int start, int end, int time_now) {
{
// perform a miniature event loop on (i) triggering draws; (ii) drawing; and (iii) motion // perform a miniature event loop on (i) triggering draws; (ii) drawing; and (iii) motion
int next_motion_time = object.motion_time - first_pixel_cycle + 4; int next_motion_time = object.motion_time - first_pixel_cycle + 4;
while(start < end) while(start < end) {
{
int next_event_time = end; int next_event_time = end;
// is the next event a movement tick? // is the next event a movement tick?
if(object.is_moving && next_motion_time < next_event_time) if(object.is_moving && next_motion_time < next_event_time) {
{
next_event_time = next_motion_time; next_event_time = next_motion_time;
} }
// is the next event a graphics trigger? // is the next event a graphics trigger?
int next_copy = 160; int next_copy = 160;
int next_copy_id = 0; int next_copy_id = 0;
if(object.copy_flags) if(object.copy_flags) {
{ if(object.position < 16 && object.copy_flags&1) {
if(object.position < 16 && object.copy_flags&1)
{
next_copy = 16; next_copy = 16;
next_copy_id = 1; next_copy_id = 1;
} else if(object.position < 32 && object.copy_flags&2) } else if(object.position < 32 && object.copy_flags&2) {
{
next_copy = 32; next_copy = 32;
next_copy_id = 2; next_copy_id = 2;
} else if(object.position < 64 && object.copy_flags&4) } else if(object.position < 64 && object.copy_flags&4) {
{
next_copy = 64; next_copy = 64;
next_copy_id = 3; next_copy_id = 3;
} }
@ -731,20 +640,14 @@ template<class T> void TIA::draw_object_visible(T &object, const uint8_t collisi
// enqueue a future intention to draw pixels if spitting them out now would violate accuracy; // enqueue a future intention to draw pixels if spitting them out now would violate accuracy;
// otherwise draw them now // otherwise draw them now
if(object.enqueues && next_event_time > time_now) if(object.enqueues && next_event_time > time_now) {
{ if(start < time_now) {
if(start < time_now)
{
object.output_pixels(&collision_buffer_[start], time_now - start, collision_identity, start + first_pixel_cycle - 4); object.output_pixels(&collision_buffer_[start], time_now - start, collision_identity, start + first_pixel_cycle - 4);
object.enqueue_pixels(time_now, next_event_time, time_now + first_pixel_cycle - 4); object.enqueue_pixels(time_now, next_event_time, time_now + first_pixel_cycle - 4);
} } else {
else
{
object.enqueue_pixels(start, next_event_time, start + first_pixel_cycle - 4); object.enqueue_pixels(start, next_event_time, start + first_pixel_cycle - 4);
} }
} } else {
else
{
object.output_pixels(&collision_buffer_[start], length, collision_identity, start + first_pixel_cycle - 4); object.output_pixels(&collision_buffer_[start], length, collision_identity, start + first_pixel_cycle - 4);
} }
@ -752,15 +655,11 @@ template<class T> void TIA::draw_object_visible(T &object, const uint8_t collisi
object.position = (object.position + length) % 160; object.position = (object.position + length) % 160;
start = next_event_time; start = next_event_time;
// if the event is a motion tick, apply // if the event is a motion tick, apply; if it's a draw trigger, trigger a draw
if(object.is_moving && start == next_motion_time) if(object.is_moving && start == next_motion_time) {
{
perform_motion_step(object); perform_motion_step(object);
next_motion_time += 4; next_motion_time += 4;
} } else if(start == next_copy_time) {
// if it's a draw trigger, trigger a draw
else if(start == next_copy_time)
{
object.reset_pixels(next_copy_id); object.reset_pixels(next_copy_id);
} }
} }
@ -768,14 +667,10 @@ template<class T> void TIA::draw_object_visible(T &object, const uint8_t collisi
#pragma mark - Missile drawing #pragma mark - Missile drawing
void TIA::draw_missile(Missile &missile, Player &player, const uint8_t collision_identity, int start, int end) void TIA::draw_missile(Missile &missile, Player &player, const uint8_t collision_identity, int start, int end) {
{ if(!missile.locked_to_player || player.latched_pixel4_time < 0) {
if(!missile.locked_to_player || player.latched_pixel4_time < 0)
{
draw_object<Missile>(missile, collision_identity, start, end); draw_object<Missile>(missile, collision_identity, start, end);
} } else {
else
{
draw_object<Missile>(missile, collision_identity, start, player.latched_pixel4_time); draw_object<Missile>(missile, collision_identity, start, player.latched_pixel4_time);
missile.position = 0; missile.position = 0;
draw_object<Missile>(missile, collision_identity, player.latched_pixel4_time, end); draw_object<Missile>(missile, collision_identity, player.latched_pixel4_time, end);

View File

@ -162,52 +162,42 @@ class TIA {
int latched_pixel4_time; 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) {
{
int old_pixel_counter = pixel_counter; int old_pixel_counter = pixel_counter;
pixel_position = std::min(32, pixel_position + count * adder); pixel_position = std::min(32, pixel_position + count * adder);
pixel_counter += count; pixel_counter += count;
if(!copy_index_ && old_pixel_counter < 4 && pixel_counter >= 4) if(!copy_index_ && old_pixel_counter < 4 && pixel_counter >= 4) {
{
latched_pixel4_time = from_horizontal_counter + 4 - old_pixel_counter; latched_pixel4_time = from_horizontal_counter + 4 - old_pixel_counter;
} }
} }
inline void reset_pixels(int copy) inline void reset_pixels(int copy) {
{
pixel_position = pixel_counter = 0; pixel_position = pixel_counter = 0;
copy_index_ = copy; copy_index_ = copy;
} }
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) {
{
output_pixels(target, count, collision_identity, pixel_position, adder, reverse_mask); output_pixels(target, count, collision_identity, pixel_position, adder, reverse_mask);
skip_pixels(count, from_horizontal_counter); skip_pixels(count, from_horizontal_counter);
} }
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) {
{ while(queue_read_pointer_ != queue_write_pointer_) {
while(queue_read_pointer_ != queue_write_pointer_)
{
uint8_t *const start_ptr = &target[queue_[queue_read_pointer_].start]; uint8_t *const start_ptr = &target[queue_[queue_read_pointer_].start];
if(queue_[queue_read_pointer_].end > time_now) if(queue_[queue_read_pointer_].end > time_now) {
{
const int length = time_now - queue_[queue_read_pointer_].start; const int length = time_now - queue_[queue_read_pointer_].start;
output_pixels(start_ptr, length, collision_identity, queue_[queue_read_pointer_].pixel_position, queue_[queue_read_pointer_].adder, queue_[queue_read_pointer_].reverse_mask); output_pixels(start_ptr, length, collision_identity, queue_[queue_read_pointer_].pixel_position, queue_[queue_read_pointer_].adder, queue_[queue_read_pointer_].reverse_mask);
queue_[queue_read_pointer_].pixel_position += length * queue_[queue_read_pointer_].adder; queue_[queue_read_pointer_].pixel_position += length * queue_[queue_read_pointer_].adder;
queue_[queue_read_pointer_].start = time_now; queue_[queue_read_pointer_].start = time_now;
return; return;
} } else {
else
{
output_pixels(start_ptr, queue_[queue_read_pointer_].end - queue_[queue_read_pointer_].start, collision_identity, queue_[queue_read_pointer_].pixel_position, queue_[queue_read_pointer_].adder, queue_[queue_read_pointer_].reverse_mask); output_pixels(start_ptr, queue_[queue_read_pointer_].end - queue_[queue_read_pointer_].start, collision_identity, queue_[queue_read_pointer_].pixel_position, queue_[queue_read_pointer_].adder, queue_[queue_read_pointer_].reverse_mask);
} }
queue_read_pointer_ = (queue_read_pointer_ + 1)&3; queue_read_pointer_ = (queue_read_pointer_ + 1)&3;
} }
} }
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) {
{
queue_[queue_write_pointer_].start = start; queue_[queue_write_pointer_].start = start;
queue_[queue_write_pointer_].end = end; queue_[queue_write_pointer_].end = end;
queue_[queue_write_pointer_].pixel_position = pixel_position; queue_[queue_write_pointer_].pixel_position = pixel_position;
@ -219,8 +209,7 @@ class TIA {
private: private:
int copy_index_; int copy_index_;
struct QueuedPixels struct QueuedPixels {
{
int start, end; int start, end;
int pixel_position; int pixel_position;
int adder; int adder;
@ -228,12 +217,10 @@ class TIA {
} queue_[4]; } queue_[4];
int queue_read_pointer_, queue_write_pointer_; int queue_read_pointer_, queue_write_pointer_;
inline void output_pixels(uint8_t *const target, const int count, const uint8_t collision_identity, int pixel_position, int adder, int reverse_mask) inline void output_pixels(uint8_t *const target, const int count, const uint8_t collision_identity, int pixel_position, int adder, int reverse_mask) {
{
if(pixel_position == 32 || !graphic[graphic_index]) return; if(pixel_position == 32 || !graphic[graphic_index]) return;
int output_cursor = 0; int output_cursor = 0;
while(pixel_position < 32 && output_cursor < count) while(pixel_position < 32 && output_cursor < count) {
{
int shift = (pixel_position >> 2) ^ reverse_mask; int shift = (pixel_position >> 2) ^ reverse_mask;
target[output_cursor] |= ((graphic[graphic_index] >> shift)&1) * collision_identity; target[output_cursor] |= ((graphic[graphic_index] >> shift)&1) * collision_identity;
output_cursor++; output_cursor++;
@ -249,18 +236,15 @@ class TIA {
int size; int size;
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) {
{
pixel_position = std::max(0, pixel_position - count); pixel_position = std::max(0, pixel_position - count);
} }
inline void reset_pixels(int copy) inline void reset_pixels(int copy) {
{
pixel_position = size; pixel_position = size;
} }
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) {
{
int output_cursor = 0; int output_cursor = 0;
while(pixel_position && output_cursor < count) while(pixel_position && output_cursor < count)
{ {
@ -283,15 +267,11 @@ class TIA {
bool locked_to_player; bool locked_to_player;
int copy_flags; int copy_flags;
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;
if(enabled && !locked_to_player) if(enabled && !locked_to_player) {
{
HorizontalRun::output_pixels(target, count, collision_identity, from_horizontal_counter); HorizontalRun::output_pixels(target, count, collision_identity, from_horizontal_counter);
} } else {
else
{
skip_pixels(count, from_horizontal_counter); skip_pixels(count, from_horizontal_counter);
} }
} }
@ -305,15 +285,11 @@ class TIA {
int enabled_index; int enabled_index;
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) {
{
if(!pixel_position) return; if(!pixel_position) return;
if(enabled[enabled_index]) if(enabled[enabled_index]) {
{
HorizontalRun::output_pixels(target, count, collision_identity, from_horizontal_counter); HorizontalRun::output_pixels(target, count, collision_identity, from_horizontal_counter);
} } else {
else
{
skip_pixels(count, from_horizontal_counter); skip_pixels(count, from_horizontal_counter);
} }
} }