vt100/src/session.c

to_terminal session_init session_step session_key session_hand

1#include "session.h"23static void to_terminal(void *ctx, const uint8_t *buf, size_t n) {4  session *s = ctx;5  for (size_t i = 0; i < n; i++) serial_put(&s->to_term, buf[i], s->now);6}78void session_init(session *s, int baud, double now_ms) {9  s->now = now_ms;10  s->machine = start_machine();11  vt_init(&s->term);12  serial_init(&s->to_term, baud);13  serial_init(&s->to_host, baud);14  console_init(&s->con, s->machine, to_terminal, s);15}1617void session_step(session *s, double now_ms, long long local_epoch_s) {18  uint8_t buf[64];19  int b, n;20  s->now = now_ms;21  vt_tick(&s->term, now_ms);22  while ((n = vt_take_tx(&s->term, buf, sizeof buf)) > 0)23    for (int i = 0; i < n; i++) serial_put(&s->to_host, buf[i], now_ms);24  while ((b = serial_get(&s->to_host, now_ms)) >= 0) {25    if (b == 0x13) serial_set_paused(&s->to_term, true, now_ms); /* NO SCROLL: XOFF */26    else if (b == 0x11) serial_set_paused(&s->to_term, false, now_ms);27    else console_input(&s->con, (uint8_t)b);28  }29  console_tick(&s->con, now_ms, local_epoch_s);30  while ((b = serial_get(&s->to_term, now_ms)) >= 0) vt_receive(&s->term, (uint8_t)b);31}3233void session_key(session *s, int key, bool down, double now_ms) {34  vt_key(&s->term, key, down, now_ms);35}3637void session_hand(session *s, int button) {38  wrap_external_call(s->machine, button == HAND_SET ? ExtCallSet : ExtCallFieldLight, BTCheekyPadding,39                     CPCheekyPadding, 0);40}4142/* the Therac-25 is power cycled; the VT100 on the desk is not */43void session_power_cycle(session *s) { console_power_cycle(&s->con); }