z88dk forums

z80 Development Kit

You are not logged in.

#1 2007-11-14 08:35:42

siggi
Well known member
Registered: 2007-07-26
Posts: 159

Local "echo" during input from keyboard

Using the current implementation of Z88DK makes input from keyboard using "scanf" hard, because there is no echo of the typed characters on the screen. And it is also not possible to correct/edit the input, before <cr> is pressed.

Example:

#include <stdio.h>

void main(void)
{
  int wert;
  printf("Wert=");
  scanf("%d", &wert);
  printf("\nRead: %d\n", wert);
}


This program (compiled with Borland C++ V3.1 and running on a pc) gives that result on the screen:

Wert=351

Read: 351


During reading (scanf) "wert" the typed characters are echoed to the screen and editing (at least backspace) that value during input is possible. After pressing <return> the last value remains on the screen.

Note: the typed <cr> after "351" seems also to be echoed -> 1 empty line

On systems with a real OS (OS-9, Unix), the line echo/edit function is embedded in the OS and is used on every read access (not only "scanf") to "terminal/console devices" (of course not, when files from disk are read).

The OS normally offers also a system-calls to enable/disable echoing (AFAIK "ss_opt" on OS-9 and "ioctl" on Unix), so that a program reading a password (e. g. "login") has the chance to hide the typed password.

Siggi


My ZX81 web-server, compiled with Z88DK V1.7:
http://zx81-siggi.endoftheinternet.org/index.html smile
Online since 2007 ...

Offline

 

#2 2007-11-14 09:08:55

dom
Administrator
Registered: 2007-07-15
Posts: 738
Website

Re: Local "echo" during input from keyboard

I think outside of z88dk scanf() cooks the terminal into line mode, but as you've spotted there's no such facility in z88dk.

All the z88dk scanf() does is to eventually call fgetc_cons() which is silent.

A way around this is to call fgets() which does offer primitive line editing facilities (fgets() calls fgets_cons() which for most platforms is a fairly noddy editor, but for those platforms with a bit more support (eg z88) you get quite a lot of facilities).

So, effectively what we'd do to fix this is for scanf() to call fgets(stdin...) with a fixed buffer size and then call sscanf() on the string.

It's the presence of the fixed buffer size which makes me slightly reticent to "fix" it in this simple way.

Offline

 

Board footer

Powered by PunBB
© Copyright 2002–2005 Rickard Andersson