Skip to content

Poking the DOS Keyboard Buffer

Vector 4:2, page 92

system interfaces

Transcribed from the printed issue; not yet reviewed. Read it in the PDF of the issue, page 92

Here is something for all you PC freaks out there. You may remember that DOS has this thing called a keyboard buffer. APL generally ignores this (unless you run with E=2), so anything you put there in the APL session stays around until you sign off.

The buffer is but 15 characters long, so you can’t do a great deal with it, but one obvious possibility is to fire up a batch file on exit from your APL system. The little function listed below will insert up to 15 chars in the buffer, replacing anything that already happens to be there. As far as I know it will work on anything PC compatible and is quite harmless in all other respects.

     SHOVE TXT;XX
     ------------

[1]  ⍝ Shove text into DOS keyboard buffer.
[2]  ⍝ Maximum length is 15 chars

[3]   TXT←,TXT ⋄ TXT←(15⌊⍴TXT)↑TXT
[4]   TXT←,TXT,[1.5]'↓'
[5]   XX←(¯1+⎕AV⍳TXT)∆POKE '041E'

[6]  ⍝ Set head and tail of buffer ...

[7]   XX←30 ∆POKE '041A'
[8]   XX←(30+⍴TXT)∆POKE '041C'
     ∇

e.g. SHOVE 'MENU' ⋄ ⎕SA←'OFF'   ⍝ Exit, then run MENU.BAT


     WAS←BYTES ∆POKE LOC;SEG;⎕ELX;N
     ------------------------------

[1]       ⍝ Poke to Hex location LOC for N bytes
[2]       ⍝ Offset defaults to low memory

[3]        ⎕ELX←'⎕DM ⋄ →Exit'
[4]        LOC←⍕LOC ⋄ ⎕SEG←0 ⋄ BYTES←,BYTES ⋄ LEN←⍴BYTES

[5]       ⍝ Check for offset in form 'F000:1234' and set ⎕SEG ...

[6]        →(':'∊LOC)↓Base
[7]        SEG←4↑LOC ⋄ LOC←5↓LOC ⋄ ⎕SEG←16⊥¯1+'0123456789ABCDEF'⍳SEG
[8]  Base:LOC←16⊥¯1+'0123456789ABCDEF'⍳LOC
[9]        WAS←BYTES ⎕POKE ¯1+LOC+⍳LEN
[10] Exit:⎕SEG←⍳0
     ∇