[comp.sys.amiga.programmer] Consoles & RastPorts, and ne'er the twain shall meet

alex@bilver.uucp (Alex Matulich) (04/30/91)

Here are two Amiga programming problems that I would like to be able to
solve, without resorting to assembly language if possible.  I need a
solution to just one of them, number 2 preferably!

(1)  I open a window using fopen("CON:", "wb").  A console window is
opened, and a convenient file pointer is returned which I can use with
functions like fprint(), fputs(), etc.  Problem:  How do I find a pointer
to this window's Window structure, specifically the pointer to its RastPort?

(2)  I open a window using OpenWindow(), and a pointer to the Window
structure is returned.  I attach a console to this window using
OpenConsole().  Problem:  How do I get an fopen-compatible stdio pointer
to the console, so that I can use fprint() with it?

It seems to me, that if I can do (1) or (2) separately, there should be a
way to combine the benifits of both.  Can anybody help?

Also, if anybody can explain how the AmigaDOS "More" program is able to
intercept keystrokes from the CLI console before the CLI gets to them
(without resorting to assembly if possible), you'd have my undying
gratitude!

-- 
 _ |__  Alex Matulich
 /(+__>  Unicorn Research Corp, 4621 N Landmark Dr, Orlando, FL 32817
//| \     UUCP:  alex@bilver.uucp   <or>  ...uunet!tarpit!bilver!alex
///__)     bitnet:  IN%"bilver!alex@uunet.uu.net"

robinson@delux2.cs.umass.edu (Richard Robinson) (05/05/91)

In article <1991Apr29.221442.14665@bilver.uucp> alex@bilver.uucp (Alex Matulich) writes:
>Here are two Amiga programming problems that I would like to be able to
>solve, without resorting to assembly language if possible.  I need a
>solution to just one of them, number 2 preferably!
>
>(1)  I open a window using fopen("CON:", "wb").  A console window is
>opened, and a convenient file pointer is returned which I can use with
>functions like fprint(), fputs(), etc.  Problem:  How do I find a pointer
>to this window's Window structure, specifically the pointer to its RastPort?
>
>(2)  I open a window using OpenWindow(), and a pointer to the Window
>structure is returned.  I attach a console to this window using
>OpenConsole().  Problem:  How do I get an fopen-compatible stdio pointer
>to the console, so that I can use fprint() with it?

An easy way to solve this is to use ConMan. It has an option to open a
standard console (so you can use fopen/fread/fetc on it) on a pre-existing
window.

>
>It seems to me, that if I can do (1) or (2) separately, there should be a
>way to combine the benifits of both.  Can anybody help?
>
>Also, if anybody can explain how the AmigaDOS "More" program is able to
>intercept keystrokes from the CLI console before the CLI gets to them
>(without resorting to assembly if possible), you'd have my undying
>gratitude!

This one is easy. Just send a packet to the console turning it to RAW
mode. I have a code fragment which I can post if you want. (I can't
send mail, so if someone else can, maybe we won't have to waste bandwidth.)
However, I can receive mail, and if several people would like the code,
I'll post (send me mail).


-Dread
--
robinson@elux1.cs.umass.edu

black@beno.CSS.GOV (Mike Black) (05/06/91)

Here's what I use for single keystroke handling from stdin:

/* Works with Manx 5.0d */
#include <stdio.h>
#include <sgtty.h>
#include <fcntl.h>

#ifdef DEBUGCON
main()
{
        int c=0;
        setraw();
        while(c==0) {
                puts("Waiting");
                c=getch();
        }
        fflush(stdin);
        printf("\nc=%c\n",c);
        setrawoff();
}
#endif

int chkget() /* returns 1 if char available else returns 0 */
{
        struct _dev *refp;
        refp = _devtab + stdin->_unit;
        if(WaitForChar(refp->fd,1)) return 1;
        return 0;
}

int getch() /* returns char from stdin if available else returns 0 */
{
        char c=0;
        struct _dev *refp;
        refp = _devtab + stdin->_unit;
        if(WaitForChar(refp->fd,1)) c=getchar();
        return c;
}

setraw() /* puts stdin in RAW mode */
{
        struct sgttyb stty;
        ioctl(fileno(stdin),TIOCGETP,&stty);
        stty.sg_flags |= RAW;
        ioctl(fileno(stdin),TIOCSETP,&stty);
}

setrawoff() /* turns RAW mode off on stdin */
{
        struct sgttyb stty;
        ioctl(fileno(stdin),TIOCGETP,&stty);
        stty.sg_flags &= ~RAW;
        ioctl(fileno(stdin),TIOCSETP,&stty);
}
--
-------------------------------------------------------------------------------
: usenet: black@beno.CSS.GOV   :  land line: 407-494-5853  : I want a computer:
: real home: Melbourne, FL     :  home line: 407-242-8619  : that does it all!:
-------------------------------------------------------------------------------

alex@bilver.uucp (Alex Matulich) (05/07/91)

In article <49605@seismo.CSS.GOV> black@beno.CSS.GOV (Mike Black) writes:
>Here's what I use for single keystroke handling from stdin:
[...a couple screenfuls of good code...]

Thanks for posting that.  I don't think I could have figured that out for
myself.  Now I gotta see if it works with SAS C...

That answers one of my questions, I think.  Now, about getting an
fopen()-compatible pointer to a console that you create and attach to a
custom window -- any ideas, anybody?
>-------------------------------------------------------------------------------
>: usenet: black@beno.CSS.GOV   :  land line: 407-494-5853  : I want a computer:

-- 
 _ |__  Alex Matulich
 /(+__>  Unicorn Research Corp, 4621 N Landmark Dr, Orlando, FL 32817
//| \     UUCP:  alex@bilver.uucp   <or>  ...uunet!tarpit!bilver!alex
///__)     bitnet:  IN%"bilver!alex@uunet.uu.net"