source: buchla-68k/orig/CLIBRARY/MICONS.C@ f7c91fc

Last change on this file since f7c91fc was 3ae31e9, checked in by Thomas Lopatic <thomas@…>, 8 years ago

Imported original source code.

  • Property mode set to 100755
File size: 2.4 KB
Line 
1/*
2 =============================================================================
3 micons.c -- motorola / intel format conversion functions
4 Version 3 -- 1987-06-11 -- D.N. Lynx Crowe
5
6 short
7 micons(wi)
8 short wi;
9
10 Convert between motorola and intel format for a short.
11
12 int
13 miconi(wi)
14 int wi;
15
16 Convert between motorola and intel format for an int.
17
18 long
19 miconl(wi)
20 long wi;
21
22 Convert between motorola and intel format for a long.
23 =============================================================================
24*/
25
26#define TESTER 0 /* define non-zero for a test program */
27
28/*
29 */
30
31/*
32 =============================================================================
33 micons(wi) -- Convert between motorola and intel format for a short.
34 =============================================================================
35*/
36
37short
38micons(wi)
39short wi;
40{
41 return((short)( ((wi << 8) & 0xFF00) | ((wi >> 8) & 0x00FF) ) );
42}
43
44/*
45 =============================================================================
46 miconi(wi) -- Convert between motorola and intel format for an int.
47 =============================================================================
48*/
49
50int
51miconi(wi)
52int wi;
53{
54 if (sizeof (int) == 4)
55 return( ((wi << 24) & 0xFF000000L) | ((wi << 8) & 0x00FF0000L) |
56 ((wi >> 8) & 0x0000FF00L) | ((wi >> 24) & 0x000000FFL) );
57 else
58 return(((wi << 8) & 0xFF00) | ((wi >> 8) & 0x00FF));
59}
60
61/*
62 =============================================================================
63 miconl(wi) -- Convert between motorola and intel format for a long.
64 =============================================================================
65*/
66
67long
68miconl(wi)
69long wi;
70{
71 return( ((wi << 24) & 0xFF000000L) | ((wi << 8) & 0x00FF0000L) |
72 ((wi >> 8) & 0x0000FF00L) | ((wi >> 24) & 0x000000FFL) );
73}
74
75/*
76 */
77
78#if TESTER
79
80#include "stdio.h"
81
82/*
83 =============================================================================
84 test program for micon functions
85 =============================================================================
86*/
87
88main()
89{
90 printf("micons(0x1234) returned 0x%04x\n", micons(0x1234));
91
92 if (sizeof (int) == 4)
93 printf("miconi(0x1234) returned 0x%04x\n", miconi(0x1234));
94 else
95 printf("miconi(0x12345678L) returned 0x%08lx\n",
96 miconi(0x12345678L));
97
98 printf("miconl(0x12345678L) returned 0x%08lx\n",
99 miconl(0x12345678L));
100}
101
102#endif
Note: See TracBrowser for help on using the repository browser.