關於 EFI shell App 使用 GOP 畫貪食蛇的嘗試

kaurohy 2009-11-05 12:09:57
#include "efi.h"
#include "efilib.h"
#include "she.h"

#include <atk_libc.h>
#include <stdio.h>
#include <stdlib.h>

#include "Bmp.h"
#include "Hii.h"
#include "ConsoleControl.h"
#include "GraphicsOutput.h"
#define Out ST->ConOut
#define In ST->ConIn
#define SCAN_CODE_UP 0x01
#define SCAN_CODE_DOWN 0x02
#define SCAN_CODE_RIGHT 0x03
#define SCAN_CODE_LEFT 0x04
#define SCAN_CODE_ESC 0x17
#define N 200

EFI_GUID gEfiConsoleControlProtocolGuid = EFI_CONSOLE_CONTROL_PROTOCOL_GUID;
EFI_GUID gEfiGraphicsOutputProtocolGuid = EFI_GRAPHICS_OUTPUT_PROTOCOL_GUID;
EFI_GUID gEfiHiiProtocolGuid = EFI_HII_PROTOCOL_GUID;
EFI_GUID gEfiUgaDrawProtocolGuid = EFI_UGA_DRAW_PROTOCOL_GUID;

EFI_CONSOLE_CONTROL_PROTOCOL *ConsoleControl;
EFI_GRAPHICS_OUTPUT_PROTOCOL *GraphicsOutput;
EFI_GRAPHICS_OUTPUT_BLT_PIXEL Color;
EFI_HII_PROTOCOL *mHii;
EFI_UGA_DRAW_PROTOCOL *UgaDraw;

EFI_SYSTEM_TABLE *gST;
EFI_BOOT_SERVICES *gBS;
EFI_RUNTIME_SERVICES *gRT;

#define _Clrscr(); ST->ConOut->ClearScreen(ST->ConOut);

static EFI_UGA_PIXEL EfiColors[16] = {
0x00, 0x00, 0x00, 0x00, // BLACK
0x98, 0x00, 0x00, 0x00, // BLUE
0x00, 0x98, 0x00, 0x00, // GREEN
0x98, 0x98, 0x00, 0x00, // CYAN
0x00, 0x00, 0x98, 0x00, // RED
0x98, 0x00, 0x98, 0x00, // MAGENTA
0x00, 0x98, 0x98, 0x00, // BROWN
0x98, 0x98, 0x98, 0x00, // LIGHTGRAY
0x30, 0x30, 0x30, 0x00, // DARKGRAY - BRIGHT BLACK
0xff, 0x00, 0x00, 0x00, // LIGHTBLUE - ?
0x00, 0xff, 0x00, 0x00, // LIGHTGREEN - ?
0xff, 0xff, 0x00, 0x00, // LIGHTCYAN
0x00, 0x00, 0xff, 0x00, // LIGHTRED
0xff, 0x00, 0xff, 0x00, // LIGHTMAGENTA
0x00, 0xff, 0xff, 0x00, // LIGHTBROWN
0xff, 0xff, 0xff, 0x00, // WHITE
};

UINTN Node;
EFI_INPUT_KEY Key;
UINTN Score=0;
UINT8 Barrier=1;
UINTN Gamespeed=100000;

struct Food
{
INTN x;
INTN y;
UINTN yes;
}food;

struct Snake
{
INTN x[N];
INTN y[N];
UINTN node;
UINTN direction;
UINTN life;
}snake;

VOID
DrawData(
IN UINT8 *ImageBuffer,
IN UINTN Col,
IN UINTN Row
);

VOID
DrawWord(
IN CHAR16 *Value,
IN UINT16 X,
IN UINT16 Y,
IN UINT16 Background,
IN UINT16 WordCount
);

UINT8
Rand(
IN EFI_HANDLE ImageHandle,
IN EFI_SYSTEM_TABLE *SystemTable
);

EFI_STATUS
Init(
IN EFI_HANDLE ImageHandle,
IN EFI_SYSTEM_TABLE *SystemTable
);

