vt100/src/web_main.c
web_frame web_text web_info web_take_clicks web_take_bells web_cursor_style
1/* Entry points for the browser (vt100/web/main.js). Everything runs on the page's one thread:2 * the page calls web_frame once per animation frame, and the simulator's own threads run in3 * between, woken by setTimeout (GHC's threadDelay on wasm). */4#include <stdio.h>5#include <string.h>67#include "session.h"89static session S;10static char text[VT_ROWS * (VT_COLS + 1) + 1];11static char info[512];1213void web_init(double now_ms) { session_init(&S, 9600, now_ms); }1415/* returns 1 if the raster was redrawn */16int web_frame(double now_ms, double local_epoch_s) {17 session_step(&S, now_ms, (long long)local_epoch_s);18 return vt_render(&S.term, now_ms) ? 1 : 0;19}2021/* 800 x 240 bytes, intensity 0-3 */22const uint8_t *web_raster(void) { return &S.term.raster[0][0]; }2324void web_key(int key, int down, double now_ms) { session_key(&S, key, down != 0, now_ms); }2526void web_hand(int button) { session_hand(&S, button); }2728void web_power(void) { session_power_cycle(&S); }2930const char *web_text(void) {31 vt_text(&S.term, text);32 return text;33}3435/* what the operator could not see, for the instructor panel: see RequestClass3 etc. */36const char *web_info(int request) {37 char *s = request_state_info(S.machine, (StateInfoRequest)request);38 snprintf(info, sizeof info, "%s", s ? s : "");39 if (s) free_state_info(s);40 return info;41}4243int web_leds(void) { return S.term.leds; }4445int web_take_clicks(void) {46 int n = S.term.clicks;47 S.term.clicks = 0;48 return n;49}5051int web_take_bells(void) {52 int n = S.term.bells;53 S.term.bells = 0;54 return n;55}5657/* SET-UP choice: 1 = blinking block, 0 = blinking underline */58void web_cursor_style(int block) {59 S.term.block_cursor = block != 0;60 S.term.dirty = true;61}