[minix3] How to type Ctrl-@ to mark begin of a block in Mined?

96 views
Skip to first unread message

PaulD

unread,
Apr 28, 2010, 11:53:57 PM4/28/10
to minix3
I was exploring Minix 3.1.7 when I began to test mined editor.
man mined tell me that I should be able to mark the beginning of a
block with Ctrl-@
I am using 'plain' us-std keyboard, so @ is above key for 2, so that
would be like Ctrl-Shift-2
I tried Ctrl-2 but that does not seems to work.

In fact I tried most keys, waiting to see the 'Mark set' in status
line, but never had it.

So that whenever I try to copy, kill or yank (paste) I get message
'Mark not set'

I ve look a bit at the code. In mined1.c MA() (MArk function) seems to
be bound to ASCII 0

But well, I am used to Ctrl-A be for ASCII 0, but Ctrl-A is go to the
beginning of line.

Any help someone can give me?

Also, I suppose the 50 KB limit of mined was for 16 bits system, and
now it should be around 4 GB, right?

--
You received this message because you are subscribed to the Google Groups "minix3" group.
To post to this group, send email to min...@googlegroups.com.
To unsubscribe from this group, send email to minix3+un...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/minix3?hl=en.

Antoine LECA

unread,
Apr 29, 2010, 3:56:58 AM4/29/10
to min...@googlegroups.com
PaulD wrote:
> I was exploring Minix 3.1.7 when I began to test mined editor.
> man mined tell me that I should be able to mark the beginning of a
> block with Ctrl-@

Ctrl-@ is a real need to be supported if you want to work with mined.

> I am using 'plain' us-std keyboard, so @ is above key for 2, so that
> would be like Ctrl-Shift-2

Since the beginning of the IBM PC in 1981, the standard association for
Ctrl-@ (^@, NUL) is Ctrl+2.

Having said that, as you saw in the maps, many keys end being mapped as
NUL as well; lately I noticed the "Logo" keys (as known as the Win keys
after their keycaps) do that too.

> I tried Ctrl-2 but that does not seems to work.

I noticed that too on certain versions and releases. Unfortunately,
I was not able to get a clear map of when it worked or not (I am a big
fan of mined, so I end trying on almost any versions of Minix I test).
For example, on my home computer with 3.1.3a, it did not worked so
I went tracing the codepath, found a strange case where "0" keypresses
were dropped, fixed that and I got back Ctrl+@ working; some time later,
I installed the same 3.1.3a from the CD (ie, unpatched) on another
computer, and I found the key working :+0
Similar cases occurred with recent releases.

This definitively need more work, but I am out of ideas.


> I ve look a bit at the code. In mined1.c MA() (MArk function) seems to
> be bound to ASCII 0

Correct.

> But well, I am used to Ctrl-A be for ASCII 0, but Ctrl-A is go to the
> beginning of line.

No; if you look at the ASCII map, A is hexa 41, a is hexa 61, and as a
result Ctrl+A (SOH) is 1; OTOH, @ is hexa 40, and logically Ctrl+@ is 0.


> Also, I suppose the 50 KB limit of mined was for 16 bits system, and
> now it should be around 4 GB, right?

Yes :-). With virtual memory I do not know exactly (probably 2GB).
With non-VM version of Minix like the 3.1.3 I alluded above, I usually
increase the chmem of mined to 150 KB or sometimes more, to be a bit
more than the size of the biggest source files around; works great.


Antoine

PaulD

unread,
Jun 6, 2010, 2:01:38 AM6/6/10
to minix3
On Apr 29, 3:56 am, Antoine LECA <Antoine.Lec...@gmail.com> wrote:
> PaulD wrote:
> > I was exploring Minix 3.1.7 when I began to test mined editor.
> > man mined tell me that I should be able to mark the beginning of a
> > block with Ctrl-@
>
> Ctrl-@ is a real need to be supported if you want to work withmined.
>
> > I am using 'plain' us-std keyboard, so @ is above key for 2, so that
> > would be like Ctrl-Shift-2
>
> Since the beginning of the IBM PC in 1981, the standard association for
> Ctrl-@ (^@, NUL) is Ctrl+2.
>
> Having said that, as you saw in the maps, many keys end being mapped as
> NUL as well; lately I noticed the "Logo" keys (as known as the Win keys
> after their keycaps) do that too.
>
> > I tried Ctrl-2 but that does not seems to work.

Thinking a bit more about this, I suspect there is no way to type a
character having ASCII code 0 on a keymap where @ is defined with
Shift, as in US-ASCII keyboard. My guess is that mined was designed
in a country using a keymap where @ is a normal key, rather than a
Shifted key.
That's why asking me to type Ctrl-@ is weird for me in the first
place, I can only type Ctrl-Shift-2.

I guess I would suggest to use Ctrl-[ for MA (MArk beginning of a
block) rather than Ctrl-@.
Ctrl-[ seems to be mapped to the function I (Ignore this keystroke),
just before Ctrl-] which is GOTO line.
Well, I did not test (was on a CD, hard to edit a file on a CD).

Does it make sense?

Antoine LECA

unread,
Jun 7, 2010, 4:31:13 AM6/7/10
to min...@googlegroups.com
PaulD wrote:
> Thinking a bit more about this, I suspect there is no way to type a
> character having ASCII code 0 on a keymap where @ is defined with
> Shift, as in US-ASCII keyboard.

I fail to understand your reasonment.
The notation Ctrl-@, Ctrl-[ etc. and also the ^@, ^[ representations,
are just convenient shorthands based on the ASCII chart map; there are
no reasons to have them linked to the US keyboard layout (which predates
ASCII by about one century).
For example, the same layout is used with EBCDIC machines; and on each
layout, being ASCII or EBCDIC, the character Ctrl-[ is got by pressing a
unshifted key (labelled Esc) which is far away from the actual [{ key.


> My guess is that mined was designed in a country using a keymap
> where @ is a normal key, rather than a Shifted key.

That is true, but I hear that computer people in Nederland prefer the US
layout to the official Dutch, because of the easier access to ] { }.
As a matter of fact, MINIX does not include the keymap for that keyboard
and the usage(8) man page explains that patches for this are not welcome
(seek for Dutch), although it might reflect Kees' personal opinion.
In fact, I am not even sure that keyboard layout was available (in
hardware, ie the key engravings) for the original PC with 83-key layout
which with Minix and mined was designed.


> That's why asking me to type Ctrl-@ is weird for me in the first
> place, I can only type Ctrl-Shift-2.

As I said, you should try Ctrl-2, without hitting the Shift key.


> I guess I would suggest to use Ctrl-[ for MA (MArk beginning of a
> block) rather than Ctrl-@.

I am not sure it would work (but I did not test either): ESC (the
character behind the Ctrl-[ combination) is used by the tty driver as
prefix for all the "extended keys" (including the function and the
movement keys), as stated in the ANSI X.40 standard and the traditional
terminal protocol used with *nix.

> Ctrl-[ seems to be mapped to the function I (Ignore this keystroke),

I read it mapped to ESC. What is mapped to I is the combination Ctrl-\,
which have two disadvantages:
* some non-US keyboard layout maps do not have the combination enabled
(but this is easy enough to solve);
* Ctrl-\ is traditionally associated on *nix to sending the QUIT signal
to the foreground task (see the tty(4) man page.)


Antoine

PaulD

unread,
Jun 7, 2010, 10:43:06 AM6/7/10
to minix3
> As I said, you should try Ctrl-2, without hitting the Shift key.
Well, I now see that I get an error on Ctrl-2, but only the first time
I pressed it after booting Minix:
tty: ignoring unrecognized straight scancode 0x3

And it looks like it is ignored after that, I see it when I try to
Ctrl-K inside it mined, it told me that Mark was not set, even if I
just tried to mark a position with Ctrl-2 before.

So I guess this message come from the tty driver, does it just means
there is no ASCII code result registered in the keymap for scancode
0x3 ? (Hoping that this question make sense to you)

BTW, where is the normal us keymap defined?

PaulD

unread,
Jun 7, 2010, 11:01:57 AM6/7/10
to minix3
Well, the message ignoring unrecognized straight scancode 0x3 was easy
to find.
Here is the function from /trunk/src/drivers/tty/keyboard.c:
/
*===========================================================================*
* make_break *

*===========================================================================*/
PRIVATE unsigned make_break(scode)
int scode; /* scan code of key just struck or released */
{
/* This routine can handle keyboards that interrupt only on key
depression,
* as well as keyboards that interrupt on key depression and key
release.
* For efficiency, the interrupt routine filters out most key
releases.
*/
int ch, make, escape;
static int CAD_count = 0;
static int rebooting = 0;

/* Check for CTRL-ALT-DEL, and if found, halt the computer. This
would
* be better done in keyboard() in case TTY is hung, except control
and
* alt are set in the high level code.
*/
if (ctrl && alt && (scode == DEL_SCAN || scode == INS_SCAN))
{
if (++CAD_count == 3) {
cons_stop();
sys_abort(RBT_HALT);
}
sys_kill(INIT_PROC_NR, SIGABRT);
rebooting = 1;
}

if(rebooting)
return -1;

/* High-order bit set on key release. */
make = (scode & KEY_RELEASE) == 0; /* true if pressed */

ch = map_key(scode &= ASCII_MASK); /* map to ASCII */

escape = esc; /* Key is escaped? (true if added since the XT) */
esc = 0;

switch (ch) {
case CTRL: /* Left or right control key */
*(escape ? &ctrl_r : &ctrl_l) = make;
ctrl = ctrl_l | ctrl_r;
break;
case SHIFT: /* Left or right shift key */
*(scode == RSHIFT_SCAN ? &shift_r : &shift_l) = make;
shift = shift_l | shift_r;
break;
case ALT: /* Left or right alt key */
*(escape ? &alt_r : &alt_l) = make;
alt = alt_l | alt_r;
if (sticky_alt_mode && (alt_r && (alt_down < make))) {
locks[ccurrent] ^= ALT_LOCK;
}
alt_down = make;
break;
case CALOCK: /* Caps lock - toggle on 0 -> 1 transition */
if (caps_down < make) {
locks[ccurrent] ^= CAPS_LOCK;
set_leds();
}
caps_down = make;
break;
case NLOCK: /* Num lock */
if (num_down < make) {
locks[ccurrent] ^= NUM_LOCK;
set_leds();
}
num_down = make;
break;
case SLOCK: /* Scroll lock */
if (scroll_down < make) {
locks[ccurrent] ^= SCROLL_LOCK;
set_leds();
}
scroll_down = make;
break;
case EXTKEY: /* Escape keycode */
esc = 1; /* Next key is escaped */
return(-1);
default: /* A normal key */
if(!make)
return -1;
if(ch)
return ch;
{
static char seen[2][NR_SCAN_CODES];
int notseen = 0, ei;
ei = escape ? 1 : 0;
if(scode >= 0 && scode < NR_SCAN_CODES) {
notseen = !seen[ei][scode];
seen[ei][scode] = 1;
} else {
printf("tty: scode %d makes no sense\n", scode);
}
if(notseen) {
printf("tty: ignoring unrecognized %s "
"scancode 0x%x\n",
escape ? "escaped" : "straight", scode);
}
}
return -1;
}

/* Key release, or a shift type key. */
return(-1);
}
----------------

And I guess this is the realed keymap info from /trunk/src/drivers/tty/
keymaps/us-std.src:
/* 03 - '2' */ '2', '@', A('2'), A('2'), A('@'), C('@'),

Well, many other keys have C('@'):
/* 13 - '=' */ '=', '+', A('='), A('='), A('+'), C('@'),
/* 51 - ',' */ ',', '<', A(','), A(','), A('<'), C('@'),
/* 52 - '.' */ '.', '>', A('.'), A('.'), A('>'), C('@'),
/* 53 - '/' */ '/', '?', A('/'), A('/'), A('?'), C('@'),
/* 86 - ??? */ '<', '>', A('<'), A('|'), A('>'), C('@'),

Well, I am not sure I understand why it did not entered the:
switch (ch) {
case CTRL: /* Left or right control key */
but I guess for a more knowing person than me, it would be easier to
see.

Antoine LECA

unread,
Jun 7, 2010, 11:48:26 AM6/7/10
to min...@googlegroups.com
PaulD wrote:
> Here is the function from /trunk/src/drivers/tty/keyboard.c:
<snip>

> ch = map_key(scode &= ASCII_MASK); /* map to ASCII */

So here, we got the code for the key, and it would be NUL, right?


> escape = esc; /* Key is escaped? (true if added since the XT) */
> esc = 0;
>
> switch (ch) {

...snipping irrelevant cases...


> default: /* A normal key */
> if(!make)
> return -1;
> if(ch)
> return ch;
> {
> static char seen[2][NR_SCAN_CODES];
> int notseen = 0, ei;
> ei = escape ? 1 : 0;

/*there*/


> if(scode >= 0 && scode < NR_SCAN_CODES) {
> notseen = !seen[ei][scode];
> seen[ei][scode] = 1;
> } else {
> printf("tty: scode %d makes no sense\n", scode);
> }
> if(notseen) {
> printf("tty: ignoring unrecognized %s "
> "scancode 0x%x\n",
> escape ? "escaped" : "straight", scode);
> }
> }
> return -1;
> }

The problem is in that small snippet: as you see, when ch is 0, there
are no difference between "ignore this key" (which returns -1, at the
bottom) and "this generates NUL" (which ought to return 0), so the
latter case is dropped on the floor. :-(

The fix is up to you. Personnally, I went the hacky way, hardcoding the
mapping scancode 3 to NUL, inserting at /*there*/ something like

if( scode == 3 )
return '\0'; /* Ctrl+2 returns NUL */
else

(in my code, 3 is replaced by NUL_SCAN which I #defined around line 65,
but the idea is the same.)


> /* Key release, or a shift type key. */
> return(-1);
> }
> ----------------
>
> And I guess this is the realed keymap info from /trunk/src/drivers/tty/
> keymaps/us-std.src:

Yes, this is correct.

> /* 03 - '2' */ '2', '@', A('2'), A('2'), A('@'), C('@'),
>
> Well, many other keys have C('@'):

... but there, it rather means "ignore that key".
And yes, this is probably a bad design which tries to shoehorse all the
char value AND the error condition inside a char object, something which
is know to _always_ leave some orphaned character code... just that NUL
is a rather bad choice IMHO.
Now we are not constrained by the 640KB of the original PC, perhaps it
might be time to revise this? And while at it, perhaps using Unicode to
encode the characters, this would permit to undo the current link
between the keyboard mapping and the on-screen characters, at the cost
of some reverse mapping later in the stack, in map_key or make_break
At least, .keymap do have a magic number, so we can upgrade into a new
version without breaking everything...


> Well, I am not sure I understand why it did not entered the:
> switch (ch) {
> case CTRL: /* Left or right control key */

This is how works the IBM PC: it sends an interrupt at each key press,
known as 'make event'; and also at each key release ('break event');
when you hit Ctrl-2, you actually send four events (unordered):
* make for CTRL (code 0x28 or 0x36)
* make for 2 (code 3)
* break for 2 (code 0x83)
* break for CTRL (code 0xA8 or 0xB6, matching the first one)

The only event which is eventually delivered to the client is the
second, the others are swallowed by the make_break() function.

Hope it is clearer for you now.


Antoine

Reply all
Reply to author
Forward
0 new messages