ulong => UInt64

_REV/_REV16 独立汇编实现,不依赖固件库
This commit is contained in:
nnhy 2016-03-07 10:46:10 +00:00
parent bc30a8eea1
commit 11ec1084fd
35 changed files with 116 additions and 106 deletions

View File

@ -17,7 +17,7 @@ private:
uint NextPacketPtr;
ulong LastTime; // 记录最后一次收到数据的时间,超时重启
UInt64 LastTime; // 记录最后一次收到数据的时间,超时重启
uint ResetPeriod; // 重启间隔默认6000微秒
uint _ResetTask; // 重启任务
public:

View File

@ -128,7 +128,7 @@ void Dhcp::Request()
void Dhcp::Start()
{
ulong now = Sys.Ms();
UInt64 now = Sys.Ms();
_expired = now + ExpiredTime;
if(!dhcpid) dhcpid = now;
@ -327,7 +327,7 @@ void Dhcp::Process(Buffer& bs, const IPEndPoint& ep)
// DHCP租约过了一半以后重新获取IP地址
if(time > 0)
{
Sys.SetTaskPeriod(taskID, (ulong)time / 2 * 1000);
Sys.SetTaskPeriod(taskID, (UInt64)time / 2 * 1000);
Sys.SetTask(taskID, true);
}
}

View File

@ -9,7 +9,7 @@ class Dhcp
private:
uint dhcpid; // 事务ID
uint taskID; // 任务ID
ulong _expired; // 目标过期时间,毫秒
UInt64 _expired; // 目标过期时间,毫秒
ISocket* Socket;
void Discover();

View File

@ -29,7 +29,7 @@ public:
uint v4;
ushort v2;
MacAddr(ulong v = 0)
MacAddr(UInt64 v = 0)
{
v4 = v;
v2 = v >> 32;
@ -38,17 +38,17 @@ public:
// 是否广播地址全0或全1
bool IsBroadcast() { return !v4 && !v2 || v4 == 0xFFFFFFFF && v2 == 0xFFFF; }
MacAddr& operator=(ulong v)
MacAddr& operator=(UInt64 v)
{
v4 = v;
v2 = v >> 32;
return *this;
}
ulong Value()
UInt64 Value()
{
ulong v = v4;
v |= ((ulong)v2) << 32;
UInt64 v = v4;
v |= ((UInt64)v2) << 32;
return v;
}

View File

@ -175,7 +175,7 @@ bool operator!=(const IPEndPoint& addr1, const IPEndPoint& addr2)
//const MacAddress MacAddress::Empty(0x0ull);
//const MacAddress MacAddress::Full(MAC_MASK);
MacAddress::MacAddress(ulong v)
MacAddress::MacAddress(UInt64 v)
{
Value = v & MAC_MASK;
}
@ -209,7 +209,7 @@ const MacAddress& MacAddress::Full()
return _Full;
}
MacAddress& MacAddress::operator=(ulong v)
MacAddress& MacAddress::operator=(UInt64 v)
{
Value = v & MAC_MASK;

View File

@ -82,16 +82,16 @@ class MacAddress : public Object
{
public:
// 长整型转为Mac地址取内存前6字节。因为是小字节序需要v4在前v2在后
ulong Value; // 地址
UInt64 Value; // 地址
MacAddress(ulong v = 0);
MacAddress(UInt64 v = 0);
MacAddress(const byte* macs);
MacAddress(const Buffer& arr);
// 是否广播地址全0或全1
bool IsBroadcast() const;
MacAddress& operator=(ulong v);
MacAddress& operator=(UInt64 v);
MacAddress& operator=(const byte* buf);
MacAddress& operator=(const Buffer& arr);

View File

@ -546,7 +546,7 @@ void InputPort::OnPress(bool down)
2使
3100
*/
ulong now = Sys.Ms();
UInt64 now = Sys.Ms();
// 预处理抖动。如果相邻两次间隔小于抖动时间,那么忽略上一次未处理的值(可能失败)
bool shake = false;
if(ShakeTime && ShakeTime > now - _PressLast)

6
Port.h
View File

@ -170,9 +170,9 @@ protected:
private:
byte _Value = 0;
uint _taskInput = 0; // 输入任务
ulong _PressStart = 0; // 开始按下时间
ulong _PressStart2 = 0; // 开始按下时间
ulong _PressLast = 0; // 最后一次按下时间
UInt64 _PressStart = 0; // 开始按下时间
UInt64 _PressStart2 = 0; // 开始按下时间
UInt64 _PressLast = 0; // 最后一次按下时间
static void InputTask(void* param);
IOReadHandler Handler = NULL;

View File

@ -203,7 +203,7 @@ void HardRTC::LoadTicks()
auto& time = (TTime&)Time;
#ifdef STM32F1
// 加上计数器的值注意计数器的单位是秒。注意必须转INT64否则溢出
ulong ms = RTC_GetCounter();
UInt64 ms = RTC_GetCounter();
// 计数器调整为毫秒,采用第二个后备寄存器保存秒以上的数据
uint sec = ReadBackup(1);
time.Seconds = sec;

View File

@ -312,11 +312,11 @@ uint Stream::ReadUInt32()
return v;
}
ulong Stream::ReadUInt64()
UInt64 Stream::ReadUInt64()
{
ulong v;
UInt64 v;
if(!Read((byte*)&v, 0, 8)) return 0;
if(!Little) v = _REV(v >> 32) | ((ulong)_REV(v & 0xFFFFFFFF) << 32);
if(!Little) v = _REV(v >> 32) | ((UInt64)_REV(v & 0xFFFFFFFF) << 32);
return v;
}
@ -339,9 +339,9 @@ bool Stream::Write(uint value)
return Write((byte*)&value, 0, 4);
}
bool Stream::Write(ulong value)
bool Stream::Write(UInt64 value)
{
if(!Little) value = _REV(value >> 32) | ((ulong)_REV(value & 0xFFFFFFFF) << 32);
if(!Little) value = _REV(value >> 32) | ((UInt64)_REV(value & 0xFFFFFFFF) << 32);
return Write((byte*)&value, 0, 8);
}

