[comp.sys.misc] C-Power 64 sys call -- HELP!

schaefer@ogcvax.UUCP (04/06/87)

[I always see these silly line-eater things, so here's mine]

I am having massive difficulties with the sys function in C-Power.

I am trying to make a call to GETIN (0xFFE4) to read a character from the
keyboard without having to wait for a carriage return.  (If you know of a
way to do this without using sys, I'd like to know about it.)  Following
the example on page 46 of the C-Power manual, I wrote:

    #define peek(x)	*((char *)(x))
    #define poke(x,y)	*((char *)(x))=(y)

    xget(c)
    char *c;
    {
	char x, y, d;

	d = peek(0x99);		/* save the current input device */
	poke(0x99,0);		/* set input from keyboard */
	for (*c = '\0'; (*c == '\0'); )
	    sys(15,0xffe4,c,&x,&y);	/* call GETIN */
	poke(0x99,d)		/* restore the input device */
    }

The result of this, when I tested it in a short program, was to kick me clear
out of the shell and back to a VERY screwed-up BASIC.

I then tried the example from page 46 (calling CHROUT to print a string), and
this had the same effect.  I tried calling CHROUT through the jump table
(0xffd2) and directly (0xf1ca), and with every bank number from 0 to 15 (the
first argument to sys is the bank number, with a mysterious reference to the
BASIC BANK command -- is this C-128 related?), and the only differences were
that some odd (i.e., non-even) bank numbers locked up the system completely
instead of just clobbering BASIC.

What's going on here?  Is my C-64 weird in some way, or do I have a strange
sys manual page, or does sys just plain not work?  HELP!  HELP!  HELP!

Please reply via a posting rather than through E-mail, as a recent "upgrade"
to 4.3 BSD has (temporarily?) messed up mail from some of our UUCP connections.

Thanks in advance ....
-- 
Bart Schaefer						Dept. of CS&E
CSNET:	schaefer@Oregon-Grad				Oregon Graduate Center
UUCP:	{ihnp4,seismo,sun}!verdix \			19600 NW Von Neumann Dr
 {hplabs,ucbvax,decvax}!tektronix  !ogcvax!schaefer	Beaverton, OR  97006

prindle@nadc.arpa (04/07/87)

In C, to pass the pointer of an object to a function (or to take the address
of an object with the & operator in general), that object must be "static" or
"auto", not "register"!  In most C compilers, the default storage class is
"auto" (given that you don't explicitly declare a storage class).  But in C-
Power, the default storage class is "register".  To solve your problem (or
at least make it manageable - I didn't check it out, just saw the obvious),
either declare any variables which you use & with to be explicitly auto as in:
	auto char x;
instead of:
	char x;
Or, even simpler, but it will make your programs run slower, use the "-a"
option when invoking the compiler - this will force the default storage class
to become "auto"; then if it works, go back and declare all variables which
can be "register" to explicitly be so.
Hope this solves your problem.

Sincerely,
Frank Prindle
Prindle@NADC.arpa

cagordon@watnot.UUCP (04/07/87)

In article <1244@ogcvax.UUCP> schaefer@ogcvax.UUCP (Barton E. Schaefer) writes:
[ article and part of program deleted ]
>	    sys(15,0xffe4,c,&x,&y);	/* call GETIN */
[ ditto ]

Remove the '15' and you will have no problems. The bank parameter is only used
in the 128 version of the compiler - if the manual lists the '15' for the 64
version (which I think shows poorly on the part of ProLine Software) then the
manual is in error.

Chris

--
-------------------------------------------------------------------------------
Chris Gordon                     UUCP: {abunchasystems}!watmath!watnot!cagordon
U of Waterloo, Ont         CompuServe: 72030,104
		               Q-Link: ChrisG22
				CSNET: cagordon%watnot@Waterloo.CSNET
-------------------------------------------------------------------------------
When you care enough to send the very best, send MONEY!

dean@hyper.UUCP (04/07/87)

in article <1244@ogcvax.UUCP>, schaefer@ogcvax.UUCP (Barton E. Schaefer) says:
>	[program fragments here]
> 	    sys(15,0xffe4,c,&x,&y);	/* call GETIN */
>	[more program fragments]
> 
> I then tried the example from page 46 (calling CHROUT to print a string), and
> this had the same effect.  I tried calling CHROUT through the jump table
> (0xffd2) and directly (0xf1ca), and with every bank number from 0 to 15 (the
> first argument to sys is the bank number, with a mysterious reference to the
> BASIC BANK command -- is this C-128 related?), and the only differences were
> that some odd (i.e., non-even) bank numbers locked up the system completely
> instead of just clobbering BASIC.
> 
> What's going on here?  Is my C-64 weird in some way, or do I have a strange
> sys manual page, or does sys just plain not work?  HELP!  HELP!  HELP!

	It sounds like you have the manual page from the C128 version of
C-power.  The sys command for the C64 version is the just like the one you
have above, with the exception that it doesn't have the bank parameter.

To do what you want to do, you should use the statement

		sys(0xffe4,c,&x,&y);	/* call GETIN */

(or, better yet, get Mark Rinfret's assembler and create an assembly
language version of this function, and stick it into your library, like
I did.  (If you're going to be using this routine in a lot of different
places, it makes a certain amount of sense))

	Good luck!


					Dean C. Gahlon
					...ihnp4!umn-cs!hyper!dean

schaefer@ogcvax.UUCP (04/07/87)

In article <brl-adm.6734> prindle@nadc.arpa writes:
>In C, to pass the pointer of an object to a function (or to take the address
>of an object with the & operator in general), that object must be "static" or
>"auto", not "register"!  In most C compilers, the default storage class is
>"auto" (given that you don't explicitly declare a storage class).  But in C-
>Power, the default storage class is "register".  To solve your problem (or
>at least make it manageable - I didn't check it out, just saw the obvious),
>either declare any variables which you use & with to be explicitly auto as in:
>	auto char x;
>instead of:
>	char x;
>
>Sincerely,
>Frank Prindle
>Prindle@NADC.arpa

This was not the problem.  (My C-Power manual says "register" declarations
are ignored -- I thought that this meant that there are no register variables
in C-64 C-Power, that the fastest you can get is 0-page, where the first 32
auto variables go.)  Thanks for the pointer, though, Frank; I'll check it out.

The evening after I posted the original article, I tried something different.
The documented call to `sys' is
	sys(bank,address,a,x,y);
but `bank' is suspicious because of the reference to the Basic BANK command,
which does not exist in C-64 Basic.  So I tried:
	sys(address,a,x,y)
i.e., leaving out the bank number.  This works, as far as making the jump to
the machine language routine and setting/reading the accumulator.  I have not
yet checked the x and y registers to see if they are correctly handled.  The
manual evidently needs some proof-reading.

By the way, I have recently heard that C-Power is no longer being distributed
by Pro-Line.  It is reportedly still available, but from some other company in
the eastern US, and possibly under the new name "Power-C".  Anybody out there
have further info on this?

-- 
Bart Schaefer						Dept. of CS&E
CSNET:	schaefer@Oregon-Grad				Oregon Graduate Center
UUCP:	{ihnp4,seismo,sun}!verdix \			19600 NW Von Neumann Dr
 {hplabs,ucbvax,decvax}!tektronix  !ogcvax!schaefer	Beaverton, OR  97006