[comp.sys.mac.hypercard] Reaction Time stacks : can I do this?

phil@mva.cs.liv.ac.uk (12/05/88)

Here at Liverpool University a number of students are doing project work
involving Hypercard.  One of the projects involves the writing of reaction
timing stacks.  What I would like to know is:
1) is it possible to write an XCMD/XFCN to await a keypress and to time
more accurately than 1/60th of a second, and return this info to a script.
2) One of the reaction timing stacks is supposed to play a sound on a
background of white noise.  Can an XCMD/XFCN play noise + a simple tone and
do (1) above?

I've written some Mac programs (nothing good enough to post) but I've never
tried to write any XCMDs/XFCNs.

Phil Jimmieson,           ***************************************************
Computer Science Dept.,   *        ** Note New Address & UserName **        *
Liverpool University,     * JANET : PHIL@UK.AC.LIV.CS.MVA                   *
Merseyside, England,      * ARPA  : PHIL%mva.cs.liv.ac.uk@cunyvm.cuny.edu   *
L69  3BX                  *                                                 *
                          * old address SQPHIL@UK.AC.LIV.CSVAX may work     *
(UK) 051-794-3689         ***************************************************

dan@Apple.COM (Dan Allen) (12/07/88)

In article <6012@mva.cs.liv.ac.uk> phil@mva.cs.liv.ac.uk writes:
>1) is it possible to write an XCMD/XFCN to await a keypress and to time
>more accurately than 1/60th of a second, and return this info to a script.

Yes, an XCMD can measure event timing to finer intervals.  You would
need to write some tricky code to use one of the VIA internal
millisecond timers.

>2) One of the reaction timing stacks is supposed to play a sound on a
>background of white noise.  Can an XCMD/XFCN play noise + a simple tone and
>do (1) above?

This may be possible, but I am not sure.  Sound and the VIA timers are
somewhat esoteric stuff that unfortunately is not documented as well as
it could be: lots of munging is required to get things working right.
At least that's what I would have to do...

Dan Allen
Apple

korn@tehran.berkeley.edu (Peter "Arrgh" Korn) (12/07/88)

In <21792@apple.Apple.COM>, dan@Apple.COM (Dan Allen) said:  
>In article <6012@mva.cs.liv.ac.uk> phil@mva.cs.liv.ac.uk writes:
>>1) is it possible to write an XCMD/XFCN to await a keypress and to time
>>more accurately than 1/60th of a second, and return this info to a script.
>
>Yes, an XCMD can measure event timing to finer intervals.  You would
>need to write some tricky code to use one of the VIA internal
>millisecond timers.

Alternately instead of writing tricky assembly code that would do nasty,
CPU depending things like talk to hardware, you could use the Time Manager
calls (Inside Mac vol IV pp 299-301) to get 1 millisecond accuracy.  If I'm
not mistaken, this requires that your machine be running version 4.2 or
later of the System, but since that's needed for Hypercard anyway, that 
shouldn't be a problem.


Peter
--
Peter "Arrgh" Korn
korn@ucbvax.Berkeley.EDU
{decvax,hplabs,sdcsvax,ulysses,usenix}!ucbvax!korn

lsr@Apple.COM (Larry Rosenstein) (12/07/88)

In article <21792@apple.Apple.COM> dan@Apple.COM (Dan Allen) writes:
>In article <6012@mva.cs.liv.ac.uk> phil@mva.cs.liv.ac.uk writes:
>>1) is it possible to write an XCMD/XFCN to await a keypress and to time
>>more accurately than 1/60th of a second, and return this info to a script.
>
>Yes, an XCMD can measure event timing to finer intervals.  You would
>need to write some tricky code to use one of the VIA internal
>millisecond timers.

It is easier to use the Time Manager that to hack with the hardware
directly.  With the Time Manager you can have an interrupt routine called
every milisecond.  The routine can simply increment a counter to provide a
more accurate time base.

-- 
		 Larry Rosenstein,  Object Specialist
 Apple Computer, Inc.  20525 Mariani Ave, MS 46-B  Cupertino, CA 95014
	    AppleLink:Rosenstein1    domain:lsr@Apple.COM
		UUCP:{sun,voder,nsc,decwrl}!apple!lsr

dan@Apple.COM (Dan Allen) (12/07/88)

Yes, use the Time Manager rather than write to the VIA directly, I
suppose.  I forgot about the Time Manager because I was around when they
wrote the Time Manager and I remember all the problems that early
versions had... and then they fixed them all and now it works great.
But for some reason I still remembered its beginnings back in the
"halcyon days" of the Mac Plus in late 1985 and thought "write to the
VIA yourself".  Actually, when I talk about writing directly to the VIA
I do not mean hard code an address, which is what everyone gets all
excited about when they talk about writing directly to hardware.  That
is just plain stupid.  What I mean is, get the low-memory global pointer
which points to where the VIA lives and then use the chip, which works
fine on all of our computers.  The only other problem, however, is that
some machines use more of the VIA than do others, so the Time Manager
really is the best way in the end.  End of historic-melancholic look at
the past.

