Difference between revisions of "NERPs"

m (□)
Line 45: Line 45:
NRN files are not read by the game.
NRN files are not read by the game.
The '''nerpnrn.h''' header file, found in <code>LegoRR0.wad/Levels/nerpnrn.h</code>, defines a standard template for NERPs source files, as well as a set of macros to make developing NERPs scripts slightly easier. For example, nerpnrn.h implements rudimentary support for functions with the <code>Func</code>, <code>Funcn</code>, <code>Function</code> and <code>FuncEnd</code> macros, via creative use of the few registers available in NERPs scripts to decide which functions to execute and use of macros to define labels at the start and end of functions.
Most NRN files in the game include the preprocessor directive <code>#include &lt;nerpnrn.h&gt;</code> (the NRN files for Level02 and Level05, [[It's A Hold Up]] and  [[The Path To Power]], do not), which allows them to use the macros defined in nerpnrn.h.
==nrM files==
==nrM files==

Revision as of 10:11, 22 February 2019

This article is an unfinished work in progress or contains transferred information that needs to be rewritten or reformatted to fit our standards. Please excuse the mess and do not mark for deletion.

NERPs is a scripting system created by Data Design Interactive which is used in the Windows version of LEGO Rock Raiders.

It consists of a bytecode language that is stored in NPL files, each level then has a NERPFile parameter in Lego.cfg that tells it which script to use. This script is called once per game tick (25 times per second) by the game engine.[1] It will run to completion on each execution, only stopping when the function named "Stop" is called or the end of the script is reached.

The source code of a NERP script is a NRN file, which is then processed through a C preprocessor to generate a nrM file. This file can then be compiled into bytecode using the appropriate tool.

Each operation in the bytecode is a double word, where the top word designates the opcode and the lower word designates the operand. Of course this is stored in little endian format in the file itself.

The opcodes are as follows:

Value Opcode Function
0x0000 Constant Load an integer constant, operand is the value
0x0001 Compares Comparison operators, operand is the comparator function.
0x0002 Function Calls a function, operand is the functions ID
0x0004 Label definition Defines a label that can be jumped to, operand is just an ID number
0x0008 Goto Jumps to a bytecode offset, operand is address to jump to

Also involved are a couple of register named R0 to R7, the contents of which are saved between executions. There are also four timers, Timer0 to Timer3. The function of these is unknown at this time.

NRN files

NRN files are the most easily readable form of NERPs script; they are uncompiled, unprocessed plain text. They were run through a C/C++ preprocessor in order to create the nrM files shipped with the game, so they use a combination of NERPs and C/C++ syntax (e.g. // is used for comments, not ;). Most (but not all) NRN files in the game use macros defined in the nerpnrn.h header file to improve readability.

NRN files are not read by the game.

nrM files

An nrM file is a plain-text version of a NERPs script. The nrM files in the game are NRN files that have been run through a C/C++ preprocessor (at DDI, the Visual Studio 6 C++ preprocessor was used[2]); at this point, they would presumably be compiled into the NPL files the game actually reads, using DDI's own NERPs compiler.

nrM files are not read by the game.

NPL files

NPL files are the compiled NERPs scripts that the game actually reads and executes.

All script from the nrM file is compiled into four bytes (two little-endian 16-bit words) for each scripted number, parameter/function, and symbol.

Numbers end in 00 00, Symbols end in 01 00, and Parameters end in 02 00. Certain Special Parameters also end in 04 00 and 08 00. The first 16-bit word in each pair indicates the number, or the number that a symbol or parameter has been given. For example, the number 4 is 04 00 00 00. Parameter #13, which is GetCrystalsCurrentlyStored, is 0D 00 02 00. Symbol #5, which is the ">" symbol, is 05 00 01 00.

Putting them altogether GetCrystalsCurrentlyStored > 4 becomes 0D 00 02 00 05 00 01 00 04 00 00 00.

NERPs resources