aboutsummaryrefslogtreecommitdiff
path: root/arm9/source/devices/stream.c
diff options
context:
space:
mode:
authorBen Bridle <ben@derelict.engineering>2025-09-19 13:17:14 +1200
committerBen Bridle <ben@derelict.engineering>2025-09-19 13:32:32 +1200
commitbb1aa5958d1b67707dcf0f6b08bfaf0b408bd46e (patch)
treeb26d07ed58aaf7a5230fc3e28c103d616abfa9b8 /arm9/source/devices/stream.c
parent9612c307f00c4313d73fe0c3a86c05c8d8cd514e (diff)
downloadbedrock-nds-bb1aa5958d1b67707dcf0f6b08bfaf0b408bd46e.zip
Massive rewrite
This commit rewrites the emulator halfway from scratch to make it easier to change and maintain in the future. The emulator core was rewritten to adhere to the released Bedrock specification (earlier versions implemented an older prototype specification, which is no longer relevant). This commit also adds proper support for running multiple concurrent Bedrock instances. This was previously supported in a limited manner for the on-screen keyboard, but now works for any regular program as well, with switching being performed by pressing the L or R bumper buttons. This is disabled by default, as programs will still need to be baked into the emulator and hand-loaded.
Diffstat (limited to 'arm9/source/devices/stream.c')
-rw-r--r--arm9/source/devices/stream.c40
1 files changed, 40 insertions, 0 deletions
diff --git a/arm9/source/devices/stream.c b/arm9/source/devices/stream.c
new file mode 100644
index 0000000..7329380
--- /dev/null
+++ b/arm9/source/devices/stream.c
@@ -0,0 +1,40 @@
+#include "stream.h"
+
+/*
+This is a skeleton of a device at the moment. The local.output.connected flag
+// of the keyboard program is manually set in main.c so that only the keyboard
+can send bytes to the main instance, otherwise user programs that write to the
+stream device will send keyboard bytes to themselves.
+*/
+
+
+void channel_reset(Channel *channel) {
+ channel->connected = false;
+ channel->transmitting = false;
+}
+
+void bytestream_reset(Bytestream *bstream) {
+ channel_reset(&bstream->input);
+ channel_reset(&bstream->output);
+}
+
+// Reset a stream device.
+void stream_reset(StreamDevice *stream) {
+ bytestream_reset(&stream->local);
+ bytestream_reset(&stream->remote);
+}
+
+// Write a byte to the stream of the main instance. This byte is expected to
+// be consumed by a keyboard program running on the sub instance.
+void stream_write(StreamDevice *stream, u8 byte) {
+ if (stream->local.output.connected) {
+ receive_keyboard_byte(byte);
+ }
+}
+
+// End the current transmission. Currently this will only hide the keyboard.
+void stream_end(StreamDevice *stream) {
+ if (stream->local.output.connected) {
+ close_keyboard();
+ }
+}