Skip to content
Browse files

Desktop build for gcc/command line

  • Loading branch information...
1 parent f3ba7e8 commit db8153b45f56e8983c71ef60fd92ccacc12ecc14 @BleuLlama committed Sep 20, 2012
Showing with 102 additions and 2 deletions.
  1. +22 −2 Arduino/TinyBasicPlus.ino
  2. +67 −0 cli/GNUmakefile
  3. +13 −0 cli/main.cpp
View
24 Arduino/TinyBasicPlus.ino
@@ -7,6 +7,9 @@
//
+// v0.04: 2012-09-20
+// Updated for building desktop command line app
+//
// v0.03: 2012-09-19
// Integrated Jürg Wullschleger's whitespace,unary fix
// Now available through github
@@ -32,6 +35,11 @@ char eliminateCompileErrors = 1; // fix to suppress arduino build errors
#define ARDUINO 1
+// hack to let makefiles work with this file unchanged
+#ifdef FORCE_DESKTOP
+#undef ARDUINO
+#endif
+
////////////////////////////////////////////////////////////////////////////////
// Feature configuration...
@@ -68,6 +76,7 @@ char eliminateCompileErrors = 1; // fix to suppress arduino build errors
#else
// Not arduino setup
+ #include <stdio.h>
// size of our program ram
#define kRamSize 4096
@@ -78,6 +87,7 @@ char eliminateCompileErrors = 1; // fix to suppress arduino build errors
// ASCII Characters
#define CR '\r'
#define NL '\n'
+#define LF 0x0a
#define TAB '\t'
#define BELL '\b'
#define SPACE ' '
@@ -222,7 +232,7 @@ static const unsigned char okmsg[] = "OK";
static const unsigned char whatmsg[] = "What? ";
static const unsigned char howmsg[] = "How?";
static const unsigned char sorrymsg[] = "Sorry!";
-static const unsigned char initmsg[] = "TinyBasic Plus V0.03";
+static const unsigned char initmsg[] = "TinyBasic Plus V0.04";
static const unsigned char memorymsg[] = " bytes free.";
static const unsigned char breakmsg[] = "break!";
static const unsigned char unimplimentedmsg[] = "Unimplemented";
@@ -1395,16 +1405,19 @@ static unsigned char breakcheck(void)
return Serial.read() == CTRLC;
return 0;
#else
+#ifdef __CONIO__
if(kbhit())
return getch() == CTRLC;
else
+#endif
return 0;
#endif
}
/***********************************************************/
static int inchar()
{
#if ARDUINO
+ // 1. FILE INPUT
#if ENABLE_FILEIO
if( inFromFile ) {
// get content from a file until it's empty
@@ -1417,6 +1430,7 @@ static int inchar()
return v;
} else {
#endif
+ // 2. SERIAL INPUT
while(1)
{
if(Serial.available())
@@ -1426,7 +1440,13 @@ static int inchar()
}
#endif
#else
- return getchar();
+ // 3. CONSOLE INPUT
+ int got = getchar();
+
+ // translation for desktop systems
+ if( got == LF ) got = CR;
+
+ return got;
#endif
}
View
67 cli/GNUmakefile
@@ -0,0 +1,67 @@
+#
+# makefile for command line TinyBasicPlus
+# (basic input version)
+#
+# requires GCC tools
+#
+# tested on OS X, MinGW
+# (we will autoconfigure for the right platform)
+
+
+########################################
+export ARCH := $(shell uname)
+ifeq ($(ARCH),MINGW32_NT-5.1)
+ # Win XP
+ export ARCH := MINGW
+endif
+ifeq ($(ARCH),MINGW32_NT-5.2)
+ # Server 2003
+ export ARCH := MINGW
+endif
+ifeq ($(ARCH),MINGW32_NT-6.1)
+ # Windows 7
+ export ARCH := MINGW
+endif
+
+# mingw will be: MINGW
+# os x will be: Darwin
+
+
+ifeq ($(ARCH),MINGW)
+export EXEEXT := .exe
+3lse
+export EXEEXT :=
+endif
+
+export CXXFLAGS += -DFORCE_DESKTOP
+
+export CXX := g++
+export CC := gcc
+
+########################################
+PROG := tbp$(EXEEXT)
+
+SRCS := TinyBasicPlus.cpp \
+ main.cpp
+
+OBJS := $(SRCS:%.cpp=%.o)
+
+all: $(PROG)
+
+$(PROG): TinyBasicPlus.o main.o
+ @echo link $@
+ @$(CXX) $(CXXFLAGS) $^ $(LDFLAGS) $(LIBS) -o $@
+
+
+TinyBasicPlus.cpp: ../Arduino/TinyBasicPlus.ino
+ @echo copy $< to $@
+ @cp $< $@
+
+%.o: %.cpp
+ @echo compile $<
+ @$(CXX) $(CXXFLAGS) $(DEFS) -c -o $@ $<
+
+clean:
+ @echo removing generated files
+ @-rm -f $(OBJS) $(PROG) TinyBasicPlus.cpp
+.PHONY: clean
View
13 cli/main.cpp
@@ -0,0 +1,13 @@
+#include <stdio.h>
+
+void setup( void );
+void loop( void );
+
+int main( int argc, char ** argv )
+{
+ printf( "Starting up TinyBasic Plus...\n\n" );
+
+ setup();
+ while( 1 )
+ loop();
+}

0 comments on commit db8153b

Please sign in to comment.
Something went wrong with that request. Please try again.