ADB Refactoring, Pt. 2

This commit is contained in:
dingusdev 2020-04-23 18:08:27 -07:00
parent d0f03f722e
commit c0d0187190
6 changed files with 424 additions and 590 deletions

View File

@ -25,12 +25,9 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#include <array>
#include <cinttypes>
#include <cstring>
#include "adb.h"
#include "adbkeybd.h"
#include "adbmouse.h"
#include "devices/adb.h"
#include <thirdparty/SDL2/include/SDL.h>
#include <thirdparty/SDL2/include/SDL_events.h>
#include <thirdparty/SDL2/include/SDL_keycode.h>
@ -41,55 +38,411 @@ using namespace std;
ADB_Bus::ADB_Bus() {
//set data streams as clear
input_stream_len = 0;
output_stream_len = 0;
this->adb_mouse_register0 = 0x8080;
this->keyboard = new ADB_Keybd();
this->mouse = new ADB_Mouse();
input_stream_len = 0;
output_stream_len = 2;
adb_keybd_register3 = 0x6201;
adb_mouse_register3 = 0x6302;
keyboard_access_no = adb_encoded;
mouse_access_no = adb_relative;
}
ADB_Bus::~ADB_Bus() {
}
void ADB_Bus::add_adb_device(int type) {
}
bool ADB_Bus::adb_verify_listen(int device, int reg) {
switch (device) {
case 0:
if ((reg == 0) | (reg == 2)) {
output_stream_len = 2;
for (int i = 0; output_stream_len < 2; i++) {
output_data_stream[i] = this->keyboard->copy_stream_byte(i);
}
return true;
}
else {
return false;
}
case 1:
if (reg == 0) {
output_stream_len = 2;
for (int i = 0; output_stream_len < 2; i++) {
output_data_stream[i] = this->mouse->copy_stream_byte(i);
}
return true;
}
else {
return false;
}
default:
return false;
}
if (device == keyboard_access_no) {
if (adb_keybd_listen(reg)) {
return true;
}
else {
return false;
}
}
else if (device == mouse_access_no) {
if (adb_mouse_listen(reg)) {
return true;
}
else {
return false;
}
}
return false;
}
bool ADB_Bus::adb_verify_talk(int device, int reg) {
//temp code
return false;
//temp code
return false;
}
bool ADB_Bus::adb_keybd_listen(int reg) {
if (reg == 3) {
output_data_stream[0] = (adb_keybd_register3 >> 8);
output_data_stream[1] = (adb_keybd_register3 & 0xff);
return true;
}
while (SDL_PollEvent(&adb_keybd_evt)) {
//Poll our SDL key event for any keystrokes.
switch (adb_keybd_evt.type) {
case SDL_KEYDOWN:
switch (adb_keybd_evt.key.keysym.sym) {
case SDLK_a:
ask_key_pressed = 0x00;
break;
case SDLK_s:
ask_key_pressed = 0x01;
break;
case SDLK_d:
ask_key_pressed = 0x02;
break;
case SDLK_f:
ask_key_pressed = 0x03;
break;
case SDLK_h:
ask_key_pressed = 0x04;
break;
case SDLK_g:
ask_key_pressed = 0x05;
break;
case SDLK_z:
ask_key_pressed = 0x06;
break;
case SDLK_x:
ask_key_pressed = 0x07;
break;
case SDLK_c:
ask_key_pressed = 0x08;
break;
case SDLK_v:
ask_key_pressed = 0x09;
break;
case SDLK_b:
ask_key_pressed = 0x0B;
break;
case SDLK_q:
ask_key_pressed = 0x0C;
break;
case SDLK_w:
ask_key_pressed = 0x0D;
break;
case SDLK_e:
ask_key_pressed = 0x0E;
break;
case SDLK_r:
ask_key_pressed = 0x0F;
break;
case SDLK_y:
ask_key_pressed = 0x10;
break;
case SDLK_t:
ask_key_pressed = 0x11;
break;
case SDLK_1:
ask_key_pressed = 0x12;
break;
case SDLK_2:
ask_key_pressed = 0x13;
break;
case SDLK_3:
ask_key_pressed = 0x14;
break;
case SDLK_4:
ask_key_pressed = 0x15;
break;
case SDLK_6:
ask_key_pressed = 0x16;
break;
case SDLK_5:
ask_key_pressed = 0x17;
break;
case SDLK_EQUALS:
ask_key_pressed = 0x18;
break;
case SDLK_9:
ask_key_pressed = 0x19;
break;
case SDLK_7:
ask_key_pressed = 0x1A;
break;
case SDLK_MINUS:
ask_key_pressed = 0x1B;
break;
case SDLK_8:
ask_key_pressed = 0x1C;
break;
case SDLK_0:
ask_key_pressed = 0x1D;
break;
case SDLK_RIGHTBRACKET:
ask_key_pressed = 0x1E;
break;
case SDLK_o:
ask_key_pressed = 0x1F;
break;
case SDLK_u:
ask_key_pressed = 0x20;
break;
case SDLK_LEFTBRACKET:
ask_key_pressed = 0x21;
break;
case SDLK_i:
ask_key_pressed = 0x22;
break;
case SDLK_p:
ask_key_pressed = 0x23;
break;
case SDLK_RETURN:
ask_key_pressed = 0x24;
break;
case SDLK_l:
ask_key_pressed = 0x25;
break;
case SDLK_j:
ask_key_pressed = 0x26;
break;
case SDLK_QUOTE:
ask_key_pressed = 0x27;
break;
case SDLK_k:
ask_key_pressed = 0x28;
break;
case SDLK_SEMICOLON:
ask_key_pressed = 0x29;
break;
case SDLK_BACKSLASH:
ask_key_pressed = 0x2A;
break;
case SDLK_COMMA:
ask_key_pressed = 0x2B;
break;
case SDLK_SLASH:
ask_key_pressed = 0x2C;
break;
case SDLK_n:
ask_key_pressed = 0x2D;
break;
case SDLK_m:
ask_key_pressed = 0x2E;
break;
case SDLK_PERIOD:
ask_key_pressed = 0x2F;
break;
case SDLK_BACKQUOTE:
ask_key_pressed = 0x32;
break;
case SDLK_ESCAPE:
ask_key_pressed = 0x35;
break;
case SDLK_LEFT:
ask_key_pressed = 0x3B;
break;
case SDLK_RIGHT:
ask_key_pressed = 0x3C;
break;
case SDLK_DOWN:
ask_key_pressed = 0x3D;
break;
case SDLK_UP:
ask_key_pressed = 0x3E;
break;
case SDLK_KP_PERIOD:
ask_key_pressed = 0x41;
break;
case SDLK_KP_MULTIPLY:
ask_key_pressed = 0x43;
break;
case SDLK_KP_PLUS:
ask_key_pressed = 0x45;
break;
case SDLK_DELETE:
ask_key_pressed = 0x47;
break;
case SDLK_KP_DIVIDE:
ask_key_pressed = 0x4B;
break;
case SDLK_KP_ENTER:
ask_key_pressed = 0x4C;
break;
case SDLK_KP_MINUS:
ask_key_pressed = 0x4E;
break;
case SDLK_KP_0:
ask_key_pressed = 0x52;
break;
case SDLK_KP_1:
ask_key_pressed = 0x53;
break;
case SDLK_KP_2:
ask_key_pressed = 0x54;
break;
case SDLK_KP_3:
ask_key_pressed = 0x55;
break;
case SDLK_KP_4:
ask_key_pressed = 0x56;
break;
case SDLK_KP_5:
ask_key_pressed = 0x57;
break;
case SDLK_KP_6:
ask_key_pressed = 0x58;
break;
case SDLK_KP_7:
ask_key_pressed = 0x59;
break;
case SDLK_KP_8:
ask_key_pressed = 0x5B;
break;
case SDLK_KP_9:
ask_key_pressed = 0x5C;
break;
case SDLK_BACKSPACE:
ask_key_pressed = 0x33;
confirm_ask_reg_2 = true;
mod_key_pressed = 0x40;
case SDLK_CAPSLOCK:
ask_key_pressed = 0x39;
confirm_ask_reg_2 = true;
mod_key_pressed = 0x20;
case SDLK_LCTRL:
case SDLK_RCTRL:
ask_key_pressed = 0x36;
confirm_ask_reg_2 = true;
mod_key_pressed = 0x8;
case SDLK_LSHIFT:
case SDLK_RSHIFT:
ask_key_pressed = 0x38;
confirm_ask_reg_2 = true;
mod_key_pressed = 0x4;
case SDLK_LALT:
case SDLK_RALT:
ask_key_pressed = 0x3A;
confirm_ask_reg_2 = true;
mod_key_pressed = 0x2;
case SDLK_HOME: //Temp key for the Command/Apple key
ask_key_pressed = 0x37;
confirm_ask_reg_2 = true;
mod_key_pressed = 0x1;
default:
break;
}
if (adb_keybd_register0 & 0x8000) {
adb_keybd_register0 &= 0x7FFF;
adb_keybd_register0 &= (ask_key_pressed << 8);
output_data_stream[0] = (adb_keybd_register0 >> 8);
output_data_stream[1] = (adb_keybd_register0 & 0xff);
}
else if (adb_keybd_register0 & 0x80) {
adb_keybd_register0 &= 0xFF7F;
adb_keybd_register0 &= (ask_key_pressed);
output_data_stream[0] = (adb_keybd_register0 >> 8);
output_data_stream[1] = (adb_keybd_register0 & 0xff);
}
//check if mod keys are being pressed
if (confirm_ask_reg_2) {
adb_keybd_register0 |= (mod_key_pressed << 8);
output_data_stream[0] = (adb_keybd_register2 >> 8);
output_data_stream[1] = (adb_keybd_register2 & 0xff);
}
break;
case SDL_KEYUP:
if (!(adb_keybd_register0 & 0x8000)) {
adb_keybd_register0 |= 0x8000;
output_data_stream[0] = (adb_keybd_register0 >> 8);
output_data_stream[1] = (adb_keybd_register0 & 0xff);
}
else if (adb_keybd_register0 & 0x80)
adb_keybd_register0 |= 0x0080;
output_data_stream[0] = (adb_keybd_register0 >> 8);
output_data_stream[1] = (adb_keybd_register0 & 0xff);
if (confirm_ask_reg_2) {
adb_keybd_register2 &= (mod_key_pressed << 8);
output_data_stream[0] = (adb_keybd_register2 >> 8);
output_data_stream[1] = (adb_keybd_register2 & 0xff);
confirm_ask_reg_2 = false;
}
}
}
if ((reg != 1)) {
return true;
}
else {
return false;
}
}
bool ADB_Bus::adb_mouse_listen(int reg) {
if ((reg != 0) | (reg != 3)) {
return false;
}
while (SDL_PollEvent(&adb_mouse_evt)) {
if (adb_mouse_evt.motion.x) {
this->adb_mouse_register0 &= 0x7F;
if (adb_mouse_evt.motion.xrel < 0) {
if (adb_mouse_evt.motion.xrel <= -64) {
this->adb_mouse_register0 |= 0x7F;
}
else if (adb_mouse_evt.motion.xrel >= 63) {
this->adb_mouse_register0 |= 0x3F;
}
else {
this->adb_mouse_register0 |= adb_mouse_evt.motion.xrel;
}
}
}
if (adb_mouse_evt.motion.y) {
this->adb_mouse_register0 &= 0x7F00;
if (adb_mouse_evt.motion.yrel < 0) {
if (adb_mouse_evt.motion.yrel <= -64) {
this->adb_mouse_register0 |= 0x7F00;
}
else if (adb_mouse_evt.motion.yrel >= 63) {
this->adb_mouse_register0 |= 0x3F00;
}
else {
this->adb_mouse_register0 |= (adb_mouse_evt.motion.yrel << 8);
}
}
}
switch (adb_mouse_evt.type) {
case SDL_MOUSEBUTTONDOWN:
this->adb_mouse_register0 &= 0x7FFF;
case SDL_MOUSEBUTTONUP:
this->adb_mouse_register0 |= 0x8000;
}
}
if (reg == 0) {
output_data_stream[0] = (adb_mouse_register0 >> 8);
output_data_stream[1] = (adb_mouse_register0 & 0xff);
}
else if (reg == 3) {
output_data_stream[0] = (adb_mouse_register3 >> 8);
output_data_stream[1] = (adb_mouse_register3 & 0xff);
}
return true;
}
uint8_t ADB_Bus::get_input_byte(int offset) {
return input_data_stream[offset];
}

