├── .gitignore ├── .hgignore ├── BASIC ├── .dep.inc ├── Makefile ├── build-Arduino_DUE ├── build-Arduino_UNO ├── build-Arduino_mega2560 ├── build-Arduino_mega2560_mainframe ├── build-Arduino_mega2560_tvout ├── build-Arduino_nano168 ├── build-Arduino_nano168p ├── build-Arduino_nano328 ├── build-Atmega1284 ├── build-Atmega_128a ├── build-Debug ├── build-Release ├── docs │ ├── UML.dia │ ├── UML.png │ ├── UM_F1.dia │ ├── UM_F1.png │ ├── developer_manual.fodt │ ├── manual_ru.fodt │ └── user_manual.fodt ├── include │ ├── HALProxyStream.hpp │ ├── HAL_arduino.h │ ├── HAL_arduino_gfx.hpp │ ├── HAL_avr8.h │ ├── HAL_esp32.h │ ├── HAL_pc.h │ ├── HAL_sdl.h │ ├── _HAL_arduino.h │ ├── _HAL_pc.h │ ├── basic.hpp │ ├── basic_arduinoio.hpp │ ├── basic_config.hpp │ ├── basic_dataparser.hpp │ ├── basic_exteeprom.hpp │ ├── basic_extmemfs.hpp │ ├── basic_functionblock.hpp │ ├── basic_gfx.hpp │ ├── basic_internalfuncs.hpp │ ├── basic_interpreter.hpp │ ├── basic_lexer.hpp │ ├── basic_math.hpp │ ├── basic_parser.hpp │ ├── basic_parser_value.hpp │ ├── basic_program.hpp │ ├── basic_task.hpp │ ├── config_arduino.hpp │ ├── config_linux.hpp │ ├── tests │ │ └── tabtest.cpp │ ├── tvoutprint.hpp │ └── version.h ├── nbproject │ ├── configurations.xml │ ├── launcher.properties │ ├── project.properties │ └── project.xml ├── src │ ├── HALProxyStream.cpp │ ├── HAL_arduino.cpp │ ├── HAL_arduino_gfx.cpp │ ├── HAL_avr8.cpp │ ├── HAL_esp32.cpp │ ├── HAL_esp32_odroidgo.cpp │ ├── HAL_esp8266.cpp │ ├── HAL_mingw32.c │ ├── HAL_pc.c │ ├── HAL_posix.c │ ├── HAL_sam.cpp │ ├── HAL_sdl.c │ ├── basic_arduinoio.cpp │ ├── basic_dataparser.cpp │ ├── basic_exteeprom.cpp │ ├── basic_extmemfs.cpp │ ├── basic_functionblock.cpp │ ├── basic_gfx.cpp │ ├── basic_internalfuncs.cpp │ ├── basic_interpreter_matrix.cpp │ ├── basic_interpreterw.cpp │ ├── basic_lexerw.cpp │ ├── basic_math.cpp │ ├── basic_parser_value.cpp │ ├── basic_parserw.cpp │ ├── basic_program.cpp │ ├── basic_task.cpp │ ├── strings_en.hpp │ ├── strings_fr.hpp │ ├── strings_ru.hpp │ ├── taskmain.cpp │ ├── tvoutprint.cpp │ └── ucbasic_main.cpp └── tests │ └── TableTest.cpp ├── COPYING ├── ChangeLog ├── Makefile.am ├── Makefile.am.terminal-basic ├── README.md ├── README.pc ├── README.sketch ├── configure.ac ├── libbasic ├── include │ ├── HAL.h │ ├── HAL_config.h │ ├── _basic_config.h │ ├── _tokens_en.h │ ├── _tokens_fr.h │ ├── _tokens_ru.h │ ├── basic.h │ ├── basic_config.h │ ├── basic_lexer.h │ ├── basic_parser.h │ ├── basic_value.h │ ├── terminal.h │ └── tools.h ├── libbasic_nb │ ├── Makefile │ └── nbproject │ │ ├── configurations.xml │ │ └── project.xml └── src │ ├── HAL.c │ ├── basic.c │ ├── basic_lexer.c │ ├── basic_lexer_en.c │ ├── basic_lexer_fr.c │ ├── basic_lexer_ru.c │ ├── basic_parser.c │ ├── basic_value.c │ ├── math │ ├── e_sqrtf.c │ ├── math.h │ └── math_private.h │ ├── test.c │ └── tools.c ├── make_autotools.sh ├── make_sketch.sh ├── path2300.png ├── pgmspace.h ├── qtcreator └── terminal-basic │ └── terminal-basic.pro └── terminal-basic.svg /.gitignore: -------------------------------------------------------------------------------- 1 | /BASIC/build/ 2 | /BASIC/dist/ 3 | /libbasic/libbasic_nb/build/ 4 | /libbasic/libbasic_nb/dist/ -------------------------------------------------------------------------------- /.hgignore: -------------------------------------------------------------------------------- 1 | syntax: glob 2 | *.o 3 | *.a 4 | *.so 5 | */private/* 6 | *.o.d 7 | *.hex 8 | *.bin 9 | */dist/* 10 | */build/* 11 | *.bash 12 | autotools/* 13 | sketch/* 14 | -------------------------------------------------------------------------------- /BASIC/.dep.inc: -------------------------------------------------------------------------------- 1 | # This code depends on make tool being used 2 | DEPFILES=$(wildcard $(addsuffix .d, ${OBJECTFILES} ${TESTOBJECTFILES})) 3 | ifneq (${DEPFILES},) 4 | include ${DEPFILES} 5 | endif 6 | -------------------------------------------------------------------------------- /BASIC/build-Arduino_DUE: -------------------------------------------------------------------------------- 1 | 10 2 | -------------------------------------------------------------------------------- /BASIC/build-Arduino_UNO: -------------------------------------------------------------------------------- 1 | 246 2 | -------------------------------------------------------------------------------- /BASIC/build-Arduino_mega2560: -------------------------------------------------------------------------------- 1 | 191 2 | -------------------------------------------------------------------------------- /BASIC/build-Arduino_mega2560_mainframe: -------------------------------------------------------------------------------- 1 | 2 2 | -------------------------------------------------------------------------------- /BASIC/build-Arduino_mega2560_tvout: -------------------------------------------------------------------------------- 1 | 49 2 | -------------------------------------------------------------------------------- /BASIC/build-Arduino_nano168: -------------------------------------------------------------------------------- 1 | 168 2 | -------------------------------------------------------------------------------- /BASIC/build-Arduino_nano168p: -------------------------------------------------------------------------------- 1 | 20 2 | -------------------------------------------------------------------------------- /BASIC/build-Arduino_nano328: -------------------------------------------------------------------------------- 1 | 59 2 | -------------------------------------------------------------------------------- /BASIC/build-Atmega1284: -------------------------------------------------------------------------------- 1 | 9 2 | -------------------------------------------------------------------------------- /BASIC/build-Atmega_128a: -------------------------------------------------------------------------------- 1 | 7 2 | -------------------------------------------------------------------------------- /BASIC/build-Debug: -------------------------------------------------------------------------------- 1 | 1388 2 | -------------------------------------------------------------------------------- /BASIC/build-Release: -------------------------------------------------------------------------------- 1 | 45 2 | -------------------------------------------------------------------------------- /BASIC/docs/UML.dia: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/terminal-basic-team/terminalbasic/04f4aab0d2c220c901c78fca4cfccc825996c080/BASIC/docs/UML.dia -------------------------------------------------------------------------------- /BASIC/docs/UML.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/terminal-basic-team/terminalbasic/04f4aab0d2c220c901c78fca4cfccc825996c080/BASIC/docs/UML.png -------------------------------------------------------------------------------- /BASIC/docs/UM_F1.dia: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/terminal-basic-team/terminalbasic/04f4aab0d2c220c901c78fca4cfccc825996c080/BASIC/docs/UM_F1.dia -------------------------------------------------------------------------------- /BASIC/docs/UM_F1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/terminal-basic-team/terminalbasic/04f4aab0d2c220c901c78fca4cfccc825996c080/BASIC/docs/UM_F1.png -------------------------------------------------------------------------------- /BASIC/include/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 | -------------------------------------------------------------------------------- /BASIC/include/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_ILI9341 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 | -------------------------------------------------------------------------------- /BASIC/include/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 | -------------------------------------------------------------------------------- /BASIC/include/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_NONE 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 1 59 | 60 | #endif /* HAL_ARDUINO_H */ 61 | -------------------------------------------------------------------------------- /BASIC/include/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 | -------------------------------------------------------------------------------- /BASIC/include/HAL_pc.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 PC terminal HAL implementation 25 | */ 26 | 27 | #ifndef HAL_PC_H 28 | #define HAL_PC_H 29 | 30 | #include "HAL_config.h" 31 | 32 | #if HAL_NVRAM 33 | #define HAL_PC_FILES_PATH "/terminal_basic_HAL/" 34 | #endif 35 | 36 | #if HAL_EXTMEM 37 | #define HAL_PC_EXTMEM_DIR_PATH "extmem/" 38 | #endif /* HAL_EXTMEM */ 39 | 40 | #endif /* HAL_LINUX_H */ 41 | -------------------------------------------------------------------------------- /BASIC/include/HAL_sdl.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 SDL2 HAL implementation 25 | */ 26 | 27 | #ifndef HAL_SDL_H 28 | #define HAL_SDL_H 29 | 30 | #include "HAL.h" 31 | #include 32 | 33 | __BEGIN_DECLS 34 | 35 | #if HAL_GFX 36 | 37 | /* 38 | * SDL2 HAL_GFX implementation 39 | */ 40 | #define HAL_SDL_GFX 1 41 | 42 | #if HAL_SDL_GFX 43 | 44 | #include 45 | 46 | extern SDL_Renderer* hal_sdl_renderer; 47 | 48 | /** 49 | * Width of the SDL window 50 | */ 51 | #define HAL_SDL_WIDTH 640 52 | /** 53 | * Height of the SDL window 54 | */ 55 | #define HAL_SDL_HEIGHT 480 56 | 57 | #endif /* HAL_SDL_GFX */ 58 | 59 | #endif /* HAL_GFX */ 60 | 61 | __END_DECLS 62 | 63 | #endif /* HAL_SDL_H */ 64 | -------------------------------------------------------------------------------- /BASIC/include/_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 | -------------------------------------------------------------------------------- /BASIC/include/_HAL_pc.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 _HAL_pc.h 25 | * @brief private header of HAL PC implementations (POSIX/Win32) 26 | */ 27 | 28 | #ifndef _HAL_PC_H 29 | #define _HAL_PC_H 30 | 31 | #include "HAL.h" 32 | 33 | #if HAL_NVRAM 34 | extern int nvram_file; 35 | #endif 36 | 37 | #if HAL_EXTMEM 38 | extern int extmem_files[HAL_EXTMEM_NUM_FILES]; 39 | 40 | extern char ext_root[256]; 41 | #endif /* HAL_EXTMEM */ 42 | 43 | #endif /* _HAL_PC_H */ 44 | -------------------------------------------------------------------------------- /BASIC/include/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 | -------------------------------------------------------------------------------- /BASIC/include/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 | -------------------------------------------------------------------------------- /BASIC/include/basic_exteeprom.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_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 | -------------------------------------------------------------------------------- /BASIC/include/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 | -------------------------------------------------------------------------------- /BASIC/include/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 | -------------------------------------------------------------------------------- /BASIC/include/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 | -------------------------------------------------------------------------------- /BASIC/include/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 | -------------------------------------------------------------------------------- /BASIC/include/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 | -------------------------------------------------------------------------------- /BASIC/include/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 | -------------------------------------------------------------------------------- /BASIC/include/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 | -------------------------------------------------------------------------------- /BASIC/include/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 | -------------------------------------------------------------------------------- /BASIC/include/basic_task.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_TASK_HPP 24 | #define BASIC_TASK_HPP 25 | 26 | #include "basic.hpp" 27 | 28 | #if CONF_USE_EXTMEMFS 29 | #include "basic_extmemfs.hpp" 30 | #endif 31 | 32 | #if USEMATH 33 | #include "basic_math.hpp" 34 | #endif 35 | 36 | #if CONF_MODULE_ARDUINOIO 37 | #include "basic_arduinoio.hpp" 38 | #endif 39 | 40 | #if USE_GFX 41 | #include "basic_gfx.hpp" 42 | #endif 43 | 44 | #include "basic_interpreter.hpp" 45 | #include "HALProxyStream.hpp" 46 | 47 | class Task 48 | { 49 | protected: 50 | 51 | Task() = default; 52 | 53 | public: 54 | 55 | virtual void init() = 0; 56 | virtual void step() = 0; 57 | }; 58 | 59 | namespace BASIC 60 | { 61 | 62 | /** 63 | * @brief Terminal-BASIC task 64 | */ 65 | class Task : public ::Task 66 | { 67 | public: 68 | 69 | explicit Task(const char*); 70 | 71 | void init() override; 72 | 73 | void step() override; 74 | 75 | private: 76 | 77 | BASIC::HALProxyStream m_halproxyStream; 78 | 79 | #if CONF_MODULE_ARDUINOIO 80 | ArduinoIO m_arduinoio; 81 | #endif 82 | 83 | #if USEMATH 84 | Math m_math; 85 | #endif 86 | 87 | #if USE_GFX 88 | GFXModule m_gfx; 89 | #endif 90 | 91 | #if CONF_USE_EXTMEMFS 92 | ExtmemFSModule m_sdfs; 93 | #endif 94 | 95 | // Interpreter object 96 | Interpreter m_interpreter; 97 | }; 98 | 99 | } // namespace BASIC 100 | 101 | #endif // BASIC_TASK_HPP 102 | -------------------------------------------------------------------------------- /BASIC/include/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 | -------------------------------------------------------------------------------- /BASIC/include/config_linux.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 CONFIG_LINUX_HPP 24 | #define CONFIG_LINUX_HPP 25 | 26 | #include "Arduino.h" 27 | #include "basic_config.hpp" 28 | #include "basic.h" 29 | 30 | #if BASIC_MULTITERMINAL 31 | #define NUM_TERMINALS 1 32 | #ifdef HAVE_HWSERIAL1 33 | #define SERIAL_PORT1 Serial1 34 | #undef NUM_TERMINALS 35 | #define NUM_TERMINALS 2 36 | #endif 37 | #ifdef HAVE_HWSERIAL2 38 | #define SERIAL_PORT2 Serial2 39 | #undef NUM_TERMINALS 40 | #define NUM_TERMINALS 3 41 | #endif 42 | #ifdef HAVE_HWSERIAL3 43 | #define SERIAL_PORT3 Serial3 44 | #undef NUM_TERMINALS 45 | #define NUM_TERMINALS 4 46 | #endif 47 | #endif // BASIC_MULTITERMINAL 48 | 49 | namespace BASIC 50 | { 51 | 52 | // Number of bytes for program text, variables and stack 53 | const pointer_t PROGRAMSIZE = 128000; 54 | 55 | #if BASIC_MULTITERMINAL 56 | const pointer_t SINGLE_PROGSIZE = PROGRAMSIZE / NUM_TERMINALS; 57 | #else 58 | const pointer_t SINGLE_PROGSIZE = PROGRAMSIZE; 59 | #endif 60 | 61 | } // namespace BASIC 62 | 63 | // BEGIN PRIVATE 64 | 65 | #define USEUTFT 0 66 | #define USETVOUT 0 67 | #define USEPS2USARTKB 0 68 | 69 | // END PRIVATE 70 | 71 | #endif // CONFIG_LINUX_HPP 72 | -------------------------------------------------------------------------------- /BASIC/include/tests/tabtest.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Разработчик: Закрытое акционерное общество "Научно исследовательский 3 | * институт "Центрпрограммсистем", г. Тверь (ЗАО НИИ ЦПС) 4 | * 5 | * Интеллектуальная собственность ЗАО НИИ ЦПС 6 | */ 7 | 8 | /* 9 | * File: tabtest.cpp 10 | * Author: starling13 11 | * 12 | * Created on 17 марта 2017 г., 19:07 13 | */ 14 | 15 | #include 16 | #include 17 | 18 | /* 19 | * Simple C++ Test Suite 20 | */ 21 | 22 | #include "basic.hpp" 23 | 24 | static const uint8_t tab1[] = { 25 | 'P', 'A', 'R', 'S', 'E'+0x80, // 0 26 | 'T', 'E', 'S', 'T', '2'+0x80, // 1 27 | 'T', 'E', 'S', 'T'+0x80, // 2 28 | 0 29 | }; 30 | 31 | void test1() 32 | { 33 | std::cout << "tabtest test 1" << std::endl; 34 | const char str[] = "TESTTEST2PARSE SYM"; 35 | 36 | uint8_t index; 37 | uint8_t *st = (uint8_t*)str; 38 | while (st = BASIC::scanTable(st, tab1, index)) { 39 | std::cout << "Token " << int(index) << std::endl; 40 | } 41 | } 42 | 43 | void test2() 44 | { 45 | std::cout << "tabtest test 2" << std::endl; 46 | //std::cout << "%TEST_FAILED% time=0 testname=test2 (tabtest) message=error message sample" << std::endl; 47 | } 48 | 49 | int main(int argc, char** argv) 50 | { 51 | std::cout << "%SUITE_STARTING% tabtest" << std::endl; 52 | std::cout << "%SUITE_STARTED%" << std::endl; 53 | 54 | std::cout << "%TEST_STARTED% test1 (tabtest)" << std::endl; 55 | test1(); 56 | std::cout << "%TEST_FINISHED% time=0 test1 (tabtest)" << std::endl; 57 | 58 | std::cout << "%TEST_STARTED% test2 (tabtest)\n" << std::endl; 59 | test2(); 60 | std::cout << "%TEST_FINISHED% time=0 test2 (tabtest)" << std::endl; 61 | 62 | std::cout << "%SUITE_FINISHED% time=0" << std::endl; 63 | 64 | return (EXIT_SUCCESS); 65 | } 66 | 67 | -------------------------------------------------------------------------------- /BASIC/include/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 | -------------------------------------------------------------------------------- /BASIC/include/version.h: -------------------------------------------------------------------------------- 1 | #define VERSION "2.3-b3-190" 2 | -------------------------------------------------------------------------------- /BASIC/nbproject/launcher.properties: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/terminal-basic-team/terminalbasic/04f4aab0d2c220c901c78fca4cfccc825996c080/BASIC/nbproject/launcher.properties -------------------------------------------------------------------------------- /BASIC/nbproject/project.properties: -------------------------------------------------------------------------------- 1 | #Mon Nov 21 14:06:20 MSK 2016 2 | -------------------------------------------------------------------------------- /BASIC/nbproject/project.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | org.netbeans.modules.cnd.makeproject 4 | 5 | 6 | BASIC 7 | c 8 | cpp 9 | h,hpp 10 | IBM866 11 | 12 | ../../libarduinoemulator 13 | ../../libps2uart/libps2uart 14 | ../../libtvoutex/netbenas 15 | ../libarduino 16 | ../arduinoext 17 | ../../libarduinoext 18 | ../libbasic/libbasic_nb 19 | ../../libarduino 20 | ../../libarduinodue 21 | ../../libsdcard/libsdcard 22 | 23 | 24 | include 25 | src 26 | ../TVoutEx 27 | include 28 | src 29 | ../TVoutEx 30 | include 31 | src 32 | ../TVoutEx 33 | 34 | 35 | 36 | Debug 37 | 1 38 | 39 | 40 | Debug_SDL 41 | 1 42 | 43 | 44 | Arduino_nano328 45 | 1 46 | 47 | 48 | Arduino_UNO 49 | 1 50 | 51 | 52 | Arduino_mega2560 53 | 1 54 | 55 | 56 | Atmega_128a 57 | 1 58 | 59 | 60 | Release 61 | 1 62 | 63 | 64 | Arduino_mega2560_mainframe 65 | 1 66 | 67 | 68 | Arduino_nano168 69 | 1 70 | 71 | 72 | Atmega1284 73 | 1 74 | 75 | 76 | Arduino_mega2560_tvout 77 | 1 78 | 79 | 80 | Arduino_pro328 81 | 1 82 | 83 | 84 | Arduino_nano168p 85 | 1 86 | 87 | 88 | Arduino_DUE 89 | 1 90 | 91 | 92 | 93 | true 94 | OpenSolaris_1|OpenBSD 95 | OpenSolaris_1|OpenBSD 96 | OpenSolaris_2|OpenBSD 97 | 98 | 99 | 100 | 101 | -------------------------------------------------------------------------------- /BASIC/src/HALProxyStream.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 "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 | -------------------------------------------------------------------------------- /BASIC/src/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 | -------------------------------------------------------------------------------- /BASIC/src/HAL_pc.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 | /** 24 | * @file HAL_pc.cpp 25 | * @brief Common part of POSIX/Linux terminal I/O HAL implementation 26 | */ 27 | 28 | #ifdef HAL_PC_TERMINAL 29 | 30 | #include 31 | 32 | #include 33 | 34 | #include 35 | #include 36 | #include 37 | #include 38 | #include 39 | 40 | #include "_HAL_pc.h" 41 | #include "HAL_pc.h" 42 | 43 | #if HAL_NVRAM 44 | int nvram_file = -1; 45 | #endif 46 | 47 | #if HAL_EXTMEM 48 | int extmem_files[HAL_EXTMEM_NUM_FILES]; 49 | char ext_root[256]; 50 | #endif /* HAL_EXTMEM */ 51 | 52 | void 53 | HAL_update() 54 | { 55 | } 56 | 57 | #if HAL_EXTMEM 58 | 59 | HAL_extmem_file_t 60 | HAL_extmem_openfile(const char str[13]) 61 | { 62 | char fpath[256]; 63 | strncpy(fpath, ext_root, 255); 64 | strncat(fpath, str, 255); 65 | 66 | int fp = open(fpath, O_CREAT|O_RDWR, S_IRUSR|S_IWUSR); 67 | if (fp == -1) { 68 | perror("open"); 69 | return 0; 70 | } 71 | 72 | for (size_t i=0; i HAL_EXTMEM_NUM_FILES) 97 | || (extmem_files[file-1] == -1)) 98 | return; 99 | 100 | if (close(extmem_files[file-1]) != 0) { 101 | perror("close"); 102 | exit(EXIT_FAILURE); 103 | } 104 | extmem_files[file-1] = -1; 105 | } 106 | 107 | off_t 108 | _seek(HAL_extmem_file_t file, off_t pos, int whence) 109 | { 110 | if ((file == 0) 111 | || (file > HAL_EXTMEM_NUM_FILES) 112 | || (extmem_files[file-1] == -1)) 113 | return 0; 114 | 115 | off_t res = lseek(extmem_files[file-1], pos, whence); 116 | if (res == -1) 117 | perror("lseek"); 118 | 119 | return res; 120 | } 121 | 122 | HAL_extmem_fileposition_t 123 | HAL_extmem_getfileposition(HAL_extmem_file_t file) 124 | { 125 | return _seek(file, 0, SEEK_CUR); 126 | } 127 | 128 | void 129 | HAL_extmem_setfileposition(HAL_extmem_file_t file, 130 | HAL_extmem_fileposition_t pos) 131 | { 132 | _seek(file, pos, SEEK_SET); 133 | } 134 | 135 | HAL_extmem_fileposition_t 136 | HAL_extmem_getfilesize(HAL_extmem_file_t file) 137 | { 138 | off_t current = _seek(file, 0, SEEK_CUR); 139 | off_t result = _seek(file, 0, SEEK_END); 140 | _seek(file, current, SEEK_SET); 141 | 142 | return result; 143 | } 144 | 145 | uint8_t 146 | HAL_extmem_readfromfile(HAL_extmem_file_t file) 147 | { 148 | if ((file == 0) 149 | || (file > HAL_EXTMEM_NUM_FILES) 150 | || (extmem_files[file-1] == -1)) 151 | return 0; 152 | 153 | char result = '\0'; 154 | if (read(extmem_files[file-1], &result, 1) != 1) 155 | fputs("HAL error \"read\": Can't read from file", stderr); 156 | 157 | return result; 158 | } 159 | 160 | void 161 | HAL_extmem_writetofile(HAL_extmem_file_t file, uint8_t byte) 162 | { 163 | if ((file == 0) 164 | || (file > HAL_EXTMEM_NUM_FILES) 165 | || (extmem_files[file-1] == -1)) 166 | return; 167 | 168 | if (write(extmem_files[file-1], &byte, 1) != 1) 169 | fputs("HAL error \"write\": Can't write to file", stderr); 170 | } 171 | 172 | BOOLEAN 173 | HAL_extmem_fileExists(const char fname[13]) 174 | { 175 | char fpath[256]; 176 | strncpy(fpath, ext_root, 255); 177 | strncat(fpath, fname, 255); 178 | 179 | if (access(fpath, F_OK) == 0) 180 | return TRUE; 181 | return FALSE; 182 | } 183 | 184 | #endif /* HAL_EXTMEM */ 185 | 186 | uint32_t 187 | HAL_time_gettime_ms() 188 | { 189 | struct timespec ts; 190 | if (clock_gettime(CLOCK_MONOTONIC, &ts) != 0) { 191 | perror("clock_gettime"); 192 | exit(EXIT_FAILURE); 193 | } 194 | 195 | return ts.tv_sec * 1000l + ts.tv_nsec / 1000000l; 196 | } 197 | 198 | #endif /* HAL_PC_TERMINAL */ 199 | -------------------------------------------------------------------------------- /BASIC/src/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 | -------------------------------------------------------------------------------- /BASIC/src/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 | -------------------------------------------------------------------------------- /BASIC/src/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 | -------------------------------------------------------------------------------- /BASIC/src/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 | #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 | -------------------------------------------------------------------------------- /BASIC/src/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 | -------------------------------------------------------------------------------- /BASIC/src/basic_task.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_task.hpp" 24 | 25 | namespace BASIC 26 | { 27 | 28 | Task::Task(const char*) : 29 | m_halproxyStream(0), 30 | m_interpreter(m_halproxyStream, m_halproxyStream, BASIC::SINGLE_PROGSIZE) 31 | { 32 | 33 | #if CONF_MODULE_ARDUINOIO 34 | m_interpreter.addModule(&m_arduinoio); 35 | #endif 36 | 37 | #if USE_GFX 38 | m_interpreter.addModule(&m_gfx); 39 | #endif 40 | 41 | #if USEMATH 42 | m_interpreter.addModule(&m_math); 43 | #endif 44 | 45 | #if CONF_USE_EXTMEMFS 46 | m_interpreter.setSDFSModule(&m_sdfs); 47 | m_interpreter.addModule(&m_sdfs); 48 | #endif 49 | } 50 | 51 | void 52 | Task::init() 53 | { 54 | m_interpreter.init(); 55 | } 56 | 57 | void 58 | Task::step() 59 | { 60 | m_interpreter.step(); 61 | } 62 | 63 | } // namespace BASIC 64 | -------------------------------------------------------------------------------- /BASIC/src/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 | -------------------------------------------------------------------------------- /BASIC/src/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 | -------------------------------------------------------------------------------- /BASIC/src/strings_ru.hpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/terminal-basic-team/terminalbasic/04f4aab0d2c220c901c78fca4cfccc825996c080/BASIC/src/strings_ru.hpp -------------------------------------------------------------------------------- /BASIC/src/taskmain.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 24 | #include 25 | 26 | #include "basic_config.hpp" 27 | #include "basic.hpp" 28 | #include "basic_task.hpp" 29 | 30 | static Task* activeTask; 31 | 32 | void 33 | setup() 34 | { 35 | HAL_initialize(); 36 | activeTask->init(); 37 | } 38 | 39 | void 40 | loop() 41 | { 42 | HAL_update(); 43 | activeTask->step(); 44 | } 45 | 46 | 47 | static BOOLEAN exitflag = FALSE; 48 | 49 | static void 50 | sighandler(int signum) 51 | { 52 | exitflag = TRUE; 53 | } 54 | 55 | int 56 | main(int argc, char **argv) 57 | { 58 | signal(SIGINT, &sighandler); 59 | srand(time(NULL)); 60 | 61 | const char *filePath = argc > 1 ? argv[1] : nullptr; 62 | activeTask = new BASIC::Task(filePath); 63 | 64 | setup(); 65 | while (!exitflag) 66 | loop(); 67 | 68 | return EXIT_SUCCESS; 69 | } 70 | -------------------------------------------------------------------------------- /BASIC/src/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 | -------------------------------------------------------------------------------- /BASIC/tests/TableTest.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | #include "basic_lexer.hpp" 5 | 6 | /* 7 | * Simple C++ Test Suite 8 | */ 9 | 10 | void test1() 11 | { 12 | std::cout << "TableTest test 1" << std::endl; 13 | BASIC::Lexer lex; 14 | uint8_t buf[16]; 15 | 16 | const uint8_t *c = lex.getTokenString(BASIC::Token::OP_AND, buf); 17 | std::cout << c << std::endl; 18 | 19 | c = lex.getTokenString(BASIC::Token::OP_NOT, buf); 20 | std::cout << c << std::endl; 21 | 22 | c = lex.getTokenString(BASIC::Token::OP_OR, buf); 23 | std::cout << c << std::endl; 24 | 25 | return; 26 | } 27 | 28 | void test2() 29 | { 30 | std::cout << "TableTest test 2" << std::endl; 31 | //std::cout << "%TEST_FAILED% time=0 testname=test2 (TableTest) message=error message sample" << std::endl; 32 | } 33 | 34 | int main(int argc, char** argv) 35 | { 36 | std::cout << "%SUITE_STARTING% TableTest" << std::endl; 37 | std::cout << "%SUITE_STARTED%" << std::endl; 38 | 39 | std::cout << "%TEST_STARTED% test1 (TableTest)" << std::endl; 40 | test1(); 41 | std::cout << "%TEST_FINISHED% time=0 test1 (TableTest)" << std::endl; 42 | 43 | std::cout << "%TEST_STARTED% test2 (TableTest)\n" << std::endl; 44 | test2(); 45 | std::cout << "%TEST_FINISHED% time=0 test2 (TableTest)" << std::endl; 46 | 47 | std::cout << "%SUITE_FINISHED% time=0" << std::endl; 48 | 49 | return (EXIT_SUCCESS); 50 | } 51 | 52 | -------------------------------------------------------------------------------- /Makefile.am: -------------------------------------------------------------------------------- 1 | AUTOMAKE_OPTIONS = foreign 2 | 3 | # 4 | # Subdirectories in which more makefiles can be found 5 | # 6 | SUBDIRS = terminalbasic 7 | 8 | # 9 | # List of data files in this directory that should be included with a tkgate distribution. 10 | # 11 | #dist_pkgdata_DATA = site-preferences 12 | 13 | # 14 | # List of common documentation files 15 | # 16 | dist_doc_DATA = README COPYING ChangeLog 17 | -------------------------------------------------------------------------------- /Makefile.am.terminal-basic: -------------------------------------------------------------------------------- 1 | AM_CXXFLAGS= -fno-rtti -Wall 2 | 3 | bin_PROGRAMS=terminalbasic 4 | terminalbasic_SOURCES=arduinoext.hpp \ 5 | Arduino.h \ 6 | Printable.h \ 7 | Print.h \ 8 | tools.h \ 9 | tools.c \ 10 | emuserial.hpp \ 11 | arduino_logger.hpp \ 12 | ascii.hpp \ 13 | basic.h \ 14 | basic.hpp \ 15 | basic.c \ 16 | HAL.c \ 17 | HAL_pc.h \ 18 | _HAL_pc.h \ 19 | HAL_pc.c \ 20 | HAL_posix.c \ 21 | HAL_mingw32.c \ 22 | HALProxyStream.cpp \ 23 | HALProxyStream.hpp \ 24 | basic_functionblock.cpp \ 25 | basic_functionblock.hpp \ 26 | basic_gfx.cpp \ 27 | basic_gfx.hpp \ 28 | basic_gfx_serial.cpp \ 29 | basic_internalfuncs.cpp \ 30 | basic_internalfuncs.hpp \ 31 | basic_interpreterw.cpp \ 32 | basic_interpreter_matrix.cpp \ 33 | basic_interpreter.hpp \ 34 | basic_lexer_ru.c \ 35 | basic_lexer_fr.c \ 36 | basic_lexer_en.c \ 37 | basic_lexer.c \ 38 | basic_lexer.h \ 39 | basic_lexerw.cpp \ 40 | basic_lexer.hpp \ 41 | basic_math.cpp \ 42 | basic_math.hpp \ 43 | basic_parserw.cpp \ 44 | basic_parser.hpp \ 45 | basic_parser_value.cpp \ 46 | basic_parser_value.hpp \ 47 | basic_program.cpp \ 48 | basic_program.hpp \ 49 | basic_extmemfs.cpp \ 50 | basic_extmemfs.hpp \ 51 | basic_dataparser.cpp \ 52 | basic_dataparser.hpp \ 53 | basic_value.h \ 54 | basic_value.c \ 55 | basic_parser.h \ 56 | basic_parser.c \ 57 | basic_task.hpp \ 58 | basic_task.cpp \ 59 | strings_en.hpp \ 60 | strings_fr.hpp \ 61 | strings_ru.hpp \ 62 | bytearray.cpp \ 63 | bytearray.hpp \ 64 | basic_config.h \ 65 | _basic_config.h \ 66 | basic_config.hpp \ 67 | config_linux.hpp \ 68 | HAL.h \ 69 | HAL_config.h \ 70 | helper.hpp \ 71 | math.hpp \ 72 | matrix.hpp \ 73 | taskmain.cpp \ 74 | types.hpp \ 75 | Stream.cpp \ 76 | Print.cpp \ 77 | arduino.cpp \ 78 | EEPROM.h \ 79 | version.h \ 80 | Stream.h \ 81 | vt100.hpp \ 82 | vt100.cpp \ 83 | _tokens_en.h \ 84 | _tokens_ru.h \ 85 | avr/interrupt.h \ 86 | avr/io.h \ 87 | avr/pgmspace.h \ 88 | avr/sfr_defs.h \ 89 | util/crc16.h 90 | 91 | terminalbasic_CXXFLAGS=-I../ -Iutility -std=gnu++11 -DHAL_PC_TERMINAL 92 | 93 | terminalbasic_CFLAGS=-I../ -Iutility -std=gnu11 -DHAL_PC_TERMINAL 94 | 95 | terminalbasic_LDADD=${sdl2_LIBS} -lpthread 96 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | [![License GPLv3](https://img.shields.io/badge/license-GPL_v3-green.svg)](http://www.gnu.org/licenses/gpl-3.0.html) 2 | [![Download Terminal-BASIC](https://img.shields.io/sourceforge/dt/terminal-basic.svg)](https://sourceforge.net/projects/terminal-basic/files/latest/download) 3 | 4 | # Terminal-BASIC ![TB](https://a.fsdn.com/allura/p/terminal-basic/icon?1550272878) 5 | 6 | Terminal-BASIC (**TB**) is a lightweight BASIC-like language interpreter. Written in C++11 it is cross-platform, although 7 | it was designed for small uC-based systems like Arduino with at least 32kb of program memory. 8 | TB supports classic BASIC dialect (non-structured) with line numbering and interactive line editor. 9 | It was inspired by the [TinyBASIC port](https://github.com/BleuLlama/TinyBasicPlus) for Arduino-compatible uc systems and 10 | [Darthmouth BASIC](https://en.wikipedia.org/wiki/Dartmouth_BASIC) - the first one. 11 | 12 | Resulting interpreter is partially compliant to the standards ISO/IEC 6373:1984 and USSR/Russian ГОСТ 27787-88 and 13 | supports some non-standard features, allowing to use many type-in utilities and games from old BASIC books and magazines. 14 | 15 | Some features of the TB interpreter: 16 | 17 | - supports number of datatypes (integer (2 bytes signed), long integer (4 bytes signed), real (4 bytes binary floating point), 18 | long real (8 bytes binary floating point), boolean and string) using variables and function suffixes; 19 | - multidimensional arrays of arbitrary size and dimensions; 20 | - Darthmouth-BASIC-like matrix operations; 21 | - optional time-sharing system mode with round-robin scheduling using multiple I/O devices for each user (i.e. USART); 22 | - configuration headers provide the number of options, which enable inclusion of the language parts and features thus allowing 23 | to adjust the code size. 24 | 25 | Sources of the TB and supporting libraries are hosted at [bitbucket.org](https://bitbucket.org/terminalbasicteam/) 26 | with [Github mirrors](https://github.com/users/starling13/projects/1). There is a dedicated repository of TB sources in the form of arduino sketch: https://github.com/terminal-basic-team/terminalbasic-arduino. Main project page for downloads and support placed 27 | at [SourceForge](https://sourceforge.net/projects/terminal-basic/). Project blog with news and discussion is hosted at 28 | [hackaday.io](https://hackaday.io/project/22036-terminal-basic). 29 | 30 | There are manual documents, describing the process of ackuiring different versions of TB, configuration and setup questions, language syntax 31 | and developing extensions and TB itself. 32 | -------------------------------------------------------------------------------- /README.pc: -------------------------------------------------------------------------------- 1 | This distribution contains Terminal-BASIC pc emulator. It is very 2 | close to version for Arduino-MEGA 2560 with 32 kB SRAM expantion shield 3 | (https://hackaday.io/project/21561-arduino-mega-2560-32kb-ram-shield), 4 | SPI SD card module using SDCard Arduino library 5 | (https://starling13@bitbucket.org/starling13/libsdcard) and 6 | TVOutEx output (https://starling13@bitbucket.org/starling13/tvoutex). 7 | 8 | Main project sites are https://sourceforge.net/projects/terminal-basic/ 9 | and https://hackaday.io/project/22036-terminal-basic 10 | 11 | This version uses posixcpp library 12 | (https://starling13@bitbucket.org/starling13/posixcpp) and SDL2. 13 | 14 | After install and first run program creates ucbasic directory in users home 15 | eeprom.img file contains program, saved with "SAVE" command, while 16 | SD directory contains SD card emulator contents. 17 | 18 | You can place example programs in ~/ucbasic/SD and load them using 19 | "DLOAD "File name w/o extension" " command. 20 | 21 | A set of sources for test programs can be downloaded from 22 | https://cloud.mail.ru/public/45SG/gGc2kFpBk 23 | 24 | Thank you for trying Terminal-BASIC. 25 | -------------------------------------------------------------------------------- /README.sketch: -------------------------------------------------------------------------------- 1 | ./terminal-basic-... - directory, containing Arduino IDE project 2 | Other directories contain necessary Arduino libraries 3 | -------------------------------------------------------------------------------- /configure.ac: -------------------------------------------------------------------------------- 1 | AC_INIT([terminalbasic],[2.3-b2],[starling13mail.ru],[terminalbasic],[https://sourceforge.net/projects/terminal-basic]) 2 | AM_INIT_AUTOMAKE([foreign]) 3 | AC_PREREQ(2.57) 4 | AC_CONFIG_HEADER(config.h) 5 | AC_LANG(C++) 6 | 7 | ############################################################################# 8 | # 9 | # Default prefix directory for installation by OS 10 | # 11 | AC_PREFIX_DEFAULT(/usr/local) 12 | 13 | ############################################################################# 14 | # 15 | # Top and bottom of config.h 16 | # 17 | 18 | #------------------------------------------------------------------------ 19 | # Standard compiler checks 20 | #------------------------------------------------------------------------ 21 | 22 | # Checks for programs. 23 | AC_PROG_CC 24 | AC_PROG_CXX 25 | AC_PROG_MAKE_SET 26 | AC_PROG_RANLIB 27 | AC_PROG_CPP 28 | AC_PROG_INSTALL 29 | 30 | # Checks for header files. 31 | AC_PATH_XTRA 32 | AC_FUNC_ALLOCA 33 | AC_HEADER_STDC 34 | AC_HEADER_SYS_WAIT 35 | AC_CHECK_HEADERS([limits.h malloc.h stdlib.h string.h sys/param.h sys/time.h unistd.h stdint.h]) 36 | 37 | # Checks for typedefs, structures, and compiler characteristics. 38 | AC_C_CONST 39 | AC_TYPE_SIZE_T 40 | AC_TYPE_INTPTR_T 41 | AC_HEADER_TIME 42 | AC_STRUCT_TM 43 | AC_CHECK_TYPES(unsigned long long) 44 | #PKG_CHECK_MODULES(posixcpp, posixcpp) 45 | #PKG_CHECK_MODULES(sdl2, sdl2) 46 | 47 | ############################################################################# 48 | # 49 | # Check for word size and Endianess 50 | # 51 | AC_C_BIGENDIAN 52 | 53 | ############################################################################# 54 | # 55 | # Substitution variables 56 | # 57 | AC_CONFIG_FILES([Makefile terminalbasic/Makefile]) 58 | AC_OUTPUT 59 | -------------------------------------------------------------------------------- /libbasic/include/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 | 69 | #define HAL_GFX_COLOR HAL_GFX_COLOR_2BITPERC 70 | 71 | #endif /* HAL_GFX */ 72 | 73 | #define HAL_GPIO 1 74 | 75 | #define HAL_BUZZER 0 76 | 77 | #endif /* HAL_CONFIG_H */ 78 | -------------------------------------------------------------------------------- /libbasic/include/_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 | -------------------------------------------------------------------------------- /libbasic/include/_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 | -------------------------------------------------------------------------------- /libbasic/include/_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 | -------------------------------------------------------------------------------- /libbasic/include/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 | -------------------------------------------------------------------------------- /libbasic/include/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 1 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 operation 116 | */ 117 | #define USE_INTEGER_DIV 1 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 | -------------------------------------------------------------------------------- /libbasic/include/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 | -------------------------------------------------------------------------------- /libbasic/include/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 | -------------------------------------------------------------------------------- /libbasic/include/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 | -------------------------------------------------------------------------------- /libbasic/include/terminal.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 sgen_terminal.h 25 | * @brief Simple text terminal interface 26 | */ 27 | 28 | #ifndef TERMINAL_H 29 | #define TERMINAL_H 30 | 31 | #include 32 | 33 | #include 34 | 35 | __BEGIN_DECLS 36 | 37 | typedef uint16_t len_t; 38 | 39 | extern uint8_t terminal_rows; 40 | extern uint8_t terminal_cols; 41 | 42 | /** 43 | * Cursor movement direction 44 | */ 45 | typedef enum 46 | { 47 | DIRECTION_UP, 48 | DIRECTION_DOWN, 49 | DIRECTION_LEFT, 50 | DIRECTION_RIGHT 51 | } direction_t; 52 | 53 | /** 54 | * [Re]initialize terminal component 55 | */ 56 | void terminal_init(); 57 | /** 58 | * @brief Move cursor one position 59 | * @param direction 60 | */ 61 | void terminal_moveCursor(direction_t); 62 | /** 63 | * @brief get current cursor position 64 | * @param line out 65 | * @param column out 66 | */ 67 | void terminal_cursorPosition(uint8_t*, uint8_t*); 68 | 69 | char terminal_getc(); 70 | 71 | len_t terminal_putc(char); 72 | 73 | /** 74 | * Terminal update callback (cursor blinking, etc...) 75 | */ 76 | void terminal_update(); 77 | 78 | __END_DECLS 79 | 80 | #endif /* TERMINAL_H */ 81 | -------------------------------------------------------------------------------- /libbasic/include/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 | -------------------------------------------------------------------------------- /libbasic/libbasic_nb/Makefile: -------------------------------------------------------------------------------- 1 | # 2 | # There exist several targets which are by default empty and which can be 3 | # used for execution of your targets. These targets are usually executed 4 | # before and after some main targets. They are: 5 | # 6 | # .build-pre: called before 'build' target 7 | # .build-post: called after 'build' target 8 | # .clean-pre: called before 'clean' target 9 | # .clean-post: called after 'clean' target 10 | # .clobber-pre: called before 'clobber' target 11 | # .clobber-post: called after 'clobber' target 12 | # .all-pre: called before 'all' target 13 | # .all-post: called after 'all' target 14 | # .help-pre: called before 'help' target 15 | # .help-post: called after 'help' target 16 | # 17 | # Targets beginning with '.' are not intended to be called on their own. 18 | # 19 | # Main targets can be executed directly, and they are: 20 | # 21 | # build build a specific configuration 22 | # clean remove built files from a configuration 23 | # clobber remove all built files 24 | # all build all configurations 25 | # help print help mesage 26 | # 27 | # Targets .build-impl, .clean-impl, .clobber-impl, .all-impl, and 28 | # .help-impl are implemented in nbproject/makefile-impl.mk. 29 | # 30 | # Available make variables: 31 | # 32 | # CND_BASEDIR base directory for relative paths 33 | # CND_DISTDIR default top distribution directory (build artifacts) 34 | # CND_BUILDDIR default top build directory (object files, ...) 35 | # CONF name of current configuration 36 | # CND_PLATFORM_${CONF} platform name (current configuration) 37 | # CND_ARTIFACT_DIR_${CONF} directory of build artifact (current configuration) 38 | # CND_ARTIFACT_NAME_${CONF} name of build artifact (current configuration) 39 | # CND_ARTIFACT_PATH_${CONF} path to build artifact (current configuration) 40 | # CND_PACKAGE_DIR_${CONF} directory of package (current configuration) 41 | # CND_PACKAGE_NAME_${CONF} name of package (current configuration) 42 | # CND_PACKAGE_PATH_${CONF} path to package (current configuration) 43 | # 44 | # NOCDDL 45 | 46 | ARDUINO_PATH=/opt/arduino-1.8.13 47 | 48 | # Environment 49 | MKDIR=mkdir 50 | CP=cp 51 | CCADMIN=CCadmin 52 | 53 | 54 | # build 55 | build: .build-post 56 | 57 | .build-pre: 58 | # Add your pre 'build' code here... 59 | 60 | .build-post: .build-impl 61 | # Add your post 'build' code here... 62 | 63 | 64 | # clean 65 | clean: .clean-post 66 | 67 | .clean-pre: 68 | # Add your pre 'clean' code here... 69 | 70 | .clean-post: .clean-impl 71 | # Add your post 'clean' code here... 72 | 73 | 74 | # clobber 75 | clobber: .clobber-post 76 | 77 | .clobber-pre: 78 | # Add your pre 'clobber' code here... 79 | 80 | .clobber-post: .clobber-impl 81 | # Add your post 'clobber' code here... 82 | 83 | 84 | # all 85 | all: .all-post 86 | 87 | .all-pre: 88 | # Add your pre 'all' code here... 89 | 90 | .all-post: .all-impl 91 | # Add your post 'all' code here... 92 | 93 | 94 | # build tests 95 | build-tests: .build-tests-post 96 | 97 | .build-tests-pre: 98 | # Add your pre 'build-tests' code here... 99 | 100 | .build-tests-post: .build-tests-impl 101 | # Add your post 'build-tests' code here... 102 | 103 | 104 | # run tests 105 | test: .test-post 106 | 107 | .test-pre: build-tests 108 | # Add your pre 'test' code here... 109 | 110 | .test-post: .test-impl 111 | # Add your post 'test' code here... 112 | 113 | 114 | # help 115 | help: .help-post 116 | 117 | .help-pre: 118 | # Add your pre 'help' code here... 119 | 120 | .help-post: .help-impl 121 | # Add your post 'help' code here... 122 | 123 | 124 | 125 | # include project implementation makefile 126 | include nbproject/Makefile-impl.mk 127 | 128 | # include project make variables 129 | include nbproject/Makefile-variables.mk 130 | -------------------------------------------------------------------------------- /libbasic/libbasic_nb/nbproject/project.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | org.netbeans.modules.cnd.makeproject 4 | 5 | 6 | libbasic_nb 7 | c 8 | 9 | h 10 | IBM866 11 | 12 | 13 | ../include 14 | ../src 15 | 16 | 17 | 18 | Debug 19 | 3 20 | 21 | 22 | Release 23 | 3 24 | 25 | 26 | Test 27 | 1 28 | 29 | 30 | Arduino_UNO 31 | 3 32 | 33 | 34 | Arduino_MEGA 35 | 3 36 | 37 | 38 | Arduino_nano168 39 | 3 40 | 41 | 42 | Arduino_nano328 43 | 3 44 | 45 | 46 | 47 | true 48 | OpenBSD|OpenBSD 49 | OpenBSD|OpenBSD 50 | OpenBSD|OpenBSD 51 | 52 | 53 | 54 | 55 | -------------------------------------------------------------------------------- /libbasic/src/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 "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 | -------------------------------------------------------------------------------- /libbasic/src/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 | -------------------------------------------------------------------------------- /libbasic/src/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 | -------------------------------------------------------------------------------- /libbasic/src/basic_lexer_ru.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/terminal-basic-team/terminalbasic/04f4aab0d2c220c901c78fca4cfccc825996c080/libbasic/src/basic_lexer_ru.c -------------------------------------------------------------------------------- /libbasic/src/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 | -------------------------------------------------------------------------------- /libbasic/src/math/e_sqrtf.c: -------------------------------------------------------------------------------- 1 | /* e_sqrtf.c -- float version of e_sqrt.c. 2 | * Conversion to float by Ian Lance Taylor, Cygnus Support, ian@cygnus.com. 3 | */ 4 | 5 | /* 6 | * ==================================================== 7 | * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. 8 | * 9 | * Developed at SunPro, a Sun Microsystems, Inc. business. 10 | * Permission to use, copy, modify, and distribute this 11 | * software is freely granted, provided that this notice 12 | * is preserved. 13 | * ==================================================== 14 | */ 15 | 16 | #if INTERNAL_MATH 17 | 18 | #include "math.h" 19 | #include "math_private.h" 20 | 21 | #include 22 | 23 | static const float one = 1.0, tiny=1.0e-30; 24 | 25 | float 26 | sqrtf(float x) 27 | { 28 | float z; 29 | int32_t sign = (int)0x80000000; 30 | int32_t ix,s,q,m,t,i; 31 | uint32_t r; 32 | 33 | GET_FLOAT_WORD(ix,x); 34 | 35 | /* take care of Inf and NaN */ 36 | if((ix&0x7f800000)==0x7f800000) { 37 | return x*x+x; /* sqrt(NaN)=NaN, sqrt(+inf)=+inf 38 | sqrt(-inf)=sNaN */ 39 | } 40 | /* take care of zero */ 41 | if(ix<=0) { 42 | if((ix&(~sign))==0) return x;/* sqrt(+-0) = +-0 */ 43 | else if(ix<0) 44 | return (x-x)/(x-x); /* sqrt(-ve) = sNaN */ 45 | } 46 | /* normalize x */ 47 | m = (ix>>23); 48 | if(m==0) { /* subnormal x */ 49 | for(i=0;(ix&0x00800000)==0;i++) ix<<=1; 50 | m -= i-1; 51 | } 52 | m -= 127; /* unbias exponent */ 53 | ix = (ix&0x007fffff)|0x00800000; 54 | if(m&1) /* odd m, double x to make it even */ 55 | ix += ix; 56 | m >>= 1; /* m = [m/2] */ 57 | 58 | /* generate sqrt(x) bit by bit */ 59 | ix += ix; 60 | q = s = 0; /* q = sqrt(x) */ 61 | r = 0x01000000; /* r = moving bit from right to left */ 62 | 63 | while(r!=0) { 64 | t = s+r; 65 | if(t<=ix) { 66 | s = t+r; 67 | ix -= t; 68 | q += r; 69 | } 70 | ix += ix; 71 | r>>=1; 72 | } 73 | 74 | /* use floating add to find out rounding direction */ 75 | if(ix!=0) { 76 | z = one-tiny; /* trigger inexact flag */ 77 | if (z>=one) { 78 | z = one+tiny; 79 | if (z>one) 80 | q += 2; 81 | else 82 | q += (q&1); 83 | } 84 | } 85 | ix = (q>>1)+0x3f000000; 86 | ix += (m <<23); 87 | 88 | SET_FLOAT_WORD(z,ix); 89 | return z; 90 | } 91 | 92 | #endif 93 | -------------------------------------------------------------------------------- /libbasic/src/test.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 | 26 | #include "math.h" 27 | 28 | #include "basic_lexer.h" 29 | #include "tools.h" 30 | #include "HAL.h" 31 | 32 | static BOOLEAN 33 | lexer_test_keywords() 34 | { 35 | const uint8_t s[] = "ANDINV(LET A = 3"; 36 | basic_token_t tokens[] = { 37 | BASIC_TOKEN_OP_AND, 38 | #if USE_MATRIX 39 | BASIC_TOKEN_KW_INV, 40 | #endif 41 | BASIC_TOKEN_LPAREN, 42 | BASIC_TOKEN_KW_LET, 43 | BASIC_TOKEN_REAL_IDENT, 44 | BASIC_TOKEN_EQUALS, 45 | BASIC_TOKEN_C_INTEGER 46 | }; 47 | basic_lexer_context_t lexer; 48 | basic_lexer_init(&lexer, s, FALSE); 49 | 50 | uint8_t i; 51 | uint8_t buf[16]; 52 | for (i = 0; i 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 | -------------------------------------------------------------------------------- /make_autotools.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | #set -e 4 | set -x 5 | 6 | VER=$(cat ./BASIC/version) 7 | SKETCH=./autotools/terminalbasic-$VER 8 | SRC_PATH=${SKETCH}/terminalbasic 9 | 10 | rm -rf $SRC_PATH 11 | 12 | SRC=" ./libbasic/include/basic.h 13 | ./libbasic/src/basic.c 14 | ./libbasic/include/tools.h 15 | ./libbasic/src/tools.c 16 | ./libbasic/include/basic_config.h 17 | ./libbasic/include/_basic_config.h 18 | ./libbasic/include/HAL.h 19 | ./libbasic/src/HAL.c 20 | ./libbasic/include/HAL_config.h 21 | ./libbasic/include/_tokens_en.h 22 | ./libbasic/include/_tokens_fr.h 23 | ./libbasic/include/_tokens_ru.h 24 | ./libbasic/include/basic_value.h 25 | ./libbasic/src/basic_value.c 26 | ./libbasic/include/basic_lexer.h 27 | ./libbasic/src/basic_lexer.c 28 | ./libbasic/src/basic_lexer_en.c 29 | ./libbasic/src/basic_lexer_fr.c 30 | ./libbasic/src/basic_lexer_ru.c 31 | ./libbasic/include/basic_parser.h 32 | ./libbasic/src/basic_parser.c 33 | ./libbasic/include/_tokens_en.h 34 | ./libbasic/include/_tokens_fr.h 35 | ./libbasic/include/_tokens_ru.h 36 | ./BASIC/include/basic.hpp 37 | ./BASIC/include/basic_lexer.hpp 38 | ./BASIC/src/basic_lexerw.cpp 39 | ./BASIC/include/basic_config.hpp 40 | ./BASIC/include/config_linux.hpp 41 | ./BASIC/include/version.h 42 | ./BASIC/src/basic.cpp 43 | ./BASIC/include/HAL_pc.h 44 | ./BASIC/include/_HAL_pc.h 45 | ./BASIC/src/HAL_pc.c 46 | ./BASIC/src/HAL_posix.c 47 | ./BASIC/src/HAL_mingw32.c 48 | ./BASIC/include/HALProxyStream.hpp 49 | ./BASIC/src/HALProxyStream.cpp 50 | ./BASIC/include/basic_interpreter.hpp 51 | ./BASIC/include/basic_program.hpp 52 | ./BASIC/include/basic_parser.hpp 53 | ./BASIC/include/basic_task.hpp 54 | ./BASIC/src/basic_task.cpp 55 | ./BASIC/src/basic_parserw.cpp 56 | ./BASIC/include/basic_dataparser.hpp 57 | ./BASIC/src/basic_dataparser.cpp 58 | ./BASIC/src/basic_interpreterw.cpp 59 | ./BASIC/src/basic_interpreter_matrix.cpp 60 | ./BASIC/src/basic_program.cpp 61 | ./BASIC/include/basic_exteeprom.hpp 62 | ./BASIC/src/basic_exteeprom.cpp 63 | ./BASIC/include/basic_functionblock.hpp 64 | ./BASIC/include/basic_math.hpp 65 | ./BASIC/src/basic_functionblock.cpp 66 | ./BASIC/src/basic_math.cpp 67 | ./BASIC/include/basic_parser_value.hpp 68 | ./BASIC/include/basic_extmemfs.hpp 69 | ./BASIC/include/basic_internalfuncs.hpp 70 | ./BASIC/src/basic_internalfuncs.cpp 71 | ./BASIC/include/basic_gfx.hpp 72 | ./BASIC/src/basic_gfx.cpp 73 | ./BASIC/src/tvoutprint.cpp 74 | ./BASIC/include/tvoutprint.hpp 75 | ./BASIC/src/basic_gfx_tvout.cpp 76 | ./BASIC/src/basic_gfx_utft.cpp 77 | ./BASIC/src/basic_gfx_serial.cpp 78 | ./BASIC/src/basic_parser_value.cpp 79 | ./BASIC/src/basic_extmemfs.cpp 80 | ./BASIC/src/taskmain.cpp 81 | ./BASIC/src/strings_en.hpp 82 | ./BASIC/src/strings_fr.hpp 83 | ./BASIC/src/strings_ru.hpp 84 | ../libarduinoext/include/vt100.hpp 85 | ../libarduinoext/include/matrix.hpp 86 | ../libarduinoext/include/types.hpp 87 | ../libarduinoext/include/i2ceeprom.hpp 88 | ../libarduinoext/include/arduino_logger.hpp 89 | ../libarduinoext/include/arduinoext.hpp 90 | ../libarduinoext/include/helper.hpp 91 | ../libarduinoext/include/math.hpp 92 | ../libarduinoext/include/bytearray.hpp 93 | ../libarduinoext/src/bytearray.cpp 94 | ../libarduinoext/src/vt100.cpp 95 | ../libarduinoext/include/seriallight.hpp 96 | ../libarduinoext/src/seriallight.cpp 97 | ../libarduinoext/include/ascii.hpp" 98 | 99 | COPY_FILES="ChangeLog COPYING configure.ac Makefile.am" 100 | 101 | rm -rf $SKETCH 102 | mkdir -p $SKETCH 103 | mkdir -p $SRC_PATH 104 | 105 | cp ./Makefile.am.terminal-basic "${SRC_PATH}/Makefile.am" 106 | rsync -r ../libarduinoemulator/include/ ${SRC_PATH} 107 | cp ../libarduinoemulator/src/Print.cpp ${SRC_PATH} 108 | cp ../libarduinoemulator/src/Stream.cpp ${SRC_PATH} 109 | cp ../libarduinoemulator/src/arduino.cpp ${SRC_PATH} 110 | 111 | #cp ../libtvoutex/TVoutEx/src/*.cpp ${SRC_PATH} 112 | #cp ../libtvoutex/TVoutEx/src/*.h ${SRC_PATH} 113 | #cp ../libtvoutex/TVoutEx/src/*.hpp ${SRC_PATH} 114 | #cp ../libtvoutex/netbenas/*.cpp ${SRC_PATH} 115 | #mkdir ${SRC_PATH}/spec 116 | #cp ../libtvoutex/TVoutEx/src/spec/* ${SRC_PATH}/spec 117 | #mkdir ${SRC_PATH}/utility 118 | #cp ../libtvoutex/TVoutEx/src/utility/*.h ${SRC_PATH}/utility/ 119 | #cp ../libtvoutex/TVoutEx/src/utility/*.hpp ${SRC_PATH}/utility/ 120 | #cp ../libtvoutex/TVoutEx/src/utility/*.cpp ${SRC_PATH} 121 | 122 | for file in $SRC 123 | do 124 | cp ${file} ${SRC_PATH} 125 | done 126 | 127 | for file in $COPY_FILES 128 | do 129 | cp ${file} ${SKETCH} 130 | done 131 | cp README.md ${SKETCH}/README 132 | 133 | cd $SKETCH 134 | autoreconf 135 | automake --add-missing 136 | autoreconf 137 | ./configure 138 | make dist 139 | -------------------------------------------------------------------------------- /make_sketch.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | set -e 4 | 5 | VER=$(cat ./BASIC/version) 6 | SKETCH=./sketch/terminal-basic-$VER 7 | SRC_PATH=${SKETCH}/terminal-basic 8 | 9 | SRC=" ./libbasic/include/basic.h \ 10 | ./libbasic/include/basic_lexer.h \ 11 | ./libbasic/include/basic_parser.h \ 12 | ./libbasic/include/basic_value.h \ 13 | ./libbasic/include/basic_config.h \ 14 | ./libbasic/include/_basic_config.h \ 15 | ./libbasic/include/HAL.h \ 16 | ./libbasic/include/HAL_config.h \ 17 | ./libbasic/include/tools.h \ 18 | ./libbasic/include/_tokens_en.h \ 19 | ./libbasic/include/_tokens_fr.h \ 20 | ./libbasic/include/_tokens_ru.h \ 21 | ./libbasic/src/basic.c \ 22 | ./libbasic/src/HAL.c \ 23 | ./libbasic/src/tools.c \ 24 | ./libbasic/src/basic_lexer_en.c \ 25 | ./libbasic/src/basic_lexer_fr.c \ 26 | ./libbasic/src/basic_lexer_ru.c \ 27 | ./libbasic/src/basic_value.c \ 28 | ./libbasic/src/basic_lexer.c \ 29 | ./libbasic/src/basic_parser.c \ 30 | ./BASIC/include/HALProxyStream.hpp \ 31 | ./BASIC/include/basic.hpp \ 32 | ./BASIC/include/basic_arduinoio.hpp \ 33 | ./BASIC/include/basic_dataparser.hpp \ 34 | ./BASIC/include/basic_interpreter.hpp \ 35 | ./BASIC/include/basic_lexer.hpp \ 36 | ./BASIC/include/basic_parser.hpp \ 37 | ./BASIC/include/basic_program.hpp \ 38 | ./BASIC/include/basic_config.hpp \ 39 | ./BASIC/include/config_arduino.hpp \ 40 | ./BASIC/include/HAL_arduino.h \ 41 | ./BASIC/include/_HAL_arduino.h \ 42 | ./BASIC/include/HAL_arduino_gfx.hpp \ 43 | ./BASIC/src/HALProxyStream.cpp \ 44 | ./BASIC/src/basic_lexerw.cpp \ 45 | ./BASIC/include/version.h \ 46 | ./BASIC/src/basic_parserw.cpp \ 47 | ./BASIC/src/basic_interpreterw.cpp \ 48 | ./BASIC/src/basic_interpreter_matrix.cpp \ 49 | ./BASIC/src/basic_dataparser.cpp \ 50 | ./BASIC/src/basic_program.cpp \ 51 | ./BASIC/include/basic_exteeprom.hpp \ 52 | ./BASIC/src/basic_exteeprom.cpp \ 53 | ./BASIC/include/basic_functionblock.hpp \ 54 | ./BASIC/include/basic_math.hpp \ 55 | ./BASIC/src/basic_functionblock.cpp \ 56 | ./BASIC/src/basic_arduinoio.cpp \ 57 | ./BASIC/src/basic_math.cpp \ 58 | ./BASIC/include/basic_parser_value.hpp \ 59 | ./BASIC/src/basic_parser_value.cpp \ 60 | ./BASIC/include/basic_extmemfs.hpp \ 61 | ./BASIC/src/basic_extmemfs.cpp \ 62 | ./BASIC/include/basic_internalfuncs.hpp \ 63 | ./BASIC/src/basic_internalfuncs.cpp \ 64 | ./BASIC/include/basic_gfx.hpp \ 65 | ./BASIC/src/tvoutprint.cpp \ 66 | ./BASIC/include/tvoutprint.hpp \ 67 | ./BASIC/src/HAL_arduino.cpp \ 68 | ./BASIC/src/HAL_arduino_gfx.cpp \ 69 | ./BASIC/include/HAL_avr8.h \ 70 | ./BASIC/src/HAL_avr8.cpp \ 71 | ./BASIC/src/HAL_esp8266.cpp \ 72 | ./BASIC/include/HAL_esp32.h \ 73 | ./BASIC/src/HAL_esp32.cpp \ 74 | ./BASIC/src/HAL_esp32_odroidgo.cpp \ 75 | ./BASIC/src/HAL_sam.cpp \ 76 | ./BASIC/src/basic_gfx.cpp \ 77 | ./BASIC/src/strings_en.hpp \ 78 | ./BASIC/src/strings_fr.hpp \ 79 | ./BASIC/src/strings_ru.hpp \ 80 | ../libarduinoext/include/ascii.hpp \ 81 | ../libarduinoext/include/vt100.hpp \ 82 | ../libarduinoext/include/buffered_terminal.hpp \ 83 | ../libarduinoext/include/gfxterm.hpp \ 84 | ../libarduinoext/include/liquidcrystalprint.hpp \ 85 | ../libarduinoext/include/seriallight.hpp \ 86 | ../libarduinoext/include/matrix.hpp \ 87 | ../libarduinoext/include/types.hpp \ 88 | ../libarduinoext/include/i2ceeprom.hpp \ 89 | ../libarduinoext/include/arduino_logger.hpp \ 90 | ../libarduinoext/include/arduinoext.hpp \ 91 | ../libarduinoext/include/helper.hpp \ 92 | ../libarduinoext/include/math.hpp \ 93 | ../libarduinoext/include/bytearray.hpp \ 94 | ../libarduinoext/src/bytearray.cpp \ 95 | ../libarduinoext/src/vt100.cpp \ 96 | ../libarduinoext/src/buffered_terminal.cpp \ 97 | ../libarduinoext/src/liquidcrystalprint.cpp \ 98 | ../libarduinoext/src/seriallight.cpp" 99 | 100 | COPY_FILES="README.md ChangeLog COPYING" 101 | 102 | rm -rf $SKETCH 103 | mkdir -p $SKETCH 104 | mkdir -p $SRC_PATH 105 | mkdir -p $SRC_PATH/sys 106 | mkdir -p $SRC_PATH/avr 107 | 108 | cp README.sketch ./sketch/README 109 | cp ./BASIC/src/ucbasic_main.cpp "${SRC_PATH}/terminal-basic.ino" 110 | cp ../libarduinoext/include/sys/cdefs.h "${SRC_PATH}/sys/" 111 | cp ./pgmspace.h "${SRC_PATH}/avr/" 112 | 113 | for file in $SRC 114 | do 115 | cp ${file} ${SRC_PATH} 116 | done 117 | 118 | for file in $COPY_FILES 119 | do 120 | cp ${file} ${SKETCH} 121 | done 122 | 123 | cd ./sketch 124 | tar -czvf ./terminal-basic-${VER}-arduino-sketch.tar.gz ./README ./terminal-basic-${VER} ../../libtvoutex/TVoutEx ../../libsdcard/SDCard ../../libutft/UTFT ../../libps2uart/ps2uartKeyboard ../../libps2kbddup/ps2kbd 125 | -------------------------------------------------------------------------------- /path2300.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/terminal-basic-team/terminalbasic/04f4aab0d2c220c901c78fca4cfccc825996c080/path2300.png -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /qtcreator/terminal-basic/terminal-basic.pro: -------------------------------------------------------------------------------- 1 | TEMPLATE = app 2 | CONFIG += console c++11 3 | CONFIG -= app_bundle 4 | CONFIG -= qt 5 | 6 | QMAKE_CFLAGS += -std=gnu11 7 | QMAKE_CXXFLAGS += -std=gnu++11 8 | 9 | SOURCES += main.cpp \ 10 | ../../libbasic/src/basic.c \ 11 | ../../libbasic/src/basic_lexer.c \ 12 | ../../libbasic/src/basic_value.c \ 13 | ../../libbasic/src/tools.c \ 14 | ../../libbasic/src/basic_lexer_ru.c \ 15 | ../../libbasic/src/basic_lexer_en.c \ 16 | ../../libbasic/src/basic_lexer_fr.c \ 17 | ../../libbasic/src/basic_parser.c \ 18 | ../../BASIC/src/basic_lexer.cpp 19 | 20 | INCLUDEPATH += ../../libbasic/include \ 21 | ../../../libarduinoemulator/include \ 22 | ../../../libarduinoext/include \ 23 | ../../BASIC/include \ 24 | 25 | HEADERS += \ 26 | ../../libbasic/include/tools.h \ 27 | ../../libbasic/include/basic.h \ 28 | ../../libbasic/include/HAL.h \ 29 | ../../libbasic/include/config.h \ 30 | ../../BASIC/include/basic_lexer.hpp \ 31 | ../../BASIC/include/config.hpp \ 32 | ../../BASIC/include/basic.hpp 33 | --------------------------------------------------------------------------------