找回密码
 加入计匠网
搜索
热搜: BIOS ACPI CPU Windows
查看: 20388|回复: 6

EFI snake game

[复制链接]
发表于 2008-1-17 17:46:00 | 显示全部楼层 |阅读模式
For EFI NT platform
For EFI 32 platform
For EFI 64 platform

Type snakeNt -s to play.  
Bert

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?加入计匠网

×
发表于 2008-2-20 15:00:33 | 显示全部楼层
试试,呵呵
谢谢啦
回复

使用道具 举报

发表于 2008-2-27 20:24:51 | 显示全部楼层
刚才玩了玩,不错!!
回复

使用道具 举报

发表于 2009-11-2 17:40:33 | 显示全部楼层

回響

// How to implement a EFI (Extensible Firmware Interface) snake game?

#include "efi.h"
#include "efilib.h"
#include "ConsoleControl\ConsoleControl.h"
#include "GraphicsOutput\GraphicsOutput.h"

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

EFI_GUID gEfiConsoleControlProtocolGuid = EFI_CONSOLE_CONTROL_PROTOCOL_GUID;
EFI_GUID gEfiUgaDrawProtocolGuid = EFI_UGA_DRAW_PROTOCOL_GUID;
EFI_GUID gEfiGraphicsOutputProtocolGuid = EFI_GRAPHICS_OUTPUT_PROTOCOL_GUID;
EFI_CONSOLE_CONTROL_PROTOCOL *ConsoleControl;
EFI_UGA_DRAW_PROTOCOL *UgaDraw;
EFI_GRAPHICS_OUTPUT_PROTOCOL *GraphicsOutput;

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

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

VOID  
SwitchGraphicsMode(UINTN Mode);

EFI_STATUS
Init(
IN EFI_HANDLE ImageHandle,
IN EFI_SYSTEM_TABLE *SystemTable
);
               
EFI_STATUS
InitializeSnakeApplication(
IN EFI_HANDLE ImageHandle,
IN EFI_SYSTEM_TABLE *SystemTable
) //EFI+<<<
{
        EFI_STATUS Status;
    EFI_GRAPHICS_OUTPUT_BLT_PIXEL Color;       
       
    UINT32 SizeOfX;
    UINT32 SizeOfY;
    UINT32 ColorDepth;
    UINT32 RefreshRate;
    UINTN BlockHeight;
    UINTN BlockWidth;
    UINTN PosX;
    UINTN PosY;
        UINT8 GLYPH_HEIGHT=0;       

        int i=0, ROW=10;
       
        Init(ImageHandle,SystemTable);        

    _Clrscr();
       
        SwitchGraphicsMode(1);

    Print(L"Test UGA and GOP\n");
       
    UgaDraw = NULL;
    Status = gBS->HandleProtocol (
             gST->ConsoleOutHandle,
             &gEfiGraphicsOutputProtocolGuid,
             (VOID **) &GraphicsOutput);
                                         
    if (EFI_ERROR (Status)) {
      GraphicsOutput = NULL;
      Status = gBS->HandleProtocol (
               gST->ConsoleOutHandle,
               &gEfiUgaDrawProtocolGuid,
               &UgaDraw);
    if (EFI_ERROR (Status)) {
      Print(L"error");
      return EFI_UNSUPPORTED;
    }
    }       
       
    if (GraphicsOutput != NULL) {
      SizeOfX = GraphicsOutput->Mode->Info->HorizontalResolution;
      SizeOfY = GraphicsOutput->Mode->Info->VerticalResolution;
      Print(L"SizeOfX:%d\n", SizeOfX);
      Print(L"SizeOfY:%d\n", SizeOfY);
    } else {
      Status = UgaDraw->GetMode (
               UgaDraw,
               &SizeOfX,
               &SizeOfY,
               &ColorDepth,
               &RefreshRate );
      if (EFI_ERROR (Status)) {
        Print(L"error");
        return EFI_UNSUPPORTED;
      }
    }

    BlockWidth = SizeOfX / 100;
    BlockHeight = SizeOfY / 50;
    PosX = 0;
    PosY = SizeOfY * 48 / 50;
    gBS->SetMem (&Color, sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL), 0xff);
