[Oberon] Re (2): Input.Timer in Native Oberon

peter at easthope.ca peter at easthope.ca
Sat Jan 30 16:42:41 CET 2016


From:	Chris Burrows <chris at cfbsoftware.com>, Fri, 29 Jan 2016 08:04:10 +1030
> ... values 100 and 12 have a certain significance in this context? 

Serial port speed 1200 appears in a few places.  Obviously no connection.
Sorry but 100 and 12 are magic numbers.  2% docked from grade for each.

If i is too large, the "key mouse" will over-respond.  One click and the arrow 
will be at the edge of the display.  If i is too small "key mouse" will under-respond. 
In the extant calculation of i, if powers of 10 are considered in the divisor, 10 is 
too small and 1000 is too large.  So "100" is OK?  The "12"?  Who knows, but see following.

> PixelCount = 1024 * 768; (* Better than PixelCount = 786432; *)

You might be astonished at the number of students in a first 
year class who don't recognize "1024 * 768".  A helpful 
reference wouldn't be a crime.

PixelCount = 1024 * 768; (* https://en.wikipedia.org/wiki/Display_resolution *)

> ... better to let the code speak for itself.

Absolutely!  I gave names to the magic numbers.  Initialized 
counter1 right after counter0.  The outmost IF statement was in 
reverse chronological order.  Reversed it for clarity.  Also, 
when kpmap * {0..2, 4, 6, 8..10} = {}, incrementing i and 
checking the four displacements is pointless.

MODULE Input;
...
CONST
	TimeUnit* = 1000;	(** portable, but VAR on other ports *)	(** timer ticks per second (platform dependent). *)
	KPpollinterval = TimeUnit DIV 100;  (* KP = keypad.  Used as pseudo mouse. *)
	KPdivisor = 8; (* counter0 per pixel. *)
	KPspeedMax = 100; (* Maximal counter0. *)
... 
PROCEDURE *Timer;
	VAR i: INTEGER;
BEGIN
	IF counter1 < KPpollinterval THEN
		INC(counter1)
	ELSE
		counter1 := 0;
		IF kpmap * {0..2, 4, 6, 8..10} = {} THEN 
			counter0 := 0
		ELSE 
			IF counter0 < KPspeedMax THEN INC(counter0) END;
			i := counter0 DIV KPdivisor + 1;
			IF kpmap * {0,4,8} # {} THEN DEC(kdx, i) END;
			IF kpmap * {0,1,2} # {} THEN DEC(kdy, i) END;
			IF kpmap * {2,6,10} # {} THEN INC(kdx, i) END;
			IF kpmap * {8,9,10} # {} THEN INC(kdy, i) END
		END
	END
END Timer;

BEGIN
		... counter0 := 0; counter1 := 0; ...
END Input.

How's that?  

Incidentally, Timer is not an enlightening name for the procedure.
Too general.  It does more than time.  KPpointer?  KPcontroller?
Many names could say more than "Timer".

Regards,                 ... 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



More information about the Oberon mailing list