EFI_STATUS
DrawK(
IN EFI_HANDLE ImageHandle,
IN EFI_SYSTEM_TABLE *SystemTable
);

VOID
PrintScore(
IN EFI_HANDLE ImageHandle,
IN EFI_SYSTEM_TABLE *SystemTable)
{
CHAR16 Str1[50];
UINT8 Count1;
ValueToString(Str1,0,Score);
Count1=(UINT8)StrLen(Str1);
DrawWord(ImageHandle,SystemTable,Str1,160,65,3,Count1);
return;
}

VOID
GameOver(VOID);

EFI_STATUS
GamePlay(
IN EFI_HANDLE ImageHandle,
IN EFI_SYSTEM_TABLE *SystemTable
);

Main(
IN EFI_HANDLE ImageHandle,
IN EFI_SYSTEM_TABLE *SystemTable
)
{
EFI_STATUS Status;

UINT8 Count,Countsize;
UINTN i,j,k;
CHAR16 *Str=L"Start Load";
CHAR16 *Str2=L"JJDD";
Count=11;

//--- if(Barrier==1)
//--- {
Init(ImageHandle,SystemTable);
ConsoleControl->SetMode (ConsoleControl, EfiConsoleControlScreenGraphics);

// UgaDraw->Blt(UgaDraw,&EfiColors[0],EfiUgaVideoFill,0,0,0,0,800,600,0);
//
if (GraphicsOutput != NULL) {
Status = GraphicsOutput->Blt(GraphicsOutput,&EfiColors[0],EfiBltVideoFill,0,0,0,0,800,600,0);
}
else {
Status = UgaDraw->Blt(UgaDraw,&EfiColors[0],EfiUgaVideoFill,0,0,0,0,800,600,0);
}

DrawData(sheData,350,250);
getchar();
//- DrawWord(Str,340,520,0,Count);
//- getchar();

k=0;
for(j=0;j<14;j++)
{
for(i=0;i<6;i++)
{
//- UgaDraw->Blt(UgaDraw,&EfiColors[15], EfiUgaVideoFill,0,0,k,565,8,16,0);
// I use Red color
Color.Green=0;
Color.Blue=0;
Color.Red=255;

if (GraphicsOutput != NULL) {
Status = GraphicsOutput->Blt(GraphicsOutput,&EfiColors[6],EfiBltVideoFill,0,0,k,565,8,16,0);
}
else {
Status = UgaDraw->Blt(UgaDraw,&EfiColors[6],EfiUgaVideoFill,0,0,k,565,8,16,0);
}
k=k+9;
BS->Stall(500000);
}
}
getchar();
//--- }
//- DrawK(ImageHandle,SystemTable);
/*
if(Barrier==1)
Str2=L"The First Barrier" ;
else if(Barrier==2)
Str2=L"The Second Barrier" ;
else if(Barrier==3)
Str2=L"The Third Barrier" ;
Countsize=(UINT8)StrLen(Str2);
*/
//- DrawWord(ImageHandle,SystemTable,Str2,300,45,3,Countsize);
//- GamePlay(ImageHandle,SystemTable);
getchar();
ConsoleControl->SetMode(ConsoleControl, EfiConsoleControlScreenText);
return EFI_SUCCESS;
}

...全文
892 4 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
windowsshaking 2011-06-18
  • 打赏
  • 举报
回复
请问楼主这个头文件atk_libc.h在哪,有什么作用?貌似udk和edk2都没有。。
xingzhe2001 2009-11-11
  • 打赏
  • 举报
回复
为什么要在bios里玩贪吃蛇?
yutaooo 2009-11-11
  • 打赏
  • 举报
回复

EFI难道是传说中的,要替代BIOS的那个规范?
kaurohy 2009-11-11
  • 打赏
  • 举报
回复
目前 發現 EFI EDK 1.05 build 出來的 EFI shell emulator 裡 好像只支援 GOP protocol 而不支援
UGA protocol 的緣故 所以做了這個修正 希望有人能來討論

70,022

社区成员

发帖
与我相关
我的任务
社区描述
C语言相关问题讨论
社区管理员
  • C语言
  • 花神庙码农
  • 架构师李肯
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