Skip to content

Commit

Permalink
#77: add BASIC key injection routines
Browse files Browse the repository at this point in the history
  • Loading branch information
alvieboy committed Apr 5, 2021
1 parent 7fda1ef commit 01c357c
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 0 deletions.
46 changes: 46 additions & 0 deletions esp32/main/basickey.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
#include "basickey.h"
#include <string.h>
#include "rom_hook.h"

static uint8_t keylen = 0;
static uint8_t keypos = 0;
static uint8_t keybuf[16];
static int8_t basic_inject_hook = -1;

bool basickey__has_inject(void)
{
return keypos!=keylen;
}

uint8_t basickey__get_inject()
{
uint8_t v = keybuf[keypos++];
if (keypos>=keylen) {
// Remove hook
if (basic_inject_hook>=0) {
rom_hook__remove(basic_inject_hook);
basic_inject_hook = -1;
}
}

return v;
}

void basickey__clearinject(void)
{
keypos=0;
keylen=0;
}

void basickey__inject(const uint8_t *keys, unsigned len)
{
// This currently removes everything
basickey__clearinject();
memcpy(keybuf, keys, len);
keylen = len;

if (basic_inject_hook<0) {
basic_inject_hook = rom_hook__add_pre_set(model__get_basic_rom(), 0x0F38, 1); // ED_LOOP
}

}
22 changes: 22 additions & 0 deletions esp32/main/basickey.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#ifndef __BASICKEY_H__
#define __BASICKEY_H__

#include <stdbool.h>
#include <inttypes.h>


#ifdef __cplusplus
extern "C" {
#endif

bool basickey__has_inject(void);
uint8_t basickey__get_inject();
void basickey__clearinject(void);
void basickey__inject(const uint8_t *keys, unsigned len);
void basickey__set_callback( void(*callback)(void) );

#ifdef __cplusplus
}
#endif

#endif

0 comments on commit 01c357c

Please sign in to comment.