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