nuclear@3: #include nuclear@3: #include nuclear@3: #include "gfx.h" nuclear@3: #include "image.h" nuclear@3: nuclear@3: static SDL_Surface *fbsurf; nuclear@3: static int scr_width, scr_height; nuclear@3: static int fb_width, fb_height; nuclear@3: static int num_bitplanes; nuclear@3: nuclear@3: nuclear@3: int gfx_init(int nbpl, unsigned int flags) nuclear@3: { nuclear@3: num_bitplanes = nbpl; nuclear@3: scr_width = fb_width = (flags & GFX_HIRES) ? 640 : 320; nuclear@3: scr_height = fb_height = (flags & GFX_ILACE) ? 512 : 256; nuclear@3: nuclear@3: if(SDL_Init(SDL_INIT_VIDEO) == -1) { nuclear@3: fprintf(stderr, "failed to initialize SDL\n"); nuclear@3: return -1; nuclear@3: } nuclear@3: if(!(fbsurf = SDL_SetVideoMode(scr_width, scr_height, 32, SDL_SWSURFACE))) { nuclear@3: fprintf(stderr, "failed to set video mode %dx%d\n", scr_width, scr_height); nuclear@3: SDL_Quit(); nuclear@3: return -1; nuclear@3: } nuclear@4: SDL_WM_SetCaption("imgv SDL version", 0); nuclear@3: nuclear@3: return 0; nuclear@3: } nuclear@3: nuclear@3: void gfx_shutdown(void) nuclear@3: { nuclear@3: SDL_Quit(); nuclear@3: } nuclear@3: nuclear@3: nuclear@3: int gfx_screen_width(void) nuclear@3: { nuclear@3: return scr_width; nuclear@3: } nuclear@3: nuclear@3: int gfx_screen_height(void) nuclear@3: { nuclear@3: return scr_height; nuclear@3: } nuclear@3: nuclear@3: nuclear@3: void *gfx_set_framebuffer(void *fb, int width, int height) nuclear@3: { nuclear@3: return 0; nuclear@3: } nuclear@3: nuclear@3: void *gfx_get_framebuffer(void) nuclear@3: { nuclear@3: return 0; nuclear@3: } nuclear@3: nuclear@3: nuclear@3: int get_framebuffer_width(void) nuclear@3: { nuclear@3: return fb_width; nuclear@3: } nuclear@3: nuclear@3: int get_framebuffer_height(void) nuclear@3: { nuclear@3: return fb_height; nuclear@3: } nuclear@3: nuclear@3: nuclear@3: void gfx_begin_copperlist(void) nuclear@3: { nuclear@3: } nuclear@3: nuclear@3: nuclear@3: int gfx_next_event(union gfx_event *ev, int block) nuclear@3: { nuclear@3: SDL_Event sdlev; nuclear@3: nuclear@3: if(block) { nuclear@3: SDL_WaitEvent(&sdlev); nuclear@3: } else { nuclear@3: if(!SDL_PollEvent(&sdlev)) { nuclear@3: return 0; nuclear@3: } nuclear@3: } nuclear@3: nuclear@3: switch(sdlev.type) { nuclear@3: case SDL_QUIT: nuclear@3: ev->type = GFX_EV_QUIT; nuclear@3: return 1; nuclear@3: nuclear@3: case SDL_KEYDOWN: nuclear@3: case SDL_KEYUP: nuclear@3: ev->type = GFX_EV_KEY; nuclear@3: ev->key.key = sdlev.key.keysym.sym; nuclear@3: ev->key.pressed = sdlev.key.state == SDL_PRESSED; nuclear@3: return 1; nuclear@3: nuclear@3: default: nuclear@3: break; nuclear@3: } nuclear@3: return 0; nuclear@3: } nuclear@3: nuclear@3: nuclear@3: void gfx_wait_vpos(int x) nuclear@3: { nuclear@3: } nuclear@3: nuclear@3: void gfx_wait_vblank(void) nuclear@3: { nuclear@3: } nuclear@3: nuclear@3: #define ARED(x) ((((x) & 0xf00) >> 4) | (((x) & 0xf00) >> 8)) nuclear@3: #define AGREEN(x) (((x) & 0xf0) | (((x) & 0xf0) >> 4)) nuclear@3: #define ABLUE(x) ((((x) & 0xf) << 4) | ((x) & 0xf)) nuclear@3: nuclear@4: #define RSHIFT (fbsurf->format->Rshift) nuclear@4: #define GSHIFT (fbsurf->format->Gshift) nuclear@4: #define BSHIFT (fbsurf->format->Bshift) nuclear@4: #define RMASK (fbsurf->format->Rmask) nuclear@4: #define GMASK (fbsurf->format->Gmask) nuclear@4: #define BMASK (fbsurf->format->Bmask) nuclear@4: nuclear@3: void gfx_show_image(struct ham_image *img) nuclear@3: { nuclear@3: int i, j, k; nuclear@3: uint32_t palette[16]; nuclear@3: uint32_t *dest; nuclear@3: unsigned char *src; nuclear@3: nuclear@3: for(i=0; i<16; i++) { nuclear@3: uint16_t pcol = img->palette[i]; nuclear@3: int red = ARED(pcol); nuclear@3: int green = AGREEN(pcol); nuclear@3: int blue = ABLUE(pcol); nuclear@4: palette[i] = (red << RSHIFT) | (green << GSHIFT) | (blue << BSHIFT); nuclear@4: printf("palette[%d]: %d %d %d\n", i, red, green, blue); nuclear@3: } nuclear@3: nuclear@3: if(SDL_MUSTLOCK(fbsurf)) { nuclear@3: SDL_LockSurface(fbsurf); nuclear@3: } nuclear@3: nuclear@3: dest = fbsurf->pixels; nuclear@3: src = img->pixels; nuclear@3: for(i=0; iheight; i++) { nuclear@3: for(j=0; jwidth; j++) { nuclear@4: uint32_t color; nuclear@3: unsigned char idx = 0; nuclear@4: unsigned char ham; nuclear@4: int bit = 7 - (j & 7); nuclear@4: nuclear@3: for(k=0; knbitplanes; k++) { nuclear@5: idx |= (((*(src + k * img->width / 8) >> bit) & 1) << k); nuclear@3: } nuclear@4: nuclear@4: printf("%d ", idx); nuclear@4: color = palette[idx]; nuclear@5: ham = (idx >> 4) & 3; nuclear@4: color = (i & j) ? dest[-1] : 0; nuclear@4: nuclear@4: switch(ham) { nuclear@4: case 0: nuclear@4: color = palette[idx]; nuclear@4: break; nuclear@4: case 1: nuclear@4: color = (color & ~BMASK) | (((uint32_t)idx & 0xf) << BSHIFT); nuclear@4: break; nuclear@4: case 2: nuclear@4: color = (color & ~RMASK) | (((uint32_t)idx & 0xf) << RSHIFT); nuclear@4: break; nuclear@4: case 3: nuclear@4: color = (color & ~GMASK) | (((uint32_t)idx & 0xf) << GSHIFT); nuclear@4: } nuclear@4: nuclear@4: *dest++ = color; nuclear@4: if(!bit) { nuclear@3: ++src; nuclear@3: } nuclear@3: } nuclear@3: src += img->width / 8 * (img->nbitplanes - 1); nuclear@3: } nuclear@4: putchar('\n'); nuclear@3: nuclear@3: if(SDL_MUSTLOCK(fbsurf)) { nuclear@3: SDL_UnlockSurface(fbsurf); nuclear@3: } nuclear@3: nuclear@3: SDL_Flip(fbsurf); nuclear@3: }