📄 pc_cnvrt.c
字号:
/*
* EBS - RTFS (Real Time File Manager)
*
* Copyright Peter Van Oudenaren , 1993
* All rights reserved.
* This code may not be redistributed in source or linkable object form
* without the consent of its author.
*/
/*
*****************************************************************************
PC_CNVRT - Convert intel byte order to native byte order.
Summary
#include <pcdisk.h>
ULONG to_DWORD (from) Convert intel style 32 bit to native 32 bit
UTINY *from;
UCOUNT to_WORD (from) Convert intel style 16 bit to native 16 bit
UTINY *from;
VOID fr_WORD (to,from) Convert native 16 bit to 16 bit intel
UTINY *to;
UCOUNT from;
VOID fr_DWORD (to,from) Convert native 32 bit to 32 bit intel
UTINY *to;
ULONG from;
Description
This code is known to work on 68K and 808x machines. It has been left
as generic as possible. You may wish to hardwire it for your CPU/Code
generator to shave off a few bytes and microseconds, be careful though
the addresses are not guaranteed to be word aligned in fact to_WORD AND
fr_WORD's arguments are definately NOT word alligned when working on odd
number indeces in 12 bit fats. (see pc_faxx and pc_pfaxx().
Note: Optimize at your own peril, and after everything else is debugged.
Bit shift operators are used to convert intel ordered storage
to native. The host byte ordering should not matter.
Returns
Example:
See other sources.
*****************************************************************************
*/
#include "pcdisk.h"
/* Convert a 32 bit intel item to a portable 32 bit */
ULONG to_DWORD ( UTINY *from) /*__fn__*/
{
ULONG t,res;
t = ((ULONG) *(from + 3)) & 0xff;
res = (t << 24);
t = ((ULONG) *(from + 2)) & 0xff;
res |= (t << 16);
t = ((ULONG) *(from + 1)) & 0xff;
res |= (t << 8);
t = ((ULONG) *from) & 0xff;
res |= t;
return(res);
}
/* Convert a 16 bit intel item to a portable 16 bit */
UCOUNT to_WORD ( UTINY *from) /*__fn__*/
{
UCOUNT nres;
UCOUNT t;
t = (UCOUNT) (((UCOUNT) *(from + 1)) & 0xff);
nres = (UCOUNT) (t << 8);
t = (UCOUNT) (((UCOUNT) *from) & 0xff);
nres |= t;
return(nres);
}
/* Convert a portable 16 bit to a 16 bit intel item */
VOID fr_WORD ( UTINY *to, UCOUNT from) /*__fn__*/
{
*to = (UTINY) (from & 0x00ff);
*(to + 1) = (UTINY) ((from >> 8) & 0x00ff);
}
/* Convert a portable 32 bit to a 32 bit intel item */
VOID fr_DWORD ( UTINY *to, ULONG from) /*__fn__*/
{
*to = (UTINY) (from & 0xff);
*(to + 1) = (UTINY) ((from >> 8) & 0xff);
*(to + 2) = (UTINY) ((from >> 16) & 0xff);
*(to + 3) = (UTINY) ((from >> 24) & 0xff);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -