Fórum témák

» Több friss téma
Fórum » Arduino
A klónok CH340 Soros-USB illesztőjének drivere (Letöltés)
Lapozás: OK   445 / 852
(#) sakrafi válasza krauszkrisztian hozzászólására (») Máj 2, 2018 /
 
Meg kell nyitni a ccp. és h. fájlokat és a WProgram.h átírni Arduino.h-ra
Itt nézz még utána:Bővebben: Link
(#) krauszkrisztian válasza sakrafi hozzászólására (») Máj 2, 2018 /
 
Sajnos nem találok ilyen szövegrészletet sehol.
Pedig Notepad++ nevű programmal néztem meg, és nem volt...
(#) krauszkrisztian válasza krauszkrisztian hozzászólására (») Máj 2, 2018 /
 
Rá is kerestem, de nem talált semmit.
Csak az Keyboard.h-t találta meg.
(#) kapu48 válasza krauszkrisztian hozzászólására (») Máj 2, 2018 /
 
Ha az Arduino1.6.5-ös IDEt használnád, fordításkor? Nem lennének ilyen gondjaid!
(#) kapu48 válasza krauszkrisztian hozzászólására (») Máj 2, 2018 /
 
Egyébként, ha lenne konkrét link + vanvalamineve?.ino + hibajelentésről copi-paste!
Akkor lehet, hogy még segíteni is tudna valaki!
(#) devilke3000 válasza krauszkrisztian hozzászólására (») Máj 2, 2018 /
 
A fő probléma oka:
Bővebben: Link
(#) krauszkrisztian válasza kapu48 hozzászólására (») Máj 3, 2018 /
 
Itt a program:
  1. //////////////////////////////////////////////////////////////////////////
  2. //             TinyBasic Plus + PS2 keyboard                            //
  3. //               for VGA monitor output                                 //
  4. //////////////////////////////////////////////////////////////////////////
  5. //
  6. // Authors: Mike Field <hamster@snap.net.nz>
  7. //          Scott Lawrence <yorgle@gmail.com>
  8. //          Brian O'Dell <megamemnon@megamemnon.com>
  9. //
  10. // Introduction of PS2 keyboard, December 2017.  
  11. //      Author: Rob Cai <rocaj74@gmail.com>
  12. //      Connections:
  13. //      Keyboard Data to Arduino pin 8;
  14. //      Keyboard IRQ (clock) to Arduino pin 3;
  15.  
  16. #define kVersion "v0.14"
  17.  
  18. // v0.14: 2013-11-07
  19. //      Input command always set the variable to 99
  20. //      Modified Input command to accept an expression using getn()
  21. //      Syntax is "input x" where x is any variable
  22. //
  23. // v0.13: 2013-03-04
  24. //      Support for Arduino 1.5 (SPI.h included, additional changes for DUE support)
  25. //
  26. // v0.12: 2013-03-01
  27. //      EEPROM load and save routines added: EFORMAT, ELIST, ELOAD, ESAVE, ECHAIN
  28. //      added EAUTORUN option (chains to EEProm saved program on startup)
  29. //      Bugfixes to build properly on non-arduino systems (PROGMEM #define workaround)
  30. //      cleaned up a bit of the #define options wrt TONE
  31. //
  32. // v0.11: 2013-02-20
  33. //      all display strings and tables moved to PROGMEM to save space
  34. //      removed second serial
  35. //      removed pinMode completely, autoconf is explicit
  36. //      beginnings of EEPROM related functionality (new,load,save,list)
  37. //
  38. // v0.10: 2012-10-15
  39. //      added kAutoConf, which eliminates the "PINMODE" statement.
  40. //      now, DWRITE,DREAD,AWRITE,AREAD automatically set the PINMODE appropriately themselves.
  41. //      should save a few bytes in your programs.
  42. //
  43. // v0.09: 2012-10-12
  44. //      Fixed directory listings.  FILES now always works. (bug in the SD library)
  45. //      fixed filesize printouts (added printUnum for unsigned numbers)
  46. //      #defineable baud rate for slow connection throttling
  47. //e
  48. // v0.08: 2012-10-02
  49. //      Tone generation through piezo added (TONE, TONEW, NOTONE)
  50. //
  51. // v0.07: 2012-09-30
  52. //      Autorun buildtime configuration feature
  53. //
  54. // v0.06: 2012-09-27
  55. //      Added optional second serial input, used for an external keyboard
  56. //
  57. // v0.05: 2012-09-21
  58. //      CHAIN to load and run a second file
  59. //      RND,RSEED for random stuff
  60. //      Added "!=" for "<>" synonym
  61. //      Added "END" for "STOP" synonym (proper name for the functionality anyway)
  62. //
  63. // v0.04: 2012-09-20
  64. //      DELAY ms   - for delaying
  65. //      PINMODE <pin>, INPUT|IN|I|OUTPUT|OUT|O
  66. //      DWRITE <pin>, HIGH|HI|1|LOW|LO|0
  67. //      AWRITE <pin>, [0..255]
  68. //      fixed "save" appending to existing files instead of overwriting
  69. //      Updated for building desktop command line app (incomplete)
  70. //
  71. // v0.03: 2012-09-19
  72. //      Integrated Jurg Wullschleger whitespace,unary fix
  73. //      Now available through github
  74. //      Project renamed  "Tiny Basic in C" to "TinyBasic Plus"
  75. //         
  76. // v0.02b: 2012-09-17  Scott Lawrence <yorgle@gmail.com>
  77. //      Better FILES listings
  78. //
  79. // v0.02a: 2012-09-17  Scott Lawrence <yorgle@gmail.com>
  80. //      Support for SD Library
  81. //      Added: SAVE, FILES (mostly works), LOAD (mostly works) (redirects IO)
  82. //      Added: MEM, ? (PRINT)
  83. //      Quirk:  "10 LET A=B+C" is ok "10 LET A = B + C" is not.
  84. //      Quirk:  INPUT seems broken?
  85.  
  86.  
  87.  
  88. // IF testing with Visual C, this needs to be the first thing in the file.
  89. //#include "stdafx.h"
  90.  
  91.  
  92. char eliminateCompileErrors = 1;  // fix to suppress arduino build errors
  93.  
  94. // hack to let makefiles work with this file unchanged
  95. #ifdef FORCE_DESKTOP
  96. #undef ARDUINO
  97. #include "desktop.h"
  98. #else
  99. #define ARDUINO 1
  100. #endif
  101.  
  102.  
  103. ////////////////////////////////////////////////////////////////////////////////
  104. // Feature option configuration...
  105.  
  106. // This enables LOAD, SAVE, FILES commands through the Arduino SD Library
  107. // it adds 9k of usage as well.
  108. //#define ENABLE_FILEIO 1
  109. #undef ENABLE_FILEIO
  110.  
  111. // this turns on "autorun".  if there's FileIO, and a file "autorun.bas",
  112. // then it will load it and run it when starting up
  113. //#define ENABLE_AUTORUN 1
  114. #undef ENABLE_AUTORUN
  115. // and this is the file that gets run
  116. #define kAutorunFilename  "autorun.bas"
  117.  
  118. // this is the alternate autorun.  Autorun the program in the eeprom.
  119. // it will load whatever is in the EEProm and run it
  120. #define ENABLE_EAUTORUN 1
  121. //#undef ENABLE_EAUTORUN
  122.  
  123. // this will enable the "TONE", "NOTONE" command using a piezo
  124. // element on the specified pin.  Wire the red/positive/piezo to the kPiezoPin,
  125. // and the black/negative/metal disc to ground.
  126. // it adds 1.5k of usage as well.
  127. //#define ENABLE_TONES 1
  128. #undef ENABLE_TONES
  129. #define kPiezoPin 5
  130.  
  131. // we can use the EEProm to store a program during powerdown.  This is
  132. // 1kbyte on the '328, and 512 bytes on the '168.  Enabling this here will
  133. // allow for this funcitonality to work.  Note that this only works on AVR
  134. // arduino.  Disable it for DUE/other devices.
  135. #define ENABLE_EEPROM 1
  136. //#undef ENABLE_EEPROM
  137.  
  138. // Sometimes, we connect with a slower device as the console.
  139. // Set your console D0/D1 baud rate here (9600 baud default)
  140. //#define kConsoleBaud 9600
  141. #define kConsoleBaud 4800 //-----------------------------------------------------------------------------------------------------------------------------------------------------------------------
  142.  
  143. ////////////////////////////////////////////////////////////////////////////////
  144. #ifdef ARDUINO
  145. #ifndef RAMEND
  146. // okay, this is a hack for now
  147. // if we're in here, we're a DUE probably (ARM instead of AVR)
  148.  
  149. #define RAMEND 4096-1
  150.  
  151. // turn off EEProm
  152. #undef ENABLE_EEPROM
  153. #undef ENABLE_TONES
  154.  
  155. #else
  156. // we're an AVR!
  157.  
  158. // we're moving our data strings into progmem
  159. #include <avr/pgmspace.h>
  160. #endif
  161.  
  162. // includes, and settings for Arduino-specific functionality
  163. #ifdef ENABLE_EEPROM
  164. #include <EEPROM.h>  /* NOTE: case sensitive */
  165. int eepos = 0;
  166. #endif
  167.  
  168. //---------------------------------------------------------------------------------------------------------------------------------------------------
  169. #include <PS2Keyboard.h>
  170. const int DataPin = 8;
  171. const int IRQpin =  3;
  172. PS2Keyboard keyboard;
  173. //-------------------------------------------------------------------------------------------------------------------------------------------------------
  174.  
  175.  
  176.  
  177. #ifdef ENABLE_FILEIO
  178. #include <SD.h>
  179. #include <SPI.h> /* needed as of 1.5 beta */
  180.  
  181. // Arduino-specific configuration
  182. // set this to the card  for your SD shield
  183. #define kSD_CS 10
  184.  
  185. #define kSD_Fail  0
  186. #define kSD_OK    1
  187.  
  188. File fp;
  189. #endif
  190.  
  191. // set up our RAM buffer size for program and user input
  192. // NOTE: This number will have to change if you include other libraries.
  193. #ifdef ARDUINO
  194. #ifdef ENABLE_FILEIO
  195. #define kRamFileIO (1030) /* approximate */
  196. #else
  197. #define kRamFileIO (0)
  198. #endif
  199. #ifdef ENABLE_TONES
  200. #define kRamTones (40)
  201. #else
  202. #define kRamTones (0)
  203. #endif
  204. #endif /* ARDUINO */
  205. #define kRamSize  (RAMEND - 1160 - kRamFileIO - kRamTones)
  206.  
  207. #ifndef ARDUINO
  208. // Not arduino setup
  209. #include <stdio.h>
  210. #include <stdlib.h>
  211. #undef ENABLE_TONES
  212.  
  213. // size of our program ram
  214. #define kRamSize   4096 /* arbitrary */
  215.  
  216. #ifdef ENABLE_FILEIO
  217. FILE * fp;
  218. #endif
  219. #endif
  220.  
  221. #ifdef ENABLE_FILEIO
  222. // functions defined elsehwere
  223. void cmd_Files( void );
  224. #endif
  225.  
  226. ////////////////////
  227.  
  228. #ifndef boolean
  229. #define boolean int
  230. #define true 1
  231. #define false 0
  232. #endif
  233. #endif
  234.  
  235. #ifndef byte
  236. typedef unsigned char byte;
  237. #endif
  238.  
  239. // some catches for AVR based text string stuff...
  240. #ifndef PROGMEM
  241. #define PROGMEM
  242. #endif
  243. #ifndef pgm_read_byte
  244. #define pgm_read_byte( A ) *(A)
  245. #endif
  246.  
  247. ////////////////////
  248.  
  249. #ifdef ENABLE_FILEIO
  250. unsigned char * filenameWord(void);
  251. static boolean sd_is_initialized = false;
  252. #endif
  253.  
  254. boolean inhibitOutput = false;
  255. static boolean runAfterLoad = false;
  256. static boolean triggerRun = false;
  257.  
  258. // these will , at runtime, where IO happens through for load/save
  259. enum {
  260.   kStreamSerial = 0,
  261.   kStreamEEProm,
  262.   kStreamFile
  263. };
  264. static unsigned char inStream = kStreamSerial;
  265. static unsigned char outStream = kStreamSerial;
  266.  
  267.  
  268. ////////////////////////////////////////////////////////////////////////////////
  269. // ASCII Characters
  270. #define CR      '\r'
  271. #define NL      '\n'
  272. #define LF      0x0a
  273. #define TAB     '\t'
  274. #define BELL    '\b'
  275. #define SPACE   ' '
  276. #define SQUOTE  '\''
  277. #define DQUOTE  '\"'
  278. #define CTRLC   0x03
  279. #define CTRLH   0x08
  280. #define CTRLS   0x13
  281. #define CTRLX   0x18
  282.  
  283. typedef short unsigned LINENUM;
  284. #ifdef ARDUINO
  285. #define ECHO_CHARS 1
  286. #else
  287. #define ECHO_CHARS 0
  288. #endif
  289.  
  290.  
  291. static unsigned char program[kRamSize];
  292. static const char *  sentinel = "HELLO";
  293. static unsigned char *txtpos,*list_line, *tmptxtpos;
  294. static unsigned char expression_error;
  295. static unsigned char *tempsp;
  296.  
  297. /***********************************************************/
  298. // Keyword table and constants - the last character has 0x80 added to it
  299. const static unsigned char keywords[] PROGMEM = {
  300.   'L','I','S','T'+0x80,
  301.   'L','O','A','D'+0x80,
  302.   'N','E','W'+0x80,
  303.   'R','U','N'+0x80,
  304.   'S','A','V','E'+0x80,
  305.   'N','E','X','T'+0x80,
  306.   'L','E','T'+0x80,
  307.   'I','F'+0x80,
  308.   'G','O','T','O'+0x80,
  309.   'G','O','S','U','B'+0x80,
  310.   'R','E','T','U','R','N'+0x80,
  311.   'R','E','M'+0x80,
  312.   'F','O','R'+0x80,
  313.   'I','N','P','U','T'+0x80,
  314.   'P','R','I','N','T'+0x80,
  315.   'P','O','K','E'+0x80,
  316.   'S','T','O','P'+0x80,
  317.   'B','Y','E'+0x80,
  318.   'F','I','L','E','S'+0x80,
  319.   'M','E','M'+0x80,
  320.   '?'+ 0x80,
  321.   '\''+ 0x80,
  322.   'A','W','R','I','T','E'+0x80,
  323.   'D','W','R','I','T','E'+0x80,
  324.   'D','E','L','A','Y'+0x80,
  325.   'E','N','D'+0x80,
  326.   'R','S','E','E','D'+0x80,
  327.   'C','H','A','I','N'+0x80,
  328. #ifdef ENABLE_TONES
  329.   'T','O','N','E','W'+0x80,
  330.   'T','O','N','E'+0x80,
  331.   'N','O','T','O','N','E'+0x80,
  332. #endif
  333. #ifdef ARDUINO
  334. #ifdef ENABLE_EEPROM
  335.   'E','C','H','A','I','N'+0x80,
  336.   'E','L','I','S','T'+0x80,
  337.   'E','L','O','A','D'+0x80,
  338.   'E','F','O','R','M','A','T'+0x80,
  339.   'E','S','A','V','E'+0x80,
  340. #endif
  341. #endif
  342.   0
  343. };
  344.  
  345. // by moving the command list to an enum, we can easily remove sections
  346. // above and below simultaneously to ively obliterate functionality.
  347. enum {
  348.   KW_LIST = 0,
  349.   KW_LOAD, KW_NEW, KW_RUN, KW_SAVE,
  350.   KW_NEXT, KW_LET, KW_IF,
  351.   KW_GOTO, KW_GOSUB, KW_RETURN,
  352.   KW_REM,
  353.   KW_FOR,
  354.   KW_INPUT, KW_PRINT,
  355.   KW_POKE,
  356.   KW_STOP, KW_BYE,
  357.   KW_FILES,
  358.   KW_MEM,
  359.   KW_QMARK, KW_QUOTE,
  360.   KW_AWRITE, KW_DWRITE,
  361.   KW_DELAY,
  362.   KW_END,
  363.   KW_RSEED,
  364.   KW_CHAIN,
  365. #ifdef ENABLE_TONES
  366.   KW_TONEW, KW_TONE, KW_NOTONE,
  367. #endif
  368. #ifdef ARDUINO
  369. #ifdef ENABLE_EEPROM
  370.   KW_ECHAIN, KW_ELIST, KW_ELOAD, KW_EFORMAT, KW_ESAVE,
  371. #endif
  372. #endif
  373.   KW_DEFAULT /* always the final one*/
  374. };
  375.  
  376. struct stack_for_frame {
  377.   char frame_type;
  378.   char for_var;
  379.   short int terminal;
  380.   short int step;
  381.   unsigned char *current_line;
  382.   unsigned char *txtpos;
  383. };
  384.  
  385. struct stack_gosub_frame {
  386.   char frame_type;
  387.   unsigned char *current_line;
  388.   unsigned char *txtpos;
  389. };
  390.  
  391. const static unsigned char func_tab[] PROGMEM = {
  392.   'P','E','E','K'+0x80,
  393.   'A','B','S'+0x80,
  394.   'A','R','E','A','D'+0x80,
  395.   'D','R','E','A','D'+0x80,
  396.   'R','N','D'+0x80,
  397.   0
  398. };
  399. #define FUNC_PEEK    0
  400. #define FUNC_ABS     1
  401. #define FUNC_AREAD   2
  402. #define FUNC_DREAD   3
  403. #define FUNC_RND     4
  404. #define FUNC_UNKNOWN 5
  405.  
  406. const static unsigned char to_tab[] PROGMEM = {
  407.   'T','O'+0x80,
  408.   0
  409. };
  410.  
  411. const static unsigned char step_tab[] PROGMEM = {
  412.   'S','T','E','P'+0x80,
  413.   0
  414. };
  415.  
  416. const static unsigned char relop_tab[] PROGMEM = {
  417.   '>','='+0x80,
  418.   '<','>'+0x80,
  419.   '>'+0x80,
  420.   '='+0x80,
  421.   '<','='+0x80,
  422.   '<'+0x80,
  423.   '!','='+0x80,
  424.   0
  425. };
  426.  
  427. #define RELOP_GE                0
  428. #define RELOP_NE                1
  429. #define RELOP_GT                2
  430. #define RELOP_EQ                3
  431. #define RELOP_LE                4
  432. #define RELOP_LT                5
  433. #define RELOP_NE_BANG           6
  434. #define RELOP_UNKNOWN   7
  435.  
  436. const static unsigned char highlow_tab[] PROGMEM = {
  437.   'H','I','G','H'+0x80,
  438.   'H','I'+0x80,
  439.   'L','O','W'+0x80,
  440.   'L','O'+0x80,
  441.   0
  442. };
  443. #define HIGHLOW_HIGH    1
  444. #define HIGHLOW_UNKNOWN 4
  445.  
  446. #define STACK_SIZE (sizeof(struct stack_for_frame)*5)
  447. #define VAR_SIZE sizeof(short int) // Size of variables in bytes
  448.  
  449. static unsigned char *stack_limit;
  450. static unsigned char *program_start;
  451. static unsigned char *program_end;
  452. static unsigned char *stack; // Software stack for things that should go on the CPU stack
  453. static unsigned char *variables_begin;
  454. static unsigned char *current_line;
  455. static unsigned char *sp;
  456. #define STACK_GOSUB_FLAG 'G'
  457. #define STACK_FOR_FLAG 'F'
  458. static unsigned char table_index;
  459. static LINENUM linenum;
  460.  
  461. static const unsigned char okmsg[]            PROGMEM = "OK";
  462. static const unsigned char whatmsg[]          PROGMEM = "What? ";
  463. static const unsigned char howmsg[]           PROGMEM = "How?";
  464. static const unsigned char sorrymsg[]         PROGMEM = "Sorry!";
  465. static const unsigned char initmsg[]          PROGMEM = "TinyBasic Plus " kVersion;
  466. static const unsigned char memorymsg[]        PROGMEM = " bytes free.";
  467. #ifdef ARDUINO
  468. #ifdef ENABLE_EEPROM
  469. static const unsigned char eeprommsg[]        PROGMEM = " EEProm bytes total.";
  470. static const unsigned char eepromamsg[]       PROGMEM = " EEProm bytes available.";
  471. #endif
  472. #endif
  473. static const unsigned char breakmsg[]         PROGMEM = "break!";
  474. static const unsigned char unimplimentedmsg[] PROGMEM = "Unimplemented";
  475. static const unsigned char backspacemsg[]     PROGMEM = "\b \b";
  476. static const unsigned char indentmsg[]        PROGMEM = "    ";
  477. static const unsigned char sderrormsg[]       PROGMEM = "SD card error.";
  478. static const unsigned char sdfilemsg[]        PROGMEM = "SD file error.";
  479. static const unsigned char dirextmsg[]        PROGMEM = "(dir)";
  480. static const unsigned char slashmsg[]         PROGMEM = "/";
  481. static const unsigned char spacemsg[]         PROGMEM = " ";
  482.  
  483. static int inchar(void);
  484. static void outchar(unsigned char c);
  485. static void line_terminator(void);
  486. static short int expression(void);
  487. static unsigned char breakcheck(void);
  488. /***************************************************************************/
  489. static void ignore_blanks(void)
  490. {
  491.   while(*txtpos == SPACE || *txtpos == TAB)
  492.     txtpos++;
  493. }
  494.  
  495.  
  496. /***************************************************************************/
  497. static void scantable(const unsigned char *table)
  498. {
  499.   int i = 0;
  500.   table_index = 0;
  501.   while(1)
  502.   {
  503.     // Run out of table entries?
  504.     if(pgm_read_byte( table ) == 0)
  505.       return;
  506.  
  507.     // Do we match this character?
  508.     if(txtpos[i] == pgm_read_byte( table ))
  509.     {
  510.       i++;
  511.       table++;
  512.     }
  513.     else
  514.     {
  515.       // do we match the last character of keywork (with 0x80 added)? If so, return
  516.       if(txtpos[i]+0x80 == pgm_read_byte( table ))
  517.       {
  518.         txtpos += i+1;  // Advance the pointer to following the keyword
  519.         ignore_blanks();
  520.         return;
  521.       }
  522.  
  523.       // Forward to the end of this keyword
  524.       while((pgm_read_byte( table ) & 0x80) == 0)
  525.         table++;
  526.  
  527.       // Now move on to the first character of the next word, and reset the position index
  528.       table++;
  529.       table_index++;
  530.       ignore_blanks();
  531.       i = 0;
  532.     }
  533.   }
  534. }
  535.  
  536. /***************************************************************************/
  537. static void pushb(unsigned char b)
  538. {
  539.   sp--;
  540.   *sp = b;
  541. }
  542.  
  543. /***************************************************************************/
  544. static unsigned char popb()
  545. {
  546.   unsigned char b;
  547.   b = *sp;
  548.   sp++;
  549.   return b;
  550. }
  551.  
  552. /***************************************************************************/
  553. void printnum(int num)
  554. {
  555.   int digits = 0;
  556.  
  557.   if(num < 0)
  558.   {
  559.     num = -num;
  560.     outchar('-');
  561.   }
  562.   do {
  563.     pushb(num%10+'0');
  564.     num = num/10;
  565.     digits++;
  566.   }
  567.   while (num > 0);
  568.  
  569.   while(digits > 0)
  570.   {
  571.     outchar(popb());
  572.     digits--;
  573.   }
  574. }
  575.  
  576. void printUnum(unsigned int num)
  577. {
  578.   int digits = 0;
  579.  
  580.   do {
  581.     pushb(num%10+'0');
  582.     num = num/10;
  583.     digits++;
  584.   }
  585.   while (num > 0);
  586.  
  587.   while(digits > 0)
  588.   {
  589.     outchar(popb());
  590.     digits--;
  591.   }
  592. }
  593.  
  594. /***************************************************************************/
  595. static unsigned short testnum(void)
  596. {
  597.   unsigned short num = 0;
  598.   ignore_blanks();
  599.  
  600.   while(*txtpos>= '0' && *txtpos <= '9' )
  601.   {
  602.     // Trap overflows
  603.     if(num >= 0xFFFF/10)
  604.     {
  605.       num = 0xFFFF;
  606.       break;
  607.     }
  608.  
  609.     num = num *10 + *txtpos - '0';
  610.     txtpos++;
  611.   }
  612.   return        num;
  613. }
  614.  
  615. /***************************************************************************/
  616. static unsigned char print_quoted_string(void)
  617. {
  618.   int i=0;
  619.   unsigned char delim = *txtpos;
  620.   if(delim != '"' && delim != '\'')
  621.     return 0;
  622.   txtpos++;
  623.  
  624.   // Check we have a closing delimiter
  625.   while(txtpos[i] != delim)
  626.   {
  627.     if(txtpos[i] == NL)
  628.       return 0;
  629.     i++;
  630.   }
  631.  
  632.   // Print the characters
  633.   while(*txtpos != delim)
  634.   {
  635.     outchar(*txtpos);
  636.     txtpos++;
  637.   }
  638.   txtpos++; // Skip over the last delimiter
  639.  
  640.   return 1;
  641. }
  642.  
  643.  
  644. /***************************************************************************/
  645. void printmsgNoNL(const unsigned char *msg)
  646. {
  647.   while( pgm_read_byte( msg ) != 0 ) {
  648.     outchar( pgm_read_byte( msg++ ) );
  649.   };
  650. }
  651.  
  652. /***************************************************************************/
  653. void printmsg(const unsigned char *msg)
  654. {
  655.   printmsgNoNL(msg);
  656.   line_terminator();
  657. }
  658.  
  659. /***************************************************************************/
  660. static void getln(char prompt)
  661. {
  662.   outchar(prompt);
  663.   txtpos = program_end+sizeof(LINENUM);
  664.  
  665.   while(1)
  666.   {
  667.     char c = inchar();
  668.     switch(c)
  669.     {
  670.     case NL:
  671.       //break;
  672.     case CR:
  673.       line_terminator();
  674.       // Terminate all strings with a NL
  675.       txtpos[0] = NL;
  676.       return;
  677.     case CTRLH:
  678.       if(txtpos == program_end)
  679.         break;
  680.       txtpos--;
  681.  
  682.       printmsg(backspacemsg);
  683.       break;
  684.     default:
  685.       // We need to leave at least one space to allow us to shuffle the line into order
  686.       if(txtpos == variables_begin-2)
  687.         outchar(BELL);
  688.       else
  689.       {
  690.         txtpos[0] = c;
  691.         txtpos++;
  692.         outchar(c);
  693.       }
  694.     }
  695.   }
  696. }
  697.  
  698. /***************************************************************************/
  699. static unsigned char *findline(void)
  700. {
  701.   unsigned char *line = program_start;
  702.   while(1)
  703.   {
  704.     if(line == program_end)
  705.       return line;
  706.  
  707.     if(((LINENUM *)line)[0] >= linenum)
  708.       return line;
  709.  
  710.     // Add the line length onto the current address, to get to the next line;
  711.     line += line[sizeof(LINENUM)];
  712.   }
  713. }
  714.  
  715. /***************************************************************************/
  716. static void toUppercaseBuffer(void)
  717. {
  718.   unsigned char *c = program_end+sizeof(LINENUM);
  719.   unsigned char quote = 0;
  720.  
  721.   while(*c != NL)
  722.   {
  723.     // Are we in a quoted string?
  724.     if(*c == quote)
  725.       quote = 0;
  726.     else if(*c == '"' || *c == '\'')
  727.       quote = *c;
  728.     else if(quote == 0 && *c >= 'a' && *c <= 'z')
  729.       *c = *c + 'A' - 'a';
  730.     c++;
  731.   }
  732. }
  733.  
  734. /***************************************************************************/
  735. void printline()
  736. {
  737.   LINENUM line_num;
  738.  
  739.   line_num = *((LINENUM *)(list_line));
  740.   list_line += sizeof(LINENUM) + sizeof(char);
  741.  
  742.   // Output the line */
  743.   printnum(line_num);
  744.   outchar(' ');
  745.   while(*list_line != NL)
  746.   {
  747.     outchar(*list_line);
  748.     list_line++;
  749.   }
  750.   list_line++;
  751.   line_terminator();
  752. }
  753.  
  754. /***************************************************************************/
  755. static short int expr4(void)
  756. {
  757.   // fix provided by Jurg Wullschleger wullschleger@gmail.com
  758.   // fixes whitespace and unary operations
  759.   ignore_blanks();
  760.  
  761.   if( *txtpos == '-' ) {
  762.     txtpos++;
  763.     return -expr4();
  764.   }
  765.   // end fix
  766.  
  767.   if(*txtpos == '0')
  768.   {
  769.     txtpos++;
  770.     return 0;
  771.   }
  772.  
  773.   if(*txtpos >= '1' && *txtpos <= '9')
  774.   {
  775.     short int a = 0;
  776.     do  {
  777.       a = a*10 + *txtpos - '0';
  778.       txtpos++;
  779.     }
  780.     while(*txtpos >= '0' && *txtpos <= '9');
  781.     return a;
  782.   }
  783.  
  784.   // Is it a function or variable reference?
  785.   if(txtpos[0] >= 'A' && txtpos[0] <= 'Z')
  786.   {
  787.     short int a;
  788.     // Is it a variable reference (single alpha)
  789.     if(txtpos[1] < 'A' || txtpos[1] > 'Z')
  790.     {
  791.       a = ((short int *)variables_begin)[*txtpos - 'A'];
  792.       txtpos++;
  793.       return a;
  794.     }
  795.  
  796.     // Is it a function with a single parameter
  797.     scantable(func_tab);
  798.     if(table_index == FUNC_UNKNOWN)
  799.       goto expr4_error;
  800.  
  801.     unsigned char f = table_index;
  802.  
  803.     if(*txtpos != '(')
  804.       goto expr4_error;
  805.  
  806.     txtpos++;
  807.     a = expression();
  808.     if(*txtpos != ')')
  809.       goto expr4_error;
  810.     txtpos++;
  811.     switch(f)
  812.     {
  813.     case FUNC_PEEK:
  814.       return program[a];
  815.      
  816.     case FUNC_ABS:
  817.       if(a < 0)
  818.         return -a;
  819.       return a;
  820.  
  821. #ifdef ARDUINO
  822.     case FUNC_AREAD:
  823.       pinMode( a, INPUT );
  824.       return analogRead( a );                        
  825.     case FUNC_DREAD:
  826.       pinMode( a, INPUT );
  827.       return digitalRead( a );
  828. #endif
  829.  
  830.     case FUNC_RND:
  831. #ifdef ARDUINO
  832.       return( random( a ));
  833. #else
  834.       return( rand() % a );
  835. #endif
  836.     }
  837.   }
  838.  
  839.   if(*txtpos == '(')
  840.   {
  841.     short int a;
  842.     txtpos++;
  843.     a = expression();
  844.     if(*txtpos != ')')
  845.       goto expr4_error;
  846.  
  847.     txtpos++;
  848.     return a;
  849.   }
  850.  
  851. expr4_error:
  852.   expression_error = 1;
  853.   return 0;
  854.  
  855. }
  856.  
  857. /***************************************************************************/
  858. static short int expr3(void)
  859. {
  860.   short int a,b;
  861.  
  862.   a = expr4();
  863.  
  864.   ignore_blanks(); // fix for eg:  100 a = a + 1
  865.  
  866.   while(1)
  867.   {
  868.     if(*txtpos == '*')
  869.     {
  870.       txtpos++;
  871.       b = expr4();
  872.       a *= b;
  873.     }
  874.     else if(*txtpos == '/')
  875.     {
  876.       txtpos++;
  877.       b = expr4();
  878.       if(b != 0)
  879.         a /= b;
  880.       else
  881.         expression_error = 1;
  882.     }
  883.     else
  884.       return a;
  885.   }
  886. }
  887.  
  888. /***************************************************************************/
  889. static short int expr2(void)
  890. {
  891.   short int a,b;
  892.  
  893.   if(*txtpos == '-' || *txtpos == '+')
  894.     a = 0;
  895.   else
  896.     a = expr3();
  897.  
  898.   while(1)
  899.   {
  900.     if(*txtpos == '-')
  901.     {
  902.       txtpos++;
  903.       b = expr3();
  904.       a -= b;
  905.     }
  906.     else if(*txtpos == '+')
  907.     {
  908.       txtpos++;
  909.       b = expr3();
  910.       a += b;
  911.     }
  912.     else
  913.       return a;
  914.   }
  915. }
  916. /***************************************************************************/
  917. static short int expression(void)
  918. {
  919.   short int a,b;
  920.  
  921.   a = expr2();
  922.  
  923.   // Check if we have an error
  924.   if(expression_error)  return a;
  925.  
  926.   scantable(relop_tab);
  927.   if(table_index == RELOP_UNKNOWN)
  928.     return a;
  929.  
  930.   switch(table_index)
  931.   {
  932.   case RELOP_GE:
  933.     b = expr2();
  934.     if(a >= b) return 1;
  935.     break;
  936.   case RELOP_NE:
  937.   case RELOP_NE_BANG:
  938.     b = expr2();
  939.     if(a != b) return 1;
  940.     break;
  941.   case RELOP_GT:
  942.     b = expr2();
  943.     if(a > b) return 1;
  944.     break;
  945.   case RELOP_EQ:
  946.     b = expr2();
  947.     if(a == b) return 1;
  948.     break;
  949.   case RELOP_LE:
  950.     b = expr2();
  951.     if(a <= b) return 1;
  952.     break;
  953.   case RELOP_LT:
  954.     b = expr2();
  955.     if(a < b) return 1;
  956.     break;
  957.   }
  958.   return 0;
  959. }
  960.  
  961. /***************************************************************************/
  962. void loop()
  963. {
  964.   Serial.println("&with &V&G&A&x&& video output");
  965.   //Serial.println("Version beta 1.0");
  966.   unsigned char *start;
  967.   unsigned char *newEnd;
  968.   unsigned char linelen;
  969.   boolean isDigital;
  970.   boolean alsoWait = false;
  971.   int val;
  972.  
  973. #ifdef ARDUINO
  974. #ifdef ENABLE_TONES
  975.   noTone( kPiezoPin );
  976. #endif
  977. #endif
  978.  
  979.   program_start = program;
  980.   program_end = program_start;
  981.   sp = program+sizeof(program);  // Needed for printnum
  982.   stack_limit = program+sizeof(program)-STACK_SIZE;
  983.   variables_begin = stack_limit - 27*VAR_SIZE;
  984.  
  985.   // memory free
  986.   printnum(variables_begin-program_end);
  987.   printmsg(memorymsg);
  988. #ifdef ARDUINO
  989. #ifdef ENABLE_EEPROM
  990.   // eprom size
  991.   printnum( E2END+1 );
  992.   printmsg( eeprommsg );
  993. #endif /* ENABLE_EEPROM */
  994. #endif /* ARDUINO */
  995.  
  996. warmstart:
  997.   // this signifies that it is running in 'direct' mode.
  998.   current_line = 0;
  999.   sp = program+sizeof(program);
  1000.   printmsg(okmsg);
  1001.  
  1002. prompt:
  1003.   if( triggerRun ){
  1004.     triggerRun = false;
  1005.     current_line = program_start;
  1006.     goto execline;
  1007.   }
  1008.  
  1009.   getln( '>' );
  1010.   toUppercaseBuffer();
  1011.  
  1012.   txtpos = program_end+sizeof(unsigned short);
  1013.  
  1014.   // Find the end of the freshly entered line
  1015.   while(*txtpos != NL)
  1016.     txtpos++;
  1017.  
  1018.   // Move it to the end of program_memory
  1019.   {
  1020.     unsigned char *dest;
  1021.     dest = variables_begin-1;
  1022.     while(1)
  1023.     {
  1024.       *dest = *txtpos;
  1025.       if(txtpos == program_end+sizeof(unsigned short))
  1026.         break;
  1027.       dest--;
  1028.       txtpos--;
  1029.     }
  1030.     txtpos = dest;
  1031.   }
  1032.  
  1033.   // Now see if we have a line number
  1034.   linenum = testnum();
  1035.   ignore_blanks();
  1036.   if(linenum == 0)
  1037.     goto direct;
  1038.  
  1039.   if(linenum == 0xFFFF)
  1040.     goto qhow;
  1041.  
  1042.   // Find the length of what is left, including the (yet-to-be-populated) line header
  1043.   linelen = 0;
  1044.   while(txtpos[linelen] != NL)
  1045.     linelen++;
  1046.   linelen++; // Include the NL in the line length
  1047.   linelen += sizeof(unsigned short)+sizeof(char); // Add space for the line number and line length
  1048.  
  1049.   // Now we have the number, add the line header.
  1050.   txtpos -= 3;
  1051.   *((unsigned short *)txtpos) = linenum;
  1052.   txtpos[sizeof(LINENUM)] = linelen;
  1053.  
  1054.  
  1055.   // Merge it into the rest of the program
  1056.   start = findline();
  1057.  
  1058.   // If a line with that number exists, then remove it
  1059.   if(start != program_end && *((LINENUM *)start) == linenum)
  1060.   {
  1061.     unsigned char *dest, *;
  1062.     unsigned tomove;
  1063.  
  1064.      = start + start[sizeof(LINENUM)];
  1065.     dest = start;
  1066.  
  1067.     tomove = program_end - ;
  1068.     while( tomove > 0)
  1069.     {
  1070.       *dest = *;
  1071.       ++;
  1072.       dest++;
  1073.       tomove--;
  1074.     }  
  1075.     program_end = dest;
  1076.   }
  1077.  
  1078.   if(txtpos[sizeof(LINENUM)+sizeof(char)] == NL) // If the line has no txt, it was just a delete
  1079.     goto prompt;
  1080.  
  1081.  
  1082.  
  1083.   // Make room for the new line, either all in one hit or lots of little shuffles
  1084.   while(linelen > 0)
  1085.   {    
  1086.     unsigned int tomove;
  1087.     unsigned char *,*dest;
  1088.     unsigned int space_to_make;
  1089.  
  1090.     space_to_make = txtpos - program_end;
  1091.  
  1092.     if(space_to_make > linelen)
  1093.       space_to_make = linelen;
  1094.     newEnd = program_end+space_to_make;
  1095.     tomove = program_end - start;
  1096.  
  1097.  
  1098.     // Source and destination - as these areas may overlap we need to move bottom up
  1099.      = program_end;
  1100.     dest = newEnd;
  1101.     while(tomove > 0)
  1102.     {
  1103.       --;
  1104.       dest--;
  1105.       *dest = *;
  1106.       tomove--;
  1107.     }
  1108.  
  1109.     // Copy over the bytes into the new space
  1110.     for(tomove = 0; tomove < space_to_make; tomove++)
  1111.     {
  1112.       *start = *txtpos;
  1113.       txtpos++;
  1114.       start++;
  1115.       linelen--;
  1116.     }
  1117.     program_end = newEnd;
  1118.   }
  1119.   goto prompt;
  1120.  
  1121. unimplemented:
  1122.   printmsg(unimplimentedmsg);
  1123.   goto prompt;
  1124.  
  1125. qhow:  
  1126.   printmsg(howmsg);
  1127.   goto prompt;
  1128.  
  1129. qwhat: 
  1130.   printmsgNoNL(whatmsg);
  1131.   if(current_line != NULL)
  1132.   {
  1133.     unsigned char tmp = *txtpos;
  1134.     if(*txtpos != NL)
  1135.       *txtpos = '^';
  1136.     list_line = current_line;
  1137.     printline();
  1138.     *txtpos = tmp;
  1139.   }
  1140.   line_terminator();
  1141.   goto prompt;
  1142.  
  1143. qsorry:
  1144.   printmsg(sorrymsg);
  1145.   goto warmstart;
  1146.  
  1147. run_next_statement:
  1148.   while(*txtpos == ':')
  1149.     txtpos++;
  1150.   ignore_blanks();
  1151.   if(*txtpos == NL)
  1152.     goto execnextline;
  1153.   goto interperateAtTxtpos;
  1154.  
  1155. direct:
  1156.   txtpos = program_end+sizeof(LINENUM);
  1157.   if(*txtpos == NL)
  1158.     goto prompt;
  1159.  
  1160. interperateAtTxtpos:
  1161.   if(breakcheck())
  1162.   {
  1163.     printmsg(breakmsg);
  1164.     goto warmstart;
  1165.   }
  1166.  
  1167.   scantable(keywords);
  1168.  
  1169.   switch(table_index)
  1170.   {
  1171.   case KW_DELAY:
  1172.     {
  1173. #ifdef ARDUINO
  1174.       expression_error = 0;
  1175.       val = expression();
  1176.       delay( val );
  1177.       goto execnextline;
  1178. #else
  1179.       goto unimplemented;
  1180. #endif
  1181.     }
  1182.  
  1183.   case KW_FILES:
  1184.     goto files;
  1185.   case KW_LIST:
  1186.     goto list;
  1187.   case KW_CHAIN:
  1188.     goto chain;
  1189.   case KW_LOAD:
  1190.     goto load;
  1191.   case KW_MEM:
  1192.     goto mem;
  1193.   case KW_NEW:
  1194.     if(txtpos[0] != NL)
  1195.       goto qwhat;
  1196.     program_end = program_start;
  1197.     goto prompt;
  1198.   case KW_RUN:
  1199.     current_line = program_start;
  1200.     goto execline;
  1201.   case KW_SAVE:
  1202.     goto save;
  1203.   case KW_NEXT:
  1204.     goto next;
  1205.   case KW_LET:
  1206.     goto assignment;
  1207.   case KW_IF:
  1208.     short int val;
  1209.     expression_error = 0;
  1210.     val = expression();
  1211.     if(expression_error || *txtpos == NL)
  1212.       goto qhow;
  1213.     if(val != 0)
  1214.       goto interperateAtTxtpos;
  1215.     goto execnextline;
  1216.  
  1217.   case KW_GOTO:
  1218.     expression_error = 0;
  1219.     linenum = expression();
  1220.     if(expression_error || *txtpos != NL)
  1221.       goto qhow;
  1222.     current_line = findline();
  1223.     goto execline;
  1224.  
  1225.   case KW_GOSUB:
  1226.     goto gosub;
  1227.   case KW_RETURN:
  1228.     goto gosub_return;
  1229.   case KW_REM:
  1230.   case KW_QUOTE:
  1231.     goto execnextline;  // Ignore line completely
  1232.   case KW_FOR:
  1233.     goto forloop;
  1234.   case KW_INPUT:
  1235.     goto input;
  1236.   case KW_PRINT:
  1237.   case KW_QMARK:
  1238.     goto print;
  1239.   case KW_POKE:
  1240.     goto poke;
  1241.   case KW_END:
  1242.   case KW_STOP:
  1243.     // This is the easy way to end - set the current line to the end of program attempt to run it
  1244.     if(txtpos[0] != NL)
  1245.       goto qwhat;
  1246.     current_line = program_end;
  1247.     goto execline;
  1248.   case KW_BYE:
  1249.     // Leave the basic interperater
  1250.     return;
  1251.  
  1252.   case KW_AWRITE:  // AWRITE <pin>, HIGH|LOW
  1253.     isDigital = false;
  1254.     goto awrite;
  1255.   case KW_DWRITE:  // DWRITE <pin>, HIGH|LOW
  1256.     isDigital = true;
  1257.     goto dwrite;
  1258.  
  1259.   case KW_RSEED:
  1260.     goto rseed;
  1261.  
  1262. #ifdef ENABLE_TONES
  1263.   case KW_TONEW:
  1264.     alsoWait = true;
  1265.   case KW_TONE:
  1266.     goto tonegen;
  1267.   case KW_NOTONE:
  1268.     goto tonestop;
  1269. #endif
  1270.  
  1271. #ifdef ARDUINO
  1272. #ifdef ENABLE_EEPROM
  1273.   case KW_EFORMAT:
  1274.     goto eformat;
  1275.   case KW_ESAVE:
  1276.     goto esave;
  1277.   case KW_ELOAD:
  1278.     goto eload;
  1279.   case KW_ELIST:
  1280.     goto elist;
  1281.   case KW_ECHAIN:
  1282.     goto echain;
  1283. #endif
  1284. #endif
  1285.  
  1286.   case KW_DEFAULT:
  1287.     goto assignment;
  1288.   default:
  1289.     break;
  1290.   }
  1291.  
  1292. execnextline:
  1293.   if(current_line == NULL)              // Processing direct commands?
  1294.     goto prompt;
  1295.   current_line +=        current_line[sizeof(LINENUM)];
  1296.  
  1297. execline:
  1298.   if(current_line == program_end) // Out of lines to run
  1299.     goto warmstart;
  1300.   txtpos = current_line+sizeof(LINENUM)+sizeof(char);
  1301.   goto interperateAtTxtpos;
  1302.  
  1303. #ifdef ARDUINO
  1304. #ifdef ENABLE_EEPROM
  1305. elist:
  1306.   {
  1307.     int i;
  1308.     for( i = 0 ; i < (E2END +1) ; i++ )
  1309.     {
  1310.       val = EEPROM.read( i );
  1311.  
  1312.       if( val == '\0' ) {
  1313.         goto execnextline;
  1314.       }
  1315.  
  1316.       if( ((val < ' ') || (val  > '~')) && (val != NL) && (val != CR))  {
  1317.         outchar( '?' );
  1318.       }
  1319.       else {
  1320.         outchar( val );
  1321.       }
  1322.     }
  1323.   }
  1324.   goto execnextline;
  1325.  
  1326. eformat:
  1327.   {
  1328.     for( int i = 0 ; i < E2END ; i++ )
  1329.     {
  1330.       if( (i & 0x03f) == 0x20 ) outchar( '.' );
  1331.       EEPROM.write( i, 0 );
  1332.     }
  1333.     outchar( LF );
  1334.   }
  1335.   goto execnextline;
  1336.  
  1337. esave:
  1338.   {
  1339.     outStream = kStreamEEProm;
  1340.     eepos = 0;
  1341.  
  1342.     // copied  "List"
  1343.     list_line = findline();
  1344.     while(list_line != program_end) {
  1345.       printline();
  1346.     }
  1347.     outchar('\0');
  1348.  
  1349.     // go back to standard output, close the file
  1350.     outStream = kStreamSerial;
  1351.    
  1352.     goto warmstart;
  1353.   }
  1354.  
  1355.  
  1356. echain:
  1357.   runAfterLoad = true;
  1358.  
  1359. eload:
  1360.   // clear the program
  1361.   program_end = program_start;
  1362.  
  1363.   // load  a file into memory
  1364.   eepos = 0;
  1365.   inStream = kStreamEEProm;
  1366.   inhibitOutput = true;
  1367.   goto warmstart;
  1368. #endif /* ENABLE_EEPROM */
  1369. #endif
  1370.  
  1371. input:
  1372.   {
  1373.     unsigned char var;
  1374.     int value;
  1375.     ignore_blanks();
  1376.     if(*txtpos < 'A' || *txtpos > 'Z')
  1377.       goto qwhat;
  1378.     var = *txtpos;
  1379.     txtpos++;
  1380.     ignore_blanks();
  1381.     if(*txtpos != NL && *txtpos != ':')
  1382.       goto qwhat;
  1383. inputagain:
  1384.     tmptxtpos = txtpos;
  1385.     getln( '?' );
  1386.     toUppercaseBuffer();
  1387.     txtpos = program_end+sizeof(unsigned short);
  1388.     ignore_blanks();
  1389.     expression_error = 0;
  1390.     value = expression();
  1391.     if(expression_error)
  1392.       goto inputagain;
  1393.     ((short int *)variables_begin)[var-'A'] = value;
  1394.     txtpos = tmptxtpos;
  1395.  
  1396.     goto run_next_statement;
  1397.   }
  1398.  
  1399. forloop:
  1400.   {
  1401.     unsigned char var;
  1402.     short int initial, step, terminal;
  1403.     ignore_blanks();
  1404.     if(*txtpos < 'A' || *txtpos > 'Z')
  1405.       goto qwhat;
  1406.     var = *txtpos;
  1407.     txtpos++;
  1408.     ignore_blanks();
  1409.     if(*txtpos != '=')
  1410.       goto qwhat;
  1411.     txtpos++;
  1412.     ignore_blanks();
  1413.  
  1414.     expression_error = 0;
  1415.     initial = expression();
  1416.     if(expression_error)
  1417.       goto qwhat;
  1418.  
  1419.     scantable(to_tab);
  1420.     if(table_index != 0)
  1421.       goto qwhat;
  1422.  
  1423.     terminal = expression();
  1424.     if(expression_error)
  1425.       goto qwhat;
  1426.  
  1427.     scantable(step_tab);
  1428.     if(table_index == 0)
  1429.     {
  1430.       step = expression();
  1431.       if(expression_error)
  1432.         goto qwhat;
  1433.     }
  1434.     else
  1435.       step = 1;
  1436.     ignore_blanks();
  1437.     if(*txtpos != NL && *txtpos != ':')
  1438.       goto qwhat;
  1439.  
  1440.  
  1441.     if(!expression_error && *txtpos == NL)
  1442.     {
  1443.       struct stack_for_frame *f;
  1444.       if(sp + sizeof(struct stack_for_frame) < stack_limit)
  1445.         goto qsorry;
  1446.  
  1447.       sp -= sizeof(struct stack_for_frame);
  1448.       f = (struct stack_for_frame *)sp;
  1449.       ((short int *)variables_begin)[var-'A'] = initial;
  1450.       f->frame_type = STACK_FOR_FLAG;
  1451.       f->for_var = var;
  1452.       f->terminal = terminal;
  1453.       f->step     = step;
  1454.       f->txtpos   = txtpos;
  1455.       f->current_line = current_line;
  1456.       goto run_next_statement;
  1457.     }
  1458.   }
  1459.   goto qhow;
  1460.  
  1461. gosub:
  1462.   expression_error = 0;
  1463.   linenum = expression();
  1464.   if(!expression_error && *txtpos == NL)
  1465.   {
  1466.     struct stack_gosub_frame *f;
  1467.     if(sp + sizeof(struct stack_gosub_frame) < stack_limit)
  1468.       goto qsorry;
  1469.  
  1470.     sp -= sizeof(struct stack_gosub_frame);
  1471.     f = (struct stack_gosub_frame *)sp;
  1472.     f->frame_type = STACK_GOSUB_FLAG;
  1473.     f->txtpos = txtpos;
  1474.     f->current_line = current_line;
  1475.     current_line = findline();
  1476.     goto execline;
  1477.   }
  1478.   goto qhow;
  1479.  
  1480. next:
  1481.   // Fnd the variable name
  1482.   ignore_blanks();
  1483.   if(*txtpos < 'A' || *txtpos > 'Z')
  1484.     goto qhow;
  1485.   txtpos++;
  1486.   ignore_blanks();
  1487.   if(*txtpos != ':' && *txtpos != NL)
  1488.     goto qwhat;
  1489.  
  1490. gosub_return:
  1491.   // Now walk up the stack frames and find the frame we want, if present
  1492.   tempsp = sp;
  1493.   while(tempsp < program+sizeof(program)-1)
  1494.   {
  1495.     switch(tempsp[0])
  1496.     {
  1497.     case STACK_GOSUB_FLAG:
  1498.       if(table_index == KW_RETURN)
  1499.       {
  1500.         struct stack_gosub_frame *f = (struct stack_gosub_frame *)tempsp;
  1501.         current_line    = f->current_line;
  1502.         txtpos                  = f->txtpos;
  1503.         sp += sizeof(struct stack_gosub_frame);
  1504.         goto run_next_statement;
  1505.       }
  1506.       // This is not the loop you are looking for... so Walk back up the stack
  1507.       tempsp += sizeof(struct stack_gosub_frame);
  1508.       break;
  1509.     case STACK_FOR_FLAG:
  1510.       // Flag, Var, Final, Step
  1511.       if(table_index == KW_NEXT)
  1512.       {
  1513.         struct stack_for_frame *f = (struct stack_for_frame *)tempsp;
  1514.         // Is the the variable we are looking for?
  1515.         if(txtpos[-1] == f->for_var)
  1516.         {
  1517.           short int *varaddr = ((short int *)variables_begin) + txtpos[-1] - 'A';
  1518.           *varaddr = *varaddr + f->step;
  1519.           // Use a different test depending on the sign of the step increment
  1520.           if((f->step > 0 && *varaddr <= f->terminal) || (f->step < 0 && *varaddr >= f->terminal))
  1521.           {
  1522.             // We have to loop so don't pop the stack
  1523.             txtpos = f->txtpos;
  1524.             current_line = f->current_line;
  1525.             goto run_next_statement;
  1526.           }
  1527.           // We've run to the end of the loop. drop out of the loop, popping the stack
  1528.           sp = tempsp + sizeof(struct stack_for_frame);
  1529.           goto run_next_statement;
  1530.         }
  1531.       }
  1532.       // This is not the loop you are looking for... so Walk back up the stack
  1533.       tempsp += sizeof(struct stack_for_frame);
  1534.       break;
  1535.     default:
  1536.       //printf("Stack is stuffed!\n");
  1537.       goto warmstart;
  1538.     }
  1539.   }
  1540.   // Didn't find the variable we've been looking for
  1541.   goto qhow;
  1542.  
  1543. assignment:
  1544.   {
  1545.     short int value;
  1546.     short int *var;
  1547.  
  1548.     if(*txtpos < 'A' || *txtpos > 'Z')
  1549.       goto qhow;
  1550.     var = (short int *)variables_begin + *txtpos - 'A';
  1551.     txtpos++;
  1552.  
  1553.     ignore_blanks();
  1554.  
  1555.     if (*txtpos != '=')
  1556.       goto qwhat;
  1557.     txtpos++;
  1558.     ignore_blanks();
  1559.     expression_error = 0;
  1560.     value = expression();
  1561.     if(expression_error)
  1562.       goto qwhat;
  1563.     // Check that we are at the end of the statement
  1564.     if(*txtpos != NL && *txtpos != ':')
  1565.       goto qwhat;
  1566.     *var = value;
  1567.   }
  1568.   goto run_next_statement;
  1569. poke:
  1570.   {
  1571.     short int value;
  1572.     unsigned char *address;
  1573.  
  1574.     // Work out where to put it
  1575.     expression_error = 0;
  1576.     value = expression();
  1577.     if(expression_error)
  1578.       goto qwhat;
  1579.     address = (unsigned char *)value;
  1580.  
  1581.     // check for a comma
  1582.     ignore_blanks();
  1583.     if (*txtpos != ',')
  1584.       goto qwhat;
  1585.     txtpos++;
  1586.     ignore_blanks();
  1587.  
  1588.     // Now get the value to assign
  1589.     expression_error = 0;
  1590.     value = expression();
  1591.     if(expression_error)
  1592.       goto qwhat;
  1593.     //printf("Poke %p value %i\n",address, (unsigned char)value);
  1594.     // Check that we are at the end of the statement
  1595.     if(*txtpos != NL && *txtpos != ':')
  1596.       goto qwhat;
  1597.   }
  1598.   goto run_next_statement;
  1599.  
  1600. list:
  1601.   linenum = testnum(); // Retuns 0 if no line found.
  1602.  
  1603.   // Should be EOL
  1604.   if(txtpos[0] != NL)
  1605.     goto qwhat;
  1606.  
  1607.   // Find the line
  1608.   list_line = findline();
  1609.   while(list_line != program_end)
  1610.     printline();
  1611.   goto warmstart;
  1612.  
  1613. print:
  1614.   // If we have an empty list then just put out a NL
  1615.   if(*txtpos == ':' )
  1616.   {
  1617.     line_terminator();
  1618.     txtpos++;
  1619.     goto run_next_statement;
  1620.   }
  1621.   if(*txtpos == NL)
  1622.   {
  1623.     goto execnextline;
  1624.   }
  1625.  
  1626.   while(1)
  1627.   {
  1628.     ignore_blanks();
  1629.     if(print_quoted_string())
  1630.     {
  1631.       ;
  1632.     }
  1633.     else if(*txtpos == '"' || *txtpos == '\'')
  1634.       goto qwhat;
  1635.     else
  1636.     {
  1637.       short int e;
  1638.       expression_error = 0;
  1639.       e = expression();
  1640.       if(expression_error)
  1641.         goto qwhat;
  1642.       printnum(e);
  1643.     }
  1644.  
  1645.     // At this point we have three options, a comma or a new line
  1646.     if(*txtpos == ',')
  1647.       txtpos++; // Skip the comma and move onto the next
  1648.     else if(txtpos[0] == ';' && (txtpos[1] == NL || txtpos[1] == ':'))
  1649.     {
  1650.       txtpos++; // This has to be the end of the print - no newline
  1651.       break;
  1652.     }
  1653.     else if(*txtpos == NL || *txtpos == ':')
  1654.     {
  1655.       line_terminator();        // The end of the print statement
  1656.       break;
  1657.     }
  1658.     else
  1659.       goto qwhat;      
  1660.   }
  1661.   goto run_next_statement;
  1662.  
  1663. mem:
  1664.   // memory free
  1665.   printnum(variables_begin-program_end);
  1666.   printmsg(memorymsg);
  1667. #ifdef ARDUINO
  1668. #ifdef ENABLE_EEPROM
  1669.   {
  1670.     // eprom size
  1671.     printnum( E2END+1 );
  1672.     printmsg( eeprommsg );
  1673.    
  1674.     // figure out the memory usage;
  1675.     val = ' ';
  1676.     int i;  
  1677.     for( i=0 ; (i<(E2END+1)) && (val != '\0') ; i++ ) {
  1678.       val = EEPROM.read( i );    
  1679.     }
  1680.     printnum( (E2END +1) - (i-1) );
  1681.    
  1682.     printmsg( eepromamsg );
  1683.   }
  1684. #endif /* ENABLE_EEPROM */
  1685. #endif /* ARDUINO */
  1686.   goto run_next_statement;
  1687.  
  1688.  
  1689.   /*************************************************/
  1690.  
  1691. #ifdef ARDUINO
  1692. awrite: // AWRITE <pin>,val
  1693. dwrite:
  1694.   {
  1695.     short int pinNo;
  1696.     short int value;
  1697.     unsigned char *txtposBak;
  1698.  
  1699.     // Get the pin number
  1700.     expression_error = 0;
  1701.     pinNo = expression();
  1702.     if(expression_error)
  1703.       goto qwhat;
  1704.  
  1705.     // check for a comma
  1706.     ignore_blanks();
  1707.     if (*txtpos != ',')
  1708.       goto qwhat;
  1709.     txtpos++;
  1710.     ignore_blanks();
  1711.  
  1712.  
  1713.     txtposBak = txtpos;
  1714.     scantable(highlow_tab);
  1715.     if(table_index != HIGHLOW_UNKNOWN)
  1716.     {
  1717.       if( table_index <= HIGHLOW_HIGH ) {
  1718.         value = 1;
  1719.       }
  1720.       else {
  1721.         value = 0;
  1722.       }
  1723.     }
  1724.     else {
  1725.  
  1726.       // and the value (numerical)
  1727.       expression_error = 0;
  1728.       value = expression();
  1729.       if(expression_error)
  1730.         goto qwhat;
  1731.     }
  1732.     pinMode( pinNo, OUTPUT );
  1733.     if( isDigital ) {
  1734.       digitalWrite( pinNo, value );
  1735.     }
  1736.     else {
  1737.       analogWrite( pinNo, value );
  1738.     }
  1739.   }
  1740.   goto run_next_statement;
  1741. #else
  1742. pinmode: // PINMODE <pin>, I/O
  1743. awrite: // AWRITE <pin>,val
  1744. dwrite:
  1745.   goto unimplemented;
  1746. #endif
  1747.  
  1748.   /*************************************************/
  1749. files:
  1750.   // display a listing of files on the device.
  1751.   // version 1: no support for subdirectories
  1752.  
  1753. #ifdef ENABLE_FILEIO
  1754.     cmd_Files();
  1755.   goto warmstart;
  1756. #else
  1757.   goto unimplemented;
  1758. #endif // ENABLE_FILEIO
  1759.  
  1760.  
  1761. chain:
  1762.   runAfterLoad = true;
  1763.  
  1764. load:
  1765.   // clear the program
  1766.   program_end = program_start;
  1767.  
  1768.   // load  a file into memory
  1769. #ifdef ENABLE_FILEIO
  1770.   {
  1771.     unsigned char *filename;
  1772.  
  1773.     // Work out the filename
  1774.     expression_error = 0;
  1775.     filename = filenameWord();
  1776.     if(expression_error)
  1777.       goto qwhat;
  1778.  
  1779. #ifdef ARDUINO
  1780.     // Arduino specific
  1781.     if( !SD.exists( (char *)filename ))
  1782.     {
  1783.       printmsg( sdfilemsg );
  1784.     }
  1785.     else {
  1786.  
  1787.       fp = SD.open( (const char *)filename );
  1788.       inStream = kStreamFile;
  1789.       inhibitOutput = true;
  1790.     }
  1791. #else // ARDUINO
  1792.     // Desktop specific
  1793. #endif // ARDUINO
  1794.     // this will kickstart a series of events to read in  the file.
  1795.  
  1796.   }
  1797.   goto warmstart;
  1798. #else // ENABLE_FILEIO
  1799.   goto unimplemented;
  1800. #endif // ENABLE_FILEIO
  1801.  
  1802.  
  1803.  
  1804. save:
  1805.   // save  memory out to a file
  1806. #ifdef ENABLE_FILEIO
  1807.   {
  1808.     unsigned char *filename;
  1809.  
  1810.     // Work out the filename
  1811.     expression_error = 0;
  1812.     filename = filenameWord();
  1813.     if(expression_error)
  1814.       goto qwhat;
  1815.  
  1816. #ifdef ARDUINO
  1817.     // remove the old file if it exists
  1818.     if( SD.exists( (char *)filename )) {
  1819.       SD.remove( (char *)filename );
  1820.     }
  1821.  
  1822.     // open the file, switch over to file output
  1823.     fp = SD.open( (const char *)filename, FILE_WRITE );
  1824.     outStream = kStreamFile;
  1825.  
  1826.     // copied  "List"
  1827.     list_line = findline();
  1828.     while(list_line != program_end)
  1829.       printline();
  1830.  
  1831.     // go back to standard output, close the file
  1832.     outStream = kStreamSerial;
  1833.  
  1834.     fp.close();
  1835. #else // ARDUINO
  1836.     // desktop
  1837. #endif // ARDUINO
  1838.     goto warmstart;
  1839.   }
  1840. #else // ENABLE_FILEIO
  1841.   goto unimplemented;
  1842. #endif // ENABLE_FILEIO
  1843.  
  1844. rseed:
  1845.   {
  1846.     short int value;
  1847.  
  1848.     //Get the pin number
  1849.     expression_error = 0;
  1850.     value = expression();
  1851.     if(expression_error)
  1852.       goto qwhat;
  1853.  
  1854. #ifdef ARDUINO
  1855.     randomSeed( value );
  1856. #else // ARDUINO
  1857.     srand( value );
  1858. #endif // ARDUINO
  1859.     goto run_next_statement;
  1860.   }
  1861.  
  1862. #ifdef ENABLE_TONES
  1863. tonestop:
  1864.   noTone( kPiezoPin );
  1865.   goto run_next_statement;
  1866.  
  1867. tonegen:
  1868.   {
  1869.     // TONE freq, duration
  1870.     // if either are 0, tones turned off
  1871.     short int freq;
  1872.     short int duration;
  1873.  
  1874.     //Get the frequency
  1875.     expression_error = 0;
  1876.     freq = expression();
  1877.     if(expression_error)
  1878.       goto qwhat;
  1879.  
  1880.     ignore_blanks();
  1881.     if (*txtpos != ',')
  1882.       goto qwhat;
  1883.     txtpos++;
  1884.     ignore_blanks();
  1885.  
  1886.  
  1887.     //Get the duration
  1888.     expression_error = 0;
  1889.     duration = expression();
  1890.     if(expression_error)
  1891.       goto qwhat;
  1892.  
  1893.     if( freq == 0 || duration == 0 )
  1894.       goto tonestop;
  1895.  
  1896.     tone( kPiezoPin, freq, duration );
  1897.     if( alsoWait ) {
  1898.       delay( duration );
  1899.       alsoWait = false;
  1900.     }
  1901.     goto run_next_statement;
  1902.   }
  1903. #endif /* ENABLE_TONES */
  1904. }
  1905.  
  1906. // returns 1 if the character is valid in a filename
  1907. static int isValidFnChar( char c )
  1908. {
  1909.   if( c >= '0' && c <= '9' ) return 1; // number
  1910.   if( c >= 'A' && c <= 'Z' ) return 1; // LETTER
  1911.   if( c >= 'a' && c <= 'z' ) return 1; // letter (for completeness)
  1912.   if( c == '_' ) return 1;
  1913.   if( c == '+' ) return 1;
  1914.   if( c == '.' ) return 1;
  1915.   if( c == '~' ) return 1;  // Window~1.txt
  1916.  
  1917.   return 0;
  1918. }
  1919.  
  1920. unsigned char * filenameWord(void)
  1921. {
  1922.   // SDL - I wasn't sure if this functionality existed above, so I figured i'd put it here
  1923.   unsigned char * ret = txtpos;
  1924.   expression_error = 0;
  1925.  
  1926.   // make sure there are no quotes or spaces, search for valid characters
  1927.   //while(*txtpos == SPACE || *txtpos == TAB || *txtpos == SQUOTE || *txtpos == DQUOTE ) txtpos++;
  1928.   while( !isValidFnChar( *txtpos )) txtpos++;
  1929.   ret = txtpos;
  1930.  
  1931.   if( *ret == '\0' ) {
  1932.     expression_error = 1;
  1933.     return ret;
  1934.   }
  1935.  
  1936.   // now, find the next nonfnchar
  1937.   txtpos++;
  1938.   while( isValidFnChar( *txtpos )) txtpos++;
  1939.   if( txtpos != ret ) *txtpos = '\0';
  1940.  
  1941.   // set the error code if we've got no string
  1942.   if( *ret == '\0' ) {
  1943.     expression_error = 1;
  1944.   }
  1945.  
  1946.   return ret;
  1947. }
  1948.  
  1949. /***************************************************************************/
  1950. static void line_terminator(void)
  1951. {
  1952.   outchar(NL);
  1953.   outchar(CR);
  1954. }
  1955.  
  1956. /***********************************************************/
  1957. void setup()
  1958. {
  1959. #ifdef ARDUINO
  1960.   Serial.begin(kConsoleBaud);   // opens serial port
  1961.   while( !Serial ); // for Leonardo
  1962.  
  1963.   keyboard.begin(DataPin, IRQpin); //----------------------------------------------------------------------------------------------------------------
  1964.   //Serial.println("Keyboard Test:");
  1965.  
  1966.   //Serial.println( sentinel );
  1967.   printmsg(initmsg);
  1968.  
  1969. #ifdef ENABLE_FILEIO
  1970.   initSD();
  1971.  
  1972. #ifdef ENABLE_AUTORUN
  1973.   if( SD.exists( kAutorunFilename )) {
  1974.     program_end = program_start;
  1975.     fp = SD.open( kAutorunFilename );
  1976.     inStream = kStreamFile;
  1977.     inhibitOutput = true;
  1978.     runAfterLoad = true;
  1979.   }
  1980. #endif /* ENABLE_AUTORUN */
  1981.  
  1982. #endif /* ENABLE_FILEIO */
  1983.  
  1984. #ifdef ENABLE_EEPROM
  1985. #ifdef ENABLE_EAUTORUN
  1986.   // read the first byte of the eeprom. if it's a number, assume it's a program we can load
  1987.   int val = EEPROM.read(0);
  1988.   if( val >= '0' && val <= '9' ) {
  1989.     program_end = program_start;
  1990.     inStream = kStreamEEProm;
  1991.     eepos = 0;
  1992.     inhibitOutput = true;
  1993.     runAfterLoad = true;
  1994.   }
  1995. #endif /* ENABLE_EAUTORUN */
  1996. #endif /* ENABLE_EEPROM */
  1997.  
  1998. #endif /* ARDUINO */
  1999. }
  2000.  
  2001.  
  2002. /***********************************************************/
  2003. static unsigned char breakcheck(void)
  2004. {
  2005. #ifdef ARDUINO
  2006.   if(Serial.available())
  2007.     return Serial.read() == CTRLC;
  2008.   return 0;
  2009. #else
  2010. #ifdef __CONIO__
  2011.   if(kbhit())
  2012.     return getch() == CTRLC;
  2013.   else
  2014. #endif
  2015.     return 0;
  2016. #endif
  2017. }
  2018. /***********************************************************/
  2019. static int inchar()
  2020. {
  2021.   int v;
  2022. #ifdef ARDUINO
  2023.  
  2024.   switch( inStream ) {
  2025.   case( kStreamFile ):
  2026. #ifdef ENABLE_FILEIO
  2027.     v = fp.read();
  2028.     if( v == NL ) v=CR; // file translate
  2029.     if( !fp.available() ) {
  2030.       fp.close();
  2031.       goto inchar_loadfinish;
  2032.     }
  2033.     return v;    
  2034. #else
  2035. #endif
  2036.      break;
  2037.   case( kStreamEEProm ):
  2038. #ifdef ENABLE_EEPROM
  2039. #ifdef ARDUINO
  2040.     v = EEPROM.read( eepos++ );
  2041.     if( v == '\0' ) {
  2042.       goto inchar_loadfinish;
  2043.     }
  2044.     return v;
  2045. #endif
  2046. #else
  2047.     inStream = kStreamSerial;
  2048.     return NL;
  2049. #endif
  2050.      break;
  2051.   case( kStreamSerial ):
  2052.   default:
  2053.     while(1)
  2054.     {
  2055.      
  2056.      //----------- the following is the key modification -------------------------------------------------------------------------------------------------
  2057.      //----------- where the code get the variables  the PS2 keyboard --------------------------------------------------------------------------------
  2058.      //----------- and treat them as the ones  the PC keyboard ---------------------------------------------------------------------------------------
  2059.  
  2060.      if (keyboard.available()) {
  2061.        // read the next key
  2062.        char c = keyboard.read();
  2063.        //Serial.print(c);
  2064.        return c;
  2065.      }
  2066.      //------------ end of modification -------------------------------------------------------------------------------------------------------------------
  2067.      
  2068.      if(Serial.available())
  2069.      return Serial.read();
  2070.  
  2071.     }
  2072.   }
  2073.  
  2074. inchar_loadfinish:
  2075.   inStream = kStreamSerial;
  2076.   inhibitOutput = false;
  2077.  
  2078.   if( runAfterLoad ) {
  2079.     runAfterLoad = false;
  2080.     triggerRun = true;
  2081.   }
  2082.   return NL; // trigger a prompt.
  2083.  
  2084. #else
  2085.   // otherwise. desktop!
  2086.   int got = getchar();
  2087.  
  2088.   // translation for desktop systems
  2089.   if( got == LF ) got = CR;
  2090.  
  2091.   return got;
  2092. #endif
  2093. }
  2094.  
  2095. /***********************************************************/
  2096. static void outchar(unsigned char c)
  2097. {
  2098.   if( inhibitOutput ) return;
  2099.  
  2100. #ifdef ARDUINO
  2101.   #ifdef ENABLE_FILEIO
  2102.     if( outStream == kStreamFile ) {
  2103.       // output to a file
  2104.       fp.write( c );
  2105.     }
  2106.     else
  2107.   #endif
  2108.   #ifdef ARDUINO
  2109.   #ifdef ENABLE_EEPROM
  2110.     if( outStream == kStreamEEProm ) {
  2111.       EEPROM.write( eepos++, c );
  2112.     }
  2113.     else
  2114.   #endif /* ENABLE_EEPROM */
  2115.   #endif /* ARDUINO */
  2116.     Serial.write(c);
  2117.  
  2118. #else
  2119.   putchar(c);
  2120. #endif
  2121. }
  2122.  
  2123. /***********************************************************/
  2124. /* SD Card helpers */
  2125.  
  2126. #if ARDUINO && ENABLE_FILEIO
  2127.  
  2128. static int initSD( void )
  2129. {
  2130.   // if the card is already initialized, we just go with it.
  2131.   // there is no support (yet?) for hot-swap of SD Cards. if you need to
  2132.   // swap, pop the card, reset the arduino.)
  2133.  
  2134.   if( sd_is_initialized == true ) return kSD_OK;
  2135.  
  2136.   // due to the way the SD Library works, pin 10 always needs to be
  2137.   // an output, even when your shield uses another line for CS
  2138.   pinMode(10, OUTPUT); // change this to 53 on a mega
  2139.  
  2140.   if( !SD.begin( kSD_CS )) {
  2141.     // failed
  2142.     printmsg( sderrormsg );
  2143.     return kSD_Fail;
  2144.   }
  2145.   // success - quietly return 0
  2146.   sd_is_initialized = true;
  2147.  
  2148.   // and our file redirection flags
  2149.   outStream = kStreamSerial;
  2150.   inStream = kStreamSerial;
  2151.   inhibitOutput = false;
  2152.  
  2153.   return kSD_OK;
  2154. }
  2155. #endif
  2156.  
  2157. #if ENABLE_FILEIO
  2158. void cmd_Files( void )
  2159. {
  2160.   File dir = SD.open( "/" );
  2161.   dir.seek(0);
  2162.  
  2163.   while( true ) {
  2164.     File entry = dir.openNextFile();
  2165.     if( !entry ) {
  2166.       entry.close();
  2167.       break;
  2168.     }
  2169.  
  2170.     // common header
  2171.     printmsgNoNL( indentmsg );
  2172.     printmsgNoNL( (const unsigned char *)entry.name() );
  2173.     if( entry.isDirectory() ) {
  2174.       printmsgNoNL( slashmsg );
  2175.     }
  2176.  
  2177.     if( entry.isDirectory() ) {
  2178.       // directory ending
  2179.       for( int i=strlen( entry.name()) ; i<16 ; i++ ) {
  2180.         printmsgNoNL( spacemsg );
  2181.       }
  2182.       printmsgNoNL( dirextmsg );
  2183.     }
  2184.     else {
  2185.       // file ending
  2186.       for( int i=strlen( entry.name()) ; i<17 ; i++ ) {
  2187.         printmsgNoNL( spacemsg );
  2188.       }
  2189.       printUnum( entry.size() );
  2190.     }
  2191.     line_terminator();
  2192.     entry.close();
  2193.   }
  2194.   dir.close();
  2195. }
  2196. #endif

A hibaüzenet:
Idézet:
„In file included C:\Documents and Settings\Krisztián\Local Settings\Temp\TinyBasicPlus_PS2_VGAx-1\TinyBasicPlus_PS2_VGAx-1.ino:170:0:

C:\Documents and Settings\Krisztián\Dokumentumok\Arduino\libraries\PS2Keyboard-master/PS2Keyboard.h:32:22: fatal error: WProgram.h: No such file or directory

#include "WProgram.h"

^

compilation terminated.

exit status 1
Hiba a(z) Arduino/Genuino Uno alaplapra fordításra.


Arduino 1.8.4-et használok.
(#) kokozo válasza krauszkrisztian hozzászólására (») Máj 3, 2018 /
 
Szia!
Nem lehet hogy az ékezetes könyvtár miatt van baja?
Krisztián\
(#) krauszkrisztian válasza kokozo hozzászólására (») Máj 3, 2018 /
 
Nem hiszem.
(#) kapu48 válasza krauszkrisztian hozzászólására (») Máj 3, 2018 /
 
Ha nem hallgatsz a jó tanácsokra? Akkor reménytelen eset vagy!

Használj: arduino1.6.5-öst. És ne legyen ékezet az elérési útban. (Csak az angol ABC betüi!)
A hozzászólás módosítva: Máj 3, 2018
(#) krauszkrisztian válasza kapu48 hozzászólására (») Máj 3, 2018 /
 
a Krisztián az a ,,User" megfelelője.
Telepítésnél ezt a nevet adtam meg.
Nem lehet átnevezni.
(#) kapu48 válasza krauszkrisztian hozzászólására (») Máj 3, 2018 /
 
Dehogynem több féle módja is lehetséges.

Létrehozol még 1 usert ékezet nélkül, és azt adod meg útvonalnak.
arduino>fájl>beállítások>Vázlatfüzet helye: C:\Documents and Settings\Krisztian\Dokumentumok\Arduino

Vagy csak egyszerűen létrehozol tetszőleges útvonalat és azt adod meg.
És átpakolsz ide mindent.

És a programod 25. sorában írja:
Idézet:
„// v0.13: 2013-03-04
// Support for Arduino 1.5 !!!”
A hozzászólás módosítva: Máj 3, 2018
(#) vargham válasza krauszkrisztian hozzászólására (») Máj 3, 2018 /
 
Tilos ékezetes felhasználónevet megadni. Vannak programok, amik nem tudják kezelni. Az Arduino is ilyen. Én csináltam új felhasználót, és töröltem a régit.
(#) kapu48 válasza krauszkrisztian hozzászólására (») Máj 3, 2018 /
 
  1. A programod 1059. sorától vannak hiányosságok!
  2.   // If a line with that number exists, then remove it
  3.   if(start != program_end && *((LINENUM *)start) == linenum)
  4.   {
  5.     unsigned char *dest, *; <Név nélküli pointer???
  6.     unsigned tomove;< Mi a változó típusa???
  7.  
  8.      = start + start[sizeof(LINENUM)];<Minek ad értéket???
  9.     dest = start;
  10.  
  11.     tomove = program_end - ;<Mit von ki belőle???
  12.     while( tomove > 0)
  13.     {
  14.       *dest = *;<Nincsen neve a pointernek???
  15.       ++;<Minek növeli az értékét???
  16.       dest++;
  17.       tomove--;
  18.     }  
  19.     program_end = dest;
  20.   }
(#) krauszkrisztian válasza kapu48 hozzászólására (») Máj 3, 2018 /
 
Az nem tetszik neki?
(#) kapu48 válasza krauszkrisztian hozzászólására (») Máj 3, 2018 /
 
Ezeket pótolod.
És a PS2Kelyboard.h 29. sorától megjegyzésbe rakod a sorokat.
Ahogy itt csináltam:
  1. //#if defined(ARDUINO) && ARDUINO >= 100
  2. #include "Arduino.h" // for attachInterrupt, FALLING
  3. //#else
  4. //#include "WProgram.h"
  5. //#endif

Akkor lefordul.
Már csak az a kérdés, hogy ennyi javítgatás után működik e?
(#) krauszkrisztian válasza krauszkrisztian hozzászólására (») Máj 3, 2018 /
 
Mindegy, akkor lemondok a projektről.
Köszönöm a kapott válaszokat!
(#) kapu48 válasza krauszkrisztian hozzászólására (») Máj 3, 2018 /
 
De hamar feladtad!
Én így javítottam:
  1. // If a line with that number exists, then remove it
  2.   if(start != program_end && *((LINENUM *)start) == linenum)
  3.   {
  4.     unsigned char *dest, *source;
  5.     unsigned char tomove;
  6.  
  7.     source = start + start[sizeof(LINENUM)];
  8.     dest = start;
  9.  
  10.     tomove = program_end - source;
  11.     while( tomove > 0)
  12.     {
  13.       *dest = *source;
  14.       source++;
  15.       dest++;
  16.       tomove--;
  17.     }  
  18.     program_end = dest;
  19.   }


És ez az eredmény:
Idézet:
„Sketch uses 9 356 bytes (29%) of program storage space. Maximum is 32 256 bytes.
Global variables use 1 512 bytes (73%) of dynamic memory, leaving 536 bytes for local variables. Maximum is 2 048 bytes.

Vagyis sikerült lefordítani.
(#) krauszkrisztian válasza kapu48 hozzászólására (») Máj 3, 2018 /
 
De honnan tudta, hogy miket kellett a hiányzó helyekre beírni?
(#) kapu48 válasza krauszkrisztian hozzászólására (») Máj 3, 2018 /
 
Próbáltam értelmezni a program részletet.

Ami 1 beirt, sort mozgatna át a helyére (karakterenként).

Mivel a cél cím mutató megvolt (*dest), a forrás pointer hiányzott, ez lett a (*source).
Ezek után értelem szerűen próbáltam pótolni a hiányzó részeket.
(#) krauszkrisztian válasza kapu48 hozzászólására (») Máj 3, 2018 /
 
Egyébként nem akartam lemondani az egészről, csak nyilván nem várhatom el másoktól, hogy ellenőrizgessék a 3ezer soros kódomat.
(#) krauszkrisztian válasza krauszkrisztian hozzászólására (») Máj 3, 2018 /
 
Köszönöm a fáradtságot.
A WProgram.h fájlt meg azért nem találtam, mert rossz könyvtárat néztem...
(#) kapu48 válasza krauszkrisztian hozzászólására (») Máj 3, 2018 /
 
Bevallom, nem olvastam át a 3000 sort.

Csak próbáltam azt a pár hibát javítani, amit a fordító kidobott.

Látható, hogy eredetileg „TinyBasic Plus”-ban írták a kódot.
És valaki át buherálta arduinora.

Ha készen van a cél HW.? Érdemes lenne tesztelni.
(#) krauszkrisztian válasza kapu48 hozzászólására (») Máj 3, 2018 /
 
Milyen HW.?
(#) kapu48 válasza krauszkrisztian hozzászólására (») Máj 3, 2018 /
 
Ami a linkben a képen van: Bővebben: Link
(#) krauszkrisztian válasza kapu48 hozzászólására (») Máj 3, 2018 /
 
Bocsi, de melyik képen?
(#) kapu48 válasza krauszkrisztian hozzászólására (») Máj 3, 2018 /
 
A linken:Lent a README.md ben

Bilentyű csatlakozó illesztése az arduinohoz + USB soros illesztés a PC monitorhoz.
A hozzászólás módosítva: Máj 3, 2018
(#) krauszkrisztian válasza kapu48 hozzászólására (») Máj 3, 2018 /
 
Igen.
Már a VGA programja is megvan, fel is töltöttem.
Már csak kettő 68Ohm-os ellenállást kell valahonnan kerítenem, meg kettő 470Ohm-osat.
A VGA aljzat és a PS2 aljzat megvan.
(#) kokike28 hozzászólása Máj 5, 2018 /
 
Sziasztok. Van egy arduino uno r3 lapom és hozzá egy 2,8-as tft kijelzõ Bővebben: Linkegy olyan problémám lenne hogy bármilyen tesztet töltök fel rá tükör irásal látszik minden. Tud valaki segiteni hogy normálisan látszódjon rajta minden, és ne tükrözõdve ?

Köszönöm elõre is.
(#) Kovidivi válasza kokike28 hozzászólására (») Máj 5, 2018 /
 
Nézd át a lib-ed, valószínűleg van benne egy display_mirror vagy hasonló függvény. Azt hívd meg, ha kell a megfelelő értékkel disp_mirror(1), vagy amit kíván. Kicsit keresgélni kell, olvasgatni, konkrét megoldást nem tudok írni.
Következő: »»   445 / 852
Bejelentkezés

Belépés

Hirdetés
XDT.hu
Az oldalon sütiket használunk a helyes működéshez. Bővebb információt az adatvédelmi szabályzatban olvashatsz. Megértettem