1 /* NXTDefs.h
2  * Constants, macros, and API functions for use in NBC
3  *
4  * NXTDefs.h contains declarations for the NBC NXT API resources
5  *
6  * License:
7  *
8  * The contents of this file are subject to the Mozilla Public License
9  * Version 1.1 (the "License"); you may not use this file except in
10  * compliance with the License. You may obtain a copy of the License at
11  * http://www.mozilla.org/MPL/
12  *
13  * Software distributed under the License is distributed on an "AS IS"
14  * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
15  * License for the specific language governing rights and limitations
16  * under the License.
17  *
18  * The Initial Developer of this code is John Hansen.
19  * Portions created by John Hansen are Copyright (C) 2009-2010 John Hansen.
20  * All Rights Reserved.
21  *
22  * ----------------------------------------------------------------------------
23  *
24  * author John Hansen (bricxcc_at_comcast.net)
25  * date 2011-03-15
26  * version 76
27  */
28 #ifndef NXTDEFS__H
29 #define NXTDEFS__H
30 
31 #include "NBCCommon.h"
32 
33 /** @addtogroup cmpconst
34  * @{
35  */
36 #define LT   0x00 /*!< The first value is less than the second. */
37 #define GT   0x01 /*!< The first value is greater than the second. */
38 #define LTEQ 0x02 /*!< The first value is less than or equal to the second. */
39 #define GTEQ 0x03 /*!< The first value is greater than or equal to the second. */
40 #define EQ   0x04 /*!< The first value is equal to the second. */
41 #define NEQ  0x05 /*!< The first value is not equal to the second. */
42 /** @} */  // end of cmpconst group
43 
44 #ifdef __DOXYGEN_DOCS
45 // nothing to see here
46 #else
47 // define structures for various system calls
48 
49 dseg	segment
50 
51 TLocation	struct
52  X		sword
53  Y		sword
54 TLocation	ends
55 
56 TSize	struct
57  Width	sword
58  Height	sword
59 TSize	ends
60 
61 // FileOpenRead, FileOpenWrite, FileOpenAppend, FileOpenWriteLinear, FileOpenWriteNonLinear, FileOpenReadLinear
62 TFileOpen	struct
63  Result		word
64  FileHandle	byte
65  Filename	byte[]
66  Length		dword
67 TFileOpen	ends
68 
69 // FileRead, FileWrite
70 TFileReadWrite	struct
71  Result		word
72  FileHandle	byte
73  Buffer		byte[]
74  Length		dword
75 TFileReadWrite	ends
76 
77 // FileClose
78 TFileClose	struct
79  Result		word
80  FileHandle	byte
81 TFileClose	ends
82 
83 // FileResolveHandle
84 TFileResolveHandle	struct
85  Result		word
86  FileHandle	byte
87  WriteHandle	byte
88  Filename	byte[]
89 TFileResolveHandle	ends
90 
91 // FileRename
92 TFileRename	struct
93  Result		word
94  OldFilename	byte[]
95  NewFilename	byte[]
96 TFileRename	ends
97 
98 // FileDelete
99 TFileDelete	struct
100  Result		word
101  Filename	byte[]
102 TFileDelete	ends
103 
104 // SoundPlayFile
105 TSoundPlayFile	struct
106  Result		sbyte
107  Filename	byte[]
108  Loop		byte
109  Volume		byte
110 TSoundPlayFile	ends
111 
112 // SoundPlayTone
113 TSoundPlayTone	struct
114  Result		sbyte
115  Frequency	word
116  Duration	word
117  Loop		byte
118  Volume		byte
119 TSoundPlayTone	ends
120 
121 // SoundGetState
122 TSoundGetState	struct
123  State		byte
124  Flags		byte
125 TSoundGetState	ends
126 
127 // SoundSetState
128 TSoundSetState	struct
129  Result		byte
130  State		byte
131  Flags		byte
132 TSoundSetState	ends
133 
134 // DrawText
135 TDrawText	struct
136  Result		sbyte
137  Location	TLocation
138  Text		byte[]
139  Options	dword
140 TDrawText	ends
141 
142 // DrawPoint
143 TDrawPoint	struct
144  Result		sbyte
145  Location	TLocation
146  Options	dword
147 TDrawPoint	ends
148 
149 // DrawLine
150 TDrawLine	struct
151  Result		sbyte
152  StartLoc	TLocation
153  EndLoc		TLocation
154  Options	dword
155 TDrawLine	ends
156 
157 // DrawCircle
158 TDrawCircle	struct
159  Result		sbyte
160  Center		TLocation
161  Size		byte
162  Options	dword
163 TDrawCircle	ends
164 
165 // DrawRect
166 TDrawRect	struct
167  Result		sbyte
168  Location	TLocation
169  Size		TSize
170  Options	dword
171 TDrawRect	ends
172 
173 // DrawGraphic
174 TDrawGraphic	struct
175  Result		sbyte
176  Location	TLocation
177  Filename	byte[]
178  Variables	sdword[]
179  Options	dword
180 TDrawGraphic	ends
181 
182 // SetScreenMode
183 TSetScreenMode	struct
184  Result		sbyte
185  ScreenMode	dword
186 TSetScreenMode	ends
187 
188 // ReadButton
189 TReadButton	struct
190  Result		sbyte
191  Index		byte
192  Pressed	byte
193  Count		byte
194  Reset		byte
195 TReadButton	ends
196 
197 // CommLSWrite
198 TCommLSWrite	struct
199  Result		sbyte
200  Port		byte
201  Buffer		byte[]
202  ReturnLen	byte
203 TCommLSWrite	ends
204 
205 // CommLSRead
206 TCommLSRead	struct
207  Result		sbyte
208  Port		byte
209  Buffer		byte[]
210  BufferLen	byte
211 TCommLSRead	ends
212 
213 // CommLSCheckStatus
214 TCommLSCheckStatus	struct
215  Result		sbyte
216  Port		byte
217  BytesReady	byte
218 TCommLSCheckStatus	ends
219 
220 // RandomNumber
221 TRandomNumber	struct
222  Result		sword
223 TRandomNumber	ends
224 
225 // GetStartTick
226 TGetStartTick	struct
227  Result		dword
228 TGetStartTick	ends
229 
230 // MessageWrite
231 TMessageWrite	struct
232  Result		sbyte
233  QueueID	byte
234  Message	byte[]
235 TMessageWrite	ends
236 
237 // MessageRead
238 TMessageRead	struct
239  Result		sbyte
240  QueueID	byte
241  Remove		byte
242  Message	byte[]
243 TMessageRead	ends
244 
245 // CommBTCheckStatus
246 TCommBTCheckStatus	struct
247  Result		sbyte
248  Connection	byte
249 TCommBTCheckStatus	ends
250 
251 // CommBTWrite
252 TCommBTWrite	struct
253  Result		sbyte
254  Connection	byte
255  Buffer		byte[]
256 TCommBTWrite	ends
257 
258 // CommBTRead
259 TCommBTRead	struct
260  Result		sbyte
261  Count		byte
262  Buffer		byte[]
263 TCommBTRead	ends
264 
265 // KeepAlive
266 TKeepAlive	struct
267  Result		dword
268 TKeepAlive	ends
269 
270 // IOMapRead
271 TIOMapRead	struct
272  Result		sbyte
273  ModuleName	byte[]
274  Offset		word
275  Count		word
276  Buffer		byte[]
277 TIOMapRead	ends
278 
279 // IOMapWrite
280 TIOMapWrite	struct
281  Result		sbyte
282  ModuleName	byte[]
283  Offset		word
284  Buffer		byte[]
285 TIOMapWrite	ends
286 
287 #ifdef __ENHANCED_FIRMWARE
288 
289 TIOMapReadByID struct
290   Result    sbyte
291   ModuleID  long
292   Offset    word
293   Count     word
294   Buffer    byte[]
295 TIOMapReadByID ends
296 
297 TIOMapWriteByID struct
298   Result   sbyte
299   ModuleID long
300   Offset   word
301   Buffer   byte[]
302 TIOMapWriteByID ends
303 
304 TDisplayExecuteFunction struct
305   Status byte
306   Cmd    byte
307   On     byte
308   X1     byte
309   Y1     byte
310   X2     byte
311   Y2     byte
312 TDisplayExecuteFunction ends
313 
314 TCommExecuteFunction struct
315   Result word
316   Cmd    byte
317   Param1 byte
318   Param2 byte
319   Param3 byte
320   Name   byte[]
321   RetVal word
322 TCommExecuteFunction ends
323 
324 TLoaderExecuteFunction struct
325   Result   word
326   Cmd      byte
327   Filename byte[]
328   Buffer   byte[]
329   Length   long
330 TLoaderExecuteFunction ends
331 
332 // FileFindFirst, FileFindNext
333 TFileFind	struct
334  Result		word
335  FileHandle	byte
336  Filename	byte[]
337  Length		dword
338 TFileFind	ends
339 
340 TCommHSControl	struct
341  Result		sbyte
342  Command	byte
343  BaudRate	byte
344 #if __FIRMWARE_VERSION > 107
345  Mode		word
346 #endif
347 TCommHSControl	ends
348 
349 TCommHSCheckStatus	struct
350  SendingData	byte
351  DataAvailable	byte
352 TCommHSCheckStatus	ends
353 
354 // CommHSRead, CommHSWrite
355 TCommHSReadWrite	struct
356  Status	sbyte
357  Buffer	byte[]
358 TCommHSReadWrite	ends
359 
360 // CommLSWriteEx
361 TCommLSWriteEx	struct
362  Result		sbyte
363  Port		byte
364  Buffer		byte[]
365  ReturnLen	byte
366  NoRestartOnRead	byte
367 TCommLSWriteEx	ends
368 
369 #if __FIRMWARE_VERSION > 107
370 //FileSeek
371 TFileSeek	struct
372  Result		word
373  FileHandle	byte
374  Origin		byte
375  Length		sdword
376 TFileSeek	ends
377 
378 //FileResize
379 TFileResize	struct
380  Result		word
381  FileHandle	byte
382  NewSize	word
383 TFileResize	ends
384 
385 // DrawGraphicArray
386 TDrawGraphicArray	struct
387  Result		sbyte
388  Location	TLocation
389  Data		byte[]
390  Variables	sdword[]
391  Options	dword
392 TDrawGraphicArray	ends
393 
394 // DrawPolygon
395 TDrawPolygon	struct
396  Result		sbyte
397  Points		TLocation[]
398  Options	dword
399 TDrawPolygon	ends
400 
401 // DrawEllipse
402 TDrawEllipse	struct
403  Result		sbyte
404  Center		TLocation
405  SizeX		byte
406  SizeY		byte
407  Options	dword
408 TDrawEllipse	ends
409 
410 // DrawFont
411 TDrawFont	struct
412  Result		sbyte
413  Location	TLocation
414  Filename	byte[]
415  Text		byte[]
416  Options	dword
417 TDrawFont	ends
418 
419 // MemoryManager
420 TMemoryManager struct
421  Result        sbyte
422  Compact       byte
423  PoolSize      word
424  DataspaceSize word
425 TMemoryManager ends
426 
427 // ReadLastResponse
428 TReadLastResponse struct
429  Result  sbyte
430  Clear   byte
431  Length  byte
432  Command byte
433  Buffer	 byte[]
434 TReadLastResponse ends
435 
436 // FileTell
437 TFileTell struct
438  Result     sbyte
439  FileHandle byte
440  Position   dword
441 TFileTell ends
442 #endif
443 #endif
444 
445 #if __FIRMWARE_VERSION > 107
446 
447 // ColorSensorRead
448 TColorSensorRead	struct
449  Result			sbyte
450  Port			byte
451  ColorValue		sword
452  RawArray		word[]
453  NormalizedArray	word[]
454  ScaledArray		sword[]
455  Invalid		byte
456 TColorSensorRead	ends
457 
458 // DatalogWrite
459 TDatalogWrite	struct
460  Result		sbyte
461  Message	byte[]
462 TDatalogWrite	ends
463 
464 // DatalogGetTimes
465 TDatalogGetTimes	struct
466  SyncTime	dword
467  SyncTick	dword
468 TDatalogGetTimes	ends
469 
470 // SetSleepTimeout
471 TSetSleepTimeout	struct
472  Result		sbyte
473  TheSleepTimeoutMS	dword
474 TSetSleepTimeout	ends
475 
476 // CommBTOnOff
477 TCommBTOnOff	struct
478 #ifdef __ENHANCED_FIRMWARE
479  Result		word
480 #else
481  Result		sbyte
482 #endif
483  PowerState	byte
484 TCommBTOnOff	ends
485 
486 // CommBTConnection
487 TCommBTConnection	struct
488 #ifdef __ENHANCED_FIRMWARE
489  Result		word
490 #else
491  Result		sbyte
492 #endif
493  Action		byte
494  Name		byte[]
495  ConnectionSlot	byte
496 TCommBTConnection	ends
497 
498 // ReadSemData
499 TReadSemData struct
500  SemData byte
501  Request byte
502 TReadSemData ends
503 
504 // WriteSemData
505 TWriteSemData struct
506  SemData byte
507  Request byte
508  NewVal byte
509  ClearBits byte
510 TWriteSemData ends
511 
512 // UpdateCalibCacheInfo
513 TUpdateCalibCacheInfo struct
514  Result byte
515  Name byte[]
516  MinVal word
517  MaxVal word
518 TUpdateCalibCacheInfo ends
519 
520 // ComputeCalibValue
521 TComputeCalibValue struct
522  Result byte
523  Name byte[]
524  RawVal word
525 TComputeCalibValue ends
526 
527 // ListFiles
528 TListFiles	struct
529  Result		sbyte
530  Pattern	byte[]
531  FileList	byte[][]
532 TListFiles	ends
533 
534 #endif
535 
536 #if defined(__ENHANCED_FIRMWARE) && (__FIRMWARE_VERSION > 107)
537 TOutputState struct // for use with the RemoteGetOutputState direct command response
538   Port            byte
539   Power           sbyte
540   Mode            byte
541   RegMode         byte
542   TurnRatio       sbyte
543   RunState        byte
544   TachoLimit      dword
545   TachoCount      sdword
546   BlockTachoCount sdword
547   RotationCount   sdword
548 TOutputState ends
549 
550 TInputValues struct // for use with the RemoteGetInputValues direct command response
551   Port            byte
552   Valid           byte
553   Calibrated      byte
554   SensorType      byte
555   SensorMode      byte
556   RawValue        word
557   NormalizedValue word
558   ScaledValue     sword
559   CalibratedValue sword
560 TInputValues ends
561 
562 TInput struct
563   CustomZeroOffset   word
564   ADRaw              word
565   SensorRaw          word
566   SensorValue        sword
567   SensorType         byte
568   SensorMode         byte
569   SensorBoolean      byte
570   DigiPinsDir        byte
571   DigiPinsIn         byte
572   DigiPinsOut        byte
573   CustomPctFullScale byte
574   CustomActiveStatus byte
575   InvalidData        byte
576 TInput ends // 17 bytes
577 
578 TOutput struct
579   TachoCnt          sdword
580   BlockTachoCount   sdword
581   RotationCount     sdword
582   TachoLimit        dword
583   MotorRPM          sword
584   Flags             byte
585   Mode              byte
586   Speed             sbyte
587   ActualSpeed       sbyte
588   RegPParameter     byte
589   RegIParameter     byte
590   RegDParameter     byte
591   RunState          byte
592   RegMode           byte
593   Overloaded        byte
594   SyncTurnParameter sbyte
595   Options           byte
596 TOutput ends // 30 bytes
597 
598 TButtonCounts struct
599   BtnPressedCnt   byte
600   BtnLongPressCnt byte
601   BtnShortRelCnt  byte
602   BtnLongRelCnt   byte
603   BtnRelCnt       byte
604 TButtonCounts ends // 5 bytes
605 
606 TBluetoothDevice struct
607   Name          byte[]
608   ClassOfDevice byte[]
609   BdAddr        byte[]
610   DeviceStatus  byte
611 TBluetoothDevice ends // 28 bytes
612 
613 TBluetoothConnection struct
614   Name          byte[]
615   ClassOfDevice byte[]
616   PinCode       byte[]
617   BdAddr        byte[]
618   HandleNr      byte
619   StreamStatus  byte
620   LinkQuality   byte
621 TBluetoothConnection ends // 46 bytes
622 
623 TBrickData struct
624   Name            byte[]
625   BluecoreVersion byte[]
626   BdAddr          byte[]
627   BtStateStatus   byte
628   BtHwStatus      byte
629   TimeOutValue    byte
630 TBrickData ends // 28 bytes
631 
632 #endif
633 
634 dseg	ends
635 
636 // motor arrays (compiler will optimize these out if they are not used)
637 dseg segment
638   __OUT_AB byte[] OUT_A, OUT_B
639   __OUT_AC byte[] OUT_A, OUT_C
640   __OUT_BC byte[] OUT_B, OUT_C
641   __OUT_ABC byte[] OUT_A, OUT_B, OUT_C
642   __OnRev_Tmp sbyte
643   __OnRevMutex mutex
644 dseg ends
645 
646 dseg segment
647   __rotateMutex0 mutex
648   __rotateMutex1 mutex
649   __rotateMutex2 mutex
650 dseg ends
651 
652 dseg segment
653 // variables for rotate motor subroutine (0)
654   __rotate_power0 byte
655   __rotate_angle0 slong
656   __rotate_ports0 byte[]
657   __rotate_firstPort0 byte
658   __rotate_sync0 byte
659   __rotate_stop0 byte
660   __rotate_turnpct0 sbyte
661   __rotate_theUF0 byte
662   __rotate_theOM0 byte
663   __rotate_theRM0 byte
664   __rotate_theRS0 byte
665   __rotate_theRVP0 byte
666   __rotate_theRVI0 byte
667   __rotate_theRVD0 byte
668   __rotate_rs0 byte
669   __rotate_OldRotCount0 sword
670   __rotate_RotCount0 sword
671   __rotate_thePower0 sbyte
672   __rotate_theAngle0 ulong
673   __rotate_theTurnPct0 sbyte
674   __rotate_then0 dword
675   __rotate_now0 dword
676 dseg ends
677 
678 dseg segment
679 // variables for rotate motor subroutine (1)
680   __rotate_power1 byte
681   __rotate_angle1 slong
682   __rotate_ports1 byte[]
683   __rotate_firstPort1 byte
684   __rotate_sync1 byte
685   __rotate_stop1 byte
686   __rotate_turnpct1 sbyte
687   __rotate_theUF1 byte
688   __rotate_theOM1 byte
689   __rotate_theRM1 byte
690   __rotate_theRS1 byte
691   __rotate_theRVP1 byte
692   __rotate_theRVI1 byte
693   __rotate_theRVD1 byte
694   __rotate_rs1 byte
695   __rotate_OldRotCount1 sword
696   __rotate_RotCount1 sword
697   __rotate_thePower1 sbyte
698   __rotate_theAngle1 ulong
699   __rotate_theTurnPct1 sbyte
700   __rotate_then1 dword
701   __rotate_now1 dword
702 dseg ends
703 
704 dseg segment
705 // variables for rotate motor subroutine (2)
706   __rotate_power2 byte
707   __rotate_angle2 slong
708   __rotate_ports2 byte[]
709   __rotate_firstPort2 byte
710   __rotate_sync2 byte
711   __rotate_stop2 byte
712   __rotate_turnpct2 sbyte
713   __rotate_theUF2 byte
714   __rotate_theOM2 byte
715   __rotate_theRM2 byte
716   __rotate_theRS2 byte
717   __rotate_theRVP2 byte
718   __rotate_theRVI2 byte
719   __rotate_theRVD2 byte
720   __rotate_rs2 byte
721   __rotate_OldRotCount2 sword
722   __rotate_RotCount2 sword
723   __rotate_thePower2 sbyte
724   __rotate_theAngle2 ulong
725   __rotate_theTurnPct2 sbyte
726   __rotate_then2 dword
727   __rotate_now2 dword
728 dseg ends
729 
730 dseg segment
731 // variables for rotate motor subroutine (3)
732   __rotate_power3 byte
733   __rotate_angle3 slong
734   __rotate_ports3 byte[]
735   __rotate_firstPort3 byte
736   __rotate_sync3 byte
737   __rotate_stop3 byte
738   __rotate_turnpct3 sbyte
739   __rotate_theUF3 byte
740   __rotate_theOM3 byte
741   __rotate_theRM3 byte
742   __rotate_theRS3 byte
743   __rotate_theRVP3 byte
744   __rotate_theRVI3 byte
745   __rotate_theRVD3 byte
746   __rotate_rs3 byte
747   __rotate_OldRotCount3 sword
748   __rotate_RotCount3 sword
749   __rotate_thePower3 sbyte
750   __rotate_theAngle3 ulong
751   __rotate_theTurnPct3 sbyte
752   __rotate_then3 dword
753   __rotate_now3 dword
754 dseg ends
755 
756 dseg segment
757 // variables for rotate motor subroutine (4)
758   __rotate_power4 byte
759   __rotate_angle4 slong
760   __rotate_ports4 byte[]
761   __rotate_firstPort4 byte
762   __rotate_sync4 byte
763   __rotate_stop4 byte
764   __rotate_turnpct4 sbyte
765   __rotate_theUF4 byte
766   __rotate_theOM4 byte
767   __rotate_theRM4 byte
768   __rotate_theRS4 byte
769   __rotate_theRVP4 byte
770   __rotate_theRVI4 byte
771   __rotate_theRVD4 byte
772   __rotate_rs4 byte
773   __rotate_OldRotCount4 sword
774   __rotate_RotCount4 sword
775   __rotate_thePower4 sbyte
776   __rotate_theAngle4 ulong
777   __rotate_theTurnPct4 sbyte
778   __rotate_then4 dword
779   __rotate_now4 dword
780 dseg ends
781 
782 dseg segment
783 // variables for rotate motor subroutine (5)
784   __rotate_power5 byte
785   __rotate_angle5 slong
786   __rotate_ports5 byte[]
787   __rotate_firstPort5 byte
788   __rotate_sync5 byte
789   __rotate_stop5 byte
790   __rotate_turnpct5 sbyte
791   __rotate_theUF5 byte
792   __rotate_theOM5 byte
793   __rotate_theRM5 byte
794   __rotate_theRS5 byte
795   __rotate_theRVP5 byte
796   __rotate_theRVI5 byte
797   __rotate_theRVD5 byte
798   __rotate_rs5 byte
799   __rotate_OldRotCount5 sword
800   __rotate_RotCount5 sword
801   __rotate_thePower5 sbyte
802   __rotate_theAngle5 ulong
803   __rotate_theTurnPct5 sbyte
804   __rotate_then5 dword
805   __rotate_now5 dword
806 dseg ends
807 
808 dseg segment
809 // variables for rotate motor subroutine (6)
810   __rotate_power6 byte
811   __rotate_angle6 slong
812   __rotate_ports6 byte[]
813   __rotate_firstPort6 byte
814   __rotate_sync6 byte
815   __rotate_stop6 byte
816   __rotate_turnpct6 sbyte
817   __rotate_theUF6 byte
818   __rotate_theOM6 byte
819   __rotate_theRM6 byte
820   __rotate_theRS6 byte
821   __rotate_theRVP6 byte
822   __rotate_theRVI6 byte
823   __rotate_theRVD6 byte
824   __rotate_rs6 byte
825   __rotate_OldRotCount6 sword
826   __rotate_RotCount6 sword
827   __rotate_thePower6 sbyte
828   __rotate_theAngle6 ulong
829   __rotate_theTurnPct6 sbyte
830   __rotate_then6 dword
831   __rotate_now6 dword
832 dseg ends
833 
834 #define UF_UPDATE_ONFWD 0x28
835 
836 // API macros
837 #define __resetMotorCounter0(_val) setout OUT_A, UpdateFlagsField, _val
838 #define __resetMotorCounter1(_val) setout OUT_B, UpdateFlagsField, _val
839 #define __resetMotorCounter2(_val) setout OUT_C, UpdateFlagsField, _val
840 #define __resetMotorCounter3(_val) setout __OUT_AB, UpdateFlagsField, _val
841 #define __resetMotorCounter4(_val) setout __OUT_AC, UpdateFlagsField, _val
842 #define __resetMotorCounter5(_val) setout __OUT_BC, UpdateFlagsField, _val
843 #define __resetMotorCounter6(_val) setout __OUT_ABC, UpdateFlagsField, _val
844 
845 #define __resetTachoCount(_p) \
846   compif EQ, isconst(_p), FALSE \
847   setout _p, UpdateFlagsField, RESET_COUNT \
848   compelse \
849   compchk LT, _p, 0x07 \
850   compchk GTEQ, _p, 0x00 \
851   __resetMotorCounter##_p(RESET_COUNT) \
852   compend
853 
854 #define __resetBlockTachoCount(_p) \
855   compif EQ, isconst(_p), FALSE \
856   setout _p, UpdateFlagsField, RESET_BLOCK_COUNT \
857   compelse \
858   compchk LT, _p, 0x07 \
859   compchk GTEQ, _p, 0x00 \
860   __resetMotorCounter##_p(RESET_BLOCK_COUNT) \
861   compend
862 
863 #define __resetRotationCount(_p) \
864   compif EQ, isconst(_p), FALSE \
865   setout _p, UpdateFlagsField, RESET_ROTATION_COUNT \
866   compelse \
867   compchk LT, _p, 0x07 \
868   compchk GTEQ, _p, 0x00 \
869   __resetMotorCounter##_p(RESET_ROTATION_COUNT) \
870   compend
871 
872 #define __resetAllTachoCounts(_p) \
873   compif EQ, isconst(_p), FALSE \
874   setout _p, UpdateFlagsField, RESET_ALL \
875   compelse \
876   compchk LT, _p, 0x07 \
877   compchk GTEQ, _p, 0x00 \
878   __resetMotorCounter##_p(RESET_ALL) \
879   compend
880 
881 #define __onFwdExPIDAll(_ports, _pwr, _reset, _p, _i, _d) setout _ports, PowerField, _pwr, OutputModeField, OUT_MODE_MOTORON+OUT_MODE_BRAKE, RegModeField, OUT_REGMODE_IDLE, RunStateField, OUT_RUNSTATE_RUNNING, TurnRatioField, 0, TachoLimitField, 0, RegPValueField, _p, RegIValueField, _i, RegDValueField, _d, UpdateFlagsField, UF_UPDATE_TACHO_LIMIT+UF_UPDATE_MODE+UF_UPDATE_SPEED+UF_UPDATE_PID_VALUES+_reset
882 #define __onFwdExPID0(_pwr, _reset, _p, _i, _d) __onFwdExPIDAll(OUT_A, _pwr, _reset, _p, _i, _d)
883 #define __onFwdExPID1(_pwr, _reset, _p, _i, _d) __onFwdExPIDAll(OUT_B, _pwr, _reset, _p, _i, _d)
884 #define __onFwdExPID2(_pwr, _reset, _p, _i, _d) __onFwdExPIDAll(OUT_C, _pwr, _reset, _p, _i, _d)
885 #define __onFwdExPID3(_pwr, _reset, _p, _i, _d) __onFwdExPIDAll(__OUT_AB, _pwr, _reset, _p, _i, _d)
886 #define __onFwdExPID4(_pwr, _reset, _p, _i, _d) __onFwdExPIDAll(__OUT_AC, _pwr, _reset, _p, _i, _d)
887 #define __onFwdExPID5(_pwr, _reset, _p, _i, _d) __onFwdExPIDAll(__OUT_BC, _pwr, _reset, _p, _i, _d)
888 #define __onFwdExPID6(_pwr, _reset, _p, _i, _d) __onFwdExPIDAll(__OUT_ABC, _pwr, _reset, _p, _i, _d)
889 
890 #define __coastExAll(_ports, _reset) setout _ports, PowerField, 0, OutputModeField, OUT_MODE_BRAKE, RegModeField, OUT_REGMODE_IDLE, RunStateField, OUT_RUNSTATE_IDLE, TurnRatioField, 0, TachoLimitField, 0, RegPValueField, PID_3, RegIValueField, PID_1, RegDValueField, PID_1, UpdateFlagsField, UF_UPDATE_TACHO_LIMIT+UF_UPDATE_MODE+UF_UPDATE_SPEED+UF_UPDATE_PID_VALUES+_reset
891 #define __coastEx0(_reset) __coastExAll(OUT_A, _reset)
892 #define __coastEx1(_reset) __coastExAll(OUT_B, _reset)
893 #define __coastEx2(_reset) __coastExAll(OUT_C, _reset)
894 #define __coastEx3(_reset) __coastExAll(__OUT_AB, _reset)
895 #define __coastEx4(_reset) __coastExAll(__OUT_AC, _reset)
896 #define __coastEx5(_reset) __coastExAll(__OUT_BC, _reset)
897 #define __coastEx6(_reset) __coastExAll(__OUT_ABC, _reset)
898 
899 #define __offExAll(_ports, _reset) setout _ports, PowerField, 0, OutputModeField, OUT_MODE_MOTORON+OUT_MODE_BRAKE, RegModeField, OUT_REGMODE_IDLE, RunStateField, OUT_RUNSTATE_RUNNING, TurnRatioField, 0, TachoLimitField, 0, RegPValueField, PID_3, RegIValueField, PID_1, RegDValueField, PID_1, UpdateFlagsField, UF_UPDATE_TACHO_LIMIT+UF_UPDATE_MODE+UF_UPDATE_SPEED+UF_UPDATE_PID_VALUES+_reset
900 #define __offEx0(_reset) __offExAll(OUT_A, _reset)
901 #define __offEx1(_reset) __offExAll(OUT_B, _reset)
902 #define __offEx2(_reset) __offExAll(OUT_C, _reset)
903 #define __offEx3(_reset) __offExAll(__OUT_AB, _reset)
904 #define __offEx4(_reset) __offExAll(__OUT_AC, _reset)
905 #define __offEx5(_reset) __offExAll(__OUT_BC, _reset)
906 #define __offEx6(_reset) __offExAll(__OUT_ABC, _reset)
907 
908 #define __onFwdRegExPIDAll(_ports, _pwr, _regmode, _reset, _p, _i, _d) setout _ports, PowerField, _pwr, OutputModeField, OUT_MODE_MOTORON+OUT_MODE_REGULATED+OUT_MODE_BRAKE, RegModeField, _regmode, RunStateField, OUT_RUNSTATE_RUNNING, TurnRatioField, 0, TachoLimitField, 0, RegPValueField, _p, RegIValueField, _i, RegDValueField, _d, UpdateFlagsField, UF_UPDATE_TACHO_LIMIT+UF_UPDATE_MODE+UF_UPDATE_SPEED+UF_UPDATE_PID_VALUES+_reset
909 #define __onFwdRegExPID0(_pwr, _regmode, _reset, _p, _i, _d) __onFwdRegExPIDAll(OUT_A, _pwr, _regmode, _reset, _p, _i, _d)
910 #define __onFwdRegExPID1(_pwr, _regmode, _reset, _p, _i, _d) __onFwdRegExPIDAll(OUT_B, _pwr, _regmode, _reset, _p, _i, _d)
911 #define __onFwdRegExPID2(_pwr, _regmode, _reset, _p, _i, _d) __onFwdRegExPIDAll(OUT_C, _pwr, _regmode, _reset, _p, _i, _d)
912 #define __onFwdRegExPID3(_pwr, _regmode, _reset, _p, _i, _d) __onFwdRegExPIDAll(__OUT_AB, _pwr, _regmode, _reset, _p, _i, _d)
913 #define __onFwdRegExPID4(_pwr, _regmode, _reset, _p, _i, _d) __onFwdRegExPIDAll(__OUT_AC, _pwr, _regmode, _reset, _p, _i, _d)
914 #define __onFwdRegExPID5(_pwr, _regmode, _reset, _p, _i, _d) __onFwdRegExPIDAll(__OUT_BC, _pwr, _regmode, _reset, _p, _i, _d)
915 #define __onFwdRegExPID6(_pwr, _regmode, _reset, _p, _i, _d) __onFwdRegExPIDAll(__OUT_ABC, _pwr, _regmode, _reset, _p, _i, _d)
916 
917 #define __onFwdSyncExPIDAll(_ports, _pwr, _turnpct, _reset, _p, _i, _d) setout _ports, PowerField, _pwr, OutputModeField, OUT_MODE_MOTORON+OUT_MODE_REGULATED+OUT_MODE_BRAKE, RegModeField, OUT_REGMODE_SYNC, TurnRatioField, _turnpct, RunStateField, OUT_RUNSTATE_RUNNING, TachoLimitField, 0, RegPValueField, _p, RegIValueField, _i, RegDValueField, _d, UpdateFlagsField, UF_UPDATE_TACHO_LIMIT+UF_UPDATE_MODE+UF_UPDATE_SPEED+UF_UPDATE_PID_VALUES+_reset
918 #define __onFwdSyncExPID0(_pwr, _turnpct, _reset, _p, _i, _d) __onFwdSyncExPIDAll(OUT_A, _pwr, _turnpct, _reset, _p, _i, _d)
919 #define __onFwdSyncExPID1(_pwr, _turnpct, _reset, _p, _i, _d) __onFwdSyncExPIDAll(OUT_B, _pwr, _turnpct, _reset, _p, _i, _d)
920 #define __onFwdSyncExPID2(_pwr, _turnpct, _reset, _p, _i, _d) __onFwdSyncExPIDAll(OUT_C, _pwr, _turnpct, _reset, _p, _i, _d)
921 #define __onFwdSyncExPID3(_pwr, _turnpct, _reset, _p, _i, _d) __onFwdSyncExPIDAll(__OUT_AB, _pwr, _turnpct, _reset, _p, _i, _d)
922 #define __onFwdSyncExPID4(_pwr, _turnpct, _reset, _p, _i, _d) __onFwdSyncExPIDAll(__OUT_AC, _pwr, _turnpct, _reset, _p, _i, _d)
923 #define __onFwdSyncExPID5(_pwr, _turnpct, _reset, _p, _i, _d) __onFwdSyncExPIDAll(__OUT_BC, _pwr, _turnpct, _reset, _p, _i, _d)
924 #define __onFwdSyncExPID6(_pwr, _turnpct, _reset, _p, _i, _d) __onFwdSyncExPIDAll(__OUT_ABC, _pwr, _turnpct, _reset, _p, _i, _d)
925 
926 #define __rotateMotorExPID0(_pwr, _angle, _turnpct, _bSync, _bStop, _p, _i, _d) \
927    acquire __rotateMutex0 \
928    arrbuild __rotate_ports0, OUT_A \
929    mov __rotate_power0, _pwr \
930    mov __rotate_angle0, _angle \
931    mov __rotate_turnpct0, _turnpct \
932    mov __rotate_sync0, _bSync \
933    mov __rotate_stop0, _bStop \
934    mov __rotate_theRVP0, _p \
935    mov __rotate_theRVI0, _i \
936    mov __rotate_theRVD0, _d \
937    call __RotateMotor0 \
938    release __rotateMutex0
939 
940 #define __rotateMotorExPID1(_pwr, _angle, _turnpct, _bSync, _bStop, _p, _i, _d) \
941    acquire __rotateMutex1 \
942    arrbuild __rotate_ports1, OUT_B \
943    mov __rotate_power1, _pwr \
944    mov __rotate_angle1, _angle \
945    mov __rotate_turnpct1, _turnpct \
946    mov __rotate_sync1, _bSync \
947    mov __rotate_stop1, _bStop \
948    mov __rotate_theRVP1, _p \
949    mov __rotate_theRVI1, _i \
950    mov __rotate_theRVD1, _d \
951    call __RotateMotor1 \
952    release __rotateMutex1
953 
954 #define __rotateMotorExPID2(_pwr, _angle, _turnpct, _bSync, _bStop, _p, _i, _d) \
955    acquire __rotateMutex2 \
956    arrbuild __rotate_ports2, OUT_C \
957    mov __rotate_power2, _pwr \
958    mov __rotate_angle2, _angle \
959    mov __rotate_turnpct2, _turnpct \
960    mov __rotate_sync2, _bSync \
961    mov __rotate_stop2, _bStop \
962    mov __rotate_theRVP2, _p \
963    mov __rotate_theRVI2, _i \
964    mov __rotate_theRVD2, _d \
965    call __RotateMotor2 \
966    release __rotateMutex2
967 
968 #define __rotateMotorExPID3(_pwr, _angle, _turnpct, _bSync, _bStop, _p, _i, _d) \
969    acquire __rotateMutex0 \
970    acquire __rotateMutex1 \
971    mov __rotate_ports3, __OUT_AB \
972    mov __rotate_power3, _pwr \
973    mov __rotate_angle3, _angle \
974    mov __rotate_turnpct3, _turnpct \
975    mov __rotate_sync3, _bSync \
976    mov __rotate_stop3, _bStop \
977    mov __rotate_theRVP3, _p \
978    mov __rotate_theRVI3, _i \
979    mov __rotate_theRVD3, _d \
980    call __RotateMotor3 \
981    release __rotateMutex1 \
982    release __rotateMutex0
983 
984 #define __rotateMotorExPID4(_pwr, _angle, _turnpct, _bSync, _bStop, _p, _i, _d) \
985    acquire __rotateMutex0 \
986    acquire __rotateMutex2 \
987    mov __rotate_ports4, __OUT_AC \
988    mov __rotate_power4, _pwr \
989    mov __rotate_angle4, _angle \
990    mov __rotate_turnpct4, _turnpct \
991    mov __rotate_sync4, _bSync \
992    mov __rotate_stop4, _bStop \
993    mov __rotate_theRVP4, _p \
994    mov __rotate_theRVI4, _i \
995    mov __rotate_theRVD4, _d \
996    call __RotateMotor4 \
997    release __rotateMutex2 \
998    release __rotateMutex0
999 
1000 #define __rotateMotorExPID5(_pwr, _angle, _turnpct, _bSync, _bStop, _p, _i, _d) \
1001    acquire __rotateMutex1 \
1002    acquire __rotateMutex2 \
1003    mov __rotate_ports5, __OUT_BC \
1004    mov __rotate_power5, _pwr \
1005    mov __rotate_angle5, _angle \
1006    mov __rotate_turnpct5, _turnpct \
1007    mov __rotate_sync5, _bSync \
1008    mov __rotate_stop5, _bStop \
1009    mov __rotate_theRVP5, _p \
1010    mov __rotate_theRVI5, _i \
1011    mov __rotate_theRVD5, _d \
1012    call __RotateMotor5 \
1013    release __rotateMutex2 \
1014    release __rotateMutex1
1015 
1016 #define __rotateMotorExPID6(_pwr, _angle, _turnpct, _bSync, _bStop, _p, _i, _d) \
1017    acquire __rotateMutex0 \
1018    acquire __rotateMutex1 \
1019    acquire __rotateMutex2 \
1020    mov __rotate_ports6, __OUT_ABC \
1021    mov __rotate_power6, _pwr \
1022    mov __rotate_angle6, _angle \
1023    mov __rotate_turnpct6, _turnpct \
1024    mov __rotate_sync6, _bSync \
1025    mov __rotate_stop6, _bStop \
1026    mov __rotate_theRVP6, _p \
1027    mov __rotate_theRVI6, _i \
1028    mov __rotate_theRVD6, _d \
1029    call __RotateMotor6 \
1030    release __rotateMutex2 \
1031    release __rotateMutex1 \
1032    release __rotateMutex0
1033 
1034 #define __rotateMotorExPIDVar(_ports, _pwr, _angle, _turnpct, _bSync, _bStop, _p, _i, _d) \
1035    acquire __rotateMutex0 \
1036    acquire __rotateMutex1 \
1037    acquire __rotateMutex2 \
1038    arrbuild __rotate_ports6, _ports \
1039    mov __rotate_power6, _pwr \
1040    mov __rotate_angle6, _angle \
1041    mov __rotate_turnpct6, _turnpct \
1042    mov __rotate_sync6, _bSync \
1043    mov __rotate_stop6, _bStop \
1044    mov __rotate_theRVP6, _p \
1045    mov __rotate_theRVI6, _i \
1046    mov __rotate_theRVD6, _d \
1047    call __RotateMotorVar \
1048    release __rotateMutex2 \
1049    release __rotateMutex1 \
1050    release __rotateMutex0
1051 
1052 subroutine __RotateMotor0
1053   brtst EQ, __rotate_Done0, __rotate_angle0
1054   sign __rotate_thePower0, __rotate_angle0
1055   abs __rotate_theAngle0, __rotate_angle0
1056   mul __rotate_thePower0, __rotate_thePower0, __rotate_power0 // convert __rotate_power to negative value if __rotate_angle is negative.
1057 
1058   set __rotate_theUF0, UF_UPDATE_TACHO_LIMIT+UF_UPDATE_SPEED+UF_UPDATE_MODE+UF_UPDATE_PID_VALUES
1059   brtst EQ, __rotate_NoSync0, __rotate_sync0
1060   set __rotate_theOM0, OUT_MODE_MOTORON+OUT_MODE_BRAKE+OUT_MODE_REGULATED
1061   set __rotate_theRM0, OUT_REGMODE_SYNC
1062   mov __rotate_theTurnPct0, __rotate_turnpct0
1063   brtst EQ, __rotate_Start0, __rotate_theTurnPct0
1064   add __rotate_theUF0, __rotate_theUF0, UF_UPDATE_RESET_BLOCK_COUNT
1065   jmp __rotate_Start0
1066 __rotate_NoSync0:
1067   set __rotate_theOM0, OUT_MODE_MOTORON+OUT_MODE_BRAKE
1068   set __rotate_theRM0, OUT_REGMODE_IDLE
1069   set __rotate_theTurnPct0, 0
1070 __rotate_Start0:
1071   set __rotate_theRS0, OUT_RUNSTATE_RUNNING
1072   setout __rotate_ports0, OutputModeField, __rotate_theOM0, RegModeField, __rotate_theRM0, TachoLimitField, __rotate_theAngle0, RunStateField, __rotate_theRS0, RegPValueField, __rotate_theRVP0, RegIValueField, __rotate_theRVI0, RegDValueField, __rotate_theRVD0, PowerField, __rotate_thePower0, TurnRatioField, __rotate_turnpct0, UpdateFlagsField, __rotate_theUF0
1073 
1074 // Waits till angle reached
1075   index __rotate_firstPort0, __rotate_ports0, NA
1076 __rotate_Running0:
1077   getout __rotate_power0, __rotate_firstPort0, PowerField
1078   brtst EQ, __rotate_doneRunning0, __rotate_power0
1079   getout __rotate_rs0, __rotate_firstPort0, RunStateField
1080   brcmp EQ, __rotate_Running0, __rotate_rs0, OUT_RUNSTATE_RUNNING
1081 __rotate_doneRunning0:
1082   brtst EQ, __rotate_Reset0, __rotate_stop0 // skip the speed regulation phase if __rotate_stop is false
1083 // Regulates for speed = 0
1084   set __rotate_theOM0, OUT_MODE_MOTORON+OUT_MODE_BRAKE+OUT_MODE_REGULATED
1085   set __rotate_theUF0, UF_UPDATE_TACHO_LIMIT+UF_UPDATE_SPEED+UF_UPDATE_MODE
1086   setout __rotate_ports0, OutputModeField, __rotate_theOM0, RegModeField, OUT_REGMODE_SPEED, RunStateField, __rotate_theRS0, PowerField, 0, TachoLimitField, 0, UpdateFlagsField, __rotate_theUF0
1087 // Verifies that motor doesn't rotate for 50ms, else loops
1088   getout __rotate_RotCount0, __rotate_firstPort0, RotationCountField
1089 __rotate_Stabilize0:
1090   mov __rotate_OldRotCount0, __rotate_RotCount0
1091   wait 50
1092   // check rotation
1093   getout __rotate_RotCount0, __rotate_firstPort0, RotationCountField
1094   brcmp NEQ, __rotate_Stabilize0, __rotate_OldRotCount0, __rotate_RotCount0
1095   set __rotate_theOM0, OUT_MODE_COAST+OUT_MODE_REGULATED
1096   setout __rotate_ports0, RegModeField, __rotate_theRM0, RunStateField, OUT_RUNSTATE_IDLE, OutputModeField, __rotate_theOM0, UpdateFlagsField, UF_UPDATE_MODE
1097 __rotate_Reset0:
1098   // maybe reset the block rotation count
1099   brtst EQ, __rotate_Done0, __rotate_theTurnPct0
1100   setout __rotate_ports0, UpdateFlagsField, UF_UPDATE_RESET_BLOCK_COUNT
1101 __rotate_Done0:
1102   return
1103 ends
1104 
1105 subroutine __RotateMotor1
1106   brtst EQ, __rotate_Done1, __rotate_angle1
1107   sign __rotate_thePower1, __rotate_angle1
1108   abs __rotate_theAngle1, __rotate_angle1
1109   mul __rotate_thePower1, __rotate_thePower1, __rotate_power1 // convert __rotate_power to negative value if __rotate_angle is negative.
1110 
1111   set __rotate_theUF1, UF_UPDATE_TACHO_LIMIT+UF_UPDATE_SPEED+UF_UPDATE_MODE+UF_UPDATE_PID_VALUES
1112   brtst EQ, __rotate_NoSync1, __rotate_sync1
1113   set __rotate_theOM1, OUT_MODE_MOTORON+OUT_MODE_BRAKE+OUT_MODE_REGULATED
1114   set __rotate_theRM1, OUT_REGMODE_SYNC
1115   mov __rotate_theTurnPct1, __rotate_turnpct1
1116   brtst EQ, __rotate_Start1, __rotate_theTurnPct1
1117   add __rotate_theUF1, __rotate_theUF1, UF_UPDATE_RESET_BLOCK_COUNT
1118   jmp __rotate_Start1
1119 __rotate_NoSync1:
1120   set __rotate_theOM1, OUT_MODE_MOTORON+OUT_MODE_BRAKE
1121   set __rotate_theRM1, OUT_REGMODE_IDLE
1122   set __rotate_theTurnPct1, 0
1123 __rotate_Start1:
1124   set __rotate_theRS1, OUT_RUNSTATE_RUNNING
1125   setout __rotate_ports1, OutputModeField, __rotate_theOM1, RegModeField, __rotate_theRM1, TachoLimitField, __rotate_theAngle1, RunStateField, __rotate_theRS1, RegPValueField, __rotate_theRVP1, RegIValueField, __rotate_theRVI1, RegDValueField, __rotate_theRVD1, PowerField, __rotate_thePower1, TurnRatioField, __rotate_turnpct1, UpdateFlagsField, __rotate_theUF1
1126 
1127 // Waits till angle reached
1128   index __rotate_firstPort1, __rotate_ports1, NA
1129 __rotate_Running1:
1130   getout __rotate_power1, __rotate_firstPort1, PowerField
1131   brtst EQ, __rotate_doneRunning1, __rotate_power1
1132   getout __rotate_rs1, __rotate_firstPort1, RunStateField
1133   brcmp EQ, __rotate_Running1, __rotate_rs1, OUT_RUNSTATE_RUNNING
1134 __rotate_doneRunning1:
1135   brtst EQ, __rotate_Reset1, __rotate_stop1 // skip the speed regulation phase if __rotate_stop is false
1136 // Regulates for speed = 0
1137   set __rotate_theOM1, OUT_MODE_MOTORON+OUT_MODE_BRAKE+OUT_MODE_REGULATED
1138   set __rotate_theUF1, UF_UPDATE_TACHO_LIMIT+UF_UPDATE_SPEED+UF_UPDATE_MODE
1139   setout __rotate_ports1, OutputModeField, __rotate_theOM1, RegModeField, OUT_REGMODE_SPEED, RunStateField, __rotate_theRS1, PowerField, 0, TachoLimitField, 0, UpdateFlagsField, __rotate_theUF1
1140 // Verifies that motor doesn't rotate for 50ms, else loops
1141   getout __rotate_RotCount1, __rotate_firstPort1, RotationCountField
1142 __rotate_Stabilize1:
1143   mov __rotate_OldRotCount1, __rotate_RotCount1
1144   wait 50
1145   // check rotation
1146   getout __rotate_RotCount1, __rotate_firstPort1, RotationCountField
1147   brcmp NEQ, __rotate_Stabilize1, __rotate_OldRotCount1, __rotate_RotCount1
1148   set __rotate_theOM1, OUT_MODE_COAST+OUT_MODE_REGULATED
1149   setout __rotate_ports1, RegModeField, __rotate_theRM1, RunStateField, OUT_RUNSTATE_IDLE, OutputModeField, __rotate_theOM1, UpdateFlagsField, UF_UPDATE_MODE
1150 __rotate_Reset1:
1151   // maybe reset the block rotation count
1152   brtst EQ, __rotate_Done1, __rotate_theTurnPct1
1153   setout __rotate_ports1, UpdateFlagsField, UF_UPDATE_RESET_BLOCK_COUNT
1154 __rotate_Done1:
1155   return
1156 ends
1157 
1158 subroutine __RotateMotor2
1159   brtst EQ, __rotate_Done2, __rotate_angle2
1160   sign __rotate_thePower2, __rotate_angle2
1161   abs __rotate_theAngle2, __rotate_angle2
1162   mul __rotate_thePower2, __rotate_thePower2, __rotate_power2 // convert __rotate_power to negative value if __rotate_angle is negative.
1163 
1164   set __rotate_theUF2, UF_UPDATE_TACHO_LIMIT+UF_UPDATE_SPEED+UF_UPDATE_MODE+UF_UPDATE_PID_VALUES
1165   brtst EQ, __rotate_NoSync2, __rotate_sync2
1166   set __rotate_theOM2, OUT_MODE_MOTORON+OUT_MODE_BRAKE+OUT_MODE_REGULATED
1167   set __rotate_theRM2, OUT_REGMODE_SYNC
1168   mov __rotate_theTurnPct2, __rotate_turnpct2
1169   brtst EQ, __rotate_Start2, __rotate_theTurnPct2
1170   add __rotate_theUF2, __rotate_theUF2, UF_UPDATE_RESET_BLOCK_COUNT
1171   jmp __rotate_Start2
1172 __rotate_NoSync2:
1173   set __rotate_theOM2, OUT_MODE_MOTORON+OUT_MODE_BRAKE
1174   set __rotate_theRM2, OUT_REGMODE_IDLE
1175   set __rotate_theTurnPct2, 0
1176 __rotate_Start2:
1177   set __rotate_theRS2, OUT_RUNSTATE_RUNNING
1178   setout __rotate_ports2, OutputModeField, __rotate_theOM2, RegModeField, __rotate_theRM2, TachoLimitField, __rotate_theAngle2, RunStateField, __rotate_theRS2, RegPValueField, __rotate_theRVP2, RegIValueField, __rotate_theRVI2, RegDValueField, __rotate_theRVD2, PowerField, __rotate_thePower2, TurnRatioField, __rotate_turnpct2, UpdateFlagsField, __rotate_theUF2
1179 
1180 // Waits till angle reached
1181   index __rotate_firstPort2, __rotate_ports2, NA
1182 __rotate_Running2:
1183   getout __rotate_power2, __rotate_firstPort2, PowerField
1184   brtst EQ, __rotate_doneRunning2, __rotate_power2
1185   getout __rotate_rs2, __rotate_firstPort2, RunStateField
1186   brcmp EQ, __rotate_Running2, __rotate_rs2, OUT_RUNSTATE_RUNNING
1187 __rotate_doneRunning2:
1188   brtst EQ, __rotate_Reset2, __rotate_stop2 // skip the speed regulation phase if __rotate_stop is false
1189 // Regulates for speed = 0
1190   set __rotate_theOM2, OUT_MODE_MOTORON+OUT_MODE_BRAKE+OUT_MODE_REGULATED
1191   set __rotate_theUF2, UF_UPDATE_TACHO_LIMIT+UF_UPDATE_SPEED+UF_UPDATE_MODE
1192   setout __rotate_ports2, OutputModeField, __rotate_theOM2, RegModeField, OUT_REGMODE_SPEED, RunStateField, __rotate_theRS2, PowerField, 0, TachoLimitField, 0, UpdateFlagsField, __rotate_theUF2
1193 // Verifies that motor doesn't rotate for 50ms, else loops
1194   getout __rotate_RotCount2, __rotate_firstPort2, RotationCountField
1195 __rotate_Stabilize2:
1196   mov __rotate_OldRotCount2, __rotate_RotCount2
1197   wait 50
1198   // check rotation
1199   getout __rotate_RotCount2, __rotate_firstPort2, RotationCountField
1200   brcmp NEQ, __rotate_Stabilize2, __rotate_OldRotCount2, __rotate_RotCount2
1201   set __rotate_theOM2, OUT_MODE_COAST+OUT_MODE_REGULATED
1202   setout __rotate_ports2, RegModeField, __rotate_theRM2, RunStateField, OUT_RUNSTATE_IDLE, OutputModeField, __rotate_theOM2, UpdateFlagsField, UF_UPDATE_MODE
1203 __rotate_Reset2:
1204   // maybe reset the block rotation count
1205   brtst EQ, __rotate_Done2, __rotate_theTurnPct2
1206   setout __rotate_ports2, UpdateFlagsField, UF_UPDATE_RESET_BLOCK_COUNT
1207 __rotate_Done2:
1208   return
1209 ends
1210 
1211 subroutine __RotateMotor3
1212   brtst EQ, __rotate_Done3, __rotate_angle3
1213   sign __rotate_thePower3, __rotate_angle3
1214   abs __rotate_theAngle3, __rotate_angle3
1215   mul __rotate_thePower3, __rotate_thePower3, __rotate_power3 // convert __rotate_power to negative value if __rotate_angle is negative.
1216 
1217   set __rotate_theUF3, UF_UPDATE_TACHO_LIMIT+UF_UPDATE_SPEED+UF_UPDATE_MODE+UF_UPDATE_PID_VALUES
1218   brtst EQ, __rotate_NoSync3, __rotate_sync3
1219   set __rotate_theOM3, OUT_MODE_MOTORON+OUT_MODE_BRAKE+OUT_MODE_REGULATED
1220   set __rotate_theRM3, OUT_REGMODE_SYNC
1221   mov __rotate_theTurnPct3, __rotate_turnpct3
1222   brtst EQ, __rotate_Start3, __rotate_theTurnPct3
1223   add __rotate_theUF3, __rotate_theUF3, UF_UPDATE_RESET_BLOCK_COUNT
1224   jmp __rotate_Start3
1225 __rotate_NoSync3:
1226   set __rotate_theOM3, OUT_MODE_MOTORON+OUT_MODE_BRAKE
1227   set __rotate_theRM3, OUT_REGMODE_IDLE
1228   set __rotate_theTurnPct3, 0
1229 __rotate_Start3:
1230   set __rotate_theRS3, OUT_RUNSTATE_RUNNING
1231   setout __rotate_ports3, OutputModeField, __rotate_theOM3, RegModeField, __rotate_theRM3, TachoLimitField, __rotate_theAngle3, RunStateField, __rotate_theRS3, RegPValueField, __rotate_theRVP3, RegIValueField, __rotate_theRVI3, RegDValueField, __rotate_theRVD3, PowerField, __rotate_thePower3, TurnRatioField, __rotate_turnpct3, UpdateFlagsField, __rotate_theUF3
1232 
1233 // Waits till angle reached
1234   index __rotate_firstPort3, __rotate_ports3, NA
1235 __rotate_Running3:
1236   getout __rotate_power3, __rotate_firstPort3, PowerField
1237   brtst EQ, __rotate_doneRunning3, __rotate_power3
1238   getout __rotate_rs3, __rotate_firstPort3, RunStateField
1239   brcmp EQ, __rotate_Running3, __rotate_rs3, OUT_RUNSTATE_RUNNING
1240 __rotate_doneRunning3:
1241   brtst EQ, __rotate_Reset3, __rotate_stop3 // skip the speed regulation phase if __rotate_stop is false
1242 // Regulates for speed = 0
1243   set __rotate_theOM3, OUT_MODE_MOTORON+OUT_MODE_BRAKE+OUT_MODE_REGULATED
1244   set __rotate_theUF3, UF_UPDATE_TACHO_LIMIT+UF_UPDATE_SPEED+UF_UPDATE_MODE
1245   setout __rotate_ports3, OutputModeField, __rotate_theOM3, RegModeField, OUT_REGMODE_SPEED, RunStateField, __rotate_theRS3, PowerField, 0, TachoLimitField, 0, UpdateFlagsField, __rotate_theUF3
1246 // Verifies that motor doesn't rotate for 50ms, else loops
1247   getout __rotate_RotCount3, __rotate_firstPort3, RotationCountField
1248 __rotate_Stabilize3:
1249   mov __rotate_OldRotCount3, __rotate_RotCount3
1250   wait 50
1251   // check rotation
1252   getout __rotate_RotCount3, __rotate_firstPort3, RotationCountField
1253   brcmp NEQ, __rotate_Stabilize3, __rotate_OldRotCount3, __rotate_RotCount3
1254   set __rotate_theOM3, OUT_MODE_COAST+OUT_MODE_REGULATED
1255   setout __rotate_ports3, RegModeField, __rotate_theRM3, RunStateField, OUT_RUNSTATE_IDLE, OutputModeField, __rotate_theOM3, UpdateFlagsField, UF_UPDATE_MODE
1256 __rotate_Reset3:
1257   // maybe reset the block rotation count
1258   brtst EQ, __rotate_Done3, __rotate_theTurnPct3
1259   setout __rotate_ports3, UpdateFlagsField, UF_UPDATE_RESET_BLOCK_COUNT
1260 __rotate_Done3:
1261   return
1262 ends
1263 
1264 subroutine __RotateMotor4
1265   brtst EQ, __rotate_Done4, __rotate_angle4
1266   sign __rotate_thePower4, __rotate_angle4
1267   abs __rotate_theAngle4, __rotate_angle4
1268   mul __rotate_thePower4, __rotate_thePower4, __rotate_power4 // convert __rotate_power to negative value if __rotate_angle is negative.
1269 
1270   set __rotate_theUF4, UF_UPDATE_TACHO_LIMIT+UF_UPDATE_SPEED+UF_UPDATE_MODE+UF_UPDATE_PID_VALUES
1271   brtst EQ, __rotate_NoSync4, __rotate_sync4
1272   set __rotate_theOM4, OUT_MODE_MOTORON+OUT_MODE_BRAKE+OUT_MODE_REGULATED
1273   set __rotate_theRM4, OUT_REGMODE_SYNC
1274   mov __rotate_theTurnPct4, __rotate_turnpct4
1275   brtst EQ, __rotate_Start4, __rotate_theTurnPct4
1276   add __rotate_theUF4, __rotate_theUF4, UF_UPDATE_RESET_BLOCK_COUNT
1277   jmp __rotate_Start4
1278 __rotate_NoSync4:
1279   set __rotate_theOM4, OUT_MODE_MOTORON+OUT_MODE_BRAKE
1280   set __rotate_theRM4, OUT_REGMODE_IDLE
1281   set __rotate_theTurnPct4, 0
1282 __rotate_Start4:
1283   set __rotate_theRS4, OUT_RUNSTATE_RUNNING
1284   setout __rotate_ports4, OutputModeField, __rotate_theOM4, RegModeField, __rotate_theRM4, TachoLimitField, __rotate_theAngle4, RunStateField, __rotate_theRS4, RegPValueField, __rotate_theRVP4, RegIValueField, __rotate_theRVI4, RegDValueField, __rotate_theRVD4, PowerField, __rotate_thePower4, TurnRatioField, __rotate_turnpct4, UpdateFlagsField, __rotate_theUF4
1285 
1286 // Waits till angle reached
1287   index __rotate_firstPort4, __rotate_ports4, NA
1288 __rotate_Running4:
1289   getout __rotate_power4, __rotate_firstPort4, PowerField
1290   brtst EQ, __rotate_doneRunning4, __rotate_power4
1291   getout __rotate_rs4, __rotate_firstPort4, RunStateField
1292   brcmp EQ, __rotate_Running4, __rotate_rs4, OUT_RUNSTATE_RUNNING
1293 __rotate_doneRunning4:
1294   brtst EQ, __rotate_Reset4, __rotate_stop4 // skip the speed regulation phase if __rotate_stop is false
1295 // Regulates for speed = 0
1296   set __rotate_theOM4, OUT_MODE_MOTORON+OUT_MODE_BRAKE+OUT_MODE_REGULATED
1297   set __rotate_theUF4, UF_UPDATE_TACHO_LIMIT+UF_UPDATE_SPEED+UF_UPDATE_MODE
1298   setout __rotate_ports4, OutputModeField, __rotate_theOM4, RegModeField, OUT_REGMODE_SPEED, RunStateField, __rotate_theRS4, PowerField, 0, TachoLimitField, 0, UpdateFlagsField, __rotate_theUF4
1299 // Verifies that motor doesn't rotate for 50ms, else loops
1300   getout __rotate_RotCount4, __rotate_firstPort4, RotationCountField
1301 __rotate_Stabilize4:
1302   mov __rotate_OldRotCount4, __rotate_RotCount4
1303   wait 50
1304   // check rotation
1305   getout __rotate_RotCount4, __rotate_firstPort4, RotationCountField
1306   brcmp NEQ, __rotate_Stabilize4, __rotate_OldRotCount4, __rotate_RotCount4
1307   set __rotate_theOM4, OUT_MODE_COAST+OUT_MODE_REGULATED
1308   setout __rotate_ports4, RegModeField, __rotate_theRM4, RunStateField, OUT_RUNSTATE_IDLE, OutputModeField, __rotate_theOM4, UpdateFlagsField, UF_UPDATE_MODE
1309 __rotate_Reset4:
1310   // maybe reset the block rotation count
1311   brtst EQ, __rotate_Done4, __rotate_theTurnPct4
1312   setout __rotate_ports4, UpdateFlagsField, UF_UPDATE_RESET_BLOCK_COUNT
1313 __rotate_Done4:
1314   return
1315 ends
1316 
1317 subroutine __RotateMotor5
1318   brtst EQ, __rotate_Done5, __rotate_angle5
1319   sign __rotate_thePower5, __rotate_angle5
1320   abs __rotate_theAngle5, __rotate_angle5
1321   mul __rotate_thePower5, __rotate_thePower5, __rotate_power5 // convert __rotate_power to negative value if __rotate_angle is negative.
1322 
1323   set __rotate_theUF5, UF_UPDATE_TACHO_LIMIT+UF_UPDATE_SPEED+UF_UPDATE_MODE+UF_UPDATE_PID_VALUES
1324   brtst EQ, __rotate_NoSync5, __rotate_sync5
1325   set __rotate_theOM5, OUT_MODE_MOTORON+OUT_MODE_BRAKE+OUT_MODE_REGULATED
1326   set __rotate_theRM5, OUT_REGMODE_SYNC
1327   mov __rotate_theTurnPct5, __rotate_turnpct5
1328   brtst EQ, __rotate_Start5, __rotate_theTurnPct5
1329   add __rotate_theUF5, __rotate_theUF5, UF_UPDATE_RESET_BLOCK_COUNT
1330   jmp __rotate_Start5
1331 __rotate_NoSync5:
1332   set __rotate_theOM5, OUT_MODE_MOTORON+OUT_MODE_BRAKE
1333   set __rotate_theRM5, OUT_REGMODE_IDLE
1334   set __rotate_theTurnPct5, 0
1335 __rotate_Start5:
1336   set __rotate_theRS5, OUT_RUNSTATE_RUNNING
1337   setout __rotate_ports5, OutputModeField, __rotate_theOM5, RegModeField, __rotate_theRM5, TachoLimitField, __rotate_theAngle5, RunStateField, __rotate_theRS5, RegPValueField, __rotate_theRVP5, RegIValueField, __rotate_theRVI5, RegDValueField, __rotate_theRVD5, PowerField, __rotate_thePower5, TurnRatioField, __rotate_turnpct5, UpdateFlagsField, __rotate_theUF5
1338 
1339 // Waits till angle reached
1340   index __rotate_firstPort5, __rotate_ports5, NA
1341 __rotate_Running5:
1342   getout __rotate_power5, __rotate_firstPort5, PowerField
1343   brtst EQ, __rotate_doneRunning5, __rotate_power5
1344   getout __rotate_rs5, __rotate_firstPort5, RunStateField
1345   brcmp EQ, __rotate_Running5, __rotate_rs5, OUT_RUNSTATE_RUNNING
1346 __rotate_doneRunning5:
1347   brtst EQ, __rotate_Reset5, __rotate_stop5 // skip the speed regulation phase if __rotate_stop is false
1348 // Regulates for speed = 0
1349   set __rotate_theOM5, OUT_MODE_MOTORON+OUT_MODE_BRAKE+OUT_MODE_REGULATED
1350   set __rotate_theUF5, UF_UPDATE_TACHO_LIMIT+UF_UPDATE_SPEED+UF_UPDATE_MODE
1351   setout __rotate_ports5, OutputModeField, __rotate_theOM5, RegModeField, OUT_REGMODE_SPEED, RunStateField, __rotate_theRS5, PowerField, 0, TachoLimitField, 0, UpdateFlagsField, __rotate_theUF5
1352 // Verifies that motor doesn't rotate for 50ms, else loops
1353   getout __rotate_RotCount5, __rotate_firstPort5, RotationCountField
1354 __rotate_Stabilize5:
1355   mov __rotate_OldRotCount5, __rotate_RotCount5
1356   wait 50
1357   // check rotation
1358   getout __rotate_RotCount5, __rotate_firstPort5, RotationCountField
1359   brcmp NEQ, __rotate_Stabilize5, __rotate_OldRotCount5, __rotate_RotCount5
1360   set __rotate_theOM5, OUT_MODE_COAST+OUT_MODE_REGULATED
1361   setout __rotate_ports5, RegModeField, __rotate_theRM5, RunStateField, OUT_RUNSTATE_IDLE, OutputModeField, __rotate_theOM5, UpdateFlagsField, UF_UPDATE_MODE
1362 __rotate_Reset5:
1363   // maybe reset the block rotation count
1364   brtst EQ, __rotate_Done5, __rotate_theTurnPct5
1365   setout __rotate_ports5, UpdateFlagsField, UF_UPDATE_RESET_BLOCK_COUNT
1366 __rotate_Done5:
1367   return
1368 ends
1369 
1370 subroutine __RotateMotor6
1371   brtst EQ, __rotate_Done6, __rotate_angle6
1372   sign __rotate_thePower6, __rotate_angle6
1373   abs __rotate_theAngle6, __rotate_angle6
1374   mul __rotate_thePower6, __rotate_thePower6, __rotate_power6 // convert __rotate_power to negative value if __rotate_angle is negative.
1375 
1376   set __rotate_theUF6, UF_UPDATE_TACHO_LIMIT+UF_UPDATE_SPEED+UF_UPDATE_MODE+UF_UPDATE_PID_VALUES
1377   brtst EQ, __rotate_NoSync6, __rotate_sync6
1378   set __rotate_theOM6, OUT_MODE_MOTORON+OUT_MODE_BRAKE+OUT_MODE_REGULATED
1379   set __rotate_theRM6, OUT_REGMODE_SYNC
1380   mov __rotate_theTurnPct6, __rotate_turnpct6
1381   brtst EQ, __rotate_Start6, __rotate_theTurnPct6
1382   add __rotate_theUF6, __rotate_theUF6, UF_UPDATE_RESET_BLOCK_COUNT
1383   jmp __rotate_Start6
1384 __rotate_NoSync6:
1385   set __rotate_theOM6, OUT_MODE_MOTORON+OUT_MODE_BRAKE
1386   set __rotate_theRM6, OUT_REGMODE_IDLE
1387   set __rotate_theTurnPct6, 0
1388 __rotate_Start6:
1389   set __rotate_theRS6, OUT_RUNSTATE_RUNNING
1390   setout __rotate_ports6, OutputModeField, __rotate_theOM6, RegModeField, __rotate_theRM6, TachoLimitField, __rotate_theAngle6, RunStateField, __rotate_theRS6, RegPValueField, __rotate_theRVP6, RegIValueField, __rotate_theRVI6, RegDValueField, __rotate_theRVD6, PowerField, __rotate_thePower6, TurnRatioField, __rotate_turnpct6, UpdateFlagsField, __rotate_theUF6
1391 
1392 // Waits till angle reached
1393   index __rotate_firstPort6, __rotate_ports6, NA
1394 __rotate_Running6:
1395   getout __rotate_power6, __rotate_firstPort6, PowerField
1396   brtst EQ, __rotate_doneRunning6, __rotate_power6
1397   getout __rotate_rs6, __rotate_firstPort6, RunStateField
1398   brcmp EQ, __rotate_Running6, __rotate_rs6, OUT_RUNSTATE_RUNNING
1399 __rotate_doneRunning6:
1400   brtst EQ, __rotate_Reset6, __rotate_stop6 // skip the speed regulation phase if __rotate_stop is false
1401 // Regulates for speed = 0
1402   set __rotate_theOM6, OUT_MODE_MOTORON+OUT_MODE_BRAKE+OUT_MODE_REGULATED
1403   set __rotate_theUF6, UF_UPDATE_TACHO_LIMIT+UF_UPDATE_SPEED+UF_UPDATE_MODE
1404   setout __rotate_ports6, OutputModeField, __rotate_theOM6, RegModeField, OUT_REGMODE_SPEED, RunStateField, __rotate_theRS6, PowerField, 0, TachoLimitField, 0, UpdateFlagsField, __rotate_theUF6
1405 // Verifies that motor doesn't rotate for 50ms, else loops
1406   getout __rotate_RotCount6, __rotate_firstPort6, RotationCountField
1407 __rotate_Stabilize6:
1408   mov __rotate_OldRotCount6, __rotate_RotCount6
1409   wait 50
1410   // check rotation
1411   getout __rotate_RotCount6, __rotate_firstPort6, RotationCountField
1412   brcmp NEQ, __rotate_Stabilize6, __rotate_OldRotCount6, __rotate_RotCount6
1413   set __rotate_theOM6, OUT_MODE_COAST+OUT_MODE_REGULATED
1414   setout __rotate_ports6, RegModeField, __rotate_theRM6, RunStateField, OUT_RUNSTATE_IDLE, OutputModeField, __rotate_theOM6, UpdateFlagsField, UF_UPDATE_MODE
1415 __rotate_Reset6:
1416   // maybe reset the block rotation count
1417   brtst EQ, __rotate_Done6, __rotate_theTurnPct6
1418   setout __rotate_ports6, UpdateFlagsField, UF_UPDATE_RESET_BLOCK_COUNT
1419 __rotate_Done6:
1420   return
1421 ends
1422 
1423 subroutine __RotateMotorVar
1424 /*
1425   _ports should be an array but it might be an integer from 0..6
1426   (OUT_A, OUT_B, OUT_C, OUT_AB, OUT_AC, OUT_BC, OUT_ABC)
1427   This subroutine converts, if necessary, an array containing a single byte
1428   > 2 into an array containing multiple bytes and then falls through to
1429   the RotateMotor6 subroutine.  It uses __rotate_rs6 as a temporary variable
1430 */
1431   arrsize __rotate_rs6, __rotate_ports6 // what is the size of the array?
1432   brcmp GT, __rmvCallSub, __rotate_rs6, 1 // fall through if size > 1
1433   // only one element in the array.  What is its value?
1434   index __rotate_rs6, __rotate_ports6, NA // grab the first element
1435   brcmp LT, __rmvCallSub, __rotate_rs6, 3 // if it is less than 3 just call the subroutine
1436   brcmp GT, __rmvExit, __rotate_rs6, 6 // if it is greater than 6 abort
1437   // start with 3
1438   mov __rotate_ports6, __OUT_AB
1439   brcmp EQ, __rmvCallSub, __rotate_rs6, 3
1440   mov __rotate_ports6, __OUT_AC
1441   brcmp EQ, __rmvCallSub, __rotate_rs6, 4
1442   mov __rotate_ports6, __OUT_BC
1443   brcmp EQ, __rmvCallSub, __rotate_rs6, 5
1444   mov __rotate_ports6, __OUT_ABC
1445 __rmvCallSub:
1446   call __RotateMotor6
1447 __rmvExit:
1448   return
1449 ends
1450 
1451 dseg segment
1452   __SensorInvalidTmp byte
1453 dseg ends
1454 
1455 dseg segment
1456   __ResetSensorMutex mutex
1457   __ResetSensorPort byte
1458   __ResetSensorTmp byte
1459 dseg ends
1460 
1461 subroutine __ResetSensorSubroutine
1462   setin TRUE, __ResetSensorPort, InvalidDataField
1463 __SensorStillInvalid:
1464   getin	__ResetSensorTmp, __ResetSensorPort, InvalidDataField
1465   brtst	NEQ, __SensorStillInvalid, __ResetSensorTmp
1466   return
1467 ends
1468 
1469 #define __ResetSensor(_port) \
1470   acquire __ResetSensorMutex \
1471   mov __ResetSensorPort, _port \
1472   call __ResetSensorSubroutine \
1473   release __ResetSensorMutex
1474 
1475 #define __SetSensorTouch(_port) \
1476   setin IN_TYPE_SWITCH, _port, TypeField \
1477   setin IN_MODE_BOOLEAN, _port, InputModeField \
1478   __ResetSensor(_port)
1479 
1480 #define __SetSensorLight(_port) \
1481   setin IN_TYPE_LIGHT_ACTIVE, _port, TypeField \
1482   setin IN_MODE_PCTFULLSCALE, _port, InputModeField \
1483   __ResetSensor(_port)
1484 
1485 #define __SetSensorSound(_port) \
1486   setin IN_TYPE_SOUND_DB, _port, TypeField \
1487   setin IN_MODE_PCTFULLSCALE, _port, InputModeField \
1488   __ResetSensor(_port)
1489 
1490 #define __SetSensorLowspeed(_port) \
1491   setin IN_TYPE_LOWSPEED_9V, _port, TypeField \
1492   setin IN_MODE_RAW, _port, InputModeField \
1493   __ResetSensor(_port)
1494 
1495 #if __FIRMWARE_VERSION > 107
1496 
1497 #define __SetSensorColorFull(_port) \
1498   setin IN_TYPE_COLORFULL, _port, TypeField \
1499   setin IN_MODE_RAW, _port, InputModeField \
1500   __ResetSensor(_port)
1501 
1502 #define __SetSensorColorRed(_port) \
1503   setin IN_TYPE_COLORRED, _port, TypeField \
1504   setin IN_MODE_PCTFULLSCALE, _port, InputModeField \
1505   __ResetSensor(_port)
1506 
1507 #define __SetSensorColorGreen(_port) \
1508   setin IN_TYPE_COLORGREEN, _port, TypeField \
1509   setin IN_MODE_PCTFULLSCALE, _port, InputModeField \
1510   __ResetSensor(_port)
1511 
1512 #define __SetSensorColorBlue(_port) \
1513   setin IN_TYPE_COLORBLUE, _port, TypeField \
1514   setin IN_MODE_PCTFULLSCALE, _port, InputModeField \
1515   __ResetSensor(_port)
1516 
1517 #define __SetSensorColorNone(_port) \
1518   setin IN_TYPE_COLORNONE, _port, TypeField \
1519   setin IN_MODE_PCTFULLSCALE, _port, InputModeField \
1520   __ResetSensor(_port)
1521 
1522 #endif
1523 
1524 dseg segment
1525 // port 0
1526   __CLSCSArgs0 TCommLSCheckStatus
1527   __CLSCSMutex0 mutex
1528   __CLSWArgs0 TCommLSWrite
1529   __CLSWMutex0 mutex
1530   __CLSRArgs0 TCommLSRead
1531   __CLSRMutex0 mutex
1532 // port 1
1533   __CLSCSArgs1 TCommLSCheckStatus
1534   __CLSCSMutex1 mutex
1535   __CLSWArgs1 TCommLSWrite
1536   __CLSWMutex1 mutex
1537   __CLSRArgs1 TCommLSRead
1538   __CLSRMutex1 mutex
1539 // port 2
1540   __CLSCSArgs2 TCommLSCheckStatus
1541   __CLSCSMutex2 mutex
1542   __CLSWArgs2 TCommLSWrite
1543   __CLSWMutex2 mutex
1544   __CLSRArgs2 TCommLSRead
1545   __CLSRMutex2 mutex
1546 // port 3
1547   __CLSCSArgs3 TCommLSCheckStatus
1548   __CLSCSMutex3 mutex
1549   __CLSWArgs3 TCommLSWrite
1550   __CLSWMutex3 mutex
1551   __CLSRArgs3 TCommLSRead
1552   __CLSRMutex3 mutex
1553 dseg ends
1554 
1555 #define __lowspeedStatus(_port, _bready, _result) \
1556   compif EQ, isconst(_port), FALSE \
1557   acquire __CLSCSMutex0 \
1558   acquire __CLSCSMutex1 \
1559   acquire __CLSCSMutex2 \
1560   acquire __CLSCSMutex3 \
1561   mov __CLSCSArgs0.Port, _port \
1562   syscall CommLSCheckStatus, __CLSCSArgs0 \
1563   mov _bready, __CLSCSArgs0.BytesReady \
1564   mov _result, __CLSCSArgs0.Result \
1565   release __CLSCSMutex0 \
1566   release __CLSCSMutex1 \
1567   release __CLSCSMutex2 \
1568   release __CLSCSMutex3 \
1569   compelse \
1570   compchk LT, _port, 0x04 \
1571   compchk GTEQ, _port, 0x00 \
1572   acquire __CLSCSMutex##_port \
1573   set __CLSCSArgs##_port.Port, _port \
1574   syscall CommLSCheckStatus, __CLSCSArgs##_port \
1575   mov _bready, __CLSCSArgs##_port.BytesReady \
1576   mov _result, __CLSCSArgs##_port.Result \
1577   release __CLSCSMutex##_port \
1578   compend
1579 
1580 #define __lowspeedCheckStatus(_port, _result) \
1581   compif EQ, isconst(_port), FALSE \
1582   acquire __CLSCSMutex0 \
1583   acquire __CLSCSMutex1 \
1584   acquire __CLSCSMutex2 \
1585   acquire __CLSCSMutex3 \
1586   mov __CLSCSArgs0.Port, _port \
1587   syscall CommLSCheckStatus, __CLSCSArgs0 \
1588   mov _result, __CLSCSArgs0.Result \
1589   release __CLSCSMutex0 \
1590   release __CLSCSMutex1 \
1591   release __CLSCSMutex2 \
1592   release __CLSCSMutex3 \
1593   compelse \
1594   compchk LT, _port, 0x04 \
1595   compchk GTEQ, _port, 0x00 \
1596   acquire __CLSCSMutex##_port \
1597   set __CLSCSArgs##_port.Port, _port \
1598   syscall CommLSCheckStatus, __CLSCSArgs##_port \
1599   mov _result, __CLSCSArgs##_port.Result \
1600   release __CLSCSMutex##_port \
1601   compend
1602 
1603 #define __lowspeedBytesReady(_port, _bready) \
1604   compif EQ, isconst(_port), FALSE \
1605   acquire __CLSCSMutex0 \
1606   acquire __CLSCSMutex1 \
1607   acquire __CLSCSMutex2 \
1608   acquire __CLSCSMutex3 \
1609   mov __CLSCSArgs0.Port, _port \
1610   syscall CommLSCheckStatus, __CLSCSArgs0 \
1611   mov _bready, __CLSCSArgs0.BytesReady \
1612   release __CLSCSMutex0 \
1613   release __CLSCSMutex1 \
1614   release __CLSCSMutex2 \
1615   release __CLSCSMutex3 \
1616   compelse \
1617   compchk LT, _port, 0x04 \
1618   compchk GTEQ, _port, 0x00 \
1619   acquire __CLSCSMutex##_port \
1620   set __CLSCSArgs##_port.Port, _port \
1621   syscall CommLSCheckStatus, __CLSCSArgs##_port \
1622   mov _bready, __CLSCSArgs##_port.BytesReady \
1623   release __CLSCSMutex##_port \
1624   compend
1625 
1626 #define __lowspeedWrite(_port, _retlen, _buffer, _result) \
1627   compif EQ, isconst(_port), FALSE \
1628   acquire __CLSWMutex0 \
1629   acquire __CLSWMutex1 \
1630   acquire __CLSWMutex2 \
1631   acquire __CLSWMutex3 \
1632   mov __CLSWArgs0.Port, _port \
1633   mov __CLSWArgs0.ReturnLen, _retlen \
1634   mov __CLSWArgs0.Buffer, _buffer \
1635   syscall CommLSWrite, __CLSWArgs0 \
1636   mov _result, __CLSWArgs0.Result \
1637   release __CLSWMutex0 \
1638   release __CLSWMutex1 \
1639   release __CLSWMutex2 \
1640   release __CLSWMutex3 \
1641   compelse \
1642   compchk LT, _port, 0x04 \
1643   compchk GTEQ, _port, 0x00 \
1644   acquire __CLSWMutex##_port \
1645   set __CLSWArgs##_port.Port, _port \
1646   mov __CLSWArgs##_port.ReturnLen, _retlen \
1647   mov __CLSWArgs##_port.Buffer, _buffer \
1648   syscall CommLSWrite, __CLSWArgs##_port \
1649   mov _result, __CLSWArgs##_port.Result \
1650   release __CLSWMutex##_port \
1651   compend
1652 
1653 #define __lowspeedRead(_port, _buflen, _buffer, _result) \
1654   compif EQ, isconst(_port), FALSE \
1655   acquire __CLSRMutex0 \
1656   acquire __CLSRMutex1 \
1657   acquire __CLSRMutex2 \
1658   acquire __CLSRMutex3 \
1659   mov __CLSRArgs0.Port, _port \
1660   mov __CLSRArgs0.BufferLen, _buflen \
1661   syscall CommLSRead, __CLSRArgs0 \
1662   mov _buffer, __CLSRArgs0.Buffer \
1663   mov _result, __CLSRArgs0.Result \
1664   release __CLSRMutex0 \
1665   release __CLSRMutex1 \
1666   release __CLSRMutex2 \
1667   release __CLSRMutex3 \
1668   compelse \
1669   compchk LT, _port, 0x04 \
1670   compchk GTEQ, _port, 0x00 \
1671   acquire __CLSRMutex##_port \
1672   set __CLSRArgs##_port.Port, _port \
1673   mov __CLSRArgs##_port.BufferLen, _buflen \
1674   syscall CommLSRead, __CLSRArgs##_port \
1675   mov _buffer, __CLSRArgs##_port.Buffer \
1676   mov _result, __CLSRArgs##_port.Result \
1677   release __CLSRMutex##_port \
1678   compend
1679 
1680 dseg segment
1681   __TextOutMutex mutex
1682   __TextOutArgs TDrawText
1683   __BlankLine byte[] '                    '
1684   __NumOutMutex mutex
1685   __NumOutArgs TDrawText
1686   __PointOutArgs TDrawPoint
1687   __PointOutMutex mutex
1688   __LineOutArgs TDrawLine
1689   __LineOutMutex mutex
1690   __RectOutArgs TDrawRect
1691   __RectOutMutex mutex
1692   __CircleOutArgs TDrawCircle
1693   __CircleOutMutex mutex
1694   __GraphicOutArgs TDrawGraphic
1695   __GraphicOutMutex mutex
1696   __GraphicOutEmptyVars sdword[]
1697 dseg ends
1698 
1699 #if defined(__ENHANCED_FIRMWARE) && (__FIRMWARE_VERSION > 107)
1700 
1701 dseg segment
1702   __GraphicArrayOutArgs TDrawGraphicArray
1703   __PolyOutArgs TDrawPolygon
1704   __PolyOutMutex mutex
1705   __EllipseOutArgs TDrawEllipse
1706   __EllipseOutMutex mutex
1707   __FontOutMutex mutex
1708   __FontOutArgs TDrawFont
1709   __MemMgrMutex mutex
1710   __MemMgrArgs TMemoryManager
1711   __ReadLastMutex mutex
1712   __ReadLastArgs TReadLastResponse
1713 dseg ends
1714 
1715 #endif
1716 
1717 #if __FIRMWARE_VERSION > 107
1718 
1719 dseg segment
1720   __ColorSensorReadArgs TColorSensorRead
1721   __ColorSensorReadMutex mutex
1722 dseg ends
1723 
1724 #define __ReadSensorColorRaw(_port, _rawVals, _result) \
1725   acquire __ColorSensorReadMutex \
1726   mov __ColorSensorReadArgs.Port,_port \
1727   syscall ColorSensorRead,__ColorSensorReadArgs \
1728   mov _rawVals, __ColorSensorReadArgs.RawArray \
1729   tst EQ, _result, __ColorSensorReadArgs.Result \
1730   release __ColorSensorReadMutex
1731 
1732 #define __ReadSensorColorEx(_port, _colorval, _rawVals, _normVals, _scaledVals, _result) \
1733   acquire __ColorSensorReadMutex \
1734   mov __ColorSensorReadArgs.Port,_port \
1735   syscall ColorSensorRead,__ColorSensorReadArgs \
1736   mov _colorval, __ColorSensorReadArgs.ColorValue \
1737   mov _rawVals, __ColorSensorReadArgs.RawArray \
1738   mov _normVals, __ColorSensorReadArgs.NormalizedArray \
1739   mov _scaledVals, __ColorSensorReadArgs.ScaledArray \
1740   tst EQ, _result, __ColorSensorReadArgs.Result \
1741   release __ColorSensorReadMutex
1742 
1743 #endif
1744 
1745 #define __OnFwdEx(_ports, _pwr, _reset) \
1746   compif EQ, isconst(_ports), FALSE \
1747   __onFwdExPIDAll(_ports, _pwr, _reset, PID_3, PID_1, PID_1) \
1748   compelse \
1749   compchk LT, _ports, 0x07 \
1750   compchk GTEQ, _ports, 0x00 \
1751   __onFwdExPID##_ports(_pwr, _reset, PID_3, PID_1, PID_1) \
1752   compend
1753 
1754 #define __OnRevEx(_ports, _pwr, _reset) \
1755   acquire __OnRevMutex \
1756   neg __OnRev_Tmp, _pwr \
1757   __OnFwdEx(_ports, __OnRev_Tmp, _reset) \
1758   release __OnRevMutex
1759 
1760 #define __OnFwdExPID(_ports, _pwr, _reset, _p, _i, _d) \
1761   compif EQ, isconst(_ports), FALSE \
1762   __onFwdExPIDAll(_ports, _pwr, _reset, _p, _i, _d) \
1763   compelse \
1764   compchk LT, _ports, 0x07 \
1765   compchk GTEQ, _ports, 0x00 \
1766   __onFwdExPID##_ports(_pwr, _reset, _p, _i, _d) \
1767   compend
1768 
1769 #define __OnRevExPID(_ports, _pwr, _reset, _p, _i, _d) \
1770   acquire __OnRevMutex \
1771   neg __OnRev_Tmp, _pwr \
1772   __OnFwdExPID(_ports, __OnRev_Tmp, _reset, _p, _i, _d) \
1773   release __OnRevMutex
1774 
1775 #define __CoastEx(_ports, _reset) \
1776   compif EQ, isconst(_ports), FALSE \
1777   __coastExAll(_ports, _reset) \
1778   compelse \
1779   compchk LT, _ports, 0x07 \
1780   compchk GTEQ, _ports, 0x00 \
1781   __coastEx##_ports(_reset) \
1782   compend
1783 
1784 #define __OffEx(_ports, _reset) \
1785   compif EQ, isconst(_ports), FALSE \
1786   __offExAll(_ports, _reset) \
1787   compelse \
1788   compchk LT, _ports, 0x07 \
1789   compchk GTEQ, _ports, 0x00 \
1790   __offEx##_ports(_reset) \
1791   compend
1792 
1793 #define __OnFwdRegEx(_ports, _pwr, _regmode, _reset) \
1794   compif EQ, isconst(_ports), FALSE \
1795   __onFwdRegExPIDAll(_ports, _pwr, _regmode, _reset, PID_3, PID_1, PID_1) \
1796   compelse \
1797   compchk LT, _ports, 0x07 \
1798   compchk GTEQ, _ports, 0x00 \
1799   __onFwdRegExPID##_ports(_pwr, _regmode, _reset, PID_3, PID_1, PID_1) \
1800   compend
1801 
1802 #define __OnRevRegEx(_ports, _pwr, _regmode, _reset) \
1803   acquire __OnRevMutex \
1804   neg __OnRev_Tmp, _pwr \
1805   __OnFwdRegEx(_ports, __OnRev_Tmp, _regmode, _reset) \
1806   release __OnRevMutex
1807 
1808 #define __OnFwdRegExPID(_ports, _pwr, _regmode, _reset, _p, _i, _d) \
1809   compif EQ, isconst(_ports), FALSE \
1810   __onFwdRegExPIDAll(_ports, _pwr, _regmode, _reset, _p, _i, _d) \
1811   compelse \
1812   compchk LT, _ports, 0x07 \
1813   compchk GTEQ, _ports, 0x00 \
1814   __onFwdRegExPID##_ports(_pwr, _regmode, _reset, _p, _i, _d) \
1815   compend
1816 
1817 #define __OnRevRegExPID(_ports, _pwr, _regmode, _reset, _p, _i, _d) \
1818   acquire __OnRevMutex \
1819   neg __OnRev_Tmp, _pwr \
1820   __OnFwdRegExPID(_ports, __OnRev_Tmp, _regmode, _reset, _p, _i, _d) \
1821   release __OnRevMutex
1822 
1823 #define __OnFwdSyncEx(_ports, _pwr, _turnpct, _reset) \
1824   compif EQ, isconst(_ports), FALSE \
1825   __onFwdSyncExPIDAll(_ports, _pwr, _turnpct, _reset, PID_3, PID_1, PID_1) \
1826   compelse \
1827   compchk LT, _ports, 0x07 \
1828   compchk GTEQ, _ports, 0x00 \
1829   __onFwdSyncExPID##_ports(_pwr, _turnpct, _reset, PID_3, PID_1, PID_1) \
1830   compend
1831 
1832 #define __OnRevSyncEx(_ports, _pwr, _turnpct, _reset) \
1833   acquire __OnRevMutex \
1834   neg __OnRev_Tmp, _pwr \
1835   __OnFwdSyncEx(_ports, __OnRev_Tmp, _turnpct, _reset) \
1836   release __OnRevMutex
1837 
1838 #define __OnFwdSyncExPID(_ports, _pwr, _turnpct, _reset, _p, _i, _d) \
1839   compif EQ, isconst(_ports), FALSE \
1840   __onFwdSyncExPIDAll(_ports, _pwr, _turnpct, _reset, _p, _i, _d) \
1841   compelse \
1842   compchk LT, _ports, 0x07 \
1843   compchk GTEQ, _ports, 0x00 \
1844   __onFwdSyncExPID##_ports(_pwr, _turnpct, _reset, _p, _i, _d) \
1845   compend
1846 
1847 #define __OnRevSyncExPID(_ports, _pwr, _turnpct, _reset, _p, _i, _d) \
1848   acquire __OnRevMutex \
1849   neg __OnRev_Tmp, _pwr \
1850   __OnFwdSyncExPID(_ports, __OnRev_Tmp, _turnpct, _reset, _p, _i, _d) \
1851   release __OnRevMutex
1852 
1853 #define __RotateMotorExPID(_ports, _pwr, _angle, _turnpct, _bSync, _bStop, _p, _i, _d) \
1854    compif EQ, isconst(_ports), FALSE \
1855    __rotateMotorExPIDVar(_ports, _pwr, _angle, _turnpct, _bSync, _bStop, _p, _i, _d) \
1856    compelse \
1857    compchk LT, _ports, 0x07 \
1858    compchk GTEQ, _ports, 0x00 \
1859    __rotateMotorExPID##_ports(_pwr, _angle, _turnpct, _bSync, _bStop, _p, _i, _d) \
1860    compend
1861 
1862 #define __TextOutEx(_x,_y,_txt,_options) \
1863   acquire __TextOutMutex \
1864   mov __TextOutArgs.Location.X,_x \
1865   mov __TextOutArgs.Location.Y,_y \
1866   mov __TextOutArgs.Options,_options \
1867   mov __TextOutArgs.Text,_txt \
1868   syscall DrawText,__TextOutArgs \
1869   release __TextOutMutex
1870 
1871 #define __NumOutEx(_x,_y,_num,_options) \
1872   acquire __NumOutMutex \
1873   mov __NumOutArgs.Location.X,_x \
1874   mov __NumOutArgs.Location.Y,_y \
1875   mov __NumOutArgs.Options,_options \
1876   numtostr __NumOutArgs.Text,_num \
1877   syscall DrawText,__NumOutArgs \
1878   release __NumOutMutex
1879 
1880 #define __PointOutEx(_x,_y,_options) \
1881   acquire __PointOutMutex \
1882   mov __PointOutArgs.Location.X,_x \
1883   mov __PointOutArgs.Location.Y,_y \
1884   mov __PointOutArgs.Options,_options \
1885   syscall DrawPoint,__PointOutArgs \
1886   release __PointOutMutex
1887 
1888 #define __LineOutEx(_x1,_y1,_x2,_y2,_options) \
1889   acquire __LineOutMutex \
1890   mov __LineOutArgs.StartLoc.X,_x1 \
1891   mov __LineOutArgs.StartLoc.Y,_y1 \
1892   mov __LineOutArgs.EndLoc.X,_x2 \
1893   mov __LineOutArgs.EndLoc.Y,_y2 \
1894   mov __LineOutArgs.Options,_options \
1895   syscall DrawLine,__LineOutArgs \
1896   release __LineOutMutex
1897 
1898 #define __RectOutEx(_x,_y,_w,_h,_options) \
1899   acquire __RectOutMutex \
1900   mov __RectOutArgs.Location.X,_x \
1901   mov __RectOutArgs.Location.Y,_y \
1902   mov __RectOutArgs.Size.Width,_w \
1903   mov __RectOutArgs.Size.Height,_h \
1904   mov __RectOutArgs.Options,_options \
1905   syscall DrawRect,__RectOutArgs \
1906   release __RectOutMutex
1907 
1908 #define __CircleOutEx(_x,_y,_r,_options) \
1909   acquire __CircleOutMutex \
1910   mov __CircleOutArgs.Center.X,_x \
1911   mov __CircleOutArgs.Center.Y,_y \
1912   mov __CircleOutArgs.Size,_r \
1913   mov __CircleOutArgs.Options,_options \
1914   syscall DrawCircle,__CircleOutArgs \
1915   release __CircleOutMutex
1916 
1917 #define __GraphicOutEx(_x,_y,_file,_vars,_options) \
1918   acquire __GraphicOutMutex \
1919   mov __GraphicOutArgs.Location.X,_x \
1920   mov __GraphicOutArgs.Location.Y,_y \
1921   mov __GraphicOutArgs.Filename,_file \
1922   mov __GraphicOutArgs.Variables,_vars \
1923   mov __GraphicOutArgs.Options,_options \
1924   syscall DrawGraphic,__GraphicOutArgs \
1925   release __GraphicOutMutex
1926 
1927 #if defined(__ENHANCED_FIRMWARE) && (__FIRMWARE_VERSION > 107)
1928 
1929 #define __GraphicArrayOutEx(_x,_y,_data,_vars,_options) \
1930   acquire __GraphicOutMutex \
1931   mov __GraphicArrayOutArgs.Location.X,_x \
1932   mov __GraphicArrayOutArgs.Location.Y,_y \
1933   mov __GraphicArrayOutArgs.Data,_data \
1934   mov __GraphicArrayOutArgs.Variables,_vars \
1935   mov __GraphicArrayOutArgs.Options,_options \
1936   syscall DrawGraphicArray,__GraphicArrayOutArgs \
1937   release __GraphicOutMutex
1938 
1939 #define __PolyOutEx(_points,_options) \
1940   acquire __PolyOutMutex \
1941   mov __PolyOutArgs.Points,_points \
1942   mov __PolyOutArgs.Options,_options \
1943   syscall DrawPolygon,__PolyOutArgs \
1944   release __PolyOutMutex
1945 
1946 #define __EllipseOutEx(_x,_y,_rX,_rY,_options) \
1947   acquire __EllipseOutMutex \
1948   mov __EllipseOutArgs.Center.X,_x \
1949   mov __EllipseOutArgs.Center.Y,_y \
1950   mov __EllipseOutArgs.SizeX,_rX \
1951   mov __EllipseOutArgs.SizeY,_rY \
1952   mov __EllipseOutArgs.Options,_options \
1953   syscall DrawEllipse,__EllipseOutArgs \
1954   release __EllipseOutMutex
1955 
1956 #define __FontTextOutEx(_x,_y,_fnt,_txt,_options) \
1957   acquire __FontOutMutex \
1958   mov __FontOutArgs.Location.X,_x \
1959   mov __FontOutArgs.Location.Y,_y \
1960   mov __FontOutArgs.Options,_options \
1961   mov __FontOutArgs.Filename,_fnt \
1962   mov __FontOutArgs.Text,_txt \
1963   syscall DrawFont,__FontOutArgs \
1964   release __FontOutMutex
1965 
1966 #define __FontNumOutEx(_x,_y,_fnt,_num,_options) \
1967   acquire __FontOutMutex \
1968   mov __FontOutArgs.Location.X,_x \
1969   mov __FontOutArgs.Location.Y,_y \
1970   mov __FontOutArgs.Options,_options \
1971   mov __FontOutArgs.Filename,_fnt \
1972   numtostr __FontOutArgs.Text,_num \
1973   syscall DrawFont,__FontOutArgs \
1974   release __FontOutMutex
1975 
1976 #define __GetMemoryInfo(_Compact,_PoolSize,_DataspaceSize,_Result) \
1977   acquire __MemMgrMutex \
1978   mov __MemMgrArgs.Compact,_Compact \
1979   syscall MemoryManager,__MemMgrArgs \
1980   mov _PoolSize, __MemMgrArgs.PoolSize \
1981   mov _DataspaceSize, __MemMgrArgs.DataspaceSize \
1982   mov _Result, __MemMgrArgs.Result \
1983   release __MemMgrMutex
1984 
1985 #define __GetLastResponseInfo(_Clear,_Length,_Command,_Buffer,_Result) \
1986   acquire __ReadLastMutex \
1987   mov __ReadLastArgs.Clear,_Clear \
1988   syscall ReadLastResponse,__ReadLastArgs \
1989   mov _Buffer, __ReadLastArgs.Buffer \
1990   mov _Length, __ReadLastArgs.Length \
1991   mov _Command, __ReadLastArgs.Command \
1992   mov _Result, __ReadLastArgs.Result \
1993   release __ReadLastMutex
1994 
1995 
1996 #endif
1997 
1998 dseg segment
1999   __RLSBbufLSWrite1 byte[] 0x02, 0x42
2000   __RSEMeterLSBuf byte[] 0x04, 0x0A
2001   __RSTempConfigLSBuf byte[] 0x98, 0x01, 0x60
2002   __RSTempLSBuf byte[] 0x98, 0x00
2003   __RSTempRaw slong
2004 dseg ends
2005 
2006 #define __ReadI2CBytes(_port, _inbuf, _count, _outbuf, _result) \
2007   compif EQ, isconst(_port), FALSE \
2008   acquire __RLSBmutex0 \
2009   acquire __RLSBmutex1 \
2010   acquire __RLSBmutex2 \
2011   acquire __RLSBmutex3 \
2012   mov __RLSReadPort, _port \
2013   mov __RLSReadBufVar, _inbuf \
2014   mov __RLSBytesCountVar, _count \
2015   call __ReadLSBytesVar \
2016   tst EQ, _result, __RLSBResultVar \
2017   mov _count, __RLSBytesCountVar \
2018   mov _outbuf, __RLSReadBufVar \
2019   release __RLSBmutex0 \
2020   release __RLSBmutex1 \
2021   release __RLSBmutex2 \
2022   release __RLSBmutex3 \
2023   compelse \
2024   compchk LT, _port, 0x04 \
2025   compchk GTEQ, _port, 0x00 \
2026   acquire __RLSBmutex##_port \
2027   mov __RLSReadBuf##_port, _inbuf \
2028   mov __RLSBytesCount##_port, _count \
2029   call __ReadLSBytes##_port \
2030   tst EQ, _result, __RLSBResult##_port \
2031   mov _count, __RLSBytesCount##_port \
2032   mov _outbuf, __RLSReadBuf##_port \
2033   release __RLSBmutex##_port \
2034   compend
2035 
2036 #define __ReadSensorUS(_port, _value) \
2037   compif EQ, isconst(_port), FALSE \
2038   acquire __RLSBmutex0 \
2039   acquire __RLSBmutex1 \
2040   acquire __RLSBmutex2 \
2041   acquire __RLSBmutex3 \
2042   mov __RLSReadPort, _port \
2043   mov __RLSReadBufVar, __RLSBbufLSWrite1 \
2044   set __RLSBytesCountVar, 1 \
2045   wait 15 \
2046   call __ReadLSBytesVar \
2047   index _value, __RLSReadBufVar, NA \
2048   release __RLSBmutex0 \
2049   release __RLSBmutex1 \
2050   release __RLSBmutex2 \
2051   release __RLSBmutex3 \
2052   compelse \
2053   compchk LT, _port, 0x04 \
2054   compchk GTEQ, _port, 0x00 \
2055   acquire __RLSBmutex##_port \
2056   mov __RLSReadBuf##_port, __RLSBbufLSWrite1 \
2057   set __RLSBytesCount##_port, 1 \
2058   wait 15 \
2059   call __ReadLSBytes##_port \
2060   index _value, __RLSReadBuf##_port, NA \
2061   release __RLSBmutex##_port \
2062   compend
2063 
2064 #define __ReadSensorUSEx(_port, _values, _result) \
2065   compif EQ, isconst(_port), FALSE \
2066   acquire __RLSBmutex0 \
2067   acquire __RLSBmutex1 \
2068   acquire __RLSBmutex2 \
2069   acquire __RLSBmutex3 \
2070   mov __RLSReadPort, _port \
2071   mov __RLSReadBufVar, __RLSBbufLSWrite1 \
2072   set __RLSBytesCountVar, 8 \
2073   wait 15 \
2074   call __ReadLSBytesVar \
2075   tst EQ, _result, __RLSBResultVar \
2076   mov _values, __RLSReadBufVar \
2077   release __RLSBmutex0 \
2078   release __RLSBmutex1 \
2079   release __RLSBmutex2 \
2080   release __RLSBmutex3 \
2081   compelse \
2082   compchk LT, _port, 0x04 \
2083   compchk GTEQ, _port, 0x00 \
2084   acquire __RLSBmutex##_port \
2085   mov __RLSReadBuf##_port, __RLSBbufLSWrite1 \
2086   set __RLSBytesCount##_port, 8 \
2087   wait 15 \
2088   call __ReadLSBytes##_port \
2089   tst EQ, _result, __RLSBResult##_port \
2090   mov _values, __RLSReadBuf##_port \
2091   release __RLSBmutex##_port \
2092   compend
2093 
2094 #define __ReadSensorEMeter(_port, _vIn, _aIn, _vOut, _aOut, _joules, _wIn, _wOut, _result) \
2095   compif EQ, isconst(_port), FALSE \
2096   acquire __RLSBmutex0 \
2097   acquire __RLSBmutex1 \
2098   acquire __RLSBmutex2 \
2099   acquire __RLSBmutex3 \
2100   mov __RLSReadPort, _port \
2101   mov __RLSReadBufVar, __RSEMeterLSBuf \
2102   set __RLSBytesCountVar, 14 \
2103   call __ReadLSBytesVar \
2104   tst EQ, _result, __RLSBResultVar \
2105   index __RLSBytesCountVar, __RLSReadBufVar, NA \
2106   index _vIn, __RLSReadBufVar, 1 \
2107   mul _vIn, _vIn, 256 \
2108   add _vIn, _vIn, __RLSBytesCountVar \
2109   div _vIn, _vIn, 1000 \
2110   index __RLSBytesCountVar, __RLSReadBufVar, 2 \
2111   index _aIn, __RLSReadBufVar, 3 \
2112   mul _aIn, _aIn, 256 \
2113   add _aIn, _aIn, __RLSBytesCountVar \
2114   div _aIn, _aIn, 1000 \
2115   index __RLSBytesCountVar, __RLSReadBufVar, 4 \
2116   index _vOut, __RLSReadBufVar, 5 \
2117   mul _vOut, _vOut, 256 \
2118   add _vOut, _vOut, __RLSBytesCountVar \
2119   div _vOut, _vOut, 1000 \
2120   index __RLSBytesCountVar, __RLSReadBufVar, 6 \
2121   index _aOut, __RLSReadBufVar, 7 \
2122   mul _aOut, _aOut, 256 \
2123   add _aOut, _aOut, __RLSBytesCountVar \
2124   div _aOut, _aOut, 1000 \
2125   index __RLSBytesCountVar, __RLSReadBufVar, 8 \
2126   index _joules, __RLSReadBufVar, 9 \
2127   mul _joules, _joules, 256 \
2128   add _joules, _joules, __RLSBytesCountVar \
2129   index __RLSBytesCountVar, __RLSReadBufVar, 10 \
2130   index _wIn, __RLSReadBufVar, 11 \
2131   mul _wIn, _wIn, 256 \
2132   add _wIn, _wIn, __RLSBytesCountVar \
2133   div _wIn, _wIn, 1000 \
2134   index __RLSBytesCountVar, __RLSReadBufVar, 12 \
2135   index _wOut, __RLSReadBufVar, 13 \
2136   mul _wOut, _wOut, 256 \
2137   add _wOut, _wOut, __RLSBytesCountVar \
2138   div _wOut, _wOut, 1000 \
2139   release __RLSBmutex0 \
2140   release __RLSBmutex1 \
2141   release __RLSBmutex2 \
2142   release __RLSBmutex3 \
2143   compelse \
2144   compchk LT, _port, 0x04 \
2145   compchk GTEQ, _port, 0x00 \
2146   acquire __RLSBmutex##_port \
2147   mov __RLSReadBuf##_port, __RSEMeterLSBuf \
2148   set __RLSBytesCount##_port, 14 \
2149   call __ReadLSBytes##_port \
2150   tst EQ, _result, __RLSBResult##_port \
2151   index __RLSBytesCount##_port, __RLSReadBuf##_port, NA \
2152   index _vIn, __RLSReadBuf##_port, 1 \
2153   mul _vIn, _vIn, 256 \
2154   add _vIn, _vIn, __RLSBytesCount##_port \
2155   div _vIn, _vIn, 1000 \
2156   index __RLSBytesCount##_port, __RLSReadBuf##_port, 2 \
2157   index _aIn, __RLSReadBuf##_port, 3 \
2158   mul _aIn, _aIn, 256 \
2159   add _aIn, _aIn, __RLSBytesCount##_port \
2160   div _aIn, _aIn, 1000 \
2161   index __RLSBytesCount##_port, __RLSReadBuf##_port, 4 \
2162   index _vOut, __RLSReadBuf##_port, 5 \
2163   mul _vOut, _vOut, 256 \
2164   add _vOut, _vOut, __RLSBytesCount##_port \
2165   div _vOut, _vOut, 1000 \
2166   index __RLSBytesCount##_port, __RLSReadBuf##_port, 6 \
2167   index _aOut, __RLSReadBuf##_port, 7 \
2168   mul _aOut, _aOut, 256 \
2169   add _aOut, _aOut, __RLSBytesCount##_port \
2170   div _aOut, _aOut, 1000 \
2171   index __RLSBytesCount##_port, __RLSReadBuf##_port, 8 \
2172   index _joules, __RLSReadBuf##_port, 9 \
2173   mul _joules, _joules, 256 \
2174   add _joules, _joules, __RLSBytesCount##_port \
2175   index __RLSBytesCount##_port, __RLSReadBuf##_port, 10 \
2176   index _wIn, __RLSReadBuf##_port, 11 \
2177   mul _wIn, _wIn, 256 \
2178   add _wIn, _wIn, __RLSBytesCount##_port \
2179   div _wIn, _wIn, 1000 \
2180   index __RLSBytesCount##_port, __RLSReadBuf##_port, 12 \
2181   index _wOut, __RLSReadBuf##_port, 13 \
2182   mul _wOut, _wOut, 256 \
2183   add _wOut, _wOut, __RLSBytesCount##_port \
2184   div _wOut, _wOut, 1000 \
2185   release __RLSBmutex##_port \
2186   compend
2187 
2188 #define __ReadSensorTemperature(_port, _temp) \
2189   compif EQ, isconst(_port), FALSE \
2190   acquire __RLSBmutex0 \
2191   acquire __RLSBmutex1 \
2192   acquire __RLSBmutex2 \
2193   acquire __RLSBmutex3 \
2194   mov __RLSReadPort, _port \
2195   mov __RLSReadBufVar, __RSTempLSBuf \
2196   set __RLSBytesCountVar, 2 \
2197   call __ReadLSBytesVar \
2198   index __RSTempRaw, __RLSReadBufVar, NA \
2199   index __RLSBytesCountVar, __RLSReadBufVar, 1 \
2200   mul __RSTempRaw, __RSTempRaw, 256 \
2201   add __RSTempRaw, __RSTempRaw, __RLSBytesCountVar \
2202   mul __RSTempRaw, __RSTempRaw, 10 \
2203   div __RSTempRaw, __RSTempRaw, 16 \
2204   div _temp, __RSTempRaw, 16 \
2205   brcmp LTEQ, __RRT_EndIf##__I__, __RSTempRaw, 20470 \
2206   sub _temp, _temp, 2560 \
2207   __RRT_EndIf##__I__: \
2208   __IncI__ \
2209   compif EQ, typeof(_temp), 10 \
2210   div _temp, _temp, 10 \
2211   compend \
2212   release __RLSBmutex0 \
2213   release __RLSBmutex1 \
2214   release __RLSBmutex2 \
2215   release __RLSBmutex3 \
2216   compelse \
2217   compchk LT, _port, 0x04 \
2218   compchk GTEQ, _port, 0x00 \
2219   acquire __RLSBmutex##_port \
2220   mov __RLSReadBuf##_port, __RSTempLSBuf \
2221   set __RLSBytesCount##_port, 2 \
2222   call __ReadLSBytes##_port \
2223   index __RSTempRaw, __RLSReadBuf##_port, NA \
2224   index __RLSBytesCount##_port, __RLSReadBuf##_port, 1 \
2225   mul __RSTempRaw, __RSTempRaw, 256 \
2226   add __RSTempRaw, __RSTempRaw, __RLSBytesCount##_port \
2227   mul __RSTempRaw, __RSTempRaw, 10 \
2228   div __RSTempRaw, __RSTempRaw, 16 \
2229   div _temp, __RSTempRaw, 16 \
2230   brcmp LTEQ, __RRT_EndIf##__I__, __RSTempRaw, 20470 \
2231   sub _temp, _temp, 2560 \
2232   __RRT_EndIf##__I__: \
2233   __IncI__ \
2234   compif EQ, typeof(_temp), 10 \
2235   div _temp, _temp, 10 \
2236   compend \
2237   release __RLSBmutex##_port \
2238   compend
2239 
2240 subroutine __ReadLSBytes0
2241   dseg segment
2242     __RLSBmutex0 mutex
2243     __RLSLastGoodRead0 byte[] 0x00
2244     __RLSBResult0 sbyte
2245     __RLSBytesCount0 byte
2246     __RLSBIterations0 byte
2247     __RLSReadBuf0 byte[]
2248   dseg ends
2249   __lowspeedWrite(0, __RLSBytesCount0, __RLSReadBuf0, __RLSBResult0)
2250   brtst EQ, __RLSBReturn0, __RLSBytesCount0 // terminate if zero bytes to read
2251   arrinit __RLSReadBuf0, 0, __RLSBytesCount0
2252   brtst NEQ, __RLSBError0, __RLSBResult0 // terminate if not NO_ERR
2253   set __RLSBIterations0, 4
2254 __RLSBDoCheckStatus0:
2255   __lowspeedStatus(0, __RLSBytesCount0, __RLSBResult0)
2256   sub __RLSBIterations0, __RLSBIterations0, 1
2257   brtst LTEQ, __RLSBError0, __RLSBIterations0
2258   brtst LT, __RLSBError0, __RLSBResult0 // negative results are absolute errors
2259   brtst EQ, __RLSBReadyToRead0, __RLSBResult0
2260   // if STAT_COMM_PENDING then wait a bit and then try again (up to 4 times)
2261   wait 15
2262   jmp __RLSBDoCheckStatus0
2263 __RLSBReadyToRead0:
2264   // Try reading now
2265   __lowspeedRead(0, __RLSBytesCount0, __RLSReadBuf0, __RLSBResult0)
2266   brtst NEQ, __RLSBError0, __RLSBResult0 // terminate if not NO_ERR
2267   mov __RLSLastGoodRead0, __RLSReadBuf0
2268   jmp __RLSBDone0
2269 __RLSBError0:
2270   mov __RLSReadBuf0, __RLSLastGoodRead0
2271 __RLSBDone0:
2272   arrsize __RLSBytesCount0, __RLSReadBuf0
2273 __RLSBReturn0:
2274   return
2275 ends
2276 
2277 subroutine __ReadLSBytes1
2278   dseg segment
2279     __RLSBmutex1 mutex
2280     __RLSLastGoodRead1 byte[] 0x00
2281     __RLSBResult1 sbyte
2282     __RLSBytesCount1 byte
2283     __RLSBIterations1 byte
2284     __RLSReadBuf1 byte[]
2285   dseg ends
2286   __lowspeedWrite(1, __RLSBytesCount1, __RLSReadBuf1, __RLSBResult1)
2287   brtst EQ, __RLSBReturn1, __RLSBytesCount1 // terminate if zero bytes to read
2288   arrinit __RLSReadBuf1, 0, __RLSBytesCount1
2289   brtst NEQ, __RLSBError1, __RLSBResult1 // terminate if not NO_ERR
2290   set __RLSBIterations1, 4
2291 __RLSBDoCheckStatus1:
2292   __lowspeedStatus(1, __RLSBytesCount1, __RLSBResult1)
2293   sub __RLSBIterations1, __RLSBIterations1, 1
2294   brtst LTEQ, __RLSBError1, __RLSBIterations1
2295   brtst LT, __RLSBError1, __RLSBResult1 // negative results are absolute errors
2296   brtst EQ, __RLSBReadyToRead1, __RLSBResult1
2297   // if STAT_COMM_PENDING then wait a bit and then try again (up to 4 times)
2298   wait 15
2299   jmp __RLSBDoCheckStatus1
2300 __RLSBReadyToRead1:
2301   // Try reading now
2302   __lowspeedRead(1, __RLSBytesCount1, __RLSReadBuf1, __RLSBResult1)
2303   brtst NEQ, __RLSBError1, __RLSBResult1 // terminate if not NO_ERR
2304   mov __RLSLastGoodRead1, __RLSReadBuf1
2305   jmp __RLSBDone1
2306 __RLSBError1:
2307   mov __RLSReadBuf1, __RLSLastGoodRead1
2308 __RLSBDone1:
2309   arrsize __RLSBytesCount1, __RLSReadBuf1
2310 __RLSBReturn1:
2311   return
2312 ends
2313 
2314 subroutine __ReadLSBytes2
2315   dseg segment
2316     __RLSBmutex2 mutex
2317     __RLSLastGoodRead2 byte[] 0x00
2318     __RLSBResult2 sbyte
2319     __RLSBytesCount2 byte
2320     __RLSBIterations2 byte
2321     __RLSReadBuf2 byte[]
2322   dseg ends
2323   __lowspeedWrite(2, __RLSBytesCount2, __RLSReadBuf2, __RLSBResult2)
2324   brtst EQ, __RLSBReturn2, __RLSBytesCount2 // terminate if zero bytes to read
2325   arrinit __RLSReadBuf2, 0, __RLSBytesCount2
2326   brtst NEQ, __RLSBError2, __RLSBResult2 // terminate if not NO_ERR
2327   set __RLSBIterations2, 4
2328 __RLSBDoCheckStatus2:
2329   __lowspeedStatus(2, __RLSBytesCount2, __RLSBResult2)
2330   sub __RLSBIterations2, __RLSBIterations2, 1
2331   brtst LTEQ, __RLSBError2, __RLSBIterations2
2332   brtst LT, __RLSBError2, __RLSBResult2 // negative results are absolute errors
2333   brtst EQ, __RLSBReadyToRead2, __RLSBResult2
2334   // if STAT_COMM_PENDING then wait a bit and then try again (up to 4 times)
2335   wait 15
2336   jmp __RLSBDoCheckStatus2
2337 __RLSBReadyToRead2:
2338   // Try reading now
2339   __lowspeedRead(2, __RLSBytesCount2, __RLSReadBuf2, __RLSBResult2)
2340   brtst NEQ, __RLSBError2, __RLSBResult2 // terminate if not NO_ERR
2341   mov __RLSLastGoodRead2, __RLSReadBuf2
2342   jmp __RLSBDone2
2343 __RLSBError2:
2344   mov __RLSReadBuf2, __RLSLastGoodRead2
2345 __RLSBDone2:
2346   arrsize __RLSBytesCount2, __RLSReadBuf2
2347 __RLSBReturn2:
2348   return
2349 ends
2350 
2351 subroutine __ReadLSBytes3
2352   dseg segment
2353     __RLSBmutex3 mutex
2354     __RLSLastGoodRead3 byte[] 0x00
2355     __RLSBResult3 sbyte
2356     __RLSBytesCount3 byte
2357     __RLSBIterations3 byte
2358     __RLSReadBuf3 byte[]
2359   dseg ends
2360   __lowspeedWrite(3, __RLSBytesCount3, __RLSReadBuf3, __RLSBResult3)
2361   brtst EQ, __RLSBReturn3, __RLSBytesCount3 // terminate if zero bytes to read
2362   arrinit __RLSReadBuf3, 0, __RLSBytesCount3
2363   brtst NEQ, __RLSBError3, __RLSBResult3 // terminate if not NO_ERR
2364   set __RLSBIterations3, 4
2365 __RLSBDoCheckStatus3:
2366   __lowspeedStatus(3, __RLSBytesCount3, __RLSBResult3)
2367   sub __RLSBIterations3, __RLSBIterations3, 1
2368   brtst LTEQ, __RLSBError3, __RLSBIterations3
2369   brtst LT, __RLSBError3, __RLSBResult3 // negative results are absolute errors
2370   brtst EQ, __RLSBReadyToRead3, __RLSBResult3
2371   // if STAT_COMM_PENDING then wait a bit and then try again (up to 4 times)
2372   wait 15
2373   jmp __RLSBDoCheckStatus3
2374 __RLSBReadyToRead3:
2375   // Try reading now
2376   __lowspeedRead(3, __RLSBytesCount3, __RLSReadBuf3, __RLSBResult3)
2377   brtst NEQ, __RLSBError3, __RLSBResult3 // terminate if not NO_ERR
2378   mov __RLSLastGoodRead3, __RLSReadBuf3
2379   jmp __RLSBDone3
2380 __RLSBError3:
2381   mov __RLSReadBuf3, __RLSLastGoodRead3
2382 __RLSBDone3:
2383   arrsize __RLSBytesCount3, __RLSReadBuf3
2384 __RLSBReturn3:
2385   return
2386 ends
2387 
2388 subroutine __ReadLSBytesVar
2389   dseg segment
2390     __RLSLastGoodReadVar byte[] 0x00
2391     __RLSBResultVar sbyte
2392     __RLSBytesCountVar byte
2393     __RLSBIterationsVar byte
2394     __RLSReadBufVar byte[]
2395     __RLSReadPort byte
2396   dseg ends
2397   __lowspeedWrite(__RLSReadPort, __RLSBytesCountVar, __RLSReadBufVar, __RLSBResultVar)
2398   brtst EQ, __RLSBReturnVar, __RLSBytesCountVar // terminate if zero bytes to read
2399   arrinit __RLSReadBufVar, 0, __RLSBytesCountVar
2400   brtst NEQ, __RLSBErrorVar, __RLSBResultVar // terminate if not NO_ERR
2401   set __RLSBIterationsVar, 4
2402 __RLSBDoCheckStatusVar:
2403   __lowspeedStatus(__RLSReadPort, __RLSBytesCountVar, __RLSBResultVar)
2404   sub __RLSBIterationsVar, __RLSBIterationsVar, 1
2405   brtst LTEQ, __RLSBErrorVar, __RLSBIterationsVar
2406   brtst LT, __RLSBErrorVar, __RLSBResultVar // negative results are absolute errors
2407   brtst EQ, __RLSBReadyToReadVar, __RLSBResultVar
2408   // if STAT_COMM_PENDING then wait a bit and then try again (up to 4 times)
2409   wait 15
2410   jmp __RLSBDoCheckStatusVar
2411 __RLSBReadyToReadVar:
2412   // Try reading now
2413   __lowspeedRead(__RLSReadPort, __RLSBytesCountVar, __RLSReadBufVar, __RLSBResultVar)
2414   brtst NEQ, __RLSBErrorVar, __RLSBResultVar // terminate if not NO_ERR
2415   mov __RLSLastGoodReadVar, __RLSReadBufVar
2416   jmp __RLSBDoneVar
2417 __RLSBErrorVar:
2418   mov __RLSReadBufVar, __RLSLastGoodReadVar
2419 __RLSBDoneVar:
2420   arrsize __RLSBytesCountVar, __RLSReadBufVar
2421 __RLSBReturnVar:
2422   return
2423 ends
2424 
2425 dseg segment
2426   __PlayToneTmp TSoundPlayTone
2427   __PlayFileTmp TSoundPlayFile
2428   __PlayFileMutex mutex
2429   __PlayToneMutex mutex
2430   __SGSMutex mutex
2431   __SGSArgs TSoundGetState
2432   __SSSMutex mutex
2433   __SSSArgs TSoundSetState
2434   __RandomTmp dword
2435   __RandomArgs TRandomNumber
2436   __RandomMutex mutex
2437   __KeepAliveArgs TKeepAlive
2438   __KeepAliveMutex mutex
2439   __GSTArgs TGetStartTick
2440   __GSTMutex mutex
2441   __RBtnMutex mutex
2442   __RBtnArgs TReadButton
2443   __IOMRMutex mutex
2444   __IOMRArgs TIOMapRead
2445   __IOMRUnflattenErr byte
2446   __IOMRUnflattenBuf byte[]
2447 dseg ends
2448 
2449 
2450 #define __PlayToneEx(_freq,_dur,_vol,_loop) \
2451   acquire __PlayToneMutex \
2452   mov __PlayToneTmp.Frequency, _freq \
2453   mov __PlayToneTmp.Duration, _dur \
2454   mov __PlayToneTmp.Volume, _vol \
2455   mov __PlayToneTmp.Loop, _loop \
2456   syscall SoundPlayTone, __PlayToneTmp \
2457   release __PlayToneMutex
2458 
2459 #define __PlayFileEx(_file,_vol,_loop) \
2460   acquire __PlayFileMutex \
2461   mov __PlayFileTmp.Filename, _file \
2462   mov __PlayFileTmp.Volume, _vol \
2463   mov __PlayFileTmp.Loop, _loop \
2464   syscall SoundPlayFile, __PlayFileTmp \
2465   release __PlayFileMutex
2466 
2467 #define __setSoundState(_state, _flags, _result) \
2468   acquire __SSSMutex \
2469   mov __SSSArgs.State, _state \
2470   mov __SSSArgs.Flags, _flags \
2471   syscall SoundSetState, __SSSArgs \
2472   mov _result, __SSSArgs.Result \
2473   release __SSSMutex
2474 
2475 #define __GetSoundState(_state, _flags) \
2476   acquire __SGSMutex \
2477   syscall SoundGetState, __SGSArgs \
2478   mov _state, __SGSArgs.State \
2479   mov _flags, __SGSArgs.Flags \
2480   release __SGSMutex
2481 
2482 #define __Random(_arg,_max) \
2483   acquire __RandomMutex \
2484   syscall RandomNumber, __RandomArgs \
2485   mov __RandomTmp, __RandomArgs.Result \
2486   add __RandomTmp, __RandomTmp, 32768 \
2487   mul __RandomTmp, __RandomTmp, _max \
2488   div __RandomTmp, __RandomTmp, 65536 \
2489   mov _arg, __RandomTmp \
2490   release __RandomMutex
2491 
2492 #define __SignedRandom(_arg) \
2493   acquire __RandomMutex \
2494   syscall RandomNumber, __RandomArgs \
2495   mov _arg, __RandomArgs.Result \
2496   release __RandomMutex
2497 
2498 #define __GetFirstTick(_value) \
2499   compchk EQ, sizeof(_value), 4 \
2500   acquire __GSTMutex \
2501   syscall GetStartTick, __GSTArgs \
2502   mov _value, __GSTArgs.Result \
2503   release __GSTMutex
2504 
2505 #define __ReadButtonEx(_idx, _reset, _pressed, _count, _result) \
2506   acquire __RBtnMutex \
2507   mov __RBtnArgs.Index, _idx \
2508   mov __RBtnArgs.Reset, _reset \
2509   syscall ReadButton, __RBtnArgs \
2510   mov _pressed, __RBtnArgs.Pressed \
2511   mov _count, __RBtnArgs.Count \
2512   mov _result, __RBtnArgs.Result \
2513   release __RBtnMutex
2514 
2515 #define __getIOMapBytes(_modName, _offset, _cnt, _arrOut) \
2516   acquire __IOMRMutex \
2517   mov __IOMRArgs.ModuleName, _modName \
2518   mov __IOMRArgs.Offset, _offset \
2519   mov __IOMRArgs.Count, _cnt \
2520   syscall IOMapRead, __IOMRArgs \
2521   mov _arrOut, __IOMRArgs.Buffer \
2522   release __IOMRMutex
2523 
2524 #define __getIOMapValue(_modName, _offset, _n) \
2525   acquire __IOMRMutex \
2526   mov __IOMRArgs.ModuleName, _modName \
2527   mov __IOMRArgs.Offset, _offset \
2528   set __IOMRArgs.Count, sizeof(_n) \
2529   syscall IOMapRead, __IOMRArgs \
2530   arrtostr __IOMRUnflattenBuf, __IOMRArgs.Buffer \
2531   unflatten _n, __IOMRUnflattenErr, __IOMRUnflattenBuf, _n \
2532   release __IOMRMutex
2533 
2534 #ifdef __ENHANCED_FIRMWARE
2535 
2536 dseg segment
2537   __IOMRBIArgs TIOMapReadByID
2538 dseg ends
2539 
2540 #define __getIOMapBytesByID(_modID, _offset, _cnt, _arrOut) \
2541   acquire __IOMRMutex \
2542   mov __IOMRBIArgs.ModuleID, _modID \
2543   mov __IOMRBIArgs.Offset, _offset \
2544   mov __IOMRBIArgs.Count, _cnt \
2545   syscall IOMapReadByID, __IOMRBIArgs \
2546   mov _arrOut, __IOMRBIArgs.Buffer \
2547   release __IOMRMutex
2548 
2549 #define __getIOMapValueByID(_modID, _offset, _n) \
2550   acquire __IOMRMutex \
2551   mov __IOMRBIArgs.ModuleID, _modID \
2552   mov __IOMRBIArgs.Offset, _offset \
2553   set __IOMRBIArgs.Count, sizeof(_n) \
2554   syscall IOMapReadByID, __IOMRBIArgs \
2555   arrtostr __IOMRUnflattenBuf, __IOMRBIArgs.Buffer \
2556   unflatten _n, __IOMRUnflattenErr, __IOMRUnflattenBuf, _n \
2557   release __IOMRMutex
2558 
2559 #define __getLowSpeedModuleBytes(_offset, _cnt, _arrOut) __getIOMapBytesByID(LowSpeedModuleID, _offset, _cnt, _arrOut)
2560 #define __getDisplayModuleBytes(_offset, _cnt, _arrOut) __getIOMapBytesByID(DisplayModuleID, _offset, _cnt, _arrOut)
2561 #define __getCommModuleBytes(_offset, _cnt, _arrOut) __getIOMapBytesByID(CommModuleID, _offset, _cnt, _arrOut)
2562 #define __getCommandModuleBytes(_offset, _cnt, _arrOut) __getIOMapBytesByID(CommandModuleID, _offset, _cnt, _arrOut)
2563 
2564 #else
2565 
2566 #define __getLowSpeedModuleBytes(_offset, _cnt, _arrOut) __getIOMapBytes(LowSpeedModuleName, _offset, _cnt, _arrOut)
2567 #define __getDisplayModuleBytes(_offset, _cnt, _arrOut) __getIOMapBytes(DisplayModuleName, _offset, _cnt, _arrOut)
2568 #define __getCommModuleBytes(_offset, _cnt, _arrOut) __getIOMapBytes(CommModuleName, _offset, _cnt, _arrOut)
2569 #define __getCommandModuleBytes(_offset, _cnt, _arrOut) __getIOMapBytes(CommandModuleName, _offset, _cnt, _arrOut)
2570 
2571 #endif
2572 
2573 #define __GetFreeMemory(_value) \
2574   compchk EQ, sizeof(_value), 4 \
2575   GetLoaderModuleValue(LoaderOffsetFreeUserFlash, _value)
2576 
2577 #define __GetSoundFrequency(_n) \
2578   compchk EQ, sizeof(_n), 2 \
2579   GetSoundModuleValue(SoundOffsetFreq, _n)
2580 
2581 #define __GetSoundDuration(_n) \
2582   compchk EQ, sizeof(_n), 2 \
2583   GetSoundModuleValue(SoundOffsetDuration, _n)
2584 
2585 #define __GetSoundSampleRate(_n) \
2586   compchk EQ, sizeof(_n), 2 \
2587   GetSoundModuleValue(SoundOffsetSampleRate, _n)
2588 
2589 #define __GetSoundMode(_n) \
2590   compchk EQ, sizeof(_n), 1 \
2591   GetSoundModuleValue(SoundOffsetMode, _n)
2592 
2593 #define __GetSoundVolume(_n) \
2594   compchk EQ, sizeof(_n), 1 \
2595   GetSoundModuleValue(SoundOffsetVolume, _n)
2596 
2597 dseg segment
2598   __btnModuleOffsetMutex mutex
2599   __btnModuleOffset word
2600 dseg ends
2601 
2602 #define __GetButtonPressCount(_b, _n) \
2603   compchk EQ, sizeof(_n), 1 \
2604   compif EQ, isconst(_b), TRUE \
2605   compchk LT, _b, 0x04 \
2606   compchk GTEQ, _b, 0x00 \
2607   GetButtonModuleValue(ButtonOffsetPressedCnt(_b), _n) \
2608   compelse \
2609   acquire __btnModuleOffsetMutex \
2610   mul __btnModuleOffset, _b, 8 \
2611   GetButtonModuleValue(__btnModuleOffset, _n) \
2612   release __btnModuleOffsetMutex \
2613   compend
2614 
2615 #define __GetButtonLongPressCount(_b, _n) \
2616   compchk EQ, sizeof(_n), 1 \
2617   compif EQ, isconst(_b), TRUE \
2618   compchk LT, _b, 0x04 \
2619   compchk GTEQ, _b, 0x00 \
2620   GetButtonModuleValue(ButtonOffsetLongPressCnt(_b), _n) \
2621   compelse \
2622   acquire __btnModuleOffsetMutex \
2623   mul __btnModuleOffset, _b, 8 \
2624   add __btnModuleOffset, __btnModuleOffset, 1 \
2625   GetButtonModuleValue(__btnModuleOffset, _n) \
2626   release __btnModuleOffsetMutex \
2627   compend
2628 
2629 #define __GetButtonShortReleaseCount(_b, _n) \
2630   compchk EQ, sizeof(_n), 1 \
2631   compif EQ, isconst(_b), TRUE \
2632   compchk LT, _b, 0x04 \
2633   compchk GTEQ, _b, 0x00 \
2634   GetButtonModuleValue(ButtonOffsetShortRelCnt(_b), _n) \
2635   compelse \
2636   acquire __btnModuleOffsetMutex \
2637   mul __btnModuleOffset, _b, 8 \
2638   add __btnModuleOffset, __btnModuleOffset, 2 \
2639   GetButtonModuleValue(__btnModuleOffset, _n) \
2640   release __btnModuleOffsetMutex \
2641   compend
2642 
2643 #define __GetButtonLongReleaseCount(_b, _n) \
2644   compchk EQ, sizeof(_n), 1 \
2645   compif EQ, isconst(_b), TRUE \
2646   compchk LT, _b, 0x04 \
2647   compchk GTEQ, _b, 0x00 \
2648   GetButtonModuleValue(ButtonOffsetLongRelCnt(_b), _n) \
2649   compelse \
2650   acquire __btnModuleOffsetMutex \
2651   mul __btnModuleOffset, _b, 8 \
2652   add __btnModuleOffset, __btnModuleOffset, 3 \
2653   GetButtonModuleValue(__btnModuleOffset, _n) \
2654   release __btnModuleOffsetMutex \
2655   compend
2656 
2657 #define __GetButtonReleaseCount(_b, _n) \
2658   compchk EQ, sizeof(_n), 1 \
2659   compif EQ, isconst(_b), TRUE \
2660   compchk LT, _b, 0x04 \
2661   compchk GTEQ, _b, 0x00 \
2662   GetButtonModuleValue(ButtonOffsetRelCnt(_b), _n) \
2663   compelse \
2664   acquire __btnModuleOffsetMutex \
2665   mul __btnModuleOffset, _b, 8 \
2666   add __btnModuleOffset, __btnModuleOffset, 4 \
2667   GetButtonModuleValue(__btnModuleOffset, _n) \
2668   release __btnModuleOffsetMutex \
2669   compend
2670 
2671 #define __GetButtonState(_b, _n) \
2672   compchk EQ, sizeof(_n), 1 \
2673   compif EQ, isconst(_b), TRUE \
2674   compchk LT, _b, 0x04 \
2675   compchk GTEQ, _b, 0x00 \
2676   GetButtonModuleValue(ButtonOffsetState(_b), _n) \
2677   compelse \
2678   acquire __btnModuleOffsetMutex \
2679   add __btnModuleOffset, _b, 32 \
2680   GetButtonModuleValue(__btnModuleOffset, _n) \
2681   release __btnModuleOffsetMutex \
2682   compend
2683 
2684 #define __GetBatteryLevel(_n) \
2685   compchk EQ, sizeof(_n), 2 \
2686   GetUIModuleValue(UIOffsetBatteryVoltage, _n)
2687 
2688 #define __GetCommandFlags(_n) \
2689   compchk EQ, sizeof(_n), 1 \
2690   GetUIModuleValue(UIOffsetFlags, _n)
2691 
2692 #define __GetUIState(_n) \
2693   compchk EQ, sizeof(_n), 1 \
2694   GetUIModuleValue(UIOffsetState, _n)
2695 
2696 #define __GetUIButton(_n) \
2697   compchk EQ, sizeof(_n), 1 \
2698   GetUIModuleValue(UIOffsetButton, _n)
2699 
2700 #define __GetVMRunState(_n) \
2701   compchk EQ, sizeof(_n), 1 \
2702   GetUIModuleValue(UIOffsetRunState, _n)
2703 
2704 #define __GetBatteryState(_n) \
2705   compchk EQ, sizeof(_n), 1 \
2706   GetUIModuleValue(UIOffsetBatteryState, _n)
2707 
2708 #define __GetBluetoothState(_n) \
2709   compchk EQ, sizeof(_n), 1 \
2710   GetUIModuleValue(UIOffsetBluetoothState, _n)
2711 
2712 #define __GetUsbState(_n) \
2713   compchk EQ, sizeof(_n), 1 \
2714   GetUIModuleValue(UIOffsetUsbState, _n)
2715 
2716 #define __GetSleepTimeout(_n) \
2717   compchk EQ, sizeof(_n), 1 \
2718   GetUIModuleValue(UIOffsetSleepTimeout, _n)
2719 
2720 #define __GetSleepTimer(_n) \
2721   compchk EQ, sizeof(_n), 1 \
2722   GetUIModuleValue(UIOffsetSleepTimer, _n)
2723 
2724 #define __GetRechargeableBattery(_n) \
2725   compchk EQ, sizeof(_n), 1 \
2726   GetUIModuleValue(UIOffsetRechargeable, _n)
2727 
2728 #define __GetVolume(_n) \
2729   compchk EQ, sizeof(_n), 1 \
2730   GetUIModuleValue(UIOffsetVolume, _n)
2731 
2732 #define __GetOnBrickProgramPointer(_n) \
2733   compchk EQ, sizeof(_n), 1 \
2734   GetUIModuleValue(UIOffsetOBPPointer, _n)
2735 
2736 #define __GetAbortFlag(_n) \
2737   compchk EQ, sizeof(_n), 1 \
2738   GetUIModuleValue(UIOffsetAbortFlag, _n)
2739 
2740 dseg segment
2741   __inputModuleOffsetMutex mutex
2742   __inputModuleOffset word
2743   __inputModuleOffsetTmp word
2744 dseg ends
2745 
2746 #define __GetInCustomZeroOffset(_p, _n) \
2747   compchk EQ, sizeof(_n), 2 \
2748   compif EQ, isconst(_p), TRUE \
2749   compchk LT, _p, 0x04 \
2750   compchk GTEQ, _p, 0x00 \
2751   GetInputModuleValue(InputOffsetCustomZeroOffset(_p), _n) \
2752   compelse \
2753   acquire __inputModuleOffsetMutex \
2754   mul __inputModuleOffset, _p, 20 \
2755   GetInputModuleValue(__inputModuleOffset, _n) \
2756   release __inputModuleOffsetMutex \
2757   compend
2758 
2759 #define __GetInSensorBoolean(_p, _n) \
2760   compchk EQ, sizeof(_n), 1 \
2761   compif EQ, isconst(_p), TRUE \
2762   compchk LT, _p, 0x04 \
2763   compchk GTEQ, _p, 0x00 \
2764   GetInputModuleValue(InputOffsetSensorBoolean(_p), _n) \
2765   compelse \
2766   acquire __inputModuleOffsetMutex \
2767   mul __inputModuleOffset, _p, 20 \
2768   add __inputModuleOffset, __inputModuleOffset, 10 \
2769   GetInputModuleValue(__inputModuleOffset, _n) \
2770   release __inputModuleOffsetMutex \
2771   compend
2772 
2773 #define __GetInDigiPinsDirection(_p, _n) \
2774   compchk EQ, sizeof(_n), 1 \
2775   compif EQ, isconst(_p), TRUE \
2776   compchk LT, _p, 0x04 \
2777   compchk GTEQ, _p, 0x00 \
2778   GetInputModuleValue(InputOffsetDigiPinsDir(_p), _n) \
2779   compelse \
2780   acquire __inputModuleOffsetMutex \
2781   mul __inputModuleOffset, _p, 20 \
2782   add __inputModuleOffset, __inputModuleOffset, 11 \
2783   GetInputModuleValue(__inputModuleOffset, _n) \
2784   release __inputModuleOffsetMutex \
2785   compend
2786 
2787 #define __GetInDigiPinsStatus(_p, _n) \
2788   compchk EQ, sizeof(_n), 1 \
2789   compif EQ, isconst(_p), TRUE \
2790   compchk LT, _p, 0x04 \
2791   compchk GTEQ, _p, 0x00 \
2792   GetInputModuleValue(InputOffsetDigiPinsIn(_p), _n) \
2793   compelse \
2794   acquire __inputModuleOffsetMutex \
2795   mul __inputModuleOffset, _p, 20 \
2796   add __inputModuleOffset, __inputModuleOffset, 12 \
2797   GetInputModuleValue(__inputModuleOffset, _n) \
2798   release __inputModuleOffsetMutex \
2799   compend
2800 
2801 #define __GetInDigiPinsOutputLevel(_p, _n) \
2802   compchk EQ, sizeof(_n), 1 \
2803   compif EQ, isconst(_p), TRUE \
2804   compchk LT, _p, 0x04 \
2805   compchk GTEQ, _p, 0x00 \
2806   GetInputModuleValue(InputOffsetDigiPinsOut(_p), _n) \
2807   compelse \
2808   acquire __inputModuleOffsetMutex \
2809   mul __inputModuleOffset, _p, 20 \
2810   add __inputModuleOffset, __inputModuleOffset, 13 \
2811   GetInputModuleValue(__inputModuleOffset, _n) \
2812   release __inputModuleOffsetMutex \
2813   compend
2814 
2815 #define __GetInCustomPercentFullScale(_p, _n) \
2816   compchk EQ, sizeof(_n), 1 \
2817   compif EQ, isconst(_p), TRUE \
2818   compchk LT, _p, 0x04 \
2819   compchk GTEQ, _p, 0x00 \
2820   GetInputModuleValue(InputOffsetCustomPctFullScale(_p), _n) \
2821   compelse \
2822   acquire __inputModuleOffsetMutex \
2823   mul __inputModuleOffset, _p, 20 \
2824   add __inputModuleOffset, __inputModuleOffset, 14 \
2825   GetInputModuleValue(__inputModuleOffset, _n) \
2826   release __inputModuleOffsetMutex \
2827   compend
2828 
2829 #define __GetInCustomActiveStatus(_p, _n) \
2830   compchk EQ, sizeof(_n), 1 \
2831   compif EQ, isconst(_p), TRUE \
2832   compchk LT, _p, 0x04 \
2833   compchk GTEQ, _p, 0x00 \
2834   GetInputModuleValue(InputOffsetCustomActiveStatus(_p), _n) \
2835   compelse \
2836   acquire __inputModuleOffsetMutex \
2837   mul __inputModuleOffset, _p, 20 \
2838   add __inputModuleOffset, __inputModuleOffset, 15 \
2839   GetInputModuleValue(__inputModuleOffset, _n) \
2840   release __inputModuleOffsetMutex \
2841   compend
2842 
2843 #if __FIRMWARE_VERSION > 107
2844 
2845 #define __GetInColorCalibration(_p, _np, _nc, _n) \
2846   compchk EQ, sizeof(_n), 4 \
2847   compif EQ, isconst(_p+_np+_nc), TRUE \
2848   compchk LT, _p, 0x04 \
2849   compchk GTEQ, _p, 0x00 \
2850   compchk LT, _np, INPUT_NO_OF_POINTS \
2851   compchk GTEQ, _np, 0x00 \
2852   compchk LT, _nc, INPUT_NO_OF_COLORS \
2853   compchk GTEQ, _nc, 0x00 \
2854   GetInputModuleValue(InputOffsetColorCalibration(_p, _np, _nc), _n) \
2855   compelse \
2856   acquire __inputModuleOffsetMutex \
2857   mul __inputModuleOffset, _p, 84 \
2858   mul __inputModuleOffsetTmp, _np, 16 \
2859   add __inputModuleOffset, __inputModuleOffset, __inputModuleOffsetTmp \
2860   mul __inputModuleOffsetTmp, _nc, 4 \
2861   add __inputModuleOffset, __inputModuleOffset, __inputModuleOffsetTmp \
2862   add __inputModuleOffset, __inputModuleOffset, 80 \
2863   GetInputModuleValue(__inputModuleOffset, _n) \
2864   release __inputModuleOffsetMutex \
2865   compend
2866 
2867 #define __GetInColorCalLimits(_p, _np, _n) \
2868   compchk EQ, sizeof(_n), 2 \
2869   compif EQ, isconst(_p+_np), TRUE \
2870   compchk LT, _p, 0x04 \
2871   compchk GTEQ, _p, 0x00 \
2872   compchk LT, _np, 0x02 \
2873   compchk GTEQ, _np, 0x00 \
2874   GetInputModuleValue(InputOffsetColorCalLimits(_p, _np), _n) \
2875   compelse \
2876   acquire __inputModuleOffsetMutex \
2877   mul __inputModuleOffset, _p, 84 \
2878   mul __inputModuleOffsetTmp, _np, 2 \
2879   add __inputModuleOffset, __inputModuleOffset, __inputModuleOffsetTmp \
2880   add __inputModuleOffset, __inputModuleOffset, 128 \
2881   GetInputModuleValue(__inputModuleOffset, _n) \
2882   release __inputModuleOffsetMutex \
2883   compend
2884 
2885 #define __GetInColorADRaw(_p, _nc, _n) \
2886   compchk EQ, sizeof(_n), 2 \
2887   compif EQ, isconst(_p+_nc), TRUE \
2888   compchk LT, _p, 0x04 \
2889   compchk GTEQ, _p, 0x00 \
2890   compchk LT, _nc, INPUT_NO_OF_COLORS \
2891   compchk GTEQ, _nc, 0x00 \
2892   GetInputModuleValue(InputOffsetColorADRaw(_p, _nc), _n) \
2893   compelse \
2894   acquire __inputModuleOffsetMutex \
2895   mul __inputModuleOffset, _p, 84 \
2896   mul __inputModuleOffsetTmp, _nc, 2 \
2897   add __inputModuleOffset, __inputModuleOffset, __inputModuleOffsetTmp \
2898   add __inputModuleOffset, __inputModuleOffset, 132 \
2899   GetInputModuleValue(__inputModuleOffset, _n) \
2900   release __inputModuleOffsetMutex \
2901   compend
2902 
2903 #define __GetInColorSensorRaw(_p, _nc, _n) \
2904   compchk EQ, sizeof(_n), 2 \
2905   compif EQ, isconst(_p+_nc), TRUE \
2906   compchk LT, _p, 0x04 \
2907   compchk GTEQ, _p, 0x00 \
2908   compchk LT, _nc, INPUT_NO_OF_COLORS \
2909   compchk GTEQ, _nc, 0x00 \
2910   GetInputModuleValue(InputOffsetColorSensorRaw(_p, _nc), _n) \
2911   compelse \
2912   acquire __inputModuleOffsetMutex \
2913   mul __inputModuleOffset, _p, 84 \
2914   mul __inputModuleOffsetTmp, _nc, 2 \
2915   add __inputModuleOffset, __inputModuleOffset, __inputModuleOffsetTmp \
2916   add __inputModuleOffset, __inputModuleOffset, 140 \
2917   GetInputModuleValue(__inputModuleOffset, _n) \
2918   release __inputModuleOffsetMutex \
2919   compend
2920 
2921 #define __GetInColorSensorValue(_p, _nc, _n) \
2922   compchk EQ, sizeof(_n), 2 \
2923   compif EQ, isconst(_p+_nc), TRUE \
2924   compchk LT, _p, 0x04 \
2925   compchk GTEQ, _p, 0x00 \
2926   compchk LT, _nc, INPUT_NO_OF_COLORS \
2927   compchk GTEQ, _nc, 0x00 \
2928   GetInputModuleValue(InputOffsetColorSensorValue(_p, _nc), _n) \
2929   compelse \
2930   acquire __inputModuleOffsetMutex \
2931   mul __inputModuleOffset, _p, 84 \
2932   mul __inputModuleOffsetTmp, _nc, 2 \
2933   add __inputModuleOffset, __inputModuleOffset, __inputModuleOffsetTmp \
2934   add __inputModuleOffset, __inputModuleOffset, 148 \
2935   GetInputModuleValue(__inputModuleOffset, _n) \
2936   release __inputModuleOffsetMutex \
2937   compend
2938 
2939 #define __GetInColorBoolean(_p, _nc, _n) \
2940   compchk EQ, sizeof(_n), 1 \
2941   compif EQ, isconst(_p+_nc), TRUE \
2942   compchk LT, _p, 0x04 \
2943   compchk GTEQ, _p, 0x00 \
2944   compchk LT, _nc, INPUT_NO_OF_COLORS \
2945   compchk GTEQ, _nc, 0x00 \
2946   GetInputModuleValue(InputOffsetColorBoolean(_p, _nc), _n) \
2947   compelse \
2948   acquire __inputModuleOffsetMutex \
2949   mul __inputModuleOffset, _p, 84 \
2950   mul __inputModuleOffsetTmp, _nc, 2 \
2951   add __inputModuleOffset, __inputModuleOffset, __inputModuleOffsetTmp \
2952   add __inputModuleOffset, __inputModuleOffset, 156 \
2953   GetInputModuleValue(__inputModuleOffset, _n) \
2954   release __inputModuleOffsetMutex \
2955   compend
2956 
2957 #define __GetInColorCalibrationState(_p, _n) \
2958   compchk EQ, sizeof(_n), 1 \
2959   compif EQ, isconst(_p), TRUE \
2960   compchk LT, _p, 0x04 \
2961   compchk GTEQ, _p, 0x00 \
2962   GetInputModuleValue(InputOffsetColorCalibrationState(_p), _n) \
2963   compelse \
2964   acquire __inputModuleOffsetMutex \
2965   mul __inputModuleOffset, _p, 84 \
2966   add __inputModuleOffset, __inputModuleOffset, 160 \
2967   GetInputModuleValue(__inputModuleOffset, _n) \
2968   release __inputModuleOffsetMutex \
2969   compend
2970 
2971 #endif
2972 
2973 #define __GetOutPwnFreq(_n) \
2974   compchk EQ, sizeof(_n), 1 \
2975   GetOutputModuleValue(OutputOffsetRegulationTime, _n)
2976 
2977 #define __GetOutRegulationTime(_n) \
2978   compchk EQ, sizeof(_n), 1 \
2979   GetOutputModuleValue(OutputOffsetRegulationTime, _n)
2980 
2981 #if defined(__ENHANCED_FIRMWARE) && (__FIRMWARE_VERSION > 107)
2982 
2983 #define __GetOutRegulationOptions(_n) \
2984   compchk EQ, sizeof(_n), 1 \
2985   GetOutputModuleValue(OutputOffsetRegulationOptions, _n)
2986 
2987 #endif
2988 
2989 dseg segment
2990   __lsModuleOffsetMutex mutex
2991   __lsModuleOffset word
2992 dseg ends
2993 
2994 #define __getLSInputBuffer(_p, _offset, _cnt, _data) \
2995   compif EQ, isconst(_p), TRUE \
2996   compchk LT, _p, 0x04 \
2997   compchk GTEQ, _p, 0x00 \
2998   GetLowSpeedModuleBytes(LowSpeedOffsetInBufBuf(_p)+_offset, _cnt, _data) \
2999   compelse \
3000   acquire __lsModuleOffsetMutex \
3001   mul __lsModuleOffset, _p, 19 \
3002   add __lsModuleOffset, __lsModuleOffset, _offset \
3003   GetLowSpeedModuleBytes(__lsModuleOffset, _cnt, _data) \
3004   release __lsModuleOffsetMutex \
3005   compend
3006 
3007 #define __GetLSInputBufferInPtr(_p, _n) \
3008   compchk EQ, sizeof(_n), 1 \
3009   compif EQ, isconst(_p), TRUE \
3010   compchk LT, _p, 0x04 \
3011   compchk GTEQ, _p, 0x00 \
3012   GetLowSpeedModuleValue(LowSpeedOffsetInBufInPtr(_p), _n) \
3013   compelse \
3014   acquire __lsModuleOffsetMutex \
3015   mul __lsModuleOffset, _p, 19 \
3016   add __lsModuleOffset, __lsModuleOffset, 16 \
3017   GetLowSpeedModuleValue(__lsModuleOffset, _n) \
3018   release __lsModuleOffsetMutex \
3019   compend
3020 
3021 #define __GetLSInputBufferOutPtr(_p, _n) \
3022   compchk EQ, sizeof(_n), 1 \
3023   compif EQ, isconst(_p), TRUE \
3024   compchk LT, _p, 0x04 \
3025   compchk GTEQ, _p, 0x00 \
3026   GetLowSpeedModuleValue(LowSpeedOffsetInBufOutPtr(_p), _n) \
3027   compelse \
3028   acquire __lsModuleOffsetMutex \
3029   mul __lsModuleOffset, _p, 19 \
3030   add __lsModuleOffset, __lsModuleOffset, 17 \
3031   GetLowSpeedModuleValue(__lsModuleOffset, _n) \
3032   release __lsModuleOffsetMutex \
3033   compend
3034 
3035 #define __GetLSInputBufferBytesToRx(_p, _n) \
3036   compchk EQ, sizeof(_n), 1 \
3037   compif EQ, isconst(_p), TRUE \
3038   compchk LT, _p, 0x04 \
3039   compchk GTEQ, _p, 0x00 \
3040   GetLowSpeedModuleValue(LowSpeedOffsetInBufBytesToRx(_p), _n) \
3041   compelse \
3042   acquire __lsModuleOffsetMutex \
3043   mul __lsModuleOffset, _p, 19 \
3044   add __lsModuleOffset, __lsModuleOffset, 18 \
3045   GetLowSpeedModuleValue(__lsModuleOffset, _n) \
3046   release __lsModuleOffsetMutex \
3047   compend
3048 
3049 #define __getLSOutputBuffer(_p, _offset, _cnt, _data) \
3050   compif EQ, isconst(_p), TRUE \
3051   compchk LT, _p, 0x04 \
3052   compchk GTEQ, _p, 0x00 \
3053   GetLowSpeedModuleBytes(LowSpeedOffsetOutBufBuf(_p)+_offset, _cnt, _data) \
3054   compelse \
3055   acquire __lsModuleOffsetMutex \
3056   mul __lsModuleOffset, _p, 19 \
3057   add __lsModuleOffset, __lsModuleOffset, 76 \
3058   add __lsModuleOffset, __lsModuleOffset, _offset \
3059   GetLowSpeedModuleBytes(__lsModuleOffset, _cnt, _data) \
3060   release __lsModuleOffsetMutex \
3061   compend
3062 
3063 #define __GetLSOutputBufferInPtr(_p, _n) \
3064   compchk EQ, sizeof(_n), 1 \
3065   compif EQ, isconst(_p), TRUE \
3066   compchk LT, _p, 0x04 \
3067   compchk GTEQ, _p, 0x00 \
3068   GetLowSpeedModuleValue(LowSpeedOffsetOutBufInPtr(_p), _n) \
3069   compelse \
3070   acquire __lsModuleOffsetMutex \
3071   mul __lsModuleOffset, _p, 19 \
3072   add __lsModuleOffset, __lsModuleOffset, 92 \
3073   GetLowSpeedModuleValue(__lsModuleOffset, _n) \
3074   release __lsModuleOffsetMutex \
3075   compend
3076 
3077 #define __GetLSOutputBufferOutPtr(_p, _n) \
3078   compchk EQ, sizeof(_n), 1 \
3079   compif EQ, isconst(_p), TRUE \
3080   compchk LT, _p, 0x04 \
3081   compchk GTEQ, _p, 0x00 \
3082   GetLowSpeedModuleValue(LowSpeedOffsetOutBufOutPtr(_p), _n) \
3083   compelse \
3084   acquire __lsModuleOffsetMutex \
3085   mul __lsModuleOffset, _p, 19 \
3086   add __lsModuleOffset, __lsModuleOffset, 93 \
3087   GetLowSpeedModuleValue(__lsModuleOffset, _n) \
3088   release __lsModuleOffsetMutex \
3089   compend
3090 
3091 #define __GetLSOutputBufferBytesToRx(_p, _n) \
3092   compchk EQ, sizeof(_n), 1 \
3093   compif EQ, isconst(_p), TRUE \
3094   compchk LT, _p, 0x04 \
3095   compchk GTEQ, _p, 0x00 \
3096   GetLowSpeedModuleValue(LowSpeedOffsetOutBufBytesToRx(_p), _n) \
3097   compelse \
3098   acquire __lsModuleOffsetMutex \
3099   mul __lsModuleOffset, _p, 19 \
3100   add __lsModuleOffset, __lsModuleOffset, 94 \
3101   GetLowSpeedModuleValue(__lsModuleOffset, _n) \
3102   release __lsModuleOffsetMutex \
3103   compend
3104 
3105 #define __GetLSMode(_p, _n) \
3106   compchk EQ, sizeof(_n), 1 \
3107   compif EQ, isconst(_p), TRUE \
3108   compchk LT, _p, 0x04 \
3109   compchk GTEQ, _p, 0x00 \
3110   GetLowSpeedModuleValue(LowSpeedOffsetMode(_p), _n) \
3111   compelse \
3112   acquire __lsModuleOffsetMutex \
3113   add __lsModuleOffset, _p, 152 \
3114   GetLowSpeedModuleValue(__lsModuleOffset, _n) \
3115   release __lsModuleOffsetMutex \
3116   compend
3117 
3118 #define __GetLSChannelState(_p, _n) \
3119   compchk EQ, sizeof(_n), 1 \
3120   compif EQ, isconst(_p), TRUE \
3121   compchk LT, _p, 0x04 \
3122   compchk GTEQ, _p, 0x00 \
3123   GetLowSpeedModuleValue(LowSpeedOffsetChannelState(_p), _n) \
3124   compelse \
3125   acquire __lsModuleOffsetMutex \
3126   add __lsModuleOffset, _p, 156 \
3127   GetLowSpeedModuleValue(__lsModuleOffset, _n) \
3128   release __lsModuleOffsetMutex \
3129   compend
3130 
3131 #define __GetLSErrorType(_p, _n) \
3132   compchk EQ, sizeof(_n), 1 \
3133   compif EQ, isconst(_p), TRUE \
3134   compchk LT, _p, 0x04 \
3135   compchk GTEQ, _p, 0x00 \
3136   GetLowSpeedModuleValue(LowSpeedOffsetErrorType(_p), _n) \
3137   compelse \
3138   acquire __lsModuleOffsetMutex \
3139   add __lsModuleOffset, _p, 160 \
3140   GetLowSpeedModuleValue(__lsModuleOffset, _n) \
3141   release __lsModuleOffsetMutex \
3142   compend
3143 
3144 #define __GetLSState(_n) \
3145   compchk EQ, sizeof(_n), 1 \
3146   GetLowSpeedModuleValue(LowSpeedOffsetState, _n)
3147 
3148 #define __GetLSSpeed(_n) \
3149   compchk EQ, sizeof(_n), 1 \
3150   GetLowSpeedModuleValue(LowSpeedOffsetSpeed, _n)
3151 
3152 #ifdef __ENHANCED_FIRMWARE
3153 
3154 #define __GetLSNoRestartOnRead(_n) \
3155   compchk EQ, sizeof(_n), 1 \
3156   GetLowSpeedModuleValue(LowSpeedOffsetNoRestartOnRead, _n)
3157 
3158 #endif
3159 
3160 #define __GetDisplayEraseMask(_n) \
3161   compchk EQ, sizeof(_n), 4 \
3162   GetDisplayModuleValue(DisplayOffsetEraseMask, _n)
3163 
3164 #define __GetDisplayUpdateMask(_n) \
3165   compchk EQ, sizeof(_n), 4 \
3166   GetDisplayModuleValue(DisplayOffsetUpdateMask, _n)
3167 
3168 #define __GetDisplayFont(_n) \
3169   compchk EQ, sizeof(_n), 4 \
3170   GetDisplayModuleValue(DisplayOffsetPFont, _n)
3171 
3172 #define __GetDisplayDisplay(_n) \
3173   compchk EQ, sizeof(_n), 4 \
3174   GetDisplayModuleValue(DisplayOffsetDisplay, _n)
3175 
3176 #define __GetDisplayFlags(_n) \
3177   compchk EQ, sizeof(_n), 1 \
3178   GetDisplayModuleValue(DisplayOffsetFlags, _n)
3179 
3180 #define __GetDisplayTextLinesCenterFlags(_n) \
3181   compchk EQ, sizeof(_n), 1 \
3182   GetDisplayModuleValue(DisplayOffsetTextLinesCenterFlags, _n)
3183 
3184 #if defined(__ENHANCED_FIRMWARE) && (__FIRMWARE_VERSION > 107)
3185 
3186 #define __GetDisplayContrast(_n) \
3187   compchk EQ, sizeof(_n), 1 \
3188   GetDisplayModuleValue(DisplayOffsetContrast, _n)
3189 
3190 #endif
3191 
3192 dseg segment
3193   __displayModuleOffsetMutex mutex
3194   __displayModuleOffset word
3195 dseg ends
3196 
3197 #define __getDisplayNormal(_x, _line, _cnt, _data) \
3198   compif EQ, isconst(_line+_x), TRUE \
3199   compchk LT, _line, 0x08 \
3200   compchk GTEQ, _line, 0x00 \
3201   GetDisplayModuleBytes(DisplayOffsetNormal(_line,_x), _cnt, _data) \
3202   compelse \
3203   acquire __displayModuleOffsetMutex \
3204   mul __displayModuleOffset, _line, 100 \
3205   add __displayModuleOffset, __displayModuleOffset, _x \
3206   add __displayModuleOffset, __displayModuleOffset, 119 \
3207   GetDisplayModuleBytes(__displayModuleOffset, _cnt, _data) \
3208   release __displayModuleOffsetMutex \
3209   compend
3210 
3211 #define __getDisplayPopup(_x, _line, _cnt, _data) \
3212   compif EQ, isconst(_line+_x), TRUE \
3213   compchk LT, _line, 0x08 \
3214   compchk GTEQ, _line, 0x00 \
3215   GetDisplayModuleBytes(DisplayOffsetPopup(_line,_x), _cnt, _data) \
3216   compelse \
3217   acquire __displayModuleOffsetMutex \
3218   mul __displayModuleOffset, _line, 100 \
3219   add __displayModuleOffset, __displayModuleOffset, _x \
3220   add __displayModuleOffset, __displayModuleOffset, 919 \
3221   GetDisplayModuleBytes(__displayModuleOffset, _cnt, _data) \
3222   release __displayModuleOffsetMutex \
3223   compend
3224 
3225 dseg segment
3226   __commModuleOffsetMutex mutex
3227   __commModuleOffset word
3228 dseg ends
3229 
3230 #define __GetBTDeviceName(_p, _str) \
3231   compif EQ, isconst(_p), TRUE \
3232   compchk LT, _p, 0x04 \
3233   compchk GTEQ, _p, 0x00 \
3234   GetCommModuleBytes(CommOffsetBtDeviceTableName(_p), 16, _str) \
3235   compelse \
3236   acquire __commModuleOffsetMutex \
3237   mul __commModuleOffset, _p, 31 \
3238   add __commModuleOffset, __commModuleOffset, 8 \
3239   GetCommModuleBytes(__commModuleOffset, 16, _str) \
3240   release __commModuleOffsetMutex \
3241   compend
3242 
3243 #define __GetBTDeviceClass(_p, _n) \
3244   compchk EQ, sizeof(_n), 4 \
3245   compif EQ, isconst(_p), TRUE \
3246   compchk LT, _p, 0x04 \
3247   compchk GTEQ, _p, 0x00 \
3248   GetCommModuleValue(CommOffsetBtDeviceTableClassOfDevice(_p), _n) \
3249   compelse \
3250   acquire __commModuleOffsetMutex \
3251   mul __commModuleOffset, _p, 31 \
3252   add __commModuleOffset, __commModuleOffset, 24 \
3253   GetCommModuleValue(__commModuleOffset, _n) \
3254   release __commModuleOffsetMutex \
3255   compend
3256 
3257 #define __getBTDeviceAddress(_p, _btaddr) \
3258   compif EQ, isconst(_p), TRUE \
3259   compchk LT, _p, 0x04 \
3260   compchk GTEQ, _p, 0x00 \
3261   GetCommModuleBytes(CommOffsetBtDeviceTableBdAddr(_p), 7, _btaddr) \
3262   compelse \
3263   acquire __commModuleOffsetMutex \
3264   mul __commModuleOffset, _p, 31 \
3265   add __commModuleOffset, __commModuleOffset, 28 \
3266   GetCommModuleBytes(__commModuleOffset, 7, _btaddr) \
3267   release __commModuleOffsetMutex \
3268   compend
3269 
3270 #define __GetBTDeviceStatus(_p, _n) \
3271   compchk EQ, sizeof(_n), 1 \
3272   compif EQ, isconst(_p), TRUE \
3273   compchk LT, _p, 0x04 \
3274   compchk GTEQ, _p, 0x00 \
3275   GetCommModuleValue(CommOffsetBtDeviceTableDeviceStatus(_p), _n) \
3276   compelse \
3277   acquire __commModuleOffsetMutex \
3278   mul __commModuleOffset, _p, 31 \
3279   add __commModuleOffset, __commModuleOffset, 35 \
3280   GetCommModuleValue(__commModuleOffset, _n) \
3281   release __commModuleOffsetMutex \
3282   compend
3283 
3284 #define __GetBTConnectionName(_p, _str) \
3285   compif EQ, isconst(_p), TRUE \
3286   compchk LT, _p, 0x04 \
3287   compchk GTEQ, _p, 0x00 \
3288   GetCommModuleBytes(CommOffsetBtConnectTableName(_p), 16, _str) \
3289   compelse \
3290   acquire __commModuleOffsetMutex \
3291   mul __commModuleOffset, _p, 47 \
3292   add __commModuleOffset, __commModuleOffset, 938 \
3293   GetCommModuleBytes(__commModuleOffset, 16, _str) \
3294   release __commModuleOffsetMutex \
3295   compend
3296 
3297 #define __GetBTConnectionClass(_p, _n) \
3298   compchk EQ, sizeof(_n), 4 \
3299   compif EQ, isconst(_p), TRUE \
3300   compchk LT, _p, 0x04 \
3301   compchk GTEQ, _p, 0x00 \
3302   GetCommModuleValue(CommOffsetBtConnectTableClassOfDevice(_p), _n) \
3303   compelse \
3304   acquire __commModuleOffsetMutex \
3305   mul __commModuleOffset, _p, 47 \
3306   add __commModuleOffset, __commModuleOffset, 954 \
3307   GetCommModuleValue(__commModuleOffset, _n) \
3308   release __commModuleOffsetMutex \
3309   compend
3310 
3311 #define __GetBTConnectionPinCode(_p, _code) \
3312   compif EQ, isconst(_p), TRUE \
3313   compchk LT, _p, 0x04 \
3314   compchk GTEQ, _p, 0x00 \
3315   GetCommModuleBytes(CommOffsetBtConnectTablePinCode(_p), 16, _code) \
3316   compelse \
3317   acquire __commModuleOffsetMutex \
3318   mul __commModuleOffset, _p, 47 \
3319   add __commModuleOffset, __commModuleOffset, 958 \
3320   GetCommModuleBytes(__commModuleOffset, 16, _code) \
3321   release __commModuleOffsetMutex \
3322   compend
3323 
3324 #define __getBTConnectionAddress(_p, _btaddr) \
3325   compif EQ, isconst(_p), TRUE \
3326   compchk LT, _p, 0x04 \
3327   compchk GTEQ, _p, 0x00 \
3328   GetCommModuleBytes(CommOffsetBtConnectTableBdAddr(_p), 7, _btaddr) \
3329   compelse \
3330   acquire __commModuleOffsetMutex \
3331   mul __commModuleOffset, _p, 47 \
3332   add __commModuleOffset, __commModuleOffset, 974 \
3333   GetCommModuleBytes(__commModuleOffset, 7, _btaddr) \
3334   release __commModuleOffsetMutex \
3335   compend
3336 
3337 #define __GetBTConnectionHandleNum(_p, _n) \
3338   compchk EQ, sizeof(_n), 1 \
3339   compif EQ, isconst(_p), TRUE \
3340   compchk LT, _p, 0x04 \
3341   compchk GTEQ, _p, 0x00 \
3342   GetCommModuleValue(CommOffsetBtConnectTableHandleNr(_p), _n) \
3343   compelse \
3344   acquire __commModuleOffsetMutex \
3345   mul __commModuleOffset, _p, 47 \
3346   add __commModuleOffset, __commModuleOffset, 981 \
3347   GetCommModuleValue(__commModuleOffset, _n) \
3348   release __commModuleOffsetMutex \
3349   compend
3350 
3351 #define __GetBTConnectionStreamStatus(_p, _n) \
3352   compchk EQ, sizeof(_n), 1 \
3353   compif EQ, isconst(_p), TRUE \
3354   compchk LT, _p, 0x04 \
3355   compchk GTEQ, _p, 0x00 \
3356   GetCommModuleValue(CommOffsetBtConnectTableStreamStatus(_p), _n) \
3357   compelse \
3358   acquire __commModuleOffsetMutex \
3359   mul __commModuleOffset, _p, 47 \
3360   add __commModuleOffset, __commModuleOffset, 982 \
3361   GetCommModuleValue(__commModuleOffset, _n) \
3362   release __commModuleOffsetMutex \
3363   compend
3364 
3365 #define __GetBTConnectionLinkQuality(_p, _n) \
3366   compchk EQ, sizeof(_n), 1 \
3367   compif EQ, isconst(_p), TRUE \
3368   compchk LT, _p, 0x04 \
3369   compchk GTEQ, _p, 0x00 \
3370   GetCommModuleValue(CommOffsetBtConnectTableLinkQuality(_p), _n) \
3371   compelse \
3372   acquire __commModuleOffsetMutex \
3373   mul __commModuleOffset, _p, 47 \
3374   add __commModuleOffset, __commModuleOffset, 983 \
3375   GetCommModuleValue(__commModuleOffset, _n) \
3376   release __commModuleOffsetMutex \
3377   compend
3378 
3379 #define __getBTInputBuffer(_offset, _cnt, _data) \
3380   compif EQ, isconst(_offset), TRUE \
3381   GetCommModuleBytes(CommOffsetBtInBufBuf+_offset, _cnt, _data) \
3382   compelse \
3383   acquire __commModuleOffsetMutex \
3384   add __commModuleOffset, _offset, CommOffsetBtInBufBuf \
3385   GetCommModuleBytes(__commModuleOffset, _cnt, _data) \
3386   release __commModuleOffsetMutex \
3387   compend
3388 
3389 #define __getBTOutputBuffer(_offset, _cnt, _data) \
3390   compif EQ, isconst(_offset), TRUE \
3391   GetCommModuleBytes(CommOffsetBtOutBufBuf+_offset, _cnt, _data) \
3392   compelse \
3393   acquire __commModuleOffsetMutex \
3394   add __commModuleOffset, _offset, CommOffsetBtOutBufBuf \
3395   GetCommModuleBytes(__commModuleOffset, _cnt, _data) \
3396   release __commModuleOffsetMutex \
3397   compend
3398 
3399 #define __getHSInputBuffer(_offset, _cnt, _data) \
3400   compif EQ, isconst(_offset), TRUE \
3401   GetCommModuleBytes(CommOffsetHsInBufBuf+_offset, _cnt, _data) \
3402   compelse \
3403   acquire __commModuleOffsetMutex \
3404   add __commModuleOffset, _offset, CommOffsetHsInBufBuf \
3405   GetCommModuleBytes(__commModuleOffset, _cnt, _data) \
3406   release __commModuleOffsetMutex \
3407   compend
3408 
3409 #define __getHSOutputBuffer(_offset, _cnt, _data) \
3410   compif EQ, isconst(_offset), TRUE \
3411   GetCommModuleBytes(CommOffsetHsOutBufBuf+_offset, _cnt, _data) \
3412   compelse \
3413   acquire __commModuleOffsetMutex \
3414   add __commModuleOffset, _offset, CommOffsetHsOutBufBuf \
3415   GetCommModuleBytes(__commModuleOffset, _cnt, _data) \
3416   release __commModuleOffsetMutex \
3417   compend
3418 
3419 #define __getUSBInputBuffer(_offset, _cnt, _data) \
3420   compif EQ, isconst(_offset), TRUE \
3421   GetCommModuleBytes(CommOffsetUsbInBufBuf+_offset, _cnt, _data) \
3422   compelse \
3423   acquire __commModuleOffsetMutex \
3424   add __commModuleOffset, _offset, CommOffsetUsbInBufBuf \
3425   GetCommModuleBytes(__commModuleOffset, _cnt, _data) \
3426   release __commModuleOffsetMutex \
3427   compend
3428 
3429 #define __getUSBOutputBuffer(_offset, _cnt, _data) \
3430   compif EQ, isconst(_offset), TRUE \
3431   GetCommModuleBytes(CommOffsetUsbOutBufBuf+_offset, _cnt, _data) \
3432   compelse \
3433   acquire __commModuleOffsetMutex \
3434   add __commModuleOffset, _offset, CommOffsetUsbOutBufBuf \
3435   GetCommModuleBytes(__commModuleOffset, _cnt, _data) \
3436   release __commModuleOffsetMutex \
3437   compend
3438 
3439 #define __getUSBPollBuffer(_offset, _cnt, _data) \
3440   compif EQ, isconst(_offset), TRUE \
3441   GetCommModuleBytes(CommOffsetUsbPollBufBuf+_offset, _cnt, _data) \
3442   compelse \
3443   acquire __commModuleOffsetMutex \
3444   add __commModuleOffset, _offset, CommOffsetUsbPollBufBuf \
3445   GetCommModuleBytes(__commModuleOffset, _cnt, _data) \
3446   release __commModuleOffsetMutex \
3447   compend
3448 
3449 dseg segment
3450   __IOMWArgs TIOMapWrite
3451   __IOMWMutex mutex
3452   __IOMWFlattenBuf byte[]
3453 dseg ends
3454 
3455 #define __SetIOMapBytes(_modName, _offset, _cnt, _arrIn) \
3456   acquire __IOMWMutex \
3457   mov __IOMWArgs.ModuleName, _modName \
3458   mov __IOMWArgs.Offset, _offset \
3459   arrsubset __IOMWArgs.Buffer, _arrIn, NA, _cnt \
3460   syscall IOMapWrite, __IOMWArgs \
3461   release __IOMWMutex
3462 
3463 #define __SetIOMapValue(_modName, _offset, _n) \
3464   acquire __IOMWMutex \
3465   mov __IOMWArgs.ModuleName, _modName \
3466   mov __IOMWArgs.Offset, _offset \
3467   flatten __IOMWFlattenBuf, _n \
3468   strtoarr __IOMWArgs.Buffer, __IOMWFlattenBuf \
3469   syscall IOMapWrite, __IOMWArgs \
3470   release __IOMWMutex
3471 
3472 #ifdef __ENHANCED_FIRMWARE
3473 
3474 dseg segment
3475   __IOMWBIArgs TIOMapWriteByID
3476 dseg ends
3477 
3478 #define __SetIOMapBytesByID(_modID, _offset, _cnt, _arrIn) \
3479   acquire __IOMWMutex \
3480   mov __IOMWBIArgs.ModuleID, _modID \
3481   mov __IOMWBIArgs.Offset, _offset \
3482   arrsubset __IOMWBIArgs.Buffer, _arrIn, NA, _cnt \
3483   syscall IOMapWriteByID, __IOMWBIArgs \
3484   release __IOMWMutex
3485 
3486 #define __SetIOMapValueByID(_modID, _offset, _n) \
3487   acquire __IOMWMutex \
3488   mov __IOMWBIArgs.ModuleID, _modID \
3489   mov __IOMWBIArgs.Offset, _offset \
3490   flatten __IOMWFlattenBuf, _n \
3491   strtoarr __IOMWBIArgs.Buffer, __IOMWFlattenBuf \
3492   syscall IOMapWriteByID, __IOMWBIArgs \
3493   release __IOMWMutex
3494 
3495 #endif
3496 
3497 #define __setLSInputBuffer(_p, _offset, _cnt, _data) \
3498   compif EQ, isconst(_p+_offset), TRUE \
3499   compchk LT, _p, 0x04 \
3500   compchk GTEQ, _p, 0x00 \
3501   SetLowSpeedModuleBytes(LowSpeedOffsetInBufBuf(_p)+_offset, _cnt, _data) \
3502   compelse \
3503   acquire __lsModuleOffsetMutex \
3504   mul __lsModuleOffset, _p, 19 \
3505   add __lsModuleOffset, __lsModuleOffset, _offset \
3506   SetLowSpeedModuleBytes(__lsModuleOffset, _cnt, _data) \
3507   release __lsModuleOffsetMutex \
3508   compend
3509 
3510 #define __setLSOutputBuffer(_p, _offset, _cnt, _data) \
3511   compif EQ, isconst(_p+_offset), TRUE \
3512   compchk LT, _p, 0x04 \
3513   compchk GTEQ, _p, 0x00 \
3514   SetLowSpeedModuleBytes(LowSpeedOffsetInBufBuf(_p)+_offset, _cnt, _data) \
3515   compelse \
3516   acquire __lsModuleOffsetMutex \
3517   mul __lsModuleOffset, _p, 19 \
3518   add __lsModuleOffset, __lsModuleOffset, 76 \
3519   add __lsModuleOffset, __lsModuleOffset, _offset \
3520   SetLowSpeedModuleBytes(__lsModuleOffset, _cnt, _data) \
3521   release __lsModuleOffsetMutex \
3522   compend
3523 
3524 #ifdef __ENHANCED_FIRMWARE
3525 
3526 #define __spawnProgram(_fname) \
3527   acquire __IOMWMutex \
3528   mov __IOMWBIArgs.ModuleID, CommandModuleID \
3529   mov __IOMWBIArgs.Offset, CommandOffsetActivateFlag \
3530   arrsubset __IOMWFlattenBuf, _fname, NA, 20 \
3531   arrbuild __IOMWBIArgs.Buffer, 1, 0, __IOMWFlattenBuf \
3532   syscall IOMapWriteByID, __IOMWBIArgs \
3533   release __IOMWMutex \
3534   stop NA
3535 
3536 #else
3537 
3538 #define __spawnProgram(_fname) \
3539   acquire __IOMWMutex \
3540   mov __IOMWArgs.ModuleName, CommandModuleName \
3541   mov __IOMWArgs.Offset, CommandOffsetActivateFlag \
3542   arrsubset __IOMWFlattenBuf, _fname, NA, 20 \
3543   arrbuild __IOMWArgs.Buffer, 1, 0, __IOMWFlattenBuf \
3544   syscall IOMapWrite, __IOMWArgs \
3545   release __IOMWMutex \
3546   stop NA
3547 
3548 #endif
3549 
3550 #define __setDisplayNormal(_x, _line, _cnt, _data) \
3551   compif EQ, isconst(_line+_x), TRUE \
3552   compchk LT, _line, 0x08 \
3553   compchk GTEQ, _line, 0x00 \
3554   SetDisplayModuleBytes(DisplayOffsetNormal(_line,_x), _cnt, _data) \
3555   compelse \
3556   acquire __displayModuleOffsetMutex \
3557   mul __displayModuleOffset, _line, 100 \
3558   add __displayModuleOffset, __displayModuleOffset, _x \
3559   add __displayModuleOffset, __displayModuleOffset, 119 \
3560   SetDisplayModuleBytes(__displayModuleOffset, _cnt, _data) \
3561   release __displayModuleOffsetMutex \
3562   compend
3563 
3564 #define __setDisplayPopup(_x, _line, _cnt, _data) \
3565   compif EQ, isconst(_line+_x), TRUE \
3566   compchk LT, _line, 0x08 \
3567   compchk GTEQ, _line, 0x00 \
3568   SetDisplayModuleBytes(DisplayOffsetPopup(_line,_x), _cnt, _data) \
3569   compelse \
3570   acquire __displayModuleOffsetMutex \
3571   mul __displayModuleOffset, _line, 100 \
3572   add __displayModuleOffset, __displayModuleOffset, _x \
3573   add __displayModuleOffset, __displayModuleOffset, 919 \
3574   SetDisplayModuleBytes(__displayModuleOffset, _cnt, _data) \
3575   release __displayModuleOffsetMutex \
3576   compend
3577 
3578 #define __setBTDeviceName(_p, _str) \
3579   compif EQ, isconst(_p), TRUE \
3580   compchk LT, _p, 0x04 \
3581   compchk GTEQ, _p, 0x00 \
3582   SetCommModuleBytes(CommOffsetBtDeviceTableName(_p), 16, _str) \
3583   compelse \
3584   acquire __commModuleOffsetMutex \
3585   mul __commModuleOffset, _p, 31 \
3586   add __commModuleOffset, __commModuleOffset, 8 \
3587   SetCommModuleBytes(__commModuleOffset, 16, _str) \
3588   release __commModuleOffsetMutex \
3589   compend
3590 
3591 #define __setBTDeviceAddress(_p, _btaddr) \
3592   compif EQ, isconst(_p), TRUE \
3593   compchk LT, _p, 0x04 \
3594   compchk GTEQ, _p, 0x00 \
3595   SetCommModuleBytes(CommOffsetBtDeviceTableBdAddr(_p), 7, _btaddr) \
3596   compelse \
3597   acquire __commModuleOffsetMutex \
3598   mul __commModuleOffset, _p, 31 \
3599   add __commModuleOffset, __commModuleOffset, 28 \
3600   SetCommModuleBytes(__commModuleOffset, 7, _btaddr) \
3601   release __commModuleOffsetMutex \
3602   compend
3603 
3604 #define __setBTConnectionName(_p, _str) \
3605   compif EQ, isconst(_p), TRUE \
3606   compchk LT, _p, 0x04 \
3607   compchk GTEQ, _p, 0x00 \
3608   SetCommModuleBytes(CommOffsetBtConnectTableName(_p), 16, _str) \
3609   compelse \
3610   acquire __commModuleOffsetMutex \
3611   mul __commModuleOffset, _p, 47 \
3612   add __commModuleOffset, __commModuleOffset, 938 \
3613   SetCommModuleBytes(__commModuleOffset, 16, _str) \
3614   release __commModuleOffsetMutex \
3615   compend
3616 
3617 #define __setBTConnectionPinCode(_p, _code) \
3618   compif EQ, isconst(_p), TRUE \
3619   compchk LT, _p, 0x04 \
3620   compchk GTEQ, _p, 0x00 \
3621   SetCommModuleBytes(CommOffsetBtConnectTablePinCode(_p), 16, _code) \
3622   compelse \
3623   acquire __commModuleOffsetMutex \
3624   mul __commModuleOffset, _p, 47 \
3625   add __commModuleOffset, __commModuleOffset, 958 \
3626   SetCommModuleBytes(__commModuleOffset, 16, _code) \
3627   release __commModuleOffsetMutex \
3628   compend
3629 
3630 #define __setBTConnectionAddress(_p, _btaddr) \
3631   compif EQ, isconst(_p), TRUE \
3632   compchk LT, _p, 0x04 \
3633   compchk GTEQ, _p, 0x00 \
3634   SetCommModuleBytes(CommOffsetBtConnectTableBdAddr(_p), 7, _btaddr) \
3635   compelse \
3636   acquire __commModuleOffsetMutex \
3637   mul __commModuleOffset, _p, 47 \
3638   add __commModuleOffset, __commModuleOffset, 974 \
3639   SetCommModuleBytes(__commModuleOffset, 7, _btaddr) \
3640   release __commModuleOffsetMutex \
3641   compend
3642 
3643 #define __setBTInputBuffer(_offset, _cnt, _data) \
3644   compif EQ, isconst(_offset), TRUE \
3645   SetCommModuleBytes(CommOffsetBtInBufBuf+_offset, _cnt, _data) \
3646   compelse \
3647   acquire __commModuleOffsetMutex \
3648   add __commModuleOffset, _offset, CommOffsetBtInBufBuf \
3649   SetCommModuleBytes(__commModuleOffset, _cnt, _data) \
3650   release __commModuleOffsetMutex \
3651   compend
3652 
3653 #define __setBTOutputBuffer(_offset, _cnt, _data) \
3654   compif EQ, isconst(_offset), TRUE \
3655   SetCommModuleBytes(CommOffsetBtOutBufBuf+_offset, _cnt, _data) \
3656   compelse \
3657   acquire __commModuleOffsetMutex \
3658   add __commModuleOffset, _offset, CommOffsetBtOutBufBuf \
3659   SetCommModuleBytes(__commModuleOffset, _cnt, _data) \
3660   release __commModuleOffsetMutex \
3661   compend
3662 
3663 #define __setHSInputBuffer(_offset, _cnt, _data) \
3664   compif EQ, isconst(_offset), TRUE \
3665   SetCommModuleBytes(CommOffsetHsInBufBuf+_offset, _cnt, _data) \
3666   compelse \
3667   acquire __commModuleOffsetMutex \
3668   add __commModuleOffset, _offset, CommOffsetHsInBufBuf \
3669   SetCommModuleBytes(__commModuleOffset, _cnt, _data) \
3670   release __commModuleOffsetMutex \
3671   compend
3672 
3673 #define __setHSOutputBuffer(_offset, _cnt, _data) \
3674   compif EQ, isconst(_offset), TRUE \
3675   SetCommModuleBytes(CommOffsetHsOutBufBuf+_offset, _cnt, _data) \
3676   compelse \
3677   acquire __commModuleOffsetMutex \
3678   add __commModuleOffset, _offset, CommOffsetHsOutBufBuf \
3679   SetCommModuleBytes(__commModuleOffset, _cnt, _data) \
3680   release __commModuleOffsetMutex \
3681   compend
3682 
3683 #define __setUSBInputBuffer(_offset, _cnt, _data) \
3684   compif EQ, isconst(_offset), TRUE \
3685   SetCommModuleBytes(CommOffsetUsbInBufBuf+_offset, _cnt, _data) \
3686   compelse \
3687   acquire __commModuleOffsetMutex \
3688   add __commModuleOffset, _offset, CommOffsetUsbInBufBuf \
3689   SetCommModuleBytes(__commModuleOffset, _cnt, _data) \
3690   release __commModuleOffsetMutex \
3691   compend
3692 
3693 #define __setUSBOutputBuffer(_offset, _cnt, _data) \
3694   compif EQ, isconst(_offset), TRUE \
3695   SetCommModuleBytes(CommOffsetUsbOutBufBuf+_offset, _cnt, _data) \
3696   compelse \
3697   acquire __commModuleOffsetMutex \
3698   add __commModuleOffset, _offset, CommOffsetUsbOutBufBuf \
3699   SetCommModuleBytes(__commModuleOffset, _cnt, _data) \
3700   release __commModuleOffsetMutex \
3701   compend
3702 
3703 #define __setUSBPollBuffer(_offset, _cnt, _data) \
3704   compif EQ, isconst(_offset), TRUE \
3705   SetCommModuleBytes(CommOffsetUsbPollBufBuf+_offset, _cnt, _data) \
3706   compelse \
3707   acquire __commModuleOffsetMutex \
3708   add __commModuleOffset, _offset, CommOffsetUsbPollBufBuf \
3709   SetCommModuleBytes(__commModuleOffset, _cnt, _data) \
3710   release __commModuleOffsetMutex \
3711   compend
3712 
3713 #define __setSoundFrequency(_n) \
3714   compchk EQ, sizeof(_n), 2 \
3715   SetSoundModuleValue(SoundOffsetFreq, _n)
3716 
3717 #define __setSoundDuration(_n) \
3718   compchk EQ, sizeof(_n), 2 \
3719   SetSoundModuleValue(SoundOffsetDuration, _n)
3720 
3721 #define __setSoundSampleRate(_n) \
3722   compchk EQ, sizeof(_n), 2 \
3723   SetSoundModuleValue(SoundOffsetSampleRate, _n)
3724 
3725 #define __setSoundFlags(_n) \
3726   compchk EQ, sizeof(_n), 1 \
3727   SetSoundModuleValue(SoundOffsetFlags, _n)
3728 
3729 #define __setSoundModuleState(_n) \
3730   compchk EQ, sizeof(_n), 1 \
3731   SetSoundModuleValue(SoundOffsetState, _n)
3732 
3733 #define __setSoundMode(_n) \
3734   compchk EQ, sizeof(_n), 1 \
3735   SetSoundModuleValue(SoundOffsetMode, _n)
3736 
3737 #define __setSoundVolume(_n) \
3738   compchk EQ, sizeof(_n), 1 \
3739   SetSoundModuleValue(SoundOffsetVolume, _n)
3740 
3741 #define __setButtonPressCount(_b, _n) \
3742   compchk EQ, sizeof(_n), 1 \
3743   compif EQ, isconst(_b), TRUE \
3744   compchk LT, _b, 0x04 \
3745   compchk GTEQ, _b, 0x00 \
3746   SetButtonModuleValue(ButtonOffsetPressedCnt(_b), _n) \
3747   compelse \
3748   acquire __btnModuleOffsetMutex \
3749   mul __btnModuleOffset, _b, 8 \
3750   SetButtonModuleValue(__btnModuleOffset, _n) \
3751   release __btnModuleOffsetMutex \
3752   compend
3753 
3754 #define __setButtonLongPressCount(_b, _n) \
3755   compchk EQ, sizeof(_n), 1 \
3756   compif EQ, isconst(_b), TRUE \
3757   compchk LT, _b, 0x04 \
3758   compchk GTEQ, _b, 0x00 \
3759   SetButtonModuleValue(ButtonOffsetLongPressCnt(_b), _n) \
3760   compelse \
3761   acquire __btnModuleOffsetMutex \
3762   mul __btnModuleOffset, _b, 8 \
3763   add __btnModuleOffset, __btnModuleOffset, 1 \
3764   SetButtonModuleValue(__btnModuleOffset, _n) \
3765   release __btnModuleOffsetMutex \
3766   compend
3767 
3768 #define __setButtonShortReleaseCount(_b, _n) \
3769   compchk EQ, sizeof(_n), 1 \
3770   compif EQ, isconst(_b), TRUE \
3771   compchk LT, _b, 0x04 \
3772   compchk GTEQ, _b, 0x00 \
3773   SetButtonModuleValue(ButtonOffsetShortRelCnt(_b), _n) \
3774   compelse \
3775   acquire __btnModuleOffsetMutex \
3776   mul __btnModuleOffset, _b, 8 \
3777   add __btnModuleOffset, __btnModuleOffset, 2 \
3778   SetButtonModuleValue(__btnModuleOffset, _n) \
3779   release __btnModuleOffsetMutex \
3780   compend
3781 
3782 #define __setButtonLongReleaseCount(_b, _n) \
3783   compchk EQ, sizeof(_n), 1 \
3784   compif EQ, isconst(_b), TRUE \
3785   compchk LT, _b, 0x04 \
3786   compchk GTEQ, _b, 0x00 \
3787   SetButtonModuleValue(ButtonOffsetLongRelCnt(_b), _n) \
3788   compelse \
3789   acquire __btnModuleOffsetMutex \
3790   mul __btnModuleOffset, _b, 8 \
3791   add __btnModuleOffset, __btnModuleOffset, 3 \
3792   SetButtonModuleValue(__btnModuleOffset, _n) \
3793   release __btnModuleOffsetMutex \
3794   compend
3795 
3796 #define __setButtonReleaseCount(_b, _n) \
3797   compchk EQ, sizeof(_n), 1 \
3798   compif EQ, isconst(_b), TRUE \
3799   compchk LT, _b, 0x04 \
3800   compchk GTEQ, _b, 0x00 \
3801   SetButtonModuleValue(ButtonOffsetRelCnt(_b), _n) \
3802   compelse \
3803   acquire __btnModuleOffsetMutex \
3804   mul __btnModuleOffset, _b, 8 \
3805   add __btnModuleOffset, __btnModuleOffset, 4 \
3806   SetButtonModuleValue(__btnModuleOffset, _n) \
3807   release __btnModuleOffsetMutex \
3808   compend
3809 
3810 #define __setButtonState(_b, _n) \
3811   compchk EQ, sizeof(_n), 1 \
3812   compif EQ, isconst(_b), TRUE \
3813   compchk LT, _b, 0x04 \
3814   compchk GTEQ, _b, 0x00 \
3815   SetButtonModuleValue(ButtonOffsetState(_b), _n) \
3816   compelse \
3817   acquire __btnModuleOffsetMutex \
3818   add __btnModuleOffset, _b, 32 \
3819   SetButtonModuleValue(__btnModuleOffset, _n) \
3820   release __btnModuleOffsetMutex \
3821   Compend
3822 
3823 #define __setCommandFlags(_n) \
3824   compchk EQ, sizeof(_n), 1 \
3825   SetUIModuleValue(UIOffsetFlags, _n)
3826 
3827 #define __setUIState(_n) \
3828   compchk EQ, sizeof(_n), 1 \
3829   SetUIModuleValue(UIOffsetState, _n)
3830 
3831 #define __setUIButton(_n) \
3832   compchk EQ, sizeof(_n), 1 \
3833   SetUIModuleValue(UIOffsetButton, _n)
3834 
3835 #define __setVMRunState(_n) \
3836   compchk EQ, sizeof(_n), 1 \
3837   SetUIModuleValue(UIOffsetRunState, _n)
3838 
3839 #define __setBatteryState(_n) \
3840   compchk EQ, sizeof(_n), 1 \
3841   SetUIModuleValue(UIOffsetBatteryState, _n)
3842 
3843 #define __setBluetoothState(_n) \
3844   compchk EQ, sizeof(_n), 1 \
3845   SetUIModuleValue(UIOffsetBluetoothState, _n)
3846 
3847 #define __setUsbState(_n) \
3848   compchk EQ, sizeof(_n), 1 \
3849   SetUIModuleValue(UIOffsetUsbState, _n)
3850 
3851 #define __setSleepTimeout(_n) \
3852   compchk EQ, sizeof(_n), 1 \
3853   SetUIModuleValue(UIOffsetSleepTimeout, _n)
3854 
3855 #define __setSleepTimer(_n) \
3856   compchk EQ, sizeof(_n), 1 \
3857   SetUIModuleValue(UIOffsetSleepTimer, _n)
3858 
3859 #define __setVolume(_n) \
3860   compchk EQ, sizeof(_n), 1 \
3861   SetUIModuleValue(UIOffsetVolume, _n)
3862 
3863 #define __setOnBrickProgramPointer(_n) \
3864   compchk EQ, sizeof(_n), 1 \
3865   SetUIModuleValue(UIOffsetOBPPointer, _n)
3866 
3867 #define __forceOff(_n) \
3868   compchk EQ, sizeof(_n), 1 \
3869   SetUIModuleValue(UIOffsetForceOff, _n)
3870 
3871 #define __setAbortFlag(_n) \
3872   compchk EQ, sizeof(_n), 1 \
3873   SetUIModuleValue(UIOffsetAbortFlag, _n)
3874 
3875 #define __setInCustomZeroOffset(_p, _n) \
3876   compchk EQ, sizeof(_n), 2 \
3877   compif EQ, isconst(_p), TRUE \
3878   compchk LT, _p, 0x04 \
3879   compchk GTEQ, _p, 0x00 \
3880   SetInputModuleValue(InputOffsetCustomZeroOffset(_p), _n) \
3881   compelse \
3882   acquire __inputModuleOffsetMutex \
3883   mul __inputModuleOffset, _p, 20 \
3884   SetInputModuleValue(__inputModuleOffset, _n) \
3885   release __inputModuleOffsetMutex \
3886   compend
3887 
3888 #define __setInSensorBoolean(_p, _n) \
3889   compchk EQ, sizeof(_n), 1 \
3890   compif EQ, isconst(_p), TRUE \
3891   compchk LT, _p, 0x04 \
3892   compchk GTEQ, _p, 0x00 \
3893   SetInputModuleValue(InputOffsetSensorBoolean(_p), _n) \
3894   compelse \
3895   acquire __inputModuleOffsetMutex \
3896   mul __inputModuleOffset, _p, 20 \
3897   add __inputModuleOffset, __inputModuleOffset, 10 \
3898   SetInputModuleValue(__inputModuleOffset, _n) \
3899   release __inputModuleOffsetMutex \
3900   compend
3901 
3902 #define __setInDigiPinsDirection(_p, _n) \
3903   compchk EQ, sizeof(_n), 1 \
3904   compif EQ, isconst(_p), TRUE \
3905   compchk LT, _p, 0x04 \
3906   compchk GTEQ, _p, 0x00 \
3907   SetInputModuleValue(InputOffsetDigiPinsDir(_p), _n) \
3908   compelse \
3909   acquire __inputModuleOffsetMutex \
3910   mul __inputModuleOffset, _p, 20 \
3911   add __inputModuleOffset, __inputModuleOffset, 11 \
3912   SetInputModuleValue(__inputModuleOffset, _n) \
3913   release __inputModuleOffsetMutex \
3914   compend
3915 
3916 #define __setInDigiPinsStatus(_p, _n) \
3917   compchk EQ, sizeof(_n), 1 \
3918   compif EQ, isconst(_p), TRUE \
3919   compchk LT, _p, 0x04 \
3920   compchk GTEQ, _p, 0x00 \
3921   SetInputModuleValue(InputOffsetDigiPinsIn(_p), _n) \
3922   compelse \
3923   acquire __inputModuleOffsetMutex \
3924   mul __inputModuleOffset, _p, 20 \
3925   add __inputModuleOffset, __inputModuleOffset, 12 \
3926   SetInputModuleValue(__inputModuleOffset, _n) \
3927   release __inputModuleOffsetMutex \
3928   compend
3929 
3930 #define __setInDigiPinsOutputLevel(_p, _n) \
3931   compchk EQ, sizeof(_n), 1 \
3932   compif EQ, isconst(_p), TRUE \
3933   compchk LT, _p, 0x04 \
3934   compchk GTEQ, _p, 0x00 \
3935   SetInputModuleValue(InputOffsetDigiPinsOut(_p), _n) \
3936   compelse \
3937   acquire __inputModuleOffsetMutex \
3938   mul __inputModuleOffset, _p, 20 \
3939   add __inputModuleOffset, __inputModuleOffset, 13 \
3940   SetInputModuleValue(__inputModuleOffset, _n) \
3941   release __inputModuleOffsetMutex \
3942   compend
3943 
3944 #define __setInCustomPercentFullScale(_p, _n) \
3945   compchk EQ, sizeof(_n), 1 \
3946   compif EQ, isconst(_p), TRUE \
3947   compchk LT, _p, 0x04 \
3948   compchk GTEQ, _p, 0x00 \
3949   SetInputModuleValue(InputOffsetCustomPctFullScale(_p), _n) \
3950   compelse \
3951   acquire __inputModuleOffsetMutex \
3952   mul __inputModuleOffset, _p, 20 \
3953   add __inputModuleOffset, __inputModuleOffset, 14 \
3954   SetInputModuleValue(__inputModuleOffset, _n) \
3955   release __inputModuleOffsetMutex \
3956   compend
3957 
3958 #define __setInCustomActiveStatus(_p, _n) \
3959   compchk EQ, sizeof(_n), 1 \
3960   compif EQ, isconst(_p), TRUE \
3961   compchk LT, _p, 0x04 \
3962   compchk GTEQ, _p, 0x00 \
3963   SetInputModuleValue(InputOffsetCustomActiveStatus(_p), _n) \
3964   compelse \
3965   acquire __inputModuleOffsetMutex \
3966   mul __inputModuleOffset, _p, 20 \
3967   add __inputModuleOffset, __inputModuleOffset, 15 \
3968   SetInputModuleValue(__inputModuleOffset, _n) \
3969   release __inputModuleOffsetMutex \
3970   compend
3971 
3972 #define __setOutPwnFreq(_n) \
3973   compchk EQ, sizeof(_n), 1 \
3974   SetOutputModuleValue(OutputOffsetRegulationTime, _n)
3975 
3976 #define __setOutRegulationTime(_n) \
3977   compchk EQ, sizeof(_n), 1 \
3978   SetOutputModuleValue(OutputOffsetRegulationTime, _n)
3979 
3980 #if defined(__ENHANCED_FIRMWARE) && (__FIRMWARE_VERSION > 107)
3981 
3982 #define __setOutRegulationOptions(_n) \
3983   compchk EQ, sizeof(_n), 1 \
3984   SetOutputModuleValue(OutputOffsetRegulationOptions, _n)
3985 
3986 #endif
3987 
3988 #define __setLSInputBufferInPtr(_p, _n) \
3989   compchk EQ, sizeof(_n), 1 \
3990   compif EQ, isconst(_p), TRUE \
3991   compchk LT, _p, 0x04 \
3992   compchk GTEQ, _p, 0x00 \
3993   SetLowSpeedModuleValue(LowSpeedOffsetInBufInPtr(_p), _n) \
3994   compelse \
3995   acquire __lsModuleOffsetMutex \
3996   mul __lsModuleOffset, _p, 19 \
3997   add __lsModuleOffset, __lsModuleOffset, 16 \
3998   SetLowSpeedModuleValue(__lsModuleOffset, _n) \
3999   release __lsModuleOffsetMutex \
4000   compend
4001 
4002 #define __setLSInputBufferOutPtr(_p, _n) \
4003   compchk EQ, sizeof(_n), 1 \
4004   compif EQ, isconst(_p), TRUE \
4005   compchk LT, _p, 0x04 \
4006   compchk GTEQ, _p, 0x00 \
4007   SetLowSpeedModuleValue(LowSpeedOffsetInBufOutPtr(_p), _n) \
4008   compelse \
4009   acquire __lsModuleOffsetMutex \
4010   mul __lsModuleOffset, _p, 19 \
4011   add __lsModuleOffset, __lsModuleOffset, 17 \
4012   SetLowSpeedModuleValue(__lsModuleOffset, _n) \
4013   release __lsModuleOffsetMutex \
4014   compend
4015 
4016 #define __setLSInputBufferBytesToRx(_p, _n) \
4017   compchk EQ, sizeof(_n), 1 \
4018   compif EQ, isconst(_p), TRUE \
4019   compchk LT, _p, 0x04 \
4020   compchk GTEQ, _p, 0x00 \
4021   SetLowSpeedModuleValue(LowSpeedOffsetInBufBytesToRx(_p), _n) \
4022   compelse \
4023   acquire __lsModuleOffsetMutex \
4024   mul __lsModuleOffset, _p, 19 \
4025   add __lsModuleOffset, __lsModuleOffset, 18 \
4026   SetLowSpeedModuleValue(__lsModuleOffset, _n) \
4027   release __lsModuleOffsetMutex \
4028   compend
4029 
4030 #define __setLSOutputBufferInPtr(_p, _n) \
4031   compchk EQ, sizeof(_n), 1 \
4032   compif EQ, isconst(_p), TRUE \
4033   compchk LT, _p, 0x04 \
4034   compchk GTEQ, _p, 0x00 \
4035   SetLowSpeedModuleValue(LowSpeedOffsetOutBufInPtr(_p), _n) \
4036   compelse \
4037   acquire __lsModuleOffsetMutex \
4038   mul __lsModuleOffset, _p, 19 \
4039   add __lsModuleOffset, __lsModuleOffset, 92 \
4040   SetLowSpeedModuleValue(__lsModuleOffset, _n) \
4041   release __lsModuleOffsetMutex \
4042   compend
4043 
4044 #define __setLSOutputBufferOutPtr(_p, _n) \
4045   compchk EQ, sizeof(_n), 1 \
4046   compif EQ, isconst(_p), TRUE \
4047   compchk LT, _p, 0x04 \
4048   compchk GTEQ, _p, 0x00 \
4049   SetLowSpeedModuleValue(LowSpeedOffsetOutBufOutPtr(_p), _n) \
4050   compelse \
4051   acquire __lsModuleOffsetMutex \
4052   mul __lsModuleOffset, _p, 19 \
4053   add __lsModuleOffset, __lsModuleOffset, 93 \
4054   SetLowSpeedModuleValue(__lsModuleOffset, _n) \
4055   release __lsModuleOffsetMutex \
4056   compend
4057 
4058 #define __setLSOutputBufferBytesToRx(_p, _n) \
4059   compchk EQ, sizeof(_n), 1 \
4060   compif EQ, isconst(_p), TRUE \
4061   compchk LT, _p, 0x04 \
4062   compchk GTEQ, _p, 0x00 \
4063   SetLowSpeedModuleValue(LowSpeedOffsetOutBufBytesToRx(_p), _n) \
4064   compelse \
4065   acquire __lsModuleOffsetMutex \
4066   mul __lsModuleOffset, _p, 19 \
4067   add __lsModuleOffset, __lsModuleOffset, 94 \
4068   SetLowSpeedModuleValue(__lsModuleOffset, _n) \
4069   release __lsModuleOffsetMutex \
4070   compend
4071 
4072 #define __setLSMode(_p, _n) \
4073   compchk EQ, sizeof(_n), 1 \
4074   compif EQ, isconst(_p), TRUE \
4075   compchk LT, _p, 0x04 \
4076   compchk GTEQ, _p, 0x00 \
4077   SetLowSpeedModuleValue(LowSpeedOffsetMode(_p), _n) \
4078   compelse \
4079   acquire __lsModuleOffsetMutex \
4080   add __lsModuleOffset, _p, 152 \
4081   SetLowSpeedModuleValue(__lsModuleOffset, _n) \
4082   release __lsModuleOffsetMutex \
4083   compend
4084 
4085 #define __setLSChannelState(_p, _n) \
4086   compchk EQ, sizeof(_n), 1 \
4087   compif EQ, isconst(_p), TRUE \
4088   compchk LT, _p, 0x04 \
4089   compchk GTEQ, _p, 0x00 \
4090   SetLowSpeedModuleValue(LowSpeedOffsetChannelState(_p), _n) \
4091   compelse \
4092   acquire __lsModuleOffsetMutex \
4093   add __lsModuleOffset, _p, 156 \
4094   SetLowSpeedModuleValue(__lsModuleOffset, _n) \
4095   release __lsModuleOffsetMutex \
4096   compend
4097 
4098 #define __setLSErrorType(_p, _n) \
4099   compchk EQ, sizeof(_n), 1 \
4100   compif EQ, isconst(_p), TRUE \
4101   compchk LT, _p, 0x04 \
4102   compchk GTEQ, _p, 0x00 \
4103   SetLowSpeedModuleValue(LowSpeedOffsetErrorType(_p), _n) \
4104   compelse \
4105   acquire __lsModuleOffsetMutex \
4106   add __lsModuleOffset, _p, 160 \
4107   SetLowSpeedModuleValue(__lsModuleOffset, _n) \
4108   release __lsModuleOffsetMutex \
4109   compend
4110 
4111 #define __setLSState(_n) \
4112   compchk EQ, sizeof(_n), 1 \
4113   SetLowSpeedModuleValue(LowSpeedOffsetState, _n)
4114 
4115 #define __setLSSpeed(_n) \
4116   compchk EQ, sizeof(_n), 1 \
4117   SetLowSpeedModuleValue(LowSpeedOffsetSpeed, _n)
4118 
4119 #ifdef __ENHANCED_FIRMWARE
4120 #define __setLSNoRestartOnRead(_n) \
4121   compchk EQ, sizeof(_n), 1 \
4122   SetLowSpeedModuleValue(LowSpeedOffsetNoRestartOnRead, _n)
4123 #endif
4124 
4125 #define __setDisplayEraseMask(_n) \
4126   compchk EQ, sizeof(_n), 4 \
4127   SetDisplayModuleValue(DisplayOffsetEraseMask, _n)
4128 
4129 #define __setDisplayUpdateMask(_n) \
4130   compchk EQ, sizeof(_n), 4 \
4131   SetDisplayModuleValue(DisplayOffsetUpdateMask, _n)
4132 
4133 #define __setDisplayFont(_n) \
4134   compchk EQ, sizeof(_n), 4 \
4135   SetDisplayModuleValue(DisplayOffsetPFont, _n)
4136 
4137 #define __setDisplayDisplay(_n) \
4138   compchk EQ, sizeof(_n), 4 \
4139   SetDisplayModuleValue(DisplayOffsetDisplay, _n)
4140 
4141 #define __setDisplayFlags(_n) \
4142   compchk EQ, sizeof(_n), 1 \
4143   SetDisplayModuleValue(DisplayOffsetFlags, _n)
4144 
4145 #define __setDisplayTextLinesCenterFlags(_n) \
4146   compchk EQ, sizeof(_n), 1 \
4147   SetDisplayModuleValue(DisplayOffsetTextLinesCenterFlags, _n)
4148 
4149 #define __setDisplayContrast(_n) \
4150   compchk EQ, sizeof(_n), 1 \
4151   SetDisplayModuleValue(DisplayOffsetContrast, _n)
4152 
4153 #define __setBTDeviceClass(_p, _n) \
4154   compchk EQ, sizeof(_n), 4 \
4155   compif EQ, isconst(_p), TRUE \
4156   compchk LT, _p, 0x04 \
4157   compchk GTEQ, _p, 0x00 \
4158   SetCommModuleValue(CommOffsetBtDeviceTableClassOfDevice(_p), _n) \
4159   compelse \
4160   acquire __commModuleOffsetMutex \
4161   mul __commModuleOffset, _p, 31 \
4162   add __commModuleOffset, __commModuleOffset, 24 \
4163   SetCommModuleValue(__commModuleOffset, _n) \
4164   release __commModuleOffsetMutex \
4165   compend
4166 
4167 #define __setBTDeviceStatus(_p, _n) \
4168   compchk EQ, sizeof(_n), 1 \
4169   compif EQ, isconst(_p), TRUE \
4170   compchk LT, _p, 0x04 \
4171   compchk GTEQ, _p, 0x00 \
4172   SetCommModuleValue(CommOffsetBtDeviceTableDeviceStatus(_p), _n) \
4173   compelse \
4174   acquire __commModuleOffsetMutex \
4175   mul __commModuleOffset, _p, 31 \
4176   add __commModuleOffset, __commModuleOffset, 35 \
4177   SetCommModuleValue(__commModuleOffset, _n) \
4178   release __commModuleOffsetMutex \
4179   compend
4180 
4181 #define __setBTConnectionClass(_p, _n) \
4182   compchk EQ, sizeof(_n), 4 \
4183   compif EQ, isconst(_p), TRUE \
4184   compchk LT, _p, 0x04 \
4185   compchk GTEQ, _p, 0x00 \
4186   SetCommModuleValue(CommOffsetBtConnectTableClassOfDevice(_p), _n) \
4187   compelse \
4188   acquire __commModuleOffsetMutex \
4189   mul __commModuleOffset, _p, 47 \
4190   add __commModuleOffset, __commModuleOffset, 954 \
4191   SetCommModuleValue(__commModuleOffset, _n) \
4192   release __commModuleOffsetMutex \
4193   compend
4194 
4195 #define __setBTConnectionHandleNum(_p, _n) \
4196   compchk EQ, sizeof(_n), 1 \
4197   compif EQ, isconst(_p), TRUE \
4198   compchk LT, _p, 0x04 \
4199   compchk GTEQ, _p, 0x00 \
4200   SetCommModuleValue(CommOffsetBtConnectTableHandleNr(_p), _n) \
4201   compelse \
4202   acquire __commModuleOffsetMutex \
4203   mul __commModuleOffset, _p, 47 \
4204   add __commModuleOffset, __commModuleOffset, 981 \
4205   SetCommModuleValue(__commModuleOffset, _n) \
4206   release __commModuleOffsetMutex \
4207   compend
4208 
4209 #define __setBTConnectionStreamStatus(_p, _n) \
4210   compchk EQ, sizeof(_n), 1 \
4211   compif EQ, isconst(_p), TRUE \
4212   compchk LT, _p, 0x04 \
4213   compchk GTEQ, _p, 0x00 \
4214   SetCommModuleValue(CommOffsetBtConnectTableStreamStatus(_p), _n) \
4215   compelse \
4216   acquire __commModuleOffsetMutex \
4217   mul __commModuleOffset, _p, 47 \
4218   add __commModuleOffset, __commModuleOffset, 982 \
4219   SetCommModuleValue(__commModuleOffset, _n) \
4220   release __commModuleOffsetMutex \
4221   compend
4222 
4223 #define __setBTConnectionLinkQuality(_p, _n) \
4224   compchk EQ, sizeof(_n), 1 \
4225   compif EQ, isconst(_p), TRUE \
4226   compchk LT, _p, 0x04 \
4227   compchk GTEQ, _p, 0x00 \
4228   SetCommModuleValue(CommOffsetBtConnectTableLinkQuality(_p), _n) \
4229   compelse \
4230   acquire __commModuleOffsetMutex \
4231   mul __commModuleOffset, _p, 47 \
4232   add __commModuleOffset, __commModuleOffset, 983 \
4233   SetCommModuleValue(__commModuleOffset, _n) \
4234   release __commModuleOffsetMutex \
4235   compend
4236 
4237 #define __setBrickDataBluecoreVersion(_n) \
4238   compchk EQ, sizeof(_n), 2 \
4239   SetCommModuleValue(CommOffsetBrickDataBluecoreVersion, _n)
4240 
4241 #define __setBrickDataBtStateStatus(_n) \
4242   compchk EQ, sizeof(_n), 1 \
4243   SetCommModuleValue(CommOffsetBrickDataBtStateStatus, _n)
4244 
4245 #define __setBrickDataBtHardwareStatus(_n) \
4246   compchk EQ, sizeof(_n), 1 \
4247   SetCommModuleValue(CommOffsetBrickDataBtHwStatus, _n)
4248 
4249 #define __setBrickDataTimeoutValue(_n) \
4250   compchk EQ, sizeof(_n), 1 \
4251   SetCommModuleValue(CommOffsetBrickDataTimeOutValue, _n)
4252 
4253 #define __setBTInputBufferInPtr(_n) \
4254   compchk EQ, sizeof(_n), 1 \
4255   SetCommModuleValue(CommOffsetBtInBufInPtr, _n)
4256 
4257 #define __setBTInputBufferOutPtr(_n) \
4258   compchk EQ, sizeof(_n), 1 \
4259   SetCommModuleValue(CommOffsetBtInBufOutPtr, _n)
4260 
4261 #define __setBTOutputBufferInPtr(_n) \
4262   compchk EQ, sizeof(_n), 1 \
4263   SetCommModuleValue(CommOffsetBtOutBufInPtr, _n)
4264 
4265 #define __setBTOutputBufferOutPtr(_n) \
4266   compchk EQ, sizeof(_n), 1 \
4267   SetCommModuleValue(CommOffsetBtOutBufOutPtr, _n)
4268 
4269 #define __setHSInputBufferInPtr(_n) \
4270   compchk EQ, sizeof(_n), 1 \
4271   SetCommModuleValue(CommOffsetHsInBufInPtr, _n)
4272 
4273 #define __setHSInputBufferOutPtr(_n) \
4274   compchk EQ, sizeof(_n), 1 \
4275   SetCommModuleValue(CommOffsetHsInBufOutPtr, _n)
4276 
4277 #define __setHSOutputBufferInPtr(_n) \
4278   compchk EQ, sizeof(_n), 1 \
4279   SetCommModuleValue(CommOffsetHsOutBufInPtr, _n)
4280 
4281 #define __setHSOutputBufferOutPtr(_n) \
4282   compchk EQ, sizeof(_n), 1 \
4283   SetCommModuleValue(CommOffsetHsOutBufOutPtr, _n)
4284 
4285 #define __setUSBInputBufferInPtr(_n) \
4286   compchk EQ, sizeof(_n), 1 \
4287   SetCommModuleValue(CommOffsetUsbInBufInPtr, _n)
4288 
4289 #define __setUSBInputBufferOutPtr(_n) \
4290   compchk EQ, sizeof(_n), 1 \
4291   SetCommModuleValue(CommOffsetUsbInBufOutPtr, _n)
4292 
4293 #define __setUSBOutputBufferInPtr(_n) \
4294   compchk EQ, sizeof(_n), 1 \
4295   SetCommModuleValue(CommOffsetUsbOutBufInPtr, _n)
4296 
4297 #define __setUSBOutputBufferOutPtr(_n) \
4298   compchk EQ, sizeof(_n), 1 \
4299   SetCommModuleValue(CommOffsetUsbOutBufOutPtr, _n)
4300 
4301 #define __setUSBPollBufferInPtr(_n) \
4302   compchk EQ, sizeof(_n), 1 \
4303   SetCommModuleValue(CommOffsetUsbPollBufInPtr, _n)
4304 
4305 #define __setUSBPollBufferOutPtr(_n) \
4306   compchk EQ, sizeof(_n), 1 \
4307   SetCommModuleValue(CommOffsetUsbPollBufOutPtr, _n)
4308 
4309 #define __setBTDeviceCount(_n) \
4310   compchk EQ, sizeof(_n), 1 \
4311   SetCommModuleValue(CommOffsetBtDeviceCnt, _n)
4312 
4313 #define __setBTDeviceNameCount(_n) \
4314   compchk EQ, sizeof(_n), 1 \
4315   SetCommModuleValue(CommOffsetBtDeviceNameCnt, _n)
4316 
4317 #define __setHSFlags(_n) \
4318   compchk EQ, sizeof(_n), 1 \
4319   SetCommModuleValue(CommOffsetHsFlags, _n)
4320 
4321 #define __setHSSpeed(_n) \
4322   compchk EQ, sizeof(_n), 1 \
4323   SetCommModuleValue(CommOffsetHsSpeed, _n)
4324 
4325 #define __setHSState(_n) \
4326   compchk EQ, sizeof(_n), 1 \
4327   SetCommModuleValue(CommOffsetHsState, _n)
4328 
4329 #define __setUSBState(_n) \
4330   compchk EQ, sizeof(_n), 1 \
4331   SetCommModuleValue(CommOffsetUsbState, _n)
4332 
4333 #if (__FIRMWARE_VERSION > 107) && defined(__ENHANCED_FIRMWARE)
4334 
4335 #define __setHSMode(_n) \
4336   compchk EQ, sizeof(_n), 2 \
4337   SetCommModuleValue(CommOffsetHsMode, _n)
4338 
4339 #define __setBTDataMode(_n) \
4340   compchk EQ, sizeof(_n), 1 \
4341   compchk EQ, isconst(_n), 1 \
4342   SetCommModuleValue(CommOffsetBtDataMode, _n|DATA_MODE_UPDATE) \
4343   wait 1
4344 
4345 #define __setHSDataMode(_n) \
4346   compchk EQ, sizeof(_n), 1 \
4347   compchk EQ, isconst(_n), 1 \
4348   SetCommModuleValue(CommOffsetHsDataMode, _n|DATA_MODE_UPDATE) \
4349   wait 1
4350 
4351 #endif
4352 
4353 dseg segment
4354   __FOMutex mutex
4355   __FOArgs TFileOpen
4356   __FCMutex mutex
4357   __FCArgs TFileClose
4358   __FRHMutex mutex
4359   __FRHArgs TFileResolveHandle
4360   __FRMutex mutex
4361   __FRArgs TFileRename
4362   __FDMutex mutex
4363   __FDArgs TFileDelete
4364   __FFMutex mutex
4365 dseg ends
4366 
4367 #ifdef __ENHANCED_FIRMWARE
4368 dseg segment
4369   __FFArgs TFileFind
4370 dseg ends
4371 #endif
4372 
4373 subroutine __fileResizeSub
4374   dseg segment
4375     __frsMutex mutex
4376     __frsNewSize dword
4377     __frsOldName byte[]
4378     __frsTmpName byte[]
4379     __frsFOReadArgs TFileOpen
4380     __frsFOWriteArgs TFileOpen
4381     __frsFReadArgs TFileReadWrite
4382     __frsFWriteArgs TFileReadWrite
4383     __frsFRArgs TFileRename
4384     __frsFCArgs TFileClose
4385     __frsFDArgs TFileDelete
4386     __frsResult word
4387   dseg ends
4388   strcat __frsFRArgs.NewFilename, '_tmp', __frsOldName
4389   mov __frsFRArgs.OldFilename, __frsOldName
4390   syscall FileRename, __frsFRArgs
4391   mov __frsResult, __frsFRArgs.Result
4392   brtst NEQ, __frsEnd, __frsResult
4393   // old file has been renamed successfully
4394   mov __frsFOReadArgs.Filename, __frsFRArgs.NewFilename
4395   syscall FileOpenRead, __frsFOReadArgs
4396   mov __frsResult, __frsFOReadArgs.Result
4397   brtst NEQ, __frsOpenReadFailed, __frsResult
4398   // renamed file is open for reading
4399   mov __frsFOWriteArgs.Filename, __frsOldName
4400   mov __frsFOWriteArgs.Length, __frsNewSize
4401   syscall FileOpenWrite, __frsFOWriteArgs
4402   mov __frsResult, __frsFOWriteArgs.Result
4403   brtst NEQ, __frsOpenWriteFailed, __frsResult
4404   // both files are open
4405   mov __frsFReadArgs.FileHandle, __frsFOReadArgs.FileHandle
4406   mov __frsFWriteArgs.FileHandle, __frsFOWriteArgs.FileHandle
4407 __frsCopyLoop:
4408   set __frsFReadArgs.Length, 1024
4409   syscall FileRead, __frsFReadArgs
4410   brtst LTEQ, __frsEndLoop, __frsFReadArgs.Length
4411   mov __frsFWriteArgs.Buffer, __frsFReadArgs.Buffer
4412   mov __frsFWriteArgs.Length, __frsFReadArgs.Length
4413   syscall FileWrite, __frsFWriteArgs
4414   brtst NEQ, __frsEndLoop, __frsFWriteArgs.Result
4415   brtst NEQ, __frsEndLoop, __frsFReadArgs.Result
4416   jmp __frsCopyLoop
4417 __frsEndLoop:
4418   // close read file
4419   mov __frsFCArgs.FileHandle, __frsFOReadArgs.FileHandle
4420   syscall FileClose, __frsFCArgs
4421   // close write file
4422   mov __frsFCArgs.FileHandle, __frsFOWriteArgs.FileHandle
4423   syscall FileClose, __frsFCArgs
4424   // delete read file
4425   mov __frsFDArgs.Filename, __frsFOReadArgs.Filename
4426   syscall FileDelete, __frsFDArgs
4427   jmp __frsEnd
4428 __frsOpenWriteFailed:
4429   // close read file
4430   mov __frsFCArgs.FileHandle, __frsFOReadArgs.FileHandle
4431   syscall FileClose, __frsFCArgs
4432   jmp __frsEnd
4433 __frsOpenReadFailed:
4434   // if the open read failed rename tmp back to original and exit
4435   mov __frsFRArgs.OldFilename, __frsFRArgs.NewFilename
4436   mov __frsFRArgs.NewFilename, __frsOldName
4437   syscall FileRename, __frsFRArgs
4438 __frsEnd:
4439   return
4440 ends
4441 
4442 #define __fileResize(_fname, _newsize, _result) \
4443   acquire __frsMutex \
4444   mov __frsOldName, _fname \
4445   mov __frsNewSize, _newsize \
4446   call __fileResizeSub \
4447   mov _result, __frsResult \
4448   release __frsMutex
4449 
4450 #define __createFile(_fname, _fsize, _handle, _result) \
4451   acquire __FOMutex \
4452   mov __FOArgs.Filename, _fname \
4453   mov __FOArgs.Length, _fsize \
4454   syscall FileOpenWrite, __FOArgs \
4455   mov _handle, __FOArgs.FileHandle \
4456   mov _result, __FOArgs.Result \
4457   release __FOMutex
4458 
4459 #define __createFileLinear(_fname, _fsize, _handle, _result) \
4460   acquire __FOMutex \
4461   mov __FOArgs.Filename, _fname \
4462   mov __FOArgs.Length, _fsize \
4463   syscall FileOpenWriteLinear, __FOArgs \
4464   mov _handle, __FOArgs.FileHandle \
4465   mov _result, __FOArgs.Result \
4466   release __FOMutex
4467 
4468 #define __createFileNonLinear(_fname, _fsize, _handle, _result) \
4469   acquire __FOMutex \
4470   mov __FOArgs.Filename, _fname \
4471   mov __FOArgs.Length, _fsize \
4472   syscall FileOpenWriteNonLinear, __FOArgs \
4473   mov _handle, __FOArgs.FileHandle \
4474   mov _result, __FOArgs.Result \
4475   release __FOMutex
4476 
4477 #define __openFileAppend(_fname, _fsize, _handle, _result) \
4478   acquire __FOMutex \
4479   mov __FOArgs.Filename, _fname \
4480   syscall FileOpenAppend, __FOArgs \
4481   mov _fsize, __FOArgs.Length \
4482   mov _handle, __FOArgs.FileHandle \
4483   mov _result, __FOArgs.Result \
4484   release __FOMutex
4485 
4486 #define __openFileRead(_fname, _fsize, _handle, _result) \
4487   acquire __FOMutex \
4488   mov __FOArgs.Filename, _fname \
4489   syscall FileOpenRead, __FOArgs \
4490   mov _fsize, __FOArgs.Length \
4491   mov _handle, __FOArgs.FileHandle \
4492   mov _result, __FOArgs.Result \
4493   release __FOMutex
4494 
4495 #define __openFileReadLinear(_fname, _fsize, _handle, _result) \
4496   acquire __FOMutex \
4497   mov __FOArgs.Filename, _fname \
4498   syscall FileOpenReadLinear, __FOArgs \
4499   mov _fsize, __FOArgs.Length \
4500   mov _handle, __FOArgs.FileHandle \
4501   mov _result, __FOArgs.Result \
4502   release __FOMutex
4503 
4504 #define __closeFile(_handle, _result) \
4505   acquire __FCMutex \
4506   mov __FCArgs.FileHandle, _handle \
4507   syscall FileClose, __FCArgs \
4508   mov _result, __FCArgs.Result \
4509   release __FCMutex
4510 
4511 #define __resolveHandle(_fname, _handle, _writeable, _result) \
4512   acquire __FRHMutex \
4513   mov __FRHArgs.Filename, _fname \
4514   syscall FileResolveHandle, __FRHArgs \
4515   mov _handle, __FRHArgs.FileHandle \
4516   mov _writeable, __FRHArgs.WriteHandle \
4517   mov _result, __FRHArgs.Result \
4518   release __FRHMutex
4519 
4520 #define __renameFile(_oldname, _newname, _result) \
4521   acquire __FRMutex \
4522   mov __FRArgs.OldFilename, _oldname \
4523   mov __FRArgs.NewFilename, _newname \
4524   syscall FileRename, __FRArgs \
4525   mov _result, __FRArgs.Result \
4526   release __FRMutex
4527 
4528 #define __deleteFile(_fname, _result) \
4529   acquire __FDMutex \
4530   mov __FDArgs.Filename, _fname \
4531   syscall FileDelete, __FDArgs \
4532   mov _result, __FDArgs.Result \
4533   release __FDMutex
4534 
4535 #ifdef __ENHANCED_FIRMWARE
4536 
4537 #define __findFirstFile(_fname, _handle, _result) \
4538   acquire __FFMutex \
4539   mov __FFArgs.Filename, _fname \
4540   syscall FileFindFirst, __FFArgs \
4541   mov _result, __FFArgs.Result \
4542   mov _handle, __FFArgs.FileHandle \
4543   mov _fname, __FFArgs.Filename \
4544   release __FFMutex
4545 
4546 #define __findNextFile(_fname, _handle, _result) \
4547   acquire __FFMutex \
4548   mov __FFArgs.FileHandle, _handle \
4549   syscall FileFindNext, __FFArgs \
4550   mov _result, __FFArgs.Result \
4551   mov _handle, __FFArgs.FileHandle \
4552   mov _fname, __FFArgs.Filename \
4553   release __FFMutex
4554 
4555 #endif
4556 
4557 dseg segment
4558   __FReadArgs TFileReadWrite
4559   __FReadTmpByte byte
4560   __FReadMutex mutex
4561   __RLSBuffer byte[]
4562   __RLSOutput byte[]
4563   __RLSReturn word
4564   __RLSReturnAddress byte
4565   __RLSMaxBytes word
4566   __RLSByteCount word
4567   __soTmpBuf byte[]
4568   __soMutex mutex
4569 dseg ends
4570 
4571 #define __sizeOF(_n, _result) \
4572   compif EQ, ((typeof(_n)>=1)&&(typeof(_n)<=6))||(typeof(_n)==10), TRUE \
4573   set _result, sizeof(_n) \
4574   compelse \
4575   acquire __soMutex \
4576   flatten __soTmpBuf, _n \
4577   arrsize _result, __soTmpBuf \
4578   sub _result, _result, 1 \
4579   release __soMutex \
4580   compend
4581 
4582 #define __readBytes(_handle, _len, _buf, _result) \
4583   acquire __FReadMutex \
4584   mov __FReadArgs.FileHandle, _handle \
4585   mov __FReadArgs.Length, _len \
4586   syscall FileRead, __FReadArgs \
4587   mov _result, __FReadArgs.Result \
4588   strtoarr _buf, __FReadArgs.Buffer \
4589   mov _len, __FReadArgs.Length \
4590   release __FReadMutex
4591 
4592 #define __readValue(_handle, _n, _result) \
4593   acquire __FReadMutex \
4594   mov __FReadArgs.FileHandle, _handle \
4595   __sizeOF(_n, __FReadArgs.Length) \
4596   syscall FileRead, __FReadArgs \
4597   mov _result, __FReadArgs.Result \
4598   unflatten _n, __FReadTmpByte, __FReadArgs.Buffer, _n \
4599   release __FReadMutex
4600 
4601 #define __readLnValue(_handle, _n, _result) \
4602   acquire __FReadMutex \
4603   mov __FReadArgs.FileHandle, _handle \
4604   __sizeOF(_n, __FReadArgs.Length) \
4605   syscall FileRead, __FReadArgs \
4606   unflatten _n, __FReadTmpByte, __FReadArgs.Buffer, _n \
4607   set __FReadArgs.Length, 2 \
4608   syscall FileRead, __FReadArgs \
4609   mov _result, __FReadArgs.Result \
4610   release __FReadMutex
4611 
4612 #define __readLnStringEx(_handle, _output, _max, _result) \
4613   acquire __FReadMutex \
4614   mov __FReadArgs.FileHandle, _handle \
4615   mov __RLSMaxBytes, _max \
4616   subcall __readStringLine, __RLSReturnAddress \
4617   mov _result, __RLSReturn \
4618   mov _output, __RLSOutput \
4619   release __FReadMutex \
4620 
4621 #define __readLnString(_handle, _output, _result) __readLnStringEx(_handle, _output, 0xFFFF, _result)
4622 
4623 subroutine __readStringLine
4624   arrinit __RLSOutput, 0, 1
4625   set __RLSByteCount, 0
4626   __RLSStringLoop:
4627   set __FReadArgs.Length, 1
4628   mov __RLSBuffer, __RLSOutput
4629   syscall FileRead, __FReadArgs
4630   mov __RLSReturn, __FReadArgs.Result
4631   brtst NEQ, __RLSStringDone, __RLSReturn
4632   index __FReadTmpByte, __FReadArgs.Buffer, NA
4633   brcmp EQ, __RLSStringDone, __FReadTmpByte, 0x0A
4634   brcmp EQ, __RLSStringSkip, __FReadTmpByte, 0x0D
4635   strcat __RLSOutput, __RLSBuffer, __FReadArgs.Buffer
4636   add __RLSByteCount, __RLSByteCount, 1
4637   brcmp GTEQ, __RLSStringDone, __RLSByteCount, __RLSMaxBytes
4638   __RLSStringSkip:
4639   jmp __RLSStringLoop
4640   __RLSStringDone:
4641   subret __RLSReturnAddress
4642 ends
4643 
4644 dseg segment
4645   __FWriteArgs TFileReadWrite
4646   __FWriteFlattenBuf byte[]
4647   __FWriteMutex mutex
4648   __FWriteLn byte[] {0x0D, 0x0A}
4649 dseg ends
4650 
4651 #define __writeBytes(_handle, _buf, _len, _result) \
4652   acquire __FWriteMutex \
4653   mov __FWriteArgs.FileHandle, _handle \
4654   mov __FWriteArgs.Buffer, _buf \
4655   arrsize __FWriteArgs.Length, __FWriteArgs.Buffer \
4656   syscall FileWrite, __FWriteArgs \
4657   mov _result, __FWriteArgs.Result \
4658   mov _len, __FWriteArgs.Length \
4659   release __FWriteMutex
4660 
4661 #define __writeString(_handle, _str, _len, _result) \
4662   acquire __FWriteMutex \
4663   mov __FWriteArgs.FileHandle, _handle \
4664   strtoarr __FWriteArgs.Buffer, _str \
4665   arrsize __FWriteArgs.Length, __FWriteArgs.Buffer \
4666   syscall FileWrite, __FWriteArgs \
4667   mov _result, __FWriteArgs.Result \
4668   mov _len, __FWriteArgs.Length \
4669   release __FWriteMutex
4670 
4671 #define __writeLnString(_handle, _str, _len, _result) \
4672   acquire __FWriteMutex \
4673   mov __FWriteArgs.FileHandle, _handle \
4674   strtoarr __FWriteFlattenBuf, _str \
4675   arrbuild __FWriteArgs.Buffer, __FWriteFlattenBuf, __FWriteLn \
4676   arrsize __FWriteArgs.Length, __FWriteArgs.Buffer \
4677   syscall FileWrite, __FWriteArgs \
4678   mov _result, __FWriteArgs.Result \
4679   mov _len, __FWriteArgs.Length \
4680   release __FWriteMutex
4681 
4682 #define __writeBytesEx(_handle, _len, _buf, _result) \
4683   acquire __FWriteMutex \
4684   mov __FWriteArgs.FileHandle, _handle \
4685   mov __FWriteArgs.Length, _len \
4686   mov __FWriteArgs.Buffer, _buf \
4687   syscall FileWrite, __FWriteArgs \
4688   mov _result, __FWriteArgs.Result \
4689   mov _len, __FWriteArgs.Length \
4690   release __FWriteMutex
4691 
4692 #define __writeValue(_handle, _n, _result) \
4693   acquire __FWriteMutex \
4694   mov __FWriteArgs.FileHandle, _handle \
4695   flatten __FWriteFlattenBuf, _n \
4696   strtoarr __FWriteArgs.Buffer, __FWriteFlattenBuf \
4697   arrsize __FWriteArgs.Length, __FWriteArgs.Buffer \
4698   syscall FileWrite, __FWriteArgs \
4699   mov _result, __FWriteArgs.Result \
4700   release __FWriteMutex
4701 
4702 #define __writeLnValue(_handle, _n, _result) \
4703   acquire __FWriteMutex \
4704   mov __FWriteArgs.FileHandle, _handle \
4705   flatten __FWriteFlattenBuf, _n \
4706   strtoarr __FWriteArgs.Buffer, __FWriteFlattenBuf \
4707   arrbuild __FWriteFlattenBuf, __FWriteArgs.Buffer, __FWriteLn \
4708   mov __FWriteArgs.Buffer, __FWriteFlattenBuf \
4709   arrsize __FWriteArgs.Length, __FWriteArgs.Buffer \
4710   syscall FileWrite, __FWriteArgs \
4711   mov _result, __FWriteArgs.Result \
4712   release __FWriteMutex
4713 
4714 dseg segment
4715   __MWMutex mutex
4716   __MWArgs TMessageWrite
4717   __MRMutex mutex
4718   __MRArgs TMessageRead
4719   __SRNTmpVal sdword
4720   __RRNTmpVal sdword
4721   __RRNErr byte
4722 dseg ends
4723 
4724 #define __sendMessage(_queue, _msg, _result) \
4725   acquire __MWMutex \
4726   mov __MWArgs.QueueID, _queue \
4727   mov __MWArgs.Message, _msg \
4728   syscall MessageWrite, __MWArgs \
4729   mov _result, __MWArgs.Result \
4730   release __MWMutex
4731 
4732 #define __receiveMessage(_queue, _clear, _msg, _result) \
4733   acquire __MRMutex \
4734   mov __MRArgs.QueueID, _queue \
4735   mov __MRArgs.Remove, _clear \
4736   syscall MessageRead, __MRArgs \
4737   mov _msg, __MRArgs.Message \
4738   mov _result, __MRArgs.Result \
4739   release __MRMutex
4740 
4741 #define __receiveRemoteBool(_queue, _clear, _bval, _result) \
4742   acquire __MRMutex \
4743   mov __MRArgs.QueueID, _queue \
4744   mov __MRArgs.Remove, _clear \
4745   set _bval, 0 \
4746   syscall MessageRead, __MRArgs \
4747   brtst NEQ, __RRB_Err##__I__, __MRArgs.Result \
4748   index _bval, __MRArgs.Message, NA \
4749   __RRB_Err##__I__: \
4750   __IncI__ \
4751   mov _result, __MRArgs.Result \
4752   release __MRMutex
4753 
4754 #define __receiveRemoteNumber(_queue, _clear, _val, _result) \
4755   acquire __MRMutex \
4756   mov __MRArgs.QueueID, _queue \
4757   mov __MRArgs.Remove, _clear \
4758   set __RRNTmpVal, 0 \
4759   syscall MessageRead, __MRArgs \
4760   unflatten __RRNTmpVal, __RRNErr, __MRArgs.Message, __RRNTmpVal \
4761   mov _val, __RRNTmpVal \
4762   mov _result, __MRArgs.Result \
4763   release __MRMutex
4764 
4765 #define __receiveRemoteMessageEx(_queue, _clear, _str, _val, _bval, _result) \
4766   acquire __MRMutex \
4767   mov __MRArgs.QueueID, _queue \
4768   mov __MRArgs.Remove, _clear \
4769   set __RRNTmpVal, 0 \
4770   set _bval, 0 \
4771   syscall MessageRead, __MRArgs \
4772   brtst NEQ, __RRM_Err##__I__, __MRArgs.Result \
4773   index _bval, __MRArgs.Message, NA \
4774   unflatten __RRNTmpVal, __RRNErr, __MRArgs.Message, __RRNTmpVal \
4775   __RRM_Err##__I__: \
4776   __IncI__ \
4777   mov _val, __RRNTmpVal \
4778   mov _str, __MRArgs.Message \
4779   mov _result, __MRArgs.Result \
4780   release __MRMutex
4781 
4782 #define __sendResponseBool(_queue, _bval, _result) \
4783   acquire __MWMutex \
4784   add __MWArgs.QueueID, _queue, 10 \
4785   arrbuild __MWArgs.Message, _bval, 0 \
4786   syscall MessageWrite, __MWArgs \
4787   mov _result, __MWArgs.Result \
4788   release __MWMutex
4789 
4790 #define __sendResponseNumber(_queue, _val, _result) \
4791   acquire __MWMutex \
4792   add __MWArgs.QueueID, _queue, 10 \
4793   mov __SRNTmpVal, _val \
4794   flatten __MWArgs.Message, __SRNTmpVal \
4795   syscall MessageWrite, __MWArgs \
4796   mov _result, __MWArgs.Result \
4797   release __MWMutex
4798 
4799 #define __sendResponseString(_queue, _msg, _result) \
4800   acquire __MWMutex \
4801   add __MWArgs.QueueID, _queue, 10 \
4802   mov __MWArgs.Message, _msg \
4803   syscall MessageWrite, __MWArgs \
4804   mov _result, __MWArgs.Result \
4805   release __MWMutex
4806 
4807 
4808 dseg segment
4809   __CBTCSArgs TCommBTCheckStatus
4810   __CBTCSMutex mutex
4811   __CBTWArgs TCommBTWrite
4812   __CBTWMutex mutex
4813   __SRSTmpBuf byte[]
4814   __SRSSendBuf byte[]
4815   __SRSTmpLongVal sdword
4816   __SRSTmpWordVal sword
4817   __SRSTmpByteVal sbyte
4818   __SRSFlattenBuf byte[]
4819   __RemoteMutex mutex
4820 dseg ends
4821 
4822 dseg segment
4823   __GenericCmdFilenamePacket byte[] {0xFF, 0xFF, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
4824   __GenericCreateFilePacket byte[]  {0xFF, 0xFF, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0xFF, 0xFF, 0xFF, 0xFF}
4825   __GenericIOMapPacket byte[]       {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF}
4826 // direct commands
4827   __DCStartProgramPacket byte[]     {0x80, 0x00}
4828   __DCStopProgramPacket byte[]      {0x80, 0x01}
4829   __DCPlaySoundFilePacket byte[]    {0x80, 0x02, 0xFF, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
4830   __DCPlayTonePacket byte[]         {0x80, 0x03, 0xFF, 0xFF, 0xFF, 0xFF}
4831   __DCSetOutputStatePacket byte[]   {0x80, 0x04}
4832   __DCSetInputModePacket byte[]     {0x80, 0x05}
4833   __DCGetOutputStatePacket byte[]   {0x00, 0x06}
4834   __DCGetInputValuesPacket byte[]   {0x00, 0x07}
4835   __DCResetScaledValuePacket byte[] {0x80, 0x08}
4836   __DCMessageWritePacket byte[]     {0x80, 0x09, 0xFF, 0xFF}
4837   __DCResetMotorPosPacket byte[]    {0x80, 0x0a}
4838   __DCGetBatteryLevelPacket byte[]  {0x00, 0x0b}
4839   __DCStopSoundPacket byte[]        {0x80, 0x0c}
4840   __DCKeepAlivePacket byte[]        {0x80, 0x0d}
4841   __DCLSGetStatusPacket byte[]      {0x00, 0x0e}
4842   __DCLSWritePacket byte[]          {0x80, 0x0f}
4843   __DCLSReadPacket byte[]           {0x00, 0x10}
4844   __DCGetCurProgNamePacket byte[]   {0x00, 0x11}
4845   __DCMessageReadPacket byte[]      {0x00, 0x13}
4846   __DCDatalogReadPacket byte[]      {0x00, 0x19}
4847   __DCDatalogSetTimesPacket byte[]  {0x80, 0x1a}
4848   __DCBTGetContactCntPacket byte[]  {0x00, 0x1b}
4849   __DCBTGetContactNamePacket byte[] {0x00, 0x1c}
4850   __DCBTGetConnectCntPacket byte[]  {0x00, 0x1d}
4851   __DCBTGetConnectNamePacket byte[] {0x00, 0x1e}
4852   __DCSetPropertyPacket byte[]      {0x80, 0x1f}
4853   __DCGetPropertyPacket byte[]      {0x00, 0x20}
4854   __DCUpdateResetCountPacket byte[] {0x80, 0x21}
4855 // system commands
4856   __SCOpenReadPacket byte[]         {0x01, 0x80}
4857   __SCOpenWritePacket byte[]        {0x01, 0x81}
4858   __SCReadPacket byte[]             {0x01, 0x82}
4859   __SCWritePacket byte[]            {0x01, 0x83}
4860   __SCClosePacket byte[]            {0x01, 0x84}
4861   __SCDeletePacket byte[]           {0x01, 0x85}
4862   __SCFindFirstPacket byte[]        {0x01, 0x86}
4863   __SCFindNextPacket byte[]         {0x01, 0x87}
4864   __SCGetFirmwareVerPacket byte[]   {0x01, 0x88}
4865   __SCOpenWriteLinearPacket byte[]  {0x01, 0x89}
4866   __SCOpenWriteDataPacket byte[]    {0x01, 0x8b}
4867   __SCOpenAppendDataPacket byte[]   {0x01, 0x8c}
4868   __SCIOMapReadPacket byte[]        {0x01, 0x94}
4869   __SCIOMapWritePacket byte[]       {0x81, 0x95}
4870   __SCSetBrickNamePacket byte[]     {0x81, 0x98, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
4871   __SCBTGetAddressPacket byte[]     {0x01, 0x9a}
4872   __SCGetDeviceInfoPacket byte[]    {0x01, 0x9b}
4873   __SCDeleteUserFlashPacket byte[]  {0x01, 0xA0}
4874   __SCPollCommandLenPacket byte[]   {0x01, 0xA1}
4875   __SCPollCommandPacket byte[]      {0x01, 0xA2} // append buffer number, cmd len,
4876   __SCRenameFilePacket byte[]       {0x81, 0xA3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
4877   __SCBTFactoryResetPacket byte[]   {0x81, 0xA4}
4878 dseg ends
4879 
4880 #define __bluetoothStatus(_conn, _result) \
4881   acquire __CBTCSMutex \
4882   mov __CBTCSArgs.Connection, _conn \
4883   syscall CommBTCheckStatus, __CBTCSArgs \
4884   mov _result, __CBTCSArgs.Result \
4885   release __CBTCSMutex
4886 
4887 #define __bluetoothWrite(_conn, _buffer, _result) \
4888   acquire __CBTWMutex \
4889   mov __CBTWArgs.Connection, _conn \
4890   mov __CBTWArgs.Buffer, _buffer \
4891   syscall CommBTWrite, __CBTWArgs \
4892   mov _result, __CBTWArgs.Result \
4893   release __CBTWMutex
4894 
4895 #define __UseRS485() \
4896   setin IN_TYPE_HISPEED, IN_4, TypeField \
4897   wait 1
4898 
4899 #ifdef __ENHANCED_FIRMWARE
4900 
4901 dseg segment
4902   __CHSCSArgs TCommHSCheckStatus
4903   __CHSCSMutex mutex
4904   __CHSWArgs TCommHSReadWrite
4905   __CHSWMutex mutex
4906   __CHSRArgs TCommHSReadWrite
4907   __CHSRMutex mutex
4908   __CHSCArgs TCommHSControl
4909   __CHSCMutex mutex
4910   __SHSTmpVal sdword
4911   __WFRRMutex mutex
4912   __WFRRAvail byte
4913   __WFRR_I byte
4914   __WFRRCmd byte
4915   __WFRRBuffer byte[]
4916   __WFRRTmpBuffer byte[]
4917   __WFRRUnflattenBuf byte[]
4918   __WFRRUnflattenErr byte
4919   __WFRRTmpByte byte
4920   __WFRRTmpSWord sword
4921   __WFRRTmpSDWord sdword
4922   __WFRRStatus sbyte
4923 dseg ends
4924 
4925 #define __RS485Status(_sendingData, _dataAvail) \
4926   acquire __CHSCSMutex \
4927   syscall CommHSCheckStatus, __CHSCSArgs \
4928   mov _sendingData, __CHSCSArgs.SendingData \
4929   mov _dataAvail, __CHSCSArgs.DataAvailable \
4930   release __CHSCSMutex
4931 
4932 #define __RS485WriteSCDC(_conn, _buffer, _status) \
4933   acquire __CHSWMutex \
4934   sub __WFRRTmpByte, _conn, CONN_HS_ALL \
4935   arrbuild __CHSWArgs.Buffer, __WFRRTmpByte, _buffer \
4936   syscall CommHSWrite, __CHSWArgs \
4937   mov _status, __CHSWArgs.Status \
4938   release __CHSWMutex
4939 
4940 #define __RS485Write(_buffer, _status) \
4941   acquire __CHSWMutex \
4942   mov __CHSWArgs.Buffer, _buffer \
4943   syscall CommHSWrite, __CHSWArgs \
4944   mov _status, __CHSWArgs.Status \
4945   release __CHSWMutex
4946 
4947 #define __RS485Read(_buffer, _status) \
4948   acquire __CHSRMutex \
4949   syscall CommHSRead, __CHSRArgs \
4950   mov _buffer, __CHSRArgs.Buffer \
4951   mov _status, __CHSRArgs.Status \
4952   release __CHSRMutex
4953 
4954 #if __FIRMWARE_VERSION > 107
4955 
4956 #define __RS485Control(_cmd, _baud, _mode, _result) \
4957   acquire __CHSCMutex \
4958   mov __CHSCArgs.Command, _cmd \
4959   mov __CHSCArgs.BaudRate, _baud \
4960   mov __CHSCArgs.Mode, _mode \
4961   syscall CommHSControl, __CHSCArgs \
4962   mov _result, __CHSCArgs.Result \
4963   release __CHSCMutex \
4964   wait 1
4965 
4966 #else
4967 
4968 #define __RS485Control(_cmd, _baud, _result) \
4969   acquire __CHSCMutex \
4970   mov __CHSCArgs.Command, _cmd \
4971   mov __CHSCArgs.BaudRate, _baud \
4972   syscall CommHSControl, __CHSCArgs \
4973   mov _result, __CHSCArgs.Result \
4974   release __CHSCMutex \
4975   wait 1
4976 
4977 #endif
4978 
4979 #define __sendRS485Bool(_bval, _status) \
4980   acquire __CHSWMutex \
4981   arrbuild __CHSWArgs.Buffer, _bval, 0 \
4982   syscall CommHSWrite, __CHSWArgs \
4983   mov _status, __CHSWArgs.Status \
4984   release __CHSWMutex
4985 
4986 #define __sendRS485Number(_val, _status) \
4987   acquire __CHSWMutex \
4988   mov __SHSTmpVal, _val \
4989   flatten __CHSWArgs.Buffer, __SHSTmpVal \
4990   syscall CommHSWrite, __CHSWArgs \
4991   mov _status, __CHSWArgs.Status \
4992   release __CHSWMutex
4993 
4994 #define __sendRS485String(_str, _status) __RS485Write(_str, _status)
4995 
4996 #endif
4997 
4998 #ifdef __ENHANCED_FIRMWARE
4999 
5000 #define __connectionSCDCWrite(_conn, _buffer, _result) \
5001   brcmp LT, __ConnWrite_Else##__I__, _conn, 4 \
5002   __RS485WriteSCDC(_conn, _buffer, _result) \
5003   jmp __ConnWrite_EndIf##__I__ \
5004   __ConnWrite_Else##__I__: \
5005   __bluetoothWrite(_conn, _buffer, _result) \
5006   __ConnWrite_EndIf##__I__: \
5007   __IncI__
5008 
5009 #define __connectionRawWrite(_conn, _buffer, _result) \
5010   brcmp LT, __ConnWrite_Else##__I__, _conn, 4 \
5011   __RS485Write(_buffer, _result) \
5012   jmp __ConnWrite_EndIf##__I__ \
5013   __ConnWrite_Else##__I__: \
5014   __bluetoothWrite(_conn, _buffer, _result) \
5015   __ConnWrite_EndIf##__I__: \
5016   __IncI__
5017 
5018 #define __remoteConnectionIdle(_conn, _result) \
5019   brcmp NEQ, __ConnIdle_Else##__I__, _conn, 4 \
5020   __RS485Status(_result, __SHSTmpVal) \
5021   jmp __ConnIdle_EndIf##__I__ \
5022   __ConnIdle_Else##__I__: \
5023   __bluetoothStatus(_conn, _result) \
5024   __ConnIdle_EndIf##__I__: \
5025   tst EQ, _result, _result \
5026   __IncI__
5027 
5028 subroutine __DoWaitForRemoteResponse
5029   set __WFRR_I, 0
5030   __wFRR_Repeat:
5031   __GetLastResponseInfo(FALSE, __WFRRAvail, __WFRRCmd, __WFRRBuffer, __WFRRStatus)
5032   wait 2
5033   add __WFRR_I, __WFRR_I, 1
5034   // if it rolls back around to 0 then break out of loop
5035   brtst EQ, __wFRR_Break, __WFRR_I
5036   brtst EQ, __wFRR_Repeat, __WFRRAvail
5037   // > 0 bytes in last response so read it one more time and clear it
5038   __GetLastResponseInfo(TRUE, __WFRRAvail, __WFRRCmd, __WFRRBuffer, __WFRRStatus)
5039   jmp __wFRR_End
5040   __wFRR_Break:
5041   set __WFRRStatus, TRUE // timeout error occurred
5042   __wFRR_End:
5043   return
5044 ends
5045 
5046 #else
5047 
5048 #define __connectionSCDCWrite(_conn, _buffer, _result) __bluetoothWrite(_conn, _buffer, _result)
5049 #define __connectionRawWrite(_conn, _buffer, _result) __bluetoothWrite(_conn, _buffer, _result)
5050 
5051 #define __remoteConnectionIdle(_conn, _result) \
5052   __bluetoothStatus(_conn, _result) \
5053   tst EQ, _result, _result
5054 
5055 #endif
5056 
5057 #define __sendRemoteBool(_conn, _queue, _bval, _result) \
5058   acquire __RemoteMutex \
5059   mov __SRSTmpBuf, __DCMessageWritePacket \
5060   replace __SRSTmpBuf, __SRSTmpBuf, 2, _queue \
5061   replace __SRSTmpBuf, __SRSTmpBuf, 3, 2 \
5062   arrbuild __SRSSendBuf, __SRSTmpBuf, _bval, 0 \
5063   __connectionSCDCWrite(_conn, __SRSSendBuf, _result) \
5064   release __RemoteMutex
5065 
5066 #define __sendRemoteNumber(_conn, _queue, _val, _result) \
5067   acquire __RemoteMutex \
5068   mov __SRSTmpBuf, __DCMessageWritePacket \
5069   replace __SRSTmpBuf, __SRSTmpBuf, 2, _queue \
5070   replace __SRSTmpBuf, __SRSTmpBuf, 3, 5 \
5071   mov __SRSTmpLongVal, _val \
5072   flatten __SRSFlattenBuf, __SRSTmpLongVal \
5073   arrbuild __SRSSendBuf, __SRSTmpBuf, __SRSFlattenBuf \
5074   __connectionSCDCWrite(_conn, __SRSSendBuf, _result) \
5075   release __RemoteMutex
5076 
5077 #define __sendRemoteString(_conn, _queue, _str, _result) \
5078   acquire __RemoteMutex \
5079   mov __SRSTmpBuf, __DCMessageWritePacket \
5080   replace __SRSTmpBuf, __SRSTmpBuf, 2, _queue \
5081   arrsize __SRSTmpLongVal, _str \
5082   replace __SRSTmpBuf, __SRSTmpBuf, 3, __SRSTmpLongVal \
5083   arrbuild __SRSSendBuf, __SRSTmpBuf, _str \
5084   __connectionSCDCWrite(_conn, __SRSSendBuf, _result) \
5085   release __RemoteMutex
5086 
5087 #define __remoteMessageRead(_conn, _queue, _result) \
5088   acquire __RemoteMutex \
5089   add __SRSTmpLongVal, _queue, 10 \
5090   arrbuild __SRSSendBuf, __DCMessageReadPacket, __SRSTmpLongVal, _queue, 0x01 \
5091   __connectionSCDCWrite(_conn, __SRSSendBuf, _result) \
5092   release __RemoteMutex
5093 
5094 #define __remoteResetScaledValue(_conn, _port, _result) \
5095   acquire __RemoteMutex \
5096   arrbuild __SRSSendBuf, __DCResetScaledValuePacket, _port \
5097   __connectionSCDCWrite(_conn, __SRSSendBuf, _result) \
5098   release __RemoteMutex
5099 
5100 #define __remoteResetMotorPosition(_conn, _port, _brelative, _result) \
5101   acquire __RemoteMutex \
5102   arrbuild __SRSSendBuf, __DCResetMotorPosPacket, _port, _brelative \
5103   __connectionSCDCWrite(_conn, __SRSSendBuf, _result) \
5104   release __RemoteMutex
5105 
5106 #define __remoteSetInputMode(_conn, _port, _type, _mode, _result) \
5107   acquire __RemoteMutex \
5108   arrbuild __SRSSendBuf, __DCSetInputModePacket, _port, _type, _mode \
5109   __connectionSCDCWrite(_conn, __SRSSendBuf, _result) \
5110   release __RemoteMutex
5111 
5112 #define __remoteSetOutputState(_conn, _port, _speed, _mode, _regmode, _turnpct, _runstate, _tacholimit, _result) \
5113   acquire __RemoteMutex \
5114   mov __SRSTmpLongVal, _tacholimit \
5115   flatten __SRSFlattenBuf, __SRSTmpLongVal \
5116   arrbuild __SRSTmpBuf, __DCSetOutputStatePacket, _port, _speed, _mode, _regmode, _turnpct, _runstate, __SRSFlattenBuf \
5117   strtoarr __SRSSendBuf, __SRSTmpBuf \
5118   __connectionSCDCWrite(_conn, __SRSSendBuf, _result) \
5119   release __RemoteMutex
5120 
5121 #define __remotePlaySoundFile(_conn, _filename, _bloop, _result) \
5122   acquire __RemoteMutex \
5123   mov __SRSSendBuf, __DCPlaySoundFilePacket \
5124   strsubset __SRSTmpBuf, _filename, NA, 19 \
5125   replace __SRSSendBuf, __SRSSendBuf, 2, _bloop \
5126   replace __SRSSendBuf, __SRSSendBuf, 3, __SRSTmpBuf \
5127   __connectionSCDCWrite(_conn, __SRSSendBuf, _result) \
5128   release __RemoteMutex
5129 
5130 #define __remotePlayTone(_conn, _frequency, _duration, _result) \
5131   acquire __RemoteMutex \
5132   mov __SRSSendBuf, __DCPlayTonePacket \
5133   and __SRSTmpLongVal, _frequency, 0xff \
5134   replace __SRSSendBuf, __SRSSendBuf, 2, __SRSTmpLongVal \
5135   div __SRSTmpLongVal, _frequency, 0xff \
5136   replace __SRSSendBuf, __SRSSendBuf, 3, __SRSTmpLongVal \
5137   and __SRSTmpLongVal, _duration, 0xff \
5138   replace __SRSSendBuf, __SRSSendBuf, 4, __SRSTmpLongVal \
5139   div __SRSTmpLongVal, _duration, 0xff \
5140   replace __SRSSendBuf, __SRSSendBuf, 5, __SRSTmpLongVal \
5141   __connectionSCDCWrite(_conn, __SRSSendBuf, _result) \
5142   release __RemoteMutex
5143 
5144 #define __remoteGenericFilenameCommand(_conn, _cmdBuf, _filename, _result) \
5145   acquire __RemoteMutex \
5146   mov __SRSSendBuf, __GenericCmdFilenamePacket \
5147   strsubset __SRSTmpBuf, _filename, NA, 19 \
5148   replace __SRSSendBuf, __SRSSendBuf, NA, _cmdBuf \
5149   replace __SRSSendBuf, __SRSSendBuf, 2, __SRSTmpBuf \
5150   __connectionSCDCWrite(_conn, __SRSSendBuf, _result) \
5151   release __RemoteMutex
5152 
5153 #define __remoteStartProgram(_conn, _filename, _result) __remoteGenericFilenameCommand(_conn, __DCStartProgramPacket, _filename, _result)
5154 
5155 #define __remoteGenericCreateFileCommand(_conn, _cmdBuf, _filename, _size, _result) \
5156   acquire __RemoteMutex \
5157   mov __SRSSendBuf, __GenericCreateFilePacket \
5158   strsubset __SRSTmpBuf, _filename, NA, 19 \
5159   replace __SRSSendBuf, __SRSSendBuf, NA, _cmdBuf \
5160   replace __SRSSendBuf, __SRSSendBuf, 2, __SRSTmpBuf \
5161   mov __SRSTmpLongVal, _size \
5162   flatten __SRSFlattenBuf, __SRSTmpLongVal \
5163   strtoarr __SRSTmpBuf, __SRSFlattenBuf \
5164   replace __SRSSendBuf, __SRSSendBuf, 22, __SRSTmpBuf \
5165   __connectionSCDCWrite(_conn, __SRSSendBuf, _result) \
5166   release __RemoteMutex
5167 
5168 #define __remoteGenericByteCommand(_conn, _cmdBuf, _val, _result) \
5169   compchk EQ, sizeof(_val), 1 \
5170   acquire __RemoteMutex \
5171   arrbuild __SRSSendBuf, _cmdBuf, _val \
5172   __connectionSCDCWrite(_conn, __SRSSendBuf, _result) \
5173   release __RemoteMutex
5174 
5175 #define __remoteResetTachoCount(_conn, _port, _result) __remoteGenericByteCommand(_conn, __DCUpdateResetCountPacket, _port, _result)
5176 
5177 #define __remoteDoWrite(_conn, _handle, _data, _result) \
5178   compchk EQ, sizeof(_handle), 1 \
5179   acquire __RemoteMutex \
5180   arrbuild __SRSSendBuf, __SCWritePacket, _handle, _data \
5181   __connectionSCDCWrite(_conn, __SRSSendBuf, _result) \
5182   release __RemoteMutex
5183 
5184 #define __remoteDoRead(_conn, _handle, _numbytes, _result) \
5185   compchk EQ, sizeof(_handle), 1 \
5186   acquire __RemoteMutex \
5187   mov __SRSTmpWordVal, _numbytes \
5188   flatten __SRSFlattenBuf, __SRSTmpWordVal \
5189   strtoarr __SRSTmpBuf, __SRSFlattenBuf \
5190   arrbuild __SRSSendBuf, __SCReadPacket, _handle, __SRSTmpBuf \
5191   __connectionSCDCWrite(_conn, __SRSSendBuf, _result) \
5192   release __RemoteMutex
5193 
5194 #define __remoteDoPollCommand(_conn, _bufnum, _len, _result) \
5195   compchk EQ, sizeof(_bufnum), 1 \
5196   compchk EQ, sizeof(_len), 1 \
5197   acquire __RemoteMutex \
5198   arrbuild __SRSSendBuf, __SCPollCommandPacket, _bufnum, _len \
5199   __connectionSCDCWrite(_conn, __SRSSendBuf, _result) \
5200   release __RemoteMutex
5201 
5202 #define __remoteDoIOMapRead(_conn, _id, _offset, _numbytes, _result) \
5203   compchk EQ, sizeof(_handle), 1 \
5204   acquire __RemoteMutex \
5205   mov __SRSSendBuf, __GenericIOMapPacket \
5206   replace __SRSSendBuf, __SRSSendBuf, NA, __SCIOMapReadPacket \
5207   mov __SRSTmpLongVal, _offset \
5208   flatten __SRSFlattenBuf, __SRSTmpLongVal \
5209   strtoarr __SRSTmpBuf, __SRSFlattenBuf \
5210   replace __SRSSendBuf, __SRSSendBuf, 2, __SRSTmpBuf \
5211   mov __SRSTmpWordVal, _offset \
5212   flatten __SRSFlattenBuf, __SRSTmpWordVal \
5213   strtoarr __SRSTmpBuf, __SRSFlattenBuf \
5214   replace __SRSSendBuf, __SRSSendBuf, 6, __SRSTmpBuf \
5215   mov __SRSTmpWordVal, _numbytes \
5216   flatten __SRSFlattenBuf, __SRSTmpWordVal \
5217   strtoarr __SRSTmpBuf, __SRSFlattenBuf \
5218   replace __SRSSendBuf, __SRSSendBuf, 8, __SRSTmpBuf \
5219   __connectionSCDCWrite(_conn, __SRSSendBuf, _result) \
5220   release __RemoteMutex
5221 
5222 
5223 #ifdef __ENHANCED_FIRMWARE
5224 
5225 #define __remoteGetOutputState(_conn, _params, _result) \
5226   __remoteGenericByteCommand(_conn, __DCGetOutputStatePacket, _params.Port, _result) \
5227   call __DoWaitForRemoteResponse \
5228   mov _result, __WFRRStatus \
5229   brtst NEQ, __RRGOSR_End##__I__, _result \
5230   brcmp NEQ, __RRGOSR_End##__I__, __WFRRAvail, 23 \
5231   unflatten _params, __WFRRUnflattenErr, __WFRRBuffer, _params \
5232   __RRGOSR_End##__I__: \
5233   __IncI__
5234 
5235 #define __remoteGetInputValues(_conn, _params, _result) \
5236   __remoteGenericByteCommand(_conn, __DCGetInputValuesPacket, _params.Port, _result) \
5237   call __DoWaitForRemoteResponse \
5238   mov _result, __WFRRStatus \
5239   brtst NEQ, __RRGIVR_End##__I__, _result \
5240   brcmp NEQ, __RRGIVR_End##__I__, __WFRRAvail, 14 \
5241   unflatten _params, __WFRRUnflattenErr, __WFRRBuffer, _params \
5242   __RRGIVR_End##__I__: \
5243   __IncI__
5244 
5245 #define __remoteGetBatteryLevel(_conn, _value, _result) \
5246   compchk EQ, sizeof(_value), 2 \
5247   __connectionSCDCWrite(_conn, __DCGetBatteryLevelPacket, _result) \
5248   call __DoWaitForRemoteResponse \
5249   mov _result, __WFRRStatus \
5250   brtst NEQ, __RRGBL_End##__I__, _result \
5251   brcmp NEQ, __RRGBL_End##__I__, __WFRRAvail, 3 \
5252   unflatten _value, __WFRRUnflattenErr, __WFRRBuffer, _value \
5253   __RRGBL_End##__I__: \
5254   __IncI__
5255 
5256 #define __remoteLowspeedGetStatus(_conn, _value, _result) \
5257   __connectionSCDCWrite(_conn, __DCLSGetStatusPacket, _result) \
5258   call __DoWaitForRemoteResponse \
5259   mov _result, __WFRRStatus \
5260   brtst NEQ, __RRLGS_End##__I__, _result \
5261   brcmp NEQ, __RRLGS_End##__I__, __WFRRAvail, 2 \
5262   index _value, __WFRRBuffer, NA \
5263   __RRLGS_End##__I__: \
5264   __IncI__
5265 
5266 #define __remoteLowspeedRead(_conn, _port, _bread, _data, _result) \
5267   __remoteGenericByteCommand(_conn, __DCLSReadPacket, _port, _result) \
5268   call __DoWaitForRemoteResponse \
5269   mov _result, __WFRRStatus \
5270   brtst NEQ, __RRLR_End##__I__, _result \
5271   brcmp NEQ, __RRLR_End##__I__, __WFRRAvail, 18 \
5272   index _bread, __WFRRBuffer, NA \
5273   arrsubset _data, __WFRRBuffer, 1, _bread \
5274   __RRLR_End##__I__: \
5275   __IncI__
5276 
5277 #define __remoteGetCurrentProgramName(_conn, _name, _result) \
5278   __connectionSCDCWrite(_conn, __DCGetCurProgNamePacket, _result) \
5279   call __DoWaitForRemoteResponse \
5280   mov _result, __WFRRStatus \
5281   brtst NEQ, __RRGCPN_End##__I__, _result \
5282   brcmp NEQ, __RRGCPN_End##__I__, __WFRRAvail, 21 \
5283   mov _name, __WFRRBuffer \
5284   __RRGCPN_End##__I__: \
5285   __IncI__
5286 
5287 #define __remoteDatalogRead(_conn, _remove, _cnt, _log, _result) \
5288   __remoteGenericByteCommand(_conn, __DCDatalogReadPacket, _remove, _result) \
5289   call __DoWaitForRemoteResponse \
5290   mov _result, __WFRRStatus \
5291   brtst NEQ, __RRDR_End##__I__, _result \
5292   brcmp NEQ, __RRDR_End##__I__, __WFRRAvail, 62 \
5293   index _cnt, __WFRRBuffer, NA \
5294   arrsubset _log, __WFRRBuffer, 1, _cnt \
5295   __RRDR_End##__I__: \
5296   __IncI__
5297 
5298 #define __remoteGetContactCount(_conn, _cnt, _result) \
5299   __connectionSCDCWrite(_conn, __DCBTGetContactCntPacket, _result) \
5300   call __DoWaitForRemoteResponse \
5301   mov _result, __WFRRStatus \
5302   brtst NEQ, __RRGCTC_End##__I__, _result \
5303   brcmp NEQ, __RRGCTC_End##__I__, __WFRRAvail, 2 \
5304   index _cnt, __WFRRBuffer, NA \
5305   __RRGCTC_End##__I__: \
5306   __IncI__
5307 
5308 #define __remoteGetContactName(_conn, _idx, _name, _result) \
5309   __remoteGenericByteCommand(_conn, __DCBTGetContactNamePacket, _idx, _result) \
5310   call __DoWaitForRemoteResponse \
5311   mov _result, __WFRRStatus \
5312   brtst NEQ, __RRGCTN_End##__I__, _result \
5313   brcmp NEQ, __RRGCTN_End##__I__, __WFRRAvail, 19 \
5314   mov _name, __WFRRBuffer \
5315   __RRGCTN_End##__I__: \
5316   __IncI__
5317 
5318 #define __remoteGetConnectionCount(_conn, _cnt, _result) \
5319   __connectionSCDCWrite(_conn, __DCBTGetConnectCntPacket, _result) \
5320   call __DoWaitForRemoteResponse \
5321   mov _result, __WFRRStatus \
5322   brtst NEQ, __RRGCNC_End##__I__, _result \
5323   brcmp NEQ, __RRGCNC_End##__I__, __WFRRAvail, 2 \
5324   index _cnt, __WFRRBuffer, NA \
5325   __RRGCNC_End##__I__: \
5326   __IncI__
5327 
5328 #define __remoteGetConnectionName(_conn, _idx, _name, _result) \
5329   __remoteGenericByteCommand(_conn, __DCBTGetConnectNamePacket, _idx, _result) \
5330   call __DoWaitForRemoteResponse \
5331   mov _result, __WFRRStatus \
5332   brtst NEQ, __RRGCNN_End##__I__, _result \
5333   brcmp NEQ, __RRGCNN_End##__I__, __WFRRAvail, 19 \
5334   mov _name, __WFRRBuffer \
5335   __RRGCNN_End##__I__: \
5336   __IncI__
5337 
5338 #define __remoteGetProperty(_conn, _property, _value, _result) \
5339   mov _value, 0 \
5340   __remoteGenericByteCommand(_conn, __DCGetPropertyPacket, _property, _result) \
5341   call __DoWaitForRemoteResponse \
5342   mov _result, __WFRRStatus \
5343   brtst NEQ, __RRGP_End##__I__, _result \
5344   unflatten _value, __WFRRUnflattenErr, __WFRRBuffer, _value \
5345   __RRGP_End##__I__: \
5346   __IncI__
5347 
5348 #define __remoteOpenRead(_conn, _filename, _handle, _size, _result) \
5349   __remoteGenericFilenameCommand(_conn, __SCOpenReadPacket, _filename, _result) \
5350   call __DoWaitForRemoteResponse \
5351   mov _result, __WFRRStatus \
5352   brtst NEQ, __RROR_End##__I__, _result \
5353   brcmp NEQ, __RROR_End##__I__, __WFRRAvail, 6 \
5354   index _handle, __WFRRBuffer, NA \
5355   arrsubset __WFRRTmpBuffer, __WFRRBuffer, 1, 5 \
5356   unflatten __WFRRTmpSDWord, __WFRRUnflattenErr, __WFRRTmpBuffer, __WFRRTmpSDWord \
5357   mov _size, __WFRRTmpSDWord \
5358   __RROR_End##__I__: \
5359   __IncI__
5360 
5361 #define __remoteOpenWrite(_conn, _filename, _size, _handle, _result) \
5362   __remoteGenericCreateFileCommand(_conn, __SCOpenWritePacket, _filename, _size, _result) \
5363   call __DoWaitForRemoteResponse \
5364   mov _result, __WFRRStatus \
5365   brtst NEQ, __RROW_End##__I__, _result \
5366   brcmp NEQ, __RROW_End##__I__, __WFRRAvail, 2 \
5367   index _handle, __WFRRBuffer, NA \
5368   __RROW_End##__I__: \
5369   __IncI__
5370 
5371 #define __remoteRead(_conn, _handle, _numbytes, _data, _result) \
5372   mov _result, 1 \
5373   brcmp GT, __RRRead_End##__I__, _numbytes, 58 \
5374   __remoteDoRead(_conn, _handle, _numbytes, _result) \
5375   call __DoWaitForRemoteResponse \
5376   mov _result, __WFRRStatus \
5377   add __WFRRTmpByte, _numbytes, 4 \
5378   brtst NEQ, __RRRead_End##__I__, _result \
5379   brcmp NEQ, __RRRead_End##__I__, __WFRRAvail, __WFRRTmpByte \
5380   index _handle, __WFRRBuffer, NA \
5381   arrsubset __WFRRTmpBuffer, __WFRRBuffer, 1, 2 \
5382   arrtostr __WFRRUnflattenBuf, __WFRRTmpBuffer \
5383   unflatten __WFRRTmpSWord, __WFRRUnflattenErr, __WFRRUnflattenBuf, __WFRRTmpSWord \
5384   mov _numbytes, __WFRRTmpSWord \
5385   arrsubset _data, __WFRRBuffer, 2, _numbytes \
5386   __RRRead_End##__I__: \
5387   __IncI__
5388 
5389 #define __remoteWrite(_conn, _handle, _numbytes, _data, _result) \
5390   mov _result, 1 \
5391   brcmp GT, __RRWrite_End##__I__, _numbytes, 58 \
5392   __remoteDoWrite(_conn, _handle, _data, _result) \
5393   call __DoWaitForRemoteResponse \
5394   mov _result, __WFRRStatus \
5395   brtst NEQ, __RRWrite_End##__I__, _result \
5396   brcmp NEQ, __RRWrite_End##__I__, __WFRRAvail, 4 \
5397   index _handle, __WFRRBuffer, NA \
5398   arrsubset __WFRRTmpBuffer, __WFRRBuffer, 1, 3 \
5399   unflatten __WFRRTmpSWord, __WFRRUnflattenErr, __WFRRTmpBuffer, __WFRRTmpSWord \
5400   mov _numbytes, __WFRRTmpSWord \
5401   __RRWrite_End##__I__: \
5402   __IncI__
5403 
5404 #define __remoteCloseFile(_conn, _handle, _result) \
5405   __remoteGenericByteCommand(_conn, __SCClosePacket, _handle, _result) \
5406   call __DoWaitForRemoteResponse \
5407   mov _result, __WFRRStatus
5408 
5409 #define __remoteDeleteFile(_conn, _filename, _result) \
5410   __remoteGenericFilenameCommand(_conn, __SCDeletePacket, _filename, _result) \
5411   call __DoWaitForRemoteResponse \
5412   mov _result, __WFRRStatus
5413 
5414 #define __remoteDeleteUserFlash(_conn, _result) \
5415   __connectionSCDCWrite(_conn, __SCDeleteUserFlashPacket, _result) \
5416   call __DoWaitForRemoteResponse \
5417   mov _result, __WFRRStatus
5418 
5419 #define __remoteFindFirstFile(_conn, _mask, _handle, _name, _size, _result) \
5420   __remoteGenericFilenameCommand(_conn, __SCFindFirstPacket, _mask, _result) \
5421   call __DoWaitForRemoteResponse \
5422   mov _result, __WFRRStatus \
5423   brtst NEQ, __RRFindFirstFile_End##__I__, _result \
5424   brcmp NEQ, __RRFindFirstFile_End##__I__, __WFRRAvail, 26 \
5425   index _handle, __WFRRBuffer, NA \
5426   arrsubset _name, __WFRRBuffer, 1, 20 \
5427   arrsubset __WFRRTmpBuffer, __WFRRBuffer, 21, 5 \
5428   unflatten __WFRRTmpSDWord, __WFRRUnflattenErr, __WFRRTmpBuffer, __WFRRTmpSDWord \
5429   mov _size, __WFRRTmpSDWord \
5430   __RRFindFirstFile_End##__I__: \
5431   __IncI__
5432 
5433 #define __remoteFindNextFile(_conn, _handle, _name, _size, _result) \
5434   __remoteGenericByteCommand(_conn, __SCFindNextPacket, _handle, _result) \
5435   call __DoWaitForRemoteResponse \
5436   mov _result, __WFRRStatus \
5437   brtst NEQ, __RRFindNextFile_End##__I__, _result \
5438   brcmp NEQ, __RRFindNextFile_End##__I__, __WFRRAvail, 26 \
5439   index _handle, __WFRRBuffer, NA \
5440   arrsubset _name, __WFRRBuffer, 1, 20 \
5441   arrsubset __WFRRTmpBuffer, __WFRRBuffer, 21, 5 \
5442   unflatten __WFRRTmpSDWord, __WFRRUnflattenErr, __WFRRTmpBuffer, __WFRRTmpSDWord \
5443   mov _size, __WFRRTmpSDWord \
5444   __RRFindNextFile_End##__I__: \
5445   __IncI__
5446 
5447 #define __remoteGetFirmwareVersion(_conn, _pmin, _pmaj, _fmin, _fmaj, _result) \
5448   __connectionSCDCWrite(_conn, __SCGetFirmwareVerPacket, _result) \
5449   call __DoWaitForRemoteResponse \
5450   mov _result, __WFRRStatus \
5451   brtst NEQ, __RRGetFirmwareVersion_End##__I__, _result \
5452   brcmp NEQ, __RRGetFirmwareVersion_End##__I__, __WFRRAvail, 5 \
5453   index _pmin, __WFRRBuffer, NA \
5454   index _pmaj, __WFRRBuffer, 1 \
5455   index _fmin, __WFRRBuffer, 2 \
5456   index _fmaj, __WFRRBuffer, 3 \
5457   __RRGetFirmwareVersion_End##__I__: \
5458   __IncI__
5459 
5460 #define __remoteOpenWriteLinear(_conn, _filename, _size, _handle, _result) \
5461   __remoteGenericCreateFileCommand(_conn, __SCOpenWriteLinearPacket, _filename, _size, _result) \
5462   call __DoWaitForRemoteResponse \
5463   mov _result, __WFRRStatus \
5464   brtst NEQ, __RROWL_End##__I__, _result \
5465   brcmp NEQ, __RROWL_End##__I__, __WFRRAvail, 2 \
5466   index _handle, __WFRRBuffer, NA \
5467   __RROWL_End##__I__: \
5468   __IncI__
5469 
5470 #define __remoteOpenWriteData(_conn, _filename, _size, _handle, _result) \
5471   __remoteGenericCreateFileCommand(_conn, __SCOpenWriteDataPacket, _filename, _size, _result) \
5472   call __DoWaitForRemoteResponse \
5473   mov _result, __WFRRStatus \
5474   brtst NEQ, __RROWD_End##__I__, _result \
5475   brcmp NEQ, __RROWD_End##__I__, __WFRRAvail, 2 \
5476   index _handle, __WFRRBuffer, NA \
5477   __RROWD_End##__I__: \
5478   __IncI__
5479 
5480 #define __remoteOpenAppendData(_conn, _filename, _handle, _size, _result) \
5481   __remoteGenericFilenameCommand(_conn, __SCOpenAppendDataPacket, _filename, _result) \
5482   call __DoWaitForRemoteResponse \
5483   mov _result, __WFRRStatus \
5484   brtst NEQ, __RROAD_End##__I__, _result \
5485   brcmp NEQ, __RROAD_End##__I__, __WFRRAvail, 6 \
5486   index _handle, __WFRRBuffer, NA \
5487   arrsubset __WFRRTmpBuffer, __WFRRBuffer, 1, 5 \
5488   unflatten __WFRRTmpSDWord, __WFRRUnflattenErr, __WFRRTmpBuffer, __WFRRTmpSDWord \
5489   mov _size, __WFRRTmpSDWord \
5490   __RROAD_End##__I__: \
5491   __IncI__
5492 
5493 #define __remoteGetDeviceInfo(_conn, _name, _btaddr, _btsignal, _freemem, _result) \
5494   __connectionSCDCWrite(_conn, __SCGetDeviceInfoPacket, _result) \
5495   call __DoWaitForRemoteResponse \
5496   mov _result, __WFRRStatus \
5497   brtst NEQ, __RRGetDeviceInfo_End##__I__, _result \
5498   brcmp NEQ, __RRGetDeviceInfo_End##__I__, __WFRRAvail, 31 \
5499   arrsubset _name, __WFRRBuffer, NA, 15 \
5500   arrsubset _btaddr, __WFRRBuffer, 15, 7 \
5501   arrsubset _btsignal, __WFRRBuffer, 22, 4 \
5502   arrsubset __WFRRTmpBuffer, __WFRRBuffer, 26, 5 \
5503   unflatten __WFRRTmpSDWord, __WFRRUnflattenErr, __WFRRTmpBuffer, __WFRRTmpSDWord \
5504   mov _freemem, __WFRRTmpSDWord \
5505   __RRGetDeviceInfo_End##__I__: \
5506   __IncI__
5507 
5508 #define __remotePollCommandLength(_conn, _bufnum, _length, _result) \
5509   __remoteGenericByteCommand(_conn, __SCPollCommandLenPacket, _bufnum, _result) \
5510   call __DoWaitForRemoteResponse \
5511   mov _result, __WFRRStatus \
5512   brtst NEQ, __RRPollCommandLength_End##__I__, _result \
5513   brcmp NEQ, __RRPollCommandLength_End##__I__, __WFRRAvail, 3 \
5514   index _length, __WFRRBuffer, 1 \
5515   __RRPollCommandLength_End##__I__: \
5516   __IncI__
5517 
5518 #define __remotePollCommand(_conn, _bufnum, _len, _data, _result) \
5519   mov _result, 1 \
5520   brcmp GT, __RRPollCommand_End##__I__, _len, 58 \
5521   __remoteDoPollCommand(_conn, _bufnum, _len, _result) \
5522   call __DoWaitForRemoteResponse \
5523   mov _result, __WFRRStatus \
5524   add __WFRRTmpByte, _len, 3 \
5525   brtst NEQ, __RRPollCommand_End##__I__, _result \
5526   brcmp NEQ, __RRPollCommand_End##__I__, __WFRRAvail, __WFRRTmpByte \
5527   index _len, __WFRRBuffer, 1 \
5528   arrsubset _data, __WFRRBuffer, 2, _len \
5529   __RRPollCommand_End##__I__: \
5530   __IncI__
5531 
5532 #define __remoteIOMapRead(_conn, _id, _offset, _numbytes, _data, _result) \
5533   mov _result, 1 \
5534   brcmp GT, __RRIOMapRead_End##__I__, _numbytes, 58 \
5535   __remoteDoIOMapRead(_conn, _id, _offset, _numbytes, _result) \
5536   call __DoWaitForRemoteResponse \
5537   mov _result, __WFRRStatus \
5538   add __WFRRTmpByte, _numbytes, 7 \
5539   brtst NEQ, __RRIOMapRead_End##__I__, _result \
5540   brcmp NEQ, __RRIOMapRead_End##__I__, __WFRRAvail, __WFRRTmpByte \
5541   arrsubset __WFRRTmpBuffer, __WFRRBuffer, 4, 2 \
5542   arrtostr __WFRRUnflattenBuf, __WFRRTmpBuffer \
5543   unflatten __WFRRTmpSWord, __WFRRUnflattenErr, __WFRRUnflattenBuf, __WFRRTmpSWord \
5544   mov _numbytes, __WFRRTmpSWord \
5545   arrsubset _data, __WFRRBuffer, 6, _numbytes \
5546   __RRIOMapRead_End##__I__: \
5547   __IncI__
5548 
5549 #define __remoteGetBluetoothAddress(_conn, _btaddr, _result) \
5550   __connectionSCDCWrite(_conn, __SCBTGetAddressPacket, _result) \
5551   call __DoWaitForRemoteResponse \
5552   mov _result, __WFRRStatus \
5553   brtst NEQ, __RRGetBluetoothAddress_End##__I__, _result \
5554   brcmp NEQ, __RRGetBluetoothAddress_End##__I__, __WFRRAvail, 8 \
5555   arrsubset _btaddr, __WFRRBuffer, NA, 7 \
5556   __RRGetBluetoothAddress_End##__I__: \
5557   __IncI__
5558 
5559 #define __remoteRenameFile(_conn, _oldname, _newname, _result) \
5560   acquire __RemoteMutex \
5561   mov __SRSSendBuf, __SCRenameFilePacket \
5562   strsubset __SRSTmpBuf, _oldname, NA, 19 \
5563   replace __SRSSendBuf, __SRSSendBuf, 2, __SRSTmpBuf \
5564   strsubset __SRSTmpBuf, _newname, NA, 19 \
5565   replace __SRSSendBuf, __SRSSendBuf, 22, __SRSTmpBuf \
5566   __connectionSCDCWrite(_conn, __SRSSendBuf, _result) \
5567   release __RemoteMutex
5568 
5569 #else
5570 
5571 #define __remoteGetOutputState(_conn, _port, _result) __remoteGenericByteCommand(_conn, __DCGetOutputStatePacket, _port, _result)
5572 #define __remoteGetInputValues(_conn, _port, _result) __remoteGenericByteCommand(_conn, __DCGetInputValuesPacket, _port, _result)
5573 #define __remoteGetBatteryLevel(_conn, _result) __connectionSCDCWrite(_conn, __DCGetBatteryLevelPacket, _result)
5574 #define __remoteLowspeedGetStatus(_conn, _result) __connectionSCDCWrite(_conn, __DCLSGetStatusPacket, _result)
5575 #define __remoteLowspeedRead(_conn, _port, _result) __remoteGenericByteCommand(_conn, __DCLSReadPacket, _port, _result)
5576 #define __remoteGetCurrentProgramName(_conn, _result) __connectionSCDCWrite(_conn, __DCGetCurProgNamePacket, _result)
5577 #define __remoteDatalogRead(_conn, _remove, _result) __remoteGenericByteCommand(_conn, __DCDatalogReadPacket, _remove, _result)
5578 #define __remoteGetContactCount(_conn, _result) __connectionSCDCWrite(_conn, __DCBTGetContactCntPacket, _result)
5579 #define __remoteGetContactName(_conn, _idx, _result) __remoteGenericByteCommand(_conn, __DCBTGetContactNamePacket, _idx, _result)
5580 #define __remoteGetConnectionCount(_conn, _result) __connectionSCDCWrite(_conn, __DCBTGetConnectCntPacket, _result)
5581 #define __remoteGetConnectionName(_conn, _idx, _result) __remoteGenericByteCommand(_conn, __DCBTGetConnectNamePacket, _idx, _result)
5582 #define __remoteGetProperty(_conn, _property, _result) __remoteGenericByteCommand(_conn, __DCGetPropertyPacket, _property, _result)
5583 
5584 
5585 #define __remoteOpenRead(_conn, _filename, _result) __remoteGenericFilenameCommand(_conn, __SCOpenReadPacket, _filename, _result)
5586 #define __remoteOpenWrite(_conn, _filename, _size, _result) __remoteGenericCreateFileCommand(_conn, __SCOpenWritePacket, _filename, _size, _result)
5587 #define __remoteRead(_conn, _handle, _numbytes, _result) __remoteDoRead(_conn, _handle, _numbytes, _result)
5588 #define __remoteWrite(_conn, _handle, _data, _result) __remoteDoWrite(_conn, _handle, _data, _result)
5589 #define __remoteCloseFile(_conn, _handle, _result) __remoteGenericByteCommand(_conn, __SCClosePacket, _handle, _result)
5590 #define __remoteDeleteFile(_conn, _filename, _result) __remoteGenericFilenameCommand(_conn, __SCDeletePacket, _filename, _result)
5591 #define __remoteFindFirstFile(_conn, _mask, _result) __remoteGenericFilenameCommand(_conn, __SCFindFirstPacket, _mask, _result)
5592 #define __remoteFindNextFile(_conn, _handle, _result) __remoteGenericByteCommand(_conn, __SCFindNextPacket, _handle, _result)
5593 #define __remoteOpenWriteLinear(_conn, _filename, _size, _result) __remoteGenericCreateFileCommand(_conn, __SCOpenWriteLinearPacket, _filename, _size, _result)
5594 #define __remoteOpenWriteData(_conn, _filename, _size, _result) __remoteGenericCreateFileCommand(_conn, __SCOpenWriteDataPacket, _filename, _size, _result)
5595 #define __remoteOpenAppendData(_conn, _filename, _result) __remoteGenericFilenameCommand(_conn, __SCOpenAppendDataPacket, _filename, _result)
5596 #define __remotePollCommandLength(_conn, _bufnum, _result) __remoteGenericByteCommand(_conn, __SCPollCommandLenPacket, _bufnum, _result)
5597 #define __remotePollCommand(_conn, _bufnum, _len, _result) __remoteDoPollCommand(_conn, _bufnum, _len, _result)
5598 #define __remoteIOMapRead(_conn, _id, _offset, _numbytes, _result) __remoteDoIOMapRead(_conn, _id, _offset, _numbytes, _result)
5599 
5600 #endif
5601 
5602 #define __remoteDatalogSetTimes(_conn, _synctime, _result) \
5603   acquire __RemoteMutex \
5604   mov __SRSTmpLongVal, _synctime \
5605   flatten __SRSFlattenBuf, __SRSTmpLongVal \
5606   strtoarr __SRSTmpBuf, __SRSFlattenBuf \
5607   arrbuild __SRSSendBuf, __DCDatalogSetTimesPacket, __SRSTmpBuf \
5608   __connectionSCDCWrite(_conn, __SRSSendBuf, _result) \
5609   release __RemoteMutex
5610 
5611 #define __remoteSetProperty(_conn, _prop, _value, _result) \
5612   compchk EQ, sizeof(_prop), 1 \
5613   acquire __RemoteMutex \
5614   flatten __SRSFlattenBuf, _value \
5615   strtoarr __SRSTmpBuf, __SRSFlattenBuf \
5616   arrbuild __SRSSendBuf, __DCSetPropertyPacket, _prop, __SRSTmpBuf \
5617   __connectionSCDCWrite(_conn, __SRSSendBuf, _result) \
5618   release __RemoteMutex
5619 
5620 #define __remoteLowspeedWrite(_conn, _port, _txlen, _rxlen, _data, _result) \
5621   compchk EQ, sizeof(_port), 1 \
5622   compchk EQ, sizeof(_txlen), 1 \
5623   compchk EQ, sizeof(_rxlen), 1 \
5624   acquire __RemoteMutex \
5625   arrbuild __SRSSendBuf, __DCLSWritePacket, _port, _txlen, _rxlen, _data \
5626   __connectionSCDCWrite(_conn, __SRSSendBuf, _result) \
5627   release __RemoteMutex
5628 
5629 #define __remoteIOMapWriteValue(_conn, _id, _offset, _value, _result) \
5630   compchk EQ, sizeof(_handle), 1 \
5631   acquire __RemoteMutex \
5632   mov __SRSSendBuf, __GenericIOMapPacket \
5633   replace __SRSSendBuf, __SRSSendBuf, NA, __SCIOMapWritePacket \
5634   mov __SRSTmpLongVal, _offset \
5635   flatten __SRSFlattenBuf, __SRSTmpLongVal \
5636   strtoarr __SRSTmpBuf, __SRSFlattenBuf \
5637   replace __SRSSendBuf, __SRSSendBuf, 2, __SRSTmpBuf \
5638   mov __SRSTmpWordVal, _offset \
5639   flatten __SRSFlattenBuf, __SRSTmpWordVal \
5640   strtoarr __SRSTmpBuf, __SRSFlattenBuf \
5641   replace __SRSSendBuf, __SRSSendBuf, 6, __SRSTmpBuf \
5642   set __SRSTmpWordVal, sizeof(_value) \
5643   flatten __SRSFlattenBuf, __SRSTmpWordVal \
5644   strtoarr __SRSTmpBuf, __SRSFlattenBuf \
5645   replace __SRSSendBuf, __SRSSendBuf, 8, __SRSTmpBuf \
5646   flatten __SRSFlattenBuf, _value \
5647   strtoarr __SRSTmpBuf, __SRSFlattenBuf \
5648   mov __SRSFlattenBuf, __SRSSendBuf \
5649   arrbuild __SRSSendBuf, __SRSFlattenBuf, __SRSTmpBuf \
5650   __connectionSCDCWrite(_conn, __SRSSendBuf, _result) \
5651   release __RemoteMutex
5652 
5653 #define __remoteIOMapWriteBytes(_conn, _id, _offset, _data, _result) \
5654   compchk EQ, sizeof(_handle), 1 \
5655   acquire __RemoteMutex \
5656   mov __SRSSendBuf, __GenericIOMapPacket \
5657   replace __SRSSendBuf, __SRSSendBuf, NA, __SCIOMapWritePacket \
5658   mov __SRSTmpLongVal, _offset \
5659   flatten __SRSFlattenBuf, __SRSTmpLongVal \
5660   strtoarr __SRSTmpBuf, __SRSFlattenBuf \
5661   replace __SRSSendBuf, __SRSSendBuf, 2, __SRSTmpBuf \
5662   mov __SRSTmpWordVal, _offset \
5663   flatten __SRSFlattenBuf, __SRSTmpWordVal \
5664   strtoarr __SRSTmpBuf, __SRSFlattenBuf \
5665   replace __SRSSendBuf, __SRSSendBuf, 6, __SRSTmpBuf \
5666   arrsize __SRSTmpWordVal, _data \
5667   flatten __SRSFlattenBuf, __SRSTmpWordVal \
5668   strtoarr __SRSTmpBuf, __SRSFlattenBuf \
5669   replace __SRSSendBuf, __SRSSendBuf, 8, __SRSTmpBuf \
5670   mov __SRSFlattenBuf, __SRSSendBuf \
5671   arrbuild __SRSSendBuf, __SRSFlattenBuf, _data \
5672   __connectionSCDCWrite(_conn, __SRSSendBuf, _result) \
5673   release __RemoteMutex
5674 
5675 #define __remoteSetBrickName(_conn, _name, _result) \
5676   acquire __RemoteMutex \
5677   mov __SRSSendBuf, __SCSetBrickNamePacket \
5678   strsubset __SRSTmpBuf, _name, NA, 15 \
5679   replace __SRSSendBuf, __SRSSendBuf, 2, __SRSTmpBuf \
5680   __connectionSCDCWrite(_conn, __SRSSendBuf, _result) \
5681   release __RemoteMutex
5682 
5683 #if defined(__ENHANCED_FIRMWARE)
5684 
5685 #define __SQRT(_X,_R) sqrt _R, _X
5686 #define __SIN(_X,_R) sin _R, _X
5687 #define __COS(_X,_R) cos _R, _X
5688 #define __ASIN(_X,_R) asin _R, _X
5689 #define __ACOS(_X,_R) acos _R, _X
5690 
5691 #else
5692 
5693 #if (__FIRMWARE_VERSION > 107)
5694 #define __SQRT(_X,_R) sqrt _R, _X
5695 #else
5696 #define __SQRT(_X,_R) \
5697   acquire __sqrtMutex \
5698   mov __sqrtValue, _X \
5699   call __sqrtSub \
5700   mov _R, __sqrtResult \
5701   release __sqrtMutex
5702 #endif
5703 
5704 #define __SIN(_X,_R) \
5705   acquire __sinMutex \
5706   mov __sinValue, _X \
5707   call __sinSub \
5708   mov _R, __sinResult \
5709   release __sinMutex
5710 
5711 #define __COS(_X,_R) \
5712   acquire __sinMutex \
5713   mov __sinValue, _X \
5714   add __sinValue, __sinValue, 90 \
5715   call __sinSub \
5716   mov _R, __sinResult \
5717   release __sinMutex
5718 
5719 #define __ASIN(_X,_R) \
5720   acquire __asinMutex \
5721   mov __asinValue, _X \
5722   call __asinSub \
5723   mov _R, __asinResult \
5724   release __asinMutex
5725 
5726 #define __ACOS(_X,_R) \
5727   acquire __asinMutex \
5728   mov __asinValue, _X \
5729   call __asinSub \
5730   sub _R, 90, __asinResult \
5731   release __asinMutex
5732 
5733 #endif
5734 
5735 // data segment
5736 dseg segment
5737 
5738   // sin/cos related tables
5739   __sin_table sword[] 0,2,3,5,7,9,10,12,14,16,17,19,21,22,24,26,28,29,31,33,34,36,37,39,41,42,44,45,47,48,50,52,53,54,56,57,59,60,62,63,64,66,67,68,69,71,72,73,74,75,77,78,79,80,81,82,83,84,85,86,87,87,88,89,90,91,91,92,93,93,94,95,95,96,96,97,97,97,98,98,98,99,99,99,99,100,100,100,100,100,100
5740   __asin_table sdword[] 0,1,1,2,2,3,3,4,5,5,6,6,7,7,8,9,9,10,10,11,12,12,13,13,14,14,15,16,16,17,17,18,19,19,20,20,21,22,22,23,24,24,25,25,26,27,27,28,29,29,30,31,31,32,33,33,34,35,35,36,37,38,38,39,40,41,41,42,43,44,44,45,46,47,48,49,49,50,51,52,53,54,55,56,57,58,59,60,62,63,64,66,67,68,70,72,74,76,79,82,90
5741 
5742   // mutexes
5743   __sqrtMutex mutex
5744   __sinMutex mutex
5745   __asinMutex mutex
5746 
5747   // sqrt variables
5748   __sqrtPairs byte[]  0, 0, 0, 0, 0, 0
5749   __sqrtPaircount sbyte
5750   __sqrtValue dword
5751   __sqrtResult dword
5752   __sqrtP dword
5753   __sqrtR dword
5754   __sqrtM dword
5755   __sqrtN dword
5756 
5757   // sin variables
5758   __sinValue sdword
5759   __sinResult sdword
5760   __sinValueNeg byte
5761 
5762   // asin variables
5763   __asinValue sdword
5764   __asinResult sdword
5765 dseg ends
5766 
5767 subroutine __sinSub
5768   // move the sin to + angle
5769   set __sinValueNeg, FALSE
5770   brtst GTEQ, __sinValuePos, __sinValue
5771 
5772   neg __sinValue, __sinValue
5773   set __sinValueNeg, TRUE
5774 
5775 __sinValuePos:
5776   // get the 360 mod and check which quarter the sin falls into
5777   mod __sinValue, __sinValue, 360
5778   brcmp GT, __sinQ4, __sinValue, 270
5779   brcmp GT, __sinQ3, __sinValue, 180
5780   brcmp GT, __sinQ2, __sinValue, 90
5781 
5782   // 1st quarter
5783   index __sinResult, __sin_table, __sinValue
5784   jmp __sinAlmostDone
5785 
5786 __sinQ2:
5787   // 2nd quarter
5788   sub __sinValue, 180, __sinValue
5789   index __sinResult, __sin_table, __sinValue
5790   jmp __sinAlmostDone
5791 
5792 __sinQ3:
5793   // 3rd quarter
5794   sub __sinValue, __sinValue, 180
5795   index __sinResult, __sin_table, __sinValue
5796   neg __sinResult, __sinResult
5797   jmp __sinAlmostDone
5798 
5799 __sinQ4:
5800   // 4th quarter
5801   sub __sinValue, 360, __sinValue
5802   index __sinResult, __sin_table, __sinValue
5803   neg __sinResult, __sinResult
5804   jmp __sinAlmostDone
5805 
5806 __sinAlmostDone:
5807 
5808   // if the incoming angle was <0, need to negate the result because sin(-x)=-sin(x)
5809   brcmp EQ, __sinDone, __sinValueNeg, FALSE
5810   neg __sinResult, __sinResult
5811 
5812 __sinDone:
5813   return
5814 ends
5815 
5816 
5817 subroutine __asinSub
5818   // input sin value should be -1 -> 1
5819   brcmp GT, __asinValueBad, __asinValue, 100
5820   brcmp LT, __asinValueBad, __asinValue, -100
5821 
5822   // check if it's 0->-1
5823   brtst LT, __asinValueNeg, __asinValue
5824 
5825   // value 0->1
5826   index __asinResult, __asin_table, __asinValue
5827   jmp __asinDone
5828 
5829 __asinValueNeg:
5830   // value 0->-1
5831   neg __asinValue, __asinValue
5832   index __asinResult, __asin_table, __asinValue
5833   neg __asinResult, __asinResult
5834   jmp __asinDone
5835 
5836 __asinValueBad:
5837   set __asinResult, 101
5838 
5839 __asinDone:
5840   return
5841 ends
5842 
5843 subroutine __sqrtSub
5844   // if the input value is 0, we're done
5845   set __sqrtResult, 0
5846   brtst EQ, __sqrtDone, __sqrtValue
5847 
5848   // init the paircount array
5849   mov __sqrtPaircount, 0
5850   replace __sqrtPairs, __sqrtPairs, 0, 0
5851   replace __sqrtPairs, __sqrtPairs, 1, 0
5852   replace __sqrtPairs, __sqrtPairs, 2, 0
5853   replace __sqrtPairs, __sqrtPairs, 3, 0
5854   replace __sqrtPairs, __sqrtPairs, 4, 0
5855 
5856 __sqrtPairsLoop:
5857   brtst EQ, __sqrtPairsOK, __sqrtValue
5858   mod __sqrtN, __sqrtValue, 100
5859   replace __sqrtPairs, __sqrtPairs, __sqrtPaircount, __sqrtN
5860   div __sqrtValue, __sqrtValue, 100
5861   add __sqrtPaircount, __sqrtPaircount, 1
5862 
5863   jmp __sqrtPairsLoop
5864 
5865 __sqrtPairsOK:
5866   // get the leftmost pair
5867   index __sqrtP, __sqrtPairs, __sqrtPaircount
5868   set __sqrtResult, 1
5869 
5870   // find the sqrt for the leftmost pair (1-9), if 0 we're not here!
5871 __sqrtFirstLoop:
5872   mul __sqrtN, __sqrtResult, __sqrtResult
5873   brcmp GT, __sqrtFirstOK, __sqrtN, __sqrtP
5874   add __sqrtResult, __sqrtResult, 1
5875   jmp __sqrtFirstLoop
5876 
5877 __sqrtFirstOK:
5878   sub __sqrtResult, __sqrtResult, 1
5879   // got the sqrt of the first pair in sqrtResult
5880 
5881   mul __sqrtN, __sqrtResult, __sqrtResult
5882   sub __sqrtM, __sqrtP, __sqrtN
5883 
5884   // in loop we get 1 new digit in sqrtResult for each pair
5885 __sqrtBigLoop:
5886   sub __sqrtPaircount, __sqrtPaircount, 1
5887 
5888   brtst LT, __sqrtDone, __sqrtPaircount
5889 
5890   mul __sqrtM, __sqrtM, 100
5891   index __sqrtP, __sqrtPairs, __sqrtPaircount
5892   add __sqrtM, __sqrtM, __sqrtP
5893 
5894   // find the next digit
5895   set __sqrtN, 1
5896 
5897 __sqrtDigitLoop:
5898   mul __sqrtR, __sqrtResult, 20
5899   add __sqrtR, __sqrtR, __sqrtN
5900   mul __sqrtR, __sqrtR, __sqrtN
5901 
5902   brcmp GT, __sqrtDigitDone, __sqrtR, __sqrtM
5903 
5904   add __sqrtN, __sqrtN, 1
5905   jmp __sqrtDigitLoop
5906 
5907 __sqrtDigitDone:
5908   sub __sqrtN, __sqrtN, 1
5909   // got the next digit
5910 
5911   // calculate the new value to continue with
5912   mul __sqrtR, __sqrtResult, 20
5913   add __sqrtR, __sqrtR, __sqrtN
5914   mul __sqrtR, __sqrtR, __sqrtN
5915   sub __sqrtM, __sqrtM, __sqrtR
5916 
5917   // add the new digit to the end of the result in sqrtResult
5918   mul __sqrtResult, __sqrtResult, 10
5919   add __sqrtResult, __sqrtResult, __sqrtN
5920 
5921   jmp __sqrtBigLoop
5922 
5923 __sqrtDone:
5924   return
5925 ends
5926 
5927 dseg segment
5928   __bcd2DecTens byte
5929   __bcd2DecOnes byte
5930   __bcd2DecMutex mutex
5931 dseg ends
5932 
5933 #define __bcd2dec(_bcd, _result) \
5934   acquire __bcd2DecMutex \
5935   div __bcd2DecTens, _bcd, 16 \
5936   mod __bcd2DecOnes, _bcd, 16 \
5937   mul _result, __bcd2DecTens, 10 \
5938   add _result, _result, __bcd2DecOnes \
5939   release __bcd2DecMutex
5940 
5941 #define __SetSensorHTEOPD(_port, _bStd) \
5942   setin IN_TYPE_LIGHT_ACTIVE+_bStd, _port, TypeField \
5943   setin IN_MODE_RAW, _port, InputModeField \
5944   __ResetSensor(_port)
5945 
5946 #define __ReadSensorHTEOPD(_port, _val) \
5947   getin _val, _port, RawValueField \
5948   sub _val, 1023, _val
5949 
5950 #define __SetSensorHTGyro(_port) \
5951   setin IN_TYPE_LIGHT_INACTIVE, _port, TypeField \
5952   setin IN_MODE_RAW, _port, InputModeField \
5953   __ResetSensor(_port)
5954 
5955 #define __ReadSensorHTGyro(_port, _offset, _val) \
5956   getin _val, _port, RawValueField \
5957   sub _val, _val, 600 \
5958   sub _val, _val, _offset
5959 
5960 #define __ReadSensorHTMagnet(_port, _offset, _val) __ReadSensorHTGyro(_port, _offset, _val)
5961 #define __SetSensorHTMagnet(_port) __SetSensorHTGyro(_port)
5962 
5963 dseg segment
5964   __HTMplexRaw word
5965   __HTMplexScaled dword
5966   __HTMplexMutex mutex
5967 dseg ends
5968 
5969 #define __ReadSensorHTTouchMultiplexer(_p, _t1, _t2, _t3, _t4) \
5970   acquire __HTMplexMutex \
5971   getin __HTMplexRaw, _p, RawValueField \
5972   mul __HTMplexScaled, __HTMplexRaw, 339 \
5973   sub __HTMplexScaled, 346797, __HTMplexScaled \
5974   div __HTMplexScaled, __HTMplexScaled, __HTMplexRaw \
5975   add __HTMplexScaled, __HTMplexScaled, 5 \
5976   div __HTMplexScaled, __HTMplexScaled, 10 \
5977   and _t4, __HTMplexScaled, 8 \
5978   and _t3, __HTMplexScaled, 4 \
5979   and _t2, __HTMplexScaled, 2 \
5980   and _t1, __HTMplexScaled, 1 \
5981   release __HTMplexMutex
5982 
5983 dseg segment
5984   __HTPFStartIRLink  byte[] 0x02, 0x42
5985   __HTPFCommitIRLink byte[] 0x0B, 0x02, 0x01
5986   __HTPFBits byte[]
5987   __HTPFI2CBuf byte[]
5988   __HTPFI sword
5989   __HTPFJ sword
5990   __HTPFValue byte
5991   __HTPFDx byte
5992   __PFBytes byte[]
5993   __PFMutex mutex
5994   __PFNx byte
5995   __PFPowerFuncMode byte
5996   __PFTmp byte
5997   __PFNibbles byte[] 0x00, 0x00, 0x00, 0x00
5998   __PF_p1 byte
5999   __PF_p2 byte
6000   __PF_p3 byte
6001   __PF_p4 byte
6002   __PF_p5 byte
6003   __PFIdx byte
6004   __PFChToggle byte
6005   __PFToggles byte[] 0x00, 0x00, 0x00, 0x00
6006   __RCToggles byte[] 0x00, 0x00, 0x00, 0x00
6007 dseg ends
6008 
6009 subroutine __PFApplyToggle
6010   mov __PFIdx, __PF_p1
6011   index __PFChToggle, __PFToggles, __PFIdx
6012   add __PF_p1, __PF_p1, __PFChToggle
6013   return
6014 ends
6015 
6016 subroutine __PFUpdateToggle
6017   xor __PFChToggle, __PFChToggle, 8
6018   replace __PFToggles, __PFToggles, __PFIdx, __PFChToggle
6019   return
6020 ends
6021 
6022 subroutine __RCApplyToggle
6023   mov __PFIdx, __PF_p1
6024   index __PFChToggle, __RCToggles, __PFIdx
6025   add __PF_p1, __PF_p1, __PFChToggle
6026   return
6027 ends
6028 
6029 subroutine __RCUpdateToggle
6030   xor __PFChToggle, __PFChToggle, 8
6031   replace __RCToggles, __RCToggles, __PFIdx, __PFChToggle
6032   return
6033 ends
6034 
6035 subroutine __PFCalcChecksum
6036   // RCTrain or Power Function
6037   brtst EQ, __PFUseIRTrainMode, __PFPowerFuncMode
6038   index __PFNx, __PFNibbles, NA
6039   xor __PFTmp, 0xF, __PFNx
6040   index __PFNx, __PFNibbles, 1
6041   xor __PFTmp, __PFTmp, __PFNx
6042   index __PFNx, __PFNibbles, 2
6043   xor __PFTmp, __PFTmp, __PFNx
6044   jmp __PFEndPowerFuncModeCheck
6045 __PFUseIRTrainMode:
6046   index __PFNx, __PFNibbles, NA
6047   sub __PFTmp, 0xF, __PFNx
6048   index __PFNx, __PFNibbles, 1
6049   sub __PFTmp, __PFTmp, __PFNx
6050   index __PFNx, __PFNibbles, 2
6051   sub __PFTmp, __PFTmp, __PFNx
6052 __PFEndPowerFuncModeCheck:
6053   replace __PFNibbles, __PFNibbles, 3, __PFTmp
6054   return
6055 ends
6056 
6057 subroutine __PFComboDirectSub
6058   call __PFApplyToggle
6059   replace __PFNibbles, __PFNibbles, NA, __PF_p1
6060   replace __PFNibbles, __PFNibbles, 1, PF_MODE_COMBO_DIRECT
6061   mul __PF_p3, __PF_p3, 4
6062   add __PF_p3, __PF_p3, __PF_p2
6063   replace __PFNibbles, __PFNibbles, 2, __PF_p3
6064   call __PFUpdateToggle
6065   return
6066 ends
6067 
6068 subroutine __PFSinglePinSub
6069   call __PFApplyToggle
6070   replace __PFNibbles, __PFNibbles, NA, __PF_p1
6071   set __PF_p1, PF_MODE_SINGLE_PIN_TIME
6072   brtst EQ, __PFEndIfSPContinuous, __PF_p5
6073   set __PF_p1, PF_MODE_SINGLE_PIN_CONT
6074 __PFEndIfSPContinuous:
6075   replace __PFNibbles, __PFNibbles, 1, __PF_p1
6076   mul __PF_p2, __PF_p2, 8
6077   mul __PF_p3, __PF_p3, 4
6078   add __PF_p2, __PF_p2, __PF_p3
6079   add __PF_p2, __PF_p2, __PF_p4
6080   replace __PFNibbles, __PFNibbles, 2, __PF_p2
6081   call __PFUpdateToggle
6082   return
6083 ends
6084 
6085 subroutine __PFSingleOutputSub
6086   call __PFApplyToggle
6087   replace __PFNibbles, __PFNibbles, NA, __PF_p1
6088   set __PF_p1, PF_MODE_SINGLE_OUTPUT_PWM
6089   brtst EQ, __PFEndIfSOCst, __PF_p4
6090   set __PF_p1, PF_MODE_SINGLE_OUTPUT_CST
6091 __PFEndIfSOCst:
6092   add __PF_p1, __PF_p1, __PF_p2
6093   replace __PFNibbles, __PFNibbles, 1, __PF_p1
6094   replace __PFNibbles, __PFNibbles, 2, __PF_p3
6095   call __PFUpdateToggle
6096   return
6097 ends
6098 
6099 subroutine __PFComboPWMSub
6100   call __PFApplyToggle
6101   add __PF_p1, __PF_p1, PF_MODE_COMBO_PWM
6102   replace __PFNibbles, __PFNibbles, NA, __PF_p1
6103   replace __PFNibbles, __PFNibbles, 1, __PF_p3
6104   replace __PFNibbles, __PFNibbles, 2, __PF_p2
6105   call __PFUpdateToggle
6106   return
6107 ends
6108 
6109 subroutine __PFTrainSub
6110   call __PFApplyToggle
6111   replace __PFNibbles, __PFNibbles, NA, __PF_p1
6112   replace __PFNibbles, __PFNibbles, 1, PF_MODE_TRAIN
6113   replace __PFNibbles, __PFNibbles, 2, __PF_p2
6114   call __PFUpdateToggle
6115   return
6116 ends
6117 
6118 subroutine __RCTrainSub
6119   call __RCApplyToggle
6120   replace __PFNibbles, __PFNibbles, NA, __PF_p1
6121   replace __PFNibbles, __PFNibbles, 1, PF_MODE_TRAIN
6122   replace __PFNibbles, __PFNibbles, 2, __PF_p2
6123   call __RCUpdateToggle
6124   return
6125 ends
6126 
6127 subroutine __PFRawOutputSub
6128   call __PFApplyToggle
6129   replace __PFNibbles, __PFNibbles, NA, __PF_p1
6130   replace __PFNibbles, __PFNibbles, 1, __PF_p2
6131   replace __PFNibbles, __PFNibbles, 2, __PF_p3
6132   call __PFUpdateToggle
6133   return
6134 ends
6135 
6136 subroutine __HTPowerFunctionCalcBits
6137   call __PFCalcChecksum
6138   brtst EQ, __HTPFUseIRTrainMode, __PFPowerFuncMode
6139   set __HTPFDx, 3
6140   jmp __HTPFEndPowerFuncModeCheck
6141 __HTPFUseIRTrainMode:
6142   set __HTPFDx, 2
6143 __HTPFEndPowerFuncModeCheck:
6144   arrinit __HTPFBits, 0, 88
6145   arrinit __PFBytes, 0, 11
6146   // fill in the bits
6147   set __PFIdx, 0
6148   replace __HTPFBits, __HTPFBits, __PFIdx, 1
6149   add __PFIdx, __PFIdx, 8
6150   // check bits in n0..n3
6151   set __HTPFI, 0
6152 __lblCalcBitsForIBitSet:
6153   index __PFNx, __PFNibbles, __HTPFI
6154   set __HTPFJ, 3
6155 __lblCalcBitsForJBitSet:
6156   replace __HTPFBits, __HTPFBits, __PFIdx, 1
6157   shl __PFTmp, 1, __HTPFJ
6158   and __HTPFValue, __PFNx, __PFTmp
6159   add __PFIdx, __PFIdx, __HTPFDx
6160   brcmp NEQ, __lblCalcBitsFoundZero, __HTPFValue, __PFTmp
6161   add __PFIdx, __PFIdx, 2
6162 __lblCalcBitsFoundZero:
6163   sub __HTPFJ, __HTPFJ, 1
6164   brtst GTEQ, __lblCalcBitsForJBitSet, __HTPFJ
6165   add __HTPFI, __HTPFI, 1
6166   brcmp LTEQ, __lblCalcBitsForIBitSet, __HTPFI, 3
6167   replace __HTPFBits, __HTPFBits, __PFIdx, 1
6168   // now calculate bytes
6169   set __HTPFI, 0
6170 __lblCalcBitsWhileIByteCalc:
6171   set __HTPFValue, 0
6172   set __HTPFJ, 0
6173 __lblCalcBitsForJByteCalc:
6174   index __PFTmp, __HTPFBits, __HTPFI
6175   add __HTPFValue, __HTPFValue, __PFTmp
6176   brcmp GTEQ, __lblCalcBitsByteCalcLastBit, __HTPFJ, 7
6177   mul __HTPFValue, __HTPFValue, 2
6178 __lblCalcBitsByteCalcLastBit:
6179   add __HTPFI, __HTPFI, 1
6180   add __HTPFJ, __HTPFJ, 1
6181   brcmp LTEQ, __lblCalcBitsForJByteCalc, __HTPFJ, 7
6182   div __PFIdx, __HTPFI, 8
6183   sub __PFIdx, __PFIdx, 1
6184   replace __PFBytes, __PFBytes, __PFIdx, __HTPFValue
6185   brcmp LT, __lblCalcBitsWhileIByteCalc, __HTPFI, 88
6186   // set IRLink mode to either PF or IRTrain
6187   sub __HTPFDx, __HTPFDx, 1
6188   replace __HTPFCommitIRLink, __HTPFCommitIRLink, 1, __HTPFDx
6189   // build i2c buffer
6190   arrbuild __HTPFI2CBuf, __HTPFStartIRLink, __PFBytes, __HTPFCommitIRLink
6191   return
6192 ends
6193 
6194 #define __HTPFComboDirect(_port, _channel, _outa, _outb, _result) \
6195   acquire __PFMutex \
6196   mod __PF_p1, _channel, 4 \
6197   mod __PF_p2, _outa, 4 \
6198   mod __PF_p3, _outb, 4 \
6199   call __PFComboDirectSub \
6200   set __PFPowerFuncMode, TRUE \
6201   call __HTPowerFunctionCalcBits \
6202   compif EQ, isconst(_port), FALSE \
6203   acquire __CLSWMutex0 \
6204   acquire __CLSWMutex1 \
6205   acquire __CLSWMutex2 \
6206   acquire __CLSWMutex3 \
6207   mov __CLSWArgs0.Buffer, __HTPFI2CBuf \
6208   release __PFMutex \
6209   mov __CLSWArgs0.Port, _port \
6210   mov __CLSWArgs0.ReturnLen, 0 \
6211   syscall CommLSWrite, __CLSWArgs0 \
6212   mov _result, __CLSWArgs0.Result \
6213   release __CLSWMutex0 \
6214   release __CLSWMutex1 \
6215   release __CLSWMutex2 \
6216   release __CLSWMutex3 \
6217   compelse \
6218   compchk LT, _port, 0x04 \
6219   compchk GTEQ, _port, 0x00 \
6220   acquire __CLSWMutex##_port \
6221   mov __CLSWArgs##_port.Buffer, __HTPFI2CBuf \
6222   release __PFMutex \
6223   set __CLSWArgs##_port.Port, _port \
6224   mov __CLSWArgs##_port.ReturnLen, 0 \
6225   syscall CommLSWrite, __CLSWArgs##_port \
6226   mov _result, __CLSWArgs##_port.Result \
6227   release __CLSWMutex##_port \
6228   compend
6229 
6230 #define __HTPFSinglePin(_port, _channel, _out, _pin, _func, _cont, _result) \
6231   acquire __PFMutex \
6232   mod __PF_p1, _channel, 4 \
6233   mod __PF_p2, _out, 2 \
6234   mod __PF_p3, _pin, 2 \
6235   mod __PF_p4, _func, 4 \
6236   set __PF_p5, _cont \
6237   call __PFSinglePinSub \
6238   set __PFPowerFuncMode, TRUE \
6239   call __HTPowerFunctionCalcBits \
6240   compif EQ, isconst(_port), FALSE \
6241   acquire __CLSWMutex0 \
6242   acquire __CLSWMutex1 \
6243   acquire __CLSWMutex2 \
6244   acquire __CLSWMutex3 \
6245   mov __CLSWArgs0.Buffer, __HTPFI2CBuf \
6246   release __PFMutex \
6247   mov __CLSWArgs0.Port, _port \
6248   mov __CLSWArgs0.ReturnLen, 0 \
6249   syscall CommLSWrite, __CLSWArgs0 \
6250   mov _result, __CLSWArgs0.Result \
6251   release __CLSWMutex0 \
6252   release __CLSWMutex1 \
6253   release __CLSWMutex2 \
6254   release __CLSWMutex3 \
6255   compelse \
6256   compchk LT, _port, 0x04 \
6257   compchk GTEQ, _port, 0x00 \
6258   acquire __CLSWMutex##_port \
6259   mov __CLSWArgs##_port.Buffer, __HTPFI2CBuf \
6260   release __PFMutex \
6261   set __CLSWArgs##_port.Port, _port \
6262   mov __CLSWArgs##_port.ReturnLen, 0 \
6263   syscall CommLSWrite, __CLSWArgs##_port \
6264   mov _result, __CLSWArgs##_port.Result \
6265   release __CLSWMutex##_port \
6266   compend
6267 
6268 #define __HTPFSingleOutput(_port, _channel, _out, _func, _cst, _result) \
6269   acquire __PFMutex \
6270   mod __PF_p1, _channel, 4 \
6271   mod __PF_p2, _out, 2 \
6272   mod __PF_p3, _func, 16 \
6273   set __PF_p4, _cst \
6274   call __PFSingleOutputSub \
6275   set __PFPowerFuncMode, TRUE \
6276   call __HTPowerFunctionCalcBits \
6277   compif EQ, isconst(_port), FALSE \
6278   acquire __CLSWMutex0 \
6279   acquire __CLSWMutex1 \
6280   acquire __CLSWMutex2 \
6281   acquire __CLSWMutex3 \
6282   mov __CLSWArgs0.Buffer, __HTPFI2CBuf \
6283   release __PFMutex \
6284   mov __CLSWArgs0.Port, _port \
6285   mov __CLSWArgs0.ReturnLen, 0 \
6286   syscall CommLSWrite, __CLSWArgs0 \
6287   mov _result, __CLSWArgs0.Result \
6288   release __CLSWMutex0 \
6289   release __CLSWMutex1 \
6290   release __CLSWMutex2 \
6291   release __CLSWMutex3 \
6292   compelse \
6293   compchk LT, _port, 0x04 \
6294   compchk GTEQ, _port, 0x00 \
6295   acquire __CLSWMutex##_port \
6296   mov __CLSWArgs##_port.Buffer, __HTPFI2CBuf \
6297   release __PFMutex \
6298   set __CLSWArgs##_port.Port, _port \
6299   mov __CLSWArgs##_port.ReturnLen, 0 \
6300   syscall CommLSWrite, __CLSWArgs##_port \
6301   mov _result, __CLSWArgs##_port.Result \
6302   release __CLSWMutex##_port \
6303   compend
6304 
6305 #define __HTPFComboPWM(_port, _channel, _outa, _outb, _result) \
6306   acquire __PFMutex \
6307   mod __PF_p1, _channel, 4 \
6308   mod __PF_p2, _outa, 16 \
6309   mod __PF_p3, _outb, 16 \
6310   call __PFComboPWMSub \
6311   set __PFPowerFuncMode, TRUE \
6312   call __HTPowerFunctionCalcBits \
6313   compif EQ, isconst(_port), FALSE \
6314   acquire __CLSWMutex0 \
6315   acquire __CLSWMutex1 \
6316   acquire __CLSWMutex2 \
6317   acquire __CLSWMutex3 \
6318   mov __CLSWArgs0.Buffer, __HTPFI2CBuf \
6319   release __PFMutex \
6320   mov __CLSWArgs0.Port, _port \
6321   mov __CLSWArgs0.ReturnLen, 0 \
6322   syscall CommLSWrite, __CLSWArgs0 \
6323   mov _result, __CLSWArgs0.Result \
6324   release __CLSWMutex0 \
6325   release __CLSWMutex1 \
6326   release __CLSWMutex2 \
6327   release __CLSWMutex3 \
6328   compelse \
6329   compchk LT, _port, 0x04 \
6330   compchk GTEQ, _port, 0x00 \
6331   acquire __CLSWMutex##_port \
6332   mov __CLSWArgs##_port.Buffer, __HTPFI2CBuf \
6333   release __PFMutex \
6334   set __CLSWArgs##_port.Port, _port \
6335   mov __CLSWArgs##_port.ReturnLen, 0 \
6336   syscall CommLSWrite, __CLSWArgs##_port \
6337   mov _result, __CLSWArgs##_port.Result \
6338   release __CLSWMutex##_port \
6339   compend
6340 
6341 #define __HTIRTrain(_port, _channel, _func, _PFMode, _result) \
6342   acquire __PFMutex \
6343   mod __PF_p1, _channel, 4 \
6344   mod __PF_p2, _func, 5 \
6345   compif EQ, _PFMode, TRUE \
6346   call __PFTrainSub \
6347   compelse \
6348   call __RCTrainSub \
6349   compend \
6350   set __PFPowerFuncMode, _PFMode \
6351   call __HTPowerFunctionCalcBits \
6352   compif EQ, isconst(_port), FALSE \
6353   acquire __CLSWMutex0 \
6354   acquire __CLSWMutex1 \
6355   acquire __CLSWMutex2 \
6356   acquire __CLSWMutex3 \
6357   mov __CLSWArgs0.Buffer, __HTPFI2CBuf \
6358   release __PFMutex \
6359   mov __CLSWArgs0.Port, _port \
6360   mov __CLSWArgs0.ReturnLen, 0 \
6361   syscall CommLSWrite, __CLSWArgs0 \
6362   mov _result, __CLSWArgs0.Result \
6363   release __CLSWMutex0 \
6364   release __CLSWMutex1 \
6365   release __CLSWMutex2 \
6366   release __CLSWMutex3 \
6367   compelse \
6368   compchk LT, _port, 0x04 \
6369   compchk GTEQ, _port, 0x00 \
6370   acquire __CLSWMutex##_port \
6371   mov __CLSWArgs##_port.Buffer, __HTPFI2CBuf \
6372   release __PFMutex \
6373   set __CLSWArgs##_port.Port, _port \
6374   mov __CLSWArgs##_port.ReturnLen, 0 \
6375   syscall CommLSWrite, __CLSWArgs##_port \
6376   mov _result, __CLSWArgs##_port.Result \
6377   release __CLSWMutex##_port \
6378   compend
6379 
6380 #define __HTPFRawOutput(_port, _nibble0, _nibble1, _nibble2, _result) \
6381   acquire __PFMutex \
6382   mod __PF_p1, _nibble0, 7 \
6383   mod __PF_p2, _nibble1, 16 \
6384   mod __PF_p3, _nibble2, 16 \
6385   call __PFRawOutputSub \
6386   set __PFPowerFuncMode, TRUE \
6387   call __HTPowerFunctionCalcBits \
6388   compif EQ, isconst(_port), FALSE \
6389   acquire __CLSWMutex0 \
6390   acquire __CLSWMutex1 \
6391   acquire __CLSWMutex2 \
6392   acquire __CLSWMutex3 \
6393   mov __CLSWArgs0.Buffer, __HTPFI2CBuf \
6394   release __PFMutex \
6395   mov __CLSWArgs0.Port, _port \
6396   mov __CLSWArgs0.ReturnLen, 0 \
6397   syscall CommLSWrite, __CLSWArgs0 \
6398   mov _result, __CLSWArgs0.Result \
6399   release __CLSWMutex0 \
6400   release __CLSWMutex1 \
6401   release __CLSWMutex2 \
6402   release __CLSWMutex3 \
6403   compelse \
6404   compchk LT, _port, 0x04 \
6405   compchk GTEQ, _port, 0x00 \
6406   acquire __CLSWMutex##_port \
6407   mov __CLSWArgs##_port.Buffer, __HTPFI2CBuf \
6408   release __PFMutex \
6409   set __CLSWArgs##_port.Port, _port \
6410   mov __CLSWArgs##_port.ReturnLen, 0 \
6411   syscall CommLSWrite, __CLSWArgs##_port \
6412   mov _result, __CLSWArgs##_port.Result \
6413   release __CLSWMutex##_port \
6414   compend
6415 
6416 #define __HTPFRepeatLastCommand(_port, _count, _delay, _result) \
6417   acquire __PFMutex \
6418   mov __PF_p1, _count \
6419   compif EQ, isconst(_port), FALSE \
6420   acquire __CLSWMutex0 \
6421   acquire __CLSWMutex1 \
6422   acquire __CLSWMutex2 \
6423   acquire __CLSWMutex3 \
6424   mov __CLSWArgs0.Buffer, __HTPFI2CBuf \
6425   release __PFMutex \
6426   mov __CLSWArgs0.Port, _port \
6427   mov __CLSWArgs0.ReturnLen, 0 \
6428   __HTPFRepeatLoop##__I__: \
6429   syscall CommLSWrite, __CLSWArgs0 \
6430   waitv _delay \
6431   sub __PF_p1, __PF_p1, 1 \
6432   brtst GT, __HTPFRepeatLoop##__I__, __PF_p1 \
6433   mov _result, __CLSWArgs0.Result \
6434   release __CLSWMutex0 \
6435   release __CLSWMutex1 \
6436   release __CLSWMutex2 \
6437   release __CLSWMutex3 \
6438   __IncI__ \
6439   compelse \
6440   compchk LT, _port, 0x04 \
6441   compchk GTEQ, _port, 0x00 \
6442   acquire __CLSWMutex##_port \
6443   mov __CLSWArgs##_port.Buffer, __HTPFI2CBuf \
6444   release __PFMutex \
6445   set __CLSWArgs##_port.Port, _port \
6446   mov __CLSWArgs##_port.ReturnLen, 0 \
6447   __HTPFRepeatLoop##__I__: \
6448   syscall CommLSWrite, __CLSWArgs##_port \
6449   waitv _delay \
6450   sub __PF_p1, __PF_p1, 1 \
6451   brtst GT, __HTPFRepeatLoop##__I__, __PF_p1 \
6452   mov _result, __CLSWArgs##_port.Result \
6453   release __CLSWMutex##_port \
6454   __IncI__ \
6455   compend
6456 
6457 dseg segment
6458 
6459 TRCXCommand struct
6460  Port byte
6461  Address byte
6462  ResponseBytes byte
6463  Command byte[]
6464  Response byte[]
6465 TRCXCommand ends
6466 
6467   __gRCXCmd TRCXCommand
6468   __RCXCmdMutex mutex
6469 
6470 dseg ends
6471 
6472 subroutine __HTRCXCommandSub
6473   dseg segment
6474     __RCSToggle byte
6475     __RCSI byte
6476     __RCSInCmd byte[]
6477     __RCSCmdBytes sbyte
6478     __RCSCmd byte
6479     __RCSCSum byte
6480     __RCSMsgBufSize byte
6481     __RCSTotalBytes byte
6482     __RCSTmpByte byte
6483     __RCSTmpByte2 byte
6484     __RCSResult byte
6485     __RCSHeaderMsg byte[] 0x02, 0x4a, 0x55, 0xff, 0x00, 0x03, 0x00, 0x01
6486   dseg ends
6487   arrsize __RCSCmdBytes, __gRCXCmd.Command
6488   index __RCSCmd, __gRCXCmd.Command, NA
6489   set __RCSCSum, 0
6490 
6491   replace __RCSHeaderMsg, __RCSHeaderMsg, NA, __gRCXCmd.Address
6492   // send the IR message
6493   __lowspeedWrite(__gRCXCmd.Port, 0, __RCSHeaderMsg, __RCSTmpByte)
6494   wait 12
6495 
6496   // build rest of the message
6497   set __RCSMsgBufSize, 2
6498   mul __RCSMsgBufSize, __RCSMsgBufSize, __RCSCmdBytes
6499   add __RCSMsgBufSize, __RCSMsgBufSize, 7
6500   add __RCSTotalBytes, __RCSMsgBufSize, __gRCXCmd.ResponseBytes
6501 
6502   arrinit __RCSInCmd, 0, __RCSMsgBufSize
6503   replace __RCSInCmd, __RCSInCmd, NA, __gRCXCmd.Address
6504   set __RCSTmpByte, 2
6505   mul __RCSTmpByte, __RCSTmpByte, __RCSCmdBytes
6506   sub __RCSTmpByte, 0x4b, __RCSTmpByte
6507   replace __RCSInCmd, __RCSInCmd, 1, __RCSTmpByte
6508 
6509   // put cmd and ~cmd into msg
6510   or __RCSTmpByte, __RCSCmd, __RCSToggle
6511   replace __RCSInCmd, __RCSInCmd, 2, __RCSTmpByte
6512   mov __RCSCSum, __RCSTmpByte
6513   sub __RCSTmpByte, 0xFF, __RCSTmpByte
6514   replace __RCSInCmd, __RCSInCmd, 3, __RCSTmpByte
6515 
6516   set __RCSI, 0
6517   xor __RCSToggle, __RCSToggle, 8
6518 
6519   brcmp LTEQ, __RCSEndWhileILTCmdBytes, __RCSCmdBytes, 1
6520 
6521 __RCSWhileILTCmdBytes:
6522   sub __RCSTmpByte, __RCSCmdBytes, 1
6523   brcmp GTEQ, __RCSEndWhileILTCmdBytes, __RCSI, __RCSTmpByte
6524   add __RCSTmpByte, __RCSI, 1
6525   index __RCSTmpByte2, __gRCXCmd.Command, __RCSTmpByte
6526   mul __RCSTmpByte, __RCSI, 2
6527   add __RCSTmpByte, __RCSTmpByte, 4
6528   replace __RCSInCmd, __RCSInCmd, __RCSTmpByte, __RCSTmpByte2
6529   add __RCSCSum, __RCSCSum, __RCSTmpByte2
6530   add __RCSTmpByte, __RCSTmpByte, 1
6531   sub __RCSTmpByte2, 0xFF, __RCSTmpByte2
6532   replace __RCSInCmd, __RCSInCmd, __RCSTmpByte, __RCSTmpByte2
6533   add __RCSI, __RCSI, 1
6534   jmp __RCSWhileILTCmdBytes
6535 __RCSEndWhileILTCmdBytes:
6536 
6537   mul __RCSTmpByte, __RCSI, 2
6538   add __RCSTmpByte, __RCSTmpByte, 4
6539   replace __RCSInCmd, __RCSInCmd, __RCSTmpByte, __RCSCSum
6540   sub __RCSTmpByte2, 0xFF, __RCSCSum
6541   add __RCSTmpByte, __RCSTmpByte, 1
6542   replace __RCSInCmd, __RCSInCmd, __RCSTmpByte, __RCSTmpByte2
6543   // fill in the last three bytes
6544   add __RCSTmpByte, __RCSTmpByte, 1
6545   mul __RCSTmpByte2, __RCSCmdBytes, 2
6546   add __RCSTmpByte2, __RCSTmpByte2, 2
6547   replace __RCSInCmd, __RCSInCmd, __RCSTmpByte, __RCSTmpByte2
6548   add __RCSTmpByte, __RCSTmpByte, 1
6549   replace __RCSInCmd, __RCSInCmd, __RCSTmpByte, 0x00
6550   add __RCSTmpByte, __RCSTmpByte, 1
6551   replace __RCSInCmd, __RCSInCmd, __RCSTmpByte, 0x01
6552 
6553   // send the IR message
6554   __lowspeedWrite(__gRCXCmd.Port, 0, __RCSInCmd, __RCSTmpByte)
6555 
6556   // give the message time to be transferred
6557   mul __RCSTmpByte, __RCSTotalBytes, 5
6558   add __RCSTmpByte, __RCSTmpByte, 10
6559   waitv __RCSTmpByte
6560 
6561   // do we need to read a response?
6562   brtst EQ, __RCSNoResponse, __gRCXCmd.ResponseBytes
6563 
6564   arrbuild __RCSInCmd, __gRCXCmd.Address, 0x51
6565   mov __RCSTmpByte, __gRCXCmd.ResponseBytes
6566   __ReadI2CBytes(__gRCXCmd.Port, __RCSInCmd, __RCSTmpByte, __gRCXCmd.Response, __RCSResult)
6567 __RCSNoResponse:
6568   return
6569 ends
6570 
6571 #define __HTRCXSetIRLinkPort(_port) \
6572   set __gRCXCmd.Port, _port \
6573   set __gRCXCmd.Address, 0x02
6574 
6575 #define __HTRCXPoll(_src, _value, _result) \
6576   acquire __RCXCmdMutex \
6577   arrbuild __gRCXCmd.Command, RCX_PollOp, _src, _value \
6578   set __gRCXCmd.ResponseBytes, 12 \
6579   call __HTRCXCommandSub \
6580   index _result, __gRCXCmd.Response, 7 \
6581   index __RCSTmpByte, __gRCXCmd.Response, 5 \
6582   mul _result, _result, 256 \
6583   add _result, _result, __RCSTmpByte \
6584   release __RCXCmdMutex
6585 
6586 #define __HTRCXBatteryLevel(_result) \
6587   acquire __RCXCmdMutex \
6588   arrbuild __gRCXCmd.Command, RCX_BatteryLevelOp \
6589   set __gRCXCmd.ResponseBytes, 12 \
6590   call __HTRCXCommandSub \
6591   index _result, __gRCXCmd.Response, 7 \
6592   index __RCSTmpByte, __gRCXCmd.Response, 5 \
6593   mul _result, _result, 256 \
6594   add _result, _result, __RCSTmpByte \
6595   release __RCXCmdMutex
6596 
6597 #define __HTRCXOpNoArgs(_op) \
6598   acquire __RCXCmdMutex \
6599   arrinit __gRCXCmd.Command, _op, 1 \
6600   set __gRCXCmd.ResponseBytes, 0 \
6601   call __HTRCXCommandSub \
6602   release __RCXCmdMutex
6603 
6604 #define __HTRCXSetOutput(_outputs, _mode) \
6605   acquire __RCXCmdMutex \
6606   add __RCSTmpByte, _outputs, _mode \
6607   arrbuild __gRCXCmd.Command, RCX_OnOffFloatOp, __RCSTmpByte \
6608   set __gRCXCmd.ResponseBytes, 0 \
6609   call __HTRCXCommandSub \
6610   release __RCXCmdMutex
6611 
6612 #define __HTRCXSetDirection(_outputs, _dir) \
6613   acquire __RCXCmdMutex \
6614   add __RCSTmpByte, _outputs, _dir \
6615   arrbuild __gRCXCmd.Command, RCX_OutputDirOp, __RCSTmpByte \
6616   set __gRCXCmd.ResponseBytes, 0 \
6617   call __HTRCXCommandSub \
6618   release __RCXCmdMutex
6619 
6620 #define __HTRCXSetPower(_outputs, _pwrsrc, _pwrval) \
6621   acquire __RCXCmdMutex \
6622   arrbuild __gRCXCmd.Command, RCX_OutputPowerOp, _outputs, _pwrsrc, _pwrval \
6623   set __gRCXCmd.ResponseBytes, 0 \
6624   call __HTRCXCommandSub \
6625   release __RCXCmdMutex
6626 
6627 #define __HTRCXOnFwd(_outputs) \
6628   __HTRCXSetDirection(_outputs, RCX_OUT_FWD) \
6629   __HTRCXSetOutput(_outputs, RCX_OUT_ON)
6630 
6631 #define __HTRCXOnRev(_outputs) \
6632   __HTRCXSetDirection(_outputs, RCX_OUT_REV) \
6633   __HTRCXSetOutput(_outputs, RCX_OUT_ON)
6634 
6635 #define __HTRCXOnFor(_outputs, _ms) \
6636   __HTRCXSetOutput(_outputs, RCX_OUT_ON) \
6637   waitv _ms \
6638   __HTRCXSetOutput(_outputs, RCX_OUT_OFF)
6639 
6640 #define __HTRCXSetTxPower(_pwr) \
6641   acquire __RCXCmdMutex \
6642   arrbuild __gRCXCmd.Command, RCX_IRModeOp, _pwr \
6643   set __gRCXCmd.ResponseBytes, 0 \
6644   call __HTRCXCommandSub \
6645   release __RCXCmdMutex
6646 
6647 #define __HTRCXPlaySound(_snd) \
6648   acquire __RCXCmdMutex \
6649   arrbuild __gRCXCmd.Command, RCX_PlaySoundOp, _snd \
6650   set __gRCXCmd.ResponseBytes, 0 \
6651   call __HTRCXCommandSub \
6652   release __RCXCmdMutex
6653 
6654 #define __HTRCXDeleteTask(_t) \
6655   acquire __RCXCmdMutex \
6656   arrbuild __gRCXCmd.Command, RCX_DeleteTaskOp, _t \
6657   set __gRCXCmd.ResponseBytes, 0 \
6658   call __HTRCXCommandSub \
6659   release __RCXCmdMutex
6660 
6661 #define __HTRCXStartTask(_t) \
6662   acquire __RCXCmdMutex \
6663   arrbuild __gRCXCmd.Command, RCX_StartTaskOp, _t \
6664   set __gRCXCmd.ResponseBytes, 0 \
6665   call __HTRCXCommandSub \
6666   release __RCXCmdMutex
6667 
6668 #define __HTRCXStopTask(_t) \
6669   acquire __RCXCmdMutex \
6670   arrbuild __gRCXCmd.Command, RCX_StopTaskOp, _t \
6671   set __gRCXCmd.ResponseBytes, 0 \
6672   call __HTRCXCommandSub \
6673   release __RCXCmdMutex
6674 
6675 #define __HTRCXSelectProgram(_prog) \
6676   acquire __RCXCmdMutex \
6677   arrbuild __gRCXCmd.Command, RCX_SelectProgramOp, _prog \
6678   set __gRCXCmd.ResponseBytes, 0 \
6679   call __HTRCXCommandSub \
6680   release __RCXCmdMutex
6681 
6682 #define __HTRCXClearTimer(_timer) \
6683   acquire __RCXCmdMutex \
6684   arrbuild __gRCXCmd.Command, RCX_ClearTimerOp, _timer \
6685   set __gRCXCmd.ResponseBytes, 0 \
6686   call __HTRCXCommandSub \
6687   release __RCXCmdMutex
6688 
6689 #define __HTRCXSetSleepTime(_t) \
6690   acquire __RCXCmdMutex \
6691   arrbuild __gRCXCmd.Command, RCX_AutoOffOp, _t \
6692   set __gRCXCmd.ResponseBytes, 0 \
6693   call __HTRCXCommandSub \
6694   release __RCXCmdMutex
6695 
6696 #define __HTRCXDeleteSub(_s) \
6697   acquire __RCXCmdMutex \
6698   arrbuild __gRCXCmd.Command, RCX_DeleteSubOp, _s \
6699   set __gRCXCmd.ResponseBytes, 0 \
6700   call __HTRCXCommandSub \
6701   release __RCXCmdMutex
6702 
6703 #define __HTRCXClearSensor(_port) \
6704   acquire __RCXCmdMutex \
6705   arrbuild __gRCXCmd.Command, RCX_ClearSensorOp, _port \
6706   set __gRCXCmd.ResponseBytes, 0 \
6707   call __HTRCXCommandSub \
6708   release __RCXCmdMutex
6709 
6710 #define __HTRCXPlayToneVar(_varnum, _duration) \
6711   acquire __RCXCmdMutex \
6712   arrbuild __gRCXCmd.Command, RCX_PlayToneVarOp, _varnum, _duration \
6713   set __gRCXCmd.ResponseBytes, 0 \
6714   call __HTRCXCommandSub \
6715   release __RCXCmdMutex
6716 
6717 #define __HTRCXSetWatch(_hours, _minutes) \
6718   acquire __RCXCmdMutex \
6719   arrbuild __gRCXCmd.Command, RCX_SetWatchOp, _hours, _minutes \
6720   set __gRCXCmd.ResponseBytes, 0 \
6721   call __HTRCXCommandSub \
6722   release __RCXCmdMutex
6723 
6724 #define __HTRCXSetSensorType(_port, _type) \
6725   acquire __RCXCmdMutex \
6726   arrbuild __gRCXCmd.Command, RCX_InputTypeOp, _port, _type \
6727   set __gRCXCmd.ResponseBytes, 0 \
6728   call __HTRCXCommandSub \
6729   release __RCXCmdMutex
6730 
6731 #define __HTRCXSetSensorMode(_port, _mode) \
6732   acquire __RCXCmdMutex \
6733   arrbuild __gRCXCmd.Command, RCX_InputModeOp, _port, _mode \
6734   set __gRCXCmd.ResponseBytes, 0 \
6735   call __HTRCXCommandSub \
6736   release __RCXCmdMutex
6737 
6738 #define __HTRCXCreateDatalog(_size) \
6739   acquire __RCXCmdMutex \
6740   and __RCSTmpByte, _size, 0xFF \
6741   div __RCSTmpByte2, _size, 256 \
6742   arrbuild __gRCXCmd.Command, RCX_SetDatalogOp, __RCSTmpByte, __RCSTmpByte2 \
6743   set __gRCXCmd.ResponseBytes, 0 \
6744   call __HTRCXCommandSub \
6745   release __RCXCmdMutex
6746 
6747 #define __HTRCXAddToDatalog(_src, _value) \
6748   acquire __RCXCmdMutex \
6749   arrbuild __gRCXCmd.Command, RCX_DatalogOp, _src, _value \
6750   set __gRCXCmd.ResponseBytes, 0 \
6751   call __HTRCXCommandSub \
6752   release __RCXCmdMutex
6753 
6754 #define __HTRCXSendSerial(_first, _count) \
6755   acquire __RCXCmdMutex \
6756   arrbuild __gRCXCmd.Command, RCX_SendUARTDataOp, _first, _count \
6757   set __gRCXCmd.ResponseBytes, 0 \
6758   call __HTRCXCommandSub \
6759   release __RCXCmdMutex
6760 
6761 #define __HTRCXRemote(_cmd) \
6762   acquire __RCXCmdMutex \
6763   and __RCSTmpByte, _cmd, 0xFF \
6764   div __RCSTmpByte2, _cmd, 256 \
6765   arrbuild __gRCXCmd.Command, RCX_RemoteOp, __RCSTmpByte, __RCSTmpByte2 \
6766   set __gRCXCmd.ResponseBytes, 0 \
6767   call __HTRCXCommandSub \
6768   release __RCXCmdMutex
6769 
6770 #define __HTRCXEvent(_src, _value) \
6771   acquire __RCXCmdMutex \
6772   and __RCSTmpByte, _value, 0xFF \
6773   div __RCSTmpByte2, _value, 256 \
6774   arrbuild __gRCXCmd.Command, RCX_DirectEventOp, _src, __RCSTmpByte, __RCSTmpByte2 \
6775   set __gRCXCmd.ResponseBytes, 0 \
6776   call __HTRCXCommandSub \
6777   release __RCXCmdMutex
6778 
6779 #define __HTRCXPlayTone(_freq, _duration) \
6780   acquire __RCXCmdMutex \
6781   and __RCSTmpByte, _freq, 0xFF \
6782   div __RCSTmpByte2, _freq, 256 \
6783   arrbuild __gRCXCmd.Command, RCX_PlayToneOp, __RCSTmpByte, __RCSTmpByte2, _duration \
6784   set __gRCXCmd.ResponseBytes, 0 \
6785   call __HTRCXCommandSub \
6786   release __RCXCmdMutex
6787 
6788 #define __HTRCXSelectDisplay(_src, _value) \
6789   acquire __RCXCmdMutex \
6790   and __RCSTmpByte, _value, 0xFF \
6791   div __RCSTmpByte2, _value, 256 \
6792   arrbuild __gRCXCmd.Command, RCX_DisplayOp, _src, __RCSTmpByte, __RCSTmpByte2 \
6793   set __gRCXCmd.ResponseBytes, 0 \
6794   call __HTRCXCommandSub \
6795   release __RCXCmdMutex
6796 
6797 #define __HTRCXPollMemory(_memaddress, _result) \
6798   acquire __RCXCmdMutex \
6799   and __RCSTmpByte, _memaddress, 0xFF \
6800   div __RCSTmpByte2, _memaddress, 256 \
6801   arrbuild __gRCXCmd.Command, RCX_PollMemoryOp, __RCSTmpByte, __RCSTmpByte2, 1 \
6802   set __gRCXCmd.ResponseBytes, 16 \
6803   call __HTRCXCommandSub \
6804   index _result, __gRCXCmd.Response, 7 \
6805   index __RCSTmpByte, __gRCXCmd.Response, 5 \
6806   mul _result, _result, 256 \
6807   add _result, _result, __RCSTmpByte \
6808   release __RCXCmdMutex
6809 
6810 #define __HTRCXSetEvent(_evt, _src, _type) \
6811   acquire __RCXCmdMutex \
6812   arrbuild __gRCXCmd.Command, RCX_SetEventOp, _evt, _src, _type \
6813   set __gRCXCmd.ResponseBytes, 0 \
6814   call __HTRCXCommandSub \
6815   release __RCXCmdMutex
6816 
6817 #define __HTRCXSetGlobalOutput(_outputs, _mode) \
6818   acquire __RCXCmdMutex \
6819   add __RCSTmpByte, _outputs, _mode \
6820   arrbuild __gRCXCmd.Command, RCX_GOutputModeOp, __RCSTmpByte \
6821   set __gRCXCmd.ResponseBytes, 0 \
6822   call __HTRCXCommandSub \
6823   release __RCXCmdMutex
6824 
6825 #define __HTRCXSetGlobalDirection(_outputs, _dir) \
6826   acquire __RCXCmdMutex \
6827   add __RCSTmpByte, _outputs, _dir \
6828   arrbuild __gRCXCmd.Command, RCX_GOutputDirOp, __RCSTmpByte \
6829   set __gRCXCmd.ResponseBytes, 0 \
6830   call __HTRCXCommandSub \
6831   release __RCXCmdMutex
6832 
6833 #define __HTRCXSetMaxPower(_outputs, _pwrsrc, _pwrval) \
6834   acquire __RCXCmdMutex \
6835   arrbuild __gRCXCmd.Command, RCX_GOutputPowerOp, _outputs, _pwrsrc, _pwrval \
6836   set __gRCXCmd.ResponseBytes, 0 \
6837   call __HTRCXCommandSub \
6838   release __RCXCmdMutex
6839 
6840 #define __HTRCXIncCounter(_counter) \
6841   acquire __RCXCmdMutex \
6842   arrbuild __gRCXCmd.Command, RCX_IncCounterOp, _counter \
6843   set __gRCXCmd.ResponseBytes, 0 \
6844   call __HTRCXCommandSub \
6845   release __RCXCmdMutex
6846 
6847 #define __HTRCXDecCounter(_counter) \
6848   acquire __RCXCmdMutex \
6849   arrbuild __gRCXCmd.Command, RCX_DecCounterOp, _counter \
6850   set __gRCXCmd.ResponseBytes, 0 \
6851   call __HTRCXCommandSub \
6852   release __RCXCmdMutex
6853 
6854 #define __HTRCXClearCounter(_counter) \
6855   acquire __RCXCmdMutex \
6856   arrbuild __gRCXCmd.Command, RCX_ClearCounterOp, _counter \
6857   set __gRCXCmd.ResponseBytes, 0 \
6858   call __HTRCXCommandSub \
6859   release __RCXCmdMutex
6860 
6861 #define __HTRCXSetPriority(_p) \
6862   acquire __RCXCmdMutex \
6863   arrbuild __gRCXCmd.Command, RCX_SetPriorityOp, _p \
6864   set __gRCXCmd.ResponseBytes, 0 \
6865   call __HTRCXCommandSub \
6866   release __RCXCmdMutex
6867 
6868 #define __HTRCXSetMessage(_msg) \
6869   acquire __RCXCmdMutex \
6870   arrbuild __gRCXCmd.Command, RCX_MessageOp, _msg \
6871   set __gRCXCmd.ResponseBytes, 0 \
6872   call __HTRCXCommandSub \
6873   release __RCXCmdMutex
6874 
6875 #define __HTScoutSetScoutMode(_mode) \
6876   acquire __RCXCmdMutex \
6877   arrbuild __gRCXCmd.Command, RCX_ScoutOp, _mode \
6878   set __gRCXCmd.ResponseBytes, 0 \
6879   call __HTRCXCommandSub \
6880   release __RCXCmdMutex
6881 
6882 #define __HTScoutSendVLL(_src, _value) \
6883   acquire __RCXCmdMutex \
6884   arrbuild __gRCXCmd.Command, RCX_VLLOp, _src, _value \
6885   set __gRCXCmd.ResponseBytes, 0 \
6886   call __HTRCXCommandSub \
6887   release __RCXCmdMutex
6888 
6889 #define __HTScoutSetSensorClickTime(_src, _value) \
6890   acquire __RCXCmdMutex \
6891   and __RCSTmpByte, _value, 0xFF \
6892   div __RCSTmpByte2, _value, 256 \
6893   arrbuild __gRCXCmd.Command, RCX_LSBlinkTimeOp, _src, __RCSTmpByte, __RCSTmpByte2 \
6894   set __gRCXCmd.ResponseBytes, 0 \
6895   call __HTRCXCommandSub \
6896   release __RCXCmdMutex
6897 
6898 #define __HTScoutSetSensorHysteresis(_src, _value) \
6899   acquire __RCXCmdMutex \
6900   and __RCSTmpByte, _value, 0xFF \
6901   div __RCSTmpByte2, _value, 256 \
6902   arrbuild __gRCXCmd.Command, RCX_LSHysteresisOp, _src, __RCSTmpByte, __RCSTmpByte2 \
6903   set __gRCXCmd.ResponseBytes, 0 \
6904   call __HTRCXCommandSub \
6905   release __RCXCmdMutex
6906 
6907 #define __HTScoutSetSensorLowerLimit(_src, _value) \
6908   acquire __RCXCmdMutex \
6909   and __RCSTmpByte, _value, 0xFF \
6910   div __RCSTmpByte2, _value, 256 \
6911   arrbuild __gRCXCmd.Command, RCX_LSLowerThreshOp, _src, __RCSTmpByte, __RCSTmpByte2 \
6912   set __gRCXCmd.ResponseBytes, 0 \
6913   call __HTRCXCommandSub \
6914   release __RCXCmdMutex
6915 
6916 #define __HTScoutSetSensorUpperLimit(_src, _value) \
6917   acquire __RCXCmdMutex \
6918   and __RCSTmpByte, _value, 0xFF \
6919   div __RCSTmpByte2, _value, 256 \
6920   arrbuild __gRCXCmd.Command, RCX_LSUpperThreshOp, _src, __RCSTmpByte, __RCSTmpByte2 \
6921   set __gRCXCmd.ResponseBytes, 0 \
6922   call __HTRCXCommandSub \
6923   release __RCXCmdMutex
6924 
6925 #define __HTScoutSetEventFeedback(_src, _value) \
6926   acquire __RCXCmdMutex \
6927   and __RCSTmpByte, _value, 0xFF \
6928   div __RCSTmpByte2, _value, 256 \
6929   arrbuild __gRCXCmd.Command, RCX_SetFeedbackOp, _src, __RCSTmpByte, __RCSTmpByte2 \
6930   set __gRCXCmd.ResponseBytes, 0 \
6931   call __HTRCXCommandSub \
6932   release __RCXCmdMutex
6933 
6934 #define __HTScoutMuteSound() \
6935   acquire __RCXCmdMutex \
6936   arrbuild __gRCXCmd.Command, RCX_SoundOp, 0x80 \
6937   set __gRCXCmd.ResponseBytes, 0 \
6938   call __HTRCXCommandSub \
6939   release __RCXCmdMutex
6940 
6941 #define __HTScoutUnmuteSound() \
6942   acquire __RCXCmdMutex \
6943   arrbuild __gRCXCmd.Command, RCX_SoundOp, 0xc0 \
6944   set __gRCXCmd.ResponseBytes, 0 \
6945   call __HTRCXCommandSub \
6946   release __RCXCmdMutex
6947 
6948 #define __HTScoutSelectSounds(_grp) \
6949   acquire __RCXCmdMutex \
6950   arrbuild __gRCXCmd.Command, RCX_SoundOp, _grp \
6951   set __gRCXCmd.ResponseBytes, 0 \
6952   call __HTRCXCommandSub \
6953   release __RCXCmdMutex
6954 
6955 #define __HTScoutSetLight(_x) \
6956   acquire __RCXCmdMutex \
6957   arrbuild __gRCXCmd.Command, RCX_LightOp, _x \
6958   set __gRCXCmd.ResponseBytes, 0 \
6959   call __HTRCXCommandSub \
6960   release __RCXCmdMutex
6961 
6962 #define __ReadSensorHTCompass(_port, _value) \
6963   compif EQ, isconst(_port), FALSE \
6964   acquire __RLSBmutex0 \
6965   acquire __RLSBmutex1 \
6966   acquire __RLSBmutex2 \
6967   acquire __RLSBmutex3 \
6968   mov __RLSReadPort, _port \
6969   mov __RLSReadBufVar, __RLSBbufLSWrite1 \
6970   set __RLSBytesCountVar, 2 \
6971   call __ReadLSBytesVar \
6972   index _value, __RLSReadBufVar, NA \
6973   index __RLSBytesCountVar, __RLSReadBufVar, 1 \
6974   add _value, _value, _value \
6975   add _value, _value, __RLSBytesCountVar \
6976   release __RLSBmutex0 \
6977   release __RLSBmutex1 \
6978   release __RLSBmutex2 \
6979   release __RLSBmutex3 \
6980   compelse \
6981   compchk LT, _port, 0x04 \
6982   compchk GTEQ, _port, 0x00 \
6983   acquire __RLSBmutex##_port \
6984   mov __RLSReadBuf##_port, __RLSBbufLSWrite1 \
6985   set __RLSBytesCount##_port, 2 \
6986   call __ReadLSBytes##_port \
6987   index _value, __RLSReadBuf##_port, NA \
6988   index __RLSBytesCount##_port, __RLSReadBuf##_port, 1 \
6989   add _value, _value, _value \
6990   add _value, _value, __RLSBytesCount##_port \
6991   release __RLSBmutex##_port \
6992   compend
6993 
6994 #define __ReadSensorHTAccel(_port, _x, _y, _z, _result) \
6995   compif EQ, isconst(_port), FALSE \
6996   acquire __RLSBmutex0 \
6997   acquire __RLSBmutex1 \
6998   acquire __RLSBmutex2 \
6999   acquire __RLSBmutex3 \
7000   mov __RLSReadPort, _port \
7001   mov __RLSReadBufVar, __RLSBbufLSWrite1 \
7002   set __RLSBytesCountVar, 6 \
7003   call __ReadLSBytesVar \
7004   tst EQ, _result, __RLSBResultVar \
7005   index _x, __RLSReadBufVar, NA \
7006   index __RLSBytesCountVar, __RLSReadBufVar, 3 \
7007   brcmp LTEQ, __RSHTAX##__I__, _x, 127 \
7008   sub _x, _x, 256 \
7009   __RSHTAX##__I__: \
7010   __IncI__ \
7011   mul _x, _x, 4 \
7012   add _x, _x, __RLSBytesCountVar \
7013   index _y, __RLSReadBufVar, 1 \
7014   index __RLSBytesCountVar, __RLSReadBufVar, 4 \
7015   brcmp LTEQ, __RSHTAY##__I__, _y, 127 \
7016   sub _y, _y, 256 \
7017   __RSHTAY##__I__: \
7018   __IncI__ \
7019   mul _y, _y, 4 \
7020   add _y, _y, __RLSBytesCountVar \
7021   index _z, __RLSReadBufVar, 2 \
7022   index __RLSBytesCountVar, __RLSReadBufVar, 5 \
7023   brcmp LTEQ, __RSHTAZ##__I__, _z, 127 \
7024   sub _z, _z, 256 \
7025   __RSHTAZ##__I__: \
7026   __IncI__ \
7027   mul _z, _z, 4 \
7028   add _z, _z, __RLSBytesCountVar \
7029   release __RLSBmutex0 \
7030   release __RLSBmutex1 \
7031   release __RLSBmutex2 \
7032   release __RLSBmutex3 \
7033   compelse \
7034   compchk LT, _port, 0x04 \
7035   compchk GTEQ, _port, 0x00 \
7036   acquire __RLSBmutex##_port \
7037   mov __RLSReadBuf##_port, __RLSBbufLSWrite1 \
7038   set __RLSBytesCount##_port, 6 \
7039   call __ReadLSBytes##_port \
7040   tst EQ, _result, __RLSBResult##_port \
7041   index _x, __RLSReadBuf##_port, NA \
7042   index __RLSBytesCount##_port, __RLSReadBuf##_port, 3 \
7043   brcmp LTEQ, __RSHTAX##__I__, _x, 127 \
7044   sub _x, _x, 256 \
7045   __RSHTAX##__I__: \
7046   __IncI__ \
7047   mul _x, _x, 4 \
7048   add _x, _x, __RLSBytesCount##_port \
7049   index _y, __RLSReadBuf##_port, 1 \
7050   index __RLSBytesCount##_port, __RLSReadBuf##_port, 4 \
7051   brcmp LTEQ, __RSHTAY##__I__, _y, 127 \
7052   sub _y, _y, 256 \
7053   __RSHTAY##__I__: \
7054   __IncI__ \
7055   mul _y, _y, 4 \
7056   add _y, _y, __RLSBytesCount##_port \
7057   index _z, __RLSReadBuf##_port, 2 \
7058   index __RLSBytesCount##_port, __RLSReadBuf##_port, 5 \
7059   brcmp LTEQ, __RSHTAZ##__I__, _z, 127 \
7060   sub _z, _z, 256 \
7061   __RSHTAZ##__I__: \
7062   __IncI__ \
7063   mul _z, _z, 4 \
7064   add _z, _z, __RLSBytesCount##_port \
7065   release __RLSBmutex##_port \
7066   compend
7067 
7068 dseg segment
7069   __RSHTColorRawBuf byte[] 0x02, 0x46
7070   __RSHTColorNormBuf byte[] 0x02, 0x4C
7071   __RSHTColor2NormBuf byte[] 0x02, 0x47
7072 dseg ends
7073 
7074 #define __ReadSensorHTRawColor(_port, _Red, _Green, _Blue, _result) \
7075   compif EQ, isconst(_port), FALSE \
7076   acquire __RLSBmutex0 \
7077   acquire __RLSBmutex1 \
7078   acquire __RLSBmutex2 \
7079   acquire __RLSBmutex3 \
7080   mov __RLSReadPort, _port \
7081   mov __RLSReadBufVar, __RSHTColorRawBuf \
7082   set __RLSBytesCountVar, 6 \
7083   call __ReadLSBytesVar \
7084   tst EQ, _result, __RLSBResultVar \
7085   index _Red, __RLSReadBufVar, 1 \
7086   index __RLSBytesCountVar, __RLSReadBufVar, NA \
7087   mul _Red, _Red, 256 \
7088   add _Red, _Red, __RLSBytesCountVar \
7089   index _Green, __RLSReadBufVar, 3 \
7090   index __RLSBytesCountVar, __RLSReadBufVar, 2 \
7091   mul _Green, _Green, 256 \
7092   add _Green, _Green, __RLSBytesCountVar \
7093   index _Blue, __RLSReadBufVar, 5 \
7094   index __RLSBytesCountVar, __RLSReadBufVar, 4 \
7095   mul _Blue, _Blue, 256 \
7096   add _Blue, _Blue, __RLSBytesCountVar \
7097   release __RLSBmutex0 \
7098   release __RLSBmutex1 \
7099   release __RLSBmutex2 \
7100   release __RLSBmutex3 \
7101   compelse \
7102   compchk LT, _port, 0x04 \
7103   compchk GTEQ, _port, 0x00 \
7104   acquire __RLSBmutex##_port \
7105   mov __RLSReadBuf##_port, __RSHTColorRawBuf \
7106   set __RLSBytesCount##_port, 6 \
7107   call __ReadLSBytes##_port \
7108   tst EQ, _result, __RLSBResult##_port \
7109   index _Red, __RLSReadBuf##_port, 1 \
7110   index __RLSBytesCount##_port, __RLSReadBuf##_port, NA \
7111   mul _Red, _Red, 256 \
7112   add _Red, _Red, __RLSBytesCount##_port \
7113   index _Green, __RLSReadBuf##_port, 3 \
7114   index __RLSBytesCount##_port, __RLSReadBuf##_port, 2 \
7115   mul _Green, _Green, 256 \
7116   add _Green, _Green, __RLSBytesCount##_port \
7117   index _Blue, __RLSReadBuf##_port, 5 \
7118   index __RLSBytesCount##_port, __RLSReadBuf##_port, 4 \
7119   mul _Blue, _Blue, 256 \
7120   add _Blue, _Blue, __RLSBytesCount##_port \
7121   release __RLSBmutex##_port \
7122   compend
7123 
7124 #define __ReadSensorHTColor(_port, _ColorNum, _Red, _Green, _Blue, _result) \
7125   compif EQ, isconst(_port), FALSE \
7126   acquire __RLSBmutex0 \
7127   acquire __RLSBmutex1 \
7128   acquire __RLSBmutex2 \
7129   acquire __RLSBmutex3 \
7130   mov __RLSReadPort, _port \
7131   mov __RLSReadBufVar, __RLSBbufLSWrite1 \
7132   set __RLSBytesCountVar, 4 \
7133   call __ReadLSBytesVar \
7134   tst EQ, _result, __RLSBResultVar \
7135   index _ColorNum, __RLSReadBufVar, NA \
7136   index _Red, __RLSReadBufVar, 1 \
7137   index _Green, __RLSReadBufVar, 2 \
7138   index _Blue, __RLSReadBufVar, 3 \
7139   release __RLSBmutex0 \
7140   release __RLSBmutex1 \
7141   release __RLSBmutex2 \
7142   release __RLSBmutex3 \
7143   compelse \
7144   compchk LT, _port, 0x04 \
7145   compchk GTEQ, _port, 0x00 \
7146   acquire __RLSBmutex##_port \
7147   mov __RLSReadBuf##_port, __RLSBbufLSWrite1 \
7148   set __RLSBytesCount##_port, 4 \
7149   call __ReadLSBytes##_port \
7150   tst EQ, _result, __RLSBResult##_port \
7151   index _ColorNum, __RLSReadBuf##_port, NA \
7152   index _Red, __RLSReadBuf##_port, 1 \
7153   index _Green, __RLSReadBuf##_port, 2 \
7154   index _Blue, __RLSReadBuf##_port, 3 \
7155   release __RLSBmutex##_port \
7156   compend
7157 
7158 #define __ReadSensorHTNormalizedColor(_port, _ColorIdx, _Red, _Green, _Blue, _result) \
7159   compif EQ, isconst(_port), FALSE \
7160   acquire __RLSBmutex0 \
7161   acquire __RLSBmutex1 \
7162   acquire __RLSBmutex2 \
7163   acquire __RLSBmutex3 \
7164   mov __RLSReadPort, _port \
7165   mov __RLSReadBufVar, __RSHTColorNormBuf \
7166   set __RLSBytesCountVar, 4 \
7167   call __ReadLSBytesVar \
7168   tst EQ, _result, __RLSBResultVar \
7169   index _ColorIdx, __RLSReadBufVar, NA \
7170   index _Red, __RLSReadBufVar, 1 \
7171   index _Green, __RLSReadBufVar, 2 \
7172   index _Blue, __RLSReadBufVar, 3 \
7173   release __RLSBmutex0 \
7174   release __RLSBmutex1 \
7175   release __RLSBmutex2 \
7176   release __RLSBmutex3 \
7177   compelse \
7178   compchk LT, _port, 0x04 \
7179   compchk GTEQ, _port, 0x00 \
7180   acquire __RLSBmutex##_port \
7181   mov __RLSReadBuf##_port, __RSHTColorNormBuf \
7182   set __RLSBytesCount##_port, 4 \
7183   call __ReadLSBytes##_port \
7184   tst EQ, _result, __RLSBResult##_port \
7185   index _ColorIdx, __RLSReadBuf##_port, NA \
7186   index _Red, __RLSReadBuf##_port, 1 \
7187   index _Green, __RLSReadBuf##_port, 2 \
7188   index _Blue, __RLSReadBuf##_port, 3 \
7189   release __RLSBmutex##_port \
7190   compend
7191 
7192 #define __ReadSensorHTColor2Active(_port, _ColorNum, _Red, _Green, _Blue, _White, _result) \
7193   compif EQ, isconst(_port), FALSE \
7194   acquire __RLSBmutex0 \
7195   acquire __RLSBmutex1 \
7196   acquire __RLSBmutex2 \
7197   acquire __RLSBmutex3 \
7198   mov __RLSReadPort, _port \
7199   mov __RLSReadBufVar, __RLSBbufLSWrite1 \
7200   set __RLSBytesCountVar, 5 \
7201   call __ReadLSBytesVar \
7202   tst EQ, _result, __RLSBResultVar \
7203   index _ColorNum, __RLSReadBufVar, NA \
7204   index _Red, __RLSReadBufVar, 1 \
7205   index _Green, __RLSReadBufVar, 2 \
7206   index _Blue, __RLSReadBufVar, 3 \
7207   index _White, __RLSReadBufVar, 4 \
7208   release __RLSBmutex0 \
7209   release __RLSBmutex1 \
7210   release __RLSBmutex2 \
7211   release __RLSBmutex3 \
7212   compelse \
7213   compchk LT, _port, 0x04 \
7214   compchk GTEQ, _port, 0x00 \
7215   acquire __RLSBmutex##_port \
7216   mov __RLSReadBuf##_port, __RLSBbufLSWrite1 \
7217   set __RLSBytesCount##_port, 5 \
7218   call __ReadLSBytes##_port \
7219   tst EQ, _result, __RLSBResult##_port \
7220   index _ColorNum, __RLSReadBuf##_port, NA \
7221   index _Red, __RLSReadBuf##_port, 1 \
7222   index _Green, __RLSReadBuf##_port, 2 \
7223   index _Blue, __RLSReadBuf##_port, 3 \
7224   index _White, __RLSReadBuf##_port, 4 \
7225   release __RLSBmutex##_port \
7226   compend
7227 
7228 #define __ReadSensorHTNormalizedColor2Active(_port, _ColorIdx, _Red, _Green, _Blue, _result) \
7229   compif EQ, isconst(_port), FALSE \
7230   acquire __RLSBmutex0 \
7231   acquire __RLSBmutex1 \
7232   acquire __RLSBmutex2 \
7233   acquire __RLSBmutex3 \
7234   mov __RLSReadPort, _port \
7235   mov __RLSReadBufVar, __RSHTColor2NormBuf \
7236   set __RLSBytesCountVar, 4 \
7237   call __ReadLSBytesVar \
7238   tst EQ, _result, __RLSBResultVar \
7239   index _ColorIdx, __RLSReadBufVar, NA \
7240   index _Red, __RLSReadBufVar, 1 \
7241   index _Green, __RLSReadBufVar, 2 \
7242   index _Blue, __RLSReadBufVar, 3 \
7243   release __RLSBmutex0 \
7244   release __RLSBmutex1 \
7245   release __RLSBmutex2 \
7246   release __RLSBmutex3 \
7247   compelse \
7248   compchk LT, _port, 0x04 \
7249   compchk GTEQ, _port, 0x00 \
7250   acquire __RLSBmutex##_port \
7251   mov __RLSReadBuf##_port, __RSHTColor2NormBuf \
7252   set __RLSBytesCount##_port, 5 \
7253   call __ReadLSBytes##_port \
7254   tst EQ, _result, __RLSBResult##_port \
7255   index _ColorIdx, __RLSReadBuf##_port, NA \
7256   index _Red, __RLSReadBuf##_port, 1 \
7257   index _Green, __RLSReadBuf##_port, 2 \
7258   index _Blue, __RLSReadBuf##_port, 3 \
7259   release __RLSBmutex##_port \
7260   compend
7261 
7262 #define __ReadSensorHTRawColor2(_port, _Red, _Green, _Blue, _White, _result) \
7263   compif EQ, isconst(_port), FALSE \
7264   acquire __RLSBmutex0 \
7265   acquire __RLSBmutex1 \
7266   acquire __RLSBmutex2 \
7267   acquire __RLSBmutex3 \
7268   mov __RLSReadPort, _port \
7269   mov __RLSReadBufVar, __RLSBbufLSWrite1 \
7270   set __RLSBytesCountVar, 8 \
7271   call __ReadLSBytesVar \
7272   tst EQ, _result, __RLSBResultVar \
7273   index _Red, __RLSReadBufVar, NA \
7274   index __RLSBytesCountVar, __RLSReadBufVar, 1 \
7275   mul _Red, _Red, 256 \
7276   add _Red, _Red, __RLSBytesCountVar \
7277   index _Green, __RLSReadBufVar, 2 \
7278   index __RLSBytesCountVar, __RLSReadBufVar, 3 \
7279   mul _Green, _Green, 256 \
7280   add _Green, _Green, __RLSBytesCountVar \
7281   index _Blue, __RLSReadBufVar, 4 \
7282   index __RLSBytesCountVar, __RLSReadBufVar, 5 \
7283   mul _Blue, _Blue, 256 \
7284   add _Blue, _Blue, __RLSBytesCountVar \
7285   index _White, __RLSReadBufVar, 6 \
7286   index __RLSBytesCountVar, __RLSReadBufVar, 7 \
7287   mul _White, _White, 256 \
7288   add _White, _White, __RLSBytesCountVar \
7289   release __RLSBmutex0 \
7290   release __RLSBmutex1 \
7291   release __RLSBmutex2 \
7292   release __RLSBmutex3 \
7293   compelse \
7294   compchk LT, _port, 0x04 \
7295   compchk GTEQ, _port, 0x00 \
7296   acquire __RLSBmutex##_port \
7297   mov __RLSReadBuf##_port, __RLSBbufLSWrite1 \
7298   set __RLSBytesCount##_port, 8 \
7299   call __ReadLSBytes##_port \
7300   tst EQ, _result, __RLSBResult##_port \
7301   index _Red, __RLSReadBuf##_port, NA \
7302   index __RLSBytesCount##_port, __RLSReadBuf##_port, 1 \
7303   mul _Red, _Red, 256 \
7304   add _Red, _Red, __RLSBytesCount##_port \
7305   index _Green, __RLSReadBuf##_port, 2 \
7306   index __RLSBytesCount##_port, __RLSReadBuf##_port, 3 \
7307   mul _Green, _Green, 256 \
7308   add _Green, _Green, __RLSBytesCount##_port \
7309   index _Blue, __RLSReadBuf##_port, 4 \
7310   index __RLSBytesCount##_port, __RLSReadBuf##_port, 5 \
7311   mul _Blue, _Blue, 256 \
7312   add _Blue, _Blue, __RLSBytesCount##_port \
7313   index _White, __RLSReadBuf##_port, 6 \
7314   index __RLSBytesCount##_port, __RLSReadBuf##_port, 7 \
7315   mul _White, _White, 256 \
7316   add _White, _White, __RLSBytesCount##_port \
7317   release __RLSBmutex##_port \
7318   compend
7319 
7320 #define __ReadSensorHTIRSeeker(_port, _dir, _s1, _s3, _s5, _s7, _s9, _result) \
7321   compif EQ, isconst(_port), FALSE \
7322   acquire __RLSBmutex0 \
7323   acquire __RLSBmutex1 \
7324   acquire __RLSBmutex2 \
7325   acquire __RLSBmutex3 \
7326   mov __RLSReadPort, _port \
7327   mov __RLSReadBufVar, __RLSBbufLSWrite1 \
7328   set __RLSBytesCountVar, 6 \
7329   call __ReadLSBytesVar \
7330   tst EQ, _result, __RLSBResultVar \
7331   index _dir, __RLSReadBufVar, NA \
7332   index _s1, __RLSReadBufVar, 1 \
7333   index _s3, __RLSReadBufVar, 2 \
7334   index _s5, __RLSReadBufVar, 3 \
7335   index _s7, __RLSReadBufVar, 4 \
7336   index _s9, __RLSReadBufVar, 5 \
7337   release __RLSBmutex0 \
7338   release __RLSBmutex1 \
7339   release __RLSBmutex2 \
7340   release __RLSBmutex3 \
7341   compelse \
7342   compchk LT, _port, 0x04 \
7343   compchk GTEQ, _port, 0x00 \
7344   acquire __RLSBmutex##_port \
7345   mov __RLSReadBuf##_port, __RLSBbufLSWrite1 \
7346   set __RLSBytesCount##_port, 6 \
7347   call __ReadLSBytes##_port \
7348   tst EQ, _result, __RLSBResult##_port \
7349   index _dir, __RLSReadBuf##_port, NA \
7350   index _s1, __RLSReadBuf##_port, 1 \
7351   index _s3, __RLSReadBuf##_port, 2 \
7352   index _s5, __RLSReadBuf##_port, 3 \
7353   index _s7, __RLSReadBuf##_port, 4 \
7354   index _s9, __RLSReadBuf##_port, 5 \
7355   release __RLSBmutex##_port \
7356   compend
7357 
7358 #define __ReadSensorHTIRSeeker2DC(_port, _dir, _s1, _s3, _s5, _s7, _s9, _avg, _result) \
7359   compif EQ, isconst(_port), FALSE \
7360   acquire __RLSBmutex0 \
7361   acquire __RLSBmutex1 \
7362   acquire __RLSBmutex2 \
7363   acquire __RLSBmutex3 \
7364   mov __RLSReadPort, _port \
7365   arrbuild __RLSReadBufVar, 0x10, 0x42 \
7366   set __RLSBytesCountVar, 7 \
7367   call __ReadLSBytesVar \
7368   tst EQ, _result, __RLSBResultVar \
7369   index _dir, __RLSReadBufVar, NA \
7370   index _s1, __RLSReadBufVar, 1 \
7371   index _s3, __RLSReadBufVar, 2 \
7372   index _s5, __RLSReadBufVar, 3 \
7373   index _s7, __RLSReadBufVar, 4 \
7374   index _s9, __RLSReadBufVar, 5 \
7375   index _avg, __RLSReadBufVar, 6 \
7376   release __RLSBmutex0 \
7377   release __RLSBmutex1 \
7378   release __RLSBmutex2 \
7379   release __RLSBmutex3 \
7380   compelse \
7381   compchk LT, _port, 0x04 \
7382   compchk GTEQ, _port, 0x00 \
7383   acquire __RLSBmutex##_port \
7384   arrbuild __RLSReadBuf##_port, 0x10, 0x42 \
7385   set __RLSBytesCount##_port, 7 \
7386   call __ReadLSBytes##_port \
7387   tst EQ, _result, __RLSBResult##_port \
7388   index _dir, __RLSReadBuf##_port, NA \
7389   index _s1, __RLSReadBuf##_port, 1 \
7390   index _s3, __RLSReadBuf##_port, 2 \
7391   index _s5, __RLSReadBuf##_port, 3 \
7392   index _s7, __RLSReadBuf##_port, 4 \
7393   index _s9, __RLSReadBuf##_port, 5 \
7394   index _avg, __RLSReadBuf##_port, 6 \
7395   release __RLSBmutex##_port \
7396   compend
7397 
7398 #define __ReadSensorHTIRSeeker2AC(_port, _dir, _s1, _s3, _s5, _s7, _s9, _result) \
7399   compif EQ, isconst(_port), FALSE \
7400   acquire __RLSBmutex0 \
7401   acquire __RLSBmutex1 \
7402   acquire __RLSBmutex2 \
7403   acquire __RLSBmutex3 \
7404   mov __RLSReadPort, _port \
7405   arrbuild __RLSReadBufVar, 0x10, 0x49 \
7406   set __RLSBytesCountVar, 6 \
7407   call __ReadLSBytesVar \
7408   tst EQ, _result, __RLSBResultVar \
7409   index _dir, __RLSReadBufVar, NA \
7410   index _s1, __RLSReadBufVar, 1 \
7411   index _s3, __RLSReadBufVar, 2 \
7412   index _s5, __RLSReadBufVar, 3 \
7413   index _s7, __RLSReadBufVar, 4 \
7414   index _s9, __RLSReadBufVar, 5 \
7415   release __RLSBmutex0 \
7416   release __RLSBmutex1 \
7417   release __RLSBmutex2 \
7418   release __RLSBmutex3 \
7419   compelse \
7420   compchk LT, _port, 0x04 \
7421   compchk GTEQ, _port, 0x00 \
7422   acquire __RLSBmutex##_port \
7423   arrbuild __RLSReadBuf##_port, 0x10, 0x49 \
7424   set __RLSBytesCount##_port, 6 \
7425   call __ReadLSBytes##_port \
7426   tst EQ, _result, __RLSBResult##_port \
7427   index _dir, __RLSReadBuf##_port, NA \
7428   index _s1, __RLSReadBuf##_port, 1 \
7429   index _s3, __RLSReadBuf##_port, 2 \
7430   index _s5, __RLSReadBuf##_port, 3 \
7431   index _s7, __RLSReadBuf##_port, 4 \
7432   index _s9, __RLSReadBuf##_port, 5 \
7433   release __RLSBmutex##_port \
7434   compend
7435 
7436 #define __ReadSensorHTIRSeeker2Addr(_port, _reg, _value) \
7437   compif EQ, isconst(_port), FALSE \
7438   acquire __RLSBmutex0 \
7439   acquire __RLSBmutex1 \
7440   acquire __RLSBmutex2 \
7441   acquire __RLSBmutex3 \
7442   mov __RLSReadPort, _port \
7443   arrbuild __RLSReadBufVar, 0x10, _reg \
7444   set __RLSBytesCountVar, 1 \
7445   call __ReadLSBytesVar \
7446   index _value, __RLSReadBufVar, NA \
7447   release __RLSBmutex0 \
7448   release __RLSBmutex1 \
7449   release __RLSBmutex2 \
7450   release __RLSBmutex3 \
7451   compelse \
7452   compchk LT, _port, 0x04 \
7453   compchk GTEQ, _port, 0x00 \
7454   acquire __RLSBmutex##_port \
7455   arrbuild __RLSReadBuf##_port, 0x10, _reg \
7456   set __RLSBytesCount##_port, 1 \
7457   call __ReadLSBytes##_port \
7458   index _value, __RLSReadBuf##_port, NA \
7459   release __RLSBmutex##_port \
7460   compend
7461 
7462 #define __SetHTIRSeeker2Mode(_port, _mode, _result) __I2CSendCmd(_port, 0x10, _mode, _result)
7463 
7464 #define __ReadSensorHTIRReceiver(_port, _pfdata, _result) \
7465   compif EQ, isconst(_port), FALSE \
7466   acquire __RLSBmutex0 \
7467   acquire __RLSBmutex1 \
7468   acquire __RLSBmutex2 \
7469   acquire __RLSBmutex3 \
7470   mov __RLSReadPort, _port \
7471   mov __RLSReadBufVar, __RLSBbufLSWrite1 \
7472   set __RLSBytesCountVar, 8 \
7473   call __ReadLSBytesVar \
7474   tst EQ, _result, __RLSBResultVar \
7475   mov _pfdata, __RLSReadBufVar \
7476   release __RLSBmutex0 \
7477   release __RLSBmutex1 \
7478   release __RLSBmutex2 \
7479   release __RLSBmutex3 \
7480   compelse \
7481   compchk LT, _port, 0x04 \
7482   compchk GTEQ, _port, 0x00 \
7483   acquire __RLSBmutex##_port \
7484   mov __RLSReadBuf##_port, __RLSBbufLSWrite1 \
7485   set __RLSBytesCount##_port, 8 \
7486   call __ReadLSBytes##_port \
7487   tst EQ, _result, __RLSBResult##_port \
7488   mov _pfdata, __RLSReadBuf##_port \
7489   release __RLSBmutex##_port \
7490   compend
7491 
7492 #define __ReadSensorHTIRReceiverEx(_port, _reg, _pfchar, _result) \
7493   compif EQ, isconst(_port), FALSE \
7494   acquire __RLSBmutex0 \
7495   acquire __RLSBmutex1 \
7496   acquire __RLSBmutex2 \
7497   acquire __RLSBmutex3 \
7498   mov __RLSReadPort, _port \
7499   add __RLSBytesCountVar, 0x42, _reg \
7500   arrbuild __RLSReadBufVar, 0x02, __RLSBytesCountVar \
7501   set __RLSBytesCountVar, 1 \
7502   call __ReadLSBytesVar \
7503   tst EQ, _result, __RLSBResultVar \
7504   index _pfchar, __RLSReadBufVar, NA \
7505   release __RLSBmutex0 \
7506   release __RLSBmutex1 \
7507   release __RLSBmutex2 \
7508   release __RLSBmutex3 \
7509   compelse \
7510   compchk LT, _port, 0x04 \
7511   compchk GTEQ, _port, 0x00 \
7512   acquire __RLSBmutex##_port \
7513   add __RLSBytesCount##_port, 0x42, _reg \
7514   arrbuild __RLSReadBuf##_port, 0x02, __RLSBytesCount##_port \
7515   set __RLSBytesCount##_port, 1 \
7516   call __ReadLSBytes##_port \
7517   tst EQ, _result, __RLSBResult##_port \
7518   index _pfchar, __RLSReadBuf##_port, NA \
7519   release __RLSBmutex##_port \
7520   compend
7521 
7522 #define __SetHTColor2Mode(_port, _mode, _result) __I2CSendCmd(_port, 0x02, _mode, _result)
7523 
7524 #define __ReadSensorHTColorNum(_port, _value) \
7525   compif EQ, isconst(_port), FALSE \
7526   acquire __RLSBmutex0 \
7527   acquire __RLSBmutex1 \
7528   acquire __RLSBmutex2 \
7529   acquire __RLSBmutex3 \
7530   mov __RLSReadPort, _port \
7531   mov __RLSReadBufVar, __RLSBbufLSWrite1 \
7532   set __RLSBytesCountVar, 1 \
7533   call __ReadLSBytesVar \
7534   index _value, __RLSReadBufVar, NA \
7535   release __RLSBmutex0 \
7536   release __RLSBmutex1 \
7537   release __RLSBmutex2 \
7538   release __RLSBmutex3 \
7539   compelse \
7540   compchk LT, _port, 0x04 \
7541   compchk GTEQ, _port, 0x00 \
7542   acquire __RLSBmutex##_port \
7543   mov __RLSReadBuf##_port, __RLSBbufLSWrite1 \
7544   set __RLSBytesCount##_port, 1 \
7545   call __ReadLSBytes##_port \
7546   index _value, __RLSReadBuf##_port, NA \
7547   release __RLSBmutex##_port \
7548   compend
7549 
7550 #define __ReadSensorHTIRSeekerDir(_port, _value) \
7551   compif EQ, isconst(_port), FALSE \
7552   acquire __RLSBmutex0 \
7553   acquire __RLSBmutex1 \
7554   acquire __RLSBmutex2 \
7555   acquire __RLSBmutex3 \
7556   mov __RLSReadPort, _port \
7557   mov __RLSReadBufVar, __RLSBbufLSWrite1 \
7558   set __RLSBytesCountVar, 1 \
7559   call __ReadLSBytesVar \
7560   index _value, __RLSReadBufVar, NA \
7561   release __RLSBmutex0 \
7562   release __RLSBmutex1 \
7563   release __RLSBmutex2 \
7564   release __RLSBmutex3 \
7565   compelse \
7566   compchk LT, _port, 0x04 \
7567   compchk GTEQ, _port, 0x00 \
7568   acquire __RLSBmutex##_port \
7569   mov __RLSReadBuf##_port, __RLSBbufLSWrite1 \
7570   set __RLSBytesCount##_port, 1 \
7571   call __ReadLSBytes##_port \
7572   index _value, __RLSReadBuf##_port, NA \
7573   release __RLSBmutex##_port \
7574   compend
7575 
7576 #define __ResetSensorHTAngle(_port, _mode, _result) \
7577   compchk EQ, isconst(_mode), TRUE \
7578   __I2CSendCmd(_port, 0x02, _mode, _result) \
7579   compif EQ, _mode, HTANGLE_MODE_CALIBRATE \
7580   wait 30 \
7581   compend
7582 
7583 #define __ReadSensorHTAngle(_port, _Angle, _AccAngle, _RPM, _result) \
7584   compif EQ, isconst(_port), FALSE \
7585   acquire __RLSBmutex0 \
7586   acquire __RLSBmutex1 \
7587   acquire __RLSBmutex2 \
7588   acquire __RLSBmutex3 \
7589   mov __RLSReadPort, _port \
7590   mov __RLSReadBufVar, __RLSBbufLSWrite1 \
7591   set __RLSBytesCountVar, 8 \
7592   call __ReadLSBytesVar \
7593   tst EQ, _result, __RLSBResultVar \
7594   index _Angle, __RLSReadBufVar, NA \
7595   add _Angle, _Angle, _Angle \
7596   index __RLSBytesCountVar, __RLSReadBufVar, 1 \
7597   add _Angle, _Angle, __RLSBytesCountVar \
7598   index _AccAngle, __RLSReadBufVar, 2 \
7599   mul _AccAngle, _AccAngle, 256 \
7600   index __RLSBytesCountVar, __RLSReadBufVar, 3 \
7601   add _AccAngle, _AccAngle, __RLSBytesCountVar \
7602   mul _AccAngle, _AccAngle, 256 \
7603   index __RLSBytesCountVar, __RLSReadBufVar, 4 \
7604   add _AccAngle, _AccAngle, __RLSBytesCountVar \
7605   mul _AccAngle, _AccAngle, 256 \
7606   index __RLSBytesCountVar, __RLSReadBufVar, 5 \
7607   add _AccAngle, _AccAngle, __RLSBytesCountVar \
7608   index _RPM, __RLSReadBufVar, 6 \
7609   mul _RPM, _RPM, 256 \
7610   index __RLSBytesCountVar, __RLSReadBufVar, 7 \
7611   add _RPM, _RPM, __RLSBytesCountVar \
7612   release __RLSBmutex0 \
7613   release __RLSBmutex1 \
7614   release __RLSBmutex2 \
7615   release __RLSBmutex3 \
7616   compelse \
7617   compchk LT, _port, 0x04 \
7618   compchk GTEQ, _port, 0x00 \
7619   acquire __RLSBmutex##_port \
7620   mov __RLSReadBuf##_port, __RLSBbufLSWrite1 \
7621   set __RLSBytesCount##_port, 8 \
7622   call __ReadLSBytes##_port \
7623   tst EQ, _result, __RLSBResult##_port \
7624   index _Angle, __RLSReadBuf##_port, NA \
7625   add _Angle, _Angle, _Angle \
7626   index __RLSBytesCount##_port, __RLSReadBuf##_port, 1 \
7627   add _Angle, _Angle, __RLSBytesCount##_port \
7628   index _AccAngle, __RLSReadBuf##_port, 2 \
7629   mul _AccAngle, _AccAngle, 256 \
7630   index __RLSBytesCount##_port, __RLSReadBuf##_port, 3 \
7631   add _AccAngle, _AccAngle, __RLSBytesCount##_port \
7632   mul _AccAngle, _AccAngle, 256 \
7633   index __RLSBytesCount##_port, __RLSReadBuf##_port, 4 \
7634   add _AccAngle, _AccAngle, __RLSBytesCount##_port \
7635   mul _AccAngle, _AccAngle, 256 \
7636   index __RLSBytesCount##_port, __RLSReadBuf##_port, 5 \
7637   add _AccAngle, _AccAngle, __RLSBytesCount##_port \
7638   index _RPM, __RLSReadBuf##_port, 6 \
7639   mul _RPM, _RPM, 256 \
7640   index __RLSBytesCount##_port, __RLSReadBuf##_port, 7 \
7641   add _RPM, _RPM, __RLSBytesCount##_port \
7642   release __RLSBmutex##_port \
7643   compend
7644 
7645 #define __ReadI2CDeviceInfo(_port, _i2caddr, _info, _strVal) \
7646   compif EQ, isconst(_port), FALSE \
7647   acquire __RLSBmutex0 \
7648   acquire __RLSBmutex1 \
7649   acquire __RLSBmutex2 \
7650   acquire __RLSBmutex3 \
7651   mov __RLSReadPort, _port \
7652   arrbuild __RLSReadBufVar, _i2caddr, _info \
7653   set __RLSBytesCountVar, 8 \
7654   call __ReadLSBytesVar \
7655   mov _strVal, __RLSReadBufVar \
7656   release __RLSBmutex0 \
7657   release __RLSBmutex1 \
7658   release __RLSBmutex2 \
7659   release __RLSBmutex3 \
7660   compelse \
7661   compchk LT, _port, 0x04 \
7662   compchk GTEQ, _port, 0x00 \
7663   acquire __RLSBmutex##_port \
7664   arrbuild __RLSReadBuf##_port, _i2caddr, _info \
7665   set __RLSBytesCount##_port, 8 \
7666   call __ReadLSBytes##_port \
7667   mov _strVal, __RLSReadBuf##_port \
7668   release __RLSBmutex##_port \
7669   compend
7670 
7671 #define __SetSensorMSPressure(_port) \
7672   setin IN_TYPE_REFLECTION, _port, TypeField \
7673   setin IN_MODE_RAW, _port, InputModeField \
7674   __ResetSensor(_port)
7675 
7676 #define __SetSensorMSDRODActive(_port) \
7677   setin IN_TYPE_LIGHT_ACTIVE, _port, TypeField \
7678   setin IN_MODE_PCTFULLSCALE, _port, InputModeField \
7679   __ResetSensor(_port)
7680 
7681 #define __SetSensorMSDRODInactive(_port) \
7682   setin IN_TYPE_LIGHT_INACTIVE, _port, TypeField \
7683   setin IN_MODE_PCTFULLSCALE, _port, InputModeField \
7684   __ResetSensor(_port)
7685 
7686 #define __SetSensorNXTSumoEyesLong(_port) \
7687   setin IN_TYPE_LIGHT_INACTIVE, _port, TypeField \
7688   setin IN_MODE_PCTFULLSCALE, _port, InputModeField \
7689   __ResetSensor(_port) \
7690   wait 275
7691 
7692 #define __SetSensorNXTSumoEyesShort(_port) \
7693   setin IN_TYPE_LIGHT_ACTIVE, _port, TypeField \
7694   setin IN_MODE_PCTFULLSCALE, _port, InputModeField \
7695   __ResetSensor(_port) \
7696   wait 275
7697 
7698 #define __SetSensorMSTouchMux(_port) \
7699   setin IN_TYPE_LIGHT_INACTIVE, _port, TypeField \
7700   setin IN_MODE_RAW, _port, InputModeField \
7701   __ResetSensor(_port)
7702 
7703 #define __ReadSensorMSPressure(_port, _value) \
7704   getin _value, _port, RawValueField \
7705   sub _value, 1024, _value \
7706   div _value, _value, 25
7707 
7708 #define __ReadSensorMSPressureRaw(_port, _value) \
7709   getin _value, _port, RawValueField
7710 
7711 #define __ReadSensorMSDROD(_port, _value) \
7712   getin _value, _port, NormalizedValueField
7713 
7714 #define __ReadSensorNXTSumoEyes(_port, _value) \
7715   getin _value, _port, NormalizedValueField \
7716   mul _value, _value, 100 \
7717   div _value, _value, 1023
7718 
7719 #define __ReadSensorMSCompass(_port, _i2caddr, _value) \
7720   compif EQ, isconst(_port), FALSE \
7721   acquire __RLSBmutex0 \
7722   acquire __RLSBmutex1 \
7723   acquire __RLSBmutex2 \
7724   acquire __RLSBmutex3 \
7725   mov __RLSReadPort, _port \
7726   arrbuild __RLSReadBufVar, _i2caddr, 0x42 \
7727   set __RLSBytesCountVar, 2 \
7728   call __ReadLSBytesVar \
7729   index _value, __RLSReadBufVar, 1 \
7730   index __RLSBytesCountVar, __RLSReadBufVar, NA \
7731   mul _value, _value, 256 \
7732   add _value, _value, __RLSBytesCountVar \
7733   release __RLSBmutex0 \
7734   release __RLSBmutex1 \
7735   release __RLSBmutex2 \
7736   release __RLSBmutex3 \
7737   compelse \
7738   compchk LT, _port, 0x04 \
7739   compchk GTEQ, _port, 0x00 \
7740   acquire __RLSBmutex##_port \
7741   arrbuild __RLSReadBuf##_port, _i2caddr, 0x42 \
7742   set __RLSBytesCount##_port, 2 \
7743   call __ReadLSBytes##_port \
7744   index _value, __RLSReadBuf##_port, 1 \
7745   index __RLSBytesCount##_port, __RLSReadBuf##_port, NA \
7746   mul _value, _value, 256 \
7747   add _value, _value, __RLSBytesCount##_port \
7748   release __RLSBmutex##_port \
7749   compend
7750 
7751 #define __ReadSensorMSRTClock(_port, _sec, _min, _hrs, _dow, _date, _month, _year, _result) \
7752   compif EQ, isconst(_port), FALSE \
7753   acquire __RLSBmutex0 \
7754   acquire __RLSBmutex1 \
7755   acquire __RLSBmutex2 \
7756   acquire __RLSBmutex3 \
7757   mov __RLSReadPort, _port \
7758   arrbuild __RLSReadBufVar, 0xD0, 0x00 \
7759   set __RLSBytesCountVar, 8 \
7760   call __ReadLSBytesVar \
7761   tst EQ, _result, __RLSBResultVar \
7762   index _sec, __RLSReadBufVar, NA \
7763   index _min, __RLSReadBufVar, 1 \
7764   index _hrs, __RLSReadBufVar, 2 \
7765   index _dow, __RLSReadBufVar, 3 \
7766   index _date, __RLSReadBufVar, 4 \
7767   index _month, __RLSReadBufVar, 5 \
7768   index _year, __RLSReadBufVar, 6 \
7769   bcd2dec(_sec, _sec) \
7770   bcd2dec(_min, _min) \
7771   bcd2dec(_hrs, _hrs) \
7772   bcd2dec(_dow, _dow) \
7773   bcd2dec(_date, _date) \
7774   bcd2dec(_month, _month) \
7775   bcd2dec(_year, _year) \
7776   release __RLSBmutex0 \
7777   release __RLSBmutex1 \
7778   release __RLSBmutex2 \
7779   release __RLSBmutex3 \
7780   compelse \
7781   compchk LT, _port, 0x04 \
7782   compchk GTEQ, _port, 0x00 \
7783   acquire __RLSBmutex##_port \
7784   arrbuild __RLSReadBuf##_port, 0xD0, 0x00 \
7785   set __RLSBytesCount##_port, 8 \
7786   call __ReadLSBytes##_port \
7787   tst EQ, _result, __RLSBResult##_port \
7788   index _sec, __RLSReadBuf##_port, NA \
7789   index _min, __RLSReadBuf##_port, 1 \
7790   index _hrs, __RLSReadBuf##_port, 2 \
7791   index _dow, __RLSReadBuf##_port, 3 \
7792   index _date, __RLSReadBuf##_port, 4 \
7793   index _month, __RLSReadBuf##_port, 5 \
7794   index _year, __RLSReadBuf##_port, 6 \
7795   bcd2dec(_sec, _sec) \
7796   bcd2dec(_min, _min) \
7797   bcd2dec(_hrs, _hrs) \
7798   bcd2dec(_dow, _dow) \
7799   bcd2dec(_date, _date) \
7800   bcd2dec(_month, _month) \
7801   bcd2dec(_year, _year) \
7802   release __RLSBmutex##_port \
7803   compend
7804 
7805 #define __ReadSensorMSTilt(_port, _i2caddr, _x, _y, _z, _result) \
7806   compif EQ, isconst(_port), FALSE \
7807   acquire __RLSBmutex0 \
7808   acquire __RLSBmutex1 \
7809   acquire __RLSBmutex2 \
7810   acquire __RLSBmutex3 \
7811   mov __RLSReadPort, _port \
7812   arrbuild __RLSReadBufVar, _i2caddr, 0x42  \
7813   set __RLSBytesCountVar, 3 \
7814   call __ReadLSBytesVar \
7815   tst EQ, _result, __RLSBResultVar \
7816   index _x, __RLSReadBufVar, NA \
7817   index _y, __RLSReadBufVar, 1 \
7818   index _z, __RLSReadBufVar, 2 \
7819   release __RLSBmutex0 \
7820   release __RLSBmutex1 \
7821   release __RLSBmutex2 \
7822   release __RLSBmutex3 \
7823   compelse \
7824   compchk LT, _port, 0x04 \
7825   compchk GTEQ, _port, 0x00 \
7826   acquire __RLSBmutex##_port \
7827   arrbuild __RLSReadBuf##_port, _i2caddr, 0x42 \
7828   set __RLSBytesCount##_port, 3 \
7829   call __ReadLSBytes##_port \
7830   tst EQ, _result, __RLSBResult##_port \
7831   index _x, __RLSReadBuf##_port, NA \
7832   index _y, __RLSReadBuf##_port, 1 \
7833   index _z, __RLSReadBuf##_port, 2 \
7834   release __RLSBmutex##_port \
7835   compend
7836 
7837 #define __ReadSensorMSAccel(_port, _i2caddr, _x, _y, _z, _result) \
7838   compif EQ, isconst(_port), FALSE \
7839   acquire __RLSBmutex0 \
7840   acquire __RLSBmutex1 \
7841   acquire __RLSBmutex2 \
7842   acquire __RLSBmutex3 \
7843   mov __RLSReadPort, _port \
7844   arrbuild __RLSReadBufVar, _i2caddr, 0x45 \
7845   set __RLSBytesCountVar, 6 \
7846   call __ReadLSBytesVar \
7847   tst EQ, _result, __RLSBResultVar \
7848   index _x, __RLSReadBufVar, NA \
7849   index __RLSBytesCountVar, __RLSReadBufVar, 1 \
7850   mul __RLSBytesCountVar, __RLSBytesCountVar, 256 \
7851   add _x, _x, __RLSBytesCountVar \
7852   index _y, __RLSReadBufVar, 2 \
7853   index __RLSBytesCountVar, __RLSReadBufVar, 3 \
7854   mul __RLSBytesCountVar, __RLSBytesCountVar, 256 \
7855   add _y, _y, __RLSBytesCountVar \
7856   index _z, __RLSReadBufVar, 4 \
7857   index __RLSBytesCountVar, __RLSReadBufVar, 5 \
7858   mul __RLSBytesCountVar, __RLSBytesCountVar, 256 \
7859   add _z, _z, __RLSBytesCountVar \
7860   release __RLSBmutex0 \
7861   release __RLSBmutex1 \
7862   release __RLSBmutex2 \
7863   release __RLSBmutex3 \
7864   compelse \
7865   compchk LT, _port, 0x04 \
7866   compchk GTEQ, _port, 0x00 \
7867   acquire __RLSBmutex##_port \
7868   arrbuild __RLSReadBuf##_port, _i2caddr, 0x45 \
7869   set __RLSBytesCount##_port, 6 \
7870   call __ReadLSBytes##_port \
7871   tst EQ, _result, __RLSBResult##_port \
7872   index _x, __RLSReadBuf##_port, NA \
7873   index __RLSBytesCount##_port, __RLSReadBuf##_port, 1 \
7874   mul __RLSBytesCount##_port, __RLSBytesCount##_port, 256 \
7875   add _x, _x, __RLSBytesCount##_port \
7876   index _y, __RLSReadBuf##_port, 2 \
7877   index __RLSBytesCount##_port, __RLSReadBuf##_port, 3 \
7878   mul __RLSBytesCount##_port, __RLSBytesCount##_port, 256 \
7879   add _y, _y, __RLSBytesCount##_port \
7880   index _z, __RLSReadBuf##_port, 4 \
7881   index __RLSBytesCount##_port, __RLSReadBuf##_port, 5 \
7882   mul __RLSBytesCount##_port, __RLSBytesCount##_port, 256 \
7883   add _z, _z, __RLSBytesCount##_port \
7884   release __RLSBmutex##_port \
7885   compend
7886 
7887 #define __PFMateSend(_port, _i2caddr, _channel, _motors, _cmdA, _spdA, _cmdB, _spdB, _result) \
7888   compif EQ, isconst(_port), FALSE \
7889   acquire __RLSBmutex0 \
7890   acquire __RLSBmutex1 \
7891   acquire __RLSBmutex2 \
7892   acquire __RLSBmutex3 \
7893   mov __RLSReadPort, _port \
7894   arrbuild __RLSReadBufVar, _i2caddr, PFMATE_REG_CHANNEL, _channel, _motors, _cmdA, _spdA, _cmdB, _spdB  \
7895   set __RLSBytesCountVar, 1 \
7896   call __ReadLSBytesVar \
7897   arrbuild __RLSReadBufVar, _i2caddr, PFMATE_REG_CMD, PFMATE_CMD_GO  \
7898   set __RLSBytesCountVar, 0 \
7899   call __ReadLSBytesVar \
7900   tst EQ, _result, __RLSBResultVar \
7901   release __RLSBmutex0 \
7902   release __RLSBmutex1 \
7903   release __RLSBmutex2 \
7904   release __RLSBmutex3 \
7905   compelse \
7906   compchk LT, _port, 0x04 \
7907   compchk GTEQ, _port, 0x00 \
7908   acquire __RLSBmutex##_port \
7909   arrbuild __RLSReadBuf##_port, _i2caddr, PFMATE_REG_CHANNEL, _channel, _motors, _cmdA, _spdA, _cmdB, _spdB  \
7910   set __RLSBytesCount##_port, 1 \
7911   call __ReadLSBytes##_port \
7912   arrbuild __RLSReadBuf##_port, _i2caddr, PFMATE_REG_CMD, PFMATE_CMD_GO  \
7913   set __RLSBytesCount##_port, 0 \
7914   call __ReadLSBytes##_port \
7915   tst EQ, _result, __RLSBResult##_port \
7916   release __RLSBmutex##_port \
7917   compend
7918 
7919 #define __PFMateSendRaw(_port, _i2caddr, _channel, _b1, _b2, _result) \
7920   compif EQ, isconst(_port), FALSE \
7921   acquire __RLSBmutex0 \
7922   acquire __RLSBmutex1 \
7923   acquire __RLSBmutex2 \
7924   acquire __RLSBmutex3 \
7925   mov __RLSReadPort, _port \
7926   arrbuild __RLSReadBufVar, _i2caddr, PFMATE_REG_CHANNEL, _channel, 0x00, _b1, _b2  \
7927   set __RLSBytesCountVar, 1 \
7928   call __ReadLSBytesVar \
7929   arrbuild __RLSReadBufVar, _i2caddr, PFMATE_REG_CMD, PFMATE_CMD_RAW  \
7930   set __RLSBytesCountVar, 0 \
7931   call __ReadLSBytesVar \
7932   tst EQ, _result, __RLSBResultVar \
7933   release __RLSBmutex0 \
7934   release __RLSBmutex1 \
7935   release __RLSBmutex2 \
7936   release __RLSBmutex3 \
7937   compelse \
7938   compchk LT, _port, 0x04 \
7939   compchk GTEQ, _port, 0x00 \
7940   acquire __RLSBmutex##_port \
7941   arrbuild __RLSReadBuf##_port, _i2caddr, PFMATE_REG_CHANNEL, _channel, 0x00, _b1, _b2  \
7942   set __RLSBytesCount##_port, 1 \
7943   call __ReadLSBytes##_port \
7944   arrbuild __RLSReadBuf##_port, _i2caddr, PFMATE_REG_CMD, PFMATE_CMD_RAW  \
7945   set __RLSBytesCount##_port, 0 \
7946   call __ReadLSBytes##_port \
7947   tst EQ, _result, __RLSBResult##_port \
7948   release __RLSBmutex##_port \
7949   compend
7950 
7951 
7952 dseg segment
7953   __RLSBbufRFIDInit byte[] 0x04, 0x32
7954   __RLSBbufRFIDData byte[] 0x04, 0x42
7955   __RFIDCount byte
7956   __RFIDCont_Port byte
7957   __RFIDCont_Result byte
7958   __RFIDCont_Output byte[]
7959   __RFIDmutex mutex
7960 dseg ends
7961 
7962 #define __RFIDInit(_port, _result) \
7963   compif EQ, isconst(_port), FALSE \
7964   acquire __RLSBmutex0 \
7965   acquire __RLSBmutex1 \
7966   acquire __RLSBmutex2 \
7967   acquire __RLSBmutex3 \
7968   mov __RLSReadPort, _port \
7969   mov __RLSReadBufVar, __RLSBbufRFIDInit \
7970   set __RLSBytesCountVar, 0 \
7971   call __ReadLSBytesVar \
7972   tst EQ, _result, __RLSBResultVar \
7973   release __RLSBmutex0 \
7974   release __RLSBmutex1 \
7975   release __RLSBmutex2 \
7976   release __RLSBmutex3 \
7977   compelse \
7978   compchk LT, _port, 0x04 \
7979   compchk GTEQ, _port, 0x00 \
7980   acquire __RLSBmutex##_port \
7981   mov __RLSReadBuf##_port, __RLSBbufRFIDInit \
7982   set __RLSBytesCount##_port, 0 \
7983   call __ReadLSBytes##_port \
7984   tst EQ, _result, __RLSBResult##_port \
7985   release __RLSBmutex##_port \
7986   compend
7987 
7988 #define __RFIDMode(_port, _mode, _result) __I2CSendCmd(_port, 0x04, _mode, _result)
7989 #define __RFIDStatus(_port, _result) __MSReadValue(_port, 0x04, 0x32, 1, _result, __RDSD_LSStatus)
7990 #define __RFIDRead(_port, _output, _result) \
7991   set __RFIDCount, 5 \
7992   __ReadI2CBytes(_port, __RLSBbufRFIDData, __RFIDCount, _output, _result)
7993 
7994 #define __RFIDStop(_port, _result) \
7995   __RFIDInit(_port, _result) \
7996   wait 10 \
7997   __RFIDMode(_port, RFID_MODE_STOP, _result)
7998 
7999 #define __RFIDReadSingle(_port, _output, _result) \
8000   __RFIDInit(_port, _result) \
8001   wait 15 \
8002   __RFIDMode(_port, RFID_MODE_SINGLE, _result) \
8003   wait 250 \
8004   __RFIDRead(_port, _output, _result)
8005 
8006 #define __RFIDReadContinuous(_port, _output, _result) \
8007   acquire __RFIDmutex \
8008   mov __RFIDCont_Port, _port \
8009   call __RFIDReadContinuousSub \
8010   mov _output, __RFIDCont_Output \
8011   mov _result, __RFIDCont_Result \
8012   release __RFIDmutex
8013 
8014 #define __NXTServoInit(_port, _i2caddr, _servo, _result) \
8015   __I2CSendCmd(_port, _i2caddr, NXTSERVO_CMD_INIT, _result) \
8016   __I2CSendCmd(_port, _i2caddr, _servo+1, _result)
8017 
8018 #define __NXTServoGotoMacroAddress(_port, _i2caddr, _macro, _result) \
8019   __I2CSendCmd(_port, _i2caddr, NXTSERVO_CMD_GOTO, _result) \
8020   __I2CSendCmd(_port, _i2caddr, _macro, _result)
8021 
8022 #define __NXTServoEditMacro(_port, _i2caddr, _result) \
8023   __I2CSendCmd(_port, _i2caddr, NXTSERVO_CMD_EDIT1, _result) \
8024   __I2CSendCmd(_port, _i2caddr, NXTSERVO_CMD_EDIT2, _result)
8025 
8026 #define __NXTHIDLoadCharacter(_port, _i2caddr, _modifier, _character, _result) \
8027   compif EQ, isconst(_port), FALSE \
8028   acquire __RLSBmutex0 \
8029   acquire __RLSBmutex1 \
8030   acquire __RLSBmutex2 \
8031   acquire __RLSBmutex3 \
8032   mov __RLSReadPort, _port \
8033   arrbuild __RLSReadBufVar, _i2caddr, _modifier, _character \
8034   set __RLSBytesCountVar, 0 \
8035   call __ReadLSBytesVar \
8036   tst EQ, _result, __RLSBResultVar \
8037   release __RLSBmutex0 \
8038   release __RLSBmutex1 \
8039   release __RLSBmutex2 \
8040   release __RLSBmutex3 \
8041   compelse \
8042   compchk LT, _port, 0x04 \
8043   compchk GTEQ, _port, 0x00 \
8044   acquire __RLSBmutex##_port \
8045   arrbuild __RLSReadBuf##_port, _i2caddr, _modifier, _character \
8046   set __RLSBytesCount##_port, 0 \
8047   call __ReadLSBytes##_port \
8048   tst EQ, _result, __RLSBResult##_port \
8049   release __RLSBmutex##_port \
8050   compend
8051 
8052 dseg segment
8053   __WDSC_LSB byte
8054   __WDSC_MSB byte
8055   __WDSC_Port byte
8056   __WDSC_WriteBytes byte[]
8057   __WDSC_SensorAddress byte
8058   __WDSC_SensorRegister byte
8059   __WDSC_ByteCount byte
8060   __WDSC_lswArgs TCommLSWrite
8061   __WDSC_LSStatus sbyte
8062   __WDSC_Result sbyte
8063   __WDSCmutex mutex
8064   __DNRVmutex mutex
8065   __RDSD_Port byte
8066   __RDSD_SensorAddress byte
8067   __RDSD_SensorRegister byte
8068   __RDSD_NumBytesToRead byte
8069   __RDSD_Value sdword
8070   __RDSD_lswArgs TCommLSWrite
8071   __RDSD_lsrArgs TCommLSRead
8072   __RDSD_LSStatus sbyte
8073   __RDSD_bytesRead sdword
8074   __RDSD_PreviousValue sdword
8075   __RDSD_Byte byte
8076 dseg ends
8077 
8078 #define __MSWriteToRegister(_port, _i2caddr, _reg, _bytes, _result) \
8079   acquire __WDSCmutex \
8080   mov __WDSC_Port, _port \
8081   mov __WDSC_SensorAddress, _i2caddr \
8082   set __WDSC_SensorRegister, _reg \
8083   arrbuild __WDSC_WriteBytes, _bytes \
8084   call __MSWriteBytesSub \
8085   mov _result, __WDSC_LSStatus \
8086   release __WDSCmutex
8087 
8088 #define __MSWriteLEIntToRegister(_port, _i2caddr, _reg, _ival, _result) \
8089   acquire __WDSCmutex \
8090   mov __WDSC_Port, _port \
8091   mov __WDSC_SensorAddress, _i2caddr \
8092   set __WDSC_SensorRegister, _reg \
8093   and __WDSC_LSB, _ival, 0xFF \
8094   div __WDSC_MSB, _ival, 0xFF \
8095   arrbuild __WDSC_WriteBytes, __WDSC_LSB, __WDSC_MSB \
8096   call __MSWriteBytesSub \
8097   mov _result, __WDSC_LSStatus \
8098   release __WDSCmutex
8099 
8100 #define __I2CSendCmd(_port, _i2caddr, _cmd, _result) \
8101   __MSWriteToRegister(_port, _i2caddr, I2C_REG_CMD, _cmd, _result)
8102 
8103 #define __TempSendCmd(_port, _cmd, _result) \
8104   __MSWriteToRegister(_port, LEGO_ADDR_TEMP, TEMP_REG_CONFIG, _cmd, _result)
8105 
8106 #define __MSReadValue(_port, _i2caddr, _reg, _bytes, _out, _result) \
8107   acquire __DNRVmutex \
8108   mov __RDSD_Port, _port \
8109   mov __RDSD_SensorAddress, _i2caddr \
8110   mov __RDSD_SensorRegister, _reg \
8111   set __RDSD_NumBytesToRead, _bytes \
8112   call __MSReadLEValueSub \
8113   mov _out, __RDSD_Value \
8114   mov _result, __RDSD_LSStatus \
8115   release __DNRVmutex
8116 
8117 subroutine __RFIDReadContinuousSub
8118   __RFIDInit(__RFIDCont_Port, __RFIDCont_Result)
8119   wait 15
8120   __RFIDStatus(__RFIDCont_Port, __RFIDCont_Result)
8121   brtst GT, __RFIDCont_Endif, __RFIDCont_Result
8122   __RFIDMode(__RFIDCont_Port, RFID_MODE_CONTINUOUS, __RFIDCont_Result)
8123   wait 250
8124 __RFIDCont_Endif:
8125   __RFIDRead(__RFIDCont_Port, __RFIDCont_Output, __RFIDCont_Result)
8126   return
8127 ends
8128 
8129 subroutine __MSWriteBytesSub
8130   mov __WDSC_lswArgs.Port, __WDSC_Port
8131   arrbuild __WDSC_lswArgs.Buffer, __WDSC_SensorAddress, __WDSC_SensorRegister, __WDSC_WriteBytes
8132   set __WDSC_lswArgs.ReturnLen, 0
8133   syscall CommLSWrite, __WDSC_lswArgs
8134 __WDSC_StatusLoop:
8135   __lowspeedCheckStatus(__WDSC_Port, __WDSC_LSStatus)
8136   brtst GT, __WDSC_StatusLoop, __WDSC_LSStatus
8137   return
8138 ends
8139 
8140 subroutine __MSReadLEValueSub
8141   mov __RDSD_lswArgs.Port, __RDSD_Port
8142   arrbuild __RDSD_lswArgs.Buffer, __RDSD_SensorAddress, __RDSD_SensorRegister
8143   mov __RDSD_lswArgs.ReturnLen, __RDSD_NumBytesToRead
8144   syscall CommLSWrite, __RDSD_lswArgs
8145 __RDSD_CheckStatusAfterWriteLoop:
8146   __lowspeedCheckStatus(__RDSD_Port, __RDSD_LSStatus)
8147   brtst GT, __RDSD_CheckStatusAfterWriteLoop, __RDSD_LSStatus
8148   brtst EQ, __RDSD_GoAheadWithRead, __RDSD_LSStatus
8149   jmp __RDSD_ReadError
8150 __RDSD_GoAheadWithRead:
8151   mov __RDSD_lsrArgs.Port, __RDSD_Port
8152   mov __RDSD_lsrArgs.BufferLen, __RDSD_NumBytesToRead
8153   syscall CommLSRead, __RDSD_lsrArgs
8154 __RDSD_CheckStatusAfterReadLoop:
8155   __lowspeedCheckStatus(__RDSD_Port, __RDSD_LSStatus)
8156   brtst GT, __RDSD_CheckStatusAfterReadLoop, __RDSD_LSStatus
8157   arrsize __RDSD_bytesRead, __RDSD_lsrArgs.Buffer
8158   brcmp NEQ, __RDSD_ReadError, __RDSD_bytesRead, __RDSD_NumBytesToRead
8159   brtst EQ, __RDSD_GoAheadAndCalculateValue, __RDSD_LSStatus
8160 __RDSD_ReadError:
8161   mov __RDSD_Value, __RDSD_PreviousValue
8162   jmp __RDSD_ReturnResults
8163 __RDSD_GoAheadAndCalculateValue:
8164   set __RDSD_Value, 0
8165   brcmp EQ, __RDSD_OneByte, __RDSD_NumBytesToRead, 1
8166   brcmp EQ, __RDSD_TwoBytes, __RDSD_NumBytesToRead, 2
8167   brcmp NEQ, __RDSD_ReadError, __RDSD_NumBytesToRead, 4
8168   index __RDSD_Byte, __RDSD_lsrArgs.Buffer, 3
8169   mul __RDSD_Value, __RDSD_Byte, 256
8170   index __RDSD_Byte, __RDSD_lsrArgs.Buffer, 2
8171   add __RDSD_Value, __RDSD_Value, __RDSD_Byte
8172   mul __RDSD_Value, __RDSD_Value, 256
8173 __RDSD_TwoBytes:
8174   index __RDSD_Byte, __RDSD_lsrArgs.Buffer, 1
8175   add __RDSD_Value, __RDSD_Value, __RDSD_Byte
8176   mul __RDSD_Value, __RDSD_Value, 256
8177 __RDSD_OneByte:
8178   index __RDSD_Byte, __RDSD_lsrArgs.Buffer, NA
8179   add __RDSD_Value, __RDSD_Value, __RDSD_Byte
8180   mov __RDSD_PreviousValue, __RDSD_Value
8181 __RDSD_ReturnResults:
8182   return
8183 ends
8184 
8185 #define __ReadSensorMSPlayStation(_port, _i2caddr, _b1, _b2, _xleft, _yleft, _xright, _yright, _result) \
8186   compif EQ, isconst(_port), FALSE \
8187   acquire __RLSBmutex0 \
8188   acquire __RLSBmutex1 \
8189   acquire __RLSBmutex2 \
8190   acquire __RLSBmutex3 \
8191   mov __RLSReadPort, _port \
8192   arrbuild __RLSReadBufVar, _i2caddr, PSP_REG_BTNSET1 \
8193   set __RLSBytesCountVar, 6 \
8194   call __ReadLSBytesVar \
8195   tst EQ, _result, __RLSBResultVar \
8196   index _b1, __RLSReadBufVar, NA \
8197   index _b2, __RLSReadBufVar, 1 \
8198   index _xleft, __RLSReadBufVar, 2 \
8199   index _yleft, __RLSReadBufVar, 3 \
8200   index _xright, __RLSReadBufVar, 4 \
8201   index _yright, __RLSReadBufVar, 5 \
8202   release __RLSBmutex0 \
8203   release __RLSBmutex1 \
8204   release __RLSBmutex2 \
8205   release __RLSBmutex3 \
8206   compelse \
8207   compchk LT, _port, 0x04 \
8208   compchk GTEQ, _port, 0x00 \
8209   acquire __RLSBmutex##_port \
8210   arrbuild __RLSReadBuf##_port, _i2caddr, PSP_REG_BTNSET1 \
8211   set __RLSBytesCount##_port, 6 \
8212   call __ReadLSBytes##_port \
8213   tst EQ, _result, __RLSBResult##_port \
8214   index _b1, __RLSReadBuf##_port, NA \
8215   index _b2, __RLSReadBuf##_port, 1 \
8216   index _xleft, __RLSReadBuf##_port, 2 \
8217   index _yleft, __RLSReadBuf##_port, 3 \
8218   index _xright, __RLSReadBuf##_port, 4 \
8219   index _yright, __RLSReadBuf##_port, 5 \
8220   release __RLSBmutex##_port \
8221   compend
8222 
8223 #define __RunNRLinkMacro(_port, _i2caddr, _macro, _result) \
8224   acquire __WDSCmutex \
8225   mov __WDSC_Port, _port \
8226   mov __WDSC_SensorAddress, _i2caddr \
8227   arrbuild __WDSC_WriteBytes, NRLINK_CMD_RUN_MACRO, _macro \
8228   call __MSWriteBytesSub \
8229   mov _result, __WDSC_LSStatus \
8230   release __WDSCmutex
8231 
8232 #define __ReadNRLinkStatus(_port, _i2caddr, _value, _result) \
8233   compif EQ, isconst(_port), FALSE \
8234   acquire __RLSBmutex0 \
8235   acquire __RLSBmutex1 \
8236   acquire __RLSBmutex2 \
8237   acquire __RLSBmutex3 \
8238   mov __RLSReadPort, _port \
8239   arrbuild __RLSReadBufVar, _i2caddr, I2C_REG_CMD \
8240   set __RLSBytesCountVar, 1 \
8241   call __ReadLSBytesVar \
8242   tst EQ, _result, __RLSBResultVar \
8243   index _value, __RLSReadBufVar, NA \
8244   release __RLSBmutex0 \
8245   release __RLSBmutex1 \
8246   release __RLSBmutex2 \
8247   release __RLSBmutex3 \
8248   compelse \
8249   compchk LT, _port, 0x04 \
8250   compchk GTEQ, _port, 0x00 \
8251   acquire __RLSBmutex##_port \
8252   arrbuild __RLSReadBuf##_port, _i2caddr, I2C_REG_CMD \
8253   set __RLSBytesCount##_port, 1 \
8254   call __ReadLSBytes##_port \
8255   tst EQ, _result, __RLSBResult##_port \
8256   index _value, __RLSReadBuf##_port, NA \
8257   release __RLSBmutex##_port \
8258   compend
8259 
8260 #define __WriteNRLinkBytes(_port, _i2caddr, _bytes, _result) \
8261   __I2CSendCmd(_port, _i2caddr, NRLINK_CMD_FLUSH, _result) \
8262   __MSWriteToRegister(_port, _i2caddr, NRLINK_REG_DATA, _bytes, _result) \
8263   arrsize __WDSC_ByteCount, _bytes \
8264   __MSWriteToRegister(_port, _i2caddr, NRLINK_REG_BYTES, __WDSC_ByteCount, _result)
8265 
8266 #define __ReadNRLinkBytes(_port, _i2caddr, _bytes, _result) \
8267   acquire __DNRVmutex \
8268   compif EQ, isconst(_port), FALSE \
8269   acquire __RLSBmutex0 \
8270   acquire __RLSBmutex1 \
8271   acquire __RLSBmutex2 \
8272   acquire __RLSBmutex3 \
8273   mov __RLSReadPort, _port \
8274   arrbuild __RLSReadBufVar, _i2caddr, NRLINK_REG_BYTES \
8275   set __RLSBytesCountVar, 1 \
8276   call __ReadLSBytesVar \
8277   index __RLSBytesCountVar, __RLSReadBufVar, NA \
8278   arrbuild __RLSReadBufVar, _i2caddr, NRLINK_REG_DATA \
8279   call __ReadLSBytesVar \
8280   tst EQ, _result, __RLSBResultVar \
8281   mov _bytes, __RLSReadBufVar \
8282   release __RLSBmutex0 \
8283   release __RLSBmutex1 \
8284   release __RLSBmutex2 \
8285   release __RLSBmutex3 \
8286   compelse \
8287   compchk LT, _port, 0x04 \
8288   compchk GTEQ, _port, 0x00 \
8289   acquire __RLSBmutex##_port \
8290   arrbuild __RLSReadBuf##_port, _i2caddr, NRLINK_REG_BYTES \
8291   set __RLSBytesCount##_port, 1 \
8292   call __ReadLSBytes##_port \
8293   index __RLSBytesCount##_port, __RLSReadBuf##_port, NA \
8294   arrbuild __RLSReadBuf##_port, _i2caddr, NRLINK_REG_DATA \
8295   call __ReadLSBytes##_port \
8296   tst EQ, _result, __RLSBResult##_port \
8297   mov _bytes, __RLSReadBuf##_port \
8298   release __RLSBmutex##_port \
8299   compend \
8300   __I2CSendCmd(_port, _i2caddr, NRLINK_CMD_FLUSH, _result) \
8301   release __DNRVmutex
8302 
8303 dseg segment
8304   __MSPFByte1 byte
8305   __MSPFByte2 byte
8306 dseg ends
8307 
8308 subroutine __MSPowerFunctionCalcBytes
8309   call __PFCalcChecksum
8310   // build __PFBytes using two values calculated from the __PFNibbles
8311   index __MSPFByte1, __PFNibbles, NA
8312   index __PFTmp, __PFNibbles, 1
8313   mul __MSPFByte1, __MSPFByte1, 16
8314   add __MSPFByte1, __MSPFByte1, __PFTmp
8315   index __MSPFByte2, __PFNibbles, 2
8316   index __PFTmp, __PFNibbles, 3
8317   mul __MSPFByte2, __MSPFByte2, 16
8318   add __MSPFByte2, __MSPFByte2, __PFTmp
8319   arrbuild __PFBytes, __MSPFByte1, __MSPFByte2
8320   return
8321 ends
8322 
8323 #define __MSPFComboDirect(_port, _i2caddr, _channel, _outa, _outb, _result) \
8324   acquire __PFMutex \
8325   mod __PF_p1, _channel, 4 \
8326   mod __PF_p2, _outa, 4 \
8327   mod __PF_p3, _outb, 4 \
8328   call __PFComboDirectSub \
8329   set __PFPowerFuncMode, TRUE \
8330   call __MSPowerFunctionCalcBytes \
8331   __WriteNRLinkBytes(_port, _i2caddr, __PFBytes, _result) \
8332   release __PFMutex
8333 
8334 #define __MSPFSinglePin(_port, _i2caddr, _channel, _out, _pin, _func, _cont, _result) \
8335   acquire __PFMutex \
8336   mod __PF_p1, _channel, 4 \
8337   mod __PF_p2, _out, 2 \
8338   mod __PF_p3, _pin, 2 \
8339   mod __PF_p4, _func, 4 \
8340   set __PF_p5, _cont \
8341   call __PFSinglePinSub \
8342   set __PFPowerFuncMode, TRUE \
8343   call __MSPowerFunctionCalcBytes \
8344   __WriteNRLinkBytes(_port, _i2caddr, __PFBytes, _result) \
8345   release __PFMutex
8346 
8347 #define __MSPFSingleOutput(_port, _i2caddr, _channel, _out, _func, _cst, _result) \
8348   acquire __PFMutex \
8349   mod __PF_p1, _channel, 4 \
8350   mod __PF_p2, _out, 2 \
8351   mod __PF_p3, _func, 16 \
8352   set __PF_p4, _cst \
8353   call __PFSingleOutputSub \
8354   set __PFPowerFuncMode, TRUE \
8355   call __MSPowerFunctionCalcBytes \
8356   __WriteNRLinkBytes(_port, _i2caddr, __PFBytes, _result) \
8357   release __PFMutex
8358 
8359 #define __MSPFComboPWM(_port, _i2caddr, _channel, _outa, _outb, _result) \
8360   acquire __PFMutex \
8361   mod __PF_p1, _channel, 4 \
8362   mod __PF_p2, _outa, 16 \
8363   mod __PF_p3, _outb, 16 \
8364   call __PFComboPWMSub \
8365   set __PFPowerFuncMode, TRUE \
8366   call __MSPowerFunctionCalcBytes \
8367   __WriteNRLinkBytes(_port, _i2caddr, __PFBytes, _result) \
8368   release __PFMutex
8369 
8370 #define __MSIRTrain(_port, _i2caddr, _channel, _func, _PFMode, _result) \
8371   acquire __PFMutex \
8372   mod __PF_p1, _channel, 4 \
8373   mod __PF_p2, _func, 5 \
8374   compif EQ, _PFMode, TRUE \
8375   call __PFTrainSub \
8376   compelse \
8377   call __RCTrainSub \
8378   compend \
8379   set __PFPowerFuncMode, _PFMode \
8380   call __MSPowerFunctionCalcBytes \
8381   __WriteNRLinkBytes(_port, _i2caddr, __PFBytes, _result) \
8382   release __PFMutex
8383 
8384 #define __MSPFRawOutput(_port, _i2caddr, _nibble0, _nibble1, _nibble2, _result) \
8385   acquire __PFMutex \
8386   mod __PF_p1, _nibble0, 7 \
8387   mod __PF_p2, _nibble1, 16 \
8388   mod __PF_p3, _nibble2, 16 \
8389   call __PFRawOutputSub \
8390   set __PFPowerFuncMode, TRUE \
8391   call __MSPowerFunctionCalcBytes \
8392   __WriteNRLinkBytes(_port, _i2caddr, __PFBytes, _result) \
8393   release __PFMutex
8394 
8395 #define __MSPFRepeatLastCommand(_port, _i2caddr, _count, _delay, _result) \
8396   acquire __PFMutex \
8397   mov __PF_p1, _count \
8398   __MSPFRepeatLoop##__I__: \
8399   __WriteNRLinkBytes(_port, _i2caddr, __PFBytes, _result) \
8400   waitv _delay \
8401   sub __PF_p1, __PF_p1, 1 \
8402   brtst GT, __MSPFRepeatLoop##__I__, __PF_p1 \
8403   release __PFMutex \
8404   __IncI__
8405 
8406 subroutine __MSRCXCommandSub
8407   dseg segment
8408     __MSRCSToggle byte
8409     __MSRCSI byte
8410     __MSRCSInCmd byte[]
8411     __MSRCSTmpBuf byte[]
8412     __MSRCSCmdBytes sbyte
8413     __MSRCSCmd byte
8414     __MSRCSCSum byte
8415     __MSRCSMsgBufSize byte
8416     __MSRCSTmpByte byte
8417     __MSRCSTmpSByte sbyte
8418     __MSRCSTmpWord word
8419     __MSRCSTmpByte2 byte
8420     __MSRCSResult byte
8421   dseg ends
8422   arrsize __MSRCSCmdBytes, __gRCXCmd.Command
8423   index __MSRCSCmd, __gRCXCmd.Command, NA
8424   set __MSRCSCSum, 0
8425 
8426   // build the message
8427   set __MSRCSMsgBufSize, 2
8428   mul __MSRCSMsgBufSize, __MSRCSMsgBufSize, __MSRCSCmdBytes
8429   add __MSRCSMsgBufSize, __MSRCSMsgBufSize, 5
8430 
8431   arrinit __MSRCSInCmd, 0, __MSRCSMsgBufSize
8432   replace __MSRCSInCmd, __MSRCSInCmd, NA, 0x55
8433   replace __MSRCSInCmd, __MSRCSInCmd, 1, 0xFF
8434   replace __MSRCSInCmd, __MSRCSInCmd, 2, 0x00
8435   // add cmd and ~cmd bytes
8436   or __MSRCSTmpByte, __MSRCSCmd, __MSRCSToggle
8437   replace __MSRCSInCmd, __MSRCSInCmd, 3, __MSRCSTmpByte
8438   mov __MSRCSCSum, __MSRCSTmpByte
8439   sub __MSRCSTmpByte, 0xFF, __MSRCSCSum
8440   replace __MSRCSInCmd, __MSRCSInCmd, 4, __MSRCSTmpByte
8441 
8442   set __MSRCSI, 0
8443   xor __MSRCSToggle, __MSRCSToggle, 8
8444 
8445   brcmp LTEQ, __MSRCSEndWhileILTCmdBytes, __MSRCSCmdBytes, 1
8446 
8447 __MSRCSWhileILTCmdBytes:
8448   sub __MSRCSTmpByte, __MSRCSCmdBytes, 1
8449   brcmp GTEQ, __MSRCSEndWhileILTCmdBytes, __MSRCSI, __MSRCSTmpByte
8450   add __MSRCSTmpByte, __MSRCSI, 1
8451   index __MSRCSTmpByte2, __gRCXCmd.Command, __MSRCSTmpByte
8452   mul __MSRCSTmpByte, __MSRCSI, 2
8453   add __MSRCSTmpByte, __MSRCSTmpByte, 5
8454   replace __MSRCSInCmd, __MSRCSInCmd, __MSRCSTmpByte, __MSRCSTmpByte2
8455   // calculate checksum
8456   add __MSRCSCSum, __MSRCSCSum, __MSRCSTmpByte2
8457   add __MSRCSTmpByte, __MSRCSTmpByte, 1
8458   sub __MSRCSTmpByte2, 255, __MSRCSTmpByte2
8459   replace __MSRCSInCmd, __MSRCSInCmd, __MSRCSTmpByte, __MSRCSTmpByte2
8460   add __MSRCSI, __MSRCSI, 1
8461   jmp __MSRCSWhileILTCmdBytes
8462 __MSRCSEndWhileILTCmdBytes:
8463 
8464   // add the two checksum bytes
8465   mul __MSRCSTmpByte, __MSRCSI, 2
8466   add __MSRCSTmpByte, __MSRCSTmpByte, 5
8467   replace __MSRCSInCmd, __MSRCSInCmd, __MSRCSTmpByte, __MSRCSCSum
8468   sub __MSRCSTmpByte2, 255, __MSRCSCSum
8469   add __MSRCSTmpByte, __MSRCSTmpByte, 1
8470   replace __MSRCSInCmd, __MSRCSInCmd, __MSRCSTmpByte, __MSRCSTmpByte2
8471 
8472   // if the size of __MSRCSInCmd > 14 then we need to chunk up the transmission
8473   mov __MSRCSTmpSByte, __MSRCSMsgBufSize
8474 __MSRCSWhileMsgBufSizeGTZero:
8475   arrsubset __gRCXCmd.Command, __MSRCSInCmd, NA, 14
8476   arrbuild __MSRCSTmpBuf, __gRCXCmd.Address, 0x42, __gRCXCmd.Command
8477   // write message bytes to the NRLink device
8478   __WriteNRLinkBytes(__gRCXCmd.Port, __gRCXCmd.Address, __MSRCSTmpBuf, __MSRCSResult)
8479   sub __MSRCSTmpSByte, __MSRCSTmpSByte, 14
8480   brtst LTEQ, __MSRCSEndWhileMsgBufSizeGTZero, __MSRCSTmpSByte
8481   arrsubset __MSRCSTmpBuf, __MSRCSInCmd, 14, NA
8482   mov __MSRCSInCmd, __MSRCSTmpBuf
8483   jmp __MSRCSWhileMsgBufSizeGTZero
8484 __MSRCSEndWhileMsgBufSizeGTZero:
8485 
8486   // Now send the IR message
8487   arrbuild __MSRCSTmpBuf, __gRCXCmd.Address, 0x40, __MSRCSMsgBufSize
8488   __WriteNRLinkBytes(__gRCXCmd.Port, __gRCXCmd.Address, __MSRCSTmpBuf, __MSRCSResult)
8489 
8490   // give the message time to be transferred
8491   mul __MSRCSTmpWord, __MSRCSMsgBufSize, 5
8492   waitv __MSRCSTmpWord
8493 
8494   // do we need to read a response?
8495   brtst EQ, __MSRCSNoResponse, __gRCXCmd.ResponseBytes
8496 
8497   // give the message time to be transferred
8498   add __MSRCSTmpWord, __MSRCSMsgBufSize, __gRCXCmd.ResponseBytes
8499   mul __MSRCSTmpWord, __MSRCSTmpWord, 5
8500   waitv __MSRCSTmpWord
8501 
8502   // read the response
8503   __ReadNRLinkBytes(__gRCXCmd.Port, __gRCXCmd.Address, __gRCXCmd.Response, __MSRCSResult)
8504 
8505 __MSRCSNoResponse:
8506   return
8507 ends
8508 
8509 
8510 #define __MSRCXSetNRLink(_port, _i2caddr) \
8511   set __gRCXCmd.Port, _port \
8512   set __gRCXCmd.Address, _i2caddr
8513 
8514 #define __MSRCXPoll(_src, _value, _result) \
8515   acquire __RCXCmdMutex \
8516   arrbuild __gRCXCmd.Command, RCX_PollOp, _src, _value \
8517   set __gRCXCmd.ResponseBytes, 12 \
8518   call __MSRCXCommandSub \
8519   index _result, __gRCXCmd.Response, 4 \
8520   index __MSRCSTmpByte, __gRCXCmd.Response, 2 \
8521   mul _result, _result, 256 \
8522   add _result, _result, __MSRCSTmpByte \
8523   release __RCXCmdMutex
8524 
8525 #define __MSRCXBatteryLevel(_result) \
8526   acquire __RCXCmdMutex \
8527   arrbuild __gRCXCmd.Command, RCX_BatteryLevelOp \
8528   set __gRCXCmd.ResponseBytes, 12 \
8529   call __MSRCXCommandSub \
8530   index _result, __gRCXCmd.Response, 4 \
8531   index __MSRCSTmpByte, __gRCXCmd.Response, 2 \
8532   mul _result, _result, 256 \
8533   add _result, _result, __MSRCSTmpByte \
8534   release __RCXCmdMutex
8535 
8536 #define __MSRCXOpNoArgs(_op) \
8537   acquire __RCXCmdMutex \
8538   arrinit __gRCXCmd.Command, _op, 1 \
8539   set __gRCXCmd.ResponseBytes, 0 \
8540   call __MSRCXCommandSub \
8541   release __RCXCmdMutex
8542 
8543 #define __MSRCXSetOutput(_outputs, _mode) \
8544   acquire __RCXCmdMutex \
8545   add __RCSTmpByte, _outputs, _mode \
8546   arrbuild __gRCXCmd.Command, RCX_OnOffFloatOp, __RCSTmpByte \
8547   set __gRCXCmd.ResponseBytes, 0 \
8548   call __MSRCXCommandSub \
8549   release __RCXCmdMutex
8550 
8551 #define __MSRCXSetDirection(_outputs, _dir) \
8552   acquire __RCXCmdMutex \
8553   add __RCSTmpByte, _outputs, _dir \
8554   arrbuild __gRCXCmd.Command, RCX_OutputDirOp, __RCSTmpByte \
8555   set __gRCXCmd.ResponseBytes, 0 \
8556   call __MSRCXCommandSub \
8557   release __RCXCmdMutex
8558 
8559 #define __MSRCXSetPower(_outputs, _pwrsrc, _pwrval) \
8560   acquire __RCXCmdMutex \
8561   arrbuild __gRCXCmd.Command, RCX_OutputPowerOp, _outputs, _pwrsrc, _pwrval \
8562   set __gRCXCmd.ResponseBytes, 0 \
8563   call __MSRCXCommandSub \
8564   release __RCXCmdMutex
8565 
8566 #define __MSRCXOnFwd(_outputs) \
8567   __MSRCXSetDirection(_outputs, RCX_OUT_FWD) \
8568   __MSRCXSetOutput(_outputs, RCX_OUT_ON)
8569 
8570 #define __MSRCXOnRev(_outputs) \
8571   __MSRCXSetDirection(_outputs, RCX_OUT_REV) \
8572   __MSRCXSetOutput(_outputs, RCX_OUT_ON)
8573 
8574 #define __MSRCXOnFor(_outputs, _ms) \
8575   __MSRCXSetOutput(_outputs, RCX_OUT_ON) \
8576   waitv _ms \
8577   __MSRCXSetOutput(_outputs, RCX_OUT_OFF)
8578 
8579 #define __MSRCXSetTxPower(_pwr) \
8580   acquire __RCXCmdMutex \
8581   arrbuild __gRCXCmd.Command, RCX_IRModeOp, _pwr \
8582   set __gRCXCmd.ResponseBytes, 0 \
8583   call __MSRCXCommandSub \
8584   release __RCXCmdMutex
8585 
8586 #define __MSRCXPlaySound(_snd) \
8587   acquire __RCXCmdMutex \
8588   arrbuild __gRCXCmd.Command, RCX_PlaySoundOp, _snd \
8589   set __gRCXCmd.ResponseBytes, 0 \
8590   call __MSRCXCommandSub \
8591   release __RCXCmdMutex
8592 
8593 #define __MSRCXDeleteTask(_t) \
8594   acquire __RCXCmdMutex \
8595   arrbuild __gRCXCmd.Command, RCX_DeleteTaskOp, _t \
8596   set __gRCXCmd.ResponseBytes, 0 \
8597   call __MSRCXCommandSub \
8598   release __RCXCmdMutex
8599 
8600 #define __MSRCXStartTask(_t) \
8601   acquire __RCXCmdMutex \
8602   arrbuild __gRCXCmd.Command, RCX_StartTaskOp, _t \
8603   set __gRCXCmd.ResponseBytes, 0 \
8604   call __MSRCXCommandSub \
8605   release __RCXCmdMutex
8606 
8607 #define __MSRCXStopTask(_t) \
8608   acquire __RCXCmdMutex \
8609   arrbuild __gRCXCmd.Command, RCX_StopTaskOp, _t \
8610   set __gRCXCmd.ResponseBytes, 0 \
8611   call __MSRCXCommandSub \
8612   release __RCXCmdMutex
8613 
8614 #define __MSRCXSelectProgram(_prog) \
8615   acquire __RCXCmdMutex \
8616   arrbuild __gRCXCmd.Command, RCX_SelectProgramOp, _prog \
8617   set __gRCXCmd.ResponseBytes, 0 \
8618   call __MSRCXCommandSub \
8619   release __RCXCmdMutex
8620 
8621 #define __MSRCXClearTimer(_timer) \
8622   acquire __RCXCmdMutex \
8623   arrbuild __gRCXCmd.Command, RCX_ClearTimerOp, _timer \
8624   set __gRCXCmd.ResponseBytes, 0 \
8625   call __MSRCXCommandSub \
8626   release __RCXCmdMutex
8627 
8628 #define __MSRCXSetSleepTime(_t) \
8629   acquire __RCXCmdMutex \
8630   arrbuild __gRCXCmd.Command, RCX_AutoOffOp, _t \
8631   set __gRCXCmd.ResponseBytes, 0 \
8632   call __MSRCXCommandSub \
8633   release __RCXCmdMutex
8634 
8635 #define __MSRCXDeleteSub(_s) \
8636   acquire __RCXCmdMutex \
8637   arrbuild __gRCXCmd.Command, RCX_DeleteSubOp, _s \
8638   set __gRCXCmd.ResponseBytes, 0 \
8639   call __MSRCXCommandSub \
8640   release __RCXCmdMutex
8641 
8642 #define __MSRCXClearSensor(_port) \
8643   acquire __RCXCmdMutex \
8644   arrbuild __gRCXCmd.Command, RCX_ClearSensorOp, _port \
8645   set __gRCXCmd.ResponseBytes, 0 \
8646   call __MSRCXCommandSub \
8647   release __RCXCmdMutex
8648 
8649 #define __MSRCXPlayToneVar(_varnum, _duration) \
8650   acquire __RCXCmdMutex \
8651   arrbuild __gRCXCmd.Command, RCX_PlayToneVarOp, _varnum, _duration \
8652   set __gRCXCmd.ResponseBytes, 0 \
8653   call __MSRCXCommandSub \
8654   release __RCXCmdMutex
8655 
8656 #define __MSRCXSetWatch(_hours, _minutes) \
8657   acquire __RCXCmdMutex \
8658   arrbuild __gRCXCmd.Command, RCX_SetWatchOp, _hours, _minutes \
8659   set __gRCXCmd.ResponseBytes, 0 \
8660   call __MSRCXCommandSub \
8661   release __RCXCmdMutex
8662 
8663 #define __MSRCXSetSensorType(_port, _type) \
8664   acquire __RCXCmdMutex \
8665   arrbuild __gRCXCmd.Command, RCX_InputTypeOp, _port, _type \
8666   set __gRCXCmd.ResponseBytes, 0 \
8667   call __MSRCXCommandSub \
8668   release __RCXCmdMutex
8669 
8670 #define __MSRCXSetSensorMode(_port, _mode) \
8671   acquire __RCXCmdMutex \
8672   arrbuild __gRCXCmd.Command, RCX_InputModeOp, _port, _mode \
8673   set __gRCXCmd.ResponseBytes, 0 \
8674   call __MSRCXCommandSub \
8675   release __RCXCmdMutex
8676 
8677 #define __MSRCXCreateDatalog(_size) \
8678   acquire __RCXCmdMutex \
8679   and __MSRCSTmpByte, _size, 0xFF \
8680   div __MSRCSTmpByte2, _size, 256 \
8681   arrbuild __gRCXCmd.Command, RCX_SetDatalogOp, __MSRCSTmpByte, __MSRCSTmpByte2 \
8682   set __gRCXCmd.ResponseBytes, 0 \
8683   call __MSRCXCommandSub \
8684   release __RCXCmdMutex
8685 
8686 #define __MSRCXAddToDatalog(_src, _value) \
8687   acquire __RCXCmdMutex \
8688   arrbuild __gRCXCmd.Command, RCX_DatalogOp, _src, _value \
8689   set __gRCXCmd.ResponseBytes, 0 \
8690   call __MSRCXCommandSub \
8691   release __RCXCmdMutex
8692 
8693 #define __MSRCXSendSerial(_first, _count) \
8694   acquire __RCXCmdMutex \
8695   arrbuild __gRCXCmd.Command, RCX_SendUARTDataOp, _first, _count \
8696   set __gRCXCmd.ResponseBytes, 0 \
8697   call __MSRCXCommandSub \
8698   release __RCXCmdMutex
8699 
8700 #define __MSRCXRemote(_cmd) \
8701   acquire __RCXCmdMutex \
8702   and __MSRCSTmpByte, _cmd, 0xFF \
8703   div __MSRCSTmpByte2, _cmd, 256 \
8704   arrbuild __gRCXCmd.Command, RCX_RemoteOp, __MSRCSTmpByte, __MSRCSTmpByte2 \
8705   set __gRCXCmd.ResponseBytes, 0 \
8706   call __MSRCXCommandSub \
8707   release __RCXCmdMutex
8708 
8709 #define __MSRCXEvent(_src, _value) \
8710   acquire __RCXCmdMutex \
8711   and __MSRCSTmpByte, _value, 0xFF \
8712   div __MSRCSTmpByte2, _value, 256 \
8713   arrbuild __gRCXCmd.Command, RCX_DirectEventOp, _src, __MSRCSTmpByte, __MSRCSTmpByte2 \
8714   set __gRCXCmd.ResponseBytes, 0 \
8715   call __MSRCXCommandSub \
8716   release __RCXCmdMutex
8717 
8718 #define __MSRCXPlayTone(_freq, _duration) \
8719   acquire __RCXCmdMutex \
8720   and __MSRCSTmpByte, _freq, 0xFF \
8721   div __MSRCSTmpByte2, _freq, 256 \
8722   arrbuild __gRCXCmd.Command, RCX_PlayToneOp, __MSRCSTmpByte, __MSRCSTmpByte2, _duration \
8723   set __gRCXCmd.ResponseBytes, 0 \
8724   call __MSRCXCommandSub \
8725   release __RCXCmdMutex
8726 
8727 #define __MSRCXSelectDisplay(_src, _value) \
8728   acquire __RCXCmdMutex \
8729   and __MSRCSTmpByte, _value, 0xFF \
8730   div __MSRCSTmpByte2, _value, 256 \
8731   arrbuild __gRCXCmd.Command, RCX_DisplayOp, _src, __MSRCSTmpByte, __MSRCSTmpByte2 \
8732   set __gRCXCmd.ResponseBytes, 0 \
8733   call __MSRCXCommandSub \
8734   release __RCXCmdMutex
8735 
8736 #define __MSRCXPollMemory(_memaddress, _result) \
8737   acquire __RCXCmdMutex \
8738   and __MSRCSTmpByte, _memaddress, 0xFF \
8739   div __MSRCSTmpByte2, _memaddress, 256 \
8740   arrbuild __gRCXCmd.Command, RCX_PollMemoryOp, __MSRCSTmpByte, __MSRCSTmpByte2, 1 \
8741   set __gRCXCmd.ResponseBytes, 12 \
8742   call __MSRCXCommandSub \
8743   index _result, __gRCXCmd.Response, 4 \
8744   index __MSRCSTmpByte, __gRCXCmd.Response, 2 \
8745   mul _result, _result, 256 \
8746   add _result, _result, __MSRCSTmpByte \
8747   release __RCXCmdMutex
8748 
8749 #define __MSRCXSetEvent(_evt, _src, _type) \
8750   acquire __RCXCmdMutex \
8751   arrbuild __gRCXCmd.Command, RCX_SetEventOp, _evt, _src, _type \
8752   set __gRCXCmd.ResponseBytes, 0 \
8753   call __MSRCXCommandSub \
8754   release __RCXCmdMutex
8755 
8756 #define __MSRCXSetGlobalOutput(_outputs, _mode) \
8757   acquire __RCXCmdMutex \
8758   add __MSRCSTmpByte, _outputs, _mode \
8759   arrbuild __gRCXCmd.Command, RCX_GOutputModeOp, __MSRCSTmpByte \
8760   set __gRCXCmd.ResponseBytes, 0 \
8761   call __MSRCXCommandSub \
8762   release __RCXCmdMutex
8763 
8764 #define __MSRCXSetGlobalDirection(_outputs, _dir) \
8765   acquire __RCXCmdMutex \
8766   add __MSRCSTmpByte, _outputs, _dir \
8767   arrbuild __gRCXCmd.Command, RCX_GOutputDirOp, __MSRCSTmpByte \
8768   set __gRCXCmd.ResponseBytes, 0 \
8769   call __MSRCXCommandSub \
8770   release __RCXCmdMutex
8771 
8772 #define __MSRCXSetMaxPower(_outputs, _pwrsrc, _pwrval) \
8773   acquire __RCXCmdMutex \
8774   arrbuild __gRCXCmd.Command, RCX_GOutputPowerOp, _outputs, _pwrsrc, _pwrval \
8775   set __gRCXCmd.ResponseBytes, 0 \
8776   call __MSRCXCommandSub \
8777   release __RCXCmdMutex
8778 
8779 #define __MSRCXCalibrateEvent(_evt, _low, _hi, _hyst) \
8780   acquire __RCXCmdMutex \
8781   arrbuild __gRCXCmd.Command, RCX_CalibrateEventOp, _evt, _low, _hi, _hyst \
8782   set __gRCXCmd.ResponseBytes, 0 \
8783   call __MSRCXCommandSub \
8784   release __RCXCmdMutex
8785 
8786 #define __RCXVarOp(_op, _vnum, _src, _val) \
8787   acquire __RCXCmdMutex \
8788   and __MSRCSTmpByte, _val, 0xFF \
8789   div __MSRCSTmpByte2, _val, 256 \
8790   arrbuild __gRCXCmd.Command, _op, _vnum, _src, __MSRCSTmpByte, __MSRCSTmpByte2 \
8791   set __gRCXCmd.ResponseBytes, 0 \
8792   call __MSRCXCommandSub \
8793   release __RCXCmdMutex
8794 
8795 #define __MSRCXSet(_dstsrc, _dstval, _src, _value) \
8796   acquire __RCXCmdMutex \
8797   and __MSRCSTmpByte, _value, 0xFF \
8798   div __MSRCSTmpByte2, _value, 256 \
8799   arrbuild __gRCXCmd.Command, RCX_SetSourceValueOp, _dstsrc, _dstval, _src, __MSRCSTmpByte, __MSRCSTmpByte2 \
8800   set __gRCXCmd.ResponseBytes, 0 \
8801   call __MSRCXCommandSub \
8802   release __RCXCmdMutex
8803 
8804 #define __MSRCXUnlock() \
8805   acquire __RCXCmdMutex \
8806   arrbuild __gRCXCmd.Command, RCX_UnlockOp, 1, 3, 5, 7, 11 \
8807   set __gRCXCmd.ResponseBytes, 16 \
8808   call __MSRCXCommandSub \
8809   release __RCXCmdMutex
8810 
8811 #define __MSRCXReset() \
8812   acquire __RCXCmdMutex \
8813   arrbuild __gRCXCmd.Command, RCX_BootModeOp, 1, 3, 5, 7, 11 \
8814   set __gRCXCmd.ResponseBytes, 0 \
8815   call __MSRCXCommandSub \
8816   release __RCXCmdMutex
8817 
8818 #define __MSRCXBoot() \
8819   acquire __RCXCmdMutex \
8820   arrbuild __gRCXCmd.Command, RCX_UnlockFirmOp, 0x4c, 0x45, 0x47, 0x4F, 0xAE \
8821   set __gRCXCmd.ResponseBytes, 0 \
8822   call __MSRCXCommandSub \
8823   release __RCXCmdMutex
8824 
8825 #define __MSRCXSetUserDisplay(_src, _value, _precision) \
8826   acquire __RCXCmdMutex \
8827   and __MSRCSTmpByte, _value, 0xFF \
8828   div __MSRCSTmpByte2, _value, 256 \
8829   arrbuild __gRCXCmd.Command, RCX_ViewSourceValOp, 0, _precision, _src, __MSRCSTmpByte, __MSRCSTmpByte2 \
8830   set __gRCXCmd.ResponseBytes, 0 \
8831   call __MSRCXCommandSub \
8832   release __RCXCmdMutex
8833 
8834 #define __MSRCXIncCounter(_counter) \
8835   acquire __RCXCmdMutex \
8836   arrbuild __gRCXCmd.Command, RCX_IncCounterOp, _counter \
8837   set __gRCXCmd.ResponseBytes, 0 \
8838   call __MSRCXCommandSub \
8839   release __RCXCmdMutex
8840 
8841 #define __MSRCXDecCounter(_counter) \
8842   acquire __RCXCmdMutex \
8843   arrbuild __gRCXCmd.Command, RCX_DecCounterOp, _counter \
8844   set __gRCXCmd.ResponseBytes, 0 \
8845   call __MSRCXCommandSub \
8846   release __RCXCmdMutex
8847 
8848 #define __MSRCXClearCounter(_counter) \
8849   acquire __RCXCmdMutex \
8850   arrbuild __gRCXCmd.Command, RCX_ClearCounterOp, _counter \
8851   set __gRCXCmd.ResponseBytes, 0 \
8852   call __MSRCXCommandSub \
8853   release __RCXCmdMutex
8854 
8855 #define __MSRCXSetPriority(_p) \
8856   acquire __RCXCmdMutex \
8857   arrbuild __gRCXCmd.Command, RCX_SetPriorityOp, _p \
8858   set __gRCXCmd.ResponseBytes, 0 \
8859   call __MSRCXCommandSub \
8860   release __RCXCmdMutex
8861 
8862 #define __MSRCXSetMessage(_msg) \
8863   acquire __RCXCmdMutex \
8864   arrbuild __gRCXCmd.Command, RCX_MessageOp, _msg \
8865   set __gRCXCmd.ResponseBytes, 0 \
8866   call __MSRCXCommandSub \
8867   release __RCXCmdMutex
8868 
8869 #define __MSScoutSetScoutMode(_mode) \
8870   acquire __RCXCmdMutex \
8871   arrbuild __gRCXCmd.Command, RCX_ScoutOp, _mode \
8872   set __gRCXCmd.ResponseBytes, 0 \
8873   call __MSRCXCommandSub \
8874   release __RCXCmdMutex
8875 
8876 #define __MSScoutSetScoutRules(_m, _t, _l, _tm, _fx) \
8877   acquire __RCXCmdMutex \
8878   arrbuild __gRCXCmd.Command, RCX_ScoutRulesOp, _m, _t, _l, _tm, _fx \
8879   set __gRCXCmd.ResponseBytes, 0 \
8880   call __MSRCXCommandSub \
8881   release __RCXCmdMutex
8882 
8883 #define __MSScoutSendVLL(_src, _value) \
8884   acquire __RCXCmdMutex \
8885   arrbuild __gRCXCmd.Command, RCX_VLLOp, _src, _value \
8886   set __gRCXCmd.ResponseBytes, 0 \
8887   call __MSRCXCommandSub \
8888   release __RCXCmdMutex
8889 
8890 #define __MSScoutSetSensorClickTime(_src, _value) \
8891   acquire __RCXCmdMutex \
8892   and __MSRCSTmpByte, _value, 0xFF \
8893   div __MSRCSTmpByte2, _value, 256 \
8894   arrbuild __gRCXCmd.Command, RCX_LSBlinkTimeOp, _src, __MSRCSTmpByte, __MSRCSTmpByte2 \
8895   set __gRCXCmd.ResponseBytes, 0 \
8896   call __MSRCXCommandSub \
8897   release __RCXCmdMutex
8898 
8899 #define __MSScoutSetSensorHysteresis(_src, _value) \
8900   acquire __RCXCmdMutex \
8901   and __MSRCSTmpByte, _value, 0xFF \
8902   div __MSRCSTmpByte2, _value, 256 \
8903   arrbuild __gRCXCmd.Command, RCX_LSHysteresisOp, _src, __MSRCSTmpByte, __MSRCSTmpByte2 \
8904   set __gRCXCmd.ResponseBytes, 0 \
8905   call __MSRCXCommandSub \
8906   release __RCXCmdMutex
8907 
8908 #define __MSScoutSetSensorLowerLimit(_src, _value) \
8909   acquire __RCXCmdMutex \
8910   and __MSRCSTmpByte, _value, 0xFF \
8911   div __MSRCSTmpByte2, _value, 256 \
8912   arrbuild __gRCXCmd.Command, RCX_LSLowerThreshOp, _src, __MSRCSTmpByte, __MSRCSTmpByte2 \
8913   set __gRCXCmd.ResponseBytes, 0 \
8914   call __MSRCXCommandSub \
8915   release __RCXCmdMutex
8916 
8917 #define __MSScoutSetSensorUpperLimit(_src, _value) \
8918   acquire __RCXCmdMutex \
8919   and __MSRCSTmpByte, _value, 0xFF \
8920   div __MSRCSTmpByte2, _value, 256 \
8921   arrbuild __gRCXCmd.Command, RCX_LSUpperThreshOp, _src, __MSRCSTmpByte, __MSRCSTmpByte2 \
8922   set __gRCXCmd.ResponseBytes, 0 \
8923   call __MSRCXCommandSub \
8924   release __RCXCmdMutex
8925 
8926 #define __MSScoutSetEventFeedback(_src, _value) \
8927   acquire __RCXCmdMutex \
8928   and __MSRCSTmpByte, _value, 0xFF \
8929   div __MSRCSTmpByte2, _value, 256 \
8930   arrbuild __gRCXCmd.Command, RCX_SetFeedbackOp, _src, __MSRCSTmpByte, __MSRCSTmpByte2 \
8931   set __gRCXCmd.ResponseBytes, 0 \
8932   call __MSRCXCommandSub \
8933   release __RCXCmdMutex
8934 
8935 #define __MSScoutSetCounterLimit(_ctr, _src, _value) \
8936   acquire __RCXCmdMutex \
8937   and __MSRCSTmpByte, _value, 0xFF \
8938   div __MSRCSTmpByte2, _value, 256 \
8939   arrbuild __gRCXCmd.Command, RCX_SetCounterOp, _ctr, _src, __MSRCSTmpByte, __MSRCSTmpByte2 \
8940   set __gRCXCmd.ResponseBytes, 0 \
8941   call __MSRCXCommandSub \
8942   release __RCXCmdMutex
8943 
8944 #define __MSScoutSetTimerLimit(_tmr, _src, _value) \
8945   acquire __RCXCmdMutex \
8946   and __MSRCSTmpByte, _value, 0xFF \
8947   div __MSRCSTmpByte2, _value, 256 \
8948   arrbuild __gRCXCmd.Command, RCX_SetTimerLimitOp, _tmr, _src, __MSRCSTmpByte, __MSRCSTmpByte2 \
8949   set __gRCXCmd.ResponseBytes, 0 \
8950   call __MSRCXCommandSub \
8951   release __RCXCmdMutex
8952 
8953 #define __MSScoutMuteSound() \
8954   acquire __RCXCmdMutex \
8955   arrbuild __gRCXCmd.Command, RCX_SoundOp, 0x80 \
8956   set __gRCXCmd.ResponseBytes, 0 \
8957   call __MSRCXCommandSub \
8958   release __RCXCmdMutex
8959 
8960 #define __MSScoutUnmuteSound() \
8961   acquire __RCXCmdMutex \
8962   arrbuild __gRCXCmd.Command, RCX_SoundOp, 0xc0 \
8963   set __gRCXCmd.ResponseBytes, 0 \
8964   call __MSRCXCommandSub \
8965   release __RCXCmdMutex
8966 
8967 #define __MSScoutSelectSounds(_grp) \
8968   acquire __RCXCmdMutex \
8969   arrbuild __gRCXCmd.Command, RCX_SoundOp, _grp \
8970   set __gRCXCmd.ResponseBytes, 0 \
8971   call __MSRCXCommandSub \
8972   release __RCXCmdMutex
8973 
8974 #define __MSScoutSetLight(_x) \
8975   acquire __RCXCmdMutex \
8976   arrbuild __gRCXCmd.Command, RCX_LightOp, _x \
8977   set __gRCXCmd.ResponseBytes, 0 \
8978   call __MSRCXCommandSub \
8979   release __RCXCmdMutex
8980 
8981 #define __glInit()                                                                             \
8982          call     __GL_glInit
8983 
8984 #define __glSet(_glType, _glValue)                                                             \
8985          mov      __GL_glSettingType,         _glType                                          \
8986          mov      __GL_glSettingValue,        _glValue                                         \
8987          call     __GL_glSet
8988 
8989 #define __glBeginObject(_glObjId)                                                              \
8990          mov      __GL_object.firstVertex,    __GL_vertexCount                                 \
8991          mov      __GL_object.lastVertex,     __GL_vertexCount                                 \
8992          mov      __GL_object.firstPolygon,   __GL_polygonCount                                \
8993          mov      _glObjId,                   __GL_objectCount
8994 
8995 #define __glEndObject()                                                                        \
8996          call     __GL_glEndObject
8997 
8998 #define __glObjectAction(_glObjectId, _glAction, _glValue)                                     \
8999          mov      __GL_objectIndex,           _glObjectId                                      \
9000          mov      __GL_action,                _glAction                                        \
9001          mov      __GL_value,                 _glValue                                         \
9002          call     __GL_glObjectAction
9003 
9004 #define __glAddVertex(_glX, _glY, _glZ)                                                        \
9005          mov      __GL_vertex0.orig.x,        _glX                                             \
9006          mov      __GL_vertex0.orig.y,        _glY                                             \
9007          mov      __GL_vertex0.orig.z,        _glZ                                             \
9008          call     __GL_glAddVertex
9009 
9010 #define __glBegin(_glBeginMode)                                                                \
9011          mov      __GL_polygon.beginMode,     _glBeginMode                                     \
9012          mov      __GL_polygon.firstVertex,   __GL_pvDataCount                                 \
9013          mov      __GL_polygon.lastVertex,    __GL_pvDataCount
9014 
9015 #define __glEnd()                                                                              \
9016          call     __GL_glEnd
9017 
9018 #define __glBeginRender()                                                                      \
9019          call     __GL_glResetObjects
9020 
9021 #define __glCallObject(_glObjectId)                                                            \
9022          mov      __GL_objectIndex,           _glObjectId                                      \
9023          call     __GL_glCallObject
9024 
9025 #define __glFinishRender()                                                                     \
9026          call     __GL_glRotateVertexList                                                      \
9027          set      __GL_glDrawPoint.Location.X, 200                                             \
9028          set      __GL_glDrawPoint.Options,    DRAW_OPT_CLEAR_WHOLE_SCREEN                     \
9029          syscall  DrawPoint,                   __GL_glDrawPoint                                \
9030          call     __GL_glRenderObjects
9031 
9032 #define __glSetAngleX(_glValue)                                                                \
9033          add      __GL_angleX,                _glValue,    3600                                \
9034          mod      __GL_angleX,                __GL_angleX, 360
9035 
9036 #define __glAddToAngleX(_glValue)                                                              \
9037          add      __GL_angleX,                __GL_angleX, _glValue                            \
9038          add      __GL_angleX,                __GL_angleX, 3600                                \
9039          mod      __GL_angleX,                __GL_angleX, 360
9040 
9041 #define __glSetAngleY(_glValue)                                                                \
9042          add      __GL_angleY,                _glValue,    3600                                \
9043          mod      __GL_angleY,                __GL_angleY, 360
9044 
9045 #define __glAddToAngleY(_glValue)                                                              \
9046          add      __GL_angleY,                __GL_angleY, _glValue                            \
9047          add      __GL_angleY,                __GL_angleY, 3600                                \
9048          mod      __GL_angleY,                __GL_angleY, 360
9049 
9050 #define __glSetAngleZ(_glValue)                                                                \
9051          add      __GL_angleZ,                _glValue,    3600                                \
9052          mod      __GL_angleZ,                __GL_angleZ, 360
9053 
9054 #define __glAddToAngleZ(_glValue)                                                              \
9055          add      __GL_angleZ,                __GL_angleZ, _glValue                            \
9056          add      __GL_angleZ,                __GL_angleZ, 3600                                \
9057          mod      __GL_angleZ,                __GL_angleZ, 360
9058 
9059 #define __glSin32768(_glAngle, _glResult)                                                      \
9060          mov      __GL_angle,                 _glAngle                                         \
9061          mod      __GL_angle,                 __GL_angle, 360                                  \
9062          index    _glResult,                  __GL_SIN_TABLE, __GL_angle
9063 
9064 #define __glCos32768(_glAngle, _glResult)                                                      \
9065          mov      __GL_angle,                 _glAngle                                         \
9066          add      __GL_angle,                 __GL_angle, 90                                   \
9067          mod      __GL_angle,                 __GL_angle, 360                                  \
9068          index    _glResult,                  __GL_SIN_TABLE, __GL_angle
9069 
9070 #define __glBox(_glMode, _glSizeX, _glSizeY, _glSizeZ, _glObjId)                               \
9071          mov      __GL_mode                   _glMode                                          \
9072          mov      __GL_sizeX                  _glSizeX                                         \
9073          mov      __GL_sizeY                  _glSizeY                                         \
9074          mov      __GL_sizeZ                  _glSizeZ                                         \
9075          call     __GL_glBox                                                                   \
9076          mov      _glObjId,                   __GL_tmpId
9077 
9078 #define __glPyramid(_glMode, _glSizeX, _glSizeY, _glSizeZ, _glOjbId)                           \
9079          mov      __GL_mode                   _glMode                                          \
9080          mov      __GL_sizeX                  _glSizeX                                         \
9081          mov      __GL_sizeY                  _glSizeY                                         \
9082          mov      __GL_sizeZ                  _glSizeZ                                         \
9083          call     __GL_glPyramid                                                               \
9084          mov      _glObjId,                   __GL_tmpId
9085 
9086 //-----------------------------------------------------------------------------------------
9087 //
9088 // Private definitions...
9089 //
9090 //-----------------------------------------------------------------------------------------
9091 #define __glRangeCheck(_glValue, _glMaxValue, _glErrorMsg)                                     \
9092          mov      __GL_glRangeValue,          _glValue                                         \
9093          mov      __GL_glRangeMaxValue,       _glMaxValue                                      \
9094          mov      __GL_glRangeErrorMsg,       _glErrorMsg                                      \
9095          call     __GL_glRangeCheck
9096 
9097 // Data sizes...
9098 #define __GL_MAX_VERTICES       256
9099 #define __GL_MAX_LINES          256
9100 #define __GL_MAX_POLYGONS       128
9101 #define __GL_MAX_OBJECT_ACTIONS  32
9102 #define __GL_MAX_OBJECTS         16
9103 #define __GL_MAX_PV_DATA        256
9104 #define __GL_MAX_PL_DATA        256
9105 
9106 dseg segment
9107   // Sine table constants...
9108   __GL_SIN_TABLE sword[] 0,572,1144,1715,2286,2856,3425,3993,4560,5126,5690,6252,6813,7371,7927,   \
9109  8481,9032,9580,10126,10668,11207,11743,12275,12803,13328,13848,14365,14876,15384,15886,16384,     \
9110  16877,17364,17847,18324,18795,19261,19720,20174,20622,21063,21498,21926,22348,22763,23170,23571,  \
9111  23965,24351,24730,25102,25466,25822,26170,26510,26842,27166,27482,27789,28088,28378,28660,28932,  \
9112  29197,29452,29698,29935,30163,30382,30592,30792,30983,31164,31336,31499,31651,31795,31928,32052,  \
9113  32166,32270,32365,32449,32524,32588,32643,32688,32723,32748,32763,32767,32763,32748,32723,32688,  \
9114  32643,32588,32524,32449,32365,32270,32166,32052,31928,31795,31651,31499,31336,31164,30983,30792,  \
9115  30592,30382,30163,29935,29698,29452,29197,28932,28660,28378,28088,27789,27482,27166,26842,26510,  \
9116  26170,25822,25466,25102,24730,24351,23965,23571,23170,22763,22348,21926,21498,21063,20622,20174,  \
9117  19720,19261,18795,18324,17847,17364,16877,16384,15886,15384,14876,14365,13848,13328,12803,12275,  \
9118  11743,11207,10668,10126,9580,9032,8481,7927,7371,6813,6252,5690,5126,4560,3993,3425,2856,2286,    \
9119  1715,1144,572,0,-572,-1144,-1715,-2286,-2856,-3425,-3993,-4560,-5126,-5690,-6252,-6813,-7371,     \
9120  -7927,-8481,-9032,-9580,-10126,-10668,-11207,-11743,-12275,-12803,-13328,-13848,-14365,-14876,    \
9121  -15384,-15886,-16384,-16877,-17364,-17847,-18324,-18795,-19261,-19720,-20174,-20622,-21063,-21498,\
9122  -21926,-22348,-22763,-23170,-23571,-23965,-24351,-24730,-25102,-25466,-25822,-26170,-26510,-26842,\
9123  -27166,-27482,-27789,-28088,-28378,-28660,-28932,-29197,-29452,-29698,-29935,-30163,-30382,-30592,\
9124  -30792,-30983,-31164,-31336,-31499,-31651,-31795,-31928,-32052,-32166,-32270,-32365,-32449,-32524,\
9125  -32588,-32643,-32688,-32723,-32748,-32763,-32767,-32763,-32748,-32723,-32688,-32643,-32588,-32524,\
9126  -32449,-32365,-32270,-32166,-32052,-31928,-31795,-31651,-31499,-31336,-31164,-30983,-30792,-30592,\
9127  -30382,-30163,-29935,-29698,-29452,-29197,-28932,-28660,-28378,-28088,-27789,-27482,-27166,-26842,\
9128  -26510,-26170,-25822,-25466,-25102,-24730,-24351,-23965,-23571,-23170,-22763,-22348,-21926,-21498,\
9129  -21063,-20622,-20174,-19720,-19261,-18795,-18324,-17847,-17364,-16877,-16384,-15886,-15384,-14876,\
9130  -14365,-13848,-13328,-12803,-12275,-11743,-11207,-10668,-10126,-9580,-9032,-8481,-7927,-7371,     \
9131  -6813,-6252,-5690,-5126,-4560,-3993,-3425,-2856,-2286,-1715,-1144,-572,0
9132 
9133   // General stuff, copied from NXTDefs.h...
9134   __GL_glDrawLine        TDrawLine
9135   __GL_glDrawPoint       TDrawPoint
9136   __GL_glDrawCircle      TDrawCircle
9137   __GL_glDrawData        TDrawText
9138 
9139   // settings...
9140   TGLSettings struct
9141     cullMode         byte
9142     circleSize       byte
9143     camDepth         byte
9144     zoom             byte
9145   TGLSettings ends
9146 
9147   __GL_glSettings        TGLSettings
9148   __GL_glSettingType     byte
9149   __GL_glSettingValue    byte
9150 
9151   // Vertex data...
9152   TGLVertex struct
9153     x                sword //sdword
9154     y                sword //sdword
9155     z                sword //sdword
9156   TGLVertex ends
9157 
9158   TGLScreenVertex struct
9159     x                sword //sdword
9160     y                sword //sdword
9161   TGLScreenVertex ends
9162 
9163   TGLRotVertex struct
9164     orig             TGLVertex
9165     rot              TGLVertex
9166     screen           TGLScreenVertex
9167   TGLRotVertex ends
9168 
9169   __GL_vertexData        TGLRotVertex[]
9170   __GL_vertex0           TGLRotVertex
9171   __GL_vertex1           TGLRotVertex
9172   __GL_vertex2           TGLRotVertex
9173   __GL_vertexCount       byte
9174   __GL_vertexIndex       byte
9175   __GL_vertexOffset      byte
9176 
9177   // Line data...
9178   TGLLine struct
9179     firstVertex      byte
9180     lastVertex       byte
9181   TGLLine ends
9182 
9183   __GL_lineData          TGLLine[]
9184   __GL_line              TGLLine
9185   __GL_lineCount         byte
9186   __GL_lineIndex         byte
9187   __GL_lineDone          byte[]
9188 
9189   // Polygon data...
9190   TGLPolygon struct
9191     beginMode        byte
9192     firstVertex      byte
9193     lastVertex       byte
9194     firstLine        byte
9195     lastLine         byte
9196   TGLPolygon ends
9197 
9198   __GL_polygonData       TGLPolygon[]
9199   __GL_polygon           TGLPolygon
9200   __GL_polygonCount      byte
9201   __GL_polygonIndex      byte
9202 
9203   // Polygon/vertex link...
9204   __GL_pvData            byte[]
9205   __GL_pvDataCount       byte
9206 
9207   // Polygon/line link...
9208   __GL_plData            byte[]
9209   __GL_plDataCount       byte
9210 
9211   // Object action...
9212   TGLObjectAction struct
9213     type             byte
9214     value            sword //sdword
9215 //    fsin             float
9216 //    fcos             float
9217     lsin             sword //sdword
9218     lcos             sword //sdword
9219   TGLObjectAction ends
9220 
9221   __GL_objectAction      TGLObjectAction
9222   __GL_objectActionData  TGLObjectAction[]
9223   __GL_objectActionCount byte
9224 
9225   // Object data...
9226   TObject struct
9227     firstVertex      byte
9228     lastVertex       byte
9229     firstPolygon     byte
9230     lastPolygon      byte
9231     firstLine        byte
9232     lastLine         byte
9233     render           byte
9234 
9235     // settings...
9236     circleSize       byte
9237     cullMode         byte
9238 
9239     actionCount      byte
9240     actionList       byte[]
9241   TObject ends
9242 
9243   __GL_objectData        TObject[]
9244   __GL_object            TObject
9245   __GL_objectCount       byte
9246   __GL_objectIndex       byte
9247 
9248   // Temp offset...
9249   __GL_offset            word
9250 
9251   // Counters...
9252   __GL_i                 word
9253   __GL_j                 word
9254   __GL_k                 word
9255   __GL_l                 word
9256 
9257   // Angles...
9258   __GL_angleX            sword //sdword
9259   __GL_angleY            sword //sdword
9260   __GL_angleZ            sword //sdword
9261 
9262   // Save angles...
9263   __GL_saveAngleX        sword //sdword
9264   __GL_saveAngleY        sword //sdword
9265   __GL_saveAngleZ        sword //sdword
9266 
9267   __GL_sinX              sword //sdword
9268   __GL_cosX              sword //sdword
9269   __GL_sinY              sword //sdword
9270   __GL_cosY              sword //sdword
9271   __GL_sinZ              sword //sdword
9272   __GL_cosZ              sword //sdword
9273 //  __GL_sinX              float
9274 //  __GL_cosX              float
9275 //  __GL_sinY              float
9276 //  __GL_cosY              float
9277 //  __GL_sinZ              float
9278 //  __GL_cosZ              float
9279 
9280   // Temp vars for calculations...
9281   __GL_a                 sdword
9282   __GL_b                 sdword
9283   __GL_c                 sdword
9284   __GL_d                 sdword
9285   __GL_e                 sdword
9286   __GL_f                 sdword
9287 
9288   // Rotated x, y, z coords...
9289   __GL_xx                sdword
9290   __GL_yy                sdword
9291   __GL_zz                sdword
9292 
9293   __GL_camDepth          sdword
9294   __GL_zoom              sdword
9295 
9296   __GL_x0                sdword
9297   __GL_y0                sdword
9298   __GL_z0                sdword
9299 
9300   __GL_x1                sdword
9301   __GL_y1                sdword
9302   __GL_z1                sdword
9303 
9304   __GL_x2                sdword
9305   __GL_y2                sdword
9306   __GL_z2                sdword
9307 
9308   // data for filling polygons...
9309   __GL_buffer            byte[]
9310 
9311   __GL_minX              sword
9312   __GL_maxX              sword
9313 
9314   __GL_startY            sword
9315   __GL_startX            sword
9316   __GL_endY              sword
9317   __GL_endX              sword
9318 
9319   __GL_deltaY            sword
9320   __GL_deltaX            sword
9321 
9322   __GL_action            byte
9323   __GL_index             word
9324   __GL_value             sword //sdword
9325   __GL_type              sword //sdword
9326 
9327   // rangecheck data...
9328   __GL_glRangeValue      word
9329   __GL_glRangeMaxValue   word
9330   __GL_glRangeErrorMsg   byte[]
9331 
9332   __GL_glErrorState      byte FALSE
9333   __GL_glErrorMsg        byte[]
9334 
9335   __GL_glLinesClipped    byte
9336 dseg ends
9337 
9338 //-----------------------------------------------------------------------------------------
9339 // Subroutine  : __GL_glRangeCheck
9340 // Description : Check array sizes.
9341 //-----------------------------------------------------------------------------------------
9342 subroutine __GL_glRangeCheck
9343   // check if there's an already error...
9344   brcmp    EQ,                     __GL_nbc_gl_range_ok, __GL_glErrorState, TRUE
9345   // check the range...
9346   brcmp    LT,                     __GL_nbc_gl_range_ok, __GL_glRangeValue, __GL_glRangeMaxValue
9347   set      __GL_glErrorState,      TRUE
9348   mov      __GL_glErrorMsg,        __GL_glRangeErrorMsg
9349 __GL_nbc_gl_range_ok:
9350   return
9351 ends
9352 
9353 //-----------------------------------------------------------------------------------------
9354 // Subroutine  : __GL_glInit
9355 // Description : Initialize vars.
9356 //-----------------------------------------------------------------------------------------
9357 subroutine __GL_glInit
9358   set      __GL_glSettings.cullMode,   GL_CULL_BACK
9359   set      __GL_glSettings.circleSize, 4
9360   set      __GL_glSettings.camDepth,   100
9361   set      __GL_glSettings.zoom,       0
9362   arrinit  __GL_vertexData,            __GL_vertex0, __GL_MAX_VERTICES
9363   set      __GL_vertexCount,           0
9364   arrinit  __GL_lineData,              __GL_line, __GL_MAX_LINES
9365   set      __GL_lineCount,             0
9366   arrinit  __GL_polygonData,           __GL_polygon, __GL_MAX_POLYGONS
9367   set      __GL_polygonCount,          0
9368   arrinit  __GL_objectActionData,      __GL_objectAction, __GL_MAX_OBJECT_ACTIONS
9369   arrinit  __GL_object.actionList,     0, __GL_MAX_OBJECT_ACTIONS
9370   arrinit  __GL_objectData,            __GL_object, __GL_MAX_OBJECTS
9371   set      __GL_objectCount,           0
9372   arrinit  __GL_pvData                 0, __GL_MAX_PV_DATA
9373   set      __GL_pvDataCount,           0
9374   arrinit  __GL_plData                 0, __GL_MAX_PL_DATA
9375   set      __GL_plDataCount            0
9376   set      __GL_angleX,                0
9377   set      __GL_angleY,                0
9378   set      __GL_angleZ,                0
9379   arrinit  __GL_buffer,                0, 200
9380   return
9381 ends
9382 
9383 //-----------------------------------------------------------------------------------------
9384 // Subroutine  : __GL_glSet
9385 // Description : Change settings.
9386 //-----------------------------------------------------------------------------------------
9387 subroutine __GL_glSet
9388   brcmp    EQ,                     __GL_nbc_gl_set_circle_size,  __GL_glSettingType, GL_CIRCLE_SIZE
9389   brcmp    EQ,                     __GL_nbc_gl_set_cull_mode,    __GL_glSettingType, GL_CULL_MODE
9390   brcmp    EQ,                     __GL_nbc_gl_set_camera_depth, __GL_glSettingType, GL_CAMERA_DEPTH
9391   brcmp    EQ,                     __GL_nbc_gl_set_zoom_factor,  __GL_glSettingType, GL_ZOOM_FACTOR
9392   // unknown setting...
9393   jmp      __GL_nbc_gl_set_done
9394 __GL_nbc_gl_set_circle_size:
9395   mov      __GL_glSettings.circleSize, __GL_glSettingValue
9396   jmp      __GL_nbc_gl_set_done
9397 __GL_nbc_gl_set_cull_mode:
9398   mov      __GL_glSettings.cullMode,   __GL_glSettingValue
9399   jmp      __GL_nbc_gl_set_done
9400 __GL_nbc_gl_set_camera_depth:
9401   mov      __GL_glSettings.camDepth,   __GL_glSettingValue
9402   jmp      __GL_nbc_gl_set_done
9403 __GL_nbc_gl_set_zoom_factor:
9404   mov      __GL_glSettings.zoom,       __GL_glSettingValue
9405 __GL_nbc_gl_set_done:
9406   return
9407 ends
9408 
9409 //-----------------------------------------------------------------------------------------
9410 // Subroutine  : __GL_glAddVertex
9411 // Description : Check if there's an existing vertex with the same (x,y,z) coord.
9412 //               If there's an existing vertex found then return the index to that vertex
9413 //               else add the vertex to the list and return the index of the added vertex.
9414 //-----------------------------------------------------------------------------------------
9415 subroutine __GL_glAddVertex
9416   brcmp    EQ,                      __GL_nbc_gl_add_vertex_error, __GL_glErrorState, TRUE
9417   // check if the list is empty...
9418   brcmp    EQ,                      __GL_nbc_gl_empty_vertex_list, __GL_vertexCount, 0
9419   // loop through the list...
9420   mov      __GL_i,                  __GL_object.firstVertex
9421 __GL_nbc_gl_find_vertex:
9422   index    __GL_vertex1,            __GL_vertexData, __GL_i
9423   brcmp    NEQ,                     __GL_nbc_gl_vertex_not_equal, __GL_vertex1.orig.x, __GL_vertex0.orig.x
9424   brcmp    NEQ,                     __GL_nbc_gl_vertex_not_equal, __GL_vertex1.orig.y, __GL_vertex0.orig.y
9425   brcmp    NEQ,                     __GL_nbc_gl_vertex_not_equal, __GL_vertex1.orig.z, __GL_vertex0.orig.z
9426   mov      __GL_vertexIndex,        __GL_i
9427   jmp      __GL_nbc_gl_add_vertex_done
9428 __GL_nbc_gl_vertex_not_equal:
9429   add      __GL_i,                  __GL_i, 1
9430   brcmp    LT,                      __GL_nbc_gl_find_vertex, __GL_i, __GL_object.lastVertex
9431 __GL_nbc_gl_empty_vertex_list:
9432   __glRangeCheck(__GL_vertexCount, __GL_MAX_VERTICES, 'Too many vertices')
9433   brcmp    EQ,                      __GL_nbc_gl_add_vertex_error, __GL_glErrorState, TRUE
9434   // there's no matching vertex found, add a new vertex to the list...
9435   replace  __GL_vertexData,         __GL_vertexData, __GL_vertexCount, __GL_vertex0
9436   mov      __GL_vertexIndex,        __GL_vertexCount
9437   add      __GL_vertexCount,        __GL_vertexCount, 1
9438 __GL_nbc_gl_add_vertex_done:
9439   replace  __GL_pvData,             __GL_pvData, __GL_polygon.lastVertex, __GL_vertexIndex
9440   add      __GL_polygon.lastVertex, __GL_polygon.lastVertex, 1
9441   add      __GL_pvDataCount,        __GL_pvDataCount, 1
9442   mov      __GL_object.lastVertex,  __GL_vertexCount
9443 __GL_nbc_gl_add_vertex_error:
9444   return
9445 ends
9446 
9447 //-----------------------------------------------------------------------------------------
9448 // Subroutine  : __GL_glEnd
9449 // Description : Store the polygon data, call __GL_glAddLines to optimize lines list.
9450 //-----------------------------------------------------------------------------------------
9451 subroutine __GL_glEnd
9452   brcmp    EQ,                     __GL_nbc_gl_end_error, __GL_glErrorState, TRUE
9453   call     __GL_glAddLines
9454   replace  __GL_polygonData,       __GL_polygonData, __GL_polygonCount, __GL_polygon
9455   add      __GL_polygonCount,      __GL_polygonCount, 1
9456 __GL_nbc_gl_end_error:
9457   return
9458 ends
9459 
9460 //-----------------------------------------------------------------------------------------
9461 // Subroutine  : __GL_glAddLines
9462 // Description : Add the lines of the polygon and check if the line already exists.
9463 //               Each line should be rendered only once.
9464 //-----------------------------------------------------------------------------------------
9465 subroutine __GL_glAddLines
9466   brcmp    EQ,                     __GL_nbc_gl_add_lines_error, __GL_glErrorState, TRUE
9467   mov      __GL_polygon.firstLine, __GL_plDataCount
9468   // loop through polygon vertex the list...
9469   mov      __GL_i,                 __GL_polygon.firstVertex
9470 __GL_nbc_gl_find_lines1:
9471   add      __GL_j,                 __GL_i, 1
9472   brcmp    LT,                     __GL_nbc_gl_find_lines_modj, __GL_j, __GL_polygon.lastVertex
9473   mov      __GL_j,                 __GL_polygon.firstVertex
9474   // if the beginMode is GL_LINE then don't close the polygon...
9475   brcmp    EQ,                     __GL_nbc_gl_add_line_done2, __GL_polygon.beginMode, GL_LINE
9476 __GL_nbc_gl_find_lines_modj:
9477   // _a = _pvData[_i]
9478   index    __GL_a,                 __GL_pvData, __GL_i
9479   // _b = _pvData[_j]
9480   index    __GL_b,                 __GL_pvData, __GL_j
9481   // check if the list is empty...
9482   brcmp    EQ,                     __GL_nbc_empty_lines_list, __GL_lineCount, 0
9483   // loop through the line list to find a matching line...
9484   mov      __GL_k,                 __GL_object.firstLine
9485 __GL_nbc_gl_find_lines2:
9486   index    __GL_line,              __GL_lineData, __GL_k
9487   brcmp    NEQ,                    __GL_nbc_gl_find_line_not_equal1, __GL_a, __GL_line.firstVertex
9488   brcmp    NEQ,                    __GL_nbc_gl_find_line_not_equal1, __GL_b, __GL_line.lastVertex
9489   mov      __GL_lineIndex,         __GL_k
9490   jmp      __GL_nbc_gl_add_line_done1
9491 __GL_nbc_gl_find_line_not_equal1:
9492   brcmp    NEQ,                    __GL_nbc_gl_find_line_not_equal2, __GL_b, __GL_line.firstVertex
9493   brcmp    NEQ,                    __GL_nbc_gl_find_line_not_equal2, __GL_a, __GL_line.lastVertex
9494   mov      __GL_lineIndex,         __GL_k
9495   jmp      __GL_nbc_gl_add_line_done1
9496 __GL_nbc_gl_find_line_not_equal2:
9497   add      __GL_k,                 __GL_k, 1
9498   brcmp    LT,                     __GL_nbc_gl_find_lines2, __GL_k, __GL_lineCount
9499 __GL_nbc_empty_lines_list:
9500   mov      __GL_line.firstVertex,  __GL_a
9501   mov      __GL_line.lastVertex,   __GL_b
9502   __glRangeCheck(__GL_lineCount, __GL_MAX_LINES, 'Too many lines')
9503   brcmp    EQ,                     __GL_nbc_gl_add_lines_error, __GL_glErrorState, TRUE
9504   // _lineData[_lineCount] = _line
9505   replace  __GL_lineData,          __GL_lineData, __GL_lineCount, __GL_line
9506   mov      __GL_lineIndex,         __GL_lineCount
9507   add      __GL_lineCount,         __GL_lineCount, 1
9508 __GL_nbc_gl_add_line_done1:
9509   __glRangeCheck(__GL_plDataCount, __GL_MAX_PL_DATA, 'Too many poly-lines')
9510   brcmp    EQ,                     __GL_nbc_gl_add_lines_error, __GL_glErrorState, TRUE
9511   // _plData[_plDataCount] = _lineIndex
9512   replace  __GL_plData,            __GL_plData, __GL_plDataCount, __GL_lineIndex
9513   add      __GL_plDataCount,       __GL_plDataCount, 1
9514   add      __GL_i,                 __GL_i, 1
9515   brcmp    LT,                     __GL_nbc_gl_find_lines1, __GL_i, __GL_polygon.lastVertex
9516 __GL_nbc_gl_add_line_done2:
9517   mov      __GL_polygon.lastLine,  __GL_plDataCount
9518 __GL_nbc_gl_add_lines_error:
9519   return
9520 ends
9521 
9522 //-----------------------------------------------------------------------------------------
9523 // Subroutine  : __GL_glEndObject
9524 // Description : Save the last polygon number, store the object in the objectlist.
9525 //-----------------------------------------------------------------------------------------
9526 subroutine __GL_glEndObject
9527   brcmp    EQ,                      __GL_nbc_gl_end_object_error, __GL_glErrorState, TRUE
9528   mov      __GL_object.lastPolygon, __GL_polygonCount
9529   replace  __GL_objectData,         __GL_objectData, __GL_objectCount, __GL_object
9530   add      __GL_objectCount,        __GL_objectCount, 1
9531 __GL_nbc_gl_end_object_error:
9532   return
9533 ends
9534 
9535 //-----------------------------------------------------------------------------------------
9536 // Subroutine  : __GL_glObjectAction
9537 // Description : Add an action to the object...
9538 //-----------------------------------------------------------------------------------------
9539 subroutine __GL_glObjectAction
9540   index    __GL_object,             __GL_objectData, __GL_objectIndex
9541   mov      __GL_objectAction.type,  __GL_action
9542   mov      __GL_objectAction.value, __GL_value
9543   brcmp    EQ,                      __GL_nbc_gl_action_rotate, __GL_action, GL_ROTATE_X
9544   brcmp    EQ,                      __GL_nbc_gl_action_rotate, __GL_action, GL_ROTATE_Y
9545   brcmp    EQ,                      __GL_nbc_gl_action_rotate, __GL_action, GL_ROTATE_Z
9546   jmp      __GL_nbc_gl_action_no_rotate
9547 __GL_nbc_gl_action_rotate:
9548   // if the action is a rotation of any kind then grab the sin and cos of the angle
9549   mod      __GL_value,              __GL_value, 360
9550 //  sind     __GL_objectAction.fsin,  __GL_value
9551 //  cosd     __GL_objectAction.fcos,  __GL_value
9552   index    __GL_objectAction.lsin,  __GL_SIN_TABLE, __GL_value
9553   add      __GL_value,              __GL_value, 90
9554   mod      __GL_value,              __GL_value, 360
9555   index    __GL_objectAction.lcos,  __GL_SIN_TABLE, __GL_value
9556 __GL_nbc_gl_action_no_rotate:
9557   __glRangeCheck(__GL_object.actionCount, __GL_MAX_OBJECT_ACTIONS, 'Too many object-actions')
9558   brcmp    EQ,                      __GL_nbc_gl_add_object_error, __GL_glErrorState, TRUE
9559   // _object.actionList[_object.actionCount] = _objectActionCount
9560   replace  __GL_object.actionList,  __GL_object.actionList, __GL_object.actionCount, __GL_objectActionCount
9561   add      __GL_object.actionCount, __GL_object.actionCount, 1
9562   replace  __GL_objectData,         __GL_objectData, __GL_objectIndex, __GL_object
9563   __glRangeCheck(__GL_objectActionCount, __GL_MAX_OBJECT_ACTIONS, 'Too many object-actions')
9564   brcmp    EQ,                      __GL_nbc_gl_add_object_error, __GL_glErrorState, TRUE
9565   // _objectActionData[_objectActionCount] = _objectAction
9566   replace  __GL_objectActionData,   __GL_objectActionData, __GL_objectActionCount, __GL_objectAction
9567   add      __GL_objectActionCount,  __GL_objectActionCount, 1
9568 __GL_nbc_gl_add_object_error:
9569   return
9570 ends
9571 
9572 //-----------------------------------------------------------------------------------------
9573 // Subroutine  : __GL_glRotateObject
9574 // Description : Check the object actions and apply them to the object...
9575 //-----------------------------------------------------------------------------------------
9576 subroutine __GL_glRotateObject
9577   mov      __GL_i,                 __GL_object.firstVertex
9578 __GL_nbc_gl_apply_next_vertex:
9579   index    __GL_vertex0,           __GL_vertexData, __GL_i
9580   mov      __GL_vertex0.rot.x,     __GL_vertex0.orig.x
9581   mov      __GL_vertex0.rot.y,     __GL_vertex0.orig.y
9582   mov      __GL_vertex0.rot.z,     __GL_vertex0.orig.z
9583   brcmp    EQ,                     __GL_nbc_gl_no_actions, __GL_object.actionCount, 0
9584   set      __GL_j,                 0
9585 __GL_nbc_gl_apply_next_action:
9586   // _objectAction = _objectActionData[_object.actionData[_j]]
9587   index    __GL_k,                 __GL_object.actionList, __GL_j
9588   index    __GL_objectAction,      __GL_objectActionData, __GL_k
9589   brcmp    EQ,                     __GL_nbc_gl_apply_translate_x, __GL_objectAction.type, GL_TRANSLATE_X
9590   brcmp    EQ,                     __GL_nbc_gl_apply_translate_y, __GL_objectAction.type, GL_TRANSLATE_Y
9591   brcmp    EQ,                     __GL_nbc_gl_apply_translate_z, __GL_objectAction.type, GL_TRANSLATE_Z
9592   brcmp    EQ,                     __GL_nbc_gl_apply_rotate_x,    __GL_objectAction.type, GL_ROTATE_X
9593   brcmp    EQ,                     __GL_nbc_gl_apply_rotate_y,    __GL_objectAction.type, GL_ROTATE_Y
9594   brcmp    EQ,                     __GL_nbc_gl_apply_rotate_z,    __GL_objectAction.type, GL_ROTATE_Z
9595   brcmp    EQ,                     __GL_nbc_gl_apply_scale_x,     __GL_objectAction.type, GL_SCALE_X
9596   brcmp    EQ,                     __GL_nbc_gl_apply_scale_y,     __GL_objectAction.type, GL_SCALE_Y
9597   brcmp    EQ,                     __GL_nbc_gl_apply_scale_z,     __GL_objectAction.type, GL_SCALE_Z
9598   jmp      __GL_nbc_gl_apply_done
9599 __GL_nbc_gl_apply_translate_x:
9600   add      __GL_vertex0.rot.x,     __GL_vertex0.rot.x, __GL_objectAction.value
9601   jmp      __GL_nbc_gl_apply_done
9602 __GL_nbc_gl_apply_translate_y:
9603   add      __GL_vertex0.rot.y,     __GL_vertex0.rot.y, __GL_objectAction.value
9604   jmp      __GL_nbc_gl_apply_done
9605 __GL_nbc_gl_apply_translate_z:
9606   add      __GL_vertex0.rot.z,     __GL_vertex0.rot.z, __GL_objectAction.value
9607   jmp      __GL_nbc_gl_apply_done
9608 __GL_nbc_gl_apply_rotate_x:
9609   mul      __GL_a,                 __GL_objectAction.lcos, __GL_vertex0.rot.y
9610   shr      __GL_a,                 __GL_a, 15
9611   mul      __GL_b,                 __GL_objectAction.lsin, __GL_vertex0.rot.z
9612   shr      __GL_b,                 __GL_b, 15
9613   sub      __GL_c,                 __GL_a, __GL_b
9614   mul      __GL_a,                 __GL_objectAction.lsin, __GL_vertex0.rot.y
9615   shr      __GL_a,                 __GL_a, 15
9616   mul      __GL_b,                 __GL_objectAction.lcos, __GL_vertex0.rot.z
9617   shr      __GL_b,                 __GL_b, 15
9618   add      __GL_d,                 __GL_a, __GL_b
9619   mov      __GL_vertex0.rot.y,     __GL_c
9620   mov      __GL_vertex0.rot.z,     __GL_d
9621   jmp      __GL_nbc_gl_apply_done
9622 __GL_nbc_gl_apply_rotate_y:
9623   mul      __GL_a,                 __GL_objectAction.lsin, __GL_vertex0.rot.z
9624   shr      __GL_a,                 __GL_a, 15
9625   mul      __GL_b,                 __GL_objectAction.lcos, __GL_vertex0.rot.x
9626   shr      __GL_b,                 __GL_b, 15
9627   add      __GL_c,                 __GL_a, __GL_b
9628   mul      __GL_a,                 __GL_objectAction.lcos, __GL_vertex0.rot.z
9629   shr      __GL_a,                 __GL_a, 15
9630   mul      __GL_b,                 __GL_objectAction.lsin, __GL_vertex0.rot.x
9631   shr      __GL_b,                 __GL_b, 15
9632   sub      __GL_d,                 __GL_a, __GL_b
9633   mov      __GL_vertex0.rot.x,     __GL_c
9634   mov      __GL_vertex0.rot.z,     __GL_d
9635   jmp      __GL_nbc_gl_apply_done
9636 __GL_nbc_gl_apply_rotate_z:
9637   mul      __GL_a,                 __GL_objectAction.lcos, __GL_vertex0.rot.x
9638   shr      __GL_a,                 __GL_a, 15
9639   mul      __GL_b,                 __GL_objectAction.lsin, __GL_vertex0.rot.y
9640   shr      __GL_b,                 __GL_b, 15
9641   sub      __GL_c,                 __GL_a, __GL_b
9642   mul      __GL_a,                 __GL_objectAction.lsin, __GL_vertex0.rot.x
9643   shr      __GL_a,                 __GL_a, 15
9644   mul      __GL_b,                 __GL_objectAction.lcos, __GL_vertex0.rot.y
9645   shr      __GL_b,                 __GL_b, 15
9646   add      __GL_d,                 __GL_a, __GL_b
9647   mov      __GL_vertex0.rot.x,     __GL_c
9648   mov      __GL_vertex0.rot.y,     __GL_d
9649   jmp      __GL_nbc_gl_apply_done
9650 __GL_nbc_gl_apply_scale_x:
9651   mul      __GL_vertex0.rot.x,     __GL_vertex0.rot.x, __GL_objectAction.value
9652   shr      __GL_vertex0.rot.x,     __GL_vertex0.rot.x, 8
9653   jmp      __GL_nbc_gl_apply_done
9654 __GL_nbc_gl_apply_scale_y:
9655   mul      __GL_vertex0.rot.y,     __GL_vertex0.rot.y, __GL_objectAction.value
9656   shr      __GL_vertex0.rot.y,     __GL_vertex0.rot.y, 8
9657   jmp      __GL_nbc_gl_apply_done
9658 __GL_nbc_gl_apply_scale_z:
9659   mul      __GL_vertex0.rot.z,     __GL_vertex0.rot.z, __GL_objectAction.value
9660   shr      __GL_vertex0.rot.z,     __GL_vertex0.rot.z, 8
9661   jmp      __GL_nbc_gl_apply_done
9662 __GL_nbc_gl_apply_done:
9663   add      __GL_j,                 __GL_j, 1
9664   brcmp    LT,                     __GL_nbc_gl_apply_next_action, __GL_j, __GL_object.actionCount
9665 __GL_nbc_gl_no_actions:
9666   replace  __GL_vertexData,        __GL_vertexData, __GL_i, __GL_vertex0
9667   add      __GL_i,                 __GL_i, 1
9668   brcmp    LT,                     __GL_nbc_gl_apply_next_vertex, __GL_i, __GL_object.lastVertex
9669   return
9670 ends
9671 
9672 //-----------------------------------------------------------------------------------------
9673 // Subroutine  : __GL_glRotateVertexList
9674 // Description : Rotate all the vertices in the vertext list...
9675 //-----------------------------------------------------------------------------------------
9676 subroutine __GL_glRotateVertexList
9677   // update all object actions first...
9678   set      __GL_l,                 0
9679 __GL_nbc_gl_rotate_objects:
9680   index    __GL_object,            __GL_objectData, __GL_l
9681   brcmp    EQ,                     __GL_nbc_gl_dont_rotate_object, __GL_object.render, FALSE
9682   call     __GL_glRotateObject
9683 __GL_nbc_gl_dont_rotate_object:
9684   add      __GL_l,                 __GL_l, 1
9685   brcmp    LT,                     __GL_nbc_gl_rotate_objects, __GL_l, __GL_objectCount
9686   mov      __GL_saveAngleX,        __GL_angleX
9687   mov      __GL_saveAngleY,        __GL_angleY
9688   index    __GL_sinX,              __GL_SIN_TABLE, __GL_angleX
9689   add      __GL_angleX,            __GL_angleX, 90
9690   mod      __GL_angleX,            __GL_angleX, 360
9691   index    __GL_cosX,              __GL_SIN_TABLE, __GL_angleX
9692   index    __GL_sinY,              __GL_SIN_TABLE, __GL_angleY
9693   add      __GL_angleY,            __GL_angleY, 90
9694   mod      __GL_angleY,            __GL_angleY, 360
9695   index    __GL_cosY,              __GL_SIN_TABLE, __GL_angleY
9696   mov      __GL_camDepth,          __GL_glSettings.camDepth
9697   mov      __GL_zoom,              __GL_glSettings.zoom
9698   set      __GL_i,                 0
9699   set      __GL_vertexOffset,      0
9700 __GL_nbc_gl_rotate_loop:
9701   // get the values from the vertex list...
9702   index    __GL_vertex0,           __GL_vertexData, __GL_vertexOffset
9703   // z1 = (_vertex0.rot.z * _cosY) - (_vertex0.rot.x * _sinY)
9704   mul      __GL_a,                 __GL_vertex0.rot.z, __GL_cosY
9705   shr      __GL_a,                 __GL_a, 15
9706   mul      __GL_b,                 __GL_vertex0.rot.x, __GL_sinY
9707   shr      __GL_b,                 __GL_b, 15
9708   sub      __GL_z1,                __GL_a, __GL_b
9709   // xx = (_vertex0.rot.z * _sinY) + (_vertex0.rot.x * _cosY)
9710   mul      __GL_a,                 __GL_vertex0.rot.z, __GL_sinY
9711   shr      __GL_a,                 __GL_a, 15
9712   mul      __GL_b,                 __GL_vertex0.rot.x, __GL_cosY
9713   shr      __GL_b,                 __GL_b, 15
9714   add      __GL_xx,                __GL_a, __GL_b
9715   // zz = (_vertex0.rot.y * _sinX) + (_z1 * _cosX) + _zoom
9716   mul      __GL_a,                 __GL_vertex0.rot.y, __GL_sinX
9717   shr      __GL_a,                 __GL_a, 15
9718   mul      __GL_b,                 __GL_z1, __GL_cosX
9719   shr      __GL_b,                 __GL_b, 15
9720   add      __GL_zz,                __GL_a, __GL_b
9721   add      __GL_zz,                __GL_zz, __GL_zoom
9722   // yy = (_vertex0.rot.y * cosX) - (z1 * sinX)
9723   mul      __GL_a,                 __GL_vertex0.rot.y, __GL_cosX
9724   shr      __GL_a,                 __GL_a, 15
9725   mul      __GL_b,                 __GL_z1, __GL_sinX
9726   shr      __GL_b,                 __GL_b, 15
9727   sub      __GL_yy,                __GL_a, __GL_b
9728   // the actual screen coords...
9729   add      __GL_zz,                __GL_zz, __GL_camDepth
9730   // _vertex0.screen.sx = width  + (x * camDepth) / (zz + camDepth))
9731   // _vertex0.screen.sy = height - (y * camDepth) / (zz + camDepth))
9732   mul      __GL_vertex0.screen.x,  __GL_xx, __GL_camDepth
9733   div      __GL_vertex0.screen.x,  __GL_vertex0.screen.x, __GL_zz
9734   add      __GL_vertex0.screen.x,  __GL_vertex0.screen.x, 50
9735   mul      __GL_vertex0.screen.y,  __GL_yy, __GL_camDepth
9736   div      __GL_vertex0.screen.y,  __GL_vertex0.screen.y, __GL_zz
9737   sub      __GL_vertex0.screen.y,  32, __GL_vertex0.screen.y
9738   // save the screen coords...
9739   replace  __GL_vertexData,        __GL_vertexData, __GL_vertexOffset, __GL_vertex0
9740   add      __GL_vertexOffset,      __GL_vertexOffset, 1
9741   add      __GL_i,                 __GL_i, 1
9742   brcmp    LT,                     __GL_nbc_gl_rotate_loop, __GL_i, __GL_vertexCount
9743   mov      __GL_angleX,            __GL_saveAngleX
9744   mov      __GL_angleY,            __GL_saveAngleY
9745   return
9746 ends
9747 
9748 //-----------------------------------------------------------------------------------------
9749 // Subroutine  : __GL_glResetObjects
9750 // Description : Reset the rotate, translate and scale actions for all objects...
9751 //-----------------------------------------------------------------------------------------
9752 subroutine __GL_glResetObjects
9753   set      __GL_glLinesClipped,     0
9754   brcmp    EQ,                      __GL_nbc_gl_reset_objects_error, __GL_glErrorState, TRUE
9755   arrinit  __GL_lineDone,           0, __GL_lineCount
9756   set      __GL_objectActionCount,  0
9757   set      __GL_i,                  0
9758 __GL_nbc_gl_reset_actions:
9759   index    __GL_object,             __GL_objectData, __GL_i
9760   set      __GL_object.actionCount, 0
9761   set      __GL_object.render,      FALSE
9762   replace  __GL_objectData,         __GL_objectData, __GL_i, __GL_object
9763   add      __GL_i,                  __GL_i, 1
9764   brcmp    LT,                      __GL_nbc_gl_reset_actions, __GL_i, __GL_objectCount
9765 __GL_nbc_gl_reset_objects_error:
9766   return
9767 ends
9768 
9769 //-----------------------------------------------------------------------------------------
9770 // Subroutine  : __GL_glCallObject
9771 // Description : Set the render boolean, copy the settings...
9772 //-----------------------------------------------------------------------------------------
9773 subroutine __GL_glCallObject
9774   brcmp    EQ,                     __GL_nbc_gl_call_object_error, __GL_glErrorState, TRUE
9775   index    __GL_object,            __GL_objectData, __GL_objectIndex
9776   set      __GL_object.render,     TRUE
9777   mov      __GL_object.cullMode,   __GL_glSettings.cullMode
9778   mov      __GL_object.circleSize, __GL_glSettings.circleSize
9779   replace  __GL_objectData,        __GL_objectData, __GL_objectIndex, __GL_object
9780 __GL_nbc_gl_call_object_error:
9781   return
9782 ends
9783 
9784 //-----------------------------------------------------------------------------------------
9785 // Subroutine  : __GL_glDrawObject
9786 // Description : Draw the object, this routine expects the '_object' struct to be set.
9787 //-----------------------------------------------------------------------------------------
9788 subroutine __GL_glDrawObject
9789   // set once...
9790   mov      __GL_glDrawLine.Options,     0
9791   // loop through the polygon list for this object...
9792   mov      __GL_i,                      __GL_object.firstPolygon
9793 __GL_nbc_gl_draw_polygons:
9794   // get the information for the polygon...
9795   index    __GL_polygon,                __GL_polygonData, __GL_i
9796   brcmp    EQ,                          __GL_nbc_gl_render_polygon, __GL_polygon.beginMode, GL_POLYGON
9797   brcmp    EQ,                          __GL_nbc_gl_render_line,    __GL_polygon.beginMode, GL_LINE
9798   brcmp    EQ,                          __GL_nbc_gl_render_point,   __GL_polygon.beginMode, GL_POINT
9799   brcmp    EQ,                          __GL_nbc_gl_render_circle,  __GL_polygon.beginMode, GL_CIRCLE
9800   jmp      __GL_nbc_gl_cull_polygon
9801   //---------------------------------------------------------------------------------------
9802   // Render a polygon...
9803   //---------------------------------------------------------------------------------------
9804 __GL_nbc_gl_render_polygon:
9805   // loop through the vertex list for this polygon...
9806   mov      __GL_j,                      __GL_polygon.firstVertex
9807   mov      __GL_k,                      __GL_polygon.lastVertex
9808   // _vertex0 = _vertexData[_pvData[j]]
9809   index    __GL_vertexOffset,           __GL_pvData, __GL_j
9810   index    __GL_vertex0,                __GL_vertexData, __GL_vertexOffset
9811   // _vertex1 = _vertexData[_pvData[j + 1]]
9812   add      __GL_j,                      __GL_j, 1
9813   index    __GL_vertexOffset,           __GL_pvData, __GL_j
9814   index    __GL_vertex1,                __GL_vertexData, __GL_vertexOffset
9815   // _vertex2 = _vertexData[_pvData[j + 2]]
9816   add      __GL_j,                      __GL_j, 1
9817   index    __GL_vertexOffset,           __GL_pvData, __GL_j
9818   index    __GL_vertex2,                __GL_vertexData, __GL_vertexOffset
9819   // check if culling is enabled...
9820   brcmp    EQ,                          __GL_nbc_gl_no_culling, __GL_object.cullMode, GL_CULL_NONE
9821   // calculate the culling...
9822   // ((x1 - x0) * (y2 - y0) >= (x2 - x0) * (y1 - y0))
9823   sub      __GL_a,                      __GL_vertex1.screen.x, __GL_vertex0.screen.x
9824   sub      __GL_b,                      __GL_vertex2.screen.y, __GL_vertex0.screen.y
9825   mul      __GL_c,                      __GL_a, __GL_b
9826   sub      __GL_d,                      __GL_vertex2.screen.x, __GL_vertex0.screen.x
9827   sub      __GL_e,                      __GL_vertex1.screen.y, __GL_vertex0.screen.y
9828   mul      __GL_f,                      __GL_d, __GL_e
9829   // check if culling is enabled...
9830   brcmp    EQ,                          __GL_nbc_gl_check_front_cull, __GL_object.cullMode, GL_CULL_FRONT
9831   brcmp    GTEQ,                        __GL_nbc_gl_cull_polygon, __GL_c, __GL_f
9832   jmp      __GL_nbc_gl_no_culling
9833 __GL_nbc_gl_check_front_cull:
9834   brcmp    GTEQ,                        __GL_nbc_gl_cull_polygon, __GL_f, __GL_c
9835 __GL_nbc_gl_no_culling:
9836   //--> render the lines...
9837   mov      __GL_j,                      __GL_polygon.firstLine
9838 __GL_nbc_gl_draw_lines:
9839   // _k = _plData[_j]
9840   index    __GL_k,                      __GL_plData, __GL_j
9841   // render every line only once!
9842   // _l = _lineDone[_k]
9843   index    __GL_l,                      __GL_lineDone, __GL_k
9844   brcmp    EQ,                          __GL_nbc_gl_line_done, __GL_l, 1
9845   // set the 'done' byte...
9846   replace  __GL_lineDone,               __GL_lineDone, 1, __GL_l
9847   // _line = _lineData[_k]
9848   index    __GL_line,                   __GL_lineData, __GL_k
9849   // _vertex1 = _vertexData[_line.firstVertex]
9850   index    __GL_vertex1,                __GL_vertexData, __GL_line.firstVertex
9851   // _vertex1 = _vertexData[_line.lastVertex]
9852   index    __GL_vertex2,                __GL_vertexData, __GL_line.lastVertex
9853   // very crude clipping...
9854 //  add      __GL_glLinesClipped,         __GL_glLinesClipped, 1
9855 //  brcmp    LT,                          __GL_nbc_gl_line_done, __GL_vertex1.screen.x,  0
9856 //  brcmp    LT,                          __GL_nbc_gl_line_done, __GL_vertex2.screen.x,  0
9857 //  brcmp    LT,                          __GL_nbc_gl_line_done, __GL_vertex1.screen.y,  0
9858 //  brcmp    LT,                          __GL_nbc_gl_line_done, __GL_vertex2.screen.y,  0
9859 //  brcmp    GT,                          __GL_nbc_gl_line_done, __GL_vertex1.screen.x, 99
9860 //  brcmp    GT,                          __GL_nbc_gl_line_done, __GL_vertex2.screen.x, 99
9861 //  brcmp    GT,                          __GL_nbc_gl_line_done, __GL_vertex1.screen.y, 63
9862 //  brcmp    GT,                          __GL_nbc_gl_line_done, __GL_vertex2.screen.y, 63
9863 //  sub      __GL_glLinesClipped,         __GL_glLinesClipped, 1
9864 //  mov      __GL_glDrawLine.StartLoc.X,  __GL_vertex1.screen.x
9865 //  mov      __GL_glDrawLine.StartLoc.Y,  __GL_vertex1.screen.y
9866 //  mov      __GL_glDrawLine.EndLoc.X,    __GL_vertex2.screen.x
9867 //  mov      __GL_glDrawLine.EndLoc.Y,    __GL_vertex2.screen.y
9868   mov      __GL_glDrawLine.StartLoc,    __GL_vertex1.screen
9869   mov      __GL_glDrawLine.EndLoc,      __GL_vertex2.screen
9870   syscall  DrawLine,                    __GL_glDrawLine
9871 __GL_nbc_gl_line_done:
9872   add      __GL_j,                      __GL_j, 1
9873   brcmp    LT,                          __GL_nbc_gl_draw_lines, __GL_j, __GL_polygon.lastLine
9874   //<-- render the lines...
9875 /*
9876   mov      __GL_minX,                  1000
9877   mov      __GL_maxX,                 -1000
9878 
9879   set      __GL_a,                     0
9880 __GL_nbc_gl_polygon_loop:
9881   add      __GL_b,                     __GL_a, 1
9882 
9883   brcmp    LT,                         __GL_nbc_gl_modb, __GL_b, __GL_polygon.lastVertex
9884   mov      __GL_b,                     __GL_polygon.firstVertex
9885 __GL_nbc_gl_modb:
9886 
9887   // _vertex1 = _vertexData[_pvData[_a]]
9888   index    __GL_vertexOffset,          __GL_pvData, __GL_a
9889   index    __GL_vertex1,               __GL_vertexData, __GL_vertexOffset
9890   // _vertex1 = _vertexData[_pvData[_b]]
9891   index    __GL_vertexOffset,          __GL_pvData, __GL_b
9892   index    __GL_vertex2,               __GL_vertexData, __GL_vertexOffset
9893 
9894   brcmp    GTEQ,                       __GL_nbc_gl_minx1, __GL_vertex1.screen.x, __GL_minX
9895   mov      __GL_minX,                  __GL_vertex1.screen.x
9896 __GL_nbc_gl_minx1:
9897   brcmp    GTEQ,                       __GL_nbc_gl_minx2, __GL_vertex2.screen.x, __GL_minX
9898   mov      __GL_minX,                  __GL_vertex2.screen.x
9899 __GL_nbc_gl_minx2:
9900 
9901   brcmp    LTEQ,                       __GL_nbc_gl_maxx1, __GL_vertex1.screen.x, __GL_maxX
9902   mov      __GL_maxX,                  __GL_vertex1.screen.x
9903 __GL_nbc_gl_maxx1:
9904   brcmp    LTEQ,                       __GL_nbc_gl_maxx2, __GL_vertex2.screen.x, __GL_maxX
9905   mov      __GL_maxX,                  __GL_vertex2.screen.x
9906 __GL_nbc_gl_maxx2:
9907 
9908   mov      __GL_index,                 0
9909 
9910   mov      __GL_startY,                __GL_vertex1.screen.y
9911   mov      __GL_startX,                __GL_vertex1.screen.x
9912   mov      __GL_endY,                  __GL_vertex2.screen.y
9913   mov      __GL_endX,                  __GL_vertex2.screen.x
9914 
9915   brcmp    GTEQ,                       __GL_nbc_gl_polygon_flip, __GL_endX, __GL_startX
9916   mov      __GL_startY,                __GL_vertex2.screen.y
9917   mov      __GL_startX,                __GL_vertex2.screen.x
9918   mov      __GL_endY,                  __GL_vertex1.screen.y
9919   mov      __GL_endX,                  __GL_vertex1.screen.x
9920   mov      __GL_index,                 100
9921 __GL_nbc_gl_polygon_flip:
9922 
9923   sub      __GL_deltaY,                __GL_endY, __GL_startY
9924   sub      __GL_deltaX,                __GL_endX, __GL_startX
9925 
9926   mov      __GL_c,                     __GL_startX
9927 __GL_nbc_gl_polygon_line:
9928   add      __GL_offset,                __GL_c, __GL_index
9929 
9930   // _startY + _deltaY * (_c - _startX) / _deltaX
9931   sub      __GL_value,                 __GL_c, __GL_startX
9932   mul      __GL_value,                 __GL_value, __GL_deltaY
9933   div      __GL_value,                 __GL_value, __GL_deltaX
9934   add      __GL_value,                 __GL_value, __GL_startY
9935 
9936   replace  __GL_buffer,                __GL_buffer, __GL_offset, __GL_value
9937 
9938   add      __GL_c,                     __GL_c, 1
9939   brcmp    LTEQ                        __GL_nbc_gl_polygon_line, __GL_c, __GL_endX
9940 
9941   add      __GL_a,                     __GL_a, 1
9942   brcmp    LT                          __GL_nbc_gl_polygon_loop, __GL_a, __GL_polygon.lastVertex
9943 
9944   mov      __GL_a,                     __GL_minX
9945 __GL_nbc_gl_polygon_lines:
9946   index    __GL_startY,                __GL_buffer, __GL_a
9947   add      __GL_b,                     __GL_a, 100
9948   index    __GL_endY,                  __GL_buffer, __GL_b
9949 
9950   mov      __GL_glDrawLine.Options,    0
9951   mov      __GL_glDrawLine.StartLoc.X, __GL_a
9952   mov      __GL_glDrawLine.StartLoc.Y, __GL_startY
9953   mov      __GL_glDrawLine.EndLoc.X,   __GL_a
9954   mov      __GL_glDrawLine.EndLoc.Y,   __GL_endY
9955   syscall  DrawLine,                   __GL_glDrawLine
9956 
9957   add      __GL_a,                     __GL_a, 1
9958   brcmp    LTEQ,                       __GL_nbc_gl_polygon_lines, __GL_a, __GL_maxX
9959 */
9960   jmp      __GL_nbc_gl_cull_polygon
9961   //---------------------------------------------------------------------------------------
9962   // Render lines...
9963   //---------------------------------------------------------------------------------------
9964 __GL_nbc_gl_render_line:
9965   mov      __GL_j,                      __GL_polygon.firstLine
9966 __GL_nbc_gl_render_lines:
9967   // _k = _plData[_j]
9968   index    __GL_k,                      __GL_plData, __GL_j
9969   // render every line only once!
9970   // _l = _lineDone[_k]
9971   index    __GL_l,                      __GL_lineDone, __GL_k
9972   brcmp    EQ,                          __GL_nbc_gl_render_lines_done, __GL_l, 1
9973   // set the 'done' byte...
9974   replace  __GL_lineDone,               __GL_lineDone, 1, __GL_l
9975   // _line = _lineData[_k]
9976   index    __GL_line,                   __GL_lineData, __GL_k
9977   // _vertex1 = _vertexData[_line.firstVertex]
9978   // _vertex2 = _vertexData[_line.lastVertex]
9979   index    __GL_vertex1,                __GL_vertexData, __GL_line.firstVertex
9980   index    __GL_vertex2,                __GL_vertexData, __GL_line.lastVertex
9981   mov      __GL_glDrawLine.StartLoc,    __GL_vertex1.screen
9982   mov      __GL_glDrawLine.EndLoc,      __GL_vertex2.screen
9983 //  mov      __GL_glDrawLine.StartLoc.X,  __GL_vertex1.screen.x
9984 //  mov      __GL_glDrawLine.StartLoc.Y,  __GL_vertex1.screen.y
9985 //  mov      __GL_glDrawLine.EndLoc.X,    __GL_vertex2.screen.x
9986 //  mov      __GL_glDrawLine.EndLoc.Y,    __GL_vertex2.screen.y
9987   syscall  DrawLine,                    __GL_glDrawLine
9988 __GL_nbc_gl_render_lines_done:
9989   add      __GL_j,                      __GL_j, 1
9990   brcmp    LT,                          __GL_nbc_gl_render_lines, __GL_j, __GL_polygon.lastLine
9991   jmp      __GL_nbc_gl_cull_polygon
9992   //---------------------------------------------------------------------------------------
9993   // Render points...
9994   //---------------------------------------------------------------------------------------
9995 __GL_nbc_gl_render_point:
9996   set      __GL_glDrawPoint.Options,    0
9997   mov      __GL_j,                      __GL_polygon.firstVertex
9998 __GL_nbc_gl_render_points:
9999   // _vertex0 = _vertexData[_pvData[j]]
10000   index    __GL_vertexOffset,           __GL_pvData, __GL_j
10001   index    __GL_vertex0,                __GL_vertexData, __GL_vertexOffset
10002   mov      __GL_glDrawPoint.Location,   __GL_vertex0.screen
10003 //  mov      __GL_glDrawPoint.Location.X, __GL_vertex0.screen.x
10004 //  mov      __GL_glDrawPoint.Location.Y, __GL_vertex0.screen.y
10005   syscall  DrawPoint,                   __GL_glDrawPoint
10006   add      __GL_j,                      __GL_j, 1
10007   brcmp    LT,                          __GL_nbc_gl_render_points, __GL_j, __GL_polygon.lastVertex
10008   jmp      __GL_nbc_gl_cull_polygon
10009   //---------------------------------------------------------------------------------------
10010   // Render circle...
10011   //---------------------------------------------------------------------------------------
10012 __GL_nbc_gl_render_circle:
10013   set      __GL_glDrawCircle.Options,   0
10014   mov      __GL_glDrawCircle.Size,      __GL_object.circleSize
10015   mov      __GL_j,                      __GL_polygon.firstVertex
10016 __GL_nbc_gl_render_circles:
10017   // _vertex0 = _vertexData[_pvData[j]]
10018   index    __GL_vertexOffset,           __GL_pvData, __GL_j
10019   index    __GL_vertex0,                __GL_vertexData, __GL_vertexOffset
10020   mov      __GL_glDrawCircle.Center,    __GL_vertex0.screen
10021 //  mov      __GL_glDrawCircle.Center.X,  __GL_vertex0.screen.x
10022 //  mov      __GL_glDrawCircle.Center.Y,  __GL_vertex0.screen.y
10023   syscall  DrawCircle,                  __GL_glDrawCircle
10024   add      __GL_j,                      __GL_j, 1
10025   brcmp    LT,                          __GL_nbc_gl_render_circles, __GL_j, __GL_polygon.lastVertex
10026   jmp      __GL_nbc_gl_cull_polygon
10027 __GL_nbc_gl_cull_polygon:
10028   add      __GL_i,                      __GL_i, 1
10029   brcmp    LT,                          __GL_nbc_gl_draw_polygons, __GL_i, __GL_object.lastPolygon
10030   return
10031 ends
10032 
10033 //-----------------------------------------------------------------------------------------
10034 // Subroutine  : __GL_glRenderObjects
10035 // Description : Draw all objects which have been called...
10036 //-----------------------------------------------------------------------------------------
10037 subroutine __GL_glRenderObjects
10038   brcmp    EQ,                          __GL_nbc_gl_render_objects_error, __GL_glErrorState, TRUE
10039   set      __GL_objectIndex,            0
10040 __GL_nbc_gl_render_objects:
10041   // get the information for the object...
10042   index    __GL_object,                 __GL_objectData, __GL_objectIndex
10043   brcmp    EQ,                          __GL_nbc_gl_dont_render_object, __GL_object.render, FALSE
10044   call     __GL_glDrawObject
10045 __GL_nbc_gl_dont_render_object:
10046   add      __GL_objectIndex,            __GL_objectIndex, 1
10047   brcmp    LT,                          __GL_nbc_gl_render_objects, __GL_objectIndex, __GL_objectCount
10048   return
10049 __GL_nbc_gl_render_objects_error:
10050   // Display the error message...
10051   set       __GL_glDrawData.Options,    1
10052   set       __GL_glDrawData.Location.X, 0
10053   set       __GL_glDrawData.Location.Y, 56
10054   mov       __GL_glDrawData.Text,       'Error:'
10055   syscall   DrawText,                   __GL_glDrawData
10056   set       __GL_glDrawData.Options,    0
10057   set       __GL_glDrawData.Location.Y, 48
10058   mov       __GL_glDrawData.Text,       __GL_glErrorMsg
10059   syscall   DrawText,                   __GL_glDrawData
10060   return
10061 ends
10062 
10063 dseg segment
10064   __GL_tmpId             byte
10065   __GL_mode              byte
10066   __GL_sizeX             sdword
10067   __GL_sizeY             sdword
10068   __GL_sizeZ             sdword
10069   __GL_angle             sdword
10070 dseg ends
10071 
10072 //-----------------------------------------------------------------------------------------
10073 // Subroutine  : __GL_glBox
10074 // Description : Add a box with the dimensions: _sizeX, _sizeY, _sizeZ.
10075 //               Use mode _mode.
10076 //-----------------------------------------------------------------------------------------
10077 subroutine __GL_glBox
10078   shr      __GL_x1,                    __GL_sizeX, 1
10079   neg      __GL_x0,                    __GL_x1
10080   shr      __GL_y1,                    __GL_sizeY, 1
10081   neg      __GL_y0,                    __GL_y1
10082   shr      __GL_z1,                    __GL_sizeZ, 1
10083   neg      __GL_z0,                    __GL_z1
10084   __glBeginObject(__GL_tmpId)
10085     __glBegin(__GL_mode)
10086       __glAddVertex(__GL_x0, __GL_y0, __GL_z0)
10087       __glAddVertex(__GL_x1, __GL_y0, __GL_z0)
10088       __glAddVertex(__GL_x1, __GL_y1, __GL_z0)
10089       __glAddVertex(__GL_x0, __GL_y1, __GL_z0)
10090     __glEnd()
10091     __glBegin(__GL_mode)
10092       __glAddVertex(__GL_x0, __GL_y1, __GL_z1)
10093       __glAddVertex(__GL_x1, __GL_y1, __GL_z1)
10094       __glAddVertex(__GL_x1, __GL_y0, __GL_z1)
10095       __glAddVertex(__GL_x0, __GL_y0, __GL_z1)
10096     __glEnd()
10097 
10098     __glBegin(__GL_mode)
10099       __glAddVertex(__GL_x0, __GL_y1, __GL_z0)
10100       __glAddVertex(__GL_x0, __GL_y1, __GL_z1)
10101       __glAddVertex(__GL_x0, __GL_y0, __GL_z1)
10102       __glAddVertex(__GL_x0, __GL_y0, __GL_z0)
10103     __glEnd()
10104     __glBegin(__GL_mode)
10105       __glAddVertex(__GL_x1, __GL_y0, __GL_z0)
10106       __glAddVertex(__GL_x1, __GL_y0, __GL_z1)
10107       __glAddVertex(__GL_x1, __GL_y1, __GL_z1)
10108       __glAddVertex(__GL_x1, __GL_y1, __GL_z0)
10109     __glEnd()
10110 
10111     __glBegin(__GL_mode)
10112       __glAddVertex(__GL_x0, __GL_y0, __GL_z0)
10113       __glAddVertex(__GL_x0, __GL_y0, __GL_z1)
10114       __glAddVertex(__GL_x1, __GL_y0, __GL_z1)
10115       __glAddVertex(__GL_x1, __GL_y0, __GL_z0)
10116     __glEnd()
10117     __glBegin(__GL_mode)
10118       __glAddVertex(__GL_x1, __GL_y1, __GL_z0)
10119       __glAddVertex(__GL_x1, __GL_y1, __GL_z1)
10120       __glAddVertex(__GL_x0, __GL_y1, __GL_z1)
10121       __glAddVertex(__GL_x0, __GL_y1, __GL_z0)
10122     __glEnd()
10123   __glEndObject()
10124   return
10125 ends
10126 
10127 //-----------------------------------------------------------------------------------------
10128 // Subroutine  : __GL_glPyramid
10129 // Description : Add a pyramid with the dimensions: _sizeX, _sizeY, _sizeZ.
10130 //               Use mode _mode.
10131 //-----------------------------------------------------------------------------------------
10132 subroutine __GL_glPyramid
10133   shr      __GL_x1,                    __GL_sizeX, 1
10134   neg      __GL_x0,                    __GL_x1
10135   shr      __GL_z1,                    __GL_sizeZ, 1
10136   neg      __GL_z0,                    __GL_z1
10137   neg      __GL_y0,                    __GL_sizeY
10138   __glBeginObject(__GL_tmpId)
10139     __glBegin(__GL_mode)
10140       __glAddVertex(__GL_x1, 0, __GL_z0)
10141       __glAddVertex(__GL_x1, 0, __GL_z1)
10142       __glAddVertex(__GL_x0, 0, __GL_z1)
10143       __glAddVertex(__GL_x0, 0, __GL_z0)
10144     __glEnd()
10145 
10146     __glBegin(__GL_mode)
10147       __glAddVertex(__GL_x0, 0,   __GL_z0)
10148       __glAddVertex(__GL_x0, 0,   __GL_z1)
10149       __glAddVertex(0,   __GL_y0, 0)
10150     __glEnd()
10151     __glBegin(__GL_mode)
10152       __glAddVertex(__GL_x1, 0,   __GL_z1)
10153       __glAddVertex(__GL_x1, 0,   __GL_z0)
10154       __glAddVertex(0,   __GL_y0, 0)
10155     __glEnd()
10156     __glBegin(__GL_mode)
10157       __glAddVertex(__GL_x1, 0,   __GL_z0)
10158       __glAddVertex(__GL_x0, 0,   __GL_z0)
10159       __glAddVertex(0,   __GL_y0, 0)
10160     __glEnd()
10161     __glBegin(__GL_mode)
10162       __glAddVertex(__GL_x0, 0,   __GL_z1)
10163       __glAddVertex(__GL_x1, 0,   __GL_z1)
10164       __glAddVertex(0,   __GL_y0, 0)
10165     __glEnd()
10166   __glEndObject()
10167   return
10168 ends
10169 
10170 // no documentation for these functions since they are essentially readonly
10171 #define SetLSInputBuffer(_p, _offset, _cnt, _data) __setLSInputBuffer(_p, _offset, _cnt, _data)
10172 #define SetLSInputBufferInPtr(_p, _n) __setLSInputBufferInPtr(_p, _n)
10173 #define SetLSInputBufferOutPtr(_p, _n) __setLSInputBufferOutPtr(_p, _n)
10174 #define SetLSInputBufferBytesToRx(_p, _n) __setLSInputBufferBytesToRx(_p, _n)
10175 
10176 #define SetLSOutputBuffer(_p, _offset, _cnt, _data) __setLSOutputBuffer(_p, _offset, _cnt, _data)
10177 #define SetLSOutputBufferInPtr(_p, _n) __setLSOutputBufferInPtr(_p, _n)
10178 #define SetLSOutputBufferOutPtr(_p, _n) __setLSOutputBufferOutPtr(_p, _n)
10179 #define SetLSOutputBufferBytesToRx(_p, _n) __setLSOutputBufferBytesToRx(_p, _n)
10180 
10181 #define SetLSMode(_p, _n) __setLSMode(_p, _n)
10182 #define SetLSChannelState(_p, _n) __setLSChannelState(_p, _n)
10183 #define SetLSErrorType(_p, _n) __setLSErrorType(_p, _n)
10184 #define SetLSState(_n) __setLSState(_n)
10185 #define SetLSSpeed(_n) __setLSSpeed(_n)
10186 
10187 #ifdef __ENHANCED_FIRMWARE
10188 #define SetLSNoRestartOnRead(_n) __setLSNoRestartOnRead(_n)
10189 #endif
10190 
10191 // these functions really cannot be used for any useful purpose (read-only)
10192 #define SetBTDeviceName(_p, _str) __setBTDeviceName(_p, _str)
10193 #define SetBTDeviceAddress(_p, _btaddr) __setBTDeviceAddress(_p, _btaddr)
10194 #define SetBTConnectionName(_p, _str) __setBTConnectionName(_p, _str)
10195 #define SetBTConnectionPinCode(_p, _code) __setBTConnectionPinCode(_p, _code)
10196 #define SetBTConnectionAddress(_p, _btaddr) __setBTConnectionAddress(_p, _btaddr)
10197 #define SetBrickDataName(_str) SetCommModuleBytes(CommOffsetBrickDataName, 16, _str)
10198 #define SetBrickDataAddress(_btaddr) SetCommModuleBytes(CommOffsetBrickDataBdAddr, 7, _btaddr)
10199 #define SetBTDeviceClass(_p, _n) __setBTDeviceClass(_p, _n)
10200 #define SetBTDeviceStatus(_p, _n) __setBTDeviceStatus(_p, _n)
10201 #define SetBTConnectionClass(_p, _n) __setBTConnectionClass(_p, _n)
10202 #define SetBTConnectionHandleNum(_p, _n) __setBTConnectionHandleNum(_p, _n)
10203 #define SetBTConnectionStreamStatus(_p, _n) __setBTConnectionStreamStatus(_p, _n)
10204 #define SetBTConnectionLinkQuality(_p, _n) __setBTConnectionLinkQuality(_p, _n)
10205 #define SetBrickDataBluecoreVersion(_n) __setBrickDataBluecoreVersion(_n)
10206 #define SetBrickDataBtStateStatus(_n) __setBrickDataBtStateStatus(_n)
10207 #define SetBrickDataBtHardwareStatus(_n) __setBrickDataBtHardwareStatus(_n)
10208 #define SetBrickDataTimeoutValue(_n) __setBrickDataTimeoutValue(_n)
10209 #define SetBTDeviceCount(_n) __setBTDeviceCount(_n)
10210 #define SetBTDeviceNameCount(_n) __setBTDeviceNameCount(_n)
10211 
10212 // not ready to be documented
10213 #define SpawnProgram(_fname) __spawnProgram(_fname)
10214 
10215 // standard firmware math functions written by Tamas Sorosy (www.sorosy.com)
10216 
10217 // X is any integer, Y is the sqrt value (0->max), if X<0, Y is the sqrt value of absolute X
10218 #define Sqrt(_X,_R) __SQRT(_X,_R)
10219 
10220 // X is any integer in degrees, Y is 100* the sin value (-100->100)
10221 #define Sin(_X,_R) __SIN(_X,_R)
10222 
10223 // X is any integer in degrees, Y is 100* the cos value (-100->100)
10224 #define Cos(_X,_R) __COS(_X,_R)
10225 
10226 // X is 100* the sin value (-100->100), Y is -90->90, Y is 101 if X is outside -100->100 range
10227 #define Asin(_X,_R) __ASIN(_X,_R)
10228 
10229 // X is 100* the cos value (-100->100), Y is 0->180, Y is -11 if X is outside -100->100 range
10230 #define Acos(_X,_R) __ACOS(_X,_R)
10231 
10232 
10233 dseg segment
10234   __Pos_i sword
10235   __Pos_l1 sword
10236   __Pos_lDelta sword
10237   __Pos_tmpstr byte[]
10238   __Pos_s2 byte[]
10239   __Pos_s1 byte[]
10240   __Pos_Result sword
10241   __Pos_Mutex mutex
10242 dseg ends
10243 
10244 subroutine __PosSubroutine
10245 	arrsize __Pos_l1, __Pos_s1
10246 	sub __Pos_l1, __Pos_l1, 1
10247 	arrsize __Pos_lDelta, __Pos_s2
10248 	sub __Pos_lDelta, __Pos_lDelta, __Pos_l1
10249 	set __Pos_i, 0
10250 __Pos_Repeat:
10251 	sub __Pos_lDelta, __Pos_lDelta, 1
10252 	brtst 0, __Pos_RepeatEnd, __Pos_lDelta
10253 	strsubset __Pos_tmpstr, __Pos_s2, __Pos_i, __Pos_l1
10254 	cmp 4, __Pos_Result, __Pos_s1, __Pos_tmpstr
10255 	brtst 4, __Pos_RepeatAgain, __Pos_Result
10256     mov __Pos_Result, __Pos_i
10257 	return
10258 __Pos_RepeatAgain:
10259 	add __Pos_i, __Pos_i, 1
10260 	jmp __Pos_Repeat
10261 __Pos_RepeatEnd:
10262 	set __Pos_Result, -1
10263 	return
10264 ends
10265 
10266 #define __doPos(_s1, _s2, _result) \
10267   acquire __Pos_Mutex \
10268   mov __Pos_s1, _s1 \
10269   mov __Pos_s2, _s2 \
10270   call __PosSubroutine \
10271   mov _result, __Pos_Result \
10272   release __Pos_Mutex \
10273 
10274 
10275 #endif
10276 
10277 
10278 ///////////////////////////////////////////////////////////////////////////////
10279 //////////////////////////////// OUTPUT MODULE ////////////////////////////////
10280 ///////////////////////////////////////////////////////////////////////////////
10281 
10282 
10283 /** @addtogroup NXTFirmwareModules
10284  * @{
10285  */
10286 /** @addtogroup OutputModule
10287  * @{
10288  */
10289 /** @defgroup OutputModuleFunctions Output module functions
10290  * Functions for accessing and modifying output module features.
10291  * @{
10292  */
10293 /**
10294  * Reset tachometer counter.
10295  * Reset the tachometer count and tachometer limit goal for the specified
10296  * outputs.
10297  *
10298  * \param _p Desired output ports. Can be a constant or a variable, see
10299  * \ref OutputPortConstants. For multiple outputs at the same time
10300  * you need to add single output port values into a byte array and pass the array
10301  * instead of a single numeric value.
10302  */
10303 #define ResetTachoCount(_p) __resetTachoCount(_p)
10304 
10305 /**
10306  * Reset block-relative counter.
10307  * Reset the block-relative position counter for the specified outputs.
10308  *
10309  * \param _p Desired output ports. Can be a constant or a variable, see
10310  * \ref OutputPortConstants. For multiple outputs at the same time
10311  * you need to add single output port values into a byte array and pass the array
10312  * instead of a single numeric value.
10313  */
10314 #define ResetBlockTachoCount(_p) __resetBlockTachoCount(_p)
10315 
10316 /**
10317  * Reset program-relative counter.
10318  * Reset the program-relative position counter for the specified outputs.
10319  *
10320  * \param _p Desired output ports. Can be a constant or a variable, see
10321  * \ref OutputPortConstants. For multiple outputs at the same time
10322  * you need to add single output port values into a byte array and pass the array
10323  * instead of a single numeric value.
10324  */
10325 #define ResetRotationCount(_p) __resetRotationCount(_p)
10326 
10327 /**
10328  * Reset all tachometer counters.
10329  * Reset all three position counters and reset the current tachometer limit
10330  * goal for the specified outputs.
10331  *
10332  * \param _p Desired output ports. Can be a constant or a variable, see
10333  * \ref OutputPortConstants. For multiple outputs at the same time
10334  * you need to add single output port values into a byte array and pass the array
10335  * instead of a single numeric value.
10336  */
10337 #define ResetAllTachoCounts(_p) __resetAllTachoCounts(_p)
10338 
10339 /**
10340  * Run motors forward and reset counters.
10341  * Set outputs to forward direction and turn them on.
10342  *
10343  * \param _ports Desired output ports. Can be a constant or a variable, see
10344  * \ref OutputPortConstants. If you use a variable and want to control multiple
10345  * outputs in a single call you need to use a byte array rather than a byte and
10346  * store the output port values in the byte array before passing it into this function.
10347  * \param _pwr Output power, 0 to 100. Can be negative to reverse direction.
10348  * \param _reset Position counters reset control. It must be a constant, see
10349  * \ref TachoResetConstants.
10350  */
10351 #define OnFwdEx(_ports, _pwr, _reset) __OnFwdEx(_ports, _pwr, _reset)
10352 
10353 /**
10354  * Run motors backward and reset counters.
10355  * Set outputs to reverse direction and turn them on.
10356  *
10357  * \param _ports Desired output ports. Can be a constant or a variable, see
10358  * \ref OutputPortConstants. If you use a variable and want to control multiple
10359  * outputs in a single call you need to use a byte array rather than a byte and
10360  * store the output port values in the byte array before passing it into this function.
10361  * \param _pwr Output power, 0 to 100. Can be negative to reverse direction.
10362  * \param _reset Position counters reset control. It must be a constant, see
10363  * \ref TachoResetConstants.
10364  */
10365 #define OnRevEx(_ports, _pwr, _reset) __OnRevEx(_ports, _pwr, _reset)
10366 
10367 /**
10368  * Run motors forward and reset counters.
10369  * Set outputs to forward direction and turn them on.
10370  * Specify proportional, integral, and derivative factors.
10371  *
10372  * \param _ports Desired output ports. Can be a constant or a variable, see
10373  * \ref OutputPortConstants. If you use a variable and want to control multiple
10374  * outputs in a single call you need to use a byte array rather than a byte and
10375  * store the output port values in the byte array before passing it into this function.
10376  * \param _pwr Output power, 0 to 100. Can be negative to reverse direction.
10377  * \param _reset Position counters reset control. It must be a constant, see
10378  * \ref TachoResetConstants.
10379  * \param _p Proportional factor used by the firmware's PID motor control
10380  * algorithm. See \ref PIDConstants.
10381  * \param _i Integral factor used by the firmware's PID motor control
10382  * algorithm. See \ref PIDConstants.
10383  * \param _d Derivative factor used by the firmware's PID motor control
10384  * algorithm. See \ref PIDConstants.
10385  */
10386 #define OnFwdExPID(_ports, _pwr, _reset, _p, _i, _d) __OnFwdExPID(_ports, _pwr, _reset, _p, _i, _d)
10387 
10388 /**
10389  * Run motors backward and reset counters.
10390  * Set outputs to reverse direction and turn them on.
10391  * Specify proportional, integral, and derivative factors.
10392  *
10393  * \param _ports Desired output ports. Can be a constant or a variable, see
10394  * \ref OutputPortConstants. If you use a variable and want to control multiple
10395  * outputs in a single call you need to use a byte array rather than a byte and
10396  * store the output port values in the byte array before passing it into this function.
10397  * \param _pwr Output power, 0 to 100. Can be negative to reverse direction.
10398  * \param _reset Position counters reset control. It must be a constant, see
10399  * \ref TachoResetConstants.
10400  * \param _p Proportional factor used by the firmware's PID motor control
10401  * algorithm. See \ref PIDConstants.
10402  * \param _i Integral factor used by the firmware's PID motor control
10403  * algorithm. See \ref PIDConstants.
10404  * \param _d Derivative factor used by the firmware's PID motor control
10405  * algorithm. See \ref PIDConstants.
10406  */
10407 #define OnRevExPID(_ports, _pwr, _reset, _p, _i, _d) __OnRevExPID(_ports, _pwr, _reset, _p, _i, _d)
10408 
10409 /**
10410  * Run motors forward.
10411  * Set outputs to forward direction and turn them on.
10412  *
10413  * \param _ports Desired output ports. Can be a constant or a variable, see
10414  * \ref OutputPortConstants. If you use a variable and want to control multiple
10415  * outputs in a single call you need to use a byte array rather than a byte and
10416  * store the output port values in the byte array before passing it into this function.
10417  * \param _pwr Output power, 0 to 100. Can be negative to reverse direction.
10418  */
10419 #define OnFwd(_ports, _pwr) OnFwdEx(_ports, _pwr, RESET_BLOCKANDTACHO)
10420 
10421 /**
10422  * Run motors backward.
10423  * Set outputs to reverse direction and turn them on.
10424  *
10425  * \param _ports Desired output ports. Can be a constant or a variable, see
10426  * \ref OutputPortConstants. If you use a variable and want to control multiple
10427  * outputs in a single call you need to use a byte array rather than a byte and
10428  * store the output port values in the byte array before passing it into this function.
10429  * \param _pwr Output power, 0 to 100. Can be negative to reverse direction.
10430  */
10431 #define OnRev(_ports, _pwr) OnRevEx(_ports, _pwr, RESET_BLOCKANDTACHO)
10432 
10433 /**
10434  * Coast motors and reset counters.
10435  * Turn off the specified outputs, making them coast to a stop.
10436  *
10437  * \param _ports Desired output ports. Can be a constant or a variable, see
10438  * \ref OutputPortConstants. If you use a variable and want to control multiple
10439  * outputs in a single call you need to use a byte array rather than a byte and
10440  * store the output port values in the byte array before passing it into this function.
10441  * \param _reset Position counters reset control. It must be a constant, see
10442  * \ref TachoResetConstants.
10443  */
10444 #define CoastEx(_ports, _reset) __CoastEx(_ports, _reset)
10445 
10446 /**
10447  * Turn motors off and reset counters.
10448  * Turn the specified outputs off (with braking).
10449  *
10450  * \param _ports Desired output ports. Can be a constant or a variable, see
10451  * \ref OutputPortConstants. If you use a variable and want to control multiple
10452  * outputs in a single call you need to use a byte array rather than a byte and
10453  * store the output port values in the byte array before passing it into this function.
10454  * \param _reset Position counters reset control. It must be a constant, see
10455  * \ref TachoResetConstants.
10456  */
10457 #define OffEx(_ports, _reset) __OffEx(_ports, _reset)
10458 
10459 /**
10460  * Coast motors.
10461  * Turn off the specified outputs, making them coast to a stop.
10462  *
10463  * \param _ports Desired output ports. Can be a constant or a variable, see
10464  * \ref OutputPortConstants. If you use a variable and want to control multiple
10465  * outputs in a single call you need to use a byte array rather than a byte and
10466  * store the output port values in the byte array before passing it into this function.
10467  */
10468 #define Coast(_ports) CoastEx(_ports, RESET_BLOCKANDTACHO)
10469 
10470 /**
10471  * Turn motors off.
10472  * Turn the specified outputs off (with braking).
10473  *
10474  * \param _ports Desired output ports. Can be a constant or a variable, see
10475  * \ref OutputPortConstants. If you use a variable and want to control multiple
10476  * outputs in a single call you need to use a byte array rather than a byte and
10477  * store the output port values in the byte array before passing it into this function.
10478  */
10479 #define Off(_ports) OffEx(_ports, RESET_BLOCKANDTACHO)
10480 
10481 /**
10482  * Float motors.
10483  * Make outputs float. Float is an alias for Coast.
10484  *
10485  * \param _ports Desired output ports. Can be a constant or a variable, see
10486  * \ref OutputPortConstants. If you use a variable and want to control multiple
10487  * outputs in a single call you need to use a byte array rather than a byte and
10488  * store the output port values in the byte array before passing it into this function.
10489  */
10490 #define Float(_ports) Coast(_ports)
10491 
10492 /**
10493  * Run motors forward regulated and reset counters.
10494  * Run the specified outputs forward using the specified regulation mode.
10495  *
10496  * \param _ports Desired output ports. Can be a constant or a variable, see
10497  * \ref OutputPortConstants. If you use a variable and want to control multiple
10498  * outputs in a single call you need to use a byte array rather than a byte and
10499  * store the output port values in the byte array before passing it into this function.
10500  * \param _pwr Output power, 0 to 100. Can be negative to reverse direction.
10501  * \param _regmode Regulation mode, see \ref OutRegModeConstants.
10502  * \param _reset Position counters reset control. It must be a constant, see
10503  * \ref TachoResetConstants.
10504  */
10505 #define OnFwdRegEx(_ports, _pwr, _regmode, _reset) __OnFwdRegEx(_ports, _pwr, _regmode, _reset)
10506 
10507 /**
10508  * Run motors backward regulated and reset counters.
10509  * Run the specified outputs in reverse using the specified regulation mode.
10510  *
10511  * \param _ports Desired output ports. Can be a constant or a variable, see
10512  * \ref OutputPortConstants. If you use a variable and want to control multiple
10513  * outputs in a single call you need to use a byte array rather than a byte and
10514  * store the output port values in the byte array before passing it into this function.
10515  * \param _pwr Output power, 0 to 100. Can be negative to reverse direction.
10516  * \param _regmode Regulation mode, see \ref OutRegModeConstants.
10517  * \param _reset Position counters reset control. It must be a constant, see
10518  * \ref TachoResetConstants.
10519  */
10520 #define OnRevRegEx(_ports, _pwr, _regmode, _reset) __OnRevRegEx(_ports, _pwr, _regmode, _reset)
10521 
10522 /**
10523  * Run motors forward regulated and reset counters with PID factors.
10524  * Run the specified outputs forward using the specified regulation mode.
10525  * Specify proportional, integral, and derivative factors.
10526  *
10527  * \param _ports Desired output ports. Can be a constant or a variable, see
10528  * \ref OutputPortConstants. If you use a variable and want to control multiple
10529  * outputs in a single call you need to use a byte array rather than a byte and
10530  * store the output port values in the byte array before passing it into this function.
10531  * \param _pwr Output power, 0 to 100. Can be negative to reverse direction.
10532  * \param _regmode Regulation mode, see \ref OutRegModeConstants.
10533  * \param _reset Position counters reset control. It must be a constant, see
10534  * \ref TachoResetConstants.
10535  * \param _p Proportional factor used by the firmware's PID motor control
10536  * algorithm. See \ref PIDConstants.
10537  * \param _i Integral factor used by the firmware's PID motor control
10538  * algorithm. See \ref PIDConstants.
10539  * \param _d Derivative factor used by the firmware's PID motor control
10540  * algorithm. See \ref PIDConstants.
10541  */
10542 #define OnFwdRegExPID(_ports, _pwr, _regmode, _reset, _p, _i, _d) __OnFwdRegExPID(_ports, _pwr, _regmode, _reset, _p, _i, _d)
10543 
10544 /**
10545  * Run motors backward regulated and reset counters with PID factors.
10546  * Run the specified outputs in reverse using the specified regulation mode.
10547  * Specify proportional, integral, and derivative factors.
10548  *
10549  * \param _ports Desired output ports. Can be a constant or a variable, see
10550  * \ref OutputPortConstants. If you use a variable and want to control multiple
10551  * outputs in a single call you need to use a byte array rather than a byte and
10552  * store the output port values in the byte array before passing it into this function.
10553  * \param _pwr Output power, 0 to 100. Can be negative to reverse direction.
10554  * \param _regmode Regulation mode, see \ref OutRegModeConstants.
10555  * \param _reset Position counters reset control. It must be a constant, see
10556  * \ref TachoResetConstants.
10557  * \param _p Proportional factor used by the firmware's PID motor control
10558  * algorithm. See \ref PIDConstants.
10559  * \param _i Integral factor used by the firmware's PID motor control
10560  * algorithm. See \ref PIDConstants.
10561  * \param _d Derivative factor used by the firmware's PID motor control
10562  * algorithm. See \ref PIDConstants.
10563  */
10564 #define OnRevRegExPID(_ports, _pwr, _regmode, _reset, _p, _i, _d) __OnRevRegExPID(_ports, _pwr, _regmode, _reset, _p, _i, _d)
10565 
10566 /**
10567  * Run motors forward regulated.
10568  * Run the specified outputs forward using the specified regulation mode.
10569  *
10570  * \param _ports Desired output ports. Can be a constant or a variable, see
10571  * \ref OutputPortConstants. If you use a variable and want to control multiple
10572  * outputs in a single call you need to use a byte array rather than a byte and
10573  * store the output port values in the byte array before passing it into this function.
10574  * \param _pwr Output power, 0 to 100. Can be negative to reverse direction.
10575  * \param _regmode Regulation mode, see \ref OutRegModeConstants.
10576  */
10577 #define OnFwdReg(_ports, _pwr, _regmode) OnFwdRegEx(_ports, _pwr, _regmode, RESET_BLOCKANDTACHO)
10578 
10579 /**
10580  * Run motors forward regulated.
10581  * Run the specified outputs in reverse using the specified regulation mode.
10582  *
10583  * \param _ports Desired output ports. Can be a constant or a variable, see
10584  * \ref OutputPortConstants. If you use a variable and want to control multiple
10585  * outputs in a single call you need to use a byte array rather than a byte and
10586  * store the output port values in the byte array before passing it into this function.
10587  * \param _pwr Output power, 0 to 100. Can be negative to reverse direction.
10588  * \param _regmode Regulation mode, see \ref OutRegModeConstants.
10589  */
10590 #define OnRevReg(_ports, _pwr, _regmode) OnRevRegEx(_ports, _pwr, _regmode, RESET_BLOCKANDTACHO)
10591 
10592 /**
10593  * Run motors forward regulated with PID factors.
10594  * Run the specified outputs forward using the specified regulation mode.
10595  * Specify proportional, integral, and derivative factors.
10596  *
10597  * \param _ports Desired output ports. Can be a constant or a variable, see
10598  * \ref OutputPortConstants. If you use a variable and want to control multiple
10599  * outputs in a single call you need to use a byte array rather than a byte and
10600  * store the output port values in the byte array before passing it into this function.
10601  * \param _pwr Output power, 0 to 100. Can be negative to reverse direction.
10602  * \param _regmode Regulation mode, see \ref OutRegModeConstants.
10603  * \param _p Proportional factor used by the firmware's PID motor control
10604  * algorithm. See \ref PIDConstants.
10605  * \param _i Integral factor used by the firmware's PID motor control
10606  * algorithm. See \ref PIDConstants.
10607  * \param _d Derivative factor used by the firmware's PID motor control
10608  * algorithm. See \ref PIDConstants.
10609  */
10610 #define OnFwdRegPID(_ports, _pwr, _regmode, _p, _i, _d) OnFwdRegExPID(_ports, _pwr, _regmode, RESET_BLOCKANDTACHO, _p, _i, _d)
10611 
10612 /**
10613  * Run motors reverse regulated with PID factors.
10614  * Run the specified outputs in reverse using the specified regulation mode.
10615  * Specify proportional, integral, and derivative factors.
10616  *
10617  * \param _ports Desired output ports. Can be a constant or a variable, see
10618  * \ref OutputPortConstants. If you use a variable and want to control multiple
10619  * outputs in a single call you need to use a byte array rather than a byte and
10620  * store the output port values in the byte array before passing it into this function.
10621  * \param _pwr Output power, 0 to 100. Can be negative to reverse direction.
10622  * \param _regmode Regulation mode, see \ref OutRegModeConstants.
10623  * \param _p Proportional factor used by the firmware's PID motor control
10624  * algorithm. See \ref PIDConstants.
10625  * \param _i Integral factor used by the firmware's PID motor control
10626  * algorithm. See \ref PIDConstants.
10627  * \param _d Derivative factor used by the firmware's PID motor control
10628  * algorithm. See \ref PIDConstants.
10629  */
10630 #define OnRevRegPID(_ports, _pwr, _regmode, _p, _i, _d) OnRevRegExPID(_ports, _pwr, _regmode, RESET_BLOCKANDTACHO, _p, _i, _d)
10631 
10632 /**
10633  * Run motors forward synchronised and reset counters.
10634  * Run the specified outputs forward with regulated synchronization using the
10635  * specified turn ratio.
10636  *
10637  * \param _ports Desired output ports. Can be a constant or a variable, see
10638  * \ref OutputPortConstants. If you use a variable and want to control multiple
10639  * outputs in a single call you need to use a byte array rather than a byte and
10640  * store the output port values in the byte array before passing it into this function.
10641  * \param _pwr Output power, 0 to 100. Can be negative to reverse direction.
10642  * \param _turnpct Turn ratio, -100 to 100. The direction of your vehicle will
10643  * depend on its construction.
10644  * \param _reset Position counters reset control. It must be a constant, see
10645  * \ref TachoResetConstants.
10646  */
10647 #define OnFwdSyncEx(_ports, _pwr, _turnpct, _reset) __OnFwdSyncEx(_ports, _pwr, _turnpct, _reset)
10648 
10649 /**
10650  * Run motors backward synchronised and reset counters.
10651  * Run the specified outputs in reverse with regulated synchronization using
10652  * the specified turn ratio.
10653  *
10654  * \param _ports Desired output ports. Can be a constant or a variable, see
10655  * \ref OutputPortConstants. If you use a variable and want to control multiple
10656  * outputs in a single call you need to use a byte array rather than a byte and
10657  * store the output port values in the byte array before passing it into this function.
10658  * \param _pwr Output power, 0 to 100. Can be negative to reverse direction.
10659  * \param _turnpct Turn ratio, -100 to 100. The direction of your vehicle will
10660  * depend on its construction.
10661  * \param _reset Position counters reset control. It must be a constant, see
10662  * \ref TachoResetConstants.
10663  */
10664 #define OnRevSyncEx(_ports, _pwr, _turnpct, _reset) __OnRevSyncEx(_ports, _pwr, _turnpct, _reset)
10665 
10666 /**
10667  * Run motors forward synchronised and reset counters with PID factors.
10668  * Run the specified outputs forward with regulated synchronization using the
10669  * specified turn ratio.
10670  * Specify proportional, integral, and derivative factors.
10671  *
10672  * \param _ports Desired output ports. Can be a constant or a variable, see
10673  * \ref OutputPortConstants. If you use a variable and want to control multiple
10674  * outputs in a single call you need to use a byte array rather than a byte and
10675  * store the output port values in the byte array before passing it into this function.
10676  * \param _pwr Output power, 0 to 100. Can be negative to reverse direction.
10677  * \param _turnpct Turn ratio, -100 to 100. The direction of your vehicle will
10678  * depend on its construction.
10679  * \param _reset Position counters reset control. It must be a constant, see
10680  * \ref TachoResetConstants.
10681  * \param _p Proportional factor used by the firmware's PID motor control
10682  * algorithm. See \ref PIDConstants.
10683  * \param _i Integral factor used by the firmware's PID motor control
10684  * algorithm. See \ref PIDConstants.
10685  * \param _d Derivative factor used by the firmware's PID motor control
10686  * algorithm. See \ref PIDConstants.
10687  */
10688 #define OnFwdSyncExPID(_ports, _pwr, _turnpct, _reset, _p, _i, _d) __OnFwdSyncExPID(_ports, _pwr, _turnpct, _reset, _p, _i, _d)
10689 
10690 /**
10691  * Run motors backward synchronised and reset counters with PID factors.
10692  * Run the specified outputs in reverse with regulated synchronization using
10693  * the specified turn ratio.
10694  * Specify proportional, integral, and derivative factors.
10695  *
10696  * \param _ports Desired output ports. Can be a constant or a variable, see
10697  * \ref OutputPortConstants. If you use a variable and want to control multiple
10698  * outputs in a single call you need to use a byte array rather than a byte and
10699  * store the output port values in the byte array before passing it into this function.
10700  * \param _pwr Output power, 0 to 100. Can be negative to reverse direction.
10701  * \param _turnpct Turn ratio, -100 to 100. The direction of your vehicle will
10702  * depend on its construction.
10703  * \param _reset Position counters reset control. It must be a constant, see
10704  * \ref TachoResetConstants.
10705  * \param _p Proportional factor used by the firmware's PID motor control
10706  * algorithm. See \ref PIDConstants.
10707  * \param _i Integral factor used by the firmware's PID motor control
10708  * algorithm. See \ref PIDConstants.
10709  * \param _d Derivative factor used by the firmware's PID motor control
10710  * algorithm. See \ref PIDConstants.
10711  */
10712 #define OnRevSyncExPID(_ports, _pwr, _turnpct, _reset, _p, _i, _d) __OnRevSyncExPID(_ports, _pwr, _turnpct, _reset, _p, _i, _d)
10713 
10714 /**
10715  * Run motors forward synchronised.
10716  * Run the specified outputs forward with regulated synchronization using the
10717  * specified turn ratio.
10718  *
10719  * \param _ports Desired output ports. Can be a constant or a variable, see
10720  * \ref OutputPortConstants. If you use a variable and want to control multiple
10721  * outputs in a single call you need to use a byte array rather than a byte and
10722  * store the output port values in the byte array before passing it into this function.
10723  * \param _pwr Output power, 0 to 100. Can be negative to reverse direction.
10724  * \param _turnpct Turn ratio, -100 to 100. The direction of your vehicle will
10725  * depend on its construction.
10726  */
10727 #define OnFwdSync(_ports, _pwr, _turnpct) OnFwdSyncEx(_ports, _pwr, _turnpct, RESET_BLOCKANDTACHO)
10728 
10729 /**
10730  * Run motors backward synchronised.
10731  * Run the specified outputs in reverse with regulated synchronization using
10732  * the specified turn ratio.
10733  *
10734  * \param _ports Desired output ports. Can be a constant or a variable, see
10735  * \ref OutputPortConstants. If you use a variable and want to control multiple
10736  * outputs in a single call you need to use a byte array rather than a byte and
10737  * store the output port values in the byte array before passing it into this function.
10738  * \param _pwr Output power, 0 to 100. Can be negative to reverse direction.
10739  * \param _turnpct Turn ratio, -100 to 100. The direction of your vehicle will
10740  * depend on its construction.
10741  */
10742 #define OnRevSync(_ports, _pwr, _turnpct) OnRevSyncEx(_ports, _pwr, _turnpct, RESET_BLOCKANDTACHO)
10743 
10744 /**
10745  * Run motors forward synchronised with PID factors.
10746  * Run the specified outputs forward with regulated synchronization using the
10747  * specified turn ratio.
10748  * Specify proportional, integral, and derivative factors.
10749  *
10750  * \param _ports Desired output ports. Can be a constant or a variable, see
10751  * \ref OutputPortConstants. If you use a variable and want to control multiple
10752  * outputs in a single call you need to use a byte array rather than a byte and
10753  * store the output port values in the byte array before passing it into this function.
10754  * \param _pwr Output power, 0 to 100. Can be negative to reverse direction.
10755  * \param _turnpct Turn ratio, -100 to 100. The direction of your vehicle will
10756  * depend on its construction.
10757  * \param _p Proportional factor used by the firmware's PID motor control
10758  * algorithm. See \ref PIDConstants.
10759  * \param _i Integral factor used by the firmware's PID motor control
10760  * algorithm. See \ref PIDConstants.
10761  * \param _d Derivative factor used by the firmware's PID motor control
10762  * algorithm. See \ref PIDConstants.
10763  */
10764 #define OnFwdSyncPID(_ports, _pwr, _turnpct, _p, _i, _d) OnFwdSyncExPID(_ports, _pwr, _turnpct, RESET_BLOCKANDTACHO, _p, _i, _d)
10765 
10766 /**
10767  * Run motors backward synchronised with PID factors.
10768  * Run the specified outputs in reverse with regulated synchronization using
10769  * the specified turn ratio.
10770  * Specify proportional, integral, and derivative factors.
10771  *
10772  * \param _ports Desired output ports. Can be a constant or a variable, see
10773  * \ref OutputPortConstants. If you use a variable and want to control multiple
10774  * outputs in a single call you need to use a byte array rather than a byte and
10775  * store the output port values in the byte array before passing it into this function.
10776  * \param _pwr Output power, 0 to 100. Can be negative to reverse direction.
10777  * \param _turnpct Turn ratio, -100 to 100. The direction of your vehicle will
10778  * depend on its construction.
10779  * \param _p Proportional factor used by the firmware's PID motor control
10780  * algorithm. See \ref PIDConstants.
10781  * \param _i Integral factor used by the firmware's PID motor control
10782  * algorithm. See \ref PIDConstants.
10783  * \param _d Derivative factor used by the firmware's PID motor control
10784  * algorithm. See \ref PIDConstants.
10785  */
10786 #define OnRevSyncPID(_ports, _pwr, _turnpct, _p, _i, _d) OnRevSyncExPID(_ports, _pwr, _turnpct, RESET_BLOCKANDTACHO, _p, _i, _d)
10787 
10788 /**
10789  * Rotate motor.
10790  * Run the specified outputs forward for the specified number of degrees.
10791  * Specify proportional, integral, and derivative factors.
10792  *
10793  * \param _ports Desired output ports. Can be a constant or a variable, see
10794  * \ref OutputPortConstants. If you use a variable and want to control multiple
10795  * outputs in a single call you need to use a byte array rather than a byte and
10796  * store the output port values in the byte array before passing it into this function.
10797  * \param _pwr Output power, 0 to 100. Can be negative to reverse direction.
10798  * \param _angle Angle limit, in degree. Can be negative to reverse direction.
10799  * \param _turnpct Turn ratio, -100 to 100. The direction of your vehicle will
10800  * depend on its construction.
10801  * \param _bSync Synchronise two motors. Should be set to true if a non-zero
10802  * turn percent is specified or no turning will occur.
10803  * \param _bStop Specify whether the motor(s) should brake at the end of the
10804  * rotation.
10805  * \param _p Proportional factor used by the firmware's PID motor control
10806  * algorithm. See \ref PIDConstants.
10807  * \param _i Integral factor used by the firmware's PID motor control
10808  * algorithm. See \ref PIDConstants.
10809  * \param _d Derivative factor used by the firmware's PID motor control
10810  * algorithm. See \ref PIDConstants.
10811  */
10812 #define RotateMotorExPID(_ports, _pwr, _angle, _turnpct, _bSync, _bStop, _p, _i, _d) \
10813    __RotateMotorExPID(_ports, _pwr, _angle, _turnpct, _bSync, _bStop, _p, _i, _d)
10814 
10815 // default PID values are 96, 32, 32 (PID_3, PID_1, PID_1)
10816 
10817 /**
10818  * Rotate motor with PID factors.
10819  * Run the specified outputs forward for the specified number of degrees.
10820  * Specify proportional, integral, and derivative factors.
10821  *
10822  * \param _ports Desired output ports. Can be a constant or a variable, see
10823  * \ref OutputPortConstants. If you use a variable and want to control multiple
10824  * outputs in a single call you need to use a byte array rather than a byte and
10825  * store the output port values in the byte array before passing it into this function.
10826  * \param _pwr Output power, 0 to 100. Can be negative to reverse direction.
10827  * \param _angle Angle limit, in degree. Can be negative to reverse direction.
10828  * \param _p Proportional factor used by the firmware's PID motor control
10829  * algorithm. See \ref PIDConstants.
10830  * \param _i Integral factor used by the firmware's PID motor control
10831  * algorithm. See \ref PIDConstants.
10832  * \param _d Derivative factor used by the firmware's PID motor control
10833  * algorithm. See \ref PIDConstants.
10834  */
10835 #define RotateMotorPID(_ports, _pwr, _angle, _p, _i, _d) \
10836    __RotateMotorExPID(_ports, _pwr, _angle, 0, FALSE, TRUE, _p, _i, _d)
10837 
10838 /**
10839  * Rotate motor.
10840  * Run the specified outputs forward for the specified number of degrees.
10841  *
10842  * \param _ports Desired output ports. Can be a constant or a variable, see
10843  * \ref OutputPortConstants. If you use a variable and want to control multiple
10844  * outputs in a single call you need to use a byte array rather than a byte and
10845  * store the output port values in the byte array before passing it into this function.
10846  * \param _pwr Output power, 0 to 100. Can be negative to reverse direction.
10847  * \param _angle Angle limit, in degree. Can be negative to reverse direction.
10848  * \param _turnpct Turn ratio, -100 to 100. The direction of your vehicle will
10849  * depend on its construction.
10850  * \param _bSync Synchronise two motors. Should be set to true if a non-zero
10851  * turn percent is specified or no turning will occur.
10852  * \param _bStop Specify whether the motor(s) should brake at the end of the
10853  * rotation.
10854  */
10855 #define RotateMotorEx(_ports, _pwr, _angle, _turnpct, _bSync, _bStop) \
10856    __RotateMotorExPID(_ports, _pwr, _angle, _turnpct, _bSync, _bStop, PID_1, PID_0, PID_3)
10857 
10858 /**
10859  * Rotate motor.
10860  * Run the specified outputs forward for the specified number of degrees.
10861  *
10862  * \param _ports Desired output ports. Can be a constant or a variable, see
10863  * \ref OutputPortConstants. If you use a variable and want to control multiple
10864  * outputs in a single call you need to use a byte array rather than a byte and
10865  * store the output port values in the byte array before passing it into this function.
10866  * \param _pwr Output power, 0 to 100. Can be negative to reverse direction.
10867  * \param _angle Angle limit, in degree. Can be negative to reverse direction.
10868  */
10869 #define RotateMotor(_ports, _pwr, _angle) \
10870    __RotateMotorExPID(_ports, _pwr, _angle, 0, FALSE, TRUE, PID_1, PID_0, PID_3)
10871 
10872 /**
10873  * Set motor regulation frequency.
10874  * Set the motor regulation frequency to the specified number of milliseconds.
10875  * \param _n The motor regulation frequency in milliseconds
10876  */
10877 #define SetOutPwnFreq(_n) __setOutPwnFreq(_n)
10878 
10879 /**
10880  * Get motor regulation frequency.
10881  * Get the current motor regulation frequency.
10882  * \param _n The motor regulation frequency in milliseconds
10883  */
10884 #define GetOutPwnFreq(_n) __GetOutPwnFreq(_n)
10885 
10886 /**
10887  * Set motor regulation time.
10888  * Set the motor regulation time to the specified number of milliseconds.
10889  * \param _n The motor regulation time in milliseconds
10890  */
10891 #define SetOutRegulationTime(_n) __setOutRegulationTime(_n)
10892 
10893 /**
10894  * Get motor regulation time.
10895  * Get the current motor regulation time.
10896  * \param _n The motor regulation time in milliseconds
10897  */
10898 #define GetOutRegulationTime(_n) __GetOutRegulationTime(_n)
10899 
10900 #if defined(__ENHANCED_FIRMWARE) && (__FIRMWARE_VERSION > 107)
10901 /**
10902  * Set motor regulation options.
10903  * Set the motor regulation options.
10904  * \param _n The motor regulation options
10905  */
10906 #define SetOutRegulationOptions(_n) __setOutRegulationOptions(_n)
10907 
10908 /**
10909  * Get motor regulation options.
10910  * Get the current motor regulation options.
10911  * \param _n The motor regulation options
10912  */
10913 #define GetOutRegulationOptions(_n) __GetOutRegulationOptions(_n)
10914 #endif
10915 
10916 /** @} */ // end of OutputModuleFunctions group
10917 /** @} */ // end of OutputModule group
10918 /** @} */ // end of NXTFirmwareModules group
10919 
10920 
10921 ///////////////////////////////////////////////////////////////////////////////
10922 ///////////////////////////////// INPUT MODULE ////////////////////////////////
10923 ///////////////////////////////////////////////////////////////////////////////
10924 
10925 
10926 /** @addtogroup NXTFirmwareModules
10927  * @{
10928  */
10929 /** @addtogroup InputModule
10930  * @{
10931  */
10932 /** @defgroup InputModuleFunctions Input module functions
10933  * Functions for accessing and modifying input module features.
10934  * @{
10935  */
10936 
10937 /**
10938  * Set sensor type.
10939  * Set a sensor's type, which must be one of the predefined sensor type
10940  * constants.  After changing the type or the mode of a sensor
10941  * port you must call \ref ResetSensor to give the firmware time to reconfigure
10942  * the sensor port.
10943  * \sa SetSensorMode()
10944  * \param _port The port to configure. See \ref NBCInputPortConstants.
10945  * \param _t The desired sensor type.  See \ref NBCSensorTypeConstants.
10946  */
10947 #define SetSensorType(_port,_t) setin _t, _port, TypeField
10948 
10949 /**
10950  * Set sensor mode.
10951  * Set a sensor's mode, which should be one of the predefined sensor mode
10952  * constants. A slope parameter for boolean conversion, if desired, may be
10953  * added to the mode. After changing the type or the mode of a sensor
10954  * port you must call \ref ResetSensor to give the firmware time to reconfigure
10955  * the sensor port.
10956  * \sa SetSensorType()
10957  * \param _port The port to configure. See \ref NBCInputPortConstants.
10958  * \param _m The desired sensor mode. See \ref NBCSensorModeConstants.
10959  */
10960 #define SetSensorMode(_port,_m) setin _m, _port, InputModeField
10961 
10962 /**
10963  * Read sensor scaled value.
10964  * Return the processed sensor reading for a sensor on the specified port.
10965  *
10966  * \param _port The sensor port. See \ref NBCInputPortConstants. A variable whose value is
10967  * the desired sensor port may also be used.
10968  * \param _value The sensor's scaled value.
10969  */
10970 #define ReadSensor(_port,_value) getin _value, _port, ScaledValueField
10971 
10972 /**
10973  * Clear a sensor value.
10974  * Clear the value of a sensor - only affects sensors that are configured
10975  * to measure a cumulative quantity such as rotation or a pulse count.
10976  * \param _port The port to clear. See \ref NBCInputPortConstants.
10977  */
10978 #define ClearSensor(_port) setin 0, _port, ScaledValueField
10979 
10980 /**
10981  * Configure a touch sensor.
10982  * Configure the sensor on the specified port as a touch sensor.
10983  * \param _port The port to configure. See \ref NBCInputPortConstants.
10984  */
10985 #define SetSensorTouch(_port) __SetSensorTouch(_port)
10986 
10987 /**
10988  * Configure a light sensor.
10989  * Configure the sensor on the specified port as an NXT light sensor.
10990  * \param _port The port to configure. See \ref NBCInputPortConstants.
10991  */
10992 #define SetSensorLight(_port) __SetSensorLight(_port)
10993 
10994 /**
10995  * Configure a sound sensor.
10996  * Configure the sensor on the specified port as a sound sensor.
10997  * \param _port The port to configure. See \ref NBCInputPortConstants.
10998  */
10999 #define SetSensorSound(_port) __SetSensorSound(_port)
11000 
11001 /**
11002  * Configure an I2C sensor.
11003  * Configure the sensor on the specified port as a 9V powered I2C digital sensor.
11004  * \param _port The port to configure. See \ref NBCInputPortConstants.
11005  */
11006 #define SetSensorLowspeed(_port) __SetSensorLowspeed(_port)
11007 
11008 /**
11009  * Configure an ultrasonic sensor.
11010  * Configure the sensor on the specified port as an ultrasonic sensor.
11011  * \param _port The port to configure. See \ref NBCInputPortConstants.
11012  */
11013 #define SetSensorUltrasonic(_port) __SetSensorLowspeed(_port)
11014 
11015 /**
11016  * Configure an EMeter sensor.
11017  * Configure the sensor on the specified port as an EMeter sensor.
11018  * \param _port The port to configure. See \ref NBCInputPortConstants.
11019  */
11020 #define SetSensorEMeter(_port) __SetSensorLowspeed(_port)
11021 
11022 /**
11023  * Configure a temperature sensor.
11024  * Configure the sensor on the specified port as a temperature sensor. Use this
11025  * to setup the temperature sensor rather than \ref SetSensorLowspeed so that
11026  * the sensor is properly configured in 12-bit conversion mode.
11027  * \param _port The port to configure. See \ref NBCInputPortConstants.
11028  */
11029 #define SetSensorTemperature(_port) \
11030   __SetSensorLowspeed(_port) \
11031   __MSWriteToRegister(_port, LEGO_ADDR_TEMP, TEMP_REG_CONFIG, TEMP_RES_12BIT, __WDSC_LSStatus)
11032 
11033 
11034 #if __FIRMWARE_VERSION > 107
11035 
11036 /**
11037  * Configure an NXT 2.0 full color sensor.
11038  * Configure the sensor on the specified port as an NXT 2.0 color sensor
11039  * in full color mode. Requires an NXT 2.0 compatible firmware.
11040  * \param _port The port to configure. See \ref NBCInputPortConstants.
11041  *
11042  * \warning This function requires an NXT 2.0 compatible firmware.
11043  */
11044 #define SetSensorColorFull(_port) __SetSensorColorFull(_port)
11045 
11046 /**
11047  * Configure an NXT 2.0 red light sensor.
11048  * Configure the sensor on the specified port as an NXT 2.0 color sensor
11049  * in red light mode. Requires an NXT 2.0 compatible firmware.
11050  * \param _port The port to configure. See \ref NBCInputPortConstants.
11051  *
11052  * \warning This function requires an NXT 2.0 compatible firmware.
11053  */
11054 #define SetSensorColorRed(_port) __SetSensorColorRed(_port)
11055 
11056 /**
11057  * Configure an NXT 2.0 green light sensor.
11058  * Configure the sensor on the specified port as an NXT 2.0 color sensor
11059  * in green light mode. Requires an NXT 2.0 compatible firmware.
11060  * \param _port The port to configure. See \ref NBCInputPortConstants.
11061  *
11062  * \warning This function requires an NXT 2.0 compatible firmware.
11063  */
11064 #define SetSensorColorGreen(_port) __SetSensorColorGreen(_port)
11065 
11066 /**
11067  * Configure an NXT 2.0 blue light sensor.
11068  * Configure the sensor on the specified port as an NXT 2.0 color sensor
11069  * in blue light mode. Requires an NXT 2.0 compatible firmware.
11070  * \param _port The port to configure. See \ref NBCInputPortConstants.
11071  *
11072  * \warning This function requires an NXT 2.0 compatible firmware.
11073  */
11074 #define SetSensorColorBlue(_port) __SetSensorColorBlue(_port)
11075 
11076 /**
11077  * Configure an NXT 2.0 no light sensor.
11078  * Configure the sensor on the specified port as an NXT 2.0 color sensor
11079  * in no light mode. Requires an NXT 2.0 compatible firmware.
11080  * \param _port The port to configure. See \ref NBCInputPortConstants.
11081  *
11082  * \warning This function requires an NXT 2.0 compatible firmware.
11083  */
11084 #define SetSensorColorNone(_port) __SetSensorColorNone(_port)
11085 
11086 #endif
11087 
11088 /**
11089  * Reset the sensor port.
11090  * Sets the invalid data flag on the specified port and waits for it to
11091  * become valid again. After changing the type or the mode of a sensor
11092  * port you must call this function to give the firmware time to reconfigure
11093  * the sensor port.
11094  * \param _port The port to reset. See \ref NBCInputPortConstants.
11095  */
11096 #define ResetSensor(_port) __ResetSensor(_port)
11097 
11098 #if __FIRMWARE_VERSION > 107
11099 
11100 /**
11101  * Read LEGO color sensor raw values.
11102  * This function lets you read the LEGO color sensor. It returns an array
11103  * containing raw color values for red, green, blue, and none indices.
11104  *
11105  * \param _port The sensor port. See \ref NBCInputPortConstants.
11106  * \param _rawVals An array containing four raw color values. See \ref InputColorIdxConstants.
11107  * \param _result The function call result.
11108  * \warning This function requires an NXT 2.0 compatible firmware.
11109  */
11110 #define ReadSensorColorRaw(_port, _rawVals, _result) __ReadSensorColorRaw(_port, _rawVals, _result)
11111 
11112 /**
11113  * Read LEGO color sensor extra.
11114  * This function lets you read the LEGO color sensor. It returns the color value,
11115  * and three arrays containing raw, normalized, and scaled color values for
11116  * red, green, blue, and none indices.
11117  *
11118  * \param _port The sensor port. See \ref NBCInputPortConstants.
11119  * \param _colorval The color value. See \ref InputColorValueConstants.
11120  * \param _rawVals An array containing four raw color values. See \ref InputColorIdxConstants.
11121  * \param _normVals An array containing four normalized color values. See \ref InputColorIdxConstants.
11122  * \param _scaledVals An array containing four scaled color values. See \ref InputColorIdxConstants.
11123  * \param _result The function call result.
11124  * \warning This function requires an NXT 2.0 compatible firmware.
11125  */
11126 #define ReadSensorColorEx(_port, _colorval, _rawVals, _normVals, _scaledVals, _result) \
11127    __ReadSensorColorEx(_port, _colorval, _rawVals, _normVals, _scaledVals, _result)
11128 
11129 #endif
11130 
11131 /**
11132  * Get the custom sensor zero offset.
11133  * Return the custom sensor zero offset value of a sensor.
11134  *
11135  * \param _p The sensor port. See \ref NBCInputPortConstants.
11136  * \param _n The custom sensor zero offset.
11137  */
11138 #define GetInCustomZeroOffset(_p, _n) __GetInCustomZeroOffset(_p, _n)
11139 
11140 /**
11141  * Read sensor boolean value.
11142  * Return the boolean value of a sensor on the specified port. Boolean
11143  * conversion is either done based on preset cutoffs, or a slope parameter
11144  * specified by calling SetSensorMode.
11145  *
11146  * \param _p The sensor port. See \ref NBCInputPortConstants. Must be a constant.
11147  * \param _n The sensor's boolean value.
11148  */
11149 #define GetInSensorBoolean(_p, _n) __GetInSensorBoolean(_p, _n)
11150 
11151 /**
11152  * Read sensor digital pins direction.
11153  * Return the digital pins direction value of a sensor on the specified port.
11154  *
11155  * \param _p The sensor port. See \ref NBCInputPortConstants. Must be a constant.
11156  * \param _n The sensor's digital pins direction.
11157  */
11158 #define GetInDigiPinsDirection(_p, _n) __GetInDigiPinsDirection(_p, _n)
11159 
11160 /**
11161  * Read sensor digital pins status.
11162  * Return the digital pins status value of a sensor on the specified port.
11163  *
11164  * \param _p The sensor port. See \ref NBCInputPortConstants. Must be a constant.
11165  * \param _n The sensor's digital pins status.
11166  */
11167 #define GetInDigiPinsStatus(_p, _n) __GetInDigiPinsStatus(_p, _n)
11168 
11169 /**
11170  * Read sensor digital pins output level.
11171  * Return the digital pins output level value of a sensor on the specified port.
11172  *
11173  * \param _p The sensor port. See \ref NBCInputPortConstants. Must be a constant.
11174  * \param _n The sensor's digital pins output level.
11175  */
11176 #define GetInDigiPinsOutputLevel(_p, _n) __GetInDigiPinsOutputLevel(_p, _n)
11177 
11178 /**
11179  * Get the custom sensor percent full scale.
11180  * Return the custom sensor percent full scale value of a sensor.
11181  *
11182  * \param _p The sensor port. See \ref NBCInputPortConstants.
11183  * \param _n The custom sensor percent full scale.
11184  */
11185 #define GetInCustomPercentFullScale(_p, _n) __GetInCustomPercentFullScale(_p, _n)
11186 
11187 /**
11188  * Get the custom sensor active status.
11189  * Return the custom sensor active status value of a sensor.
11190  *
11191  * \param _p The sensor port. See \ref NBCInputPortConstants.
11192  * \param _n The custom sensor active status.
11193 */
11194 #define GetInCustomActiveStatus(_p, _n) __GetInCustomActiveStatus(_p, _n)
11195 
11196 #if __FIRMWARE_VERSION > 107
11197 
11198 /**
11199  * Read a LEGO color sensor calibration point value.
11200  * This function lets you directly access a specific LEGO color calibration point value.
11201  * The port, point, and color index must be constants.
11202  *
11203  * \param _p The sensor port. See \ref NBCInputPortConstants. Must be a constant.
11204  * \param _np The calibration point. See \ref InputColorCalibrationConstants. Must be a constant.
11205  * \param _nc The color index. See \ref InputColorIdxConstants. Must be a constant.
11206  * \param _n The calibration point value.
11207  * \warning This function requires an NXT 2.0 compatible firmware.
11208  */
11209 #define GetInColorCalibration(_p, _np, _nc, _n) __GetInColorCalibration(_p, _np, _nc, _n)
11210 
11211 /**
11212  * Read a LEGO color sensor calibration limit value.
11213  * This function lets you directly access a specific LEGO color calibration limit value.
11214  * The port and the point must be constants.
11215  *
11216  * \param _p The sensor port. See \ref NBCInputPortConstants. Must be a constant.
11217  * \param _np The calibration point. See \ref InputColorCalibrationConstants. Must be a constant.
11218  * \param _n The calibration limit value.
11219  * \warning This function requires an NXT 2.0 compatible firmware.
11220  */
11221 #define GetInColorCalLimits(_p, _np, _n) __GetInColorCalLimits(_p, _np, _n)
11222 
11223 /**
11224  * Read a LEGO color sensor AD raw value.
11225  * This function lets you directly access a specific LEGO color sensor AD raw value. Both the
11226  * port and the color index must be constants.
11227  *
11228  * \param _p The sensor port. See \ref NBCInputPortConstants. Must be a constant.
11229  * \param _nc The color index. See \ref InputColorIdxConstants. Must be a constant.
11230  * \param _n The AD raw value.
11231  * \warning This function requires an NXT 2.0 compatible firmware.
11232  */
11233 #define GetInColorADRaw(_p, _nc, _n) __GetInColorADRaw(_p, _nc, _n)
11234 
11235 /**
11236  * Read a LEGO color sensor raw value.
11237  * This function lets you directly access a specific LEGO color sensor raw value. Both the
11238  * port and the color index must be constants.
11239  *
11240  * \param _p The sensor port. See \ref NBCInputPortConstants. Must be a constant.
11241  * \param _nc The color index. See \ref InputColorIdxConstants. Must be a constant.
11242  * \param _n The raw value.
11243  * \warning This function requires an NXT 2.0 compatible firmware.
11244  */
11245 #define GetInColorSensorRaw(_p, _nc, _n) __GetInColorSensorRaw(_p, _nc, _n)
11246 
11247 /**
11248  * Read a LEGO color sensor scaled value.
11249  * This function lets you directly access a specific LEGO color sensor scaled value. Both the
11250  * port and the color index must be constants.
11251  *
11252  * \param _p The sensor port. See \ref NBCInputPortConstants. Must be a constant.
11253  * \param _nc The color index. See \ref InputColorIdxConstants. Must be a constant.
11254  * \param _n The scaled value.
11255  * \warning This function requires an NXT 2.0 compatible firmware.
11256  */
11257 #define GetInColorSensorValue(_p, _nc, _n) __GetInColorSensorValue(_p, _nc, _n)
11258 
11259 /**
11260  * Read a LEGO color sensor boolean value.
11261  * This function lets you directly access a specific LEGO color sensor boolean value. Both the
11262  * port and the color index must be constants.
11263  *
11264  * \param _p The sensor port. See \ref NBCInputPortConstants. Must be a constant.
11265  * \param _nc The color index. See \ref InputColorIdxConstants. Must be a constant.
11266  * \param _n The boolean value.
11267  * \warning This function requires an NXT 2.0 compatible firmware.
11268  */
11269 #define GetInColorBoolean(_p, _nc, _n) __GetInColorBoolean(_p, _nc, _n)
11270 
11271 /**
11272  * Read LEGO color sensor calibration state.
11273  * This function lets you directly access the LEGO color calibration state.
11274  * The port must be a constant.
11275  *
11276  * \param _p The sensor port. See \ref NBCInputPortConstants. Must be a constant.
11277  * \param _n The calibration state.
11278  * \warning This function requires an NXT 2.0 compatible firmware.
11279  */
11280 #define GetInColorCalibrationState(_p, _n) __GetInColorCalibrationState(_p, _n)
11281 
11282 #endif
11283 
11284 /**
11285  * Set custom zero offset.
11286  * Sets the zero offset value of a custom sensor.
11287  *
11288  * \param _p The sensor port. See \ref NBCInputPortConstants. Must be a constant.
11289  * \param _n The new zero offset value.
11290  */
11291 #define SetInCustomZeroOffset(_p, _n) __setInCustomZeroOffset(_p, _n)
11292 
11293 /**
11294  * Set sensor boolean value.
11295  * Sets the boolean value of a sensor.
11296  *
11297  * \param _p The sensor port. See \ref NBCInputPortConstants. Must be a constant.
11298  * \param _n The new boolean value.
11299  */
11300 #define SetInSensorBoolean(_p, _n) __setInSensorBoolean(_p, _n)
11301 
11302 /**
11303  * Set digital pins direction.
11304  * Sets the digital pins direction value of a sensor.
11305  *
11306  * \param _p The sensor port. See \ref NBCInputPortConstants. Must be a constant.
11307  * \param _n The new digital pins direction value.
11308  */
11309 #define SetInDigiPinsDirection(_p, _n) __setInDigiPinsDirection(_p, _n)
11310 
11311 /**
11312  * Set digital pins status.
11313  * Sets the digital pins status value of a sensor.
11314  *
11315  * \param _p The sensor port. See \ref NBCInputPortConstants. Must be a constant.
11316  * \param _n The new digital pins status value.
11317  */
11318 #define SetInDigiPinsStatus(_p, _n) __setInDigiPinsStatus(_p, _n)
11319 
11320 /**
11321  * Set digital pins output level.
11322  * Sets the digital pins output level value of a sensor.
11323  *
11324  * \param _p The sensor port. See \ref NBCInputPortConstants. Must be a constant.
11325  * \param _n The new digital pins output level value.
11326  */
11327 #define SetInDigiPinsOutputLevel(_p, _n) __setInDigiPinsOutputLevel(_p, _n)
11328 
11329 /**
11330  * Set percent full scale.
11331  * Sets the percent full scale value of a custom sensor.
11332  *
11333  * \param _p The sensor port. See \ref NBCInputPortConstants. Must be a constant.
11334  * \param _n The new percent full scale value.
11335  */
11336 #define SetInCustomPercentFullScale(_p, _n) __setInCustomPercentFullScale(_p, _n)
11337 
11338 /**
11339  * Set active status.
11340  * Sets the active status value of a custom sensor.
11341  *
11342  * \param _p The sensor port. See \ref NBCInputPortConstants. Must be a constant.
11343  * \param _n The new active status value.
11344  */
11345 #define SetInCustomActiveStatus(_p, _n) __setInCustomActiveStatus(_p, _n)
11346 
11347 /** @} */ // end of InputModuleFunctions group
11348 /** @} */ // end of InputModule group
11349 /** @} */ // end of NXTFirmwareModules group
11350 
11351 
11352 ///////////////////////////////////////////////////////////////////////////////
11353 /////////////////////////////// LOWSPEED MODULE ///////////////////////////////
11354 ///////////////////////////////////////////////////////////////////////////////
11355 
11356 
11357 /** @addtogroup NXTFirmwareModules
11358  * @{
11359  */
11360 /** @addtogroup LowSpeedModule
11361  * @{
11362  */
11363 /** @defgroup LowSpeedModuleFunctions LowSpeed module functions
11364  * Functions for accessing and modifying low speed module features.
11365  * @{
11366  */
11367 
11368 /**
11369  * Read ultrasonic sensor value.
11370  * Return the ultrasonic sensor distance value. Since an
11371  * ultrasonic sensor is an I2C digital sensor its value cannot be read using
11372  * the standard Sensor(n) value.
11373  * The port must be configured as a Lowspeed port before using this function.
11374  * \param _port The port to which the ultrasonic sensor is attached. See the
11375  * \ref NBCInputPortConstants group. You may use a constant or a variable.
11376  * \param _value The ultrasonic sensor distance value (0..255)
11377  */
11378 #define ReadSensorUS(_port, _value) __ReadSensorUS(_port, _value)
11379 
11380 /**
11381  * Read multiple ultrasonic sensor values.
11382  * Return eight ultrasonic sensor distance values.
11383  * \param _port The port to which the ultrasonic sensor is attached. See the
11384  * \ref NBCInputPortConstants group. You may use a constant or a variable.
11385  * \param _values An array of bytes that will contain the 8 distance values
11386  * read from the ultrasonic sensor.
11387  * \param _result A status code indicating whether the read completed successfully or not.
11388  * See \ref TCommLSRead for possible Result values.
11389  */
11390 #define ReadSensorUSEx(_port, _values, _result) __ReadSensorUSEx(_port, _values, _result)
11391 
11392 /**
11393  * Read the LEGO EMeter values.
11394  * Read all the LEGO EMeter register values.
11395  * They must all be read at once to ensure data coherency.
11396  *
11397  * \param _port The port to which the LEGO EMeter sensor is attached. See the
11398  * \ref NBCInputPortConstants group. You may use a constant or a variable.
11399  * \param _vIn Input voltage
11400  * \param _aIn Input current
11401  * \param _vOut Output voltage
11402  * \param _aOut Output current
11403  * \param _joules The number of joules stored in E-Meter
11404  * \param _wIn The number of watts generated
11405  * \param _wOut The number of watts consumed
11406  * \param _result A status code indicating whether the read completed successfully or not.
11407  * See \ref TCommLSRead for possible Result values.
11408  */
11409 #define ReadSensorEMeter(_port, _vIn, _aIn, _vOut, _aOut, _joules, _wIn, _wOut, _result) __ReadSensorEMeter(_port, _vIn, _aIn, _vOut, _aOut, _joules, _wIn, _wOut, _result)
11410 
11411 /**
11412  * Configure LEGO Temperature sensor options.
11413  * Set various LEGO Temperature sensor options.
11414  *
11415  * \param _port The port to which the LEGO EMeter sensor is attached. See the
11416  * \ref NBCInputPortConstants group. You may use a constant or a variable.
11417  * \param _config The temperature sensor configuration settings.  See
11418  * \ref TempI2CConstants for configuration constants that can be ORed or added
11419  * together.
11420  * \param _result A status code indicating whether the read completed successfully or not.
11421  * See \ref TCommLSRead for possible Result values.
11422  */
11423 #define ConfigureTemperatureSensor(_port, _config, _result) __TempSendCmd(_port, _config, _result)
11424 
11425 /**
11426  * Read the LEGO Temperature sensor value.
11427  * Return the temperature sensor value in degrees celcius. Since a
11428  * temperature sensor is an I2C digital sensor its value cannot be read using
11429  * the standard Sensor(n) value.
11430  * The port must be configured as a temperature sensor port before using this
11431  * function. Use \ref SetSensorTemperature to configure the port.
11432  * \param _port The port to which the temperature sensor is attached. See the
11433  * \ref NBCInputPortConstants group. You may use a constant or a variable.
11434  * \param _temp The temperature sensor value in degrees celcius.
11435  */
11436 #define ReadSensorTemperature(_port, _temp) __ReadSensorTemperature(_port, _temp)
11437 
11438 /**
11439  * Get lowspeed status.
11440  * This method checks the status of the I2C communication on the specified
11441  * port. If the last operation on this port was a successful LowspeedWrite
11442  * call that requested response data from the device then bytesready will
11443  * be set to the number of bytes in the internal read buffer.
11444  *
11445  * \param _port The port to which the I2C device is attached. See the
11446  * \ref NBCInputPortConstants group. You may use a constant or a variable. Constants should
11447  * be used where possible to avoid blocking access to I2C devices on other
11448  * ports by code running on other threads.
11449  * \param _bready The number of bytes available to be read from the internal I2C buffer.
11450  * The maximum number of bytes that can be read is 16.
11451  * \param _result A status code indicating whether the write completed successfully or not.
11452  * See \ref TCommLSCheckStatus for possible Result values. If the return
11453  * value is \ref NO_ERR then the last operation did not cause any errors.
11454  * Avoid calls to \ref LowspeedRead or \ref LowspeedWrite while LowspeedStatus returns
11455  * \ref STAT_COMM_PENDING.
11456  * \sa LowspeedRead, LowspeedWrite, and LowspeedCheckStatus
11457  */
11458 #define LowspeedStatus(_port, _bready, _result) __lowspeedStatus(_port, _bready, _result)
11459 
11460 /**
11461  * Check lowspeed status.
11462  * This method checks the status of the I2C communication on the specified
11463  * port.
11464  *
11465  * \param _port The port to which the I2C device is attached. See the
11466  * \ref NBCInputPortConstants group. You may use a constant or a variable. Constants should
11467  * be used where possible to avoid blocking access to I2C devices on other
11468  * ports by code running on other threads.
11469  * \param _result A status code indicating whether the write completed successfully or not.
11470  * See \ref TCommLSCheckStatus for possible Result values. If the return
11471  * value is \ref NO_ERR then the last operation did not cause any errors.
11472  * Avoid calls to \ref LowspeedRead or \ref LowspeedWrite while LowspeedCheckStatus returns
11473  * \ref STAT_COMM_PENDING.
11474  * \sa LowspeedRead, LowspeedWrite, and LowspeedStatus
11475  */
11476 #define LowspeedCheckStatus(_port, _result) __lowspeedCheckStatus(_port, _result)
11477 
11478 /**
11479  * Get lowspeed bytes ready.
11480  * This method checks the number of bytes that are ready to be read on the
11481  * specified port. If the last operation on this port was a successful
11482  * LowspeedWrite call that requested response data from the device then the
11483  * return value will be the number of bytes in the internal read buffer.
11484  *
11485  * \param _port The port to which the I2C device is attached. See the
11486  * \ref NBCInputPortConstants group. You may use a constant or a variable. Constants should
11487  * be used where possible to avoid blocking access to I2C devices on other
11488  * ports by code running on other threads.
11489  * \param _bready The number of bytes available to be read from the internal I2C buffer.
11490  * The maximum number of bytes that can be read is 16.
11491  * \sa LowspeedRead, LowspeedWrite, and LowspeedStatus
11492  */
11493 #define LowspeedBytesReady(_port, _bready) __lowspeedBytesReady(_port, _bready)
11494 
11495 /**
11496  * Write lowspeed data.
11497  * This method starts a transaction to write the bytes contained in the array
11498  * buffer to the I2C device on the specified port. It also tells the I2C device
11499  * the number of bytes that should be included in the response. The maximum
11500  * number of bytes that can be written or read is 16.
11501  *
11502  * \param _port The port to which the I2C device is attached. See the
11503  * \ref NBCInputPortConstants group. You may use a constant or a variable. Constants should
11504  * be used where possible to avoid blocking access to I2C devices on other
11505  * ports by code running on other threads.
11506  * \param _retlen The number of bytes that should be returned by the I2C device.
11507  * \param _buffer A byte array containing the address of the I2C device, the I2C
11508  * device register at which to write data, and up to 14 bytes of data to be
11509  * written at the specified register.
11510  * \param _result A status code indicating whether the write completed successfully or not.
11511  * See \ref TCommLSWrite for possible Result values. If the return
11512  * value is \ref NO_ERR then the last operation did not cause any errors.
11513  * \sa LowspeedRead, LowspeedCheckStatus, LowspeedBytesReady, and LowspeedStatus
11514  */
11515 #define LowspeedWrite(_port, _retlen, _buffer, _result) __lowspeedWrite(_port, _retlen, _buffer, _result)
11516 
11517 /**
11518  * Read lowspeed data.
11519  * Read the specified number of bytes from the I2C device on the specified
11520  * port and store the bytes read in the byte array buffer provided.  The maximum
11521  * number of bytes that can be written or read is 16.
11522  *
11523  * \param _port The port to which the I2C device is attached. See the
11524  * \ref NBCInputPortConstants group. You may use a constant or a variable. Constants should
11525  * be used where possible to avoid blocking access to I2C devices on other
11526  * ports by code running on other threads.
11527  * \param _buflen The initial size of the output buffer.
11528  * \param _buffer A byte array that contains the data read from the internal I2C
11529  * buffer.  If the return value is negative then the output buffer will be empty.
11530  * \param _result A status code indicating whether the write completed successfully or not.
11531  * See \ref TCommLSRead for possible Result values. If the return
11532  * value is \ref NO_ERR then the last operation did not cause any errors.
11533  * \sa LowspeedWrite, LowspeedCheckStatus, LowspeedBytesReady, and LowspeedStatus
11534  */
11535 #define LowspeedRead(_port, _buflen, _buffer, _result) __lowspeedRead(_port, _buflen, _buffer, _result)
11536 
11537 /**
11538  * Perform an I2C write/read transaction.
11539  * This method writes the bytes contained in the input buffer (inbuf) to the
11540  * I2C device on the specified port, checks for the specified number of bytes
11541  * to be ready for reading, and then tries to read the specified number (count)
11542  * of bytes from the I2C device into the output buffer (outbuf).
11543  *
11544  * This is a higher-level wrapper around the three main I2C functions. It also
11545  * maintains a "last good read" buffer and returns values from that buffer if
11546  * the I2C communication transaction fails.
11547  *
11548  * \param _port The port to which the I2C device is attached. See the
11549  * \ref NBCInputPortConstants group. You may use a constant or a variable. Constants should
11550  * be used where possible to avoid blocking access to I2C devices on other
11551  * ports by code running on other threads.
11552  * \param _inbuf A byte array containing the address of the I2C device, the I2C
11553  * device register at which to write data, and up to 14 bytes of data to be
11554  * written at the specified register.
11555  * \param _count The number of bytes that should be returned by the I2C device.
11556  * On output count is set to the number of bytes in outbuf.
11557  * \param _outbuf A byte array that contains the data read from the internal I2C
11558  * buffer.
11559  * \param _result Returns true or false indicating whether the I2C transaction
11560  * succeeded or failed.
11561  * \sa LowspeedRead, LowspeedWrite, LowspeedCheckStatus, LowspeedBytesReady,
11562  * and LowspeedStatus
11563  */
11564 #define ReadI2CBytes(_port, _inbuf, _count, _outbuf, _result) __ReadI2CBytes(_port, _inbuf, _count, _outbuf, _result)
11565 
11566 /**
11567  * Read I2C device information.
11568  * Read standard I2C device information: version, vendor, and device ID. The
11569  * I2C device uses the specified address.
11570  *
11571  * \param _port The port to which the I2C device is attached. See the
11572  * \ref NBCInputPortConstants group. You may use a constant or a variable. Constants should
11573  * be used where possible to avoid blocking access to I2C devices on other
11574  * ports by code running on other threads.
11575  * \param _i2caddr The I2C device address.
11576  * \param _info A value indicating the type of device information you are requesting.
11577  * See \ref GenericI2CConstants.
11578  * \param _strVal A string containing the requested device information.
11579  */
11580 #define ReadI2CDeviceInfo(_port, _i2caddr, _info, _strVal) __ReadI2CDeviceInfo(_port, _i2caddr, _info, _strVal)
11581 
11582 /**
11583  * Read I2C device version.
11584  * Read standard I2C device version. The I2C device uses the specified address.
11585  *
11586  * \param _port The port to which the I2C device is attached. See the
11587  * \ref NBCInputPortConstants group. You may use a constant or a variable. Constants should
11588  * be used where possible to avoid blocking access to I2C devices on other
11589  * ports by code running on other threads.
11590  * \param _i2caddr The I2C device address.
11591  * \param _strVal A string containing the device version.
11592  */
11593 #define ReadI2CVersion(_port, _i2caddr, _strVal) ReadI2CDeviceInfo(_port, _i2caddr, I2C_REG_VERSION, _strVal)
11594 
11595 /**
11596  * Read I2C device vendor.
11597  * Read standard I2C device vendor. The I2C device uses the specified address.
11598  *
11599  * \param _port The port to which the I2C device is attached. See the
11600  * \ref NBCInputPortConstants group. You may use a constant or a variable. Constants should
11601  * be used where possible to avoid blocking access to I2C devices on other
11602  * ports by code running on other threads.
11603  * \param _i2caddr The I2C device address.
11604  * \param _strVal A string containing the device vendor.
11605  */
11606 #define ReadI2CVendorId(_port, _i2caddr, _strVal) ReadI2CDeviceInfo(_port, _i2caddr, I2C_REG_VENDOR_ID, _strVal)
11607 
11608 /**
11609  * Read I2C device identifier.
11610  * Read standard I2C device identifier. The I2C device uses the specified address.
11611  *
11612  * \param _port The port to which the I2C device is attached. See the
11613  * \ref NBCInputPortConstants group. You may use a constant or a variable. Constants should
11614  * be used where possible to avoid blocking access to I2C devices on other
11615  * ports by code running on other threads.
11616  * \param _i2caddr The I2C device address.
11617  * \param _strVal A string containing the device identifier.
11618  */
11619 #define ReadI2CDeviceId(_port, _i2caddr, _strVal) ReadI2CDeviceInfo(_port, _i2caddr, I2C_REG_DEVICE_ID, _strVal)
11620 
11621 /**
11622  * Read I2C register.
11623  * Read a single byte from an I2C device register.
11624  * \param _port The port to which the I2C device is attached. See the
11625  * \ref NBCInputPortConstants group. You may use a constant or a variable.
11626  * \param _i2caddr The I2C device address.
11627  * \param _reg The I2C device register from which to read a single byte.
11628  * \param _out The single byte read from the I2C device.
11629  * \param _result A status code indicating whether the read completed successfully or not.
11630  * See \ref TCommLSRead for possible Result values.
11631  */
11632 #define ReadI2CRegister(_port, _i2caddr, _reg, _out, _result) __MSReadValue(_port, _i2caddr, _reg, 1, _out, _result)
11633 
11634 /**
11635  * Write I2C register.
11636  * Write a single byte to an I2C device register.
11637  * \param _port The port to which the I2C device is attached. See the
11638  * \ref NBCInputPortConstants group. You may use a constant or a variable.
11639  * \param _i2caddr The I2C device address.
11640  * \param _reg The I2C device register to which to write a single byte.
11641  * \param _val The byte to write to the I2C device.
11642  * \param _result A status code indicating whether the write completed successfully or not.
11643  * See \ref TCommLSCheckStatus for possible Result values.
11644  */
11645 #define WriteI2CRegister(_port, _i2caddr, _reg, _val, _result) __MSWriteToRegister(_port, _i2caddr, _reg, _val, _result)
11646 
11647 /**
11648  * Send an I2C command.
11649  * Send a command to an I2C device at the standard command register: \ref I2C_REG_CMD.
11650  * The I2C device uses the specified address.
11651  * \param _port The port to which the I2C device is attached. See the
11652  * \ref NBCInputPortConstants group. You may use a constant or a variable. Constants should
11653  * be used where possible to avoid blocking access to I2C devices on other
11654  * ports by code running on other threads.
11655  * \param _i2caddr The I2C device address.
11656  * \param _cmd The command to send to the I2C device.
11657  * \param _result A status code indicating whether the write completed successfully or not.
11658  * See \ref TCommLSCheckStatus for possible Result values.
11659  */
11660 #define I2CSendCommand(_port, _i2caddr, _cmd, _result) __I2CSendCmd(_port, _i2caddr, _cmd, _result)
11661 
11662 /** @defgroup LowLevelLowSpeedModuleFunctions Low level LowSpeed module functions
11663  * Low level functions for accessing low speed module features.
11664  * @{
11665  */
11666 
11667 /**
11668  * Get I2C input buffer data.
11669  * This method reads count bytes of data from the I2C input buffer for the
11670  * specified port and writes it to the buffer provided.
11671  * \param _p A constant port number (S1..S4). See \ref NBCInputPortConstants.
11672  * \param _offset A constant offset into the I2C input buffer.
11673  * \param _cnt The number of bytes to read.
11674  * \param _data The byte array reference which will contain the data read from
11675  * the I2C input buffer.
11676  */
11677 #define GetLSInputBuffer(_p, _offset, _cnt, _data) __getLSInputBuffer(_p, _offset, _cnt, _data)
11678 
11679 /**
11680  * Get I2C input buffer in-pointer.
11681  * This method returns the value of the input pointer of the I2C input
11682  * buffer for the specified port.
11683  * \param _p A constant port number (S1..S4). See \ref NBCInputPortConstants.
11684  * \param _n The I2C input buffer's in-pointer value.
11685  */
11686 #define GetLSInputBufferInPtr(_p, _n) __GetLSInputBufferInPtr(_p, _n)
11687 
11688 /**
11689  * Get I2C input buffer out-pointer.
11690  * This method returns the value of the output pointer of the I2C input
11691  * buffer for the specified port.
11692  * \param _p A constant port number (S1..S4). See \ref NBCInputPortConstants.
11693  * \param _n The I2C input buffer's out-pointer value.
11694  */
11695 #define GetLSInputBufferOutPtr(_p, _n) __GetLSInputBufferOutPtr(_p, _n)
11696 
11697 /**
11698  * Get I2C input buffer bytes to rx.
11699  * This method returns the value of the bytes to rx field of the I2C input
11700  * buffer for the specified port.
11701  * \param _p A constant port number (S1..S4). See \ref NBCInputPortConstants.
11702  * \param _n The I2C input buffer's bytes to rx value.
11703  */
11704 #define GetLSInputBufferBytesToRx(_p, _n) __GetLSInputBufferBytesToRx(_p, _n)
11705 
11706 /**
11707  * Get I2C output buffer data.
11708  * This method reads cnt bytes of data from the I2C output buffer for the
11709  * specified port and writes it to the buffer provided.
11710  * \param _p A constant port number (S1..S4). See \ref NBCInputPortConstants.
11711  * \param _offset A constant offset into the I2C output buffer.
11712  * \param _cnt The number of bytes to read.
11713  * \param _data The byte array reference which will contain the data read from
11714  * the I2C output buffer.
11715  */
11716 #define GetLSOutputBuffer(_p, _offset, _cnt, _data) __getLSOutputBuffer(_p, _offset, _cnt, _data)
11717 
11718 /**
11719  * Get I2C output buffer in-pointer.
11720  * This method returns the value of the input pointer of the I2C output
11721  * buffer for the specified port.
11722  * \param _p A constant port number (S1..S4). See \ref NBCInputPortConstants.
11723  * \param _n The I2C output buffer's in-pointer value.
11724  */
11725 #define GetLSOutputBufferInPtr(_p, _n) __GetLSOutputBufferInPtr(_p, _n)
11726 
11727 /**
11728  * Get I2C output buffer out-pointer.
11729  * This method returns the value of the output pointer of the I2C output
11730  * buffer for the specified port.
11731  * \param _p A constant port number (S1..S4). See \ref NBCInputPortConstants.
11732  * \param _n The I2C output buffer's out-pointer value.
11733  */
11734 #define GetLSOutputBufferOutPtr(_p, _n) __GetLSOutputBufferOutPtr(_p, _n)
11735 
11736 /**
11737  * Get I2C output buffer bytes to rx.
11738  * This method returns the value of the bytes to rx field of the I2C output
11739  * buffer for the specified port.
11740  * \param _p A constant port number (S1..S4). See \ref NBCInputPortConstants.
11741  * \param _n The I2C output buffer's bytes to rx value.
11742  */
11743 #define GetLSOutputBufferBytesToRx(_p, _n) __GetLSOutputBufferBytesToRx(_p, _n)
11744 
11745 /**
11746  * Get I2C mode.
11747  * This method returns the value of the I2C mode for the specified port.
11748  * \param _p A constant port number (S1..S4). See \ref NBCInputPortConstants.
11749  * \param _n The I2C port mode. See \ref LowSpeedModeConstants.
11750  */
11751 #define GetLSMode(_p, _n) __GetLSMode(_p, _n)
11752 
11753 /**
11754  * Get I2C channel state.
11755  * This method returns the value of the I2C channel state for the specified port.
11756  * \param _p A constant port number (S1..S4). See \ref NBCInputPortConstants.
11757  * \param _n The I2C port channel state. See \ref LowSpeedChannelStateConstants.
11758  */
11759 #define GetLSChannelState(_p, _n) __GetLSChannelState(_p, _n)
11760 
11761 /**
11762  * Get I2C error type.
11763  * This method returns the value of the I2C error type for the specified port.
11764  * \param _p A constant port number (S1..S4). See \ref NBCInputPortConstants.
11765  * \param _n The I2C port error type. See \ref LowSpeedErrorTypeConstants.
11766  */
11767 #define GetLSErrorType(_p, _n) __GetLSErrorType(_p, _n)
11768 
11769 /**
11770  * Get I2C state.
11771  * This method returns the value of the I2C state.
11772  * \param _n The I2C state. See \ref LowSpeedStateConstants.
11773  */
11774 #define GetLSState(_n) __GetLSState(_n)
11775 
11776 /**
11777  * Get I2C speed.
11778  * This method returns the value of the I2C speed.
11779  * \param _n The I2C speed.
11780  *
11781  * \warning This function is unimplemented within the firmware.
11782  */
11783 #define GetLSSpeed(_n) __GetLSSpeed(_n)
11784 
11785 #ifdef __ENHANCED_FIRMWARE
11786 /**
11787  * Get I2C no restart on read setting.
11788  * This method returns the value of the I2C no restart on read field.
11789  * \param _n The I2C no restart on read field. See \ref LowSpeedNoRestartConstants.
11790  */
11791 #define GetLSNoRestartOnRead(_n) __GetLSNoRestartOnRead(_n)
11792 #endif
11793 
11794 /** @} */ // end of LowLevelLowSpeedModuleFunctions group
11795 
11796 /** @} */ // end of LowSpeedModuleFunctions group
11797 /** @} */ // end of LowSpeedModule group
11798 /** @} */ // end of NXTFirmwareModules group
11799 
11800 
11801 ///////////////////////////////////////////////////////////////////////////////
11802 /////////////////////////////// DISPLAY MODULE ////////////////////////////////
11803 ///////////////////////////////////////////////////////////////////////////////
11804 
11805 
11806 /** @addtogroup NXTFirmwareModules
11807  * @{
11808  */
11809 /** @addtogroup DisplayModule
11810  * @{
11811  */
11812 /** @defgroup DisplayModuleFunctions Display module functions
11813  * Functions for accessing and modifying display module features.
11814  * @{
11815  */
11816 
11817 /**
11818  * Clear a line on the LCD screen.
11819  * This function lets you clear a single line on the NXT LCD.
11820  * \param _line The line you want to clear. See \ref LineConstants.
11821  */
11822 #define ClearLine(_line) __TextOutEx(0, _line, __BlankLine, 0)
11823 
11824 /**
11825  * Draw a point with drawing options.
11826  * This function lets you draw a point on the screen at x, y.
11827  * Also specify drawing options. Valid display option constants are listed in
11828  * the \ref DisplayDrawOptionConstants group.
11829  * \sa TDrawPoint
11830  *
11831  * \param _x The x value for the point.
11832  * \param _y The y value for the point.
11833  * \param _options The optional drawing options.
11834  */
11835 #define PointOutEx(_x,_y,_options) __PointOutEx(_x,_y,_options)
11836 
11837 /**
11838  * Draw a point.
11839  * This function lets you draw
11840  a point on the screen at x, y.
11841  * \sa TDrawPoint
11842  *
11843  * \param _x The x value for the point.
11844  * \param _y The y value for the point.
11845  */
11846 #define PointOut(_x,_y) __PointOutEx(_x,_y,0)
11847 
11848 /**
11849  * Clear LCD screen.
11850  * This function lets you clear the NXT LCD to a blank screen.
11851  */
11852 #define ClearScreen() __PointOutEx(200, 200, 1)
11853 
11854 /**
11855  * Draw a line with drawing options.
11856  * This function lets you draw a line on the screen from x1, y1 to x2, y2.
11857  * Also specify drawing options. Valid display option constants are listed in
11858  * the \ref DisplayDrawOptionConstants group.
11859  * \sa TDrawLine
11860  *
11861  * \param _x1 The x value for the start of the line.
11862  * \param _y1 The y value for the start of the line.
11863  * \param _x2 The x value for the end of the line.
11864  * \param _y2 The y value for the end of the line.
11865  * \param _options The optional drawing options.
11866  */
11867 #define LineOutEx(_x1,_y1,_x2,_y2,_options) __LineOutEx(_x1,_y1,_x2,_y2,_options)
11868 
11869 /**
11870  * Draw a line.
11871  * This function lets you draw a line on the screen from x1, y1 to x2, y2.
11872  * \sa TDrawLine
11873  *
11874  * \param _x1 The x value for the start of the line.
11875  * \param _y1 The y value for the start of the line.
11876  * \param _x2 The x value for the end of the line.
11877  * \param _y2 The y value for the end of the line.
11878  */
11879 #define LineOut(_x1,_y1,_x2,_y2) __LineOutEx(_x1,_y1,_x2,_y2,0)
11880 
11881 /**
11882  * Draw a rectangle with drawing options.
11883  * This function lets you draw a rectangle on the screen at x, y with the
11884  * specified width and height.
11885  * Also specify drawing options. Valid display option constants are listed in
11886  * the \ref DisplayDrawOptionConstants group.
11887  * \sa TDrawRect
11888  *
11889  * \param _x The x value for the top left corner of the rectangle.
11890  * \param _y The y value for the top left corner of the rectangle.
11891  * \param _w The width of the rectangle.
11892  * \param _h The height of the rectangle.
11893  * \param _options The optional drawing options.
11894  */
11895 #define RectOutEx(_x,_y,_w,_h,_options) __RectOutEx(_x,_y,_w,_h,_options)
11896 
11897 /**
11898  * Draw a rectangle.
11899  * This function lets you draw a rectangle on the screen at x, y with the
11900  * specified width and height.
11901  * \sa TDrawRect
11902  *
11903  * \param _x The x value for the top left corner of the rectangle.
11904  * \param _y The y value for the top left corner of the rectangle.
11905  * \param _w The width of the rectangle.
11906  * \param _h The height of the rectangle.
11907  */
11908 #define RectOut(_x,_y,_w,_h) __RectOutEx(_x,_y,_w,_h,0)
11909 
11910 /**
11911  * Draw a circle with drawing options.
11912  * This function lets you draw a circle on the screen with its center at the
11913  * specified x and y location, using the specified radius. Also specify
11914  * drawing options. Valid display option constants are listed in the
11915  * \ref DisplayDrawOptionConstants group.
11916  * \sa TDrawCircle
11917  *
11918  * \param _x The x value for the center of the circle.
11919  * \param _y The y value for the center of the circle.
11920  * \param _r The radius of the circle.
11921  * \param _options The optional drawing options.
11922  */
11923 #define CircleOutEx(_x,_y,_r,_options) __CircleOutEx(_x,_y,_r,_options)
11924 
11925 /**
11926  * Draw a circle.
11927  * This function lets you draw a circle on the screen with its center at the
11928  * specified x and y location, using the specified radius.
11929  * \sa TDrawCircle
11930  *
11931  * \param _x The x value for the center of the circle.
11932  * \param _y The y value for the center of the circle.
11933  * \param _r The radius of the circle.
11934  */
11935 #define CircleOut(_x,_y,_r) __CircleOutEx(_x,_y,_r,0)
11936 
11937 /**
11938  * Draw a number with drawing options.
11939  * Draw a numeric value on the screen at the specified x and y location. The y
11940  * value must be a multiple of 8.  Valid line number constants are listed in
11941  * the \ref LineConstants group.
11942  * Also specify drawing options. Valid display option constants are listed in
11943  * the \ref DisplayDrawOptionConstants group.
11944  * \sa TDrawText
11945  *
11946  * \param _x The x value for the start of the number output.
11947  * \param _y The text line number for the number output.
11948  * \param _num The value to output to the LCD screen. Any numeric type is supported.
11949  * \param _options The optional drawing options.
11950  */
11951 #define NumOutEx(_x,_y,_num,_options) __NumOutEx(_x,_y,_num,_options)
11952 
11953 /**
11954  * Draw a number.
11955  * Draw a numeric value on the screen at the specified x and y location. The y
11956  * value must be a multiple of 8.  Valid line number constants are listed in
11957  * the \ref LineConstants group.
11958  * \sa TDrawText
11959  *
11960  * \param _x The x value for the start of the number output.
11961  * \param _y The text line number for the number output.
11962  * \param _num The value to output to the LCD screen. Any numeric type is supported.
11963  */
11964 #define NumOut(_x,_y,_num) __NumOutEx(_x,_y,_num,0)
11965 
11966 /**
11967  * Draw text.
11968  * Draw a text value on the screen at the specified x and y location. The y
11969  * value must be a multiple of 8.  Valid line number constants are listed in
11970  * the \ref LineConstants group.
11971  * Also specify drawing options. Valid display option constants are listed in
11972  * the \ref DisplayDrawOptionConstants group.
11973  * \sa TDrawText
11974  *
11975  * \param _x The x value for the start of the text output.
11976  * \param _y The text line number for the text output.
11977  * \param _txt The text to output to the LCD screen.
11978  * \param _options The optional drawing options.
11979  */
11980 #define TextOutEx(_x,_y,_txt,_options) __TextOutEx(_x,_y,_txt,_options)
11981 
11982 /**
11983  * Draw text.
11984  * Draw a text value on the screen at the specified x and y location. The y
11985  * value must be a multiple of 8.  Valid line number constants are listed in
11986  * the \ref LineConstants group.
11987  * \sa TDrawText
11988  *
11989  * \param _x The x value for the start of the text output.
11990  * \param _y The text line number for the text output.
11991  * \param _txt The text to output to the LCD screen.
11992  */
11993 #define TextOut(_x,_y,_txt) __TextOutEx(_x,_y,_txt,0)
11994 
11995 /**
11996  * Draw a graphic image with parameters and drawing options.
11997  * Draw a graphic image file on the screen at the specified x and y location using
11998  * an array of parameters. Valid display option constants are listed in
11999  * the \ref DisplayDrawOptionConstants group. If the file cannot be found then
12000  * nothing will be drawn and no errors will be reported.
12001  * \sa TDrawGraphic
12002  *
12003  * \param _x The x value for the position of the graphic image.
12004  * \param _y The y value for the position of the graphic image.
12005  * \param _file The filename of the RIC graphic image.
12006  * \param _vars The byte array of parameters.
12007  * \param _options The drawing options.
12008  */
12009 #define GraphicOutEx(_x,_y,_file,_vars,_options) __GraphicOutEx(_x,_y,_file,_vars,_options)
12010 
12011 /**
12012  * Draw a graphic image.
12013  * Draw a graphic image file on the screen at the specified x and y location.
12014  * If the file cannot be found then
12015  * nothing will be drawn and no errors will be reported.
12016  * \sa TDrawGraphic
12017  *
12018  * \param _x The x value for the position of the graphic image.
12019  * \param _y The y value for the position of the graphic image.
12020  * \param _file The filename of the RIC graphic image.
12021  */
12022 #define GraphicOut(_x,_y,_file) __GraphicOutEx(_x,_y,_file,__GraphicOutEmptyVars,0)
12023 
12024 #if defined(__ENHANCED_FIRMWARE) && (__FIRMWARE_VERSION > 107)
12025 
12026 /**
12027  * Draw a graphic image from byte array with parameters and drawing options.
12028  * Draw a graphic image byte array on the screen at the specified x and y
12029  * location using an array of parameters and drawing options.
12030  * Valid display option constants are listed in the
12031  * \ref DisplayDrawOptionConstants group. If the file cannot be found then
12032  * nothing will be drawn and no errors will be reported.
12033  * \sa TDrawGraphicArray
12034  *
12035  * \param _x The x value for the position of the graphic image.
12036  * \param _y The y value for the position of the graphic image.
12037  * \param _data The byte array of the RIC graphic image.
12038  * \param _vars The byte array of parameters.
12039  * \param _options The drawing options.
12040  */
12041 #define GraphicArrayOutEx(_x,_y,_data,_vars,_options) __GraphicArrayOutEx(_x,_y,_data,_vars,_options)
12042 
12043 /**
12044  * Draw a graphic image from byte array.
12045  * Draw a graphic image byte array on the screen at the specified x and y
12046  * location. If the file cannot be found then nothing will be drawn and no
12047  * errors will be reported.
12048  * \sa TDrawGraphicArray
12049  *
12050  * \param _x The x value for the position of the graphic image.
12051  * \param _y The y value for the position of the graphic image.
12052  * \param _data The byte array of the RIC graphic image.
12053  */
12054 #define GraphicArrayOut(_x,_y,_data) __GraphicArrayOutEx(_x,_y,_data,__GraphicOutEmptyVars,0)
12055 
12056 /**
12057  * Draw an ellipse with drawing options.
12058  * This function lets you draw an ellipse on the screen with its center at the
12059  * specified x and y location, using the specified radii. Also specify
12060  * drawing options. Valid display option constants are listed in the
12061  * \ref DisplayDrawOptionConstants group.
12062  * \sa SysDrawEllipse, DrawEllipseType
12063  *
12064  * \warning This function requires the enhanced NBC/NXC firmware version 1.28+.
12065  *
12066  * \param _x The x value for the center of the ellipse.
12067  * \param _y The y value for the center of the ellipse.
12068  * \param _rX The x axis radius.
12069  * \param _rY The y axis radius.
12070  * \param _options The drawing options.
12071  */
12072 #define EllipseOutEx(_x,_y,_rX,_rY,_options) __EllipseOutEx(_x,_y,_rX,_rY,_options)
12073 
12074 /**
12075  * Draw an ellipse.
12076  * This function lets you draw an ellipse on the screen with its center at the
12077  * specified x and y location, using the specified radii.
12078  * \sa TDrawEllipse
12079  *
12080  * \warning This function requires the enhanced NBC/NXC firmware version 1.28+.
12081  *
12082  * \param _x The x value for the center of the ellipse.
12083  * \param _y The y value for the center of the ellipse.
12084  * \param _rX The x axis radius.
12085  * \param _rY The y axis radius.
12086  */
12087 #define EllipseOut(_x,_y,_rX,_rY) __EllipseOutEx(_x,_y,_rX,_rY,0)
12088 
12089 /**
12090  * Draw a polygon with drawing options.
12091  * This function lets you draw a polygon on the screen using an array of points.
12092  * Also specify drawing options. Valid display option constants are listed in
12093  * the \ref DisplayDrawOptionConstants group.
12094  * \sa TDrawPolygon
12095  *
12096  * \warning This function requires the enhanced NBC/NXC firmware version 1.28+.
12097  *
12098  * \param _points An array of \ref TLocation points that define the polygon.
12099  * \param _options The drawing options.
12100  */
12101 #define PolyOutEx(_points,_options) __PolyOutEx(_points,_options)
12102 
12103 /**
12104  * Draw a polygon.
12105  * This function lets you draw a polygon on the screen using an array of points.
12106  * \sa TDrawPolygon
12107  *
12108  * \warning This function requires the enhanced NBC/NXC firmware version 1.28+.
12109  *
12110  * \param _points An array of LocationType points that define the polygon.
12111  */
12112 #define PolyOut(_points) __PolyOutEx(_points,0)
12113 
12114 /**
12115  * Draw text with font and drawing options.
12116  * Draw a text value on the screen at the specified x and y location using
12117  * a custom RIC font. Also specify drawing options. Valid display option
12118  * constants are listed in the \ref DisplayDrawOptionConstants group.  See the
12119  * \ref DisplayFontDrawOptionConstants for options specific to the font
12120  * drawing functions.
12121  * \sa FontNumOut, TDrawFont
12122  *
12123  * \warning This function requires the enhanced NBC/NXC firmware version 1.28+.
12124  *
12125  * \param _x The x value for the start of the text output.
12126  * \param _y The y value for the start of the text output.
12127  * \param _fnt The filename of the RIC font.
12128  * \param _txt The text to output to the LCD screen.
12129  * \param _options The drawing options.
12130  */
12131 #define FontTextOutEx(_x,_y,_fnt,_txt,_options) __FontTextOutEx(_x,_y,_fnt,_txt,_options)
12132 
12133 /**
12134  * Draw text with font.
12135  * Draw a text value on the screen at the specified x and y location using
12136  * a custom RIC font.
12137  * \sa FontNumOut, TDrawFont
12138  *
12139  * \warning This function requires the enhanced NBC/NXC firmware version 1.28+.
12140  *
12141  * \param _x The x value for the start of the text output.
12142  * \param _y The y value for the start of the text output.
12143  * \param _fnt The filename of the RIC font.
12144  * \param _txt The text to output to the LCD screen.
12145  */
12146 #define FontTextOut(_x,_y,_fnt,_txt) __FontTextOutEx(_x,_y,_fnt,_txt,0)
12147 
12148 /**
12149  * Draw a number with font and drawing options.
12150  * Draw a numeric value on the screen at the specified x and y location using
12151  * a custom RIC font. Also specify drawing options. Valid display option
12152  * constants are listed in the \ref DisplayDrawOptionConstants group.  See the
12153  * \ref DisplayFontDrawOptionConstants for options specific to the font
12154  * drawing functions.
12155  * \sa FontTextOut, TDrawFont
12156  *
12157  * \warning This function requires the enhanced NBC/NXC firmware version 1.28+.
12158  *
12159  * \param _x The x value for the start of the number output.
12160  * \param _y The y value for the start of the number output.
12161  * \param _fnt The filename of the RIC font.
12162  * \param _num The value to output to the LCD screen. Any numeric type is supported.
12163  * \param _options The optional drawing options.
12164  */
12165 #define FontNumOutEx(_x,_y,_fnt,_num,_options) __FontNumOutEx(_x,_y,_fnt,_num,_options)
12166 
12167 /**
12168  * Draw a number with font.
12169  * Draw a numeric value on the screen at the specified x and y location using
12170  * a custom RIC font.
12171  * \sa FontTextOut, TDrawFont
12172  *
12173  * \warning This function requires the enhanced NBC/NXC firmware version 1.28+.
12174  *
12175  * \param _x The x value for the start of the number output.
12176  * \param _y The y value for the start of the number output.
12177  * \param _fnt The filename of the RIC font.
12178  * \param _num The value to output to the LCD screen. Any numeric type is supported.
12179  */
12180 #define FontNumOut(_x,_y,_fnt,_num) __FontNumOutEx(_x,_y,_fnt,_num,0)
12181 
12182 #endif
12183 
12184 /**
12185  * Read the display erase mask value.
12186  * This function lets you read the current display erase mask value.
12187  * \param _n The current display erase mask value.
12188  */
12189 #define GetDisplayEraseMask(_n) __GetDisplayEraseMask(_n)
12190 
12191 /**
12192  * Read the display update mask value.
12193  * This function lets you read the current display update mask value.
12194  * \param _n The current display update mask.
12195  */
12196 #define GetDisplayUpdateMask(_n) __GetDisplayUpdateMask(_n)
12197 
12198 /**
12199  * Read the display font memory address.
12200  * This function lets you read the current display font memory address.
12201  * \param _n The current display font memory address.
12202  */
12203 #define GetDisplayFont(_n) __GetDisplayFont(_n)
12204 
12205 /**
12206  * Read the display memory address.
12207  * This function lets you read the current display memory address.
12208  * \param _n The current display memory address.
12209  */
12210 #define GetDisplayDisplay(_n) __GetDisplayDisplay(_n)
12211 
12212 /**
12213  * Read the display flags.
12214  * This function lets you read the current display flags.
12215  * Valid flag values are listed in the \ref DisplayFlagsGroup group.
12216  * \param _n The current display flags.
12217  */
12218 #define GetDisplayFlags(_n) __GetDisplayFlags(_n)
12219 
12220 /**
12221  * Read the display text lines center flags.
12222  * This function lets you read the current display text lines center flags.
12223  * \param _n The current display text lines center flags.
12224  */
12225 #define GetDisplayTextLinesCenterFlags(_n) __GetDisplayTextLinesCenterFlags(_n)
12226 
12227 #if defined(__ENHANCED_FIRMWARE) && (__FIRMWARE_VERSION > 107)
12228 /**
12229  * Read the display contrast setting.
12230  * This function lets you read the current display contrast setting.
12231  * \param _n The current display contrast (byte).
12232  *
12233  * \warning This function requires the enhanced NBC/NXC firmware version 1.28+.
12234  */
12235 #define GetDisplayContrast(_n) __GetDisplayContrast(_n)
12236 #endif
12237 
12238 /**
12239  * Read pixel data from the normal display buffer.
12240  * Read "cnt" bytes from the normal display memory into the data array. Start
12241  * reading from the specified x, line coordinate. Each byte of data read from
12242  * screen memory is a vertical strip of 8 bits at the desired location. Each
12243  * bit represents a single pixel on the LCD screen. Use TEXTLINE_1 through
12244  * TEXTLINE_8 for the "line" parameter.
12245  *
12246  * \param _x The desired x position from which to read pixel data.
12247  * \param _line The desired line from which to read pixel data.
12248  * \param _cnt The number of bytes of pixel data to read.
12249  * \param _data The array of bytes into which pixel data is read.
12250  */
12251 #define GetDisplayNormal(_x, _line, _cnt, _data) __getDisplayNormal(_x, _line, _cnt, _data)
12252 
12253 /**
12254  * Read pixel data from the popup display buffer.
12255  * Read "cnt" bytes from the popup display memory into the data array. Start
12256  * reading from the specified x, line coordinate. Each byte of data read from
12257  * screen memory is a vertical strip of 8 bits at the desired location. Each
12258  * bit represents a single pixel on the LCD screen. Use TEXTLINE_1 through
12259  * TEXTLINE_8 for the "line" parameter.
12260  *
12261  * \param _x The desired x position from which to read pixel data.
12262  * \param _line The desired line from which to read pixel data.
12263  * \param _cnt The number of bytes of pixel data to read.
12264  * \param _data The array of bytes into which pixel data is read.
12265  */
12266 #define GetDisplayPopup(_x, _line, _cnt, _data) __getDisplayPopup(_x, _line, _cnt, _data)
12267 
12268 /**
12269  * Set the display font memory address.
12270  * This function lets you set the current display font memory address.
12271  *
12272  * \param _n The new display font memory address.
12273  */
12274 #define SetDisplayFont(_n) __setDisplayFont(_n)
12275 
12276 /**
12277  * Set the display memory address.
12278  * This function lets you set the current display memory address.
12279  *
12280  * \param _n The new display memory address.
12281  */
12282 #define SetDisplayDisplay(_n) __setDisplayDisplay(_n)
12283 
12284 /**
12285  * Set the display erase mask.
12286  * This function lets you set the current display erase mask.
12287  *
12288  * \param _n The new display erase mask.
12289  */
12290 #define SetDisplayEraseMask(_n) __setDisplayEraseMask(_n)
12291 
12292 /**
12293  * Set the display flags.
12294  * This function lets you set the current display flags.
12295  *
12296  * \param _n The new display flags. See \ref DisplayFlagsGroup.
12297  */
12298 #define SetDisplayFlags(_n) __setDisplayFlags(_n)
12299 
12300 /**
12301  * Set the display text lines center flags.
12302  * This function lets you set the current display text lines center flags.
12303  *
12304  * \param _n The new display text lines center flags.
12305  */
12306 #define SetDisplayTextLinesCenterFlags(_n) __setDisplayTextLinesCenterFlags(_n)
12307 
12308 /**
12309  * Set the display update mask.
12310  * This function lets you set the current display update mask.
12311  *
12312  * \param _n The new display update mask.
12313  */
12314 #define SetDisplayUpdateMask(_n) __setDisplayUpdateMask(_n)
12315 
12316 #if defined(__ENHANCED_FIRMWARE) && (__FIRMWARE_VERSION > 107)
12317 /**
12318  * Set the display contrast.
12319  * This function lets you set the display contrast setting.
12320  *
12321  * \param _n The desired display contrast.
12322  *
12323  * \warning This function requires the enhanced NBC/NXC firmware version 1.28+.
12324  */
12325 #define SetDisplayContrast(_n) __setDisplayContrast(_n)
12326 #endif
12327 
12328 /**
12329  * Write pixel data to the normal display buffer.
12330  * Write "cnt" bytes to the normal display memory from the data array. Start
12331  * writing at the specified x, line coordinate. Each byte of data is a
12332  * vertical strip of 8 bits at the desired location. Each
12333  * bit represents a single pixel on the LCD screen. Use TEXTLINE_1 through
12334  * TEXTLINE_8 for the "line" parameter.
12335  *
12336  * \param _x The desired x position where you wish to write pixel data.
12337  * \param _line The desired line where you wish to write pixel data.
12338  * \param _cnt The number of bytes of pixel data to write.
12339  * \param _data The array of bytes from which pixel data is read.
12340  */
12341 #define SetDisplayNormal(_x, _line, _cnt, _data) __setDisplayNormal(_x, _line, _cnt, _data)
12342 
12343 /**
12344  * Write pixel data to the popup display buffer.
12345  * Write "cnt" bytes to the popup display memory from the data array. Start
12346  * writing at the specified x, line coordinate. Each byte of data is a
12347  * vertical strip of 8 bits at the desired location. Each
12348  * bit represents a single pixel on the LCD screen. Use TEXTLINE_1 through
12349  * TEXTLINE_8 for the "line" parameter.
12350  *
12351  * \param _x The desired x position where you wish to write pixel data.
12352  * \param _line The desired line where you wish to write pixel data.
12353  * \param _cnt The number of bytes of pixel data to write.
12354  * \param _data The array of bytes from which pixel data is read.
12355  */
12356 #define SetDisplayPopup(_x, _line, _cnt, _data) __setDisplayPopup(_x, _line, _cnt, _data)
12357 
12358 /** @} */ // end of DisplayModuleFunctions group
12359 /** @} */ // end of DisplayModule group
12360 /** @} */ // end of NXTFirmwareModules group
12361 
12362 
12363 ///////////////////////////////////////////////////////////////////////////////
12364 ///////////////////////////////// SOUND MODULE ////////////////////////////////
12365 ///////////////////////////////////////////////////////////////////////////////
12366 
12367 
12368 /** @addtogroup NXTFirmwareModules
12369  * @{
12370  */
12371 /** @addtogroup SoundModule
12372  * @{
12373  */
12374 /** @defgroup SoundModuleFunctions Sound module functions
12375  * Functions for accessing and modifying sound module features.
12376  * @{
12377  */
12378 
12379 /**
12380  * Play a tone with extra options.
12381  * Play a single tone of the specified frequency, duration, and volume. The
12382  * frequency is in Hz (see the \ref ToneConstants group). The duration is in
12383  * 1000ths of a second (see the \ref TimeConstants group). Volume should be a
12384  * number from 0 (silent) to 4 (loudest). Play the tone repeatedly if loop is
12385  * true.
12386  *
12387  * \param _freq The desired tone frequency, in Hz.
12388  * \param _dur The desired tone duration, in ms.
12389  * \param _vol The desired tone volume.
12390  * \param _loop A boolean flag indicating whether to play the tone repeatedly.
12391  */
12392 #define PlayToneEx(_freq,_dur,_vol,_loop) __PlayToneEx(_freq,_dur,_vol,_loop)
12393 
12394 /**
12395  * Play a tone.
12396  * Play a single tone of the specified frequency and duration. The frequency is
12397  * in Hz (see the \ref ToneConstants group). The duration is in 1000ths of a
12398  * second (see the \ref TimeConstants group). The tone is played at the loudest
12399  * sound level supported by the firmware and it is not looped.
12400  *
12401  * \param _freq The desired tone frequency, in Hz.
12402  * \param _dur The desired tone duration, in ms.
12403  */
12404 #define PlayTone(_freq,_dur) __PlayToneEx(_freq,_dur,4,0)
12405 
12406 /**
12407  * Play a file.
12408  * Play the specified file. The filename may be any valid string expression.
12409  * The sound file can either be an RSO file containing PCM or compressed ADPCM
12410  * samples or it can be an NXT melody (RMD) file containing frequency and
12411  * duration values.
12412  *
12413  * \param _file The name of the sound or melody file to play.
12414  */
12415 #define PlayFile(_file) __PlayFileEx(_file,4,0)
12416 
12417 /**
12418  * Play a file with extra options.
12419  * Play the specified file. The filename may be any valid string expression.
12420  * Volume should be a number from 0 (silent) to 4 (loudest). Play the file
12421  * repeatedly if loop is true.
12422  * The sound file can either be an RSO file containing PCM or compressed ADPCM
12423  * samples or it can be an NXT melody (RMD) file containing frequency and
12424  * duration values.
12425  *
12426  * \param _file The name of the sound or melody file to play.
12427  * \param _vol The desired tone volume.
12428  * \param _loop A boolean flag indicating whether to play the file repeatedly.
12429  */
12430 #define PlayFileEx(_file,_vol,_loop) __PlayFileEx(_file,_vol,_loop)
12431 
12432 /**
12433  * Get sound module state and flags.
12434  * Return the current sound module state and flags.
12435  * See the \ref SoundStateConstants group.
12436  *
12437  * \sa SetSoundState
12438  * \param _state The current sound module state.
12439  * \param _flags The current sound module flags.
12440  */
12441 #define GetSoundState(_state, _flags) __GetSoundState(_state, _flags)
12442 
12443 /**
12444  * Set sound module state and flags.
12445  * Set the sound module state and flags.
12446  * See the \ref SoundStateConstants group.
12447  *
12448  * \sa GetSoundState
12449  * \param _state The sound module state.
12450  * \param _flags The sound module flags.
12451  * \param _result The function call result.
12452  */
12453 #define SetSoundState(_state, _flags, _result) __setSoundState(_state, _flags, _result)
12454 
12455 /**
12456  * Get sound frequency.
12457  * Return the current sound frequency.
12458  *
12459  * \sa SetSoundFrequency
12460  * \param _n The current sound frequency.
12461  */
12462 #define GetSoundFrequency(_n) __GetSoundFrequency(_n)
12463 
12464 /**
12465  * Get sound duration.
12466  * Return the current sound duration.
12467  *
12468  * \sa SetSoundDuration
12469  * \param _n The current sound duration.
12470  */
12471 #define GetSoundDuration(_n) __GetSoundDuration(_n)
12472 
12473 /**
12474  * Get sample rate.
12475  * Return the current sound sample rate.
12476  *
12477  * \sa SetSoundSampleRate
12478  * \param _n The current sound sample rate.
12479  */
12480 #define GetSoundSampleRate(_n) __GetSoundSampleRate(_n)
12481 
12482 /**
12483  * Get sound mode.
12484  * Return the current sound mode.  See the \ref SoundModeConstants group.
12485  *
12486  * \sa SetSoundMode
12487  * \param _n The current sound mode.
12488  */
12489 #define GetSoundMode(_n) __GetSoundMode(_n)
12490 
12491 /**
12492  * Get volume.
12493  * Return the current sound volume.
12494  *
12495  * \sa SetSoundVolume
12496  * \param _n The current sound volume.
12497  */
12498 #define GetSoundVolume(_n) __GetSoundVolume(_n)
12499 
12500 /**
12501  * Set sound duration.
12502  * Set the sound duration.
12503  *
12504  * \sa GetSoundDuration
12505  * \param _n The new sound duration
12506  */
12507 #define SetSoundDuration(_n) __setSoundDuration(_n)
12508 
12509 /**
12510  * Set sound module flags.
12511  * Set the sound module flags. See the \ref SoundFlagsConstants group.
12512  *
12513  * \param _n The new sound module flags
12514  */
12515 #define SetSoundFlags(_n) __setSoundFlags(_n)
12516 
12517 /**
12518  * Set sound frequency.
12519  * Set the sound frequency.
12520  *
12521  * \sa GetSoundFrequency
12522  * \param _n The new sound frequency
12523  */
12524 #define SetSoundFrequency(_n) __setSoundFrequency(_n)
12525 
12526 /**
12527  * Set sound mode.
12528  * Set the sound mode.  See the \ref SoundModeConstants group.
12529  *
12530  * \sa GetSoundMode
12531  * \param _n The new sound mode
12532  */
12533 #define SetSoundMode(_n) __setSoundMode(_n)
12534 
12535 /**
12536  * Set sound module state.
12537  * Set the sound module state. See the \ref SoundStateConstants group.
12538  *
12539  * \sa GetSoundState
12540  * \param _n The new sound state
12541  */
12542 #define SetSoundModuleState(_n) __setSoundModuleState(_n)
12543 
12544 /**
12545  * Set sample rate.
12546  * Set the sound sample rate.
12547  *
12548  * \sa GetSoundSampleRate
12549  * \param _n The new sample rate
12550  */
12551 #define SetSoundSampleRate(_n) __setSoundSampleRate(_n)
12552 
12553 /**
12554  * Set sound volume.
12555  * Set the sound volume.
12556  *
12557  * \sa GetSoundVolume
12558  * \param _n The new volume
12559  */
12560 #define SetSoundVolume(_n) __setSoundVolume(_n)
12561 
12562 /** @} */ // end of SoundModuleFunctions group
12563 /** @} */ // end of SoundModule group
12564 /** @} */ // end of NXTFirmwareModules group
12565 
12566 
12567 ///////////////////////////////////////////////////////////////////////////////
12568 /////////////////////////////// COMMAND MODULE ////////////////////////////////
12569 ///////////////////////////////////////////////////////////////////////////////
12570 
12571 
12572 /** @addtogroup NXTFirmwareModules
12573  * @{
12574  */
12575 /** @addtogroup CommandModule
12576  * @{
12577  */
12578 /** @defgroup CommandModuleFunctions Command module functions
12579  * Functions for accessing and modifying Command module features.
12580  * @{
12581  */
12582 
12583 /**
12584  * Set IOMap bytes by name.
12585  * Modify one or more bytes of data in an IOMap structure. The IOMap
12586  * structure is specified by its module name. You also provide the offset into
12587  * the IOMap structure where you want to start writing, the number of bytes to
12588  * write at that location, and a byte array containing the new data.
12589  * \param _modName The module name of the IOMap to modify. See \ref ModuleNameConstants.
12590  * \param _offset The number of bytes offset from the start of the IOMap
12591  * structure where the data should be written
12592  * \param _cnt The number of bytes to write at the specified IOMap
12593  * offset.
12594  * \param _arrIn The byte array containing the data to write to the IOMap
12595  */
12596 #define SetIOMapBytes(_modName, _offset, _cnt, _arrIn) __SetIOMapBytes(_modName, _offset, _cnt, _arrIn)
12597 
12598 /**
12599  * Set IOMap value by name.
12600  * Set one of the fields of an IOMap structure to a new value.  The IOMap
12601  * structure is specified by its module name. You also provide the offset into
12602  * the IOMap structure where you want to write the value along with a variable
12603  * containing the new value.
12604  * \param _modName The module name of the IOMap to modify. See \ref ModuleNameConstants.
12605  * \param _offset The number of bytes offset from the start of the IOMap
12606  * structure where the new value should be written
12607  * \param _n A variable containing the new value to write to the IOMap
12608  */
12609 #define SetIOMapValue(_modName, _offset, _n) __SetIOMapValue(_modName, _offset, _n)
12610 
12611 #ifdef __ENHANCED_FIRMWARE
12612 
12613 /**
12614  * Set IOMap bytes by ID.
12615  * Modify one or more bytes of data in an IOMap structure. The IOMap
12616  * structure is specified by its Module ID. You also provide the offset into
12617  * the IOMap structure where you want to start writing, the number of bytes to
12618  * write at that location, and a byte array containing the new data.
12619  * \param _modID The module ID of the IOMap to modify. See \ref ModuleIDConstants.
12620  * \param _offset The number of bytes offset from the start of the IOMap
12621  * structure where the data should be written.
12622  * \param _cnt The number of bytes to write at the specified IOMap
12623  * offset.
12624  * \param _arrIn The byte array containing the data to write to the IOMap.
12625  * \warning This function requires the enhanced NBC/NXC firmware.
12626  */
12627 #define SetIOMapBytesByID(_modID, _offset, _cnt, _arrIn) __SetIOMapBytesByID(_modID, _offset, _cnt, _arrIn)
12628 
12629 /**
12630  * Set IOMap value by ID.
12631  * Set one of the fields of an IOMap structure to a new value.  The IOMap
12632  * structure is specified by its Module ID. You also provide the offset into
12633  * the IOMap structure where you want to write the value along with a variable
12634  * containing the new value.
12635  * \param _modID The module ID of the IOMap to modify. See \ref ModuleIDConstants.
12636  * \param _offset The number of bytes offset from the start of the IOMap
12637  * structure where the new value should be written.
12638  * \param _n A variable containing the new value to write to the IOMap.
12639  * \warning This function requires the enhanced NBC/NXC firmware.
12640  */
12641 #define SetIOMapValueByID(_modID, _offset, _n) __SetIOMapValueByID(_modID, _offset, _n)
12642 
12643 /**
12644  * Set Command module IOMap value.
12645  * Set one of the fields of the Command module IOMap structure to a new value.
12646  * You provide the offset into the Command module IOMap structure where you
12647  * want to write the value along with a variable containing the new value.
12648  * \param _offset The number of bytes offset from the start of the Command
12649  * module IOMap structure where the new value should be written. See \ref CommandIOMAP.
12650  * \param _n A variable containing the new value to write to the Command
12651  * module IOMap.
12652  */
12653 #define SetCommandModuleValue(_offset, _n) SetIOMapValueByID(CommandModuleID, _offset, _n)
12654 
12655 /**
12656  * Set IOCtrl module IOMap value.
12657  * Set one of the fields of the IOCtrl module IOMap structure to a new value.
12658  * You provide the offset into the IOCtrl module IOMap structure where you
12659  * want to write the value along with a variable containing the new value.
12660  * \param _offset The number of bytes offset from the start of the IOCtrl
12661  * module IOMap structure where the new value should be written. See \ref IOCtrlIOMAP.
12662  * \param _n A variable containing the new value to write to the IOCtrl
12663  * module IOMap.
12664  */
12665 #define SetIOCtrlModuleValue(_offset, _n) SetIOMapValueByID(IOCtrlModuleID, _offset, _n)
12666 
12667 /**
12668  * Set Loader module IOMap value.
12669  * Set one of the fields of the Loader module IOMap structure to a new value.
12670  * You provide the offset into the Loader module IOMap structure where you
12671  * want to write the value along with a variable containing the new value.
12672  * \param _offset The number of bytes offset from the start of the Loader
12673  * module IOMap structure where the new value should be written. See \ref LoaderIOMAP.
12674  * \param _n A variable containing the new value to write to the Loader
12675  * module IOMap.
12676  */
12677 #define SetLoaderModuleValue(_offset, _n) SetIOMapValueByID(LoaderModuleID, _offset, _n)
12678 
12679 /**
12680  * Set Ui module IOMap value.
12681  * Set one of the fields of the Ui module IOMap structure to a new value.
12682  * You provide the offset into the Ui module IOMap structure where you
12683  * want to write the value along with a variable containing the new value.
12684  * \param _offset The number of bytes offset from the start of the Ui
12685  * module IOMap structure where the new value should be written. See \ref UiIOMAP.
12686  * \param _n A variable containing the new value to write to the Ui
12687  * module IOMap.
12688  */
12689 #define SetUIModuleValue(_offset, _n) SetIOMapValueByID(UIModuleID, _offset, _n)
12690 
12691 /**
12692  * Set Sound module IOMap value.
12693  * Set one of the fields of the Sound module IOMap structure to a new value.
12694  * You provide the offset into the Sound module IOMap structure where you
12695  * want to write the value along with a variable containing the new value.
12696  * \param _offset The number of bytes offset from the start of the Sound
12697  * module IOMap structure where the new value should be written. See \ref SoundIOMAP.
12698  * \param _n A variable containing the new value to write to the Sound
12699  * module IOMap.
12700  */
12701 #define SetSoundModuleValue(_offset, _n) SetIOMapValueByID(SoundModuleID, _offset, _n)
12702 
12703 /**
12704  * Set Button module IOMap value.
12705  * Set one of the fields of the Button module IOMap structure to a new value.
12706  * You provide the offset into the Button module IOMap structure where you
12707  * want to write the value along with a variable containing the new value.
12708  * \param _offset The number of bytes offset from the start of the Button
12709  * module IOMap structure where the new value should be written. See \ref ButtonIOMAP.
12710  * \param _n A variable containing the new value to write to the Button
12711  * module IOMap.
12712  */
12713 #define SetButtonModuleValue(_offset, _n) SetIOMapValueByID(ButtonModuleID, _offset, _n)
12714 
12715 /**
12716  * Set Input module IOMap value.
12717  * Set one of the fields of the Input module IOMap structure to a new value.
12718  * You provide the offset into the Input module IOMap structure where you
12719  * want to write the value along with a variable containing the new value.
12720  * \param _offset The number of bytes offset from the start of the Input
12721  * module IOMap structure where the new value should be written. See \ref InputIOMAP.
12722  * \param _n A variable containing the new value to write to the Input
12723  * module IOMap.
12724  */
12725 #define SetInputModuleValue(_offset, _n) SetIOMapValueByID(InputModuleID, _offset, _n)
12726 
12727 /**
12728  * Set Output module IOMap value.
12729  * Set one of the fields of the Output module IOMap structure to a new value.
12730  * You provide the offset into the Output module IOMap structure where you
12731  * want to write the value along with a variable containing the new value.
12732  * \param _offset The number of bytes offset from the start of the Output
12733  * module IOMap structure where the new value should be written. See \ref OutputIOMAP.
12734  * \param _n A variable containing the new value to write to the Output
12735  * module IOMap.
12736  */
12737 #define SetOutputModuleValue(_offset, _n) SetIOMapValueByID(OutputModuleID, _offset, _n)
12738 
12739 /**
12740  * Set Lowspeed module IOMap value.
12741  * Set one of the fields of the Lowspeed module IOMap structure to a new value.
12742  * You provide the offset into the Lowspeed module IOMap structure where you
12743  * want to write the value along with a variable containing the new value.
12744  * \param _offset The number of bytes offset from the start of the Lowspeed
12745  * module IOMap structure where the new value should be written. See \ref LowSpeedIOMAP.
12746  * \param _n A variable containing the new value to write to the Lowspeed
12747  * module IOMap.
12748  */
12749 #define SetLowSpeedModuleValue(_offset, _n) SetIOMapValueByID(LowSpeedModuleID, _offset, _n)
12750 
12751 /**
12752  * Set Display module IOMap value.
12753  * Set one of the fields of the Display module IOMap structure to a new value.
12754  * You provide the offset into the Display module IOMap structure where you
12755  * want to write the value along with a variable containing the new value.
12756  * \param _offset The number of bytes offset from the start of the Display
12757  * module IOMap structure where the new value should be written. See \ref DisplayIOMAP.
12758  * \param _n A variable containing the new value to write to the Display
12759  * module IOMap.
12760  */
12761 #define SetDisplayModuleValue(_offset, _n) SetIOMapValueByID(DisplayModuleID, _offset, _n)
12762 
12763 /**
12764  * Set Comm module IOMap value.
12765  * Set one of the fields of the Comm module IOMap structure to a new value.
12766  * You provide the offset into the Comm module IOMap structure where you
12767  * want to write the value along with a variable containing the new value.
12768  * \param _offset The number of bytes offset from the start of the Comm
12769  * module IOMap structure where the new value should be written. See \ref CommIOMAP.
12770  * \param _n A variable containing the new value to write to the Comm
12771  * module IOMap.
12772  */
12773 #define SetCommModuleValue(_offset, _n) SetIOMapValueByID(CommModuleID, _offset, _n)
12774 
12775 /**
12776  * Set Command module IOMap bytes.
12777  * Modify one or more bytes of data in the Command module IOMap structure. You
12778  * provide the offset into the Command module IOMap structure where you want
12779  * to start writing, the number of bytes to write at that location, and a byte
12780  * array containing the new data.
12781  * \param _offset The number of bytes offset from the start of the Command module
12782  * IOMap structure where the data should be written. See \ref CommandIOMAP.
12783  * \param _cnt The number of bytes to write at the specified Command module
12784  * IOMap offset.
12785  * \param _arrIn The byte array containing the data to write to the Command
12786  * module IOMap.
12787  */
12788 #define SetCommandModuleBytes(_offset, _cnt, _arrIn) SetIOMapBytesByID(CommandModuleID, _offset, _cnt, _arrIn)
12789 
12790 /**
12791  * Set Lowspeed module IOMap bytes.
12792  * Modify one or more bytes of data in the Lowspeed module IOMap structure. You
12793  * provide the offset into the Lowspeed module IOMap structure where you want
12794  * to start writing, the number of bytes to write at that location, and a byte
12795  * array containing the new data.
12796  * \param _offset The number of bytes offset from the start of the Lowspeed
12797  * module IOMap structure where the data should be written. See \ref LowSpeedIOMAP.
12798  * \param _cnt The number of bytes to write at the specified Lowspeed module
12799  * IOMap offset.
12800  * \param _arrIn The byte array containing the data to write to the Lowspeed
12801  * module IOMap.
12802  */
12803 #define SetLowSpeedModuleBytes(_offset, _cnt, _arrIn) SetIOMapBytesByID(LowSpeedModuleID, _offset, _cnt, _arrIn)
12804 
12805 /**
12806  * Set Display module IOMap bytes.
12807  * Modify one or more bytes of data in the Display module IOMap structure. You
12808  * provide the offset into the Display module IOMap structure where you want to
12809  * start writing, the number of bytes to write at that location, and a byte
12810  * array containing the new data.
12811  * \param _offset The number of bytes offset from the start of the Display module
12812  * IOMap structure where the data should be written. See \ref DisplayIOMAP.
12813  * \param _cnt The number of bytes to write at the specified Display module
12814  * IOMap offset.
12815  * \param _arrIn The byte array containing the data to write to the Display
12816  * module IOMap.
12817  */
12818 #define SetDisplayModuleBytes(_offset, _cnt, _arrIn) SetIOMapBytesByID(DisplayModuleID, _offset, _cnt, _arrIn)
12819 
12820 /**
12821  * Set Comm module IOMap bytes.
12822  * Modify one or more bytes of data in an IOMap structure. You provide the
12823  * offset into the Comm module IOMap structure where you want to start writing,
12824  * the number of bytes to write at that location, and a byte array containing
12825  * the new data.
12826  * \param _offset The number of bytes offset from the start of the Comm module
12827  * IOMap structure where the data should be written. See \ref CommIOMAP.
12828  * \param _cnt The number of bytes to write at the specified Comm module IOMap
12829  * offset.
12830  * \param _arrIn The byte array containing the data to write to the Comm module
12831  * IOMap.
12832  */
12833 #define SetCommModuleBytes(_offset, _cnt, _arrIn) SetIOMapBytesByID(CommModuleID, _offset, _cnt, _arrIn)
12834 
12835 #else
12836 
12837 #define SetCommandModuleValue(_offset, _n) SetIOMapValue(CommandModuleName, _offset, _n)
12838 #define SetIOCtrlModuleValue(_offset, _n) SetIOMapValue(IOCtrlModuleName, _offset, _n)
12839 #define SetLoaderModuleValue(_offset, _n) SetIOMapValue(LoaderModuleName, _offset, _n)
12840 #define SetUIModuleValue(_offset, _n) SetIOMapValue(UIModuleName, _offset, _n)
12841 #define SetSoundModuleValue(_offset, _n) SetIOMapValue(SoundModuleName, _offset, _n)
12842 #define SetButtonModuleValue(_offset, _n) SetIOMapValue(ButtonModuleName, _offset, _n)
12843 #define SetInputModuleValue(_offset, _n) SetIOMapValue(InputModuleName, _offset, _n)
12844 #define SetOutputModuleValue(_offset, _n) SetIOMapValue(OutputModuleName, _offset, _n)
12845 #define SetLowSpeedModuleValue(_offset, _n) SetIOMapValue(LowSpeedModuleName, _offset, _n)
12846 #define SetDisplayModuleValue(_offset, _n) SetIOMapValue(DisplayModuleName, _offset, _n)
12847 #define SetCommModuleValue(_offset, _n) SetIOMapValue(CommModuleName, _offset, _n)
12848 
12849 #define SetCommandModuleBytes(_offset, _cnt, _arrIn) SetIOMapBytes(CommandModuleName, _offset, _cnt, _arrIn)
12850 #define SetLowSpeedModuleBytes(_offset, _cnt, _arrIn) SetIOMapBytes(LowSpeedModuleName, _offset, _cnt, _arrIn)
12851 #define SetDisplayModuleBytes(_offset, _cnt, _arrIn) SetIOMapBytes(DisplayModuleName, _offset, _cnt, _arrIn)
12852 #define SetCommModuleBytes(_offset, _cnt, _arrIn) SetIOMapBytes(CommModuleName, _offset, _cnt, _arrIn)
12853 
12854 #endif
12855 
12856 /**
12857  * Get IOMap bytes by name.
12858  * Read one or more bytes of data from an IOMap structure. The IOMap
12859  * structure is specified by its module name. You also provide the offset into
12860  * the IOMap structure where you want to start reading, the number of bytes to
12861  * read from that location, and a byte array where the data will be stored.
12862  * \param _modName The module name of the IOMap. See \ref ModuleNameConstants.
12863  * \param _offset The number of bytes offset from the start of the IOMap
12864  * structure where the data should be read
12865  * \param _cnt The number of bytes to read from the specified IOMap
12866  * offset.
12867  * \param _arrOut A byte array that will contain the data read from the IOMap
12868  */
12869 #define GetIOMapBytes(_modName, _offset, _cnt, _arrOut) __getIOMapBytes(_modName, _offset, _cnt, _arrOut)
12870 
12871 /**
12872  * Get IOMap value by name.
12873  * Read a value from an IOMap structure.  The IOMap
12874  * structure is specified by its module name. You also provide the offset into
12875  * the IOMap structure where you want to read the value along with a variable
12876  * that will contain the IOMap value.
12877  * \param _modName The module name of the IOMap. See \ref ModuleNameConstants.
12878  * \param _offset The number of bytes offset from the start of the IOMap
12879  * structure where the value should be read
12880  * \param _n A variable that will contain the value read from the IOMap
12881  */
12882 #define GetIOMapValue(_modName, _offset, _n) __getIOMapValue(_modName, _offset, _n)
12883 
12884 #ifdef __ENHANCED_FIRMWARE
12885 
12886 /**
12887  * Get IOMap bytes by ID.
12888  * Read one or more bytes of data from an IOMap structure. The IOMap
12889  * structure is specified by its Module ID. You also provide the offset into
12890  * the IOMap structure where you want to start reading, the number of bytes to
12891  * read from that location, and a byte array where the data will be stored.
12892  * \param _modID The module ID of the IOMap. See \ref ModuleIDConstants.
12893  * \param _offset The number of bytes offset from the start of the IOMap
12894  * structure where the data should be read.
12895  * \param _cnt The number of bytes to read from the specified IOMap
12896  * offset.
12897  * \param _arrOut A byte array that will contain the data read from the IOMap.
12898  * \warning This function requires the enhanced NBC/NXC firmware.
12899  */
12900 #define GetIOMapBytesByID(_modID, _offset, _cnt, _arrOut) __getIOMapBytesByID(_modID, _offset, _cnt, _arrOut)
12901 
12902 /**
12903  * Get IOMap value by ID.
12904  * Read a value from an IOMap structure.  The IOMap
12905  * structure is specified by its Module ID. You also provide the offset into
12906  * the IOMap structure where you want to read the value along with a variable
12907  * that will contain the IOMap value.
12908  * \param _modID The module ID of the IOMap. See \ref ModuleIDConstants.
12909  * \param _offset The number of bytes offset from the start of the IOMap
12910  * structure where the value should be read.
12911  * \param _n A variable that will contain the value read from the IOMap.
12912  * \warning This function requires the enhanced NBC/NXC firmware.
12913  */
12914 #define GetIOMapValueByID(_modID, _offset, _n) __getIOMapValueByID(_modID, _offset, _n)
12915 
12916 /**
12917  * Get Command module IOMap value.
12918  * Read a value from the Command module IOMap structure.  You provide the
12919  * offset into the Command module IOMap structure where you want to read
12920  * the value from along with a variable that will store the value. The type
12921  * of the variable determines how many bytes are read from the IOMap.
12922  * \param _offset The number of bytes offset from the start of the IOMap
12923  * structure where the value should be read. See \ref CommandIOMAP.
12924  * \param _n A variable that will contain the value read from the IOMap.
12925  */
12926 #define GetCommandModuleValue(_offset, _n) GetIOMapValueByID(CommandModuleID, _offset, _n)
12927 
12928 /**
12929  * Get Loader module IOMap value.
12930  * Read a value from the Loader module IOMap structure.  You provide the
12931  * offset into the Loader module IOMap structure where you want to read
12932  * the value from along with a variable that will store the value. The type
12933  * of the variable determines how many bytes are read from the IOMap.
12934  * \param _offset The number of bytes offset from the start of the IOMap
12935  * structure where the value should be read. See \ref LoaderIOMAP.
12936  * \param _n A variable that will contain the value read from the IOMap.
12937  */
12938 #define GetLoaderModuleValue(_offset, _n) GetIOMapValueByID(LoaderModuleID, _offset, _n)
12939 
12940 /**
12941  * Get Sound module IOMap value.
12942  * Read a value from the Sound module IOMap structure.  You provide the
12943  * offset into the Sound module IOMap structure where you want to read
12944  * the value from along with a variable that will store the value. The type
12945  * of the variable determines how many bytes are read from the IOMap.
12946  * \param _offset The number of bytes offset from the start of the IOMap
12947  * structure where the value should be read. See \ref SoundIOMAP.
12948  * \param _n A variable that will contain the value read from the IOMap.
12949  */
12950 #define GetSoundModuleValue(_offset, _n) GetIOMapValueByID(SoundModuleID, _offset, _n)
12951 
12952 /**
12953  * Get Button module IOMap value.
12954  * Read a value from the Button module IOMap structure.  You provide the
12955  * offset into the Button module IOMap structure where you want to read
12956  * the value from along with a variable that will store the value. The type
12957  * of the variable determines how many bytes are read from the IOMap.
12958  * \param _offset The number of bytes offset from the start of the IOMap
12959  * structure where the value should be read. See \ref ButtonIOMAP.
12960  * \param _n A variable that will contain the value read from the IOMap.
12961  */
12962 #define GetButtonModuleValue(_offset, _n) GetIOMapValueByID(ButtonModuleID, _offset, _n)
12963 
12964 /**
12965  * Get Ui module IOMap value.
12966  * Read a value from the Ui module IOMap structure.  You provide the
12967  * offset into the Ui module IOMap structure where you want to read
12968  * the value from along with a variable that will store the value. The type
12969  * of the variable determines how many bytes are read from the IOMap.
12970  * \param _offset The number of bytes offset from the start of the IOMap
12971  * structure where the value should be read. See \ref UiIOMAP.
12972  * \param _n A variable that will contain the value read from the IOMap.
12973  */
12974 #define GetUIModuleValue(_offset, _n) GetIOMapValueByID(UIModuleID, _offset, _n)
12975 
12976 /**
12977  * Get Input module IOMap value.
12978  * Read a value from the Input module IOMap structure.  You provide the
12979  * offset into the Input module IOMap structure where you want to read
12980  * the value from along with a variable that will store the value. The type
12981  * of the variable determines how many bytes are read from the IOMap.
12982  * \param _offset The number of bytes offset from the start of the IOMap
12983  * structure where the value should be read. See \ref InputIOMAP.
12984  * \param _n A variable that will contain the value read from the IOMap.
12985  */
12986 #define GetInputModuleValue(_offset, _n) GetIOMapValueByID(InputModuleID, _offset, _n)
12987 
12988 /**
12989  * Get Output module IOMap value.
12990  * Read a value from the Output module IOMap structure.  You provide the
12991  * offset into the Output module IOMap structure where you want to read
12992  * the value from along with a variable that will store the value. The type
12993  * of the variable determines how many bytes are read from the IOMap.
12994  * \param _offset The number of bytes offset from the start of the IOMap
12995  * structure where the value should be read. See \ref OutputIOMAP.
12996  * \param _n A variable that will contain the value read from the IOMap.
12997  */
12998 #define GetOutputModuleValue(_offset, _n) GetIOMapValueByID(OutputModuleID, _offset, _n)
12999 
13000 /**
13001  * Get LowSpeed module IOMap value.
13002  * Read a value from the LowSpeed module IOMap structure.  You provide the
13003  * offset into the Command module IOMap structure where you want to read
13004  * the value from along with a variable that will store the value. The type
13005  * of the variable determines how many bytes are read from the IOMap.
13006  * \param _offset The number of bytes offset from the start of the IOMap
13007  * structure where the value should be read. See \ref LowSpeedIOMAP.
13008  * \param _n A variable that will contain the value read from the IOMap.
13009  */
13010 #define GetLowSpeedModuleValue(_offset, _n) GetIOMapValueByID(LowSpeedModuleID, _offset, _n)
13011 
13012 /**
13013  * Get Display module IOMap value.
13014  * Read a value from the Display module IOMap structure.  You provide the
13015  * offset into the Display module IOMap structure where you want to read
13016  * the value from along with a variable that will store the value. The type
13017  * of the variable determines how many bytes are read from the IOMap.
13018  * \param _offset The number of bytes offset from the start of the IOMap
13019  * structure where the value should be read. See \ref DisplayIOMAP.
13020  * \param _n A variable that will contain the value read from the IOMap.
13021  */
13022 #define GetDisplayModuleValue(_offset, _n) GetIOMapValueByID(DisplayModuleID, _offset, _n)
13023 
13024 /**
13025  * Get Comm module IOMap value.
13026  * Read a value from the Comm module IOMap structure.  You provide the
13027  * offset into the Comm module IOMap structure where you want to read
13028  * the value from along with a variable that will store the value. The type
13029  * of the variable determines how many bytes are read from the IOMap.
13030  * \param _offset The number of bytes offset from the start of the IOMap
13031  * structure where the value should be read. See \ref CommIOMAP.
13032  * \param _n A variable that will contain the value read from the IOMap.
13033  */
13034 #define GetCommModuleValue(_offset, _n) GetIOMapValueByID(CommModuleID, _offset, _n)
13035 
13036 #else
13037 
13038 #define GetCommandModuleValue(_offset, _n) GetIOMapValue(CommandModuleName, _offset, _n)
13039 #define GetLoaderModuleValue(_offset, _n) GetIOMapValue(LoaderModuleName, _offset, _n)
13040 #define GetSoundModuleValue(_offset, _n) GetIOMapValue(SoundModuleName, _offset, _n)
13041 #define GetButtonModuleValue(_offset, _n) GetIOMapValue(ButtonModuleName, _offset, _n)
13042 #define GetUIModuleValue(_offset, _n) GetIOMapValue(UIModuleName, _offset, _n)
13043 #define GetInputModuleValue(_offset, _n) GetIOMapValue(InputModuleName, _offset, _n)
13044 #define GetOutputModuleValue(_offset, _n) GetIOMapValue(OutputModuleName, _offset, _n)
13045 #define GetLowSpeedModuleValue(_offset, _n) GetIOMapValue(LowSpeedModuleName, _offset, _n)
13046 #define GetDisplayModuleValue(_offset, _n) GetIOMapValue(DisplayModuleName, _offset, _n)
13047 #define GetCommModuleValue(_offset, _n) GetIOMapValue(CommModuleName, _offset, _n)
13048 
13049 #endif
13050 
13051 /**
13052  * Get Lowspeed module IOMap bytes.
13053  * Read one or more bytes of data from Lowspeed module IOMap structure.
13054  * You provide the offset into the Lowspeed module IOMap structure where you
13055  * want to start reading, the number of bytes to read from that location, and
13056  * a byte array where the data will be stored.
13057  * \param _offset The number of bytes offset from the start of the Lowspeed
13058  * module IOMap structure where the data should be read. See \ref LowSpeedIOMAP.
13059  * \param _cnt The number of bytes to read from the specified Lowspeed module
13060  * IOMap offset.
13061  * \param _arrOut A byte array that will contain the data read from the Lowspeed
13062  * module IOMap.
13063  */
13064 #define GetLowSpeedModuleBytes(_offset, _cnt, _arrOut) __getLowSpeedModuleBytes(_offset, _cnt, _arrOut)
13065 
13066 /**
13067  * Get Display module IOMap bytes.
13068  * Read one or more bytes of data from Display module IOMap structure.
13069  * You provide the offset into the Display module IOMap structure where you
13070  * want to start reading, the number of bytes to read from that location, and
13071  * a byte array where the data will be stored.
13072  * \param _offset The number of bytes offset from the start of the Display
13073  * module IOMap structure where the data should be read. See \ref DisplayIOMAP.
13074  * \param _cnt The number of bytes to read from the specified Display module
13075  * IOMap offset.
13076  * \param _arrOut A byte array that will contain the data read from the Display
13077  * module IOMap.
13078  */
13079 #define GetDisplayModuleBytes(_offset, _cnt, _arrOut) __getDisplayModuleBytes(_offset, _cnt, _arrOut)
13080 
13081 /**
13082  * Get Comm module IOMap bytes.
13083  * Read one or more bytes of data from Comm module IOMap structure.
13084  * You provide the offset into the Comm module IOMap structure where you
13085  * want to start reading, the number of bytes to read from that location, and
13086  * a byte array where the data will be stored.
13087  * \param _offset The number of bytes offset from the start of the Comm module
13088  * IOMap structure where the data should be read. See \ref CommIOMAP.
13089  * \param _cnt The number of bytes to read from the specified Comm module
13090  * IOMap offset.
13091  * \param _arrOut A byte array that will contain the data read from the Comm
13092  * module IOMap.
13093  */
13094 #define GetCommModuleBytes(_offset, _cnt, _arrOut) __getCommModuleBytes(_offset, _cnt, _arrOut)
13095 
13096 /**
13097  * Get Command module IOMap bytes.
13098  * Read one or more bytes of data from Command module IOMap structure.
13099  * You provide the offset into the Command module IOMap structure where you
13100  * want to start reading, the number of bytes to read from that location, and
13101  * a byte array where the data will be stored.
13102  * \param _offset The number of bytes offset from the start of the Command module
13103  * IOMap structure where the data should be read. See \ref CommandIOMAP.
13104  * \param _cnt The number of bytes to read from the specified Command module
13105  * IOMap offset.
13106  * \param _arrOut A byte array that will contain the data read from the Command
13107  * module IOMap.
13108  */
13109 #define GetCommandModuleBytes(_offset, _cnt, _arrOut) __getCommandModuleBytes(_offset, _cnt, _arrOut)
13110 
13111 /**
13112  * Reset the sleep timer.
13113  * This function lets you reset the sleep timer.
13114  *
13115  */
13116 #define ResetSleepTimer syscall KeepAlive, __KeepAliveArgs
13117 
13118 /**
13119  * Get the first tick.
13120  * Return an unsigned 32-bit value, which is the system timing value
13121  * (called a "tick") in milliseconds at the time that the program began
13122  * running.
13123  *
13124  * \param _value The tick count at the start of program execution.
13125  */
13126 #define GetFirstTick(_value) __GetFirstTick(_value)
13127 
13128 /**
13129  * Wait some milliseconds.
13130  * Make a task sleep for specified amount of time (in 1000ths of a second).
13131  *
13132  * \param _n The number of milliseconds to sleep.
13133  */
13134 #define Wait(_n) waitv _n
13135 
13136 #if defined(__ENHANCED_FIRMWARE) && (__FIRMWARE_VERSION > 107)
13137 /**
13138  * Read memory information.
13139  * Read the current pool size and dataspace size.  Optionally compact the
13140  * dataspace before returning the information. Running programs have a maximum
13141  * of 32k bytes of memory available.  The amount of free RAM can be calculated
13142  * by subtracting the value returned by this function from \ref POOL_MAX_SIZE.
13143  *
13144  * \warning This function requires the enhanced NBC/NXC firmware version 1.28+.
13145  *
13146  * \param _Compact A boolean value indicating whether to compact the dataspace or not.
13147  * \param _PoolSize The current pool size.
13148  * \param _DataspaceSize The current dataspace size.
13149  * \param _Result The function call result. It will be \ref NO_ERR if the compact
13150  * operation is not performed.  Otherwise it will be the result of the compact
13151  * operation.
13152  */
13153 #define GetMemoryInfo(_Compact,_PoolSize,_DataspaceSize,_Result) __GetMemoryInfo(_Compact,_PoolSize,_DataspaceSize,_Result)
13154 
13155 /**
13156  * Read last response information.
13157  * Read the last direct or system command response packet received by the NXT.
13158  * Optionally clear the response after retrieving the information.
13159  *
13160  * \warning This function requires the enhanced NBC/NXC firmware version 1.31+.
13161  *
13162  * \param _Clear A boolean value indicating whether to clear the response or not.
13163  * \param _Length The response packet length.
13164  * \param _Command The original command byte.
13165  * \param _Buffer The response packet buffer.
13166  * \param _Result The response status code.
13167  */
13168 #define GetLastResponseInfo(_Clear,_Length,_Command,_Buffer,_Result) __GetLastResponseInfo(_Clear,_Length,_Command,_Buffer,_Result)
13169 
13170 #endif
13171 
13172 
13173 /** @} */ // end of CommandModuleFunctions group
13174 /** @} */ // end of CommandModule group
13175 /** @} */ // end of NXTFirmwareModules group
13176 
13177 
13178 ///////////////////////////////////////////////////////////////////////////////
13179 //////////////////////////////// BUTTON MODULE ////////////////////////////////
13180 ///////////////////////////////////////////////////////////////////////////////
13181 
13182 
13183 /** @addtogroup NXTFirmwareModules
13184  * @{
13185  */
13186 /** @addtogroup ButtonModule
13187  * @{
13188  */
13189 /** @defgroup ButtonModuleFunctions Button module functions
13190  * Functions for accessing and modifying Button module features.
13191  * @{
13192  */
13193 
13194 /**
13195  * Read button information.
13196  * Read the specified button. Set the pressed and count parameters with the
13197  * current state of the button. Optionally reset the press count after
13198  * reading it.
13199  *
13200  * \param _idx The button to check. See \ref ButtonNameConstants.
13201  * \param _reset Whether or not to reset the press counter.
13202  * \param _pressed The button pressed state.
13203  * \param _count The button press count.
13204  * \param _result The function call result.
13205  */
13206 #define ReadButtonEx(_idx, _reset, _pressed, _count, _result) __ReadButtonEx(_idx, _reset, _pressed, _count, _result)
13207 
13208 /**
13209  * Get button press count.
13210  * Return the press count of the specified button.
13211  *
13212  * \param _b The button to check. See \ref ButtonNameConstants.
13213  * \param _n The button press count.
13214  */
13215 #define GetButtonPressCount(_b, _n) __GetButtonPressCount(_b, _n)
13216 
13217 /**
13218  * Get button long press count.
13219  * Return the long press count of the specified button.
13220  *
13221  * \param _b The button to check. See \ref ButtonNameConstants.
13222  * \param _n The button long press count.
13223  */
13224 #define GetButtonLongPressCount(_b, _n) __GetButtonLongPressCount(_b, _n)
13225 
13226 /**
13227  * Get button short release count.
13228  * Return the short release count of the specified button.
13229  *
13230  * \param _b The button to check. See \ref ButtonNameConstants.
13231  * \param _n The button short release count.
13232  */
13233 #define GetButtonShortReleaseCount(_b, _n) __GetButtonShortReleaseCount(_b, _n)
13234 
13235 /**
13236  * Get button long release count.
13237  * Return the long release count of the specified button.
13238  *
13239  * \param _b The button to check. See \ref ButtonNameConstants.
13240  * \param _n The button long release count.
13241  */
13242 #define GetButtonLongReleaseCount(_b, _n) __GetButtonLongReleaseCount(_b, _n)
13243 
13244 /**
13245  * Get button release count.
13246  * Return the release count of the specified button.
13247  *
13248  * \param _b The button to check. See \ref ButtonNameConstants.
13249  * \param _n The button release count.
13250 */
13251 #define GetButtonReleaseCount(_b, _n) __GetButtonReleaseCount(_b, _n)
13252 
13253 /**
13254  * Get button state.
13255  * Return the state of the specified button. See \ref ButtonStateConstants.
13256  *
13257  * \param _b The button to check. See \ref ButtonNameConstants.
13258  * \param _n The button state.
13259  */
13260 #define GetButtonState(_b, _n) __GetButtonState(_b, _n)
13261 
13262 /**
13263  * Set button press count.
13264  * Set the press count of the specified button.
13265  *
13266  * \param _b The button number. See \ref ButtonNameConstants.
13267  * \param _n The new press count value.
13268  */
13269 #define SetButtonPressCount(_b, _n) __setButtonPressCount(_b, _n)
13270 
13271 /**
13272  * Set button long press count.
13273  * Set the long press count of the specified button.
13274  *
13275  * \param _b The button number. See \ref ButtonNameConstants.
13276  * \param _n The new long press count value.
13277  */
13278 #define SetButtonLongPressCount(_b, _n) __setButtonLongPressCount(_b, _n)
13279 
13280 /**
13281  * Set button short release count.
13282  * Set the short release count of the specified button.
13283  *
13284  * \param _b The button number. See \ref ButtonNameConstants.
13285  * \param _n The new short release count value.
13286  */
13287 #define SetButtonShortReleaseCount(_b, _n) __setButtonShortReleaseCount(_b, _n)
13288 
13289 /**
13290  * Set button long release count.
13291  * Set the long release count of the specified button.
13292  *
13293  * \param _b The button number. See \ref ButtonNameConstants.
13294  * \param _n The new long release count value.
13295  */
13296 #define SetButtonLongReleaseCount(_b, _n) __setButtonLongReleaseCount(_b, _n)
13297 
13298 /**
13299  * Set button release count.
13300  * Set the release count of the specified button.
13301  *
13302  * \param _b The button number. See \ref ButtonNameConstants.
13303  * \param _n The new release count value.
13304  */
13305 #define SetButtonReleaseCount(_b, _n) __setButtonReleaseCount(_b, _n)
13306 
13307 /**
13308  * Set button state.
13309  * Set the state of the specified button.
13310  *
13311  * \param _b The button to check. See \ref ButtonNameConstants.
13312  * \param _n The new button state. See \ref ButtonStateConstants.
13313 */
13314 #define SetButtonState(_b, _n) __setButtonState(_b, _n)
13315 
13316 /** @} */ // end of ButtonModuleFunctions group
13317 /** @} */ // end of ButtonModule group
13318 /** @} */ // end of NXTFirmwareModules group
13319 
13320 
13321 ///////////////////////////////////////////////////////////////////////////////
13322 ////////////////////////////////// UI MODULE //////////////////////////////////
13323 ///////////////////////////////////////////////////////////////////////////////
13324 
13325 
13326 /** @addtogroup NXTFirmwareModules
13327  * @{
13328  */
13329 /** @addtogroup UiModule
13330  * @{
13331  */
13332 /** @defgroup UiModuleFunctions Ui module functions
13333  * Functions for accessing and modifying Ui module features.
13334  * @{
13335  */
13336 
13337 /**
13338  * Set command flags.
13339  * Set the command flags.
13340  *
13341  * \param _n The new command flags. See \ref UiFlagsConstants.
13342  */
13343 #define SetCommandFlags(_n) __setCommandFlags(_n)
13344 
13345 /**
13346  * Set UI state.
13347  * Set the user interface state.
13348  *
13349  * \param _n A user interface state value. See \ref UiStateConstants.
13350  */
13351 #define SetUIState(_n) __setUIState(_n)
13352 
13353 /**
13354  * Set UI button.
13355  * Set user interface button information.
13356  *
13357  * \param _n A user interface button value. See \ref UiButtonConstants.
13358  */
13359 #define SetUIButton(_n) __setUIButton(_n)
13360 
13361 /**
13362  * Set VM run state.
13363  * Set VM run state information.
13364  *
13365  * \param _n The desired VM run state. See \ref UiVMRunStateConstants.
13366  */
13367 #define SetVMRunState(_n) __setVMRunState(_n)
13368 
13369 /**
13370  * Set battery state.
13371  * Set battery state information.
13372  *
13373  * \param _n The desired battery state (0..4).
13374  */
13375 #define SetBatteryState(_n) __setBatteryState(_n)
13376 
13377 /**
13378  * Set bluetooth state.
13379  * Set the Bluetooth state.
13380  *
13381  * \param _n The desired bluetooth state. See \ref UiBluetoothStateConstants.
13382  */
13383 #define SetBluetoothState(_n) __setBluetoothState(_n)
13384 
13385 /**
13386  * Set Usb state.
13387  * This method sets the value of the Usb state.
13388  * \param _n The Usb state.
13389  */
13390 #define SetUsbState(_n) __setUsbState(_n)
13391 
13392 /**
13393  * Set sleep timeout.
13394  * Set the NXT sleep timeout value to the specified number of minutes.
13395  *
13396  * \param _n The minutes to wait before sleeping.
13397  */
13398 #define SetSleepTimeout(_n) __setSleepTimeout(_n)
13399 
13400 /**
13401  * Set the sleep timer.
13402  * Set the system sleep timer to the specified number of minutes.
13403  *
13404  * \param _n The minutes left on the timer.
13405  */
13406 #define SetSleepTimer(_n) __setSleepTimer(_n)
13407 
13408 /**
13409  * Set volume.
13410  * Set the user interface volume level. Valid values are from 0 to 4.
13411  *
13412  * \param _n The new volume level.
13413  */
13414 #define SetVolume(_n) __setVolume(_n)
13415 
13416 /**
13417  * Set on-brick program pointer.
13418  * Set the current OBP (on-brick program) step.
13419  *
13420  * \param _n The new on-brick program step.
13421  */
13422 #define SetOnBrickProgramPointer(_n) __setOnBrickProgramPointer(_n)
13423 
13424 /**
13425  * Turn off NXT.
13426  * Force the NXT to turn off if the specified value is greater than zero.
13427  * \param _n If greater than zero the NXT will turn off.
13428 */
13429 #define ForceOff(_n) __forceOff(_n)
13430 
13431 /**
13432  * Set abort flag.
13433  * Set the enhanced NBC/NXC firmware's program abort flag. By default the
13434  * running program can be interrupted by a short press of the escape button.
13435  * You can change this to any other button state flag.
13436  *
13437  * \param _n The new abort flag value. See \ref ButtonStateConstants
13438  *
13439  * \warning This function requires the enhanced NBC/NXC firmware.
13440  */
13441 #define SetAbortFlag(_n) __setAbortFlag(_n)
13442 
13443 /**
13444  * Get battery Level.
13445  * Return the battery level in millivolts.
13446  * \param _n The battery level
13447  */
13448 #define GetBatteryLevel(_n) __GetBatteryLevel(_n)
13449 
13450 /**
13451  * Get command flags.
13452  * Return the command flags.
13453  * \param _n Command flags. See \ref UiFlagsConstants
13454  */
13455 #define GetCommandFlags(_n) __GetCommandFlags(_n)
13456 
13457 /**
13458  * Get UI module state.
13459  * Return the user interface state.
13460  * \param _n The UI module state. See \ref UiStateConstants.
13461  */
13462 #define GetUIState(_n) __GetUIState(_n)
13463 
13464 /**
13465  * Read UI button.
13466  * Return user interface button information.
13467  * \param _n A UI button value.  See \ref UiButtonConstants.
13468  */
13469 #define GetUIButton(_n) __GetUIButton(_n)
13470 
13471 /**
13472  * Read VM run state.
13473  * Return VM run state information.
13474  * \param _n VM run state. See \ref UiVMRunStateConstants.
13475  */
13476 #define GetVMRunState(_n) __GetVMRunState(_n)
13477 
13478 /**
13479  * Get battery state.
13480  * Return battery state information (0..4).
13481  * \param _n The battery state (0..4)
13482  */
13483 #define GetBatteryState(_n) __GetBatteryState(_n)
13484 
13485 /**
13486  * Get bluetooth state.
13487  * Return the bluetooth state.
13488  * \param _n The bluetooth state. See \ref UiBluetoothStateConstants.
13489  */
13490 #define GetBluetoothState(_n) __GetBluetoothState(_n)
13491 
13492 /**
13493  * Get UI module USB state.
13494  * This method returns the UI module USB state.
13495  * \param _n The UI module USB state.  (0=disconnected, 1=connected, 2=working)
13496  */
13497 #define GetUsbState(_n) __GetUsbState(_n)
13498 
13499 /**
13500  * Read sleep timeout.
13501  * Return the number of minutes that the NXT will remain on before
13502  * it automatically shuts down.
13503  * \param _n The sleep timeout value
13504  */
13505 #define GetSleepTimeout(_n) __GetSleepTimeout(_n)
13506 
13507 /**
13508  * Read sleep timer.
13509  * Return the number of minutes left in the countdown to zero from the
13510  * original SleepTimeout value. When the SleepTimer value reaches zero the
13511  * NXT will shutdown.
13512  * \param _n The sleep timer value
13513  */
13514 #define GetSleepTimer(_n) __GetSleepTimer(_n)
13515 
13516 /**
13517  * Read battery type.
13518  * Return whether the NXT has a rechargeable battery installed or not.
13519  * \param _n Whether the battery is rechargeable or not. (false = no, true = yes)
13520  */
13521 #define GetRechargeableBattery(_n) __GetRechargeableBattery(_n)
13522 
13523 /**
13524  * Read volume.
13525  * Return the user interface volume level. Valid values are from 0 to 4.
13526  * \param _n The UI module volume. (0..4)
13527  */
13528 #define GetVolume(_n) __GetVolume(_n)
13529 
13530 /**
13531  * Read the on brick program pointer value.
13532  * Return the current OBP (on-brick program) step
13533  *
13534  * \param _n On brick program pointer (step).
13535  */
13536 #define GetOnBrickProgramPointer(_n) __GetOnBrickProgramPointer(_n)
13537 
13538 /**
13539  * Read abort flag.
13540  * Return the enhanced NBC/NXC firmware's abort flag.
13541  *
13542  * \param _n The current abort flag value.  See \ref ButtonStateConstants.
13543  * \warning This function requires the enhanced NBC/NXC firmware.
13544 */
13545 #define GetAbortFlag(_n) __GetAbortFlag(_n)
13546 
13547 /** @} */ // end of UiModuleFunctions group
13548 /** @} */ // end of UiModule group
13549 /** @} */ // end of NXTFirmwareModules group
13550 
13551 
13552 ///////////////////////////////////////////////////////////////////////////////
13553 ///////////////////////////////// COMM MODULE /////////////////////////////////
13554 ///////////////////////////////////////////////////////////////////////////////
13555 
13556 
13557 /** @addtogroup NXTFirmwareModules
13558  * @{
13559  */
13560 /** @addtogroup CommModule
13561  * @{
13562  */
13563 /** @defgroup CommModuleFunctions Comm module functions
13564  * Functions for accessing and modifying Comm module features.
13565  * @{
13566  */
13567 
13568 /**
13569  * Send a message to a queue/mailbox.
13570  * Write a message into a local mailbox.
13571  *
13572  * \param _queue The mailbox number. See \ref MailboxConstants.
13573  * \param _msg The message to write to the mailbox.
13574  * \param _result A char value indicating whether the function call succeeded or not.
13575  */
13576 #define SendMessage(_queue, _msg, _result) __sendMessage(_queue, _msg, _result)
13577 
13578 /**
13579  * Read a message from a queue/mailbox.
13580  * Read a message from a mailbox and optionally remove it.  If the local mailbox
13581  * is empty and this NXT is the master then it attempts to poll one of its
13582  * slave NXTs for a message from the response mailbox that corresponds to the
13583  * specified local mailbox number.
13584  *
13585  * \param _queue The mailbox number. See \ref MailboxConstants.
13586  * \param _clear A flag indicating whether to remove the message from the mailbox
13587  * after it has been read.
13588  * \param _msg The message that is read from the mailbox.
13589  * \param _result A char value indicating whether the function call succeeded or not.
13590  */
13591 #define ReceiveMessage(_queue, _clear, _msg, _result) __receiveMessage(_queue, _clear, _msg, _result)
13592 
13593 /**
13594  * Read a boolean value from a queue/mailbox.
13595  * Read a boolean value from a mailbox and optionally remove it.  If the local mailbox
13596  * is empty and this NXT is the master then it attempts to poll one of its
13597  * slave NXTs for a message from the response mailbox that corresponds to the
13598  * specified local mailbox number.
13599  *
13600  * \param _queue The mailbox number. See \ref MailboxConstants.
13601  * \param _clear A flag indicating whether to remove the message from the mailbox
13602  * after it has been read.
13603  * \param _bval The boolean value that is read from the mailbox.
13604  * \param _result A char value indicating whether the function call succeeded or not.
13605  */
13606 #define ReceiveRemoteBool(_queue, _clear, _bval, _result) __receiveRemoteBool(_queue, _clear, _bval, _result)
13607 
13608 /**
13609  * Read a numeric value from a queue/mailbox.
13610  * Read a numeric value from a mailbox and optionally remove it.  If the local mailbox
13611  * is empty and this NXT is the master then it attempts to poll one of its
13612  * slave NXTs for a message from the response mailbox that corresponds to the
13613  * specified local mailbox number.
13614  *
13615  * \param _queue The mailbox number. See \ref MailboxConstants.
13616  * \param _clear A flag indicating whether to remove the message from the mailbox
13617  * after it has been read.
13618  * \param _val The numeric value that is read from the mailbox.
13619  * \param _result A char value indicating whether the function call succeeded or not.
13620  */
13621 #define ReceiveRemoteNumber(_queue, _clear, _val, _result) __receiveRemoteNumber(_queue, _clear, _val, _result)
13622 
13623 /**
13624  * Read a string value from a queue/mailbox.
13625  * Read a string value from a mailbox and optionally remove it.  If the local mailbox
13626  * is empty and this NXT is the master then it attempts to poll one of its
13627  * slave NXTs for a message from the response mailbox that corresponds to the
13628  * specified local mailbox number.
13629  *
13630  * \param _queue The mailbox number. See \ref MailboxConstants.
13631  * \param _clear A flag indicating whether to remove the message from the mailbox
13632  * after it has been read.
13633  * \param _str The string value that is read from the mailbox.
13634  * \param _result A char value indicating whether the function call succeeded or not.
13635  */
13636 #define ReceiveRemoteString(_queue, _clear, _str, _result) __receiveMessage(_queue, _clear, _str, _result)
13637 
13638 /**
13639  * Read a value from a queue/mailbox.
13640  * Read a value from a mailbox and optionally remove it.  If the local mailbox
13641  * is empty and this NXT is the master then it attempts to poll one of its
13642  * slave NXTs for a message from the response mailbox that corresponds to the
13643  * specified local mailbox number.  Output the value in string, number, and
13644  * boolean form.
13645  *
13646  * \param _queue The mailbox number. See \ref MailboxConstants.
13647  * \param _clear A flag indicating whether to remove the message from the mailbox
13648  * after it has been read.
13649  * \param _str The string value that is read from the mailbox.
13650  * \param _val The numeric value that is read from the mailbox.
13651  * \param _bval The boolean value that is read from the mailbox.
13652  * \param _result A char value indicating whether the function call succeeded or not.
13653  */
13654 #define ReceiveRemoteMessageEx(_queue, _clear, _str, _val, _bval, _result) __receiveRemoteMessageEx(_queue, _clear, _str, _val, _bval, _result)
13655 
13656 /**
13657  * Write a string value to a local response mailbox.
13658  * Write a string value to a response mailbox (the mailbox number + 10).
13659  *
13660  * \param _queue The mailbox number. See \ref MailboxConstants. This function
13661  * shifts the specified value into the range of response mailbox numbers by
13662  * adding 10.
13663  * \param _msg The string value to write.
13664  * \param _result A char value indicating whether the function call succeeded or not.
13665  */
13666 #define SendResponseString(_queue, _msg, _result) __sendResponseString(_queue, _msg, _result)
13667 
13668 /**
13669  * Write a boolean value to a local response mailbox.
13670  * Write a boolean value to a response mailbox (the mailbox number + 10).
13671  *
13672  * \param _queue The mailbox number. See \ref MailboxConstants. This function
13673  * shifts the specified value into the range of response mailbox numbers by
13674  * adding 10.
13675  * \param _bval The boolean value to write.
13676  * \param _result A char value indicating whether the function call succeeded or not.
13677  */
13678 #define SendResponseBool(_queue, _bval, _result) __sendResponseBool(_queue, _bval, _result)
13679 
13680 /**
13681  * Write a numeric value to a local response mailbox.
13682  * Write a numeric value to a response mailbox (the mailbox number + 10).
13683  *
13684  * \param _queue The mailbox number. See \ref MailboxConstants. This function
13685  * shifts the specified value into the range of response mailbox numbers by
13686  * adding 10.
13687  * \param _val The numeric value to write.
13688  * \param _result A char value indicating whether the function call succeeded or not.
13689  */
13690 #define SendResponseNumber(_queue, _val, _result) __sendResponseNumber(_queue, _val, _result)
13691 
13692 /**
13693  * Check bluetooth status.
13694  * Check the status of the bluetooth subsystem for the specified connection slot.
13695  *
13696  * \param _conn The connection slot (0..3). Connections 0 through 3 are for
13697  * bluetooth connections. See \ref CommConnectionConstants.
13698  * \param _result The bluetooth status for the specified connection.
13699  */
13700 #define BluetoothStatus(_conn, _result) __bluetoothStatus(_conn, _result)
13701 
13702 /**
13703  * Write to a bluetooth connection.
13704  * This method tells the NXT firmware to write the data in the buffer to the
13705  * device on the specified Bluetooth connection. Use \ref BluetoothStatus to
13706  * determine when this write request is completed.
13707  *
13708  * \param _conn The connection slot (0..3). Connections 0 through 3 are for
13709  * bluetooth connections.  See \ref CommConnectionConstants.
13710  * \param _buffer The data to be written (up to 128 bytes)
13711  * \param _result A char value indicating whether the function call succeeded or not.
13712  */
13713 #define BluetoothWrite(_conn, _buffer, _result) __bluetoothWrite(_conn, _buffer, _result)
13714 
13715 /**
13716  * Write to a remote connection.
13717  * This method tells the NXT firmware to write the data in the buffer to the
13718  * device on the specified connection. Use \ref RemoteConnectionIdle to determine
13719  * when this write request is completed.
13720  *
13721  * \param _conn The connection slot (0..4). Connections 0 through 3 are for
13722  * bluetooth connections.  Connection 4 refers to the RS485 hi-speed port.
13723  * See \ref CommConnectionConstants.
13724  * \param _buffer The data to be written (up to 128 bytes)
13725  * \param _result A char value indicating whether the function call succeeded or not.
13726  *
13727  * \warning Writing to the RS485 hi-speed connection requires the enhanced
13728  * NBC/NXC firmware
13729  */
13730 #define RemoteConnectionWrite(_conn, _buffer, _result) __connectionRawWrite(_conn, _buffer, _result)
13731 
13732 /**
13733  * Check if remote connection is idle.
13734  * Check whether a Bluetooth or RS485 hi-speed port connection is idle,
13735  * i.e., not currently sending data.
13736  *
13737  * \param _conn The connection slot (0..4). Connections 0 through 3 are for
13738  * bluetooth connections.  Connection 4 refers to the RS485 hi-speed port.
13739  * See \ref CommConnectionConstants.
13740  * \param _result A boolean value indicating whether the connection is idle or busy.
13741  *
13742  * \warning Checking the status of the RS485 hi-speed connection requires the
13743  * enhanced NBC/NXC firmware
13744  */
13745 #define RemoteConnectionIdle(_conn, _result) __remoteConnectionIdle(_conn, _result)
13746 
13747 /**
13748  * Send a boolean value to a remote mailbox.
13749  * Send a boolean value on the specified connection to the
13750  * specified remote mailbox number.  Use \ref RemoteConnectionIdle to determine
13751  * when this write request is completed.
13752  *
13753  * \param _conn The connection slot (0..4). Connections 0 through 3 are for
13754  * bluetooth connections.  Connection 4 refers to the RS485 hi-speed port.
13755  * See \ref CommConnectionConstants.
13756  * \param _queue The mailbox number. See \ref MailboxConstants.
13757  * \param _bval The boolean value to send.
13758  * \param _result A char value indicating whether the function call succeeded or not.
13759  */
13760 #define SendRemoteBool(_conn, _queue, _bval, _result) __sendRemoteBool(_conn, _queue, _bval, _result)
13761 
13762 /**
13763  * Send a numeric value to a remote mailbox.
13764  * Send a numeric value on the specified connection to the
13765  * specified remote mailbox number.  Use \ref RemoteConnectionIdle to determine
13766  * when this write request is completed.
13767  *
13768  * \param _conn The connection slot (0..4). Connections 0 through 3 are for
13769  * bluetooth connections.  Connection 4 refers to the RS485 hi-speed port.
13770  * See \ref CommConnectionConstants.
13771  * \param _queue The mailbox number. See \ref MailboxConstants.
13772  * \param _val The numeric value to send.
13773  * \param _result A char value indicating whether the function call succeeded or not.
13774  */
13775 #define SendRemoteNumber(_conn, _queue, _val, _result) __sendRemoteNumber(_conn, _queue, _val, _result)
13776 
13777 /**
13778  * Send a string value to a remote mailbox.
13779  * Send a string value on the specified connection to the
13780  * specified remote mailbox number. Use \ref RemoteConnectionIdle to determine
13781  * when this write request is completed.
13782  *
13783  * \param _conn The connection slot (0..4). Connections 0 through 3 are for
13784  * bluetooth connections.  Connection 4 refers to the RS485 hi-speed port.
13785  * See \ref CommConnectionConstants.
13786  * \param _queue The mailbox number. See \ref MailboxConstants.
13787  * \param _str The string value to send.
13788  * \param _result A char value indicating whether the function call succeeded or not.
13789  */
13790 #define SendRemoteString(_conn, _queue, _str, _result) __sendRemoteString(_conn, _queue, _str, _result)
13791 
13792 
13793 /** @defgroup CommModuleDCFunctions Direct Command functions
13794  * Functions for sending direct commands to another NXT.
13795  * @{
13796  */
13797 
13798 /**
13799  * Send a MessageRead message.
13800  * This method sends a MessageRead direct command to the device on the
13801  * specified connection. Use \ref RemoteConnectionIdle to determine when this write
13802  * request is completed.
13803  *
13804  * \param _conn The connection slot (0..4). Connections 0 through 3 are for
13805  * bluetooth connections.  Connection 4 refers to the RS485 hi-speed port.
13806  * See \ref CommConnectionConstants.
13807  * \param _queue The mailbox to read. See \ref MailboxConstants.
13808  * \param _result A char value indicating whether the function call succeeded or not.
13809  */
13810 #define RemoteMessageRead(_conn, _queue, _result) __remoteMessageRead(_conn, _queue, _result)
13811 
13812 /**
13813  * Send a MessageWrite message.
13814  * This method sends a MessageWrite direct command to the device on the
13815  * specified connection. Use \ref RemoteConnectionIdle to determine when this write
13816  * request is completed.
13817  *
13818  * \param _conn The connection slot (0..4). Connections 0 through 3 are for
13819  * bluetooth connections.  Connection 4 refers to the RS485 hi-speed port.
13820  * See \ref CommConnectionConstants.
13821  * \param _queue The mailbox to write. See \ref MailboxConstants.
13822  * \param _msg The message to write to the mailbox.
13823  * \param _result A char value indicating whether the function call succeeded or not.
13824  */
13825 #define RemoteMessageWrite(_conn, _queue, _msg, _result) __sendRemoteString(_conn, _queue, _msg, _result)
13826 
13827 /**
13828  * Send a StartProgram message.
13829  * Send the StartProgram direct command on the specified connection slot.
13830  * Use \ref RemoteConnectionIdle to determine when this write request is completed.
13831  *
13832  * \param _conn The connection slot (0..4). Connections 0 through 3 are for
13833  * bluetooth connections.  Connection 4 refers to the RS485 hi-speed port.
13834  * See \ref CommConnectionConstants.
13835  * \param _filename The name of the program to start running.
13836  * \param _result A char value indicating whether the function call succeeded or not.
13837  */
13838 #define RemoteStartProgram(_conn, _filename, _result) __remoteStartProgram(_conn, _filename, _result)
13839 
13840 /**
13841  * Send a StopProgram message.
13842  * Send the StopProgram direct command on the specified connection slot.
13843  * Use \ref RemoteConnectionIdle to determine when this write request is completed.
13844  *
13845  * \param _conn The connection slot (0..4). Connections 0 through 3 are for
13846  * bluetooth connections.  Connection 4 refers to the RS485 hi-speed port.
13847  * See \ref CommConnectionConstants.
13848  * \param _result A char value indicating whether the function call succeeded or not.
13849  */
13850 #define RemoteStopProgram(_conn, _result) __connectionSCDCWrite(_conn, __DCStopProgramPacket, _result)
13851 
13852 /**
13853  * Send a PlaySoundFile message.
13854  * Send the PlaySoundFile direct command on the specified connection slot.
13855  * Use \ref RemoteConnectionIdle to determine when this write request is completed.
13856  *
13857  * \param _conn The connection slot (0..4). Connections 0 through 3 are for
13858  * bluetooth connections.  Connection 4 refers to the RS485 hi-speed port.
13859  * See \ref CommConnectionConstants.
13860  * \param _filename The name of the sound file to play.
13861  * \param _bloop A boolean value indicating whether to loop the sound file or not.
13862  * \param _result A char value indicating whether the function call succeeded or not.
13863  */
13864 #define RemotePlaySoundFile(_conn, _filename, _bloop, _result) __remotePlaySoundFile(_conn, _filename, _bloop, _result)
13865 
13866 /**
13867  * Send a PlayTone message.
13868  * Send the PlayTone direct command on the specified connection slot.
13869  * Use \ref RemoteConnectionIdle to determine when this write request is completed.
13870  *
13871  * \param _conn The connection slot (0..4). Connections 0 through 3 are for
13872  * bluetooth connections.  Connection 4 refers to the RS485 hi-speed port.
13873  * See \ref CommConnectionConstants.
13874  * \param _frequency The frequency of the tone.
13875  * \param _duration The duration of the tone.
13876  * \param _result A char value indicating whether the function call succeeded or not.
13877  */
13878 #define RemotePlayTone(_conn, _frequency, _duration, _result) __remotePlayTone(_conn, _frequency, _duration, _result)
13879 
13880 /**
13881  * Send a StopSound message.
13882  * Send the StopSound direct command on the specified connection slot.
13883  * Use \ref RemoteConnectionIdle to determine when this write request is completed.
13884  *
13885  * \param _conn The connection slot (0..4). Connections 0 through 3 are for
13886  * bluetooth connections.  Connection 4 refers to the RS485 hi-speed port.
13887  * See \ref CommConnectionConstants.
13888  * \param _result A char value indicating whether the function call succeeded or not.
13889  */
13890 #define RemoteStopSound(_conn, _result) __connectionSCDCWrite(_conn, __DCStopSoundPacket, _result)
13891 
13892 /**
13893  * Send a KeepAlive message.
13894  * This method sends a KeepAlive direct command to the device on the specified
13895  * connection. Use \ref RemoteConnectionIdle to determine when this write request is
13896  * completed.
13897  *
13898  * \param _conn The connection slot (0..4). Connections 0 through 3 are for
13899  * bluetooth connections.  Connection 4 refers to the RS485 hi-speed port.
13900  * See \ref CommConnectionConstants.
13901  * \param _result A char value indicating whether the function call succeeded or not.
13902  */
13903 #define RemoteKeepAlive(_conn, _result) __connectionSCDCWrite(_conn, __DCKeepAlivePacket, _result)
13904 
13905 /**
13906  * Send a ResetScaledValue message.
13907  * Send the ResetScaledValue direct command on the specified connection slot.
13908  * Use \ref RemoteConnectionIdle to determine when this write request is completed.
13909  *
13910  * \param _conn The connection slot (0..4). Connections 0 through 3 are for
13911  * bluetooth connections.  Connection 4 refers to the RS485 hi-speed port.
13912  * See \ref CommConnectionConstants.
13913  * \param _port The input port to reset.
13914  * \param _result A char value indicating whether the function call succeeded or not.
13915  */
13916 #define RemoteResetScaledValue(_conn, _port, _result) __remoteResetScaledValue(_conn, _port, _result)
13917 
13918 /**
13919  * Send a ResetMotorPosition message.
13920  * Send the ResetMotorPosition direct command on the specified connection slot.
13921  * Use \ref RemoteConnectionIdle to determine when this write request is completed.
13922  *
13923  * \param _conn The connection slot (0..4). Connections 0 through 3 are for
13924  * bluetooth connections.  Connection 4 refers to the RS485 hi-speed port.
13925  * See \ref CommConnectionConstants.
13926  * \param _port The output port to reset.
13927  * \param _brelative A flag indicating whether the counter to reset is relative.
13928  * \param _result A char value indicating whether the function call succeeded or not.
13929  */
13930 #define RemoteResetMotorPosition(_conn, _port, _brelative, _result) __remoteResetMotorPosition(_conn, _port, _brelative, _result)
13931 
13932 /**
13933  * Send a SetInputMode message.
13934  * Send the SetInputMode direct command on the specified connection slot.
13935  * Use \ref RemoteConnectionIdle to determine when this write request is completed.
13936  *
13937  * \param _conn The connection slot (0..4). Connections 0 through 3 are for
13938  * bluetooth connections.  Connection 4 refers to the RS485 hi-speed port.
13939  * See \ref CommConnectionConstants.
13940  * \param _port The input port to configure. See \ref NBCInputPortConstants.
13941  * \param _type The sensor type. See \ref NBCSensorTypeConstants.
13942  * \param _mode The sensor mode. See \ref NBCSensorModeConstants.
13943  * \param _result A char value indicating whether the function call succeeded or not.
13944  */
13945 #define RemoteSetInputMode(_conn, _port, _type, _mode, _result) __remoteSetInputMode(_conn, _port, _type, _mode, _result)
13946 
13947 /**
13948  * Send a SetOutputMode message.
13949  * Send the SetOutputMode direct command on the specified connection slot.
13950  * Use \ref RemoteConnectionIdle to determine when this write request is completed.
13951  *
13952  * \param _conn The connection slot (0..4). Connections 0 through 3 are for
13953  * bluetooth connections.  Connection 4 refers to the RS485 hi-speed port.
13954  * See \ref CommConnectionConstants.
13955  * \param _port The output port to configure. See \ref OutputPortConstants.
13956  * \param _speed The motor speed. (-100..100)
13957  * \param _mode The motor mode. See \ref OutModeConstants.
13958  * \param _regmode The motor regulation mode. See \ref OutRegModeConstants.
13959  * \param _turnpct The motor synchronized turn percentage. (-100..100)
13960  * \param _runstate The motor run state. See \ref OutRunStateConstants.
13961  * \param _tacholimit The motor tachometer limit.
13962  * \param _result A char value indicating whether the function call succeeded or not.
13963  */
13964 #define RemoteSetOutputState(_conn, _port, _speed, _mode, _regmode, _turnpct, _runstate, _tacholimit, _result) \
13965   __remoteSetOutputState(_conn, _port, _speed, _mode, _regmode, _turnpct, _runstate, _tacholimit, _result)
13966 
13967 #ifdef __ENHANCED_FIRMWARE
13968 
13969 /**
13970  * Send a GetOutputState message.
13971  * Send the GetOutputState direct command on the specified connection slot.
13972  *
13973  * \param _conn The connection slot (0..4). Connections 0 through 3 are for
13974  * bluetooth connections.  Connection 4 refers to the RS485 hi-speed port.
13975  * See \ref CommConnectionConstants.
13976  * \param _params The input and output parameters for the function call.
13977  * \param _result A char value indicating whether the function call succeeded or not.
13978  */
13979 #define RemoteGetOutputState(_conn, _params, _result) \
13980   compchktype _params, TOutputState \
13981   __remoteGetOutputState(_conn, _params, _result)
13982 
13983 /**
13984  * Send a GetInputValues message.
13985  * Send the GetInputValues direct command on the specified connection slot.
13986  *
13987  * \param _conn The connection slot (0..4). Connections 0 through 3 are for
13988  * bluetooth connections.  Connection 4 refers to the RS485 hi-speed port.
13989  * See \ref CommConnectionConstants.
13990  * \param _params The input and output parameters for the function call.
13991  * \param _result A char value indicating whether the function call succeeded or not.
13992  */
13993 #define RemoteGetInputValues(_conn, _params, _result) \
13994   compchktype _params, TInputValues \
13995 __remoteGetInputValues(_conn, _params, _result)
13996 
13997 /**
13998  * Send a GetBatteryLevel message.
13999  * This method sends a GetBatteryLevel direct command to the device on the specified
14000  * connection.
14001  *
14002  * \param _conn The connection slot (0..4). Connections 0 through 3 are for
14003  * bluetooth connections.  Connection 4 refers to the RS485 hi-speed port.
14004  * See \ref CommConnectionConstants.
14005  * \param _value The battery level value.
14006  * \param _result A char value indicating whether the function call succeeded or not.
14007  */
14008 #define RemoteGetBatteryLevel(_conn, _value, _result) __remoteGetBatteryLevel(_conn, _value, _result)
14009 
14010 /**
14011  * Send a LSGetStatus message.
14012  * This method sends a LSGetStatus direct command to the device on the specified
14013  * connection.
14014  *
14015  * \param _conn The connection slot (0..4). Connections 0 through 3 are for
14016  * bluetooth connections.  Connection 4 refers to the RS485 hi-speed port.
14017  * See \ref CommConnectionConstants.
14018  * \param _value The count of available bytes to read.
14019  * \param _result A char value indicating whether the function call succeeded or not.
14020  */
14021 #define RemoteLowspeedGetStatus(_conn, _value, _result) __remoteLowspeedGetStatus(_conn, _value, _result)
14022 
14023 /**
14024  * Send a LowspeedRead message.
14025  * Send the LowspeedRead direct command on the specified connection slot.
14026  *
14027  * \param _conn The connection slot (0..4). Connections 0 through 3 are for
14028  * bluetooth connections.  Connection 4 refers to the RS485 hi-speed port.
14029  * See \ref CommConnectionConstants.
14030  * \param _port The input port from which to read I2C data. See \ref NBCInputPortConstants.
14031  * \param _bread The number of bytes read.
14032  * \param _data A byte array containing the data read from the I2C device.
14033  * \param _result A char value indicating whether the function call succeeded or not.
14034  */
14035 #define RemoteLowspeedRead(_conn, _port, _bread, _data, _result) __remoteLowspeedRead(_conn, _port, _bread, _data, _result)
14036 
14037 /**
14038  * Send a GetCurrentProgramName message.
14039  * This method sends a GetCurrentProgramName direct command to the device on the specified
14040  * connection.
14041  *
14042  * \param _conn The connection slot (0..4). Connections 0 through 3 are for
14043  * bluetooth connections.  Connection 4 refers to the RS485 hi-speed port.
14044  * See \ref CommConnectionConstants.
14045  * \param _name The current program name.
14046  * \param _result A char value indicating whether the function call succeeded or not.
14047  */
14048 #define RemoteGetCurrentProgramName(_conn, _name, _result) __remoteGetCurrentProgramName(_conn, _name, _result)
14049 
14050 /**
14051  * Send a DatalogRead message.
14052  * Send the DatalogRead direct command on the specified connection slot.
14053  *
14054  * \param _conn The connection slot (0..4). Connections 0 through 3 are for
14055  * bluetooth connections.  Connection 4 refers to the RS485 hi-speed port.
14056  * See \ref CommConnectionConstants.
14057  * \param _remove Remove the datalog message from the queue after reading it (true or false).
14058  * \param _cnt The number of bytes read from the datalog.
14059  * \param _log A byte array containing the datalog contents.
14060  * \param _result A char value indicating whether the function call succeeded or not.
14061  */
14062 #define RemoteDatalogRead(_conn, _remove, _cnt, _log, _result) __remoteDatalogRead(_conn, _remove, _cnt, _log, _result)
14063 
14064 /**
14065  * Send a GetContactCount message.
14066  * This method sends a GetContactCount direct command to the device on the specified
14067  * connection.
14068  *
14069  * \param _conn The connection slot (0..4). Connections 0 through 3 are for
14070  * bluetooth connections.  Connection 4 refers to the RS485 hi-speed port.
14071  * See \ref CommConnectionConstants.
14072  * \param _cnt The number of contacts.
14073  * \param _result A char value indicating whether the function call succeeded or not.
14074  */
14075 #define RemoteGetContactCount(_conn, _cnt, _result) __remoteGetContactCount(_conn, _cnt, _result)
14076 
14077 /**
14078  * Send a GetContactName message.
14079  * Send the GetContactName direct command on the specified connection slot.
14080  *
14081  * \param _conn The connection slot (0..4). Connections 0 through 3 are for
14082  * bluetooth connections.  Connection 4 refers to the RS485 hi-speed port.
14083  * See \ref CommConnectionConstants.
14084  * \param _idx The index of the contact.
14085  * \param _name The name of the specified contact.
14086  * \param _result A char value indicating whether the function call succeeded or not.
14087  */
14088 #define RemoteGetContactName(_conn, _idx, _name, _result) __remoteGetContactName(_conn, _idx, _name, _result)
14089 
14090 /**
14091  * Send a GetConnectionCount message.
14092  * This method sends a GetConnectionCount direct command to the device on the specified
14093  * connection.
14094  *
14095  * \param _conn The connection slot (0..4). Connections 0 through 3 are for
14096  * bluetooth connections.  Connection 4 refers to the RS485 hi-speed port.
14097  * See \ref CommConnectionConstants.
14098  * \param _cnt The number of connections.
14099  * \param _result A char value indicating whether the function call succeeded or not.
14100  */
14101 #define RemoteGetConnectionCount(_conn, _cnt, _result) __remoteGetConnectionCount(_conn, _cnt, _result)
14102 
14103 /**
14104  * Send a GetConnectionName message.
14105  * Send the GetConnectionName direct command on the specified connection slot.
14106  *
14107  * \param _conn The connection slot (0..4). Connections 0 through 3 are for
14108  * bluetooth connections.  Connection 4 refers to the RS485 hi-speed port.
14109  * See \ref CommConnectionConstants.
14110  * \param _idx The index of the connection.
14111  * \param _name The name of the specified connection.
14112  * \param _result A char value indicating whether the function call succeeded or not.
14113  */
14114 #define RemoteGetConnectionName(_conn, _idx, _name, _result) __remoteGetConnectionName(_conn, _idx, _name, _result)
14115 
14116 
14117 #else
14118 
14119 /**
14120  * Send a GetOutputState message.
14121  * Send the GetOutputState direct command on the specified connection slot.
14122  * Use \ref RemoteConnectionIdle to determine when this write request is completed.
14123  *
14124  * \param _conn The connection slot (0..4). Connections 0 through 3 are for
14125  * bluetooth connections.  Connection 4 refers to the RS485 hi-speed port.
14126  * See \ref CommConnectionConstants.
14127  * \param _port The output port from which to read state information. See \ref OutputPortConstants.
14128  * \param _result A char value indicating whether the function call succeeded or not.
14129  */
14130 #define RemoteGetOutputState(_conn, _port, _result) __remoteGetOutputState(_conn, _port, _result)
14131 
14132 /**
14133  * Send a GetInputValues message.
14134  * Send the GetInputValues direct command on the specified connection slot.
14135  * Use \ref RemoteConnectionIdle to determine when this write request is completed.
14136  *
14137  * \param _conn The connection slot (0..4). Connections 0 through 3 are for
14138  * bluetooth connections.  Connection 4 refers to the RS485 hi-speed port.
14139  * See \ref CommConnectionConstants.
14140  * \param _port The input port from which to read sensor values. See \ref NBCInputPortConstants.
14141  * \param _result A char value indicating whether the function call succeeded or not.
14142  */
14143 #define RemoteGetInputValues(_conn, _port, _result) __remoteGetInputValues(_conn, _port, _result)
14144 
14145 /**
14146  * Send a GetBatteryLevel message.
14147  * This method sends a GetBatteryLevel direct command to the device on the specified
14148  * connection. Use \ref RemoteConnectionIdle to determine when this write request is
14149  * completed.
14150  *
14151  * \param _conn The connection slot (0..4). Connections 0 through 3 are for
14152  * bluetooth connections.  Connection 4 refers to the RS485 hi-speed port.
14153  * See \ref CommConnectionConstants.
14154  * \param _result A char value indicating whether the function call succeeded or not.
14155  */
14156 #define RemoteGetBatteryLevel(_conn, _result) __remoteGetBatteryLevel(_conn, _result)
14157 
14158 /**
14159  * Send a LSGetStatus message.
14160  * This method sends a LSGetStatus direct command to the device on the specified
14161  * connection. Use \ref RemoteConnectionIdle to determine when this write request is
14162  * completed.
14163  *
14164  * \param _conn The connection slot (0..4). Connections 0 through 3 are for
14165  * bluetooth connections.  Connection 4 refers to the RS485 hi-speed port.
14166  * See \ref CommConnectionConstants.
14167  * \param _result A char value indicating whether the function call succeeded or not.
14168  */
14169 #define RemoteLowspeedGetStatus(_conn, _result) __remoteLowspeedGetStatus(_conn, _result)
14170 
14171 /**
14172  * Send a LowspeedRead message.
14173  * Send the LowspeedRead direct command on the specified connection slot.
14174  * Use \ref RemoteConnectionIdle to determine when this write request is completed.
14175  *
14176  * \param _conn The connection slot (0..4). Connections 0 through 3 are for
14177  * bluetooth connections.  Connection 4 refers to the RS485 hi-speed port.
14178  * See \ref CommConnectionConstants.
14179  * \param _port The input port from which to read I2C data. See \ref NBCInputPortConstants.
14180  * \param _result A char value indicating whether the function call succeeded or not.
14181  */
14182 #define RemoteLowspeedRead(_conn, _port, _result) __remoteLowspeedRead(_conn, _port, _result)
14183 
14184 /**
14185  * Send a GetCurrentProgramName message.
14186  * This method sends a GetCurrentProgramName direct command to the device on the specified
14187  * connection. Use \ref RemoteConnectionIdle to determine when this write request is
14188  * completed.
14189  *
14190  * \param _conn The connection slot (0..4). Connections 0 through 3 are for
14191  * bluetooth connections.  Connection 4 refers to the RS485 hi-speed port.
14192  * See \ref CommConnectionConstants.
14193  * \param _result A char value indicating whether the function call succeeded or not.
14194  */
14195 #define RemoteGetCurrentProgramName(_conn, _result) __remoteGetCurrentProgramName(_conn, _result)
14196 
14197 /**
14198  * Send a DatalogRead message.
14199  * Send the DatalogRead direct command on the specified connection slot.
14200  * Use \ref RemoteConnectionIdle to determine when this write request is completed.
14201  *
14202  * \param _conn The connection slot (0..4). Connections 0 through 3 are for
14203  * bluetooth connections.  Connection 4 refers to the RS485 hi-speed port.
14204  * See \ref CommConnectionConstants.
14205  * \param _remove Remove the datalog message from the queue after reading it (true or false).
14206  * \param _result A char value indicating whether the function call succeeded or not.
14207  */
14208 #define RemoteDatalogRead(_conn, _remove, _result) __remoteDatalogRead(_conn, _remove, _result)
14209 
14210 /**
14211  * Send a GetContactCount message.
14212  * This method sends a GetContactCount direct command to the device on the specified
14213  * connection. Use \ref RemoteConnectionIdle to determine when this write request is
14214  * completed.
14215  *
14216  * \param _conn The connection slot (0..4). Connections 0 through 3 are for
14217  * bluetooth connections.  Connection 4 refers to the RS485 hi-speed port.
14218  * See \ref CommConnectionConstants.
14219  * \param _result A char value indicating whether the function call succeeded or not.
14220  */
14221 #define RemoteGetContactCount(_conn, _result) __remoteGetContactCount(_conn, _result)
14222 
14223 /**
14224  * Send a GetContactName message.
14225  * Send the GetContactName direct command on the specified connection slot.
14226  * Use \ref RemoteConnectionIdle to determine when this write request is completed.
14227  *
14228  * \param _conn The connection slot (0..4). Connections 0 through 3 are for
14229  * bluetooth connections.  Connection 4 refers to the RS485 hi-speed port.
14230  * See \ref CommConnectionConstants.
14231  * \param _idx The index of the contact.
14232  * \param _result A char value indicating whether the function call succeeded or not.
14233  */
14234 #define RemoteGetContactName(_conn, _idx, _result) __remoteGetContactName(_conn, _idx, _result)
14235 
14236 /**
14237  * Send a GetConnectionCount message.
14238  * This method sends a GetConnectionCount direct command to the device on the specified
14239  * connection. Use \ref RemoteConnectionIdle to determine when this write
14240  * request is completed.
14241  *
14242  * \param _conn The connection slot (0..4). Connections 0 through 3 are for
14243  * bluetooth connections.  Connection 4 refers to the RS485 hi-speed port.
14244  * See \ref CommConnectionConstants.
14245  * \param _result A char value indicating whether the function call succeeded or not.
14246  */
14247 #define RemoteGetConnectionCount(_conn, _result) __remoteGetConnectionCount(_conn, _result)
14248 
14249 /**
14250  * Send a GetConnectionName message.
14251  * Send the GetConnectionName direct command on the specified connection slot.
14252  * Use \ref RemoteConnectionIdle to determine when this write request is completed.
14253  *
14254  * \param _conn The connection slot (0..4). Connections 0 through 3 are for
14255  * bluetooth connections.  Connection 4 refers to the RS485 hi-speed port.
14256  * See \ref CommConnectionConstants.
14257  * \param _idx The index of the connection.
14258  * \param _result A char value indicating whether the function call succeeded or not.
14259  */
14260 #define RemoteGetConnectionName(_conn, _idx, _result) __remoteGetConnectionName(_conn, _idx, _result)
14261 
14262 
14263 #endif
14264 
14265 /**
14266  * Send a ResetTachoCount message.
14267  * Send the ResetTachoCount direct command on the specified connection slot.
14268  * Use \ref RemoteConnectionIdle to determine when this write request is completed.
14269  *
14270  * \param _conn The connection slot (0..4). Connections 0 through 3 are for
14271  * bluetooth connections.  Connection 4 refers to the RS485 hi-speed port.
14272  * See \ref CommConnectionConstants.
14273  * \param _port The output port to reset the tachometer count on. See \ref OutputPortConstants.
14274  * \param _result A char value indicating whether the function call succeeded or not.
14275  */
14276 #define RemoteResetTachoCount(_conn, _port, _result) __remoteResetTachoCount(_conn, _port, _result)
14277 
14278 /**
14279  * Send a GetProperty message.
14280  * Send the GetProperty direct command on the specified connection slot.
14281  * Use \ref RemoteConnectionIdle to determine when this write request is completed.
14282  *
14283  * \param _conn The connection slot (0..4). Connections 0 through 3 are for
14284  * bluetooth connections.  Connection 4 refers to the RS485 hi-speed port.
14285  * See \ref CommConnectionConstants.
14286  * \param _property The property to read. See \ref RCPropertyConstants.
14287  * \param _result A char value indicating whether the function call succeeded or not.
14288  */
14289 #define RemoteGetProperty(_conn, _property, _result) __remoteGetProperty(_conn, _property, _result)
14290 
14291 /**
14292  * Send a DatalogSetTimes message.
14293  * Send the DatalogSetTimes direct command on the specified connection slot.
14294  * Use \ref RemoteConnectionIdle to determine when this write request is completed.
14295  *
14296  * \param _conn The connection slot (0..4). Connections 0 through 3 are for
14297  * bluetooth connections.  Connection 4 refers to the RS485 hi-speed port.
14298  * See \ref CommConnectionConstants.
14299  * \param _synctime The datalog sync time.
14300  * \param _result A char value indicating whether the function call succeeded or not.
14301  */
14302 #define RemoteDatalogSetTimes(_conn, _synctime, _result) __remoteDatalogSetTimes(_conn, _synctime, _result)
14303 
14304 /**
14305  * Send a SetProperty message.
14306  * Send the SetProperty direct command on the specified connection slot.
14307  * Use \ref RemoteConnectionIdle to determine when this write request is completed.
14308  *
14309  * \param _conn The connection slot (0..4). Connections 0 through 3 are for
14310  * bluetooth connections.  Connection 4 refers to the RS485 hi-speed port.
14311  * See \ref CommConnectionConstants.
14312  * \param _prop The property to set. See \ref RCPropertyConstants.
14313  * \param _value The new property value.
14314  * \param _result A char value indicating whether the function call succeeded or not.
14315  */
14316 #define RemoteSetProperty(_conn, _prop, _value, _result) __remoteSetProperty(_conn, _prop, _value, _result)
14317 
14318 /**
14319  * Send a LowspeedWrite message.
14320  * Send the LowspeedWrite direct command on the specified connection slot.
14321  * Use \ref RemoteConnectionIdle to determine when this write request is completed.
14322  *
14323  * \param _conn The connection slot (0..4). Connections 0 through 3 are for
14324  * bluetooth connections.  Connection 4 refers to the RS485 hi-speed port.
14325  * See \ref CommConnectionConstants.
14326  * \param _port The I2C port. See \ref NBCInputPortConstants.
14327  * \param _txlen The number of bytes you are writing to the I2C device.
14328  * \param _rxlen The number of bytes want to read from the I2C device.
14329  * \param _data A byte array containing the data you are writing to the device.
14330  * \param _result A char value indicating whether the function call succeeded or not.
14331  */
14332 #define RemoteLowspeedWrite(_conn, _port, _txlen, _rxlen, _data, _result) __remoteLowspeedWrite(_conn, _port, _txlen, _rxlen, _data, _result)
14333 
14334 
14335 /** @} */ // end of CommModuleDCFunctions group
14336 
14337 /** @defgroup CommModuleSCFunctions System Command functions
14338  * Functions for sending system commands to another NXT.
14339  * @{
14340  */
14341 
14342 #ifdef __ENHANCED_FIRMWARE
14343 
14344 /**
14345  * Send an OpenRead message.
14346  * Send the OpenRead system command on the specified connection slot.
14347  *
14348  * \warning This function requires the enhanced NBC/NXC firmware version 1.28+.
14349  *
14350  * \param _conn The connection slot (0..4). Connections 0 through 3 are for
14351  * bluetooth connections.  Connection 4 refers to the RS485 hi-speed port.
14352  * See \ref CommConnectionConstants.
14353  * \param _filename The name of the file to open for reading.
14354  * \param _handle The handle of the file.
14355  * \param _size The size of the file.
14356  * \param _result A char value indicating whether the function call succeeded or not.
14357  */
14358 #define RemoteOpenRead(_conn, _filename, _handle, _size, _result) __remoteOpenRead(_conn, _filename, _handle, _size, _result)
14359 
14360 /**
14361  * Send an OpenAppendData message.
14362  * Send the OpenAppendData system command on the specified connection slot.
14363  *
14364  * \warning This function requires the enhanced NBC/NXC firmware version 1.28+.
14365  *
14366  * \param _conn The connection slot (0..4). Connections 0 through 3 are for
14367  * bluetooth connections.  Connection 4 refers to the RS485 hi-speed port.
14368  * See \ref CommConnectionConstants.
14369  * \param _filename The name of the file to open for appending.
14370  * \param _handle The handle of the file.
14371  * \param _size The size of the file.
14372  * \param _result A char value indicating whether the function call succeeded or not.
14373  */
14374 #define RemoteOpenAppendData(_conn, _filename, _handle, _size, _result) __remoteOpenAppendData(_conn, _filename, _handle, _size, _result)
14375 
14376 /**
14377  * Send a DeleteFile message.
14378  * Send the DeleteFile system command on the specified connection slot.
14379  *
14380  * \warning This function requires the enhanced NBC/NXC firmware version 1.28+.
14381  *
14382  * \param _conn The connection slot (0..4). Connections 0 through 3 are for
14383  * bluetooth connections.  Connection 4 refers to the RS485 hi-speed port.
14384  * See \ref CommConnectionConstants.
14385  * \param _filename The name of the program to delete.
14386  * \param _result A char value indicating whether the function call succeeded or not.
14387  */
14388 #define RemoteDeleteFile(_conn, _filename, _result) __remoteDeleteFile(_conn, _filename, _result)
14389 
14390 /**
14391  * Send a FindFirstFile message.
14392  * Send the FindFirstFile system command on the specified connection slot.
14393  *
14394  * \warning This function requires the enhanced NBC/NXC firmware version 1.28+.
14395  *
14396  * \param _conn The connection slot (0..4). Connections 0 through 3 are for
14397  * bluetooth connections.  Connection 4 refers to the RS485 hi-speed port.
14398  * See \ref CommConnectionConstants.
14399  * \param _mask The filename mask for the files you want to find.
14400  * \param _handle The handle of the found file.
14401  * \param _name The name of the found file.
14402  * \param _size The size of the found file.
14403  * \param _result A char value indicating whether the function call succeeded or not.
14404  */
14405 #define RemoteFindFirstFile(_conn, _mask, _handle, _name, _size, _result) __remoteFindFirstFile(_conn, _mask, _handle, _name, _size, _result)
14406 
14407 /**
14408  * Send a GetFirmwareVersion message.
14409  * This method sends a GetFirmwareVersion system command to the device on the specified
14410  * connection.
14411  *
14412  * \warning This function requires the enhanced NBC/NXC firmware version 1.28+.
14413  *
14414  * \param _conn The connection slot (0..4). Connections 0 through 3 are for
14415  * bluetooth connections.  Connection 4 refers to the RS485 hi-speed port.
14416  * See \ref CommConnectionConstants.
14417  * \param _pmin The protocol minor version byte.
14418  * \param _pmaj The protocol major version byte.
14419  * \param _fmin The firmware minor version byte.
14420  * \param _fmaj The firmware major version byte.
14421  * \param _result A char value indicating whether the function call succeeded or not.
14422  */
14423 #define RemoteGetFirmwareVersion(_conn, _pmin, _pmaj, _fmin, _fmaj, _result) __remoteGetFirmwareVersion(_conn, _pmin, _pmaj, _fmin, _fmaj, _result)
14424 
14425 /**
14426  * Send a GetBluetoothAddress message.
14427  * This method sends a GetBluetoothAddress system command to the device on the specified
14428  * connection.
14429  *
14430  * \warning This function requires the enhanced NBC/NXC firmware version 1.28+.
14431  *
14432  * \param _conn The connection slot (0..4). Connections 0 through 3 are for
14433  * bluetooth connections.  Connection 4 refers to the RS485 hi-speed port.
14434  * See \ref CommConnectionConstants.
14435  * \param _btaddr The bluetooth address of the remote device.
14436  * \param _result A char value indicating whether the function call succeeded or not.
14437  */
14438 #define RemoteGetBluetoothAddress(_conn, _btaddr, _result) __remoteGetBluetoothAddress(_conn, _btaddr, _result)
14439 
14440 /**
14441  * Send a GetDeviceInfo message.
14442  * This method sends a GetDeviceInfo system command to the device on the specified
14443  * connection.
14444  *
14445  * \warning This function requires the enhanced NBC/NXC firmware version 1.28+.
14446  *
14447  * \param _conn The connection slot (0..4). Connections 0 through 3 are for
14448  * bluetooth connections.  Connection 4 refers to the RS485 hi-speed port.
14449  * See \ref CommConnectionConstants.
14450  * \param _name The name of the remote device.
14451  * \param _btaddr The bluetooth address of the remote device.
14452  * \param _btsignal The signal strength of each connection on the remote device.
14453  * \param _freemem The number of bytes of free flash memory on the remote device.
14454  * \param _result A char value indicating whether the function call succeeded or not.
14455  */
14456 #define RemoteGetDeviceInfo(_conn, _name, _btaddr, _btsignal, _freemem, _result) __remoteGetDeviceInfo(_conn, _name, _btaddr, _btsignal, _freemem, _result)
14457 
14458 /**
14459  * Send a DeleteUserFlash message.
14460  * This method sends a DeleteUserFlash system command to the device on the specified
14461  * connection.
14462  *
14463  * \warning This function requires the enhanced NBC/NXC firmware version 1.28+.
14464  *
14465  * \param _conn The connection slot (0..4). Connections 0 through 3 are for
14466  * bluetooth connections.  Connection 4 refers to the RS485 hi-speed port.
14467  * See \ref CommConnectionConstants.
14468  * \param _result A char value indicating whether the function call succeeded or not.
14469  */
14470 #define RemoteDeleteUserFlash(_conn, _result) __remoteDeleteUserFlash(_conn, _result)
14471 
14472 /**
14473  * Send an OpenWrite message.
14474  * Send the OpenWrite system command on the specified connection slot.
14475  *
14476  * \warning This function requires the enhanced NBC/NXC firmware version 1.28+.
14477  *
14478  * \param _conn The connection slot (0..4). Connections 0 through 3 are for
14479  * bluetooth connections.  Connection 4 refers to the RS485 hi-speed port.
14480  * See \ref CommConnectionConstants.
14481  * \param _filename The name of the program to open for writing (i.e., create the file).
14482  * \param _size The size for the new file.
14483  * \param _result A char value indicating whether the function call succeeded or not.
14484  */
14485 #define RemoteOpenWrite(_conn, _filename, _size, _result) __remoteOpenWrite(_conn, _filename, _size, _result)
14486 
14487 /**
14488  * Send an OpenWriteLinear message.
14489  * Send the OpenWriteLinear system command on the specified connection slot.
14490  *
14491  * \warning This function requires the enhanced NBC/NXC firmware version 1.28+.
14492  *
14493  * \param _conn The connection slot (0..4). Connections 0 through 3 are for
14494  * bluetooth connections.  Connection 4 refers to the RS485 hi-speed port.
14495  * See \ref CommConnectionConstants.
14496  * \param _filename The name of the program to open for writing (i.e., create the file).
14497  * \param _size The size for the new file.
14498  * \param _result A char value indicating whether the function call succeeded or not.
14499  */
14500 #define RemoteOpenWriteLinear(_conn, _filename, _size, _result) __remoteOpenWriteLinear(_conn, _filename, _size, _result)
14501 
14502 /**
14503  * Send an OpenWriteData message.
14504  * Send the OpenWriteData system command on the specified connection slot.
14505  *
14506  * \warning This function requires the enhanced NBC/NXC firmware version 1.28+.
14507  *
14508  * \param _conn The connection slot (0..4). Connections 0 through 3 are for
14509  * bluetooth connections.  Connection 4 refers to the RS485 hi-speed port.
14510  * See \ref CommConnectionConstants.
14511  * \param _filename The name of the program to open for writing (i.e., create the file).
14512  * \param _size The size for the new file.
14513  * \param _result A char value indicating whether the function call succeeded or not.
14514  */
14515 #define RemoteOpenWriteData(_conn, _filename, _size, _result) __remoteOpenWriteData(_conn, _filename, _size, _result)
14516 
14517 /**
14518  * Send a CloseFile message.
14519  * Send the CloseFile system command on the specified connection slot.
14520  *
14521  * \warning This function requires the enhanced NBC/NXC firmware version 1.28+.
14522  *
14523  * \param _conn The connection slot (0..4). Connections 0 through 3 are for
14524  * bluetooth connections.  Connection 4 refers to the RS485 hi-speed port.
14525  * See \ref CommConnectionConstants.
14526  * \param _handle The handle of the file to close.
14527  * \param _result A char value indicating whether the function call succeeded or not.
14528  */
14529 #define RemoteCloseFile(_conn, _handle, _result) __remoteCloseFile(_conn, _handle, _result)
14530 
14531 /**
14532  * Send a FindNextFile message.
14533  * Send the FindNextFile system command on the specified connection slot.
14534  *
14535  * \warning This function requires the enhanced NBC/NXC firmware version 1.28+.
14536  *
14537  * \param _conn The connection slot (0..4). Connections 0 through 3 are for
14538  * bluetooth connections.  Connection 4 refers to the RS485 hi-speed port.
14539  * See \ref CommConnectionConstants.
14540  * \param _handle The handle returned by the last \ref FindFirstFile or FindNextFile call.
14541  * \param _result A char value indicating whether the function call succeeded or not.
14542  */
14543 #define RemoteFindNextFile(_conn, _handle, _result) __remoteFindNextFile(_conn, _handle, _result)
14544 
14545 /**
14546  * Send a PollCommandLength message.
14547  * Send the PollCommandLength system command on the specified connection slot.
14548  *
14549  * \warning This function requires the enhanced NBC/NXC firmware version 1.28+.
14550  *
14551  * \param _conn The connection slot (0..4). Connections 0 through 3 are for
14552  * bluetooth connections.  Connection 4 refers to the RS485 hi-speed port.
14553  * See \ref CommConnectionConstants.
14554  * \param _bufnum The poll buffer you want to query (0=USBPoll, 1=HiSpeed).
14555  * \param _result A char value indicating whether the function call succeeded or not.
14556  */
14557 #define RemotePollCommandLength(_conn, _bufnum, _result) __remotePollCommandLength(_conn, _bufnum, _result)
14558 
14559 /**
14560  * Send a Write message.
14561  * Send the Write system command on the specified connection slot.
14562  *
14563  * \warning This function requires the enhanced NBC/NXC firmware version 1.28+.
14564  *
14565  * \param _conn The connection slot (0..4). Connections 0 through 3 are for
14566  * bluetooth connections.  Connection 4 refers to the RS485 hi-speed port.
14567  * See \ref CommConnectionConstants.
14568  * \param _handle The handle of the file you are writing to.
14569  * \param _data A byte array containing the data you are writing.
14570  * \param _result A char value indicating whether the function call succeeded or not.
14571  */
14572 #define RemoteWrite(_conn, _handle, _data, _result) __remoteWrite(_conn, _handle, _data, _result)
14573 
14574 /**
14575  * Send a Read message.
14576  * Send the Read system command on the specified connection slot.
14577  *
14578  * \warning This function requires the enhanced NBC/NXC firmware version 1.28+.
14579  *
14580  * \param _conn The connection slot (0..4). Connections 0 through 3 are for
14581  * bluetooth connections.  Connection 4 refers to the RS485 hi-speed port.
14582  * See \ref CommConnectionConstants.
14583  * \param _handle The handle of the file you are reading from.
14584  * \param _numbytes The number of bytes you want to read.
14585  * \param _result A char value indicating whether the function call succeeded or not.
14586  */
14587 #define RemoteRead(_conn, _handle, _numbytes, _result) __remoteRead(_conn, _handle, _numbytes, _result)
14588 
14589 /**
14590  * Send an IOMapRead message.
14591  * Send the IOMapRead system command on the specified connection slot.
14592  *
14593  * \warning This function requires the enhanced NBC/NXC firmware version 1.28+.
14594  *
14595  * \param _conn The connection slot (0..4). Connections 0 through 3 are for
14596  * bluetooth connections.  Connection 4 refers to the RS485 hi-speed port.
14597  * See \ref CommConnectionConstants.
14598  * \param _id The ID of the module from which to read data.
14599  * \param _offset The offset into the IOMap structure from which to read.
14600  * \param _numbytes The number of bytes of data to read.
14601  * \param _result A char value indicating whether the function call succeeded or not.
14602  */
14603 #define RemoteIOMapRead(_conn, _id, _offset, _numbytes, _result) __remoteIOMapRead(_conn, _id, _offset, _numbytes, _result)
14604 
14605 /**
14606  * Send a PollCommand message.
14607  * Send the PollCommand system command on the specified connection slot to
14608  * write the data provided.
14609  *
14610  * \warning This function requires the enhanced NBC/NXC firmware version 1.28+.
14611  *
14612  * \param _conn The connection slot (0..4). Connections 0 through 3 are for
14613  * bluetooth connections.  Connection 4 refers to the RS485 hi-speed port.
14614  * See \ref CommConnectionConstants.
14615  * \param _bufnum The buffer from which to read data (0=USBPoll, 1=HiSpeed).
14616  * \param _len The number of bytes to read.
14617  * \param _result A char value indicating whether the function call succeeded or not.
14618  */
14619 #define RemotePollCommand(_conn, _bufnum, _len, _result) __remotePollCommand(_conn, _bufnum, _len, _result)
14620 
14621 /**
14622  * Send a RenameFile message.
14623  * Send the RenameFile system command on the specified connection slot to
14624  * write the data provided.
14625  * Use \ref RemoteConnectionIdle to determine when this write request is completed.
14626  *
14627  * \warning This function requires the enhanced NBC/NXC firmware version 1.28+.
14628  *
14629  * \param _conn The connection slot (0..4). Connections 0 through 3 are for
14630  * bluetooth connections.  Connection 4 refers to the RS485 hi-speed port.
14631  * See \ref CommConnectionConstants.
14632  * \param _oldname The old filename.
14633  * \param _newname The new filename.
14634  * \param _result A char value indicating whether the function call succeeded or not.
14635  */
14636 #define RemoteRenameFile(_conn, _oldname, _newname, _result) __remoteRenameFile(_conn, _oldname, _newname, _result)
14637 
14638 #else
14639 
14640 /**
14641  * Send an OpenRead message.
14642  * Send the OpenRead system command on the specified connection slot.
14643  * Use \ref RemoteConnectionIdle to determine when this write request is completed.
14644  *
14645  * \param _conn The connection slot (0..4). Connections 0 through 3 are for
14646  * bluetooth connections.  Connection 4 refers to the RS485 hi-speed port.
14647  * See \ref CommConnectionConstants.
14648  * \param _filename The name of the program to open for reading.
14649  * \param _result A char value indicating whether the function call succeeded or not.
14650  */
14651 #define RemoteOpenRead(_conn, _filename, _result) __remoteOpenRead(_conn, _filename, _result)
14652 
14653 /**
14654  * Send an OpenAppendData message.
14655  * Send the OpenAppendData system command on the specified connection slot.
14656  * Use \ref RemoteConnectionIdle to determine when this write request is completed.
14657  *
14658  * \param _conn The connection slot (0..4). Connections 0 through 3 are for
14659  * bluetooth connections.  Connection 4 refers to the RS485 hi-speed port.
14660  * See \ref CommConnectionConstants.
14661  * \param _filename The name of the program to open for appending.
14662  * \param _result A char value indicating whether the function call succeeded or not.
14663  */
14664 #define RemoteOpenAppendData(_conn, _filename, _result) __remoteOpenAppendData(_conn, _filename, _result)
14665 
14666 /**
14667  * Send a DeleteFile message.
14668  * Send the DeleteFile system command on the specified connection slot.
14669  * Use \ref RemoteConnectionIdle to determine when this write request is completed.
14670  *
14671  * \param _conn The connection slot (0..4). Connections 0 through 3 are for
14672  * bluetooth connections.  Connection 4 refers to the RS485 hi-speed port.
14673  * See \ref CommConnectionConstants.
14674  * \param _filename The name of the program to delete.
14675  * \param _result A char value indicating whether the function call succeeded or not.
14676  */
14677 #define RemoteDeleteFile(_conn, _filename, _result) __remoteDeleteFile(_conn, _filename, _result)
14678 
14679 /**
14680  * Send a FindFirstFile message.
14681  * Send the FindFirstFile system command on the specified connection slot.
14682  * Use \ref RemoteConnectionIdle to determine when this write request is completed.
14683  *
14684  * \param _conn The connection slot (0..4). Connections 0 through 3 are for
14685  * bluetooth connections.  Connection 4 refers to the RS485 hi-speed port.
14686  * See \ref CommConnectionConstants.
14687  * \param _mask The filename mask for the files you want to find.
14688  * \param _result A char value indicating whether the function call succeeded or not.
14689  */
14690 #define RemoteFindFirstFile(_conn, _mask, _result) __remoteFindFirstFile(_conn, _mask, _result)
14691 
14692 /**
14693  * Send a GetFirmwareVersion message.
14694  * This method sends a GetFirmwareVersion system command to the device on the specified
14695  * connection. Use \ref RemoteConnectionIdle to determine when this write request is
14696  * completed.
14697  *
14698  * \param _conn The connection slot (0..4). Connections 0 through 3 are for
14699  * bluetooth connections.  Connection 4 refers to the RS485 hi-speed port.
14700  * See \ref CommConnectionConstants.
14701  * \param _result A char value indicating whether the function call succeeded or not.
14702  */
14703 #define RemoteGetFirmwareVersion(_conn, _result) __connectionSCDCWrite(_conn, __SCGetFirmwareVerPacket, _result)
14704 
14705 /**
14706  * Send a GetBluetoothAddress message.
14707  * This method sends a GetBluetoothAddress system command to the device on the specified
14708  * connection. Use \ref RemoteConnectionIdle to determine when this write request is
14709  * completed.
14710  *
14711  * \param _conn The connection slot (0..4). Connections 0 through 3 are for
14712  * bluetooth connections.  Connection 4 refers to the RS485 hi-speed port.
14713  * See \ref CommConnectionConstants.
14714  * \param _result A char value indicating whether the function call succeeded or not.
14715  */
14716 #define RemoteGetBluetoothAddress(_conn, _result) __connectionSCDCWrite(_conn, __SCBTGetAddressPacket, _result)
14717 
14718 /**
14719  * Send a GetDeviceInfo message.
14720  * This method sends a GetDeviceInfo system command to the device on the specified
14721  * connection. Use \ref RemoteConnectionIdle to determine when this write request is
14722  * completed.
14723  *
14724  * \param _conn The connection slot (0..4). Connections 0 through 3 are for
14725  * bluetooth connections.  Connection 4 refers to the RS485 hi-speed port.
14726  * See \ref CommConnectionConstants.
14727  * \param _result A char value indicating whether the function call succeeded or not.
14728  */
14729 #define RemoteGetDeviceInfo(_conn, _result) __connectionSCDCWrite(_conn, __SCGetDeviceInfoPacket, _result)
14730 
14731 /**
14732  * Send a DeleteUserFlash message.
14733  * This method sends a DeleteUserFlash system command to the device on the specified
14734  * connection. Use \ref RemoteConnectionIdle to determine when this write request is
14735  * completed.
14736  *
14737  * \param _conn The connection slot (0..4). Connections 0 through 3 are for
14738  * bluetooth connections.  Connection 4 refers to the RS485 hi-speed port.
14739  * See \ref CommConnectionConstants.
14740  * \param _result A char value indicating whether the function call succeeded or not.
14741  */
14742 #define RemoteDeleteUserFlash(_conn, _result) __connectionSCDCWrite(_conn, __SCDeleteUserFlashPacket, _result)
14743 
14744 /**
14745  * Send an OpenWrite message.
14746  * Send the OpenWrite system command on the specified connection slot.
14747  * Use \ref RemoteConnectionIdle to determine when this write request is completed.
14748  *
14749  * \param _conn The connection slot (0..4). Connections 0 through 3 are for
14750  * bluetooth connections.  Connection 4 refers to the RS485 hi-speed port.
14751  * See \ref CommConnectionConstants.
14752  * \param _filename The name of the program to open for writing (i.e., create the file).
14753  * \param _size The size for the new file.
14754  * \param _result A char value indicating whether the function call succeeded or not.
14755  */
14756 #define RemoteOpenWrite(_conn, _filename, _size, _result) __remoteOpenWrite(_conn, _filename, _size, _result)
14757 
14758 /**
14759  * Send an OpenWriteLinear message.
14760  * Send the OpenWriteLinear system command on the specified connection slot.
14761  * Use \ref RemoteConnectionIdle to determine when this write request is completed.
14762  *
14763  * \param _conn The connection slot (0..4). Connections 0 through 3 are for
14764  * bluetooth connections.  Connection 4 refers to the RS485 hi-speed port.
14765  * See \ref CommConnectionConstants.
14766  * \param _filename The name of the program to open for writing (i.e., create the file).
14767  * \param _size The size for the new file.
14768  * \param _result A char value indicating whether the function call succeeded or not.
14769  */
14770 #define RemoteOpenWriteLinear(_conn, _filename, _size, _result) __remoteOpenWriteLinear(_conn, _filename, _size, _result)
14771 
14772 /**
14773  * Send an OpenWriteData message.
14774  * Send the OpenWriteData system command on the specified connection slot.
14775  * Use \ref RemoteConnectionIdle to determine when this write request is completed.
14776  *
14777  * \param _conn The connection slot (0..4). Connections 0 through 3 are for
14778  * bluetooth connections.  Connection 4 refers to the RS485 hi-speed port.
14779  * See \ref CommConnectionConstants.
14780  * \param _filename The name of the program to open for writing (i.e., create the file).
14781  * \param _size The size for the new file.
14782  * \param _result A char value indicating whether the function call succeeded or not.
14783  */
14784 #define RemoteOpenWriteData(_conn, _filename, _size, _result) __remoteOpenWriteData(_conn, _filename, _size, _result)
14785 
14786 /**
14787  * Send a CloseFile message.
14788  * Send the CloseFile system command on the specified connection slot.
14789  * Use \ref RemoteConnectionIdle to determine when this write request is completed.
14790  *
14791  * \param _conn The connection slot (0..4). Connections 0 through 3 are for
14792  * bluetooth connections.  Connection 4 refers to the RS485 hi-speed port.
14793  * See \ref CommConnectionConstants.
14794  * \param _handle The handle of the file to close.
14795  * \param _result A char value indicating whether the function call succeeded or not.
14796  */
14797 #define RemoteCloseFile(_conn, _handle, _result) __remoteCloseFile(_conn, _handle, _result)
14798 
14799 /**
14800  * Send a FindNextFile message.
14801  * Send the FindNextFile system command on the specified connection slot.
14802  * Use \ref RemoteConnectionIdle to determine when this write request is completed.
14803  *
14804  * \param _conn The connection slot (0..4). Connections 0 through 3 are for
14805  * bluetooth connections.  Connection 4 refers to the RS485 hi-speed port.
14806  * See \ref CommConnectionConstants.
14807  * \param _handle The handle returned by the last \ref FindFirstFile or FindNextFile call.
14808  * \param _result A char value indicating whether the function call succeeded or not.
14809  */
14810 #define RemoteFindNextFile(_conn, _handle, _result) __remoteFindNextFile(_conn, _handle, _result)
14811 
14812 /**
14813  * Send a PollCommandLength message.
14814  * Send the PollCommandLength system command on the specified connection slot.
14815  * Use \ref RemoteConnectionIdle to determine when this write request is completed.
14816  *
14817  * \param _conn The connection slot (0..4). Connections 0 through 3 are for
14818  * bluetooth connections.  Connection 4 refers to the RS485 hi-speed port.
14819  * See \ref CommConnectionConstants.
14820  * \param _bufnum The poll buffer you want to query (0=USBPoll, 1=HiSpeed).
14821  * \param _result A char value indicating whether the function call succeeded or not.
14822  */
14823 #define RemotePollCommandLength(_conn, _bufnum, _result) __remotePollCommandLength(_conn, _bufnum, _result)
14824 
14825 /**
14826  * Send a Write message.
14827  * Send the Write system command on the specified connection slot.
14828  * Use \ref RemoteConnectionIdle to determine when this write request is completed.
14829  *
14830  * \param _conn The connection slot (0..4). Connections 0 through 3 are for
14831  * bluetooth connections.  Connection 4 refers to the RS485 hi-speed port.
14832  * See \ref CommConnectionConstants.
14833  * \param _handle The handle of the file you are writing to.
14834  * \param _data A byte array containing the data you are writing.
14835  * \param _result A char value indicating whether the function call succeeded or not.
14836  */
14837 #define RemoteWrite(_conn, _handle, _data, _result) __remoteWrite(_conn, _handle, _data, _result)
14838 
14839 /**
14840  * Send a Read message.
14841  * Send the Read system command on the specified connection slot.
14842  * Use \ref RemoteConnectionIdle to determine when this write request is completed.
14843  *
14844  * \param _conn The connection slot (0..4). Connections 0 through 3 are for
14845  * bluetooth connections.  Connection 4 refers to the RS485 hi-speed port.
14846  * See \ref CommConnectionConstants.
14847  * \param _handle The handle of the file you are reading from.
14848  * \param _numbytes The number of bytes you want to read.
14849  * \param _result A char value indicating whether the function call succeeded or not.
14850  */
14851 #define RemoteRead(_conn, _handle, _numbytes, _result) __remoteRead(_conn, _handle, _numbytes, _result)
14852 
14853 /**
14854  * Send an IOMapRead message.
14855  * Send the IOMapRead system command on the specified connection slot.
14856  * Use \ref RemoteConnectionIdle to determine when this write request is completed.
14857  *
14858  * \param _conn The connection slot (0..4). Connections 0 through 3 are for
14859  * bluetooth connections.  Connection 4 refers to the RS485 hi-speed port.
14860  * See \ref CommConnectionConstants.
14861  * \param _id The ID of the module from which to read data.
14862  * \param _offset The offset into the IOMap structure from which to read.
14863  * \param _numbytes The number of bytes of data to read.
14864  * \param _result A char value indicating whether the function call succeeded or not.
14865  */
14866 #define RemoteIOMapRead(_conn, _id, _offset, _numbytes, _result) __remoteIOMapRead(_conn, _id, _offset, _numbytes, _result)
14867 
14868 /**
14869  * Send a PollCommand message.
14870  * Send the PollCommand system command on the specified connection slot to
14871  * write the data provided.
14872  * Use \ref RemoteConnectionIdle to determine when this write request is completed.
14873  *
14874  * \param _conn The connection slot (0..4). Connections 0 through 3 are for
14875  * bluetooth connections.  Connection 4 refers to the RS485 hi-speed port.
14876  * See \ref CommConnectionConstants.
14877  * \param _bufnum The buffer from which to read data (0=USBPoll, 1=HiSpeed).
14878  * \param _len The number of bytes to read.
14879  * \param _result A char value indicating whether the function call succeeded or not.
14880  */
14881 #define RemotePollCommand(_conn, _bufnum, _len, _result) __remotePollCommand(_conn, _bufnum, _len, _result)
14882 
14883 #endif
14884 
14885 /**
14886  * Send a BluetoothFactoryReset message.
14887  * This method sends a BluetoothFactoryReset system command to the device on the specified
14888  * connection. Use \ref RemoteConnectionIdle to determine when this write request is
14889  * completed.
14890  *
14891  * \param _conn The connection slot (0..4). Connections 0 through 3 are for
14892  * bluetooth connections.  Connection 4 refers to the RS485 hi-speed port.
14893  * See \ref CommConnectionConstants.
14894  * \param _result A char value indicating whether the function call succeeded or not.
14895  */
14896 #define RemoteBluetoothFactoryReset(_conn, _result) __connectionSCDCWrite(_conn, __SCBTFactoryResetPacket, _result)
14897 
14898 /**
14899  * Send an IOMapWrite value message.
14900  * Send the IOMapWrite system command on the specified connection slot to
14901  * write the value provided.
14902  * Use \ref RemoteConnectionIdle to determine when this write request is completed.
14903  *
14904  * \param _conn The connection slot (0..4). Connections 0 through 3 are for
14905  * bluetooth connections.  Connection 4 refers to the RS485 hi-speed port.
14906  * See \ref CommConnectionConstants.
14907  * \param _id The ID of the module to which to write data.
14908  * \param _offset The offset into the IOMap structure to which to write.
14909  * \param _value A scalar variable containing the value you are writing to the IOMap structure.
14910  * \param _result A char value indicating whether the function call succeeded or not.
14911  */
14912 #define RemoteIOMapWriteValue(_conn, _id, _offset, _value, _result) __remoteIOMapWriteValue(_conn, _id, _offset, _value, _result)
14913 
14914 /**
14915  * Send an IOMapWrite bytes message.
14916  * Send the IOMapWrite system command on the specified connection slot to
14917  * write the data provided.
14918  * Use \ref RemoteConnectionIdle to determine when this write request is completed.
14919  *
14920  * \param _conn The connection slot (0..4). Connections 0 through 3 are for
14921  * bluetooth connections.  Connection 4 refers to the RS485 hi-speed port.
14922  * See \ref CommConnectionConstants.
14923  * \param _id The ID of the module to which to write data.
14924  * \param _offset The offset into the IOMap structure to which to write.
14925  * \param _data A byte array containing the data you are writing to the IOMap structure.
14926  * \param _result A char value indicating whether the function call succeeded or not.
14927  */
14928 #define RemoteIOMapWriteBytes(_conn, _id, _offset, _data, _result) __remoteIOMapWriteBytes(_conn, _id, _offset, _data, _result)
14929 
14930 /**
14931  * Send a SetBrickName message.
14932  * Send the SetBrickName system command on the specified connection slot to
14933  * write the data provided.
14934  * Use \ref RemoteConnectionIdle to determine when this write request is completed.
14935  *
14936  * \param _conn The connection slot (0..4). Connections 0 through 3 are for
14937  * bluetooth connections.  Connection 4 refers to the RS485 hi-speed port.
14938  * See \ref CommConnectionConstants.
14939  * \param _name The new brick name.
14940  * \param _result A char value indicating whether the function call succeeded or not.
14941  */
14942 #define RemoteSetBrickName(_conn, _name, _result) __remoteSetBrickName(_conn, _name, _result)
14943 
14944 /** @} */ // end of CommModuleSCFunctions group
14945 
14946 /**
14947  * Use the RS485 port.
14948  * Configure port 4 for RS485 usage.
14949  *
14950  */
14951 #define UseRS485() __UseRS485()
14952 
14953 #ifdef __ENHANCED_FIRMWARE
14954 
14955 /**
14956  * Check RS485 status.
14957  * Check the status of the RS485 hi-speed port.
14958  *
14959  * \param _sendingData A boolean value set to true on output if data is being sent.
14960  * \param _dataAvail A boolean value set to true on output if data is available to be read.
14961  *
14962  * \warning This function requires the enhanced NBC/NXC firmware.
14963  */
14964 #define RS485Status(_sendingData, _dataAvail) __RS485Status(_sendingData, _dataAvail)
14965 
14966 /**
14967  * Write RS485 data.
14968  * Write data to the RS485 hi-speed port.
14969  *
14970  * \param _buffer A byte array containing the data to write to the RS485 port.
14971  * \param _status A char value indicating whether the function call succeeded or not.
14972  *
14973  * \warning This function requires the enhanced NBC/NXC firmware.
14974  */
14975 #define RS485Write(_buffer, _status) __RS485Write(_buffer, _status)
14976 
14977 /**
14978  * Read RS485 data.
14979  * Read data from the RS485 hi-speed port.
14980  *
14981  * \param _buffer A byte array that will contain the data read from the RS485 port.
14982  * \param _status A char value indicating whether the function call succeeded or not.
14983  *
14984  * \warning This function requires the enhanced NBC/NXC firmware.
14985  */
14986 #define RS485Read(_buffer, _status) __RS485Read(_buffer, _status)
14987 
14988 #if __FIRMWARE_VERSION > 107
14989 
14990 /**
14991  * Control the RS485 port.
14992  * Control the RS485 hi-speed port using the specified parameters.
14993  *
14994  * \param _cmd The control command to send to the port. See \ref CommHiSpeedCtrlConstants.
14995  * \param _baud The baud rate for the RS485 port. See \ref CommHiSpeedBaudConstants.
14996  * \param _mode The RS485 port mode (data bits, stop bits, parity).  See \ref
14997  * CommHiSpeedDataBitsConstants, \ref CommHiSpeedStopBitsConstants, \ref
14998  * CommHiSpeedParityConstants, and \ref CommHiSpeedCombinedConstants.
14999  * \param _result A char value indicating whether the function call succeeded or not.
15000  *
15001  * \warning This function requires the enhanced NBC/NXC firmware.
15002  */
15003 #define RS485Control(_cmd, _baud, _mode, _result) __RS485Control(_cmd, _baud, _mode, _result)
15004 
15005 /**
15006  * Configure RS485 UART.
15007  * Configure the RS485 UART parameters, including baud rate, data bits,
15008  * stop bits, and parity.
15009  *
15010  * \param _baud The baud rate for the RS485 port. See \ref CommHiSpeedBaudConstants.
15011  * \param _mode The RS485 port mode (data bits, stop bits, parity).  See \ref
15012  * CommHiSpeedDataBitsConstants, \ref CommHiSpeedStopBitsConstants, \ref
15013  * CommHiSpeedParityConstants, and \ref CommHiSpeedCombinedConstants.
15014  * \param _result A char value indicating whether the function call succeeded or not.
15015  *
15016  * \warning This function requires the enhanced NBC/NXC firmware.
15017  */
15018 #define RS485Uart(_baud, _mode, _result) __RS485Control(HS_CTRL_UART, _baud, _mode, _result)
15019 
15020 /**
15021  * Initialize RS485 port.
15022  * Initialize the RS485 UART port to its default values.  The baud rate is
15023  * set to 921600 and the mode is set to 8N1 (8 data bits, no parity, 1 stop bit).
15024  * Data cannot be sent or received over the RS485 port until the UART is
15025  * initialized and the port has been configured for RS485 usage.
15026  *
15027  * \param _result A char value indicating whether the function call succeeded or not.
15028  *
15029  * \warning This function requires the enhanced NBC/NXC firmware.
15030  */
15031 #define RS485Initialize(_result) __RS485Control(HS_CTRL_UART, HS_BAUD_DEFAULT, HS_MODE_DEFAULT, _result)
15032 
15033 /**
15034  * Enable RS485.
15035  * Turn on the RS485 hi-speed port so that it can be used.
15036  *
15037  * \param _result A char value indicating whether the function call succeeded or not.
15038  *
15039  * \warning This function requires the enhanced NBC/NXC firmware.
15040  */
15041 #define RS485Enable(_result) __RS485Control(HS_CTRL_INIT, HS_BAUD_DEFAULT, HS_MODE_DEFAULT, _result)
15042 
15043 /**
15044  * Disable RS485.
15045  * Turn off the RS485 port.
15046  *
15047  * \param _result A char value indicating whether the function call succeeded or not.
15048  *
15049  * \warning This function requires the enhanced NBC/NXC firmware.
15050  */
15051 #define RS485Disable(_result) __RS485Control(HS_CTRL_EXIT, HS_BAUD_DEFAULT, HS_MODE_DEFAULT, _result)
15052 
15053 #else
15054 
15055 #define RS485Control(_cmd, _baud, _result) __RS485Control(_cmd, _baud, _result)
15056 #define RS485Uart(_baud, _result) __RS485Control(HS_CTRL_UART, _baud, _result)
15057 #define RS485Initialize(_result) __RS485Control(HS_CTRL_UART, HS_BAUD_DEFAULT, _result)
15058 #define RS485Enable(_result) __RS485Control(HS_CTRL_INIT, HS_BAUD_DEFAULT, _result)
15059 #define RS485Disable(_result) __RS485Control(HS_CTRL_EXIT, HS_BAUD_DEFAULT, _result)
15060 
15061 #endif
15062 
15063 /**
15064  * Write RS485 boolean.
15065  * Write a boolean value to the RS485 hi-speed port.
15066  *
15067  * \param _bval A boolean value to write over the RS485 port.
15068  * \param _status A char value indicating whether the function call succeeded or not.
15069  *
15070  * \warning This function requires the enhanced NBC/NXC firmware.
15071  */
15072 #define SendRS485Bool(_bval, _status) __sendRS485Bool(_bval, _status)
15073 
15074 /**
15075  * Write RS485 numeric.
15076  * Write a numeric value to the RS485 hi-speed port.
15077  *
15078  * \param _val A numeric value to write over the RS485 port.
15079  * \param _status A char value indicating whether the function call succeeded or not.
15080  *
15081  * \warning This function requires the enhanced NBC/NXC firmware.
15082  */
15083 #define SendRS485Number(_val, _status) __sendRS485Number(_val, _status)
15084 
15085 /**
15086  * Write RS485 string.
15087  * Write a string value to the RS485 hi-speed port.
15088  *
15089  * \param _str A string value to write over the RS485 port.
15090  * \param _status A char value indicating whether the function call succeeded or not.
15091  *
15092  * \warning This function requires the enhanced NBC/NXC firmware.
15093  */
15094 #define SendRS485String(_str, _status) __sendRS485String(_str, _status)
15095 
15096 #endif
15097 
15098 /**
15099  * Get bluetooth device name.
15100  * This method returns the name of the device at the specified index in the
15101  * Bluetooth device table.
15102  * \param _p The device table index.
15103  * \param _str The device name of the specified bluetooth device.
15104  */
15105 #define GetBTDeviceName(_p, _str) __GetBTDeviceName(_p, _str)
15106 
15107 /**
15108  * Get bluetooth device class.
15109  * This method returns the class of the device at the specified index within
15110  * the Bluetooth device table.
15111  * \param _p The device table index.
15112  * \param _n The device class of the specified bluetooth device.
15113  */
15114 #define GetBTDeviceClass(_p, _n) __GetBTDeviceClass(_p, _n)
15115 
15116 /**
15117  * Get bluetooth device address.
15118  * This method reads the address of the device at the specified index within
15119  * the Bluetooth device table and stores it in the data buffer provided.
15120  * \param _p The device table index.
15121  * \param _btaddr The byte array reference that will contain the device address.
15122  */
15123 #define GetBTDeviceAddress(_p, _btaddr) __getBTDeviceAddress(_p, _btaddr)
15124 
15125 /**
15126  * Get bluetooth device status.
15127  * This method returns the status of the device at the specified index within
15128  * the Bluetooth device table.
15129  * \param _p The device table index.
15130  * \param _n The status of the specified bluetooth device.
15131  */
15132 #define GetBTDeviceStatus(_p, _n) __GetBTDeviceStatus(_p, _n)
15133 
15134 /**
15135  * Get bluetooth device name.
15136  * This method returns the name of the device at the specified index in the
15137  * Bluetooth connection table.
15138  * \param _p The connection slot (0..3).
15139  * \param _str The name of the bluetooth device at the specified connection slot.
15140  */
15141 #define GetBTConnectionName(_p, _str) __GetBTConnectionName(_p, _str)
15142 
15143 /**
15144  * Get bluetooth device class.
15145  * This method returns the class of the device at the specified index within
15146  * the Bluetooth connection table.
15147  * \param _p The connection slot (0..3).
15148  * \param _n The class of the bluetooth device at the specified connection slot.
15149  */
15150 #define GetBTConnectionClass(_p, _n) __GetBTConnectionClass(_p, _n)
15151 
15152 /**
15153  * Get bluetooth device pin code.
15154  * This method returns the pin code of the device at the specified index in the
15155  * Bluetooth connection table.
15156  * \param _p The connection slot (0..3).
15157  * \param _code The pin code for the bluetooth device at the specified connection slot.
15158  */
15159 #define GetBTConnectionPinCode(_p, _code) __GetBTConnectionPinCode(_p, _code)
15160 
15161 /**
15162  * Get bluetooth device address.
15163  * This method reads the address of the device at the specified index within
15164  * the Bluetooth connection table and stores it in the data buffer provided.
15165  * \param _p The connection slot (0..3).
15166  * \param _btaddr The byte array reference that will contain the device address.
15167  */
15168 #define GetBTConnectionAddress(_p, _btaddr) __getBTConnectionAddress(_p, _btaddr)
15169 
15170 /**
15171  * Get bluetooth device handle number.
15172  * This method returns the handle number of the device at the specified index within
15173  * the Bluetooth connection table.
15174  * \param _p The connection slot (0..3).
15175  * \param _n The handle number of the bluetooth device at the specified connection slot.
15176  */
15177 #define GetBTConnectionHandleNum(_p, _n) __GetBTConnectionHandleNum(_p, _n)
15178 
15179 /**
15180  * Get bluetooth device stream status.
15181  * This method returns the stream status of the device at the specified index within
15182  * the Bluetooth connection table.
15183  * \param _p The connection slot (0..3).
15184  * \param _n The stream status of the bluetooth device at the specified connection slot.
15185  */
15186 #define GetBTConnectionStreamStatus(_p, _n) __GetBTConnectionStreamStatus(_p, _n)
15187 
15188 /**
15189  * Get bluetooth device link quality.
15190  * This method returns the link quality of the device at the specified index within
15191  * the Bluetooth connection table.
15192  * \param _p The connection slot (0..3).
15193  * \param _n The link quality of the specified connection slot (unimplemented).
15194  * \warning This function is not implemented at the firmware level.
15195  */
15196 #define GetBTConnectionLinkQuality(_p, _n) __GetBTConnectionLinkQuality(_p, _n)
15197 
15198 /**
15199  * Get NXT name.
15200  * This method returns the name of the NXT.
15201  * \param _str The NXT's bluetooth name.
15202  */
15203 #define GetBrickDataName(_str) GetCommModuleBytes(CommOffsetBrickDataName, 16, _str)
15204 
15205 /**
15206  * Get NXT bluecore version.
15207  * This method returns the bluecore version of the NXT.
15208  * \param _n The NXT's bluecore version number.
15209  */
15210 #define GetBrickDataBluecoreVersion(_n) \
15211   compchk EQ, sizeof(_n), 2 \
15212   GetCommModuleValue(CommOffsetBrickDataBluecoreVersion, _n)
15213 
15214 /**
15215  * Get NXT address.
15216  * This method reads the address of the NXT and stores it in the data buffer
15217  * provided.
15218  * \param _btaddr The byte array reference that will contain the device address.
15219  */
15220 #define GetBrickDataAddress(_btaddr) GetCommModuleBytes(CommOffsetBrickDataBdAddr, 7, _btaddr)
15221 
15222 /**
15223  * Get NXT bluetooth state status.
15224  * This method returns the Bluetooth state status of the NXT.
15225  * \param _n The NXT's bluetooth state status.
15226  */
15227 #define GetBrickDataBtStateStatus(_n) \
15228   compchk EQ, sizeof(_n), 1 \
15229   GetCommModuleValue(CommOffsetBrickDataBtStateStatus, _n)
15230 
15231 /**
15232  * Get NXT bluetooth hardware status.
15233  * This method returns the Bluetooth hardware status of the NXT.
15234  * \param _n The NXT's bluetooth hardware status.
15235  */
15236 #define GetBrickDataBtHardwareStatus(_n) \
15237   compchk EQ, sizeof(_n), 1 \
15238   GetCommModuleValue(CommOffsetBrickDataBtHwStatus, _n)
15239 
15240 /**
15241  * Get NXT bluetooth timeout value.
15242  * This method returns the Bluetooth timeout value of the NXT.
15243  * \param _n The NXT's bluetooth timeout value.
15244  */
15245 #define GetBrickDataTimeoutValue(_n) \
15246   compchk EQ, sizeof(_n), 1 \
15247   GetCommModuleValue(CommOffsetBrickDataTimeOutValue, _n)
15248 
15249 /**
15250  * Get bluetooth input buffer data.
15251  * This method reads count bytes of data from the Bluetooth input buffer and
15252  * writes it to the buffer provided.
15253  *
15254  * \param _offset A constant offset into the bluetooth input buffer.
15255  * \param _cnt The number of bytes to read.
15256  * \param _data The byte array reference which will contain the data read from
15257  * the bluetooth input buffer.
15258  */
15259 #define GetBTInputBuffer(_offset, _cnt, _data) __getBTInputBuffer(_offset, _cnt, _data)
15260 
15261 /**
15262  * Get bluetooth input buffer in-pointer.
15263  * This method returns the value of the input pointer of the Bluetooth input
15264  * buffer.
15265  * \param _n The bluetooth input buffer's in-pointer value.
15266  */
15267 #define GetBTInputBufferInPtr(_n) \
15268   compchk EQ, sizeof(_n), 1 \
15269   GetCommModuleValue(CommOffsetBtInBufInPtr, _n)
15270 
15271 /**
15272  * Get bluetooth input buffer out-pointer.
15273  * This method returns the value of the output pointer of the Bluetooth input
15274  * buffer.
15275  * \param _n The bluetooth input buffer's out-pointer value.
15276  */
15277 #define GetBTInputBufferOutPtr(_n) \
15278   compchk EQ, sizeof(_n), 1 \
15279   GetCommModuleValue(CommOffsetBtInBufOutPtr, _n)
15280 
15281 /**
15282  * Get bluetooth output buffer data.
15283  * This method reads count bytes of data from the Bluetooth output buffer and
15284  * writes it to the buffer provided.
15285  *
15286  * \param _offset A constant offset into the bluetooth output buffer.
15287  * \param _cnt The number of bytes to read.
15288  * \param _data The byte array reference which will contain the data read from
15289  * the bluetooth output buffer.
15290  */
15291 #define GetBTOutputBuffer(_offset, _cnt, _data) __getBTOutputBuffer(_offset, _cnt, _data)
15292 
15293 /**
15294  * Get bluetooth output buffer in-pointer.
15295  * This method returns the value of the input pointer of the Bluetooth output
15296  * buffer.
15297  * \param _n The bluetooth output buffer's in-pointer value.
15298  */
15299 #define GetBTOutputBufferInPtr(_n) \
15300   compchk EQ, sizeof(_n), 1 \
15301   GetCommModuleValue(CommOffsetBtOutBufInPtr, _n)
15302 
15303 /**
15304  * Get bluetooth output buffer out-pointer.
15305  * This method returns the value of the output pointer of the Bluetooth output
15306  * buffer.
15307  * \param _n The bluetooth output buffer's out-pointer value.
15308  */
15309 #define GetBTOutputBufferOutPtr(_n) \
15310   compchk EQ, sizeof(_n), 1 \
15311   GetCommModuleValue(CommOffsetBtOutBufOutPtr, _n)
15312 
15313 /**
15314  * Get hi-speed port input buffer data.
15315  * This method reads count bytes of data from the hi-speed port input buffer and
15316  * writes it to the buffer provided.
15317  *
15318  * \param _offset A constant offset into the hi-speed port input buffer.
15319  * \param _cnt The number of bytes to read.
15320  * \param _data The byte array reference which will contain the data read from
15321  * the hi-speed port input buffer.
15322  */
15323 #define GetHSInputBuffer(_offset, _cnt, _data) __getHSInputBuffer(_offset, _cnt, _data)
15324 
15325 /**
15326  * Get hi-speed port input buffer in-pointer.
15327  * This method returns the value of the input pointer of the hi-speed port input
15328  * buffer.
15329  * \param _n The hi-speed port input buffer's in-pointer value.
15330  */
15331 #define GetHSInputBufferInPtr(_n) \
15332   compchk EQ, sizeof(_n), 1 \
15333   GetCommModuleValue(CommOffsetHsInBufInPtr, _n)
15334 
15335 /**
15336  * Get hi-speed port input buffer out-pointer.
15337  * This method returns the value of the output pointer of the hi-speed port input
15338  * buffer.
15339  * \param _n The hi-speed port input buffer's out-pointer value.
15340  */
15341 #define GetHSInputBufferOutPtr(_n) \
15342   compchk EQ, sizeof(_n), 1 \
15343   GetCommModuleValue(CommOffsetHsInBufOutPtr, _n)
15344 
15345 /**
15346  * Get hi-speed port output buffer data.
15347  * This method reads count bytes of data from the hi-speed port output buffer and
15348  * writes it to the buffer provided.
15349  *
15350  * \param _offset A constant offset into the hi-speed port output buffer.
15351  * \param _cnt The number of bytes to read.
15352  * \param _data The byte array reference which will contain the data read from
15353  * the hi-speed port output buffer.
15354  */
15355 #define GetHSOutputBuffer(_offset, _cnt, _data) __getHSOutputBuffer(_offset, _cnt, _data)
15356 
15357 /**
15358  * Get hi-speed port output buffer in-pointer.
15359  * This method returns the value of the input pointer of the hi-speed port output
15360  * buffer.
15361  * \param _n The hi-speed port output buffer's in-pointer value.
15362  */
15363 #define GetHSOutputBufferInPtr(_n) \
15364   compchk EQ, sizeof(_n), 1 \
15365   GetCommModuleValue(CommOffsetHsOutBufInPtr, _n)
15366 
15367 /**
15368  * Get hi-speed port output buffer out-pointer.
15369  * This method returns the value of the output pointer of the hi-speed port output
15370  * buffer.
15371  * \param _n The hi-speed port output buffer's out-pointer value.
15372  */
15373 #define GetHSOutputBufferOutPtr(_n) \
15374   compchk EQ, sizeof(_n), 1 \
15375   GetCommModuleValue(CommOffsetHsOutBufOutPtr, _n)
15376 
15377 /**
15378  * Get usb input buffer data.
15379  * This method reads count bytes of data from the usb input buffer and
15380  * writes it to the buffer provided.
15381  *
15382  * \param _offset A constant offset into the usb input buffer.
15383  * \param _cnt The number of bytes to read.
15384  * \param _data The byte array reference which will contain the data read from
15385  * the usb input buffer.
15386  */
15387 #define GetUSBInputBuffer(_offset, _cnt, _data) __getUSBInputBuffer(_offset, _cnt, _data)
15388 
15389 /**
15390  * Get usb port input buffer in-pointer.
15391  * This method returns the value of the input pointer of the usb port input
15392  * buffer.
15393  * \param _n The USB port input buffer's in-pointer value.
15394  */
15395 #define GetUSBInputBufferInPtr(_n) \
15396   compchk EQ, sizeof(_n), 1 \
15397   GetCommModuleValue(CommOffsetUsbInBufInPtr, _n)
15398 
15399 /**
15400  * Get usb port input buffer out-pointer.
15401  * This method returns the value of the output pointer of the usb port input
15402  * buffer.
15403  * \param _n The USB port input buffer's out-pointer value.
15404  */
15405 #define GetUSBInputBufferOutPtr(_n) \
15406   compchk EQ, sizeof(_n), 1 \
15407   GetCommModuleValue(CommOffsetUsbInBufOutPtr, _n)
15408 
15409 /**
15410  * Get usb output buffer data.
15411  * This method reads count bytes of data from the usb output buffer and
15412  * writes it to the buffer provided.
15413  * \param _offset A constant offset into the usb output buffer.
15414  * \param _cnt The number of bytes to read.
15415  * \param _data The byte array reference which will contain the data read from
15416  * the usb output buffer.
15417  */
15418 #define GetUSBOutputBuffer(_offset, _cnt, _data) __getUSBOutputBuffer(_offset, _cnt, _data)
15419 
15420 /**
15421  * Get usb port output buffer in-pointer.
15422  * This method returns the value of the input pointer of the usb port output
15423  * buffer.
15424  * \param _n The USB port output buffer's in-pointer value.
15425  */
15426 #define GetUSBOutputBufferInPtr(_n) \
15427   compchk EQ, sizeof(_n), 1 \
15428   GetCommModuleValue(CommOffsetUsbOutBufInPtr, _n)
15429 
15430 /**
15431  * Get usb port output buffer out-pointer.
15432  * This method returns the value of the output pointer of the usb port output
15433  * buffer.
15434  * \param _n The USB port output buffer's out-pointer value.
15435  */
15436 #define GetUSBOutputBufferOutPtr(_n) \
15437   compchk EQ, sizeof(_n), 1 \
15438   GetCommModuleValue(CommOffsetUsbOutBufOutPtr, _n)
15439 
15440 /**
15441  * Get usb poll buffer data.
15442  * This method reads count bytes of data from the usb poll buffer and
15443  * writes it to the buffer provided.
15444  * \param _offset A constant offset into the usb poll buffer.
15445  * \param _cnt The number of bytes to read.
15446  * \param _data The byte array reference which will contain the data read from
15447  * the usb poll buffer.
15448  */
15449 #define GetUSBPollBuffer(_offset, _cnt, _data) __getUSBPollBuffer(_offset, _cnt, _data)
15450 
15451 /**
15452  * Get usb port poll buffer in-pointer.
15453  * This method returns the value of the input pointer of the usb port poll
15454  * buffer.
15455  * \param _n The USB port poll buffer's in-pointer value.
15456  */
15457 #define GetUSBPollBufferInPtr(_n) \
15458   compchk EQ, sizeof(_n), 1 \
15459   GetCommModuleValue(CommOffsetUsbPollBufInPtr, _n)
15460 
15461 /**
15462  * Get usb port poll buffer out-pointer.
15463  * This method returns the value of the output pointer of the usb port poll
15464  * buffer.
15465  * \param _n The USB port poll buffer's out-pointer value.
15466  */
15467 #define GetUSBPollBufferOutPtr(_n) \
15468   compchk EQ, sizeof(_n), 1 \
15469   GetCommModuleValue(CommOffsetUsbPollBufOutPtr, _n)
15470 
15471 /**
15472  * Get bluetooth device count.
15473  * This method returns the number of devices defined within the Bluetooth
15474  * device table.
15475  * \return The count of known bluetooth devices.
15476  */
15477 #define GetBTDeviceCount(_n) \
15478   compchk EQ, sizeof(_n), 1 \
15479   GetCommModuleValue(CommOffsetBtDeviceCnt, _n)
15480 
15481 /**
15482  * Get bluetooth device name count.
15483  * This method returns the number of device names defined within the Bluetooth
15484  * device table. This usually has the same value as BTDeviceCount but it can
15485  * differ in some instances.
15486  * \param _n The count of known bluetooth device names.
15487  */
15488 #define GetBTDeviceNameCount(_n) \
15489   compchk EQ, sizeof(_n), 1 \
15490   GetCommModuleValue(CommOffsetBtDeviceNameCnt, _n)
15491 
15492 /**
15493  * Get hi-speed port flags.
15494  * This method returns the value of the hi-speed port flags.
15495  * \param _n The hi-speed port flags. See \ref CommHiSpeedFlagsConstants.
15496  */
15497 #define GetHSFlags(_n) \
15498   compchk EQ, sizeof(_n), 1 \
15499   GetCommModuleValue(CommOffsetHsFlags, _n)
15500 
15501 /**
15502  * Get hi-speed port speed.
15503  * This method returns the value of the hi-speed port speed (baud rate).
15504  * \param _n The hi-speed port speed (baud rate).  See \ref CommHiSpeedBaudConstants.
15505  */
15506 #define GetHSSpeed(_n) \
15507   compchk EQ, sizeof(_n), 1 \
15508   GetCommModuleValue(CommOffsetHsSpeed, _n)
15509 
15510 /**
15511  * Get hi-speed port state.
15512  * This method returns the value of the hi-speed port state.
15513  * \param _n The hi-speed port state. See \ref CommHiSpeedStateConstants.
15514  */
15515 #define GetHSState(_n) \
15516   compchk EQ, sizeof(_n), 1 \
15517   GetCommModuleValue(CommOffsetHsState, _n)
15518 
15519 /**
15520  * Get USB state.
15521  * This method returns the value of the USB state.
15522  * \param _n The USB state.
15523  */
15524 #define GetUSBState(_n) \
15525   compchk EQ, sizeof(_n), 1 \
15526   GetCommModuleValue(CommOffsetUsbState, _n)
15527 
15528 #if (__FIRMWARE_VERSION > 107) && defined(__ENHANCED_FIRMWARE)
15529 
15530 /**
15531  * Get hi-speed port mode.
15532  * This method returns the value of the hi-speed port mode.
15533  * \param _n The hi-speed port mode (data bits, stop bits, parity).  See
15534  * \ref CommHiSpeedDataBitsConstants, \ref CommHiSpeedStopBitsConstants,
15535  * \ref CommHiSpeedParityConstants, and \ref CommHiSpeedCombinedConstants.
15536  *
15537  * \warning This function requires the enhanced NBC/NXC firmware version 1.28+.
15538  */
15539 #define GetHSMode(_n) \
15540   compchk EQ, sizeof(_n), 2 \
15541   GetCommModuleValue(CommOffsetHsMode, _n)
15542 
15543 /**
15544  * Get Bluetooth data mode.
15545  * This method returns the value of the Bluetooth data mode.
15546  * \param _n The Bluetooth data mode.  See \ref CommDataModeConstants.
15547  *
15548  * \warning This function requires the enhanced NBC/NXC firmware version 1.28+.
15549  */
15550 #define GetBTDataMode(_n) \
15551   compchk EQ, sizeof(_n), 1 \
15552   GetCommModuleValue(CommOffsetBtDataMode, _n)
15553 
15554 /**
15555  * Get hi-speed port data mode.
15556  * This method returns the value of the hi-speed port data mode.
15557  * \param _n The hi-speed port data mode.  See \ref CommDataModeConstants.
15558  *
15559  * \warning This function requires the enhanced NBC/NXC firmware version 1.28+.
15560  */
15561 #define GetHSDataMode(_n) \
15562   compchk EQ, sizeof(_n), 1 \
15563   GetCommModuleValue(CommOffsetHsDataMode, _n)
15564 
15565 #endif
15566 
15567 /**
15568  * Set bluetooth input buffer data.
15569  * Write cnt bytes of data to the bluetooth input buffer at offset.
15570  * \param _offset A constant offset into the input buffer
15571  * \param _cnt The number of bytes to write
15572  * \param _data A byte array containing the data to write
15573  */
15574 #define SetBTInputBuffer(_offset, _cnt, _data) __setBTInputBuffer(_offset, _cnt, _data)
15575 
15576 /**
15577  * Set bluetooth input buffer in-pointer.
15578  * Set the value of the input buffer in-pointer.
15579  * \param _n The new in-pointer value (0..127).
15580  */
15581 #define SetBTInputBufferInPtr(_n) __setBTInputBufferInPtr(_n)
15582 
15583 /**
15584  * Set bluetooth input buffer out-pointer.
15585  * Set the value of the input buffer out-pointer.
15586  * \param _n The new out-pointer value (0..127).
15587  */
15588 #define SetBTInputBufferOutPtr(_n) __setBTInputBufferOutPtr(_n)
15589 
15590 /**
15591  * Set bluetooth output buffer data.
15592  * Write cnt bytes of data to the bluetooth output buffer at offset.
15593  * \param _offset A constant offset into the output buffer
15594  * \param _cnt The number of bytes to write
15595  * \param _data A byte array containing the data to write
15596  */
15597 #define SetBTOutputBuffer(_offset, _cnt, _data) __setBTOutputBuffer(_offset, _cnt, _data)
15598 
15599 /**
15600  * Set bluetooth output buffer in-pointer.
15601  * Set the value of the output buffer in-pointer.
15602  * \param _n The new in-pointer value (0..127).
15603  */
15604 #define SetBTOutputBufferInPtr(_n) __setBTOutputBufferInPtr(_n)
15605 
15606 /**
15607  * Set bluetooth output buffer out-pointer.
15608  * Set the value of the output buffer out-pointer.
15609  * \param _n The new out-pointer value (0..127).
15610  */
15611 #define SetBTOutputBufferOutPtr(_n) __setBTOutputBufferOutPtr(_n)
15612 
15613 /**
15614  * Set hi-speed port input buffer data.
15615  * Write cnt bytes of data to the hi-speed port input buffer at offset.
15616  * \param _offset A constant offset into the input buffer
15617  * \param _cnt The number of bytes to write
15618  * \param _data A byte array containing the data to write
15619  */
15620 #define SetHSInputBuffer(_offset, _cnt, _data) __setHSInputBuffer(_offset, _cnt, _data)
15621 
15622 /**
15623  * Set hi-speed port input buffer in-pointer.
15624  * Set the value of the input buffer in-pointer.
15625  * \param _n The new in-pointer value (0..127).
15626  */
15627 #define SetHSInputBufferInPtr(_n) __setHSInputBufferInPtr(_n)
15628 
15629 /**
15630  * Set hi-speed port input buffer out-pointer.
15631  * Set the value of the input buffer out-pointer.
15632  * \param _n The new out-pointer value (0..127).
15633  */
15634 #define SetHSInputBufferOutPtr(_n) __setHSInputBufferOutPtr(_n)
15635 
15636 /**
15637  * Set hi-speed port output buffer data.
15638  * Write cnt bytes of data to the hi-speed port output buffer at offset.
15639  * \param _offset A constant offset into the output buffer
15640  * \param _cnt The number of bytes to write
15641  * \param _data A byte array containing the data to write
15642  */
15643 #define SetHSOutputBuffer(_offset, _cnt, _data) __setHSOutputBuffer(_offset, _cnt, _data)
15644 
15645 /**
15646  * Set hi-speed port output buffer in-pointer.
15647  * Set the value of the output buffer in-pointer.
15648  * \param _n The new in-pointer value (0..127).
15649  */
15650 #define SetHSOutputBufferInPtr(_n) __setHSOutputBufferInPtr(_n)
15651 
15652 /**
15653  * Set hi-speed port output buffer out-pointer.
15654  * Set the value of the output buffer out-pointer.
15655  * \param _n The new out-pointer value (0..127).
15656  */
15657 #define SetHSOutputBufferOutPtr(_n) __setHSOutputBufferOutPtr(_n)
15658 
15659 /**
15660  * Set USB input buffer data.
15661  * Write cnt bytes of data to the USB input buffer at offset.
15662  * \param _offset A constant offset into the input buffer
15663  * \param _cnt The number of bytes to write
15664  * \param _data A byte array containing the data to write
15665  */
15666 #define SetUSBInputBuffer(_offset, _cnt, _data) __setUSBInputBuffer(_offset, _cnt, _data)
15667 
15668 /**
15669  * Set USB input buffer in-pointer.
15670  * Set the value of the input buffer in-pointer.
15671  * \param _n The new in-pointer value (0..63).
15672  */
15673 #define SetUSBInputBufferInPtr(_n) __setUSBInputBufferInPtr(_n)
15674 
15675 /**
15676  * Set USB input buffer out-pointer.
15677  * Set the value of the input buffer out-pointer.
15678  * \param _n The new out-pointer value (0..63).
15679  */
15680 #define SetUSBInputBufferOutPtr(_n) __setUSBInputBufferOutPtr(_n)
15681 
15682 /**
15683  * Set USB output buffer data.
15684  * Write cnt bytes of data to the USB output buffer at offset.
15685  * \param _offset A constant offset into the output buffer
15686  * \param _cnt The number of bytes to write
15687  * \param _data A byte array containing the data to write
15688  */
15689 #define SetUSBOutputBuffer(_offset, _cnt, _data) __setUSBOutputBuffer(_offset, _cnt, _data)
15690 
15691 /**
15692  * Set USB output buffer in-pointer.
15693  * Set the value of the output buffer in-pointer.
15694  * \param _n The new in-pointer value (0..63).
15695  */
15696 #define SetUSBOutputBufferInPtr(_n) __setUSBOutputBufferInPtr(_n)
15697 
15698 /**
15699  * Set USB output buffer out-pointer.
15700  * Set the value of the output buffer out-pointer.
15701  * \param _n The new out-pointer value (0..63).
15702  */
15703 #define SetUSBOutputBufferOutPtr(_n) __setUSBOutputBufferOutPtr(_n)
15704 
15705 /**
15706  * Set USB poll buffer data.
15707  * Write cnt bytes of data to the USB poll buffer at offset.
15708  * \param _offset A constant offset into the poll buffer
15709  * \param _cnt The number of bytes to write
15710  * \param _data A byte array containing the data to write
15711  */
15712 #define SetUSBPollBuffer(_offset, _cnt, _data) __setUSBPollBuffer(_offset, _cnt, _data)
15713 
15714 /**
15715  * Set USB poll buffer in-pointer.
15716  * Set the value of the poll buffer in-pointer.
15717  * \param _n The new in-pointer value (0..63).
15718  */
15719 #define SetUSBPollBufferInPtr(_n) __setUSBPollBufferInPtr(_n)
15720 
15721 /**
15722  * Set USB poll buffer out-pointer.
15723  * Set the value of the poll buffer out-pointer.
15724  * \param _n The new out-pointer value (0..63).
15725  */
15726 #define SetUSBPollBufferOutPtr(_n) __setUSBPollBufferOutPtr(_n)
15727 
15728 /**
15729  * Set hi-speed port flags.
15730  * This method sets the value of the hi-speed port flags.
15731  * \param _n The hi-speed port flags. See \ref CommHiSpeedFlagsConstants.
15732  */
15733 #define SetHSFlags(_n) __setHSFlags(_n)
15734 
15735 /**
15736  * Set hi-speed port speed.
15737  * This method sets the value of the hi-speed port speed (baud rate).
15738  * \param _n The hi-speed port speed (baud rate).  See \ref CommHiSpeedBaudConstants.
15739  */
15740 #define SetHSSpeed(_n) __setHSSpeed(_n)
15741 
15742 /**
15743  * Set hi-speed port state.
15744  * This method sets the value of the hi-speed port state.
15745  * \param _n The hi-speed port state. See \ref CommHiSpeedStateConstants.
15746  */
15747 #define SetHSState(_n) __setHSState(_n)
15748 
15749 /**
15750  * Set USB state.
15751  * This method sets the value of the USB state.
15752  * \param _n The USB state.
15753  */
15754 #define SetUSBState(_n) __setUSBState(_n)
15755 
15756 #if (__FIRMWARE_VERSION > 107) && defined(__ENHANCED_FIRMWARE)
15757 
15758 /**
15759  * Set hi-speed port mode.
15760  * This method sets the value of the hi-speed port mode.
15761  * \param _n The hi-speed port mode (data bits, stop bits, parity).  See
15762  * \ref CommHiSpeedDataBitsConstants, \ref CommHiSpeedStopBitsConstants,
15763  * \ref CommHiSpeedParityConstants, and \ref CommHiSpeedCombinedConstants.
15764  *
15765  * \warning This function requires the enhanced NBC/NXC firmware version 1.28+.
15766  */
15767 #define SetHSMode(_n) __setHSMode(_n)
15768 
15769 /**
15770  * Set Bluetooth data mode.
15771  * This method sets the value of the Bluetooth data mode.
15772  * \param _n The Bluetooth data mode.  See \ref CommDataModeConstants.
15773  *
15774  * \warning This function requires the enhanced NBC/NXC firmware version 1.28+.
15775  */
15776 #define SetBTDataMode(_n) __setBTDataMode(_n)
15777 
15778 /**
15779  * Set hi-speed port data mode.
15780  * This method sets the value of the hi-speed port data mode.
15781  * \param _n The hi-speed port data mode.  See \ref CommDataModeConstants.
15782  *
15783  * \warning This function requires the enhanced NBC/NXC firmware version 1.28+.
15784  */
15785 #define SetHSDataMode(_n) __setHSDataMode(_n)
15786 
15787 #endif
15788 
15789 /** @} */ // end of CommModuleFunctions group
15790 /** @} */ // end of CommModule group
15791 /** @} */ // end of NXTFirmwareModules group
15792 
15793 
15794 ///////////////////////////////////////////////////////////////////////////////
15795 //////////////////////////////// IOCTRL MODULE ////////////////////////////////
15796 ///////////////////////////////////////////////////////////////////////////////
15797 
15798 
15799 /** @addtogroup NXTFirmwareModules
15800  * @{
15801  */
15802 /** @addtogroup IOCtrlModule
15803  * @{
15804  */
15805 /** @defgroup IOCtrlModuleFunctions IOCtrl module functions
15806  * Functions for accessing and modifying IOCtrl module features.
15807  * @{
15808  */
15809 
15810 /**
15811  * Power down the NXT.
15812  * This function powers down the NXT.
15813  * The running program will terminate as a result of this action.
15814  */
15815 #define PowerDown SetIOCtrlModuleValue(IOCtrlOffsetPowerOn, IOCTRL_POWERDOWN)
15816 
15817 /**
15818  * Reboot the NXT in firmware download mode.
15819  * This function lets you reboot the NXT into SAMBA or firmware download mode.
15820  * The running program will terminate as a result of this action.
15821  */
15822 #define RebootInFirmwareMode SetIOCtrlModuleValue(IOCtrlOffsetPowerOn, IOCTRL_BOOT)
15823 
15824 /** @} */ // end of IOCtrlModuleFunctions group
15825 /** @} */ // end of IOCtrlModule group
15826 /** @} */ // end of NXTFirmwareModules group
15827 
15828 
15829 ///////////////////////////////////////////////////////////////////////////////
15830 //////////////////////////////// LOADER MODULE ////////////////////////////////
15831 ///////////////////////////////////////////////////////////////////////////////
15832 
15833 
15834 /** @addtogroup NXTFirmwareModules
15835  * @{
15836  */
15837 /** @addtogroup LoaderModule
15838  * @{
15839  */
15840 /** @defgroup LoaderModuleFunctions Loader module functions
15841  * Functions for accessing and modifying Loader module features.
15842  * @{
15843  */
15844 
15845 /**
15846  * Get free flash memory.
15847  * Get the number of bytes of flash memory that are available for use.
15848  *
15849  * \param _value The number of bytes of unused flash memory.
15850  */
15851 #define GetFreeMemory(_value) __GetFreeMemory(_value)
15852 
15853 /**
15854  * Create a file.
15855  * Create a new file with the specified filename and size and open it for
15856  * writing. The file handle is returned in the last parameter, which must be a
15857  * variable. The loader result code is returned as the value of the function
15858  * call. The filename and size parameters must be constants, constant
15859  * expressions, or variables. A file created with a size of zero bytes cannot
15860  * be written to since the NXC file writing functions do not grow the file if
15861  * its capacity is exceeded during a write attempt.
15862  *
15863  * \param _fname The name of the file to create.
15864  * \param _fsize The size of the file.
15865  * \param _handle The file handle output from the function call.
15866  * \param _result The function call result. See \ref LoaderErrors.
15867  */
15868 #define CreateFile(_fname, _fsize, _handle, _result) __createFile(_fname, _fsize, _handle, _result)
15869 
15870 /**
15871  * Open a file for appending.
15872  * Open an existing file with the specified filename for writing. The file
15873  * size is returned in the second parameter, which must be a variable. The
15874  * file handle is returned in the last parameter, which must be a variable.
15875  * The loader result code is returned as the value of the function call.
15876  * The filename parameter must be a constant or a variable.
15877  *
15878  * \param _fname The name of the file to open.
15879  * \param _fsize The size of the file returned by the function.
15880  * \param _handle The file handle output from the function call.
15881  * \param _result The function call result. See \ref LoaderErrors.
15882  */
15883 #define OpenFileAppend(_fname, _fsize, _handle, _result) __openFileAppend(_fname, _fsize, _handle, _result)
15884 
15885 /**
15886  * Open a file for reading.
15887  * Open an existing file with the specified filename for reading. The file
15888  * size is returned in the second parameter, which must be a variable. The
15889  * file handle is returned in the last parameter, which must be a variable.
15890  * The loader result code is returned as the value of the function call. The
15891  * filename parameter must be a constant or a variable.
15892  *
15893  * \param _fname The name of the file to open.
15894  * \param _fsize The size of the file returned by the function.
15895  * \param _handle The file handle output from the function call.
15896  * \param _result The function call result. See \ref LoaderErrors.
15897  */
15898 #define OpenFileRead(_fname, _fsize, _handle, _result) __openFileRead(_fname, _fsize, _handle, _result)
15899 
15900 /**
15901  * Close a file.
15902  * Close the file associated with the specified file handle. The loader
15903  * result code is returned as the value of the function call. The handle
15904  * parameter must be a constant or a variable.
15905  *
15906  * \param _handle The file handle.
15907  * \param _result The function call result. See \ref LoaderErrors.
15908  */
15909 #define CloseFile(_handle, _result) __closeFile(_handle, _result)
15910 
15911 /**
15912  * Resolve a handle.
15913  * Resolve a file handle from the specified filename. The file handle is
15914  * returned in the second parameter, which must be a variable. A boolean
15915  * value indicating whether the handle can be used to write to the file or
15916  * not is returned in the last parameter, which must be a variable. The
15917  * loader result code is returned as the value of the function call. The
15918  * filename parameter must be a constant or a variable.
15919  *
15920  * \param _fname The name of the file for which to resolve a handle.
15921  * \param _handle The file handle output from the function call.
15922  * \param _writeable A boolean flag indicating whether the handle is
15923  * to a file open for writing (true) or reading (false).
15924  * \param _result The function call result. See \ref LoaderErrors.
15925  */
15926 #define ResolveHandle(_fname, _handle, _writeable, _result) __resolveHandle(_fname, _handle, _writeable, _result)
15927 
15928 /**
15929  * Rename a file.
15930  * Rename a file from the old filename to the new filename. The loader
15931  * param _result code is returned as the value of the function call. The filename
15932  * parameters must be constants or variables.
15933  *
15934  * \param _oldname The old filename.
15935  * \param _newname The new filename.
15936  * \param _result The function call result. See \ref LoaderErrors.
15937  */
15938 #define RenameFile(_oldname, _newname, _result) __renameFile(_oldname, _newname, _result)
15939 
15940 /**
15941  * Delete a file.
15942  * Delete the specified file. The loader result code is returned as the
15943  * value of the function call. The filename parameter must be a constant or a
15944  * variable.
15945  *
15946  * \param _fname The name of the file to delete.
15947  * \param _result The function call result. See \ref LoaderErrors.
15948  */
15949 #define DeleteFile(_fname, _result) __deleteFile(_fname, _result)
15950 
15951 /**
15952  * Resize a file.
15953  * Resize the specified file. The loader result code is returned as the
15954  * value of the function call. The filename parameter must be a constant or a
15955  * variable.
15956  *
15957  * \param _fname The name of the file to resize.
15958  * \param _newsize The new size for the file.
15959  * \param _result The function call result. See \ref LoaderErrors.
15960  */
15961 #define ResizeFile(_fname, _newsize, _result) __fileResize(_fname, _newsize, _result)
15962 
15963 #ifdef __ENHANCED_FIRMWARE
15964 
15965 /**
15966  * Create a linear file.
15967  * Create a new linear file with the specified filename and size and open it for
15968  * writing. The file handle is returned in the last parameter, which must be a
15969  * variable. The loader result code is returned as the value of the function
15970  * call. The filename and size parameters must be constants, constant
15971  * expressions, or variables. A file created with a size of zero bytes cannot
15972  * be written to since the NXC file writing functions do not grow the file if
15973  * its capacity is exceeded during a write attempt.
15974  *
15975  * \param _fname The name of the file to create.
15976  * \param _fsize The size of the file.
15977  * \param _handle The file handle output from the function call.
15978  * \param _result The function call result. See \ref LoaderErrors.
15979  * \warning This function requires the enhanced NBC/NXC firmware.
15980  */
15981 #define CreateFileLinear(_fname, _fsize, _handle, _result) __createFileLinear(_fname, _fsize, _handle, _result)
15982 
15983 /**
15984  * Create a non-linear file.
15985  * Create a new non-linear file with the specified filename and size and open it for
15986  * writing. The file handle is returned in the last parameter, which must be a
15987  * variable. The loader result code is returned as the value of the function
15988  * call. The filename and size parameters must be constants, constant
15989  * expressions, or variables. A file created with a size of zero bytes cannot
15990  * be written to since the NXC file writing functions do not grow the file if
15991  * its capacity is exceeded during a write attempt.
15992  *
15993  * \param _fname The name of the file to create.
15994  * \param _fsize The size of the file.
15995  * \param _handle The file handle output from the function call.
15996  * \param _result The function call result. See \ref LoaderErrors.
15997  * \warning This function requires the enhanced NBC/NXC firmware.
15998  */
15999 #define CreateFileNonLinear(_fname, _fsize, _handle, _result) __createFileNonLinear(_fname, _fsize, _handle, _result)
16000 
16001 /**
16002  * Open a linear file for reading.
16003  * Open an existing linear file with the specified filename for reading. The file
16004  * size is returned in the second parameter, which must be a variable. The
16005  * file handle is returned in the last parameter, which must be a variable.
16006  * The loader result code is returned as the value of the function call. The
16007  * filename parameter must be a constant or a variable.
16008  *
16009  * \param _fname The name of the file to open.
16010  * \param _fsize The size of the file returned by the function.
16011  * \param _handle The file handle output from the function call.
16012  * \param _result The function call result. See \ref LoaderErrors.
16013  * \warning This function requires the enhanced NBC/NXC firmware.
16014  */
16015 #define OpenFileReadLinear(_fname, _fsize, _handle, _result) __openFileReadLinear(_fname, _fsize, _handle, _result)
16016 
16017 /**
16018  * Start searching for files.
16019  * This function lets you begin iterating through files stored on the NXT.
16020  *
16021  * \param _fname On input this contains the filename pattern you are searching
16022  * for. On output this contains the name of the first file found that matches
16023  * the pattern.
16024  * \param _handle The search handle input to and output from the function call.
16025  * \param _result The function call result. See \ref LoaderErrors.
16026  * \warning This function requires the enhanced NBC/NXC firmware.
16027  */
16028 #define FindFirstFile(_fname, _handle, _result) __findFirstFile(_fname, _handle, _result)
16029 
16030 /**
16031  * Continue searching for files.
16032  * This function lets you continue iterating through files stored on the NXT.
16033  *
16034  * \param _fname On output this contains the name of the next file found that
16035  * matches the pattern used when the search began by calling \ref FindFirstFile.
16036  * \param _handle The search handle input to and output from the function call.
16037  * \param _result The function call result. See \ref LoaderErrors.
16038  * \warning This function requires the enhanced NBC/NXC firmware.
16039  */
16040 #define FindNextFile(_fname, _handle, _result) __findNextFile(_fname, _handle, _result)
16041 #endif
16042 
16043 /**
16044  * Calculate the size of a variable.
16045  * Calculate the number of bytes required to store the contents of the
16046  * variable passed into the function.
16047  *
16048  * \param _n The variable.
16049  * \param _result The number of bytes occupied by the variable.
16050  */
16051 #define SizeOf(_n, _result) __sizeOF(_n, _result)
16052 
16053 /**
16054  * Read a value from a file.
16055  * Read a value from the file associated with the specified handle.
16056  * The handle parameter must be a variable. The value parameter must be a
16057  * variable. The type of the value parameter determines the number of bytes of
16058  * data read.
16059  *
16060  * \param _handle The file handle.
16061  * \param _n The variable to store the data read from the file.
16062  * \param _result The function call result. See \ref LoaderErrors.
16063  */
16064 #define Read(_handle, _n, _result) __readValue(_handle, _n, _result)
16065 
16066 /**
16067  * Read a value from a file plus line ending.
16068  * Read a value from the file associated with the specified handle.
16069  * The handle parameter must be a variable. The value parameter must be a
16070  * variable. The type of the value parameter determines the number of bytes
16071  * of data read. The ReadLn function reads two additional bytes from the
16072  * file which it assumes are a carriage return and line feed pair.
16073  *
16074  * \param _handle The file handle.
16075  * \param _n The variable to store the data read from the file.
16076  * \param _result The function call result. See \ref LoaderErrors.
16077  */
16078 #define ReadLn(_handle, _n, _result) __readLnValue(_handle, _n, _result)
16079 
16080 /**
16081  * Read bytes from a file.
16082  * Read the specified number of bytes from the file associated with the
16083  * specified handle. The handle parameter must be a variable. The length
16084  * parameter must be a variable. The buf parameter must be an array or a
16085  * string variable. The actual number of bytes read is returned in the
16086  * length parameter.
16087  *
16088  * \param _handle The file handle.
16089  * \param _len The number of bytes to read. Returns the number of bytes actually read.
16090  * \param _buf The byte array where the data is stored on output.
16091  * \param _result The function call result. See \ref LoaderErrors.
16092  */
16093 #define ReadBytes(_handle, _len, _buf, _result) __readBytes(_handle, _len, _buf, _result)
16094 
16095 /**
16096  * Read a string from a file plus line ending.
16097  * Read a string from the file associated with the specified handle.
16098  * The handle parameter must be a variable. The output parameter must be a
16099  * variable. Appends bytes to the output variable until a line ending (CRLF)
16100  * is reached. The line ending is also read but it is not appended to the
16101  * output parameter.
16102  *
16103  * \param _handle The file handle.
16104  * \param _output The variable to store the string read from the file.
16105  * \param _result The function call result. See \ref LoaderErrors.
16106  */
16107 #define ReadLnString(_handle, _output, _result) __readLnString(_handle, _output, _result)
16108 
16109 /**
16110  * Write value to file.
16111  * Write a value to the file associated with the specified handle.
16112  * The handle parameter must be a variable. The value parameter must be a
16113  * constant, a constant expression, or a variable. The type of the value
16114  * parameter determines the number of bytes of data written.
16115  *
16116  * \param _handle The file handle.
16117  * \param _n The value to write to the file.
16118  * \param _result The function call result. See \ref LoaderErrors.
16119  */
16120 #define Write(_handle, _n, _result) __writeValue(_handle, _n, _result)
16121 
16122 /**
16123  * Write a value and new line to a file.
16124  * Write a value to the file associated with the specified handle. The
16125  * handle parameter must be a variable. The value parameter must be a constant,
16126  * a constant expression, or a variable. The type of the value parameter
16127  * determines the number of bytes of data written. This function also
16128  * writes a carriage return and a line feed to the file following the numeric
16129  * data.
16130  *
16131  * \param _handle The file handle.
16132  * \param _n The value to write to the file.
16133  * \param _result The function call result. See \ref LoaderErrors.
16134  */
16135 #define WriteLn(_handle, _n, _result) __writeLnValue(_handle, _n, _result)
16136 
16137 /**
16138  * Write string to a file.
16139  * Write the string to the file associated with the specified handle. The
16140  * handle parameter must be a variable. The count parameter must be a variable.
16141  * The str parameter must be a string variable or string constant. The actual
16142  * number of bytes written is returned in the cnt parameter.
16143  *
16144  * \param _handle The file handle.
16145  * \param _str The string to write to the file.
16146  * \param _cnt The number of bytes actually written to the file.
16147  * \param _result The function call result. See \ref LoaderErrors.
16148  */
16149 #define WriteString(_handle, _str, _cnt, _result) __writeString(_handle, _str, _cnt, _result)
16150 
16151 /**
16152  * Write string and new line to a file.
16153  * Write the string to the file associated with the specified handle. The
16154  * handle parameter must be a variable. The count parameter must be a variable.
16155  * The str parameter must be a string variable or string constant. This
16156  * function also writes a carriage return and a line feed to the file following
16157  * the string data. The total number of bytes written is returned in the
16158  * cnt parameter.
16159  *
16160  * \param _handle The file handle.
16161  * \param _str The string to write to the file.
16162  * \param _cnt The number of bytes actually written to the file.
16163  * \param _result The function call result. See \ref LoaderErrors.
16164  */
16165 #define WriteLnString(_handle, _str, _cnt, _result) __writeLnString(_handle, _str, _cnt, _result)
16166 
16167 /**
16168  * Write bytes to file.
16169  * Write the contents of the data array to the file associated with the
16170  * specified handle. The handle parameter must be a variable. The cnt
16171  * parameter must be a variable. The data parameter must be a byte array. The
16172  * actual number of bytes written is returned in the cnt parameter.
16173  *
16174  * \param _handle The file handle.
16175  * \param _buf The byte array or string containing the data to write.
16176  * \param _cnt The number of bytes actually written to the file.
16177  * \param _result The function call result. See \ref LoaderErrors.
16178  */
16179 #define WriteBytes(_handle, _buf, _cnt, _result) __writeBytes(_handle, _buf, _cnt, _result)
16180 
16181 /**
16182  * Write bytes to a file with limit.
16183  * Write the specified number of bytes to the file associated with the
16184  * specified handle. The handle parameter must be a variable. The len
16185  * parameter must be a variable. The buf parameter must be a byte array or a
16186  * string variable or string constant. The actual number of bytes written is
16187  * returned in the len parameter.
16188  *
16189  * \param _handle The file handle.
16190  * \param _len The maximum number of bytes to write on input.  Returns the
16191  * actual number of bytes written.
16192  * \param _buf The byte array or string containing the data to write.
16193  * \param _result The function call result. See \ref LoaderErrors.
16194  */
16195 #define WriteBytesEx(_handle, _len, _buf, _result) __writeBytesEx(_handle, _len, _buf, _result)
16196 
16197 /** @} */ // end of LoaderModuleFunctions group
16198 /** @} */ // end of LoaderModule group
16199 /** @} */ // end of NXTFirmwareModules group
16200 
16201 /** @addtogroup StandardCAPIFunctions
16202  * @{
16203  */
16204 
16205 /** @defgroup cstdlibAPI cstdlib API
16206  * Standard C cstdlib API functions.
16207  * @{
16208  */
16209 
16210 /**
16211  * Generate an unsigned random number.
16212  * Return an unsigned 16-bit random number. The
16213  * returned value will range between 0 and n (exclusive).
16214  *
16215  * \param _arg An unsigned random number.
16216  * \param _max The maximum unsigned value desired.
16217  */
16218 #define Random(_arg,_max) __Random(_arg,_max)
16219 
16220 /**
16221  * Generate signed random number.
16222  * Return a signed 16-bit random number.
16223  *
16224  * \param _arg A signed random number
16225  */
16226 #define SignedRandom(_arg) __SignedRandom(_arg)
16227 
16228 /** @} */ // end of cstdlibAPI group
16229 
16230 /** @defgroup cmathAPI cmath API
16231  * Standard C cmath API functions.
16232  * @{
16233  */
16234 
16235 /**
16236  * Convert from BCD to decimal
16237  * Return the decimal equivalent of the binary coded decimal value provided.
16238  *
16239  * \param _bcd The value you want to convert from bcd to decimal.
16240  * \param _result The decimal equivalent of the binary coded decimal byte.
16241  */
16242 #define bcd2dec(_bcd, _result) __bcd2dec(_bcd, _result)
16243 
16244 /** @} */ // end of cmathAPI group
16245 /** @} */ // end of StandardCAPIFunctions group
16246 
16247 
16248 /** @addtogroup ThirdPartyDevices
16249  * @{
16250  */
16251 
16252 ///////////////////////////////////////////////////////////////////////////////
16253 //////////////////////////////// HiTechnic API ////////////////////////////////
16254 ///////////////////////////////////////////////////////////////////////////////
16255 
16256 
16257 /** @addtogroup HiTechnicAPI
16258  * @{
16259  */
16260 
16261 /**
16262  * Set sensor as HiTechnic Gyro.
16263  * Configure the sensor on the specified port as a HiTechnic Gyro sensor.
16264  *
16265  * \param _port The sensor port. See \ref NBCInputPortConstants.
16266  */
16267 #define SetSensorHTGyro(_port) __SetSensorHTGyro(_port)
16268 
16269 /**
16270  * Read HiTechnic Gyro sensor.
16271  * Read the HiTechnic Gyro sensor on the specified port. The offset value
16272  * should be calculated by averaging several readings with an offset of zero
16273  * while the sensor is perfectly still.
16274  *
16275  * \param _p The sensor port. See \ref NBCInputPortConstants.
16276  * \param _offset The zero offset.
16277  * \param _val The Gyro sensor reading.
16278  */
16279 #define ReadSensorHTGyro(_p, _offset, _val) __ReadSensorHTGyro(_p, _offset, _val)
16280 
16281 /**
16282  * Set sensor as HiTechnic Magnet.
16283  * Configure the sensor on the specified port as a HiTechnic Magnet sensor.
16284  *
16285  * \param _port The sensor port. See \ref NBCInputPortConstants.
16286  */
16287 #define SetSensorHTMagnet(_port) __SetSensorHTGyro(_port)
16288 
16289 /**
16290  * Read HiTechnic Magnet sensor.
16291  * Read the HiTechnic Magnet sensor on the specified port. The offset value
16292  * should be calculated by averaging several readings with an offset of zero
16293  * while the sensor is perfectly still.
16294  *
16295  * \param _p The sensor port. See \ref NBCInputPortConstants.
16296  * \param _offset The zero offset.
16297  * \param _val The Magnet sensor reading.
16298  */
16299 #define ReadSensorHTMagnet(_p, _offset, _val) __ReadSensorHTGyro(_p, _offset, _val)
16300 
16301 /**
16302  * Set sensor as HiTechnic EOPD.
16303  * Configure the sensor on the specified port as a HiTechnic EOPD sensor.
16304  *
16305  * \param _port The sensor port. See \ref NBCInputPortConstants.
16306  * \param _bStd Configure in standard or long-range mode.
16307  */
16308 #define SetSensorHTEOPD(_port, _bStd) __SetSensorHTEOPD(_port, _bStd)
16309 
16310 /**
16311  * Read HiTechnic EOPD sensor.
16312  * Read the HiTechnic EOPD sensor on the specified port.
16313  *
16314  * \param _port The sensor port. See \ref NBCInputPortConstants.
16315  * \param _val The EOPD sensor reading.
16316  */
16317 #define ReadSensorHTEOPD(_port, _val) __ReadSensorHTEOPD(_port, _val)
16318 
16319 /**
16320  * Read HiTechnic touch multiplexer.
16321  * Read touch sensor values from the HiTechnic touch multiplexer device.
16322  *
16323  * \param _p The sensor port. See \ref NBCInputPortConstants.
16324  * \param _t1 The value of touch sensor 1.
16325  * \param _t2 The value of touch sensor 2.
16326  * \param _t3 The value of touch sensor 3.
16327  * \param _t4 The value of touch sensor 4.
16328  */
16329 #define ReadSensorHTTouchMultiplexer(_p, _t1, _t2, _t3, _t4) __ReadSensorHTTouchMultiplexer(_p, _t1, _t2, _t3, _t4)
16330 
16331 /**
16332  * HTPowerFunctionCommand function.
16333  * Execute a pair of Power Function motor commands on the specified channel
16334  * using the HiTechnic iRLink device. Commands for outa and outb are
16335  * \ref PF_CMD_STOP, \ref PF_CMD_REV, \ref PF_CMD_FWD, and \ref PF_CMD_BRAKE.
16336  * Valid channels are \ref PF_CHANNEL_1 through \ref PF_CHANNEL_4. The port
16337  * must be configured as a Lowspeed port before using this function.
16338  *
16339  * \param _port The sensor port. See \ref NBCInputPortConstants.
16340  * \param _channel The Power Function channel.  See \ref PFChannelConstants.
16341  * \param _outa The Power Function command for output A. See \ref PFCmdConstants.
16342  * \param _outb The Power Function command for output B. See \ref PFCmdConstants.
16343  * \param _result The function call result. \ref NO_ERR or \ref CommandCommErrors.
16344  */
16345 #define HTPowerFunctionCommand(_port, _channel, _outa, _outb, _result) \
16346   __HTPFComboDirect(_port, _channel, _outa, _outb, _result)
16347 
16348 /**
16349  * HTIRTrain function.
16350  * Control an IR Train receiver set to the specified channel using the
16351  * HiTechnic iRLink device. Valid func values are \ref TRAIN_FUNC_STOP,
16352  * \ref TRAIN_FUNC_INCR_SPEED, \ref TRAIN_FUNC_DECR_SPEED, and \ref TRAIN_FUNC_TOGGLE_LIGHT.
16353  * Valid channel values are \ref TRAIN_CHANNEL_1 through \ref TRAIN_CHANNEL_3 and
16354  * \ref TRAIN_CHANNEL_ALL. The port must be configured as a Lowspeed port before
16355  * using this function.
16356  *
16357  * \param _port The sensor port. See \ref NBCInputPortConstants.
16358  * \param _channel The IR Train channel.  See \ref IRTrainChannels.
16359  * \param _func The IR Train function. See \ref IRTrainFuncs
16360  * \param _result The function call result. \ref NO_ERR or \ref CommandCommErrors.
16361  */
16362 #define HTIRTrain(_port, _channel, _func, _result) \
16363   __HTIRTrain(_port, _channel, _func, FALSE, _result)
16364 
16365 /**
16366  * HTPFComboDirect function.
16367  * Execute a pair of Power Function motor commands on the specified channel
16368  * using the HiTechnic iRLink device. Commands for outa and outb are
16369  * \ref PF_CMD_STOP, \ref PF_CMD_REV, \ref PF_CMD_FWD, and \ref PF_CMD_BRAKE. Valid channels are
16370  * \ref PF_CHANNEL_1 through \ref PF_CHANNEL_4. The port must be configured as a
16371  * Lowspeed port before using this function.
16372  *
16373  * \param _port The sensor port. See \ref NBCInputPortConstants.
16374  * \param _channel The Power Function channel.  See \ref PFChannelConstants.
16375  * \param _outa The Power Function command for output A. See \ref PFCmdConstants.
16376  * \param _outb The Power Function command for output B. See \ref PFCmdConstants.
16377  * \param _result The function call result. \ref NO_ERR or \ref CommandCommErrors.
16378  */
16379 #define HTPFComboDirect(_port, _channel, _outa, _outb, _result) \
16380   __HTPFComboDirect(_port, _channel, _outa, _outb, _result)
16381 
16382 /**
16383  * HTPFComboPWM function.
16384  * Control the speed of both outputs on a Power Function receiver set to the
16385  * specified channel using the HiTechnic iRLink device. Valid output values
16386  * are \ref PF_PWM_FLOAT, \ref PF_PWM_FWD1, \ref PF_PWM_FWD2, \ref PF_PWM_FWD3, \ref PF_PWM_FWD4,
16387  * \ref PF_PWM_FWD5, \ref PF_PWM_FWD6, \ref PF_PWM_FWD7, \ref PF_PWM_BRAKE, \ref PF_PWM_REV7,
16388  * \ref PF_PWM_REV6, \ref PF_PWM_REV5, \ref PF_PWM_REV4, \ref PF_PWM_REV3, \ref PF_PWM_REV2, and
16389  * \ref PF_PWM_REV1. Valid channels are \ref PF_CHANNEL_1 through \ref PF_CHANNEL_4. The
16390  * port must be configured as a Lowspeed port before using this function.
16391  *
16392  * \param _port The sensor port. See \ref NBCInputPortConstants.
16393  * \param _channel The Power Function channel.  See \ref PFChannelConstants.
16394  * \param _outa The Power Function PWM command for output A. See \ref PFPWMOptions.
16395  * \param _outb The Power Function PWM command for output B. See \ref PFPWMOptions.
16396  * \param _result The function call result. \ref NO_ERR or \ref CommandCommErrors.
16397  */
16398 #define HTPFComboPWM(_port, _channel, _outa, _outb, _result) \
16399   __HTPFComboPWM(_port, _channel, _outa, _outb, _result)
16400 
16401 /**
16402  * HTPFRawOutput function.
16403  * Control a Power Function receiver set to the specified channel using the
16404  * HiTechnic iRLink device. Build the raw data stream using the 3 nibbles
16405  * (4 bit values). The port must be configured as a Lowspeed port before using
16406  * this function.
16407  *
16408  * \param _port The sensor port. See \ref NBCInputPortConstants.
16409  * \param _nibble0 The first raw data nibble.
16410  * \param _nibble1 The second raw data nibble.
16411  * \param _nibble2 The third raw data nibble.
16412  * \param _result The function call result. \ref NO_ERR or \ref CommandCommErrors.
16413  */
16414 #define HTPFRawOutput(_port, _nibble0, _nibble1, _nibble2, _result) \
16415   __HTPFRawOutput(_port, _nibble0, _nibble1, _nibble2, _result)
16416 
16417 /**
16418  * HTPFRepeat function.
16419  * Repeat sending the last Power Function command using the HiTechnic
16420  * IRLink device. Specify the number of times to repeat the command and the
16421  * number of milliseconds of delay between each repetition. The port must be
16422  * configured as a Lowspeed port before using this function.
16423  *
16424  * \param _port The sensor port. See \ref NBCInputPortConstants.
16425  * \param _count The number of times to repeat the command.
16426  * \param _delay The number of milliseconds to delay between each repetition.
16427  * \param _result The function call result. \ref NO_ERR or \ref CommandCommErrors.
16428  */
16429 #define HTPFRepeat(_port, _count, _delay, _result) \
16430   __HTPFRepeatLastCommand(_port, _count, _delay, _result)
16431 
16432 /**
16433  * HTPFSingleOutputCST function.
16434  * Control a single output on a Power Function receiver set to the specified
16435  * channel using the HiTechnic iRLink device. Select the desired output
16436  * using \ref PF_OUT_A or \ref PF_OUT_B. Valid functions are \ref PF_CST_CLEAR1_CLEAR2,
16437  * \ref PF_CST_SET1_CLEAR2, \ref PF_CST_CLEAR1_SET2, \ref PF_CST_SET1_SET2,
16438  * \ref PF_CST_INCREMENT_PWM, \ref PF_CST_DECREMENT_PWM, \ref PF_CST_FULL_FWD,
16439  * \ref PF_CST_FULL_REV, and \ref PF_CST_TOGGLE_DIR. Valid channels are
16440  * \ref PF_CHANNEL_1 through \ref PF_CHANNEL_4. The port must be configured as a
16441  * Lowspeed port before using this function.
16442  *
16443  * \param _port The sensor port. See \ref NBCInputPortConstants.
16444  * \param _channel The Power Function channel.  See \ref PFChannelConstants.
16445  * \param _out The Power Function output. See \ref PFOutputs.
16446  * \param _func The Power Function CST function. See \ref PFCSTOptions.
16447  * \param _result The function call result. \ref NO_ERR or \ref CommandCommErrors.
16448  */
16449 #define HTPFSingleOutputCST(_port, _channel, _out, _func, _result) \
16450   __HTPFSingleOutput(_port, _channel, _out, _func, TRUE, _result)
16451 
16452 /**
16453  * HTPFSingleOutputPWM function.
16454  * Control the speed of a single output on a Power Function receiver set to
16455  * the specified channel using the HiTechnic iRLink device. Select the
16456  * desired output using \ref PF_OUT_A or \ref PF_OUT_B. Valid functions are
16457  * \ref PF_PWM_FLOAT, \ref PF_PWM_FWD1, \ref PF_PWM_FWD2, \ref PF_PWM_FWD3, \ref PF_PWM_FWD4,
16458  * \ref PF_PWM_FWD5, \ref PF_PWM_FWD6, \ref PF_PWM_FWD7, \ref PF_PWM_BRAKE, \ref PF_PWM_REV7,
16459  * \ref PF_PWM_REV6, \ref PF_PWM_REV5, \ref PF_PWM_REV4, \ref PF_PWM_REV3, \ref PF_PWM_REV2, and
16460  * \ref PF_PWM_REV1. Valid channels are \ref PF_CHANNEL_1 through \ref PF_CHANNEL_4. The
16461  * port must be configured as a Lowspeed port before using this function.
16462  *
16463  * \param _port The sensor port. See \ref NBCInputPortConstants.
16464  * \param _channel The Power Function channel.  See \ref PFChannelConstants.
16465  * \param _out The Power Function output. See \ref PFOutputs.
16466  * \param _func The Power Function PWM function. See \ref PFPWMOptions.
16467  * \param _result The function call result. \ref NO_ERR or \ref CommandCommErrors.
16468  */
16469 #define HTPFSingleOutputPWM(_port, _channel, _out, _func, _result) \
16470   __HTPFSingleOutput(_port, _channel, _out, _func, FALSE, _result)
16471 
16472 /**
16473  * HTPFSinglePin function.
16474  * Control a single pin on a Power Function receiver set to the specified
16475  * channel using the HiTechnic iRLink device. Select the desired output
16476  * using \ref PF_OUT_A or \ref PF_OUT_B.  Select the desired pin using \ref PF_PIN_C1 or
16477  * \ref PF_PIN_C2. Valid functions are \ref PF_FUNC_NOCHANGE, \ref PF_FUNC_CLEAR,
16478  * \ref PF_FUNC_SET, and \ref PF_FUNC_TOGGLE. Valid channels are \ref PF_CHANNEL_1 through
16479  * \ref PF_CHANNEL_4. Specify whether the mode by passing true (continuous) or
16480  * false (timeout) as the final parameter. The port must be configured as a
16481  * Lowspeed port before using this function.
16482  *
16483  * \param _port The sensor port. See \ref NBCInputPortConstants.
16484  * \param _channel The Power Function channel.  See \ref PFChannelConstants.
16485  * \param _out The Power Function output. See \ref PFOutputs.
16486  * \param _pin The Power Function pin. See \ref PFPinConstants.
16487  * \param _func The Power Function single pin function. See \ref PFPinFuncs.
16488  * \param _cont Control whether the mode is continuous or timeout.
16489  * \param _result The function call result. \ref NO_ERR or \ref CommandCommErrors.
16490  */
16491 #define HTPFSinglePin(_port, _channel, _out, _pin, _func, _cont, _result) \
16492   __HTPFSinglePin(_port, _channel, _out, _pin, _func, _cont, _result)
16493 
16494 /**
16495  * HTPFTrain function.
16496  * Control both outputs on a Power Function receiver set to the specified
16497  * channel using the HiTechnic iRLink device as if it were an IR Train
16498  * receiver. Valid function values are \ref TRAIN_FUNC_STOP, \ref TRAIN_FUNC_INCR_SPEED,
16499  * \ref TRAIN_FUNC_DECR_SPEED, and \ref TRAIN_FUNC_TOGGLE_LIGHT. Valid channels are
16500  * \ref PF_CHANNEL_1 through \ref PF_CHANNEL_4. The port must be configured as a
16501  * Lowspeed port before using this function.
16502  *
16503  * \param _port The sensor port. See \ref NBCInputPortConstants.
16504  * \param _channel The Power Function channel.  See \ref PFChannelConstants.
16505  * \param _func The Power Function train function. See \ref IRTrainFuncs.
16506  * \param _result The function call result. \ref NO_ERR or \ref CommandCommErrors.
16507  */
16508 #define HTPFTrain(_port, _channel, _func, _result) \
16509   __HTIRTrain(_port, _channel, _func, TRUE, _result)
16510 
16511 /**
16512  * HTRCXSetIRLinkPort function.
16513  * Set the global port in advance of using the HTRCX* and HTScout* API
16514  * functions for sending RCX and Scout messages over the HiTechnic iRLink
16515  * device. The port must be configured as a Lowspeed port before using any of
16516  * the HiTechnic RCX and Scout iRLink functions.
16517  *
16518  * \param _port The sensor port. See \ref NBCInputPortConstants.
16519  */
16520 #define HTRCXSetIRLinkPort(_port) __HTRCXSetIRLinkPort(_port)
16521 
16522 /**
16523  * HTRCXBatteryLevel function.
16524  * Send the BatteryLevel command to an RCX to read the current battery level.
16525  *
16526  * \param _result The RCX battery level.
16527  */
16528 #define HTRCXBatteryLevel(_result) __HTRCXBatteryLevel(_result)
16529 
16530 /**
16531  * HTRCXPoll function
16532  * Send the Poll command to an RCX to read a signed 2-byte value at the
16533  * specified source and value combination.
16534  *
16535  * \param _src The RCX source.  See \ref RCXSourceConstants.
16536  * \param _value The RCX value.
16537  * \param _result The value read from the specified port and value.
16538  */
16539 #define HTRCXPoll(_src, _value, _result) __HTRCXPoll(_src, _value, _result)
16540 
16541 /**
16542  * HTRCXPollMemory function.
16543  * Send the PollMemory command to an RCX.
16544  *
16545  * \param _memaddress The RCX memory address.
16546  * \param _result The value read from the specified address.
16547  */
16548 #define HTRCXPollMemory(_memaddress, _result) __HTRCXPollMemory(_memaddress, _result)
16549 
16550 /**
16551  * HTRCXAddToDatalog function.
16552  * Send the AddToDatalog command to an RCX.
16553  *
16554  * \param _src The RCX source.  See \ref RCXSourceConstants.
16555  * \param _value The RCX value.
16556  */
16557 #define HTRCXAddToDatalog(_src, _value) __HTRCXAddToDatalog(_src, _value)
16558 
16559 /**
16560  * HTRCXClearAllEvents function.
16561  * Send the ClearAllEvents command to an RCX.
16562  */
16563 #define HTRCXClearAllEvents() __HTRCXOpNoArgs(RCX_ClearAllEventsOp)
16564 
16565 /**
16566  * HTRCXClearCounter function.
16567  * Send the ClearCounter command to an RCX.
16568  *
16569  * \param _counter The counter to clear.
16570  */
16571 #define HTRCXClearCounter(_counter) __HTRCXClearCounter(_counter)
16572 
16573 /**
16574  * HTRCXClearMsg function.
16575  * Send the ClearMsg command to an RCX.
16576  */
16577 #define HTRCXClearMsg() __HTRCXOpNoArgs(RCX_ClearMsgOp)
16578 
16579 /**
16580  * HTRCXClearSensor function.
16581  * Send the ClearSensor command to an RCX.
16582  *
16583  * \param _port The RCX port number.
16584  */
16585 #define HTRCXClearSensor(_port) __HTRCXClearSensor(_port)
16586 
16587 /**
16588  * HTRCXClearSound function.
16589  * Send the ClearSound command to an RCX.
16590  */
16591 #define HTRCXClearSound() __HTRCXOpNoArgs(RCX_ClearSoundOp)
16592 
16593 /**
16594  * HTRCXClearTimer function.
16595  * Send the ClearTimer command to an RCX.
16596  *
16597  * \param _timer The timer to clear.
16598  */
16599 #define HTRCXClearTimer(_timer) __HTRCXClearTimer(_timer)
16600 
16601 /**
16602  * HTRCXCreateDatalog function.
16603  * Send the CreateDatalog command to an RCX.
16604  *
16605  * \param _size The new datalog size.
16606  */
16607 #define HTRCXCreateDatalog(_size) __HTRCXCreateDatalog(_size)
16608 
16609 /**
16610  * HTRCXDecCounter function.
16611  * Send the DecCounter command to an RCX.
16612  *
16613  * \param _counter The counter to decrement.
16614  */
16615 #define HTRCXDecCounter(_counter) __HTRCXDecCounter(_counter)
16616 
16617 /**
16618  * HTRCXDeleteSub function.
16619  * Send the DeleteSub command to an RCX.
16620  *
16621  * \param _s The subroutine number to delete.
16622  */
16623 #define HTRCXDeleteSub(_s) __HTRCXDeleteSub(_s)
16624 
16625 /**
16626  * HTRCXDeleteSubs function.
16627  * Send the DeleteSubs command to an RCX.
16628  */
16629 #define HTRCXDeleteSubs() __HTRCXOpNoArgs(RCX_DeleteSubsOp)
16630 
16631 /**
16632  * HTRCXDeleteTask function.
16633  * Send the DeleteTask command to an RCX.
16634  *
16635  * \param _t The task number to delete.
16636  */
16637 #define HTRCXDeleteTask(_t) __HTRCXDeleteTask(_t)
16638 
16639 /**
16640  * HTRCXDeleteTasks function.
16641  * Send the DeleteTasks command to an RCX.
16642  */
16643 #define HTRCXDeleteTasks() __HTRCXOpNoArgs(RCX_DeleteTasksOp)
16644 
16645 /**
16646  * HTRCXDisableOutput function.
16647  * Send the DisableOutput command to an RCX.
16648  *
16649  * \param _outputs The RCX output(s) to disable. See \ref RCXOutputConstants.
16650  */
16651 #define HTRCXDisableOutput(_outputs) __HTRCXSetGlobalOutput(_outputs, RCX_OUT_OFF)
16652 
16653 /**
16654  * HTRCXEnableOutput function.
16655  * Send the EnableOutput command to an RCX.
16656  *
16657  * \param _outputs The RCX output(s) to enable. See \ref RCXOutputConstants.
16658  */
16659 #define HTRCXEnableOutput(_outputs) __HTRCXSetGlobalOutput(_outputs, RCX_OUT_ON)
16660 
16661 /**
16662  * HTRCXEvent function.
16663  * Send the Event command to an RCX.
16664  *
16665  * \param _src The RCX source.  See \ref RCXSourceConstants.
16666  * \param _value The RCX value.
16667  */
16668 #define HTRCXEvent(_src, _value) __HTRCXEvent(_src, _value)
16669 
16670 /**
16671  * HTRCXFloat function.
16672  * Send commands to an RCX to float the specified outputs.
16673  *
16674  * \param _outputs The RCX output(s) to float. See \ref RCXOutputConstants.
16675  */
16676 #define HTRCXFloat(_outputs) __HTRCXSetOutput(_outputs, RCX_OUT_FLOAT)
16677 
16678 /**
16679  * HTRCXFwd function.
16680  * Send commands to an RCX to set the specified outputs to the forward direction.
16681  *
16682  * \param _outputs The RCX output(s) to set forward. See \ref RCXOutputConstants.
16683  */
16684 #define HTRCXFwd(_outputs) __HTRCXSetDirection(_outputs, RCX_OUT_FWD)
16685 
16686 /**
16687  * HTRCXIncCounter function.
16688  * Send the IncCounter command to an RCX.
16689  *
16690  * \param _counter The counter to increment.
16691  */
16692 #define HTRCXIncCounter(_counter) __HTRCXIncCounter(_counter)
16693 
16694 /**
16695  * HTRCXInvertOutput function.
16696  * Send the InvertOutput command to an RCX.
16697  *
16698  * \param _outputs The RCX output(s) to invert. See \ref RCXOutputConstants.
16699  */
16700 #define HTRCXInvertOutput(_outputs) __HTRCXSetGlobalDirection(_outputs, RCX_OUT_REV)
16701 
16702 /**
16703  * HTRCXMuteSound function.
16704  * Send the MuteSound command to an RCX.
16705  */
16706 #define HTRCXMuteSound() __HTRCXOpNoArgs(RCX_MuteSoundOp)
16707 
16708 /**
16709  * HTRCXObvertOutput function.
16710  * Send the ObvertOutput command to an RCX.
16711  *
16712  * \param _outputs The RCX output(s) to obvert. See \ref RCXOutputConstants.
16713  */
16714 #define HTRCXObvertOutput(_outputs) __HTRCXSetGlobalDirection(_outputs, RCX_OUT_FWD)
16715 
16716 /**
16717  * HTRCXOff function.
16718  * Send commands to an RCX to turn off the specified outputs.
16719  *
16720  * \param _outputs The RCX output(s) to turn off. See \ref RCXOutputConstants.
16721  */
16722 #define HTRCXOff(_outputs) __HTRCXSetOutput(_outputs, RCX_OUT_OFF)
16723 
16724 /**
16725  * HTRCXOn function.
16726  * Send commands to an RCX to turn on the specified outputs.
16727  *
16728  * \param _outputs The RCX output(s) to turn on. See \ref RCXOutputConstants.
16729  */
16730 #define HTRCXOn(_outputs) __HTRCXSetOutput(_outputs, RCX_OUT_ON)
16731 
16732 /**
16733  * HTRCXOnFor function.
16734  * Send commands to an RCX to turn on the specified outputs in the forward
16735  * direction for the specified duration.
16736  *
16737  * \param _outputs The RCX output(s) to turn on. See \ref RCXOutputConstants.
16738  * \param _ms The number of milliseconds to leave the outputs on
16739  */
16740 #define HTRCXOnFor(_outputs, _ms) __HTRCXOnFor(_outputs, _ms)
16741 
16742 /**
16743  * HTRCXOnFwd function.
16744  * Send commands to an RCX to turn on the specified outputs in the forward
16745  * direction.
16746  *
16747  * \param _outputs The RCX output(s) to turn on in the forward direction. See \ref RCXOutputConstants.
16748  */
16749 #define HTRCXOnFwd(_outputs) __HTRCXOnFwd(_outputs)
16750 
16751 /**
16752  * HTRCXOnRev function.
16753  * Send commands to an RCX to turn on the specified outputs in the reverse direction.
16754  *
16755  * \param _outputs The RCX output(s) to turn on in the reverse direction. See \ref RCXOutputConstants.
16756  */
16757 #define HTRCXOnRev(_outputs) __HTRCXOnRev(_outputs)
16758 
16759 /**
16760  * HTRCXPBTurnOff function.
16761  * Send the PBTurnOff command to an RCX.
16762  */
16763 #define HTRCXPBTurnOff() __HTRCXOpNoArgs(RCX_PBTurnOffOp)
16764 
16765 /**
16766  * HTRCXPing function.
16767  * Send the Ping command to an RCX.
16768  */
16769 #define HTRCXPing() __HTRCXOpNoArgs(RCX_PingOp)
16770 
16771 /**
16772  * HTRCXPlaySound function.
16773  * Send the PlaySound command to an RCX.
16774  *
16775  * \param _snd The sound number to play.
16776  */
16777 #define HTRCXPlaySound(_snd) __HTRCXPlaySound(_snd)
16778 
16779 /**
16780  * HTRCXPlayTone function.
16781  * Send the PlayTone command to an RCX.
16782  *
16783  * \param _freq The frequency of the tone to play.
16784  * \param _duration The duration of the tone to play.
16785  */
16786 #define HTRCXPlayTone(_freq, _duration) __HTRCXPlayTone(_freq, _duration)
16787 
16788 /**
16789  * HTRCXPlayToneVar function.
16790  * Send the PlayToneVar command to an RCX.
16791  *
16792  * \param _varnum The variable containing the tone frequency to play.
16793  * \param _duration The duration of the tone to play.
16794  */
16795 #define HTRCXPlayToneVar(_varnum, _duration) __HTRCXPlayToneVar(_varnum, _duration)
16796 
16797 /**
16798  * HTRCXRemote function.
16799  * Send the Remote command to an RCX.
16800  *
16801  * \param _cmd The RCX IR remote command to send. See \ref RCXRemoteConstants.
16802  */
16803 #define HTRCXRemote(_cmd) __HTRCXRemote(_cmd)
16804 
16805 /**
16806  * HTRCXRev function.
16807  * Send commands to an RCX to set the specified outputs to the reverse direction.
16808  *
16809  * \param _outputs The RCX output(s) to reverse direction. See \ref RCXOutputConstants.
16810  */
16811 #define HTRCXRev(_outputs) __HTRCXSetDirection(_outputs, RCX_OUT_REV)
16812 
16813 /**
16814  * HTRCXSelectDisplay function.
16815  * Send the SelectDisplay command to an RCX.
16816  *
16817  * \param _src The RCX source.  See \ref RCXSourceConstants.
16818  * \param _value The RCX value.
16819  */
16820 #define HTRCXSelectDisplay(_src, _value) __HTRCXSelectDisplay(_src, _value)
16821 
16822 /**
16823  * HTRCXSelectProgram function.
16824  * Send the SelectProgram command to an RCX.
16825  *
16826  * \param _prog The program number to select.
16827  */
16828 #define HTRCXSelectProgram(_prog) __HTRCXSelectProgram(_prog)
16829 
16830 /**
16831  * HTRCXSendSerial function.
16832  * Send the SendSerial command to an RCX.
16833  *
16834  * \param _first The first byte address.
16835  * \param _count The number of bytes to send.
16836  */
16837 #define HTRCXSendSerial(_first, _count) __HTRCXSendSerial(_first, _count)
16838 
16839 /**
16840  * HTRCXSetDirection function.
16841  * Send the SetDirection command to an RCX to configure the direction of the specified outputs.
16842  *
16843  * \param _outputs The RCX output(s) to set direction. See \ref RCXOutputConstants.
16844  * \param _dir The RCX output direction. See \ref RCXOutputDirection.
16845  */
16846 #define HTRCXSetDirection(_outputs, _dir) __HTRCXSetDirection(_outputs, _dir)
16847 
16848 /**
16849  * HTRCXSetEvent function.
16850  * Send the SetEvent command to an RCX.
16851  *
16852  * \param _evt The event number to set.
16853  * \param _src The RCX source. See \ref RCXSourceConstants.
16854  * \param _type The event type.
16855  */
16856 #define HTRCXSetEvent(_evt, _src, _type) __HTRCXSetEvent(_evt, _src, _type)
16857 
16858 /**
16859  * HTRCXSetGlobalDirection function.
16860  * Send the SetGlobalDirection command to an RCX.
16861  *
16862  * \param _outputs The RCX output(s) to set global direction. See \ref RCXOutputConstants.
16863  * \param _dir The RCX output direction. See \ref RCXOutputDirection.
16864  */
16865 #define HTRCXSetGlobalDirection(_outputs, _dir) __HTRCXSetGlobalDirection(_outputs, _dir)
16866 
16867 /**
16868  * HTRCXSetGlobalOutput function.
16869  * Send the SetGlobalOutput command to an RCX.
16870  *
16871  * \param _outputs The RCX output(s) to set global mode. See \ref RCXOutputConstants.
16872  * \param _mode The RCX output mode. See \ref RCXOutputMode.
16873  */
16874 #define HTRCXSetGlobalOutput(_outputs, _mode) __HTRCXSetGlobalOutput(_outputs, _mode)
16875 
16876 /**
16877  * HTRCXSetMaxPower function.
16878  * Send the SetMaxPower command to an RCX.
16879  *
16880  * \param _outputs The RCX output(s) to set max power. See \ref RCXOutputConstants.
16881  * \param _pwrsrc The RCX source.  See \ref RCXSourceConstants.
16882  * \param _pwrval The RCX value.
16883  */
16884 #define HTRCXSetMaxPower(_outputs, _pwrsrc, _pwrval) __HTRCXSetMaxPower(_outputs, _pwrsrc, _pwrval)
16885 
16886 /**
16887  * HTRCXSetMessage function.
16888  * Send the SetMessage command to an RCX.
16889  *
16890  * \param _msg The numeric message to send.
16891  */
16892 #define HTRCXSetMessage(_msg) __HTRCXSetMessage(_msg)
16893 
16894 /**
16895  * HTRCXSetOutput function.
16896  * Send the SetOutput command to an RCX to configure the mode of the specified outputs
16897  *
16898  * \param _outputs The RCX output(s) to set mode. See \ref RCXOutputConstants.
16899  * \param _mode The RCX output mode. See \ref RCXOutputMode.
16900  */
16901 #define HTRCXSetOutput(_outputs, _mode) __HTRCXSetOutput(_outputs, _mode)
16902 
16903 /**
16904  * HTRCXSetPower function.
16905  * Send the SetPower command to an RCX to configure the power level of the specified outputs.
16906  *
16907  * \param _outputs The RCX output(s) to set power. See \ref RCXOutputConstants.
16908  * \param _pwrsrc The RCX source.  See \ref RCXSourceConstants.
16909  * \param _pwrval The RCX value.
16910  */
16911 #define HTRCXSetPower(_outputs, _pwrsrc, _pwrval) __HTRCXSetPower(_outputs, _pwrsrc, _pwrval)
16912 
16913 /**
16914  * HTRCXSetPriority function.
16915  * Send the SetPriority command to an RCX.
16916  *
16917  * \param _p The new task priority.
16918  */
16919 #define HTRCXSetPriority(_p) __HTRCXSetPriority(_p)
16920 
16921 /**
16922  * HTRCXSetSensorMode function.
16923  * Send the SetSensorMode command to an RCX.
16924  *
16925  * \param _port The RCX sensor port.
16926  * \param _mode The RCX sensor mode.
16927  */
16928 #define HTRCXSetSensorMode(_port, _mode) __HTRCXSetSensorMode(_port, _mode)
16929 
16930 /**
16931  * HTRCXSetSensorType function.
16932  * Send the SetSensorType command to an RCX.
16933  *
16934  * \param _port The RCX sensor port.
16935  * \param _type The RCX sensor type.
16936  */
16937 #define HTRCXSetSensorType(_port, _type) __HTRCXSetSensorType(_port, _type)
16938 
16939 /**
16940  * HTRCXSetSleepTime function.
16941  * Send the SetSleepTime command to an RCX.
16942  *
16943  * \param _t The new sleep time value.
16944  */
16945 #define HTRCXSetSleepTime(_t) __HTRCXSetSleepTime(_t)
16946 
16947 /**
16948  * HTRCXSetTxPower function.
16949  * Send the SetTxPower command to an RCX.
16950  *
16951  * \param _pwr The IR transmit power level.
16952  */
16953 #define HTRCXSetTxPower(_pwr) __HTRCXSetTxPower(_pwr)
16954 
16955 /**
16956  * HTRCXSetWatch function.
16957  * Send the SetWatch command to an RCX.
16958  *
16959  * \param _hours The new watch time hours value.
16960  * \param _minutes The new watch time minutes value.
16961  */
16962 #define HTRCXSetWatch(_hours, _minutes) __HTRCXSetWatch(_hours, _minutes)
16963 
16964 /**
16965  * HTRCXStartTask function.
16966  * Send the StartTask command to an RCX.
16967  *
16968  * \param _t The task number to start.
16969  */
16970 #define HTRCXStartTask(_t) __HTRCXStartTask(_t)
16971 
16972 /**
16973  * HTRCXStopAllTasks function.
16974  * Send the StopAllTasks command to an RCX.
16975  */
16976 #define HTRCXStopAllTasks() __HTRCXOpNoArgs(RCX_StopAllTasksOp)
16977 
16978 /**
16979  * HTRCXStopTask function.
16980  * Send the StopTask command to an RCX.
16981  *
16982  * \param _t The task number to stop.
16983  */
16984 #define HTRCXStopTask(_t) __HTRCXStopTask(_t)
16985 
16986 /**
16987  * HTRCXToggle function.
16988  * Send commands to an RCX to toggle the direction of the specified outputs.
16989  *
16990  * \param _outputs The RCX output(s) to toggle. See \ref RCXOutputConstants.
16991  */
16992 #define HTRCXToggle(_outputs) __HTRCXSetDirection(_outputs, RCX_OUT_TOGGLE)
16993 
16994 /**
16995  * HTRCXUnmuteSound function.
16996  * Send the UnmuteSound command to an RCX.
16997  */
16998 #define HTRCXUnmuteSound() __HTRCXOpNoArgs(RCX_UnmuteSoundOp)
16999 
17000 /**
17001  * HTScoutCalibrateSensor function.
17002  * Send the CalibrateSensor command to a Scout.
17003  */
17004 #define HTScoutCalibrateSensor() __HTRCXOpNoArgs(RCX_LSCalibrateOp)
17005 
17006 /**
17007  * HTScoutMuteSound function.
17008  * Send the MuteSound command to a Scout.
17009  */
17010 #define HTScoutMuteSound() __HTScoutMuteSound()
17011 
17012 /**
17013  * HTScoutSelectSounds function.
17014  * Send the SelectSounds command to a Scout.
17015  *
17016  * \param _grp The Scout sound group to select.
17017  */
17018 #define HTScoutSelectSounds(_grp) __HTScoutSelectSounds(_grp)
17019 
17020 /**
17021  * HTScoutSendVLL function.
17022  * Send the SendVLL command to a Scout.
17023  *
17024  * \param _src The Scout source.  See \ref RCXSourceConstants.
17025  * \param _value The Scout value.
17026  */
17027 #define HTScoutSendVLL(_src, _value) __HTScoutSendVLL(_src, _value)
17028 
17029 /**
17030  * HTScoutSetEventFeedback function.
17031  * Send the SetEventFeedback command to a Scout.
17032  *
17033  * \param _src The Scout source.  See \ref RCXSourceConstants.
17034  * \param _value The Scout value.
17035  */
17036 #define HTScoutSetEventFeedback(_src, _value) __HTScoutSetEventFeedback(_src, _value)
17037 
17038 /**
17039  * HTScoutSetLight function.
17040  * Send the SetLight command to a Scout.
17041  *
17042  * \param _x Set the light on or off using this value. See \ref ScoutLightConstants.
17043  */
17044 #define HTScoutSetLight(_x) __HTScoutSetLight(_x)
17045 
17046 /**
17047  * HTScoutSetScoutMode function.
17048  * Send the SetScoutMode command to a Scout.
17049  *
17050  * \param _mode Set the scout mode. See \ref ScoutModeConstants.
17051 */
17052 #define HTScoutSetScoutMode(_mode) __HTScoutSetScoutMode(_mode)
17053 
17054 /**
17055  * HTScoutSetSensorClickTime function.
17056  * Send the SetSensorClickTime command to a Scout.
17057  *
17058  * \param _src The Scout source.  See \ref RCXSourceConstants.
17059  * \param _value The Scout value.
17060  */
17061 #define HTScoutSetSensorClickTime(_src, _value) __HTScoutSetSensorClickTime(_src, _value)
17062 
17063 /**
17064  * HTScoutSetSensorHysteresis function.
17065  * Send the SetSensorHysteresis command to a Scout.
17066  *
17067  * \param _src The Scout source.  See \ref RCXSourceConstants.
17068  * \param _value The Scout value.
17069  */
17070 #define HTScoutSetSensorHysteresis(_src, _value) __HTScoutSetSensorHysteresis(_src, _value)
17071 
17072 /**
17073  * HTScoutSetSensorLowerLimit function.
17074  * Send the SetSensorLowerLimit command to a Scout.
17075  *
17076  * \param _src The Scout source.  See \ref RCXSourceConstants.
17077  * \param _value The Scout value.
17078  */
17079 #define HTScoutSetSensorLowerLimit(_src, _value) __HTScoutSetSensorLowerLimit(_src, _value)
17080 
17081 /**
17082  * HTScoutSetSensorUpperLimit function.
17083  * Send the SetSensorUpperLimit command to a Scout.
17084  *
17085  * \param _src The Scout source.  See \ref RCXSourceConstants.
17086  * \param _value The Scout value.
17087  */
17088 #define HTScoutSetSensorUpperLimit(_src, _value) __HTScoutSetSensorUpperLimit(_src, _value)
17089 
17090 /**
17091  * HTScoutUnmuteSound function.
17092  * Send the UnmuteSound command to a Scout.
17093  */
17094 #define HTScoutUnmuteSound() __HTScoutUnmuteSound()
17095 
17096 /**
17097  * Read HiTechnic compass.
17098  * Read the compass heading value of the HiTechnic Compass sensor on the
17099  * specified port. The port must be configured as a Lowspeed port before
17100  * using this function.
17101  *
17102  * \param _port The sensor port. See \ref NBCInputPortConstants.
17103  * \param _value The compass heading.
17104  */
17105 #define ReadSensorHTCompass(_port, _value) __ReadSensorHTCompass(_port, _value)
17106 
17107 /**
17108  * Read HiTechnic color sensor color number.
17109  * Read the color number from the HiTechnic Color sensor on the specified
17110  * port. The port must be configured as a Lowspeed port before using this
17111  * function.
17112  *
17113  * \param _port The sensor port. See \ref NBCInputPortConstants.
17114  * \param _value The color number.
17115  */
17116 #define ReadSensorHTColorNum(_port, _value) __ReadSensorHTColorNum(_port, _value)
17117 
17118 /**
17119  * Read HiTechnic IRSeeker direction.
17120  * Read the direction value of the HiTechnic IR Seeker on the specified
17121  * port. The port must be configured as a Lowspeed port before using this
17122  * function.
17123  *
17124  * \param _port The sensor port. See \ref NBCInputPortConstants.
17125  * \param _value The IRSeeker direction.
17126  */
17127 #define ReadSensorHTIRSeekerDir(_port, _value) __ReadSensorHTIRSeekerDir(_port, _value)
17128 
17129 /**
17130  * Read HiTechnic IRSeeker2 register.
17131  * Read a register value from the HiTechnic IR Seeker2 on the specified
17132  * port. The port must be configured as a Lowspeed port before using this
17133  * function.
17134  *
17135  * \param _port The sensor port. See \ref NBCInputPortConstants.
17136  * \param _reg The register address. See \ref HTIRSeeker2Constants.
17137  * \param _value The IRSeeker2 register value.
17138  */
17139 #define ReadSensorHTIRSeeker2Addr(_port, _reg, _value) __ReadSensorHTIRSeeker2Addr(_port, _reg, _value)
17140 
17141 /**
17142  * Read HiTechnic acceleration values.
17143  * Read X, Y, and Z axis acceleration values from the HiTechnic Accelerometer
17144  * sensor. Returns a boolean value indicating whether or not the operation
17145  * completed successfully. The port must be configured as a Lowspeed port
17146  * before using this function.
17147  *
17148  * \param _port The sensor port. See \ref NBCInputPortConstants.
17149  * \param _x The output x-axis acceleration.
17150  * \param _y The output y-axis acceleration.
17151  * \param _z The output z-axis acceleration.
17152  * \param _result The function call result.
17153  */
17154 #define ReadSensorHTAccel(_port, _x, _y, _z, _result) __ReadSensorHTAccel(_port, _x, _y, _z, _result)
17155 
17156 /**
17157  * Read HiTechnic Color values.
17158  * Read color number, red, green, and blue values from the HiTechnic Color
17159  * sensor. Returns a boolean value indicating whether or not the operation
17160  * completed successfully. The port must be configured as a Lowspeed port
17161  * before using this function.
17162  *
17163  * \param _port The sensor port. See \ref NBCInputPortConstants.
17164  * \param _ColorNum The output color number.
17165  * \param _Red The red color value.
17166  * \param _Green The green color value.
17167  * \param _Blue The blue color value.
17168  * \param _result The function call result.
17169  */
17170 #define ReadSensorHTColor(_port, _ColorNum, _Red, _Green, _Blue, _result) __ReadSensorHTColor(_port, _ColorNum, _Red, _Green, _Blue, _result)
17171 
17172 /**
17173  * Read HiTechnic Color raw values.
17174  * Read the raw red, green, and blue values from the HiTechnic Color sensor.
17175  * Returns a boolean value indicating whether or not the operation completed
17176  * successfully. The port must be configured as a Lowspeed port before using
17177  * this function.
17178  *
17179  * \param _port The sensor port. See \ref NBCInputPortConstants.
17180  * \param _Red The raw red color value.
17181  * \param _Green The raw green color value.
17182  * \param _Blue The raw blue color value.
17183  * \param _result The function call result.
17184  */
17185 #define ReadSensorHTRawColor(_port, _Red, _Green, _Blue, _result) __ReadSensorHTRawColor(_port, _Red, _Green, _Blue, _result)
17186 
17187 /**
17188  * Read HiTechnic Color normalized values.
17189  * Read the color index and the normalized red, green, and blue values from
17190  * the HiTechnic Color sensor. Returns a boolean value indicating whether or
17191  * not the operation completed successfully. The port must be configured as a
17192  * Lowspeed port before using this function.
17193  *
17194  * \param _port The sensor port. See \ref NBCInputPortConstants.
17195  * \param _ColorIdx The output color index.
17196  * \param _Red The normalized red color value.
17197  * \param _Green The normalized green color value.
17198  * \param _Blue The normalized blue color value.
17199  * \param _result The function call result.
17200  */
17201 #define ReadSensorHTNormalizedColor(_port, _ColorIdx, _Red, _Green, _Blue, _result) __ReadSensorHTNormalizedColor(_port, _ColorIdx, _Red, _Green, _Blue, _result)
17202 
17203 /**
17204  * Read HiTechnic IRSeeker values.
17205  * Read direction, and five signal strength values from the HiTechnic
17206  * IRSeeker sensor. Returns a boolean value indicating whether or not the
17207  * operation completed successfully. The port must be configured as a
17208  * Lowspeed port before using this function.
17209  *
17210  * \param _port The sensor port. See \ref NBCInputPortConstants.
17211  * \param _dir The direction.
17212  * \param _s1 The signal strength from sensor 1.
17213  * \param _s3 The signal strength from sensor 3.
17214  * \param _s5 The signal strength from sensor 5.
17215  * \param _s7 The signal strength from sensor 7.
17216  * \param _s9 The signal strength from sensor 9.
17217  * \param _result The function call result.
17218  */
17219 #define ReadSensorHTIRSeeker(_port, _dir, _s1, _s3, _s5, _s7, _s9, _result) __ReadSensorHTIRSeeker(_port, _dir, _s1, _s3, _s5, _s7, _s9, _result)
17220 
17221 /**
17222  * Read HiTechnic IRSeeker2 DC values.
17223  * Read direction, five signal strength, and average strength values from the
17224  * HiTechnic IRSeeker2 sensor. Returns a boolean value indicating whether or
17225  * not the operation completed successfully. The port must be configured as a
17226  * Lowspeed port before using this function.
17227  *
17228  * \param _port The sensor port. See \ref NBCInputPortConstants.
17229  * \param _dir The direction.
17230  * \param _s1 The signal strength from sensor 1.
17231  * \param _s3 The signal strength from sensor 3.
17232  * \param _s5 The signal strength from sensor 5.
17233  * \param _s7 The signal strength from sensor 7.
17234  * \param _s9 The signal strength from sensor 9.
17235  * \param _avg The average signal strength.
17236  * \param _result The function call result.
17237  */
17238 #define ReadSensorHTIRSeeker2DC(_port, _dir, _s1, _s3, _s5, _s7, _s9, _avg, _result) __ReadSensorHTIRSeeker2DC(_port, _dir, _s1, _s3, _s5, _s7, _s9, _avg, _result)
17239 
17240 /**
17241  * Read HiTechnic IRSeeker2 AC values.
17242  * Read direction, and five signal strength values from the HiTechnic
17243  * IRSeeker2 sensor in AC mode. Returns a boolean value indicating whether or
17244  * not the operation completed successfully. The port must be configured as a
17245  * Lowspeed port before using this function.
17246  *
17247  * \param _port The sensor port. See \ref NBCInputPortConstants.
17248  * \param _dir The direction.
17249  * \param _s1 The signal strength from sensor 1.
17250  * \param _s3 The signal strength from sensor 3.
17251  * \param _s5 The signal strength from sensor 5.
17252  * \param _s7 The signal strength from sensor 7.
17253  * \param _s9 The signal strength from sensor 9.
17254  * \param _result The function call result.
17255  */
17256 #define ReadSensorHTIRSeeker2AC(_port, _dir, _s1, _s3, _s5, _s7, _s9, _result) __ReadSensorHTIRSeeker2AC(_port, _dir, _s1, _s3, _s5, _s7, _s9, _result)
17257 
17258 /**
17259  * Set HiTechnic IRSeeker2 mode.
17260  * Set the mode of the HiTechnic IRSeeker2 sensor on the specified
17261  * port. The port must be configured as a Lowspeed port before using this
17262  * function.
17263  *
17264  * \param _port The sensor port. See \ref NBCInputPortConstants.
17265  * \param _mode The IRSeeker2 mode. See \ref HTIRSeeker2Constants.
17266  * \param _result The function call result. \ref NO_ERR or \ref CommandCommErrors.
17267  */
17268 #define SetHTIRSeeker2Mode(_port, _mode, _result) __SetHTIRSeeker2Mode(_port, _mode, _result)
17269 
17270 /**
17271  * Set HiTechnic Color2 mode.
17272  * Set the mode of the HiTechnic Color2 sensor on the specified
17273  * port. The port must be configured as a Lowspeed port before using this
17274  * function.
17275  *
17276  * \param _port The sensor port. See \ref NBCInputPortConstants.
17277  * \param _mode The Color2 mode. See \ref HTColor2Constants.
17278  * \param _result The function call result. \ref NO_ERR or \ref CommandCommErrors.
17279  */
17280 #define SetHTColor2Mode(_port, _mode, _result) __SetHTColor2Mode(_port, _mode, _result)
17281 
17282 /**
17283  * Read HiTechnic Color2 active values.
17284  * Read color number, red, green, and blue values from the HiTechnic Color2
17285  * sensor. Returns a boolean value indicating whether or not the operation
17286  * completed successfully. The port must be configured as a Lowspeed port
17287  * before using this function.
17288  *
17289  * \param _port The sensor port. See \ref NBCInputPortConstants.
17290  * \param _ColorNum The output color number.
17291  * \param _Red The red color value.
17292  * \param _Green The green color value.
17293  * \param _Blue The blue color value.
17294  * \param _White The white color value.
17295  * \param _result The function call result.
17296  */
17297 #define ReadSensorHTColor2Active(_port, _ColorNum, _Red, _Green, _Blue, _White, _result) __ReadSensorHTColor2Active(_port, _ColorNum, _Red, _Green, _Blue, _White, _result)
17298 
17299 /**
17300  * Read HiTechnic Color2 normalized active values.
17301  * Read the color index and the normalized red, green, and blue values from
17302  * the HiTechnic Color2 sensor. Returns a boolean value indicating whether or
17303  * not the operation completed successfully. The port must be configured as a
17304  * Lowspeed port before using this function.
17305  *
17306  * \param _port The sensor port. See \ref NBCInputPortConstants.
17307  * \param _ColorIdx The output color index.
17308  * \param _Red The normalized red color value.
17309  * \param _Green The normalized green color value.
17310  * \param _Blue The normalized blue color value.
17311  * \param _result The function call result.
17312  */
17313 #define ReadSensorHTNormalizedColor2Active(_port, _ColorIdx, _Red, _Green, _Blue, _result) __ReadSensorHTNormalizedColor2Active(_port, _ColorIdx, _Red, _Green, _Blue, _result)
17314 
17315 /**
17316  * Read HiTechnic Color2 raw values.
17317  * Read the raw red, green, and blue values from the HiTechnic Color2 sensor.
17318  * Returns a boolean value indicating whether or not the operation completed
17319  * successfully. The port must be configured as a Lowspeed port before using
17320  * this function.
17321  *
17322  * \param _port The sensor port. See \ref NBCInputPortConstants.
17323  * \param _Red The raw red color value.
17324  * \param _Green The raw green color value.
17325  * \param _Blue The raw blue color value.
17326  * \param _White The raw white color value.
17327  * \param _result The function call result.
17328  */
17329 #define ReadSensorHTRawColor2(_port, _Red, _Green, _Blue, _White, _result) __ReadSensorHTRawColor2(_port, _Red, _Green, _Blue, _White, _result)
17330 
17331 /**
17332  * Read HiTechnic IRReceiver Power Function bytes.
17333  * Read Power Function bytes from the HiTechnic IRReceiver sensor.
17334  * Returns a boolean value indicating whether or not the operation completed
17335  * successfully. The port must be configured as a Lowspeed port before using
17336  * this function.
17337  *
17338  * \param _port The sensor port. See \ref NBCInputPortConstants.
17339  * \param _pfdata Eight bytes of power function remote IR data.
17340  * \param _result The function call result.
17341  */
17342 #define ReadSensorHTIRReceiver(_port, _pfdata, _result) __ReadSensorHTIRReceiver(_port, _pfdata, _result)
17343 
17344 /**
17345  * Read HiTechnic IRReceiver Power Function value.
17346  * Read a Power Function byte from the HiTechnic IRReceiver sensor.
17347  * Returns a boolean value indicating whether or not the operation completed
17348  * successfully. The port must be configured as a Lowspeed port before using
17349  * this function.
17350  *
17351  * \param _port The sensor port. See \ref NBCInputPortConstants.
17352  * \param _reg The power function data offset. See \ref HTIRReceiverConstants.
17353  * \param _pfchar A single byte of power function remote IR data.
17354  * \param _result The function call result.
17355  */
17356 #define ReadSensorHTIRReceiverEx(_port, _reg, _pfchar, _result) __ReadSensorHTIRReceiverEx(_port, _reg, _pfchar, _result)
17357 
17358 /**
17359  * Reset HiTechnic Angle sensor.
17360  * Reset the HiTechnic Angle sensor on the specified
17361  * port. The port must be configured as a Lowspeed port before using this
17362  * function.
17363  *
17364  * \param _port The sensor port. See \ref NBCInputPortConstants.
17365  * \param _mode The Angle reset mode. See \ref HTAngleConstants.
17366  * \param _result The function call result. \ref NO_ERR or \ref CommandCommErrors.
17367  */
17368 #define ResetSensorHTAngle(_port, _mode, _result) __ResetSensorHTAngle(_port, _mode, _result)
17369 
17370 /**
17371  * Read HiTechnic Angle sensor values.
17372  * Read values from the HiTechnic Angle sensor.
17373  * Returns a boolean value indicating whether or not the operation completed
17374  * successfully. The port must be configured as a Lowspeed port before using
17375  * this function.
17376  *
17377  * \param _port The sensor port. See \ref NBCInputPortConstants.
17378  * \param _Angle Current angle in degrees (0-359).
17379  * \param _AccAngle Accumulated angle in degrees (-2147483648 to 2147483647).
17380  * \param _RPM rotations per minute (-1000 to 1000).
17381  * \param _result The function call result.
17382  */
17383 #define ReadSensorHTAngle(_port, _Angle, _AccAngle, _RPM, _result) __ReadSensorHTAngle(_port, _Angle, _AccAngle, _RPM, _result)
17384 
17385 
17386 /** @} */ // end of HiTechnicAPI group
17387 
17388 
17389 ///////////////////////////////////////////////////////////////////////////////
17390 /////////////////////////////// MindSensors API ///////////////////////////////
17391 ///////////////////////////////////////////////////////////////////////////////
17392 
17393 
17394 /** @addtogroup MindSensorsAPI
17395  * @{
17396  */
17397 
17398 /**
17399  * Read mindsensors compass value.
17400  * Return the Mindsensors Compass sensor value.
17401  *
17402  * \param _port The sensor port. See \ref NBCInputPortConstants.
17403  * \param _i2caddr The sensor I2C address. See sensor documentation for this value.
17404  * \param _value The mindsensors compass value
17405  */
17406 #define ReadSensorMSCompass(_port, _i2caddr, _value) __ReadSensorMSCompass(_port, _i2caddr, _value)
17407 
17408 /**
17409  * Read mindsensors DROD value.
17410  * Return the Mindsensors DROD sensor value.
17411  *
17412  * \param _port The sensor port. See \ref NBCInputPortConstants.
17413  * \param _value The mindsensors DROD value
17414  */
17415 #define ReadSensorMSDROD(_port, _value) __ReadSensorMSDROD(_port, _value)
17416 
17417 /**
17418  * Configure a mindsensors DROD active sensor.
17419  * Configure the specified port for an active mindsensors DROD sensor.
17420  *
17421  * \param _port The port to configure. See \ref NBCInputPortConstants.
17422  */
17423 #define SetSensorMSDRODActive(_port) __SetSensorMSDRODActive(_port)
17424 
17425 /**
17426  * Configure a mindsensors DROD inactive sensor.
17427  * Configure the specified port for an inactive mindsensors DROD sensor.
17428  *
17429  * \param _port The port to configure. See \ref NBCInputPortConstants.
17430  */
17431 #define SetSensorMSDRODInactive(_port) __SetSensorMSDRODInactive(_port)
17432 
17433 /**
17434  * Read mindsensors NXTSumoEyes value.
17435  * Return the Mindsensors NXTSumoEyes sensor value.
17436  *
17437  * \param _port The sensor port. See \ref NBCInputPortConstants.
17438  * \param _value The mindsensors NXTSumoEyes value
17439  */
17440 #define ReadSensorNXTSumoEyes(_port, _value) __ReadSensorNXTSumoEyes(_port, _value)
17441 
17442 /**
17443  * Configure a mindsensors NXTSumoEyes long range sensor.
17444  * Configure the specified port for a long range mindsensors NXTSumoEyes sensor.
17445  *
17446  * \param _port The port to configure. See \ref NBCInputPortConstants.
17447  */
17448 #define SetSensorNXTSumoEyesLong(_port) __SetSensorNXTSumoEyesLong(_port)
17449 
17450 /**
17451  * Configure a mindsensors NXTSumoEyes short range sensor.
17452  * Configure the specified port for a short range mindsensors NXTSumoEyes sensor.
17453  *
17454  * \param _port The port to configure. See \ref NBCInputPortConstants.
17455  */
17456 #define SetSensorNXTSumoEyesShort(_port) __SetSensorNXTSumoEyesShort(_port)
17457 
17458 /**
17459  * Read mindsensors raw pressure value.
17460  * Return the Mindsensors pressure sensor raw value.
17461  *
17462  * \param _port The sensor port. See \ref NBCInputPortConstants.
17463  * \param _value The mindsensors raw pressure value
17464  */
17465 #define ReadSensorMSPressureRaw(_port, _value) __ReadSensorMSPressureRaw(_port, _value)
17466 
17467 /**
17468  * Read mindsensors processed pressure value.
17469  * Return the Mindsensors pressure sensor processed value.
17470  *
17471  * \param _port The sensor port. See \ref NBCInputPortConstants.
17472  * \param _value The mindsensors processed pressure value
17473  */
17474 #define ReadSensorMSPressure(_port, _value) __ReadSensorMSPressure(_port, _value)
17475 
17476 /**
17477  * Configure a mindsensors pressure sensor.
17478  * Configure the specified port for a mindsensors pressure sensor.
17479  *
17480  * \param _port The port to configure. See \ref NBCInputPortConstants.
17481  */
17482 #define SetSensorMSPressure(_port) __SetSensorMSPressure(_port)
17483 
17484 /**
17485  * Configure a mindsensors touch sensor multiplexer.
17486  * Configure the specified port for a mindsensors touch sensor multiplexer.
17487  *
17488  * \param _port The port to configure. See \ref NBCInputPortConstants.
17489  */
17490 #define SetSensorMSTouchMux(_port) __SetSensorMSTouchMux(_port)
17491 
17492 /**
17493  * Read mindsensors acceleration values.
17494  * Read X, Y, and Z axis acceleration values from the mindsensors Accelerometer
17495  * sensor. Returns a boolean value indicating whether or not the operation
17496  * completed successfully. The port must be configured as a Lowspeed port
17497  * before using this function.
17498  *
17499  * \param _port The sensor port. See \ref NBCInputPortConstants.
17500  * \param _i2caddr The sensor I2C address. See sensor documentation for this value.
17501  * \param _x The output x-axis acceleration.
17502  * \param _y The output y-axis acceleration.
17503  * \param _z The output z-axis acceleration.
17504  * \param _result The function call result.
17505  */
17506 #define ReadSensorMSAccel(_port, _i2caddr, _x, _y, _z, _result) __ReadSensorMSAccel(_port, _i2caddr, _x, _y, _z, _result)
17507 
17508 /**
17509  * Read mindsensors playstation controller values.
17510  * Read playstation controller values from the mindsensors playstation
17511  * sensor. Returns a boolean value indicating whether or not the operation
17512  * completed successfully. The port must be configured as a Lowspeed port
17513  * before using this function.
17514  *
17515  * \param _port The sensor port. See \ref NBCInputPortConstants.
17516  * \param _i2caddr The sensor I2C address. See sensor documentation for this value.
17517  * \param _b1 The button set 1 values. See \ref MSPSPNXBtnSet1.
17518  * \param _b2 The button set 2 values. See \ref MSPSPNXBtnSet2.
17519  * \param _xleft The left joystick x value.
17520  * \param _yleft The left joystick y value.
17521  * \param _xright The right joystick x value.
17522  * \param _yright The right joystick y value.
17523  * \param _result The function call result.
17524  */
17525 #define ReadSensorMSPlayStation(_port, _i2caddr, _b1, _b2, _xleft, _yleft, _xright, _yright, _result) \
17526   __ReadSensorMSPlayStation(_port, _i2caddr, _b1, _b2, _xleft, _yleft, _xright, _yright, _result)
17527 
17528 /**
17529  * Read mindsensors RTClock values.
17530  * Read real-time clock values from the Mindsensors RTClock sensor. Returns
17531  * a boolean value indicating whether or not the operation completed
17532  * successfully. The port must be configured as a Lowspeed port before using
17533  * this function.
17534  *
17535  * \param _port The sensor port. See \ref NBCInputPortConstants.
17536  * \param _sec The seconds.
17537  * \param _min The minutes.
17538  * \param _hrs The hours.
17539  * \param _dow The day of week number.
17540  * \param _date The day.
17541  * \param _month The month.
17542  * \param _year The year.
17543  * \param _result The function call result.
17544  */
17545 #define ReadSensorMSRTClock(_port, _sec, _min, _hrs, _dow, _date, _month, _year, _result) \
17546   __ReadSensorMSRTClock(_port, _sec, _min, _hrs, _dow, _date, _month, _year, _result)
17547 
17548 /**
17549  * Read mindsensors tilt values.
17550  * Read X, Y, and Z axis tilt values from the mindsensors tilt
17551  * sensor. Returns a boolean value indicating whether or not the operation
17552  * completed successfully. The port must be configured as a Lowspeed port
17553  * before using this function.
17554  *
17555  * \param _port The sensor port. See \ref NBCInputPortConstants.
17556  * \param _i2caddr The sensor I2C address. See sensor documentation for this value.
17557  * \param _x The output x-axis tilt.
17558  * \param _y The output y-axis tilt.
17559  * \param _z The output z-axis tilt.
17560  * \param _result The function call result.
17561  */
17562 #define ReadSensorMSTilt(_port, _i2caddr, _x, _y, _z, _result) __ReadSensorMSTilt(_port, _i2caddr, _x, _y, _z, _result)
17563 
17564 /**
17565  * Send PFMate command.
17566  * Send a PFMate command to the power function IR receiver.
17567  * Returns a boolean value indicating whether or not the operation
17568  * completed successfully. The port must be configured as a Lowspeed port
17569  * before using this function.
17570  *
17571  * \param _port The sensor port. See \ref NBCInputPortConstants.
17572  * \param _i2caddr The sensor I2C address. See sensor documentation for this value.
17573  * \param _channel The power function IR receiver channel. See the \ref PFMateChannelConstants group.
17574  * \param _motors The motor(s) to control. See the \ref PFMateMotorConstants group.
17575  * \param _cmdA The power function command for motor A. See the \ref PFCmdConstants group.
17576  * \param _spdA The power function speed for motor A.
17577  * \param _cmdB The power function command for motor B. See the \ref PFCmdConstants group.
17578  * \param _spdB The power function speed for motor B.
17579  * \param _result The function call result.
17580  */
17581 #define PFMateSend(_port, _i2caddr, _channel, _motors, _cmdA, _spdA, _cmdB, _spdB, _result) __PFMateSend(_port, _i2caddr, _channel, _motors, _cmdA, _spdA, _cmdB, _spdB, _result)
17582 
17583 /**
17584  * Send raw PFMate command.
17585  * Send a raw PFMate command to the power function IR receiver.
17586  * Returns a boolean value indicating whether or not the operation
17587  * completed successfully. The port must be configured as a Lowspeed port
17588  * before using this function.
17589  *
17590  * \param _port The sensor port. See \ref NBCInputPortConstants.
17591  * \param _i2caddr The sensor I2C address. See sensor documentation for this value.
17592  * \param _channel The power function IR receiver channel. See the \ref PFMateChannelConstants group.
17593  * \param _b1 Raw byte 1.
17594  * \param _b2 Raw byte 2.
17595  * \param _result The function call result.
17596  */
17597 #define PFMateSendRaw(_port, _i2caddr, _channel, _b1, _b2, _result) __PFMateSendRaw(_port, _i2caddr, _channel, _b1, _b2, _result)
17598 
17599 /**
17600  * Read a mindsensors device value.
17601  * Read a one, two, or four byte value from a mindsensors sensor. The value must be
17602  * stored with the least signficant byte (LSB) first (i.e., little endian). Returns a boolean value
17603  * indicating whether or not the operation completed successfully. The port
17604  * must be configured as a Lowspeed port before using this function.
17605  *
17606  * \param _port The sensor port. See \ref NBCInputPortConstants.
17607  * \param _i2caddr The sensor I2C address. See sensor documentation for this value.
17608  * \param _reg The device register to read.
17609  * \param _bytes The number of bytes to read. Only 1, 2, or 4 byte values are supported.
17610  * \param _out The value read from the device.
17611  * \param _result The function call result.
17612  */
17613 #define MSReadValue(_port, _i2caddr, _reg, _bytes, _out, _result) __MSReadValue(_port, _i2caddr, _reg, _bytes, _out, _result)
17614 
17615 /**
17616  * Turn on power to device.
17617  * Turn the power on for the mindsensors device on the specified port. The port
17618  * must be configured as a Lowspeed port before using this function.
17619  *
17620  * \param _port The sensor port. See \ref NBCInputPortConstants.
17621  * \param _i2caddr The sensor I2C address. See sensor documentation for this value.
17622  * \param _result The function call result.
17623  */
17624 #define MSEnergize(_port, _i2caddr, _result) __I2CSendCmd(_port, _i2caddr, MS_CMD_ENERGIZED, _result)
17625 
17626 /**
17627  * Turn off power to device.
17628  * Turn power off for the mindsensors device on the specified port. The port
17629  * must be configured as a Lowspeed port before using this function.
17630  *
17631  * \param _port The sensor port. See \ref NBCInputPortConstants.
17632  * \param _i2caddr The sensor I2C address. See sensor documentation for this value.
17633  * \param _result The function call result.
17634  */
17635 #define MSDeenergize(_port, _i2caddr, _result) __I2CSendCmd(_port, _i2caddr, MS_CMD_DEENERGIZED, _result)
17636 
17637 /**
17638  * Turn on mindsensors ADPA mode.
17639  * Turn ADPA mode on for the mindsensors device on the specified port. The port
17640  * must be configured as a Lowspeed port before using this function.
17641  *
17642  * \param _port The sensor port. See \ref NBCInputPortConstants.
17643  * \param _i2caddr The sensor I2C address. See sensor documentation for this value.
17644  * \param _result The function call result.
17645  */
17646 #define MSADPAOn(_port, _i2caddr, _result) __I2CSendCmd(_port, _i2caddr, MS_CMD_ADPA_ON, _result)
17647 
17648 /**
17649  * Turn off mindsensors ADPA mode.
17650  * Turn ADPA mode off for the mindsensors device on the specified port. The port
17651  * must be configured as a Lowspeed port before using this function.
17652  *
17653  * \param _port The sensor port. See \ref NBCInputPortConstants.
17654  * \param _i2caddr The sensor I2C address. See sensor documentation for this value.
17655  * \param _result The function call result.
17656  */
17657 #define MSADPAOff(_port, _i2caddr, _result) __I2CSendCmd(_port, _i2caddr, MS_CMD_ADPA_OFF, _result)
17658 
17659 /**
17660  * Configure DIST-Nx as GP2D12.
17661  * Configure the mindsensors DIST-Nx sensor as GP2D12. The port
17662  * must be configured as a Lowspeed port before using this function.
17663  *
17664  * \param _port The sensor port. See \ref NBCInputPortConstants.
17665  * \param _i2caddr The sensor I2C address. See sensor documentation for this value.
17666  * \param _result The function call result.
17667  */
17668 #define DISTNxGP2D12(_port, _i2caddr, _result) __I2CSendCmd(_port, _i2caddr, DIST_CMD_GP2D12, _result)
17669 
17670 /**
17671  * Configure DIST-Nx as GP2D120.
17672  * Configure the mindsensors DIST-Nx sensor as GP2D120. The port
17673  * must be configured as a Lowspeed port before using this function.
17674  *
17675  * \param _port The sensor port. See \ref NBCInputPortConstants.
17676  * \param _i2caddr The sensor I2C address. See sensor documentation for this value.
17677  * \param _result The function call result.
17678  */
17679 #define DISTNxGP2D120(_port, _i2caddr, _result) __I2CSendCmd(_port, _i2caddr, DIST_CMD_GP2D120, _result)
17680 
17681 /**
17682  * Configure DIST-Nx as GP2YA02.
17683  * Configure the mindsensors DIST-Nx sensor as GP2YA02. The port
17684  * must be configured as a Lowspeed port before using this function.
17685  *
17686  * \param _port The sensor port. See \ref NBCInputPortConstants.
17687  * \param _i2caddr The sensor I2C address. See sensor documentation for this value.
17688  * \param _result The function call result.
17689  */
17690 #define DISTNxGP2YA02(_port, _i2caddr, _result) __I2CSendCmd(_port, _i2caddr, DIST_CMD_GP2YA02, _result)
17691 
17692 /**
17693  * Configure DIST-Nx as GP2YA21.
17694  * Configure the mindsensors DIST-Nx sensor as GP2YA21. The port
17695  * must be configured as a Lowspeed port before using this function.
17696  *
17697  * \param _port The sensor port. See \ref NBCInputPortConstants.
17698  * \param _i2caddr The sensor I2C address. See sensor documentation for this value.
17699  * \param _result The function call result.
17700  */
17701 #define DISTNxGP2YA21(_port, _i2caddr, _result) __I2CSendCmd(_port, _i2caddr, DIST_CMD_GP2YA21, _result)
17702 
17703 /**
17704  * Read DIST-Nx distance value.
17705  * Read the mindsensors DIST-Nx sensor's distance value.
17706  * The port must be configured as a Lowspeed port before using this function.
17707  *
17708  * \param _port The sensor port. See \ref NBCInputPortConstants.
17709  * \param _i2caddr The sensor I2C address. See sensor documentation for this value.
17710  * \param _out The distance value.
17711  * \param _result The function call result.
17712  */
17713 #define ReadDISTNxDistance(_port, _i2caddr, _out, _result) __MSReadValue(_port, _i2caddr, DIST_REG_DIST, 2, _out, _result)
17714 
17715 /**
17716  * Read DIST-Nx maximum distance value.
17717  * Read the mindsensors DIST-Nx sensor's maximum distance value.
17718  * The port must be configured as a Lowspeed port before using this function.
17719  *
17720  * \param _port The sensor port. See \ref NBCInputPortConstants.
17721  * \param _i2caddr The sensor I2C address. See sensor documentation for this value.
17722  * \param _out The maximum distance value.
17723  * \param _result The function call result.
17724  */
17725 #define ReadDISTNxMaxDistance(_port, _i2caddr, _out, _result) __MSReadValue(_port, _i2caddr, DIST_REG_DIST_MAX, 2, _out, _result)
17726 
17727 /**
17728  * Read DIST-Nx minimum distance value.
17729  * Read the mindsensors DIST-Nx sensor's minimum distance value.
17730  * The port must be configured as a Lowspeed port before using this function.
17731  *
17732  * \param _port The sensor port. See \ref NBCInputPortConstants.
17733  * \param _i2caddr The sensor I2C address. See sensor documentation for this value.
17734  * \param _out The minimum distance value.
17735  * \param _result The function call result.
17736  */
17737 #define ReadDISTNxMinDistance(_port, _i2caddr, _out, _result) __MSReadValue(_port, _i2caddr, DIST_REG_DIST_MIN, 2, _out, _result)
17738 
17739 /**
17740  * Read DIST-Nx module type value.
17741  * Read the mindsensors DIST-Nx sensor's module type value.
17742  * The port must be configured as a Lowspeed port before using this function.
17743  *
17744  * \param _port The sensor port. See \ref NBCInputPortConstants.
17745  * \param _i2caddr The sensor I2C address. See sensor documentation for this value.
17746  * \param _out The module type value.
17747  * \param _result The function call result.
17748  */
17749 #define ReadDISTNxModuleType(_port, _i2caddr, _out, _result) __MSReadValue(_port, _i2caddr, DIST_REG_MODULE_TYPE, 1, _out, _result)
17750 
17751 /**
17752  * Read DIST-Nx num points value.
17753  * Read the mindsensors DIST-Nx sensor's num points value.
17754  * The port must be configured as a Lowspeed port before using this function.
17755  *
17756  * \param _port The sensor port. See \ref NBCInputPortConstants.
17757  * \param _i2caddr The sensor I2C address. See sensor documentation for this value.
17758  * \param _out The num points value.
17759  * \param _result The function call result.
17760  */
17761 #define ReadDISTNxNumPoints(_port, _i2caddr, _out, _result) __MSReadValue(_port, _i2caddr, DIST_REG_NUM_POINTS, 1, _out, _result)
17762 
17763 /**
17764  * Read DIST-Nx voltage value.
17765  * Read the mindsensors DIST-Nx sensor's voltage value.
17766  * The port must be configured as a Lowspeed port before using this function.
17767  *
17768  * \param _port The sensor port. See \ref NBCInputPortConstants.
17769  * \param _i2caddr The sensor I2C address. See sensor documentation for this value.
17770  * \param _out The voltage value.
17771  * \param _result The function call result.
17772  */
17773 #define ReadDISTNxVoltage(_port, _i2caddr, _out, _result) __MSReadValue(_port, _i2caddr, DIST_REG_VOLT, 2, _out, _result)
17774 
17775 /**
17776  * Calibrate ACCL-Nx X-axis.
17777  * Calibrate the mindsensors ACCL-Nx sensor X-axis. The port
17778  * must be configured as a Lowspeed port before using this function.
17779  *
17780  * \param _port The sensor port. See \ref NBCInputPortConstants.
17781  * \param _i2caddr The sensor I2C address. See sensor documentation for this value.
17782  * \param _result The function call result.
17783  */
17784 #define ACCLNxCalibrateX(_port, _i2caddr, _result) __I2CSendCmd(_port, _i2caddr, ACCL_CMD_X_CAL, _result)
17785 
17786 /**
17787  * Stop calibrating ACCL-Nx X-axis.
17788  * Stop calibrating the mindsensors ACCL-Nx sensor X-axis. The port
17789  * must be configured as a Lowspeed port before using this function.
17790  *
17791  * \param _port The sensor port. See \ref NBCInputPortConstants.
17792  * \param _i2caddr The sensor I2C address. See sensor documentation for this value.
17793  * \param _result The function call result.
17794  */
17795 #define ACCLNxCalibrateXEnd(_port, _i2caddr, _result) __I2CSendCmd(_port, _i2caddr, ACCL_CMD_X_CAL_END, _result)
17796 
17797 /**
17798  * Calibrate ACCL-Nx Y-axis.
17799  * Calibrate the mindsensors ACCL-Nx sensor Y-axis. The port
17800  * must be configured as a Lowspeed port before using this function.
17801  *
17802  * \param _port The sensor port. See \ref NBCInputPortConstants.
17803  * \param _i2caddr The sensor I2C address. See sensor documentation for this value.
17804  * \param _result The function call result.
17805  */
17806 #define ACCLNxCalibrateY(_port, _i2caddr, _result) __I2CSendCmd(_port, _i2caddr, ACCL_CMD_Y_CAL, _result)
17807 
17808 /**
17809  * Stop calibrating ACCL-Nx Y-axis.
17810  * Stop calibrating the mindsensors ACCL-Nx sensor Y-axis. The port
17811  * must be configured as a Lowspeed port before using this function.
17812  *
17813  * \param _port The sensor port. See \ref NBCInputPortConstants.
17814  * \param _i2caddr The sensor I2C address. See sensor documentation for this value.
17815  * \param _result The function call result.
17816  */
17817 #define ACCLNxCalibrateYEnd(_port, _i2caddr, _result) __I2CSendCmd(_port, _i2caddr, ACCL_CMD_Y_CAL_END, _result)
17818 
17819 /**
17820  * Calibrate ACCL-Nx Z-axis.
17821  * Calibrate the mindsensors ACCL-Nx sensor Z-axis. The port
17822  * must be configured as a Lowspeed port before using this function.
17823  *
17824  * \param _port The sensor port. See \ref NBCInputPortConstants.
17825  * \param _i2caddr The sensor I2C address. See sensor documentation for this value.
17826  * \param _result The function call result.
17827  */
17828 #define ACCLNxCalibrateZ(_port, _i2caddr, _result) __I2CSendCmd(_port, _i2caddr, ACCL_CMD_Z_CAL, _result)
17829 
17830 /**
17831  * Stop calibrating ACCL-Nx Z-axis.
17832  * Stop calibrating the mindsensors ACCL-Nx sensor Z-axis. The port
17833  * must be configured as a Lowspeed port before using this function.
17834  *
17835  * \param _port The sensor port. See \ref NBCInputPortConstants.
17836  * \param _i2caddr The sensor I2C address. See sensor documentation for this value.
17837  * \param _result The function call result.
17838  */
17839 #define ACCLNxCalibrateZEnd(_port, _i2caddr, _result) __I2CSendCmd(_port, _i2caddr, ACCL_CMD_Z_CAL_END, _result)
17840 
17841 /**
17842  * Reset ACCL-Nx calibration.
17843  * Reset the mindsensors ACCL-Nx sensor calibration to factory settings. The port
17844  * must be configured as a Lowspeed port before using this function.
17845  *
17846  * \param _port The sensor port. See \ref NBCInputPortConstants.
17847  * \param _i2caddr The sensor I2C address. See sensor documentation for this value.
17848  * \param _result The function call result.
17849  */
17850 #define ACCLNxResetCalibration(_port, _i2caddr, _result) __I2CSendCmd(_port, _i2caddr, ACCL_CMD_RESET_CAL, _result)
17851 
17852 /**
17853  * Set ACCL-Nx sensitivity.
17854  * Reset the mindsensors ACCL-Nx sensor calibration to factory settings. The port
17855  * must be configured as a Lowspeed port before using this function.
17856  *
17857  * \param _port The sensor port. See \ref NBCInputPortConstants.
17858  * \param _i2caddr The sensor I2C address. See sensor documentation for this value.
17859  * \param _slevel The sensitivity level. See \ref MSACCLNxSLevel.
17860  * \param _result The function call result.
17861  */
17862 #define SetACCLNxSensitivity(_port, _i2caddr, _slevel, _result) __I2CSendCmd(_port, _i2caddr, _slevel, _result)
17863 
17864 /**
17865  * Read ACCL-Nx sensitivity value.
17866  * Read the mindsensors ACCL-Nx sensitivity value.
17867  * The port must be configured as a Lowspeed port before using this function.
17868  *
17869  * \param _port The sensor port. See \ref NBCInputPortConstants.
17870  * \param _i2caddr The sensor I2C address. See sensor documentation for this value.
17871  * \param _out The sensitivity value.
17872  * \param _result The function call result.
17873  */
17874 #define ReadACCLNxSensitivity(_port, _i2caddr, _out, _result) __MSReadValue(_port, _i2caddr, ACCL_REG_sENS_LVL, 1, _out, _result)
17875 
17876 /**
17877  * Read ACCL-Nx X offset value.
17878  * Read the mindsensors ACCL-Nx sensor's X offset value.
17879  * The port must be configured as a Lowspeed port before using this function.
17880  *
17881  * \param _port The sensor port. See \ref NBCInputPortConstants.
17882  * \param _i2caddr The sensor I2C address. See sensor documentation for this value.
17883  * \param _out The X offset value.
17884  * \param _result The function call result.
17885  */
17886 #define ReadACCLNxXOffset(_port, _i2caddr, _out, _result) __MSReadValue(_port, _i2caddr, ACCL_REG_X_OFFSET, 2, _out, _result)
17887 
17888 /**
17889  * Read ACCL-Nx X range value.
17890  * Read the mindsensors ACCL-Nx sensor's X range value.
17891  * The port must be configured as a Lowspeed port before using this function.
17892  *
17893  * \param _port The sensor port. See \ref NBCInputPortConstants.
17894  * \param _i2caddr The sensor I2C address. See sensor documentation for this value.
17895  * \param _out The X range value.
17896  * \param _result The function call result.
17897  */
17898 #define ReadACCLNxXRange(_port, _i2caddr, _out, _result) __MSReadValue(_port, _i2caddr, ACCL_REG_X_RANGE, 2, _out, _result)
17899 
17900 /**
17901  * Read ACCL-Nx Y offset value.
17902  * Read the mindsensors ACCL-Nx sensor's Y offset value.
17903  * The port must be configured as a Lowspeed port before using this function.
17904  *
17905  * \param _port The sensor port. See \ref NBCInputPortConstants.
17906  * \param _i2caddr The sensor I2C address. See sensor documentation for this value.
17907  * \param _out The Y offset value.
17908  * \param _result The function call result.
17909  */
17910 #define ReadACCLNxYOffset(_port, _i2caddr, _out, _result) __MSReadValue(_port, _i2caddr, ACCL_REG_Y_OFFSET, 2, _out, _result)
17911 
17912 /**
17913  * Read ACCL-Nx Y range value.
17914  * Read the mindsensors ACCL-Nx sensor's Y range value.
17915  * The port must be configured as a Lowspeed port before using this function.
17916  *
17917  * \param _port The sensor port. See \ref NBCInputPortConstants.
17918  * \param _i2caddr The sensor I2C address. See sensor documentation for this value.
17919  * \param _out The Y range value.
17920  * \param _result The function call result.
17921  */
17922 #define ReadACCLNxYRange(_port, _i2caddr, _out, _result) __MSReadValue(_port, _i2caddr, ACCL_REG_Y_RANGE, 2, _out, _result)
17923 
17924 /**
17925  * Read ACCL-Nx Z offset value.
17926  * Read the mindsensors ACCL-Nx sensor's Z offset value.
17927  * The port must be configured as a Lowspeed port before using this function.
17928  *
17929  * \param _port The sensor port. See \ref NBCInputPortConstants.
17930  * \param _i2caddr The sensor I2C address. See sensor documentation for this value.
17931  * \param _out The Z offset value.
17932  * \param _result The function call result.
17933  */
17934 #define ReadACCLNxZOffset(_port, _i2caddr, _out, _result) __MSReadValue(_port, _i2caddr, ACCL_REG_Z_OFFSET, 2, _out, _result)
17935 
17936 /**
17937  * Read ACCL-Nx Z range value.
17938  * Read the mindsensors ACCL-Nx sensor's Z range value.
17939  * The port must be configured as a Lowspeed port before using this function.
17940  *
17941  * \param _port The sensor port. See \ref NBCInputPortConstants.
17942  * \param _i2caddr The sensor I2C address. See sensor documentation for this value.
17943  * \param _out The Z range value.
17944  * \param _result The function call result.
17945  */
17946 #define ReadACCLNxZRange(_port, _i2caddr, _out, _result) __MSReadValue(_port, _i2caddr, ACCL_REG_Z_RANGE, 2, _out, _result)
17947 
17948 /**
17949  * Configure PSP-Nx in digital mode.
17950  * Configure the mindsensors PSP-Nx device in digital mode. The port
17951  * must be configured as a Lowspeed port before using this function.
17952  *
17953  * \param _port The sensor port. See \ref NBCInputPortConstants.
17954  * \param _i2caddr The sensor I2C address. See sensor documentation for this value.
17955  * \param _result The function call result.
17956  */
17957 #define PSPNxDigital(_port, _i2caddr, _result) __I2CSendCmd(_port, _i2caddr, PSP_CMD_DIGITAL, _result)
17958 
17959 /**
17960  * Configure PSP-Nx in analog mode.
17961  * Configure the mindsensors PSP-Nx device in analog mode. The port
17962  * must be configured as a Lowspeed port before using this function.
17963  *
17964  * \param _port The sensor port. See \ref NBCInputPortConstants.
17965  * \param _i2caddr The sensor I2C address. See sensor documentation for this value.
17966  * \param _result The function call result.
17967  */
17968 #define PSPNxAnalog(_port, _i2caddr, _result) __I2CSendCmd(_port, _i2caddr, PSP_CMD_ANALOG, _result)
17969 
17970 /**
17971  * Read NXTServo servo position value.
17972  * Read the mindsensors NXTServo device's servo position value.
17973  * The port must be configured as a Lowspeed port before using this function.
17974  *
17975  * \param _port The sensor port. See \ref NBCInputPortConstants.
17976  * \param _i2caddr The sensor I2C address. See sensor documentation for this value.
17977  * \param _servo The servo number. See \ref NXTServoNumbers group.
17978  * \param _out The specified servo's position value.
17979  * \param _result A status code indicating whether the operation completed successfully or not.
17980  * See \ref TCommLSCheckStatus for possible Result values.
17981  */
17982 #define ReadNXTServoPosition(_port, _i2caddr, _servo, _out, _result) __MSReadValue(_port, _i2caddr, NXTSERVO_REG_S1_POS+(_servo*2), 2, _out, _result)
17983 
17984 /**
17985  * Read NXTServo servo speed value.
17986  * Read the mindsensors NXTServo device's servo speed value.
17987  * The port must be configured as a Lowspeed port before using this function.
17988  *
17989  * \param _port The sensor port. See \ref NBCInputPortConstants.
17990  * \param _i2caddr The sensor I2C address. See sensor documentation for this value.
17991  * \param _servo The servo number. See \ref NXTServoNumbers group.
17992  * \param _out The specified servo's speed value.
17993  * \param _result A status code indicating whether the operation completed successfully or not.
17994  * See \ref TCommLSCheckStatus for possible Result values.
17995  */
17996 #define ReadNXTServoSpeed(_port, _i2caddr, _servo, _out, _result) __MSReadValue(_port, _i2caddr, NXTSERVO_REG_S1_SPEED+_servo, 1, _out, _result)
17997 
17998 /**
17999  * Read NXTServo battery voltage value.
18000  * Read the mindsensors NXTServo device's battery voltage value.
18001  * The port must be configured as a Lowspeed port before using this function.
18002  *
18003  * \param _port The sensor port. See \ref NBCInputPortConstants.
18004  * \param _i2caddr The sensor I2C address. See sensor documentation for this value.
18005  * \param _out The NXTServo battery voltage.
18006  * \param _result A status code indicating whether the operation completed successfully or not.
18007  * See \ref TCommLSCheckStatus for possible Result values.
18008  */
18009 #define ReadNXTServoBatteryVoltage(_port, _i2caddr, _out, _result) __MSReadValue(_port, _i2caddr, NXTSERVO_REG_VOLTAGE, 1, _out, _result)
18010 
18011 /**
18012  * Set NXTServo servo motor speed.
18013  * Set the speed of a servo motor controlled by the NXTServo device. The port
18014  * must be configured as a Lowspeed port before using this function.
18015  *
18016  * \param _port The sensor port. See \ref NBCInputPortConstants.
18017  * \param _i2caddr The sensor I2C address. See sensor documentation for this value.
18018  * \param _servo The servo number. See \ref NXTServoNumbers group.
18019  * \param _speed The servo speed. (0..255)
18020  * \param _result A status code indicating whether the operation completed successfully or not.
18021  * See \ref TCommLSCheckStatus for possible Result values.
18022  */
18023 #define SetNXTServoSpeed(_port, _i2caddr, _servo, _speed, _result) __MSWriteToRegister(_port, _i2caddr, NXTSERVO_REG_S1_SPEED+_servo, _speed, _result)
18024 
18025 /**
18026  * Set NXTServo servo motor quick position.
18027  * Set the quick position of a servo motor controlled by the NXTServo device. The port
18028  * must be configured as a Lowspeed port before using this function.
18029  *
18030  * \param _port The sensor port. See \ref NBCInputPortConstants.
18031  * \param _i2caddr The sensor I2C address. See sensor documentation for this value.
18032  * \param _servo The servo number. See \ref NXTServoNumbers group.
18033  * \param _qpos The servo quick position. See \ref NXTServoQPos group.
18034  * \param _result A status code indicating whether the operation completed successfully or not.
18035  * See \ref TCommLSCheckStatus for possible Result values.
18036  */
18037 #define SetNXTServoQuickPosition(_port, _i2caddr, _servo, _qpos, _result) __MSWriteToRegister(_port, _i2caddr, NXTSERVO_REG_S1_QPOS+_servo, _qpos, _result)
18038 
18039 /**
18040  * Set NXTServo servo motor position.
18041  * Set the position of a servo motor controlled by the NXTServo device. The port
18042  * must be configured as a Lowspeed port before using this function.
18043  *
18044  * \param _port The sensor port. See \ref NBCInputPortConstants.
18045  * \param _i2caddr The sensor I2C address. See sensor documentation for this value.
18046  * \param _servo The servo number. See \ref NXTServoNumbers group.
18047  * \param _pos The servo position. See \ref NXTServoPos group.
18048  * \param _result A status code indicating whether the operation completed successfully or not.
18049  * See \ref TCommLSCheckStatus for possible Result values.
18050  */
18051 #define SetNXTServoPosition(_port, _i2caddr, _servo, _pos, _result) __MSWriteLEIntToRegister(_port, _i2caddr, _reg, _pos, _result)
18052 
18053 /**
18054  * Reset NXTServo properties.
18055  * Reset NXTServo device properties to factory defaults.
18056  * Initial position = 1500.  Initial speed = 0. The port
18057  * must be configured as a Lowspeed port before using this function.
18058  *
18059  * \param _port The sensor port. See \ref NBCInputPortConstants.
18060  * \param _i2caddr The sensor I2C address. See sensor documentation for this value.
18061  * \param _result A status code indicating whether the operation completed successfully or not.
18062  * See \ref TCommLSCheckStatus for possible Result values.
18063  */
18064 #define NXTServoReset(_port, _i2caddr, _result) __I2CSendCmd(_port, _i2caddr, NXTSERVO_CMD_RESET, _result)
18065 
18066 /**
18067  * Halt NXTServo macro.
18068  * Halt a macro executing on the NXTServo device. This command re-initializes
18069  * the macro environment.
18070  * The port must be configured as a Lowspeed port before using this function.
18071  *
18072  * \param _port The sensor port. See \ref NBCInputPortConstants.
18073  * \param _i2caddr The sensor I2C address. See sensor documentation for this value.
18074  * \param _result A status code indicating whether the operation completed successfully or not.
18075  * See \ref TCommLSCheckStatus for possible Result values.
18076  */
18077 #define NXTServoHaltMacro(_port, _i2caddr, _result) __I2CSendCmd(_port, _i2caddr, NXTSERVO_CMD_HALT, _result)
18078 
18079 /**
18080  * Resume NXTServo macro.
18081  * Resume a macro executing on the NXTServo device. This command resumes
18082  * executing a macro where it was paused last, using the same environment.
18083  * The port must be configured as a Lowspeed port before using this function.
18084  *
18085  * \param _port The sensor port. See \ref NBCInputPortConstants.
18086  * \param _i2caddr The sensor I2C address. See sensor documentation for this value.
18087  * \param _result A status code indicating whether the operation completed successfully or not.
18088  * See \ref TCommLSCheckStatus for possible Result values.
18089  */
18090 #define NXTServoResumeMacro(_port, _i2caddr, _result) __I2CSendCmd(_port, _i2caddr, NXTSERVO_CMD_RESUME, _result)
18091 
18092 /**
18093  * Pause NXTServo macro.
18094  * Pause a macro executing on the NXTServo device. This command will pause the
18095  * currently executing macro, and save the environment for subsequent resumption.
18096  * The port must be configured as a Lowspeed port before using this function.
18097  *
18098  * \param _port The sensor port. See \ref NBCInputPortConstants.
18099  * \param _i2caddr The sensor I2C address. See sensor documentation for this value.
18100  * \param _result A status code indicating whether the operation completed successfully or not.
18101  * See \ref TCommLSCheckStatus for possible Result values.
18102  */
18103 #define NXTServoPauseMacro(_port, _i2caddr, _result) __I2CSendCmd(_port, _i2caddr, NXTSERVO_CMD_PAUSE, _result)
18104 
18105 /**
18106  * Initialize NXTServo servo properties.
18107  * Store the initial speed and position properties of the servo motor 'n'.
18108  * Current speed and position values of the nth servo is read from the
18109  * servo speed register and servo position register and written to permanent
18110  * memory.
18111  * The port must be configured as a Lowspeed port before using this function.
18112  *
18113  * \param _port The sensor port. See \ref NBCInputPortConstants.
18114  * \param _i2caddr The sensor I2C address. See sensor documentation for this value.
18115  * \param _servo The servo number. See \ref NXTServoNumbers group.
18116  * \param _result A status code indicating whether the operation completed successfully or not.
18117  * See \ref TCommLSCheckStatus for possible Result values.
18118  */
18119 #define NXTServoInit(_port, _i2caddr, _servo, _result) __NXTServoInit(_port, _i2caddr, _servo, _result)
18120 
18121 /**
18122  * Goto NXTServo macro address.
18123  * Run the macro found at the specified EEPROM macro address. This command
18124  * re-initializes the macro environment.
18125  * The port must be configured as a Lowspeed port before using this function.
18126  *
18127  * \param _port The sensor port. See \ref NBCInputPortConstants.
18128  * \param _i2caddr The sensor I2C address. See sensor documentation for this value.
18129  * \param _macro The EEPROM macro address.
18130  * \param _result A status code indicating whether the operation completed successfully or not.
18131  * See \ref TCommLSCheckStatus for possible Result values.
18132  */
18133 #define NXTServoGotoMacroAddress(_port, _i2caddr, _macro, _result) __NXTServoGotoMacroAddress(_port, _i2caddr, _macro, _result)
18134 
18135 /**
18136  * Edit NXTServo macro.
18137  * Put the NXTServo device into macro edit mode. This operation changes the
18138  * I2C address of the device to 0x40.  Macros are written to EEPROM addresses
18139  * between 0x21 and 0xFF. Use \ref NXTServoQuitEdit to return the device to
18140  * its normal operation mode.
18141  * The port must be configured as a Lowspeed port before using this function.
18142  *
18143  * \param _port The sensor port. See \ref NBCInputPortConstants.
18144  * \param _i2caddr The sensor I2C address. See sensor documentation for this value.
18145  * \param _result A status code indicating whether the operation completed successfully or not.
18146  * See \ref TCommLSCheckStatus for possible Result values.
18147  */
18148 #define NXTServoEditMacro(_port, _i2caddr, _result) __NXTServoEditMacro(_port, _i2caddr, _result)
18149 
18150 /**
18151  * Quit NXTServo macro edit mode.
18152  * Stop editing NXTServo device macro EEPROM memory. Use \ref NXTServoEditMacro
18153  * to start editing a macro.
18154  * The port must be configured as a Lowspeed port before using this function.
18155  *
18156  * \param _port The sensor port. See \ref NBCInputPortConstants.
18157  * \param _result A status code indicating whether the operation completed successfully or not.
18158  * See \ref TCommLSCheckStatus for possible Result values.
18159  */
18160 #define NXTServoQuitEdit(_port, _result) __MSWriteToRegister(_port, MS_ADDR_NXTSERVO_EM, NXTSERVO_EM_REG_CMD, NXTSERVO_EM_CMD_QUIT, _result)
18161 
18162 /**
18163  * Set NXTHID into ASCII data mode.
18164  * Set the NXTHID device into ASCII data mode. The port
18165  * must be configured as a Lowspeed port before using this function.
18166  *
18167  * \param _port The sensor port. See \ref NBCInputPortConstants.
18168  * \param _i2caddr The sensor I2C address. See sensor documentation for this value.
18169  * \param _result A status code indicating whether the operation completed successfully or not.
18170  * See \ref TCommLSCheckStatus for possible Result values.
18171  */
18172 #define NXTHIDAsciiMode(_port, _i2caddr, _result) __I2CSendCmd(_port, _i2caddr, NXTHID_CMD_ASCII, _result)
18173 
18174 /**
18175  * Set NXTHID into direct data mode.
18176  * Set the NXTHID device into direct data mode. The port
18177  * must be configured as a Lowspeed port before using this function.
18178  *
18179  * \param _port The sensor port. See \ref NBCInputPortConstants.
18180  * \param _i2caddr The sensor I2C address. See sensor documentation for this value.
18181  * \param _result A status code indicating whether the operation completed successfully or not.
18182  * See \ref TCommLSCheckStatus for possible Result values.
18183  */
18184 #define NXTHIDDirectMode(_port, _i2caddr, _result) __I2CSendCmd(_port, _i2caddr, NXTHID_CMD_DIRECT, _result)
18185 
18186 /**
18187  * Transmit NXTHID character.
18188  * Transmit a single character to a computer using the NXTHID device. The port
18189  * must be configured as a Lowspeed port before using this function.
18190  *
18191  * \param _port The sensor port. See \ref NBCInputPortConstants.
18192  * \param _i2caddr The sensor I2C address. See sensor documentation for this value.
18193  * \param _result A status code indicating whether the operation completed successfully or not.
18194  * See \ref TCommLSCheckStatus for possible Result values.
18195  */
18196 #define NXTHIDTransmit(_port, _i2caddr, _result) __I2CSendCmd(_port, _i2caddr, NXTHID_CMD_TRANSMIT, _result)
18197 
18198 /**
18199  * Load NXTHID character.
18200  * Load a character into the NXTHID device.
18201  * The port must be configured as a Lowspeed port before using this function.
18202  *
18203  * \param _port The sensor port. See \ref NBCInputPortConstants.
18204  * \param _i2caddr The sensor I2C address. See sensor documentation for this value.
18205  * \param _modifier The key modifier.
18206  * \param _character The character.
18207  * \param _result A status code indicating whether the operation completed successfully or not.
18208  * See \ref TCommLSCheckStatus for possible Result values.
18209  */
18210 #define NXTHIDLoadCharacter(_port, _i2caddr, _modifier, _character, _result) __NXTHIDLoadCharacter(_port, _i2caddr, _modifier, _character, _result)
18211 
18212 /**
18213  * Reset NXTPowerMeter counters.
18214  * Reset the NXTPowerMeter counters back to zero. The port
18215  * must be configured as a Lowspeed port before using this function.
18216  *
18217  * \param _port The sensor port. See \ref NBCInputPortConstants.
18218  * \param _i2caddr The sensor I2C address. See sensor documentation for this value.
18219  * \param _result A status code indicating whether the operation completed successfully or not.
18220  * See \ref TCommLSCheckStatus for possible Result values.
18221  */
18222 #define NXTPowerMeterResetCounters(_port, _i2caddr, _result) __I2CSendCmd(_port, _i2caddr, NXTPM_CMD_RESET, _result)
18223 
18224 /**
18225  * Read NXTPowerMeter present current.
18226  * Read the mindsensors NXTPowerMeter device's present current value.
18227  * The port must be configured as a Lowspeed port before using this function.
18228  *
18229  * \param _port The sensor port. See \ref NBCInputPortConstants.
18230  * \param _i2caddr The sensor I2C address. See sensor documentation for this value.
18231  * \param _out The NXTPowerMeter present current.
18232  * \param _result A status code indicating whether the operation completed successfully or not.
18233  * See \ref TCommLSCheckStatus for possible Result values.
18234  */
18235 #define ReadNXTPowerMeterPresentCurrent(_port, _i2caddr, _out, _result) __MSReadValue(_port, _i2caddr, NXTPM_REG_CURRENT, 2, _out, _result)
18236 
18237 /**
18238  * Read NXTPowerMeter present voltage.
18239  * Read the mindsensors NXTPowerMeter device's present voltage value.
18240  * The port must be configured as a Lowspeed port before using this function.
18241  *
18242  * \param _port The sensor port. See \ref NBCInputPortConstants.
18243  * \param _i2caddr The sensor I2C address. See sensor documentation for this value.
18244  * \param _out The NXTPowerMeter present voltage.
18245  * \param _result A status code indicating whether the operation completed successfully or not.
18246  * See \ref TCommLSCheckStatus for possible Result values.
18247  */
18248 #define ReadNXTPowerMeterPresentVoltage(_port, _i2caddr, _out, _result) __MSReadValue(_port, _i2caddr, NXTPM_REG_VOLTAGE, 2, _out, _result)
18249 
18250 /**
18251  * Read NXTPowerMeter capacity used.
18252  * Read the mindsensors NXTPowerMeter device's capacity used since the last reset command.
18253  * The port must be configured as a Lowspeed port before using this function.
18254  *
18255  * \param _port The sensor port. See \ref NBCInputPortConstants.
18256  * \param _i2caddr The sensor I2C address. See sensor documentation for this value.
18257  * \param _out The NXTPowerMeter capacity used value.
18258  * \param _result A status code indicating whether the operation completed successfully or not.
18259  * See \ref TCommLSCheckStatus for possible Result values.
18260  */
18261 #define ReadNXTPowerMeterCapacityUsed(_port, _i2caddr, _out, _result) __MSReadValue(_port, _i2caddr, NXTPM_REG_CAPACITY, 2, _out, _result)
18262 
18263 /**
18264  * Read NXTPowerMeter present power.
18265  * Read the mindsensors NXTPowerMeter device's present power value.
18266  * The port must be configured as a Lowspeed port before using this function.
18267  *
18268  * \param _port The sensor port. See \ref NBCInputPortConstants.
18269  * \param _i2caddr The sensor I2C address. See sensor documentation for this value.
18270  * \param _out The NXTPowerMeter present power value.
18271  * \param _result A status code indicating whether the operation completed successfully or not.
18272  * See \ref TCommLSCheckStatus for possible Result values.
18273  */
18274 #define ReadNXTPowerMeterPresentPower(_port, _i2caddr, _out, _result) __MSReadValue(_port, _i2caddr, NXTPM_REG_POWER, 2, _out, _result)
18275 
18276 /**
18277  * Read NXTPowerMeter total power consumed.
18278  * Read the mindsensors NXTPowerMeter device's total power consumed since the last reset command.
18279  * The port must be configured as a Lowspeed port before using this function.
18280  *
18281  * \param _port The sensor port. See \ref NBCInputPortConstants.
18282  * \param _i2caddr The sensor I2C address. See sensor documentation for this value.
18283  * \param _out The NXTPowerMeter total power consumed value.
18284  * \param _result A status code indicating whether the operation completed successfully or not.
18285  * See \ref TCommLSCheckStatus for possible Result values.
18286  */
18287 #define ReadNXTPowerMeterTotalPowerConsumed(_port, _i2caddr, _out, _result) __MSReadValue(_port, _i2caddr, NXTPM_REG_POWER, 4, _out, _result)
18288 
18289 /**
18290  * Read NXTPowerMeter maximum current.
18291  * Read the mindsensors NXTPowerMeter device's maximum current value.
18292  * The port must be configured as a Lowspeed port before using this function.
18293  *
18294  * \param _port The sensor port. See \ref NBCInputPortConstants.
18295  * \param _i2caddr The sensor I2C address. See sensor documentation for this value.
18296  * \param _out The NXTPowerMeter maximum current value.
18297  * \param _result A status code indicating whether the operation completed successfully or not.
18298  * See \ref TCommLSCheckStatus for possible Result values.
18299  */
18300 #define ReadNXTPowerMeterMaxCurrent(_port, _i2caddr, _out, _result) __MSReadValue(_port, _i2caddr, NXTPM_REG_MAXCURRENT, 2, _out, _result)
18301 
18302 /**
18303  * Read NXTPowerMeter minimum current.
18304  * Read the mindsensors NXTPowerMeter device's minimum current value.
18305  * The port must be configured as a Lowspeed port before using this function.
18306  *
18307  * \param _port The sensor port. See \ref NBCInputPortConstants.
18308  * \param _i2caddr The sensor I2C address. See sensor documentation for this value.
18309  * \param _out The NXTPowerMeter minimum current value.
18310  * \param _result A status code indicating whether the operation completed successfully or not.
18311  * See \ref TCommLSCheckStatus for possible Result values.
18312  */
18313 #define ReadNXTPowerMeterMinCurrent(_port, _i2caddr, _out, _result) __MSReadValue(_port, _i2caddr, NXTPM_REG_MINCURRENT, 2, _out, _result)
18314 
18315 /**
18316  * Read NXTPowerMeter maximum voltage.
18317  * Read the mindsensors NXTPowerMeter device's maximum voltage value.
18318  * The port must be configured as a Lowspeed port before using this function.
18319  *
18320  * \param _port The sensor port. See \ref NBCInputPortConstants.
18321  * \param _i2caddr The sensor I2C address. See sensor documentation for this value.
18322  * \param _out The NXTPowerMeter maximum voltage value.
18323  * \param _result A status code indicating whether the operation completed successfully or not.
18324  * See \ref TCommLSCheckStatus for possible Result values.
18325  */
18326 #define ReadNXTPowerMeterMaxVoltage(_port, _i2caddr, _out, _result) __MSReadValue(_port, _i2caddr, NXTPM_REG_MAXVOLTAGE, 2, _out, _result)
18327 
18328 /**
18329  * Read NXTPowerMeter minimum voltage.
18330  * Read the mindsensors NXTPowerMeter device's minimum voltage value.
18331  * The port must be configured as a Lowspeed port before using this function.
18332  *
18333  * \param _port The sensor port. See \ref NBCInputPortConstants.
18334  * \param _i2caddr The sensor I2C address. See sensor documentation for this value.
18335  * \param _out The NXTPowerMeter minimum voltage value.
18336  * \param _result A status code indicating whether the operation completed successfully or not.
18337  * See \ref TCommLSCheckStatus for possible Result values.
18338  */
18339 #define ReadNXTPowerMeterMinVoltage(_port, _i2caddr, _out, _result) __MSReadValue(_port, _i2caddr, NXTPM_REG_MINVOLTAGE, 2, _out, _result)
18340 
18341 /**
18342  * Read NXTPowerMeter elapsed time.
18343  * Read the mindsensors NXTPowerMeter device's elapsed time since the last reset command.
18344  * The port must be configured as a Lowspeed port before using this function.
18345  *
18346  * \param _port The sensor port. See \ref NBCInputPortConstants.
18347  * \param _i2caddr The sensor I2C address. See sensor documentation for this value.
18348  * \param _out The NXTPowerMeter elapsed time value.
18349  * \param _result A status code indicating whether the operation completed successfully or not.
18350  * See \ref TCommLSCheckStatus for possible Result values.
18351  */
18352 #define ReadNXTPowerMeterElapsedTime(_port, _i2caddr, _out, _result) __MSReadValue(_port, _i2caddr, NXTPM_REG_TIME, 4, _out, _result)
18353 
18354 /**
18355  * Read NXTPowerMeter error count.
18356  * Read the mindsensors NXTPowerMeter device's error count value.
18357  * The port must be configured as a Lowspeed port before using this function.
18358  *
18359  * \param _port The sensor port. See \ref NBCInputPortConstants.
18360  * \param _i2caddr The sensor I2C address. See sensor documentation for this value.
18361  * \param _out The NXTPowerMeter error count value.
18362  * \param _result A status code indicating whether the operation completed successfully or not.
18363  * See \ref TCommLSCheckStatus for possible Result values.
18364  */
18365 #define ReadNXTPowerMeterErrorCount(_port, _i2caddr, _out, _result) __MSReadValue(_port, _i2caddr, NXTPM_REG_ERRORCOUNT, 2, _out, _result)
18366 
18367 /**
18368  * Powerdown NXTLineLeader device.
18369  * Put the NXTLineLeader to sleep so that it does not consume power when it is
18370  * not required. The device wakes up on its own when any I2C communication
18371  * happens or you can specifically wake it up by using the \ref NXTLineLeaderPowerUp
18372  * command.
18373  * The port must be configured as a Lowspeed port before using this function.
18374  *
18375  * \param _port The sensor port. See \ref NBCInputPortConstants.
18376  * \param _i2caddr The sensor I2C address. See sensor documentation for this value.
18377  * \param _result A status code indicating whether the operation completed successfully or not.
18378  * See \ref TCommLSCheckStatus for possible Result values.
18379  */
18380 #define NXTLineLeaderPowerDown(_port, _i2caddr, _result) __I2CSendCmd(_port, _i2caddr, NXTLL_CMD_POWERDOWN, _result)
18381 
18382 /**
18383  * Powerup NXTLineLeader device.
18384  * Wake up the NXTLineLeader device so that it can be used. The device can be
18385  * put to sleep using the \ref NXTLineLeaderPowerDown command.
18386  * The port must be configured as a Lowspeed port before using this function.
18387  *
18388  * \param _port The sensor port. See \ref NBCInputPortConstants.
18389  * \param _i2caddr The sensor I2C address. See sensor documentation for this value.
18390  * \param _result A status code indicating whether the operation completed successfully or not.
18391  * See \ref TCommLSCheckStatus for possible Result values.
18392  */
18393 #define NXTLineLeaderPowerUp(_port, _i2caddr, _result) __I2CSendCmd(_port, _i2caddr, NXTLL_CMD_POWERUP, _result)
18394 
18395 /**
18396  * Invert NXTLineLeader colors.
18397  * Invert color sensing so that the device can detect a white line on a
18398  * black background.
18399  * The port must be configured as a Lowspeed port before using this function.
18400  *
18401  * \param _port The sensor port. See \ref NBCInputPortConstants.
18402  * \param _i2caddr The sensor I2C address. See sensor documentation for this value.
18403  * \param _result A status code indicating whether the operation completed successfully or not.
18404  * See \ref TCommLSCheckStatus for possible Result values.
18405  */
18406 #define NXTLineLeaderInvert(_port, _i2caddr, _result) __I2CSendCmd(_port, _i2caddr, NXTLL_CMD_INVERT, _result)
18407 
18408 /**
18409  * Reset NXTLineLeader color inversion.
18410  * Reset the NXTLineLeader color detection back to its default state (black
18411  * line on a white background).
18412  * The port must be configured as a Lowspeed port before using this function.
18413  *
18414  * \param _port The sensor port. See \ref NBCInputPortConstants.
18415  * \param _i2caddr The sensor I2C address. See sensor documentation for this value.
18416  * \param _result A status code indicating whether the operation completed successfully or not.
18417  * See \ref TCommLSCheckStatus for possible Result values.
18418  */
18419 #define NXTLineLeaderReset(_port, _i2caddr, _result) __I2CSendCmd(_port, _i2caddr, NXTLL_CMD_RESET, _result)
18420 
18421 /**
18422  * Take NXTLineLeader line snapshot.
18423  * Takes a snapshot of the line under the sensor and tracks that position in
18424  * subsequent tracking operations.  This function also will set color inversion
18425  * if it sees a white line on a black background.
18426  * The port must be configured as a Lowspeed port before using this function.
18427  *
18428  * \param _port The sensor port. See \ref NBCInputPortConstants.
18429  * \param _i2caddr The sensor I2C address. See sensor documentation for this value.
18430  * \param _result A status code indicating whether the operation completed successfully or not.
18431  * See \ref TCommLSCheckStatus for possible Result values.
18432  */
18433 #define NXTLineLeaderSnapshot(_port, _i2caddr, _result) __I2CSendCmd(_port, _i2caddr, NXTLL_CMD_SNAPSHOT, _result)
18434 
18435 /**
18436  * Calibrate NXTLineLeader white color.
18437  * Store calibration data for the white color.
18438  * The port must be configured as a Lowspeed port before using this function.
18439  *
18440  * \param _port The sensor port. See \ref NBCInputPortConstants.
18441  * \param _i2caddr The sensor I2C address. See sensor documentation for this value.
18442  * \param _result A status code indicating whether the operation completed successfully or not.
18443  * See \ref TCommLSCheckStatus for possible Result values.
18444  */
18445 #define NXTLineLeaderCalibrateWhite(_port, _i2caddr, _result) __I2CSendCmd(_port, _i2caddr, NXTLL_CMD_WHITE, _result)
18446 
18447 /**
18448  * Calibrate NXTLineLeader black color.
18449  * Store calibration data for the black color.
18450  * The port must be configured as a Lowspeed port before using this function.
18451  *
18452  * \param _port The sensor port. See \ref NBCInputPortConstants.
18453  * \param _i2caddr The sensor I2C address. See sensor documentation for this value.
18454  * \param _result A status code indicating whether the operation completed successfully or not.
18455  * See \ref TCommLSCheckStatus for possible Result values.
18456  */
18457 #define NXTLineLeaderCalibrateBlack(_port, _i2caddr, _result) __I2CSendCmd(_port, _i2caddr, NXTLL_CMD_BLACK, _result)
18458 
18459 /**
18460  * Read NXTLineLeader steering.
18461  * Read the mindsensors NXTLineLeader device's steering value. This is the power
18462  * returned by the sensor to correct your course.  Add this value to your left
18463  * motor and subtract it from your right motor.
18464  * The port must be configured as a Lowspeed port before using this function.
18465  *
18466  * \param _port The sensor port. See \ref NBCInputPortConstants.
18467  * \param _i2caddr The sensor I2C address. See sensor documentation for this value.
18468  * \param _out The NXTLineLeader steering value.
18469  * \param _result A status code indicating whether the operation completed successfully or not.
18470  * See \ref TCommLSCheckStatus for possible Result values.
18471  */
18472 #define ReadNXTLineLeaderSteering(_port, _i2caddr, _out, _result) __MSReadValue(_port, _i2caddr, NXTLL_REG_STEERING, 1, _out, _result)
18473 
18474 /**
18475  * Read NXTLineLeader average.
18476  * Read the mindsensors NXTLineLeader device's average value. The
18477  * average is a weighted average of the bits set to 1 based on the position.
18478  * The left most bit has a weight of 10, second bit has a weight of 20, and so
18479  * forth. When all 8 sensors are over a black surface the average will be 45.
18480  * The port must be configured as a Lowspeed port before using this function.
18481  *
18482  * \param _port The sensor port. See \ref NBCInputPortConstants.
18483  * \param _i2caddr The sensor I2C address. See sensor documentation for this value.
18484  * \param _out The NXTLineLeader average value.
18485  * \param _result A status code indicating whether the operation completed successfully or not.
18486  * See \ref TCommLSCheckStatus for possible Result values.
18487  */
18488 #define ReadNXTLineLeaderAverage(_port, _i2caddr, _out, _result) __MSReadValue(_port, _i2caddr, NXTLL_REG_AVERAGE, 1, _out, _result)
18489 
18490 /**
18491  * Read NXTLineLeader result.
18492  * Read the mindsensors NXTLineLeader device's result value. This is a single
18493  * byte showing the 8 sensor's readings. Each bit corresponding to the sensor
18494  * where the line is seen is set to 1, otherwise it is set to 0.
18495  * When all 8 sensors are over a black surface the result will be 255 (b11111111).
18496  * The port must be configured as a Lowspeed port before using this function.
18497  *
18498  * \param _port The sensor port. See \ref NBCInputPortConstants.
18499  * \param _i2caddr The sensor I2C address. See sensor documentation for this value.
18500  * \param _out The NXTLineLeader result value.
18501  * \param _result A status code indicating whether the operation completed successfully or not.
18502  * See \ref TCommLSCheckStatus for possible Result values.
18503  */
18504 #define ReadNXTLineLeaderResult(_port, _i2caddr, _out, _result) __MSReadValue(_port, _i2caddr, NXTLL_REG_RESULT, 1, _out, _result)
18505 
18506 /**
18507  * Write NXTLineLeader setpoint.
18508  * Write a new setpoint value to the NXTLineLeader device. The Set Point is a
18509  * value you can ask sensor to maintain the average to. The default value is
18510  * 45, whereby the line is maintained in center of the sensor. If you need to
18511  * maintain line towards left of the sensor, set the Set Point to
18512  * a lower value (minimum: 10). If you need it to be towards on the right of the
18513  * sensor, set it to higher value (maximum: 80). Set point is also useful while
18514  * tracking an edge of dark and light areas.
18515  * The port must be configured as a Lowspeed port before using this function.
18516  *
18517  * \param _port The sensor port. See \ref NBCInputPortConstants.
18518  * \param _i2caddr The sensor I2C address. See sensor documentation for this value.
18519  * \param _value The new setpoint value (10..80).
18520  * \param _result A status code indicating whether the operation completed successfully or not.
18521  * See \ref TCommLSCheckStatus for possible Result values.
18522  */
18523 #define SetNXTLineLeaderSetpoint(_port, _i2caddr, _value, _result) __MSWriteToRegister(_port, _i2caddr, NXTLL_REG_SETPOINT, _value, _result)
18524 
18525 /**
18526  * Write NXTLineLeader Kp value.
18527  * Write a Kp value to the NXTLineLeader device. This value divided by PID
18528  * Factor for Kp is the Proportional value for the PID control. Suggested value
18529  * is 25 with a divisor factor of 32 (which is also a factory default), start
18530  * with this value, and tune it to meet your needs. Value ranges
18531  * between 0 and 255.
18532  * The port must be configured as a Lowspeed port before using this function.
18533  *
18534  * \param _port The sensor port. See \ref NBCInputPortConstants.
18535  * \param _i2caddr The sensor I2C address. See sensor documentation for this value.
18536  * \param _value The new Kp value.
18537  * \param _result A status code indicating whether the operation completed successfully or not.
18538  * See \ref TCommLSCheckStatus for possible Result values.
18539  */
18540 #define SetNXTLineLeaderKpValue(_port, _i2caddr, _value, _result) __MSWriteToRegister(_port, _i2caddr, NXTLL_REG_KP_VALUE, _value, _result)
18541 
18542 /**
18543  * Write NXTLineLeader Ki value.
18544  * Write a Ki value to the NXTLineLeader device. This value divided by PID
18545  * Factor for Ki is the Integral value for the PID control. Suggested value
18546  * is 0 with a divisor factor of 32 (which is also a factory default), start
18547  * with this value, and tune it to meet your needs. Value ranges
18548  * between 0 and 255.
18549  * The port must be configured as a Lowspeed port before using this function.
18550  *
18551  * \param _port The sensor port. See \ref NBCInputPortConstants.
18552  * \param _i2caddr The sensor I2C address. See sensor documentation for this value.
18553  * \param _value The new Ki value.
18554  * \param _result A status code indicating whether the operation completed successfully or not.
18555  * See \ref TCommLSCheckStatus for possible Result values.
18556  */
18557 #define SetNXTLineLeaderKiValue(_port, _i2caddr, _value, _result) __MSWriteToRegister(_port, _i2caddr, NXTLL_REG_KI_VALUE, _value, _result)
18558 
18559 /**
18560  * Write NXTLineLeader Kd value.
18561  * Write a Kd value to the NXTLineLeader device. This value divided by PID
18562  * Factor for Kd is the Derivative value for the PID control. Suggested value
18563  * is 8 with a divisor factor of 32 (which is also a factory default), start
18564  * with this value, and tune it to meet your needs. Value ranges
18565  * between 0 and 255.
18566  * The port must be configured as a Lowspeed port before using this function.
18567  *
18568  * \param _port The sensor port. See \ref NBCInputPortConstants.
18569  * \param _i2caddr The sensor I2C address. See sensor documentation for this value.
18570  * \param _value The new Kd value.
18571  * \param _result A status code indicating whether the operation completed successfully or not.
18572  * See \ref TCommLSCheckStatus for possible Result values.
18573  */
18574 #define SetNXTLineLeaderKdValue(_port, _i2caddr, _value, _result) __MSWriteToRegister(_port, _i2caddr, NXTLL_REG_KD_VALUE, _value, _result)
18575 
18576 /**
18577  * Write NXTLineLeader Kp factor.
18578  * Write a Kp divisor factor to the NXTLineLeader device. Value ranges between
18579  * 1 and 255. Change this value if you need more granularities in Kp value.
18580  * The port must be configured as a Lowspeed port before using this function.
18581  *
18582  * \param _port The sensor port. See \ref NBCInputPortConstants.
18583  * \param _i2caddr The sensor I2C address. See sensor documentation for this value.
18584  * \param _value The new Kp factor.
18585  * \param _result A status code indicating whether the operation completed successfully or not.
18586  * See \ref TCommLSCheckStatus for possible Result values.
18587  */
18588 #define SetNXTLineLeaderKpFactor(_port, _i2caddr, _value, _result) __MSWriteToRegister(_port, _i2caddr, NXTLL_REG_KP_FACTOR, _value, _result)
18589 
18590 /**
18591  * Write NXTLineLeader Ki factor.
18592  * Write a Ki divisor factor to the NXTLineLeader device. Value ranges between
18593  * 1 and 255. Change this value if you need more granularities in Ki value.
18594  * The port must be configured as a Lowspeed port before using this function.
18595  *
18596  * \param _port The sensor port. See \ref NBCInputPortConstants.
18597  * \param _i2caddr The sensor I2C address. See sensor documentation for this value.
18598  * \param _value The new Ki factor.
18599  * \param _result A status code indicating whether the operation completed successfully or not.
18600  * See \ref TCommLSCheckStatus for possible Result values.
18601  */
18602 #define SetNXTLineLeaderKiFactor(_port, _i2caddr, _value, _result) __MSWriteToRegister(_port, _i2caddr, NXTLL_REG_KI_FACTOR, _value, _result)
18603 
18604 /**
18605  * Write NXTLineLeader Kd factor.
18606  * Write a Kd divisor factor to the NXTLineLeader device. Value ranges between
18607  * 1 and 255. Change this value if you need more granularities in Kd value.
18608  * The port must be configured as a Lowspeed port before using this function.
18609  *
18610  * \param _port The sensor port. See \ref NBCInputPortConstants.
18611  * \param _i2caddr The sensor I2C address. See sensor documentation for this value.
18612  * \param _value The new Kd factor.
18613  * \param _result A status code indicating whether the operation completed successfully or not.
18614  * See \ref TCommLSCheckStatus for possible Result values.
18615  */
18616 #define SetNXTLineLeaderKdFactor(_port, _i2caddr, _value, _result) __MSWriteToRegister(_port, _i2caddr, NXTLL_REG_KD_FACTOR, _value, _result)
18617 
18618 /**
18619  * Configure NRLink in 2400 baud mode.
18620  * Configure the mindsensors NRLink device in 2400 baud mode. The port
18621  * must be configured as a Lowspeed port before using this function.
18622  *
18623  * \param _port The sensor port. See \ref NBCInputPortConstants.
18624  * \param _i2caddr The sensor I2C address. See sensor documentation for this value.
18625  * \param _result The function call result.
18626  */
18627 #define NRLink2400(_port, _i2caddr, _result) __I2CSendCmd(_port, _i2caddr, NRLINK_CMD_2400, _result)
18628 
18629 /**
18630  * Configure NRLink in 4800 baud mode.
18631  * Configure the mindsensors NRLink device in 4800 baud mode. The port
18632  * must be configured as a Lowspeed port before using this function.
18633  *
18634  * \param _port The sensor port. See \ref NBCInputPortConstants.
18635  * \param _i2caddr The sensor I2C address. See sensor documentation for this value.
18636  * \param _result The function call result.
18637  */
18638 #define NRLink4800(_port, _i2caddr, _result) __I2CSendCmd(_port, _i2caddr, NRLINK_CMD_4800, _result)
18639 
18640 /**
18641  * Flush NRLink buffers.
18642  * Flush the mindsensors NRLink device buffers. The port
18643  * must be configured as a Lowspeed port before using this function.
18644  *
18645  * \param _port The sensor port. See \ref NBCInputPortConstants.
18646  * \param _i2caddr The sensor I2C address. See sensor documentation for this value.
18647  * \param _result The function call result.
18648  */
18649 #define NRLinkFlush(_port, _i2caddr, _result) __I2CSendCmd(_port, _i2caddr, NRLINK_CMD_FLUSH, _result)
18650 
18651 /**
18652  * Configure NRLink in IR long mode.
18653  * Configure the mindsensors NRLink device in IR long mode. The port
18654  * must be configured as a Lowspeed port before using this function.
18655  *
18656  * \param _port The sensor port. See \ref NBCInputPortConstants.
18657  * \param _i2caddr The sensor I2C address. See sensor documentation for this value.
18658  * \param _result The function call result.
18659  */
18660 #define NRLinkIRLong(_port, _i2caddr, _result) __I2CSendCmd(_port, _i2caddr, NRLINK_CMD_IR_LONG, _result)
18661 
18662 /**
18663  * Configure NRLink in IR short mode.
18664  * Configure the mindsensors NRLink device in IR short mode. The port
18665  * must be configured as a Lowspeed port before using this function.
18666  *
18667  * \param _port The sensor port. See \ref NBCInputPortConstants.
18668  * \param _i2caddr The sensor I2C address. See sensor documentation for this value.
18669  * \param _result The function call result.
18670  */
18671 #define NRLinkIRShort(_port, _i2caddr, _result) __I2CSendCmd(_port, _i2caddr, NRLINK_CMD_IR_SHORT, _result)
18672 
18673 /**
18674  * Configure NRLink in power function mode.
18675  * Configure the mindsensors NRLink device in power function mode. The port
18676  * must be configured as a Lowspeed port before using this function.
18677  *
18678  * \param _port The sensor port. See \ref NBCInputPortConstants.
18679  * \param _i2caddr The sensor I2C address. See sensor documentation for this value.
18680  * \param _result The function call result.
18681  */
18682 #define NRLinkSetPF(_port, _i2caddr, _result) __I2CSendCmd(_port, _i2caddr, NRLINK_CMD_SET_PF, _result)
18683 
18684 /**
18685  * Configure NRLink in RCX mode.
18686  * Configure the mindsensors NRLink device in RCX mode. The port
18687  * must be configured as a Lowspeed port before using this function.
18688  *
18689  * \param _port The sensor port. See \ref NBCInputPortConstants.
18690  * \param _i2caddr The sensor I2C address. See sensor documentation for this value.
18691  * \param _result The function call result.
18692  */
18693 #define NRLinkSetRCX(_port, _i2caddr, _result) __I2CSendCmd(_port, _i2caddr, NRLINK_CMD_SET_RCX, _result)
18694 
18695 /**
18696  * Configure NRLink in IR train mode.
18697  * Configure the mindsensors NRLink device in IR train mode. The port
18698  * must be configured as a Lowspeed port before using this function.
18699  *
18700  * \param _port The sensor port. See \ref NBCInputPortConstants.
18701  * \param _i2caddr The sensor I2C address. See sensor documentation for this value.
18702  * \param _result The function call result.
18703  */
18704 #define NRLinkSetTrain(_port, _i2caddr, _result) __I2CSendCmd(_port, _i2caddr, NRLINK_CMD_SET_TRAIN, _result)
18705 
18706 /**
18707  * Configure NRLink in raw IR transmit mode.
18708  * Configure the mindsensors NRLink device in raw IR transmit mode. The port
18709  * must be configured as a Lowspeed port before using this function.
18710  *
18711  * \param _port The sensor port. See \ref NBCInputPortConstants.
18712  * \param _i2caddr The sensor I2C address. See sensor documentation for this value.
18713  * \param _result The function call result.
18714  */
18715 #define NRLinkTxRaw(_port, _i2caddr, _result) __I2CSendCmd(_port, _i2caddr, NRLINK_CMD_TX_RAW, _result)
18716 
18717 /**
18718  * Read NRLink status.
18719  * Read the status of the mindsensors NRLink device. The port
18720  * must be configured as a Lowspeed port before using this function.
18721  *
18722  * \param _port The sensor port. See \ref NBCInputPortConstants.
18723  * \param _i2caddr The sensor I2C address. See sensor documentation for this value.
18724  * \param _value The mindsensors NRLink status.
18725  * \param _result The function call result.
18726  */
18727 #define ReadNRLinkStatus(_port, _i2caddr, _value, _result) __ReadNRLinkStatus(_port, _i2caddr, _value, _result)
18728 
18729 /**
18730  * Run NRLink macro.
18731  * Run the specified mindsensors NRLink device macro. The port
18732  * must be configured as a Lowspeed port before using this function.
18733  *
18734  * \param _port The sensor port. See \ref NBCInputPortConstants.
18735  * \param _i2caddr The sensor I2C address. See sensor documentation for this value.
18736  * \param _macro The address of the macro to execute.
18737  * \param _result The function call result.
18738  */
18739 #define RunNRLinkMacro(_port, _i2caddr, _macro, _result) __RunNRLinkMacro(_port, _i2caddr, _macro, _result)
18740 
18741 /**
18742  * Write data to NRLink.
18743  * Write data to the mindsensors NRLink device on the specified port. The port
18744  * must be configured as a Lowspeed port before using this function.
18745  *
18746  * \param _port The sensor port. See \ref NBCInputPortConstants.
18747  * \param _i2caddr The sensor I2C address. See sensor documentation for this value.
18748  * \param _bytes A byte array containing the data to write.
18749  * \param _result The function call result.
18750  */
18751 #define WriteNRLinkBytes(_port, _i2caddr, _bytes, _result) __WriteNRLinkBytes(_port, _i2caddr, _bytes, _result)
18752 
18753 /**
18754  * Read data from NRLink.
18755  * Read data from the mindsensors NRLink device on the specified port. The port
18756  * must be configured as a Lowspeed port before using this function.
18757  *
18758  * \param _port The sensor port. See \ref NBCInputPortConstants.
18759  * \param _i2caddr The sensor I2C address. See sensor documentation for this value.
18760  * \param _bytes A byte array that will contain the data read from the device on output.
18761  * \param _result The function call result.
18762  */
18763 #define ReadNRLinkBytes(_port, _i2caddr, _bytes, _result) __ReadNRLinkBytes(_port, _i2caddr, _bytes, _result)
18764 
18765 /**
18766  * MSIRTrain function.
18767  * Control an IR Train receiver set to the specified channel using the
18768  * mindsensors NRLink device. Valid function values are \ref TRAIN_FUNC_STOP,
18769  * \ref TRAIN_FUNC_INCR_SPEED, \ref TRAIN_FUNC_DECR_SPEED, and \ref TRAIN_FUNC_TOGGLE_LIGHT.
18770  * Valid channels are \ref TRAIN_CHANNEL_1 through \ref TRAIN_CHANNEL_3 and
18771  * \ref TRAIN_CHANNEL_ALL. The port must be configured as a Lowspeed port before
18772  * using this function.
18773  *
18774  * \param _port The sensor port. See \ref NBCInputPortConstants.
18775  * \param _i2caddr The sensor I2C address. See sensor documentation for this value.
18776  * \param _channel The IR Train channel.  See \ref IRTrainChannels.
18777  * \param _func The IR Train function. See \ref IRTrainFuncs
18778  * \param _result The function call result. \ref NO_ERR or \ref CommandCommErrors.
18779  */
18780 #define MSIRTrain(_port, _i2caddr, _channel, _func, _result) \
18781   __MSIRTrain(_port, _i2caddr, _channel, _func, FALSE, _result)
18782 
18783 /**
18784  * MSPFComboDirect function.
18785  * Execute a pair of Power Function motor commands on the specified channel
18786  * using the mindsensors NRLink device. Commands for outa and outb are
18787  * PF_CMD_STOP, PF_CMD_REV, PF_CMD_FWD, and \ref PF_CMD_BRAKE. Valid channels are
18788  * PF_CHANNEL_1 through PF_CHANNEL_4. The port must be configured as a
18789  * Lowspeed port before using this function.
18790  *
18791  * \param _port The sensor port. See \ref NBCInputPortConstants.
18792  * \param _i2caddr The sensor I2C address. See sensor documentation for this value.
18793  * \param _channel The Power Function channel.  See \ref PFChannelConstants.
18794  * \param _outa The Power Function command for output A. See \ref PFCmdConstants.
18795  * \param _outb The Power Function command for output B. See \ref PFCmdConstants.
18796  * \param _result The function call result. \ref NO_ERR or \ref CommandCommErrors.
18797  */
18798 #define MSPFComboDirect(_port, _i2caddr, _channel, _outa, _outb, _result) \
18799   __MSPFComboDirect(_port, _i2caddr, _channel, _outa, _outb, _result)
18800 
18801 /**
18802  * MSPFComboPWM function.
18803  * Control the speed of both outputs on a Power Function receiver set to the
18804  * specified channel using the mindsensors NRLink device. Valid output values
18805  * are \ref PF_PWM_FLOAT, \ref PF_PWM_FWD1, \ref PF_PWM_FWD2, \ref PF_PWM_FWD3, \ref PF_PWM_FWD4,
18806  * \ref PF_PWM_FWD5, \ref PF_PWM_FWD6, \ref PF_PWM_FWD7, \ref PF_PWM_BRAKE, \ref PF_PWM_REV7,
18807  * \ref PF_PWM_REV6, \ref PF_PWM_REV5, \ref PF_PWM_REV4, \ref PF_PWM_REV3, \ref PF_PWM_REV2, and
18808  * \ref PF_PWM_REV1. Valid channels are \ref PF_CHANNEL_1 through \ref PF_CHANNEL_4. The
18809  * port must be configured as a Lowspeed port before using this function.
18810  *
18811  * \param _port The sensor port. See \ref NBCInputPortConstants.
18812  * \param _i2caddr The sensor I2C address. See sensor documentation for this value.
18813  * \param _channel The Power Function channel.  See \ref PFChannelConstants.
18814  * \param _outa The Power Function PWM command for output A. See \ref PFPWMOptions.
18815  * \param _outb The Power Function PWM command for output B. See \ref PFPWMOptions.
18816  * \param _result The function call result. \ref NO_ERR or \ref CommandCommErrors.
18817  */
18818 #define MSPFComboPWM(_port, _i2caddr, _channel, _outa, _outb, _result) \
18819   __MSPFComboPWM(_port, _i2caddr, _channel, _outa, _outb, _result)
18820 
18821 /**
18822  * MSPFRawOutput function.
18823  * Control a Power Function receiver set to the specified channel using the
18824  * mindsensors NRLink device. Build the raw data stream using the 3 nibbles
18825  * (4 bit values). The port must be configured as a Lowspeed port before using
18826  * this function.
18827  *
18828  * \param _port The sensor port. See \ref NBCInputPortConstants.
18829  * \param _i2caddr The sensor I2C address. See sensor documentation for this value.
18830  * \param _nibble0 The first raw data nibble.
18831  * \param _nibble1 The second raw data nibble.
18832  * \param _nibble2 The third raw data nibble.
18833  * \param _result The function call result. \ref NO_ERR or \ref CommandCommErrors.
18834  */
18835 #define MSPFRawOutput(_port, _i2caddr, _nibble0, _nibble1, _nibble2, _result) \
18836   __MSPFRawOutput(_port, _i2caddr, _nibble0, _nibble1, _nibble2, _result)
18837 
18838 /**
18839  * MSPFRepeat function.
18840  * Repeat sending the last Power Function command using the mindsensors
18841  * NRLink device. Specify the number of times to repeat the command and the
18842  * number of milliseconds of delay between each repetition. The port must be
18843  * configured as a Lowspeed port before using this function.
18844  *
18845  * \param _port The sensor port. See \ref NBCInputPortConstants.
18846  * \param _i2caddr The sensor I2C address. See sensor documentation for this value.
18847  * \param _count The number of times to repeat the command.
18848  * \param _delay The number of milliseconds to delay between each repetition.
18849  * \param _result The function call result. \ref NO_ERR or \ref CommandCommErrors.
18850  */
18851 #define MSPFRepeat(_port, _i2caddr, _count, _delay, _result) \
18852   __MSPFRepeatLastCommand(_port, _i2caddr, _count, _delay, _result)
18853 
18854 /**
18855  * MSPFSingleOutputCST function.
18856  * Control a single output on a Power Function receiver set to the specified
18857  * channel using the mindsensors NRLink device. Select the desired output
18858  * using \ref PF_OUT_A or \ref PF_OUT_B. Valid functions are \ref PF_CST_CLEAR1_CLEAR2,
18859  * \ref PF_CST_SET1_CLEAR2, \ref PF_CST_CLEAR1_SET2, \ref PF_CST_SET1_SET2,
18860  * \ref PF_CST_INCREMENT_PWM, \ref PF_CST_DECREMENT_PWM, \ref PF_CST_FULL_FWD,
18861  * \ref PF_CST_FULL_REV, and \ref PF_CST_TOGGLE_DIR. Valid channels are
18862  * \ref PF_CHANNEL_1 through \ref PF_CHANNEL_4. The port must be configured as a
18863  * Lowspeed port before using this function.
18864  *
18865  * \param _port The sensor port. See \ref NBCInputPortConstants.
18866  * \param _i2caddr The sensor I2C address. See sensor documentation for this value.
18867  * \param _channel The Power Function channel.  See \ref PFChannelConstants.
18868  * \param _out The Power Function output. See \ref PFOutputs.
18869  * \param _func The Power Function CST function. See \ref PFCSTOptions.
18870  * \param _result The function call result. \ref NO_ERR or \ref CommandCommErrors.
18871  */
18872 #define MSPFSingleOutputCST(_port, _i2caddr, _channel, _out, _func, _result) \
18873   __MSPFSingleOutput(_port, _i2caddr, _channel, _out, _func, TRUE, _result)
18874 
18875 /**
18876  * MSPFSingleOutputPWM function.
18877  * Control the speed of a single output on a Power Function receiver set to
18878  * the specified channel using the mindsensors NRLink device. Select the
18879  * desired output using \ref PF_OUT_A or \ref PF_OUT_B. Valid functions are
18880  * \ref PF_PWM_FLOAT, \ref PF_PWM_FWD1, \ref PF_PWM_FWD2, \ref PF_PWM_FWD3, \ref PF_PWM_FWD4,
18881  * \ref PF_PWM_FWD5, \ref PF_PWM_FWD6, \ref PF_PWM_FWD7, \ref PF_PWM_BRAKE, \ref PF_PWM_REV7,
18882  * \ref PF_PWM_REV6, \ref PF_PWM_REV5, \ref PF_PWM_REV4, \ref PF_PWM_REV3, \ref PF_PWM_REV2, and
18883  * \ref PF_PWM_REV1. Valid channels are \ref PF_CHANNEL_1 through \ref PF_CHANNEL_4. The
18884  * port must be configured as a Lowspeed port before using this function.
18885  *
18886  * \param _port The sensor port. See \ref NBCInputPortConstants.
18887  * \param _i2caddr The sensor I2C address. See sensor documentation for this value.
18888  * \param _channel The Power Function channel.  See \ref PFChannelConstants.
18889  * \param _out The Power Function output. See \ref PFOutputs.
18890  * \param _func The Power Function PWM function. See \ref PFPWMOptions.
18891  * \param _result The function call result. \ref NO_ERR or \ref CommandCommErrors.
18892  */
18893 #define MSPFSingleOutputPWM(_port, _i2caddr, _channel, _out, _func, _result) \
18894   __MSPFSingleOutput(_port, _i2caddr, _channel, _out, _func, FALSE, _result)
18895 
18896 /**
18897  * MSPFSinglePin function.
18898  * Control a single pin on a Power Function receiver set to the specified
18899  * channel using the mindsensors NRLink device. Select the desired output
18900  * using \ref PF_OUT_A or \ref PF_OUT_B.  Select the desired pin using \ref PF_PIN_C1 or
18901  * \ref PF_PIN_C2. Valid functions are \ref PF_FUNC_NOCHANGE, \ref PF_FUNC_CLEAR,
18902  * \ref PF_FUNC_SET, and \ref PF_FUNC_TOGGLE. Valid channels are \ref PF_CHANNEL_1 through
18903  * \ref PF_CHANNEL_4. Specify whether the mode by passing true (continuous) or
18904  * false (timeout) as the final parameter. The port must be configured as a
18905  * Lowspeed port before using this function.
18906  *
18907  * \param _port The sensor port. See \ref NBCInputPortConstants.
18908  * \param _i2caddr The sensor I2C address. See sensor documentation for this value.
18909  * \param _channel The Power Function channel.  See \ref PFChannelConstants.
18910  * \param _out The Power Function output. See \ref PFOutputs.
18911  * \param _pin The Power Function pin. See \ref PFPinConstants.
18912  * \param _func The Power Function single pin function. See \ref PFPinFuncs.
18913  * \param _cont Control whether the mode is continuous or timeout.
18914  * \param _result The function call result. \ref NO_ERR or \ref CommandCommErrors.
18915  */
18916 #define MSPFSinglePin(_port, _i2caddr, _channel, _out, _pin, _func, _cont, _result) \
18917   __MSPFSinglePin(_port, _i2caddr, _channel, _out, _pin, _func, _cont, _result)
18918 
18919 /**
18920  * MSPFTrain function.
18921  * Control both outputs on a Power Function receiver set to the specified
18922  * channel using the mindsensors NRLink device as if it were an IR Train
18923  * receiver. Valid function values are \ref TRAIN_FUNC_STOP, \ref TRAIN_FUNC_INCR_SPEED,
18924  * \ref TRAIN_FUNC_DECR_SPEED, and \ref TRAIN_FUNC_TOGGLE_LIGHT. Valid channels are
18925  * PF_CHANNEL_1 through PF_CHANNEL_4. The port must be configured as a
18926  * Lowspeed port before using this function.
18927  *
18928  * \param _port The sensor port. See \ref NBCInputPortConstants.
18929  * \param _i2caddr The sensor I2C address. See sensor documentation for this value.
18930  * \param _channel The Power Function channel.  See \ref PFChannelConstants.
18931  * \param _func The Power Function train function. See \ref IRTrainFuncs.
18932  * \param _result The function call result. \ref NO_ERR or \ref CommandCommErrors.
18933  */
18934 #define MSPFTrain(_port, _i2caddr, _channel, _func, _result) \
18935   __MSIRTrain(_port, _i2caddr, _channel, _func, TRUE, _result)
18936 
18937 /**
18938  * MSRCXSetIRLinkPort function.
18939  * Set the global port in advance of using the MSRCX* and MSScout* API
18940  * functions for sending RCX and Scout messages over the mindsensors NRLink
18941  * device. The port must be configured as a Lowspeed port before using any of
18942  * the mindsensors RCX and Scout NRLink functions.
18943  *
18944  * \param _port The sensor port. See \ref NBCInputPortConstants.
18945  * \param _i2caddr The sensor I2C address. See sensor documentation for this value.
18946  */
18947 #define MSRCXSetNRLinkPort(_port, _i2caddr) __MSRCXSetNRLink(_port, _i2caddr)
18948 
18949 /**
18950  * MSRCXBatteryLevel function.
18951  * Send the BatteryLevel command to an RCX to read the current battery level.
18952  *
18953  * \param _result The RCX battery level.
18954  */
18955 #define MSRCXBatteryLevel(_result) __MSRCXBatteryLevel(_result)
18956 
18957 /**
18958  * MSRCXPoll function.
18959  * Send the Poll command to an RCX to read a signed 2-byte value at the
18960  * specified source and value combination.
18961  *
18962  * \param _src The RCX source.  See \ref RCXSourceConstants.
18963  * \param _value The RCX value.
18964  * \param _result The value read from the specified port and value.
18965  */
18966 #define MSRCXPoll(_src, _value, _result) __MSRCXPoll(_src, _value, _result)
18967 
18968 /**
18969  * MSRCXPollMemory function.
18970  * Send the PollMemory command to an RCX.
18971  *
18972  * \param _memaddress The RCX memory address.
18973  * \param _result The value read from the specified address.
18974  */
18975 #define MSRCXPollMemory(_memaddress, _result) __MSRCXPollMemory(_memaddress, _result)
18976 
18977 /**
18978  * MSRCXAbsVar function.
18979  * Send the AbsVar command to an RCX.
18980  *
18981  * \param _varnum The variable number to change.
18982  * \param _src The RCX source.  See \ref RCXSourceConstants.
18983  * \param _value The RCX value.
18984  */
18985 #define MSRCXAbsVar(_varnum, _src, _value) __MSRCXVarOp(RCX_AbsVarOp, _varnum, _src, _value)
18986 
18987 /**
18988  * MSRCXAddToDatalog function.
18989  * Send the AddToDatalog command to an RCX.
18990  *
18991  * \param _src The RCX source.  See \ref RCXSourceConstants.
18992  * \param _value The RCX value.
18993  */
18994 #define MSRCXAddToDatalog(_src, _value) __MSRCXAddToDatalog(_src, _value)
18995 
18996 /**
18997  * MSRCXAndVar function.
18998  * Send the AndVar command to an RCX.
18999  *
19000  * \param _varnum The variable number to change.
19001  * \param _src The RCX source.  See \ref RCXSourceConstants.
19002  * \param _value The RCX value.
19003  */
19004 #define MSRCXAndVar(_varnum, _src, _value) __MSRCXVarOp(RCX_AndVarOp, _varnum, _src, _value)
19005 
19006 /**
19007  * MSRCXBoot function.
19008  * Send the Boot command to an RCX.
19009  */
19010 #define MSRCXBoot() __MSRCXBoot()
19011 
19012 /**
19013  * MSRCXCalibrateEvent function.
19014  * Send the CalibrateEvent command to an RCX.
19015  *
19016  * \param _evt The event number.
19017  * \param _low The low threshold.
19018  * \param _hi The high threshold.
19019  * \param _hyst The hysterisis value.
19020  */
19021 #define MSRCXCalibrateEvent(_evt, _low, _hi, _hyst) __MSRCXCalibrateEvent(_evt, _low, _hi, _hyst)
19022 
19023 /**
19024  * MSRCXClearAllEvents function.
19025  * Send the ClearAllEvents command to an RCX.
19026  */
19027 #define MSRCXClearAllEvents() __MSRCXOpNoArgs(RCX_ClearAllEventsOp)
19028 
19029 /**
19030  * MSRCXClearCounter function.
19031  * Send the ClearCounter command to an RCX.
19032  *
19033  * \param _counter The counter to clear.
19034  */
19035 #define MSRCXClearCounter(_counter) __MSRCXClearCounter(_counter)
19036 
19037 /**
19038  * MSRCXClearMsg function.
19039  * Send the ClearMsg command to an RCX.
19040  */
19041 #define MSRCXClearMsg() __MSRCXOpNoArgs(RCX_ClearMsgOp)
19042 
19043 /**
19044  * MSRCXClearSensor function.
19045  * Send the ClearSensor command to an RCX.
19046  *
19047  * \param _port The RCX port number.
19048  */
19049 #define MSRCXClearSensor(_port) __MSRCXClearSensor(_port)
19050 
19051 /**
19052  * MSRCXClearSound function.
19053  * Send the ClearSound command to an RCX.
19054  */
19055 #define MSRCXClearSound() __MSRCXOpNoArgs(RCX_ClearSoundOp)
19056 
19057 /**
19058  * MSRCXClearTimer function.
19059  * Send the ClearTimer command to an RCX.
19060  *
19061  * \param _timer The timer to clear.
19062  */
19063 #define MSRCXClearTimer(_timer) __MSRCXClearTimer(_timer)
19064 
19065 /**
19066  * MSRCXCreateDatalog function.
19067  * Send the CreateDatalog command to an RCX.
19068  *
19069  * \param _size The new datalog size.
19070  */
19071 #define MSRCXCreateDatalog(_size) __MSRCXCreateDatalog(_size)
19072 
19073 /**
19074  * MSRCXDecCounter function.
19075  * Send the DecCounter command to an RCX.
19076  *
19077  * \param _counter The counter to decrement.
19078  */
19079 #define MSRCXDecCounter(_counter) __MSRCXDecCounter(_counter)
19080 
19081 /**
19082  * MSRCXDeleteSub function.
19083  * Send the DeleteSub command to an RCX.
19084  *
19085  * \param _s The subroutine number to delete.
19086  */
19087 #define MSRCXDeleteSub(_s) __MSRCXDeleteSub(_s)
19088 
19089 /**
19090  * MSRCXDeleteSubs function.
19091  * Send the DeleteSubs command to an RCX.
19092  */
19093 #define MSRCXDeleteSubs() __MSRCXOpNoArgs(RCX_DeleteSubsOp)
19094 
19095 /**
19096  * MSRCXDeleteTask function.
19097  * Send the DeleteTask command to an RCX.
19098  *
19099  * \param _t The task number to delete.
19100  */
19101 #define MSRCXDeleteTask(_t) __MSRCXDeleteTask(_t)
19102 
19103 /**
19104  * MSRCXDeleteTasks function.
19105  * Send the DeleteTasks command to an RCX.
19106  */
19107 #define MSRCXDeleteTasks() __MSRCXOpNoArgs(RCX_DeleteTasksOp)
19108 
19109 /**
19110  * MSRCXDisableOutput function.
19111  * Send the DisableOutput command to an RCX.
19112  *
19113  * \param _outputs The RCX output(s) to disable. See \ref RCXOutputConstants.
19114  */
19115 #define MSRCXDisableOutput(_outputs) __MSRCXSetGlobalOutput(_outputs, RCX_OUT_OFF)
19116 
19117 /**
19118  * MSRCXDivVar function.
19119  * Send the DivVar command to an RCX.
19120  *
19121  * \param _varnum The variable number to change.
19122  * \param _src The RCX source.  See \ref RCXSourceConstants.
19123  * \param _value The RCX value.
19124  */
19125 #define MSRCXDivVar(_varnum, _src, _value) __MSRCXVarOp(RCX_DivVarOp, _varnum, _src, _value)
19126 
19127 /**
19128  * MSRCXEnableOutput function.
19129  * Send the EnableOutput command to an RCX.
19130  *
19131  * \param _outputs The RCX output(s) to enable. See \ref RCXOutputConstants.
19132  */
19133 #define MSRCXEnableOutput(_outputs) __MSRCXSetGlobalOutput(_outputs, RCX_OUT_ON)
19134 
19135 /**
19136  * MSRCXEvent function.
19137  * Send the Event command to an RCX.
19138  *
19139  * \param _src The RCX source.  See \ref RCXSourceConstants.
19140  * \param _value The RCX value.
19141  */
19142 #define MSRCXEvent(_src, _value) __MSRCXEvent(_src, _value)
19143 
19144 /**
19145  * MSRCXFloat function.
19146  * Send commands to an RCX to float the specified outputs.
19147  *
19148  * \param _outputs The RCX output(s) to float. See \ref RCXOutputConstants.
19149  */
19150 #define MSRCXFloat(_outputs) __MSRCXSetOutput(_outputs, RCX_OUT_FLOAT)
19151 
19152 /**
19153  * MSRCXFwd function.
19154  * Send commands to an RCX to set the specified outputs to the forward direction.
19155  *
19156  * \param _outputs The RCX output(s) to set forward. See \ref RCXOutputConstants.
19157  */
19158 #define MSRCXFwd(_outputs) __MSRCXSetDirection(_outputs, RCX_OUT_FWD)
19159 
19160 /**
19161  * MSRCXIncCounter function.
19162  * Send the IncCounter command to an RCX.
19163  *
19164  * \param _counter The counter to increment.
19165  */
19166 #define MSRCXIncCounter(_counter) __MSRCXIncCounter(_counter)
19167 
19168 /**
19169  * MSRCXInvertOutput function.
19170  * Send the InvertOutput command to an RCX.
19171  *
19172  * \param _outputs The RCX output(s) to invert. See \ref RCXOutputConstants.
19173  */
19174 #define MSRCXInvertOutput(_outputs) __MSRCXSetGlobalDirection(_outputs, RCX_OUT_REV)
19175 
19176 /**
19177  * MSRCXMulVar function.
19178  * Send the MulVar command to an RCX.
19179  *
19180  * \param _varnum The variable number to change.
19181  * \param _src The RCX source.  See \ref RCXSourceConstants.
19182  * \param _value The RCX value.
19183  */
19184 #define MSRCXMulVar(_varnum, _src, _value) __MSRCXVarOp(RCX_MulVarOp, _varnum, _src, _value)
19185 
19186 /**
19187  * MSRCXMuteSound function.
19188  * Send the MuteSound command to an RCX.
19189  */
19190 #define MSRCXMuteSound() __MSRCXOpNoArgs(RCX_MuteSoundOp)
19191 
19192 /**
19193  * MSRCXObvertOutput function.
19194  * Send the ObvertOutput command to an RCX.
19195  *
19196  * \param _outputs The RCX output(s) to obvert. See \ref RCXOutputConstants.
19197  */
19198 #define MSRCXObvertOutput(_outputs) __MSRCXSetGlobalDirection(_outputs, RCX_OUT_FWD)
19199 
19200 /**
19201  * MSRCXOff function.
19202  * Send commands to an RCX to turn off the specified outputs.
19203  *
19204  * \param _outputs The RCX output(s) to turn off. See \ref RCXOutputConstants.
19205  */
19206 #define MSRCXOff(_outputs) __MSRCXSetOutput(_outputs, RCX_OUT_OFF)
19207 
19208 /**
19209  * MSRCXOn function.
19210  * Send commands to an RCX to turn on the specified outputs.
19211  *
19212  * \param _outputs The RCX output(s) to turn on. See \ref RCXOutputConstants.
19213  */
19214 #define MSRCXOn(_outputs) __MSRCXSetOutput(_outputs, RCX_OUT_ON)
19215 
19216 /**
19217  * MSRCXOnFor function.
19218  * Send commands to an RCX to turn on the specified outputs in the forward
19219  * direction for the specified duration.
19220  *
19221  * \param _outputs The RCX output(s) to turn on. See \ref RCXOutputConstants.
19222  * \param _ms The number of milliseconds to leave the outputs on
19223  */
19224 #define MSRCXOnFor(_outputs, _ms) __MSRCXOnFor(_outputs, _ms)
19225 
19226 /**
19227  * MSRCXOnFwd function.
19228  * Send commands to an RCX to turn on the specified outputs in the forward
19229  * direction.
19230  *
19231  * \param _outputs The RCX output(s) to turn on in the forward direction. See \ref RCXOutputConstants.
19232  */
19233 #define MSRCXOnFwd(_outputs) __MSRCXOnFwd(_outputs)
19234 
19235 /**
19236  * MSRCXOnRev function.
19237  * Send commands to an RCX to turn on the specified outputs in the reverse direction.
19238  *
19239  * \param _outputs The RCX output(s) to turn on in the reverse direction. See \ref RCXOutputConstants.
19240  */
19241 #define MSRCXOnRev(_outputs) __MSRCXOnRev(_outputs)
19242 
19243 /**
19244  * MSRCXOrVar function.
19245  * Send the OrVar command to an RCX.
19246  *
19247  * \param _varnum The variable number to change.
19248  * \param _src The RCX source.  See \ref RCXSourceConstants.
19249  * \param _value The RCX value.
19250  */
19251 #define MSRCXOrVar(_varnum, _src, _value) __MSRCXVarOp(RCX_OrVarOp, _varnum, _src, _value)
19252 
19253 /**
19254  * MSRCXPBTurnOff function.
19255  * Send the PBTurnOff command to an RCX.
19256  */
19257 #define MSRCXPBTurnOff() __MSRCXOpNoArgs(RCX_PBTurnOffOp)
19258 
19259 /**
19260  * MSRCXPing function.
19261  * Send the Ping command to an RCX.
19262  */
19263 #define MSRCXPing() __MSRCXOpNoArgs(RCX_PingOp)
19264 
19265 /**
19266  * MSRCXPlaySound function.
19267  * Send the PlaySound command to an RCX.
19268  *
19269  * \param _snd The sound number to play.
19270  */
19271 #define MSRCXPlaySound(_snd) __MSRCXPlaySound(_snd)
19272 
19273 /**
19274  * MSRCXPlayTone function.
19275  * Send the PlayTone command to an RCX.
19276  *
19277  * \param _freq The frequency of the tone to play.
19278  * \param _duration The duration of the tone to play.
19279  */
19280 #define MSRCXPlayTone(_freq, _duration) __MSRCXPlayTone(_freq, _duration)
19281 
19282 /**
19283  * MSRCXPlayToneVar function.
19284  * Send the PlayToneVar command to an RCX.
19285  *
19286  * \param _varnum The variable containing the tone frequency to play.
19287  * \param _duration The duration of the tone to play.
19288  */
19289 #define MSRCXPlayToneVar(_varnum, _duration) __MSRCXPlayToneVar(_varnum, _duration)
19290 
19291 /**
19292  * MSRCXRemote function.
19293  * Send the Remote command to an RCX.
19294  *
19295  * \param _cmd The RCX IR remote command to send. See \ref RCXRemoteConstants.
19296  */
19297 #define MSRCXRemote(_cmd) __MSRCXRemote(_cmd)
19298 
19299 /**
19300  * MSRCXReset function.
19301  * Send the Reset command to an RCX.
19302  */
19303 #define MSRCXReset() __MSRCXReset()
19304 
19305 /**
19306  * MSRCXRev function.
19307  * Send commands to an RCX to set the specified outputs to the reverse direction.
19308  *
19309  * \param _outputs The RCX output(s) to reverse direction. See \ref RCXOutputConstants.
19310  */
19311 #define MSRCXRev(_outputs) __MSRCXSetDirection(_outputs, RCX_OUT_REV)
19312 
19313 /**
19314  * MSRCXSelectDisplay function.
19315  * Send the SelectDisplay command to an RCX.
19316  *
19317  * \param _src The RCX source.  See \ref RCXSourceConstants.
19318  * \param _value The RCX value.
19319  */
19320 #define MSRCXSelectDisplay(_src, _value) __MSRCXSelectDisplay(_src, _value)
19321 
19322 /**
19323  * MSRCXSelectProgram function.
19324  * Send the SelectProgram command to an RCX.
19325  *
19326  * \param _prog The program number to select.
19327  */
19328 #define MSRCXSelectProgram(_prog) __MSRCXSelectProgram(_prog)
19329 
19330 /**
19331  * MSRCXSendSerial function.
19332  * Send the SendSerial command to an RCX.
19333  *
19334  * \param _first The first byte address.
19335  * \param _count The number of bytes to send.
19336  */
19337 #define MSRCXSendSerial(_first, _count) __MSRCXSendSerial(_first, _count)
19338 
19339 /**
19340  * MSRCXSet function.
19341  * Send the Set command to an RCX.
19342  *
19343  * \param _dstsrc The RCX destination source.  See \ref RCXSourceConstants.
19344  * \param _dstval The RCX destination value.
19345  * \param _src The RCX source.  See \ref RCXSourceConstants.
19346  * \param _value The RCX value.
19347  */
19348 #define MSRCXSet(_dstsrc, _dstval, _src, _value) __MSRCXSet(_dstsrc, _dstval, _src, _value)
19349 
19350 /**
19351  * MSRCXSetDirection function.
19352  * Send the SetDirection command to an RCX to configure the direction of the specified outputs.
19353  *
19354  * \param _outputs The RCX output(s) to set direction. See \ref RCXOutputConstants.
19355  * \param _dir The RCX output direction. See \ref RCXOutputDirection.
19356  */
19357 #define MSRCXSetDirection(_outputs, _dir) __MSRCXSetDirection(_outputs, _dir)
19358 
19359 /**
19360  * MSRCXSetEvent function.
19361  * Send the SetEvent command to an RCX.
19362  *
19363  * \param _evt The event number to set.
19364  * \param _src The RCX source. See \ref RCXSourceConstants.
19365  * \param _type The event type.
19366  */
19367 #define MSRCXSetEvent(_evt, _src, _type) __MSRCXSetEvent(_evt, _src, _type)
19368 
19369 /**
19370  * MSRCXSetGlobalDirection function.
19371  * Send the SetGlobalDirection command to an RCX.
19372  *
19373  * \param _outputs The RCX output(s) to set global direction. See \ref RCXOutputConstants.
19374  * \param _dir The RCX output direction. See \ref RCXOutputDirection.
19375  */
19376 #define MSRCXSetGlobalDirection(_outputs, _dir) __MSRCXSetGlobalDirection(_outputs, _dir)
19377 
19378 /**
19379  * MSRCXSetGlobalOutput function.
19380  * Send the SetGlobalOutput command to an RCX.
19381  *
19382  * \param _outputs The RCX output(s) to set global mode. See \ref RCXOutputConstants.
19383  * \param _mode The RCX output mode. See \ref RCXOutputMode.
19384  */
19385 #define MSRCXSetGlobalOutput(_outputs, _mode) __MSRCXSetGlobalOutput(_outputs, _mode)
19386 
19387 /**
19388  * MSRCXSetMaxPower function.
19389  * Send the SetMaxPower command to an RCX.
19390  *
19391  * \param _outputs The RCX output(s) to set max power. See \ref RCXOutputConstants.
19392  * \param _pwrsrc The RCX source.  See \ref RCXSourceConstants.
19393  * \param _pwrval The RCX value.
19394  */
19395 #define MSRCXSetMaxPower(_outputs, _pwrsrc, _pwrval) __MSRCXSetMaxPower(_outputs, _pwrsrc, _pwrval)
19396 
19397 /**
19398  * MSRCXSetMessage function.
19399  * Send the SetMessage command to an RCX.
19400  *
19401  * \param _msg The numeric message to send.
19402  */
19403 #define MSRCXSetMessage(_msg) __MSRCXSetMessage(_msg)
19404 
19405 /**
19406  * MSRCXSetOutput function.
19407  * Send the SetOutput command to an RCX to configure the mode of the specified outputs
19408  *
19409  * \param _outputs The RCX output(s) to set mode. See \ref RCXOutputConstants.
19410  * \param _mode The RCX output mode. See \ref RCXOutputMode.
19411  */
19412 #define MSRCXSetOutput(_outputs, _mode) __MSRCXSetOutput(_outputs, _mode)
19413 
19414 /**
19415  * MSRCXSetPower function.
19416  * Send the SetPower command to an RCX to configure the power level of the specified outputs.
19417  *
19418  * \param _outputs The RCX output(s) to set power. See \ref RCXOutputConstants.
19419  * \param _pwrsrc The RCX source.  See \ref RCXSourceConstants.
19420  * \param _pwrval The RCX value.
19421  */
19422 #define MSRCXSetPower(_outputs, _pwrsrc, _pwrval) __MSRCXSetPower(_outputs, _pwrsrc, _pwrval)
19423 
19424 /**
19425  * MSRCXSetPriority function.
19426  * Send the SetPriority command to an RCX.
19427  *
19428  * \param _p The new task priority.
19429  */
19430 #define MSRCXSetPriority(_p) __MSRCXSetPriority(_p)
19431 
19432 /**
19433  * MSRCXSetSensorMode function.
19434  * Send the SetSensorMode command to an RCX.
19435  *
19436  * \param _port The RCX sensor port.
19437  * \param _mode The RCX sensor mode.
19438  */
19439 #define MSRCXSetSensorMode(_port, _mode) __MSRCXSetSensorMode(_port, _mode)
19440 
19441 /**
19442  * MSRCXSetSensorType function.
19443  * Send the SetSensorType command to an RCX.
19444  *
19445  * \param _port The RCX sensor port.
19446  * \param _type The RCX sensor type.
19447  */
19448 #define MSRCXSetSensorType(_port, _type) __MSRCXSetSensorType(_port, _type)
19449 
19450 /**
19451  * MSRCXSetSleepTime function.
19452  * Send the SetSleepTime command to an RCX.
19453  *
19454  * \param _t The new sleep time value.
19455  */
19456 #define MSRCXSetSleepTime(_t) __MSRCXSetSleepTime(_t)
19457 
19458 /**
19459  * MSRCXSetTxPower function.
19460  * Send the SetTxPower command to an RCX.
19461  *
19462  * \param _pwr The IR transmit power level.
19463  */
19464 #define MSRCXSetTxPower(_pwr) __MSRCXSetTxPower(_pwr)
19465 
19466 /**
19467  * MSRCXSetUserDisplay function.
19468  * Send the SetUserDisplay command to an RCX.
19469  *
19470  * \param _src The RCX source.  See \ref RCXSourceConstants.
19471  * \param _value The RCX value.
19472  * \param _precision The number of digits of precision.
19473  */
19474 #define MSRCXSetUserDisplay(_src, _value, _precision) __MSRCXSetUserDisplay(_src, _value, _precision)
19475 
19476 /**
19477  * MSRCXSetVar function.
19478  * Send the SetVar command to an RCX.
19479  *
19480  * \param _varnum The variable number to change.
19481  * \param _src The RCX source.  See \ref RCXSourceConstants.
19482  * \param _value The RCX value.
19483  */
19484 #define MSRCXSetVar(_varnum, _src, _value) __MSRCXVarOp(RCX_SetVarOp, _varnum, _src, _value)
19485 
19486 /**
19487  * MSRCXSetWatch function.
19488  * Send the SetWatch command to an RCX.
19489  *
19490  * \param _hours The new watch time hours value.
19491  * \param _minutes The new watch time minutes value.
19492  */
19493 #define MSRCXSetWatch(_hours, _minutes) __MSRCXSetWatch(_hours, _minutes)
19494 
19495 /**
19496  * MSRCXSgnVar function.
19497  * Send the SgnVar command to an RCX.
19498  *
19499  * \param _varnum The variable number to change.
19500  * \param _src The RCX source.  See \ref RCXSourceConstants.
19501  * \param _value The RCX value.
19502  */
19503 #define MSRCXSgnVar(_varnum, _src, _value) __MSRCXVarOp(RCX_SgnVarOp, _varnum, _src, _value)
19504 
19505 /**
19506  * MSRCXStartTask function.
19507  * Send the StartTask command to an RCX.
19508  *
19509  * \param _t The task number to start.
19510  */
19511 #define MSRCXStartTask(_t) __MSRCXStartTask(_t)
19512 
19513 /**
19514  * MSRCXStopAllTasks function.
19515  * Send the StopAllTasks command to an RCX.
19516  */
19517 #define MSRCXStopAllTasks() __MSRCXOpNoArgs(RCX_StopAllTasksOp)
19518 
19519 /**
19520  * MSRCXStopTask function.
19521  * Send the StopTask command to an RCX.
19522  *
19523  * \param _t The task number to stop.
19524  */
19525 #define MSRCXStopTask(_t) __MSRCXStopTask(_t)
19526 
19527 /**
19528  * MSRCXSubVar function.
19529  * Send the SubVar command to an RCX.
19530  *
19531  * \param _varnum The variable number to change.
19532  * \param _src The RCX source.  See \ref RCXSourceConstants.
19533  * \param _value The RCX value.
19534  */
19535 #define MSRCXSubVar(_varnum, _src, _value) __MSRCXVarOp(RCX_SubVarOp, _varnum, _src, _value)
19536 
19537 /**
19538  * MSRCXSumVar function.
19539  * Send the SumVar command to an RCX.
19540  *
19541  * \param _varnum The variable number to change.
19542  * \param _src The RCX source.  See \ref RCXSourceConstants.
19543  * \param _value The RCX value.
19544  */
19545 #define MSRCXSumVar(_varnum, _src, _value) __MSRCXVarOp(RCX_SumVarOp, _varnum, _src, _value)
19546 
19547 /**
19548  * MSRCXToggle function.
19549  * Send commands to an RCX to toggle the direction of the specified outputs.
19550  *
19551  * \param _outputs The RCX output(s) to toggle. See \ref RCXOutputConstants.
19552  */
19553 #define MSRCXToggle(_outputs) __MSRCXSetDirection(_outputs, RCX_OUT_TOGGLE)
19554 
19555 /**
19556  * MSRCXUnlock function.
19557  * Send the Unlock command to an RCX.
19558  */
19559 #define MSRCXUnlock() __MSRCXUnlock()
19560 
19561 /**
19562  * MSRCXUnmuteSound function.
19563  * Send the UnmuteSound command to an RCX.
19564  */
19565 #define MSRCXUnmuteSound() __MSRCXOpNoArgs(RCX_UnmuteSoundOp)
19566 
19567 /**
19568  * MSScoutCalibrateSensor function.
19569  * Send the CalibrateSensor command to a Scout.
19570  */
19571 #define MSScoutCalibrateSensor() __MSRCXOpNoArgs(RCX_LSCalibrateOp)
19572 
19573 /**
19574  * MSScoutMuteSound function.
19575  * Send the MuteSound command to a Scout.
19576  */
19577 #define MSScoutMuteSound() __MSScoutMuteSound()
19578 
19579 /**
19580  * MSScoutSelectSounds function.
19581  * Send the SelectSounds command to a Scout.
19582  *
19583  * \param _grp The Scout sound group to select.
19584  */
19585 #define MSScoutSelectSounds(_grp) __MSScoutSelectSounds(_grp)
19586 
19587 /**
19588  * MSScoutSendVLL function.
19589  * Send the SendVLL command to a Scout.
19590  *
19591  * \param _src The Scout source.  See \ref RCXSourceConstants.
19592  * \param _value The Scout value.
19593  */
19594 #define MSScoutSendVLL(_src, _value) __MSScoutSendVLL(_src, _value)
19595 
19596 /**
19597  * MSScoutSetCounterLimit function.
19598  * Send the SetCounterLimit command to a Scout.
19599  *
19600  * \param _ctr The counter for which to set the limit.
19601  * \param _src The Scout source.  See \ref RCXSourceConstants.
19602  * \param _value The Scout value.
19603  */
19604 #define MSScoutSetCounterLimit(_ctr, _src, _value) __MSScoutSetCounterLimit(_ctr, _src, _value)
19605 
19606 /**
19607  * MSScoutSetEventFeedback function.
19608  * Send the SetEventFeedback command to a Scout.
19609  *
19610  * \param _src The Scout source.  See \ref RCXSourceConstants.
19611  * \param _value The Scout value.
19612  */
19613 #define MSScoutSetEventFeedback(_src, _value) __MSScoutSetEventFeedback(_src, _value)
19614 
19615 /**
19616  * MSScoutSetLight function.
19617  * Send the SetLight command to a Scout.
19618  *
19619  * \param _x Set the light on or off using this value. See \ref ScoutLightConstants.
19620  */
19621 #define MSScoutSetLight(_x) __MSScoutSetLight(_x)
19622 
19623 /**
19624  * MSScoutSetScoutMode function.
19625  * Send the SetScoutMode command to a Scout.
19626  *
19627  * \param _mode Set the scout mode. See \ref ScoutModeConstants.
19628 */
19629 #define MSScoutSetScoutMode(_mode) __MSScoutSetScoutMode(_mode)
19630 
19631 /**
19632  * MSScoutSetScoutRules function.
19633  * Send the SetScoutRules command to a Scout.
19634  *
19635  * \param _m Scout motion rule. See \ref ScoutMotionRuleConstants.
19636  * \param _t Scout touch rule. See \ref ScoutTouchRuleConstants.
19637  * \param _l Scout light rule. See \ref ScoutLightRuleConstants.
19638  * \param _tm Scout transmit rule. See \ref ScoutTransmitRuleConstants.
19639  * \param _fx Scout special effects rule. See \ref ScoutSpecialEffectConstants.
19640  */
19641 #define MSScoutSetScoutRules(_m, _t, _l, _tm, _fx) __MSScoutSetScoutRules(_m, _t, _l, _tm, _fx)
19642 
19643 /**
19644  * MSScoutSetSensorClickTime function.
19645  * Send the SetSensorClickTime command to a Scout.
19646  *
19647  * \param _src The Scout source.  See \ref RCXSourceConstants.
19648  * \param _value The Scout value.
19649  */
19650 #define MSScoutSetSensorClickTime(_src, _value) __MSScoutSetSensorClickTime(_src, _value)
19651 
19652 /**
19653  * MSScoutSetSensorHysteresis function.
19654  * Send the SetSensorHysteresis command to a Scout.
19655  *
19656  * \param _src The Scout source.  See \ref RCXSourceConstants.
19657  * \param _value The Scout value.
19658  */
19659 #define MSScoutSetSensorHysteresis(_src, _value) __MSScoutSetSensorHysteresis(_src, _value)
19660 
19661 /**
19662  * MSScoutSetSensorLowerLimit function.
19663  * Send the SetSensorLowerLimit command to a Scout.
19664  *
19665  * \param _src The Scout source.  See \ref RCXSourceConstants.
19666  * \param _value The Scout value.
19667  */
19668 #define MSScoutSetSensorLowerLimit(_src, _value) __MSScoutSetSensorLowerLimit(_src, _value)
19669 
19670 /**
19671  * MSScoutSetSensorUpperLimit function.
19672  * Send the SetSensorUpperLimit command to a Scout.
19673  *
19674  * \param _src The Scout source.  See \ref RCXSourceConstants.
19675  * \param _value The Scout value.
19676  */
19677 #define MSScoutSetSensorUpperLimit(_src, _value) __MSScoutSetSensorUpperLimit(_src, _value)
19678 
19679 /**
19680  * MSScoutSetTimerLimit function.
19681  * Send the SetTimerLimit command to a Scout.
19682  *
19683  * \param _tmr The timer for which to set a limit.
19684  * \param _src The Scout source.  See \ref RCXSourceConstants.
19685  * \param _value The Scout value.
19686  */
19687 #define MSScoutSetTimerLimit(_tmr, _src, _value) __MSScoutSetTimerLimit(_tmr, _src, _value)
19688 
19689 /**
19690  * MSScoutUnmuteSound function.
19691  * Send the UnmuteSound command to a Scout.
19692  */
19693 #define MSScoutUnmuteSound() __MSScoutUnmuteSound()
19694 
19695 /** @} */ // end of MindSensorsAPI group
19696 
19697 /** @addtogroup CodatexAPI
19698  * @{
19699  */
19700 
19701 // Codatex RFID functions
19702 
19703 /**
19704  * RFIDInit function.
19705  * Initialize the Codatex RFID sensor.
19706  *
19707  * \param _port The port to which the Codatex RFID sensor is attached. See the
19708  * \ref NBCInputPortConstants group. You may use a constant or a variable.
19709  * \param _result The boolean function call result.
19710  */
19711 #define RFIDInit(_port, _result) __RFIDInit(_port, _result)
19712 
19713 /**
19714  * RFIDMode function.
19715  * Configure the Codatex RFID sensor mode.
19716  *
19717  * \param _port The port to which the Codatex RFID sensor is attached. See the
19718  * \ref NBCInputPortConstants group. You may use a constant or a variable.
19719  * \param _mode The RFID sensor mode.  See the \ref CTRFIDModeConstants group.
19720  * \param _result The boolean function call result.
19721  */
19722 #define RFIDMode(_port, _mode, _result) __RFIDMode(_port, _mode, _result)
19723 
19724 /**
19725  * RFIDStatus function.
19726  * Read the Codatex RFID sensor status.
19727  *
19728  * \param _port The port to which the Codatex RFID sensor is attached. See the
19729  * \ref NBCInputPortConstants group. You may use a constant or a variable.
19730  * \param _result The RFID sensor status.
19731  */
19732 #define RFIDStatus(_port, _result) __RFIDStatus(_port, _result)
19733 
19734 /**
19735  * RFIDRead function.
19736  * Read the Codatex RFID sensor value.
19737  *
19738  * \param _port The port to which the Codatex RFID sensor is attached. See the
19739  * \ref NBCInputPortConstants group. You may use a constant or a variable.
19740  * \param _output The five bytes of RFID data.
19741  * \param _result The boolean function call result.
19742  */
19743 #define RFIDRead(_port, _output, _result) __RFIDRead(_port, _output, _result)
19744 
19745 /**
19746  * RFIDStop function.
19747  * Stop the Codatex RFID sensor.
19748  *
19749  * \param _port The port to which the Codatex RFID sensor is attached. See the
19750  * \ref NBCInputPortConstants group. You may use a constant or a variable.
19751  * \param _result The boolean function call result.
19752  */
19753 #define RFIDStop(_port, _result) __RFIDStop(_port, _result)
19754 
19755 /**
19756  * RFIDReadSingle function.
19757  * Set the Codatex RFID sensor into single mode and read the RFID data.
19758  *
19759  * \param _port The port to which the Codatex RFID sensor is attached. See the
19760  * \ref NBCInputPortConstants group. You may use a constant or a variable.
19761  * \param _output The five bytes of RFID data.
19762  * \param _result The boolean function call result.
19763  */
19764 #define RFIDReadSingle(_port, _output, _result) __RFIDReadSingle(_port, _output, _result)
19765 
19766 /**
19767  * RFIDReadContinuous function.
19768  * Set the Codatex RFID sensor into continuous mode, if necessary, and read
19769  * the RFID data.
19770  *
19771  * \param _port The port to which the Codatex RFID sensor is attached. See the
19772  * \ref NBCInputPortConstants group. You may use a constant or a variable.
19773  * \param _output The five bytes of RFID data.
19774  * \param _result The boolean function call result.
19775  */
19776 #define RFIDReadContinuous(_port, _output, _result) __RFIDReadContinuous(_port, _output, _result)
19777 
19778 /** @} */  // end of CodatexAPI group
19779 
19780 /** @} */ // end of ThirdPartyDevices group
19781 
19782 
19783 /** @addtogroup GraphicsLibrary
19784  * @{
19785  */
19786 
19787 //------------------------------------------------------------------------------
19788 // File          : nbcGL.nbc
19789 // Description   : Data and subroutines for a very simple 3D engine.
19790 // Programmed by : Arno van der Vegt, legoasimo@gmail.com
19791 //------------------------------------------------------------------------------
19792 
19793 /**
19794  * Initialize graphics library.
19795  * Setup all the necessary data for the graphics library to function. Call this
19796  * function before any other graphics library routine.
19797  */
19798 #define glInit() __glInit()
19799 
19800 /**
19801  * Set graphics library options.
19802  * Adjust graphic library settings for circle size and cull mode.
19803  *
19804  * \param _glType The setting type.  See \ref GLConstantsSettings.
19805  * \param _glValue The setting value. For culling modes see \ref GLConstantsCullMode.
19806  */
19807 #define glSet(_glType, _glValue) __glSet(_glType, _glValue)
19808 
19809 /**
19810  * Begin defining an object.
19811  * Start the process of defining a graphics library object using low level
19812  * functions such as \ref glBegin, \ref glAddVertex, and \ref glEnd.
19813  *
19814  * \param _glObjId The object index of the new object being created.
19815  */
19816 #define glBeginObject(_glObjId) __glBeginObject(_glObjId)
19817 
19818 /**
19819  * Stop defining an object.
19820  * Finish the process of defining a graphics library object.  Call this function
19821  * after you have completed the object definition.
19822  */
19823 #define glEndObject() __glEndObject()
19824 
19825 /**
19826  * Perform an object action.
19827  * Execute the specified action on the specified object.
19828  *
19829  * \param _glObjectId The object id.
19830  * \param _glAction The action to perform on the object. See \ref GLConstantsActions.
19831  * \param _glValue The setting value.
19832  */
19833 #define glObjectAction(_glObjectId, _glAction, _glValue) __glObjectAction(_glObjectId, _glAction, _glValue)
19834 
19835 /**
19836  * Add a vertex to an object.
19837  * Add a vertex to an object currently being defined.  This function should
19838  * only be used between \ref glBegin and \ref glEnd which are themselves
19839  * nested within a \ref glBeginObject and \ref glEndObject pair.
19840  *
19841  * \param _glX The X axis coordinate.
19842  * \param _glY The Y axis coordinate.
19843  * \param _glZ The Z axis coordinate.
19844  */
19845 #define glAddVertex(_glX, _glY, _glZ) __glAddVertex(_glX, _glY, _glZ)
19846 
19847 /**
19848  * Begin a new polygon for the current object.
19849  * Start defining a polygon surface for the current graphics object using
19850  * the specified begin mode.
19851  *
19852  * \param _glBeginMode The desired mode.  See \ref GLConstantsBeginModes.
19853  */
19854 #define glBegin(_glBeginMode) __glBegin(_glBeginMode)
19855 
19856 /**
19857  * Finish a polygon for the current object.
19858  * Stop defining a polgyon surface for the current graphics object.
19859  */
19860 #define glEnd() __glEnd()
19861 
19862 /**
19863  * Begin a new render.
19864  * Start the process of rendering the existing graphic objects.
19865  */
19866 #define glBeginRender() __glBeginRender()
19867 
19868 /**
19869  * Call a graphic object.
19870  * Tell the graphics library that you want it to include the specified
19871  * object in the render.
19872  *
19873  * \param _glObjectId The desired object id.
19874  */
19875 #define glCallObject(_glObjectId) __glCallObject(_glObjectId)
19876 
19877 /**
19878  * Finish the current render.
19879  * Rotate the vertex list, clear the screen, and draw the rendered objects
19880  * to the LCD.
19881  */
19882 #define glFinishRender() __glFinishRender()
19883 
19884 /**
19885  * Set the X axis angle.
19886  * Set the X axis angle to the specified value.
19887  *
19888  * \param _glValue The new X axis angle.
19889  */
19890 #define glSetAngleX(_glValue) __glSetAngleX(_glValue)
19891 
19892 /**
19893  * Add to the X axis angle.
19894  * Add the specified value to the existing X axis angle.
19895  *
19896  * \param _glValue The value to add to the X axis angle.
19897  */
19898 #define glAddToAngleX(_glValue) __glAddToAngleX(_glValue)
19899 
19900 /**
19901  * Set the Y axis angle.
19902  * Set the Y axis angle to the specified value.
19903  *
19904  * \param _glValue The new Y axis angle.
19905  */
19906 #define glSetAngleY(_glValue) __glSetAngleY(_glValue)
19907 
19908 /**
19909  * Add to the Y axis angle.
19910  * Add the specified value to the existing Y axis angle.
19911  *
19912  * \param _glValue The value to add to the Y axis angle.
19913  */
19914 #define glAddToAngleY(_glValue) __glAddToAngleY(_glValue)
19915 
19916 /**
19917  * Set the Z axis angle.
19918  * Set the Z axis angle to the specified value.
19919  *
19920  * \param _glValue The new Z axis angle.
19921  */
19922 #define glSetAngleZ(_glValue) __glSetAngleZ(_glValue)
19923 
19924 /**
19925  * Add to the Z axis angle.
19926  * Add the specified value to the existing Z axis angle.
19927  *
19928  * \param _glValue The value to add to the Z axis angle.
19929  */
19930 #define glAddToAngleZ(_glValue) __glAddToAngleZ(_glValue)
19931 
19932 /**
19933  * Table-based sine scaled by 32768.
19934  * Return the sine of the specified angle in degrees.  The result is scaled
19935  * by 32768.
19936  *
19937  * \param _glAngle The angle in degrees.
19938  * \param _glResult The sine value scaled by 32768.
19939  */
19940 #define glSin32768(_glAngle, _glResult) __glSin32768(_glAngle, _glResult)
19941 
19942 /**
19943  * Table-based cosine scaled by 32768.
19944  * Return the cosine of the specified angle in degrees.  The result is scaled
19945  * by 32768.
19946  *
19947  * \param _glAngle The angle in degrees.
19948  * \param _glResult The cosine value scaled by 32768.
19949  */
19950 #define glCos32768(_glAngle, _glResult) __glCos32768(_glAngle, _glResult)
19951 
19952 /**
19953  * Create a 3D box.
19954  * Define a 3D box using the specified begin mode for all faces. The center
19955  * of the box is at the origin of the XYZ axis with width, height, and depth
19956  * specified via the glSizeX, glSizeY, and glSizeZ parameters.
19957  *
19958  * \param _glMode The begin mode for each surface.  See \ref GLConstantsBeginModes.
19959  * \param _glSizeX The X axis size (width).
19960  * \param _glSizeY The Y axis size (height).
19961  * \param _glSizeZ The Z axis size (depth).
19962  * \param _glObjId The object ID of the new object.
19963  */
19964 #define glBox(_glMode, _glSizeX, _glSizeY, _glSizeZ, _glObjId) __glBox(_glMode, _glSizeX, _glSizeY, _glSizeZ, _glObjId)
19965 
19966 /**
19967  * Create a 3D cube.
19968  * Define a 3D cube using the specified begin mode for all faces. The center
19969  * of the box is at the origin of the XYZ axis with equal width, height, and depth
19970  * specified via the glSize parameter.
19971  *
19972  * \param _glMode The begin mode for each surface.  See \ref GLConstantsBeginModes.
19973  * \param _glSize The cube's width, height, and depth.
19974  * \param _glObjId The object ID of the new object.
19975  */
19976 #define glCube(_glMode, _glSize, _glObjId) __glBox(_glMode, _glSize, _glSize, _glSize, _glObjId)
19977 
19978 /**
19979  * Create a 3D pyramid.
19980  * Define a 3D pyramid using the specified begin mode for all faces. The center
19981  * of the pyramid is at the origin of the XYZ axis with width, height, and depth
19982  * specified via the glSizeX, glSizeY, and glSizeZ parameters.
19983  *
19984  * \param _glMode The begin mode for each surface.  See \ref GLConstantsBeginModes.
19985  * \param _glSizeX The X axis size (width).
19986  * \param _glSizeY The Y axis size (height).
19987  * \param _glSizeZ The Z axis size (depth).
19988  * \param _glObjId The object ID of the new object.
19989  */
19990 #define glPyramid(_glMode, _glSizeX, _glSizeY, _glSizeZ, _glObjId) __glPyramid(_glMode, _glSizeX, _glSizeY, _glSizeZ, _glObjId)
19991 
19992 /** @} */ // end of GraphicsLibrary group
19993 
19994 
19995 #endif // NXTDEFS__H
19996