Welcome to Next Byte Codes and Not eXactly C
Next Byte Codes (NBC) is a simple language with an assembly language syntax that can be
used to program LEGO's NXT programmable brick (from the new LEGO Mindstorms NXT set).
Not eXactly C (NXC) is a high level language, similar to C, built on top of the
NBC compiler. It can also be used to program the NXT brick. NXC is basically NQC for the NXT.
To compile NXC programs just use the NBC compiler with source code files that have a .nxc
file extension.
 |
If you are just getting started with programming, then graphical
environments such as the Mindstorms NXT software may be
better choices for you. If, however, you're a programmer and you prefer typing a
few lines to drag and drop icon programming, then either NBC or NXC may be perfect for
you.
NBC/NXC is free software released under the Mozilla Public License (MPL).
Download the NBC Guide for detailed
information about the NBC language.
A reference guide for NXC is also available.
Donations to NBC and NXC will be used toward developing support for additional platforms.
To take advantage of multi-dimensional array support and native shift and wait operations
be sure to download the enhanced NBC/NXC firmware and install it on your NXT.
|
|
|
News
November 25, 2007 - NBC 1.0.1.b34 beta is available.
- Fixes typo bugs in the math API functions introduced in b33.
November 5, 2007 - NBC 1.0.1.b33 beta is available.
- See history.txt for a list of all the fixes in this release.
August 10, 2007 - NBC 1.0.1.b32 beta is available.
- Fixes a couple NXC system call structure definition bugs.
- Adds compchktype compile-time opcode for checking variable types in preprocessor
macros.
- Changes low-level NXC syscall inline functions to use preprocessor macros with
type checking instead (for improved code efficiency).
- Fixes an access violation when trying to compile user-defined type references
which include invalid member names.
- Allows array opcodes to take constant array arguments
- Reworked low level IOMap read and write NXC API functions to allow non-constant
arguments for ports, etc...
- Fixed a bug in RotateMotor functions which can cause it to hang if another task
changes the power level while the function is waiting for the target tacho limit
to be reached.
- Fixed a bug in I2CBytes and SensorUS and the NBC equivalents which made the
functions not work for constant port values for ports 3 and 4.
- Fixes a bug in variable and parameter name decoration which made task & function
names containing an underscore not work correctly in some situations.
July 13, 2007 - NBC 1.0.1.b31 beta is available.
- Fixes a boolean expression bug which occurred when you used a numeric variable
or constant on its own in a logical AND operation. (e.g., if (Nsamps && x < 3)).
- Fixes problems with reference type arguments that are arrays or user-defined
types.
- Fixes problems where the compiler hangs while processing function parameters.
- Fixes several other struct and array parameter passing problems.
- Fixes NXTDefs.h typo bug in ResetAllTachoCounts.
- Fixes NXCDefs.h typo bug in I2CStatus.
- Tightened up semicolon checking so that the parser complains when they are
required but they are missing.
- Fixed global array initialize when a length expression is specified and an
initial value is also specified. The length, in that case, is now ignored
since the array is statically initialized.
- Fixed a problem with initializing multi-dimensional global or local arrays
where the generated nested variable type declaration was causing an NBC
compiler error.
- Improved parsing of open and close parenthesis so that the compiler will
complain if you have an extra close parenthesis.
- Added code in the NXC compiler to initialize a hidden graphic variables
array and use it when calling the GraphicOut API function so that
parameterized RIC files can be drawn using either GraphicOut or GraphicOutEx.
- Added support in NBC for RICScript programs which can be used to create
RIC files via a simple text programming language. A source file with a .rs
extension will use the RICScript compiler built into NBC and the output will
be a .ric file if there are no compiler errors.
- Adds the "safecall" keyword to NXC. A function or subroutine declared with
this keyword will automatically be wrapped in Acquire/Release with a global
mutex specific to that function so that multiple threads can safely call the
function without hanging.
- Adds the -safecall command line switch for NXC. If a program is compiled with
this switch on the command line then all function calls will use the safecall
calling convention, i.e., they will be wrapped in Acquire/Release so that
multiple tasks/threads can share the subroutine safely.
- Fixes inline functions so that they are now thread-safe.
- Added code to the parser to complain about recursive function calls
since they are not supported by the NXT firmware.
- Added code to the parser to complain about calling an inline function from
another inline function call.
- Fixed a for-loop local variable nesting level bug that made for-loop variables
not work correctly if defined within the for-loop parenthesis.
- Added NXC/NBC API function I2CCheckStatus and LowspeedCheckStatus which only
return the status (and not bytes ready). Added I2CBytesReady and
LowspeedBytesReady which only return the number of bytes ready but not the
status. (NBC does not include the I2C alias versions).
- Added constants and structure declarations for enhanced firmware features
in lms_arm_jch.zip. If using the enhanced standard NXT firmware make sure
to pass -EF on the NBC/NXC command line.
- Fixes a bug in struct declarations which was causing the compiler to not
support types with the "unsigned" type qualifier keyword prior to the type
name.
- Added several low-level syscall inline functions to NXC.
- Fixed type checking of function parameters that are user-defined types.
This had just been checking that the variable passed in was a UDT but it
now makes sure the two types of UDT are the same.
- Renamed ByteArrayToStr as ByteArrayToStrEx and added a new ByteArrayToStr
function that returns a string rather than requiring that the string variable
be passed into the function.
June 5, 2007 - NBC 1.0.1.b30 beta is available.
- Fixes a bug in the RotateMotorExPID macro in NXTDefs.h that was introduced
in b29.
- Fixes error message line number problems in NBC that were introduced in b29.
- Added NXC compiler error message when trying to use nested calls to the same
function (e.g., Max(3, Max(5, 6)).
- Fixes an expression optimizer bug which was intrepeting variables that looked
like valid hexadecimal numbers as a constant value (e.g., xa0, x1, x03, xff).
- Fixes a bug in the NXC compiler's support for function prototypes that was
introduced in b29.
- Adds support in NXC for the "return" statement to have optional parenthesis
around the return expression when the return type is string. Scalar types already
support surrounding parenthesis as part of the expression parsing.
- Fixes a bug in the NBC compiler support for compif/compelse/compend where
code that should have been ignored by the compiler was not being ignored.
- Fixes a bug in ## handling within non-parameterized preprocessor macros.
- *** NXC & NBC BREAKING CHANGE *** Changed the RotateMotorEx API functions
(in b29, actually) to take an additional boolean parameter.
RotateMotorExPID(ports, pwr, angle, turnpct, bsync, bStop, p, i, d)
RotateMotorEx(ports, pwr, angle, turnpct, bSync, bStop)
The new "bStop" parameter indicates whether you want the motors to come to a
hard stop at the end of the specified angle of rotation.
- Fixes NXC bug with empty strings causing a compiler error. Now empty strings
work as expected.
May 21, 2007 - NBC 1.0.1.b29 beta is available.
- Fixes a bug with not setting the left hand side datatype correctly after a user
defined type is used.
- Fixes reading a struct out of an array of struct.
- Fixes a bug in NXC switch statements that have no default case where the first case
was being improperly executed.
- Fixes a bug with initialized globals which was causing them to be treated as constants
in math expressions.
- Overhauled the I2C routines and the Motor routines. See
history.txt for details.
- Added GraphicOutEx for NXC which takes an array of values which can change the
drawing behavior at runtime.
- Changed NumOut and TextOut in NXC so they accept an optional 4th argument (cls)
which controls whether the screen is cleared or not. This makes these functions
consistant with the other drawing routines.
- Changed NumOutEx and TextOutEx in NBC so that the cls argument is the fourth
argument rather than the third argument (NumOutEx(x, y, value, cls) rather than
NumOutEx(x, y, cls, value)). This change makes these two functions consistant
with the other Ex drawing routines in NBC.
- Changed ArrayBuild in NXC so that instead of having ArrayBuild1..ArrayBuild4
defined in the NXCDefs.h header file the function is now built into the compiler
and it can take any number of source arguments.
E.G., ArrayBuild(aout, src1, ..., srcN);
- Fixed a problem in the NXC preprocessor where it was incorrectly handling char
constants (e.g., ArrayInit(aout, 'a', 10);).
- Fixed a problem in I2CBytes/ReadI2CBytes where it was returning true even when
an error occurred during the write/read operation. Now these functions return
false if any sort of error condition occurred during the I2C operation.
- Added new NXC functions which are aliases for the LowspeedStatus, LowspeedRead, and
LowspeedWrite functions. The new NXC functions are named I2CStatus, I2CRead, and
I2CWrite.
- Changed the behavior of the ## operator in the preprocessor. In previous versions
a token such as OUT_A would be left as a literal if it was concatenated with the
preceding value but in this version OUT_A will be evaluated as 0 before it is
concatenated with the preceding value. E.G., myVar##port, in previous releases
would have ended up as myVarOUT_A, but as of b29 it will end up as myVar0.
- Changed the preprocessor to evaluate tokens until no changes occur during
evaluation. As of b29 if the first preprocessor evaluation produces __rotateMotor0
as a token then it will evaluate the result again which may expand that token
into a multi-line macro function expansion. This will continue until the pre-
evaluation value matches the post-evaluation value. This change was required to
implement the motor and I2C API changes mentioned above.
- Changed the compiler to automatically include NXTDefs.h or NXCDefs.h (and
NBCCommon.h) automatically just as NQC would automatically include its API header
file. This can be disabled via the new -n command line switch. The header
files are actually compiled into the compiler executable. The contents of the
built-in header files can be extracted via the new -api command line switch. As
a result of this change it is no longer necessary to start an NBC or NXC program
with #include "NXTDefs.h" or #include "NXCDefs.h".
- Renamed the Tamas Sorosy math functions added in b28 so that they do not conflict
with the compile-time expression evaluator functions of the same names. The
new function names are Sqrt, Sin, Cos, Asin, and Acos.
- Added a -q command line switch which tells the compiler to not make the NXT beep
at the end of a program download operation.
- Changed the compiler so that, by default, it tells the NXT to beep after
downloading a program.
- Changed the compiler so that it stops any running program before starting to
download a program.
- Added compif, compelse, and compend operations to the NBC compiler so that it
can determine at compile-time whether to ignore or include certain blocks
of code. This compiler processing occurs after the preprocessor is finished.
- Fixed the NXC function parameter parser so that if an error occurs while
parsing the parameter declarations it will abort and skip to the closing
parenthesis. This had been a place where the parser could get into an
infinite loop prior to this change.
April 13, 2007 - NBC 1.0.1.b28 beta is available.
- Adds support for structs and typedefs. See struct.nxc for examples.
- Adds Tamas Sorosy math functions (sqrt, sin, cos, asin, acos) to NBC
and NXC API.
- Adds a 13 ms wait in ReadSensorUS (NBC) and SensorUS (NXC) to fix a problem
where when called in a tight loop a manual wait was needed to get correct
readings.
- Adds preprocessor support for #if, #elif, and #error.
- Adds support for alternate NXT firmwares which implement the wait and waitv
opcodes. Use the -EF switch to enable this feature.
- Adds support for short-circuit boolean expression evaluation (for && and ||
operators)
- Adds a workaround in NXC for a firmware bug in the "set" opcode which is
triggered by setting a signed long to a negative number.
- Fixes a preprocessor bug with nested #ifdefs.
- Fixes a preprocessor bug with nested function macros with empty parameter
lists.
- Fixes an optimizer bug which was generating bad code for the sign opcode.
- The NXC compiler now accepts (void) in addition to () for task declarations.
- The NXC compiler now outputs an error if the routine named "main" is declared
using a keyword other than "task".
February 17, 2007 - NBC 1.0.1.b27 beta is available.
- Adds pre-increment and pre-decrement (++i, --i) support.
- Adds support for expressions as statements
task main() { int i=23; 0x3f; +3-i; }
- Adds support for pre- and post-increment/decrement within expressions
(such as in array indexes). Increment/decrement used to only be
allowed in a statement.
- Fixes some string array indexing bugs
- Adds support for string expressions within TextOut API function
- *** NXC BREAKING CHANGE *** Removed the "cls" argument from the NumOut and
TextOut functions. To update your code to work with beta 27 you will need
to add calls to ClearScreen() wherever you previously passed "true" to this
argument and remove the additional argument from each call to one of
these API functions. The PointOut, CircleOut, LineOut, RectOut, and GraphicOut
API functions all now take cls as an optional argument with a default value of
false. Since this argument is optional it can still be used but if you
are currently passing "false" to these functions you can now remove the extra
argument.
- *** NBC BREAKING CHANGE *** Removed the "cls" argument from the NumOut, TextOut,
PointOut, CircleOut, LineOut, RectOut, and GraphicOut functions. Added NumOutEx,
TextOutEx, PointOutEx, CircleOutEx, LineOutEx, RectOutEx, and GraphicOutEx API
functions which all include the "cls" argument exactly as the non-Ex versions
did prior to beta 27. To update your code to work with beta 27 you will need
to either add calls to ClearScreen() wherever you previously passed "true" to this
argument and remove the additional argument from each call to one of the non-Ex
API functions OR you can replace your calls to the non-Ex version with calls to
the Ex version of the API function.
- Adds -w- and -w+ command line switches which let you control whether
the compiler outputs warning messages or not. The default is - which
means that warnings are not output. If you want to turn on warnings then
add the new -w+ switch to the command line.
- Fixes a mutex optimization bug which was incorrectly removing acquire/release
statements and mutex variables.
February 12, 2007 - NBC 1.0.1.b26 beta is available.
- Fixes an array indexing bug introduced in b25
- Fixes a local variable declaration bug introduced in b25
- Fixes a bug in the NXC and NBC Read API functions
- Fixes a bug in the NXC and NBC WriteLnString API function
- Adds support for asm block statements anywhere within an NXC file (not
just within a task or subroutine)
- Adds a ReadLnString API function to NBC and NXC
- Fixes a preprocessor bug where comments following a #include statement were
breaking the include
February 8, 2007 - NBC 1.0.1.b25 beta is available.
- Fixes string whitespace bug introduced in b22
- Fixes division bug where 1st operand is negative and 2nd operand is unsigned
- Fixes bugs in the NBC and NXC file I/O macros
- Adds support in NXC for string indexing
- Adds support in NXC for inline functions
- Adds support in NXC for const and reference function argument types
- Adds support in NXC for const variable declarations
- Adds support in NXC for arrays of strings
- Improves NXC parameter type checking in function calls
- Adds NBC and NXC API macros to simplify NXT<->NXT bluetooth communication
- Adds NBC and NXC API macros for sending direct commands to another NXT
January 29, 2007 - NBC 1.0.1.b24 beta is available.
- Fixes a preprocessor bug in NBC and NXC that is triggered by not having a ')'
at the end of a macro invocation (or anywhere following in the entire program).
- Replaced the ResetMotor macros in NBC and NXC with ResetTachoCount(p),
ResetBlockTachoCount(p), ResetRotationCount(p), and ResetAllTachoCounts(p)
- Added NBC and NXC API file i/o macros
- Replaced the code underlying the ReadSensorUS (NBC) and SensorUS (NXC) API
functions with a version which appears to be more reliable (and generic).
- Added NBC and NXC API "Ex" motor functions to give control over reseting rotation counters
- Added NBC and NXC "RESET" constants for the "Ex" motor functions
- Added NBC and NXC API functions which expose the PID parameters
- Added NBC and NXC API function for clearing the screen
- Added support in the NXC SetOutput function for multiple sets of field/value pairs
- Added generic I2C read/write routine for NBC and NXC
- Added NBC start opcode and NXC start statement to spawn a thread anywhere within the current thread
January 21, 2007 - NBC 1.0.1.b23 beta is available.
- Adds support in NXC for nested switch statements
- Adds support in NXC for array indexed math assignments (e.g., x[0] += 23;)
- Adds support in NXC for using true and false in asm blocks
- Adds support in NXC for local variable declarations anywhere within a function.
Local variable declarations used to be limited to the beginning of a function
block. Locals now honor nesting levels and go out of scope if they are declared
within a block statement. "for" loops can now declare a local or use an existing
variable.
- Adds support in NXC for empty for loop (e.g., for ( ; ; ) ) for infinite loops
- Adds support in NXC for scalar and string local (not global) variable
initialization via expressions of any form (not just constants):
- Adds support in NXC for single-dimension global variable array initialization
using a syntax like array initialization in NBC.
- Fixes indexing of local arrays (used to only work with globals)
- Fixes a bug in the NBC sign, shl, and shr opcodes which was triggered
by passing the same variable as the first and last arguments.
January 16, 2007 - NBC 1.0.1.b22 beta is available.
- Adds support in NXC switch statements for strings, constant expressions,
character constants, and the true and false keywords
- Adds support in NBC for strings delimited by double quote characters
- Fixes several motor macros in NBC/NXC so that they reset the block count
before executing when it is appropriate for them to do so
- Fixes NXC ForceOff macro in NXCDefs.h
- Fixes the RotateMotor/RotateMotorEx macros so that programs no longer
hang when the angle is set to zero
- Fixes a problem in expressions which were not properly setting the zero
flag register variable if in a sub-expression it had already been set
January 09, 2007 - NBC 1.0.1.b21 beta is available.
- Adds NXC API macro ResetMotor(ports)
- Adds support in NXC for the ?: expression
- Adds support in NXC for the switch statement
- Adds several new NQC compatibility macros in NXCDefs.h
- Fixes an NXC shift right and shift left bug introduced in b20.
- Fixes an NXC macro subsitution bug in the "until" macro.
- Modifies GetOutput and GetInput API functions so that the port parameter no
longer accepts an expression (must be a variable or constant value)
January 06, 2007 - NBC 1.0.1.b20 beta is available.
- Adds support in NXC for string comparisons (==, !=, <=, >=, <, >)
- Adds support in NXC for function return types (int, bool, char, byte, short, long,
unsigned versions of same, and string)
- Adds support in NXC for "void" functions (synonymous with "sub").
- Adds support in NXC for comma-separated assignments in for loops.
- Fixes an NXC bug in | and ^ expressions which was putting the parser into an
infinite loop.
- Fixes an NXC bug in the subroutine calling mechanism which is triggered by leaving
off the () characters when calling the subroutine. It was causing an infinite
parser loop.
- Fixes an NXC bug in relational expressions which were not setting the main register
to a boolean value.
January 02, 2007 - NBC 1.0.1.b19 beta is available.
December 28, 2006 - NBC 1.0.1.b16 beta is available.
December 20, 2006 - NBC 1.0.1.b15 beta is available.
December 12, 2006 - NBC 1.0.1.b13 beta is available.
November 21, 2006 - NBC 1.0.1.b12 beta is available.
November 02, 2006 - NBC 1.0.1.b11 beta is available.
October 10, 2006 - NBC 1.0.1.b10 beta is available.
Send me an email if you have any questions.
Submit bug reports or feature requests via the sourceforge tracker.