├── .gitignore ├── ChangeLog ├── LICENSE ├── README ├── README.md └── terminal-basic ├── HAL.c ├── HAL.h ├── HALProxyStream.cpp ├── HALProxyStream.hpp ├── HAL_arduino.cpp ├── HAL_arduino.h ├── HAL_arduino_gfx.cpp ├── HAL_arduino_gfx.hpp ├── HAL_avr8.cpp ├── HAL_avr8.h ├── HAL_config.h ├── HAL_esp32.cpp ├── HAL_esp32.h ├── HAL_esp32_odroidgo.cpp ├── HAL_esp8266.cpp ├── HAL_sam.cpp ├── _HAL_arduino.h ├── _basic_config.h ├── _tokens_en.h ├── _tokens_fr.h ├── _tokens_ru.h ├── arduino_logger.hpp ├── arduinoext.hpp ├── ascii.hpp ├── avr └── pgmspace.h ├── basic.c ├── basic.h ├── basic.hpp ├── basic_arduinoio.cpp ├── basic_arduinoio.hpp ├── basic_config.h ├── basic_config.hpp ├── basic_dataparser.cpp ├── basic_dataparser.hpp ├── basic_exteeprom.cpp ├── basic_exteeprom.hpp ├── basic_extmemfs.cpp ├── basic_extmemfs.hpp ├── basic_functionblock.cpp ├── basic_functionblock.hpp ├── basic_gfx.cpp ├── basic_gfx.hpp ├── basic_internalfuncs.cpp ├── basic_internalfuncs.hpp ├── basic_interpreter.hpp ├── basic_interpreter_matrix.cpp ├── basic_interpreterw.cpp ├── basic_lexer.c ├── basic_lexer.h ├── basic_lexer.hpp ├── basic_lexer_en.c ├── basic_lexer_fr.c ├── basic_lexer_ru.c ├── basic_lexerw.cpp ├── basic_math.cpp ├── basic_math.hpp ├── basic_parser.c ├── basic_parser.h ├── basic_parser.hpp ├── basic_parser_value.cpp ├── basic_parser_value.hpp ├── basic_parserw.cpp ├── basic_program.cpp ├── basic_program.hpp ├── basic_value.c ├── basic_value.h ├── buffered_terminal.cpp ├── buffered_terminal.hpp ├── bytearray.cpp ├── bytearray.hpp ├── config_arduino.hpp ├── gfxterm.hpp ├── helper.hpp ├── i2ceeprom.hpp ├── liquidcrystalprint.cpp ├── liquidcrystalprint.hpp ├── math.hpp ├── matrix.hpp ├── seriallight.cpp ├── seriallight.hpp ├── strings_en.hpp ├── strings_fr.hpp ├── strings_ru.hpp ├── sys └── cdefs.h ├── terminal-basic.ino ├── tools.c ├── tools.h ├── tvoutprint.cpp ├── tvoutprint.hpp ├── types.hpp ├── version.h ├── vt100.cpp └── vt100.hpp /.gitignore: -------------------------------------------------------------------------------- 1 | # Prerequisites 2 | *.d 3 | 4 | # Compiled Object files 5 | *.slo 6 | *.lo 7 | *.o 8 | *.obj 9 | 10 | # Precompiled Headers 11 | *.gch 12 | *.pch 13 | 14 | # Compiled Dynamic libraries 15 | *.so 16 | *.dylib 17 | *.dll 18 | 19 | # Fortran module files 20 | *.mod 21 | *.smod 22 | 23 | # Compiled Static libraries 24 | *.lai 25 | *.la 26 | *.a 27 | *.lib 28 | 29 | # Executables 30 | *.exe 31 | *.out 32 | *.app 33 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # terminalbasic-arduino 2 | Terminal-BASIC is a lightweight interpreter of classical BASIC programming language (unstructured with line numbers). 3 | 4 | Main project repository is placed at https://github.com/terminal-basic-team/terminalbasic, but the sources structure is relatively complex, consisting from 5 | several netbeans-ide projects and scripts for authoring of the sources. Here I place all the published versions in the form of Arduino-IDE sketches. 6 | -------------------------------------------------------------------------------- /terminal-basic/HAL.c: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of Terminal-BASIC: a lightweight BASIC-like language 3 | * interpreter. 4 | * 5 | * Copyright (C) 2016-2018 Andrey V. Skvortsov 6 | * Copyright (C) 2019-2021 Terminal-BASIC team 7 | * 8 | * 9 | * This program is free software: you can redistribute it and/or modify 10 | * it under the terms of the GNU General Public License as published by 11 | * the Free Software Foundation, either version 3 of the License, or 12 | * (at your option) any later version. 13 | * 14 | * This program is distributed in the hope that it will be useful, 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | * GNU General Public License for more details. 18 | * 19 | * You should have received a copy of the GNU General Public License 20 | * along with this program. If not, see . 21 | */ 22 | 23 | #include "HAL.h" 24 | 25 | #if HAL_TERMINAL_STDIO >= HAL_TERMINAL_NUM 26 | #error STDIO terminal index is greater then number of terminals 27 | #endif 28 | 29 | #if HAL_NVRAM 30 | 31 | void 32 | HAL_nvram_write_buf(HAL_nvram_address_t address, const void* buf, uint32_t size) 33 | { 34 | const uint8_t* bp = (const uint8_t*)buf; 35 | HAL_nvram_address_t a; 36 | for (a=address; a 6 | * Copyright (C) 2019-2021 Terminal-BASIC team 7 | * 8 | * 9 | * This program is free software: you can redistribute it and/or modify 10 | * it under the terms of the GNU General Public License as published by 11 | * the Free Software Foundation, either version 3 of the License, or 12 | * (at your option) any later version. 13 | * 14 | * This program is distributed in the hope that it will be useful, 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | * GNU General Public License for more details. 18 | * 19 | * You should have received a copy of the GNU General Public License 20 | * along with this program. If not, see . 21 | */ 22 | 23 | #include "HALProxyStream.hpp" 24 | 25 | namespace BASIC 26 | { 27 | 28 | HALProxyStream::HALProxyStream(uint8_t term) : 29 | m_term(term), m_hasByte(false) 30 | { 31 | } 32 | 33 | int 34 | HALProxyStream::available() 35 | { 36 | return HAL_terminal_isdataready(m_term) ? 1 : 0; 37 | } 38 | 39 | size_t 40 | HALProxyStream::write(uint8_t byte) 41 | { 42 | HAL_terminal_write(m_term, byte); 43 | return 1; 44 | } 45 | 46 | void 47 | HALProxyStream::flush() 48 | { 49 | } 50 | 51 | int 52 | HALProxyStream::peek() 53 | { 54 | if (m_hasByte) { 55 | m_hasByte = false; 56 | } else if (HAL_terminal_isdataready(m_term)) { 57 | m_byte = HAL_terminal_read(m_term); 58 | m_hasByte = true; 59 | } else 60 | return -1; 61 | return m_byte; 62 | } 63 | 64 | int 65 | HALProxyStream::read() 66 | { 67 | if (m_hasByte) 68 | return m_byte; 69 | else if (HAL_terminal_isdataready(m_term)) 70 | return HAL_terminal_read(m_term); 71 | else 72 | return -1; 73 | 74 | } 75 | 76 | } // namespace BASIC 77 | -------------------------------------------------------------------------------- /terminal-basic/HALProxyStream.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of Terminal-BASIC: a lightweight BASIC-like language 3 | * interpreter. 4 | * 5 | * Copyright (C) 2016-2018 Andrey V. Skvortsov 6 | * Copyright (C) 2019-2021 Terminal-BASIC team 7 | * 8 | * 9 | * This program is free software: you can redistribute it and/or modify 10 | * it under the terms of the GNU General Public License as published by 11 | * the Free Software Foundation, either version 3 of the License, or 12 | * (at your option) any later version. 13 | * 14 | * This program is distributed in the hope that it will be useful, 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | * GNU General Public License for more details. 18 | * 19 | * You should have received a copy of the GNU General Public License 20 | * along with this program. If not, see . 21 | */ 22 | 23 | #ifndef HALPROXYSTREAM_HPP 24 | #define HALPROXYSTREAM_HPP 25 | 26 | #include "HAL.h" 27 | #include 28 | 29 | namespace BASIC 30 | { 31 | 32 | class HALProxyStream : public Stream 33 | { 34 | public: 35 | 36 | HALProxyStream(uint8_t); 37 | 38 | void begin(int) {} 39 | 40 | private: 41 | 42 | const uint8_t m_term; 43 | 44 | bool m_hasByte; 45 | 46 | uint8_t m_byte; 47 | 48 | // Stream interface 49 | public: 50 | 51 | int available() override; 52 | 53 | size_t write(uint8_t) override; 54 | 55 | void flush() override; 56 | 57 | int peek() override; 58 | 59 | int read() override; 60 | }; 61 | 62 | } // namespace BASIC 63 | 64 | #endif // HALPROXYSTREAM_HPP 65 | 66 | -------------------------------------------------------------------------------- /terminal-basic/HAL_arduino.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of Terminal-BASIC: a lightweight BASIC-like language 3 | * interpreter. 4 | * 5 | * Copyright (C) 2016-2018 Andrey V. Skvortsov 6 | * Copyright (C) 2019-2021 Terminal-BASIC team 7 | * 8 | * 9 | * This program is free software: you can redistribute it and/or modify 10 | * it under the terms of the GNU General Public License as published by 11 | * the Free Software Foundation, either version 3 of the License, or 12 | * (at your option) any later version. 13 | * 14 | * This program is distributed in the hope that it will be useful, 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | * GNU General Public License for more details. 18 | * 19 | * You should have received a copy of the GNU General Public License 20 | * along with this program. If not, see . 21 | */ 22 | 23 | /** 24 | * @brief Configuration for the Arduino core HAL implementation 25 | */ 26 | 27 | #ifndef HAL_ARDUINO_H 28 | #define HAL_ARDUINO_H 29 | 30 | #include "HAL.h" 31 | #include "_HAL_arduino.h" 32 | 33 | /** 34 | * Output devices 35 | * 36 | * HAL_ARDUINO_TERMINAL_OUTPUT_NONE - output not used (implemented outside aeduino module) 37 | * HAL_ARDUINO_TERMINAL_OUTPUT_SERIAL - Serial[N] objects from arduino library 38 | * HAL_ARDUINO_TERMINAL_OUTPUT_ILI9341 - Use Adafruit GFX library for 240x320 ILI9341 tft displays 39 | * HAL_ARDUINO_TERMINAL_OUTPUT_TFTeSPI - Use Use TFT_eSPI library 40 | */ 41 | #define HAL_ARDUINO_TERMINAL_OUTPUT HAL_ARDUINO_TERMINAL_OUTPUT_NONE 42 | 43 | /** 44 | * Input devices 45 | * 46 | * HAL_ARDUINO_TERMINAL_INPUT_NONE 47 | * HAL_ARDUINO_TERMINAL_INPUT_SERIAL 48 | * HAL_ARDUINO_TERMINAL_INPUT_PS2KBD 49 | */ 50 | #define HAL_ARDUINO_TERMINAL_INPUT HAL_ARDUINO_TERMINAL_INPUT_NONE 51 | 52 | #if (HAL_ARDUINO_TERMINAL_OUTPUT == HAL_ARDUINO_TERMINAL_OUTPUT_SERIAL) || \ 53 | (HAL_ARDUINO_TERMINAL_INPUT == HAL_ARDUINO_TERMINAL_INPUT_SERIAL) 54 | #define HAL_ARDUINO_TERMINAL_SERIAL_0_BR 115200 55 | #if HAL_TERMINAL_NUM > 0 56 | #define HAL_ARDUINO_TERMINAL_SERIAL_1_BR 115200 57 | #endif /* HAL_TERMINAL_NUM */ 58 | #if HAL_TERMINAL_NUM > 1 59 | #define HAL_ARDUINO_TERMINAL_SERIAL_2_BR 115200 60 | #endif /* HAL_TERMINAL_NUM */ 61 | #if HAL_TERMINAL_NUM > 2 62 | #define HAL_ARDUINO_TERMINAL_SERIAL_3_BR 115200 63 | #endif /* HAL_TERMINAL_NUM */ 64 | #endif 65 | #if HAL_ARDUINO_TERMINAL_OUTPUT == HAL_ARDUINO_TERMINAL_OUTPUT_ILI9341 66 | #define TFT_DC 27 67 | #define TFT_CS 2 68 | #define TFT_RS 4 69 | #endif /* HAL_ARDUINO_TERMINAL_OUTPUT */ 70 | 71 | #if HAL_ARDUINO_TERMINAL_INPUT == HAL_ARDUINO_TERMINAL_INPUT_PS2KBD 72 | #define HAL_ARDUINO_TERMINAL_INPUT_PS2KBD_DATAPIN 32 73 | #define HAL_ARDUINO_TERMINAL_INPUT_PS2KBD_CLKPIN 33 74 | #endif 75 | 76 | #if HAL_EXTMEM 77 | 78 | /* 79 | * External memory (storage) implementation 80 | * 81 | * HAL_ARDUINO_EXTMEM_NONE - No extmem implementation 82 | * HAL_ARDUINO_EXTMEM_SD - Standard SD library implementation 83 | * HAL_ARDUINO_EXTMEM_SDFS - SDFS library implememntation 84 | * HAL_ARDUINO_EXTMEM_I2CEEPROM - I2C eeprom HAL extmem implementation 85 | */ 86 | #define HAL_ARDUINO_EXTMEM HAL_ARDUINO_EXTMEM_SDFS 87 | 88 | #endif /* HAL_EXTMEM */ 89 | 90 | #if HAL_GFX 91 | 92 | /* 93 | * Used GFX implementation 94 | * 95 | * HAL_ARDUINO_GFX_NONE - No GFX implementation (implemented outside) 96 | * HAL_ARDUINO_GFX_SERIAL - Serial binary protocol implementation 97 | * HAL_ARDUINO_GFX_UTFT - UTFT HAL GFX implementation 98 | * HAL_ARDUINO_GFX_ILI9341 - Implementation based on Adafruit lib for ILI9341 displays 99 | * HAL_ARDUINO_GFX_TFTeSPI - TFTeSPI library implementation 100 | */ 101 | #define HAL_ARDUINO_GFX HAL_ARDUINO_GFX_SERIAL 102 | 103 | #if HAL_ARDUINO_GFX == HAL_ARDUINO_GFX_SERIAL 104 | #define HAL_ARDUINO_GFX_SERIAL_TERMNO 0 105 | #endif 106 | 107 | #endif /* HAL_GFX */ 108 | 109 | #if HAL_GPIO 110 | /** 111 | * HAL_GPIO_ARDUINO_NONE - No GPIO implementation 112 | * HAL_GPIO_ARDUINO_CORE - Implementation based on Arduino-core functions (digitalRead, digitalWrite...) 113 | */ 114 | #define HAL_GPIO_ARDUINO HAL_GPIO_ARDUINO_CORE 115 | #endif /* HAL_GPIO */ 116 | 117 | #if HAL_BUZZER 118 | /** 119 | * HAL_BUZZER_ARDUINO_NONE - No buzzer implementation 120 | * HAL_BUZZER_ARDUINO_TONE - Implementation, base4d on tone function 121 | */ 122 | #define HAL_BUZZER_ARDUINO HAL_BUZZER_ARDUINO_TONE 123 | #endif /* HAL_BUZZER */ 124 | 125 | #endif /* HAL_ARDUINO_H */ 126 | -------------------------------------------------------------------------------- /terminal-basic/HAL_arduino_gfx.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of Terminal-BASIC: a lightweight BASIC-like language 3 | * interpreter. 4 | * 5 | * Copyright (C) 2016-2018 Andrey V. Skvortsov 6 | * Copyright (C) 2019-2021 Terminal-BASIC team 7 | * 8 | * 9 | * This program is free software: you can redistribute it and/or modify 10 | * it under the terms of the GNU General Public License as published by 11 | * the Free Software Foundation, either version 3 of the License, or 12 | * (at your option) any later version. 13 | * 14 | * This program is distributed in the hope that it will be useful, 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | * GNU General Public License for more details. 18 | * 19 | * You should have received a copy of the GNU General Public License 20 | * along with this program. If not, see . 21 | */ 22 | 23 | #ifndef HAL_ARDUINO_GFX_HPP 24 | #define HAL_ARDUINO_GFX_HPP 25 | 26 | #include "HAL_arduino.h" 27 | #include "vt100.hpp" 28 | 29 | #if HAL_ARDUINO_TERMINAL_OUTPUT == HAL_ARDUINO_TERMINAL_OUTPUT_ILI9341 30 | #include "Adafruit_ILI9341.h" 31 | 32 | class ESPI : public VT100::Print 33 | { 34 | public: 35 | 36 | #define CURSOR_BLINK_PERIOD 20 37 | 38 | ESPI(uint8_t cs, uint8_t dc, uint8_t rs); 39 | 40 | void begin(); 41 | 42 | void clear() override; 43 | 44 | void onTimer(); 45 | 46 | Adafruit_ILI9341 tft; 47 | 48 | protected: 49 | 50 | void drawCursor(bool v); 51 | 52 | void scrollLine(); 53 | 54 | void writeChar(uint8_t c) override; 55 | 56 | uint8_t getCursorX() override 57 | { 58 | return m_column; 59 | } 60 | 61 | void setCursorX(uint8_t x) override 62 | { 63 | setCursor(x, m_row); 64 | } 65 | 66 | void setCursor(uint8_t x, uint8_t y) override 67 | { 68 | drawCursor(false); 69 | m_row = y % m_rows; 70 | m_column = x % m_columns; 71 | tft.setCursor(m_column * 6, (y * 8 + m_scroll) % tft.height()); 72 | drawCursor(true); 73 | } 74 | 75 | void addAttribute(VT100::TextAttr ta) override 76 | { 77 | switch (ta) { 78 | case VT100::TextAttr::BRIGHT: 79 | m_attr |= VT100::TextAttr::BRIGHT; 80 | break; 81 | case VT100::TextAttr::C_GREEN: 82 | case VT100::TextAttr::C_YELLOW: 83 | case VT100::TextAttr::C_BLUE: 84 | case VT100::TextAttr::C_CYAN: 85 | case VT100::TextAttr::C_MAGENTA: 86 | case VT100::TextAttr::C_RED: 87 | case VT100::TextAttr::C_WHITE: 88 | case VT100::TextAttr::C_BLACK: 89 | m_attr &= VT100::TextAttr(0x0F); 90 | m_attr |= ta; 91 | break; 92 | default: 93 | break; 94 | } 95 | 96 | VT100::Color color = VT100::Color::COLOR_BLACK; 97 | switch (m_attr & 0xF0) { 98 | case VT100::TextAttr::C_GREEN: 99 | color = VT100::Color::COLOR_GREEN; 100 | break; 101 | case VT100::TextAttr::C_YELLOW: 102 | color = VT100::Color::COLOR_YELLOW; 103 | break; 104 | case VT100::TextAttr::C_BLUE: 105 | color = VT100::Color::COLOR_BLUE; 106 | break; 107 | case VT100::TextAttr::C_CYAN: 108 | color = VT100::Color::COLOR_CYAN; 109 | break; 110 | case VT100::TextAttr::C_MAGENTA: 111 | color = VT100::Color::COLOR_MAGENTA; 112 | break; 113 | case VT100::TextAttr::C_RED: 114 | color = VT100::Color::COLOR_RED; 115 | break; 116 | case VT100::TextAttr::C_WHITE: 117 | color = VT100::Color::COLOR_WHITE; 118 | break; 119 | } 120 | 121 | if (m_attr & VT100::TextAttr::BRIGHT) 122 | tft.setTextColor(pgm_read_word(&s_colors[color][1])); 123 | else 124 | tft.setTextColor(pgm_read_word(&s_colors[color][0])); 125 | } 126 | 127 | void resetAttributes() override 128 | { 129 | tft.setTextColor(ILI9341_LIGHTGREY); 130 | m_attr = VT100::TextAttr::NO_ATTR; 131 | } 132 | 133 | private: 134 | 135 | uint8_t m_row, m_column; 136 | 137 | uint8_t m_rows, m_columns; 138 | 139 | uint16_t m_scroll; 140 | 141 | VT100::TextAttr m_attr; 142 | 143 | static const uint16_t s_colors[uint8_t(VT100::Color::NUM_COLORS)][2] PROGMEM; 144 | 145 | bool m_lockCursor, m_cursorState; 146 | 147 | uint8_t m_cursorCounter; 148 | }; 149 | 150 | extern ESPI espi; 151 | 152 | #endif // HAL_ARDUINO_TERMINAL_OUTPUT 153 | 154 | #endif // HAL_ARDUINO_GFX_HPP 155 | -------------------------------------------------------------------------------- /terminal-basic/HAL_avr8.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of Terminal-BASIC: a lightweight BASIC-like language 3 | * interpreter. 4 | * 5 | * Copyright (C) 2016-2018 Andrey V. Skvortsov 6 | * Copyright (C) 2019-2021 Terminal-BASIC team 7 | * 8 | * 9 | * This program is free software: you can redistribute it and/or modify 10 | * it under the terms of the GNU General Public License as published by 11 | * the Free Software Foundation, either version 3 of the License, or 12 | * (at your option) any later version. 13 | * 14 | * This program is distributed in the hope that it will be useful, 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | * GNU General Public License for more details. 18 | * 19 | * You should have received a copy of the GNU General Public License 20 | * along with this program. If not, see . 21 | */ 22 | 23 | #ifdef ARDUINO_ARCH_AVR 24 | 25 | #include 26 | #include 27 | 28 | #include "HAL_avr8.h" 29 | 30 | #define _SERIALLIGHT_USED \ 31 | (HAL_ARDUINO_AVR8_TERMINAL_OUTPUT == HAL_ARDUINO_AVR8_TERMINAL_OUTPUT_SERIALLIGHT) || \ 32 | (HAL_ARDUINO_AVR8_TERMINAL_INPUT == HAL_ARDUINO_AVR8_TERMINAL_INPUT_SERIALLIGHT) 33 | 34 | #if _SERIALLIGHT_USED 35 | #include "seriallight.hpp" 36 | #endif 37 | 38 | __BEGIN_DECLS 39 | void 40 | HAL_initialize_concrete() 41 | { 42 | #if _SERIALLIGHT_USED 43 | SerialL.begin(HAL_ARDUINO_AVR8_TERMINAL_SERIAL_0_BR); 44 | #if defined(HAVE_HWSERIAL1) && (HAL_TERMINAL_NUM > 0) 45 | SerialL1.begin(HAL_ARDUINO_AVR8_TERMINAL_SERIAL_1_BR); 46 | #endif 47 | #if defined(HAVE_HWSERIAL2) && (HAL_TERMINAL_NUM > 1) 48 | SerialL2.begin(HAL_ARDUINO_AVR8_TERMINAL_SERIAL_2_BR); 49 | #endif 50 | #if defined(HAVE_HWSERIAL3) && (HAL_TERMINAL_NUM > 2) 51 | SerialL3.begin(HAL_ARDUINO_AVR8_TERMINAL_SERIAL_3_BR); 52 | #endif 53 | #endif // HAL_ARDUINO_AVR8_TERMINAL 54 | #if HAL_ARDUINO_AVR8_EXTMEM 55 | XMCRA |= 1ul<<7; // Switch ext mem iface on 56 | XMCRB = 0; 57 | #endif // HAL_ARDUINO_AVR8_EXTMEM 58 | } 59 | __END_DECLS 60 | 61 | void 62 | HAL_finalize() 63 | { 64 | } 65 | 66 | #if HAL_NVRAM 67 | 68 | HAL_nvram_address_t HAL_nvram_getsize() 69 | { 70 | return (HAL_nvram_address_t)(E2END+1); 71 | } 72 | 73 | uint8_t HAL_nvram_read(HAL_nvram_address_t addr) 74 | { 75 | return eeprom_read_byte((uint8_t*)addr); 76 | } 77 | 78 | void HAL_nvram_write(HAL_nvram_address_t addr, uint8_t byte) 79 | { 80 | return eeprom_update_byte((uint8_t*)addr, byte); 81 | } 82 | 83 | #endif // HAL_NVRAM 84 | 85 | #if HAL_ARDUINO_AVR8_TERMINAL_OUTPUT == HAL_ARDUINO_AVR8_TERMINAL_OUTPUT_SERIALLIGHT 86 | 87 | void 88 | HAL_terminal_write(HAL_terminal_t t, uint8_t b) 89 | { 90 | if (t == 0) 91 | SerialL.write(b); 92 | #if defined(HAVE_HWSERIAL1) && (HAL_TERMINAL_NUM > 0) 93 | else if (t == 1) 94 | SerialL1.write(b); 95 | #endif 96 | } 97 | 98 | #endif // HAL_ARDUINO_AVR8_TERMINAL_OUTPUT 99 | 100 | #if HAL_ARDUINO_AVR8_TERMINAL_INPUT == HAL_ARDUINO_AVR8_TERMINAL_INPUT_SERIALLIGHT 101 | 102 | uint8_t 103 | HAL_terminal_read(HAL_terminal_t t) 104 | { 105 | if (t == 0) 106 | return SerialL.read(); 107 | #if defined(HAVE_HWSERIAL1) && (HAL_TERMINAL_NUM > 0) 108 | else if (t == 1) 109 | return SerialL1.read(); 110 | #endif 111 | return 0; 112 | } 113 | 114 | BOOLEAN 115 | HAL_terminal_isdataready(HAL_terminal_t t) 116 | { 117 | if (t == 0) 118 | return SerialL.available(); 119 | #if defined(HAVE_HWSERIAL1) && (HAL_TERMINAL_NUM > 0) 120 | else if (t == 1) 121 | return SerialL1.available(); 122 | #endif 123 | return FALSE; 124 | } 125 | #endif // HAL_ARDUINO_AVR8_TERMINAL_INPUT 126 | 127 | __BEGIN_DECLS 128 | void 129 | HAL_update_concrete() 130 | { 131 | } 132 | __END_DECLS 133 | 134 | #endif // ARDUINO_ARCH_AVR 135 | -------------------------------------------------------------------------------- /terminal-basic/HAL_avr8.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of Terminal-BASIC: a lightweight BASIC-like language 3 | * interpreter. 4 | * 5 | * Copyright (C) 2016-2018 Andrey V. Skvortsov 6 | * Copyright (C) 2019-2021 Terminal-BASIC team 7 | * 8 | * 9 | * This program is free software: you can redistribute it and/or modify 10 | * it under the terms of the GNU General Public License as published by 11 | * the Free Software Foundation, either version 3 of the License, or 12 | * (at your option) any later version. 13 | * 14 | * This program is distributed in the hope that it will be useful, 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | * GNU General Public License for more details. 18 | * 19 | * You should have received a copy of the GNU General Public License 20 | * along with this program. If not, see . 21 | */ 22 | 23 | /** 24 | * @brief Configuration for the Arduino core AVR8 HAL implementation 25 | */ 26 | 27 | #ifndef HAL_AVR8_H 28 | #define HAL_AVR8_H 29 | 30 | #include "HAL.h" 31 | 32 | #define HAL_ARDUINO_AVR8_TERMINAL_OUTPUT_NONE 0 33 | /* Use SerialL[N] objects for terminal */ 34 | #define HAL_ARDUINO_AVR8_TERMINAL_OUTPUT_SERIALLIGHT 1 35 | 36 | #define HAL_ARDUINO_AVR8_TERMINAL_OUTPUT HAL_ARDUINO_AVR8_TERMINAL_OUTPUT_SERIALLIGHT 37 | 38 | #define HAL_ARDUINO_AVR8_TERMINAL_INPUT_NONE 0 39 | /* Use SerialL[N] objects for terminal */ 40 | #define HAL_ARDUINO_AVR8_TERMINAL_INPUT_SERIALLIGHT 1 41 | 42 | #define HAL_ARDUINO_AVR8_TERMINAL_INPUT HAL_ARDUINO_AVR8_TERMINAL_INPUT_SERIALLIGHT 43 | 44 | #if HAL_ARDUINO_AVR8_TERMINAL == HAL_ARDUINO_AVR8_TERMINAL_SERIALLIGHT 45 | #define HAL_ARDUINO_AVR8_TERMINAL_SERIAL_0_BR 115200 46 | #if HAL_TERMINAL_NUM > 0 47 | #define HAL_ARDUINO_AVR8_TERMINAL_SERIAL_1_BR 115200 48 | #endif /* HAL_TERMINAL_NUM */ 49 | #if HAL_TERMINAL_NUM > 1 50 | #define HAL_ARDUINO_AVR8_TERMINAL_SERIAL_2_BR 115200 51 | #endif /* HAL_TERMINAL_NUM */ 52 | #if HAL_TERMINAL_NUM > 2 53 | #define HAL_ARDUINO_AVR8_TERMINAL_SERIAL_3_BR 115200 54 | #endif /* HAL_TERMINAL_NUM */ 55 | #endif /* HAL_ARDUINO_AVR8_TERMINAL */ 56 | 57 | // Use ATMega128/2560 external memory (SRAM) interface 58 | #define HAL_ARDUINO_AVR8_EXTMEM 0 59 | 60 | #endif /* HAL_ARDUINO_H */ 61 | -------------------------------------------------------------------------------- /terminal-basic/HAL_config.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of Terminal-BASIC: a lightweight BASIC-like language 3 | * interpreter. 4 | * 5 | * Copyright (C) 2016-2018 Andrey V. Skvortsov 6 | * Copyright (C) 2019-2021 Terminal-BASIC team 7 | * 8 | * 9 | * This program is free software: you can redistribute it and/or modify 10 | * it under the terms of the GNU General Public License as published by 11 | * the Free Software Foundation, either version 3 of the License, or 12 | * (at your option) any later version. 13 | * 14 | * This program is distributed in the hope that it will be useful, 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | * GNU General Public License for more details. 18 | * 19 | * You should have received a copy of the GNU General Public License 20 | * along with this program. If not, see . 21 | */ 22 | 23 | #ifndef HAL_CONFIG_H 24 | #define HAL_CONFIG_H 25 | 26 | /** 27 | * Number of available terminals 28 | */ 29 | #define HAL_TERMINAL_NUM 1 30 | 31 | /** 32 | * Zero-baszed index of active terminal for standard input/output 33 | * (not greater then HAL_TERMINAL_NUM-1) 34 | */ 35 | #define HAL_TERMINAL_STDIO 0 36 | 37 | /* 38 | * Enable NVRAM read/write functions 39 | * 40 | * NVRAM provides a single storage space, preserved between software runs 41 | */ 42 | #define HAL_NVRAM 1 43 | 44 | /* 45 | * Enable external memory interface 46 | * 47 | * External memory is a simple filesystem model 48 | */ 49 | #define HAL_EXTMEM 0 50 | #if HAL_EXTMEM 51 | /* 52 | * Maximal number of simulteniously opened files 53 | */ 54 | #define HAL_EXTMEM_NUM_FILES 2 55 | #endif /* HAL_EXTMEM */ 56 | 57 | /* 58 | * Enable GFX interface functions 59 | */ 60 | #define HAL_GFX 0 61 | #if HAL_GFX 62 | /* Default implementation of the explicit color setting commands */ 63 | #define HAL_GFX_EXPCOLOR_SIMPL 0 64 | 65 | #define HAL_GFX_COLOR_MONO 0 66 | #define HAL_GFX_COLOR_1BITPERC 1 67 | #define HAL_GFX_COLOR_2BITPERC 2 68 | #define HAL_GFX_COLOR_HIGH 3 69 | 70 | #define HAL_GFX_COLOR HAL_GFX_COLOR_2BITPERC 71 | 72 | #endif /* HAL_GFX */ 73 | 74 | #define HAL_GPIO 0 75 | 76 | #define HAL_BUZZER 0 77 | 78 | #endif /* HAL_CONFIG_H */ 79 | -------------------------------------------------------------------------------- /terminal-basic/HAL_esp32.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of Terminal-BASIC: a lightweight BASIC-like language 3 | * interpreter. 4 | * 5 | * Copyright (C) 2016-2018 Andrey V. Skvortsov 6 | * Copyright (C) 2019-2021 Terminal-BASIC team 7 | * 8 | * 9 | * This program is free software: you can redistribute it and/or modify 10 | * it under the terms of the GNU General Public License as published by 11 | * the Free Software Foundation, either version 3 of the License, or 12 | * (at your option) any later version. 13 | * 14 | * This program is distributed in the hope that it will be useful, 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | * GNU General Public License for more details. 18 | * 19 | * You should have received a copy of the GNU General Public License 20 | * along with this program. If not, see . 21 | */ 22 | 23 | /** 24 | * @brief Configuration for the Arduino core ESP32 HAL implementation 25 | */ 26 | 27 | #ifndef HAL_ESP32_H 28 | #define HAL_ESP32_H 29 | 30 | #include "HAL_arduino.h" 31 | 32 | #if HAL_NVRAM 33 | 34 | // Size of the SPIFFS file, used as NVRAM storage 35 | #define NVRAMSIZE 65536 36 | 37 | #endif /* HAL_NVRAM */ 38 | 39 | #if HAL_EXTMEM 40 | 41 | /** External memory implementations **/ 42 | /* SPIFFS external memory implementation */ 43 | #define HAL_ESP32_EXTEM_SPIFFS 1 44 | /* SD card external memory implementation */ 45 | #define HAL_ESP32_EXTEM_SD 2 46 | 47 | /* Used external memory implementation */ 48 | #define HAL_ESP32_EXTMEM HAL_ESP32_EXTEM_SD 49 | 50 | #endif /* HAL_EXTMEM */ 51 | 52 | void analogWrite(uint8_t, uint8_t); 53 | 54 | #if HAL_BUZZER 55 | 56 | #define HAL_BUZZER_ESP32_NONE 0 57 | #define HAL_BUZZER_ESP32_PWM 1 58 | 59 | #define HAL_BUZZER_ESP32 HAL_BUZZER_ESP32_PWM 60 | 61 | #endif /* HAL_BUZZER */ 62 | 63 | /* ODROID-GO Hardware support */ 64 | #define HAL_ESP32_ODROIDGO 0 65 | #if HAL_ESP32_ODROIDGO 66 | /* Use ODROID-GO qwerty keyboard for input */ 67 | #define HAL_ESP32_ODROIDGO_QWERTY 1 68 | #if HAL_GFX 69 | #define HAL_ESP32_ODROIDGO_GFX 1 70 | #endif 71 | #endif /* HAL_ESP32_ODROIDGO */ 72 | 73 | #endif /* HAL_ESP32_H */ 74 | -------------------------------------------------------------------------------- /terminal-basic/HAL_sam.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of Terminal-BASIC: a lightweight BASIC-like language 3 | * interpreter. 4 | * 5 | * Copyright (C) 2016-2018 Andrey V. Skvortsov 6 | * Copyright (C) 2019-2021 Terminal-BASIC team 7 | * 8 | * 9 | * This program is free software: you can redistribute it and/or modify 10 | * it under the terms of the GNU General Public License as published by 11 | * the Free Software Foundation, either version 3 of the License, or 12 | * (at your option) any later version. 13 | * 14 | * This program is distributed in the hope that it will be useful, 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | * GNU General Public License for more details. 18 | * 19 | * You should have received a copy of the GNU General Public License 20 | * along with this program. If not, see . 21 | */ 22 | 23 | #ifdef ARDUINO_ARCH_SAM 24 | 25 | #include "HAL.h" 26 | 27 | void 28 | HAL_initialize() 29 | { 30 | } 31 | 32 | void 33 | HAL_finalize() 34 | { 35 | } 36 | 37 | HAL_nvram_address_t HAL_nvram_getsize() 38 | { 39 | return 0; 40 | } 41 | 42 | uint8_t HAL_nvram_read(HAL_nvram_address_t) 43 | { 44 | return 0; 45 | } 46 | 47 | void HAL_nvram_write(HAL_nvram_address_t, uint8_t) 48 | { 49 | } 50 | 51 | #endif // ARDUINO_ARCH_SAM 52 | -------------------------------------------------------------------------------- /terminal-basic/_HAL_arduino.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of Terminal-BASIC: a lightweight BASIC-like language 3 | * interpreter. 4 | * 5 | * Copyright (C) 2016-2018 Andrey V. Skvortsov 6 | * Copyright (C) 2019-2021 Terminal-BASIC team 7 | * 8 | * 9 | * This program is free software: you can redistribute it and/or modify 10 | * it under the terms of the GNU General Public License as published by 11 | * the Free Software Foundation, either version 3 of the License, or 12 | * (at your option) any later version. 13 | * 14 | * This program is distributed in the hope that it will be useful, 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | * GNU General Public License for more details. 18 | * 19 | * You should have received a copy of the GNU General Public License 20 | * along with this program. If not, see . 21 | */ 22 | 23 | #ifndef _HAL_ARDUINO_H 24 | #define _HAL_ARDUINO_H 25 | 26 | /** Output devices **/ 27 | 28 | /* Output not used */ 29 | #define HAL_ARDUINO_TERMINAL_OUTPUT_NONE 0 30 | /* Use Serial[N] objects for output */ 31 | #define HAL_ARDUINO_TERMINAL_OUTPUT_SERIAL 1 32 | /* Use Adafruit GFX library for 240x320 ILI9341 tft displays */ 33 | #define HAL_ARDUINO_TERMINAL_OUTPUT_ILI9341 2 34 | /* Use Use TFT_eSPI library */ 35 | #define HAL_ARDUINO_TERMINAL_OUTPUT_TFTeSPI 3 36 | 37 | /** Input devices */ 38 | 39 | /* Do not use input device (implemented outside) */ 40 | #define HAL_ARDUINO_TERMINAL_INPUT_NONE 0 41 | /* Serial[N] objects from arduino library */ 42 | #define HAL_ARDUINO_TERMINAL_INPUT_SERIAL 1 43 | /* PS/2 keyboard using libkbddup */ 44 | #define HAL_ARDUINO_TERMINAL_INPUT_PS2KBD 2 45 | 46 | /** GFX-implementation **/ 47 | 48 | /* No GFX implementation (implemented outside) */ 49 | #define HAL_ARDUINO_GFX_NONE 0 50 | /* Serial 2-mode graphics protocol HAL GFX implementation */ 51 | #define HAL_ARDUINO_GFX_SERIAL 1 52 | /* UTFT HAL GFX implementation */ 53 | #define HAL_ARDUINO_GFX_UTFT 2 54 | /* Implementation based on Adafruit lib for ILI9341 displays */ 55 | #define HAL_ARDUINO_GFX_ILI9341 3 56 | /* TFTeSPI library implementation */ 57 | #define HAL_ARDUINO_GFX_TFTeSPI 4 58 | 59 | /** External memory (storage) implementation **/ 60 | #define HAL_ARDUINO_EXTMEM_NONE 0 61 | /* Standart SD library implementation */ 62 | #define HAL_ARDUINO_EXTMEM_SD 1 63 | /* SDFS HAL extmem implementation */ 64 | #define HAL_ARDUINO_EXTMEM_SDFS 2 65 | /* I2C eeprom HAL extmem implementation */ 66 | #define HAL_ARDUINO_EXTMEM_I2CEEPROM 3 67 | 68 | /** GPIO implementations **/ 69 | 70 | /* No GPIO implementation */ 71 | #define HAL_GPIO_ARDUINO_NONE 0 72 | /* Implementation based on Arduino-core functions (digitalRead, digitalWrite...) */ 73 | #define HAL_GPIO_ARDUINO_CORE 1 74 | 75 | /** Buzzer implementation **/ 76 | 77 | /* No buzzer implementation */ 78 | #define HAL_BUZZER_ARDUINO_NONE 0 79 | /* Implementation, base4d on tone function */ 80 | #define HAL_BUZZER_ARDUINO_TONE 1 81 | 82 | #endif /* _HAL_ARDUINO_H */ 83 | -------------------------------------------------------------------------------- /terminal-basic/_basic_config.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of Terminal-BASIC: a lightweight BASIC-like language 3 | * interpreter. 4 | * 5 | * Copyright (C) 2016-2018 Andrey V. Skvortsov 6 | * Copyright (C) 2019-2021 Terminal-BASIC team 7 | * 8 | * 9 | * This program is free software: you can redistribute it and/or modify 10 | * it under the terms of the GNU General Public License as published by 11 | * the Free Software Foundation, either version 3 of the License, or 12 | * (at your option) any later version. 13 | * 14 | * This program is distributed in the hope that it will be useful, 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | * GNU General Public License for more details. 18 | * 19 | * You should have received a copy of the GNU General Public License 20 | * along with this program. If not, see . 21 | */ 22 | 23 | #ifndef _BASIC_CONFIG_H 24 | #define _BASIC_CONFIG_H 25 | 26 | /* 27 | * Language constants for later usage 28 | */ 29 | #define LANG_EN 0 /* English */ 30 | #define LANG_RU 1 /* Russian */ 31 | #define LANG_FR 3 /* French */ 32 | 33 | #define OPT_SPEED 1 /* Extensive usage of switch/case constructs */ 34 | #define OPT_SIZE 2 /* Use cascade of if/else if instead of switch/case */ 35 | 36 | #endif /* _BASIC_CONFIG_H */ 37 | 38 | -------------------------------------------------------------------------------- /terminal-basic/_tokens_en.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of Terminal-BASIC: a lightweight BASIC-like language 3 | * interpreter. 4 | * 5 | * Copyright (C) 2016-2018 Andrey V. Skvortsov 6 | * Copyright (C) 2019-2021 Terminal-BASIC team 7 | * 8 | * 9 | * This program is free software: you can redistribute it and/or modify 10 | * it under the terms of the GNU General Public License as published by 11 | * the Free Software Foundation, either version 3 of the License, or 12 | * (at your option) any later version. 13 | * 14 | * This program is distributed in the hope that it will be useful, 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | * GNU General Public License for more details. 18 | * 19 | * You should have received a copy of the GNU General Public License 20 | * along with this program. If not, see . 21 | */ 22 | 23 | #include "basic.h" 24 | 25 | /** 26 | * @brief lexical tokens 27 | */ 28 | typedef enum basic_token 29 | { 30 | BASIC_TOKEN_NOTOKEN = 0, // 0 31 | BASIC_TOKEN_OP_AND, // 1 32 | #if USE_DUMP 33 | BASIC_TOKEN_KW_ARRAYS, // 2 34 | #endif 35 | #if USE_SAVE_LOAD 36 | BASIC_TOKEN_COM_CHAIN, // 3 37 | #endif 38 | #if USE_TEXTATTRIBUTES 39 | BASIC_TOKEN_COM_CLS, // 4 40 | #endif 41 | #if USESTOPCONT 42 | BASIC_TOKEN_COM_CONT, // 6 43 | #endif 44 | #if USE_MATRIX 45 | BASIC_TOKEN_KW_CON, // 7 46 | #endif 47 | #if USE_DATA 48 | BASIC_TOKEN_KW_DATA, // 8 49 | #endif 50 | #if USE_DEFFN 51 | BASIC_TOKEN_KW_DEF, // 9 52 | #endif 53 | #if USE_DELAY 54 | BASIC_TOKEN_COM_DELAY, // 10 55 | #endif 56 | #if USE_MATRIX 57 | BASIC_TOKEN_KW_DET, // 11 58 | #endif 59 | BASIC_TOKEN_KW_DIM, // 12 60 | #if USE_DIV_KW 61 | BASIC_TOKEN_KW_DIV, // 13 62 | #endif 63 | #if USE_DUMP 64 | BASIC_TOKEN_COM_DUMP, // 15 65 | #endif 66 | BASIC_TOKEN_KW_END, // 16 67 | BASIC_TOKEN_KW_FALSE, // 17 68 | #if USE_DEFFN 69 | BASIC_TOKEN_KW_FN, // 18 70 | #endif 71 | BASIC_TOKEN_KW_FOR, // 19 72 | BASIC_TOKEN_KW_GOSUB, // 20 73 | BASIC_TOKEN_KW_GOTO, // 21 74 | #if CONF_SEPARATE_GO_TO 75 | BASIC_TOKEN_KW_GO, // 22 76 | #endif 77 | #if USE_MATRIX 78 | BASIC_TOKEN_KW_IDN, // 23 79 | #endif 80 | BASIC_TOKEN_KW_IF, // 24 81 | BASIC_TOKEN_KW_INPUT, // 25 82 | #if USE_MATRIX 83 | BASIC_TOKEN_KW_INV, // 26 84 | #endif 85 | BASIC_TOKEN_KW_LET, // 27 86 | BASIC_TOKEN_COM_LIST, // 28 87 | #if USE_SAVE_LOAD 88 | BASIC_TOKEN_COM_LOAD, // 29 89 | #endif 90 | #if USE_TEXTATTRIBUTES 91 | BASIC_TOKEN_COM_LOCATE, // 30 92 | #endif 93 | #if USE_MATRIX 94 | BASIC_TOKEN_KW_MAT, // 32 95 | #endif 96 | #if USE_INTEGER_DIV 97 | BASIC_TOKEN_KW_MOD, // 33 98 | #endif 99 | BASIC_TOKEN_COM_NEW, // 34 100 | BASIC_TOKEN_KW_NEXT, // 35 101 | BASIC_TOKEN_OP_NOT, // 36 102 | #if CONF_USE_ON_GOTO 103 | BASIC_TOKEN_KW_ON, // 37 104 | #endif 105 | // KW_OPTION, 106 | BASIC_TOKEN_OP_OR, // 38 107 | #if USE_PEEK_POKE 108 | BASIC_TOKEN_KW_POKE, // 39 109 | #endif 110 | BASIC_TOKEN_KW_PRINT, // 40 111 | #if USE_RANDOM 112 | BASIC_TOKEN_KW_RANDOMIZE, // 41 113 | #endif 114 | #if USE_DATA 115 | BASIC_TOKEN_KW_READ, // 42 116 | #endif 117 | BASIC_TOKEN_KW_REM, // 43 118 | #if USE_DATA 119 | BASIC_TOKEN_KW_RESTORE, // 44 120 | #endif 121 | BASIC_TOKEN_KW_RETURN, // 45 122 | BASIC_TOKEN_COM_RUN, // 46 123 | #if USE_SAVE_LOAD 124 | BASIC_TOKEN_COM_SAVE, // 47 125 | #endif 126 | #if CONF_USE_SPC_PRINT_COM 127 | BASIC_TOKEN_KW_SPC, // 48 128 | #endif 129 | BASIC_TOKEN_KW_STEP, // 49 130 | #if USESTOPCONT 131 | BASIC_TOKEN_KW_STOP, // 50 132 | #endif 133 | #if USE_TEXTATTRIBUTES 134 | BASIC_TOKEN_KW_TAB, // 51 135 | #endif 136 | BASIC_TOKEN_KW_THEN, // 52 137 | BASIC_TOKEN_KW_TO, // 53 138 | #if USE_MATRIX 139 | BASIC_TOKEN_KW_TRN, // 54 140 | #endif 141 | BASIC_TOKEN_KW_TRUE, // 55 142 | #if USE_DUMP 143 | BASIC_TOKEN_KW_VARS, // 56 144 | #endif 145 | BASIC_TOKEN_OP_XOR, // 57 146 | #if USE_MATRIX 147 | BASIC_TOKEN_KW_ZER, // 58 148 | #endif 149 | // * 150 | BASIC_TOKEN_STAR, // 59 151 | // / 152 | BASIC_TOKEN_SLASH, // 50 153 | #if USE_REALS && USE_INTEGER_DIV 154 | BASIC_TOKEN_BACK_SLASH, // 61 155 | #endif 156 | // + 157 | BASIC_TOKEN_PLUS, // 62 158 | // - 159 | BASIC_TOKEN_MINUS, // 63 160 | // = 161 | BASIC_TOKEN_EQUALS, // 64 162 | // : 163 | BASIC_TOKEN_COLON, // 65 164 | // ; 165 | BASIC_TOKEN_SEMI, // 66 166 | // < 167 | BASIC_TOKEN_LT, // 67 168 | // > 169 | BASIC_TOKEN_GT, // 68 170 | // <= 171 | BASIC_TOKEN_LTE, // 69 172 | // >= 173 | BASIC_TOKEN_GTE, // 70 174 | // <> 175 | BASIC_TOKEN_NE, // 71 176 | #if CONF_USE_ALTERNATIVE_NE 177 | // >< 178 | BASIC_TOKEN_NEA, // 72 179 | #endif 180 | // , 181 | BASIC_TOKEN_COMMA, // 73 182 | // ^ 183 | BASIC_TOKEN_POW, // 74 184 | // ( 185 | BASIC_TOKEN_LPAREN, // 75 186 | // ) 187 | BASIC_TOKEN_RPAREN, // 76 188 | 189 | BASIC_TOKEN_INTEGER_IDENT, // 77 190 | BASIC_TOKEN_REAL_IDENT, // 78 191 | #if USE_LONG_REALS 192 | BASIC_TOKEN_LONG_REAL_IDENT,// 79 193 | #endif 194 | #if USE_LONGINT 195 | BASIC_TOKEN_LONGINT_IDENT, // 80 196 | #endif 197 | BASIC_TOKEN_STRING_IDENT, // 81 198 | BASIC_TOKEN_BOOL_IDENT, // 82 199 | 200 | BASIC_TOKEN_C_INTEGER, // 83 201 | #if USE_LONGINT 202 | BASIC_TOKEN_C_LONG_INTEGER,// 83 203 | #endif 204 | BASIC_TOKEN_C_REAL, // 84 205 | #if USE_LONG_REALS 206 | BASIC_TOKEN_C_LONG_REAL, // 85 207 | #endif 208 | BASIC_TOKEN_C_BOOLEAN, // 86 209 | BASIC_TOKEN_C_STRING, // 87 210 | #if FAST_MODULE_CALL 211 | BASIC_TOKEN_COMMAND, // 88 212 | #endif 213 | BASIC_TOKEN_NUM_TOKENS // 89 214 | } basic_token_t; 215 | -------------------------------------------------------------------------------- /terminal-basic/_tokens_fr.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of Terminal-BASIC: a lightweight BASIC-like language 3 | * interpreter. 4 | * 5 | * Copyright (C) 2016-2018 Andrey V. Skvortsov 6 | * Copyright (C) 2019-2021 Terminal-BASIC team 7 | * 8 | * 9 | * This program is free software: you can redistribute it and/or modify 10 | * it under the terms of the GNU General Public License as published by 11 | * the Free Software Foundation, either version 3 of the License, or 12 | * (at your option) any later version. 13 | * 14 | * This program is distributed in the hope that it will be useful, 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | * GNU General Public License for more details. 18 | * 19 | * You should have received a copy of the GNU General Public License 20 | * along with this program. If not, see . 21 | */ 22 | 23 | #include "basic.h" 24 | 25 | /** 26 | * @brief lexical tokens 27 | */ 28 | typedef enum basic_token 29 | { 30 | BASIC_TOKEN_NOTOKEN = 0, // 0 31 | BASIC_TOKEN_KW_GOTO, // 1 32 | BASIC_TOKEN_KW_GOSUB, // 2 33 | BASIC_TOKEN_KW_THEN, // 3 34 | BASIC_TOKEN_OP_AND, // 4 35 | #if USE_DUMP 36 | BASIC_TOKEN_KW_ARRAYS, // 5 37 | #endif 38 | #if USE_SAVE_LOAD 39 | BASIC_TOKEN_COM_CHAIN, // 6 40 | #endif 41 | #if USE_TEXTATTRIBUTES 42 | BASIC_TOKEN_COM_CLS, // 7 43 | #endif 44 | #if USESTOPCONT 45 | BASIC_TOKEN_COM_CONT, // 8 46 | #endif 47 | #if USE_MATRIX 48 | BASIC_TOKEN_KW_CON, // 9 49 | #endif 50 | #if USE_DATA 51 | BASIC_TOKEN_KW_DATA, // 10 52 | #endif 53 | #if USE_DEFFN 54 | BASIC_TOKEN_KW_DEF, // 11 55 | #endif 56 | #if USE_DELAY 57 | BASIC_TOKEN_COM_DELAY, // 12 58 | #endif 59 | #if USE_MATRIX 60 | BASIC_TOKEN_KW_DET, // 13 61 | #endif 62 | BASIC_TOKEN_KW_DIM, // 14 63 | #if USE_DIV_KW 64 | BASIC_TOKEN_KW_DIV, // 15 65 | #endif 66 | #if USE_DUMP 67 | BASIC_TOKEN_COM_DUMP, // 16 68 | #endif 69 | #if CONF_USE_ON_GOTO 70 | BASIC_TOKEN_KW_ON, // 17 71 | #endif 72 | BASIC_TOKEN_KW_FALSE, // 18 73 | BASIC_TOKEN_KW_END, // 19 74 | #if USE_DEFFN 75 | BASIC_TOKEN_KW_FN, // 20 76 | #endif 77 | #if CONF_SEPARATE_GO_TO 78 | BASIC_TOKEN_KW_GO, // 21 79 | #endif 80 | #if USE_MATRIX 81 | BASIC_TOKEN_KW_IDN, // 22 82 | #endif 83 | BASIC_TOKEN_KW_INPUT, // 23 84 | #if USE_MATRIX 85 | BASIC_TOKEN_KW_INV, // 24 86 | #endif 87 | BASIC_TOKEN_KW_TO, // 25 88 | BASIC_TOKEN_KW_LET, // 26 89 | BASIC_TOKEN_COM_LIST, // 27 90 | #if USE_SAVE_LOAD 91 | BASIC_TOKEN_COM_LOAD, // 28 92 | #endif 93 | #if USE_TEXTATTRIBUTES 94 | BASIC_TOKEN_COM_LOCATE, // 29 95 | #endif 96 | #if USE_MATRIX 97 | BASIC_TOKEN_KW_MAT, // 30 98 | #endif 99 | #if USE_INTEGER_DIV 100 | BASIC_TOKEN_KW_MOD, // 31 101 | #endif 102 | BASIC_TOKEN_COM_NEW, // 32 103 | BASIC_TOKEN_OP_NOT, // 34 104 | // KW_OPTION, 105 | BASIC_TOKEN_OP_OR, 106 | #if USE_PEEK_POKE 107 | BASIC_TOKEN_KW_POKE, 108 | #endif 109 | BASIC_TOKEN_KW_FOR, // 36 110 | BASIC_TOKEN_KW_PRINT, // 37 111 | #if USE_RANDOM 112 | BASIC_TOKEN_KW_RANDOMIZE, // 38 113 | #endif 114 | #if USE_DATA 115 | BASIC_TOKEN_KW_READ, // 39 116 | #endif 117 | BASIC_TOKEN_KW_REM, // 43 118 | #if USE_DATA 119 | BASIC_TOKEN_KW_RESTORE, // 44 120 | #endif 121 | BASIC_TOKEN_KW_RETURN, // 45 122 | BASIC_TOKEN_COM_RUN, // 46 123 | #if USE_SAVE_LOAD 124 | BASIC_TOKEN_COM_SAVE, // 47 125 | #endif 126 | BASIC_TOKEN_KW_IF, // 22 127 | #if CONF_USE_SPC_PRINT_COM 128 | BASIC_TOKEN_KW_SPC, // 48 129 | #endif 130 | BASIC_TOKEN_KW_STEP, // 49 131 | #if USESTOPCONT 132 | BASIC_TOKEN_KW_STOP, // 50 133 | #endif 134 | BASIC_TOKEN_KW_NEXT, // 33 135 | #if USE_TEXTATTRIBUTES 136 | BASIC_TOKEN_KW_TAB, // 51 137 | #endif 138 | #if USE_MATRIX 139 | BASIC_TOKEN_KW_TRN, // 54 140 | #endif 141 | BASIC_TOKEN_KW_TRUE, // 55 142 | #if USE_DUMP 143 | BASIC_TOKEN_KW_VARS, // 56 144 | #endif 145 | BASIC_TOKEN_OP_XOR, // 57 146 | #if USE_MATRIX 147 | BASIC_TOKEN_KW_ZER, // 58 148 | #endif 149 | // * 150 | BASIC_TOKEN_STAR, // 59 151 | // / 152 | BASIC_TOKEN_SLASH, // 50 153 | #if USE_REALS && USE_INTEGER_DIV 154 | BASIC_TOKEN_BACK_SLASH, // 61 155 | #endif 156 | // + 157 | BASIC_TOKEN_PLUS, // 62 158 | // - 159 | BASIC_TOKEN_MINUS, // 63 160 | // = 161 | BASIC_TOKEN_EQUALS, // 64 162 | // : 163 | BASIC_TOKEN_COLON, // 65 164 | // ; 165 | BASIC_TOKEN_SEMI, // 66 166 | // < 167 | BASIC_TOKEN_LT, // 67 168 | // > 169 | BASIC_TOKEN_GT, // 68 170 | // <= 171 | BASIC_TOKEN_LTE, // 69 172 | // >= 173 | BASIC_TOKEN_GTE, // 70 174 | // <> 175 | BASIC_TOKEN_NE, // 71 176 | #if CONF_USE_ALTERNATIVE_NE 177 | // >< 178 | BASIC_TOKEN_NEA, // 72 179 | #endif 180 | // , 181 | BASIC_TOKEN_COMMA, // 73 182 | // ^ 183 | BASIC_TOKEN_POW, // 74 184 | // ( 185 | BASIC_TOKEN_LPAREN, // 75 186 | // ) 187 | BASIC_TOKEN_RPAREN, // 76 188 | 189 | BASIC_TOKEN_INTEGER_IDENT, // 77 190 | BASIC_TOKEN_REAL_IDENT, // 78 191 | #if USE_LONG_REALS 192 | BASIC_TOKEN_LONG_REAL_IDENT,// 85 193 | #endif 194 | #if USE_LONGINT // 79 195 | BASIC_TOKEN_LONGINT_IDENT, // 80 196 | #endif 197 | BASIC_TOKEN_STRING_IDENT, // 81 198 | BASIC_TOKEN_BOOL_IDENT, // 82 199 | 200 | BASIC_TOKEN_C_INTEGER, // 83 201 | #if USE_LONGINT 202 | BASIC_TOKEN_C_LONG_INTEGER,// 83 203 | #endif 204 | BASIC_TOKEN_C_REAL, // 84 205 | #if USE_LONG_REALS 206 | BASIC_TOKEN_C_LONG_REAL, // 85 207 | #endif 208 | BASIC_TOKEN_C_BOOLEAN, // 86 209 | BASIC_TOKEN_C_STRING, // 87 210 | #if FAST_MODULE_CALL 211 | BASIC_TOKEN_COMMAND, // 88 212 | #endif 213 | BASIC_TOKEN_NUM_TOKENS // 88 214 | } basic_token_t; 215 | -------------------------------------------------------------------------------- /terminal-basic/_tokens_ru.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of Terminal-BASIC: a lightweight BASIC-like language 3 | * interpreter. 4 | * 5 | * Copyright (C) 2016-2018 Andrey V. Skvortsov 6 | * Copyright (C) 2019-2021 Terminal-BASIC team 7 | * 8 | * 9 | * This program is free software: you can redistribute it and/or modify 10 | * it under the terms of the GNU General Public License as published by 11 | * the Free Software Foundation, either version 3 of the License, or 12 | * (at your option) any later version. 13 | * 14 | * This program is distributed in the hope that it will be useful, 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | * GNU General Public License for more details. 18 | * 19 | * You should have received a copy of the GNU General Public License 20 | * along with this program. If not, see . 21 | */ 22 | 23 | #include "basic.h" 24 | 25 | /** 26 | * @brief lexical tokens 27 | */ 28 | typedef enum basic_token 29 | { 30 | BASIC_TOKEN_NOTOKEN = 0, // 0 31 | #if USE_DUMP 32 | BASIC_TOKEN_KW_ARRAYS, // 2 33 | #endif 34 | #if USE_SAVE_LOAD 35 | BASIC_TOKEN_COM_CHAIN, // 3 36 | #endif 37 | #if USE_TEXTATTRIBUTES 38 | BASIC_TOKEN_COM_CLS, // 4 39 | #endif 40 | #if USESTOPCONT 41 | BASIC_TOKEN_COM_CONT, // 6 42 | #endif 43 | #if USE_MATRIX 44 | BASIC_TOKEN_KW_CON, // 7 45 | #endif 46 | #if USE_DELAY 47 | BASIC_TOKEN_COM_DELAY, // 10 48 | #endif 49 | #if USE_MATRIX 50 | BASIC_TOKEN_KW_DET, // 11 51 | #endif 52 | #if USE_DIV_KW 53 | BASIC_TOKEN_KW_DIV, // 13 54 | #endif 55 | #if USE_DUMP 56 | BASIC_TOKEN_COM_DUMP, // 15 57 | #endif 58 | BASIC_TOKEN_KW_FALSE, // 17 59 | BASIC_TOKEN_KW_GOSUB, // 20 60 | #if CONF_SEPARATE_GO_TO 61 | BASIC_TOKEN_KW_GO, // 22 62 | #endif 63 | #if USE_MATRIX 64 | BASIC_TOKEN_KW_IDN, // 23 65 | BASIC_TOKEN_KW_INV, // 26 66 | #endif 67 | #if USE_SAVE_LOAD 68 | BASIC_TOKEN_COM_LOAD, // 29 69 | #endif 70 | #if USE_TEXTATTRIBUTES 71 | BASIC_TOKEN_COM_LOCATE, // 30 72 | #endif 73 | #if USE_INTEGER_DIV 74 | BASIC_TOKEN_KW_MOD, // 33 75 | #endif 76 | // KW_OPTION, // 38 77 | #if USE_PEEK_POKE 78 | BASIC_TOKEN_KW_POKE, 79 | #endif 80 | #if USE_RANDOM 81 | BASIC_TOKEN_KW_RANDOMIZE, // 41 82 | #endif 83 | #if USE_SAVE_LOAD 84 | BASIC_TOKEN_COM_SAVE, // 47 85 | #endif 86 | #if CONF_USE_SPC_PRINT_COM 87 | BASIC_TOKEN_KW_SPC, // 48 88 | #endif 89 | #if USE_TEXTATTRIBUTES 90 | BASIC_TOKEN_KW_TAB, // 51 91 | #endif 92 | #if USE_MATRIX 93 | BASIC_TOKEN_KW_TRN, // 54 94 | #endif 95 | BASIC_TOKEN_KW_TRUE, // 55 96 | #if USE_DUMP 97 | BASIC_TOKEN_KW_VARS, // 56 98 | #endif 99 | BASIC_TOKEN_OP_XOR, // 57 100 | #if USE_MATRIX 101 | BASIC_TOKEN_KW_ZER, // 58 102 | #endif 103 | BASIC_TOKEN_KW_INPUT, 104 | #if USE_DATA 105 | BASIC_TOKEN_KW_READ, 106 | #endif 107 | BASIC_TOKEN_KW_RETURN, 108 | BASIC_TOKEN_KW_PRINT, 109 | #if USE_DATA 110 | BASIC_TOKEN_KW_DATA, 111 | #endif 112 | BASIC_TOKEN_KW_FOR, 113 | BASIC_TOKEN_KW_TO, 114 | BASIC_TOKEN_KW_IF, 115 | BASIC_TOKEN_OP_OR, 116 | BASIC_TOKEN_OP_AND, 117 | BASIC_TOKEN_KW_REM, 118 | BASIC_TOKEN_KW_END, 119 | BASIC_TOKEN_COM_LIST, 120 | #if USE_MATRIX 121 | BASIC_TOKEN_KW_MAT, // 32 122 | #endif 123 | BASIC_TOKEN_KW_GOTO, 124 | BASIC_TOKEN_OP_NOT, 125 | BASIC_TOKEN_COM_NEW, // 34 126 | #if USE_DEFFN 127 | BASIC_TOKEN_KW_DEF, 128 | #endif 129 | #if CONF_USE_ON_GOTO 130 | BASIC_TOKEN_KW_ON, 131 | #endif 132 | BASIC_TOKEN_COM_RUN, 133 | BASIC_TOKEN_KW_LET, 134 | BASIC_TOKEN_KW_DIM, 135 | #if USE_DATA 136 | BASIC_TOKEN_KW_RESTORE, 137 | #endif 138 | #if USESTOPCONT 139 | BASIC_TOKEN_KW_STOP, 140 | #endif 141 | BASIC_TOKEN_KW_THEN, 142 | #if USE_DEFFN 143 | BASIC_TOKEN_KW_FN, 144 | #endif 145 | BASIC_TOKEN_KW_NEXT, 146 | BASIC_TOKEN_KW_STEP, 147 | 148 | // * 149 | BASIC_TOKEN_STAR, // 59 150 | // / 151 | BASIC_TOKEN_SLASH, // 50 152 | #if USE_REALS && USE_INTEGER_DIV 153 | BASIC_TOKEN_BACK_SLASH, // 61 154 | #endif 155 | // + 156 | BASIC_TOKEN_PLUS, // 62 157 | // - 158 | BASIC_TOKEN_MINUS, // 63 159 | // = 160 | BASIC_TOKEN_EQUALS, // 64 161 | // : 162 | BASIC_TOKEN_COLON, // 65 163 | // ; 164 | BASIC_TOKEN_SEMI, // 66 165 | // < 166 | BASIC_TOKEN_LT, // 67 167 | // > 168 | BASIC_TOKEN_GT, // 68 169 | // <= 170 | BASIC_TOKEN_LTE, // 69 171 | // >= 172 | BASIC_TOKEN_GTE, // 70 173 | // <> 174 | BASIC_TOKEN_NE, // 71 175 | #if CONF_USE_ALTERNATIVE_NE 176 | // >< 177 | BASIC_TOKEN_NEA, // 72 178 | #endif 179 | // , 180 | BASIC_TOKEN_COMMA, // 73 181 | // ^ 182 | BASIC_TOKEN_POW, // 74 183 | // ( 184 | BASIC_TOKEN_LPAREN, // 75 185 | // ) 186 | BASIC_TOKEN_RPAREN, // 76 187 | 188 | BASIC_TOKEN_INTEGER_IDENT, // 77 189 | BASIC_TOKEN_REAL_IDENT, // 78 190 | #if USE_LONG_REALS 191 | BASIC_TOKEN_LONG_REAL_IDENT,// 85 192 | #endif 193 | #if USE_LONGINT // 79 194 | BASIC_TOKEN_LONGINT_IDENT, // 80 195 | #endif 196 | BASIC_TOKEN_STRING_IDENT, // 81 197 | BASIC_TOKEN_BOOL_IDENT, // 82 198 | 199 | BASIC_TOKEN_C_INTEGER, // 83 200 | BASIC_TOKEN_C_LONG_INTEGER,// 83 201 | BASIC_TOKEN_C_REAL, // 84 202 | #if USE_LONG_REALS 203 | BASIC_TOKEN_C_LONG_REAL, // 85 204 | #endif 205 | BASIC_TOKEN_C_BOOLEAN, // 85 206 | BASIC_TOKEN_C_STRING, // 86 207 | #if FAST_MODULE_CALL 208 | BASIC_TOKEN_COMMAND, // 88 209 | #endif 210 | BASIC_TOKEN_NUM_TOKENS // 87 211 | } basic_token_t; 212 | -------------------------------------------------------------------------------- /terminal-basic/arduino_logger.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * ArduinoExt is a set of utility libraries for Arduino 3 | * 4 | * Copyright (C) 2016-2018 Andrey V. Skvortsov 5 | * Copyright (C) 2019,2021 Terminal-BASIC team 6 | * 7 | * 8 | * This program is free software: is free software: you can redistribute it and/or 9 | * modify it under the terms of the GNU Lesser General Public License 10 | * as published by the Free Software Foundation, either version 3 of 11 | * the License, or (at your option) any later version. 12 | 13 | * ArduinoExt library is distributed in the hope that it will be useful, 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | * GNU General Public License for more details. 17 | 18 | * You should have received a copy of the GNU Lesser General Public 19 | * License along with Posixcpp library. If not, see 20 | * . 21 | */ 22 | 23 | #ifndef ARDUINO_LOGGER_HPP 24 | #define ARDUINO_LOGGER_HPP 25 | 26 | #include 27 | 28 | #include "arduinoext.hpp" 29 | #include "Stream.h" 30 | #include "Arduino.h" 31 | 32 | #define ARDUINO_LOG 0 33 | 34 | #if ARDUINO_LOG 35 | #define LOG_INIT(T) Logger::init(T) 36 | #define LOG(args...) Logger::log(args) 37 | #define LOG_TRACE LOG(__PRETTY_FUNCTION__) 38 | #else 39 | #define LOG_INIT(T) 40 | #define LOG(...) 41 | #define LOG_TRACE 42 | #endif 43 | 44 | Package(Logger) { 45 | public: 46 | 47 | enum class format_t 48 | { 49 | bin = 2, dec = 10, oct = 8, hex = 16, endl 50 | }; 51 | 52 | static void init(Stream&); 53 | 54 | template 55 | static void log(const Args&... args) 56 | { 57 | _log(args...); 58 | _instance._stream->println(); 59 | } 60 | 61 | private: 62 | 63 | friend Logger &operator<<(Logger &logger, format_t formaat) 64 | { 65 | logger._format = formaat; 66 | return logger; 67 | } 68 | 69 | friend Logger &operator<<(Logger &logger, const Printable &p) { 70 | logger._stream->print(p); 71 | return logger.delimiter(); 72 | } 73 | 74 | friend Logger &operator<<(Logger &logger, uint32_t val) { 75 | logger._stream->print(val, int(_format)); 76 | return logger.delimiter(); 77 | } 78 | 79 | friend Logger &operator<<(Logger &logger, int32_t val) { 80 | logger._stream->print(val, int(_format)); 81 | return logger.delimiter(); 82 | } 83 | 84 | friend Logger &operator<<(Logger &logger, uint16_t val) { 85 | logger._stream->print(val, int(_format)); 86 | return logger.delimiter(); 87 | } 88 | 89 | friend Logger &operator<<(Logger &logger, int16_t val) { 90 | logger._stream->print(val, int(_format)); 91 | return logger.delimiter(); 92 | } 93 | 94 | friend Logger &operator<<(Logger &logger, uint8_t val) { 95 | logger._stream->print(val, int(_format)); 96 | return logger.delimiter(); 97 | } 98 | 99 | friend Logger &operator<<(Logger &logger, int8_t val) { 100 | logger._stream->print(val, int(_format)); 101 | return logger.delimiter(); 102 | } 103 | 104 | friend Logger &operator<<(Logger &logger, const char* first) { 105 | logger._stream->print(first); 106 | return logger.delimiter(); 107 | } 108 | 109 | friend Logger &operator<<(Logger &logger, char* first) { 110 | logger._stream->print(first); 111 | return logger.delimiter(); 112 | } 113 | 114 | template 115 | friend Logger &operator<<(Logger &logger, T *first) 116 | { 117 | logger._stream->print(intptr_t(first), 16); 118 | return logger.delimiter(); 119 | } 120 | 121 | template 122 | friend Logger &operator<<(Logger &logger, T first) 123 | { 124 | logger._stream->print(first); 125 | return logger.delimiter(); 126 | } 127 | 128 | template 129 | static void _log(T first) 130 | { 131 | _instance << first; 132 | } 133 | 134 | template 135 | static void _log(T first, const Args&... args) 136 | { 137 | _log(first); 138 | _log(args...); 139 | } 140 | 141 | Logger &delimiter() 142 | { 143 | _instance._stream->print(" "); 144 | return *this; 145 | } 146 | 147 | static Logger _instance; 148 | 149 | static format_t _format; 150 | 151 | Stream *_stream; 152 | }; 153 | 154 | #endif 155 | -------------------------------------------------------------------------------- /terminal-basic/arduinoext.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * ArduinoExt is a set of utility libraries for Arduino 3 | * 4 | * Copyright (C) 2016-2018 Andrey V. Skvortsov 5 | * Copyright (C) 2019,2021 Terminal-BASIC team 6 | * 7 | * 8 | * This program is free software: is free software: you can redistribute it and/or 9 | * modify it under the terms of the GNU Lesser General Public License 10 | * as published by the Free Software Foundation, either version 3 of 11 | * the License, or (at your option) any later version. 12 | 13 | * ArduinoExt library is distributed in the hope that it will be useful, 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | * GNU General Public License for more details. 17 | 18 | * You should have received a copy of the GNU Lesser General Public 19 | * License along with Posixcpp library. If not, see 20 | * . 21 | */ 22 | 23 | #ifndef EXT_HPP 24 | #define EXT_HPP 25 | 26 | #if __cplusplus < 201103L 27 | #error This file requires C++11-able compiler 28 | #endif 29 | 30 | // Packed data object 31 | #define EXT_PACKED __attribute__ ((__packed__)) 32 | 33 | // Class of not copyable objects 34 | #define EXT_NOTCOPYABLE(ClassName) \ 35 | private: \ 36 | ClassName(const ClassName&) = delete; \ 37 | ClassName(ClassName&&) = delete; \ 38 | ClassName &operator =(const ClassName&) = delete; 39 | 40 | // Not instantiable class 41 | #define EXT_STATIC(ClassName) \ 42 | private: \ 43 | ClassName() = delete; \ 44 | EXT_NOTCOPYABLE(ClassName) 45 | 46 | // Class-package (Ada nostalgie) 47 | #define Package(ClassName) class ClassName final 48 | #define EXT_PACKAGE(ClassName) EXT_STATIC(ClassName) \ 49 | 50 | // Interface class (Wanna be java) 51 | #define Interface(ClassName) class ClassName 52 | #define EXT_INTERFACE (ClassName) \ 53 | public: \ 54 | virtual ~ClassName() = default; \ 55 | protected: \ 56 | ClassName() = default; \ 57 | EXT_NOTCOPYABLE(ClassName) 58 | 59 | #ifdef swap 60 | #undef swap 61 | #endif 62 | template 63 | void swap(T &r, T &l) 64 | { 65 | T buf = r; 66 | r = l; 67 | l = buf; 68 | } 69 | 70 | #endif //EXT_HPP 71 | -------------------------------------------------------------------------------- /terminal-basic/ascii.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * ArduinoExt is a set of utility libraries for Arduino 3 | * 4 | * Copyright (C) 2016-2018 Andrey V. Skvortsov 5 | * Copyright (C) 2019,2021 Terminal-BASIC team 6 | * 7 | * 8 | * This program is free software: is free software: you can redistribute it and/or 9 | * modify it under the terms of the GNU Lesser General Public License 10 | * as published by the Free Software Foundation, either version 3 of 11 | * the License, or (at your option) any later version. 12 | 13 | * ArduinoExt library is distributed in the hope that it will be useful, 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | * GNU General Public License for more details. 17 | 18 | * You should have received a copy of the GNU Lesser General Public 19 | * License along with Posixcpp library. If not, see 20 | * . 21 | */ 22 | 23 | #ifndef ASCII_HPP 24 | #define ASCII_HPP 25 | 26 | #include 27 | 28 | /** 29 | * @brief ASCII characters 30 | */ 31 | enum class ASCII : uint8_t 32 | { 33 | NUL = 0x00, 34 | SOH = 0x01, 35 | STX = 0x02, 36 | ETX = 0x03, 37 | EOT = 0x04, 38 | ENQ = 0x05, 39 | ACK = 0x06, 40 | BEL = 0x07, 41 | BS = 0x08, 42 | HT = 0x09, 43 | LF = 0x0A, 44 | VT = 0x0B, 45 | FF = 0x0C, 46 | CR = 0x0D, 47 | SO = 0x0E, 48 | SI = 0x0F, 49 | DLE = 0x10, // Data link escape 50 | NAK = 0x15, 51 | SYN = 0x16, 52 | ETB = 0x17, 53 | CAN = 0x18, 54 | ESC = 0x1B, 55 | SPACE = ' ', 56 | QMARK = '?', 57 | DOT = '.', 58 | COLON = ':', 59 | SEMICOLON = ';', 60 | QUMARK = '\"', 61 | LPAREN = '(', 62 | RPAREN = ')', 63 | COMMA = ',', 64 | GT = '>', 65 | LT = '<', 66 | TILDE = 0x7E, 67 | DEL = 0x7F 68 | }; 69 | 70 | #endif 71 | -------------------------------------------------------------------------------- /terminal-basic/avr/pgmspace.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Libarduinoemulator is a simple library to emulate ArduinoIDE API on a Linux PC 3 | * Copyright (C) 2016, 2017 Andrey V. Skvortsov 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU Lesser General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program. If not, see . 17 | */ 18 | 19 | #ifndef PGMSPACE_H 20 | #define PGMSPACE_H 21 | 22 | #if (defined ARDUINO_ARCH_AVR) || (defined ARDUINO_ARCH_SAM) || (defined ARDUINO_ARCH_ESP8266) 23 | #include_next 24 | #else 25 | 26 | #include 27 | #include 28 | 29 | #define PGM_P const char* 30 | #define PROGMEM 31 | #define pgm_read_byte(a) (*((const uint8_t*)a)) 32 | #define pgm_read_word(a) (*a) 33 | #define pgm_read_ptr(a) (*a) 34 | #define strcpy_P(a,b) strcpy(a,b) 35 | #define strcmp_P(a,b) strcmp(a,b) 36 | #define memcpy_P(a,b,c) memcpy(a,b,c) 37 | 38 | #endif /* ARDUINO_ARCH_AVR */ 39 | 40 | #endif /* PGMSPACE_H */ 41 | -------------------------------------------------------------------------------- /terminal-basic/basic.c: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of Terminal-BASIC: a lightweight BASIC-like language 3 | * interpreter. 4 | * 5 | * Copyright (C) 2016-2018 Andrey V. Skvortsov 6 | * Copyright (C) 2019-2021 Terminal-BASIC team 7 | * 8 | * 9 | * This program is free software: you can redistribute it and/or modify 10 | * it under the terms of the GNU General Public License as published by 11 | * the Free Software Foundation, either version 3 of the License, or 12 | * (at your option) any later version. 13 | * 14 | * This program is distributed in the hope that it will be useful, 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | * GNU General Public License for more details. 18 | * 19 | * You should have received a copy of the GNU General Public License 20 | * along with this program. If not, see . 21 | */ 22 | 23 | #include "tools.h" 24 | #include "basic.h" 25 | 26 | #include 27 | 28 | #include "avr/pgmspace.h" 29 | 30 | uint8_t* 31 | scanTable(const uint8_t *token, const uint8_t table[], uint8_t *index) 32 | { 33 | uint8_t tokPos = 0, // Position in current token 34 | tabPos = 0; // Index in the token table 35 | while (TRUE) { 36 | // Read next table byte 37 | uint8_t c = pgm_read_byte(table); 38 | // token byte to compare with table 39 | uint8_t ct = token[tokPos]; 40 | /* If token table is over */ 41 | if (c == ASCII_ETX) 42 | return NULL; 43 | else if (c > ct && ct > ' ') 44 | return NULL; 45 | /* Current symbol matches table element */ 46 | else if (ct == c) { 47 | ++tokPos, ++table; 48 | if (pgm_read_byte(table) == ASCII_NUL) { 49 | *index = tabPos; 50 | return (uint8_t*)token+tokPos; 51 | } 52 | continue; 53 | } else if (ct <= ' ' && c == ASCII_NUL) { 54 | *index = tabPos; 55 | return (uint8_t*)token+tokPos; 56 | } else { 57 | while (pgm_read_byte(table++) != ASCII_NUL); 58 | ++tabPos, tokPos=0; 59 | continue; 60 | } 61 | /* Not current token, take next table row */ 62 | if (ct == ASCII_NUL) { 63 | while (pgm_read_byte(table++) != ASCII_NUL); 64 | ++tabPos, tokPos=0; 65 | } 66 | } 67 | return NULL; 68 | } 69 | 70 | void getToken(const uint8_t* table, uint8_t index, uint8_t* buf) 71 | { 72 | uint8_t byte = 0xFF; 73 | while (byte != ASCII_ETX) { 74 | if (byte == ASCII_NUL) 75 | --index; 76 | if (index == 0) { 77 | while ((byte = pgm_read_byte(table++)) != ASCII_NUL) 78 | *(buf++) = byte; 79 | break; 80 | } 81 | byte = pgm_read_byte(table++); 82 | } 83 | *buf = '\0'; 84 | } 85 | -------------------------------------------------------------------------------- /terminal-basic/basic.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of Terminal-BASIC: a lightweight BASIC-like language 3 | * interpreter. 4 | * 5 | * Copyright (C) 2016-2018 Andrey V. Skvortsov 6 | * Copyright (C) 2019-2021 Terminal-BASIC team 7 | * 8 | * 9 | * This program is free software: you can redistribute it and/or modify 10 | * it under the terms of the GNU General Public License as published by 11 | * the Free Software Foundation, either version 3 of the License, or 12 | * (at your option) any later version. 13 | * 14 | * This program is distributed in the hope that it will be useful, 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | * GNU General Public License for more details. 18 | * 19 | * You should have received a copy of the GNU General Public License 20 | * along with this program. If not, see . 21 | */ 22 | 23 | #ifndef BASIC_H 24 | #define BASIC_H 25 | 26 | #include "sys/cdefs.h" 27 | #include 28 | 29 | #include "basic_config.h" 30 | 31 | #if USE_REALS 32 | #include 33 | #endif 34 | 35 | __BEGIN_DECLS 36 | 37 | typedef uintptr_t pointer_t; 38 | 39 | /** 40 | * @brief ASCII characters 41 | */ 42 | typedef enum ascii_codes 43 | { 44 | ASCII_NUL = 0x00, /* Null */ 45 | SOH = 0x01, /* Start of heading */ 46 | STX = 0x02, /* Start of text */ 47 | ASCII_ETX = 0x03, /* End of text */ 48 | EOT = 0x04, /* End of transmission */ 49 | ENQ = 0x05, /* Enquire */ 50 | ACK = 0x06, /* Acknowledgement */ 51 | BEL = 0x07, /* Bell */ 52 | BS = 0x08, /* Backspace */ 53 | HT = 0x09, /* Horizontal tab */ 54 | LF = 0x0A, /* Line feed */ 55 | VT = 0x0B, /* Vertical tab */ 56 | FF = 0x0C, /* Form feed */ 57 | CR = 0x0D, /* Carriage return */ 58 | SO = 0x0E, /* Shift out */ 59 | SI = 0x0F, /* Shift in */ 60 | ASCII_DLE = 0x10, /* Data link escape */ 61 | DC1 = 0x11, /* Device control 1 */ 62 | DC2 = 0x12, /* Device control 2 */ 63 | DC3 = 0x13, /* Device control 3 */ 64 | DC4 = 0x14, /* Device control 4 */ 65 | NAK = 0x15, /* Negative acknowledgement */ 66 | SYN = 0x16, /* Synchronous idle */ 67 | ETB = 0x17, /* End of transmission block */ 68 | CAN = 0x18, /* Cancel */ 69 | ESC = 0x1B, /* Escape */ 70 | FS = 0x1C, /* File separator */ 71 | GS = 0x1D, /* Group separator */ 72 | RS = 0x1E, /* Record separator */ 73 | US = 0x1F, /* Unit separator */ 74 | SPACE = ' ', 75 | QMARK = '?', 76 | DOT = '.', 77 | COLON = ':', 78 | SEMICOLON = ';', 79 | QUMARK = '\"', 80 | LPAREN = '(', 81 | RPAREN = ')', 82 | COMMA = ',', 83 | GT = '>', 84 | LT = '<', 85 | TILDE = 0x7E, 86 | DEL = 0x7F 87 | } ascii_codes_t; 88 | 89 | // integer type 90 | typedef int16_t integer_t; 91 | #define MAX_INTEGER (integer_t)(INT16_MAX) 92 | #if USE_LONGINT 93 | // long integer type 94 | typedef int32_t long_integer_t; 95 | #define MAX_LONG_INTEGER (long_integer_t)(INT32_MAX) 96 | typedef long_integer_t INT; 97 | #define MAXINT MAX_LONG_INTEGER 98 | #else 99 | typedef integer_t INT; 100 | #define MAXINT MAX_INTEGER 101 | #endif // USE_LONGINT 102 | // floating point type 103 | #if USE_REALS 104 | typedef float real_t; 105 | #if USE_LONG_REALS 106 | typedef double long_real_t; 107 | #endif 108 | #endif // USE_REALS 109 | 110 | /** 111 | * @brief Scan token table 112 | * @param token 113 | * @param table 114 | * @param index 115 | * @return find flag 116 | */ 117 | uint8_t *scanTable(const uint8_t*, const uint8_t[], uint8_t*); 118 | 119 | /** 120 | * 121 | * @param table [in] 122 | * @param index [in] 123 | * @param tokenString [out] 124 | */ 125 | void getToken(const uint8_t*, uint8_t, uint8_t*); 126 | 127 | #if CONF_LEXER_LANG == LANG_EN 128 | #include "_tokens_en.h" 129 | #elif CONF_LEXER_LANG == LANG_RU 130 | #include "_tokens_ru.h" 131 | #elif CONF_LEXER_LANG == LANG_FR 132 | #include "_tokens_fr.h" 133 | #else 134 | #error You should define CONF_LEXER_LANG to one of the supported languages 135 | #endif // CONF_LANG 136 | 137 | struct basic_lexer_context; 138 | typedef struct basic_lexer_context basic_lexer_context_t; 139 | 140 | struct basic_parser_context; 141 | typedef struct basic_parser_context basic_parser_context_t; 142 | 143 | __END_DECLS 144 | 145 | #endif /* BASIC_H */ 146 | -------------------------------------------------------------------------------- /terminal-basic/basic_arduinoio.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of Terminal-BASIC: a lightweight BASIC-like language 3 | * interpreter. 4 | * 5 | * Copyright (C) 2016-2018 Andrey V. Skvortsov 6 | * Copyright (C) 2019-2021 Terminal-BASIC team 7 | * 8 | * 9 | * This program is free software: you can redistribute it and/or modify 10 | * it under the terms of the GNU General Public License as published by 11 | * the Free Software Foundation, either version 3 of the License, or 12 | * (at your option) any later version. 13 | * 14 | * This program is distributed in the hope that it will be useful, 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | * GNU General Public License for more details. 18 | * 19 | * You should have received a copy of the GNU General Public License 20 | * along with this program. If not, see . 21 | */ 22 | 23 | #include "basic_arduinoio.hpp" 24 | 25 | #if CONF_MODULE_ARDUINOIO 26 | 27 | #include "Arduino.h" 28 | #ifdef ARDUINO_ARCH_ESP32 29 | #include "HAL_esp32.h" 30 | #endif 31 | #include 32 | 33 | namespace BASIC 34 | { 35 | 36 | static const uint8_t arduinoIOFuncs[] PROGMEM = { 37 | 'A', 'R', 'E', 'A', 'D', '%', ASCII_NUL, 38 | #if USE_REALS 39 | 'A', 'R', 'E', 'A', 'D', ASCII_NUL, 40 | #endif 41 | 'D', 'R', 'E', 'A', 'D', ASCII_NUL, 42 | ASCII_ETX 43 | }; 44 | 45 | const FunctionBlock::function ArduinoIO::_funcs[] PROGMEM = { 46 | ArduinoIO::func_aread_int, 47 | #if USE_REALS 48 | ArduinoIO::func_aread, 49 | #endif 50 | ArduinoIO::func_dread 51 | }; 52 | 53 | static const uint8_t arduinoIOCommands[] PROGMEM = { 54 | 'A', 'W', 'R', 'I', 'T', 'E', ASCII_NUL, 55 | #if CONF_BEEP 56 | 'B', 'E', 'E', 'P', ASCII_NUL, 57 | #endif 58 | #if CONF_MODULE_ARDUINOIO_TONE 59 | 'D', 'N', 'O', 'T', 'O', 'N', 'E', ASCII_NUL, 60 | 'D', 'T', 'O', 'N', 'E', ASCII_NUL, 61 | #endif 62 | 'D', 'W', 'R', 'I', 'T', 'E', ASCII_NUL, 63 | ASCII_ETX 64 | }; 65 | 66 | const FunctionBlock::command ArduinoIO::_commands[] PROGMEM = { 67 | ArduinoIO::comm_awrite 68 | #if CONF_BEEP 69 | , ArduinoIO::comm_beep 70 | #endif 71 | #if CONF_MODULE_ARDUINOIO_TONE 72 | , ArduinoIO::comm_notone 73 | , ArduinoIO::comm_tone 74 | #endif 75 | , ArduinoIO::comm_dwrite 76 | #if FAST_MODULE_CALL 77 | , nullptr 78 | #endif 79 | }; 80 | 81 | ArduinoIO::ArduinoIO() 82 | { 83 | commands = _commands; 84 | commandTokens = arduinoIOCommands; 85 | functions = _funcs; 86 | functionTokens = arduinoIOFuncs; 87 | } 88 | 89 | #if USE_REALS 90 | 91 | bool 92 | ArduinoIO::func_aread(Interpreter &i) 93 | { 94 | return general_func(i, aread_r); 95 | } 96 | #endif 97 | 98 | bool 99 | ArduinoIO::func_aread_int(Interpreter &i) 100 | { 101 | return general_func(i, aread_i); 102 | } 103 | 104 | bool 105 | ArduinoIO::func_dread(Interpreter &i) 106 | { 107 | INT v; 108 | if (getIntegerFromStack(i, v)) 109 | return i.pushValue(bool(HAL_gpio_readPin(v))); 110 | 111 | return false; 112 | } 113 | 114 | bool 115 | ArduinoIO::comm_awrite(Interpreter &i) 116 | { 117 | INT v; 118 | if (getIntegerFromStack(i, v)) { 119 | INT v2; 120 | if (getIntegerFromStack(i, v2)) { 121 | pinMode(v2, OUTPUT); 122 | analogWrite(v2, v); 123 | return true; 124 | } 125 | } 126 | return false; 127 | } 128 | 129 | bool 130 | ArduinoIO::comm_dwrite(Interpreter &i) 131 | { 132 | Parser::Value v(false); 133 | if (i.popValue(v)) { 134 | if (v.type() == Parser::Value::LOGICAL) { 135 | INT v2; 136 | if (getIntegerFromStack(i, v2)) { 137 | HAL_gpio_writePin(v2, bool(v)); 138 | return true; 139 | } 140 | } 141 | } 142 | 143 | return false; 144 | } 145 | 146 | #if CONF_MODULE_ARDUINOIO_TONE 147 | 148 | bool 149 | ArduinoIO::comm_tone(Interpreter &i) 150 | { 151 | INT pin, freq, dur; 152 | Parser::Value on(false); 153 | if (getIntegerFromStack(i, dur)) { 154 | if (getIntegerFromStack(i, freq)) { 155 | if (getIntegerFromStack(i, pin)) { 156 | HAL_buzzer_tone(pin, freq, dur); 157 | return true; 158 | } 159 | } 160 | } 161 | return false; 162 | } 163 | 164 | bool 165 | ArduinoIO::comm_notone(Interpreter &i) 166 | { 167 | INT pin; 168 | if (getIntegerFromStack(i, pin)) { 169 | HAL_buzzer_notone(pin); 170 | return true; 171 | } 172 | return false; 173 | } 174 | 175 | #endif 176 | 177 | #if USE_REALS 178 | Real 179 | ArduinoIO::aread_r(Real v) 180 | { 181 | pinMode(v, INPUT); 182 | 183 | return Real(analogRead(v)) / Real(1023) * Real(5.0); 184 | } 185 | #endif 186 | 187 | INT 188 | ArduinoIO::aread_i(INT v) 189 | { 190 | return analogRead(v); 191 | } 192 | 193 | #if CONF_BEEP 194 | 195 | bool 196 | ArduinoIO::comm_beep(Interpreter &) 197 | { 198 | HAL_buzzer_tone(BEEP_PIN, BEEP_FREQ, BEEP_DURATION); 199 | return true; 200 | } 201 | #endif // CONF_BEEP 202 | 203 | } // namespace BASIC 204 | 205 | #endif // CONF_MODULE_ARDUINOIO 206 | -------------------------------------------------------------------------------- /terminal-basic/basic_arduinoio.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of Terminal-BASIC: a lightweight BASIC-like language 3 | * interpreter. 4 | * 5 | * Copyright (C) 2016-2018 Andrey V. Skvortsov 6 | * Copyright (C) 2019-2021 Terminal-BASIC team 7 | * 8 | * 9 | * This program is free software: you can redistribute it and/or modify 10 | * it under the terms of the GNU General Public License as published by 11 | * the Free Software Foundation, either version 3 of the License, or 12 | * (at your option) any later version. 13 | * 14 | * This program is distributed in the hope that it will be useful, 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | * GNU General Public License for more details. 18 | * 19 | * You should have received a copy of the GNU General Public License 20 | * along with this program. If not, see . 21 | */ 22 | 23 | /** 24 | * @file basic_arduinoio.hpp 25 | * @brief Arduino io container 26 | */ 27 | 28 | #ifndef BASIC_ARDUINOIO_HPP 29 | #define BASIC_ARDUINOIO_HPP 30 | 31 | #include "basic_functionblock.hpp" 32 | #include "basic_interpreter.hpp" 33 | 34 | namespace BASIC 35 | { 36 | 37 | /** 38 | * @brief Module, containing Arduino digital and abalog I/O functions 39 | */ 40 | class ArduinoIO : public FunctionBlock 41 | { 42 | public: 43 | explicit ArduinoIO(); 44 | private: 45 | #if USE_REALS 46 | static bool func_aread(Interpreter&); 47 | #endif // USE_REALS 48 | static bool func_aread_int(Interpreter&); 49 | static bool func_dread(Interpreter&); 50 | static bool comm_awrite(Interpreter&); 51 | static bool comm_dwrite(Interpreter&); 52 | #if CONF_MODULE_ARDUINOIO_TONE 53 | static bool comm_tone(Interpreter&); 54 | static bool comm_notone(Interpreter&); 55 | #if CONF_BEEP 56 | static bool comm_beep(Interpreter&); 57 | #endif // CONF_BEEP 58 | #endif // CONF_MODULE_ARDUINOIO_TONE 59 | 60 | #if USE_REALS 61 | static Real aread_r(Real); 62 | #endif // USE_REALS 63 | 64 | static INT aread_i(INT); 65 | 66 | static const FunctionBlock::function _funcs[] PROGMEM; 67 | static const FunctionBlock::command _commands[] PROGMEM; 68 | }; 69 | 70 | } // namespace BASIC 71 | 72 | #endif // BASIC_ARDUINOIO_HPP 73 | -------------------------------------------------------------------------------- /terminal-basic/basic_config.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of Terminal-BASIC: a lightweight BASIC-like language 3 | * interpreter. 4 | * 5 | * Copyright (C) 2016-2018 Andrey V. Skvortsov 6 | * Copyright (C) 2019-2021 Terminal-BASIC team 7 | * 8 | * 9 | * This program is free software: you can redistribute it and/or modify 10 | * it under the terms of the GNU General Public License as published by 11 | * the Free Software Foundation, either version 3 of the License, or 12 | * (at your option) any later version. 13 | * 14 | * This program is distributed in the hope that it will be useful, 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | * GNU General Public License for more details. 18 | * 19 | * You should have received a copy of the GNU General Public License 20 | * along with this program. If not, see . 21 | */ 22 | 23 | /** 24 | * @file basic_config.h 25 | * @brief Configuration parameters, common among versions 26 | */ 27 | 28 | #ifndef BASIC_CONFIG_H 29 | #define BASIC_CONFIG_H 30 | 31 | #include "_basic_config.h" 32 | 33 | /* 34 | * 1. Real arithmetics 35 | * 36 | * Support of operations with real numbers. 37 | * When enabled, all variables and arrays, which names are not ending with "$ ! %" 38 | * are treated as reals. Mathematical functions support depend on this option 39 | * This type is 4-byte binary floating point (C/C++ float) 40 | */ 41 | #define USE_REALS 1 42 | 43 | #if USE_REALS 44 | /** 45 | * 1.1 Long real numbers 46 | * 47 | * Support of long real numbers. Arrays, variables and functions, ending 48 | * with "!" character are long real. 49 | * This type is 8-byte binary floating point (C/C++ double). This means 50 | * it can't be used on systems w/o double type support, such as 8-bit AVR 51 | * arduino boards (UNO/NANO/PRO mini/Mega...) 52 | * 53 | * All real number constants (1e6, 0.5, 3., .04 ... ) treated as long reals 54 | */ 55 | #define USE_LONG_REALS 0 56 | #endif 57 | 58 | /* 59 | * Support of 4-byte integer datatype 60 | * 61 | * Default integer constants are 2-byte signed [-32768 .. 32768), but this 62 | * option enables 4-byte signed type. 63 | * Functions, variables and arrays of long integer type ends with double "%!" 64 | * symbols will be treated as long integers 65 | */ 66 | #define USE_LONGINT 0 67 | 68 | /** 69 | * DUMP command support 70 | * This command can be used to check BASIC memory image, variables and arrays list 71 | */ 72 | #define USE_DUMP 0 73 | 74 | /* 75 | * RANDOMIZE command and RND() function support 76 | */ 77 | #define USE_RANDOM 1 78 | 79 | /* 80 | * Support of Darthmouth BASIC-style matrix operations 81 | */ 82 | #define USE_MATRIX 0 83 | 84 | /** 85 | * Support of DATA/READ statements 86 | */ 87 | #define USE_DATA 0 88 | 89 | /* 90 | * Support of DEF FN construct 91 | */ 92 | #define USE_DEFFN 0 93 | 94 | /* 95 | * DELAY command, suspending execution for N ms 96 | */ 97 | #define USE_DELAY 1 98 | 99 | /* 100 | * Allow ON ... GOTO ... statements 101 | */ 102 | #define CONF_USE_ON_GOTO 0 103 | 104 | /* 105 | * Allow GO TO OPERATOR in addition to GOTO 106 | */ 107 | #define CONF_SEPARATE_GO_TO 0 108 | 109 | /* 110 | * Fast command call using C-function address 111 | */ 112 | #define FAST_MODULE_CALL 1 113 | 114 | /* 115 | * Support of integer division '\' and modulo 'MOD' operation 116 | */ 117 | #define USE_INTEGER_DIV 0 118 | #if USE_INTEGER_DIV 119 | /* 120 | * Use DIV keyword for integer division in addition to \ operation 121 | */ 122 | #define USE_DIV_KW 0 123 | #endif // USE_INTEGER_DIV 124 | 125 | /* 126 | * Use >< as not-equals operator (with default <>) 127 | */ 128 | #define CONF_USE_ALTERNATIVE_NE 0 129 | 130 | /* 131 | * SAVE, LOAD and CHAIN commands support 132 | */ 133 | #define USE_SAVE_LOAD 1 134 | 135 | /* 136 | * Use ANSI text attributes 137 | */ 138 | #define USE_TEXTATTRIBUTES 1 139 | #if USE_TEXTATTRIBUTES 140 | /* 141 | * Support of SPC(N) print command 142 | */ 143 | #define CONF_USE_SPC_PRINT_COM 1 144 | #endif // USE_TEXTATTRIBUTES 145 | 146 | /* 147 | * STOP and CONTINUE commands support 148 | */ 149 | #define USESTOPCONT 1 150 | 151 | /* 152 | * PEEK FUNCTION, POKE command support 153 | */ 154 | #define USE_PEEK_POKE 0 155 | 156 | /* 157 | * Messages and errors localization 158 | * LANG_EN: English 159 | * LANG_RU: Russian 160 | * LANG_FR: French 161 | */ 162 | #define CONF_LANG LANG_EN 163 | 164 | /* 165 | * Lexer localization 166 | */ 167 | #define CONF_LEXER_LANG LANG_EN 168 | 169 | /* Size of the string identifiers */ 170 | #define STRING_SIZE 72 171 | 172 | /* 173 | * Enabling packed structures reduces BASIC memory usage, but results to 174 | * unaligned memory acces. It should be disabled on ESP8266, Motorola 68k, etc. 175 | */ 176 | #define USE_PACKED_STRUCT 1 177 | 178 | /* 179 | * High-level code optimisation mode 180 | * OPT_SPEED Extensive usage of switch/case constructs 181 | * OPT_SIZE Use cascade of if/else if instead of switch/case 182 | */ 183 | #define OPT OPT_SIZE /* Selected mode */ 184 | 185 | #endif /* BASIC_CONFIG_H */ 186 | -------------------------------------------------------------------------------- /terminal-basic/basic_config.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of Terminal-BASIC: a lightweight BASIC-like language 3 | * interpreter. 4 | * 5 | * Copyright (C) 2016-2018 Andrey V. Skvortsov 6 | * Copyright (C) 2019-2021 Terminal-BASIC team 7 | * 8 | * 9 | * This program is free software: you can redistribute it and/or modify 10 | * it under the terms of the GNU General Public License as published by 11 | * the Free Software Foundation, either version 3 of the License, or 12 | * (at your option) any later version. 13 | * 14 | * This program is distributed in the hope that it will be useful, 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | * GNU General Public License for more details. 18 | * 19 | * You should have received a copy of the GNU General Public License 20 | * along with this program. If not, see . 21 | */ 22 | 23 | /** 24 | * @file config.hpp 25 | * @brief Configuration parameters, specific to Terminal-BASIC 26 | */ 27 | 28 | #ifndef CONFIG_HPP 29 | #define CONFIG_HPP 30 | 31 | #include "basic_config.h" 32 | 33 | /* 34 | * Allow '_' symbol in identifiers 35 | */ 36 | #define ALLOW_UNDERSCORE_ID 0 37 | 38 | #if USE_REALS 39 | /* 40 | * Mathematical functions support 41 | */ 42 | #define USEMATH 1 43 | #if USEMATH 44 | /* 45 | * SIN COS TAN COT 46 | */ 47 | #define M_TRIGONOMETRIC 1 48 | #define M_HYPERBOLIC 0 49 | /* 50 | * ACS ASN ATN 51 | */ 52 | #define M_REVERSE_TRIGONOMETRIC 0 53 | /* 54 | * CBR (cubic root) ... 55 | */ 56 | #define M_ADDITIONAL 0 57 | #endif // USEMATH 58 | #endif // USE_REALS 59 | 60 | // Use string functions and operations 61 | #define USE_STRINGOPS 1 62 | #if USE_STRINGOPS 63 | // GET$ function, returns string from last pressed key symbol 64 | #define USE_INKEY 0 65 | // CHR$ function, returns string from the parameter ASCII code 66 | #define USE_CHR 1 67 | // ASC function, returns code of the first symbol in a string 68 | #define USE_ASC 1 69 | // LEN function, returns length of the string 70 | #define USE_LEN 1 71 | // LEFT$ function, returns leftmost part of the string 72 | #define USE_LEFT 0 73 | // RIGHT$ function, returns rightmost part of the string 74 | #define USE_RIGHT 0 75 | // MID$ function, returns middle part of the string 76 | #define USE_MID 1 77 | // An alias for MID$ 78 | #define USE_SEG 1 79 | // HEX$ function, returns string with hexsadecimal representation of the expression value 80 | #define USE_HEX 0 81 | // VAL function, returns numeric value from string 82 | #define USE_VAL 0 83 | #endif // USE_STRINGOPS 84 | /* 85 | * Clear program memory on NEW command 86 | */ 87 | #define CLEAR_PROGRAM_MEMORY 1 88 | /** 89 | * Allow INPUT command with text message e.g. INPUT "A:";A 90 | */ 91 | #define OPT_INPUT_WITH_TEXT 1 92 | /** 93 | * Implicit arrays without DIM statement 94 | */ 95 | #define OPT_IMPLICIT_ARRAYS 0 96 | 97 | #if USE_TEXTATTRIBUTES 98 | /* 99 | * Use ANSI color attributes 100 | */ 101 | #define USE_COLORATTRIBUTES 1 102 | /* 103 | * Set print zones width (tab spacing) 104 | */ 105 | #define SET_PRINTZNES 0 106 | #if SET_PRINTZNES 107 | #define PRINT_ZONE_WIDTH 12 108 | #define PRINT_ZONES_NUMBER 5 109 | #endif // SET_PRINTZNES 110 | #endif // USE_TEXTATTRIBUTES 111 | 112 | #if USE_SAVE_LOAD 113 | // Compute checksums while SAVE, LOAD and CHAIN 114 | #define SAVE_LOAD_CHECKSUM 0 115 | #endif // USE_SAVE_LOAD 116 | 117 | // Convert all input to upper register 118 | #define AUTOCAPITALIZE 0 119 | 120 | /* 121 | * External memory filesystem module 122 | */ 123 | #define CONF_USE_EXTMEMFS 0 124 | #if CONF_USE_EXTMEMFS 125 | // Unix-like file operations 126 | #define USE_FILEOP 1 127 | #endif 128 | 129 | // Use text error strings 130 | #define CONF_ERROR_STRINGS 0 131 | 132 | // Arduino IO module 133 | #define CONF_MODULE_ARDUINOIO 0 134 | #if CONF_MODULE_ARDUINOIO 135 | // TONE command support 136 | #define CONF_MODULE_ARDUINOIO_TONE 0 137 | // BEEP command 138 | #if CONF_MODULE_ARDUINOIO_TONE 139 | #define CONF_BEEP 1 140 | #if CONF_BEEP 141 | #define BEEP_PIN 32 142 | #define BEEP_FREQ 440 143 | #define BEEP_DURATION 300 144 | #endif // CONF_BEEP 145 | #endif // CONF_MODULE_ARDUINOIO_TONE 146 | #endif // CONF_MODULE_ARDUINOIO 147 | 148 | // External EEPROM functions module 149 | #define USE_EXTEEPROM 0 150 | #if USE_EXTEEPROM 151 | /* 152 | * Size in bytes 153 | */ 154 | #define EXTEEPROM_SIZE 32768 155 | #endif // USE_EXTEEPROM 156 | 157 | /* 158 | * Indention of the loop bodies 159 | */ 160 | #define LOOP_INDENT 1 161 | 162 | /* 163 | * Indention of the line numbers in LIST output 164 | */ 165 | #define LINE_NUM_INDENT 1 166 | 167 | /** 168 | * Aligned memory access. A bit slower, but necessary on ESP8266, MC68k, etc. 169 | */ 170 | #define CONF_USE_ALIGN 0 171 | 172 | /* 173 | * GFX module 174 | */ 175 | #define USE_GFX 0 176 | #if USE_GFX 177 | // Use drawing functions with explisit color setting 178 | #define GFX_EXP_COLOR 1 179 | #endif 180 | 181 | /* 182 | * Prompt on new line 183 | */ 184 | #define CLI_PROMPT_NEWLINE 1 185 | 186 | /* 187 | * LF character processing 188 | */ 189 | #define LF_NONE 0 // Not handled 190 | #define LF_EAT 1 // Silently eat it 191 | #define LF_NEWLINE 2 // Use as new line 192 | #define PROCESS_LF LF_NEWLINE 193 | 194 | /* 195 | * Input and output for single terminal mode 196 | */ 197 | 198 | // Input variants 199 | #define HAL_I 11 200 | 201 | // Output variants 202 | #define HAL_O 13 203 | 204 | // Input select 205 | #define S_INPUT HAL_I 206 | 207 | // Output select 208 | #define S_OUTPUT HAL_O 209 | 210 | #if USE_EXTEEPROM 211 | #define USE_WIRE 1 212 | #else 213 | #define USE_WIRE 0 214 | #endif 215 | 216 | // Use multiterminal mode 217 | #define BASIC_MULTITERMINAL 0 218 | 219 | /* 220 | * Max size of the program line 221 | */ 222 | #define PROGSTRINGSIZE 80 223 | 224 | // Number of characters in variable name 225 | #define VARSIZE 5 226 | 227 | // Show license message on start 228 | #define LICENSE_TEXT_ON_START 0 229 | 230 | #endif // CONFIG_HPP 231 | -------------------------------------------------------------------------------- /terminal-basic/basic_dataparser.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of Terminal-BASIC: a lightweight BASIC-like language 3 | * interpreter. 4 | * 5 | * Copyright (C) 2016-2018 Andrey V. Skvortsov 6 | * Copyright (C) 2019-2021 Terminal-BASIC team 7 | * 8 | * 9 | * This program is free software: you can redistribute it and/or modify 10 | * it under the terms of the GNU General Public License as published by 11 | * the Free Software Foundation, either version 3 of the License, or 12 | * (at your option) any later version. 13 | * 14 | * This program is distributed in the hope that it will be useful, 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | * GNU General Public License for more details. 18 | * 19 | * You should have received a copy of the GNU General Public License 20 | * along with this program. If not, see . 21 | */ 22 | 23 | #include "basic_dataparser.hpp" 24 | 25 | #if USE_DATA 26 | 27 | namespace BASIC 28 | { 29 | 30 | DataParser::DataParser(Interpreter &interpreter) : 31 | _interpreter(interpreter) 32 | { 33 | } 34 | 35 | bool 36 | DataParser::searchData(const uint8_t *str, Parser::Value &value) 37 | { 38 | _lexer.init(str, true); 39 | while (_lexer.getNext()) { 40 | if ((_lexer.getToken() == Token::KW_DATA) && 41 | _lexer.getNext()) 42 | return readValue(value); 43 | } 44 | return false; 45 | } 46 | 47 | bool 48 | DataParser::read(const uint8_t *str, Parser::Value &value) 49 | { 50 | _lexer.init(str, true); 51 | if (_lexer.getNext() && (_lexer.getToken() == Token::COMMA) 52 | && _lexer.getNext()) 53 | return readValue(value); 54 | return false; 55 | } 56 | 57 | bool 58 | DataParser::readValue(Parser::Value &value) 59 | { 60 | bool minus = _lexer.getToken() == Token::MINUS; 61 | if (minus || _lexer.getToken() == Token::PLUS) { 62 | if (!_lexer.getNext()) 63 | return false; 64 | } 65 | if ((_lexer.getToken() >= Token::C_INTEGER) 66 | && (_lexer.getToken() <= Token::C_STRING)) { 67 | value = _lexer.getValue(); 68 | if (minus) 69 | value.switchSign(); 70 | if (_lexer.getToken() == Token::C_STRING) 71 | _interpreter.pushString(_lexer.id()); 72 | return true; 73 | } else if ((_lexer.getToken() >= Token::INTEGER_IDENT) 74 | && (_lexer.getToken() <= Token::BOOL_IDENT)) { 75 | value.setType(Parser::Value::Type::STRING); 76 | _interpreter.pushString(_lexer.id()); 77 | return true; 78 | } 79 | return false; 80 | } 81 | 82 | } // namespace BASIC 83 | 84 | #endif // USE_DATA 85 | -------------------------------------------------------------------------------- /terminal-basic/basic_dataparser.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of Terminal-BASIC: a lightweight BASIC-like language 3 | * interpreter. 4 | * 5 | * Copyright (C) 2016-2018 Andrey V. Skvortsov 6 | * Copyright (C) 2019-2021 Terminal-BASIC team 7 | * 8 | * 9 | * This program is free software: you can redistribute it and/or modify 10 | * it under the terms of the GNU General Public License as published by 11 | * the Free Software Foundation, either version 3 of the License, or 12 | * (at your option) any later version. 13 | * 14 | * This program is distributed in the hope that it will be useful, 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | * GNU General Public License for more details. 18 | * 19 | * You should have received a copy of the GNU General Public License 20 | * along with this program. If not, see . 21 | */ 22 | 23 | /** 24 | * @file basic_dataparser.hpp 25 | */ 26 | 27 | #ifndef BASIC_DATAPARSER_HPP 28 | #define BASIC_DATAPARSER_HPP 29 | 30 | #include "basic_interpreter.hpp" 31 | 32 | namespace BASIC 33 | { 34 | 35 | class DataParser 36 | { 37 | public: 38 | DataParser(Interpreter&); 39 | bool searchData(const uint8_t*, Parser::Value&); 40 | bool read(const uint8_t*, Parser::Value&); 41 | const Lexer &lexer() const { return _lexer; } 42 | private: 43 | bool readValue(Parser::Value&); 44 | Lexer _lexer; 45 | Interpreter &_interpreter; 46 | }; 47 | 48 | } // namespace BASIC 49 | 50 | #endif // BASIC_DATAPARSER_HPP 51 | -------------------------------------------------------------------------------- /terminal-basic/basic_exteeprom.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of Terminal-BASIC: a lightweight BASIC-like language 3 | * interpreter. 4 | * 5 | * Copyright (C) 2016-2018 Andrey V. Skvortsov 6 | * Copyright (C) 2019-2021 Terminal-BASIC team 7 | * 8 | * 9 | * This program is free software: you can redistribute it and/or modify 10 | * it under the terms of the GNU General Public License as published by 11 | * the Free Software Foundation, either version 3 of the License, or 12 | * (at your option) any later version. 13 | * 14 | * This program is distributed in the hope that it will be useful, 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | * GNU General Public License for more details. 18 | * 19 | * You should have received a copy of the GNU General Public License 20 | * along with this program. If not, see . 21 | */ 22 | 23 | #include "basic.hpp" 24 | 25 | #if USE_EXTEEPROM 26 | 27 | #include "basic_exteeprom.hpp" 28 | #include "basic_interpreter.hpp" 29 | #include "basic_program.hpp" 30 | 31 | #include "i2ceeprom.hpp" 32 | 33 | namespace BASIC 34 | { 35 | 36 | static AT28C256C i2c_eeprom(0x50); 37 | 38 | static const uint8_t extEEPROMCommandTokens[] PROGMEM = { 39 | 'E', 'C', 'H', 'A', 'I', 'N' + 0x80, 40 | 'E', 'L', 'O', 'A', 'D' + 0x80, 41 | 'E', 'S', 'A', 'V', 'E' + 0x80, 42 | 0 43 | }; 44 | 45 | const FunctionBlock::function ExtEEPROM::_commands[] PROGMEM = { 46 | ExtEEPROM::com_echain, 47 | ExtEEPROM::com_eload, 48 | ExtEEPROM::com_esave 49 | }; 50 | 51 | struct PACKED ZoneHeader 52 | { 53 | uint16_t number; 54 | uint16_t crc; 55 | uint16_t textEnd, varsEnd, arraysEnd, sp; 56 | }; 57 | 58 | static constexpr const uint16_t zoneSize = SINGLE_PROGSIZE+sizeof(ZoneHeader); 59 | 60 | class ZoneInfo 61 | { 62 | uint16_t crc_16; 63 | uint16_t text_end; 64 | uint16_t vars_end; 65 | uint16_t arrays_end; 66 | }; 67 | 68 | ExtEEPROM::ExtEEPROM() 69 | { 70 | commands = _commands; 71 | commandTokens = extEEPROMCommandTokens; 72 | } 73 | 74 | void 75 | ExtEEPROM::_init() 76 | { 77 | } 78 | 79 | bool 80 | ExtEEPROM::com_echain(Interpreter &i) 81 | { 82 | INT zoneNumber; 83 | if (!getIntegerFromStack(i, zoneNumber)) 84 | return false; 85 | 86 | const uint16_t zoneAddr = zoneNumber*zoneSize; 87 | if (zoneAddr+zoneSize > AT28C256C::size) 88 | return false; 89 | // Read program from EEPROM 90 | ZoneHeader h; 91 | if (!i2c_eeprom.read(zoneAddr, h)) 92 | return false; 93 | i._program.clearProg(); 94 | i._program.moveData(h.textEnd); 95 | for (uint16_t p = 0; p < h.textEnd; ++p) { 96 | delay(5); 97 | if (!i2c_eeprom.readByte(zoneAddr+p+sizeof(ZoneHeader), 98 | reinterpret_cast(i._program._text[p]))) 99 | return false; 100 | } 101 | i.newline(); 102 | i._program.jump(0); 103 | 104 | return true; 105 | } 106 | 107 | bool 108 | ExtEEPROM::com_eload(Interpreter &i) 109 | { 110 | INT zoneNumber; 111 | if (!getIntegerFromStack(i, zoneNumber)) 112 | return false; 113 | 114 | const uint16_t zoneAddr = zoneNumber*zoneSize; 115 | if (zoneAddr+zoneSize > AT28C256C::size) 116 | return false; 117 | // Read program from EEPROM 118 | i.newProgram(); 119 | ZoneHeader h; 120 | if (!i2c_eeprom.read(zoneAddr, h)) 121 | return false; 122 | for (uint16_t p = 0; p(i._program._text[p]))) 126 | return false; 127 | else 128 | i.print('.'); 129 | } 130 | i.newline(); 131 | i._program.setTextEnd(h.textEnd); 132 | i._program.setVarsEnd(h.varsEnd); 133 | i._program.setArraysEnd(h.arraysEnd); 134 | i._program.setSP(h.sp); 135 | 136 | return true; 137 | } 138 | 139 | bool 140 | ExtEEPROM::com_esave(Interpreter &i) 141 | { 142 | INT zoneNumber; 143 | if (!getIntegerFromStack(i, zoneNumber)) 144 | return false; 145 | 146 | const uint16_t zoneAddr = zoneNumber*zoneSize; 147 | if (zoneAddr+zoneSize > AT28C256C::size) 148 | return false; 149 | // Write program to EEPROM 150 | ZoneHeader h; 151 | h.textEnd = i._program.textEnd(); 152 | h.varsEnd = i._program.varsEnd(); 153 | h.arraysEnd = i._program.arraysEnd(); 154 | h.sp = i._program.sp(); 155 | if (!i2c_eeprom.write(zoneAddr, h)) 156 | return false; 157 | for (uint16_t p = 0; p 6 | * Copyright (C) 2019-2021 Terminal-BASIC team 7 | * 8 | * 9 | * This program is free software: you can redistribute it and/or modify 10 | * it under the terms of the GNU General Public License as published by 11 | * the Free Software Foundation, either version 3 of the License, or 12 | * (at your option) any later version. 13 | * 14 | * This program is distributed in the hope that it will be useful, 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | * GNU General Public License for more details. 18 | * 19 | * You should have received a copy of the GNU General Public License 20 | * along with this program. If not, see . 21 | */ 22 | 23 | /** 24 | * @file basic_exteeprom.hpp 25 | * @brief I2C/SPI external eeprom functions and commands 26 | */ 27 | 28 | #ifndef BASIC_EXTEEPROM_HPP 29 | #define BASIC_EXTEEPROM_HPP 30 | 31 | #include "basic_functionblock.hpp" 32 | 33 | namespace BASIC 34 | { 35 | 36 | class ExtEEPROM : public FunctionBlock 37 | { 38 | public: 39 | explicit ExtEEPROM(); 40 | private: 41 | static bool com_echain(Interpreter&); 42 | static bool com_eload(Interpreter&); 43 | static bool com_esave(Interpreter&); 44 | 45 | static const FunctionBlock::command _commands[] PROGMEM; 46 | // FunctionBlock interface 47 | protected: 48 | void _init() override; 49 | }; 50 | 51 | } // namespace BASIC 52 | 53 | #endif // BASIC_EXTEEPROM_HPP 54 | -------------------------------------------------------------------------------- /terminal-basic/basic_extmemfs.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of Terminal-BASIC: a lightweight BASIC-like language 3 | * interpreter. 4 | * 5 | * Copyright (C) 2016-2018 Andrey V. Skvortsov 6 | * Copyright (C) 2019-2021 Terminal-BASIC team 7 | * 8 | * 9 | * This program is free software: you can redistribute it and/or modify 10 | * it under the terms of the GNU General Public License as published by 11 | * the Free Software Foundation, either version 3 of the License, or 12 | * (at your option) any later version. 13 | * 14 | * This program is distributed in the hope that it will be useful, 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | * GNU General Public License for more details. 18 | * 19 | * You should have received a copy of the GNU General Public License 20 | * along with this program. If not, see . 21 | */ 22 | 23 | #ifndef BASIC_SDFS_HPP 24 | #define BASIC_SDFS_HPP 25 | 26 | #include "basic_functionblock.hpp" 27 | #include "basic_interpreter.hpp" 28 | 29 | #if CONF_USE_EXTMEMFS 30 | 31 | namespace BASIC 32 | { 33 | 34 | class FileStream : public Stream 35 | { 36 | public: 37 | 38 | FileStream() : m_file(0) {} 39 | 40 | explicit FileStream(HAL_extmem_file_t f) : 41 | m_file(f) {} 42 | 43 | void setFile(HAL_extmem_file_t f) 44 | { 45 | m_file = f; 46 | } 47 | 48 | void close() 49 | { 50 | HAL_extmem_closefile(m_file); 51 | } 52 | 53 | private: 54 | 55 | HAL_extmem_file_t m_file; 56 | 57 | // Print interface 58 | public: 59 | size_t write(uint8_t b) override 60 | { 61 | HAL_extmem_writetofile(m_file, b); 62 | return 1; 63 | } 64 | 65 | // Stream interface 66 | public: 67 | int available() override 68 | { 69 | const auto fsize = HAL_extmem_getfilesize(m_file); 70 | const auto fpos = HAL_extmem_getfileposition(m_file); 71 | return fsize - fpos; 72 | } 73 | 74 | void flush() override 75 | { 76 | } 77 | 78 | int peek() override 79 | { 80 | const auto pos = HAL_extmem_getfileposition(m_file); 81 | const int res = HAL_extmem_readfromfile(m_file); 82 | HAL_extmem_setfileposition(m_file, pos); 83 | return res; 84 | } 85 | 86 | int read() override 87 | { 88 | return HAL_extmem_readfromfile(m_file); 89 | } 90 | }; 91 | 92 | /** 93 | * @brief Module with commands to store the programs on the exxternal memory 94 | * file system 95 | */ 96 | class ExtmemFSModule : public FunctionBlock 97 | { 98 | // Function block interface 99 | public: 100 | ExtmemFSModule(); 101 | 102 | void loadAutorun(Interpreter&); 103 | 104 | private: 105 | static bool dchain(Interpreter&); 106 | static bool dsave(Interpreter&); 107 | static bool directory(Interpreter&); 108 | static bool scratch(Interpreter&); 109 | static bool dload(Interpreter&); 110 | static bool header(Interpreter&); 111 | #if USE_FILEOP 112 | static bool com_fclose(Interpreter&); 113 | static bool com_fdelete(Interpreter&); 114 | static bool com_fseek(Interpreter&); 115 | static bool com_fwrite(Interpreter&); 116 | 117 | static bool func_fopen(Interpreter&); 118 | static bool func_fsize(Interpreter&); 119 | static bool func_fread(Interpreter&); 120 | #endif // USE_FILEOP 121 | static bool getFileName(Interpreter&, char[]); 122 | static bool _loadText(FileStream&, Interpreter&); 123 | 124 | static const FunctionBlock::function _commands[] PROGMEM; 125 | #if USE_FILEOP 126 | static const FunctionBlock::function _functions[] PROGMEM; 127 | #endif 128 | }; 129 | 130 | } // namespace BASIC 131 | 132 | #endif // USESD 133 | 134 | #endif // BASIC_SDFS_HPP 135 | -------------------------------------------------------------------------------- /terminal-basic/basic_functionblock.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of Terminal-BASIC: a lightweight BASIC-like language 3 | * interpreter. 4 | * 5 | * Copyright (C) 2016-2018 Andrey V. Skvortsov 6 | * Copyright (C) 2019-2021 Terminal-BASIC team 7 | * 8 | * 9 | * This program is free software: you can redistribute it and/or modify 10 | * it under the terms of the GNU General Public License as published by 11 | * the Free Software Foundation, either version 3 of the License, or 12 | * (at your option) any later version. 13 | * 14 | * This program is distributed in the hope that it will be useful, 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | * GNU General Public License for more details. 18 | * 19 | * You should have received a copy of the GNU General Public License 20 | * along with this program. If not, see . 21 | */ 22 | 23 | #include "basic_functionblock.hpp" 24 | #include "basic_parser.hpp" 25 | #include "basic_parser_value.hpp" 26 | #include "basic_interpreter.hpp" 27 | 28 | namespace BASIC 29 | { 30 | 31 | FunctionBlock::FunctionBlock(FunctionBlock *next) : 32 | commandTokens(nullptr), commands(nullptr), 33 | functionTokens(nullptr), functions(nullptr), _next(next) 34 | { 35 | } 36 | 37 | void 38 | FunctionBlock::init() 39 | { 40 | this->_init(); 41 | if (_next != nullptr) 42 | _next->init(); 43 | } 44 | 45 | void 46 | FunctionBlock::setNext(FunctionBlock *next) 47 | { 48 | if (_next != nullptr) 49 | _next->setNext(next); 50 | else 51 | _next = next; 52 | } 53 | 54 | FunctionBlock::function 55 | FunctionBlock::getFunction(const char *name) const 56 | { 57 | function result; 58 | if (((result = _getFunction(name)) == nullptr) && 59 | _next != nullptr) 60 | result = _next->getFunction(name); 61 | return result; 62 | } 63 | 64 | FunctionBlock::command 65 | FunctionBlock::getCommand(const char *name) const 66 | { 67 | command result; 68 | if (((result = _getCommand(name)) == nullptr) && 69 | _next != nullptr) 70 | result = _next->getCommand(name); 71 | return result; 72 | } 73 | 74 | void 75 | FunctionBlock::getCommandName(command c, uint8_t* buf) const 76 | { 77 | uint8_t index = 0; 78 | command wc; 79 | if (commands != nullptr) { 80 | while ((wc = reinterpret_cast( 81 | pgm_read_ptr(&commands[index]))) != nullptr) { 82 | if (wc == c) { 83 | getToken(commandTokens, index, buf); 84 | return; 85 | } 86 | ++index; 87 | } 88 | } 89 | if (_next != nullptr) 90 | _next->getCommandName(c, buf); 91 | } 92 | 93 | FunctionBlock::function 94 | FunctionBlock::_getFunction(const char *name) const 95 | { 96 | function result = nullptr; 97 | 98 | if (functionTokens != nullptr) { 99 | uint8_t index; 100 | if (scanTable((const uint8_t*)name, functionTokens, &index)) { 101 | result = reinterpret_cast( 102 | pgm_read_ptr(&functions[index])); 103 | } 104 | } 105 | 106 | return result; 107 | } 108 | 109 | FunctionBlock::command 110 | FunctionBlock::_getCommand(const char *name) const 111 | { 112 | if (commandTokens == nullptr) 113 | return nullptr; 114 | 115 | uint8_t index; 116 | if (scanTable((const uint8_t*)name, commandTokens, &index)) 117 | return (reinterpret_cast( 118 | pgm_read_ptr(&commands[index]))); 119 | 120 | return nullptr; 121 | } 122 | 123 | #if USE_REALS 124 | bool 125 | FunctionBlock::general_func(Interpreter &i, _funcReal f) 126 | { 127 | Parser::Value v(Real(0)); 128 | i.popValue(v); 129 | if (v.type() == Parser::Value::INTEGER || 130 | #if USE_LONGINT 131 | v.type() == Parser::Value::LONG_INTEGER || 132 | #endif 133 | #if USE_LONG_REALS 134 | v.type() == Parser::Value::LONG_REAL || 135 | #endif 136 | v.type() == Parser::Value::REAL) { 137 | v = (*f)(Real(v)); 138 | if (i.pushValue(v)) 139 | return true; 140 | } 141 | return false; 142 | } 143 | 144 | #if USE_LONG_REALS 145 | bool 146 | FunctionBlock::general_func(Interpreter &i, _funcLongReal f) 147 | { 148 | Parser::Value v(LongReal(0)); 149 | i.popValue(v); 150 | if (v.type() == Parser::Value::INTEGER || 151 | #if USE_LONGINT 152 | v.type() == Parser::Value::LONG_INTEGER || 153 | #endif 154 | v.type() == Parser::Value::LONG_REAL || 155 | v.type() == Parser::Value::REAL) { 156 | v = (*f)(LongReal(v)); 157 | if (i.pushValue(v)) 158 | return true; 159 | } 160 | return false; 161 | } 162 | #endif // USE_LONG_REALS 163 | #endif // USE_REALS 164 | 165 | bool 166 | FunctionBlock::general_func(Interpreter &i, _funcInteger f) 167 | { 168 | INT v; 169 | if (getIntegerFromStack(i, v)) { 170 | v = (*f)(v); 171 | if (i.pushValue(v)) 172 | return true; 173 | } 174 | return false; 175 | } 176 | 177 | bool 178 | FunctionBlock::getIntegerFromStack(Interpreter &i, INT &num) 179 | { 180 | Parser::Value v(Integer(0)); 181 | if (i.popValue(v) && ( 182 | v.type() == Parser::Value::INTEGER 183 | #if USE_LONGINT 184 | || v.type() == Parser::Value::LONG_INTEGER 185 | #endif 186 | #if USE_REALS 187 | || v.type() == Parser::Value::REAL 188 | #endif 189 | )) { 190 | num = INT(v); 191 | return true; 192 | } 193 | return false; 194 | } 195 | 196 | #undef _Integer 197 | 198 | } // namespace BASIC 199 | -------------------------------------------------------------------------------- /terminal-basic/basic_functionblock.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of Terminal-BASIC: a lightweight BASIC-like language 3 | * interpreter. 4 | * 5 | * Copyright (C) 2016-2018 Andrey V. Skvortsov 6 | * Copyright (C) 2019-2021 Terminal-BASIC team 7 | * 8 | * 9 | * This program is free software: you can redistribute it and/or modify 10 | * it under the terms of the GNU General Public License as published by 11 | * the Free Software Foundation, either version 3 of the License, or 12 | * (at your option) any later version. 13 | * 14 | * This program is distributed in the hope that it will be useful, 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | * GNU General Public License for more details. 18 | * 19 | * You should have received a copy of the GNU General Public License 20 | * along with this program. If not, see . 21 | */ 22 | 23 | #ifndef BASIC_FUNCTIONBLOCK_HPP 24 | #define BASIC_FUNCTIONBLOCK_HPP 25 | 26 | #include 27 | #include "basic.hpp" 28 | 29 | namespace BASIC 30 | { 31 | 32 | class Interpreter; 33 | 34 | class FunctionBlock 35 | { 36 | public: 37 | 38 | typedef bool (*function)(Interpreter&); 39 | 40 | typedef bool (*command)(Interpreter&); 41 | 42 | function getFunction(const char*) const; 43 | 44 | command getCommand(const char*) const; 45 | 46 | void getCommandName(command, uint8_t*) const; 47 | 48 | void init(); 49 | 50 | FunctionBlock *next() { return _next; } 51 | 52 | void setNext(FunctionBlock *newVal); 53 | 54 | protected: 55 | #if USE_REALS 56 | typedef Real (*_funcReal)(Real); 57 | #if USE_LONG_REALS 58 | typedef LongReal (*_funcLongReal)(LongReal); 59 | #endif 60 | #endif // USE_REALS 61 | typedef INT (*_funcInteger)(INT); 62 | 63 | explicit FunctionBlock(FunctionBlock* =NULL); 64 | 65 | virtual void _init() {} 66 | /** 67 | * @brief return pointer to the function of this block 68 | * or NULL if no one 69 | * @param fName function name 70 | * @return function pointer 71 | */ 72 | function _getFunction(const char*) const; 73 | /** 74 | * @brief return pointer to the command, provided by this block 75 | * or NULL if no one 76 | * @param fName command name 77 | * @return command pointer 78 | */ 79 | command _getCommand(const char*) const; 80 | #if USE_REALS 81 | /** 82 | * @brief general function wrapper with 1 Real argument 83 | * @param interpreter Interpreter object 84 | * @param func underlying function pointer 85 | * @return ok status 86 | */ 87 | static bool general_func(Interpreter&, _funcReal); 88 | #if USE_LONG_REALS 89 | static bool general_func(Interpreter&, _funcLongReal); 90 | #endif 91 | #endif // USE_REALS 92 | /** 93 | * @brief general function wrapper with 1 Real argument 94 | * @param interpreter Interpreter object 95 | * @param func underlying function pointer 96 | * @return ok status 97 | */ 98 | static bool general_func(Interpreter&, _funcInteger); 99 | 100 | static bool getIntegerFromStack(Interpreter&, INT&); 101 | 102 | const uint8_t *commandTokens; 103 | const FunctionBlock::command *commands; 104 | const uint8_t *functionTokens; 105 | const FunctionBlock::function *functions; 106 | private: 107 | FunctionBlock *_next; 108 | }; 109 | 110 | } // namespace BASIC 111 | 112 | #endif // BASIC_FUNCTIONBLOCK_HPP 113 | -------------------------------------------------------------------------------- /terminal-basic/basic_gfx.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of Terminal-BASIC: a lightweight BASIC-like language 3 | * interpreter. 4 | * 5 | * Copyright (C) 2016-2018 Andrey V. Skvortsov 6 | * Copyright (C) 2019-2021 Terminal-BASIC team 7 | * 8 | * 9 | * This program is free software: you can redistribute it and/or modify 10 | * it under the terms of the GNU General Public License as published by 11 | * the Free Software Foundation, either version 3 of the License, or 12 | * (at your option) any later version. 13 | * 14 | * This program is distributed in the hope that it will be useful, 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | * GNU General Public License for more details. 18 | * 19 | * You should have received a copy of the GNU General Public License 20 | * along with this program. If not, see . 21 | */ 22 | 23 | #ifndef BASIC_GFX_HPP 24 | #define BASIC_GFX_HPP 25 | 26 | #include "basic_functionblock.hpp" 27 | #include "basic_interpreter.hpp" 28 | 29 | namespace BASIC 30 | { 31 | 32 | class GFXModule : public FunctionBlock 33 | { 34 | public: 35 | explicit GFXModule(); 36 | 37 | #if GFX_EXP_COLOR 38 | static bool command_boxc(Interpreter&); 39 | #endif 40 | static bool command_box(Interpreter&); 41 | #if GFX_EXP_COLOR 42 | static bool command_circlec(Interpreter&); 43 | #endif 44 | static bool command_circle(Interpreter&); 45 | static bool command_color(Interpreter&); 46 | static bool command_cursor(Interpreter&); 47 | #if GFX_EXP_COLOR 48 | static bool command_ellipsec(Interpreter&); 49 | #endif 50 | static bool command_ellipse(Interpreter&); 51 | #if GFX_EXP_COLOR 52 | static bool command_linec(Interpreter&); 53 | #endif 54 | static bool command_lineto(Interpreter&); 55 | static bool command_line(Interpreter&); 56 | #if GFX_EXP_COLOR 57 | static bool command_pointc(Interpreter&); 58 | #endif 59 | static bool command_point(Interpreter&); 60 | static bool command_screen(Interpreter&); 61 | 62 | protected: 63 | 64 | void _init() override; 65 | 66 | private: 67 | static const FunctionBlock::command comms[] PROGMEM; 68 | }; 69 | 70 | } // namespace BASIC 71 | 72 | #endif // BASIC_GFX_HPP 73 | -------------------------------------------------------------------------------- /terminal-basic/basic_internalfuncs.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of Terminal-BASIC: a lightweight BASIC-like language 3 | * interpreter. 4 | * 5 | * Copyright (C) 2016-2018 Andrey V. Skvortsov 6 | * Copyright (C) 2019-2021 Terminal-BASIC team 7 | * 8 | * 9 | * This program is free software: you can redistribute it and/or modify 10 | * it under the terms of the GNU General Public License as published by 11 | * the Free Software Foundation, either version 3 of the License, or 12 | * (at your option) any later version. 13 | * 14 | * This program is distributed in the hope that it will be useful, 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | * GNU General Public License for more details. 18 | * 19 | * You should have received a copy of the GNU General Public License 20 | * along with this program. If not, see . 21 | */ 22 | 23 | #ifndef BASIC_INTERNALFUNCS_HPP 24 | #define BASIC_INTERNALFUNCS_HPP 25 | 26 | #include "basic_functionblock.hpp" 27 | #include "helper.hpp" 28 | 29 | namespace BASIC 30 | { 31 | 32 | class InternalFunctions : public FunctionBlock 33 | { 34 | public: 35 | InternalFunctions(FunctionBlock* = nullptr); 36 | private: 37 | static bool func_abs(Interpreter&); 38 | #if USE_ASC 39 | static bool func_asc(Interpreter&); 40 | #endif 41 | #if USE_CHR 42 | static bool func_chr(Interpreter&); 43 | #endif 44 | #if USE_HEX 45 | static bool func_hex(Interpreter&); 46 | #endif 47 | #if USE_INKEY 48 | static bool func_inkey(Interpreter&); 49 | #endif 50 | #if USE_REALS 51 | static bool func_int(Interpreter&); 52 | #endif 53 | #if USE_LEFT 54 | static bool func_left(Interpreter&); 55 | #endif 56 | #if USE_RIGHT 57 | static bool func_right(Interpreter&); 58 | #endif 59 | #if USE_LEN 60 | static bool func_len(Interpreter&); 61 | #endif 62 | #if USE_MID || USE_SEG 63 | static bool func_mid(Interpreter&); 64 | #endif 65 | #if USE_PEEK_POKE 66 | static bool func_peek(Interpreter&); 67 | #endif 68 | static bool func_result(Interpreter&); 69 | #if USE_RANDOM 70 | static bool func_rnd(Interpreter&); 71 | #endif 72 | static bool func_sgn(Interpreter&); 73 | static bool func_str(Interpreter&); 74 | static bool func_tim(Interpreter&); 75 | #if USE_VAL 76 | static bool func_val(Interpreter&); 77 | #endif 78 | #if USE_REALS 79 | #define ___TYP Real 80 | #else 81 | #define ___TYP INT 82 | #endif // USE_REALS 83 | static ___TYP sgn(___TYP); 84 | #undef ___TYP 85 | 86 | static const FunctionBlock::function funcs[] PROGMEM; 87 | }; 88 | 89 | } // namespace BASIC 90 | 91 | #endif // BASIC_INTERNALFUNCS_HPP 92 | -------------------------------------------------------------------------------- /terminal-basic/basic_lexer.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of Terminal-BASIC: a lightweight BASIC-like language 3 | * interpreter. 4 | * 5 | * Copyright (C) 2016-2018 Andrey V. Skvortsov 6 | * Copyright (C) 2019-2021 Terminal-BASIC team 7 | * 8 | * 9 | * This program is free software: you can redistribute it and/or modify 10 | * it under the terms of the GNU General Public License as published by 11 | * the Free Software Foundation, either version 3 of the License, or 12 | * (at your option) any later version. 13 | * 14 | * This program is distributed in the hope that it will be useful, 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | * GNU General Public License for more details. 18 | * 19 | * You should have received a copy of the GNU General Public License 20 | * along with this program. If not, see . 21 | */ 22 | 23 | #ifndef BASIC_LEXER_H 24 | #define BASIC_LEXER_H 25 | 26 | #include "basic.h" 27 | #include "basic_value.h" 28 | 29 | __BEGIN_DECLS 30 | 31 | /** 32 | * @brief lexical analyses stage errors 33 | */ 34 | typedef enum basic_lexer_error 35 | { 36 | BASIC_LEXER_ERROR_NOERROR = 0, 37 | BASIC_LEXER_ERROR_STRING_OVERFLOW = 1 38 | } basic_lexer_error_t; 39 | 40 | struct basic_lexer_context 41 | { 42 | const uint8_t *string_to_parse; 43 | /* position in the parsing string */ 44 | uint8_t string_pointer; 45 | 46 | basic_token_t token; 47 | 48 | /* current identifier string */ 49 | char _id[STRING_SIZE]; 50 | /* Identifier string pointer */ 51 | uint8_t _value_pointer; 52 | /* scanned numeric/logical value */ 53 | basic_value_t value; 54 | /* scanner error */ 55 | basic_lexer_error_t _error; 56 | 57 | BOOLEAN tokenized; 58 | }; 59 | 60 | /** 61 | * @brief Initialize lexer by the string 62 | * @param self lexer context 63 | * @param str ASCII or tokenized basic string 64 | * @param tokenized 65 | */ 66 | void basic_lexer_init(basic_lexer_context_t*, const uint8_t*, BOOLEAN); 67 | 68 | /** 69 | * @brief Get next token from ASCII string 70 | * @param self lexer context 71 | * @return true if there are more symbols to scan 72 | */ 73 | BOOLEAN basic_lexer_getnextPlain(basic_lexer_context_t*); 74 | 75 | /** 76 | * @brief Get next token from tokenized string 77 | * @param self lexer context 78 | * @return true if there are more symbols to scan 79 | */ 80 | BOOLEAN basic_lexer_getnextTokenized(basic_lexer_context_t*); 81 | 82 | BOOLEAN basic_lexer_getNext(basic_lexer_context_t*); 83 | 84 | /** 85 | * @brief Get token text representation to buffer 86 | * @param t token 87 | * @param buf char buffer of appropriate length 88 | */ 89 | BOOLEAN basic_lexer_tokenString(basic_token_t, uint8_t*); 90 | 91 | /** 92 | * @brief tokenize a string 93 | * @param self Lexer context 94 | * @param dst destination buffer 95 | * @param dstsize length of the dst buffer 96 | * @param src source buffer 97 | * @return size of the actually tokenized buffer 98 | */ 99 | uint8_t basic_lexer_tokenize(basic_lexer_context_t*, uint8_t*, uint8_t, 100 | const uint8_t*); 101 | 102 | __END_DECLS 103 | 104 | #endif /* BASIC_LEXER_H */ 105 | 106 | -------------------------------------------------------------------------------- /terminal-basic/basic_lexer.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of Terminal-BASIC: a lightweight BASIC-like language 3 | * interpreter. 4 | * 5 | * Copyright (C) 2016-2018 Andrey V. Skvortsov 6 | * Copyright (C) 2019-2021 Terminal-BASIC team 7 | * 8 | * 9 | * This program is free software: you can redistribute it and/or modify 10 | * it under the terms of the GNU General Public License as published by 11 | * the Free Software Foundation, either version 3 of the License, or 12 | * (at your option) any later version. 13 | * 14 | * This program is distributed in the hope that it will be useful, 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | * GNU General Public License for more details. 18 | * 19 | * You should have received a copy of the GNU General Public License 20 | * along with this program. If not, see . 21 | */ 22 | 23 | #ifndef LEXER_HPP 24 | #define LEXER_HPP 25 | 26 | #include 27 | #include 28 | 29 | #include "arduino_logger.hpp" 30 | #include "basic_parser.hpp" 31 | #include "basic_parser_value.hpp" 32 | #include "helper.hpp" 33 | #include "basic_lexer.h" 34 | 35 | namespace BASIC 36 | { 37 | 38 | #if ARDUINO_LOG 39 | Logger& 40 | operator<<(Logger &logger, Token tok); 41 | #endif 42 | 43 | /** 44 | * @brief Lexical analyzer class 45 | */ 46 | class Lexer 47 | { 48 | public: 49 | /** 50 | * @brief lexical analyses stage errors 51 | */ 52 | enum Error : uint8_t 53 | { 54 | NO_ERROR = 0, 55 | STRING_OVERFLOW = 1 56 | }; 57 | /** 58 | * @brief initialize lexer session 59 | * @param str null-terminating string to extract tokens from 60 | * @param tok tokenized text flag 61 | */ 62 | void init(const uint8_t*, bool); 63 | /** 64 | * @brief continue lexical analyze for next token 65 | * @return string end flag 66 | */ 67 | bool getNext(); 68 | /** 69 | * @brief get last extracted token 70 | * @return last token 71 | */ 72 | Token getToken() const { return Token(m_context.token); } 73 | /** 74 | * @brief get last lexer error 75 | * @return error code 76 | */ 77 | Error getError() const { return Error(m_context._error); } 78 | /** 79 | * @brief get current value (numberm boolean...) 80 | * @return value, extracted from string 81 | */ 82 | const Parser::Value &getValue() const 83 | { 84 | return reinterpret_cast(m_context.value); 85 | } 86 | /** 87 | * @brief get current string (identifier) 88 | * @return identifier string 89 | */ 90 | const char *id() const { return m_context._id; } 91 | /** 92 | * @brief get current string position 93 | * @return string position index 94 | */ 95 | uint8_t getPointer() const { return m_context.string_pointer; } 96 | 97 | void setPointer(uint8_t newVal) { m_context.string_pointer = newVal; } 98 | 99 | const uint8_t* getString() const { return m_context.string_to_parse; } 100 | /** 101 | * @brief Get null-terminated token string representation 102 | * @param token Token code 103 | * @param buf String buffer to copy to 104 | * @return buffer pointer or nullptr if error 105 | */ 106 | static bool getTokenString(Token, uint8_t*); 107 | 108 | /** 109 | * 110 | * @param dst 111 | * @param dstlen 112 | * @param src 113 | */ 114 | uint8_t tokenize(uint8_t*, uint8_t, const uint8_t*); 115 | private: 116 | 117 | // Parse decimal number 118 | void decimalNumber(); 119 | // Parse Binary number 120 | void binaryInteger(); 121 | #if USE_REALS 122 | void binaryReal(); 123 | bool numberScale(); 124 | #endif 125 | void ident(); 126 | void stringConst(); 127 | 128 | basic_lexer_context_t m_context; 129 | }; 130 | 131 | } // namespace BASIC 132 | 133 | #endif 134 | -------------------------------------------------------------------------------- /terminal-basic/basic_lexer_en.c: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of Terminal-BASIC: a lightweight BASIC-like language 3 | * interpreter. 4 | * 5 | * Copyright (C) 2016-2018 Andrey V. Skvortsov 6 | * Copyright (C) 2019-2021 Terminal-BASIC team 7 | * 8 | * 9 | * This program is free software: you can redistribute it and/or modify 10 | * it under the terms of the GNU General Public License as published by 11 | * the Free Software Foundation, either version 3 of the License, or 12 | * (at your option) any later version. 13 | * 14 | * This program is distributed in the hope that it will be useful, 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | * GNU General Public License for more details. 18 | * 19 | * You should have received a copy of the GNU General Public License 20 | * along with this program. If not, see . 21 | */ 22 | 23 | #include "avr/pgmspace.h" 24 | #include "basic_config.h" 25 | #include "basic.h" 26 | 27 | #if CONF_LEXER_LANG == LANG_EN 28 | 29 | const uint8_t _basic_lexer_symbolsShift PROGMEM = 0; 30 | 31 | const uint8_t _basic_lexer_tokenTable[] PROGMEM = { 32 | ASCII_NUL, 33 | 'A', 'N', 'D',ASCII_NUL, // 1 34 | #if USE_DUMP 35 | 'A', 'R', 'R', 'A', 'Y', 'S',ASCII_NUL, // 2 36 | #endif 37 | #if USE_SAVE_LOAD 38 | 'C', 'H', 'A', 'I', 'N', ASCII_NUL, // 4 39 | #endif 40 | #if USE_TEXTATTRIBUTES 41 | 'C', 'L', 'S', ASCII_NUL, // 5 42 | #endif 43 | #if USESTOPCONT 44 | 'C', 'O', 'N', 'T', ASCII_NUL, // 6 45 | #endif 46 | #if USE_MATRIX 47 | 'C', 'O', 'N', ASCII_NUL, // 7 48 | #endif 49 | #if USE_DATA 50 | 'D', 'A', 'T', 'A', ASCII_NUL, // 8 51 | #endif 52 | #if USE_DEFFN 53 | 'D', 'E', 'F', ASCII_NUL, // 9 54 | #endif 55 | #if USE_DELAY 56 | 'D', 'E', 'L', 'A', 'Y', ASCII_NUL, // 10 57 | #endif 58 | #if USE_MATRIX 59 | 'D', 'E', 'T', ASCII_NUL, // 11 60 | #endif 61 | 'D', 'I', 'M', ASCII_NUL, // 12 62 | #if USE_DIV_KW 63 | 'D', 'I', 'V', ASCII_NUL, // 13 64 | #endif 65 | #if USE_DUMP 66 | 'D', 'U', 'M', 'P', ASCII_NUL, // 15 67 | #endif 68 | 'E', 'N', 'D', ASCII_NUL, 69 | 'F', 'A', 'L', 'S', 'E', ASCII_NUL, 70 | #if USE_DEFFN 71 | 'F', 'N', ASCII_NUL, // 18 72 | #endif 73 | 'F', 'O', 'R', ASCII_NUL, // 19 74 | 'G', 'O', 'S', 'U', 'B', ASCII_NUL, // 20 75 | 'G', 'O', 'T', 'O', ASCII_NUL, // 11 76 | #if CONF_SEPARATE_GO_TO 77 | 'G', 'O', ASCII_NUL, // 12 78 | #endif 79 | #if USE_MATRIX 80 | 'I', 'D', 'N', ASCII_NUL, 81 | #endif 82 | 'I', 'F', ASCII_NUL, // 16 83 | 'I', 'N', 'P', 'U', 'T', ASCII_NUL, // 17 84 | #if USE_MATRIX 85 | 'I', 'N', 'V', ASCII_NUL, 86 | #endif 87 | 'L', 'E', 'T', ASCII_NUL, 88 | 'L', 'I', 'S', 'T', ASCII_NUL, // 19 89 | #if USE_SAVE_LOAD 90 | 'L', 'O', 'A', 'D', ASCII_NUL, // 20 91 | #endif 92 | #if USE_TEXTATTRIBUTES 93 | 'L', 'O', 'C', 'A', 'T', 'E', ASCII_NUL, // 21 94 | #endif 95 | #if USE_MATRIX 96 | 'M', 'A', 'T', ASCII_NUL, // 23 97 | #endif 98 | #if USE_INTEGER_DIV 99 | 'M', 'O', 'D', ASCII_NUL, // 24 100 | #endif 101 | 'N', 'E', 'W', ASCII_NUL, // 21 102 | 'N', 'E', 'X', 'T', ASCII_NUL, // 22 103 | 'N', 'O', 'T', ASCII_NUL, 104 | #if CONF_USE_ON_GOTO 105 | 'O', 'N', ASCII_NUL, // 23 106 | #endif 107 | 'O', 'R', ASCII_NUL, 108 | #if USE_PEEK_POKE 109 | 'P', 'O', 'K', 'E', ASCII_NUL, 110 | #endif 111 | 'P', 'R', 'I', 'N', 'T', ASCII_NUL, 112 | #if USE_RANDOM 113 | 'R', 'A', 'N', 'D', 'O', 'M', 'I', 'Z', 'E', ASCII_NUL, //26 114 | #endif 115 | #if USE_DATA 116 | 'R', 'E', 'A', 'D', ASCII_NUL, // 27 117 | #endif 118 | 'R', 'E', 'M', ASCII_NUL, 119 | #if USE_DATA 120 | 'R', 'E', 'S', 'T', 'O', 'R', 'E', ASCII_NUL, 121 | #endif 122 | 'R', 'E', 'T', 'U', 'R', 'N', ASCII_NUL, 123 | 'R', 'U', 'N', ASCII_NUL, 124 | #if USE_SAVE_LOAD 125 | 'S', 'A', 'V', 'E', ASCII_NUL, 126 | #endif 127 | #if CONF_USE_SPC_PRINT_COM 128 | 'S', 'P', 'C', ASCII_NUL, 129 | #endif 130 | 'S', 'T', 'E', 'P', ASCII_NUL, 131 | #if USESTOPCONT 132 | 'S', 'T', 'O', 'P', ASCII_NUL, 133 | #endif 134 | #if USE_TEXTATTRIBUTES 135 | 'T', 'A', 'B', ASCII_NUL, 136 | #endif 137 | 'T', 'H', 'E', 'N', ASCII_NUL, 138 | 'T', 'O', ASCII_NUL, 139 | #if USE_MATRIX 140 | 'T', 'R', 'N', ASCII_NUL, 141 | #endif 142 | 'T', 'R', 'U', 'E', ASCII_NUL, 143 | #if USE_DUMP 144 | 'V', 'A', 'R', 'S', ASCII_NUL, 145 | #endif 146 | 'X', 'O', 'R', ASCII_NUL, 147 | #if USE_MATRIX 148 | 'Z', 'E', 'R',ASCII_NUL, 149 | #endif 150 | ASCII_ETX 151 | }; 152 | 153 | #endif // CONF_LEXER_LANG 154 | -------------------------------------------------------------------------------- /terminal-basic/basic_lexer_fr.c: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of Terminal-BASIC: a lightweight BASIC-like language 3 | * interpreter. 4 | * 5 | * Copyright (C) 2016-2018 Andrey V. Skvortsov 6 | * Copyright (C) 2019-2021 Terminal-BASIC team 7 | * 8 | * 9 | * This program is free software: you can redistribute it and/or modify 10 | * it under the terms of the GNU General Public License as published by 11 | * the Free Software Foundation, either version 3 of the License, or 12 | * (at your option) any later version. 13 | * 14 | * This program is distributed in the hope that it will be useful, 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | * GNU General Public License for more details. 18 | * 19 | * You should have received a copy of the GNU General Public License 20 | * along with this program. If not, see . 21 | */ 22 | 23 | #include "avr/pgmspace.h" 24 | #include "basic_config.h" 25 | #include "basic.h" 26 | 27 | #if CONF_LEXER_LANG == LANG_FR 28 | 29 | const uint8_t _basic_lexer_symbolsShift PROGMEM = 0; 30 | 31 | const uint8_t _basic_lexer_tokenTable[] PROGMEM = { 32 | ASCII_NUL, // 0 33 | 'A', 'L', 'L', 'E', 'R', 'A', ASCII_NUL, // 1 34 | 'A', 'L', 'L', 'E', 'R', 'S', 'O', 'U', 'S', ASCII_NUL, // 2 35 | 'A', 'L', 'O', 'R', 'S', ASCII_NUL, // 3 36 | 'A', 'N', 'D', ASCII_NUL, // 4 37 | #if USE_DUMP 38 | 'A', 'R', 'R', 'A', 'Y', 'S',ASCII_NUL, // 5 39 | #endif 40 | #if USE_SAVE_LOAD 41 | 'C', 'H', 'A', 'I', 'N', ASCII_NUL, // 6 42 | #endif 43 | #if USE_TEXTATTRIBUTES 44 | 'C', 'L', 'S', ASCII_NUL, // 7 45 | #endif 46 | #if USESTOPCONT 47 | 'C', 'O', 'N', 'T', ASCII_NUL, // 8 48 | #endif 49 | #if USE_MATRIX 50 | 'C', 'O', 'N', ASCII_NUL, // 9 51 | #endif 52 | #if USE_DATA 53 | 'D', 'A', 'T', 'A', ASCII_NUL, // 10 54 | #endif 55 | #if USE_DEFFN 56 | 'D', 'E', 'F', ASCII_NUL, // 11 57 | #endif 58 | #if USE_DELAY 59 | 'D', 'E', 'L', 'A', 'Y', ASCII_NUL, // 12 60 | #endif 61 | #if USE_MATRIX 62 | 'D', 'E', 'T', ASCII_NUL, // 13 63 | #endif 64 | 'D', 'I', 'M', ASCII_NUL, // 14 65 | #if USE_DIV_KW 66 | 'D', 'I', 'V', ASCII_NUL, // 15 67 | #endif 68 | #if USE_DUMP 69 | 'D', 'U', 'M', 'P', ASCII_NUL, // 16 70 | #endif 71 | #if CONF_USE_ON_GOTO 72 | 'E', 'N', 'C', 'A', 'S', ASCII_NUL, // 17 73 | #endif 74 | 'F', 'A', 'L', 'S', 'E', ASCII_NUL, // 18 75 | 'F', 'I', 'N', ASCII_NUL, // 19 76 | #if USE_DEFFN 77 | 'F', 'N', ASCII_NUL, // 20 78 | #endif 79 | #if CONF_SEPARATE_GO_TO 80 | 'G', 'O', ASCII_NUL, // 21 81 | #endif 82 | #if USE_MATRIX 83 | 'I', 'D', 'N', ASCII_NUL, // 22 84 | #endif 85 | 'I', 'N', 'P', 'U', 'T', ASCII_NUL, // 23 86 | #if USE_MATRIX 87 | 'I', 'N', 'V', ASCII_NUL, // 24 88 | #endif 89 | 'J', 'U', 'S', 'Q', 'U', 'A', ASCII_NUL, // 25 90 | 'L', 'E', 'T', ASCII_NUL, // 26 91 | 'L', 'I', 'S', 'T', 'E', 'R', ASCII_NUL, // 27 92 | #if USE_SAVE_LOAD 93 | 'L', 'O', 'A', 'D', ASCII_NUL, // 28 94 | #endif 95 | #if USE_TEXTATTRIBUTES 96 | 'L', 'O', 'C', 'A', 'T', 'E', ASCII_NUL, // 29 97 | #endif 98 | #if USE_MATRIX 99 | 'M', 'A', 'T', ASCII_NUL, // 30 100 | #endif 101 | #if USE_INTEGER_DIV 102 | 'M', 'O', 'D', ASCII_NUL, // 31 103 | #endif 104 | 'N', 'E', 'W', ASCII_NUL, // 32 105 | 'N', 'O', 'T', ASCII_NUL, 106 | 'O', 'R', ASCII_NUL, 107 | #if USE_PEEK_POKE 108 | 'P', 'O', 'K', 'E', ASCII_NUL, 109 | #endif 110 | 'P', 'O', 'U', 'R', ASCII_NUL, // 19 111 | 'P', 'R', 'I', 'N', 'T', ASCII_NUL, 112 | #if USE_RANDOM 113 | 'R', 'A', 'N', 'D', 'O', 'M', 'I', 'Z', 'E', ASCII_NUL, //26 114 | #endif 115 | #if USE_DATA 116 | 'R', 'E', 'A', 'D', ASCII_NUL, // 27 117 | #endif 118 | 'R', 'E', 'M', ASCII_NUL, 119 | #if USE_DATA 120 | 'R', 'E', 'S', 'T', 'O', 'R', 'E', ASCII_NUL, 121 | #endif 122 | 'R', 'E', 'T', 'O', 'U', 'R', ASCII_NUL, 123 | 'R', 'U', 'N', ASCII_NUL, 124 | #if USE_SAVE_LOAD 125 | 'S', 'A', 'V', 'E', ASCII_NUL, 126 | #endif 127 | 'S', 'I', ASCII_NUL, // 16 128 | #if CONF_USE_SPC_PRINT_COM 129 | 'S', 'P', 'C', ASCII_NUL, 130 | #endif 131 | 'S', 'T', 'E', 'P', ASCII_NUL, 132 | #if USESTOPCONT 133 | 'S', 'T', 'O', 'P', ASCII_NUL, 134 | #endif 135 | 'S', 'U', 'I', 'V', 'A', 'N', 'T', ASCII_NUL, 136 | #if USE_TEXTATTRIBUTES 137 | 'T', 'A', 'B', ASCII_NUL, 138 | #endif 139 | #if USE_MATRIX 140 | 'T', 'R', 'N', ASCII_NUL, 141 | #endif 142 | 'T', 'R', 'U', 'E', ASCII_NUL, 143 | #if USE_DUMP 144 | 'V', 'A', 'R', 'S', ASCII_NUL, 145 | #endif 146 | 'X', 'O', 'R', ASCII_NUL, 147 | #if USE_MATRIX 148 | 'Z', 'E', 'R',ASCII_NUL, 149 | #endif 150 | ASCII_ETX 151 | }; 152 | 153 | #endif // CONF_LEXER_LANG 154 | -------------------------------------------------------------------------------- /terminal-basic/basic_lexer_ru.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/terminal-basic-team/terminalbasic-arduino/696be0738c213082125c95f4c6ae180d2989d50e/terminal-basic/basic_lexer_ru.c -------------------------------------------------------------------------------- /terminal-basic/basic_lexerw.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of Terminal-BASIC: a lightweight BASIC-like language 3 | * interpreter. 4 | * 5 | * Copyright (C) 2016-2018 Andrey V. Skvortsov 6 | * Copyright (C) 2019-2021 Terminal-BASIC team 7 | * 8 | * 9 | * This program is free software: you can redistribute it and/or modify 10 | * it under the terms of the GNU General Public License as published by 11 | * the Free Software Foundation, either version 3 of the License, or 12 | * (at your option) any later version. 13 | * 14 | * This program is distributed in the hope that it will be useful, 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | * GNU General Public License for more details. 18 | * 19 | * You should have received a copy of the GNU General Public License 20 | * along with this program. If not, see . 21 | */ 22 | 23 | #include "basic_lexer.hpp" 24 | #include "helper.hpp" 25 | 26 | #include 27 | #include 28 | #include 29 | #include 30 | 31 | /* 32 | * OP_AND = "AND" // 1 33 | * KW_ARRAYS = "ARRAYS" // 1 34 | * KW_BASE = "BASE" // 2 35 | * COM_CHAIN = "CHAIN" // 3 36 | * COM_CLS = "CLS" // 4 37 | * KW_CON = "CON" 38 | * KW_DATA = "DATA" // 5 39 | * KW_DEF = "DEF" // 6 40 | * KW_DET = "DET" 41 | * COM_DELAY = "DELAY" // 7 42 | * KW_DIM = "DIM" // 8 43 | * KW_DO = "DO" 44 | * COM_DUMP = "DUMP" // 9 45 | * KW_END = "END" // 10 46 | * KW_FALSE = "FALSE" // 11 47 | * KW_FOR = "FOR" // 12 48 | * KW_GOSUB = "GOSUB" // 13 49 | * KW_GOTO = "GOTO" // 14 50 | * KW_GO = "GO" // 15 51 | * KW_IDN = "IDN" 52 | * KW_IF = "IF" // 16 53 | * KW_INPUT = "INPUT" // 17 54 | * KW_INV = "INV" 55 | * KW_LET = "LET" // 18 56 | * COM_LIST = "LIST" // 19 57 | * COM_LOAD = "LOAD" // 20 58 | * KW_MAT = "MAT" 59 | * COM_NEW = "NEW" // 21 60 | * KW_NEXT = "NEXT" // 22 61 | * OP_NOT = "NOT" 62 | * KW_ON = "ON" // 23 63 | * KW_OPTION = "OPTION" // 24 64 | * OP_OR = "OR" 65 | * KW_PRINT = "PRINT" // 25 66 | * KW_RANDOMIZE = "RANDOMIZE" 67 | * KW_READ = "READ" 68 | * KW_REM = "REM" 69 | * KW_RETURN = "RETURN" 70 | * COM_RUN = "RUN" 71 | * COM_SAVE = "SAVE" 72 | * KW_STEP = "STEP" 73 | * KW_STOP = "STOP" 74 | * KW_TAB = "TAB" 75 | * KW_THEN = "THEN" 76 | * KW_TO = "TO" 77 | * KW_TRN = "TRN" 78 | * KW_TRUE = "TRUE" 79 | * KW_VARS = "VARS" 80 | * KW_ZER = "ZER" 81 | * 82 | * STAR = '*' 83 | * SLASH = '/' 84 | * PLUS = '+' 85 | * COLON = ':' 86 | * SEMI = ';' 87 | * LT = '<' 88 | * LTE = "<=" 89 | * GT = '>' 90 | * GTE = ">=" 91 | * EQUALS = '=' 92 | * NE = "<>" 93 | * NEA = "><" 94 | * MINUS = '-' 95 | * POW = '^' 96 | * IDENT = [A-Z][A-Z0-9]* 97 | * C_INTEGER = [0-9]+ 98 | * C_REAL = [0-9]+[.][0-9]* 99 | */ 100 | 101 | namespace BASIC 102 | { 103 | 104 | #if ARDUINO_LOG 105 | 106 | Logger& 107 | operator<<(Logger &logger, Token tok) 108 | { 109 | char buf[12]; 110 | strcpy_P(buf, (PGM_P) pgm_read_word(&(Lexer::tokenStrings[uint8_t(tok)]))); 111 | 112 | logger.log(buf); 113 | return (logger); 114 | } 115 | #endif 116 | 117 | #define SYM (uint8_t(_string[_pointer])) 118 | 119 | bool 120 | Lexer::getTokenString(Token t, uint8_t *buf) 121 | { 122 | return basic_lexer_tokenString(basic_token_t(t), buf); 123 | } 124 | 125 | void 126 | Lexer::init(const uint8_t *string, bool tok) 127 | { 128 | basic_lexer_init(&m_context, string, tok); 129 | } 130 | 131 | bool 132 | Lexer::getNext() 133 | { 134 | return basic_lexer_getNext(&m_context); 135 | } 136 | 137 | uint8_t 138 | Lexer::tokenize(uint8_t* dst, uint8_t dstlen, const uint8_t* src) 139 | { 140 | return basic_lexer_tokenize(&m_context, dst, dstlen, src); 141 | } 142 | 143 | } // namespace BASIC 144 | -------------------------------------------------------------------------------- /terminal-basic/basic_math.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of Terminal-BASIC: a lightweight BASIC-like language 3 | * interpreter. 4 | * 5 | * Copyright (C) 2016-2018 Andrey V. Skvortsov 6 | * Copyright (C) 2019-2021 Terminal-BASIC team 7 | * 8 | * 9 | * This program is free software: you can redistribute it and/or modify 10 | * it under the terms of the GNU General Public License as published by 11 | * the Free Software Foundation, either version 3 of the License, or 12 | * (at your option) any later version. 13 | * 14 | * This program is distributed in the hope that it will be useful, 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | * GNU General Public License for more details. 18 | * 19 | * You should have received a copy of the GNU General Public License 20 | * along with this program. If not, see . 21 | */ 22 | 23 | /** 24 | * @file basic_math.hpp 25 | * @brief Mathematical functions container 26 | */ 27 | 28 | #ifndef BASIC_MATH_HPP 29 | #define BASIC_MATH_HPP 30 | 31 | #include "basic_functionblock.hpp" 32 | #include "basic_interpreter.hpp" 33 | 34 | #if USEMATH 35 | #if !USE_REALS 36 | #error Math module requires real arithmetics support 37 | #endif 38 | #endif // USEMATH 39 | 40 | namespace BASIC 41 | { 42 | 43 | class Math : public FunctionBlock 44 | { 45 | public: 46 | explicit Math(); 47 | private: 48 | #if M_TRIGONOMETRIC 49 | static bool func_cos(Interpreter&); 50 | static bool func_cot(Interpreter&); 51 | static bool func_sin(Interpreter&); 52 | static bool func_tan(Interpreter&); 53 | 54 | static Real cos_r(Real); 55 | static Real cot_r(Real); 56 | static Real sin_r(Real); 57 | static Real tan_r(Real); 58 | #if USE_LONG_REALS 59 | static bool func_cos_lr(Interpreter&); 60 | static bool func_cot_lr(Interpreter&); 61 | static bool func_sin_lr(Interpreter&); 62 | static bool func_tan_lr(Interpreter&); 63 | 64 | static LongReal cos_lr(LongReal); 65 | static LongReal cot_lr(LongReal); 66 | static LongReal sin_lr(LongReal); 67 | static LongReal tan_lr(LongReal); 68 | #endif // USE_LONG_REALS 69 | #endif // M_TRIGONOMETRIC 70 | #if M_REVERSE_TRIGONOMETRIC 71 | static bool func_acs(Interpreter&); 72 | static bool func_asn(Interpreter&); 73 | static bool func_atn(Interpreter&); 74 | 75 | static Real acs_r(Real); 76 | static Real asn_r(Real); 77 | static Real atn_r(Real); 78 | #if USE_LONG_REALS 79 | static bool func_acs_lr(Interpreter&); 80 | static bool func_asn_lr(Interpreter&); 81 | static bool func_atn_lr(Interpreter&); 82 | 83 | static LongReal acs_lr(LongReal); 84 | static LongReal asn_lr(LongReal); 85 | static LongReal atn_lr(LongReal); 86 | #endif 87 | #if M_ADDITIONAL 88 | static bool func_atn2(Interpreter&); 89 | #if USE_LONG_REALS 90 | static bool func_atn2_lr(Interpreter&); 91 | #endif 92 | #endif // M_ADDITIONAL 93 | #endif // M_REVERSE_TRIGONOMETRIC 94 | #if M_HYPERBOLIC 95 | static bool func_cosh(Interpreter&); 96 | static bool func_sinh(Interpreter&); 97 | static bool func_tanh(Interpreter&); 98 | 99 | static Real cosh_r(Real); 100 | static Real sinh_r(Real); 101 | static Real tanh_r(Real); 102 | #if USE_LONG_REALS 103 | static bool func_cosh_lr(Interpreter&); 104 | static bool func_sinh_lr(Interpreter&); 105 | static bool func_tanh_lr(Interpreter&); 106 | 107 | static LongReal cosh_lr(LongReal); 108 | static LongReal sinh_lr(LongReal); 109 | static LongReal tanh_lr(LongReal); 110 | #endif // USE_LONG_REALS 111 | #endif // M_HYPERBOLIC 112 | static bool func_exp(Interpreter&); 113 | static bool func_log(Interpreter&); 114 | static bool func_sqr(Interpreter&); 115 | static bool func_pi(Interpreter&); 116 | 117 | static Real exp_r(Real); 118 | static Real log_r(Real); 119 | static Real sqr_r(Real); 120 | #if USE_LONG_REALS 121 | static bool func_exp_lr(Interpreter&); 122 | static bool func_log_lr(Interpreter&); 123 | static bool func_sqr_lr(Interpreter&); 124 | static bool func_pi_lr(Interpreter&); 125 | 126 | static LongReal exp_lr(LongReal); 127 | static LongReal log_lr(LongReal); 128 | static LongReal sqr_lr(LongReal); 129 | #endif // USE_LONG_REALS 130 | #if M_ADDITIONAL 131 | static bool func_cbr(Interpreter&); 132 | static bool func_hyp(Interpreter&); 133 | static bool func_log10(Interpreter&); 134 | 135 | static Real cbr_r(Real); 136 | static Real log10_r(Real); 137 | #if USE_LONG_REALS 138 | static bool func_cbr_lr(Interpreter&); 139 | static bool func_hyp_lr(Interpreter&); 140 | static bool func_log10_lr(Interpreter&); 141 | 142 | static LongReal cbr_lr(LongReal); 143 | static LongReal log10_lr(LongReal); 144 | #endif // USE_LONG_REALS 145 | #endif // M_ADDITIONAL 146 | static const FunctionBlock::function funcs[] PROGMEM;; 147 | }; 148 | 149 | } // namespace BASIC 150 | 151 | #endif // BASIC_MATH_HPP 152 | -------------------------------------------------------------------------------- /terminal-basic/basic_parser.c: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of Terminal-BASIC: a lightweight BASIC-like language 3 | * interpreter. 4 | * 5 | * Copyright (C) 2016-2018 Andrey V. Skvortsov 6 | * Copyright (C) 2019-2021 Terminal-BASIC team 7 | * 8 | * 9 | * This program is free software: you can redistribute it and/or modify 10 | * it under the terms of the GNU General Public License as published by 11 | * the Free Software Foundation, either version 3 of the License, or 12 | * (at your option) any later version. 13 | * 14 | * This program is distributed in the hope that it will be useful, 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | * GNU General Public License for more details. 18 | * 19 | * You should have received a copy of the GNU General Public License 20 | * along with this program. If not, see . 21 | */ 22 | 23 | #include "basic_parser.h" 24 | 25 | BOOLEAN 26 | basic_parser_fidentifier(basic_parser_context_t* self, char *idName) 27 | { 28 | /* if ((_lexer.getToken() >= Token::INTEGER_IDENT) && 29 | (_lexer.getToken() <= Token::BOOL_IDENT)) { 30 | strncpy(idName, _lexer.id(), IDSIZE); 31 | idName[IDSIZE-1] = '\0'; 32 | return true; 33 | } else*/ 34 | return FALSE; 35 | } 36 | -------------------------------------------------------------------------------- /terminal-basic/basic_parser.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of Terminal-BASIC: a lightweight BASIC-like language 3 | * interpreter. 4 | * 5 | * Copyright (C) 2016-2018 Andrey V. Skvortsov 6 | * Copyright (C) 2019-2021 Terminal-BASIC team 7 | * 8 | * 9 | * This program is free software: you can redistribute it and/or modify 10 | * it under the terms of the GNU General Public License as published by 11 | * the Free Software Foundation, either version 3 of the License, or 12 | * (at your option) any later version. 13 | * 14 | * This program is distributed in the hope that it will be useful, 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | * GNU General Public License for more details. 18 | * 19 | * You should have received a copy of the GNU General Public License 20 | * along with this program. If not, see . 21 | */ 22 | 23 | #ifndef BASIC_PARSER_H 24 | #define BASIC_PARSER_H 25 | 26 | #include "basic.h" 27 | #include "tools.h" 28 | 29 | __BEGIN_DECLS 30 | 31 | /** 32 | * Parser mode: syntax check or execute commands of the interpreter 33 | * context 34 | */ 35 | typedef enum 36 | { 37 | BASIC_PARSER_SCAN = 0, 38 | BASIC_PARSER_EXECUTE = 1 39 | } basic_parser_mode_t; 40 | 41 | struct basic_parser_context { 42 | // current mode 43 | uint8_t mode; 44 | // stop parsing string flag 45 | BOOLEAN stopParse; 46 | }; 47 | 48 | /** 49 | * 50 | * @param self context 51 | * @param str string to parse 52 | * @param success flag of successfull execution 53 | * @return true if there are more operators in string 54 | */ 55 | BOOLEAN basic_parser_parse(basic_parser_context_t*, const char*, BOOLEAN*); 56 | 57 | BOOLEAN basic_parser_fidenifier(basic_parser_context_t*, const char*); 58 | 59 | __END_DECLS 60 | 61 | #endif /* BASIC_PARSER_H */ 62 | 63 | -------------------------------------------------------------------------------- /terminal-basic/basic_parser.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of Terminal-BASIC: a lightweight BASIC-like language 3 | * interpreter. 4 | * 5 | * Copyright (C) 2016-2018 Andrey V. Skvortsov 6 | * Copyright (C) 2019-2021 Terminal-BASIC team 7 | * 8 | * 9 | * This program is free software: you can redistribute it and/or modify 10 | * it under the terms of the GNU General Public License as published by 11 | * the Free Software Foundation, either version 3 of the License, or 12 | * (at your option) any later version. 13 | * 14 | * This program is distributed in the hope that it will be useful, 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | * GNU General Public License for more details. 18 | * 19 | * You should have received a copy of the GNU General Public License 20 | * along with this program. If not, see . 21 | */ 22 | 23 | #ifndef PARSER_HPP 24 | #define PARSER_HPP 25 | 26 | #include 27 | #include 28 | 29 | #include "arduinoext.hpp" 30 | #include "basic.hpp" 31 | #include "basic_parser.h" 32 | #include "basic_internalfuncs.hpp" 33 | 34 | namespace BASIC 35 | { 36 | 37 | class Lexer; 38 | class Interpreter; 39 | 40 | /** 41 | * @brief Syntactic analyzer class 42 | */ 43 | class Parser 44 | { 45 | public: 46 | 47 | /** 48 | * @brief Syntax errors 49 | */ 50 | enum ErrorCodes : uint8_t 51 | { 52 | NO_ERROR = 0, // Not an error 53 | OPERATOR_EXPECTED = 1, // Operator expected 54 | IDENTIFIER_EXPECTED = 2, 55 | EXPRESSION_EXPECTED = 3, 56 | INTEGER_CONSTANT_EXPECTED = 4, 57 | THEN_OR_GOTO_EXPECTED = 5, 58 | INVALID_DATA_EXPR = 6, 59 | INVALID_READ_EXPR = 7, 60 | VARIABLES_LIST_EXPECTED = 8, 61 | STRING_OVERFLOW = 9, 62 | MISSING_RPAREN = 10, 63 | #if CONF_USE_ON_GOTO 64 | INVALID_ONGOTO_INDEX = 11 65 | #endif 66 | }; 67 | 68 | class PACKED Value; 69 | /** 70 | * @brief constructor 71 | * @param lexer Lexical analyzer object refertence 72 | * @param interpreter Interpreter context object reference 73 | */ 74 | Parser(Lexer&, Interpreter&); 75 | /** 76 | * @brief Parse a text string 77 | * @param str string to parse 78 | * @param ok successfull parsing flag 79 | * @param tok flag of the tokenized program text 80 | * @return end of parsed string 81 | */ 82 | bool parse(const uint8_t*, bool&, bool); 83 | 84 | void stop(); 85 | 86 | /** 87 | * @brief get last static error code 88 | * @return error code 89 | */ 90 | ErrorCodes getError() const 91 | { 92 | return _error; 93 | } 94 | 95 | void init(); 96 | 97 | FunctionBlock::command getCommand(const char*); 98 | 99 | void getCommandName(FunctionBlock::command, uint8_t*); 100 | 101 | void addModule(FunctionBlock*); 102 | #if CONF_ERROR_STRINGS 103 | static PGM_P const errorStrings[] PROGMEM; 104 | #endif 105 | private: 106 | 107 | /** 108 | * Parser mode: syntax check or execute commands of the interpreter 109 | * context 110 | */ 111 | enum Mode : uint8_t 112 | { 113 | SCAN = BASIC_PARSER_SCAN, 114 | EXECUTE = BASIC_PARSER_EXECUTE 115 | }; 116 | 117 | void setMode(Mode); 118 | Mode getMode() const; 119 | 120 | void setStopParse(bool); 121 | bool getSTopParse() const; 122 | 123 | bool testExpression(Value&); 124 | 125 | bool fOperators(bool&); 126 | bool fOperator(); 127 | #if CONF_USE_ON_GOTO 128 | bool fOnStatement(uint8_t); 129 | #endif 130 | #if USE_DATA 131 | bool fDataStatement(); 132 | bool fReadStatement(); 133 | #endif // USE_DATA 134 | #if USE_DEFFN 135 | bool fDefStatement(); 136 | bool fFnexec(Value&); 137 | #endif 138 | bool fImplicitAssignment(char*); 139 | #if USE_PEEK_POKE 140 | bool fPoke(); 141 | #endif 142 | bool fPrintList(); 143 | bool fPrintItem(); 144 | bool fExpression(Value&); 145 | bool fLogicalAdd(Value&); 146 | bool fLogicalFinal(Value&); 147 | bool fSimpleExpression(Value&); 148 | bool fTerm(Value&); 149 | bool fFactor(Value&); 150 | bool fFinal(Value&); 151 | bool fIfStatement(); 152 | bool fCommand(); 153 | void fCommandArguments(FunctionBlock::command); 154 | bool fGotoStatement(); 155 | bool fForConds(); 156 | bool fIdentifier(char*); 157 | bool fVarList(); 158 | bool fArrayList(); 159 | bool fArray(uint8_t&); 160 | bool fDimensions(uint8_t&); 161 | bool fIdentifierExpr(char*, Value&); 162 | #if USE_MATRIX 163 | bool fMatrixOperation(); 164 | bool fMatrixPrint(); 165 | bool fMatrixExpression(const char*); 166 | #endif 167 | // last static semantic error 168 | ErrorCodes _error; 169 | // lexical analyser object reference 170 | Lexer &_lexer; 171 | // interpreter context object reference 172 | Interpreter &_interpreter; 173 | 174 | // first module in chain 175 | InternalFunctions _internal; 176 | 177 | basic_parser_context_t m_context; 178 | }; 179 | 180 | } // namespace BASIC 181 | 182 | #endif // PARSER_HPP 183 | -------------------------------------------------------------------------------- /terminal-basic/basic_parser_value.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of Terminal-BASIC: a lightweight BASIC-like language 3 | * interpreter. 4 | * 5 | * Copyright (C) 2016-2018 Andrey V. Skvortsov 6 | * Copyright (C) 2019-2021 Terminal-BASIC team 7 | * 8 | * 9 | * This program is free software: you can redistribute it and/or modify 10 | * it under the terms of the GNU General Public License as published by 11 | * the Free Software Foundation, either version 3 of the License, or 12 | * (at your option) any later version. 13 | * 14 | * This program is distributed in the hope that it will be useful, 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | * GNU General Public License for more details. 18 | * 19 | * You should have received a copy of the GNU General Public License 20 | * along with this program. If not, see . 21 | */ 22 | 23 | #ifndef BASIC_PARSER_VALUE_HPP 24 | #define BASIC_PARSER_VALUE_HPP 25 | 26 | #include "basic_parser.hpp" 27 | #include "basic_value.h" 28 | 29 | #include 30 | 31 | namespace BASIC 32 | { 33 | 34 | class PACKED Parser::Value 35 | { 36 | public: 37 | /** 38 | * @brief types of the value 39 | */ 40 | enum Type : uint8_t 41 | { 42 | INTEGER = BASIC_VALUE_TYPE_INTEGER, 43 | #if USE_LONGINT 44 | LONG_INTEGER = BASIC_VALUE_TYPE_LONG_INTEGER, 45 | #endif 46 | #if USE_REALS 47 | REAL = BASIC_VALUE_TYPE_REAL, 48 | #if USE_LONG_REALS 49 | LONG_REAL = BASIC_VALUE_TYPE_LONG_REAL, 50 | #endif 51 | #endif // USE_REALS 52 | LOGICAL = BASIC_VALUE_TYPE_LOGICAL, 53 | STRING = BASIC_VALUE_TYPE_STRING 54 | }; 55 | 56 | /** 57 | * @brief Default constructor 58 | * 59 | * Initializes a value with 0 INTEGER, which s always available 60 | */ 61 | Value() 62 | { 63 | basic_value_setFromInteger(&m_value, 0); 64 | } 65 | 66 | #if USE_LONGINT 67 | /** 68 | * @brief Constructor ftrom LongInteger number 69 | * @param v 70 | */ 71 | Value(LongInteger v) 72 | { 73 | basic_value_setFromLongInteger(&m_value, v); 74 | } 75 | #endif 76 | Value(Integer); 77 | #if USE_REALS 78 | Value(Real); 79 | #if USE_LONG_REALS 80 | Value(LongReal); 81 | #endif 82 | #endif // USE_REALS 83 | Value(bool); 84 | 85 | #if USE_REALS 86 | explicit operator Real() const; 87 | #if USE_LONG_REALS 88 | explicit operator LongReal() const; 89 | #endif 90 | #endif // USE_REALS 91 | explicit operator bool() const; 92 | explicit operator Integer() const; 93 | #if USE_LONGINT 94 | explicit operator LongInteger() const; 95 | #endif 96 | 97 | bool operator<(const Value&) const; 98 | bool operator==(const Value&) const; 99 | bool operator>(const Value&) const; 100 | friend bool operator >=(const Value&, const Value&); 101 | friend bool operator <=(const Value&, const Value&); 102 | 103 | Value &operator+=(const Value&); 104 | Value &operator-=(const Value&); 105 | Value &operator*=(const Value&); 106 | Value &operator/=(const Value&); 107 | Value &divEquals(const Value&); 108 | Value &modEquals(const Value&); 109 | Value &operator^=(const Value&); 110 | Value &operator|=(const Value&); 111 | Value &operator&=(const Value&); 112 | void switchSign(); 113 | 114 | static size_t size(Type); 115 | 116 | // Return Variable/Array/Function type based on it's name 117 | static Type typeFromName(const char*); 118 | 119 | Type type() const 120 | { 121 | return Type(m_value.type); 122 | } 123 | 124 | void setType(Type newVal) 125 | { 126 | m_value.type = basic_value_type_t(newVal); 127 | } 128 | 129 | basic_value_t m_value; 130 | 131 | // Printable interface 132 | size_t printTo(Print& p) const; 133 | }; 134 | 135 | template <> 136 | inline void writeValue(Parser::Value v, uint8_t* str) 137 | { 138 | memcpy(str, &v, sizeof(Parser::Value)); 139 | } 140 | 141 | template <> 142 | inline typename Parser::Value readValue(const uint8_t* str) 143 | { 144 | Parser::Value result; 145 | memcpy(&result, str, sizeof(Parser::Value)); 146 | return result; 147 | } 148 | 149 | } // namespace BASIC 150 | 151 | #endif // BASIC_PARSER_VALUE_HPP 152 | -------------------------------------------------------------------------------- /terminal-basic/basic_value.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of Terminal-BASIC: a lightweight BASIC-like language 3 | * interpreter. 4 | * 5 | * Copyright (C) 2016-2018 Andrey V. Skvortsov 6 | * Copyright (C) 2019-2021 Terminal-BASIC team 7 | * 8 | * 9 | * This program is free software: you can redistribute it and/or modify 10 | * it under the terms of the GNU General Public License as published by 11 | * the Free Software Foundation, either version 3 of the License, or 12 | * (at your option) any later version. 13 | * 14 | * This program is distributed in the hope that it will be useful, 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | * GNU General Public License for more details. 18 | * 19 | * You should have received a copy of the GNU General Public License 20 | * along with this program. If not, see . 21 | */ 22 | 23 | #ifndef BASIC_VALUE_H 24 | #define BASIC_VALUE_H 25 | 26 | #include "basic.h" 27 | #include "tools.h" 28 | 29 | #include 30 | 31 | __BEGIN_DECLS 32 | 33 | /** 34 | * @brief types of the value 35 | */ 36 | typedef enum basic_value_type 37 | { 38 | BASIC_VALUE_TYPE_INTEGER, 39 | #if USE_LONGINT 40 | BASIC_VALUE_TYPE_LONG_INTEGER, 41 | #endif 42 | #if USE_REALS 43 | BASIC_VALUE_TYPE_REAL, 44 | #if USE_LONG_REALS 45 | BASIC_VALUE_TYPE_LONG_REAL, 46 | #endif 47 | #endif // USE_REALS 48 | BASIC_VALUE_TYPE_LOGICAL, 49 | BASIC_VALUE_TYPE_STRING 50 | } basic_value_type_t; 51 | 52 | /** 53 | * Universal value body 54 | */ 55 | typedef union basic_univalue 56 | { 57 | integer_t integer; 58 | #if USE_LONGINT 59 | long_integer_t long_integer; 60 | #endif 61 | #if USE_REALS 62 | real_t real; 63 | #if USE_LONG_REALS 64 | long_real_t long_real; 65 | #endif 66 | #endif // USE_REALS 67 | BOOLEAN logical; 68 | } basic_univalue_t; 69 | 70 | typedef struct basic_value 71 | { 72 | basic_value_type_t type; 73 | basic_univalue_t body; 74 | } basic_value_t; 75 | 76 | #if USE_REALS 77 | real_t basic_value_toReal(const basic_value_t*); 78 | 79 | basic_value_t basic_value_from_real(real_t); 80 | 81 | void basic_value_setFromReal(basic_value_t*, real_t); 82 | 83 | #if USE_LONG_REALS 84 | long_real_t basic_value_toLongReal(const basic_value_t*); 85 | 86 | basic_value_t basic_value_from_longReal(long_real_t); 87 | 88 | void basic_value_setFromLongReal(basic_value_t*, long_real_t); 89 | 90 | #endif // v 91 | #endif // USE_REALS 92 | 93 | #if USE_LONGINT 94 | long_integer_t basic_value_toLongInteger(const basic_value_t*); 95 | 96 | basic_value_t basic_value_fromLongInteger(long_integer_t); 97 | 98 | void basic_value_setFromLongInteger(basic_value_t*, long_integer_t); 99 | #endif 100 | 101 | integer_t basic_value_toInteger(const basic_value_t*); 102 | 103 | basic_value_t basic_value_fromInteger(integer_t); 104 | 105 | void basic_value_setFromInteger(basic_value_t*, integer_t); 106 | 107 | 108 | BOOLEAN basic_value_toLogical(const basic_value_t*); 109 | 110 | basic_value_t basic_value_fromLogical(BOOLEAN); 111 | 112 | void basic_value_setFromLogical(basic_value_t*, BOOLEAN); 113 | 114 | 115 | void basic_value_pluseq(basic_value_t*, const basic_value_t*); 116 | 117 | void basic_value_minuseq(basic_value_t*, const basic_value_t*); 118 | 119 | void basic_value_multeq(basic_value_t*, const basic_value_t*); 120 | 121 | void basic_value_diveq(basic_value_t*, const basic_value_t*); 122 | 123 | void basic_value_poweq(basic_value_t*, const basic_value_t*); 124 | 125 | void basic_value_oreq(basic_value_t*, const basic_value_t*); 126 | 127 | void basic_value_andeq(basic_value_t*, const basic_value_t*); 128 | 129 | 130 | void basic_value_switchSign(basic_value_t*); 131 | 132 | BOOLEAN basic_value_equals(const basic_value_t*, const basic_value_t*); 133 | 134 | BOOLEAN basic_value_greater(const basic_value_t*, const basic_value_t*); 135 | 136 | __END_DECLS 137 | 138 | #endif /* BASIC_VALUE_H */ 139 | 140 | -------------------------------------------------------------------------------- /terminal-basic/buffered_terminal.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * ArduinoExt is a set of utility libraries for Arduino 3 | * 4 | * Copyright (C) 2016-2018 Andrey V. Skvortsov 5 | * Copyright (C) 2019,2021 Terminal-BASIC team 6 | * 7 | * 8 | * This program is free software: is free software: you can redistribute it and/or 9 | * modify it under the terms of the GNU Lesser General Public License 10 | * as published by the Free Software Foundation, either version 3 of 11 | * the License, or (at your option) any later version. 12 | 13 | * ArduinoExt library is distributed in the hope that it will be useful, 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | * GNU General Public License for more details. 17 | 18 | * You should have received a copy of the GNU Lesser General Public 19 | * License along with Posixcpp library. If not, see 20 | * . 21 | */ 22 | 23 | #include "buffered_terminal.hpp" 24 | 25 | void 26 | BufferedTerminal::begin(uint16_t rows, uint16_t columns) 27 | { 28 | m_row = m_column = 0; 29 | m_rows = rows, m_columns = columns; 30 | m_attr = VT100::TextAttr::NO_ATTR; 31 | m_lockCursor = false; 32 | m_cursorState = true; 33 | } 34 | 35 | void 36 | BufferedTerminal::update() 37 | { 38 | // If cursor is locked by the non-interrupt code - return 39 | if (m_lockCursor) 40 | return; 41 | 42 | // Count down cursor blank interrupt counter 43 | if (--m_cursorCounter == 0) { 44 | m_cursorCounter = m_cursorBlinkPeriod; 45 | } else 46 | return; 47 | 48 | m_cursorState = !m_cursorState; 49 | drawCursor(m_cursorState); 50 | } 51 | 52 | uint8_t 53 | BufferedTerminal::getCursorX() 54 | { 55 | return m_column; 56 | } 57 | 58 | void 59 | BufferedTerminal::setCursorX(uint8_t x) 60 | { 61 | setCursor(x, m_row); 62 | } 63 | -------------------------------------------------------------------------------- /terminal-basic/buffered_terminal.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * ArduinoExt is a set of utility libraries for Arduino 3 | * 4 | * Copyright (C) 2016-2018 Andrey V. Skvortsov 5 | * Copyright (C) 2019,2021 Terminal-BASIC team 6 | * 7 | * 8 | * This program is free software: is free software: you can redistribute it and/or 9 | * modify it under the terms of the GNU Lesser General Public License 10 | * as published by the Free Software Foundation, either version 3 of 11 | * the License, or (at your option) any later version. 12 | 13 | * ArduinoExt library is distributed in the hope that it will be useful, 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | * GNU General Public License for more details. 17 | 18 | * You should have received a copy of the GNU Lesser General Public 19 | * License along with Posixcpp library. If not, see 20 | * . 21 | */ 22 | 23 | #ifndef BUFFERED_TERMINAL_HPP 24 | #define BUFFERED_TERMINAL_HPP 25 | 26 | #include "vt100.hpp" 27 | 28 | class BufferedTerminal : public VT100::Print 29 | { 30 | EXT_NOTCOPYABLE(BufferedTerminal) 31 | 32 | public: 33 | /** 34 | * @param rows 35 | * @param columns 36 | */ 37 | void begin( 38 | uint16_t, 39 | uint16_t); 40 | 41 | void update(); 42 | 43 | protected: 44 | 45 | BufferedTerminal() = default; 46 | 47 | virtual void drawCursor(bool) = 0; 48 | 49 | // Current row and column 50 | uint16_t m_row, m_column; 51 | // Number of rows and columns 52 | uint16_t m_rows, m_columns; 53 | // Cursor lock object and blinking cursor state 54 | bool m_lockCursor, m_cursorState; 55 | // Cursor counter and period 56 | uint8_t m_cursorCounter, m_cursorBlinkPeriod = 20; 57 | // Current attribute 58 | VT100::TextAttr m_attr; 59 | 60 | // VT100::Print interface 61 | protected: 62 | uint8_t getCursorX() override; 63 | 64 | void setCursorX(uint8_t) override; 65 | }; 66 | 67 | #endif // BUFFERED_TERMINAL_HPP 68 | -------------------------------------------------------------------------------- /terminal-basic/bytearray.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * ArduinoExt is a set of utility libraries for Arduino 3 | * 4 | * Copyright (C) 2016-2018 Andrey V. Skvortsov 5 | * Copyright (C) 2019,2021 Terminal-BASIC team 6 | * 7 | * 8 | * This program is free software: is free software: you can redistribute it and/or 9 | * modify it under the terms of the GNU Lesser General Public License 10 | * as published by the Free Software Foundation, either version 3 of 11 | * the License, or (at your option) any later version. 12 | 13 | * ArduinoExt library is distributed in the hope that it will be useful, 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | * GNU General Public License for more details. 17 | 18 | * You should have received a copy of the GNU Lesser General Public 19 | * License along with Posixcpp library. If not, see 20 | * . 21 | */ 22 | 23 | #include "bytearray.hpp" 24 | 25 | #include "Print.h" 26 | #include "ascii.hpp" 27 | #include 28 | 29 | ByteArray::ByteArray() : 30 | _data(nullptr), _size(0), _ownsData(false) 31 | { 32 | } 33 | 34 | ByteArray::ByteArray(const uint8_t *data, size_t size) : 35 | _data(const_cast(data)), _size(size), _ownsData(false) 36 | { 37 | } 38 | 39 | void 40 | ByteArray::createData() 41 | { 42 | if (_ownsData && _data != nullptr) 43 | free(_data); 44 | 45 | if (_size == 0) { 46 | _data = nullptr; 47 | return; 48 | } 49 | 50 | _data = reinterpret_cast(malloc(_size)); 51 | } 52 | 53 | size_t 54 | ByteArray::printTo(Print& p) const 55 | { 56 | size_t res = 0; 57 | for (size_t i = 0; i < size();) { 58 | size_t ii = i; 59 | 60 | // Leading zeros of the absolute address 61 | size_t addr = i + uintptr_t(data()); 62 | uint8_t digits; 63 | 64 | // Leading zeros of the relative address 65 | addr = i; 66 | for (digits = 0; addr > 15; addr >>= 4, ++digits); 67 | while (++digits < sizeof(intptr_t)*2) 68 | p.print('0'); 69 | 70 | p.print(i, HEX), p.print(':'); 71 | size_t j; 72 | for (j = 0; j < 8; ++j, ++ii) { 73 | if (ii >= size()) 74 | break; 75 | uint8_t c = data()[ii]; 76 | res += p.print(char(ASCII::SPACE)); 77 | if (c < 0x10) 78 | res += p.print('0'); 79 | res += p.print(c, HEX); 80 | } 81 | j*=3; 82 | for (; j < 8*3; ++j) 83 | res += p.print(char(ASCII::SPACE)); 84 | res += 2; p.print(" "); 85 | for (j = 0; j < 8; ++j, ++i) { 86 | if (i >= size()) 87 | break; 88 | const signed char c = ((const signed char*)data())[i]; 89 | if (c < ' ') 90 | res += p.print('.'); 91 | else 92 | res += p.print((char)c); 93 | } 94 | res += p.println(); 95 | } 96 | return res; 97 | } 98 | -------------------------------------------------------------------------------- /terminal-basic/bytearray.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * ArduinoExt is a set of utility libraries for Arduino 3 | * 4 | * Copyright (C) 2016-2018 Andrey V. Skvortsov 5 | * Copyright (C) 2019,2021 Terminal-BASIC team 6 | * 7 | * 8 | * This program is free software: is free software: you can redistribute it and/or 9 | * modify it under the terms of the GNU Lesser General Public License 10 | * as published by the Free Software Foundation, either version 3 of 11 | * the License, or (at your option) any later version. 12 | 13 | * ArduinoExt library is distributed in the hope that it will be useful, 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | * GNU General Public License for more details. 17 | 18 | * You should have received a copy of the GNU Lesser General Public 19 | * License along with Posixcpp library. If not, see 20 | * . 21 | */ 22 | 23 | #ifndef BYTEARRAY_HPP 24 | #define BYTEARRAY_HPP 25 | 26 | #include 27 | 28 | #include "Printable.h" 29 | 30 | class ByteArray : public Printable 31 | { 32 | public: 33 | ByteArray(); 34 | ByteArray(const uint8_t*, size_t); 35 | ByteArray(const char *c, size_t s) : 36 | ByteArray(reinterpret_cast(c), s) {} 37 | 38 | void createData(); 39 | 40 | size_t printTo(Print& p) const override; 41 | 42 | const uint8_t *data() const 43 | { 44 | return (_data); 45 | } 46 | 47 | uint8_t *data() 48 | { 49 | return (_data); 50 | } 51 | 52 | size_t size() const 53 | { 54 | return (_size); 55 | } 56 | private: 57 | uint8_t *_data; 58 | size_t _size; 59 | bool _ownsData; 60 | }; 61 | 62 | #endif // BYTEARRAY_HPP 63 | -------------------------------------------------------------------------------- /terminal-basic/config_arduino.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of Terminal-BASIC: a lightweight BASIC-like language 3 | * interpreter. 4 | * 5 | * Copyright (C) 2016-2018 Andrey V. Skvortsov 6 | * Copyright (C) 2019-2021 Terminal-BASIC team 7 | * 8 | * 9 | * This program is free software: you can redistribute it and/or modify 10 | * it under the terms of the GNU General Public License as published by 11 | * the Free Software Foundation, either version 3 of the License, or 12 | * (at your option) any later version. 13 | * 14 | * This program is distributed in the hope that it will be useful, 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | * GNU General Public License for more details. 18 | * 19 | * You should have received a copy of the GNU General Public License 20 | * along with this program. If not, see . 21 | */ 22 | 23 | /** 24 | * @file config_arduino.hpp 25 | * @brief Configuration parameters, specific for Arduino builds 26 | */ 27 | 28 | #ifndef CONFIG_ARDUINO_HPP 29 | #define CONFIG_ARDUINO_HPP 30 | 31 | #include "basic_config.hpp" 32 | #include "basic.h" 33 | #ifdef ARDUINO_ARCH_AVR 34 | #include "HAL_avr8.h" 35 | #endif 36 | 37 | /** 38 | * Parameters 39 | */ 40 | 41 | #ifdef ARDUINO_ARCH_SAM 42 | #define HAVE_HWSERIAL1 43 | #define HAVE_HWSERIAL2 44 | #define HAVE_HWSERIAL3 45 | #define HAVE_HWSERIAL4 46 | #endif 47 | 48 | #if BASIC_MULTITERMINAL 49 | #define NUM_TERMINALS 1 50 | #ifdef HAVE_HWSERIAL1 51 | #define SERIAL_PORT1 Serial1 52 | #undef NUM_TERMINALS 53 | #define NUM_TERMINALS 2 54 | #endif 55 | #ifdef HAVE_HWSERIAL2 56 | #define SERIAL_PORT2 Serial2 57 | #undef NUM_TERMINALS 58 | #define NUM_TERMINALS 3 59 | #endif 60 | #ifdef HAVE_HWSERIAL3 61 | #define SERIAL_PORT3 Serial3 62 | #undef NUM_TERMINALS 63 | #define NUM_TERMINALS 4 64 | #endif 65 | #endif // BASIC_MULTITERMINAL 66 | 67 | // Use external memory 68 | #if HAL_ARDUINO_AVR8_EXTMEM 69 | #define USE_EXTMEM 1 70 | #define EXTMEM_ADDRESS 0x8000 71 | #define EXTMEM_SIZE 32768 72 | #else 73 | #define USE_EXTMEM 0 74 | #endif // HAL_ARDUINO_AVR8_EXTMEM 75 | 76 | namespace BASIC 77 | { 78 | // Number of bytes for program text, variables and stack 79 | #if USE_EXTMEM 80 | const pointer_t PROGRAMSIZE = EXTMEM_SIZE; 81 | #elif defined (__AVR_ATmega1284__) || defined (__AVR_ATmega1284P__) 82 | #if (S_OUTPUT != TVOUT_O) 83 | const pointer_t PROGRAMSIZE = 14336; 84 | #else 85 | const pointer_t PROGRAMSIZE = 8192; 86 | #endif 87 | #elif defined (__AVR_ATmega2560__) 88 | #if (S_OUTPUT != TVOUT_O) && (!USE_EXTMEM) && (!CONF_USE_EXTMEMFS) 89 | const pointer_t PROGRAMSIZE = 6144; 90 | #elif (!USE_EXTMEM) && (CONF_USE_EXTMEMFS) 91 | const pointer_t PROGRAMSIZE = 5900; 92 | #else 93 | const pointer_t PROGRAMSIZE = 512; 94 | #endif 95 | #elif defined (__AVR_ATmega128__) || defined (__AVR_ATmega128A__) 96 | const pointer_t PROGRAMSIZE = 3072; 97 | #elif defined (__AVR_ATmega328__) || defined (__AVR_ATmega328P__) 98 | #if CONF_USE_EXTMEMFS 99 | const pointer_t PROGRAMSIZE = 256; 100 | #else 101 | const pointer_t PROGRAMSIZE = 1024; 102 | #endif 103 | #elif defined (__AVR_ATmega168__) || defined (__AVR_ATmega168P__) 104 | const pointer_t PROGRAMSIZE = 384; 105 | #elif defined ARDUINO_ARCH_SAM 106 | const pointer_t PROGRAMSIZE = 65535; 107 | #elif defined ARDUINO_ARCH_ESP8266 108 | const pointer_t PROGRAMSIZE = 32768; 109 | #elif defined ARDUINO_ARCH_ESP32 110 | const pointer_t PROGRAMSIZE = 65535; 111 | #else 112 | const pointer_t PROGRAMSIZE = 1024; 113 | #endif // USE_EXTMEM 114 | 115 | #if BASIC_MULTITERMINAL 116 | const pointer_t SINGLE_PROGSIZE = PROGRAMSIZE / (NUM_TERMINALS+1); 117 | #else 118 | const pointer_t SINGLE_PROGSIZE = PROGRAMSIZE; 119 | #endif 120 | 121 | // BEGIN PRIVATE 122 | 123 | #define USEUTFT 0 124 | #define USETVOUT 0 125 | #define USELIQUIDCRYSTAL 0 126 | 127 | // END PRIVATE 128 | 129 | } // nameespace BASIC 130 | 131 | #endif // CONFIG_ARDUINO_HPP 132 | -------------------------------------------------------------------------------- /terminal-basic/gfxterm.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * ArduinoExt is a set of utility libraries for Arduino 3 | * 4 | * Copyright (C) 2016-2018 Andrey V. Skvortsov 5 | * Copyright (C) 2019,2021 Terminal-BASIC team 6 | * 7 | * 8 | * This program is free software: is free software: you can redistribute it and/or 9 | * modify it under the terms of the GNU Lesser General Public License 10 | * as published by the Free Software Foundation, either version 3 of 11 | * the License, or (at your option) any later version. 12 | * 13 | * ArduinoExt library is distributed in the hope that it will be useful, 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | * GNU General Public License for more details. 17 | * 18 | * You should have received a copy of the GNU Lesser General Public 19 | * License along with Posixcpp library. If not, see 20 | * . 21 | */ 22 | 23 | #ifndef GFXTERM_HPP 24 | #define GFXTERM_HPP 25 | 26 | #include "ascii.hpp" 27 | #include "arduinoext.hpp" 28 | 29 | Package(GFXTERM) 30 | { 31 | EXT_PACKAGE(GFXTERM) 32 | 33 | public: 34 | 35 | enum class Command : uint8_t 36 | { 37 | NONE = 0x00, 38 | // Set terminal video mode 39 | // param m - uint8_t mode number 40 | MODE, 41 | // Set text cursor visible 42 | // param bool (uint8_t) visible 43 | CURSOR, 44 | // Set colors (ink and paper) 45 | // param uint8_t ink, uint8_t paper 46 | COLOR, 47 | // Set active font 48 | // param uint8_t font index 49 | FONT, 50 | // Draw circle 51 | // param int16_t cx, cy, r 52 | CIRCLE, 53 | // Draw circle 54 | // param int16_t cx, cy, r, uint8_t ink, paper 55 | CIRCLEC, 56 | // Draw box (rectangle) 57 | // param int16_t x,y, w,h 58 | BOX, 59 | // Draw color box (rectangle) 60 | // param int16_t x,y, w,h, uint8_t ink, paper 61 | BOXC, 62 | // Draw ellipse 63 | // param int16_t x,y, w,h 64 | ELLIPSE, 65 | // Draw color ellipse 66 | // param int16_t x,y, w,h, uint8_t ink, paper 67 | ELLIPSEC, 68 | // Draw line 69 | // param int16_t x1,y1, x2,y2 70 | LINE, 71 | // Draw color line 72 | // param int16_t x1,y1, x2,y2, uint8_t ink 73 | LINEC, 74 | // Draw line from current position 75 | // param int16_t x,y 76 | LINETO, 77 | // Draw color line from current position 78 | // param int16_t x,y, uint8_t ink 79 | LINETOC, 80 | // Draw point 81 | // param int16_t x,y 82 | POINT, 83 | // Set ink color and draw point 84 | // param int16_t x,y, uint8_t ink 85 | POINTC, 86 | 87 | NUM_COMMANDS 88 | }; 89 | }; 90 | 91 | #endif /* GFXTERM_HPP */ 92 | -------------------------------------------------------------------------------- /terminal-basic/helper.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * ArduinoExt is a set of utility libraries for Arduino 3 | * 4 | * Copyright (C) 2016-2018 Andrey V. Skvortsov 5 | * Copyright (C) 2019,2021 Terminal-BASIC team 6 | * 7 | * 8 | * This program is free software: is free software: you can redistribute it and/or 9 | * modify it under the terms of the GNU Lesser General Public License 10 | * as published by the Free Software Foundation, either version 3 of 11 | * the License, or (at your option) any later version. 12 | 13 | * ArduinoExt library is distributed in the hope that it will be useful, 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | * GNU General Public License for more details. 17 | 18 | * You should have received a copy of the GNU Lesser General Public 19 | * License along with Posixcpp library. If not, see 20 | * . 21 | */ 22 | 23 | #ifndef HELPER_HPP 24 | #define HELPER_HPP 25 | 26 | #include "arduinoext.hpp" 27 | #include 28 | 29 | #ifdef ARDUINO 30 | #include 31 | 32 | inline void 33 | positiveLedBlink(size_t num = 1) 34 | { 35 | for (size_t i = 0; i 5 | * Copyright (C) 2019,2021 Terminal-BASIC team 6 | * 7 | * 8 | * This program is free software: is free software: you can redistribute it and/or 9 | * modify it under the terms of the GNU Lesser General Public License 10 | * as published by the Free Software Foundation, either version 3 of 11 | * the License, or (at your option) any later version. 12 | 13 | * ArduinoExt library is distributed in the hope that it will be useful, 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | * GNU General Public License for more details. 17 | 18 | * You should have received a copy of the GNU Lesser General Public 19 | * License along with Posixcpp library. If not, see 20 | * . 21 | */ 22 | 23 | #ifndef I2CEEPROM_HPP 24 | #define I2CEEPROM_HPP 25 | 26 | #include 27 | 28 | template 29 | class I2CEEPROM 30 | { 31 | static_assert((SIZE > pageSize) && (SIZE % pageSize == 0), 32 | "EEPROM size should be multiply of the page size"); 33 | public: 34 | 35 | I2CEEPROM(uint8_t address) : 36 | _address(address) 37 | { 38 | } 39 | 40 | bool 41 | writePage(uint16_t pageNum, const uint8_t *pageBuf) 42 | { 43 | const uint16_t pageAddr = pageNum*numPages; 44 | Wire.beginTransmission(_address); 45 | Wire.write(pageAddr >> 8); // MSB 46 | Wire.write(pageAddr & uint16_t(0xFF)); // LSB 47 | for (uint8_t c = 0; c < pageSize; ++c) 48 | Wire.write(pageBuf[c]); 49 | const uint8_t res = Wire.endTransmission(); 50 | Serial.println(res, DEC); 51 | Wire.flush(); 52 | return res == 0; 53 | } 54 | 55 | bool 56 | writeByte(uint16_t address, uint8_t byte) 57 | { 58 | Wire.beginTransmission(_address); 59 | Wire.write(address >> 8); // MSB 60 | Wire.write(address & 0xFF); // LSB 61 | Wire.write(byte); 62 | const uint8_t res = Wire.endTransmission(); 63 | Wire.flush(); 64 | return res == 0; 65 | } 66 | 67 | bool 68 | readByte(uint16_t address, uint8_t &byte) 69 | { 70 | Wire.beginTransmission(_address); 71 | Wire.write(address >> 8); // MSB 72 | Wire.write(address & 0xFF); // LSB 73 | const uint8_t res = Wire.endTransmission(); 74 | if (res != 0) 75 | return false; 76 | Wire.requestFrom(_address, uint8_t(1)); 77 | uint8_t repeat = 3; 78 | while (!Wire.available()) { 79 | delay(1); 80 | if (repeat-- == 0) 81 | break; 82 | } 83 | if (Wire.available()) { 84 | byte = Wire.read(); 85 | return true; 86 | } else 87 | return false; 88 | } 89 | 90 | bool 91 | readPage(uint16_t pageNum, uint8_t *pageBuf) 92 | { 93 | const uint16_t pageAddr = pageNum*numPages; 94 | Wire.beginTransmission(_address); 95 | Wire.write(pageAddr >> 8); // MSB 96 | Wire.write(pageAddr & uint16_t(0xFF)); // LSB 97 | const uint8_t res = Wire.endTransmission(); 98 | if (res != 0) 99 | return false; 100 | Wire.flush(); 101 | Wire.requestFrom(_address, pageSize); 102 | for (uint8_t c = 0; c < pageSize; ++c) { 103 | uint8_t repeat = 3; 104 | while (!Wire.available()) { 105 | delay(1); 106 | if (repeat-- == 0) 107 | break; 108 | } 109 | if (Wire.available()) 110 | pageBuf[c] = Wire.read(); 111 | else 112 | return false; 113 | } 114 | return true; 115 | } 116 | 117 | template 118 | bool 119 | read(uint16_t address, T &object) 120 | { 121 | uint8_t *buf = reinterpret_cast(&object); 122 | 123 | for (uint16_t i=0, position=0; i> 8); // MSB 127 | Wire.write(address & uint16_t(0xFF)); // LSB 128 | const uint8_t res = Wire.endTransmission(); 129 | if (res != 0) 130 | return false; 131 | Wire.flush(); 132 | Wire.requestFrom(_address, sizeof(object)); 133 | } 134 | if (position == pageSize) { 135 | position = 0; 136 | const uint8_t res = Wire.endTransmission(); 137 | Wire.flush(); 138 | if (res != 0) 139 | return false; 140 | } 141 | uint8_t repeat = 3; 142 | while (!Wire.available()) { 143 | delay(1); 144 | if (repeat-- == 0) 145 | break; 146 | } 147 | if (Wire.available()) 148 | buf[i] = Wire.read(); 149 | else 150 | return false; 151 | } 152 | return true; 153 | } 154 | 155 | template 156 | bool 157 | write(uint16_t address, const T &object) 158 | { 159 | const uint8_t *buf = reinterpret_cast(&object); 160 | for (uint16_t i=0, position=0; i> 8); // MSB 164 | Wire.write(address & uint16_t(0xFF)); // LSB 165 | } 166 | if (position == pageSize) { 167 | position = 0; 168 | const uint8_t res = Wire.endTransmission(); 169 | Wire.flush(); 170 | if (res != 0) 171 | return false; 172 | if (i>=sizeof(object)) 173 | return true; 174 | } 175 | Wire.write(buf[i]); 176 | } 177 | const uint8_t res = Wire.endTransmission(); 178 | Wire.flush(); 179 | return res == 0; 180 | } 181 | 182 | static constexpr uint16_t numPages = SIZE / pageSize; 183 | static constexpr uint32_t size = SIZE; 184 | 185 | private: 186 | uint8_t _address; 187 | }; 188 | 189 | typedef I2CEEPROM<16384ul, 64> AT28C128C; 190 | typedef I2CEEPROM<32768ul, 64> AT28C256C; 191 | typedef I2CEEPROM<65536ul, 128> AT28C512C; 192 | 193 | #endif // I2CEEPROM_HPP 194 | -------------------------------------------------------------------------------- /terminal-basic/liquidcrystalprint.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * ArduinoExt is a set of utility libraries for Arduino 3 | * 4 | * Copyright (C) 2016-2018 Andrey V. Skvortsov 5 | * Copyright (C) 2019,2021 Terminal-BASIC team 6 | * 7 | * 8 | * This program is free software: is free software: you can redistribute it and/or 9 | * modify it under the terms of the GNU Lesser General Public License 10 | * as published by the Free Software Foundation, either version 3 of 11 | * the License, or (at your option) any later version. 12 | 13 | * ArduinoExt library is distributed in the hope that it will be useful, 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | * GNU General Public License for more details. 17 | 18 | * You should have received a copy of the GNU Lesser General Public 19 | * License along with Posixcpp library. If not, see 20 | * . 21 | */ 22 | 23 | #include 24 | 25 | #include "liquidcrystalprint.hpp" 26 | #include "ascii.hpp" 27 | 28 | LiquidCrystalVt100::LiquidCrystalVt100(LiquidCrystal &lc, uint8_t w, uint8_t h, 29 | uint8_t *buffer) : 30 | _crystal(lc), _w(w), _h(h), _buffer(buffer) 31 | { 32 | } 33 | 34 | void 35 | LiquidCrystalVt100::clear() 36 | { 37 | _crystal.clear(); 38 | _x=_y=0; 39 | _crystal.setCursor(0,0); 40 | memset(_buffer, ' ', _w*_h); 41 | } 42 | 43 | uint8_t 44 | LiquidCrystalVt100::getCursorX() 45 | { 46 | return _x; 47 | } 48 | 49 | void 50 | LiquidCrystalVt100::setCursor(uint8_t x, uint8_t y) 51 | { 52 | if (x >= _w) 53 | x = _w-1; 54 | if (y >= _h) 55 | y = _h-1; 56 | _x=x; _y=y; 57 | _crystal.setCursor(x,y); 58 | } 59 | 60 | void 61 | LiquidCrystalVt100::setCursorX(uint8_t x) 62 | { 63 | while (x >= _w) { 64 | x -= _w; 65 | _x = 0; 66 | scroll(); 67 | } 68 | _x = x; 69 | _crystal.setCursor(_x, _y); 70 | } 71 | 72 | void 73 | LiquidCrystalVt100::writeChar(uint8_t c) 74 | { 75 | switch (c) { 76 | case '\n': 77 | scroll(); break; 78 | case '\r': 79 | _x = 0; 80 | _crystal.setCursor(_x, _y); break; 81 | case uint8_t(ASCII::BS) : 82 | if (_x > 0) 83 | --_x; 84 | else if (_y > 0) { 85 | --_y; 86 | _x = _w-1; 87 | } 88 | _crystal.setCursor(_x, _y); 89 | _crystal.write(' '); 90 | _crystal.setCursor(_x, _y); 91 | _buffer[_y*_w+_x] = ' '; 92 | break; 93 | default: 94 | _crystal.write(c); 95 | _buffer[_y*_w+_x] = c; 96 | if (_x < (_w-1)) 97 | ++_x; 98 | else { 99 | scroll(); 100 | _x = 0; 101 | _crystal.setCursor(_x, _y); 102 | } 103 | } 104 | } 105 | 106 | void 107 | LiquidCrystalVt100::scroll() 108 | { 109 | if (_y < (_h-1)) { 110 | ++_y; 111 | } else { 112 | _crystal.noCursor(); 113 | memmove(_buffer, _buffer+_w, _w*(_h-1)); 114 | for (uint8_t y=0; y<(_h-1); ++y) { 115 | _crystal.setCursor(0,y); 116 | for (uint8_t x=0; x<_w; ++x) 117 | _crystal.write(_buffer[(_w*y)+x]); 118 | } 119 | _crystal.setCursor(0, _h-1); 120 | for (uint8_t x=0; x<_w; ++x) { 121 | _crystal.write(uint8_t(' ')); 122 | _buffer[_w*(_h-1)+x] = ' '; 123 | } 124 | _crystal.cursor(); 125 | } 126 | _crystal.setCursor(_x, _y); 127 | } 128 | -------------------------------------------------------------------------------- /terminal-basic/liquidcrystalprint.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * ArduinoExt is a set of utility libraries for Arduino 3 | * 4 | * Copyright (C) 2016-2018 Andrey V. Skvortsov 5 | * Copyright (C) 2019,2021 Terminal-BASIC team 6 | * 7 | * 8 | * This program is free software: is free software: you can redistribute it and/or 9 | * modify it under the terms of the GNU Lesser General Public License 10 | * as published by the Free Software Foundation, either version 3 of 11 | * the License, or (at your option) any later version. 12 | 13 | * ArduinoExt library is distributed in the hope that it will be useful, 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | * GNU General Public License for more details. 17 | 18 | * You should have received a copy of the GNU Lesser General Public 19 | * License along with Posixcpp library. If not, see 20 | * . 21 | */ 22 | 23 | #ifndef LIQUIDCRYSTALPRINT_HPP 24 | #define LIQUIDCRYSTALPRINT_HPP 25 | 26 | #include "vt100.hpp" 27 | #include "LiquidCrystal.h" 28 | 29 | class LiquidCrystalVt100 : public VT100::Print 30 | { 31 | EXT_NOTCOPYABLE(LiquidCrystalVt100) 32 | public: 33 | LiquidCrystalVt100(LiquidCrystal&, uint8_t, uint8_t, uint8_t*); 34 | void clear() override; 35 | protected: 36 | uint8_t getCursorX() override; 37 | void setCursor(uint8_t, uint8_t) override; 38 | void setCursorX(uint8_t) override; 39 | void writeChar(uint8_t) override; 40 | private: 41 | void scroll(); 42 | LiquidCrystal &_crystal; 43 | uint8_t _x,_y, _w, _h; 44 | uint8_t *_buffer; 45 | }; 46 | 47 | #endif 48 | -------------------------------------------------------------------------------- /terminal-basic/seriallight.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * ArduinoExt is a set of utility libraries for Arduino 3 | * 4 | * Copyright (C) 2016-2018 Andrey V. Skvortsov 5 | * Copyright (C) 2019,2021 Terminal-BASIC team 6 | * 7 | * 8 | * This program is free software: you can redistribute it and/or modify 9 | * it under the terms of the GNU General Public License as published by 10 | * the Free Software Foundation, either version 3 of the License, or 11 | * (at your option) any later version. 12 | * 13 | * This program is distributed in the hope that it will be useful, 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | * GNU General Public License for more details. 17 | * 18 | * You should have received a copy of the GNU General Public License 19 | * along with this program. If not, see . 20 | */ 21 | 22 | #ifdef __AVR_ARCH__ 23 | 24 | #include "seriallight.hpp" 25 | 26 | #include 27 | #include "wiring_private.h" 28 | 29 | SerialLight SerialL(&UBRR0H, &UBRR0L, &UCSR0A, &UCSR0B, &UCSR0C, &UDR0); 30 | #ifdef HAVE_HWSERIAL1 31 | SerialLight SerialL1(&UBRR1H, &UBRR1L, &UCSR1A, &UCSR1B, &UCSR1C, &UDR1); 32 | #endif 33 | #ifdef HAVE_HWSERIAL2 34 | SerialLight SerialL2(&UBRR2H, &UBRR2L, &UCSR2A, &UCSR2B, &UCSR2C, &UDR2); 35 | #endif 36 | #ifdef HAVE_HWSERIAL3 37 | SerialLight SerialL3(&UBRR3H, &UBRR3L, &UCSR3A, &UCSR3B, &UCSR3C, &UDR3); 38 | #endif 39 | 40 | SerialLight::SerialLight( 41 | volatile uint8_t *ubrrh, volatile uint8_t *ubrrl, 42 | volatile uint8_t *ucsra, volatile uint8_t *ucsrb, 43 | volatile uint8_t *ucsrc, volatile uint8_t *udr) : 44 | _ubrrh(ubrrh), _ubrrl(ubrrl), 45 | _ucsra(ucsra), _ucsrb(ucsrb), _ucsrc(ucsrc), 46 | _udr(udr), _hasByte(false) 47 | { 48 | } 49 | 50 | void 51 | SerialLight::begin(unsigned long baud, uint8_t config) 52 | { 53 | // Try u2x mode first 54 | uint16_t baud_setting = (F_CPU / 4 / baud - 1) / 2; 55 | *_ucsra = 1 << U2X0; 56 | 57 | // hardcoded exception for 57600 for compatibility with the bootloader 58 | // shipped with the Duemilanove and previous boards and the firmware 59 | // on the 8U2 on the Uno and Mega 2560. Also, The baud_setting cannot 60 | // be > 4095, so switch back to non-u2x mode if the baud rate is too 61 | // low. 62 | if (((F_CPU == 16000000UL) && (baud == 57600)) || (baud_setting > 4095)) { 63 | *_ucsra = 0; 64 | baud_setting = (F_CPU / 8 / baud - 1) / 2; 65 | } 66 | 67 | // assign the baud_setting, a.k.a. ubrr (USART Baud Rate Register) 68 | *_ubrrh = baud_setting >> 8; 69 | *_ubrrl = baud_setting; 70 | 71 | //set the data bits, parity, and stop bits 72 | #if defined(__AVR_ATmega8__) 73 | config |= 0x80; // select UCSRC register (shared with UBRRH) 74 | #endif 75 | *_ucsrc = config; 76 | 77 | sbi(*_ucsrb, RXEN0); 78 | sbi(*_ucsrb, TXEN0); 79 | } 80 | 81 | int 82 | SerialLight::available() 83 | { 84 | if (*_ucsra & (1< 5 | * Copyright (C) 2019,2021 Terminal-BASIC team 6 | * 7 | * 8 | * This program is free software: is free software: you can redistribute it and/or 9 | * modify it under the terms of the GNU Lesser General Public License 10 | * as published by the Free Software Foundation, either version 3 of 11 | * the License, or (at your option) any later version. 12 | 13 | * ArduinoExt library is distributed in the hope that it will be useful, 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | * GNU General Public License for more details. 17 | 18 | * You should have received a copy of the GNU Lesser General Public 19 | * License along with Posixcpp library. If not, see 20 | * . 21 | */ 22 | 23 | #ifndef SERIALLIGHT_HPP 24 | #define SERIALLIGHT_HPP 25 | 26 | #include 27 | #include 28 | 29 | #include "HardwareSerial.h" 30 | 31 | #ifdef ARDUINO_ARCH_SAM 32 | 33 | typedef HardwareSerial SerialLight; 34 | 35 | #define SerialL Serial 36 | #ifdef HAVE_HWSERIAL1 37 | #define SerialL1 Serial1 38 | #endif 39 | #ifdef HAVE_HWSERIAL2 40 | #define SerialL2 Serial2 41 | #endif 42 | #ifdef HAVE_HWSERIAL3 43 | #define SerialL3 Serial3 44 | #endif 45 | 46 | #elif ARDUINO_ARCH_AVR 47 | 48 | #define SERIAL_8N1 0x06 49 | class SerialLight : public Stream 50 | { 51 | public: 52 | SerialLight( 53 | volatile uint8_t *ubrrh, volatile uint8_t *ubrrl, 54 | volatile uint8_t *ucsra, volatile uint8_t *ucsrb, 55 | volatile uint8_t *ucsrc, volatile uint8_t *udr); 56 | 57 | void 58 | begin(unsigned long baud) 59 | { 60 | begin(baud, SERIAL_8N1); 61 | } 62 | void begin(unsigned long, uint8_t); 63 | 64 | int available() override; 65 | void flush() override; 66 | int peek() override; 67 | int read() override; 68 | size_t write(uint8_t) override; 69 | private: 70 | volatile uint8_t * const _ubrrh; 71 | volatile uint8_t * const _ubrrl; 72 | volatile uint8_t * const _ucsra; 73 | volatile uint8_t * const _ucsrb; 74 | volatile uint8_t * const _ucsrc; 75 | volatile uint8_t * const _udr; 76 | bool _hasByte; 77 | uint8_t _byte; 78 | }; 79 | 80 | extern SerialLight SerialL; 81 | #ifdef HAVE_HWSERIAL1 82 | extern SerialLight SerialL1; 83 | #endif 84 | #ifdef HAVE_HWSERIAL2 85 | extern SerialLight SerialL2; 86 | #endif 87 | #ifdef HAVE_HWSERIAL3 88 | extern SerialLight SerialL3; 89 | #endif 90 | 91 | #endif 92 | 93 | #endif // SERIALLIGHT_HPP 94 | -------------------------------------------------------------------------------- /terminal-basic/strings_en.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of Terminal-BASIC: a lightweight BASIC-like language 3 | * interpreter. 4 | * 5 | * Copyright (C) 2016-2018 Andrey V. Skvortsov 6 | * Copyright (C) 2019-2021 Terminal-BASIC team 7 | * 8 | * 9 | * This program is free software: you can redistribute it and/or modify 10 | * it under the terms of the GNU General Public License as published by 11 | * the Free Software Foundation, either version 3 of the License, or 12 | * (at your option) any later version. 13 | * 14 | * This program is distributed in the hope that it will be useful, 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | * GNU General Public License for more details. 18 | * 19 | * You should have received a copy of the GNU General Public License 20 | * along with this program. If not, see . 21 | */ 22 | 23 | #ifndef STRINGS_EN_HPP 24 | #define STRINGS_EN_HPP 25 | 26 | #define STR_NO_ERROR "NO ERROR" 27 | #define STR_OPERATOR_EXPECTED "OPERATOR EXPECTED" 28 | #define STR_IDENTIFYER_EXPECTED "IDENTIFIER EXPECTED" 29 | #define STR_EXPRESSION_EXPECTED "EXPRESSION EXPECTED" 30 | #define STR_INTEGER_CONSTANT_EXPECTED "INTEGER CONSTANT EXPECTED" 31 | #define STR_THEN_OR_GOTO_EXPECTED "THEN OR GOTO EXPECTED" 32 | #define STR_INVALID_DATA_EXPRESSION "INVALID DATA EXPRESSION" 33 | #define STR_INVALID_READ_EXPRESSION "INVALID READ EXPRESSION" 34 | #define STR_VARIABLES_LIST_EXPECTED "VARIABLES LIST EXPECTED" 35 | #define STR_STRING_OVERFLOW "STRING OVERFLOW" 36 | #define STR_MISSING_RPAREN "MISSING RIGHT PARENTHESIS" 37 | #define STR_INVALID_ONGOTO_INDEX "INVALID ON ... GOTO INDEX" 38 | 39 | #define STR_OUTTA_MEMORY "OUT OF MEMORY" 40 | #define STR_REDIMED_ARRAY "ARRAY ALREADY ALLOCATED" 41 | #define STR_STACK_FRAME_ALLOC "UNABLE TO ALLOCATE STACK FRAME" 42 | #define STR_MISING_STRING_FRAME "MISSING STRING FRAME" 43 | #define STR_INVALID_NEXT "MISPLACED FOR ... NEXT" 44 | #define STR_RETURN_WO_GOSUB "RETURN WITHOUT GOSUB" 45 | #define STR_NO_SUCH_LINE "NO SUCH PROGRAM LINE" 46 | #define STR_INVALID_VALUE_TYPE "INVALID TYPE" 47 | #define STR_NO_SUCH_ARRAY "NO SUCH ARRAY" 48 | #define STR_INTEGER_EXP_EXPECTED "INTEGER EXPECTED" 49 | #define STR_BAD_CHECKSUM "BAD CHECKSUM" 50 | #define STR_INVALID_TAB "INVALID TAB VALUE" 51 | #define STR_INVALID_ELEMENT_INDEX "INVALID ELEMENT INDEX" 52 | #define STR_SQUARE_MATRIX_EXPECTED "SQUARE_MATRIX_EXPECTED" 53 | #define STR_DIMENSIONS_MISMATCH "DIMENSIONS MISMATCH" 54 | #define STR_COMMAND_FAILED "COMMAND EXECUTION FAILED" 55 | #define STR_VAR_DUPLICATE "DUPLICATE VARIABLE" 56 | #define STR_FUNCTION_DUPLICATE "DUPLICATE FUNCTION" 57 | #define STR_NO_SUCH_FUNCION "NO SUCH FUNCTION" 58 | #define STR_INSUFFICIENT_DATA "INSUFFICIENT DATA FOR READ" 59 | 60 | #define STR_LICENSE_MESSAGE \ 61 | "Copyright (C) 2016-2018 Andrey V. Skvortsov \n" \ 62 | "Copyright (C) 2019-2021 Terminal-BASIC team\n" \ 63 | " \n" \ 64 | "This program comes with ABSOLUTELY NO WARRANTY.\n" \ 65 | "This is free software, and you are welcome to redistribute it\n" \ 66 | "under the terms of the GNU General Public License as published by\n" \ 67 | "the Free Software Foundation, either version 3 of the License, or\n" \ 68 | "(at your option) any later version." 69 | 70 | #define STR_ERROR "ERROR" 71 | #define STR_BYTES "BYTES" 72 | #define STR_VERSION "VERSION" 73 | #define STR_AVAILABLE "AVAILABLE" 74 | #define STR_CLI_PROMPT "READY" 75 | #define STR_SYNTAX "SYNTAX" 76 | #define STR_SEMANTIC "SEMANTIC" 77 | 78 | #endif // STRINGS_EN_HPP 79 | -------------------------------------------------------------------------------- /terminal-basic/strings_fr.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of Terminal-BASIC: a lightweight BASIC-like language 3 | * interpreter. 4 | * 5 | * Copyright (C) 2016-2018 Andrey V. Skvortsov 6 | * Copyright (C) 2019-2021 Terminal-BASIC team 7 | * 8 | * 9 | * This program is free software: you can redistribute it and/or modify 10 | * it under the terms of the GNU General Public License as published by 11 | * the Free Software Foundation, either version 3 of the License, or 12 | * (at your option) any later version. 13 | * 14 | * This program is distributed in the hope that it will be useful, 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | * GNU General Public License for more details. 18 | * 19 | * You should have received a copy of the GNU General Public License 20 | * along with this program. If not, see . 21 | */ 22 | 23 | #ifndef STRINGS_EN_HPP 24 | #define STRINGS_EN_HPP 25 | 26 | #define STR_NO_ERROR "PAS D'ERREUR" 27 | #define STR_OPERATOR_EXPECTED "L'OPERATEUR ATTENDU" 28 | #define STR_IDENTIFYER_EXPECTED "IDENTIFIANT ATTENDU" 29 | #define STR_EXPRESSION_EXPECTED "L'EXPRESSION ATTENDU" 30 | #define STR_INTEGER_CONSTANT_EXPECTED "CONSTANTE ENTIERE ATTENDUE" 31 | #define STR_THEN_OR_GOTO_EXPECTED "ALORS OU ALLERA ATTENDU" 32 | #define STR_INVALID_DATA_EXPRESSION "EXPRESSION DATA NON VALIDE" 33 | #define STR_INVALID_READ_EXPRESSION "EXPRESSION LIRE NON VALIDE" 34 | #define STR_VARIABLES_LIST_EXPECTED "LISTE DES VARIABLES ATTENDUES" 35 | #define STR_STRING_OVERFLOW "DEBORDEMENT DE CHAINE" 36 | #define STR_MISSING_RPAREN "PARENTHESE DROITE MANQUANTE" 37 | #define STR_INVALID_ONGOTO_INDEX "INVALID ENCAS ... ALLERA INDEX" 38 | 39 | #define STR_OUTTA_MEMORY "MEMOIRE INSUFFISANTE" 40 | #define STR_REDIMED_ARRAY "TABLEAU DEJA ALLOUE" 41 | #define STR_STACK_FRAME_ALLOC "IMPOSSIBLE D'ALLOUER LE TRAME DE PILE" 42 | #define STR_MISING_STRING_FRAME "MISSING STRING FRAME" 43 | #define STR_INVALID_NEXT "POUR ... SUIVANT DEPLACEE" 44 | #define STR_RETURN_WO_GOSUB "RETOUR SANS ALLERSOUS" 45 | #define STR_NO_SUCH_LINE "PAS DE TELLE LIGNE DE PROGRAMME" 46 | #define STR_INVALID_VALUE_TYPE "INVALID TYPE" 47 | #define STR_NO_SUCH_ARRAY "NO SUCH ARRAY" 48 | #define STR_INTEGER_EXP_EXPECTED "INTEGER EXPECTED" 49 | #define STR_BAD_CHECKSUM "BAD CHECKSUM" 50 | #define STR_INVALID_TAB "INVALID TAB VALUE" 51 | #define STR_INVALID_ELEMENT_INDEX "INVALID ELEMENT INDEX" 52 | #define STR_SQUARE_MATRIX_EXPECTED "SQUARE_MATRIX_EXPECTED" 53 | #define STR_DIMENSIONS_MISMATCH "DIMENSIONS MISMATCH" 54 | #define STR_COMMAND_FAILED "COMMAND EXECUTION FAILED" 55 | #define STR_VAR_DUPLICATE "DUPLICATE VARIABLE" 56 | #define STR_FUNCTION_DUPLICATE "DUPLICATE FUNCTION" 57 | #define STR_NO_SUCH_FUNCION "PAS DE TELLE FONCTION" 58 | #define STR_INSUFFICIENT_DATA "INSUFFICIENT DATA FOR READ" 59 | 60 | #define STR_LICENSE_MESSAGE \ 61 | "Copyright (C) 2016-2018 Andrey V. Skvortsov \n" \ 62 | "Copyright (C) 2019-2021 Terminal-BASIC team\n" \ 63 | " \n" \ 64 | "This program comes with ABSOLUTELY NO WARRANTY.\n" \ 65 | "This is free software, and you are welcome to redistribute it\n" \ 66 | "under the terms of the GNU General Public License as published by\n" \ 67 | "the Free Software Foundation, either version 3 of the License, or\n" \ 68 | "(at your option) any later version." 69 | 70 | #define STR_ERROR "ERREUR" 71 | #define STR_BYTES "OCTETS" 72 | #define STR_VERSION "VERSION" 73 | #define STR_AVAILABLE "DISPONIBLES" 74 | #define STR_CLI_PROMPT "PRET" 75 | #define STR_SYNTAX "SYNTAXE" 76 | #define STR_SEMANTIC "SEMANTIC" 77 | 78 | #endif // STRINGS_EN_HPP 79 | -------------------------------------------------------------------------------- /terminal-basic/strings_ru.hpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/terminal-basic-team/terminalbasic-arduino/696be0738c213082125c95f4c6ae180d2989d50e/terminal-basic/strings_ru.hpp -------------------------------------------------------------------------------- /terminal-basic/sys/cdefs.h: -------------------------------------------------------------------------------- 1 | /* Copyright (C) 1992-2014 Free Software Foundation, Inc. 2 | This file is part of the GNU C Library. 3 | 4 | The GNU C Library is free software; you can redistribute it and/or 5 | modify it under the terms of the GNU Lesser General Public 6 | License as published by the Free Software Foundation; either 7 | version 2.1 of the License, or (at your option) any later version. 8 | 9 | The GNU C Library is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | Lesser General Public License for more details. 13 | 14 | You should have received a copy of the GNU Lesser General Public 15 | License along with the GNU C Library; if not, see 16 | . */ 17 | 18 | // Modified by Andrey V. Skvortsov, 2017 19 | 20 | #ifndef CDEFS_H 21 | #define CDEFS_H 22 | 23 | #ifdef ARDUINO 24 | 25 | /* C++ needs to know that types and declarations are C, not C++. */ 26 | #ifdef __cplusplus 27 | # define __BEGIN_DECLS extern "C" { 28 | # define __END_DECLS } 29 | #else 30 | # define __BEGIN_DECLS 31 | # define __END_DECLS 32 | #endif 33 | 34 | #else 35 | #include_next 36 | #endif 37 | 38 | #endif /* CDEFS_H */ 39 | -------------------------------------------------------------------------------- /terminal-basic/tools.c: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of Terminal-BASIC: a lightweight BASIC-like language 3 | * interpreter. 4 | * 5 | * Copyright (C) 2016-2018 Andrey V. Skvortsov 6 | * Copyright (C) 2019-2021 Terminal-BASIC team 7 | * 8 | * 9 | * This program is free software: you can redistribute it and/or modify 10 | * it under the terms of the GNU General Public License as published by 11 | * the Free Software Foundation, either version 3 of the License, or 12 | * (at your option) any later version. 13 | * 14 | * This program is distributed in the hope that it will be useful, 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | * GNU General Public License for more details. 18 | * 19 | * You should have received a copy of the GNU General Public License 20 | * along with this program. If not, see . 21 | */ 22 | 23 | #include 24 | #include 25 | #include 26 | 27 | #include "tools.h" 28 | 29 | #define FLOAT_DIGITS10 7 30 | 31 | BOOLEAN 32 | tools_isAlpha(uint8_t c) 33 | { 34 | /* cp866 alpha symbols */ 35 | return (c >= 224 && c <= 247) || 36 | (c >= 128 && c <= 175) || 37 | (c >= 65 && c <= 90) || 38 | (c >= 97 && c <= 122); 39 | } 40 | 41 | BOOLEAN 42 | tools_isAlphaNum(uint8_t c) 43 | { 44 | return isdigit(c) || tools_isAlpha(c); 45 | } 46 | 47 | void 48 | _ftoa(float f, char *buf) 49 | { 50 | if (f != f) { // NaN - comparision invalid 51 | strcpy(buf, "NAN"); 52 | return; 53 | } else if (f + f == f) { // machine zero 54 | if (1.f / f < 0.f) 55 | strcpy(buf, "-0.0"); 56 | else if (f == 0.0f) 57 | strcpy(buf, "0.0"); 58 | else if (f > 0.0f) 59 | strcpy(buf, "INF"); 60 | else 61 | strcpy(buf, "-INF"); 62 | return; 63 | } 64 | 65 | if (f < 0.f) { // Add "-" for negative ordinar values 66 | f = -f; 67 | *(buf++) = '-'; 68 | } 69 | 70 | int32_t n = 0; 71 | // Move to set 1st significant decimal digit before decimal point 72 | if (f < 1e6f) { 73 | do { 74 | f *= 10.f; 75 | --n; 76 | } while (f < (1e6f - 0.5f)); 77 | } else if (f >= 1e7f) { 78 | do { 79 | f /= 10.f; 80 | ++n; 81 | } while (f >= 1e7f + 0.5f); 82 | } 83 | n += FLOAT_DIGITS10 - 1; 84 | uint32_t fi = f + 0.5f; 85 | 86 | uint8_t i; 87 | for (i = FLOAT_DIGITS10; i > 1; --i) { 88 | buf[i] = fi % 10 + '0'; 89 | fi /= 10; 90 | } 91 | buf[1] = '.'; 92 | buf[0] = fi % 10 + '0'; 93 | buf += FLOAT_DIGITS10 + 1; 94 | if (n != 0) { 95 | *(buf++) = 'e'; 96 | if (n < 0) { 97 | *(buf++) = '-'; 98 | n = -n; 99 | } 100 | if (n >= 10) 101 | *(buf++) = n / 10 + '0'; 102 | *(buf++) = n % 10 + '0'; 103 | } 104 | 105 | *buf = '\0'; 106 | } 107 | 108 | union U16 { 109 | uint16_t num; 110 | char bytes[sizeof(uint16_t)]; 111 | }; 112 | 113 | union U32 { 114 | uint32_t num; 115 | char bytes[sizeof(uint32_t)]; 116 | }; 117 | 118 | union U64 { 119 | uint64_t num; 120 | char bytes[sizeof(uint64_t)]; 121 | }; 122 | 123 | union R32 { 124 | float num; 125 | char bytes[sizeof(float)]; 126 | }; 127 | 128 | union R64 { 129 | double num; 130 | char bytes[sizeof(double)]; 131 | }; 132 | 133 | void 134 | readU16(uint16_t *num, const uint8_t *buf) 135 | { 136 | union U16 s; 137 | 138 | s.bytes[1] = *(buf++); 139 | s.bytes[0] = *buf; 140 | 141 | *num = s.num; 142 | } 143 | 144 | void 145 | writeU16(uint16_t num, uint8_t *buf) 146 | { 147 | union U16 s; 148 | 149 | s.num = num; 150 | 151 | *(buf++) = s.bytes[1]; 152 | *buf = s.bytes[0]; 153 | } 154 | 155 | void 156 | readU32(uint32_t *num, const uint8_t *buf) 157 | { 158 | union U32 s; 159 | 160 | s.bytes[3] = *(buf++); 161 | s.bytes[2] = *(buf++); 162 | s.bytes[1] = *(buf++); 163 | s.bytes[0] = *buf; 164 | 165 | *num = s.num; 166 | } 167 | 168 | void 169 | writeU32(uint32_t num, uint8_t *buf) 170 | { 171 | union U32 s; 172 | 173 | s.num = num; 174 | 175 | *(buf++) = s.bytes[3]; 176 | *(buf++) = s.bytes[2]; 177 | *(buf++) = s.bytes[1]; 178 | *buf = s.bytes[0]; 179 | } 180 | 181 | void 182 | readU64(uint64_t *num, const uint8_t *buf) 183 | { 184 | union U64 s; 185 | 186 | s.bytes[7] = *(buf++); 187 | s.bytes[6] = *(buf++); 188 | s.bytes[5] = *(buf++); 189 | s.bytes[4] = *(buf++); 190 | s.bytes[3] = *(buf++); 191 | s.bytes[2] = *(buf++); 192 | s.bytes[1] = *(buf++); 193 | s.bytes[0] = *buf; 194 | 195 | *num = s.num; 196 | } 197 | 198 | void 199 | writeU64(uint64_t num, uint8_t *buf) 200 | { 201 | union U64 s; 202 | 203 | s.num = num; 204 | 205 | *(buf++) = s.bytes[7]; 206 | *(buf++) = s.bytes[6]; 207 | *(buf++) = s.bytes[5]; 208 | *(buf++) = s.bytes[4]; 209 | *(buf++) = s.bytes[3]; 210 | *(buf++) = s.bytes[2]; 211 | *(buf++) = s.bytes[1]; 212 | *buf = s.bytes[0]; 213 | } 214 | 215 | void 216 | readR32(float *num, const const uint8_t *buf) 217 | { 218 | union R32 s; 219 | 220 | s.bytes[3] = *(buf++); 221 | s.bytes[2] = *(buf++); 222 | s.bytes[1] = *(buf++); 223 | s.bytes[0] = *buf; 224 | 225 | *num = s.num; 226 | } 227 | 228 | void 229 | writeR32(float num, uint8_t *buf) 230 | { 231 | union R32 s; 232 | 233 | s.num = num; 234 | 235 | *(buf++) = s.bytes[3]; 236 | *(buf++) = s.bytes[2]; 237 | *(buf++) = s.bytes[1]; 238 | *buf = s.bytes[0]; 239 | } 240 | 241 | void 242 | writeR64(double num, uint8_t *buf) 243 | { 244 | union R64 s; 245 | 246 | s.num = num; 247 | 248 | *(buf++) = s.bytes[7]; 249 | *(buf++) = s.bytes[6]; 250 | *(buf++) = s.bytes[5]; 251 | *(buf++) = s.bytes[4]; 252 | *(buf++) = s.bytes[3]; 253 | *(buf++) = s.bytes[2]; 254 | *(buf++) = s.bytes[1]; 255 | *buf = s.bytes[0]; 256 | } 257 | 258 | void 259 | readR64(double *num, const uint8_t *buf) 260 | { 261 | union U64 s; 262 | 263 | s.bytes[7] = *(buf++); 264 | s.bytes[6] = *(buf++); 265 | s.bytes[5] = *(buf++); 266 | s.bytes[4] = *(buf++); 267 | s.bytes[3] = *(buf++); 268 | s.bytes[2] = *(buf++); 269 | s.bytes[1] = *(buf++); 270 | s.bytes[0] = *buf; 271 | 272 | *num = s.num; 273 | } 274 | -------------------------------------------------------------------------------- /terminal-basic/tools.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of Terminal-BASIC: a lightweight BASIC-like language 3 | * interpreter. 4 | * 5 | * Copyright (C) 2016-2018 Andrey V. Skvortsov 6 | * Copyright (C) 2019-2021 Terminal-BASIC team 7 | * 8 | * 9 | * This program is free software: you can redistribute it and/or modify 10 | * it under the terms of the GNU General Public License as published by 11 | * the Free Software Foundation, either version 3 of the License, or 12 | * (at your option) any later version. 13 | * 14 | * This program is distributed in the hope that it will be useful, 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | * GNU General Public License for more details. 18 | * 19 | * You should have received a copy of the GNU General Public License 20 | * along with this program. If not, see . 21 | */ 22 | 23 | #ifndef TOOLS_H 24 | #define TOOLS_H 25 | 26 | #include "sys/cdefs.h" 27 | #include 28 | 29 | __BEGIN_DECLS 30 | 31 | typedef uint8_t BOOLEAN; 32 | 33 | #ifndef TRUE 34 | #define TRUE ((BOOLEAN)1) 35 | #endif 36 | 37 | #ifndef FALSE 38 | #define FALSE ((BOOLEAN)0) 39 | #endif 40 | 41 | /** 42 | * @brief Test if character is alphabetic 43 | * @param 44 | */ 45 | BOOLEAN tools_isAlpha(uint8_t); 46 | 47 | BOOLEAN tools_isAlphaNum(uint8_t); 48 | 49 | void _ftoa(float, char*); 50 | 51 | void _dtoa(double, char*); 52 | 53 | void readU16(uint16_t*, const uint8_t*); 54 | 55 | void writeU16(uint16_t, uint8_t*); 56 | 57 | void readU32(uint32_t*, const uint8_t*); 58 | 59 | void writeU32(uint32_t, uint8_t*); 60 | 61 | void readU64(uint64_t*, const uint8_t*); 62 | 63 | void writeU64(uint64_t, uint8_t*); 64 | 65 | void readR32(float*, const uint8_t*); 66 | 67 | void writeR32(float, uint8_t*); 68 | 69 | void writeR64(double, uint8_t*); 70 | 71 | void readR64(double*, const uint8_t*); 72 | 73 | #define ARRAY_SIZE(a) (sizeof(a)/sizeof(a[0])) 74 | 75 | #define LOW_BYTE_U16(w) ((uint8_t)w) 76 | 77 | #define HIGH_BYTE_U16(w) ((uint8_t)((w) >> 8)) 78 | 79 | __END_DECLS 80 | 81 | #endif /* TOOLS_H */ 82 | 83 | -------------------------------------------------------------------------------- /terminal-basic/tvoutprint.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of Terminal-BASIC: a lightweight BASIC-like language 3 | * interpreter. 4 | * 5 | * Copyright (C) 2016-2018 Andrey V. Skvortsov 6 | * Copyright (C) 2019-2021 Terminal-BASIC team 7 | * 8 | * 9 | * This program is free software: you can redistribute it and/or modify 10 | * it under the terms of the GNU General Public License as published by 11 | * the Free Software Foundation, either version 3 of the License, or 12 | * (at your option) any later version. 13 | * 14 | * This program is distributed in the hope that it will be useful, 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | * GNU General Public License for more details. 18 | * 19 | * You should have received a copy of the GNU General Public License 20 | * along with this program. If not, see . 21 | */ 22 | 23 | #include "tvoutprint.hpp" 24 | 25 | #if USETVOUT 26 | 27 | #include "ascii.hpp" 28 | 29 | #if TVOUT_DEBUG 30 | #include "seriallight.hpp" 31 | #endif 32 | 33 | TVoutPrint::TVoutPrint() 34 | { 35 | } 36 | 37 | void 38 | TVoutPrint::writeChar(uint8_t c) 39 | { 40 | TVoutEx::instance()->write(c); 41 | } 42 | 43 | uint8_t 44 | TVoutPrint::getCursorX() 45 | { 46 | return TVoutEx::instance()->getCursorX(); 47 | } 48 | 49 | void 50 | TVoutPrint::setCursorX(uint8_t x) 51 | { 52 | TVoutEx::instance()->setCursorX(x); 53 | } 54 | 55 | void 56 | TVoutPrint::setCursor(uint8_t x, uint8_t y) 57 | { 58 | TVoutEx::instance()->setCursorCharPosition(x, y); 59 | } 60 | 61 | void 62 | TVoutPrint::clear() 63 | { 64 | TVoutEx::instance()->clearScreen(); 65 | } 66 | 67 | #endif // USETVOUT 68 | -------------------------------------------------------------------------------- /terminal-basic/tvoutprint.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of Terminal-BASIC: a lightweight BASIC-like language 3 | * interpreter. 4 | * 5 | * Copyright (C) 2016-2018 Andrey V. Skvortsov 6 | * Copyright (C) 2019-2021 Terminal-BASIC team 7 | * 8 | * 9 | * This program is free software: you can redistribute it and/or modify 10 | * it under the terms of the GNU General Public License as published by 11 | * the Free Software Foundation, either version 3 of the License, or 12 | * (at your option) any later version. 13 | * 14 | * This program is distributed in the hope that it will be useful, 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | * GNU General Public License for more details. 18 | * 19 | * You should have received a copy of the GNU General Public License 20 | * along with this program. If not, see . 21 | */ 22 | 23 | #ifndef TVOUT_PRINT_HPP 24 | #define TVOUT_PRINT_HPP 25 | 26 | #include "basic.hpp" 27 | 28 | #if USETVOUT 29 | 30 | #include "TVoutEx.h" 31 | #include "vt100.hpp" 32 | 33 | /** 34 | * @brief TVoutEx print wrapper with vt100 capabilities 35 | */ 36 | class TVoutPrint : public VT100::Print 37 | { 38 | EXT_NOTCOPYABLE(TVoutPrint) 39 | public: 40 | /** 41 | * @brief default constructor 42 | * @param tv TVoutEx object instance to wrap 43 | */ 44 | explicit TVoutPrint(); 45 | 46 | ~TVoutPrint() = default; 47 | 48 | private: 49 | void writeLbracket(uint8_t); 50 | void writeFirstNum(uint8_t); 51 | void writeSecondNum(uint8_t); 52 | // VT100::Print interface 53 | public: 54 | void clear() override; 55 | protected: 56 | void writeChar(uint8_t) override; 57 | uint8_t getCursorX() override; 58 | void setCursorX(uint8_t) override; 59 | void setCursor(uint8_t, uint8_t) override; 60 | void addAttribute(VT100::TextAttr) override {}; 61 | void resetAttributes() override {}; 62 | }; 63 | 64 | #endif // USETVOUT 65 | 66 | #endif /* TVOUT_PRINT_HPP */ 67 | -------------------------------------------------------------------------------- /terminal-basic/types.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * ArduinoExt is a set of utility libraries for Arduino 3 | * 4 | * Copyright (C) 2016-2018 Andrey V. Skvortsov 5 | * Copyright (C) 2019,2021 Terminal-BASIC team 6 | * 7 | * 8 | * This program is free software: is free software: you can redistribute it and/or 9 | * modify it under the terms of the GNU Lesser General Public License 10 | * as published by the Free Software Foundation, either version 3 of 11 | * the License, or (at your option) any later version. 12 | 13 | * ArduinoExt library is distributed in the hope that it will be useful, 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | * GNU General Public License for more details. 17 | 18 | * You should have received a copy of the GNU Lesser General Public 19 | * License along with Posixcpp library. If not, see 20 | * . 21 | */ 22 | 23 | #ifndef TYPES_HPP 24 | #define TYPES_HPP 25 | 26 | #include 27 | 28 | template 29 | class type_factory 30 | { 31 | public: 32 | using unsigned_type = uint8_t; 33 | }; 34 | 35 | template <> 36 | class type_factory<2> 37 | { 38 | public: 39 | using unsigned_type = uint16_t; 40 | }; 41 | 42 | template <> 43 | class type_factory<4> 44 | { 45 | public: 46 | using unsigned_type = uint32_t; 47 | }; 48 | 49 | template <> 50 | class type_factory<8> 51 | { 52 | public: 53 | using unsigned_type = uint64_t; 54 | }; 55 | 56 | template 57 | class typespec 58 | { 59 | public: 60 | typedef void longer; 61 | typedef void shorter; 62 | 63 | static constexpr bool isinteger = false; 64 | static constexpr bool isreal = false; 65 | }; 66 | 67 | template <> 68 | class typespec 69 | { 70 | public: 71 | typedef double longer; 72 | typedef float shorter; 73 | 74 | static constexpr bool isinteger = false; 75 | static constexpr bool isreal = true; 76 | }; 77 | 78 | template <> 79 | class typespec 80 | { 81 | public: 82 | typedef long double longer; 83 | typedef float shorter; 84 | 85 | static constexpr bool isinteger = false; 86 | static constexpr bool isreal = true; 87 | }; 88 | 89 | template <> 90 | class typespec 91 | { 92 | public: 93 | typedef long longer; 94 | typedef short shorter; 95 | 96 | static constexpr bool isinteger = true; 97 | static constexpr bool isreal = false; 98 | }; 99 | 100 | template <> 101 | class typespec 102 | { 103 | public: 104 | typedef int longer; 105 | typedef signed char shorter; 106 | 107 | static constexpr bool isinteger = true; 108 | static constexpr bool isreal = false; 109 | }; 110 | 111 | #endif // TYPES_HPP 112 | -------------------------------------------------------------------------------- /terminal-basic/version.h: -------------------------------------------------------------------------------- 1 | #define VERSION "2.3-rc1-1403" 2 | -------------------------------------------------------------------------------- /terminal-basic/vt100.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * ArduinoExt is a set of utility libraries for Arduino 3 | * 4 | * Copyright (C) 2016-2018 Andrey V. Skvortsov 5 | * Copyright (C) 2019,2021 Terminal-BASIC team 6 | * 7 | * 8 | * This program is free software: is free software: you can redistribute it and/or 9 | * modify it under the terms of the GNU Lesser General Public License 10 | * as published by the Free Software Foundation, either version 3 of 11 | * the License, or (at your option) any later version. 12 | * 13 | * ArduinoExt library is distributed in the hope that it will be useful, 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | * GNU General Public License for more details. 17 | 18 | * You should have received a copy of the GNU Lesser General Public 19 | * License along with Posixcpp library. If not, see 20 | * . 21 | */ 22 | 23 | #include "vt100.hpp" 24 | 25 | #include "ascii.hpp" 26 | 27 | #include 28 | 29 | VT100::Print::Print() : 30 | _state(IDLE), _pZoneWidth(10) 31 | { 32 | } 33 | 34 | void 35 | VT100::Print::writeIdle(uint8_t c) 36 | { 37 | switch (c) { 38 | case uint8_t(ASCII::ESC) : 39 | // ESC symbol - begin ANSI sequance 40 | _state = ESCAPE; 41 | break; 42 | case uint8_t('\t') : { 43 | // TAB symbol, deal with print zones 44 | const uint8_t pZone = this->getCursorX() / this->_pZoneWidth; 45 | this->setCursorX((pZone+1)*this->_pZoneWidth); 46 | break; 47 | } 48 | default: 49 | // Simply write symbol 50 | this->writeChar(c); 51 | } 52 | } 53 | 54 | void 55 | VT100::Print::writeESC(uint8_t c) 56 | { 57 | _value = _value2 = 0; 58 | switch (c) { 59 | case uint8_t('[') : 60 | _state = LBRACKET; 61 | break; 62 | default: 63 | _state = IDLE; 64 | } 65 | } 66 | 67 | void 68 | VT100::Print::writeLbracket(uint8_t c) 69 | { 70 | switch (c) { 71 | case 'H': 72 | this->setCursor(0, 0); 73 | break; 74 | default: 75 | if (isdigit(c)) { 76 | _value = c-'0'; 77 | _state = FIRST_NUM; 78 | return; 79 | } 80 | break; 81 | } 82 | _state = IDLE; 83 | } 84 | 85 | void 86 | VT100::Print::writeFirstNum(uint8_t c) 87 | { 88 | switch (c) { 89 | case 'J': // \x1B2J clear screen 90 | if (_value == 2) 91 | this->clear(); 92 | break; 93 | case 'm': 94 | switch (_value) { 95 | case 0 : 96 | resetAttributes(); break; 97 | case 1 : 98 | addAttribute(BRIGHT); break; 99 | case 30 : 100 | addAttribute(C_BLACK); break; 101 | case 31 : 102 | addAttribute(C_RED); break; 103 | case 32 : 104 | addAttribute(C_GREEN); break; 105 | case 33 : 106 | addAttribute(C_YELLOW); break; 107 | case 34 : 108 | addAttribute(C_BLUE); break; 109 | case 35 : 110 | addAttribute(C_MAGENTA); break; 111 | case 36 : 112 | addAttribute(C_CYAN); break; 113 | case 37 : 114 | addAttribute(C_WHITE); break; 115 | } 116 | break; 117 | case 'C': { 118 | const auto x = this->getCursorX() + 1; 119 | this->setCursorX(_value + x); 120 | } break; 121 | case 'D': { 122 | const auto x = this->getCursorX(); 123 | if (_value > x) 124 | _value = x; 125 | this->setCursorX(x-_value); 126 | } break; 127 | case ';': 128 | _state = SECOND_NUM; 129 | _value2 = 0; 130 | return; 131 | default: 132 | if (isdigit(c)) { 133 | _value *= 10; 134 | _value += c-'0'; 135 | return; 136 | } 137 | } 138 | _state = IDLE; 139 | } 140 | 141 | void 142 | VT100::Print::writeSecondNum(uint8_t c) 143 | { 144 | switch (c) { 145 | case 'f': 146 | case 'H': 147 | this->setCursor(_value2-1, _value-1); 148 | _state = IDLE; 149 | break; 150 | default: 151 | if (isdigit(c)) { 152 | _value2 *= 10; 153 | _value2 += c-'0'; 154 | return; 155 | } 156 | } 157 | } 158 | 159 | size_t 160 | VT100::Print::write(uint8_t c) 161 | { 162 | switch (_state) { 163 | case IDLE: 164 | writeIdle(c); 165 | break; 166 | case ESCAPE: 167 | writeESC(c); 168 | break; 169 | case LBRACKET: 170 | writeLbracket(c); 171 | break; 172 | case FIRST_NUM: 173 | writeFirstNum(c); 174 | break; 175 | case SECOND_NUM: 176 | writeSecondNum(c); 177 | break; 178 | } 179 | return 1; 180 | } 181 | -------------------------------------------------------------------------------- /terminal-basic/vt100.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * ArduinoExt is a set of utility libraries for Arduino 3 | * 4 | * Copyright (C) 2016-2018 Andrey V. Skvortsov 5 | * Copyright (C) 2019,2021 Terminal-BASIC team 6 | * 7 | * 8 | * This program is free software: is free software: you can redistribute it and/or 9 | * modify it under the terms of the GNU Lesser General Public License 10 | * as published by the Free Software Foundation, either version 3 of 11 | * the License, or (at your option) any later version. 12 | * 13 | * ArduinoExt library is distributed in the hope that it will be useful, 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | * GNU General Public License for more details. 17 | * 18 | * You should have received a copy of the GNU Lesser General Public 19 | * License along with Posixcpp library. If not, see 20 | * . 21 | */ 22 | 23 | #ifndef VT100_HPP 24 | #define VT100_HPP 25 | 26 | #include 27 | #include 28 | 29 | #include "arduinoext.hpp" 30 | 31 | /** 32 | * @package VT100 33 | * @brief Package, implementing some ANSI terminal functions 34 | */ 35 | Package(VT100) 36 | { 37 | EXT_PACKAGE(VT100); 38 | public: 39 | // Terminal text attributes to use when printing 40 | enum TextAttr : uint8_t 41 | { 42 | NO_ATTR = 0x0, 43 | BRIGHT = 0x1, 44 | UNDERSCORE = 0x2, 45 | BLINK = 0x4, 46 | REVERSE = 0x8, 47 | C_WHITE = 0x00, 48 | C_BLACK = 0x10, 49 | C_RED = 0x20, 50 | C_GREEN = 0x30, 51 | C_YELLOW = 0x40, 52 | C_BLUE = 0x50, 53 | C_MAGENTA = 0x60, 54 | C_CYAN = 0x70, 55 | CB_BLACK = 0x80, 56 | CB_RED = 0x90, 57 | CB_GREEN = 0xA0, 58 | CB_YELLOW = 0xB0, 59 | CB_BLUE = 0xC0, 60 | CB_MAGENTA = 0xD0, 61 | CB_CYAN = 0xE0, 62 | CB_WHITE = 0xF0, 63 | }; 64 | 65 | /** 66 | * Colors used by the terminal 67 | */ 68 | enum Color : uint8_t 69 | { 70 | COLOR_BLACK = 0, 71 | COLOR_RED, 72 | COLOR_GREEN, 73 | COLOR_YELLOW, 74 | COLOR_BLUE, 75 | COLOR_MAGENTA, 76 | COLOR_CYAN, 77 | COLOR_WHITE, 78 | NUM_COLORS 79 | }; 80 | 81 | /** 82 | * @brief Print print wrapper with vt100 capabilities 83 | */ 84 | class Print : public ::Print 85 | { 86 | EXT_NOTCOPYABLE(Print) 87 | public: 88 | 89 | virtual ~Print() = default; 90 | 91 | virtual void clear() = 0; 92 | 93 | protected: 94 | /** 95 | * @brief escape codes parsing automata state set 96 | */ 97 | enum State_t : uint8_t 98 | { 99 | IDLE, // Initial state without escape sequances 100 | ESCAPE, // escape-char was read 101 | LBRACKET, // left bracket char was read 102 | FIRST_NUM, // reading first number code 103 | SECOND_NUM // reading second number code 104 | }; 105 | 106 | Print() ; 107 | 108 | virtual void writeChar(uint8_t) = 0; 109 | virtual uint8_t getCursorX() = 0; 110 | virtual void setCursorX(uint8_t) = 0; 111 | virtual void setCursor(uint8_t, uint8_t) = 0; 112 | virtual void addAttribute(TextAttr) = 0; 113 | virtual void resetAttributes() = 0; 114 | 115 | private: 116 | void writeIdle(uint8_t); 117 | void writeESC(uint8_t); 118 | void writeLbracket(uint8_t); 119 | void writeFirstNum(uint8_t); 120 | void writeSecondNum(uint8_t); 121 | // FSM state 122 | State_t _state; 123 | // Parsed values 124 | uint16_t _value, _value2; 125 | // Print zone width 126 | uint8_t _pZoneWidth; 127 | // Print interface 128 | public: 129 | size_t write(uint8_t) override; 130 | }; 131 | }; 132 | 133 | inline VT100::TextAttr& operator |= (VT100::TextAttr& left, VT100::TextAttr right) 134 | { 135 | reinterpret_cast(left) |= uint8_t(right); 136 | return left; 137 | } 138 | 139 | inline VT100::TextAttr& operator &= (VT100::TextAttr& left, VT100::TextAttr right) 140 | { 141 | reinterpret_cast(left) &= uint8_t(right); 142 | return left; 143 | } 144 | 145 | #endif // VT100_HPP 146 | 147 | --------------------------------------------------------------------------------