• Home
  • History
  • Annotate
Name Date Size #Lines LOC

..03-May-2022-

ChangelogH A D15-Mar-201169.6 KiB1,5971,458

ReadmeH A D15-Mar-201114.5 KiB507432

Readme

1                              Not eXactly C
2                              -------------
3
4Not eXactly C (NXC) is a high level programming language similar to NQC.
5It targets the new LEGO NXT product.  Like NQC, it is available for Windows,
6Mac OS X, and Linux platforms.  While NXC is not yet complete, it is very
7functional, with a large API for the NXT.
8
9The NXC language currently supports the following programming constructs:
10
11if/else, while, do-while, repeat, for, switch, until, goto, and asm {}
12
13break and continue are both supported within looping constructs.  return may be
14used to exit a subroutine at any point, optionally returning a value to the
15calling routine.
16
17The NXC language supports global variables, local variables, tasks with no
18parameters, and functions with parameters and return values.  Currently supported
19variable types are:
20
21int, short, long, byte, char, bool, unsigned short, unsigned long, unsigned int, float,
22mutex, string, and arrays of all these types except mutex. (int == short).
23
24Global variables may be initialized at the point of declaration using constants
25or constant expressions.  Local variables may also be initialized at their
26declaration using any type of expression (not limited to constants).
27
28Arrays of any dimension may be declared by adding one or more pairs of square
29brackets after the variable name (int X[];).  Global arrays of one dimension may
30be initialized at the point of declaration using the following syntax:
31
32  int X[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}; // 10 elements
33
34Multi-dimensional arrays and local arrays must be initialized using the ArrayInit
35API function.
36
37Support for struct declarations and variables of type struct is included
38as of beta 28.  Support for typdefs is also included as of beta 28.
39
40NXC supports the following standard C (and NQC) operators:
41
42+, -, *, /, %,  & (bitwise and), | (bitwise or), ^ (bitwise xor), ! (logical
43not), ++ (pre and post increment), -- (pre and post decrement), <, <=, >, >=, ==, !=, =, *=, /=,
44%=, +=, -=, &=, |=, ^=, &&, ||, <<, >>, <<=, >>=, ||=, and +-=.
45
46The ?: operator is also supported.
47
48Here's the current list of API functions:
49
50Acquire(mutex);
51Release(mutex);
52Precedes(task1, task2, ..., taskn);
53Follows(task1, task2, ..., taskn);
54
55val = ButtonCount(btn, reset);
56val = ButtonPressed(btn, reset);
57ReadButtonEx(btn, reset, pressed, count);
58
59ClearSensor(port);
60ResetSensor(port);
61val = Sensor(port);
62val = SensorUS(port);
63SetSensorLight(port);
64SetSensorSound(port);
65SetSensorTouch(port);
66SetSensorLowspeed(port);
67SetSensorType(port, type);
68SetSensorMode(port, mode);
69SetInput(port, field, value);
70val = GetInput(port, field);
71val = SensorType(p);
72val = SensorMode(p);
73val = SensorRaw(p);
74val = SensorNormalized(p);
75val = SensorScaled(p);
76val = SensorInvalid(p);
77
78
79val = FirstTick();
80val = CurrentTick();
81Wait(ms);
82ResetSleepTimer();
83
84val = IOMA(num);
85SetIOMA(num);
86val = FreeMemory();
87val = BatteryLevel();
88PowerDown();
89RebootInFirmwareMode();
90
91ClearScreen();
92NumOut(x, y, number, cls=false);
93TextOut(x, y, string, cls=false);
94GraphicOut(x, y, filename, cls=false);
95GraphicOutEx(x, y, filename, vars, cls=false);
96CircleOut(x, y, radius, cls=false);
97LineOut(x1, y1, x2, y2, cls=false);
98PointOut(x, y, cls=false);
99RectOut(x, y, width, height, cls=false);
100ResetScreen();
101
102Coast(ports);
103Float(ports);
104Off(ports);
105OnFwd(ports, power);
106OnRev(ports, power);
107OnFwdReg(ports, power, regmode);
108OnRevReg(ports, power, regmode);
109OnFwdSync(ports, power, turnpct);
110OnRevSync(ports, power, turnpct);
111CoastEx(ports, reset);
112OffEx(ports, reset);
113OnFwdEx(ports, power, reset);
114OnRevEx(ports, power, reset);
115OnFwdRegEx(ports, power, regmode, reset);
116OnRevRegEx(ports, power, regmode, reset);
117OnFwdSyncEx(ports, power, turnpct, reset);
118OnRevSyncEx(ports, power, turnpct, reset);
119RotateMotor(ports, power, angle);
120RotateMotorEx(ports, power, angle, turnpct, sync, stop);
121RotateMotorPID(ports, power, angle, p, i, d);
122RotateMotorExPID(ports, power, angle, turnpct, sync, stop, p, i, d);
123
124SetOutput(ports, field1, value1, ..., fieldN, valueN);
125
126val = GetOutput(port, field);
127val = MotorMode(p);
128val = MotorPower(p);
129val = MotorActualSpeed(p);
130val = MotorTachoCount(p);
131val = MotorTachoLimit(p);
132val = MotorRunState(p);
133val = MotorTurnRatio(p);
134val = MotorRegulation(p);
135val = MotorOverload(p);
136val = MotorRegPValue(p);
137val = MotorRegIValue(p);
138val = MotorRegDValue(p);
139val = MotorBlockTachoCount(p);
140val = MotorRotationCount(p);
141
142ResetTachoCount(ports);
143ResetBlockTachoCount(ports);
144ResetRotationCount(ports);
145ResetAllTachoCounts(ports);
146
147PlayFile(filename);
148PlayFileEx(filename, volume, loop);
149PlayTone(frequency, duration);
150PlayToneEx(frequency, duration, volume, loop);
151val = SoundFlags();
152val = SoundState();
153StopSound();
154
155val = Random(); // signed word value
156val = Random(max); // unsigned word value
157
158start taskname;
159ExitTo(taskname);
160Stop(bvalue);
161
162val = abs(n);
163val = sign(n);
164
165val = StrToNum(str);
166val = StrLen(str);
167val = StrIndex(str, idx);
168
169str = NumToStr(num);
170str = StrCat(str1, str2, ..., strN);
171str = SubStr(string, idx, len);
172str = StrReplace(string, idx, strnew);
173str = Flatten(num);
174str = ByteArrayToStr(a);
175
176ByteArrayToStrEx(a, s);
177StrToByteArray(s, a);
178num = ArrayLen(a);
179ArrayInit(a, val, cnt);
180ArraySubset(aout, asrc, idx, len);
181ArrayBuild(aout, src1, ..., srcN);
182
183GetLSInputBuffer(p, offset, cnt, data);
184GetLSOutputBuffer(p, offset, cnt, data);
185GetDisplayNormal(x, line, cnt, data);
186GetDisplayPopup(x, line, cnt, data);
187GetBTInputBuffer(offset, cnt, data);
188GetBTOutputBuffer(offset, cnt, data);
189GetHSInputBuffer(offset, cnt, data);
190GetHSOutputBuffer(offset, cnt, data);
191GetUSBInputBuffer(offset, cnt, data);
192GetUSBOutputBuffer(offset, cnt, data);
193GetUSBPollBuffer(offset, cnt, data);
194
195str = BTDeviceName(p);
196str = BTConnectionName(p);
197str = BTConnectionPinCode(p);
198str = BrickDataName();
199
200GetBTDeviceAddress(p, data);
201GetBTConnectionAddress(p, data);
202GetBrickDataAddress(data);
203
204val = SoundFrequency();
205val = SoundDuration();
206val = SoundSampleRate();
207val = SoundMode();
208val = SoundVolume();
209
210val = ButtonPressCount(b);
211val = ButtonLongPressCount(b);
212val = ButtonShortReleaseCount(b);
213val = ButtonLongReleaseCount(b);
214val = ButtonReleaseCount(b);
215val = ButtonState(b);
216
217val = CommandFlags();
218val = UIState();
219val = UIButton();
220val = VMRunState();
221val = BatteryState();
222val = BluetoothState();
223val = UsbState();
224val = SleepTimeout();
225val = SleepTimer();
226val = RechargeableBattery();
227val = Volume();
228val = OnBrickProgramPointer();
229
230val = CustomSensorZeroOffset(p);
231val = CustomSensorPercentFullScale(p);
232val = CustomSensorActiveStatus(p);
233val = SensorBoolean(p);
234val = SensorDigiPinsDirection(p);
235val = SensorDigiPinsStatus(p);
236val = SensorDigiPinsOutputLevel(p);
237
238val = MotorPwnFreq();
239
240val = LSInputBufferInPtr(p);
241val = LSInputBufferOutPtr(p);
242val = LSInputBufferBytesToRx(p);
243val = LSOutputBufferInPtr(p);
244val = LSOutputBufferOutPtr(p);
245val = LSOutputBufferBytesToRx(p);
246val = LSMode(p);
247val = LSChannelState(p);
248val = LSErrorType(p);
249val = LSState();
250val = LSSpeed();
251
252val = DisplayEraseMask();
253val = DisplayUpdateMask();
254val = DisplayDisplay();
255val = DisplayFlags();
256val = DisplayTextLinesCenterFlags();
257
258val = BTDeviceClass(p);
259val = BTDeviceStatus(p);
260val = BTConnectionClass(p);
261val = BTConnectionHandleNum(p);
262val = BTConnectionStreamStatus(p);
263val = BTConnectionLinkQuality(p);
264val = BrickDataBluecoreVersion();
265val = BrickDataBtStateStatus();
266val = BrickDataBtHardwareStatus();
267val = BrickDataTimeoutValue();
268val = BTInputBufferInPtr();
269val = BTInputBufferOutPtr();
270val = BTOutputBufferInPtr();
271val = BTOutputBufferOutPtr();
272val = HSInputBufferInPtr();
273val = HSInputBufferOutPtr();
274val = HSOutputBufferInPtr();
275val = HSOutputBufferOutPtr();
276val = USBInputBufferInPtr();
277val = USBInputBufferOutPtr();
278val = USBOutputBufferInPtr();
279val = USBOutputBufferOutPtr();
280val = USBPollBufferInPtr();
281val = USBPollBufferOutPtr();
282val = BTDeviceCount();
283val = BTDeviceNameCount();
284val = HSFlags();
285val = HSSpeed();
286val = HSState();
287val = USBState();
288
289SetSoundFrequency(n);
290SetSoundDuration(n);
291SetSoundSampleRate(n);
292SetSoundFlags(n);
293SetSoundState(n);
294SetSoundMode(n);
295SetSoundVolume(n);
296
297SetCommandFlags(n);
298SetUIState(n);
299SetUIButton(n);
300SetVMRunState(n);
301SetBatteryState(n);
302SetBluetoothState(n);
303SetUsbState(n);
304SetSleepTimeout(n);
305SetSleepTimer(n);
306SetVolume(n);
307SetOnBrickProgramPointer(n);
308ForceOff(n);
309
310SetCustomSensorZeroOffset(p, n);
311SetCustomSensorPercentFullScale(p, n);
312SetCustomSensorActiveStatus(p, n);
313SetSensorBoolean(p, n);
314SetSensorDigiPinsDirection(p, n);
315SetSensorDigiPinsStatus(p, n);
316SetSensorDigiPinsOutputLevel(p, n);
317
318SetMotorPwnFreq(n);
319
320SetLSInputBuffer(p, offset, cnt, data);
321SetLSInputBufferInPtr(p, n);
322SetLSInputBufferOutPtr(p, n);
323SetLSInputBufferBytesToRx(p, n);
324SetLSOutputBuffer(p, offset, cnt, data);
325SetLSOutputBufferInPtr(p, n);
326SetLSOutputBufferOutPtr(p, n);
327SetLSOutputBufferBytesToRx(p, n);
328SetLSMode(p, n);
329SetLSChannelState(p, n);
330SetLSErrorType(p, n);
331SetLSState(n);
332SetLSSpeed(n);
333
334SetDisplayEraseMask(n);
335SetDisplayUpdateMask(n);
336SetDisplayDisplay(n);
337SetDisplayFlags(n);
338SetDisplayTextLinesCenterFlags(n);
339SetDisplayNormal(x, line, cnt, data);
340SetDisplayPopup(x, line, cnt, data);
341
342SetBTDeviceName(p, str);
343SetBTDeviceAddress(p, addr);
344SetBTConnectionName(p, str);
345SetBTConnectionPinCode(p, code);
346SetBTConnectionAddress(p, addr);
347SetBrickDataName(str);
348SetBrickDataAddress(p, addr);
349SetBTDeviceClass(p, n);
350SetBTDeviceStatus(p, n);
351SetBTConnectionClass(p, n);
352SetBTConnectionHandleNum(p, n);
353SetBTConnectionStreamStatus(p, n);
354SetBTConnectionLinkQuality(p, n);
355SetBrickDataBluecoreVersion(n);
356SetBrickDataBtStateStatus(n);
357SetBrickDataBtHardwareStatus(n);
358SetBrickDataTimeoutValue(n);
359SetBTInputBuffer(offset, cnt, data);
360SetBTInputBufferInPtr(n);
361SetBTInputBufferOutPtr(n);
362SetBTOutputBuffer(offset, cnt, data);
363SetBTOutputBufferInPtr(n);
364SetBTOutputBufferOutPtr(n);
365SetHSInputBuffer(offset, cnt, data);
366SetHSInputBufferInPtr(n);
367SetHSInputBufferOutPtr(n);
368SetHSOutputBuffer(offset, cnt, data);
369SetHSOutputBufferInPtr(n);
370SetHSOutputBufferOutPtr(n);
371SetUSBInputBuffer(offset, cnt, data);
372SetUSBInputBufferInPtr(n);
373SetUSBInputBufferOutPtr(n);
374SetUSBOutputBuffer(offset, cnt, data);
375SetUSBOutputBufferInPtr(n);
376SetUSBOutputBufferOutPtr(n);
377SetUSBPollBuffer(offset, cnt, data);
378SetUSBPollBufferInPtr(n);
379SetUSBPollBufferOutPtr(n);
380SetBTDeviceCount(n);
381SetBTDeviceNameCount(n);
382SetHSFlags(n);
383SetHSSpeed(n);
384SetHSState(n);
385SetUSBState(n);
386
387val = CreateFile(fname, fsize, handle);
388val = OpenFileAppend(fname, fsize, handle);
389val = OpenFileRead(fname, fsize, handle);
390val = CloseFile(handle);
391val = ResolveHandle(fname, handle, writeable);
392val = RenameFile(oldname, newname);
393val = DeleteFile(fname);
394val = Read(handle, n);
395val = ReadLn(handle, n);
396val = ReadBytes(handle, len, buf);
397val = Write(handle, n);
398val = WriteLn(handle, n);
399val = WriteString(handle, str, cnt);
400val = WriteLnString(handle, str, cnt);
401val = WriteBytes(handle, buf, cnt);
402val = WriteBytesEx(handle, len, buf);
403
404val = SendMessage(queue, msg);
405val = ReceiveMessage(queue, clear, msg);
406
407val = LowspeedStatus(port, bready);
408val = LowspeedBytesReady(port);
409val = LowspeedCheckStatus(port);
410val = LowspeedWrite(port, retlen, buffer);
411val = LowspeedRead(port, buflen, buffer);
412
413val = I2CStatus(port, bready);
414val = I2CBytesReady(port);
415val = I2CCheckStatus(port);
416val = I2CWrite(port, retlen, buffer);
417val = I2CRead(port, buflen, buffer);
418val = I2CBytes(port, inbuf, count, outbuf)
419
420val = BluetoothStatus(conn);
421val = BluetoothWrite(conn, buffer);
422
423result = ReceiveRemoteBool(queue, clear, bval);
424result = ReceiveRemoteNumber(queue, clear, val);
425result = ReceiveRemoteString(queue, clear, str);
426result = ReceiveRemoteMessageEx(queue, clear, str, val, bval);
427result = SendRemoteBool(conn, queue, bval);
428result = SendRemoteNumber(conn, queue, val);
429result = SendRemoteString(conn, queue, str);
430result = SendResponseBool(queue, bval);
431result = SendResponseNumber(queue, val);
432result = SendResponseString(queue, str);
433
434result = RemoteMessageRead(conn, queue);
435result = RemoteMessageWrite(conn, queue, msg); // alias for SendRemoteString
436result = RemoteStartProgram(conn, filename);
437result = RemoteStopProgram(conn);
438result = RemotePlaySoundFile(conn, filename, bloop);
439result = RemotePlayTone(conn, frequency, duration);
440result = RemoteStopSound(conn);
441result = RemoteKeepAlive(conn);
442result = RemoteResetScaledValue(conn, port);
443result = RemoteResetMotorPosition(conn, port, brelative);
444result = RemoteSetInputMode(conn, port, type, mode);
445result = RemoteSetOutputState(conn, port, speed, mode, regmode, turnpct, runstate, tacholimit);
446
447result = Sqrt(X);
448result = Sin(X);
449result = Cos(X);
450result = Asin(X);
451result = Acos(X);
452
453SysCall(func, args);
454
455SysFileOpenRead(FileOpenType & args);
456SysFileOpenWrite(FileOpenType & args);
457SysFileOpenAppend(FileOpenType & args);
458SysFileRead(FileReadWriteType & args);
459SysFileWrite(FileReadWriteType & args);
460SysFileClose(FileCloseType & args);
461SysFileResolveHandle(FileResolveHandleType & args);
462SysFileRename(FileRenameType & args);
463SysFileDelete(FileDeleteType & args);
464
465SysSoundPlayFile(SoundPlayFileType & args);
466SysSoundPlayTone(SoundPlayToneType & args);
467SysSoundGetState(SoundGetStateType & args);
468SysSoundSetState(SoundSetStateType & args);
469
470SysDrawText(DrawTextType & args);
471SysDrawPoint(DrawPointType & args);
472SysDrawLine(DrawLineType & args);
473SysDrawCircle(DrawCircleType & args);
474SysDrawRect(DrawRectType & args);
475SysDrawGraphic(DrawGraphicType & args);
476SysSetScreenMode(SetScreenModeType & args);
477
478SysReadButton(ReadButtonType & args);
479
480SysCommLSWrite(CommLSWriteType & args);
481SysCommLSRead(CommLSReadType & args);
482SysCommLSCheckStatus(CommLSCheckStatusType & args);
483
484SysRandomNumber(RandomNumberType & args);
485
486SysGetStartTick(GetStartTickType & args);
487
488SysMessageWrite(MessageWriteType & args);
489SysMessageRead(MessageReadType & args);
490
491SysCommBTWrite(CommBTWriteType & args);
492SysCommBTCheckStatus(CommBTCheckStatusType & args);
493
494SysKeepAlive(KeepAliveType & args);
495
496SysIOMapRead(IOMapReadType & args);
497SysIOMapWrite(IOMapWriteType & args);
498
499SysIOMapReadByID(IOMapReadByIDType & args);
500SysIOMapWriteByID(IOMapWriteByIDType & args);
501
502SysDisplayExecuteFunction(DisplayExecuteFunctionType & args);
503SysCommExecuteFunction(CommExecuteFunctionType & args);
504SysLoaderExecuteFunction(LoaderExecuteFunctionType & args);
505
506You can find NXC at http://bricxcc.sourceforge.net/nxc/.
507