[f40a309] | 1 | /*
|
---|
| 2 | =============================================================================
|
---|
| 3 | micons.c -- motorola / intel format conversion functions
|
---|
| 4 | Version 3 -- 1987-06-11 -- D.N. Lynx Crowe
|
---|
| 5 |
|
---|
[d18a473] | 6 | micon16(wi)
|
---|
[f40a309] | 7 |
|
---|
| 8 | Convert between motorola and intel format for a short.
|
---|
| 9 |
|
---|
[d18a473] | 10 | micon32(wi)
|
---|
[f40a309] | 11 |
|
---|
| 12 | Convert between motorola and intel format for a long.
|
---|
| 13 | =============================================================================
|
---|
| 14 | */
|
---|
| 15 |
|
---|
[b28a12e] | 16 | #include "ram.h"
|
---|
[6262b5c] | 17 |
|
---|
[f40a309] | 18 | #define TESTER 0 /* define non-zero for a test program */
|
---|
| 19 |
|
---|
| 20 | /*
|
---|
| 21 | =============================================================================
|
---|
[d18a473] | 22 | micon16(wi) -- Convert between motorola and intel format for a short.
|
---|
[f40a309] | 23 | =============================================================================
|
---|
| 24 | */
|
---|
| 25 |
|
---|
[d18a473] | 26 | uint16_t micon16(uint16_t wi)
|
---|
[f40a309] | 27 | {
|
---|
[d18a473] | 28 | return(((wi << 8) & 0xFF00u) | ((wi >> 8) & 0x00FFu));
|
---|
[f40a309] | 29 | }
|
---|
| 30 |
|
---|
| 31 | /*
|
---|
| 32 | =============================================================================
|
---|
[d18a473] | 33 | micon32(wi) -- Convert between motorola and intel format for a long.
|
---|
[f40a309] | 34 | =============================================================================
|
---|
| 35 | */
|
---|
| 36 |
|
---|
[d18a473] | 37 | uint32_t micon32(uint32_t wi)
|
---|
[f40a309] | 38 | {
|
---|
[d18a473] | 39 | return(((wi << 24) & 0xFF000000ul) | ((wi << 8) & 0x00FF0000ul) |
|
---|
| 40 | ((wi >> 8) & 0x0000FF00ul) | ((wi >> 24) & 0x000000FFul));
|
---|
[f40a309] | 41 | }
|
---|
| 42 |
|
---|
| 43 | #if TESTER
|
---|
| 44 |
|
---|
[b28a12e] | 45 | #include "ram.h"
|
---|
[f40a309] | 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
|
---|
[6262b5c] | 68 |
|
---|