diameter 发表于 2013-6-23 21:31:45

Nspire机上C解释器 dPicoC v2.11 beta1

本帖最后由 ExAcler 于 2015-2-1 22:24 编辑

变更日志      v2.11          -   增加 <OS.h><math.h>支持。但只有部分函数被支持          -   增加脚本模式,工程模式,配置模式v2.10          -Nspire版本放出
截图
主界面:

测试(未完成的)小游戏:EvilSword:


设置:

附件:(包含主程序,完整说明文档,程序例)

函数支持见2L。

diameter 发表于 2013-6-23 21:31:51

本帖最后由 diameter 于 2013-6-23 21:43 编辑

内建头文件/函数列表新添加的函数以粗体标注stdio.h
int sprintf(char *, char *,...);
int puts(char *);
char * gets(char *);
void cls();
int printf(char*,...);
FILE *fopen(char *, char *);
FILE *freopen(char *, char *, FILE *);
int fclose(FILE *);
int fread(void *, int, int, FILE *);
int fwrite(void *, int, int, FILE *);
int fgetc(FILE *);
int getc(FILE *);
char *fgets(char *, int, FILE *);
int fputc(int, FILE *);
int fputs(char *, FILE *);
int feof(FILE *);
int ftell(FILE *);
int fseek(FILE *, int, int);
stdlib.h
float atof(char *);
int atoi(char *);
int atol(char *);
int strtol(char *,char **,int);
void *malloc(int);
void *calloc(int,int);
void *realloc(void *,int);
void free(void *);
int rand();
void srand(int);
void abort();
void exit(int);
char *getenv(char *);
int abs(int);
int labs(int);
string.h
void *memcpy(void *,void *,int);

void *memmove(void *,void *,int);
void *memchr(char *,int,int);
int memcmp(void *,void *,int);
void *memset(void *,int,int);
char *strcat(char *,char *);
char *strncat(char *,char *,int);
char *strchr(char *,int);
char *strrchr(char *,int);
int strcmp(char *,char *);
int strncmp(char *,char *,int);
char *strcpy(char *,char *);
char *strncpy(char *,char *,int);
ctype.h
int isalnum(int);

int isalpha(int);
int isblank(int);
int iscntrl(int);
int isdigit(int);
int isgraph(int);
int islower(int);
int isprint(int);
int ispunct(int);
int isspace(int);
int isupper(int);
int isxdigit(int);
int tolower(int);
int toupper(int);
math.h
double sin(double);
double cos(double);
double tan(double);
double sqrt(double);
double fabs(double);
double ln(double);
double log(double);
double exp(double);
double pow(double);
os.h
intis_incolor();
void setpixel(int x,int y,int color);
intgetpixel(int x,int y);
void setpixelbuf(unsigned char*scrbuf,int x,int y,intcolor);
intgetpixelbuf(unsigned char*scrbuf,int x,inty);
void wait_key();
void wait_no_key();
intgetch();
void clrscr();
unsigned char * get_scr_base_addr();
intget_scr_byte_size();
intmsgbox(char*title,char*msg);
int   msgbox2b(char*title,char*msg,char*button1,char*button2);
int   msgbox3b(char*title,char*msg,char*button1,char*button2,char*button3);
void sleep(int);
intusr_input(char*title,char*subtitle,char*default,char**value);
intnum_input1(char*title,char*subtitle,char*msg,int*value_ref,int min,int max);
intnum_input2(char*title,char*subtitle,char*msg1,int*value_ref1,int min1,int max2,char* msg2,int*value_ref2,int min2,int max2);
void putstr(int x,inty,char*str,int color_fg,int_color_bg);
void write_graph(int x,inty,int width,int height,unsigned char* image,int color_fg,int color_bg);
voidwrite_graph_buf(unsigned char*scrbuf,int x,int y,int width,int height,unsignedchar* image,int color_fg,int color_bg);

diameter 发表于 2013-6-23 21:32:29

本帖最后由 diameter 于 2013-6-23 21:48 编辑

程序例
脚本模式测试:script_chs_demo.c.tns
需要把附带的HZK16.tns文件放在文件夹”dpicoc“中
截图:
#define FONT_16_SIZE 32

FILE *                        HZK = NULL;
unsigned char      mat;

int open_hzk ()
{
      HZK = 16.tns","rb");
      if (HZK==NULL) return 0;
      return 1;
}

void put_chs(int x,int y,unsigned char * str)
{
      unsigned char c1,c2;
      while(*str)
      {
                c1 = *str++;
                if(!(c1 & 0x80)) continue;
                c2 = *str++;
                fseek(HZK,(94*(c1-0xa1)+(c2-0xa1))*FONT_16_SIZE,SEEK_SET);
                fread(mat,FONT_16_SIZE,1,HZK);
                write_graph(x,y,16,16,mat,0x0,0xF);
                x+=16;
      }
}

