home *** CD-ROM | disk | FTP | other *** search
/ Frozen Fish 1: Amiga / FrozenFish-Apr94.iso / bbs / alib / d6xx / d658 / view.lha / View / Source / Console.c < prev    next >
C/C++ Source or Header  |  1992-05-15  |  4KB  |  131 lines

  1. /*-- AutoRev header do NOT edit!
  2. *
  3. *   Program         :   Console.c
  4. *   Copyright       :   Copyright © 1991-92 Jaba Development
  5. *   Author          :   Jan van den Baard
  6. *   Creation Date   :   04-Apr-92
  7. *   Current version :   2.0
  8. *   Translator      :   Dice v2.06.40
  9. *
  10. *   REVISION HISTORY
  11. *
  12. *   Date          Version         Comment
  13. *   ---------     -------         ------------------------------------------
  14. *   04-Apr-92     2.0             Console routine (rewrite)
  15. *
  16. *-- REV_END --*/
  17.  
  18. #include "View.h"
  19.  
  20. Prototype long OpenConsole( void );
  21. Prototype void CloseConsole( void );
  22. Prototype void ConvertKeyTab( void );
  23. Prototype void Inform( UBYTE * );
  24. Prototype void Display( struct Line * );
  25.  
  26. extern struct Window        *vwWindow;
  27.  
  28. static struct MsgPort       *CPort         = NULL;
  29. struct IOStdReq             *CMsg          = NULL;
  30. APTR                         ConsoleDevice = NULL;
  31.  
  32. UBYTE                        KeyTable[ 64 ];
  33. UBYTE                        SKeyTable[ 64 ];
  34.  
  35. UBYTE                        MoveStr[]  = { CSI, 0x00, 0x00, 0x3b, 0x00, 0x00, 0x48, 0x00 };
  36. UBYTE                        ClearStr[] = { 0x0c, 0x00 };
  37. UBYTE                        ScrUpStr[] = { CSI, 0x53, 0x00 };
  38. UBYTE                        ScrDnStr[] = { CSI, 0x54, 0x00 };
  39. UBYTE                        StdStr[]   = { ESC, 0x63, CSI, 0x30, 0x20, 0x70, CSI, 0x00, 0x38, 0x79, 0x00 };
  40. UBYTE                        NoScrStr[] = { CSI, 0x3e, 0x31, 0x6c };
  41. UBYTE                       *ResStr     = "\033[0m";
  42. UBYTE                       *FFStr      =  "\033[7mF\033[0m";
  43.  
  44. long OpenConsole( void )
  45. {
  46.     if ( CPort = CreateMsgPort()) {
  47.         if ( CMsg = ( struct IOStdReq * )CreateIORequest( CPort, (long)sizeof( struct IOStdReq ))) {
  48.  
  49.             CMsg->io_Data   = (APTR) vwWindow;
  50.             CMsg->io_Length = (LONG) sizeof( struct Window );
  51.  
  52.             if ( ! OpenDevice( "console.device", NULL, ( struct IORequest * )CMsg, NULL )) {
  53.                 ConsoleDevice = CMsg->io_Device;
  54.                 ConvertKeyTab();
  55.                 Inform( StdStr );
  56.                 return( TRUE );
  57.             }
  58.         }
  59.     }
  60.  
  61.     CloseConsole();
  62.     return( FALSE );
  63. }
  64.  
  65. void CloseConsole( void )
  66. {
  67.     if ( ConsoleDevice ) {
  68.         CloseDevice(( struct IORequest * )CMsg );
  69.         ConsoleDevice = NULL;
  70.     }
  71.  
  72.     if ( CMsg ) {
  73.         DeleteIORequest(( struct IORequest * )CMsg );
  74.         CMsg = NULL;
  75.     }
  76.  
  77.     if ( CPort ) {
  78.         DeleteMsgPort( CPort );
  79.         CPort = NULL;
  80.     }
  81. }
  82.  
  83. void ConvertKeyTab( void )
  84. {
  85.     struct InputEvent   ievent;
  86.     UWORD               i;
  87.  
  88.     setmem( &ievent, sizeof( struct InputEvent ), NULL );
  89.  
  90.     ievent.ie_Class = IECLASS_RAWKEY;
  91.  
  92.     for ( i = 0; i < 64; i++ ) {
  93.         ievent.ie_Code = i;
  94.         RawKeyConvert( &ievent, &KeyTable[ i ], 1, NULL );
  95.     }
  96.  
  97.     ievent.ie_Qualifier = IEQUALIFIER_LSHIFT;
  98.  
  99.     for ( i = 0; i < 64; i++ ) {
  100.         ievent.ie_Code = i;
  101.         RawKeyConvert( &ievent, &SKeyTable[ i ], 1, NULL );
  102.     }
  103. }
  104.  
  105. void Inform( UBYTE *text )
  106. {
  107.     CMsg->io_Command = CMD_WRITE;
  108.     CMsg->io_Data    = (APTR) text;
  109.     CMsg->io_Length  = (LONG) strlen( text );
  110.  
  111.     DoIO(( struct IORequest * )CMsg );
  112. }
  113.  
  114. void Display( struct Line *line )
  115. {
  116.     Inform( ResStr );
  117.     Inform( NoScrStr );
  118.  
  119.     CMsg->io_Command = CMD_WRITE;
  120.     CMsg->io_Data    = (APTR) line->Text;
  121.     CMsg->io_Length  = (LONG) line->Size - 1;
  122.  
  123.     if ( line->Text[ 0 ] == FF ) {
  124.         Inform( FFStr );
  125.         CMsg->io_Data   = (APTR) &line->Text[ 1 ];
  126.         CMsg->io_Length = (LONG) line->Size - 2;
  127.     }
  128.  
  129.     DoIO(( struct IORequest * )CMsg );
  130. }
  131.