home *** CD-ROM | disk | FTP | other *** search
/ Amiga Developer CD v1.2 / amidev_cd_12.iso / reference / amiga_mail_vol1 / dos / conrawevent next >
Text File  |  1990-01-26  |  8KB  |  234 lines

  1. (c)  Copyright 1989 Commodore-Amiga, Inc.   All rights reserved.
  2. The information contained herein is subject to change without notice, and 
  3. is provided "as is" without warranty of any kind, either expressed or implied.  
  4. The entire risk as to the use of this information is assumed by the user.
  5.  
  6.  
  7.  
  8.                      CON: and Raw Event Streams
  9.  
  10.                       Carolyn Scheppner - CATS
  11.  
  12.  
  13.      The ability to toggle CON: or NEWCON: windows in and out of
  14. RAW: mode can provide some convenient features for Amiga programmers.
  15. Normally, CON: and NEWCON: windows like the CLI provide a simple, 
  16. buffered form of console input where all echoing and line editing is 
  17. handled for you and you receive the characters when the user hits 
  18. the RETURN key.  But sometimes you need more control, or more keys, 
  19. or more information than CON: provides.
  20.  
  21.      The AmigaDOS ACTION_SCREEN_MODE packet allows you to toggle
  22. a CON: or NEWCON: window into RAW: mode.  In RAW: mode, you still
  23. get keymap character translation for international compatibility,
  24. but you get each ASCII character as it is received instead of when
  25. the user hits the Return key.  In RAW: mode, you also receive the 
  26. keymap's escape strings for keys such as the cursor and function keys.  
  27. However, since you receive all characters directly, you are responsible 
  28. for managing all filtering, echoing and line editing.
  29.  
  30.      The ability to toggle a window back and forth between CON: and RAW: 
  31. gives you the ability to match the input style to your program's needs.  
  32. For example, the More program on Workbench keeps its CON: text display 
  33. window in RAW: mode most of the time for immediate processing of single-key 
  34. user commands.  But when the user selects a key command which requires a 
  35. string argument to be input (such as the "/" or "." search commands), the 
  36. More program temporarily toggles the window back into CON: mode to let 
  37. the system provide automatically filtered and echoed line input.
  38.  
  39.  
  40.      In addition to providing immediate character input and escape strings 
  41. for the non-vanilla keys, RAW: windows may be set up to pass on a variety 
  42. of raw events as escape strings.  These events are requested with the 
  43. aSRE (SET RAW EVENTS) escape sequence.  This sequence and its counterpart 
  44. (RESET RAW EVENTS) have the following form:
  45.  
  46. aSRE   SET RAW EVENTS          <CSI>n{
  47. aRRE   RESET RAW EVENTS        <CSI>n}
  48.  
  49. <CSI> is the Control Sequence Introducer and n is the number in ASCII of the 
  50. raw event you wish to receive.  The Control Sequence Introducer may be either 
  51. the two-byte code "\033[" (also known as ESC[ ) or the one-byte code "\233"
  52. (ESC with the high bit set ).  A full list of the types of raw events available 
  53. may be found in the Console Input and Output chapter of the Bantam AmigaDOS 
  54. manual.  This list includes:
  55.  
  56.      3  Window made active
  57.      9  Requester activity
  58.     12  Window resized
  59.     15  Disk removed
  60.     16  Disk inserted
  61.  
  62.    For example, Window Active events would be requested by writing
  63. the escape string "\033[3{" to the raw mode CON:, and turned off
  64. by writing "\033[3}".
  65.  
  66.    The example program DiskI.c toggles the CLI window into RAW: mode
  67. and asks for DISKINSERTED and DISKREMOVED events.  Note that the
  68. two requests are combined into a single escape sequence by separating
  69. the ASCII event numbers with a semicolon.  Both events 15 and 16
  70. are requested using the escape string "\033[15;16{".
  71.  
  72.     DiskI.c demonstrates several techniques which you may want to try
  73. in your programs:
  74.  
  75.       - Sending an AmigaDOS packet
  76.       - Toggling a CON: into RAW mode and back
  77.       - Requesting, receiving, and resetting additional raw events
  78.  
  79.  
  80.  
  81.  
  82.  
  83.  
  84. /*
  85.   Diski.c - Get Disk Inserted and Removed Raw Events from CLI window
  86.   Carolyn Scheppner  CBM  04/89
  87.  
  88.   Copyright (c) 1989 Commodore-Amiga, Inc.
  89.  
  90.   Executables based on this information may be used in software
  91.   for Commodore Amiga computers.  All other rights reserved.
  92.  
  93.   This information is provided "as is"; no warranties are made.
  94.   All use is at your own risk, and no liability or responsibility is assumed.
  95. */
  96.  
  97. #include "exec/types.h"
  98. #include "exec/memory.h"
  99. #include "libraries/dos.h"
  100. #include "libraries/dosextens.h"
  101.  
  102. /* Defined in 1.3 Includes
  103. #define  DOSTRUE (-1L)
  104. #define  DOSFALSE (0L)
  105. */
  106.  
  107.  
  108. main()
  109.    {
  110.    printf("\nThis demo will set CON to RAW, request DISKINSERTED and\n");
  111.    printf("DISKREMOVED events, then prompt for disk insertion/removal\n");
  112.    printf("in any drive.\n\n");
  113.    printf("Experiment by inserting and removing disks, and typing keys.\n");
  114.    printf("The program will print out all input characters in ascii,\n");
  115.    printf("but will print escape (1B) as ESC, and csi (9B) as CSI.\n");
  116.    printf("[ Press CTRL/C to exit when done experimenting. ]\n\n");
  117.  
  118.    /* Set our process's pr_ConsoleTask to RAW */
  119.    setRawCon(DOSTRUE);
  120.  
  121.    /* Ask RAW window for raw DISKINSERTED and DISKREMOVED events */
  122.    printf("\033[15;16{");
  123.  
  124.    printf("Please insert or remove disk in any drive...\n\n");
  125.  
  126.    while(!(SetSignal(0,0)&SIGBREAKF_CTRL_C))
  127.       {
  128.       dochar();
  129.       }
  130.  
  131.    /* Clear the CTRL/C signal */
  132.    SetSignal(0,SIGBREAKF_CTRL_C);
  133.  
  134.    /* Tell RAW window to stop sending raw DISKINSERTED/REMOVED events */
  135.    printf("\033[15;16}");
  136.  
  137.    printf("\n\nDemo has now asked to NOT receive DISK events.\n");
  138.    printf("Inserting a disk now should cause no input characters.\n");
  139.    printf("[ Press CTRL/C to exit when done experimenting. ]\n\n");
  140.  
  141.    while(!(SetSignal(0,0)&SIGBREAKF_CTRL_C))
  142.       {
  143.       dochar();
  144.       }
  145.  
  146.    /* Reset to normal CON */
  147.    setRawCon(DOSFALSE);
  148.  
  149.    printf("\nDone.  Console has been reset to CON:, demo exiting...\n\n");
  150.    }
  151.  
  152.  
  153. dochar()
  154.    {
  155.    UBYTE c;
  156.  
  157.    c=getchar();
  158.  
  159.    if(c==0x1B)        printf("\nESC\n");
  160.    else if(c==0x9B)   printf("\nCSI\n");
  161.    else               putchar(c);
  162.    }
  163.  
  164.  
  165. /* sendpkt code - A. Finkel, P. Lindsay, C. Scheppner  CBM */
  166.  
  167. LONG setRawCon(toggle)
  168. LONG toggle;     /* DOSTRUE (-1L)  or  DOSFALSE (0L) */
  169.    {
  170.    struct MsgPort *conid;
  171.    struct Process *me;
  172.    LONG myargs[8] ,nargs, res1;
  173.  
  174.    me = (struct Process *) FindTask(NULL);
  175.    conid = (struct MsgPort *) me->pr_ConsoleTask;
  176.  
  177.    myargs[0]=toggle;
  178.    nargs = 1;
  179.    res1 = (LONG)sendpkt(conid,ACTION_SCREEN_MODE,myargs,nargs);
  180.    return(res1);
  181.    }
  182.  
  183.  
  184. LONG sendpkt(pid,action,args,nargs)
  185. struct MsgPort *pid;  /* process indentifier ... (handlers message port ) */
  186. LONG action,          /* packet type ... (what you want handler to do )   */
  187.      args[],          /* a pointer to a argument list */
  188.      nargs;           /* number of arguments in list  */
  189.    {
  190.    struct MsgPort        *replyport;
  191.    struct StandardPacket *packet;
  192.  
  193.    LONG  count, *pargs, res1;
  194.  
  195.    if(!pid) return(NULL);
  196.    replyport = (struct MsgPort *) CreatePort(NULL,0);
  197.    if(!replyport) return(NULL);
  198.  
  199.    packet = (struct StandardPacket *) 
  200.       AllocMem((long)sizeof(struct StandardPacket),MEMF_PUBLIC|MEMF_CLEAR);
  201.    if(!packet) 
  202.       {
  203.       DeletePort(replyport);
  204.       return(NULL);
  205.       }
  206.  
  207.    packet->sp_Msg.mn_Node.ln_Name = (char *)&(packet->sp_Pkt);
  208.    packet->sp_Pkt.dp_Link         = &(packet->sp_Msg);
  209.    packet->sp_Pkt.dp_Port         = replyport;
  210.    packet->sp_Pkt.dp_Type         = action;
  211.  
  212.    /* copy the args into the packet */
  213.    pargs = &(packet->sp_Pkt.dp_Arg1);       /* address of first argument */
  214.    for(count=0;count < nargs;count++) 
  215.       pargs[count]=args[count];
  216.  
  217.    PutMsg(pid,packet); /* send packet */
  218.  
  219.    WaitPort(replyport);
  220.    GetMsg(replyport); 
  221.  
  222.    res1 = packet->sp_Pkt.dp_Res1;
  223.  
  224.    FreeMem(packet,(long)sizeof(struct StandardPacket));
  225.    DeletePort(replyport); 
  226.  
  227.    return(res1);
  228.    }
  229.  
  230.  
  231. /* end */
  232.  
  233.  
  234.