1 | /*
|
---|
2 | =============================================================================
|
---|
3 | micons.c -- motorola / intel format conversion functions
|
---|
4 | Version 3 -- 1987-06-11 -- D.N. Lynx Crowe
|
---|
5 |
|
---|
6 | micon16(wi)
|
---|
7 |
|
---|
8 | Convert between motorola and intel format for a short.
|
---|
9 |
|
---|
10 | micon32(wi)
|
---|
11 |
|
---|
12 | Convert between motorola and intel format for a long.
|
---|
13 | =============================================================================
|
---|
14 | */
|
---|
15 |
|
---|
16 | #include "ram.h"
|
---|
17 |
|
---|
18 | #define TESTER 0 /* define non-zero for a test program */
|
---|
19 |
|
---|
20 | /*
|
---|
21 | =============================================================================
|
---|
22 | micon16(wi) -- Convert between motorola and intel format for a short.
|
---|
23 | =============================================================================
|
---|
24 | */
|
---|
25 |
|
---|
26 | uint16_t micon16(uint16_t wi)
|
---|
27 | {
|
---|
28 | return(((wi << 8) & 0xFF00u) | ((wi >> 8) & 0x00FFu));
|
---|
29 | }
|
---|
30 |
|
---|
31 | /*
|
---|
32 | =============================================================================
|
---|
33 | micon32(wi) -- Convert between motorola and intel format for a long.
|
---|
34 | =============================================================================
|
---|
35 | */
|
---|
36 |
|
---|
37 | uint32_t micon32(uint32_t wi)
|
---|
38 | {
|
---|
39 | return(((wi << 24) & 0xFF000000ul) | ((wi << 8) & 0x00FF0000ul) |
|
---|
40 | ((wi >> 8) & 0x0000FF00ul) | ((wi >> 24) & 0x000000FFul));
|
---|
41 | }
|
---|
42 |
|
---|
43 | #if TESTER
|
---|
44 |
|
---|
45 | #include "ram.h"
|
---|
46 |
|
---|
47 | /*
|
---|
48 | =============================================================================
|
---|
49 | test program for micon functions
|
---|
50 | =============================================================================
|
---|
51 | */
|
---|
52 |
|
---|
53 | main()
|
---|
54 | {
|
---|
55 | printf("micons(0x1234) returned 0x%04x\n", micons(0x1234));
|
---|
56 |
|
---|
57 | if (sizeof (int) == 4)
|
---|
58 | printf("miconi(0x1234) returned 0x%04x\n", miconi(0x1234));
|
---|
59 | else
|
---|
60 | printf("miconi(0x12345678L) returned 0x%08lx\n",
|
---|
61 | miconi(0x12345678L));
|
---|
62 |
|
---|
63 | printf("miconl(0x12345678L) returned 0x%08lx\n",
|
---|
64 | miconl(0x12345678L));
|
---|
65 | }
|
---|
66 |
|
---|
67 | #endif
|
---|
68 |
|
---|