📄 datetime.hhf
字号:
hhmm24, badTimeFormat }; timerec: record; secs :uns8; mins :uns8; hours :uns16; endrecord; duration: record; secs :int8; mins :int8; hours :int16; endrecord; static TimeFormat :OutputFormat; @external( "TIME_FORMAT" ); // _isTimeRec_- // // This is a utility macro that returns true or false // depending upon whether the parameter is a time.timerec // object. This is for internal use within this header file. #macro _isTimeRec_( _tr_ ); #if( @typename( _tr_ ) = "timerec" ) #if ( @defined( _tr_.hours ) & @defined( _tr_.mins ) & @defined( _tr_.secs ) ) true #else false #endif #else false #endif #endmacro // _isHMS_ // // This is another utility macro. It checks its parameters // to ensure that they are all valid h:m:s types. #macro _isHMS_( _h_, _m_, _s_ ):_error_; ?_error_ := !hla.isNumber( _h_ ) | !hla.isNumber( _m_) | !hla.isNumber( _s_); #if( !_error_ ) ?_error_ := ( !@IsConst( _m_ ) & @size( _m_ ) <> 1 ) | ( !@IsConst( _s_ ) & @size( _s_ ) <> 1 ) | ( !@IsConst( _h_ ) & @size( _h_ ) <> 2 ); #endif (!_error_) #endmacro // validate- // // Checks the time passed as a parameter to see if it is valid. // Raises the "ex.InvalidTime" exception if it is not valid. // // Note that time.validate is a macro that overloads the // time._validate procedure, allowing a timerec or (h,m,s) // parameters to be passed. procedure _validate( tm:timerec ); @external( "TIME_VALIDATE" ); #macro validate( _h_, _ms_[] ); #if( @elements( _ms_ ) = 0 ) // _h_ had better be a timerec object // if we had only one parameter. #if( @global:time._isTimeRec_( _h_ )) @global:time._validate( _h_ ) #else #error( "Expected a timerec type as the parameter" ) #endif #elseif( @elements( _ms_ ) = 2 ) #if( @global:time._isHMS_( _h_, @text( _ms_[0]), @text( _ms_[1]))) pushw( @text(_h_) ); sub( 2, esp ); push( eax ); mov( @text(_ms_[0]), al ); mov( @text(_ms_[1]), ah ); mov( ax, [esp+4] ); pop( eax ); call @global:time._validate; #else #error( "Syntax error in time.validate parameter list" ); #endif #else #error ( "Error in time.validate parameter list" nl "Usage: time.validate( tm:timerec ) or " nl " time.validate( h:word; m:byte; s:byte )" ) #endif #endmacro // time.unpack- // // The first parameter is a time.timerec object. The remaining // parameters are dword objects. This macro unpacks the time // in the timerec parameter into its constituent parts. // No range checking is done on the date value. #macro unpack( tm, _h_, _m_, _s_ ); #if( !@global:time._isTimeRec_( tm ) ) #error( "Expected a time.timerec type as the 1st parameter" ) #elseif ( !( hla.IsNumber( _h_ ) & @size(_h_) = 4 ) & !( hla.IsNumber( _m_ ) & @size(_m_) = 4 ) & !( hla.IsNumber( _s_ ) & @size(_s_) = 4 ) ) #error( "Hours, Mins, and Secs values must be dword objects" ) #else push( eax ); movzx( tm.hours, eax ); mov( eax, _h_ ); movzx( tm.mins, eax ); mov( eax, _m_ ); movzx( tm.secs, eax ); mov( eax, _s_ ); pop( eax ); #endif #endmacro // time.pack- // // This macro takes three dword objects representing the // hours, minutes, and seconds and packs these values into a // timerec variable. Minimal range checking is done on the // time value. val hoursStr :string := ""; minsStr :string := ""; secsStr :string := ""; #macro pack( _hrs_, _mins_, _secs_, _tm_ ); ?@global:time.hoursStr := @lowercase( @string:_hrs_, 0); ?@global:time.minsStr := @lowercase( @string:_mins_, 0); ?@global:time.secsStr := @lowercase( @string:_secs_, 0); #if( !@global:time._isTimeRec_( _tm_ )) #error( "Expected a time.timerec type as the 4th parameter" ) // Handle the special case where _mins_ and _secs_ are both constants: #elseif( @isconst(_secs_) & @isconst(_mins_)) #if( (_secs_) > 59 | (_mins_) > 59 ) #error( "Minutes or Seconds value is out of range" ) #endif #if( @isconst( _hrs_ )) #if( (_hrs_) > 23 ) #error( "Hours value is out of range" ) #endif mov( (_secs_) + ((_mins_) << 8) + ((_hrs_)<<16), _tm_ ); #elseif( @isreg16( _hrs_ )) mov( (_secs_) + ((_mins_) << 8), (type word _tm_)); mov( _hrs_, _tm_.hours ); #else push( eax ); mov( (_secs_) + ((_mins_) << 8), (type word _tm_)); mov( _hrs_, ax ); mov( ax, _tm_.hours ); pop( eax ); #endif #elseif( @isreg8(_mins_) & @isreg8(_secs_)) #if ( @substr( @global:time.secsStr, 1, 1 ) = "l" & @substr( @global:time.minsStr, 1, 1 ) = "h" & @substr( @global:time.secsStr, 0, 1 ) = @substr( @global:time.minsStr, 0, 1 ) ) mov ( @text ( @substr ( @global:time.secsStr, 0, 1 ) + "x" ), (type word _tm_)); #else mov( _secs_, _tm_.secs ); mov( _mins_, _tm_.mins ); #endif #if( @isreg16(_hrs_) | @isconst(_hrs_) ) mov( _hrs_, _tm_.hours ); #else push( eax ); mov( (type word _hrs_), ax ); mov( ax, _tm_.hours ); pop( eax ); #endif #else push( eax ); // Special case -- we might use EAX // for the minutes and seconds stuff, so // if the hours was passed in AX, store // that away first. #if( @global:time.hoursStr = "ax" ) mov( ax, _tm_.hours ); #endif // Okay, deal with the seconds: #if( @isconst( _secs_ ) ) #if( (_secs_) <= 31 & (_secs_) > 0 ) mov( _secs_, al ); #else #error( "Seconds value is out of range" ); #endif #elseif( @global:time.secsStr <> "al" ) mov( (type byte _secs_), al ); #endif #if( @isconst( _mins_ ) ) #if( (_mins_) <= 12 & (_mins_) > 0 ) mov( _mins_, ah ); #else #error( "Minutes value is out of range" ); #endif #elseif( @global:time.minsStr = "al" ) mov( (type byte [esp]), ah ); #elseif( @global:time.minsStr <> "ah" ) mov( (type byte _mins_), ah ); #endif mov( ax, (type word _tm_)); #if( @isconst( _hrs_ ) ) #if( (_hrs_) < 24 ) mov( _hrs_, _tm_.hours ); #else #error( "Hours value is out of range" ); #endif #elseif( @isreg16( _hrs_ )) // Note: the case where the hours was // passed in AX was handled earlier. #if( @global:time.hoursStr <> "ax" ) mov( _hrs_, _tm_.hours ); #endif #else mov( (type word _hrs_), ax ); mov( ax, _tm_.hours ); #endif pop( eax ); #endif #endmacro // IsValid- // // Checks the time passed as a parameter to see if it is valid. // Returns true/false in AL to denote the validity of the parameter. // // Note that time.IsValid is a macro that overloads the // time._IsValid procedure, allowing a timerec or (h,m,s) // parameters to be passed. procedure _isValid( tm:timerec ); @returns( "al" ); @external( "TIME_ISVALID" ); #macro isValid( _h_, _ms_[] ); #if( @elements( _ms_ ) = 0 ) // _h_ had better be a timerec object // if we had only one parameter. #if( @global:time._isTimeRec_( _h_ ) ) @global:time._isValid( _h_ ) #else #error( "Expected a time.timerec type as the parameter" ) #endif #elseif( @elements( _ms_ ) = 2 ) #if( @global:time._isHMS_( _h_, @text( _ms_[0] ), @text( _ms_[1]))) @global:time._isValid ( #{ pushw( @text(_h_) ); sub( 2, esp ); push( eax ); mov( @text(_ms_[0]), al ); mov( @text(_ms_[1]), ah ); mov( ax, [esp+4] ); pop( eax ); }# ) #else #error( "Syntax error in IsValid parameter list" ) #endif #else #error ( "Error in time.isValid parameter list" nl "Usage: time.isValid( tm:timerec ) or " nl " time.isValid( h:word; m:byte; s:byte )" ) #endif #endmacro procedure durationToSecs( hours:word; mins:byte; secs:byte ); @returns( "eax" ); @external( "TIME_DURATIONTOSECS" ); procedure secsToDuration ( seconds :uns32; var hours :word; var mins :byte; var secs :byte ); @external( "TIME_SECSTODURATION" ); procedure addSecs( seconds:uns32; var HMS:timerec ); @returns( "eax" ); @external( "TIME_ADDSECS" ); procedure addMins( minutes:uns32; var HMS:timerec ); @returns( "eax" ); @external( "TIME_ADDMINS" ); procedure addHours( hours:uns32; var HMS:timerec ); @returns( "eax" ); @external( "TIME_ADDHOURS" ); procedure subSecs( seconds:uns32; var HMS:timerec ); @external( "TIME_SUBSECS" ); procedure subMins( minutes:uns32; var HMS:timerec ); @external( "TIME_SUBMINS" ); procedure subHours( hours:uns32; var HMS:timerec ); @external( "TIME_SUBHOURS" ); procedure secsBetweenTimes( time1:timerec; time2:timerec ); @returns( "eax" ); @external( "TIME_SECSBETWEENTIMES" ); procedure toString( HMS:timerec; dest:string ); @external( "TIME_TOSTRING" ); procedure a_toString( HMS:timerec ); @returns( "eax" ); @external( "TIME_A_TOSTRING" ); procedure toWinFileTime( DMY:@global:date.daterec; HMS:timerec ); @returns( "edx:eax" ); @external( "TIME_TOWINFILETIME" ); procedure fromWinFileTime ( winTime:qword; var HMS:timerec; var DMY:@global:date.daterec ); @external( "TIME_FROMWINFILETIME" ); procedure toUnixTime( DMY:@global:date.daterec; HMS:timerec ); @returns( "edx:eax" ); @external( "TIME_TOUNIXTIME" ); procedure fromUnixTime ( unixTime :qword; var HMS :timerec; var DMY :@global:date.daterec ); @external( "TIME_FROMUNIXTIME" ); procedure setFormat( f:OutputFormat ); @external( "TIME_SETFORMAT" ); procedure curTime( var HMS:timerec ); @external( "TIME_CURTIME" ); procedure utcTime( var HMS:timerec ); @external( "TIME_UTCTIME" ); procedure fromSecs( seconds:uns32; var HMS:timerec ); @external( "TIME_FROMSECS" ); procedure _toSecs( HMS:timerec ); @returns( "eax" ); @external( "TIME_TOSECS" ); #macro toSecs( _h_, _ms_[] ); #if( @elements( _ms_ ) = 0 ) // _h_ had better be a timerec object // if we had only one parameter. #if( @global:time._isTimeRec_( _h_ ) ) @global:time._toSecs( _h_ ) #else #error ( "toSecs expected a timerec type as the parameter" ) #endif #elseif( @elements( _ms_ ) = 2 ) @global:time._toSecs ( #{ pushw( _h_ ); sub( 2, esp ); push( eax ); mov( @text(_ms_[0]), ah ); mov( @text(_ms_[1]), al ); mov( ax, [esp+4] ); pop( eax ); }# ) #else #error ( "Error in hmsToSecs parameter list" ) #endif #endmacroend time;#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -