void gr_palette_read (ubyte *pal) { ggi_color colors[256]; int i, j; ggiGetPalette (screenvis, 0, 256, colors); for (i = 0, j = 0; i < 256; i++) { pal[j++] = colors[i].r / 0x3ff; pal[j++] = colors[i].g / 0x3ff; pal[j++] = colors[i].b / 0x3ff; } }
SDL_Surface *GGI_SetVideoMode(_THIS, SDL_Surface *current, int width, int height, int bpp, Uint32 flags) { ggi_mode mode = { 1, { GGI_AUTO, GGI_AUTO }, { GGI_AUTO, GGI_AUTO }, { 0, 0 }, GT_AUTO, { GGI_AUTO, GGI_AUTO } }; const ggi_directbuffer *db; ggi_color pal[256]; int err; fprintf(stderr, "GGI_SetVideoMode()\n"); mode.visible.x = mode.virt.x = width; mode.visible.y = mode.virt.y = height; /* Translate requested SDL bit depth into a GGI mode */ switch (bpp) { case 1: mode.graphtype = GT_1BIT; break; case 2: mode.graphtype = GT_2BIT; break; case 4: mode.graphtype = GT_4BIT; break; case 8: mode.graphtype = GT_8BIT; break; case 15: mode.graphtype = GT_15BIT; break; case 16: mode.graphtype = GT_16BIT; break; case 24: mode.graphtype = GT_24BIT; break; case 32: mode.graphtype = GT_32BIT; break; default: SDL_SetError("Unknown SDL bit depth, using GT_AUTO....\n"); mode.graphtype = GT_AUTO; } /* Validate mode, autodetecting any GGI_AUTO or GT_AUTO fields */ ggiCheckMode(VIS, &mode); /* At this point we should have a valid mode - try to set it */ err = ggiSetMode(VIS, &mode); /* If we couldn't set _any_ modes, something is very wrong */ if (err) { SDL_SetError("Can't set a mode!\n"); ggiClose(VIS); ggiExit(); GGI_VideoQuit(NULL); } /* Set a palette for palletized modes */ if (GT_SCHEME(mode.graphtype) == GT_PALETTE) { ggiSetColorfulPalette(VIS); ggiGetPalette(VIS, 0, 1 << bpp, pal); } db = ggiDBGetBuffer(VIS, 0); /* Set up the new mode framebuffer */ current->flags = (SDL_FULLSCREEN | SDL_HWSURFACE); current->w = mode.virt.x; current->h = mode.virt.y; current->pitch = db->buffer.plb.stride; current->pixels = db->read; /* Set the blit function */ this->UpdateRects = GGI_DirectUpdate; /* We're done */ return(current); }
int GGI_VideoInit(_THIS, SDL_PixelFormat *vformat) { ggi_mode mode = { 1, { GGI_AUTO, GGI_AUTO }, { GGI_AUTO, GGI_AUTO }, { 0, 0 }, GT_AUTO, { GGI_AUTO, GGI_AUTO } }; struct private_hwdata *priv; ggi_color pal[256], map[256]; const ggi_directbuffer *db; int err, num_bufs; ggi_pixel white, black; priv = SDL_malloc(sizeof(struct private_hwdata)); if (priv == NULL) { SDL_SetError("Unhandled GGI mode type!\n"); GGI_VideoQuit(NULL); } if (ggiInit() != 0) { SDL_SetError("Unable to initialize GGI!\n"); GGI_VideoQuit(NULL); } VIS = ggiOpen(NULL); if (VIS == NULL) { SDL_SetError("Unable to open default GGI visual!\n"); ggiExit(); GGI_VideoQuit(NULL); } ggiSetFlags(VIS, GGIFLAG_ASYNC); /* Validate mode, autodetecting any GGI_AUTO or GT_AUTO fields */ ggiCheckMode(VIS, &mode); /* At this point we should have a valid mode - try to set it */ err = ggiSetMode(VIS, &mode); /* If we couldn't set _any_ modes, something is very wrong */ if (err) { SDL_SetError("Can't set a mode!\n"); ggiClose(VIS); ggiExit(); GGI_VideoQuit(NULL); } /* Determine the current screen size */ this->info.current_w = mode.virt.x; this->info.current_h = mode.virt.y; /* Set a palette for palletized modes */ if (GT_SCHEME(mode.graphtype) == GT_PALETTE) { ggiSetColorfulPalette(VIS); ggiGetPalette(VIS, 0, 1 << vformat->BitsPerPixel, pal); } /* Now we try to get the DirectBuffer info, which determines whether * SDL can access hardware surfaces directly. */ num_bufs = ggiDBGetNumBuffers(VIS); if (num_bufs > 0) { db = ggiDBGetBuffer(VIS, 0); /* Only handle one DB for now */ vformat->BitsPerPixel = db->buffer.plb.pixelformat->depth; vformat->Rmask = db->buffer.plb.pixelformat->red_mask; vformat->Gmask = db->buffer.plb.pixelformat->green_mask; vformat->Bmask = db->buffer.plb.pixelformat->blue_mask; /* Fill in our hardware acceleration capabilities */ this->info.wm_available = 0; this->info.hw_available = 1; this->info.video_mem = db->buffer.plb.stride * mode.virt.y; } video_mode.x = 0; video_mode.y = 0; video_mode.w = mode.virt.x; video_mode.h = mode.virt.y; SDL_modelist[((vformat->BitsPerPixel + 7) / 8) - 1] = &video_mode; /* We're done! */ return(0); }