mirror of
https://github.com/dingusdev/dingusppc.git
synced 2026-12-01 06:23:18 -10:00
Compare commits
1
Commits
master
...
kbd-rewrite
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
ee838f0519 |
No files matched your search
@@ -67,7 +67,8 @@ protected:
|
||||
virtual void set_register_3() {}
|
||||
|
||||
uint8_t exc_event_flag = 0;
|
||||
uint8_t srq_flag = 0;
|
||||
uint8_t srq_flag = 0;
|
||||
uint8_t led_state = 0;
|
||||
uint8_t my_addr = 0;
|
||||
uint8_t dev_handler_id = 0;
|
||||
bool got_collision = false;
|
||||
|
||||
@@ -35,13 +35,18 @@ AdbKeyboard::AdbKeyboard(std::string name) : AdbDevice(name) {
|
||||
|
||||
void AdbKeyboard::event_handler(const KeyboardEvent& event) {
|
||||
this->pending_events.push_back(std::make_unique<KeyboardEvent>(event));
|
||||
|
||||
if (this->pending_events.size() == 1) {
|
||||
this->srq_flag = 1;
|
||||
}
|
||||
}
|
||||
|
||||
void AdbKeyboard::reset() {
|
||||
this->my_addr = ADB_ADDR_KBD;
|
||||
this->dev_handler_id = 2; // Extended ADB keyboard
|
||||
this->exc_event_flag = 1;
|
||||
this->srq_flag = 1; // enable service requests
|
||||
this->srq_flag = 0; // don't process keyboard service requests yet
|
||||
this->led_state = 0; // LEDs off
|
||||
this->pending_events.clear();
|
||||
}
|
||||
|
||||
@@ -53,6 +58,11 @@ bool AdbKeyboard::get_register_0() {
|
||||
out_buf[0] = this->consume_pending_event();
|
||||
out_buf[1] = this->consume_pending_event();
|
||||
this->host_obj->set_output_count(2);
|
||||
|
||||
if (this->pending_events.empty()) {
|
||||
this->srq_flag = 0;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -68,14 +78,7 @@ uint8_t AdbKeyboard::consume_pending_event() {
|
||||
std::unique_ptr<KeyboardEvent> event = std::move(this->pending_events.front());
|
||||
this->pending_events.pop_front();
|
||||
|
||||
uint8_t key_state = 0;
|
||||
if (event->flags & KEYBOARD_EVENT_DOWN) {
|
||||
key_state = 0;
|
||||
} else if (event->flags & KEYBOARD_EVENT_UP) {
|
||||
key_state = 1;
|
||||
} else {
|
||||
LOG_F(WARNING, "%s: unknown keyboard event flags %x", this->name.c_str(), event->flags);
|
||||
}
|
||||
uint8_t key_state = (event->flags & KEYBOARD_EVENT_UP) ? 1 : 0;
|
||||
|
||||
if (this->dev_handler_id != 3) {
|
||||
switch (event->key) {
|
||||
@@ -88,7 +91,31 @@ uint8_t AdbKeyboard::consume_pending_event() {
|
||||
return (key_state << 7) | (event->key & 0x7F);
|
||||
}
|
||||
|
||||
bool AdbKeyboard::get_register_2() {
|
||||
uint8_t* out_buf = this->host_obj->get_output_buf();
|
||||
out_buf[0] = 0;
|
||||
out_buf[1] = this->led_state & 0x07;
|
||||
this->host_obj->set_output_count(2);
|
||||
return true;
|
||||
}
|
||||
|
||||
void AdbKeyboard::set_register_2() {
|
||||
if (this->host_obj->get_input_count() < 2)
|
||||
return;
|
||||
|
||||
const uint8_t* in_data = this->host_obj->get_input_buf();
|
||||
|
||||
this->led_state = in_data[1] & 0x07;
|
||||
}
|
||||
|
||||
bool AdbKeyboard::get_register_3() {
|
||||
uint8_t* out_buf = this->host_obj->get_output_buf();
|
||||
|
||||
out_buf[0] = (this->my_addr << 4) | (1 << 1) | 1; // Address + SRQ Enable + Exc Event
|
||||
out_buf[1] = this->dev_handler_id;
|
||||
|
||||
this->host_obj->set_output_count(2);
|
||||
return true;
|
||||
}
|
||||
|
||||
void AdbKeyboard::set_register_3() {
|
||||
|
||||
@@ -46,6 +46,8 @@ public:
|
||||
void event_handler(const KeyboardEvent& event);
|
||||
|
||||
bool get_register_0() override;
|
||||
bool get_register_2() override;
|
||||
bool get_register_3() override;
|
||||
void set_register_2() override;
|
||||
void set_register_3() override;
|
||||
|
||||
|
||||
Reference in new issue
Block a user