示例#1
0
EFI_STATUS
EFIAPI
efi_main (EFI_HANDLE ImageHandle, EFI_SYSTEM_TABLE *SystemTable)
{
  EFI_INPUT_KEY efi_input_key;

  int a = 10, b = 20;

  InitializeLib(ImageHandle, SystemTable);
  //Print(L"Hello, world!\n");
  terra_main(L"Hello, Terra from C!\n");
  Print(L"%d + %d = %d\n", a, b, terra_add(a,b));

  Print(L"%s\n", SystemTable->FirmwareVendor);

  EFI_STATUS status;
  EFI_GRAPHICS_OUTPUT_PROTOCOL *gop;

  status = LibLocateProtocol(&GraphicsOutputProtocol, (void **)&gop);

  if(EFI_ERROR(status))
    return status;

  status = uefi_call_wrapper(SystemTable->BootServices->LocateProtocol, 3, &GraphicsOutputProtocol, NULL, &gop);

  Print(L"Framebuffer base is at %lx\n", gop->Mode->FrameBufferBase);
  
  print_modes(gop);

  Print(L"\n\n\nHit any key\n");
  WaitForSingleEvent(SystemTable->ConIn->WaitForKey, 0);
  status = uefi_call_wrapper(SystemTable->ConIn->ReadKeyStroke, 2, SystemTable->ConIn, &efi_input_key);
 
  paint_screen(gop, (UINT32)0x00FF0000);
  uefi_call_wrapper(BS->Stall, 1, 2 * 1000 * 1000);
 
  paint_screen(gop, (UINT32)0x0000FF00);
  uefi_call_wrapper(BS->Stall, 1, 2 * 1000 * 1000);
 
  paint_screen(gop, (UINT32)0x000000FF0);

  // FROM: https://github.com/vathpela/gnu-efi/blob/master/apps/t7.c

  Print(L"\n\n\nHit any key to exit this image\n");

  WaitForSingleEvent(SystemTable->ConIn->WaitForKey, 0);
  
  uefi_call_wrapper(SystemTable->ConOut->OutputString, 2, SystemTable->ConOut, L"\n\n");
  
  status = uefi_call_wrapper(SystemTable->ConIn->ReadKeyStroke, 2, SystemTable->ConIn, &efi_input_key);
  
  Print(L"ScanCode: %xh  UnicodeChar: %xh\n", efi_input_key.ScanCode, efi_input_key.UnicodeChar);

  return EFI_SUCCESS;
}
示例#2
0
static int pev_command(GrEvent * ev)
{
    int i;
    char nprog[81];

    if (ev->type == GREV_COMMAND) {
	if (ev->p1 == ID_EXIT) {
	    par_event_queue(GREV_END, 0, 0, 0);
	    return 1;
	}
        if (ev->p1 == ID_PAGE1) {
            bgact = &bgp1;
            paint_screen();
	    return 1;
	}
        if (ev->p1 == ID_PAGE2) {
            bgact = &bgp2;
            paint_screen();
	    return 1;
	}
	for (i = 0; i < NDEMOS; i++) {
	    if (ev->p1 == ptable[i].cid) {
		gfaz_fin();
#if defined(__MSDOS__) || defined(__WIN32__)
		if (ev->p1 == ID_MODETEST)
		    strcpy(nprog, "..\\bin\\");
		else
		    strcpy(nprog, ".\\");
#else
		if (ev->p1 == ID_MODETEST)
		    strcpy(nprog, "../bin/");
		else
		    strcpy(nprog, "./");
#endif
#if defined(__XWIN__)
		strcat(nprog, "x");
#endif
		strcat(nprog, ptable[i].prog);
		system(nprog);
		ini_graphics();
                GrSetWindowTitle(wintitle);
		paint_screen();
		return 1;
	    }
	}
    }
    return 0;
}
示例#3
0
int main(int argc, char **argv)
{
    GrEvent ev;
    long oldtime = 0;

    if (argc >= 4) {
	gwidth = atoi(argv[1]);
	gheight = atoi(argv[2]);
	gbpp = atoi(argv[3]);
    }

    ini_graphics();
    GrSetWindowTitle(wintitle);
    ini_objects();
    paint_screen();

    while (1) {
	GrEventRead(&ev);
	if (ev.type == GREV_MOUSE) {
	    ev.p2 -= worg;
	    ev.p3 -= horg;
	}
	if (ev.type == GREV_END)
	    break;
	if ((ev.type == GREV_KEY) && (ev.p1 == GrKey_Escape))
	    break;
	if ((ev.type == GREV_KEY) && (ev.p1 == 's')) {
	    GrSaveContextToPpm(NULL, "demomgrx.ppm", "DemoMGRX");
	    continue;
	}
        if (pev_button_group(&ev, bgact))
	    continue;
	if (pev_command(&ev))
	    continue;
	if (pev_select(&ev))
	    continue;
	if (ev.type == GREV_MOUSE) {
	    if (ev.p1 == GRMOUSE_LB_PRESSED)
		paint_foot("over a button, please");
	    else if (ev.p1 == GRMOUSE_LB_RELEASED)
		paint_foot("Hold down left mouse buttom to see a comment");
	}
	if (ev.type == GREV_NULL) {
	    if (ev.time > (oldtime + 5)) {
		paint_animation();
		oldtime = ev.time;
	    }
	}
    }

    gfaz_fin();
    return 0;
}
示例#4
0
文件: Game.c 项目: GURKE/Memory
int Mouse_Motion(int *mod, int *card1, int *card2, SDL_Event event, int amplayers)
{
    // Check for the button
    int Types[] = { 2 };
    int actbutton = dist2object(&objects, event.button.x, event.button.y, Types, 1);
    if (actbutton > -1)
    {
        if (actbutton != ClickedButton)
        {
            objects[actbutton].button.Clicked = 1;
            ClickedButton = actbutton;
        }
    }
    else if (ClickedButton > -1) // Reset clicked button, after mouse left it
    {
        objects[ClickedButton].button.Clicked = 0;
        ClickedButton = -1;
    }
    paint_screen(_screen, &objects);
}
示例#5
0
文件: Game.c 项目: GURKE/Memory
int start_game(int amplayers, struct Card (*stack)[], int AmCards, int SizeX, int SizeY, struct Picture *BG, int Loading_Game)
{
    // SizeX && SizeY are the amount of Cards in x and y direction on the gamefield
    Card_Background = *BG;

    SDL_Event event;  /* event handling structure */
    int *mod = (int *)malloc(sizeof(int)); // 0 = first card, 1 = second card, 2 = turn cards back or remove them
    *mod = 0;
    int *card1;
    card1 = (int *)malloc(sizeof(int));
    *card1 = -1;
    int *card2;
    card2 = (int*)malloc(sizeof(int));
    *card2 = -1;

    if (amplayers > 8)
        return TOO_MANY_PLAYERS;

    int result = init_game(amplayers, stack, AmCards, SizeX, SizeY);
    if (result)
        return result;

    paint_screen(_screen, &objects);

    while (SDL_WaitEvent(&event))
    {
        if (event.type == SDL_QUIT)
            break;
        if (event.type == SDL_MOUSEBUTTONDOWN && event.button.button == SDL_BUTTON_LEFT)
        {
            int result = Mouse_Clicked(mod, card1, card2, &stack, AmCards, event, amplayers, SizeX, SizeY);
            if (result == -1)
                break;

        }
        else if (event.type == SDL_MOUSEMOTION)
        {
            Mouse_Motion(mod, card1, card2, event, amplayers);
        }
    }
}
示例#6
0
文件: Game.c 项目: GURKE/Memory
int Mouse_Clicked(int *mod, int *card1, int *card2, struct Card *cards[], int amCards, SDL_Event event, int amplayers, int GameSizeX, int GameSizeY)
{
    int Types[] = { 1, 2 };
    int actcard = dist2object(&objects, event.button.x, event.button.y, Types, 2);

    if (objects[actcard].type == 2) // Button
    {
        switch (objects[actcard].button.Type) // Beenden
        {
        case 0:
            return -1;
        case 1:
            Save_Game(amplayers, amCards, cards, GameSizeX, GameSizeY);
            break;
        case 2:
            Load_Game();
            break;
        default:
            break;
        }
    }
    else
    {
        switch (*mod)
        {
        case 0:
        case 1: // tap card
            if (actcard > -1 && objects[actcard].enabled && !objects[actcard].card.visible)
            {
                if (*mod == 0)
                    *card1 = actcard;
                else
                    *card2 = actcard;

                objects[actcard].card.visible = 1;
                (*mod)++;
            }
            break;

        case 2: // Remove them or move them back
            if (objects[*card1].card.type == objects[*card2].card.type)
            {
                objects[*card1].enabled = 0;
                objects[*card2].enabled = 0;

                pairs[AktPlayer]++;

                char *c = (char *)malloc(sizeof(char));
                sprintf(c, "%d", pairs[AktPlayer]);
                objects[textfield[AktPlayer][1]].picture = Create_Picture_By_Text(objects[textfield[AktPlayer][1]].picture, concat(c, " pairs found"), 0);

                NuOfRePairs--;
                *c = (char *)malloc(sizeof(char));
                sprintf(c, "%d", NuOfRePairs);
                objects[PosOfReCards].picture = Create_Picture_By_Text(objects[PosOfReCards].picture, concat("Amount of remaining pairs: ", c), 0);

                if (NuOfRePairs == 0) // Game ends
                {
                    GameEnd(amplayers);
                }
            }
            else
            {
                objects[*card1].card.visible = 0;
                objects[*card2].card.visible = 0;

                char *c = (char *)malloc(sizeof(char));
                sprintf(c, "%d", AktPlayer + 1);
                objects[textfield[AktPlayer][0]].picture = Create_Picture_By_Text(objects[textfield[AktPlayer][0]].picture, concat("Player ", c), 0);

                AktPlayer++;
                if (AktPlayer == amplayers) AktPlayer = 0;

                sprintf(c, "%d", AktPlayer + 1);
                objects[textfield[AktPlayer][0]].picture = Create_Picture_By_Text(objects[textfield[AktPlayer][0]].picture, concat("Player ", c), 1);
            }
            *mod = 0;
            break;
        default:
            break;
        }
        paint_screen(_screen, &objects);
    }
}