⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 rb_load.c

📁 可以在嵌入式应用中
💻 C
字号:
#include <CsAgb.h>
#include <rb_stdio.h>
#include <pro.h>
#include <rbasic.h>
#include <rb_math.h>
#include <rb_string.h>
#include <rb_data.h>
const char *rbcoms=LOADBASE;
/*const char rbcoms[]="10 cls
20 locate 1,2:print \"WELCOME TO THE BASIC WORLD!!\"
30 locate 2,4:print \"PRESS ANY KEY TO CONTINUE.\"
35 A$=\"REDBOY BASIC FOR GBA V1.0.\":j=1000
40 while getkey(1)=0
45 a$=strmv$(a$,0,1)
50 locate 2,6:print a$
60 i=i+1
70 line 20+i,100,20+i,120,j,4
75 WRITE 50,105,RND(30000),\"欢迎来到BASIC的世界!\"
80 if i=200 THEN (i=0:j=j+100)
90 if i%20=0 THEN (locate 2,4:print \"                          \")
95 if i%25=0 then (locate 2,4:print \"PRESS ANY KEY TO CONTINUE.\")
100 wend
110 cls
120 color 31710
130 locate 9,3:print \"----MENU----\"
140 locate 9,4:print \"1.CALCULATOR\"
150 locate 9,5:print \"2.MINI GAMES\"
160 locate 9,6:print \"3.EXIT BASIC\"
170 box 70,30,170,70,2345,4
180 old=0:sel=1:do=0
185 gosub 1020
190 while do<>9
200 do=getkey(0)
210 if do=1 then sel=sel-1
220 if do=2 then sel=sel+1
230 if sel<1 then sel=3
240 if sel>3 then sel=1
250 gosub 1020
260 wend
270 locate 9,7:print \"LOAD...\"
280 on sel goto 305,350,400
305 for i=1 to 4
310 for j=4 to 7
320 print i;\"+\";j;\"=\";i+j
325 next
330 next
331 a=getkey(0)
335 cls
340 old=0:goto 130
350 print \"NO GAME FOUND!\"
360 cls
370 old=0:goto 130
400 end
1000 a=getkey(0)
1020 if sel then box 70,30+sel*10,170,39+sel*10,0,5
1030 if old then box 70,30+old*10,170,39+old*10,0,5
1040 old=sel
1050 ret";
*/
u32 rb_com_lines;//程序总行数
void rb_load(char *coms)
{
   u32 i=0,line;
   char lin[str_max_len];
   u8 lp=0;
   struct comtree *start=NULL;
   while (coms[i]!='\0')
   {
      while (!is_number(coms[i])) i++;
      while (coms[i]!=' ')//取得行号
      {
         lin[lp]=coms[i];
         if (!is_number(lin[lp]))
         {
            rb_error=27;
            return;
         }
         lp++;
         i++;
      }
      if (lp>9)
      {
         rb_error=27;
         return;
      }
      rb_com_lines++;
      lin[lp]='\0';
      lp=0;
      line=str_to_int_num(lin);
      if (start==NULL)
      {
         start=(struct comtree *)malloc(sizeof(struct comtree));
         comstart=start;
         if (start==NULL)
         {
            rb_error=1;
            return;
         }
      }
      else
      {
         start->next=(struct comtree *)malloc(sizeof(struct comtree));
         if (start->next==NULL)
         {
            rb_error=1;
            return;
         }
         start=start->next;
      }
      while (coms[i]==' ') i++;
      start->line=line;
      start->com=coms+i;
      start->next=NULL;
      while (coms[i]!='\n' && coms[i]!='\0') i++;
   }
}
void line_list(struct comtree *com)
{
   u8 i=0;
   if (com==NULL) return;
   show_float(com->line,rb_co);
   prtchar(0,' ');
   while(com->com[i]!='\n' &&com->com[i]!='\0')
   {
      prtchar(rb_co,com->com[i]);
      i++;
   }
   endl();
}
void sort_list()
{
   struct comtree *now;
   struct comtree *max;
   struct comtree temp;
   u32 i,j;
   u32 steps=rb_com_lines-1;
   if (steps<1 || rb_com_lines<1) return;
   for (i=0;i<steps;i++)
   {
      now=comstart;
      max=comstart;
      temp=*comstart;
      for (j=0;j<steps-i;j++)
      {
         if (max->line<now->next->line)
         {
            max=now->next;
         }
         else if(max->line==now->next->line)//存在相同的语句行号
         {
            rb_error=28;
            rb_now_line=now->next;
            return;
         }
         now=now->next;
      }
      temp=*max;
      max->line=now->line;//交换行号
      max->com=now->com;
      now->line=temp.line;
      now->com=temp.com;
   }
}
struct comtree *seek_line(u32 line)//寻找指定行
{
   struct comtree *now=comstart;
   while (now!=NULL && now->line!=line) now=now->next;
   return now;
}
void com_free(struct comtree *com)//释放所有命令行
{
   if (com->next!=NULL) com_free(com->next);
   free(com);
   com=NULL;
}
void rb_new()
{
   com_free(comstart);
}
void list_all()
{
   struct comtree *com=comstart;
   while (com!=NULL)
   {
      line_list(com);
      com=com->next;
   }
}
/*void seek_rom()
{
   u32 i=0;
   endl();
   for (i=0;i<1;i++)
   {
      prtchar(RGB(20,0,30),rbcoms[i]);
      if (rbcoms[i]=='l' && rbcoms[i+1]=='o' && rbcoms[i+2]=='n' && rbcoms[i+3]=='g')
      {
         rb_say_error("FOUND!");
         prt_int_num(i,RGB(20,30,10));
         break;
      }
   }
   rb_say_error("OK!");
}
void seek_rom()
{
   prtchar(RGB(20,0,30),rbcoms[0]);
   prtchar(RGB(20,0,30),rbcoms[1]);
   prtchar(RGB(20,0,30),rbcoms[2]);
   endl();
}*/

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -