all repos — xyw @ da2d0985fb6f8ebe7f072144482105b1c04a1e2e

A minimal virtual machine and assembler for terminals.

devices/terminal.c

 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
#include <stdio.h>
#include "../xyw.h"

/* terminal device */
#define TERMINAL_INPUT 0x0
#define TERMINAL_OUTPUT 0x1
#define TERMINAL_ON_KEYPRESS 0x2

void terminal_output(xyw_byte *data, xyw_byte addr, xyw_byte *error)
{
    (void)error;
    switch (addr)
    {
    case TERMINAL_OUTPUT:
        fputc(data[addr], stdout);
        fflush(stdout);
        break;
    }
}

void terminal_input(xyw_byte *data, xyw_byte addr, xyw_byte *error)
{
    (void)error;
    switch (addr)
    {
    case TERMINAL_INPUT:
        data[addr] = (xyw_byte)getchar();
        // If on keypress word is set, trigger jump to address at that location
        if (data[TERMINAL_ON_KEYPRESS] != 0)
        {
            xyw_word jump_addr = XYW_PEEKW(&data[TERMINAL_ON_KEYPRESS]);
            // Todo: execute code at address
        }
        break;
    }
}