sys.c

来自「redboy for gba 是BPNS为GBA编写的一个小软件。软件的邹形是B」· C语言 代码 · 共 191 行

C
191
字号
#include <CsAgb.h>
#include <graph.h>
#include <rb_stdio.h>
#include <text.h>
#include <Qgraph.h>
#include <rb_mem.h>
#include <rbasic.h>
//#define VScr (u16 *) 0x0202d400
#define mVRAM (u16 *) 0x06000000
#define VSAVE (u16 *) 0x06012C00
#define plines 3
extern void title(char *title);
void save_scr(u16 *sav,u8 xp,u8 yp,u8 xsp,u8 ysp)
{
   int i,num,loc=0,ploc;
   if (xsp>239) xsp=239;
   if (ysp>159) ysp=159;
   num=xsp-xp+1;
   ploc=240*yp+xp;
   for (i=yp;i<=ysp;i++)
   {
      DmaCopy(2,mVRAM+ploc,sav+loc,num*2,16);
      loc+=num;
      ploc+=240;
   }
}
void load_scr(u16 *sav,u8 xp,u8 yp,u8 xsp,u8 ysp)
{
   int i,num,loc=0,ploc;
   if (xsp>239) xsp=239;
   if (ysp>159) ysp=159;
   num=xsp-xp+1;
   ploc=240*yp+xp;
   for (i=yp;i<=ysp;i++)
   {
      DmaCopy(3,sav+loc,mVRAM+ploc,num*2,16);
      loc+=num;
      ploc+=240;
   }
}
void arlt_mes(char *text)
{
   u8 xp=42,yp=0;
   u32 i=0;
   u16 color=RGB(3,7,15);
   while (text[i]!='\0')
   {
      if (text[i]>127 && text[i]>=64)//汉字
      {
         if (xp+12>188)
         {
            xp=42;
            yp++;
         }
         else
         {
            paint_ch(xp,57+15*yp,color,text+i);
            xp+=12;
            i+=2;
         }
      }
      else if(text[i]>=32 && text[i]<=127)//可显示英文
      {
         if (xp+7>188)
         {
            xp=42;
            yp++;
         }
         else
         {
            paint_eng(xp,58+15*yp,color,text[i]);
            xp+=7;
            i++;
         }
      }
      else if (text[i]=='\n')
      {
         xp=42;
         yp++;
         i++;
      }
      else i++;
      if (yp==plines) return;
   }
}
u8 arlt(char *tit,char *mes)
{
   u16 i=0;
   char str[2][30];
   u16 *ScrSav=new_malloc(19*1024);
   /*rb_xp=0;
   rb_yp=0;
   show_float((u32)ScrSav,0);*/
   if (ScrSav==NULL) return 0;
   save_scr(ScrSav,40,41,191,101);
   r_box(40,42,191,101,0,0);
   Q_box(41,42,189,55,RGB(3,7,15));
   r_box(40,41,190,100,RGB(30,30,30),0);
   Q_box(41,56,189,99,RGB(27,27,26));
   r_line(40,55,190,55,RGB(30,30,30),1);
   cwrite(42,43,RGB(30,30,30),tit);
   arlt_mes(mes);
   while (1)
   {
      CS_ReadKey();
      if (CS_IsKeyDown(KEY_A))
      {
         load_scr(ScrSav,40,41,191,101);
         new_free(ScrSav);
         return 1;
      }
      else if (CS_IsKeyDown(KEY_B))
      {
         load_scr(ScrSav,40,41,191,101);
         new_free(ScrSav);
         return 0;
      }
      else if (CS_IsKeyDown(KEY_R))
      {
         load_scr(ScrSav,40,41,191,101);
         new_free(ScrSav);
         return 2;
      }
   }
}
void show_mitem(const char *item,u8 id,u16 color,u16 bg)
{
   u8 xp=id/8,yp=id%8;
   Q_box(2+118*xp,18+yp*16,120+118*xp,30+yp*16,bg);
   paint_en(5+118*xp,22+yp*16,color,id+65);
   write(17+118*xp,19+yp*16,color,item);
}
u8 show_menu(const char *menu,u8 num,u8 select)
{
   u8 i;
   int sel=select;
   u8 done=1;
   u16 c_color=RGB(1,8,14);
   u16 bg=RGB(27,27,26);
   u16 r_color=RGB(1,8,14);
   u16 Rcolor=RGB(30,30,30);
   for (i=0;i<num;i++) show_mitem(menu+17*i,i,c_color,bg);
   while (TRUE)
   {
      if(done)
      {
         show_mitem(menu+17*select,select,c_color,bg);
         show_mitem(menu+17*sel,sel,Rcolor,r_color);
         select=sel;
         done=0;
      }
      readkey();
      if (CS_IsKeyDown(KEY_RIGHT))
      {
         sel+=8;
         if (sel>=num) sel-=8;
         done=1;
      }
      else if (CS_IsKeyDown(KEY_LEFT))
      {
         sel-=8;
         if (sel<0) sel+=8;
         done=1;
      }
      else if (CS_IsKeyDown(KEY_UP))
      {
         sel--;
         if (sel<0) sel=num-1;
         done=1;
      }
      else if (CS_IsKeyDown(KEY_DOWN))
      {
         sel++;
         if (sel>=num) sel=0;
         done=1;
      }
      else if (CS_IsKeyDown(KEY_A)) return sel;
      else if (CS_IsKeyDown(KEY_B)) return 20;//退出
   }
}
void win_plate(char *tit,char *mes,u16 bg)
{
   title(tit);
   Q_box(0,16,239,159,bg);
   r_box(0,0,239,159,28160,0);
   r_line(0,16,239,16,28160,1);
   r_line(0,144,239,144,28160,1);
   Q_box(1,145,238,158,32459);
   cwrite(2,147,RGB(3,7,15),mes);
}

⌨️ 快捷键说明

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