hwabstract.cpp

00001 #include "sdl.h"
00002 
00003 #include "openem.h"
00004 #include "hw/abstract/hwabstract.h"
00005 
00006 #include <string.h>
00007 
00008 void OE_HW_COUNTER::set(OE_HW_LAYER *e, uint32 thresh)
00009 {
00010     oel = e;
00011     ltick = e->getticks();
00012     threshold = thresh;
00013 }
00014 
00015 uint32 OE_HW_COUNTER::done(void)
00016 {
00017     calcval = oel->getticks() - ltick;
00018     if (calcval >= threshold) return 1;
00019     return 0;
00020 }
00021 
00022 
00023 void OE_HW_LAYER::SDL_window(char *c)
00024 {
00025     SDL_WM_SetCaption(c,NULL);
00026 }
00027 
00028 
00029 void OE_HW_LAYER::do_events(void)
00030 {
00031     // Right now we only handle keyboard events
00032     SDL_Event even;
00033     while( SDL_PollEvent( &even ) ){
00034         switch( even.type ){
00035         case SDL_KEYDOWN:
00036             keyd[even.key.keysym.sym] = 1;
00037             keyp[even.key.keysym.sym]++;
00038             break;
00039         case SDL_KEYUP:
00040             keyd[even.key.keysym.sym] = 0;
00041             break;
00042         default:
00043             break;
00044         }
00045     }
00046 }
00047 
00048 uint32 OE_HW_LAYER::getticks(void)
00049 {
00050     return SDL_GetTicks();
00051 }
00052 
00053 void OE_HW_LAYER::init(void)
00054 {
00055     int a = SDL_Init(SDL_INIT_VIDEO | SDL_INIT_TIMER);
00056     OE_ASSERT(a>=0);
00057     atexit(SDL_Quit);
00058     for (int i = 0; i < 256; i++) {
00059         keyd[i] = 0;
00060         keyp[i] = 0;
00061     }
00062 }
00063 
00064 int OE_HW_LAYER::set_res(uint32 w, uint32 h)
00065 {
00066     SDLscreen = SDL_SetVideoMode(w, h, 32, SDL_HWSURFACE);
00067     if ( SDLscreen == NULL ) return -1;
00068     
00069     myh = h;
00070     myw = w;
00071     return 0;
00072 }
00073 
00074 void OE_HW_LAYER::log(char *c)
00075 {
00076 }
00077 
00078 void OE_HW_LAYER::blit(void *src, uint32 w, uint32 h)
00079 {
00080     uint8 *srcptr = (uint8 *)src;
00081     SDL_LockSurface(SDLscreen);
00082     uint8 *destptr = (uint8 *)SDLscreen->pixels;
00083     // Copy line for line
00084     for (uint32 line = 0; line < h; line++) {
00085         memcpy(destptr, srcptr, (w*4));
00086         srcptr+= (w*4);
00087         destptr+= (SDLscreen->w)*4;
00088     }
00089     SDL_UnlockSurface(SDLscreen);
00090     //SDL_UpdateRect(SDLscreen,0,0,w,h);
00091     SDL_Flip(SDLscreen);
00092 }

Generated on Sat Sep 9 03:50:42 2006 for Openem APIs by  doxygen 1.4.7