rayzor

annotate src/dosemu/dosemu.c @ 17:79609d482762

the renderer renders, also fixed an unnoticed matrix conversion problem between scenegraph and min3d
author John Tsiombikas <nuclear@member.fsf.org>
date Mon, 14 Apr 2014 07:34:45 +0300
parents d94a69933a71
children
rev   line source
nuclear@5 1 /* This file implements all calls made to dos-specific code using SDL */
nuclear@5 2 #include <stdlib.h>
nuclear@5 3 #include <assert.h>
nuclear@5 4 #include <SDL/SDL.h>
nuclear@5 5 #ifdef DOSEMU_CAPTURE
nuclear@5 6 #include <imago2.h>
nuclear@5 7 #endif
nuclear@5 8 #include "gfx.h"
nuclear@5 9 #include "mouse.h"
nuclear@5 10 #include "keyb.h"
nuclear@5 11 #include "timer.h"
nuclear@5 12
nuclear@9 13 static void cleanup(void);
nuclear@5 14 static void proc_events(void);
nuclear@12 15 static int translate_sdlkey(int sym);
nuclear@12 16 static void update_modkeys(void);
nuclear@5 17 static void capture_frame(unsigned char *frame);
nuclear@5 18
nuclear@9 19 static void init_sdl(void)
nuclear@5 20 {
nuclear@5 21 const SDL_version *ver;
nuclear@5 22
nuclear@5 23 if(!SDL_WasInit(SDL_INIT_EVERYTHING)) {
nuclear@5 24 SDL_Init(SDL_INIT_VIDEO | SDL_INIT_TIMER);
nuclear@5 25
nuclear@5 26 if((ver = SDL_Linked_Version())) {
nuclear@5 27 printf("SDL %d.%d.%d initialized\n", ver->major, ver->minor, ver->patch);
nuclear@5 28 }
nuclear@9 29 atexit(cleanup);
nuclear@5 30 }
nuclear@5 31 }
nuclear@5 32
nuclear@9 33 static void cleanup(void)
nuclear@9 34 {
nuclear@9 35 SDL_Quit();
nuclear@9 36 }
nuclear@9 37
nuclear@5 38 /* ----- graphics (gfx.c (vbe) implementation) ----- */
nuclear@5 39 static SDL_Surface *fbsurf;
nuclear@5 40 static int scale = 1;
nuclear@5 41 static int frames_to_capture;
nuclear@5 42
nuclear@5 43 static struct {
nuclear@5 44 unsigned char r, g, b;
nuclear@5 45 } palette[256];
nuclear@5 46
nuclear@5 47
nuclear@5 48 void *set_video_mode(int xsz, int ysz, int bpp)
nuclear@5 49 {
nuclear@5 50 unsigned int sdl_flags = bpp <= 8 ? SDL_HWPALETTE : 0;
nuclear@5 51 char *env;
nuclear@5 52
nuclear@5 53 if(getenv("DOSEMU_DOUBLESIZE")) {
nuclear@5 54 scale = 2;
nuclear@5 55 }
nuclear@5 56
nuclear@5 57 if((env = getenv("DOSEMU_SCALE"))) {
nuclear@5 58 int n = atoi(env);
nuclear@5 59 if(n > 0) {
nuclear@5 60 scale = n;
nuclear@5 61 }
nuclear@5 62 }
nuclear@5 63 xsz *= scale;
nuclear@5 64 ysz *= scale;
nuclear@5 65
nuclear@5 66 if(getenv("DOSEMU_FULLSCREEN")) {
nuclear@5 67 sdl_flags |= SDL_FULLSCREEN;
nuclear@5 68 }
nuclear@5 69
nuclear@5 70 init_sdl();
nuclear@5 71
nuclear@5 72 if(!(fbsurf = SDL_SetVideoMode(xsz, ysz, bpp, sdl_flags))) {
nuclear@5 73 fprintf(stderr, "failed to set video mode\n");
nuclear@5 74 abort();
nuclear@5 75 }
nuclear@5 76 SDL_WM_SetCaption("Rayzor", 0);
nuclear@5 77 /*SDL_ShowCursor(0);*/
nuclear@5 78
nuclear@5 79 return fbsurf->pixels;
nuclear@5 80 }
nuclear@5 81
nuclear@5 82 int set_text_mode(void)
nuclear@5 83 {
nuclear@5 84 SDL_ShowCursor(1);
nuclear@5 85 SDL_EnableKeyRepeat(0, 0);
nuclear@5 86 return 0;
nuclear@5 87 }
nuclear@5 88
nuclear@5 89 int get_color_depth(void)
nuclear@5 90 {
nuclear@5 91 return fbsurf->format->BitsPerPixel;
nuclear@5 92 }
nuclear@5 93
nuclear@5 94 static int count_bits(unsigned int x)
nuclear@5 95 {
nuclear@5 96 int i, count = 0;
nuclear@5 97 for(i=0; i<32; i++) {
nuclear@5 98 if(x & 1) {
nuclear@5 99 count++;
nuclear@5 100 }
nuclear@5 101 x >>= 1;
nuclear@5 102 }
nuclear@5 103 return count;
nuclear@5 104 }
nuclear@5 105
nuclear@5 106 int get_color_bits(int *rbits, int *gbits, int *bbits)
nuclear@5 107 {
nuclear@5 108 *rbits = count_bits(fbsurf->format->Rmask);
nuclear@5 109 *gbits = count_bits(fbsurf->format->Gmask);
nuclear@5 110 *bbits = count_bits(fbsurf->format->Bmask);
nuclear@5 111 return *rbits + *gbits + *bbits;
nuclear@5 112 }
nuclear@5 113
nuclear@5 114 int get_color_shift(int *rshift, int *gshift, int *bshift)
nuclear@5 115 {
nuclear@5 116 *rshift = fbsurf->format->Rshift;
nuclear@5 117 *gshift = fbsurf->format->Gshift;
nuclear@5 118 *bshift = fbsurf->format->Bshift;
nuclear@5 119 return 0;
nuclear@5 120 }
nuclear@5 121
nuclear@5 122 int get_color_mask(unsigned int *rmask, unsigned int *gmask, unsigned int *bmask)
nuclear@5 123 {
nuclear@5 124 *rmask = fbsurf->format->Rmask;
nuclear@5 125 *gmask = fbsurf->format->Gmask;
nuclear@5 126 *bmask = fbsurf->format->Bmask;
nuclear@5 127 return 0;
nuclear@5 128 }
nuclear@5 129
nuclear@5 130
nuclear@5 131 void set_palette(int idx, int r, int g, int b)
nuclear@5 132 {
nuclear@5 133 SDL_Color col;
nuclear@5 134 col.r = r;
nuclear@5 135 col.g = g;
nuclear@5 136 col.b = b;
nuclear@5 137
nuclear@5 138 if(SDL_SetPalette(fbsurf, SDL_LOGPAL | SDL_PHYSPAL, &col, idx, 1) != 1) {
nuclear@5 139 fprintf(stderr, "set_palette failed to set the required color\n");
nuclear@5 140 }
nuclear@5 141
nuclear@5 142 palette[idx].r = r;
nuclear@5 143 palette[idx].g = g;
nuclear@5 144 palette[idx].b = b;
nuclear@5 145 }
nuclear@5 146
nuclear@5 147 static int copy_frame_called;
nuclear@5 148
nuclear@5 149 void copy_frame(void *pixels)
nuclear@5 150 {
nuclear@5 151 unsigned char *frame = (unsigned char*)pixels;
nuclear@5 152 copy_frame_called = 1;
nuclear@5 153
nuclear@5 154 if(SDL_MUSTLOCK(fbsurf)) {
nuclear@5 155 SDL_LockSurface(fbsurf);
nuclear@5 156 }
nuclear@5 157
nuclear@5 158 if(pixels) {
nuclear@5 159 if(scale > 1) {
nuclear@5 160 int i, j, xsz, ysz;
nuclear@5 161 unsigned char *dest = fbsurf->pixels;
nuclear@5 162
nuclear@5 163 xsz = fbsurf->w * scale;
nuclear@5 164 ysz = fbsurf->h * scale;
nuclear@5 165
nuclear@5 166 for(i=0; i<ysz; i++) {
nuclear@5 167 for(j=0; j<xsz; j++) {
nuclear@5 168 *dest++ = frame[(i / scale) * fbsurf->w + (j / scale)];
nuclear@5 169 }
nuclear@5 170 }
nuclear@5 171 } else {
nuclear@5 172 int num_pixels = fbsurf->w * fbsurf->h;
nuclear@5 173 memcpy(fbsurf->pixels, frame, num_pixels * fbsurf->format->BytesPerPixel);
nuclear@5 174 }
nuclear@5 175 }
nuclear@5 176
nuclear@5 177 if(SDL_MUSTLOCK(fbsurf)) {
nuclear@5 178 SDL_UnlockSurface(fbsurf);
nuclear@5 179 }
nuclear@5 180
nuclear@5 181 SDL_Flip(fbsurf);
nuclear@5 182
nuclear@5 183 if(frames_to_capture > 0) {
nuclear@5 184 capture_frame(pixels);
nuclear@5 185 --frames_to_capture;
nuclear@5 186 }
nuclear@5 187
nuclear@5 188 /* also print fps every second ... */
nuclear@9 189 /*{
nuclear@5 190 static long prev_fps, num_frames;
nuclear@5 191 long msec, dt;
nuclear@5 192
nuclear@5 193 msec = get_msec();
nuclear@5 194 dt = msec - prev_fps;
nuclear@5 195 if(dt >= 1000) {
nuclear@5 196 float fps = (float)num_frames / ((float)dt / 1000.0f);
nuclear@5 197 printf("framerate: %.1f \r", fps);
nuclear@5 198 fflush(stdout);
nuclear@5 199 num_frames = 0;
nuclear@5 200 prev_fps = msec;
nuclear@5 201 } else {
nuclear@5 202 num_frames++;
nuclear@5 203 }
nuclear@9 204 }*/
nuclear@5 205 }
nuclear@5 206
nuclear@5 207 #define spin_delay(ms) \
nuclear@5 208 do { \
nuclear@5 209 unsigned int end = SDL_GetTicks() + ms; \
nuclear@5 210 while((prev_msec = SDL_GetTicks()) < end); \
nuclear@5 211 } while(0)
nuclear@5 212
nuclear@5 213 #define FRAME_INTERVAL (1000/70)
nuclear@5 214
nuclear@5 215 void wait_vsync(void)
nuclear@5 216 {
nuclear@9 217 /*static int prev_msec;
nuclear@9 218 int msec, dt, tleft;*/
nuclear@5 219
nuclear@5 220 if(!copy_frame_called) {
nuclear@5 221 copy_frame(0);
nuclear@5 222 copy_frame_called = 0;
nuclear@5 223 }
nuclear@5 224
nuclear@9 225 /*
nuclear@5 226 msec = SDL_GetTicks();
nuclear@5 227
nuclear@5 228 dt = msec - prev_msec;
nuclear@5 229
nuclear@5 230 tleft = FRAME_INTERVAL - dt;
nuclear@5 231 if(tleft > 0) {
nuclear@5 232 int coarse = tleft & 0xfffffff8;
nuclear@5 233 tleft = tleft & 7;
nuclear@5 234
nuclear@5 235 if(coarse) {
nuclear@5 236 SDL_Delay(coarse);
nuclear@5 237 }
nuclear@5 238 if(tleft) {
nuclear@5 239 spin_delay(tleft);
nuclear@5 240 } else {
nuclear@5 241 prev_msec = SDL_GetTicks();
nuclear@5 242 }
nuclear@5 243 } else {
nuclear@5 244 prev_msec = msec;
nuclear@5 245 }
nuclear@9 246 */
nuclear@5 247 }
nuclear@5 248
nuclear@5 249 static int cap_count = 0;
nuclear@5 250 void begin_capture(int frames)
nuclear@5 251 {
nuclear@5 252 frames_to_capture = frames;
nuclear@5 253 }
nuclear@5 254
nuclear@5 255 void end_capture(void)
nuclear@5 256 {
nuclear@5 257 cap_count = 0;
nuclear@5 258 frames_to_capture = 0;
nuclear@5 259 }
nuclear@5 260
nuclear@5 261 #define NUMPIX (fbsurf->w * fbsurf->h)
nuclear@5 262 static void capture_frame(unsigned char *frame)
nuclear@5 263 {
nuclear@5 264 #ifdef DOSEMU_CAPTURE
nuclear@5 265 static unsigned char rgbpix[NUMPIX * 4];
nuclear@5 266 char fname[32];
nuclear@5 267 int i;
nuclear@5 268 unsigned char *src, *dest;
nuclear@5 269
nuclear@5 270 sprintf(fname, "frame%04d.png", cap_count++);
nuclear@5 271
nuclear@5 272 src = frame;
nuclear@5 273 dest = rgbpix;
nuclear@5 274
nuclear@5 275 for(i=0; i<NUMPIX; i++) {
nuclear@5 276 unsigned char c = *src++;
nuclear@5 277 *dest++ = palette[c].r;
nuclear@5 278 *dest++ = palette[c].g;
nuclear@5 279 *dest++ = palette[c].b;
nuclear@5 280 *dest++ = 255;
nuclear@5 281 }
nuclear@5 282
nuclear@5 283 img_save_pixels(fname, rgbpix, fbsurf->w, fbsurf->h, IMG_FMT_RGBA32);
nuclear@5 284 #endif
nuclear@5 285 }
nuclear@5 286
nuclear@5 287
nuclear@5 288 /* ----- event handling (conio.h) ----- */
nuclear@5 289 static SDL_Event *keybev;
nuclear@5 290 static int mousex, mousey, bnmask;
nuclear@5 291
nuclear@5 292 static int keystate[256];
nuclear@5 293 static int num_pressed;
nuclear@5 294
nuclear@5 295 int kbhit(void)
nuclear@5 296 {
nuclear@5 297 if(!keybev) {
nuclear@5 298 proc_events();
nuclear@5 299 }
nuclear@5 300 return keybev != 0;
nuclear@5 301 }
nuclear@5 302
nuclear@5 303 int getch(void)
nuclear@5 304 {
nuclear@5 305 int res;
nuclear@5 306
nuclear@5 307 while(!keybev) {
nuclear@5 308 SDL_Event ev;
nuclear@5 309 SDL_WaitEvent(&ev);
nuclear@5 310 SDL_PushEvent(&ev);
nuclear@5 311 proc_events();
nuclear@5 312 }
nuclear@5 313 res = keybev->key.keysym.sym;
nuclear@5 314 keybev = 0;
nuclear@5 315 return res;
nuclear@5 316 }
nuclear@5 317
nuclear@5 318 /* ----- improved event handling (keyb.h) ---- */
nuclear@12 319 static char sdlkey_tbl[SDLK_LAST];
nuclear@5 320
nuclear@5 321 int kb_init(int bufsz)
nuclear@5 322 {
nuclear@12 323 int i;
nuclear@5 324 init_sdl();
nuclear@5 325
nuclear@12 326 /* construct the SDL key translation table */
nuclear@12 327 for(i=0; i<256; i++) {
nuclear@12 328 sdlkey_tbl[i] = i; /* start from an identity mapping for the first 256 */
nuclear@12 329 }
nuclear@12 330 /* then change the special keys */
nuclear@12 331 sdlkey_tbl[SDLK_LALT] = KB_LALT;
nuclear@12 332 sdlkey_tbl[SDLK_RALT] = KB_RALT;
nuclear@12 333 sdlkey_tbl[SDLK_LCTRL] = KB_LCTRL;
nuclear@12 334 sdlkey_tbl[SDLK_RCTRL] = KB_RCTRL;
nuclear@12 335 sdlkey_tbl[SDLK_LSHIFT] = KB_LSHIFT;
nuclear@12 336 for(i=0; i<12; i++) {
nuclear@12 337 sdlkey_tbl[SDLK_F1 + i] = KB_F1 + i;
nuclear@12 338 }
nuclear@12 339 sdlkey_tbl[SDLK_CAPSLOCK] = KB_CAPSLK;
nuclear@12 340 sdlkey_tbl[SDLK_NUMLOCK] = KB_NUMLK;
nuclear@12 341 sdlkey_tbl[SDLK_SCROLLOCK] = KB_SCRLK;
nuclear@12 342 sdlkey_tbl[SDLK_SYSREQ] = KB_SYSRQ;
nuclear@12 343 sdlkey_tbl[SDLK_ESCAPE] = KB_ESC;
nuclear@12 344 sdlkey_tbl[SDLK_INSERT] = KB_INSERT;
nuclear@12 345 sdlkey_tbl[SDLK_DELETE] = KB_DEL;
nuclear@12 346 sdlkey_tbl[SDLK_HOME] = KB_HOME;
nuclear@12 347 sdlkey_tbl[SDLK_END] = KB_END;
nuclear@12 348 sdlkey_tbl[SDLK_PAGEUP] = KB_PGUP;
nuclear@12 349 sdlkey_tbl[SDLK_PAGEDOWN] = KB_PGDN;
nuclear@12 350 sdlkey_tbl[SDLK_LEFT] = KB_LEFT;
nuclear@12 351 sdlkey_tbl[SDLK_RIGHT] = KB_RIGHT;
nuclear@12 352 sdlkey_tbl[SDLK_UP] = KB_UP;
nuclear@12 353 sdlkey_tbl[SDLK_DOWN] = KB_DOWN;
nuclear@12 354 sdlkey_tbl[SDLK_KP_PERIOD] = KB_NUM_DOT;
nuclear@12 355 sdlkey_tbl[SDLK_KP_ENTER] = KB_NUM_ENTER;
nuclear@12 356 sdlkey_tbl[SDLK_KP_PLUS] = KB_NUM_PLUS;
nuclear@12 357 sdlkey_tbl[SDLK_KP_MINUS] = KB_NUM_MINUS;
nuclear@12 358 sdlkey_tbl[SDLK_KP_MULTIPLY] = KB_NUM_MUL;
nuclear@12 359 sdlkey_tbl[SDLK_KP_DIVIDE] = KB_NUM_DIV;
nuclear@12 360 /* TODO missing numeric keypad numbers */
nuclear@12 361 sdlkey_tbl[SDLK_BACKSPACE] = KB_BACKSP;
nuclear@12 362
nuclear@12 363
nuclear@5 364 return 0;
nuclear@5 365 }
nuclear@5 366
nuclear@5 367 void kb_shutdown(void)
nuclear@5 368 {
nuclear@5 369 }
nuclear@5 370
nuclear@5 371 int kb_getkey(void)
nuclear@5 372 {
nuclear@5 373 int res = -1;
nuclear@5 374
nuclear@5 375 proc_events();
nuclear@5 376 if(keybev) {
nuclear@12 377 res = translate_sdlkey(keybev->key.keysym.sym);
nuclear@5 378 keybev = 0;
nuclear@5 379 }
nuclear@5 380 return res;
nuclear@5 381 }
nuclear@5 382
nuclear@5 383 int kb_isdown(int key)
nuclear@5 384 {
nuclear@12 385 switch(key) {
nuclear@12 386 case KB_ANY:
nuclear@5 387 return num_pressed;
nuclear@12 388
nuclear@12 389 case KB_ALT:
nuclear@12 390 return keystate[KB_LALT] + keystate[KB_RALT];
nuclear@12 391
nuclear@12 392 case KB_CTRL:
nuclear@12 393 return keystate[KB_LCTRL] + keystate[KB_RCTRL];
nuclear@5 394 }
nuclear@5 395 return keystate[key];
nuclear@5 396 }
nuclear@5 397
nuclear@5 398 /* mouse handling (mouse.c implementation) */
nuclear@5 399 static unsigned long last_mouse_hide_time;
nuclear@5 400
nuclear@5 401 int have_mouse(void)
nuclear@5 402 {
nuclear@5 403 return 1;
nuclear@5 404 }
nuclear@5 405
nuclear@8 406 void set_mouse_limits(int xmin, int ymin, int xmax, int ymax)
nuclear@8 407 {
nuclear@8 408 }
nuclear@8 409
nuclear@5 410 void set_mouse(int x, int y)
nuclear@5 411 {
nuclear@5 412 SDL_ShowCursor(0);
nuclear@5 413 last_mouse_hide_time = get_msec();
nuclear@5 414
nuclear@5 415 SDL_WarpMouse(x * scale, y * scale);
nuclear@5 416 mousex = x;
nuclear@5 417 mousey = y;
nuclear@5 418 }
nuclear@5 419
nuclear@5 420 int read_mouse(int *xp, int *yp)
nuclear@5 421 {
nuclear@5 422 if(xp) *xp = mousex;
nuclear@5 423 if(yp) *yp = mousey;
nuclear@5 424 return bnmask;
nuclear@5 425 }
nuclear@5 426
nuclear@5 427 static void proc_events(void)
nuclear@5 428 {
nuclear@5 429 static SDL_Event ev;
nuclear@5 430
nuclear@5 431 if(last_mouse_hide_time > 0 && get_msec() - last_mouse_hide_time > 3000) {
nuclear@5 432 last_mouse_hide_time = 0;
nuclear@5 433 SDL_ShowCursor(1);
nuclear@5 434 }
nuclear@5 435
nuclear@5 436 while(SDL_PollEvent(&ev)) {
nuclear@5 437 switch(ev.type) {
nuclear@5 438 case SDL_KEYDOWN:
nuclear@5 439 {
nuclear@12 440 int key = translate_sdlkey(ev.key.keysym.sym);
nuclear@5 441
nuclear@5 442 if(!keybev) {
nuclear@5 443 keybev = &ev;
nuclear@5 444 }
nuclear@5 445
nuclear@5 446 if(!keystate[key]) {
nuclear@5 447 keystate[key] = 1;
nuclear@5 448 num_pressed++;
nuclear@5 449 }
nuclear@12 450
nuclear@12 451 update_modkeys();
nuclear@5 452 }
nuclear@5 453 break;
nuclear@5 454
nuclear@5 455 case SDL_KEYUP:
nuclear@5 456 {
nuclear@12 457 int key = translate_sdlkey(ev.key.keysym.sym);
nuclear@5 458
nuclear@5 459 if(keystate[key]) {
nuclear@5 460 keystate[key] = 0;
nuclear@5 461 if(--num_pressed < 0) {
nuclear@5 462 num_pressed = 0;
nuclear@5 463 }
nuclear@5 464 }
nuclear@12 465
nuclear@12 466 update_modkeys();
nuclear@5 467 }
nuclear@5 468 break;
nuclear@5 469
nuclear@5 470 case SDL_MOUSEMOTION:
nuclear@5 471 mousex = ev.motion.x / scale;
nuclear@5 472 mousey = ev.motion.y / scale;
nuclear@5 473 break;
nuclear@5 474
nuclear@5 475 case SDL_MOUSEBUTTONDOWN:
nuclear@5 476 case SDL_MOUSEBUTTONUP:
nuclear@5 477 {
nuclear@5 478 int mask = 0;
nuclear@5 479 switch(ev.button.button) {
nuclear@5 480 case SDL_BUTTON_LEFT:
nuclear@5 481 mask = MOUSE_LEFT;
nuclear@5 482 break;
nuclear@5 483 case SDL_BUTTON_MIDDLE:
nuclear@5 484 mask = MOUSE_MIDDLE;
nuclear@5 485 break;
nuclear@5 486 case SDL_BUTTON_RIGHT:
nuclear@5 487 mask = MOUSE_RIGHT;
nuclear@5 488 default:
nuclear@5 489 break;
nuclear@5 490 }
nuclear@5 491 if(!mask) {
nuclear@5 492 break;
nuclear@5 493 }
nuclear@5 494
nuclear@5 495 if(ev.button.state == SDL_PRESSED) {
nuclear@5 496 bnmask |= mask;
nuclear@5 497 } else {
nuclear@5 498 bnmask &= ~mask;
nuclear@5 499 }
nuclear@5 500 }
nuclear@5 501 break;
nuclear@5 502
nuclear@5 503 default:
nuclear@5 504 break;
nuclear@5 505 }
nuclear@5 506 }
nuclear@5 507 }
nuclear@5 508
nuclear@12 509 static int translate_sdlkey(int sym)
nuclear@12 510 {
nuclear@14 511 return sdlkey_tbl[sym];
nuclear@12 512 }
nuclear@12 513
nuclear@12 514 static void update_modkeys(void)
nuclear@12 515 {
nuclear@12 516 unsigned int mod = SDL_GetModState();
nuclear@12 517
nuclear@12 518 keystate[KB_LALT] = mod & KMOD_LALT;
nuclear@12 519 keystate[KB_RALT] = mod & KMOD_RALT;
nuclear@12 520 keystate[KB_LCTRL] = mod & KMOD_LCTRL;
nuclear@12 521 keystate[KB_RCTRL] = mod & KMOD_RCTRL;
nuclear@12 522 keystate[KB_LSHIFT] = mod & KMOD_LSHIFT;
nuclear@12 523 keystate[KB_RSHIFT] = mod & KMOD_RSHIFT;
nuclear@12 524 }
nuclear@12 525
nuclear@5 526 /* ---- timer.c implementation ---- */
nuclear@5 527 static Uint32 start_time;
nuclear@5 528
nuclear@5 529 void init_timer(int res_hz)
nuclear@5 530 {
nuclear@5 531 init_sdl();
nuclear@5 532 reset_timer();
nuclear@5 533 }
nuclear@5 534
nuclear@5 535 void reset_timer(void)
nuclear@5 536 {
nuclear@5 537 start_time = SDL_GetTicks();
nuclear@5 538 printf("resetting timer: %u, %lu\n", start_time, get_msec());
nuclear@5 539 }
nuclear@5 540
nuclear@5 541 unsigned long get_msec(void)
nuclear@5 542 {
nuclear@5 543 Uint32 ticks = SDL_GetTicks();
nuclear@5 544 return (unsigned long)(ticks - start_time);
nuclear@5 545 }