Path: ns-mx!uunet!comp.vuw.ac.nz!actrix!David.Empson From: David.Empson@actrix.gen.nz (David Empson) Newsgroups: comp.sys.apple2 Subject: Re: Pascal question Keywords: pascal question Message-ID: <1991Aug21.134832.23864@actrix.gen.nz> Date: 21 Aug 91 13:48:32 GMT References: <5386@batman.moravian.EDU> Organization: Actrix Information Exchange, Wellington, New Zealand Lines: 78 Comment-To: pongitoM@batman.moravian.EDU In article <5386@batman.moravian.EDU> pongitoM@batman.moravian.EDU (That Guy) writes: > > This may sound like a stupid question, but, how do you get input > from the keyboard without holding up the program (as in READLN). I > can't seem to find the answer in my Orca/pascal manual. Is there a > toolbox command. Is this in a 'vanilla' or 'desktop' program? If the latter, you should be using the Event Manager anyway. If you are writing a vanilla or shell program, and you have the ORCA/M assembler, it is probably easiest to write some assembly language functions to do the trick. The following functions are based on the example at the bottom of page 69 of the ORCA/Pascal manual. You will need the ORCA/M assembler to use this. If you like, I can send you a library containing these functions, so that they can be linked automatically (you will still need to declare them as external). The Pascal program should include these declarations: function Keypress: boolean; extern; function GetKey: char; extern; To use the functions: if Keypress then begin ch := GetKey; { do whatever you want to with the key } end; At the end of the source file, including the line: {$append 'keyboard.asm'} The assembly language file (keyboard.asm): ; ; Return the status of the keyboard strobe ; Keypress start sep #$20 ; Set accumulator to 8-bit mode lda >$C000 ; Get keypress pending flag (bit 7) asl a ; Put the flag into Carry rep #$20 ; Back to 16-bit mode lda #0 rol a ; Get the keypress flag into bit 0 rtl end ; ; Return a key (if one has been pressed) ; GetKey start sep #$20 ; Set accumulator to 8-bit mode lda >$C000 ; Read the keyboard register bmi IsKey ; If negative, there is a keypress rep #$20 ; Back to 16-bit mode lda #$0000 ; No keypress - return 0 rtl IsKey anop sta >$C010 ; Keypress - clear the strobe rep #$20 ; Back to 16-bit mode and #$007F ; Drop the 'key pending' bit rtl end I hope this helps somewhat. E-Mail me if you have any further questions. -- David Empson USENET: David.Empson@bbs.actrix.gen.nz