all repos — xyw @ e3cdbb1b205d3ce3a5e8a3f975d6ff19835e155a

A minimal virtual machine and assembler for terminals.

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

#define SYSTEM_STATE 0x00
#define SYSTEM_ERROR 0x01
#define SYSTEM_PAGE 0x02
#define SYSTEM_RANDOM 0x03

void system_init(xyw_byte *data)
{
    (void)data;
    // Initialize random generator seed
    srand(time(NULL));
}

xyw_byte system_input(xyw_byte *data, xyw_byte addr, xyw_byte *error)
{
    if (addr == SYSTEM_RANDOM)
    {
        return (xyw_byte)(rand() & 0xFF);
    }
    (void)error;
    return data[addr];
}