More work on docs for the new opcodes.
[retro/experimental.git] / ngaro / c-crc / sdl / endian.c
blobba956d2996c27963dabb591ce47a6cb515c1aa72
1 /******************************************************
2 * Ngaro
4 *|F|
5 *|F| FILE: endian.c
6 *|F|
8 * Written by Charles Childers, released into the public
9 * domain
10 ******************************************************/
12 #include <stdio.h>
13 #include <stddef.h>
14 #include <stdlib.h>
16 #include "functions.h"
17 #include "vm.h"
19 extern VM_STATE vm;
21 #define BIGENDIAN 0
22 #define LITTLEENDIAN 1
24 /* This is a slightly tricky bit of code to convert an image from one endian to the other. */
25 /* It's only recieved minimal testing, so I hope it actually works... */
26 void swapEndian()
28 int endian, x, a;
29 short int word = 0x0001;
30 char *byte = (char *) &word;
31 endian = (byte[0] ? LITTLEENDIAN : BIGENDIAN);
33 if (endian == LITTLEENDIAN)
34 printf("Converting to big endian\n");
35 if (endian == BIGENDIAN)
36 printf("Converting to little endian\n");
38 for(a = 0; a < IMAGE_SIZE; a++)
40 x = vm.image[a];
41 vm.image[a] = (x>>24) | ((x<<8) & 0x00FF0000) | ((x>>8) & 0x0000FF00) | (x<<24);
43 printf("Done!\n");