void close_hzk ()
{
      if (HZK!=NULL)
                fclose(HZK);
}

open_hzk      ();
put_chs                (0,0,"汉字库使用演示——by 安德兰");
close_hzk      ();

sleep(500);
getch();工程模式测试:
a.cpj.tns(必须放置在dpicoc文件夹中)/documents/dpicoc/file1.c.tns
/documents/dpicoc/file2.c.tnsfile1.c.tns#include <stdio.h>
extern int abs(int);
extern long atol(char *);

int main ()
{
      int a;
      char buf;
      puts("input a num");
      a = atol(gets(buf));
      printf("abs(%d)=%d\n",a,abs(a));
      return 0;
}file2.c.tns#include <ctype.h>
long atol(char *nptr)
{
    int c;
    long total;
    int sign;

    while ( isspace((int)(unsigned char)*nptr) )
      ++nptr;

    c = (int)(unsigned char)*nptr++;
    sign = c;
    if (c == '-' || c == '+')
      c = (int)(unsigned char)*nptr++;

    total = 0;

    while (isdigit(c)) {
      total = 10 * total + (c - '0');
      c = (int)(unsigned char)*nptr++;
    }

    if (sign == '-')return -total;
    else            return total;
}

int abs(int x)
{
return x<0 ? -x:x;
}

白菜白 发表于 2013-6-23 21:41:55

{:grin:} 太好了 。有的玩了

qihai1314 发表于 2013-6-24 09:27:47

我是看不懂{:051:}

_14522 发表于 2013-6-24 13:05:30

好东西

DAS 发表于 2013-6-24 13:26:28

好,有的玩了

DAS 发表于 2013-6-24 19:44:56

我觉得楼主应修改一下,尽量向标准C语言靠近

diameter 发表于 2013-6-24 20:24:12

DAS 发表于 2013-6-24 19:44 static/image/common/back.gif
我觉得楼主应修改一下,尽量向标准C语言靠近

给点具体的意见?是标准库还是语法

415987611 发表于 2013-6-25 08:53:30

#inculde <stdio.h>
int main()
{double a=1.0,b=2.0;
printf("a=%f,b=%f\n",a,b);
return 0;
}

运行结果:
a=0.000000 b=0.000000

float 也是

怎么回事?

diameter 发表于 2013-6-25 09:49:31

415987611 发表于 2013-6-25 08:53 static/image/common/back.gif
#inculde
int main()
{double a=1.0,b=2.0;

请仔细查看说明文档(最后一页)
这是ndless标准库的问题,printf只有%d能正常工作
%x无论什么结果都显示xxx
%f无论什么都显示0.000000

415987611 发表于 2013-6-25 10:01:55

这么坑爹……

有什么替代的解决方案?

diameter 发表于 2013-6-25 10:08:51

本帖最后由 diameter 于 2013-6-25 10:09 编辑

415987611 发表于 2013-6-25 10:01 static/image/common/back.gif
这么坑爹……

有什么替代的解决方案?
自己实现一个呗...gcvt在ndless里面倒是可以正常使用,下一次加到内建函数里面去
这里倒是有一个比较烂的ftoachar *d_ftoa(double d, char* str)
{
      char str1;
      int j=0,k,i;

      if (d<0)
      {
                *str = '-';
                d_ftoa(-d,str+1);
      }
      else
      {
                i = (int)d;//浮点数的整数部分
                if (i==0)
                {
                        str1 = '0';
                }
                else
                {
                        while(i>0)
                        {
                              str1 = i%10+'0';
                              i /= 10;
                        }
                }
                for(k=0;k<j;k++)
                        str = str1; //
               
                str = '.';
               
                d -= (int)d;
               
                for(i=0;i<16;i++)
                {
                        d *= 10.0;
                        str = (int)d+'0';
                        d -= (int)d;
                }
               
                j-=4;
               
                while(str[--j]=='0');
                        str = '\0';
               
                if (str=='.')
                        str = '\0';
      }
      return str;
}

gaojd 发表于 2013-8-12 17:05:15

好东西。。。。。。。。

yymalu 发表于 2013-12-23 19:55:00

C语言!!好厉害

illuminati 发表于 2014-4-26 22:07:13

感谢楼主分享!

549597890 发表于 2014-4-26 23:09:41

bug不少...
最大的bug是键盘

549597890 发表于 2014-4-26 23:10:41

bug不少..
最大bug是键盘

留守tiGTC

rourou_Jun 发表于 2014-4-27 17:11:56

居然早就有了!!!太赞

suhaijie 发表于 2014-7-16 16:31:20

看得眼花缭乱
页: [1] 2
查看完整版本: Nspire机上C解释器 dPicoC v2.11 beta1