Skip to content
This repository has been archived by the owner on Jul 2, 2020. It is now read-only.

pierre-24/nxt-interpreter

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

40 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

WIP ... WIP ... WIP ... WIP ... WIP ... WIP ... WIP ... WIP ... WIP ... WIP

I'm working on it, stay tuned.

NXT (Lego Mindstorm language) interpreter

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 ;)

Compile that

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.

Usage

The 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  

The interpreter

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.

Note: dropped and added stuffs

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 and Server, since I only need a single robot here. Thus, I'll use the Single 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 can FileWrite directly in it (it is always open and you can't close it anyway).

Note: the project structure

I did a bit of cleaning by giving a little bit of structure in the files of the src/ folder

Releases

No releases published

Packages

No packages published

Languages