home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
OS/2 Shareware BBS: 10 Tools
/
10-Tools.zip
/
nqc_10b1.zip
/
rcx.nqh
< prev
next >
Wrap
Text File
|
1998-11-02
|
4KB
|
135 lines
/*
* rcx.nqh - version 1.0 b1
* Copyright (C) 1998 Dave Baum
*
* This file is part of nqcc, the Not Quite C Compiler
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2, or (at your option)
* any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; see the file COPYING. If not, write to
* the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
*
*/
/*
* This file defines various system constants and macros to be used
* with the RCX. Most of the real functionality of the RCX is
* defined here rather than within nqcc itself.
*
*/
// constants for selecting sensors
#define IN_1 Input(0)
#define IN_2 Input(1)
#define IN_3 Input(2)
// constants for selecting outputs
#define OUT_A (1 << 0)
#define OUT_B (1 << 1)
#define OUT_C (1 << 2)
// output modes
#define OUT_FLOAT 0
#define OUT_OFF 0x40
#define OUT_ON 0x80
// output directions
#define OUT_REV 0
#define OUT_FLIP 0x40
#define OUT_FWD 0x80
// full speed
#define OUT_FULL 7
// types for SensorType() and IN_CFG()
#define STYPE_SWITCH 1
#define STYPE_TEMP 2
#define STYPE_LIGHT 3
#define STYPE_ANGLE 4
// modes for SensorMode() and IN_CFG()
#define SMODE_RAW 0x00
#define SMODE_BOOL 0x20
#define SMODE_EDGE 0x40
#define SMODE_PULSE 0x60
#define SMODE_PERCENT 0x80
#define SMODE_CELCIUS 0xa0
#define SMODE_FAHRENHEIT 0xc0
#define SMODE_ANGLE 0xe0
// input configurations - used in calls to Sensor()
#define IN_CFG(type,mode) (((type)<<8) + (mode))
#define IN_SWITCH IN_CFG(STYPE_SWITCH, SMODE_BOOL)
#define IN_LIGHT IN_CFG(STYPE_LIGHT, SMODE_PERCENT)
#define IN_ANGLE IN_CFG(STYPE_ANGLE, SMODE_ANGLE)
#define IN_PULSE IN_CFG(STYPE_SWITCH, SMODE_PULSE)
#define IN_EDGE IN_CFG(STYPE_SWITCH, SMODE_EDGE)
// handy macros for building asm blocks
#define TYPE(v) ([v] >> 16)
#define LO8(v) ([v])
#define HI8(v) ([v] >> 8)
// output functions
#define OutputMode(o, m) asm { 0x21, (o) + (m) }
#define OutputDir(o, d) asm { 0xe1, (o) + (d) }
#define OutputPower(o, p) asm { 0x13, (o), TYPE(p), LO8(p) }
#define Fwd(o, p) do { OutputDir(o,OUT_FWD); \
OutputMode(o,OUT_ON); \
OutputPower(o,p); } while(false)
#define Rev(o, p) do { OutputDir(o,OUT_REV); \
OutputMode(o,OUT_ON); \
OutputPower(o,p); } while(false)
#define Off(o) OutputMode(o, OUT_OFF)
#define SensorType(i, t) asm { 0x32, ([i]), ([t]) }
#define SensorMode(i,s,m) asm { 0x42, ([i]), (s) + ((m)<<5) }
#define Sensor(i, tm) asm { 0x32, ([i]), HI8(tm), 0x42, ([i]), LO8(tm) }
#define PlaySound(x) asm { 0x51, x }
#define PlayNote(f, d) asm { 0x23, (f), (f)>>8, (d) }
#define Display(v) asm { 0x33, TYPE(v), LO8(v), HI8(v) }
#define Sleep(v) asm { 0x43, TYPE(v), LO8(v), HI8(v) }
#define SendMessage(v) asm { 0xb2, TYPE(v), LO8(v) }
#define ClearMessage() asm { 0x90 }
#define ClearTimer(n) asm { 0xa1, n }
#define ClearSensor(n) asm { 0xd1, ([n]) }
#define SetDatalog(size) asm { 0x52, LO8(size), HI8(size) }
#define Datalog(v) asm { 0x62, TYPE(v), LO8(v) }
#define UploadDatalog(s, n) asm { 0xa4, LO8(s), HI8(s), LO8(n), HI8(n) }
// Use these to read values at runtime
#define Timer(n) @(0x10000 + (n))
#define Random(n) @(0x40000 + (n))
#define Input(n) @(0x90000 + (n))
#define Watch() @(0xe0000)
#define Message() @(0xf0000)
// support for controlling the IRMode
#define IR_LO 0
#define IR_HI 1
#define IRMode(m) asm { 0x31, m }
// a rather useful control structure
#define wait(c) while(!(c))