Dan Allen
Apple

tim@hoptoad.uucp (Tim Maroney) (12/08/88)

These were not particularly helpful replies.  It seems one can indeed
do such a stack in HyperCard, but it would be more difficult than
writing an application to do the same thing.  The entire process has to
be done within an XCMD.  Consider the elements of a reaction time
test.  First you have to show something meant to cause a reaction; then
you have to determine when the reaction was given.

You can't do the display portion in a card -- the graphics tools and
commands to manipulate them may run at any speed.  You can't do the
reaction sensing using HyperCard's mouse or keyboard handling --
there's no way to tell when the reaction happened.  You can't draw
right into a card yourself -- the results are undefined.  So the XCMD
has to bring up a window, draw the whatever with QuickDraw, and then
monitor the mouse and keyboard watching for the reaction.  Where does
HyperCard come into it?  You have a button to give the XCMD and start
the test, and the results are written into a field or text file
somewhere.  These two things are just as easy to accomplish in an
application.

Applications are easier to write than XCMDs, so all in all it seems
you've lost a great deal by using HyperCard for such a thing.
-- 
Tim Maroney, Consultant, Eclectic Software, sun!hoptoad!tim
"Jesus died for somebody's sins, but not mine." -- Patti Smith

tgl@zog.cs.cmu.edu (Tom Lane) (12/09/88)

In article <21826@apple.Apple.COM>, dan@Apple.COM (Dan Allen) writes:
> [Use the Time Manager to get millisecond timing of keyboard events.]

I may be mistaken, but I thought that keyboard & mouse sensing was done by
the vertical retrace routines (in order to do debouncing conveniently).
This would imply that keyboard/mouse events would be posted at 1/60th second
intervals.

Hence hacking around with the Time Manager to get a millisecond time base
will buy you nothing: the events you are interested in are only reported to
1/60th second accuracy anyway.

You might be able to get around this by making a Time Manager-driven ISR
that directly interrogates the hardware, but that would mean you'd have to
do your own debouncing etc.  You'd also have a substantial risk of
interfering with the normal system input routines.

-- 
				tom lane
Internet: tgl@zog.cs.cmu.edu
UUCP: <your favorite internet/arpanet gateway>!zog.cs.cmu.edu!tgl
BITNET: tgl%zog.cs.cmu.edu@cmuccvma
-- 

fry@brauer.harvard.edu (David Fry) (12/09/88)

On SEs and Mac IIs, equipped with ADB interfaces, the
keyboard and mouse are accessed once every 10 ms, according to
Developer Services.  Events reported by {Get,Wait}NextEvent
also have to flow through the event queue, which can take a
few more milliseconds, but you can access mouse events more
quickly with Button, and you can use GetKeys for the keyboard.

In short, you can do things just a little faster than the 17
ms accorded with TickCount().

David Fry				fry@huma1.harvard.EDU
Department of Mathematics		fry@huma1.bitnet
Harvard University			...!harvard!huma1!fry
Cambridge, MA  02138		

oster@dewey.soe.berkeley.edu (David Phillip Oster) (12/10/88)

If you use a digitizing tablet connected to the Mac serial port at
19.2KBaud, you'll be talking at about 2kBytes a second. Since it takes
about 5 bytes for a tablet to send a position record (depends on the brand
of tablet.) it takes 2.5m sec to get the position data. This means that
you can't measure events that are closer together in time than that.
However, since the tablet introduces a uniform delay, and since it begins
transmitting as soon as the pen comes within range of the tablet,
you can measure events to an accuracy greater than 2.5ms. Just watch out
for tablet continuous mode: in this mode many tablets transmit as
infrequently as one hundred times a second.  

Once again, you'll need to draw the images yourself, rather than leaving
them for hypercard to draw, and be sure to allow for the fact that the
drawing is quantized in time by the video hardware to be no faster than 60
times a second.

--- David Phillip Oster            --"When we replace the mouse with a pen,
Arpa: oster@dewey.soe.berkeley.edu --3 button mouse fans will need saxophone
Uucp: {uwvax,decvax}!ucbvax!oster%dewey.soe.berkeley.edu --lessons." - Gasee

ts@cup.portal.com (Tim W Smith) (12/12/88)

Couldn't you use the Time Manager instead of fiddling with the VIA?
Have a routine called by the Time Manager that increments a global
variable and just check that?

						Tim Smith