]> icculus.org git repositories - btb/d2x.git/blob - 2d/bitmap.h
portability
[btb/d2x.git] / 2d / bitmap.h
1 /* $Id: bitmap.h,v 1.3 2002-07-17 21:55:19 bradleyb Exp $ */
2 #ifndef _BITMAP_H
3 #define _BITMAP_H
4
5 #ifndef NO_ASM
6 #ifdef __WATCOMC__
7 void decode_data_asm(ubyte *data, int num_pixels, ubyte * colormap, int * count );
8 #pragma aux decode_data_asm parm [esi] [ecx] [edi] [ebx] modify exact [esi edi eax ebx ecx] = \
9 "again_ddn:"                            \
10     "xor    eax,eax"                \
11     "mov    al,[esi]"           \
12     "inc    dword ptr [ebx+eax*4]"      \
13     "mov    al,[edi+eax]"       \
14     "mov    [esi],al"           \
15     "inc    esi"                    \
16     "dec    ecx"                    \
17     "jne    again_ddn"
18 #elif defined __GNUC__
19 static inline void decode_data_asm(ubyte *data, int num_pixels, ubyte * colormap, int * count ) {
20         int dummy[4];
21    __asm__ __volatile__ (
22     "xorl   %%eax,%%eax;"
23 "0:;"
24     "movb   (%%esi), %%al;"
25     "incl   (%%ebx, %%eax, 4);"
26     "movb   (%%edi, %%eax), %%al;"
27     "movb   %%al, (%%esi);"
28     "incl   %%esi;"
29     "decl   %%ecx;"
30     "jne    0b"
31     : "=S" (dummy[0]), "=c" (dummy[1]), "=D" (dummy[2]), "=b" (dummy[3])
32         : "0" (data), "1" (num_pixels), "2" (colormap), "3" (count)
33         : "%eax");
34 }
35 #elif defined _MSC_VER
36 __inline void decode_data_asm(ubyte *data, int num_pixels, ubyte * colormap, int * count )
37 {
38   __asm {
39         mov esi,[data]
40         mov ecx,[num_pixels]
41         mov edi,[colormap]
42         mov ebx,[count]
43 again_ddn:
44         xor eax,eax
45         mov al,[esi]
46         inc dword ptr [ebx+eax*4]
47         mov al,[edi+eax]
48         mov [esi],al
49         inc esi
50         dec ecx
51         jne again_ddn
52   }
53 }
54 #else
55 #define NO_ASM 1 // We really do want no assembler...
56 #endif
57 #endif
58
59 #ifdef NO_ASM
60 static void decode_data_asm(ubyte *data, int num_pixels, ubyte *colormap, int *count)
61 {
62         int i;
63         ubyte mapped;
64         
65         for (i = 0; i < num_pixels; i++) {
66                 count[*data]++;
67                 mapped = *data;
68                 *data = colormap[mapped];
69                 data++;
70         }
71 }
72 #endif
73 #endif