PCem
view src/allegro-video.c @ 154:d0d530adce12
Initial port to Linux (using Allegro).
64-bit fixes.
Some changes to aid portability.
A few other tweaks.
| author | TomW |
|---|---|
| date | Thu Sep 04 21:07:24 2014 +0100 |
| parents | |
| children |
line source
1 #include "allegro-main.h"
2 #include "ibm.h"
3 #include "video.h"
5 #include "allegro-video.h"
7 static PALETTE cgapal=
8 {
9 {0,0,0},{0,42,0},{42,0,0},{42,21,0},
10 {0,0,0},{0,42,42},{42,0,42},{42,42,42},
11 {0,0,0},{21,63,21},{63,21,21},{63,63,21},
12 {0,0,0},{21,63,63},{63,21,63},{63,63,63},
14 {0,0,0},{0,0,42},{0,42,0},{0,42,42},
15 {42,0,0},{42,0,42},{42,21,00},{42,42,42},
16 {21,21,21},{21,21,63},{21,63,21},{21,63,63},
17 {63,21,21},{63,21,63},{63,63,21},{63,63,63},
19 {0,0,0},{0,21,0},{0,0,42},{0,42,42},
20 {42,0,21},{21,10,21},{42,0,42},{42,0,63},
21 {21,21,21},{21,63,21},{42,21,42},{21,63,63},
22 {63,0,0},{42,42,0},{63,21,42},{41,41,41},
24 {0,0,0},{0,42,42},{42,0,0},{42,42,42},
25 {0,0,0},{0,42,42},{42,0,0},{42,42,42},
26 {0,0,0},{0,63,63},{63,0,0},{63,63,63},
27 {0,0,0},{0,63,63},{63,0,0},{63,63,63},
28 };
30 static uint32_t pal_lookup[256];
32 static void allegro_blit_memtoscreen(int x, int y, int y1, int y2, int w, int h);
33 static void allegro_blit_memtoscreen_8(int x, int y, int w, int h);
34 static BITMAP *buffer32_vscale;
35 void allegro_video_init()
36 {
37 int c;
39 set_color_depth(32);
40 set_gfx_mode(GFX_AUTODETECT_WINDOWED, 640, 480, 0, 0);
41 video_blit_memtoscreen = allegro_blit_memtoscreen;
42 video_blit_memtoscreen_8 = allegro_blit_memtoscreen_8;
44 for (c = 0; c < 256; c++)
45 pal_lookup[c] = makecol(cgapal[c].r << 2, cgapal[c].g << 2, cgapal[c].b << 2);
47 buffer32_vscale = create_bitmap(2048, 2048);
48 }
50 void allegro_video_close()
51 {
52 destroy_bitmap(buffer32_vscale);
53 }
55 void allegro_video_update_size(int x, int y)
56 {
57 if (set_gfx_mode(GFX_AUTODETECT_WINDOWED, x, y, 0, 0))
58 fatal("Failed to set gfx mode %i,%i : %s\n", x, y, allegro_error);
59 }
61 static void allegro_blit_memtoscreen(int x, int y, int y1, int y2, int w, int h)
62 {
63 if (h < winsizey)
64 {
65 int yy;
67 for (yy = y+y1; yy < y+y2; yy++)
68 {
69 if (yy >= 0)
70 {
71 memcpy(&((uint32_t *)buffer32_vscale->line[yy*2])[x], &((uint32_t *)buffer32->line[yy])[x], w*4);
72 memcpy(&((uint32_t *)buffer32_vscale->line[(yy*2)+1])[x], &((uint32_t *)buffer32->line[yy])[x], w*4);
73 }
74 }
76 blit(buffer32_vscale, screen, x, (y+y1)*2, 0, y1, w, (y2-y1)*2);
77 }
78 else
79 blit(buffer32, screen, x, y+y1, 0, y1, w, y2-y1);
80 }
82 static void allegro_blit_memtoscreen_8(int x, int y, int w, int h)
83 {
84 int xx, yy;
86 if (y < 0)
87 {
88 h += y;
89 y = 0;
90 }
92 for (yy = y; yy < y+h; yy++)
93 {
94 int dy = yy*2;
95 for (xx = x; xx < x+w; xx++)
96 {
97 ((uint32_t *)buffer32->line[dy])[xx] =
98 ((uint32_t *)buffer32->line[dy + 1])[xx] = pal_lookup[buffer->line[yy][xx]];
99 }
100 }
102 if (readflash)
103 {
104 rectfill(buffer32, x+SCREEN_W-40, y*2+8, SCREEN_W-8, y*2+14, makecol(255, 255, 255));
105 readflash = 0;
106 }
108 blit(buffer32, screen, x, y*2, 0, 0, w, h*2);
109 }
