//--------------------------------------------------------------------------- #include #include "video/colors.h" #include "video/gbuffer.h" //--------------------------------------------------------------------------- static SDL_Surface *screen = NULL; typedef struct { int lastkey; int lastkeysym; int lastkeymod; } keyb; static keyb keys[100]; static int keybufferlen; int timer_tick = 0; static Uint32 timer_handler(Uint32 interval, void *param) { timer_tick ++; return(interval); } int startptc(char *label) { SDL_Color palette[256]; int qi; lastkey = -1; lastkeysym = -1; lastkeymod = -1; keybufferlen = 0; if ( (screen = SDL_SetVideoMode(WINSIZEX,WINSIZEY,8,SDL_SWSURFACE)) == NULL) { return 0; } memset(&palette,0x00,sizeof(palette)); for (qi = 0; qi < sizeof(palette)/sizeof(unsigned int); qi++) { palette[qi].r = (colors[qi] >> 16) & 0xff; palette[qi].g = (colors[qi] >> 8) & 0xff; palette[qi].b = colors[qi] & 0xff; } SDL_SetColors(screen, palette, 0, 256); if ( SDL_LockSurface(screen) < 0 ) { return 0; } SDL_WM_SetCaption(label, label); SDL_AddTimer(1000/20, timer_handler, NULL); return 1; } //--------------------------------------------------------------------------- int getkeys() { int i; if (keybufferlen > 0) { lastkey = keys[0].lastkey; lastkeysym = keys[0].lastkeysym; lastkeymod = keys[0].lastkeymod; for (i=1; i= 128)) keys[keybufferlen].lastkey = 0; keybufferlen++; } break; case SDL_KEYUP: if (keybufferlen < 100) { keys[keybufferlen].lastkey = -1; keys[keybufferlen].lastkeysym = -1; keys[keybufferlen++].lastkeymod = -1; } break; case SDL_QUIT: keys[0].lastkey = -2; keys[0].lastkeysym = -1; keybufferlen = 1; break; default: break; } count ++; } } void updateptc() { SDL_UnlockSurface(screen); SDL_UpdateRect(screen, 0, 0, 0, 0); SDL_LockSurface(screen); events(); } //--------------------------------------------------------------------------- void endptc() { SDL_UnlockSurface(screen); SDL_FreeSurface(screen); } //----------------------------------------------------------------------------- void drawchar(int cx, int cy, unsigned char ch, unsigned char fgcolor, unsigned char bgcolor, unsigned char *charset) { int charsetstart, qi, qj; int mempos; char tempreg; char *pixels = screen->pixels; charsetstart = (ch << 3); cy = cy << 3; cx = cx << 3; for (qi = cy; qi < cy + 8; qi++) { tempreg = charset[charsetstart++]; mempos = (2 + qi) * screen->pitch + cx + 2; if ((tempreg & 0x80) == 0x80) pixels[mempos++] = fgcolor; else pixels[mempos++] = bgcolor; if ((tempreg & 0x40) == 0x40) pixels[mempos++] = fgcolor; else pixels[mempos++] = bgcolor; if ((tempreg & 0x20) == 0x20) pixels[mempos++] = fgcolor; else pixels[mempos++] = bgcolor; if ((tempreg & 0x10) == 0x10) pixels[mempos++] = fgcolor; else pixels[mempos++] = bgcolor; if ((tempreg & 0x08) == 0x08) pixels[mempos++] = fgcolor; else pixels[mempos++] = bgcolor; if ((tempreg & 0x04) == 0x04) pixels[mempos++] = fgcolor; else pixels[mempos++] = bgcolor; if ((tempreg & 0x02) == 0x02) pixels[mempos++] = fgcolor; else pixels[mempos++] = bgcolor; if ((tempreg & 0x01) == 0x01) pixels[mempos++] = fgcolor; else pixels[mempos++] = bgcolor; } } //--------------------------------------------------------------------------- void drawstring(int cx, int cy, unsigned char *str, unsigned char fgcolor, unsigned char bgcolor, void *charset) { int qi; while (*str != 0) { if (*str == '\r') { for (qi = cx; qi