1
0
mirror of https://github.com/TomHarte/CLK.git synced 2025-08-08 14:25:05 +00:00

Caps mouse speed.

Also takes another guess at CIA interrupt bits. To no avail.
This commit is contained in:
Thomas Harte
2021-10-27 18:38:02 -07:00
parent 7e31658932
commit da1a69be27
2 changed files with 62 additions and 30 deletions

View File

@@ -96,7 +96,7 @@ Chipset::Changes Chipset::run_until_cpu_slot() {
void Chipset::set_cia_interrupts(bool cia_a_interrupt, bool cia_b_interrupt) { void Chipset::set_cia_interrupts(bool cia_a_interrupt, bool cia_b_interrupt) {
// TODO: are these really latched, or are they active live? // TODO: are these really latched, or are they active live?
interrupt_requests_ &= ~InterruptMask<InterruptFlag::IOPortsAndTimers, InterruptFlag::External>::value; // interrupt_requests_ &= ~InterruptMask<InterruptFlag::IOPortsAndTimers, InterruptFlag::External>::value;
interrupt_requests_ |= interrupt_requests_ |=
(cia_a_interrupt ? InterruptMask<InterruptFlag::IOPortsAndTimers>::value : 0) | (cia_a_interrupt ? InterruptMask<InterruptFlag::IOPortsAndTimers>::value : 0) |
(cia_b_interrupt ? InterruptMask<InterruptFlag::External>::value : 0); (cia_b_interrupt ? InterruptMask<InterruptFlag::External>::value : 0);
@@ -601,12 +601,10 @@ void Chipset::perform(const CPU::MC68000::Microcycle &cycle) {
// Raster position. // Raster position.
case Read(0x004): { case Read(0x004): {
const uint16_t position = uint16_t(y_ >> 8); const uint16_t position = uint16_t(y_ >> 8);
// LOG("Read vertical position high " << PADHEX(4) << position);
cycle.set_value16(position); cycle.set_value16(position);
} break; } break;
case Read(0x006): { case Read(0x006): {
const uint16_t position = uint16_t(((line_cycle_ << 6) & 0xff00) | (y_ & 0x00ff)); const uint16_t position = uint16_t(((line_cycle_ << 6) & 0xff00) | (y_ & 0x00ff));
// LOG("Read position low " << PADHEX(4) << position);
cycle.set_value16(position); cycle.set_value16(position);
} break; } break;
@@ -619,12 +617,7 @@ void Chipset::perform(const CPU::MC68000::Microcycle &cycle) {
// Joystick/mouse input. // Joystick/mouse input.
case Read(0x00a): case Read(0x00a):
cycle.set_value16( cycle.set_value16(mouse_.get_position());
uint16_t(
(mouse_.position[1] << 8) |
mouse_.position[0]
)
);
break; break;
case Read(0x00c): case Read(0x00c):
cycle.set_value16(0x0202); cycle.set_value16(0x0202);
@@ -1175,7 +1168,7 @@ uint8_t Chipset::CIAAHandler::get_port_input(MOS::MOS6526::Port port) {
} else { } else {
return return
controller_.get_rdy_trk0_wpro_chng() & controller_.get_rdy_trk0_wpro_chng() &
mouse_.button_state; mouse_.get_cia_button();
} }
return 0xff; return 0xff;
} }
@@ -1416,27 +1409,60 @@ int Chipset::Mouse::get_number_of_buttons() {
} }
void Chipset::Mouse::set_button_pressed(int button, bool is_set) { void Chipset::Mouse::set_button_pressed(int button, bool is_set) {
// TODO: this is nothing like correct; the second and optional switch(button) {
// third buttons aren't exposed via CIA A like the first is, case 0:
// so there's not really a single location of buttons. cia_state_ = (cia_state_ &~ 0x40) | (is_set ? 0 : 0x40);
// break;
// Leaving as is for now, as this gives me a working left default:
// button in port 0 and that'll do. break;
const auto mask = uint8_t(0x40 << button); }
button_state = }
(button_state & ~mask) |
(is_set ? 0 : mask); uint8_t Chipset::Mouse::get_cia_button() {
return cia_state_;
} }
void Chipset::Mouse::reset_all_buttons() { void Chipset::Mouse::reset_all_buttons() {
button_state = 0xff; cia_state_ = 0xff;
} }
void Chipset::Mouse::move(int x, int y) { void Chipset::Mouse::move(int x, int y) {
position[0] += x; position_[0] += x;
position[1] += y; position_[1] += y;
} }
Inputs::Mouse &Chipset::get_mouse() { Inputs::Mouse &Chipset::get_mouse() {
return mouse_; return mouse_;
} }
uint16_t Chipset::Mouse::get_position() {
// The Amiga hardware retains only eight bits of position
// for the mouse; its software polls frequently and maps
// changes into a larger space.
//
// On modern computers with 5k+ displays and trackpads, it
// proved empirically possible to overflow the hardware
// counters more quickly than software would poll.
//
// Therefore the approach taken for mapping mouse motion
// into the Amiga is to do it in steps of no greater than
// [-128, +127], as per the below.
const int pending[] = {
position_[0], position_[1]
};
const int8_t change[] = {
int8_t(std::clamp(pending[0], -128, 127)),
int8_t(std::clamp(pending[1], -128, 127))
};
position_[0] -= change[0];
position_[1] -= change[1];
declared_position_[0] += change[0];
declared_position_[1] += change[1];
return uint16_t(
(declared_position_[1] << 8) |
declared_position_[0]
);
}

View File

@@ -309,14 +309,20 @@ class Chipset: private ClockingHint::Observer {
// MARK: - Mouse. // MARK: - Mouse.
private: private:
struct Mouse: public Inputs::Mouse { class Mouse: public Inputs::Mouse {
int get_number_of_buttons() final; public:
void set_button_pressed(int, bool) final; uint16_t get_position();
void reset_all_buttons() final; uint8_t get_cia_button();
void move(int, int) final;
uint8_t position[2]{}; private:
uint8_t button_state = 0xff; int get_number_of_buttons() final;
void set_button_pressed(int, bool) final;
void reset_all_buttons() final;
void move(int, int) final;
uint8_t declared_position_[2]{};
uint8_t cia_state_ = 0xff;
std::array<std::atomic<int>, 2> position_{};
} mouse_; } mouse_;
public: public: