Keyboard Buffer

Discuss all aspects of programming here. From 8-bit through to modern architectures.
Post Reply
Coeus
Posts: 1033
Joined: Mon Jul 25, 2016 11:05 am
Contact:

Keyboard Buffer

Post by Coeus » Tue Apr 10, 2018 9:32 am

Does anyone know what is buffered in the keyboard buffer on the BBC? Is it ASCII characters or keycodes? I'll have a dig in the OS disassembly later, if not.

User avatar
MartinB
Posts: 4948
Joined: Mon Mar 31, 2008 9:04 pm
Location: Obscurity
Contact:

Re: Keyboard Buffer

Post by MartinB » Tue Apr 10, 2018 10:13 am

I often needs to pull things out of the command line for my utility programs and the the characters are always in readable ASCII - the buffer is in the $700 region for BASIC (&3E00-&3FF for OS) but there's OS calls to dynamically find the start address and to pull characters (I think!).

User avatar
jgharston
Posts: 3212
Joined: Thu Sep 24, 2009 11:22 am
Location: Whitby/Sheffield
Contact:

Re: Keyboard Buffer

Post by jgharston » Tue Apr 10, 2018 4:23 pm

Keycodes. Eg *FX138,0,145 will put Shift-f1 in the keyboard buffer, *FX138,0,32 will put SPACE in the keyboard buffer. No need to disassemble the MOS, just check the manual.
MartinB wrote:I often needs to pull things out of the command line for my utility programs and the the characters are always in readable ASCII - the buffer is in the $700 region for BASIC (&3E00-&3FF for OS) but there's OS calls to dynamically find the start address and to pull characters (I think!).
No, the keyboard buffer is in MOS workspace, not in language workspace, and it is at &03E0-&03FF, see AllMem. &700 is BASIC's command input buffer, not the MOS's keyboard buffer. All the MOS workspace is in, well, MOS workspace, not in language workspace.

Code: Select all

$ bbcbasic
PDP11 BBC BASIC IV Version 0.25
(C) Copyright J.G.Harston 1989,2005-2015
>_

User avatar
MartinB
Posts: 4948
Joined: Mon Mar 31, 2008 9:04 pm
Location: Obscurity
Contact:

Re: Keyboard Buffer

Post by MartinB » Tue Apr 10, 2018 5:38 pm

:roll:
JGH wrote:No, the keyboard buffer is in MOS workspace, not in language workspace, and it is at &03E0-&03FF
Read my reply - I said exactly that.
and wrote:&700 is BASIC's command input buffer
I said that too and I was being helpful with extra information.

crj
Posts: 834
Joined: Thu May 02, 2013 4:58 pm
Contact:

Re: Keyboard Buffer

Post by crj » Wed Apr 11, 2018 12:14 am

It's neither key codes nor ASCII. Things are a tiny bit more complicated than that.

Most things in the keyboard buffer itself (the thing you insert into using *FX138) are simple ASCII characters or control codes. They're not keyboard raster codes, and considerations like SHIFT, CTRL, SHIFT LOCK and CAPS LOCK have already been factored in. This is good - it means that whether you get 'A' or 'a' depends on whether SHIFT was held when you pressed 'A', not whether it's being pressed when the key is extracted from the buffer.

The awkward wrinkle is the soft keys: F0-F9, Break, Copy, Left, Right, Up, Down. (*FX4 controls whether or not the Copy and the cursor keys are actually soft keys.) These are assigned numbers &0 to &F. When you press one, a code in the range &80-&8F is placed in the keyboard buffer. Shift+key inserts &90-&9F, Ctrl+key &A0-&AF and Shift+Ctrl+key &B0-&BF.

However, although those are the values that enter the keyboard buffer, they're not what you get when you call OSRDCH. Whenever the OS gets a soft key code out of the keyboard buffer, it uses the *FX225-*FX228 settings to control what happens. It might ignore the code entirely, it might expand the soft key using its corresponding *KEY setting, or it might return the character code which was configured by *FX225-*FX228.

Coeus
Posts: 1033
Joined: Mon Jul 25, 2016 11:05 am
Contact:

Re: Keyboard Buffer

Post by Coeus » Wed Apr 11, 2018 11:13 am

Thanks, everyone I now have what I need from this. What I was actually working on was "paste from clipboard as if typed" in B-Em. Simulating keystrokes works but is very speed limited. Tom Seddon hooks OSRDCH in b2 and that is much faster but does not self-start, i.e. at the moment you choose paste from the menu the OS is already within OSRDCH looking for a character from the keyboard buffer so I had the idea to hook the buffer remove routine instead so, if the pasting from clipboard and the buffer number in X is zero, i.e. keyboard buffer, I set the return values from the clipboard and force the CPU to do an RTS instead. It seems to work well.

crj
Posts: 834
Joined: Thu May 02, 2013 4:58 pm
Contact:

Re: Keyboard Buffer

Post by crj » Wed Apr 11, 2018 12:32 pm

It might be more polite and more robust to insert the keystrokes into the buffer. That will work even if someone's installed different buffering code, and means what you insert ends up queued behind anything that's already pending.

You could hook into the RTI instruction. If pasting then, before executing the instruction, set AXY aside, invoke INSV, check the carry flag to see if the insertion succeeded, restore AXY, continue.

Post Reply