// I want a RED rectangle
    Color.Green=0;
    Color.Blue=0;
    Color.Red=255;

    if (GraphicsOutput != NULL) {
      Status = GraphicsOutput->Blt (
               GraphicsOutput,
               &Color,
               EfiBltVideoFill,
               0,
               0,
               0,
               PosY - GLYPH_HEIGHT - 1,
               SizeOfX,
               SizeOfY - (PosY - GLYPH_HEIGHT - 1),
               SizeOfX * sizeof (EFI_UGA_PIXEL));
    } else {
      Status = UgaDraw->Blt (
               UgaDraw,
               (EFI_UGA_PIXEL *) &Color,
               EfiUgaVideoFill,
               0,
               0,
               0,
               PosY - GLYPH_HEIGHT - 1,
               SizeOfX,
               SizeOfY - (PosY - GLYPH_HEIGHT - 1),
               SizeOfX * sizeof (EFI_UGA_PIXEL)
               );
    }
//show image until get a key
  
    getchar();
        SwitchGraphicsMode(0);
       
//shows the frame(a game window)

    Print(L"Just for Testing...\n");
    getchar();
  
    ST->ConOut->ClearScreen(ST->ConOut);               
    _LIBC_Cleanup();                        
    return EFI_SUCCESS;  
}

VOID  
SwitchGraphicsMode(UINTN Mode)
{
if(Mode){
ConsoleControl->SetMode(ConsoleControl,EfiConsoleControlScreenGraphics);
}
else
ConsoleControl->SetMode(ConsoleControl,EfiConsoleControlScreenText);
}

EFI_STATUS
Init(
IN EFI_HANDLE ImageHandle,
IN EFI_SYSTEM_TABLE *SystemTable
)
{
        EFI_STATUS Status;
        EFI_HANDLE *HandleBuffer;
        EFI_HANDLE *UgaHandle;
        EFI_GUID   gConsoleControlProtocolGuid = EFI_CONSOLE_CONTROL_PROTOCOL_GUID;
        UINTN      NoHandle;
        UINTN      UgaDrawProtocolCount;

    gST = SystemTable;
    gBS = gST->BootServices;
    gRT = gST->RuntimeServices;               
       
    InitializeLib(ImageHandle,SystemTable);
        InitializeLibC(ImageHandle, SystemTable);       

        Status=gBS->LocateProtocol(&gConsoleControlProtocolGuid,NULL,(VOID **)&ConsoleControl);
        if(EFI_ERROR(Status))
        {
          Print(L"error");
        }
       
        Status=gBS->LocateHandleBuffer(ByProtocol,&UgaDrawProtocol,NULL,&NoHandle,&HandleBuffer);
        if(EFI_ERROR(Status))
        {
      Print(L"error");
        }
       
        gBS->FreePool(HandleBuffer);
        Status=gBS->HandleProtocol(&UgaHandle,&gEfiUgaDrawProtocolGuid,(VOID **)&UgaDraw);
        if(EFI_ERROR(Status))
        {
          Print(L"error");
        }
       
        Status = LibLocateHandle (
             ByProtocol,
             &gEfiUgaDrawProtocolGuid,
             NULL,
             &UgaDrawProtocolCount,
             &UgaHandle
             );
        if(EFI_ERROR(Status))
        {
          Print(L"error");
        }       

        return EFI_SUCCESS;
}
回复

使用道具 举报

发表于 2009-11-3 15:41:39 | 显示全部楼层

A snake game today modefied for PUDN 2009/11/03

#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;

static BOOLEAN egHasGraphics = TRUE;
static UINTN egScreenWidth  = 800;
static UINTN egScreenHeight = 600;

#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;
    EFI_GRAPHICS_OUTPUT_BLT_PIXEL ForeGround;
    EFI_GRAPHICS_OUTPUT_BLT_PIXEL BackGround;       
       
        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;
}

