📄 rb_mfun.c
字号:
//数学计算处理
#include <CsAgb.h>
#include <rb_math.h>
#include <math.h>
#include <rbasic.h>
#include <cal.h>
#include <timer.h>
#include <strpro.h>
#include <rb_string.h>
#include <string.h>
u8 peek(u16 id)
{
id=id%512;
return rb_peek_M[id];
}
u8 rb_getkey(u8 fla)//获得健值
{
u8 count=0;
u8 key=0;
fla=fla?1:0;
while (TRUE)
{
CS_ReadKey();
if (CS_IsKeyDown(KEY_UP)) key=1;
else if (CS_IsKeyDown(KEY_DOWN)) key=2;
else if (CS_IsKeyDown(KEY_LEFT)) key=3;
else if (CS_IsKeyDown(KEY_RIGHT)) key=4;
else if (CS_IsKeyDown(KEY_L)) key=5;
else if (CS_IsKeyDown(KEY_R)) key=6;
else if (CS_IsKeyDown(KEY_START)) key=7;
else if (CS_IsKeyDown(KEY_SELECT)) key=8;
else if (CS_IsKeyDown(KEY_A)) key=9;
else if (CS_IsKeyDown(KEY_B)) key=10;
count+=fla;
if (count>20 || key) return key;
}
}
double rb_calcu(char *exp)
{
double re=rb_cal(exp);
rb_error=0;//错误屏幕
return re;
}
double math_fun(u8 id,char *par)//计算
{
double pn=rb_cal(par);
if (rb_error) return 0.0;
switch(id)
{
case 1://sin
return sin(pn);
case 2://cos
return cos(pn);
case 3://tan
return tan(pn);
case 4://log
if (pn<=0.0)
{
rb_error=24;
return 0.0;
}
return log10(pn);
case 5://ln
if (pn<=0.0)
{
rb_error=24;
return 0.0;
}
return log(pn);
case 6://pow
return pow(10.0,pn);
case 7://exp
return exp(pn);
case 8://sqr
if (pn<=0.0)
{
rb_error=24;
return 0.0;
}
return sqrt(pn);
case 9://abs
return abs(pn);
case 10://sgn
return pn<0?-1.0:(pn>0?1.0:0.0);
case 11://int
return get_int(pn);
case 12://ARCSIN
if (pn>1.0 || pn<-1.0)
{
rb_error=25;
return 0.0;
}
return asin(pn);
case 13://arccos
if (pn>1.0 || pn<-1.0)
{
rb_error=25;
return 0.0;
}
return acos(pn);
case 14://arctan
return atan(pn);
case 15://sinh
return sinh(pn);
case 16://cosh
return cosh(pn);
case 17://tanh
return tanh(pn);
case 18://RND
if (get_int(pn)==0) return 0.0;
return CS_Rand()%get_int(pn);
case 19://TIME
return get_time()-pn;
case 20://PEEK;
return peek(pn);
case 21://csrline
return rb_yp;
case 22://pos
return rb_xp;
case 23://GETBG
return rb_bg;
case 24://GETCOR
return rb_co;
case 25://GETPET
return *(mVRAM+(int)pn);
case 26://GETKEY
return rb_getkey(pn);
default://
return 0.0;
}
}
double strn_fun(u8 id,char *exp)//关于字符串的运算函数
{
u8 loc;
char str[2][str_max_len];
char temp[2];
if (id!=3 && id!=5) get_str(str[0],exp);
else
{
if (get_para(temp,exp,2)) {rb_error=12;return 0.0;}//参数不对
get_str(str[0],exp);
get_str(str[1],exp+temp[0]);//获得字符串参数
}
if (rb_error) return 0.0;
switch (id)
{
case 1://LEN
return str_len(str[0]);
case 2://VAL
return str_to_num(str[0]);
case 3://INSTR
loc=str_find(str[0],str[1]);
return loc==str_max_len?0:(loc+1);
case 4://ASC
return str[0][0];
case 5://CMP
return strcmp(str[0],str[1]);
case 6://CALCU
return rb_calcu(str[0]);
default:
return 0.0;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -