Wait for 5secs or leave with keypress...

All 680x0 related coding posts in this section please.

Moderators: exxos, simonsunnyboy, Mug UK, Zorro 2, Moderator Team

User avatar
simonsunnyboy
Moderator
Moderator
Posts: 4873
Joined: Wed Oct 23, 2002 4:36 pm
Location: Friedrichshafen, Germany
Contact:

Wait for 5secs or leave with keypress...

Postby simonsunnyboy » Fri Sep 18, 2015 4:40 pm

Hello all,

I'm a bit stuck with a small piece of m68k.
I want to code a loop, waiting for 5secs max, the loop is to be aborted on keypress. I do not want to use direct hardware access or polling the _hz_200 variable directly.

Is there a cheap and simple way available?

Regards,
ssb
Simon Sunnyboy/Paradize - http://paradize.atari.org/ - STOT: http://www.npoi.de/stot/

Stay cool, stay Atari!

1x2600jr, 1x1040STFm, 1x1040STE 4MB+TOS2.06+SatanDisk, 1xF030 14MB+FPU+NetUS-Bee

Jabber: simonsunnyboy@atari-jabber.org

User avatar
mfro
Atari Super Hero
Atari Super Hero
Posts: 689
Joined: Thu Aug 02, 2012 10:33 am
Location: SW Germany

Re: Wait for 5secs or leave with keypress...

Postby mfro » Fri Sep 18, 2015 4:57 pm

Code: Select all

while Cconis() Cconin();       /* empty keyboard buffer */
start = Tgettime();

while (!Cconis() && Tgettime() <= start + 2);
Cconin();                      /* empty keyboard buffer again */


(off head, not tested, but should do the trick)

Why do you want to avoid reading _hz_200? There is no other easy way in TOS (apart from setting up an MFP timer yourself using Xbtimer() or direct MFP programming) to measure time. Even the GEMDOS way above _is not_ exactly what you want because GEMDOS can measure time in 2 sec intervals only (so it's either 4 or 6 seconds).

User avatar
simonsunnyboy
Moderator
Moderator
Posts: 4873
Joined: Wed Oct 23, 2002 4:36 pm
Location: Friedrichshafen, Germany
Contact:

Re: Wait for 5secs or leave with keypress...

Postby simonsunnyboy » Fri Sep 18, 2015 5:24 pm

Tgettime() sounds like a good solution, 2secs intervals are ok.
I want to avoid using Super() in my case, that'S why I don't want to poll _hz_200 directly.

Thank you!
Simon Sunnyboy/Paradize - http://paradize.atari.org/ - STOT: http://www.npoi.de/stot/

Stay cool, stay Atari!

1x2600jr, 1x1040STFm, 1x1040STE 4MB+TOS2.06+SatanDisk, 1xF030 14MB+FPU+NetUS-Bee

Jabber: simonsunnyboy@atari-jabber.org

User avatar
mfro
Atari Super Hero
Atari Super Hero
Posts: 689
Joined: Thu Aug 02, 2012 10:33 am
Location: SW Germany

Re: Wait for 5secs or leave with keypress...

Postby mfro » Fri Sep 18, 2015 5:50 pm

Tgettime() bit 0-4 wraps around at 30 (=60 seconds) instead of 31, so above code will be off by 2 seconds occasionally.

This one is cleaner:

Code: Select all

long get_time(void)
{
    return * _hz_200;
}

long timer(void)
{
    return Supexec(get_time);
}
...
start = timer();
while (!Cconis() && timer() <= start + 5 * Tickcal());

User avatar
Mikefulton
Captain Atari
Captain Atari
Posts: 169
Joined: Sun Nov 29, 2015 10:27 am

Re: Wait for 5secs or leave with keypress...

Postby Mikefulton » Fri Dec 11, 2015 6:51 am

If this is a GEM app, just do event-multi with a 5 second timer and a keypress event specified.

wietze
Captain Atari
Captain Atari
Posts: 190
Joined: Fri Mar 01, 2013 10:52 pm

Re: Wait for 5secs or leave with keypress...

Postby wietze » Fri Dec 11, 2015 9:25 am

Whats against counting vbls?

User avatar
shoggoth
Nature
Nature
Posts: 856
Joined: Tue Aug 01, 2006 9:21 am
Location: Halmstad, Sweden
Contact:

Re: Wait for 5secs or leave with keypress...

Postby shoggoth » Fri Dec 11, 2015 10:58 am

VBL frequencies vary.
Ain't no space like PeP-space.

User avatar
simonsunnyboy
Moderator
Moderator
Posts: 4873
Joined: Wed Oct 23, 2002 4:36 pm
Location: Friedrichshafen, Germany
Contact:

Re: Wait for 5secs or leave with keypress...

Postby simonsunnyboy » Thu Apr 14, 2016 4:17 pm

Short answer: I decided to poll _hz_200 directly and it doesn't make any fuss. I actually implemented the thing in C now, my menu does not use assembly code for this.
Simon Sunnyboy/Paradize - http://paradize.atari.org/ - STOT: http://www.npoi.de/stot/

Stay cool, stay Atari!

1x2600jr, 1x1040STFm, 1x1040STE 4MB+TOS2.06+SatanDisk, 1xF030 14MB+FPU+NetUS-Bee

Jabber: simonsunnyboy@atari-jabber.org


Social Media

     

Return to “680x0”

Who is online

Users browsing this forum: No registered users and 1 guest