Article View: comp.lang.modula2
Article #3507Re: Help - Dedicating keys
From: Richard A Creed
Date: Sat, 20 Apr 1996 16:41
Date: Sat, 20 Apr 1996 16:41
127 lines
5756 bytes
5756 bytes
In article <4l4ikl$6vj@seagoon.newcastle.edu.au>, Peter Moylan (peter@fourier.newcastle.edu.au) writes:
>Richard A Creed (creed@bigsilver.win-uk.net) wrote:
>
Using FST 3.5, on a PC running DOS 6.22....
>>I would like to make one or more function keys availiable in a game
>>program I have written, sort of: F1 - Help (opens a window)
>> F2 - Rules (opens a window)
>> F3 - Exit Programme
>>(and perhaps make the esc key availiable to close the windows).
I should have said so that they would, in effect, be hotkeys.
>
>One traditional solution is to put the KeuPressed() call in
>your main loop, or somewhere where it's going to be executed
>frequently while the program is doing its other things, and
>then when a key is pressed you save the character value
>somewhere, and take a look at the saved value at some
>appropriate later place - probably at a place where you were
>going to get some keyboard input anyway.
This is not possible because the program demands user input
continuously, and demands by turns a CARDINAL or a CHAR with a
return key, because the keyed input must be editable.
Checking the input & then storing it in a buffer which emulates
keyboard input won't do the job, becuase the Function key reaction
must be instantaneous, whilst any other user input must be editable
and followed by the return. I would require something similar to
Peter's HotKeys but I am simply not experienced enough to port the
appropriate PMOS modules or bits of them.
>A superior solution is to write a separate thread for keyboard
>input, so that you can deal with keypresses asynchronously
>with other work.
This is really what I want to do. I have two options - either using
the kernel module which came with FST or using the rather nice
Semaphores Module which Pat Terry posted here last week. My
problem is that I don't know how to work with Semaphores, (or even
what they *are*, (though I think I have the gist of them
becuase I'm sure they're what I'll need for this...). I imagine that
I would have to set up a keychecking procedure as one thread
something like (as per Pat Terry's module)
StartProcess(KeyChecking, Size);
StartTasking(FALSE);
but what do I do with it after that? I half feel that my main
program should be defined as another process - but then I'd be
switching between the two rather than one being resident and
switched to inside the other. Everything I've tried lets the
KeyChecking process work fine but no multitasking occurs i.e the
KeyChecking process takes over. I dont know how to switch in and
out of the task. I have a feeling I should be using the SIGNAL and
WAIT procedures but none of the Modula2 books to which I have
access cover multitasking. What I really need to know is the
meaning and the syntactic application of working with Semaphores.
Pat Terry's Semaphores Module is defined thus, and I think that
someone who understands Semaphores would be likely to understand
it:
DEFINITION MODULE Semaphores;
(* Simple Semaphore based multi-tasking kernel *)
TYPE SEMAPHORE;
PROCEDURE StartProcess (P : PROC; N : CARDINAL);
(* Sets up a process with procedure P and workspace of size N
The process is not given control until StartTasking is invoked *)
PROCEDURE SIGNAL (VAR S : SEMAPHORE);
(* Signals semaphore S, and either returns first process on S to
ready status, or increases value associated with S *)
PROCEDURE WAIT (VAR S : SEMAPHORE);
(* Suspends calling process on S if associated value of S is zero *)
PROCEDURE SemInit (VAR S : SEMAPHORE; Count : CARDINAL);
(* Initializes semaphore S to have the associated value Count *)
PROCEDURE StartTasking (TimeSliced : BOOLEAN);
(* Launches a sequence of started processes, possibly TimeSliced *)
PROCEDURE EnterDos;
(* Protects Dos calls *)
PROCEDURE LeaveDos;
(* Allows other procedures to enter DOS *)
END Semaphores.
If someone who understands the principles of these procedures could
spare the time to give me some idea of how to apply them I'd be
grateful.
>The most flexible approach is to write your own keyboard
>handler, including your own interrupt routine, but of course
>it's a fair amount of work to get that right.
A little beyond me yet, I think...
>You can get some hints by looking at the PMOS source code,
>available by following the links in my signature below.
>Look particularly at modules Keyboard and MultiScreen.
>Modula-2 information at
> http://www.eng.newcastle.edu.au/ee/Moylan/m2/Modula2.html
Thankyou, Peter. Getting hold of all the source and library modules
I could find on the WWW was the first thing I did when I started
learning Modula2 (& programming) a couple of weeks ago. Your
site was the second place I visited, and of course I grabbed
everything that I could from you. It isn't very FST friendly (as
you admit) but it is educational and I am grateful. I've got to the
stage where if I knew how other compilers define SHORTCARD (which
my FST doesn't offer), I might be able to start porting some of it.
Richard
Richard Creed is at creed@bigsilver.win-uk.net
& once a week at cr589@gre.ac.uk
& always ? http://www.gre.ac.uk/~cr589/
Technical Details
Message-ID:
<278@bigsilver.win-uk.net>Path:
arc1-ca.pugleaf.net!laura.pcug.co.uk!bigsilver!creedReferences:
<273@bigsilver.win-uk.net><4l4ikl$6vj@seagoon.newcastle.edu.au>Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!laura.pcug.co.uk!bigsilver!creed Newsgroups: comp.lang.modula2 Message-ID: <278@bigsilver.win-uk.net> References: <273@bigsilver.win-uk.net><4l4ikl$6vj@seagoon.newcastle.edu.au> Reply-To: creed@bigsilver.win-uk.net (Richard A Creed) From: creed@bigsilver.win-uk.net (Richard A Creed) Date: Sat, 20 Apr 1996 16:41:11 GMT Subject: Re: Help - Dedicating keys