aboutsummaryrefslogtreecommitdiff
path: root/arm9/source/devices/stream.c
blob: 73293803ba85b1dad089306c8303911e47c4d441 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
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();
    }
}