sdl

FORK: Simple Directmedia Layer
git clone https://git.neptards.moe/neptards/sdl.git
Log | Files | Refs

SDL_systimer.c (2062B)


      1 /*
      2   Simple DirectMedia Layer
      3   Copyright (C) 1997-2020 Sam Lantinga <slouken@libsdl.org>
      4 
      5   This software is provided 'as-is', without any express or implied
      6   warranty.  In no event will the authors be held liable for any damages
      7   arising from the use of this software.
      8 
      9   Permission is granted to anyone to use this software for any purpose,
     10   including commercial applications, and to alter it and redistribute it
     11   freely, subject to the following restrictions:
     12 
     13   1. The origin of this software must not be misrepresented; you must not
     14      claim that you wrote the original software. If you use this software
     15      in a product, an acknowledgment in the product documentation would be
     16      appreciated but is not required.
     17   2. Altered source versions must be plainly marked as such, and must not be
     18      misrepresented as being the original software.
     19   3. This notice may not be removed or altered from any source distribution.
     20 */
     21 #include "../../SDL_internal.h"
     22 
     23 #ifdef SDL_TIMERS_PSP
     24 
     25 #include "SDL_thread.h"
     26 #include "SDL_timer.h"
     27 #include "SDL_error.h"
     28 #include "../SDL_timer_c.h"
     29 #include <stdlib.h>
     30 #include <time.h>
     31 #include <sys/time.h>
     32 #include <pspthreadman.h>
     33 
     34 static struct timeval start;
     35 static SDL_bool ticks_started = SDL_FALSE;
     36 
     37 void
     38 SDL_TicksInit(void)
     39 {
     40     if (ticks_started) {
     41         return;
     42     }
     43     ticks_started = SDL_TRUE;
     44 
     45     gettimeofday(&start, NULL);
     46 }
     47 
     48 void
     49 SDL_TicksQuit(void)
     50 {
     51     ticks_started = SDL_FALSE;
     52 }
     53 
     54 Uint32 SDL_GetTicks(void)
     55 {
     56     if (!ticks_started) {
     57         SDL_TicksInit();
     58     }
     59 
     60     struct timeval now;
     61     Uint32 ticks;
     62 
     63     gettimeofday(&now, NULL);
     64     ticks=(now.tv_sec-start.tv_sec)*1000+(now.tv_usec-start.tv_usec)/1000;
     65     return(ticks);
     66 }
     67 
     68 Uint64
     69 SDL_GetPerformanceCounter(void)
     70 {
     71     return SDL_GetTicks();
     72 }
     73 
     74 Uint64
     75 SDL_GetPerformanceFrequency(void)
     76 {
     77     return 1000;
     78 }
     79 
     80 void SDL_Delay(Uint32 ms)
     81 {
     82     const Uint32 max_delay = 0xffffffffUL / 1000;
     83     if(ms > max_delay)
     84         ms = max_delay;
     85     sceKernelDelayThreadCB(ms * 1000);
     86 }
     87 
     88 #endif /* SDL_TIMERS_PSP */
     89 
     90 /* vim: ts=4 sw=4
     91  */