static int handle_sball_event(sball_event *ev);
static void recalc_sball_matrix(float *xform);
-static int sdlkey_to_demokey(int sdlkey);
+static int sdlkey_to_demokey(int sdlkey, unsigned int mod);
static int quit;
int main(int argc, char **argv)
{
- int s, i, j;
+ int s;
char *env;
- unsigned short *sptr, *dptr;
if((env = getenv("FBSCALE")) && (s = atoi(env))) {
fbscale = s;
printf("Framebuffer scaling x%d\n", fbscale);
}
- xsz = fb_width * fbscale;
- ysz = fb_height * fbscale;
+ xsz = FB_WIDTH * fbscale;
+ ysz = FB_HEIGHT * fbscale;
+ /* now start_loadscr sets up fb_pixels to the space used by the loading image,
+ * so no need to allocate another framebuffer
+ */
+#if 0
/* allocate 1 extra row as a guard band, until we fucking fix the rasterizer */
- if(!(fb_pixels = malloc(fb_width * (fb_height + 1) * fb_bpp / CHAR_BIT))) {
+ if(!(fb_pixels = malloc(FB_WIDTH * (FB_HEIGHT + 1) * FB_BPP / CHAR_BIT))) {
fprintf(stderr, "failed to allocate virtual framebuffer\n");
return 1;
}
- vmem = fb_pixels;
+#endif
SDL_Init(SDL_INIT_VIDEO | SDL_INIT_TIMER | SDL_INIT_NOPARACHUTE);
- if(!(fbsurf = SDL_SetVideoMode(xsz, ysz, fb_bpp, sdl_flags))) {
- fprintf(stderr, "failed to set video mode %dx%d %dbpp\n", fb_width, fb_height, fb_bpp);
- free(fb_pixels);
+ if(!(fbsurf = SDL_SetVideoMode(xsz, ysz, FB_BPP, sdl_flags))) {
+ fprintf(stderr, "failed to set video mode %dx%d %dbpp\n", FB_WIDTH, FB_HEIGHT, FB_BPP);
+ /*free(fb_pixels);*/
SDL_Quit();
return 1;
}
time_msec = 0;
if(demo_init(argc, argv) == -1) {
- free(fb_pixels);
+ /*free(fb_pixels);*/
SDL_Quit();
return 1;
}
+ vmem = fb_pixels;
if(opt.sball && sball_init() == 0) {
use_sball = 1;
time_msec = get_msec();
demo_draw();
-
- if(SDL_MUSTLOCK(fbsurf)) {
- SDL_LockSurface(fbsurf);
- }
-
- sptr = fb_pixels;
- dptr = (unsigned short*)fbsurf->pixels + (fbsurf->w - xsz) / 2;
- for(i=0; i<fb_height; i++) {
- for(j=0; j<fb_width; j++) {
- int x, y;
- unsigned short pixel = *sptr++;
-
- for(y=0; y<fbscale; y++) {
- for(x=0; x<fbscale; x++) {
- dptr[y * fbsurf->w + x] = pixel;
- }
- }
- dptr += fbscale;
- }
- dptr += (fbsurf->w - fb_width) * fbscale;
- }
-
- if(SDL_MUSTLOCK(fbsurf)) {
- SDL_UnlockSurface(fbsurf);
- }
- SDL_Flip(fbsurf);
}
break_evloop:
void swap_buffers(void *pixels)
{
+ int i, j;
+ unsigned short *sptr, *dptr;
+
demo_post_draw(pixels ? pixels : fb_pixels);
- /* do nothing, all pointers point to the same buffer */
if(opt.vsync) {
wait_vsync();
}
+
+ if(SDL_MUSTLOCK(fbsurf)) {
+ SDL_LockSurface(fbsurf);
+ }
+
+ sptr = fb_pixels;
+ dptr = (unsigned short*)fbsurf->pixels + (fbsurf->w - xsz) / 2;
+ for(i=0; i<FB_HEIGHT; i++) {
+ for(j=0; j<FB_WIDTH; j++) {
+ int x, y;
+ unsigned short pixel = *sptr++;
+
+ for(y=0; y<fbscale; y++) {
+ for(x=0; x<fbscale; x++) {
+ dptr[y * fbsurf->w + x] = pixel;
+ }
+ }
+ dptr += fbscale;
+ }
+ dptr += (fbsurf->w - FB_WIDTH) * fbscale;
+ }
+
+ if(SDL_MUSTLOCK(fbsurf)) {
+ SDL_UnlockSurface(fbsurf);
+ }
+ SDL_Flip(fbsurf);
}
static int bnmask(int sdlbn)
toggle_fullscreen();
break;
}
- key = sdlkey_to_demokey(ev->key.keysym.sym);
+ key = sdlkey_to_demokey(ev->key.keysym.sym, ev->key.keysym.mod);
demo_keyboard(key, ev->key.state == SDL_PRESSED ? 1 : 0);
break;
SDL_Surface *newsurf;
unsigned int newflags = sdl_flags ^ SDL_FULLSCREEN;
- if(!(newsurf = SDL_SetVideoMode(xsz, ysz, fb_bpp, newflags))) {
+ if(!(newsurf = SDL_SetVideoMode(xsz, ysz, FB_BPP, newflags))) {
fprintf(stderr, "failed to go %s\n", newflags & SDL_FULLSCREEN ? "fullscreen" : "windowed");
return;
}
xform[14] = pos.z;
}
-static int sdlkey_to_demokey(int sdlkey)
+#define SSORG '\''
+#define SSEND '`'
+static char symshift[] = {
+ '"', 0, 0, 0, 0, '<', '_', '>', '?',
+ ')', '!', '@', '#', '$', '%', '^', '&', '*', '(',
+ 0, ':', 0, '+', 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ '{', '|', '}', 0, 0, '~'
+};
+
+
+static int sdlkey_to_demokey(int sdlkey, unsigned int mod)
{
- if(sdlkey < 128) return sdlkey;
+ if(sdlkey < 128) {
+ if(mod & (KMOD_SHIFT)) {
+ if(sdlkey >= 'a' && sdlkey <= 'z') {
+ sdlkey = toupper(sdlkey);
+ } else if(sdlkey >= SSORG && sdlkey <= SSEND) {
+ sdlkey = symshift[sdlkey - SSORG];
+ }
+ }
+ return sdlkey;
+ }
if(sdlkey < 256) return 0;
return sdlkey - 128;
}