Table of contents
1.1 Differents: TI-Basic vs. C
2.1.1 Adding MSYS to the PATH variable
2.3.1 Adding 7-Zip to the PATH variable
These are some examples I picked to show some differents between TI-Basic and C.
Another point is that C is a lot faster than TI-Basic.
Just follow all instructions and install it to C:\msys\1.0
Open the Start menu and choose “Run…”, type cmd and hit enter.
Type the following into the console:
set %PATH%=%PATH%;C:\msys\1.0\bin
Follow the instructions and install it to a destination of your choose.
Make sure “Add YAGARTO to the PATH variable” is checked in the “Choose Components”-Window!
Follow the instructions and install it to a destination of your choose.
Open the Start menu and choose “Run…”, type cmd and hit enter.
Type the following into the console:
set %PATH%=%PATH%;<7-Zip Installation Folder>
Replace <7-Zip Installation Folder> with your installation folder, for example C:\Program Files\7-Zip.
Tortoise SVN is not especially required; you can use any SVN client you want, but I will use Tortoise in this Tutorial.
Just follow all instructions and install it to a destination of your choose.
Create a
folder called “ndless” on your system drive and right-click it. Choose “SVN
Checkout…” and enter https://www.unsads.com/scm/svn/nsptools/Ndless/trunk in “URL of
repository”. You should end up like this:
Image 1: SVN Checkout
Now just click “OK”. You will be asked for username and password; Use guest for
both.
After downloading the source code, you need to add the path where you installed ndless (e.g. C:\ndless\bin) to your PATH variable. Do it like you did before in 2.1.1 and 2.3.1.
Open StartàProgram Files/All ProgramsàMinGWàMSYSàmsys (rxvt). Type cd /C/ndless and press enter. Now type make. It may take a while to finish.
If your
output looks like this:
Image 2: MSYS
You have done everything correctly.
Now that you have built ndless, you should download and set up nspire_emu.
At first open the downloaded OS file with 7-Zip (Right-clickà7-ZipàOpen). These files should be included in the image:
Image 3: OS files
Now extract the selected file (boot2.img) to the imgdump folder, open a console (StartàRun…àcmd) and type:
cd <imgdump_path>
imgdump.exe boot2.img
Replace <imgdump_path> with the path where your imgdump is located. This will produce a file called boot2.img.raw. Copy it to your nspire_emu folder.
To create a flash image with preinstalled OS, type into the console:
cd <nspire_emu_path>
nspire_emu.exe /N /F=flash.bin /PO=<OS_Image_File_name>
Replace <nspire_emu_path> with the path where nspire_emu is located and <OS_Image_File_name.tno> with the name of your downloaded OS 2.1 Image file name.
Make sure to add /C to the console command if you are using a CAS OS.
Now you are ready to boot your emulated Nspire and install the OS. To make starting the emulator a lot easier, you should create a batch (*.bat) file in your emulator’s directory that contains:
nspire_emu.exe /B=boot2.img.raw /F=flash.bin
Now you can just double-click this file and the emulator will boot your nSpire. When you start it for the first time, you have to press “I” when you are asked to. After the OS is installed (and you have chosen your language and font size) you need to save your flash to make sure you do not have to install the OS again every time the Nspire boots. To do so, go to FileàSave Flash.
Every time the calculator tries to go in standby (normally after three minutes of inactivity), the emulator will freeze. To prevent those crashes, you can set the standby time to 30 minutes. Go to Settings & StatusàHandheld Setup… and change the Power Standby time. After doing this, save the flash again.
Image 4: Setting the standby time
Now you should have two windows. The first, the RS232 console, shows all the stuff the calc sends trough the RS232 interface[1]; The second is the calculator itself, including keypad and screen.
Image 5: RS232 Console
Image 6: Calculator screen
To install ndless, you need to send it to your emulated calculator first. Open LinkàConnect to “plug the USB cable in”. Your RS232 console should output usblink connected. Now you can send the ndless files by choosing LinkàSend Document…; the required files are named ndless_installer_os-2.1.0.tns and ndless_resources.tns. They are located in <ndless_path>/calcbin. Replace <ndless_path> with the path of your compiled ndless. After both files are sent, save the flash again. Now go to My Documents, select ndless_installer_os-2.1.0 (should be located in Examples) and press Enter. After a successful installation a message will appear:
Image 7: ndless installation
If random pixel lines show up and the calculator freezes, the installation failed and you need to try again. If the calculator does not restart itself, you need to reset the CPU (EmulationàReset CPU). The Nspire will restart then.
Now that you know how to send files to the emulator, we will code our first C program. Create a new folder for this project.
Every program you might code will need this file. Some important settings are located in it. An example Makefile can be found in ndless’s samples/hello directory. Copy it in your folder.
A Makefile is not necessarily needed, but it will make compiling programs a lot easier.
GCC = nspire-gcc
LD = nspire-ld
GCCFLAGS = -Os -nostdlib -Wall -W -marm
LDFLAGS = -nostdlib
OBJCOPY := "$(shell which arm-elf-objcopy 2>/dev/null)"
ifeq (${OBJCOPY},"")
OBJCOPY := arm-none-eabi-objcopy
endif
EXE = hello.tns
OBJS = hello.o
DISTDIR = ../../calcbin/samples
vpath %.tns $(DISTDIR)
all: $(EXE)
%.o: %.c
$(GCC) $(GCCFLAGS) -c $<
$(EXE): $(OBJS)
$(LD) $(LDFLAGS) $^ -o $(@:.tns=.elf)
mkdir -p $(DISTDIR)
$(OBJCOPY) -O binary $(@:.tns=.elf) $(DISTDIR)/$@
clean:
rm -f *.o *.elf
rm -f $(DISTDIR)/$(EXE)
You do not have to know what all these lines do, but some of them are important:
EXE = hello.tns
OBJS = hello.o
DISTDIR = ../../calcbin/samples
So the these three lines say that the executable file will be called hello.tns and consists of hello.o. It will be located in the folder ../../calcbin/samples. Because we want to have the executable in our directory, change the DISTDIR to . .
Create a new file called hello.c. Write these lines:
#include <os.h>
int main(void)
{
puts("hello world!");
return 0;
}
This is a VERY basic program, so I think I do not have to say much.
#include <os.h>
Includes the file os.h. It is required by every ndless program.
int main(void)
Declares the main-function of our program. You should now
that.
puts("hello world!");
Sends hello world! Through the RS232-Interface.
return 0;
Returns zero. Ends the
program.
Open up msys (rxvt), navigate to your folder (using cd) and type make.
On a successful compilation your output will look like this:
nspire-gcc -Os -nostdlib -Wall -W -marm -c hello.c
nspire-ld -nostdlib hello.o -o hello.elf
mkdir -p .
arm-none-eabi-objcopy -O binary hello.elf ./hello.tns
Start the emulator, install ndless and send the file hello.tns. Now just click on it in the My Documents screen. A message will appear in the RS232 console:
Image 8: Hello World!