File size: 2,973 Bytes
a2a15a2
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
/*
 *
 *  $Id: TinyVT52.ino,v 1.1 2022/12/13 19:00:16 stefan Exp stefan $ 
 *
 *  Stefan's TinyVT52 derived from the IoT BASIC interpreter 
 *
 *  See the licence file on 
 *  https://github.com/slviajero/tinybasic for copyright/left.
 *    (GNU GENERAL PUBLIC LICENSE, Version 3, 29 June 2007)
 *
 *  Author: Stefan Lenz, sl001@serverfabrik.de
 *
 * Device drivers and low level I/O routines are used from the BASIC code
 * These definitions are in basic.h and hardware-arduino.h. These two files 
 * are exactly identical to the BASIC language files to make sure that further
 * work on the device drivers can be used here without changes.
 * 
 * To use the terminal, the hardware definition in hardware-arduino.h need to be set
 * 
 * Any one of the following macros need to be defined 
 * 
 * Always set #define DISPLAYCANSCROLL
 * 
 * Displays: define one(!) of the following displays in hardware
 *  ARDUINOLCDI2C, ARDUINONOKIA51, ARDUINOILI9488, ARDUINOSSD1306
 *  ARDUINOMCUFRIEND, ARDUINOGRAPHDUMMY, LCDSHIELD, ARDUINOTFT
 * 
 * Keyboards:
 *  ARDUINOPS2, ARDUINOUSBKBD (alpha!!), ARDUINOZX81KBD
 * 
 * Printers:
 *  ARDUINOPRT 
 *
 */

/* which serial port is used for terminal I/O */
#define SERIALPORT Serial

/* which serial port is used for printer IO */
#define PRTSERIAL Serial3

/* the only language feature of BASIC that we need is the VT52 component */
#define HASVT52

/* should the VT52 also handle Wiring */
#define VT52WIRING

/* the device driver code from BASIC */
#include "basic.h"
#include "hardware-arduino.h"

/* XON and XOFF characters */
#define XON 0x11
#define XOFF 0x13

/* a shallow buffer */
#define VT52BUFSIZE 64
char vt52sbuf[VT52BUFSIZE];
int vt52sbi = 0;

void setup() {

/* start the terminal interface */
  SERIALPORT.begin(9600);

/* start the display stream */
  dspbegin();  

/* if a printer port is defined, start the printer, this is Serial1 of Software Serial */
#if defined(ARDUINOPRT)
  prtbegin();
#endif

/* if any wire subsystem is requested, start it as well */
#if defined(NEEDSWIRE)
  wirebegin();
#endif

/* and then there is SPI */
#if defined(ARDUINOSPI)
  spibegin();
#endif

}

void loop() {
  char ch;

/* first test, just use the serial port as in */

/* read a chunk of characters */
/* display output is slow, it is an operation at the timescale of 10 ms per character, XOFF while we do it*/
  if (SERIALPORT.available()) {
/* send XOFF to hold the output */
    SERIALPORT.write(XOFF);
/* free the serial buffer immediately to be ready for characters sent before XOFF could be processes*/
    while (SERIALPORT.available() && vt52bi < VT52BUFSIZE) vt52sbuf[vt52bi++]=SERIALPORT.read();
/* now empty the buffer completely */
    for (int i=0; i<vt52bi; i++) dspwrite(vt52sbuf[i]);
    vt52bi=0;
/* send XON to continue output */
    SERIALPORT.write(XON);
  }
  
/* send all characters from the display to the serial stream */
  while (kbdavailable()) {
    ch=kbdread();
    SERIALPORT.write(ch);
  } 
}