WIP ... WIP ... WIP ... WIP ... WIP ... WIP ... WIP ... WIP ... WIP ... WIP
I'm working on it, stay tuned.
Excerpt of this simulator (for which the source code is available here) in order to get a functional interpreter of the NXT language, without the graphical and sound part.
Again, the goal here is to test some code compiled from NBC (Next Bytes Code) since it is the target language of my CS compiler project lecture.
I do not plan on fixing bug or anything ... But if you are a CS student in the University of Namur, you probably know where to find me for (some kind of) support, though... Lucky you ;)
You need CMake to at least version 3.10 (I especially lower this requirement so that I can compile it on my "old" Ubuntu 18.04, so that should be good on your more recent distribution).
mkdir build
cd build
cmake ..
make -J 2
There is a lot of warning (deprecated C++14 stuffs herited from the original source code that I could clean up if I had a second life), but two executable should be found in the build
directory: nxt_interpreter
and rxe_analyser
.
rxe_anlyser
is a disassambler of RXE file (excutable NXT format). It gives you the DSTOC section, the Dope Vectors one, the clumps (thread/subroutines) and finally the code.
Sample output:
Output of the interpreter
$ ./rxe_analyser ../tests/simple.rxe
-- Static data --
DSTOC Count: 10
Initial Size: 36
Static Size: 12
Default Data Size: 33
Dynamic Default Offset: 9
Dynamic Default Size: 24
Memory Manager Head: 1
Memory Manager Tail: 0
Dope Vector Offset: 16
Clump Count: 1
Code Word Count: 29
-- DSTOC --
entry type flags desc contents
0: sword 0 0 2000
1: ubyte 1 2 0
2: sbyte 0 3 96
3: sbyte 0 4 63
4: sbyte 0 5 100
5: sbyte 0 6 32
6: sbyte 1 7 0
7: sbyte 0 8 3
8: array 0 10 1
9: ubyte 0 0 208
-- Dope Vectors --
entry size count
0: 10 2
1: 1 2
-- Clump data --
entry fc cs dependents
0: 0 0
-- Code --
pc word Disassembled
0 0 OP_SETOUT 46 8 (array) 2 (sbyte) 4 (sbyte) 1 (ubyte) 7 (sbyte) 8 (array) 6 (sbyte) 6 (sbyte) 5 (sbyte) 7 (sbyte) 6 (sbyte) 5 (sbyte) 6 (sbyte) 10 (?????) 2 (sbyte) 11 (void) 5 (sbyte) 12 (?????) 5 (sbyte) 0 (sword) 3 (sbyte)
1 23 OP_WAIT 65535 (NOT_A_DS_ID) 0 (sword)
2 26 OP_FINCLUMP 65535 65535
On the other hand, nxt_interpreter
is an interpreter.
$ nxt_interpreter -h
Usage: nxt_interpreter [options] inputfile
Execute RXE file
-h: print this help and exit
-g: debug output
-s <factor>: speedup factor (default=1)
-m <file.map>: map file
-c <file.csv>: csv output file (position and angle)
Sample output (if you want to understand this strange output, check the source code):
$ ./nxt_interpreter ../tests/file.rxe
this, this, and that 21
For more information about the map, the robot, and its movement, check there.
I dropped:
Drawer
, and basically the graphical part (rely on SDL) ;RobotSpeaker
, which use OpenAL for nothing much (we don't play sounds here).Client
andServer
, since I only need a single robot here. Thus, I'll use theSingle
one.
... And I added:
- I implemented some of the few remaning opcodes (see what's left here).
- A threading mechanism, so
op_finclump
really schedule other clumps (= threads) (see there). - A virtual file system, if you ever need that (see there).
- A special handler,
0
for the standard output, so you canFileWrite
directly in it (it is always open and you can't close it anyway).
I did a bit of cleaning by giving a little bit of structure in the files of the src/
folder
src/Execution
folder: related to the execution of the RXE byte code, with the context which serve as the main interface to execute a code and theRXEFile
object, which opens the binary file.src/Interpreter
folder: contains the bytecodeInterpreter
(which sets up the threading mechanism).src/System
folder: related to the virtual operating system of which the codes run. In particular, theVMMemory
object (which manage the memory), theVFileSystem
object (which implement a in memory virtual flat file system), and theSystem
object (which handle syscalls and other system stuffs).src/Robot
folder: related to the robot itself, and its motor. Also contains the (in)famousNetworkInterface
abstract object to communicate with it.src/Environement/
folder: related to the robot environment in which it moves, corresponding to a kind of "map". In particular, it deals with the light sensor and the collisions.src/utils
folder: the traditionalutils
folder (here byte manipulations and vectors).