Input.Timer in Native Oberon
From joerg.straube at iaeth.ch Tue Jan 12 11:31:53 2016 I like to move around the caret with my keyboard instead of the mouse ...
Input.Timer translates keypad arrow activation (KP-Right for example) to a displacement (INC(kdx, i) for example). For time interval counter0, the displacement increment is i := counter0 DIV (100 DIV 12)+1; Isn't 100 DIV 12 always 8? Why not this arithmetic? i := counter0 DIV 8+1; Thanks, ... Lyall E. -- 123456789 123456789 123456789 123456789 123456789 123456789 123456789 12 Tel +1 360 639 0202 http://easthope.ca/Peter.html Bcc: peter at easthope. ca
Am 28.01.2016 um 19:28 schrieb peter@easthope.ca:
For time interval counter0, the displacement increment is i := counter0 DIV (100 DIV 12)+1;
Isn't 100 DIV 12 always 8? Why not this arithmetic? i := counter0 DIV 8+1;
Usually the compiler does this. The object code should be the same. Peter
For time interval counter0, the displacement increment is i := counter0 DIV (100 DIV 12)+1;
Isn't 100 DIV 12 always 8? Why not this arithmetic? i := counter0 DIV 8+1;
Usually the compiler does this. The object code should be the same.
But not if it's i := counter0 DIV 100 * 12 + 1; so the original "why" still stands, right? :) Cheers, Paul
counter0 measures the time how long a cursor key is pressed with a granularity of 10 ms. The longer you keep the key pressed the faster the mouse moves. The IF limits counter0 to max 100 = 1 sec. If you write "counter0 DIV (100 DIV 12) + 1" the interpretation is as follows: Max speed at 1 second is 12 + 1 pixel. If you write "counter0 DIV 8 + 1" you say: All 80 ms the speed is increased by 1 pixel. I would have coded this procedure as follows: CONST Home = 0; UpArr = 1; PgUp = 2; LftArr = 4; RtArr = 6; End = 8; DnArr = 9; PgDn = 10; IF counter1 # TimeUnit DIV 100 THEN INC(counter1) ELSE (* check cursor keys all 10 ms *) counter1 := 0; IF kpmap * {0..2, 4, 6, 8..10} = {} THEN counter0 := 0 (* no cursor key *) ELSE IF counter0 < 100 THEN INC(counter0) END; (* max speed at 1 sec *) i := counter0 DIV (100 DIV 12) + 1; (* max speed is 12+1 pixel *) IF kpmap * {Home, LftArr, End} # {} THEN DEC(kdx, i) END; IF kpmap * {Home, UpArr, PgUp} # {} THEN DEC(kdy, i) END; IF kpmap * {PgUp, RtArr, PgDn} # {} THEN INC(kdx, i) END; IF kpmap * {End, DnArr, PgDn} # {} THEN INC(kdy, i) END END END br, Jörg Am 28.01.2016 um 20:16 schrieb Paul Reed <paulreed@paddedcell.com>:
For time interval counter0, the displacement increment is i := counter0 DIV (100 DIV 12)+1;
Isn't 100 DIV 12 always 8? Why not this arithmetic? i := counter0 DIV 8+1;
Usually the compiler does this. The object code should be the same.
But not if it's
i := counter0 DIV 100 * 12 + 1;
so the original "why" still stands, right? :)
Cheers, Paul
-- Oberon@lists.inf.ethz.ch mailing list for ETH Oberon and related systems https://lists.inf.ethz.ch/mailman/listinfo/oberon
-----Original Message----- From: Oberon [mailto:oberon-bounces@lists.inf.ethz.ch] On Behalf Of peter@easthope.ca Sent: Friday, 29 January 2016 4:58 AM To: oberon@lists.inf.ethz.ch Subject: [Oberon] Input.Timer in Native Oberon
From joerg.straube at iaeth.ch Tue Jan 12 11:31:53 2016
I like to move around the caret with my keyboard instead of the mouse ...
Input.Timer translates keypad arrow activation (KP-Right for example) to a displacement (INC(kdx, i) for example).
For time interval counter0, the displacement increment is i := counter0 DIV (100 DIV 12)+1;
Isn't 100 DIV 12 always 8? Why not this arithmetic? i := counter0 DIV 8+1;
I hven't looked at the code but presumably the values 100 and 12 have a certain significance in this context? If 100 DIV 12 is pre-evaluated to 8 then that information is no longer available to the reader of the code. The initial programmer would have to add a comment if they wanted to provide that information - better to let the code speak for itself. Other examples are: PixelCount = 1024 * 768; (* Better than PixelCount = 786432; *) answer := 42; (* Better than what? See The Hitchhiker's Guide to the Galaxy ;-) *) Regards, Chris Chris Burrows CFB Software http://www.cfbsoftware.com
participants (5)
-
Chris Burrows -
Jörg Straube -
Paul Reed -
Peter Matthias -
peter@easthope.ca