From 5d6101ab48d9db625916e4c5aee3ab28eed1e00a Mon Sep 17 00:00:00 2001 From: Lior Halphon Date: Sat, 30 Nov 2024 18:39:12 +0200 Subject: [PATCH] Updated GB_set_input_callback (markdown) --- GB_set_input_callback.md | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/GB_set_input_callback.md b/GB_set_input_callback.md index a46c367..3bf7b8b 100644 --- a/GB_set_input_callback.md +++ b/GB_set_input_callback.md @@ -4,16 +4,24 @@ typedef char *(*GB_input_callback_t)(GB_gameboy_t *gb); ``` -void GB_set_async_input_callback([[GB_gameboy_t]] *gb, [[GB_input_callback_t]] callback); +void GB_set_async_input_callback([[GB_gameboy_t]] *gb, GB_input_callback_t callback); -void GB_set_input_callback([[GB_gameboy_t]] *gb, [[GB_input_callback_t]] callback); +void GB_set_input_callback([[GB_gameboy_t]] *gb, GB_input_callback_t callback); In `gb.h` ## Description -TBD +`GB_set_input_callback` and `GB_set_async_input_callback` sets callback that will be called when an emulator instance's debugger requests input synchronously and asynchronously, respectively. The callbacks must return a UTF-8 string allocated by `malloc` (which will be automatically freed by the caller), or `NULL`. + +Returning `NULL` from the synchronous callback tells the debugger the input source is not available, and ROM execution will resume until it's explicitly stopped or reaches a stopping condition again. Returning `NULL` from the asynchronous callback means the user has no pending asynchronous commands to execute, and will not prevent the debugger from calling the callback again. + +If these functions are not called, the default callbacks will return lines read from `stdin`. ## Thread Safety If `callback` is not NULL, `GB_set_input_callback` and `GB_set_async_input_callback` are thread-safe and can be called from any thread and context. Otherwise, it must not be called if the instance is being run in another thread, but may be called from the current one (via a callback). + +## Notes + +The default asynchronous input callback is not supported on Windows; provide a custom callback if you wish to support asynchronous debugger commands on Windows. \ No newline at end of file