home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / nqc_10b1.zip / rcx.nqh < prev    next >
Text File  |  1998-11-02  |  4KB  |  135 lines

  1. /*
  2.  * rcx.nqh - version 1.0 b1
  3.  * Copyright (C) 1998 Dave Baum
  4.  *
  5.  * This file is part of nqcc, the Not Quite C Compiler
  6.  *
  7.  * This program is free software; you can redistribute it and/or modify
  8.  * it under the terms of the GNU General Public License as published by
  9.  * the Free Software Foundation; either version 2, or (at your option)
  10.  * any later version.
  11.  *
  12.  * This program is distributed in the hope that it will be useful,
  13.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  15.  * GNU General Public License for more details.
  16.  *
  17.  * You should have received a copy of the GNU General Public License
  18.  * along with this program; see the file COPYING.  If not, write to
  19.  * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
  20.  *
  21.  */
  22.  
  23. /*
  24.  *  This file defines various system constants and macros to be used
  25.  *  with the RCX.  Most of the real functionality of the RCX is
  26.  *  defined here rather than within nqcc itself.
  27.  *
  28.  */
  29.  
  30. // constants for selecting sensors
  31. #define IN_1    Input(0)
  32. #define IN_2    Input(1)
  33. #define IN_3    Input(2)
  34.  
  35. // constants for selecting outputs
  36. #define OUT_A    (1 << 0)
  37. #define OUT_B    (1 << 1)
  38. #define OUT_C    (1 << 2)
  39.  
  40. // output modes
  41. #define OUT_FLOAT    0
  42. #define OUT_OFF        0x40
  43. #define OUT_ON        0x80
  44.  
  45. // output directions
  46. #define OUT_REV        0
  47. #define OUT_FLIP    0x40
  48. #define OUT_FWD        0x80
  49.  
  50. // full speed
  51. #define OUT_FULL    7
  52.  
  53. // types for SensorType() and IN_CFG()
  54. #define STYPE_SWITCH    1
  55. #define STYPE_TEMP        2
  56. #define STYPE_LIGHT        3
  57. #define STYPE_ANGLE        4
  58.  
  59. // modes for SensorMode() and IN_CFG()
  60. #define SMODE_RAW        0x00
  61. #define SMODE_BOOL        0x20
  62. #define SMODE_EDGE        0x40
  63. #define SMODE_PULSE        0x60
  64. #define SMODE_PERCENT    0x80
  65. #define SMODE_CELCIUS    0xa0
  66. #define SMODE_FAHRENHEIT 0xc0
  67. #define SMODE_ANGLE        0xe0
  68.  
  69. // input configurations - used in calls to Sensor()
  70. #define IN_CFG(type,mode)    (((type)<<8) + (mode))
  71. #define IN_SWITCH    IN_CFG(STYPE_SWITCH, SMODE_BOOL)
  72. #define IN_LIGHT    IN_CFG(STYPE_LIGHT,  SMODE_PERCENT)
  73. #define IN_ANGLE    IN_CFG(STYPE_ANGLE,  SMODE_ANGLE)
  74. #define    IN_PULSE    IN_CFG(STYPE_SWITCH, SMODE_PULSE)
  75. #define IN_EDGE        IN_CFG(STYPE_SWITCH, SMODE_EDGE)
  76.  
  77.  
  78. // handy macros for building asm blocks
  79. #define TYPE(v)        ([v] >> 16)
  80. #define LO8(v)        ([v])
  81. #define HI8(v)        ([v] >> 8)
  82.  
  83.  
  84. // output functions
  85. #define OutputMode(o, m)    asm { 0x21, (o) + (m) }
  86. #define OutputDir(o, d)        asm { 0xe1, (o) + (d) }
  87. #define OutputPower(o, p)    asm    { 0x13, (o), TYPE(p), LO8(p) }
  88.  
  89. #define Fwd(o, p)    do {     OutputDir(o,OUT_FWD); \
  90.                             OutputMode(o,OUT_ON); \
  91.                             OutputPower(o,p); } while(false)
  92.                             
  93. #define Rev(o, p)    do {    OutputDir(o,OUT_REV); \
  94.                             OutputMode(o,OUT_ON); \
  95.                             OutputPower(o,p); } while(false)
  96.                             
  97. #define Off(o)                OutputMode(o, OUT_OFF)
  98.  
  99.  
  100. #define SensorType(i, t)    asm { 0x32, ([i]), ([t]) }
  101. #define SensorMode(i,s,m)    asm { 0x42, ([i]), (s) + ((m)<<5) }
  102. #define Sensor(i, tm)        asm { 0x32, ([i]), HI8(tm), 0x42, ([i]), LO8(tm) }
  103.  
  104. #define PlaySound(x)        asm { 0x51, x }
  105. #define PlayNote(f, d)        asm { 0x23, (f), (f)>>8, (d) }
  106.  
  107. #define Display(v)        asm { 0x33, TYPE(v), LO8(v), HI8(v) }
  108.  
  109. #define Sleep(v)        asm { 0x43, TYPE(v), LO8(v), HI8(v) }
  110.  
  111. #define SendMessage(v)    asm    { 0xb2, TYPE(v), LO8(v) }
  112. #define ClearMessage()    asm { 0x90 }
  113. #define ClearTimer(n)    asm { 0xa1, n }
  114. #define ClearSensor(n)    asm    { 0xd1, ([n]) }
  115.  
  116. #define SetDatalog(size)    asm    { 0x52, LO8(size), HI8(size) }
  117. #define Datalog(v)            asm { 0x62, TYPE(v), LO8(v) }
  118. #define UploadDatalog(s, n)    asm { 0xa4, LO8(s), HI8(s), LO8(n), HI8(n) }
  119.  
  120.  
  121. // Use these to read values at runtime
  122. #define Timer(n)    @(0x10000 + (n))
  123. #define Random(n)    @(0x40000 + (n))
  124. #define Input(n)    @(0x90000 + (n))
  125. #define Watch()        @(0xe0000)
  126. #define Message()    @(0xf0000)
  127.  
  128. // support for controlling the IRMode
  129. #define IR_LO 0
  130. #define IR_HI 1
  131. #define IRMode(m)      asm { 0x31, m }
  132.  
  133. // a rather useful control structure
  134. #define wait(c)        while(!(c))
  135.