1
0
mirror of https://github.com/TomHarte/CLK.git synced 2025-02-21 05:29:13 +00:00

Clarify and slightly improve state machine.

No more using the visible flag to permit a DMA control fetch.
This commit is contained in:
Thomas Harte 2022-07-19 15:39:57 -04:00
parent 0c6d7e07ee
commit 830704b4a9
2 changed files with 12 additions and 12 deletions

View File

@ -611,7 +611,7 @@ template <int cycle, bool stop_if_cpu> bool Chipset::perform_cycle() {
constexpr auto sprite_id = (cycle - 0x16) >> 2; constexpr auto sprite_id = (cycle - 0x16) >> 2;
static_assert(sprite_id >= 0 && sprite_id < std::tuple_size<decltype(sprites_)>::value); static_assert(sprite_id >= 0 && sprite_id < std::tuple_size<decltype(sprites_)>::value);
if(sprites_[sprite_id].advance_dma(!(cycle&2))) { if(sprites_[sprite_id].advance_dma((~cycle&2) >> 1)) {
return false; return false;
} }
} }

View File

@ -59,35 +59,35 @@ void Sprite::advance_line(int y, bool is_end_of_blank) {
} }
if(is_end_of_blank || y == v_stop_) { if(is_end_of_blank || y == v_stop_) {
dma_state_ = DMAState::FetchControl; dma_state_ = DMAState::FetchControl;
visible = true;
} }
} }
bool Sprite::advance_dma(int offset) { bool Sprite::advance_dma(int offset) {
if(!visible) return false; assert(offset == 0 || offset == 1);
// Fetch another word. // Determine which word would be fetched, if DMA occurs.
// A bit of a cheat.
const uint16_t next_word = ram_[pointer_[0] & ram_mask_]; const uint16_t next_word = ram_[pointer_[0] & ram_mask_];
++pointer_[0];
// Put the fetched word somewhere appropriate and update the DMA state. // Put the fetched word somewhere appropriate and update the DMA state.
switch(dma_state_) { switch(dma_state_) {
// i.e. stopped.
default: return false;
case DMAState::FetchControl: case DMAState::FetchControl:
if(offset) { if(offset) {
set_stop_and_control(next_word); set_stop_and_control(next_word);
} else { } else {
set_start_position(next_word); set_start_position(next_word);
} }
return true; break;
case DMAState::FetchImage: case DMAState::FetchImage:
set_image_data(1 - bool(offset), next_word); if(!visible) return false;
return true; set_image_data(1 - offset, next_word);
break;
} }
return false;
// Acknowledge the fetch.
++pointer_[0];
return true;
} }
template <int sprite> void TwoSpriteShifter::load( template <int sprite> void TwoSpriteShifter::load(