Microsoft KB Archive/37312: Difference between revisions
(importing KB archive) |
m (Text replacement - "&" to "&") |
||
Line 53: | Line 53: | ||
* The Date2Secs ROM function<br /> | * The Date2Secs ROM function<br /> | ||
<br /> | <br /> | ||
This function takes a given date/time record, (a0& | This function takes a given date/time record, (a0&), which is the pointer to the date/time record, and converts it to the corresponding seconds since midnight of January 1, 1904. The result is put in the argument (d0&). The dayofweek field can be ignored for this function. See code example 1 below. | ||
* The Secs2Date ROM function<br /> | * The Secs2Date ROM function<br /> | ||
<br /> | <br /> | ||
This function takes the number of seconds since midnight, January 1, 1904, (d0& | This function takes the number of seconds since midnight, January 1, 1904, (d0&) and converts it to the corresponding date and time, returning it in the date/time record argument, (a0&), which is the pointer to the date/time record. See code example 2 below. | ||
Note: Further below are examples of how to use the date and time conversion functions listed above. | Note: Further below are examples of how to use the date and time conversion functions listed above. | ||
Line 69: | Line 69: | ||
</pre> | </pre> | ||
You can make a register-based ROM call in the following manner | You can make a register-based ROM call in the following manner | ||
<pre class="codesample"> ToolBox "R",trapnum%,returnarray& | <pre class="codesample"> ToolBox "R",trapnum%,returnarray&(0),(a0&),(a1&),(d0&),(d1&),(d2&) | ||
</pre> | </pre> | ||
where the following is true: | where the following is true: | ||
Line 78: | Line 78: | ||
trapnum% -- is the trap number for the ROM routine.<br /> | trapnum% -- is the trap number for the ROM routine.<br /> | ||
<br /> | <br /> | ||
returnarray& | returnarray&(0) -- will contain the contents of the registers a0&, a1&, d0&, d1&, d2& (in order) after the ROM call. This array must be dimensioned to five elememts.<br /> | ||
<br /> | <br /> | ||
The arguments a0& | The arguments a0&, a1&, d0&, d1&, d2& are arguments whose values are passed into the registers before the ROM call. | ||
</div> | </div> | ||
Note: The arguments and returnarray& | Note: The arguments and returnarray&(0) are optional. They depend upon whether you need to use a particular register and whether there is a return value.<br /> | ||
<br /> | <br /> | ||
The Date2Secs and Secs2Date functions use the following date/time record structure (based in Pascal): | The Date2Secs and Secs2Date functions use the following date/time record structure (based in Pascal): | ||
Line 117: | Line 117: | ||
' forget this statement, you get "Invalid Function Call" | ' forget this statement, you get "Invalid Function Call" | ||
' Example of invoking Date2Secs function. | ' Example of invoking Date2Secs function. | ||
DIM returnarray& | DIM returnarray&(5) 'Must be at least 5 to handle the | ||
'five arguments for register ROM calls. | 'five arguments for register ROM calls. | ||
DIM DateTimeRec%(6) 'set up date/time record | DIM DateTimeRec%(6) 'set up date/time record | ||
trapnum% = & | trapnum% = &HA9C7 'trapnum for Date2Secs function | ||
d0& | d0& = 0 'initialization | ||
DateTimeRec%(0) = 1904 'fill date/time record | DateTimeRec%(0) = 1904 'fill date/time record | ||
DateTimeRec%(1) = 1 | DateTimeRec%(1) = 1 | ||
Line 129: | Line 129: | ||
DateTimeRec%(5) = 40 | DateTimeRec%(5) = 40 | ||
DateTimeRec%(6) = 6 | DateTimeRec%(6) = 6 | ||
ToolBox "R",trapnum%,returnarray& | ToolBox "R",trapnum%,returnarray&(0),DateTimeRec%(0) | ||
' Note: The only parameter needed is DateTimeRec%, which is passed | ' Note: The only parameter needed is DateTimeRec%, which is passed | ||
' through the a0& | ' through the a0& register as noted by its position. | ||
PRINT returnarray& | PRINT returnarray&(2), "seconds have elapsed since 01-01-04" | ||
</pre> | </pre> | ||
The code example above gives the following output: | The code example above gives the following output: | ||
Line 144: | Line 144: | ||
<pre class="codesample"> ' Secs2Date function example: | <pre class="codesample"> ' Secs2Date function example: | ||
DIM datetimerec%(6) | DIM datetimerec%(6) | ||
trapnum% = & | trapnum% = &HA9C6 'trap number for Secs2Date | ||
d0& | d0& = 10000 'time in seconds | ||
ToolBox "i" | ToolBox "i" | ||
a0& | a0& = VARPTR(datetimerec%(0)) | ||
ToolBox "R",trapnum%,,(a0& | ToolBox "R",trapnum%,,(a0&),,(d0&) | ||
' NOTE: since no return value is needed, returnarray%(0) is omitted. | ' NOTE: since no return value is needed, returnarray%(0) is omitted. | ||
PRINT "the year is ";datetimerec%(0) | PRINT "the year is ";datetimerec%(0) |
Latest revision as of 14:13, 21 July 2020
Article ID: 37312
Article Last Modified on 10/20/2003
APPLIES TO
- Microsoft QuickBasic Compiler for Macintosh 1.0
- Microsoft QuickBasic Compiler for Macintosh 1.0
- Microsoft QuickBasic Compiler for Macintosh 1.0
This article was previously published under Q37312
SUMMARY
This article provides an example of calling Macintosh register-based ROM functions with the ToolBox statement in QuickBasic versions 1.0, 1.0a, and 1.0b for the Apple Macintosh.
This article discusses date and time conversion functions, which are register-based ROM calls accessible with the QuickBasic Toolbox statement. The following register-based ROM calls pass arguments in Macintosh machine registers:
- The Date2Secs ROM function
This function takes a given date/time record, (a0&), which is the pointer to the date/time record, and converts it to the corresponding seconds since midnight of January 1, 1904. The result is put in the argument (d0&). The dayofweek field can be ignored for this function. See code example 1 below.
- The Secs2Date ROM function
This function takes the number of seconds since midnight, January 1, 1904, (d0&) and converts it to the corresponding date and time, returning it in the date/time record argument, (a0&), which is the pointer to the date/time record. See code example 2 below.
Note: Further below are examples of how to use the date and time conversion functions listed above.
MORE INFORMATION
You can access Date2Secs and Secs2Date from within a QuickBasic program with the ToolBox statement. The ToolBox statement must first be initialized (only once within a program) with the following statement:
ToolBox "i" 'case is not significant
You can make a register-based ROM call in the following manner
ToolBox "R",trapnum%,returnarray&(0),(a0&),(a1&),(d0&),(d1&),(d2&)
where the following is true:
"R" -- is for "register call."
trapnum% -- is the trap number for the ROM routine.
returnarray&(0) -- will contain the contents of the registers a0&, a1&, d0&, d1&, d2& (in order) after the ROM call. This array must be dimensioned to five elememts.
The arguments a0&, a1&, d0&, d1&, d2& are arguments whose values are passed into the registers before the ROM call.
Note: The arguments and returnarray&(0) are optional. They depend upon whether you need to use a particular register and whether there is a return value.
The Date2Secs and Secs2Date functions use the following date/time record structure (based in Pascal):
TYPE DateTimeRec = year: integer; {1904 to 2040} month: integer; {1 to 12 for January to December} day: integer; {1 to 31} hour: integer; {0 to 23) minute: integer; {0 to 59} second: integer; {0 to 59} dayofweek: integer; {1 to 7 for Sunday to Saturday} END;
In Basic, use an integer array to represent this structure, as in the following example:
DIM DateTimeRec%(6)
where:
DateTimeRec%(0) represents DateTimeRec.year DateTimeRec%(1) represents DateTimeRec.month DateTimeRec%(2) represents DateTimeRec.day DateTimeRec%(3) represents DateTimeRec.hour DateTimeRec%(4) represents DateTimeRec.minute DateTimeRec%(5) represents DateTimeRec.second DateTimeRec%(6) represents DateTimeRec.dayofweek
For additional information, see sections E.10.3 to E.10.3.5 of the "Microsoft QuickBASIC for the Apple Macintosh: Language Reference."
See "Inside Macintosh Volume II" for trap numbers and descriptions of routines.
Code Example 1
Toolbox "i" ' Required to initialized toolbox routines; if you ' forget this statement, you get "Invalid Function Call" ' Example of invoking Date2Secs function. DIM returnarray&(5) 'Must be at least 5 to handle the 'five arguments for register ROM calls. DIM DateTimeRec%(6) 'set up date/time record trapnum% = &HA9C7 'trapnum for Date2Secs function d0& = 0 'initialization DateTimeRec%(0) = 1904 'fill date/time record DateTimeRec%(1) = 1 DateTimeRec%(2) = 1 DateTimeRec%(3) = 2 DateTimeRec%(4) = 46 DateTimeRec%(5) = 40 DateTimeRec%(6) = 6 ToolBox "R",trapnum%,returnarray&(0),DateTimeRec%(0) ' Note: The only parameter needed is DateTimeRec%, which is passed ' through the a0& register as noted by its position. PRINT returnarray&(2), "seconds have elapsed since 01-01-04"
The code example above gives the following output:
Code Example 2
' Secs2Date function example: DIM datetimerec%(6) trapnum% = &HA9C6 'trap number for Secs2Date d0& = 10000 'time in seconds ToolBox "i" a0& = VARPTR(datetimerec%(0)) ToolBox "R",trapnum%,,(a0&),,(d0&) ' NOTE: since no return value is needed, returnarray%(0) is omitted. PRINT "the year is ";datetimerec%(0) PRINT "month ";datetimerec%(1); " of the year" PRINT "day ";datetimerec%(2); " of the month" PRINT "the time is ";datetimerec%(3);" hours "; datetimerec%(4); PRINT " minutes ";datetimerec%(5);" seconds military time" PRINT "this is day ";datetimerec%(6); " in the week"
The code example above gives the following output:
Additional query words: MQuickB 1.00 1.00a 1.00b
Keywords: KB37312