-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#77: add BASIC key injection routines
- Loading branch information
Showing
2 changed files
with
68 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |