amiga_imgv

view src/sdl/gfx.c @ 3:663471a80c21

broken + sdl emu
author John Tsiombikas <nuclear@member.fsf.org>
date Thu, 26 Oct 2017 15:49:56 +0300
parents
children 0fd37effde29
line source
1 #include <stdio.h>
2 #include <SDL/SDL.h>
3 #include "gfx.h"
4 #include "image.h"
6 static SDL_Surface *fbsurf;
7 static int scr_width, scr_height;
8 static int fb_width, fb_height;
9 static int num_bitplanes;
12 int gfx_init(int nbpl, unsigned int flags)
13 {
14 num_bitplanes = nbpl;
15 scr_width = fb_width = (flags & GFX_HIRES) ? 640 : 320;
16 scr_height = fb_height = (flags & GFX_ILACE) ? 512 : 256;
18 if(SDL_Init(SDL_INIT_VIDEO) == -1) {
19 fprintf(stderr, "failed to initialize SDL\n");
20 return -1;
21 }
22 if(!(fbsurf = SDL_SetVideoMode(scr_width, scr_height, 32, SDL_SWSURFACE))) {
23 fprintf(stderr, "failed to set video mode %dx%d\n", scr_width, scr_height);
24 SDL_Quit();
25 return -1;
26 }
28 return 0;
29 }
31 void gfx_shutdown(void)
32 {
33 SDL_Quit();
34 }
37 int gfx_screen_width(void)
38 {
39 return scr_width;
40 }
42 int gfx_screen_height(void)
43 {
44 return scr_height;
45 }
48 void *gfx_set_framebuffer(void *fb, int width, int height)
49 {
50 return 0;
51 }
53 void *gfx_get_framebuffer(void)
54 {
55 return 0;
56 }
59 int get_framebuffer_width(void)
60 {
61 return fb_width;
62 }
64 int get_framebuffer_height(void)
65 {
66 return fb_height;
67 }
70 void gfx_begin_copperlist(void)
71 {
72 }
75 int gfx_next_event(union gfx_event *ev, int block)
76 {
77 SDL_Event sdlev;
79 if(block) {
80 SDL_WaitEvent(&sdlev);
81 } else {
82 if(!SDL_PollEvent(&sdlev)) {
83 return 0;
84 }
85 }
87 switch(sdlev.type) {
88 case SDL_QUIT:
89 ev->type = GFX_EV_QUIT;
90 return 1;
92 case SDL_KEYDOWN:
93 case SDL_KEYUP:
94 ev->type = GFX_EV_KEY;
95 ev->key.key = sdlev.key.keysym.sym;
96 ev->key.pressed = sdlev.key.state == SDL_PRESSED;
97 return 1;
99 default:
100 break;
101 }
102 return 0;
103 }
106 void gfx_wait_vpos(int x)
107 {
108 }
110 void gfx_wait_vblank(void)
111 {
112 }
114 #define ARED(x) ((((x) & 0xf00) >> 4) | (((x) & 0xf00) >> 8))
115 #define AGREEN(x) (((x) & 0xf0) | (((x) & 0xf0) >> 4))
116 #define ABLUE(x) ((((x) & 0xf) << 4) | ((x) & 0xf))
118 void gfx_show_image(struct ham_image *img)
119 {
120 int i, j, k;
121 uint32_t palette[16];
122 uint32_t *dest;
123 unsigned char *src;
125 for(i=0; i<16; i++) {
126 uint16_t pcol = img->palette[i];
127 int red = ARED(pcol);
128 int green = AGREEN(pcol);
129 int blue = ABLUE(pcol);
130 palette[i] = (red << fbsurf->format->Rshift) | (green << fbsurf->format->Gshift) |
131 (blue << fbsurf->format->Bshift);
132 }
134 if(SDL_MUSTLOCK(fbsurf)) {
135 SDL_LockSurface(fbsurf);
136 }
138 dest = fbsurf->pixels;
139 src = img->pixels;
140 for(i=0; i<img->height; i++) {
141 for(j=0; j<img->width; j++) {
142 unsigned char idx = 0;
143 int bit = j & 7;
144 for(k=0; k<img->nbitplanes; k++) {
145 idx = (idx << 1) | ((*(src + k * img->width / 8) >> bit) & 1);
146 }
147 *dest++ = palette[idx];
148 if(bit == 7) {
149 ++src;
150 }
151 }
152 src += img->width / 8 * (img->nbitplanes - 1);
153 }
155 if(SDL_MUSTLOCK(fbsurf)) {
156 SDL_UnlockSurface(fbsurf);
157 }
159 SDL_Flip(fbsurf);
160 }