vt100/src/console.h
console_field console
1/* The Therac-25 treatment console program: the part of the PDP-11 software the operator2 * talked to through the VT100 (keyboard handler, the data-entry screen, the treatment console3 * screen processor). It only sees bytes from the terminal and writes bytes back; the machine4 * is the therac25 simulator, reached through csrc/Therac.h. */5#pragma once6#include <stdbool.h>7#include <stddef.h>8#include <stdint.h>910#include "Therac.h"1112typedef void (*console_out_fn)(void *ctx, const uint8_t *buf, size_t n);1314enum console_field {15 F_NAME,16 F_MODE,17 F_BEAM,18 F_ENERGY,19 F_RATE,20 F_MU,21 F_TIME,22 F_GANTRY,23 F_COLLROT,24 F_COLLX,25 F_COLLY,26 F_WEDGE,27 F_ACCESSORY,28 F_COMMAND,29 F_COUNT30};3132#define CONSOLE_SITE_ROWS 63334typedef struct console {35 HsStablePtr machine;36 console_out_fn out;37 void *out_ctx;3839 /* the form */40 char text[F_COUNT][24]; /* what the field shows */41 char committed[F_COUNT][24]; /* its last accepted value (for cursor-up without accepting) */42 bool fresh; /* the next printable key replaces the field */43 int field; /* where the cursor is */44 double actual[CONSOLE_SITE_ROWS]; /* treatment site as set up in the room */45 char beam; /* 'X', 'E' or 0: accepted beam type */46 int energy; /* accepted MeV, 0 if none */47 char cmd[12];4849 /* keyboard handler: escape sequences from the terminal */50 int esc_state;5152 /* what the machine said at the last screen processor pass */53 char outcome[64], phase[32], reason[64], set_prompt[32];54 int displayed_mu;5556 /* screen processor */57 char shown[24][80]; /* what the terminal is showing, as far as we know */58 int cur_row, cur_col;59 bool need_clear;60 double next_pass;61 long long clock_s; /* local time, seconds since 1970 */62} console;6364void console_init(console *c, HsStablePtr machine, console_out_fn out, void *ctx);65/* one byte from the terminal */66void console_input(console *c, uint8_t byte);67/* runs the screen processor every 0.1 s; local_epoch_s is the wall clock in local time */68void console_tick(console *c, double now_ms, long long local_epoch_s);69/* the machine was power cycled: clear the form and repaint */70void console_power_cycle(console *c);71/* the 24 lines the program wants on the screen (for tests); out must hold 24*81+1 bytes */72void console_wanted_text(console *c, char *out);