mirror of
https://github.com/TomHarte/CLK.git
synced 2024-07-27 02:29:12 +00:00
Started trying to be a bit more explicit about usage, and to divide up drawing responsibility.
This commit is contained in:
parent
23f3ccd77a
commit
6bcf95042c
@ -126,7 +126,7 @@ 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;
|
return 4 + (cycles_per_line - (horizontal_counter_ + (int)from_offset) % cycles_per_line);
|
||||||
}
|
}
|
||||||
|
|
||||||
void TIA::set_background_colour(uint8_t colour)
|
void TIA::set_background_colour(uint8_t colour)
|
||||||
@ -156,6 +156,8 @@ 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;
|
||||||
|
playfield_is_above_players_ = !!(value & 4);
|
||||||
|
playfield_is_in_score_mode_ = !playfield_is_above_players_ && (value & 2);
|
||||||
}
|
}
|
||||||
|
|
||||||
void TIA::set_playfield_ball_colour(uint8_t colour)
|
void TIA::set_playfield_ball_colour(uint8_t colour)
|
||||||
@ -338,12 +340,8 @@ void TIA::output_for_cycles(int number_of_cycles)
|
|||||||
}
|
}
|
||||||
if(pixel_target_)
|
if(pixel_target_)
|
||||||
{
|
{
|
||||||
while(output_cursor < horizontal_counter_)
|
draw_background(pixel_target_, output_cursor, horizontal_counter_);
|
||||||
{
|
output_cursor = horizontal_counter_;
|
||||||
int offset = (output_cursor - 68) >> 2;
|
|
||||||
pixel_target_[output_cursor - pixel_target_origin_] = ((background_[(offset/20)&background_half_mask_] >> (offset%20))&1) ? playfield_ball_colour_ : background_colour_;
|
|
||||||
output_cursor++;
|
|
||||||
}
|
|
||||||
} else output_cursor = horizontal_counter_;
|
} else output_cursor = horizontal_counter_;
|
||||||
if(horizontal_counter_ == cycles_per_line)
|
if(horizontal_counter_ == cycles_per_line)
|
||||||
{
|
{
|
||||||
@ -377,3 +375,21 @@ void TIA::output_line()
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#pragma mark - Background and playfield
|
||||||
|
|
||||||
|
void TIA::draw_background(uint8_t *target, int start, int length) const
|
||||||
|
{
|
||||||
|
if(!target) return;
|
||||||
|
int position = start;
|
||||||
|
while(length--)
|
||||||
|
{
|
||||||
|
int offset = (position - 68) >> 2;
|
||||||
|
target[position - pixel_target_origin_] = ((background_[(offset/20)&background_half_mask_] >> (offset%20))&1) ? playfield_ball_colour_ : background_colour_;
|
||||||
|
position++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void TIA::draw_playfield(uint8_t *target, int start, int length) const
|
||||||
|
{
|
||||||
|
}
|
||||||
|
@ -23,6 +23,10 @@ class TIA {
|
|||||||
NTSC, PAL
|
NTSC, PAL
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/*!
|
||||||
|
Advances the TIA by @c number_of_cycles cycles. Any queued setters take effect in the
|
||||||
|
first cycle performed.
|
||||||
|
*/
|
||||||
void run_for_cycles(int number_of_cycles);
|
void run_for_cycles(int number_of_cycles);
|
||||||
void set_output_mode(OutputMode output_mode);
|
void set_output_mode(OutputMode output_mode);
|
||||||
|
|
||||||
@ -71,9 +75,8 @@ class TIA {
|
|||||||
inline void output_for_cycles(int number_of_cycles);
|
inline void output_for_cycles(int number_of_cycles);
|
||||||
inline void output_line();
|
inline void output_line();
|
||||||
|
|
||||||
inline void draw_background(uint8_t *target, int start, int length);
|
inline void draw_background(uint8_t *target, int start, int length) const;
|
||||||
inline void draw_playfield(uint8_t *target, int start, int length);
|
inline void draw_playfield(uint8_t *target, int start, int length) const;
|
||||||
inline void draw_background_and_playfield(uint8_t *target, int start, int length);
|
|
||||||
|
|
||||||
// the master counter; counts from 0 to 228 with all visible pixels being in the final 160
|
// the master counter; counts from 0 to 228 with all visible pixels being in the final 160
|
||||||
int horizontal_counter_;
|
int horizontal_counter_;
|
||||||
@ -81,14 +84,25 @@ class TIA {
|
|||||||
// contains flags to indicate whether sync or blank are currently active
|
// contains flags to indicate whether sync or blank are currently active
|
||||||
int output_mode_;
|
int output_mode_;
|
||||||
|
|
||||||
// keeps track of the target pixel buffer for this line and when it was acquired
|
// keeps track of the target pixel buffer for this line and when it was acquired, and a corresponding collision buffer
|
||||||
uint8_t *pixel_target_;
|
uint8_t *pixel_target_;
|
||||||
int pixel_target_origin_;
|
int pixel_target_origin_;
|
||||||
|
uint8_t collision_buffer_[160];
|
||||||
|
enum class CollisionType : uint8_t {
|
||||||
|
Playfield,
|
||||||
|
Sprite1,
|
||||||
|
Sprite2,
|
||||||
|
Missile1,
|
||||||
|
Missile2,
|
||||||
|
Ball
|
||||||
|
};
|
||||||
|
|
||||||
// playfield state
|
// playfield state
|
||||||
uint8_t playfield_ball_colour_;
|
uint8_t playfield_ball_colour_;
|
||||||
uint8_t background_colour_;
|
uint8_t background_colour_;
|
||||||
int background_half_mask_;
|
int background_half_mask_;
|
||||||
|
bool playfield_is_in_score_mode_;
|
||||||
|
bool playfield_is_above_players_;
|
||||||
uint32_t background_[2]; // contains two 20-bit bitfields representing the background state;
|
uint32_t background_[2]; // contains two 20-bit bitfields representing the background state;
|
||||||
// at index 0 is the left-hand side of the playfield with bit 0 being
|
// at index 0 is the left-hand side of the playfield with bit 0 being
|
||||||
// the first bit to display, bit 1 the second, etc. Index 1 contains
|
// the first bit to display, bit 1 the second, etc. Index 1 contains
|
||||||
@ -96,6 +110,7 @@ class TIA {
|
|||||||
// mirroring mode, background_[0] will be output on the left and
|
// mirroring mode, background_[0] will be output on the left and
|
||||||
// background_[1] on the right; otherwise background_[0] will be
|
// background_[1] on the right; otherwise background_[0] will be
|
||||||
// output twice.
|
// output twice.
|
||||||
|
int latched_playfield_value_;
|
||||||
|
|
||||||
// player state
|
// player state
|
||||||
struct Player {
|
struct Player {
|
||||||
|
Loading…
Reference in New Issue
Block a user