Re: sdl2 and ffi
- Posted by Icy_Viking Dec 05, 2022
- 1152 views
OK, I've changed the code in SDL_Version.e following Greg's advice. It works for me. I've changed from C_UINT to C_UINT8, and rewrote the SDL_GetVersion() function as Greg has shown. I tested it and it works for me. I've also pushed these changes on github. I had forgotten to update the values for the current SDL version in the SDL_Version.e code, but that has been fixed too.
include std/ffi.e include std/machine.e --I got "free" not found if I don't include machine.e include sdl.e public constant SDL_VERSION = define_c_type({ C_UINT8, --major C_UINT8, --minor C_UINT8 --patch }) public constant SDL_MAJOR_VERSION = 2, SDL_MINOR_VERSION = 26, SDL_PATCHLEVEL = 1 export constant xSDL_GetVersion = define_c_proc(sdl,"+SDL_GetVersion",{C_POINTER}) public function SDL_GetVersion() atom ver = allocate_struct(SDL_VERSION) c_proc(xSDL_GetVersion,{ver}) sequence res = peek_struct(ver,SDL_VERSION) free(ver) return res end function export constant xSDL_GetRevision = define_c_func(sdl,"+SDL_GetRevision",{},C_STRING) public function SDL_GetRevision() return c_func(xSDL_GetRevision,{}) end function export constant xSDL_GetRevisionNumber = define_c_func(sdl,"+SDL_GetRevisionNumber",{},C_INT) public function SDL_GetRevisionNumber() return c_func(xSDL_GetRevisionNumber,{}) end function
--Show CPU Info Demo include sdl.e puts(1,"1 Means True, 0 Means False\n") printf(1,"CPU Count: %d\n",{SDL_GetCPUCount() }) printf(1,"Cache Line Size: %d\n",{SDL_GetCPUCacheLineSize() }) printf(1,"Has RDTSC: %d\n",{SDL_HasRDTSC() }) printf(1,"Has AtltiVec: %d\n",{SDL_HasAltiVec() }) printf(1,"Has MMX:%d\n",{SDL_HasMMX() }) printf(1,"Has 3D Now:%d\n",{SDL_Has3DNow() }) printf(1,"Has SSE:%d\n",{SDL_HasSSE() }) printf(1,"Has SSE2:%d\n",{SDL_HasSSE2() }) printf(1,"Has SSE3:%d\n",{SDL_HasSSE3() }) printf(1,"Has SSE41:%d\n",{SDL_HasSSE41() }) printf(1,"Has SSE42:%d\n",{SDL_HasSSE42() }) printf(1,"Has AVX:%d\n",{SDL_HasAVX() }) printf(1,"Has AVX2:%d\n",{SDL_HasAVX2() }) printf(1,"Has AVX512F:%d\n",{SDL_HasAVX512F() }) printf(1,"Has ARMSIMD:%d\n",{SDL_HasARMSIMD() }) printf(1,"Has NEON:%d\n",{SDL_HasNEON() }) printf(1,"Has LSX:%d\n",{SDL_HasLSX() }) printf(1,"Has LASX:%d\n",{SDL_HasLASX() }) printf(1,"RAM: %d\n",{SDL_GetSystemRAM() }) printf(1,"OS: %s\n",{SDL_GetPlatform() }) sequence ver = SDL_GetVersion() printf(1,"SDL Version:\n") printf(1,"Major: %d\n",ver[1]) printf(1,"Minor: %d\n",ver[2]) printf(1,"Patch: %d\n",ver[3])