|
In case anyone would like to have it, here is my spy.nqh file in its entirety.
With respect to the ROM subroutines, it is important to note that most of them
use global variables, timers, and events which must be assigned a particular
number by the compiler. That's fine for MindScript since you must load the
globals.h file which defines the variables, timers, and events in the correct
order. For NQC you can make it work if you are very careful and you know what
you are doing.
Also, certain subroutines try to call user-written subroutines which must have a
particular number as well. Again, in MindScript this is okay because you can
assign subroutine numbers. In NQC you would have to define the subroutines in a
particular order to make sure they end up with the right number. The same goes
for certain event watcher tasks which some of the built-in ROM subroutines
attempt to start or stop.
Most of the built-in subroutines, then, are not of general use and should not be
defined in any official NQC Spybot API or in the currently unofficial spy.nqh
file. Some of the subroutines use no global variables and are generally useful.
I've included all of the ones in utils.h (from Mark Ferris' earlier post) as
well as a small handful of others. It might be arguably better to keep all the
built-in subroutine access methods in one or more separate .nqh header files.
Regarding constants, I have tried to follow the NQC naming pattern which
involves all uppercase words separated by underscores.
/*
* The contents of this file are subject to the Mozilla Public License
* Version 1.0 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS"
* basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
* License for the specific language governing rights and limitations
* under the License.
*
* The Initial Developer of this code is David Baum.
* Portions created by David Baum are Copyright (C) 2000 David Baum.
* All Rights Reserved.
*/
// last updated 1/1/2003
#if defined(__SPY)
// LED's may be set/checked manually
#define LED(n) @(0x160000 + (n)) // LED control registers
__nolist void SetLED(const int mode, const int &v) { Set(LED(mode), v); }
// constants for the mode argument in SetLED()
#define LED_MODE_ON 0
#define LED_MODE_BLINK 1
#define LED_MODE_DURATION 2
#define LED_MODE_SCALE 3
#define LED_MODE_SCALE_BLINK 4
#define LED_MODE_SCALE_DURATION 5
#define LED_MODE_RED_SCALE 6
#define LED_MODE_RED_SCALE_BLINK 7
#define LED_MODE_GREEN_SCALE 8
#define LED_MODE_GREEN_SCALE_BLINK 9
#define LED_MODE_YELLOW 10
#define LED_MODE_YELLOW_BLINK 11
#define LED_MODE_YELLOW_DURATION 12
#define LED_MODE_VLL 13
#define LED_MODE_VLL_BLINK 14
#define LED_MODE_VLL_DURATION 15
// ROM animations (for the front LEDs)
#define ANIMATION_SCAN 0
#define ANIMATION_SPARKLE 1
#define ANIMATION_FLASH 2
#define ANIMATION_RED_TO_GREEN 3
#define ANIMATION_GREEN_TO_RED 4
#define ANIMATION_POINT_FORWARD 5
#define ANIMATION_ALARM 6
#define ANIMATION_THINKING 7
// macro for defining a user animation:
// ANIMATION my_animation { 1, 10, 2, 10, 4, 10, 2, 10, 255, 255 };
//
#define ANIMATION __res 3
// function to start a given animation
__nolist void SetAnimation(const int t) { asm { 0xc7, t }; }
#define AnimateLED(f, t) f, t
#define RepeatAnimation() 0xFF, 0
#define SOUNDEFFECT __res 2
#define Gate(o, p) 0x62, p, o
#define GateOff() 0x70
#define Glide(s, p, t) 0x45, t, s & 0xFF, s >> 8, p & 0xFF, p >> 8
#define Vibrato(s, p, t) 0x55, t, s & 0xFF, s >> 8, p & 0xFF, p >> 8
#define WaitEffect(t) 0x21, t
#define FixedWaitEffect(t) 0x81, t
#define Tone(f, t) 0x33, t, f & 0xFF, f >> 8
#define FixedTone(f, t) 0x93, t, f & 0xFF, f >> 8
#define RepeatEffect() 0x10
#define EffectSound() @(0x350000) // Sound Effects control registers (0,1)
#define EffectTime() @(0x350001)
__nolist void SetEffectSound(const int &s) { Set(EffectSound(), s); }
__nolist void SetEffectTime(const int &t) { Set(EffectTime(), t); }
#define TARGET_NONE 255
#define ID_NONE = 0
#define ID_CTRL1 1
#define ID_CTRL2 2
#define ID_CTRL3 3
#define ID_CTRL4 4
#define ID_CTRL5 5
#define ID_CTRL6 6
#define ID_PC 7
#define ID_BOT_MIN 8
#define ID_BOT_MAX 255
#define RANGE_NOWHERE 0
#define RANGE_ANYWHERE 1
#define RANGE_THERE 2
#define RANGE_HERE 3
#define DIRECTION_LEFT 0
#define DIRECTION_LEFT_OF_CENTER 1
#define DIRECTION_CENTER 2
#define DIRECTION_RIGHT_OF_CENTER 3
#define DIRECTION_RIGHT 4
#define ASPECT_FRONT_LEFT 0
#define ASPECT_FRONT 1
#define ASPECT_FRONT_RIGHT 2
#define ASPECT_BACK_RIGHT 3
#define ASPECT_BACK 4
#define ASPECT_BACK_LEFT 5
#define SPY_TARGETID 0
#define SPY_NOTE 1
#define SPY_LINKID 2
#define SPY_RANGE 3
#define SPY_DIRECTION 4
#define SPY_ASPECT 5
#define SPY_INFO 6
#define SPY_SHORTID 7
#define REL_GT 0
#define REL_LT 1
#define REL_EQ 2
#define REL_NE 3
__nolist void FindWorld(int &v, const int relsrc, const int crit, const int&
thresh)
{
asm { 0xd5, &v : 0x3000001, 0x2a + relsrc, crit, &thresh : __ASM_SMALL_VALUE
};
}
__nolist void ClearWorld() { asm { 0x36 }; }
#define Target(n) @(0x320000 + n)
__nolist void SetTargetID(const int &v) { Set(Target(SPY_TARGETID), v); }
__nolist void SetTargetNote(const int &v) { Set(Target(SPY_NOTE), v); }
__nolist void GetWorld(const int n, int &t, int &v)
{
asm { 0x14, &v : __ASM_NO_TYPE + __ASM_SMALL_VALUE, 0x2a + n,
&t : __ASM_NO_TYPE + __ASM_SMALL_VALUE, 0x00 };
}
__nolist void GetWorldShortID(int &t, int &v) { GetWorld(SPY_SHORTID, t, v); }
__nolist void GetWorldLinkID(int &t, int &v) { GetWorld(SPY_LINKID, t, v); }
__nolist void GetWorldRange(int &t, int &v) { GetWorld(SPY_RANGE, t, v); }
__nolist void GetWorldDirection(int &t, int &v) { GetWorld(SPY_DIRECTION, t,
v); }
__nolist void GetWorldAspect(int &t, int &v) { GetWorld(SPY_ASPECT, t, v); }
__nolist void GetWorldNote(int &t, int &v) { GetWorld(SPY_NOTE, t, v); }
__nolist void SetWorldNote(int &t, const int &v)
{
asm { 0x05, 0x2b, &t : __ASM_NO_TYPE + __ASM_SMALL_VALUE, &v};
}
#define Stack(n) @(0x120000 + (n))
__nolist void Push(const int v) { asm { 0xe3, v }; }
__nolist void Pop(const int n) { asm { 0x01, n }; }
__nolist void SetStack(const int i, const int &v) { Set(Stack(i), v); }
#define TIMER_RUNNING 1
#define TIMER_STOPPED 0
#define TimerState(n) @(0x130000 + (n))
__nolist void SetTimerState(const int n, const int s) { Set(TimerState(n), s);
}
#define EEPROM(n) @(0x140000 + (n))
__nolist void SetEEPROM(const int i, const int &d) { Set(EEPROM(i), d); }
#define CurrentTaskID() @(0x200000)
#define SerialData(n) @(0x210000 + (n)) // data for SendSerial
__nolist void SetSerialData(const int n, const int &v) { Set(SerialData(n),
v); }
#define TX_TYPE_SPYBOT 0
#define TX_TYPE_RCX 1
#define TX_TYPE_RC 2
#define TX_TYPE_USER 3
#define TxType() @(0x210010)
__nolist void SetTxType(const int &t) { Set(TxType(), t); }
#define TX_BAUD_2400 0
#define TX_BAUD_4800 1
#define TX_BAUD_9600 3
#define TxBaud() @(0x210011)
__nolist void SetTxBaud(const int &b) { Set(TxBaud(), b); }
#define TX_DIRECTION_FRONT_LEFT 0
#define TX_DIRECTION_FRONT_RIGHT 1
#define TX_DIRECTION_BACK 2
#define TX_DIRECTION_HIGH_POWER 3
#define TX_DIRECTION_PC 4
#define TxDirection() @(0x210012)
__nolist void SetTxDirection(const int &d) { Set(TxDirection(), d); }
#define TxUserPreamblePos() @(0x210013)
__nolist void SetTxUserPreamblePos(const int p) { Set(TxUserPreamblePos(), p);
}
#define TxUserPreambleLen() @(0x210014)
__nolist void SetTxUserPreambleLen(const int l) { Set(TxUserPreambleLen(), l);
}
#define TX_USER_NO_CHECKSUM 0
#define TX_USER_SUM_CHECKSUM 0x04
#define TX_USER_ZERO_SUM_CHECKSUM 0x08
#define TxUserChecksum() @(0x210015)
__nolist void SetTxUserChecksum(const int n) { Set(TxUserChecksum(), n); }
#define TX_USER_NO_BIPHASE 0
#define TX_USER_BIPHASE 1
#define TxUserBiPhase() @(0x210016)
__nolist void SetTxUserBiPhase(const int n) { Set(TxUserBiPhase(), n); }
#define MESSAGE_UNLOCK 0
#define MESSAGE_LOCK_IR 1
#define MESSAGE_LOCK_PC 2
#define MessageLock() @(0x210017)
__nolist void SetMessageLock(const int &l) { Set(MessageLock(), l); }
#define RxBufferIndex() @(0x210018)
#define MSG_RX_CHANNEL_IR 1
#define MSG_RX_CHANNEL_PC 2
#define MessageRxChannel() @(0x210019)
#define RxBufferIRId() @(0x21001a)
#define RxBufferPCId() @(0x21001b)
#define MSG_INDEX 0
#define MSG_COMMAND 1
#define MSG_HI_BYTE 2
#define MSG_LO_BYTE 3
#define COMMAND_CONTROLLER 0x40
#define RxIRMessage(n) @(0x21001c + (n)) // 4 bytes
#define RxPCMessage(n) @(0x210020 + (n)) // 4 bytes
__nolist void SendSerial(const int first, const int count) { asm { 0xc2,
first, count }; }
#define PingControl(n) @(0x330000 + (n)) // 51
#define PingData() PingControl(0)
__nolist void SetPingData(const int &d) { Set(PingData(), d); }
#define PingInterval() PingControl(1)
__nolist void SetPingInterval(const int &i) { Set(PingInterval(), i); }
#define PingID() PingControl(2)
#define BeaconControl(n) @(0x340000 + (n)) // 52
#define LinkID() BeaconControl(0)
#define RC_CHANNEL_BROADCAST 0
#define RC_CHANNEL_1 1
#define RC_CHANNEL_2 2
#define RC_CHANNEL_3 3
#define RC_CHANNEL_DISABLED 4
#define RCRxChannel() BeaconControl(1)
__nolist void SetRCRxChannel(const int c) { Set(RCRxChannel(), c); }
#define RCTxChannel() BeaconControl(2)
__nolist void SetRCTxChannel(const int c) { Set(RCTxChannel(), c); }
#define RCTXMODE_SINGLE_SHOT 0
#define RCTXMODE_CONTINUOUS 1
#define RCTxMode() BeaconControl(3)
__nolist void SetRCTxMode(const int m) { Set(RCTxMode(), m); }
#define IndirectEEProm() @(0x360000) // 54 ????
__nolist void StartTask(const int t) { asm { 0x71, t}; }
#define CONTROLLER_BUTTON1 0x0100
#define CONTROLLER_BUTTON2 0x0200
#define CONTROLLER_BUTTON3 0x0001
#define CONTROLLER_BUTTON4 0x0101
#define CONTROLLER_BUTTON5 0x0201
// ROM subroutines
// engine subroutines
__nolist void MainSub() { asm { 0x17, 0 }; }
__nolist void EnterBead() { asm { 0x17, 40 }; }
__nolist void ExitBead() { asm { 0x17, 41 }; }
// interaction subroutines
__nolist void SendSpybotMessage(const int nIndex, const int nCmd,
const int nHiByte, const int nLoByte)
{
asm { 0xe3, &nIndex };
asm { 0xe3, &nCmd };
asm { 0xe3, &nHiByte };
asm { 0xe3, &nLoByte };
asm { 0x17, 34 };
asm { 0x01, 4 };
}
__nolist void SendRCXMessage(const int nMessage)
{ asm { 0xe3, &nMessage, 0x17, 37, 0x01, 1 }; }
__nolist void SendAllRangeMessage(const int nMessage, const int nData)
{ asm { 0xe3, &nMessage, 0xe3, &nData, 0x17, 38, 0x01, 2 }; }
// utils subroutines
__nolist void Disp(const int display)
{ asm { 0xe3, &display, 0x17, 42, 0x01, 1 }; }
#define MOVE_BASIC 0x0100
#define MOVE_RANDOM 0x0200
#define MOVE_FANCY 0x0300
#define MOVE_SLOWDOWN 0x0400
#define MOVE_SPEEDUP 0x0500
#define MOVE_MASK 0x00ff
#define MOVE_TYPE_MASK 0xff00
#define MOVE_BASIC_FORWARD MOVE_BASIC + 1
#define MOVE_BASIC_BACKWARD MOVE_BASIC + 2
#define MOVE_BASIC_SPIN_LEFT MOVE_BASIC + 3
#define MOVE_BASIC_SPIN_RIGHT MOVE_BASIC + 4
#define MOVE_BASIC_TURN_LEFT MOVE_BASIC + 5
#define MOVE_BASIC_TURN_RIGHT MOVE_BASIC + 6
#define MOVE_BASIC_AVOID_LEFT MOVE_BASIC + 7
#define MOVE_BASIC_AVOID_RIGHT MOVE_BASIC + 8
#define MOVE_BASIC_REST MOVE_BASIC + 9
#define MOVE_BASIC_STOP MOVE_BASIC + 10
#define MOVE_RANDOM_FORWARD MOVE_RANDOM + 1
#define MOVE_RANDOM_BACKWARD MOVE_RANDOM + 2
#define MOVE_RANDOM_SPIN_LEFT MOVE_RANDOM + 3
#define MOVE_RANDOM_SPIN_RIGHT MOVE_RANDOM + 4
#define MOVE_RANDOM_TURN_LEFT MOVE_RANDOM + 5
#define MOVE_RANDOM_TURN_RIGHT MOVE_RANDOM + 6
#define MOVE_RANDOM_REST MOVE_RANDOM + 7
#define MOVE_FANCY_ZIGZAG MOVE_FANCY + 1
#define MOVE_FANCY_SHAKE MOVE_FANCY + 2
#define MOVE_FANCY_SCAN MOVE_FANCY + 3
#define MOVE_FANCY_STEP MOVE_FANCY + 4
#define MOVE_FANCY_STEP_BACK MOVE_FANCY + 5
#define MOVE_FANCY_SEARCH MOVE_FANCY + 6
#define MOVE_FANCY_FAKE_LEFT MOVE_FANCY + 7
#define MOVE_FANCY_RAKE_RIGHT MOVE_FANCY + 8
#define MOVE_FANCY_BUG_FORWARD MOVE_FANCY + 9
#define MOVE_FANCY_LAZY MOVE_FANCY + 10
#define MOVE_FANCY_WALK MOVE_FANCY + 11
#define MOVE_FANCY_WALK_BACK MOVE_FANCY + 12
#define MOVE_FANCY_DANCE MOVE_FANCY + 13
#define MOVE_SLOWDOWN_FORWARD MOVE_SLOWDOWN + 1
#define MOVE_SLOWDOWN_BACKWARD MOVE_SLOWDOWN + 2
#define MOVE_SLOWDOWN_SPIN_LEFT MOVE_SLOWDOWN + 3
#define MOVE_SLOWDOWN_SPIN_RIGHT MOVE_SLOWDOWN + 4
#define MOVE_SPEEDUP_FORWARD MOVE_SPEEDUP + 1
#define MOVE_SPEEDUP_BACKWARD MOVE_SPEEDUP + 2
#define MOVE_SPEEDUP_SPIN_LEFT MOVE_SPEEDUP + 3
#define MOVE_SPEEDUP_SPIN_RIGHT MOVE_SPEEDUP + 4
__nolist void BasicMove (const int move, const int time)
{ asm { 0xe3, &move, 0xe3, &time, 0x17, 43, 0x01, 2 }; }
// nSound is 0-79, -1 = no sound
// nDisplay is LED animation (0-15) to play, -1 = no animation
// nMovement is from the *Move routines defined below, -1 = no move
// nRepeat is number of times to repeat motion
// ntime is in 10ms steps
__nolist void Action (const int nSound, const int nDisplay,
const int nMovement, const int nRepeat, const int nTime)
{
asm { 0xe3, &nSound };
asm { 0xe3, &nDisplay };
asm { 0xe3, &nMovement };
asm { 0xe3, &nRepeat };
asm { 0xe3, &nTime };
asm { 0x17, 44 };
asm { 0x01, 5 };
}
__nolist void RandomMove (const int move, const int time)
{
asm { 0xe3, &move };
asm { 0xe3, &time };
asm { 0x17, 46 };
asm { 0x01, 2 };
}
__nolist void FancyMove (const int move, const int time)
{
asm { 0xe3, &move };
asm { 0xe3, &time };
asm { 0x17, 47 };
asm { 0x01, 2 };
}
__nolist void SlowDownMove (const int move, const int time)
{
asm { 0xe3, &move };
asm { 0xe3, &time };
asm { 0x17, 48 };
asm { 0x01, 2 };
}
__nolist void SpeedUpMove (const int move, const int time)
{
asm { 0xe3, &move };
asm { 0xe3, &time };
asm { 0x17, 49 };
asm { 0x01, 2 };
}
// Adds a value to a 2 byte location in EEprom
__nolist void Sum2Mem (const int nMem, const int nValue)
{
asm { 0xe3, &nMem };
asm { 0xe3, &nValue };
asm { 0x17, 50 };
asm { 0x01, 2 };
}
// Adds a value to a 4 byte location in EEprom
__nolist void Sum4Mem (const int nMem, const int nValue)
{
asm { 0xe3, &nMem };
asm { 0xe3, &nValue };
asm { 0x17, 51 };
asm { 0x01, 2 };
}
#define SOUND_NONE -1
#define SOUND_SHOCKED 6
#define SOUND_FIRE_LASER 7
#define SOUND_FIRE_ELECTRONET 8
#define SOUND_FIRE_SPINNER 9
#define SOUND_HIT_BY_LASER 10
#define SOUND_HIT_BY_ELECTRONET 11
#define SOUND_HIT_BY_SPINNER 12
#define SOUND_TAG 13
#define SOUND_CRASH 14
#define SOUND_FIGHT 15
#define SOUND_GOT_IT 16
#define SOUND_GENERAL_ALERT 17
#define SOUND_OUT_OF_ENERGY_ALERT 18
#define SOUND_LOW_ENERGY_ALERT 19
#define SOUND_SCORE_ALERT 20
#define SOUND_TIME_ALERT 21
#define SOUND_PROXIMITY_ALERT 22
#define SOUND_DANGER_ALERT 23
#define SOUND_BOMB_ALERT 24
#define SOUND_FINAL_COUNTDOWN 25
#define SOUND_TICK_TOCK 26
#define SOUND_GOTO 27
#define SOUND_SCAN 28
#define SOUND_POINT_TO 29
#define SOUND_ACTIVATE_SHIELDS 30
#define SOUND_ACTIVATE_REFLECT 31
#define SOUND_ACTIVATE_CLOAK 32
#define SOUND_ACTIVATE_FLASH_BLIND 33
#define SOUND_MAGNET 34
#define SOUND_QUAD_DAMAGE 35
#define SOUND_REPULSE 36
#define SOUND_TURBO 37
#define SOUND_FREEZE 38
#define SOUND_SLOW 39
#define SOUND_REVERSE 40
#define SOUND_DIZZY 41
#define SOUND_BOOST 42
#define SOUND_DEACTIVATE_SHIELDS 43
#define SOUND_DEACTIVATE_REFLECT 44
#define SOUND_DEACTIVATE_CLOAK 45
#define SOUND_REFLECT 46
#define SOUND_EXPLOSION 47
#define SOUND_BIG_EXPLOSION 48
#define SOUND_PLACE_BOMB 49
#define SOUND_HIT_BY_WIND 50
#define SOUND_OUCH 51
#define SOUND_GEIGER 52
#define SOUND_WHISTLE 53
#define SOUND_IM_IT 54
#define SOUND_HELP 55
#define SOUND_SIREN 56
#define SOUND_BURNT 57
#define SOUND_GRINDED 58
#define SOUND_SMACKED 59
#define SOUND_TRILL_UP 60
#define SOUND_TRILL_DOWN 61
#define SOUND_YELL 62
#define SOUND_WHISPER 63
#define LED_RED1 0x01
#define LED_RED2 0x02
#define LED_RED3 0x04
#define LED_GREEN1 0x08
#define LED_GREEN2 0x10
#define LED_GREEN3 0x20
#define LED_YELLOW 0x40
#define LED_ALL_RED LED_RED1 + LED_RED2 + LED_RED3
#define LED_ALL_GREEN LED_GREEN1 + LED_GREEN2 + LED_GREEN3
#define LED_ALL_RED_GREEN LED_ALL_RED + LED_ALL_GREEN
#define LED_ALL LED_ALL_REDGREEN + LED_YELLOW
#define FX_SHUDDER 0
#define FX_SHOCKED 1
#define FX_FIRE_AT_BOT 2
#define FX_TWITTER 3
__nolist void Fx_Bead(const int nFx, const int nTimes)
{
asm { 0xe3, &nFx };
asm { 0xe3, &nTimes };
asm { 0x17, 68 };
asm { 0x01, 2 };
}
#endif
|
|
1 Message in This Thread:
- Entire Thread on One Page:
- Nested:
All | Brief | Compact | Dots
Linear:
All | Brief | Compact
|
|
|
|