📄 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.
*/
/*
Changes made by L. Brooks (03/97):
Added support for Texas Instruments DSP architecture.
ULONG pack_BYTEs_into_DWORD( UTINY *from ) Converts a word represented
by four consecutive byte elements (chars) 8-bits of information each
into a single double word element (long) with 32 bits of information
UCOUNT pack_BYTEs_into_WORD( UTINY *from ) Converts a word represented
by two consecutive byte elements (chars) 8-bits of information each into
a single word element (short) with 16 bits of information
VOID unpack_DWORD_into_BYTEs( UTINY *to, ULONG from ) Converts a double
word represented by a single double word element (long) with 32-bits of
information into a word represented by four consecutive byte elements
(chars) with 8-bits of information each.
VOID unpack_WORD_into_BYTEs( UTINY *to, UCOUNT from ) Converts a word
represented by a single word element (short) with 16-bits of information
into a word represented by two consecutive byte elements (chars) with
8-bits of information each.
void
ToPTABLE( UTINY *buf ) Conversion between char array and PTABLE.
void
ToDOSINODE( DOSINODE *target_dosinode, UTINY *source_buf ) Conversion
between char array and DOSINODE.
void
FromDOSINODE( UTINY *target_buf, DOSINODE *source_dosinode ) Conversion
between char array and DOSINODE.
*/
/*****************************************************************************
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"
void
ToPTABLE( UTINY *buf )
{
#if (TI_DSP)
int i;
PTABLE *tempPTABLE = (PTABLE *)buf;
for( i=0; i<4; i++ )
{
int offset = i*0x10;
tempPTABLE->ents[i].boot = buf[0x0+offset];
tempPTABLE->ents[i].s_head = buf[0x1+offset];
tempPTABLE->ents[i].s_cyl = pack_BYTEs_into_WORD( &buf[0x2+offset] );
tempPTABLE->ents[i].p_typ = buf[0x4+offset];
tempPTABLE->ents[i].e_head = buf[0x5+offset];
tempPTABLE->ents[i].e_cyl = pack_BYTEs_into_WORD( &buf[0x6+offset] );
tempPTABLE->ents[i].r_sec = pack_BYTEs_into_DWORD( &buf[0x8+offset] );
tempPTABLE->ents[i].p_size = pack_BYTEs_into_DWORD( &buf[0xc+offset] );
}
tempPTABLE->signature = pack_BYTEs_into_WORD( &buf[0x40] );
#endif
}
void
FromDOSINODE( UTINY *target_buf, DOSINODE *source_dosinode )
{
#if (TI_DSP)
copybuff( &(target_buf[0x0]), source_dosinode->fname, 8 );
copybuff( &(target_buf[0x8]), source_dosinode->fext, 3 );
target_buf[0xb] = source_dosinode->fattribute;
copybuff( &(target_buf[0xc]), source_dosinode->resarea, 10 );
unpack_WORD_into_BYTEs( &(target_buf[0x16]), source_dosinode->ftime );
unpack_WORD_into_BYTEs( &(target_buf[0x18]), source_dosinode->fdate );
unpack_WORD_into_BYTEs( &(target_buf[0x1a]), source_dosinode->fcluster );
unpack_DWORD_into_BYTEs( &(target_buf[0x1c]), source_dosinode->fsize );
#else
copybuff( target_buf, source_dosinode, sizeof(DOSINODE) );
#endif
}
void
ToDOSINODE( DOSINODE *target_dosinode, UTINY *source_buf )
{
#if (TI_DSP)
copybuff( target_dosinode->fname, &(source_buf[0x0]), 8 );
copybuff( target_dosinode->fext, &(source_buf[0x8]), 3 );
target_dosinode->fattribute = source_buf[0xb];
copybuff( target_dosinode->resarea, &(source_buf[0xc]), 10 );
target_dosinode->ftime = pack_BYTEs_into_WORD( &(source_buf[0x16]) );
target_dosinode->fdate = pack_BYTEs_into_WORD( &(source_buf[0x18]) );
target_dosinode->fcluster = pack_BYTEs_into_WORD( &(source_buf[0x1a]) );
target_dosinode->fsize = pack_BYTEs_into_DWORD( &(source_buf[0x1c]) );
#else
*target_dosinode = *((DOSINODE *)source_buf);
#endif
}
/* Converts a word represented by four consecutive byte elements (chars)
8-bits of information each into a single double word element (long)
with 32 bits of information */
ULONG pack_BYTEs_into_DWORD( UTINY *from ) /*__fn__*/
{
ULONG t, res;
t = ((ULONG) *(from + 3)) & (ULONG)0xff;
res = (t << 24);
t = ((ULONG) *(from + 2)) & (ULONG)0xff;
res |= (t << 16);
t = ((ULONG) *(from + 1)) & (ULONG)0xff;
res |= (t << 8);
t = ((ULONG) * from ) & (ULONG)0xff;
res |= t;
return(res);
}
/* Converts a word represented by two consecutive byte elements (chars)
8-bits of information each into a single word element (short) with
16 bits of information */
UCOUNT pack_BYTEs_into_WORD( UTINY *from ) /*__fn__*/
{
UCOUNT t, nres;
t = ((UCOUNT) *(from + 1)) & (UCOUNT)0xff;
nres = (t << 8);
t = ((UCOUNT) * from ) & (UCOUNT)0xff;
nres |= t;
return(nres);
}
/*
Converts a word represented by a single word element (short)
with 16-bits of information into a word represented by two
consecutive byte elements (chars) with 8-bits of information
each.
*/
VOID unpack_WORD_into_BYTEs( UTINY *to, UCOUNT from ) /*__fn__*/
{
*to = (UTINY)( from & (UCOUNT)0xff );
*(to + 1) = (UTINY)((from >> 8) & (UCOUNT)0xff );
}
/*
Converts a double word represented by a single double word
element (long) with 32-bits of information into a word
represented by four consecutive byte elements (chars) with
8-bits of information each.
*/
VOID unpack_DWORD_into_BYTEs( UTINY *to, ULONG from ) /*__fn__*/
{
*to = (UTINY)( from & (ULONG)0xff );
*(to + 1) = (UTINY)((from >> 8) & (ULONG)0xff );
*(to + 2) = (UTINY)((from >> 16) & (ULONG)0xff );
*(to + 3) = (UTINY)((from >> 24) & (ULONG)0xff );
}
/* Older conversion routines: */
// #if 0
/* 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);
}
// #endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -