-
Notifications
You must be signed in to change notification settings - Fork 46
/
arduino_BASIC.ino
109 lines (92 loc) · 2.78 KB
/
arduino_BASIC.ino
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
#include <font.h>
#include <SSD1306ASCII.h>
// ^ - modified for faster SPI
#include <PS2Keyboard.h>
#include <EEPROM.h>
#include "basic.h"
#include "host.h"
// Define in host.h if using an external EEPROM e.g. 24LC256
// Should be connected to the I2C pins
// SDA -> Analog Pin 4, SCL -> Analog Pin 5
// See e.g. http://www.hobbytronics.co.uk/arduino-external-eeprom
// If using an external EEPROM, you'll also have to initialise it by
// running once with the appropriate lines enabled in setup() - see below
#if EXTERNAL_EEPROM
#include <I2cMaster.h>
// Instance of class for hardware master with pullups enabled
TwiMaster rtc(true);
#endif
// Keyboard
const int DataPin = 8;
const int IRQpin = 3;
PS2Keyboard keyboard;
// OLED
#define OLED_DATA 9
#define OLED_CLK 10
#define OLED_DC 11
#define OLED_CS 12
#define OLED_RST 13
SSD1306ASCII oled(OLED_DATA, OLED_CLK, OLED_DC, OLED_RST, OLED_CS);
// NB Keyboard needs a seperate ground from the OLED
// buzzer pin, 0 = disabled/not present
#define BUZZER_PIN 5
// BASIC
unsigned char mem[MEMORY_SIZE];
#define TOKEN_BUF_SIZE 64
unsigned char tokenBuf[TOKEN_BUF_SIZE];
const char welcomeStr[] PROGMEM = "Arduino BASIC";
char autorun = 0;
void setup() {
keyboard.begin(DataPin, IRQpin);
oled.ssd1306_init(SSD1306_SWITCHCAPVCC);
reset();
host_init(BUZZER_PIN);
host_cls();
host_outputProgMemString(welcomeStr);
// show memory size
host_outputFreeMem(sysVARSTART - sysPROGEND);
host_showBuffer();
// IF USING EXTERNAL EEPROM
// The following line 'wipes' the external EEPROM and prepares
// it for use. Uncomment it, upload the sketch, then comment it back
// in again and upload again, if you use a new EEPROM.
// writeExtEEPROM(0,0); writeExtEEPROM(1,0);
if (EEPROM.read(0) == MAGIC_AUTORUN_NUMBER)
autorun = 1;
else
host_startupTone();
}
void loop() {
int ret = ERROR_NONE;
if (!autorun) {
// get a line from the user
char *input = host_readLine();
// special editor commands
if (input[0] == '?' && input[1] == 0) {
host_outputFreeMem(sysVARSTART - sysPROGEND);
host_showBuffer();
return;
}
// otherwise tokenize
ret = tokenize((unsigned char*)input, tokenBuf, TOKEN_BUF_SIZE);
}
else {
host_loadProgram();
tokenBuf[0] = TOKEN_RUN;
tokenBuf[1] = 0;
autorun = 0;
}
// execute the token buffer
if (ret == ERROR_NONE) {
host_newLine();
ret = processInput(tokenBuf);
}
if (ret != ERROR_NONE) {
host_newLine();
if (lineNumber !=0) {
host_outputInt(lineNumber);
host_outputChar('-');
}
host_outputProgMemString((char *)pgm_read_word(&(errorTable[ret])));
}
}