source: buchla-68k/lib700/micons.c@ fa38804

Last change on this file since fa38804 was fa38804, checked in by Thomas Lopatic <thomas@…>, 7 years ago

Removed form-feed comments.

  • Property mode set to 100644
File size: 2.3 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#include "ram.h"
27
28#define TESTER 0 /* define non-zero for a test program */
29
30/*
31 =============================================================================
32 micons(wi) -- Convert between motorola and intel format for a short.
33 =============================================================================
34*/
35
36int16_t micons(int16_t wi)
37{
38 return((int16_t)( ((wi << 8) & 0xFF00) | ((wi >> 8) & 0x00FF) ) );
39}
40
41/*
42 =============================================================================
43 miconi(wi) -- Convert between motorola and intel format for an int.
44 =============================================================================
45*/
46
47int16_t miconi(int16_t wi)
48{
49 if (sizeof (int16_t) == 4)
50 return( ((wi << 24) & 0xFF000000L) | ((wi << 8) & 0x00FF0000L) |
51 ((wi >> 8) & 0x0000FF00L) | ((wi >> 24) & 0x000000FFL) );
52 else
53 return(((wi << 8) & 0xFF00) | ((wi >> 8) & 0x00FF));
54}
55
56/*
57 =============================================================================
58 miconl(wi) -- Convert between motorola and intel format for a long.
59 =============================================================================
60*/
61
62int32_t miconl(int32_t wi)
63{
64 return( ((wi << 24) & 0xFF000000L) | ((wi << 8) & 0x00FF0000L) |
65 ((wi >> 8) & 0x0000FF00L) | ((wi >> 24) & 0x000000FFL) );
66}
67
68#if TESTER
69
70#include "ram.h"
71
72/*
73 =============================================================================
74 test program for micon functions
75 =============================================================================
76*/
77
78main()
79{
80 printf("micons(0x1234) returned 0x%04x\n", micons(0x1234));
81
82 if (sizeof (int) == 4)
83 printf("miconi(0x1234) returned 0x%04x\n", miconi(0x1234));
84 else
85 printf("miconi(0x12345678L) returned 0x%08lx\n",
86 miconi(0x12345678L));
87
88 printf("miconl(0x12345678L) returned 0x%08lx\n",
89 miconl(0x12345678L));
90}
91
92#endif
93
Note: See TracBrowser for help on using the repository browser.