-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathtty.h
67 lines (50 loc) · 1.38 KB
/
tty.h
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
// (C) 2018-2024 by Folkert van Heusden
// Released under MIT license
#pragma once
#include "gen.h"
#include <ArduinoJson.h>
#include <atomic>
#include <mutex>
#include <stdint.h>
#include <stdio.h>
#include <string>
#include <thread>
#include <vector>
#include "bus.h"
#include "console.h"
#define PDP11TTY_TKS 0177560 // reader status
#define PDP11TTY_TKB 0177562 // reader buffer
#define PDP11TTY_TPS 0177564 // puncher status
#define PDP11TTY_TPB 0177566 // puncher buffer
#define PDP11TTY_BASE PDP11TTY_TKS
#define PDP11TTY_END (PDP11TTY_TPB + 2)
class memory;
class tty
{
private:
console *const c { nullptr };
bus *const b { nullptr };
#if defined(BUILD_FOR_RP2040)
SemaphoreHandle_t chars_lock { xSemaphoreCreateBinary() };
#else
std::mutex chars_lock;
#endif
std::vector<char> chars;
uint16_t registers[4] { 0 };
#if !defined(BUILD_FOR_RP2040)
std::thread *th { nullptr };
#endif
std::atomic_bool stop_flag { false };
void notify_rx();
public:
tty(console *const c, bus *const b);
virtual ~tty();
JsonDocument serialize();
static tty *deserialize(const JsonVariantConst j, bus *const b, console *const cnsl);
void reset();
uint8_t read_byte(const uint16_t addr);
uint16_t read_word(const uint16_t addr);
void write_byte(const uint16_t addr, const uint8_t v);
void write_word(const uint16_t addr, uint16_t v);
void operator()();
};