View File

@ -73,16 +73,16 @@ public:
byte ReadByte();
ushort ReadUInt16();
uint ReadUInt32();
ulong ReadUInt64();
UInt64 ReadUInt64();
bool Write(byte value);
bool Write(ushort value);
bool Write(uint value);
bool Write(ulong value);
bool Write(UInt64 value);
bool Write(sbyte value) { return Write((byte)value); }
bool Write(short value) { return Write((ushort)value); }
bool Write(int value) { return Write((uint)value); }
bool Write(Int64 value) { return Write((ulong)value); }
bool Write(Int64 value) { return Write((UInt64)value); }
// 取回指定结构体指针,并移动游标位置
template<typename T>

View File

@ -10,7 +10,7 @@
extern char* itoa(int value, char* string, int radix);
extern char* ltoa(Int64 value, char* string, int radix);
extern char* utoa(uint value, char* string, int radix);
extern char* ultoa(ulong value, char* string, int radix);
extern char* ultoa(UInt64 value, char* string, int radix);
char* dtostrf(double val, char width, byte prec, char* sout);
/******************************** String ********************************/
@ -81,7 +81,7 @@ String::String(Int64 value, byte radix)
ltoa(value, _Arr, radix);
}
String::String(ulong value, byte radix)
String::String(UInt64 value, byte radix)
{
init();
@ -313,9 +313,9 @@ bool String::Concat(Int64 num, byte radix)
return Concat(buf, strlen(buf));
}
bool String::Concat(ulong num, byte radix)
bool String::Concat(UInt64 num, byte radix)
{
char buf[1 + 3 * sizeof(ulong)];
char buf[1 + 3 * sizeof(UInt64)];
ultoa(num, buf, radix);
return Concat(buf, strlen(buf));
}
@ -391,7 +391,7 @@ StringHelper& operator + (const StringHelper& lhs, Int64 num)
return a;
}
StringHelper& operator + (const StringHelper& lhs, ulong num)
StringHelper& operator + (const StringHelper& lhs, UInt64 num)
{
auto& a = const_cast<StringHelper&>(lhs);
if (!a.Concat(num)) a.release();
@ -765,7 +765,7 @@ extern char* ltoa(Int64 value, char* string, int radix )
char tmp[33];
char *tp = tmp;
Int64 i;
ulong v;
UInt64 v;
int sign;
char *sp;
@ -777,7 +777,7 @@ extern char* ltoa(Int64 value, char* string, int radix )
if (sign)
v = -value;
else
v = (ulong)value;
v = (UInt64)value;
while (v || tp == tmp)
{
@ -804,12 +804,12 @@ extern char* utoa(uint value, char* string, int radix)
return ultoa(value, string, radix ) ;
}
extern char* ultoa(ulong value, char* string, int radix)
extern char* ultoa(UInt64 value, char* string, int radix)
{
char tmp[33];
char *tp = tmp;
Int64 i;
ulong v = value;
UInt64 v = value;
char *sp;
if ( string == NULL ) return 0;

View File

@ -22,7 +22,7 @@ public:
explicit String(int value, byte radix = 10);
explicit String(uint value, byte radix = 10);
explicit String(Int64 value, byte radix = 10);
explicit String(ulong value, byte radix = 10);
explicit String(UInt64 value, byte radix = 10);
explicit String(float value, byte decimalPlaces = 2);
explicit String(double value, byte decimalPlaces = 2);
virtual ~String();
@ -49,7 +49,7 @@ public:
bool Concat(int num, byte radix = 10);
bool Concat(uint num, byte radix = 10);
bool Concat(Int64 num, byte radix = 10);
bool Concat(ulong num, byte radix = 10);
bool Concat(UInt64 num, byte radix = 10);
bool Concat(float num);
bool Concat(double num);
@ -63,7 +63,7 @@ public:
String& operator += (int num) {Concat(num); return (*this);}
String& operator += (uint num) {Concat(num); return (*this);}
String& operator += (Int64 num) {Concat(num); return (*this);}
String& operator += (ulong num) {Concat(num); return (*this);}
String& operator += (UInt64 num) {Concat(num); return (*this);}
String& operator += (float num) {Concat(num); return (*this);}
String& operator += (double num) {Concat(num); return (*this);}
@ -82,7 +82,7 @@ public:
friend StringHelper& operator + (const StringHelper& lhs, int num);
friend StringHelper& operator + (const StringHelper& lhs, uint num);
friend StringHelper& operator + (const StringHelper& lhs, Int64 num);
friend StringHelper& operator + (const StringHelper& lhs, ulong num);
friend StringHelper& operator + (const StringHelper& lhs, UInt64 num);
friend StringHelper& operator + (const StringHelper& lhs, float num);
friend StringHelper& operator + (const StringHelper& lhs, double num);
@ -184,7 +184,7 @@ public:
StringHelper(int num) : String(num) {}
StringHelper(uint num) : String(num) {}
StringHelper(Int64 num) : String(num) {}
StringHelper(ulong num) : String(num) {}
StringHelper(UInt64 num) : String(num) {}
StringHelper(float num) : String(num) {}
StringHelper(double num) : String(num) {}
};

View File

@ -497,7 +497,7 @@ void TimeSleep(uint us)
}
// 系统启动后的毫秒数
ulong TSys::Ms() const { return Time.Current(); }
UInt64 TSys::Ms() const { return Time.Current(); }
// 系统绝对当前时间,秒
uint TSys::Seconds() const { return Time.Seconds + Time.BaseSeconds; }