View File

@ -22,12 +22,16 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
#ifndef ADB_H
#define ADB_H
#include <array>
#include <cinttypes>
#include <thirdparty/SDL2/include/SDL.h>
#include <thirdparty/SDL2/include/SDL_events.h>
#include "adbkeybd.h"
#include "adbmouse.h"
enum adb_default_values {
adb_reserved0, adb_reserved1, adb_encoded, adb_relative,
adb_absolute, adb_reserved5, adb_reserved6, adb_reserved7,
adb_other8, adb_other9, adb_other10, adb_other11,
adb_other12, adb_other13, adb_other14, adb_other15
};
class ADB_Bus
{
@ -35,10 +39,12 @@ public:
ADB_Bus();
~ADB_Bus();
void add_adb_device(int type);
bool adb_verify_listen(int device, int reg);
bool adb_verify_talk(int device, int reg);
bool adb_keybd_listen(int reg);
bool adb_mouse_listen(int reg);
uint8_t get_input_byte(int offset);
uint8_t get_output_byte(int offset);
@ -46,8 +52,27 @@ public:
int get_output_len();
private:
ADB_Keybd* keyboard;
ADB_Mouse* mouse;
int keyboard_access_no;
int mouse_access_no;
//Keyboard Variables
uint16_t adb_keybd_register0;
uint16_t adb_keybd_register2;
uint16_t adb_keybd_register3;
SDL_Event adb_keybd_evt;
uint8_t ask_key_pressed;
uint8_t mod_key_pressed;
bool confirm_ask_reg_2;
//Mouse Variables
SDL_Event adb_mouse_evt;
uint16_t adb_mouse_register0;
uint16_t adb_mouse_register3;
uint8_t input_data_stream[16]; //temp buffer
int input_stream_len;

View File

@ -1,337 +0,0 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-20 divingkatae and maximum
(theweirdo) spatium
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
/** ADB keyboard definitions
Simulates Apple Desktop Bus (ADB) standard keyboard
*/
#include <array>
#include <cinttypes>
#include <cstring>
#include "adbkeybd.h"
#include <thirdparty/SDL2/include/SDL.h>
#include <thirdparty/SDL2/include/SDL_events.h>
#include <thirdparty/SDL2/include/SDL_mouse.h>
#include <thirdparty/SDL2/include/SDL_stdinc.h>
using namespace std;
ADB_Keybd::ADB_Keybd() {
this->ask_register0 = 0xFFFF;
this->ask_register2 = 0xFFFF;
}
ADB_Keybd::~ADB_Keybd() {
}
void ADB_Keybd::input_keybd(int reg) {
while (SDL_PollEvent(&adb_keybd_evt)) {
//Poll our SDL key event for any keystrokes.
switch (adb_keybd_evt.type) {
case SDL_KEYDOWN:
switch (adb_keybd_evt.key.keysym.sym) {
case SDLK_a:
this->ask_key_pressed = 0x00;
break;
case SDLK_s:
this->ask_key_pressed = 0x01;
break;
case SDLK_d:
this->ask_key_pressed = 0x02;
break;
case SDLK_f:
this->ask_key_pressed = 0x03;
break;
case SDLK_h:
this->ask_key_pressed = 0x04;
break;
case SDLK_g:
this->ask_key_pressed = 0x05;
break;
case SDLK_z:
this->ask_key_pressed = 0x06;
break;
case SDLK_x:
this->ask_key_pressed = 0x07;
break;
case SDLK_c:
this->ask_key_pressed = 0x08;
break;
case SDLK_v:
this->ask_key_pressed = 0x09;
break;
case SDLK_b:
this->ask_key_pressed = 0x0B;
break;
case SDLK_q:
this->ask_key_pressed = 0x0C;
break;
case SDLK_w:
this->ask_key_pressed = 0x0D;
break;
case SDLK_e:
this->ask_key_pressed = 0x0E;
break;
case SDLK_r:
this->ask_key_pressed = 0x0F;
break;
case SDLK_y:
this->ask_key_pressed = 0x10;
break;
case SDLK_t:
this->ask_key_pressed = 0x11;
break;
case SDLK_1:
this->ask_key_pressed = 0x12;
break;
case SDLK_2:
this->ask_key_pressed = 0x13;
break;
case SDLK_3:
this->ask_key_pressed = 0x14;
break;
case SDLK_4:
this->ask_key_pressed = 0x15;
break;
case SDLK_6:
this->ask_key_pressed = 0x16;
break;
case SDLK_5:
this->ask_key_pressed = 0x17;
break;
case SDLK_EQUALS:
this->ask_key_pressed = 0x18;
break;
case SDLK_9:
this->ask_key_pressed = 0x19;
break;
case SDLK_7:
this->ask_key_pressed = 0x1A;
break;
case SDLK_MINUS:
this->ask_key_pressed = 0x1B;
break;
case SDLK_8:
this->ask_key_pressed = 0x1C;
break;
case SDLK_0:
this->ask_key_pressed = 0x1D;
break;
case SDLK_RIGHTBRACKET:
this->ask_key_pressed = 0x1E;
break;
case SDLK_o:
this->ask_key_pressed = 0x1F;
break;
case SDLK_u:
this->ask_key_pressed = 0x20;
break;
case SDLK_LEFTBRACKET:
this->ask_key_pressed = 0x21;
break;
case SDLK_i:
this->ask_key_pressed = 0x22;
break;
case SDLK_p:
this->ask_key_pressed = 0x23;
break;
case SDLK_RETURN:
this->ask_key_pressed = 0x24;
break;
case SDLK_l:
this->ask_key_pressed = 0x25;
break;
case SDLK_j:
this->ask_key_pressed = 0x26;
break;
case SDLK_QUOTE:
this->ask_key_pressed = 0x27;
break;
case SDLK_k:
this->ask_key_pressed = 0x28;
break;
case SDLK_SEMICOLON:
this->ask_key_pressed = 0x29;
break;
case SDLK_BACKSLASH:
this->ask_key_pressed = 0x2A;
break;
case SDLK_COMMA:
this->ask_key_pressed = 0x2B;
break;
case SDLK_SLASH:
this->ask_key_pressed = 0x2C;
break;
case SDLK_n:
this->ask_key_pressed = 0x2D;
break;
case SDLK_m:
this->ask_key_pressed = 0x2E;
break;
case SDLK_PERIOD:
this->ask_key_pressed = 0x2F;
break;
case SDLK_BACKQUOTE:
this->ask_key_pressed = 0x32;
break;
case SDLK_ESCAPE:
this->ask_key_pressed = 0x35;
break;
case SDLK_LEFT:
this->ask_key_pressed = 0x3B;
break;
case SDLK_RIGHT:
this->ask_key_pressed = 0x3C;
break;
case SDLK_DOWN:
this->ask_key_pressed = 0x3D;
break;
case SDLK_UP:
this->ask_key_pressed = 0x3E;
break;
case SDLK_KP_PERIOD:
this->ask_key_pressed = 0x41;
break;
case SDLK_KP_MULTIPLY:
this->ask_key_pressed = 0x43;
break;
case SDLK_KP_PLUS:
this->ask_key_pressed = 0x45;
break;
case SDLK_DELETE:
this->ask_key_pressed = 0x47;
break;
case SDLK_KP_DIVIDE:
this->ask_key_pressed = 0x4B;
break;
case SDLK_KP_ENTER:
this->ask_key_pressed = 0x4C;
break;
case SDLK_KP_MINUS:
this->ask_key_pressed = 0x4E;
break;
case SDLK_KP_0:
this->ask_key_pressed = 0x52;
break;
case SDLK_KP_1:
this->ask_key_pressed = 0x53;
break;
case SDLK_KP_2:
this->ask_key_pressed = 0x54;
break;
case SDLK_KP_3:
this->ask_key_pressed = 0x55;
break;
case SDLK_KP_4:
this->ask_key_pressed = 0x56;
break;
case SDLK_KP_5:
this->ask_key_pressed = 0x57;
break;
case SDLK_KP_6:
this->ask_key_pressed = 0x58;
break;
case SDLK_KP_7:
this->ask_key_pressed = 0x59;
break;
case SDLK_KP_8:
this->ask_key_pressed = 0x5B;
break;
case SDLK_KP_9:
this->ask_key_pressed = 0x5C;
break;
case SDLK_BACKSPACE:
this->ask_key_pressed = 0x33;
this->confirm_ask_reg_2 = true;
this->mod_key_pressed = 0x40;
case SDLK_CAPSLOCK:
this->ask_key_pressed = 0x39;
this->confirm_ask_reg_2 = true;
this->mod_key_pressed = 0x20;
case SDLK_LCTRL:
case SDLK_RCTRL:
this->ask_key_pressed = 0x36;
this->confirm_ask_reg_2 = true;
this->mod_key_pressed = 0x8;
case SDLK_LSHIFT:
case SDLK_RSHIFT:
this->ask_key_pressed = 0x38;
this->confirm_ask_reg_2 = true;
this->mod_key_pressed = 0x4;
case SDLK_LALT:
case SDLK_RALT:
this->ask_key_pressed = 0x3A;
this->confirm_ask_reg_2 = true;
this->mod_key_pressed = 0x2;
case SDLK_HOME: //Temp key for the Command/Apple key
this->ask_key_pressed = 0x37;
this->confirm_ask_reg_2 = true;
this->mod_key_pressed = 0x1;
default:
break;
}
if (this->ask_register0 & 0x8000) {
this->ask_register0 &= 0x7FFF;
this->ask_register0 &= (ask_key_pressed << 8);
}
else if (this->ask_register0 & 0x80) {
this->ask_register0 &= 0xFF7F;
this->ask_register0 &= (ask_key_pressed);
}
//check if mod keys are being pressed
if (this->confirm_ask_reg_2) {
this->ask_register2 |= (this->mod_key_pressed << 8);
}
break;
case SDL_KEYUP:
if (!(this->ask_register0 & 0x8000)) {
this->ask_register0 |= 0x8000;
}
else if (this->ask_register0 & 0x80)
this->ask_register0 |= 0x0080;
if (this->confirm_ask_reg_2) {
this->ask_register2 &= (this->mod_key_pressed << 8);
this->confirm_ask_reg_2 = false;
}
}
}
if (reg == 0) {
reg_stream[0] = (this->ask_register0 >> 8);
reg_stream[1] = (this->ask_register0 & 0xff);
}
else if (reg == 2) {
reg_stream[0] = (this->ask_register2 >> 8);
reg_stream[1] = (this->ask_register2 & 0xff);
}
}
uint8_t ADB_Keybd::copy_stream_byte(int offset) {
return this->reg_stream[offset];
}

View File

@ -1,61 +0,0 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-20 divingkatae and maximum
(theweirdo) spatium
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
/** ADB input device definitions
Simulates Apple Desktop Bus (ADB) keyboard and mice
*/
#ifndef ADBKEYBD_H
#define ADBKEYBD_H
#include <array>
#include <cinttypes>
#include <thirdparty/SDL2/include/SDL.h>
#include <thirdparty/SDL2/include/SDL_events.h>
using namespace std;
class ADB_Keybd
{
public:
ADB_Keybd();
~ADB_Keybd();
void input_keybd(int reg);
uint8_t copy_stream_byte(int offset);
private:
SDL_Event adb_keybd_evt;
uint16_t ask_register0;
uint16_t ask_register2;
uint8_t ask_key_pressed;
uint8_t mod_key_pressed;
uint8_t reg_stream[2] = { 0 };
bool confirm_ask_reg_2;
};
#endif /* ADB_H */

View File

@ -1,94 +0,0 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-20 divingkatae and maximum
(theweirdo) spatium
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
/** ADB mouse definitions
Simulates Apple Desktop Bus (ADB) standard mice
*/
#include <array>
#include <cinttypes>
#include <cstring>
#include "adbmouse.h"
#include <thirdparty/SDL2/include/SDL.h>
#include <thirdparty/SDL2/include/SDL_events.h>
#include <thirdparty/SDL2/include/SDL_mouse.h>
#include <thirdparty/SDL2/include/SDL_stdinc.h>
using namespace std;
ADB_Mouse::ADB_Mouse() {
this->adb_mousereg0 = 0x8080;
}
ADB_Mouse::~ADB_Mouse() {
}
void ADB_Mouse::input_mouse() {
while (SDL_PollEvent(&adb_mouse_evt)) {
if (adb_mouse_evt.motion.x) {
this->adb_mousereg0 &= 0x7F;
if (adb_mouse_evt.motion.xrel < 0) {
if (adb_mouse_evt.motion.xrel <= -64) {
this->adb_mousereg0 |= 0x7F;
}
else if (adb_mouse_evt.motion.xrel >= 63) {
this->adb_mousereg0 |= 0x3F;
}
else {
this->adb_mousereg0 |= adb_mouse_evt.motion.xrel;
}
}
}
if (adb_mouse_evt.motion.y) {
this->adb_mousereg0 &= 0x7F00;
if (adb_mouse_evt.motion.yrel < 0) {
if (adb_mouse_evt.motion.yrel <= -64) {
this->adb_mousereg0 |= 0x7F00;
}
else if (adb_mouse_evt.motion.yrel >= 63) {
this->adb_mousereg0 |= 0x3F00;
}
else {
this->adb_mousereg0 |= (adb_mouse_evt.motion.yrel << 8);
}
}
}
switch (adb_mouse_evt.type) {
case SDL_MOUSEBUTTONDOWN:
this->adb_mousereg0 &= 0x7FFF;
case SDL_MOUSEBUTTONUP:
this->adb_mousereg0 |= 0x8000;
}
}
reg_stream[0] = (this->adb_mousereg0 >> 8);
reg_stream[1] = (this->adb_mousereg0 & 0xff);
}
uint8_t ADB_Mouse::copy_stream_byte(int offset) {
return this->reg_stream[offset];
}

View File

@ -1,52 +0,0 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-20 divingkatae and maximum
(theweirdo) spatium
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
/** ADB input device definitions
Simulates Apple Desktop Bus (ADB) keyboard and mice
*/
#ifndef ADBMOUSE_H
#define ADBMOUSE_H
#include <array>
#include <cinttypes>
#include <thirdparty/SDL2/include/SDL.h>
#include <thirdparty/SDL2/include/SDL_events.h>
class ADB_Mouse
{
public:
ADB_Mouse();
~ADB_Mouse();
void input_mouse();
uint8_t copy_stream_byte(int offset);
private:
SDL_Event adb_mouse_evt;
uint16_t adb_mousereg0;
uint8_t reg_stream[2] = { 0 };
};
#endif /* ADB_H */