|
前提
你需要C语言编程基础
Ndless SDK
下载Ndless SDK。选择一个版本最高的。
对于Windows
解压SDK压缩包,保证路径中没有空格。
如果你用过之前基于命令行的SDK,请删除PATH变量中的相关定义,新的SDK可能与它们冲突。
按照 emu_resources/_ReadMe.txt中的步骤安装SDK集成的TI-Nspire模拟器
你可能还希望把c和h文件与NdlessEditor.exe关联起来。
现在一切都已就绪,从编辑器到编译器,Ndless SDK都已经准备好了,不需要其它步骤。
对于Linux
SDK提供了编译器脚本、头文件和库,但是你必须自己建立GCC编译工具链,使用你自己的编辑器和模拟器。可以参考这个教程.
Ndless编辑器
Ndless编辑器是一个基于SciTE的文本编辑器,但是经过了配置和扩展,使他十分适合用来编写C语言程序。
打开SDK根目录下的 NdlessEditor.exe
和Ndless有关的命令在 Tools 菜单下。运行命令时,相关消息会显示在屏幕下方。
你的第一个程序
我们将会用一个经典的HelloWorld来开始。这个例程中我们将会使用SDK提供的nspireio库。接下来,你将会了解到如何新建一个工程,编译,并在模拟器中运行。
使用 Tools > New Ndless project 来建立一个新的ndless工程
把他保存到工程目录里,我们将把源码命名为 hello.c 并保存在 helloworld/ 文件夹中
编写代码
接下来我们就用nspireio2库来显示一句Hello World.
首先引用一下
#include <os.h>
#include <nspireio2.h>
定义一个nspireio控制台,初始化为灰度模式,然后清屏
nio_console csl;
lcd_ingray();
clrscr();
设置一下
// 53 columns, 29 rows. 0px offset for x/y.
// Background color 0 (black), foreground color 15 (white)
nio_InitConsole(&csl, 53, 29, 0, 0, 0, 15);
nio_DrawConsole(&csl);
然后显示Hello World,等待按键按下
nio_printf(&csl, "hello world!");
wait_key_pressed();
最后程序退出时释放控制台
nio_CleanUp(&csl);
return 0;
我们来看看完整的程序- #include <os.h>
- #include <nspireio2.h>
- int main(void) {
- nio_console csl;
- lcd_ingray();
- clrscr();
- // 53 columns, 29 rows. 0px offset for x/y.
- // Background color 0 (black), foreground color 15 (white)
- nio_InitConsole(&csl, 53, 29, 0, 0, 0, 15);
- nio_DrawConsole(&csl);
- nio_printf(&csl, "hello world!");
- wait_key_pressed();
- nio_CleanUp(&csl);
- return 0;
- }
复制代码 关于更多这里使用的函数,请参考 nspireio’s documentation 和 libndls’s documentation (libndls 是由Sdk提供的 TI-Nspire 定义库).
编译
使用 Tools > Build (或者按下F7)来编译程序。第一次编译时必须给程序命名。Type ‘helloworld’ in the at the bottom of the editor, and press enter. This will be the name of the generated .tns.
A Makefile is created in the program’s directory. If you want to change the name of the program later, you’ll be able to edit the Makefile and change the EXE variable.
The build commands result are displayed in the message pane. If you get an error, double check the source code of the program.
Emulating
Testing the first versions of your program with the emulator may be faster than transferring them after each build to a real TI-Nspire. Let’s run the TI-Nspire emulator with the Tools > TI-Nspire emulator command. Wait for a few seconds until the OS is fully loaded.
If you have any issue here, make sure you have followed every step described in emu_resources/_ReadMe.txt of the Ndless SDK.
We can now send the helloworld.tns file we have just built. In the Ndless Editor where hello.c is open, use the command Tools > Transfer the program. The program will be automatically sent to the ‘ndless’ directory of the TI-Nspire OS.
Finally let make it say hello to the world: open the ‘ndless’ directory in the emulator and open helloworld.tns. If a popup is displayed telling you that ‘This document format is not supported’, Ndless was not installed correctly. Follow again the instructions in emu_resources/_ReadMe.txt.
helloworld.tns is stored in the ‘hello/’ directory of the computer we have created at the beginning of the tutorial. What about trying it on your own TI-Nspire?
Going further
You can explore the program samples in the ‘_samples/’ directory of the SDK.
Also make sure to have a look at the libdndls’s documentation for TI-Nspire specific functions, and the syscalls page for the supported standard functions. You will then be interested by advanced usage of the Ndless SDK.
To try to port SDL-based programs and games, use hoffa’s nSDL library. The library itself is already provided with the Ndless SDK, you just have to include <SDL/SDL.h> at the beginning of the program. See _samples/helloworld-sdl/ in the Ndless SDK directory for a sample program.
Advanced editing
The Ndless Editor’s Tools menu provides the following additional commands:
Compile: compile the currently open .c file, but not the whole program. This command can be used to quickly check the file for syntax errors.
Clean Build: rebuild the whole program. Building with the Build command is incremental. A Clean Build can sometimes solve building issues.
Clean: clean any file generated by the build.
Ndless SDK console: open a MSYS (Unix-like) console in the current program directory. This can be useful if you have customized the program’s Makefile and want to run specific Make targets.
Since the Ndless Editor is SciTE-based, you may want to fiddle with SciTE’s configuration options to customize it for a better TI-Nspire development experience. Overriding the default Ndless SDK configuration with the file SciTEUser.properties is the recommended way to go. |
评分
-
查看全部评分
|