2
Sys.h
View File

@ -81,7 +81,7 @@ public:
uint HeapBase() const; // 堆起始地址,前面是静态分配内存
uint StackTop() const; // 栈顶,后面是初始化不清零区域
ulong Ms() const; // 系统启动后的毫秒数
UInt64 Ms() const; // 系统启动后的毫秒数
uint Seconds() const; // 系统绝对当前时间,秒
void Sleep(uint ms) const; // 毫秒级延迟

View File

@ -28,7 +28,7 @@ Task::~Task()
#pragma arm section code = "SectionForSys"
#endif
bool Task::Execute(ulong now)
bool Task::Execute(UInt64 now)
{
//TS("Task::Execute");
TS(Name);
@ -251,9 +251,9 @@ void TaskScheduler::Execute(uint msMax)
{
TS("Task::Execute");
ulong now = Sys.Ms();
ulong end = now + msMax;
ulong min = UInt64_Max; // 最小时间,这个时间就会有任务到来
UInt64 now = Sys.Ms();
UInt64 end = now + msMax;
UInt64 min = UInt64_Max; // 最小时间,这个时间就会有任务到来
TimeCost tc;
@ -278,8 +278,8 @@ void TaskScheduler::Execute(uint msMax)
// 如果事件型任务还需要执行,那么就不要做任何等待
if(task->NextTime < 0)
min = 0;
else if((ulong)task->NextTime < min)
min = (ulong)task->NextTime;
else if((UInt64)task->NextTime < min)
min = (UInt64)task->NextTime;
}
}

