Skip to content
Permalink
Browse files

Add host keyboard/time hooks for homebrew and custom firmware

  • Loading branch information...
Cydrak Cydrak
Cydrak authored and Cydrak committed Aug 2, 2013
1 parent 353c407 commit 5beb60787c3ca1cd1d74e2791015490cf7d16ed0
@@ -112,7 +112,13 @@ struct Interface {
//debugger functions
virtual bool tracerEnable(bool) { return false; }
virtual void exportMemory() {}


virtual void keyboardEvent(unsigned type, unsigned long code) {}

enum {
KeyNoEvent, keyUpEvent, KeyDownEvent
};

Interface() : bind(nullptr) {}
};

@@ -505,6 +505,11 @@ uint32 ARM946ES::readReg(uint32 addr, uint32 size) {
case 0x0698: case 0x069c: case 0x06a0:
return gpu.regLightMatrix((addr - 0x4000680)/4);

// Special registers unique to dasShiny
case 0xde00: return system.regKeyboardEvents();
case 0xde14: return system.regHostTime(0);
case 0xde18: return system.regHostTime(1);
case 0xde1c: return system.regHostTime(2);
}
return CPUCore::readReg(addr, size);
}
@@ -676,6 +681,10 @@ void ARM946ES::writeReg(uint32 addr, uint32 size, uint32 data) {

// zelda gallery writes 0x2468ace0 here - ???
case 0x0640: break;

// Special registers unique to dasShiny
case 0xde00: return system.regKeyboardEvents(data);
case 0xde10: return system.regReadHostTime();
}
return CPUCore::writeReg(addr, size, data);
}
@@ -287,6 +287,13 @@ void Interface::videoRefresh(const uint32_t *data, unsigned pitch, unsigned widt
return bind->videoRefresh(pixels, 256*4, 256, 384);
}

void Interface::keyboardEvent(unsigned type, unsigned long code) {
uint32 event = type<<24 | code;

if(system.keyboardEvents.size() < 256)
system.keyboardEvents.append(event);
}


Interface::Interface() {
interface = this;
@@ -55,7 +55,9 @@ struct Interface : Emulator::Interface {
void power();
void run();
void videoRefresh(const uint32_t *data, unsigned pitch, unsigned width, unsigned height);


void keyboardEvent(unsigned type, unsigned long code);

serializer serialize();
bool unserialize(serializer&);

@@ -291,6 +291,35 @@ void System::regVmap(unsigned index, uint32 data, uint32 mask) {



uint32 System::regKeyboardEvents() {
return keyboardEnabled && keyboardEvents.size()? keyboardEvents.take(0) : 0;
}

void System::regKeyboardEvents(uint32 enable) {
keyboardEnabled = enable == 0xda5;
keyboardEvents.reset();
}

void System::regReadHostTime() {
struct timeval tv = {};
gettimeofday(&tv, 0);
hostTime = *localtime(&tv.tv_sec);
hostUsec = tv.tv_usec;
}

uint32 System::regHostTime(int index) {
if(index == 0)
return hostTime.tm_year+1900<<16 | hostTime.tm_mon+1<<8 | hostTime.tm_mday<<0;
if(index == 1)
return hostTime.tm_hour<<16 | hostTime.tm_min<<8 | hostTime.tm_sec<<0;
if(index == 2)
return hostUsec;

return 0;
}



void System::loadArm7Bios(const stream& stream) {
delete[] arm7.bios.data;

@@ -504,6 +533,11 @@ void System::power() {
clearVmap();
memset(vmap.dirty, 0xff, sizeof vmap.dirty);

keyboardEnabled = false;
keyboardEvents.reset();
memset(&hostTime, 0, sizeof hostTime);
hostUsec = 0;

arm9.config.arm9 = true;
arm9.config.arm7 = false;
arm7.config.arm9 = false;
@@ -1,4 +1,5 @@
#include "eventqueue.hpp"
#include <sys/time.h>

typedef function<void()> Action;
typedef EventQueue_of<Action> EventQueue;
@@ -152,6 +153,9 @@ struct System {

uint16 unmappedVram[0x2000];

struct tm hostTime;
uint32 hostUsec;

struct VRAMConfig {
uint1 enable;
uint2 offset;
@@ -204,14 +208,22 @@ struct System {
uint8 dirty[(512 + 96 + 48)*1024 / 256];
} vmap;


void clearVmap();
void updateVmap();
void mapVram(VRAMMapping* loc, uint8 *dirtyBits, unsigned npages, HalfMemory& bank);

uint32 regVmap(unsigned index);
void regVmap(unsigned index, uint32 data, uint32 mask);

bool keyboardEnabled;
nall::vector<uint32> keyboardEvents;

void regKeyboardEvents(uint32 enable);
uint32 regKeyboardEvents();

void regReadHostTime();
uint32 regHostTime(int index);

void loadArm7Bios(const stream&);
void loadArm9Bios(const stream&);
void loadFirmware(const stream&);
@@ -232,6 +232,13 @@ void InputManager::poll() {

for(unsigned n = 0; n < Scancode::Limit; n++) {
if(scancode[0][n] != scancode[1][n]) {
if(n < Keyboard::Scancode::Limit) {
if(program->active && presentation->focused())
program->active->keyboardEvent(scancode[activeScancode][n]
? Emulator::Interface::KeyDownEvent
: Emulator::Interface::keyUpEvent,
n);
}
if(settings->focused()) {
inputSettings->inputEvent(n, scancode[activeScancode][n]);
hotkeySettings->inputEvent(n, scancode[activeScancode][n]);
@@ -253,6 +260,7 @@ void InputManager::saveConfiguration() {
InputManager::InputManager() {
inputManager = this;
activeScancode = 0;
memset(scancode, 0, sizeof scancode);
bootstrap();
}

0 comments on commit 5beb607

Please sign in to comment.
You can’t perform that action at this time.