Re: [cc65] input for C64

Date view Thread view Subject view

From: Ullrich von Bassewitz (uz_at_musoftware.de)
Date: 2001-03-04 22:30:28


On Sun, Mar 04, 2001 at 04:10:22PM -0500, troy silvey wrote:
> To your credit, the puts() seems to work perfectly so far for the 64.
> I was hoping gets() would too.

I was hoping that, too:-) The read() function is a hack, and it seems to be
wrong. It might be possible to fix it, but it would be a hack anyway, so I
don't like that idea. I will remove the read() function from the makefile, so
you will get a linker error for future releases when trying to use gets(),
fgets() or similar.

> I've tried to use some of the functions, but I havn't gotten the
> complete hang of it yet. Results are still messy.
> I'll study it more and try and put it to work.

Here is a routine that reads one line of input using the console functions:


    char* cgets (char* Buf, unsigned Size)
    /* Similar to fgets, but uses console I/O */
    {
	char C;
	unsigned Count = 0;

	/* Remember the current cursor and enable it */
	unsigned char SavedCursor = cursor (1);

	/* Be sure not to write outside the buffer */
	while (Count < Size-1) {

	    /* Read one character and check for the final CR. We won't
	     * output the newline, which should be ok in most cases.
	      */
	    if ((C = cgetc()) == '\n') {
	     	break;
	    }

	    /* Echo the input character just read */
	    cputc (C);

	    /* Store it into the buffer */
	    Buf [Count++] = C;
	}

	/* Terminate the buffer */
	Buf [Count] = '\0';

	/* Restore the old cursor state */
	cursor (SavedCursor);

	/* Return the buffer pointer */
	return Buf;
    }


It is called "cgets" because it works similar to fgets but reads from the
console. It would probably be a better idea to return the number of characters
in the buffer instead of the buffer pointer, but since gets returns a buffer
pointer, I've used the same convention for this function.

> I know you're doing CC65 for fun, not profit so I hate to bring up
> things that would cause you more work. So far CC65 has gone
> along way to help me learn C. And even finding and working
> around some of limits of CC65 has helped me learn.

I'm glad to hear that, and I'm happy about all suggestions, even if I'm not
able or willing to honour them:-)

> You mentioned trying to impement some scanf features in a future
> version. It seems to me that gets() would be a good alternative.
> Data conversions could be done by other fuctions already included.
> Would gets be any easier or compact to add than scanf ?

Doing gets() right would mean adding file support since gets() is just a
special file function reading from stdin. And I've personally decided not to
add file support in the near future, since I don't need it.

For real programs, gets() would not be a good idea anyway, because it has
similar problems as the BASIC "INPUT" command. It would accept cursor commands
and similar stuff. Nothing you want to use in a program that you want to show
other people:-)

Regards


	Uz


--
Ullrich von Bassewitz                                  uz_at_musoftware.de
----------------------------------------------------------------------
To unsubscribe from the list send mail to majordomo_at_musoftware.de with
the string "unsubscribe cc65" in the body(!) of the mail.


Date view Thread view Subject view

This archive was generated by hypermail 2.1.3 : 2001-12-14 22:05:39 CET