To LUGNET HomepageTo LUGNET News HomepageTo LUGNET Guide Homepage
 Help on Searching
 
Post new message to lugnet.roboticsOpen lugnet.robotics in your NNTP NewsreaderTo LUGNET News Traffic PageSign In (Members)
 Robotics / 26483
26482  |  26484
Subject: 
NBC News for NXT
Newsgroups: 
lugnet.robotics
Date: 
Thu, 12 Oct 2006 18:00:51 GMT
Viewed: 
2613 times
  
Last night I uploaded a new beta to the NBC website.  This new beta includes
support for multi-dimensional arrays.  In NBC you can now define arrays of 3 or
4 (or more) dimensions.  You can use arrays of structures containing arrays of
arrays, etc...  Here's a sample program which demonstrates the multi-dimensional
array support:

#include "NXTDefs.h"

dseg segment
  dtArgs TDrawText
//  y byte[] 'testing'
  y byte[] '__FILE__'
//  z byte[] 'testing2'
  z byte[] '__VER__'
  yy byte[] 'amazing'
  zz byte[] 'incredible'
  r byte[][]
  rr byte[][]
  tmp byte[][]
  odd byte[][][]

  __buf byte[]
  __tmp1 byte[]
  __tmp2 byte[]
  idx byte
  idx2 byte
dseg ends

#define TEXTOUT(x,y,cls,txt, ms)  mov dtArgs.Location.X,x \
                              mov dtArgs.Location.Y,y \
                              mov dtArgs.Options,cls \
                              mov dtArgs.Text,txt \
                              syscall DrawText,dtArgs \
                              wait ms
thread main
  set idx, 0
  set idx2, 0
  arrbuild r, z, y // add strings to array of strings
  arrbuild rr, zz, yy // add strings to array of strings
  arrbuild odd, r, rr // 3-dimensional array !!!

  Forever:
     numtostr __tmp1, idx2
     numtostr __tmp2, idx
     strcat __buf, 'odd[', __tmp1, '][', __tmp2, ']'
     TEXTOUT(0, 52, TRUE, __buf, 10)

     index tmp, odd, idx2
     index __buf, tmp, idx
     // _buf = odd[idx2][idx]
     TEXTOUT(0, 40, FALSE, __buf, 1000)

     ; increment idx
     add idx, idx, 1
     mod idx, idx, 2

     brtst NEQ, Forever, idx ; if idx<>0 do not change idx2

     ; increment idx2
     add idx2, idx2, 1
     mod idx2, idx2, 2

  jmp Forever

endt


Compiler optimizations in NBC are now controlled via a command line switch which
specifies the optimization level.  By default (unlike in beta 8) the
optimization level is 0 (i.e., no optimization).  Level 1 is equivalent to the
optimization in beta 8 (-Z1).  -Z and -Z2 enable a second level of code
optimization which does such things as remove code which sets a variable to a
value and that variable is never referenced again in code.

Also note in the above snippet the use of __FILE__ and __VER__.  There are
several new tokens which can be used in an NBC program which provide some cool
new abilities.  In NBC you can now write preprocessor macros which can be used
repeatedly in a thread or across concurrent threads without worrying about the
code not being thread-safe or winding up with duplicate label names.  Supported
tokens are:

__FILE__, __LINE__, __VER__, __THREADNAME__, __I__, __J__, __IncI__, __IncJ__,
__DecI__, __DecJ__, __ResetI__, __ResetJ__, and ##.

With these you can write a macro like this:

#define testing __##__THREADNAME__##_##__I__: \
                set b3, 100 \
                jmp __##__THREADNAME__##_##__I__ \
                __IncI__

That's not a terribly useful macro since it creates an infinite loop, but you
get the picture.  Each time you use a macro like this one you will get a label
name which will not clash with a label name from another instance of this macro
in the same thread.  The ## token is simply deleted from the input before the
compiler processes the code.

My sincere thanks go out especially to a very smart fellow named Tamas Sorosy
whose assistance has been invaluable in getting multi-dimensional array support
working.  Tamas is writing an extraordinarily cool NXT debugger which supports
run-time variable watching and modifying as well as debugging NXT programs via
single-step execution, pause, run, and user-defined breakpoints.  It will be
able to show the call stack and it will work with multiple concurrent threads as
well.  Absolutely awesome!  It integrates with BricxCC as well.

John Hansen

http://bricxcc.sourceforge.net/nbc



1 Message in This Thread:

Entire Thread on One Page:
Nested:  All | Brief | Compact | Dots
Linear:  All | Brief | Compact
    

Custom Search

©2005 LUGNET. All rights reserved. - hosted by steinbruch.info GbR