2
Task.h
View File

@ -39,7 +39,7 @@ public:
~Task();
// 执行任务。返回是否正常执行。
bool Execute(ulong now);
bool Execute(UInt64 now);
// 设置任务的开关状态同时运行指定任务最近一次调度的时间0表示马上调度
void Set(bool enable, int msNextTime = -1);
// 显示状态

View File

@ -96,7 +96,7 @@ void TestCrc()
// 结果相同但都不是0
// 连续测试。构建8字节前面是data后面是前面的crc
ulong data2 = temp;
UInt64 data2 = temp;
data2 <<= 32;
data2 += data;
ByteArray bs2(&data2, 8);

View File

@ -48,7 +48,7 @@ public:
void Suspend();
void Resume();
ulong DelayExpire; // 过期时间,单位微秒。睡眠的线程达到该时间后将恢复唤醒
UInt64 DelayExpire; // 过期时间,单位微秒。睡眠的线程达到该时间后将恢复唤醒
void Sleep(uint ms); // 睡眠指定毫秒数。
// 静态管理

View File

@ -142,7 +142,7 @@ uint TTime::CurrentTicks() const
}
// 当前毫秒数
ulong TTime::Current() const
UInt64 TTime::Current() const
{
uint cnt = g_Timers[Index]->CNT;
#if ! (defined(STM32F0) || defined(GD32F150))
@ -151,7 +151,7 @@ ulong TTime::Current() const
return Milliseconds + cnt;
}
void TTime::SetTime(ulong seconds)
void TTime::SetTime(UInt64 seconds)
{
if(seconds >= BASE_YEAR_US) seconds -= BASE_YEAR_US;
BaseSeconds = seconds - Seconds;
@ -226,7 +226,7 @@ void TTime::Delay(uint us) const
if(!us) return;
// 无需关闭中断,也能实现延迟
ulong ms = Current();
UInt64 ms = Current();
uint ticks = CurrentTicks() + us * Ticks;
if(ticks >= (1000 - 1) * Ticks)
{
@ -261,7 +261,7 @@ const int CummulativeDaysForMonth[13] = {0, 31, 59, 90, 120, 151, 181, 212, 243,
#define YEARS_TO_DAYS(y) ((NUMBER_OF_YEARS(y) * 365) + NUMBER_OF_LEAP_YEARS(y))
#define MONTH_TO_DAYS(y, m) (CummulativeDaysForMonth[m - 1] + ((IS_LEAP_YEAR(y) && (m > 2)) ? 1 : 0))
DateTime& DateTime::Parse(ulong seconds)
DateTime& DateTime::Parse(UInt64 seconds)
{
DateTime& st = *this;
@ -305,7 +305,7 @@ DateTime& DateTime::Parse(ulong seconds)
return st;
}
DateTime& DateTime::ParseUs(ulong us)
DateTime& DateTime::ParseUs(UInt64 us)
{
Parse(us / 1000000ULL);
uint n = us % 1000000ULL;
@ -320,7 +320,7 @@ DateTime::DateTime()
memset(&Year, 0, &Microsecond - &Year + sizeof(Microsecond));
}
DateTime::DateTime(ulong seconds)
DateTime::DateTime(UInt64 seconds)
{
if(seconds == 0)
memset(&Year, 0, &Microsecond - &Year + sizeof(Microsecond));
@ -329,7 +329,7 @@ DateTime::DateTime(ulong seconds)
}
// 重载等号运算符
DateTime& DateTime::operator=(ulong seconds)
DateTime& DateTime::operator=(UInt64 seconds)
{
Parse(seconds);
@ -347,9 +347,9 @@ uint DateTime::TotalSeconds()
return s;
}
ulong DateTime::TotalMicroseconds()
UInt64 DateTime::TotalMicroseconds()
{
ulong sec = (ulong)TotalSeconds();
UInt64 sec = (UInt64)TotalSeconds();
uint us = (uint)Millisecond * 1000 + Microsecond;
return sec * 1000 + us;
@ -437,7 +437,7 @@ void TimeWheel::Reset(uint seconds, uint ms, uint us)
// 是否已过期
bool TimeWheel::Expired()
{
ulong now = Time.Current();
UInt64 now = Time.Current();
if(now > Expire) return true;
if(now == Expire && Time.CurrentTicks() >= Expire2) return true;

18
Time.h
View File

@ -15,7 +15,7 @@ private:
public:
uint Seconds; // 全局秒数。累加
ulong Milliseconds; // 全局毫秒数。累加
UInt64 Milliseconds; // 全局毫秒数。累加
uint BaseSeconds; // 基准秒数。时间调节影响Now()
byte Ticks; // 每微秒的时钟滴答数
byte Index; // 定时器
@ -35,8 +35,8 @@ public:
void Init();
uint CurrentTicks() const; // 当前滴答时钟
ulong Current() const; // 当前毫秒数
void SetTime(ulong seconds); // 设置时间
UInt64 Current() const; // 当前毫秒数
void SetTime(UInt64 seconds); // 设置时间
void Sleep(uint ms, bool* running = NULL) const;
// 微秒级延迟
@ -68,7 +68,7 @@ public:
class TimeCost
{
public:
ulong Start; // 开始时间,毫秒
UInt64 Start; // 开始时间,毫秒
ushort StartTicks; // 开始滴答
TimeCost();
@ -92,15 +92,15 @@ public:
ushort Microsecond;
DateTime();
DateTime(ulong seconds);
DateTime(UInt64 seconds);
// 重载等号运算符
DateTime& operator=(ulong seconds);
DateTime& operator=(UInt64 seconds);
DateTime& Parse(ulong seconds);
DateTime& ParseUs(ulong us);
DateTime& Parse(UInt64 seconds);
DateTime& ParseUs(UInt64 us);
uint TotalSeconds();
ulong TotalMicroseconds();
UInt64 TotalMicroseconds();
virtual String& ToStr(String& str) const;

View File

@ -78,7 +78,7 @@ uint TinyIP::Fetch(Stream& ms)
// 获取第一个结构体,不要移动指针
ETH_HEADER* eth = ms.Retrieve<ETH_HEADER>(false);
ulong v = eth->DestMac.Value();
UInt64 v = eth->DestMac.Value();
// 广播地址有效,直接返回
if(!v || v == 0xFFFFFFFFFFFFFFFFull) return len;

View File

@ -40,7 +40,7 @@ class TinyIP : public ISocketHost
{
private:
ITransport* _port;
ulong _StartTime;
UInt64 _StartTime;
ByteArray Buffer; // 缓冲区
// 循环调度的任务,捕获数据包,返回长度

View File

@ -21,7 +21,7 @@ public:
ushort Type; // 设备类型。两个字节可做二级分类
ByteArray Password; // 通讯密码
ulong LastActive; // 最后活跃时间
UInt64 LastActive; // 最后活跃时间
ushort HardCrc; // 硬件ID校验
bool Encryption; // 是否加密

View File

@ -721,7 +721,7 @@ void TinyController::Loop()
// 检查时间。至少发送一次
if(node.Times > 0)
{
ulong now = Sys.Ms();
UInt64 now = Sys.Ms();
// 已过期则删除
if(node.EndTime < now || node.Times > 50)
@ -771,7 +771,7 @@ void TinyController::Loop()
// 计算下一次重发时间
{
ulong now = Sys.Ms();
UInt64 now = Sys.Ms();
//node.LastSend = now;
// 随机延迟。随机数1~5。每次延迟递增
@ -834,7 +834,7 @@ void MessageNode::Set(const TinyMessage& msg, int msTimeout)
Times = 0;
//LastSend = 0;
ulong now = Sys.Ms();
UInt64 now = Sys.Ms();
StartTime = now;
EndTime = now + msTimeout;

View File

@ -64,7 +64,7 @@ class RingQueue
public:
int Index;
ushort Arr[32];
ulong Expired; // 过期时间,微秒
UInt64 Expired; // 过期时间,微秒
RingQueue();
void Push(ushort item);
@ -104,10 +104,10 @@ public:
byte Times; // 发送次数
byte Data[64];
byte Mac[6]; // 物理地址
ulong StartTime; // 开始时间ms
ulong EndTime; // 过期时间ms
ulong Next; // 下一次重发时间ms
//ulong LastSend; // 最后一次发送时间ms
UInt64 StartTime; // 开始时间ms
UInt64 EndTime; // 过期时间ms
UInt64 Next; // 下一次重发时间ms
//UInt64 LastSend; // 最后一次发送时间ms
void Set(const TinyMessage& msg, int msTimeout);
};

View File

@ -28,7 +28,7 @@ void DeviceMessage::Write(Stream& ms) const
// 密码取MD5后传输
ms.WriteArray(MD5::Hash(Key));
ulong now = Sys.Ms();
UInt64 now = Sys.Ms();
//Salt.Set((byte*)&now, 8);
//ms.WriteArray(Salt);
ms.WriteArray(Array(&now, 8));

View File

@ -14,7 +14,7 @@ public:
ushort Version; // 版本
String Type; // 类型
String Name; // 名称
ulong LocalTime; // 时间ms
UInt64 LocalTime; // 时间ms
IPEndPoint EndPoint;
ByteArray Ciphers;

View File

@ -37,7 +37,7 @@ void LoginMessage::Write(Stream& ms) const
ms.WriteArray(Salt);
else
{
ulong now = Sys.Ms();
UInt64 now = Sys.Ms();
ms.WriteArray(MD5::Hash(Array(&now, 8)));
}
}

View File

@ -32,7 +32,7 @@ void RegisterMessage::Write(Stream& ms) const
ms.WriteArray(Salt);
else
{
ulong now = Sys.Ms();
UInt64 now = Sys.Ms();
ms.WriteArray(MD5::Hash(Array(&now, 8)));
}
}

View File

@ -464,7 +464,7 @@ void TokenClient::Ping()
TokenMessage msg(3);
ulong time = Sys.Ms();
UInt64 time = Sys.Ms();
Stream ms = msg.ToStream();
ms.WriteArray(Array(&time, 8));
msg.Length = ms.Position();
@ -479,8 +479,8 @@ bool TokenClient::OnPing(TokenMessage& msg, Controller* ctrl)
Stream ms = msg.ToStream();
ulong now = Sys.Ms();
ulong start = ms.ReadArray().ToUInt64();
UInt64 now = Sys.Ms();
UInt64 start = ms.ReadArray().ToUInt64();
int cost = (int)(now - start);
if(cost < 0) cost = -cost;
if(cost > 1000) ((TTime&)Time).SetTime(start / 1000);

View File

@ -19,8 +19,8 @@ public:
int Status; // 状态。0准备、1握手完成、2登录后
ulong LoginTime; // 登录时间ms
ulong LastActive; // 最后活跃时间ms
UInt64 LoginTime; // 登录时间ms
UInt64 LastActive; // 最后活跃时间ms
int Delay; // 心跳延迟。一条心跳指令从发出到收到所花费的时间
Controller* Control;
@ -80,8 +80,8 @@ public:
IPEndPoint Addr; // 地址
int Status; // 状态。0准备、1握手完成、2登录后
ulong LoginTime; // 登录时间ms
ulong LastActive; // 最后活跃时间ms
UInt64 LoginTime; // 登录时间ms
UInt64 LastActive; // 最后活跃时间ms
};
#endif

View File

@ -100,7 +100,7 @@ private:
{
public:
byte Code;
ulong Time; // 时间ms
UInt64 Time; // 时间ms
};
QueueItem _Queue[16];

View File

@ -3,7 +3,6 @@
#include <math.h>
#include <stdarg.h>
#include "Sys.h"
#include "Platform\stm32.h"
/******************************** Object ********************************/
@ -597,7 +596,7 @@ int ByteArray::Load(const void* data, int maxsize)
// 从普通字节数据组加载,首字节为长度
int ByteArray::Save(void* data, int maxsize) const
{
assert_param(_Length <= 0xFF);
assert_param2(_Length <= 0xFF, "_Length <= 0xFF");
byte* p = (byte*)data;
int len = _Length <= maxsize ? _Length : maxsize;
@ -644,17 +643,17 @@ uint ByteArray::ToUInt32() const
return p[0] | (p[1] << 8) | (p[2] << 0x10) | (p[3] << 0x18);
}
ulong ByteArray::ToUInt64() const
UInt64 ByteArray::ToUInt64() const
{
auto p = GetBuffer();
// 字节对齐时才能之前转为目标整数
if(((int)p & 0x07) == 0) return *(ulong*)p;
if(((int)p & 0x07) == 0) return *(UInt64*)p;
uint n1 = p[0] | (p[1] << 8) | (p[2] << 0x10) | (p[3] << 0x18);
p += 4;
uint n2 = p[0] | (p[1] << 8) | (p[2] << 0x10) | (p[3] << 0x18);
return n1 | ((ulong)n2 << 0x20);
return n1 | ((UInt64)n2 << 0x20);
}
void ByteArray::Write(ushort value, int index)
@ -677,12 +676,23 @@ void ByteArray::Write(int value, int index)
Copy(index, (byte*)&value, sizeof(int));
}
void ByteArray::Write(ulong value, int index)
void ByteArray::Write(UInt64 value, int index)
{
Copy(index, (byte*)&value, sizeof(ulong));
Copy(index, (byte*)&value, sizeof(UInt64));
}
/******************************** REV ********************************/
uint _REV(uint value) { return __REV(value); }
ushort _REV16(ushort value) { return __REV16(value); }
//uint _REV(uint value) { return __REV(value); }
//ushort _REV16(ushort value) { return __REV16(value); }
__asm uint _REV(uint value)
{
rev16 r0, r0
bx lr
}
__asm ushort _REV16(ushort value)
{
rev16 r0, r0
bx lr
}

6
Type.h
View File

@ -9,7 +9,7 @@ typedef char sbyte;
typedef unsigned char byte;
typedef unsigned short ushort;
typedef unsigned int uint;
typedef unsigned long long ulong;
typedef unsigned long long UInt64;
typedef long long Int64;
#define UInt64_Max 0xFFFFFFFFFFFFFFFFull
@ -348,12 +348,12 @@ public:
ushort ToUInt16() const;
uint ToUInt32() const;
ulong ToUInt64() const;
UInt64 ToUInt64() const;
void Write(ushort value, int index = 0);
void Write(short value, int index = 0);
void Write(uint value, int index = 0);
void Write(int value, int index = 0);
void Write(ulong value, int index = 0);
void Write(UInt64 value, int index = 0);
//friend bool operator==(const ByteArray& bs1, const ByteArray& bs2);
//friend bool operator!=(const ByteArray& bs1, const ByteArray& bs2);