EFI_STATUS
Init(
IN EFI_HANDLE ImageHandle,
IN EFI_SYSTEM_TABLE *SystemTable
)
{
    EFI_HANDLE  Handle;
    UINTN       Size;
        EFI_STATUS Status;
        EFI_HANDLE *HandleBuffer;
        EFI_HANDLE *UgaHandle;
        EFI_GUID   gConsoleControlProtocolGuid = EFI_CONSOLE_CONTROL_PROTOCOL_GUID;
        UINTN      NoHandle;
        UINTN      UgaDrawProtocolCount;

    gST = SystemTable;
    gBS = gST->BootServices;
    gRT = gST->RuntimeServices;               
       
    InitializeLib(ImageHandle,SystemTable);
        InitializeLibC(ImageHandle, SystemTable);

    _Clrscr();       

        Status = gBS->LocateProtocol(&gConsoleControlProtocolGuid,NULL,(VOID **)&ConsoleControl);
        if(EFI_ERROR(Status))
        {
          Print(L"Error on gBS->LocateProtocol of ConsoleControl\n");
        }
       
    Status = gBS->HandleProtocol(gST->ConsoleOutHandle,&gEfiGraphicsOutputProtocolGuid,(VOID **) &GraphicsOutput);                                         
    if (EFI_ERROR (Status)) {
          Print(L"Error on gBS->HandleProtocol of GraphicsOutput\n");
      GraphicsOutput = NULL;
      Status = gBS->HandleProtocol(gST->ConsoleOutHandle,&gEfiUgaDrawProtocolGuid,&UgaDraw);
      if (EFI_ERROR (Status)) {
        Print(L"Error on gBS->HandleProtocol of UgaDraw\n");
        return EFI_UNSUPPORTED;
      }
    }               
       
        Status = gBS->LocateHandleBuffer(ByProtocol,&UgaDrawProtocol,NULL,&NoHandle,&HandleBuffer);
        if(EFI_ERROR(Status))
        {
      Print(L"Error on gBS->LocateHandleBuffer of UgaDrawProtocol\n");
        }
       
        gBS->FreePool(HandleBuffer);
        Status = gBS->HandleProtocol(&UgaHandle,&gEfiUgaDrawProtocolGuid,(VOID **)&UgaDraw);
        if(EFI_ERROR(Status))
        {
          Print(L"Error on gBS->HandleProtocol of UgaDraw\n");
        }
       
        Status = LibLocateHandle(ByProtocol,&gEfiUgaDrawProtocolGuid,NULL,&UgaDrawProtocolCount,&UgaHandle);
        if(EFI_ERROR(Status))
        {
          Print(L"Error on LibLocateHandle of UgaHandle\n");
        }

    Status = gBS->LocateHandle(ByProtocol,&gEfiHiiProtocolGuid,NULL,&Size,&Handle);
        if(EFI_ERROR(Status))
        {
          Print(L"Error on gBS->LocateHandle of gEfiHiiProtocolGuid Handle\n");
        }

    Status = gBS->HandleProtocol(Handle,&gEfiHiiProtocolGuid,&mHii);       
    if(EFI_ERROR(Status))
        {
          Print(L"Error on gBS->HandleProtocol of gEfiHiiProtocolGuid EfiHiiProtocol mHii\n");
        }       
       
    getchar();
       
        return EFI_SUCCESS;

/*  
    EFI_HANDLE  Handle;
    UINTN       Size;
    EFI_STATUS  Status;     
    UINTN       UgaDrawProtocolCount;
    EFI_HANDLE  *UgaDrawHandles;

    ConsoleControl = NULL;
        InitializeLib(ImageHandle,SystemTable);
        InitializeLibC(ImageHandle,SystemTable);
        Size = sizeof (EFI_HANDLE);
               
    Status = BS->HandleProtocol(ST->ConsoleOutHandle,&gEfiGraphicsOutputProtocolGuid,(VOID **) &GraphicsOutput);                                         
    if (EFI_ERROR (Status)) {
      GraphicsOutput = NULL;
      Status = BS->HandleProtocol(ST->ConsoleOutHandle,&gEfiUgaDrawProtocolGuid,&UgaDraw);
      if (EFI_ERROR (Status)) {
        Print(L"error");
        return EFI_UNSUPPORTED;
      }
    }                       
       
    Status = BS->LocateHandle(ByProtocol,&gEfiHiiProtocolGuid,NULL,&Size,&Handle);
    if (EFI_ERROR (Status)) {
      return Status;
    }

    Status = BS->HandleProtocol(Handle,&gEfiHiiProtocolGuid,&mHii);       
    Status = BS->LocateProtocol(&gEfiConsoleControlProtocolGuid,NULL,(VOID **)&ConsoleControl);
    if(EFI_ERROR(Status))
        {
          Print(L"error");
        }
        Status = LibLocateHandle(ByProtocol,&gEfiUgaDrawProtocolGuid,NULL,&UgaDrawProtocolCount,&UgaDrawHandles);
        if(EFI_ERROR(Status))
        {
          Print(L"error");
        }
    Status = BS->HandleProtocol(UgaDrawHandles[0],&gEfiUgaDrawProtocolGuid,&UgaDraw);
    if(EFI_ERROR(Status))
        {
          Print(L"error");
        }       
    return EFI_SUCCESS;
*/       
}
回复

使用道具 举报

发表于 2012-1-5 19:23:06 | 显示全部楼层
不错哦,学习了,
回复

使用道具 举报

发表于 2012-10-1 17:59:52 | 显示全部楼层
谢谢 收下 懒人包
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 加入计匠网

本版积分规则

Archiver|手机版|小黑屋|计匠网

GMT+8, 2024-5-8 18:54 , Processed in 0.025288 second(s), 17 queries .

Powered by Discuz! X3.5

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表