What's New in NQC 2.0
New options
There are a number of major changes in NQC 2.0 - so much that it won't compile most NQC 1.0 programs. To ease transition to NQC 2.0, the compiler supports a backwards compatibility mode using the -1 option. This mode allows deprecated syntax to be used and uses the old NQC 1.0 system definitions instead of the new 2.0 ones. For example, to compile and download a 1.0 version program named foo.nqc:
nqc -1 -d foo.nqc
A full datalog listing can be obtained using the -datalog_full action:
nqc -datalog_full
A program may be cleared with the -clear action:
nqc -clear 1
rcx.nqh
The system include file, rcx.nqh, is now contained as data within the nqc compiler itself. You no longer need a separate rcx.nqh file.
For reference purposes, rcx1.nqh and rcx2.nqh files are provided. These are copies of the compiler's own system definitions. Normally, nqc will use the definitions listed in rcx2.nqh, but the backwards compatibility option (-1) will use NQC 1.0 definitions as listed in rcx1.nqh.
Arguments for Inline functions
Inline function can now have arguments. The syntax is similar to C...
void foo(int a)
{
}
There are four different argument types:
int - pass by value, uses a temporary
const int - pass by value, but must be constant at compile time
int & - pass by reference, must be a variable
cosnt int & - constant pass by reference. This is usually the best choice since it is very efficient for the compiler and does not cause a temporary variable to be created.
rcx2.nqh has some good examples of inline function syntax.
Deprecated Syntax
Inline functions and tasks now use a more C-like declaration syntax:
task main()
{
}
void foo()
{
}
instead of the older 1.0 style...
task main
{
}
inline foo
{
}
In normal mode, the old syntax is an error. In NQC 1.0 compatibility mode, the old syntax is still accepted.
No more "wait" statement
The wait statement has been renamed to "until".
until(SENSOR_1 == 1);
New System Definitions
These are the most significant changes to NQC, and I'm sure everyone will complain for a while about them. I know it will be a pain to move code from the old API to the new one, but the old one was pretty wild. The new API is a lot more self-consistent, and maps cleaner to RCX Code, thus it should be a lot easier for people to learn. In addition, some convenience functions have been introduced to make life a little easier.
You can keep using the old API, as long as you compile with the -1 option.
Instead of listing every single function and constant, I'm just listing them in groups. For example, instead of showing IN_1, IN_2, and IN_3, I just list IN_xxx. Exceptions to the general rule follow the rule itself (for example IN_SWITCH becomes SENSOR_TOUCH). In some cases (e.g. SENSOR_CELSIUS) there was no corresponding item in the old API.
Constants
Old |
New |
IN_xxx |
SENSOR_xxx |
SMODE_xxx |
SENSOR_MODE_xxx |
STYPE_xxx |
SENSOR_TYPE_xxx |
SMODE_ANGLE |
SENSOR_MODE_ROTATION |
STYPE_SWITCH |
SENSOR_TYPE_TOUCH |
STYPE_ANGLE |
SENSOR_TYPE_ROTATION |
STYPE_TEMP |
SENSOR_TYPE_TEMPERATURE |
IN_SWITCH |
SENSOR_TOUCH |
IN_ANGLE |
SENSOR_ROTATION |
- |
SENSOR_CELSIUS |
- |
SENSOR_FAHRENHEIT |
OUT_FLIP |
OUT_TOGGLE |
OUT_HALF |
value has changed from 4 to 3) |
IR_xxx |
TX_POWER_xxx |
Functions
Sensor() |
SetSensor() |
SensorMode() |
SetSensorMode() |
SensorType() |
SetSensorType() |
OutputMode() |
SetOutput() |
OutputDir() |
SetDirection() |
OutputPower() |
SetPower() |
Fwd() |
(new version takes only one argument) |
Rev() |
(new version takes only one argument) |
LO8() |
- |
HI8() |
- |
PlayNote() |
PlayTone() |
Sleep() |
Wait() |
Display() |
SelectDisplay() |
SetDatalog() |
CreateDatalog() |
Datalog() |
AddToDatalog() |
IRMode() |
SetTxPower() |
New Functions
On(motors) |
turns on one or more motors |
OnFwd(motors) |
sets direction to forward and turns on |
OnRev(motors) |
sets direction to reverse and turns on |
OnFor(motors, time) |
turns on motors for specified time (in 0.01 second increments) |
Values
Input() |
SensorValue() |
InputType() |
SensorType() |
InputMode() |
SensorMode() |
InputRaw() |
SensorValueRaw() |
InputBool(0 |
SensorValueBool() |
Initialization Code
NQC programs by default now contain initialization code that sets all three outputs to full power and in the forward direction (but still turned off). The automatic generation of this code can be disabled with the following directive:
#pragma noinit
Alternatively, you can write your own initialization code as an inline function, then tell the compiler to use the custom function instead of the default. For example, if your function were named foo, you would use the following directive:
#pragma init foo
Miscellaneous Changes
New operators: ++, -- (both prefix and postfix)
Bytecode listings improved (SetWatch, ClearTachoCounter, TxPower added)
an expression may be used as a statement (works well with ++ and --)
variables may be initialized during declaration
variable reuse has been improved
Watch() is now a valid source for the datalog
"unterminated #endif" bug fixed
"no task" bug fixed