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