Z-Pocket Game Pro(ZPG Pro)
libffb
libffb.c
#include <stdio.h> #include <stdlib.h> #include <sys/types.h> #include <sys/stat.h> #include <fcntl.h> #include <unistd.h> #include <stdint.h> #include <sys/ioctl.h> #include <sys/types.h> #include <sys/mman.h> #include <string.h> #include <linux/fb.h> #include <SDL.h> #include <SDL_image.h> #include <SDL_ttf.h> #include "libffb.h" static uint32_t sdl_w=0; static uint32_t sdl_h=0; static uint32_t sdl_bpp=0; static SDL_Joystick *joy=NULL; static SDL_Window *window=NULL; static SDL_Surface *screen=NULL; static SDL_Texture *texture=NULL; static SDL_Renderer *renderer=NULL; int MYSDL_Init(uint32_t v) { int r=0; r = SDL_Init(v | SDL_INIT_JOYSTICK); joy = SDL_JoystickOpen(0); printf("%s, r=%d, joy=%p\n", __func__, r, joy); return r; } int MYSDL_WasInit(uint32_t v) { return SDL_WasInit(v); } int MYSDL_InitSubSystem(uint32_t v) { int r=0; r = SDL_InitSubSystem(v); printf("%s, r=%d\n", __func__, r); return r; } void MYSDL_QuitSubSystem(uint32_t v) { SDL_QuitSubSystem(v); } SDL_Surface* MYSDL_SetVideoMode(uint32_t w, uint32_t h, uint32_t bpp, uint32_t flags) { sdl_w = w; sdl_h = h; sdl_bpp = bpp; window = SDL_CreateWindow("libffb", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, w, h, SDL_WINDOW_SHOWN); renderer = SDL_CreateRenderer(window, -1, SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTVSYNC); screen = SDL_CreateRGBSurface(0, w, h, bpp, 0, 0, 0, 0); texture = SDL_CreateTexture(renderer, SDL_PIXELFORMAT_RGB565, SDL_TEXTUREACCESS_STREAMING, w, h); printf("%s, w=%d, h=%d, bpp=%d\n", __func__, w, h, bpp); return screen; } void MYSDL_Flip(SDL_Surface *s) { SDL_UpdateTexture(texture, NULL, s->pixels, s->pitch); SDL_RenderClear(renderer); SDL_RenderCopy(renderer, texture, NULL, NULL); SDL_RenderPresent(renderer); } void MYSDL_Quit(void) { SDL_FreeSurface(screen); SDL_DestroyTexture(texture); SDL_DestroyRenderer(renderer); SDL_DestroyWindow(window); if(joy){ SDL_JoystickClose(joy); } SDL_Quit(); } int MYSDL_PollEvent(uint32_t *type, uint32_t *btn) { int r=0; SDL_Event e={0}; r = SDL_PollEvent(&e); *type = e.type & 0xff; *btn = e.jbutton.button; return r; }
libffb.h
#ifndef __FFB_H__ #define __FFB_H__ #ifdef ZPG #define MYSDL_KEYDOWN 3 #define MYSDL_KEYUP 4 #define MYSDLK_LALT 0 #define MYSDLK_LCTRL 1 #define MYSDLK_SPACE 2 #define MYSDLK_LSHIFT 3 #define MYSDLK_TAB 4 #define MYSDLK_BACKSPACE 5 #define MYSDLK_PAGEUP 6 #define MYSDLK_PAGEDOWN 7 #define MYSDLK_UP 8 #define MYSDLK_DOWN 9 #define MYSDLK_LEFT 10 #define MYSDLK_RIGHT 11 #define MYSDLK_HOME 12 #define MYSDLK_END 13 #define MYSDLK_ESCAPE 14 #define MYSDLK_RETURN 15 #define MYSDLK_VOLUP 16 #define MYSDLK_VOLDOWN 17 int MYSDL_Init(uint32_t); int MYSDL_WasInit(uint32_t); int MYSDL_InitSubSystem(uint32_t); void MYSDL_QuitSubSystem(uint32_t); SDL_Surface* MYSDL_SetVideoMode(uint32_t, uint32_t, uint32_t, uint32_t); void MYSDL_Quit(void); void MYSDL_Flip(SDL_Surface*); int MYSDL_PollEvent(uint32_t*, uint32_t*); #else #define MYSDL_KEYDOWN SDL_KEYDOWN #define MYSDL_KEYUP SDL_KEYUP #define MYSDLK_LALT SDLK_LALT #define MYSDLK_LCTRL SDLK_LCTRL #define MYSDLK_SPACE SDLK_SPACE #define MYSDLK_LSHIFT SDLK_LSHIFT #define MYSDLK_TAB SDLK_TAB #define MYSDLK_BACKSPACE SDLK_BACKSPACE #define MYSDLK_PAGEUP SDLK_PAGEUP #define MYSDLK_PAGEDOWN SDLK_PAGEDOWN #define MYSDLK_UP SDLK_UP #define MYSDLK_DOWN SDLK_DOWN #define MYSDLK_LEFT SDLK_LEFT #define MYSDLK_RIGHT SDLK_RIGHT #define MYSDLK_HOME SDLK_HOME #define MYSDLK_END SDLK_END #define MYSDLK_ESCAPE SDLK_ESCAPE #define MYSDLK_RETURN SDLK_RETURN #define MYSDLK_VOLUP SDLK_VOLUP #define MYSDLK_VOLDOWN SDLK_VOLDOWN #define MYSDL_Init SDL_Init #define MYSDL_InitSubSystem SDL_InitSubSystem #define MYSDL_SetVideoMode SDL_SetVideoMode #define MYSDL_Quit SDL_Quit #define MYSDL_Flip SDL_Flip #define MYSDL_PollEvent SDL_PollEvent #endif #endif
編譯
$ gcc libffb.c -DZPG -fPIC -shared -o libffbcc.so -ggdb -lSDL2 -I/usr/include/SDL2 $ g++ libffb.c -DZPG -fPIC -shared -o libffbcxx.so -ggdb -lSDL2 -I/usr/include/SDL2 -fpermissive