home *** CD-ROM | disk | FTP | other *** search
/ Aminet 18 / aminetcdnumber181997.iso / Aminet / misc / emu / AROSdev.lha / AROS / rom / devs / console.c < prev    next >
Encoding:
C/C++ Source or Header  |  1997-01-27  |  5.1 KB  |  210 lines

  1. /*
  2.     (C) 1995-96 AROS - The Amiga Replacement OS
  3.     $Id: console.c,v 1.5 1997/01/27 00:39:37 ldp Exp $
  4.     $Log: console.c,v $
  5.     Revision 1.5  1997/01/27 00:39:37  ldp
  6.     Include proto instead of clib
  7.  
  8.     Revision 1.4  1996/11/14 22:35:37  aros
  9.     Fixed register conflict
  10.  
  11.     Revision 1.3  1996/10/24 15:50:21  aros
  12.     Use the official AROS macros over the __AROS versions.
  13.  
  14.     Revision 1.2  1996/09/11 16:54:19  digulla
  15.     Always use AROS_SLIB_ENTRY() to access shared external symbols, because
  16.         some systems name an external symbol "x" as "_x" and others as "x".
  17.         (The problem arises with assembler symbols which might differ)
  18.  
  19.     Revision 1.1  1996/08/23 17:32:23  digulla
  20.     Implementation of the console.device
  21.  
  22.  
  23.     Desc:
  24.     Lang:
  25. */
  26. #include <exec/resident.h>
  27. #include <devices/inputevent.h>
  28. #include <proto/exec.h>
  29. #include <proto/console.h>
  30. #include <aros/libcall.h>
  31. #ifdef __GNUC__
  32. #    include "console_gcc.h"
  33. #endif
  34.  
  35. static const char name[];
  36. static const char version[];
  37. static const APTR inittabl[4];
  38. static void *const functable[];
  39. static const UBYTE datatable;
  40.  
  41. struct consolebase *AROS_SLIB_ENTRY(init,Console)();
  42. void AROS_SLIB_ENTRY(open,Console)();
  43. BPTR AROS_SLIB_ENTRY(close,Console)();
  44. BPTR AROS_SLIB_ENTRY(expunge,Console)();
  45. int AROS_SLIB_ENTRY(null,Console)();
  46. void AROS_SLIB_ENTRY(beginio,Console)();
  47. LONG AROS_SLIB_ENTRY(abortio,Console)();
  48.  
  49. extern struct InputEvent * AROS_SLIB_ENTRY(CDInputHandler,Console) ();
  50. extern LONG AROS_SLIB_ENTRY(RawKeyConvert,Console) ();
  51. static const char end;
  52.  
  53. int AROS_SLIB_ENTRY(entry,Console)(void)
  54. {
  55.     /* If the device was executed by accident return error code. */
  56.     return -1;
  57. }
  58.  
  59. const struct Resident Console_resident=
  60. {
  61.     RTC_MATCHWORD,
  62.     (struct Resident *)&Console_resident,
  63.     (APTR)&end,
  64.     RTF_AUTOINIT,
  65.     1,
  66.     NT_LIBRARY,
  67.     0,
  68.     (char *)name,
  69.     (char *)&version[6],
  70.     (ULONG *)inittabl
  71. };
  72.  
  73. static const char name[]="console.device";
  74.  
  75. static const char version[]="$VER: console 1.0 (23.8.96)\n\015";
  76.  
  77. static const APTR inittabl[4]=
  78. {
  79.     (APTR)sizeof(struct consolebase),
  80.     (APTR)functable,
  81.     (APTR)&datatable,
  82.     &AROS_SLIB_ENTRY(init,Console)
  83. };
  84.  
  85. static void *const functable[]=
  86. {
  87.     &AROS_SLIB_ENTRY(open,Console),
  88.     &AROS_SLIB_ENTRY(close,Console),
  89.     &AROS_SLIB_ENTRY(expunge,Console),
  90.     &AROS_SLIB_ENTRY(null,Console),
  91.     &AROS_SLIB_ENTRY(beginio,Console),
  92.     &AROS_SLIB_ENTRY(abortio,Console),
  93.     &AROS_SLIB_ENTRY(CDInputHandler,Console),
  94.     &AROS_SLIB_ENTRY(RawKeyConvert,Console),
  95.     (void *)-1
  96. };
  97.  
  98. AROS_LH2(struct consolebase *, init,
  99.  AROS_LHA(struct consolebase *, consoleDevice, D0),
  100.  AROS_LHA(BPTR,              segList,   A0),
  101.        struct ExecBase *, sysBase, 0, Console)
  102. {
  103.     AROS_LIBFUNC_INIT
  104.  
  105.     /* Store arguments */
  106.     consoleDevice->sysBase = sysBase;
  107.     consoleDevice->seglist = segList;
  108.  
  109.     consoleDevice->device.dd_Library.lib_OpenCnt=1;
  110.  
  111.     return consoleDevice;
  112.     AROS_LIBFUNC_EXIT
  113. }
  114.  
  115. AROS_LH3(void, open,
  116.  AROS_LHA(struct IORequest *, ioreq, A1),
  117.  AROS_LHA(ULONG,              unitnum, D0),
  118.  AROS_LHA(ULONG,              flags, D1),
  119.        struct consolebase *, ConsoleDevice, 1, Console)
  120. {
  121.     AROS_LIBFUNC_INIT
  122.  
  123.     /* Keep compiler happy */
  124.     unitnum=0;
  125.     flags=0;
  126.  
  127.     /* I have one more opener. */
  128.     ConsoleDevice->device.dd_Library.lib_Flags&=~LIBF_DELEXP;
  129.  
  130.     AROS_LIBFUNC_EXIT
  131. }
  132.  
  133. AROS_LH1(BPTR, close,
  134.  AROS_LHA(struct IORequest *, ioreq, A1),
  135.        struct consolebase *, ConsoleDevice, 2, Console)
  136. {
  137.     AROS_LIBFUNC_INIT
  138.  
  139.     /* Let any following attemps to use the device crash hard. */
  140.     ioreq->io_Device=(struct Device *)-1;
  141.     return 0;
  142.     AROS_LIBFUNC_EXIT
  143. }
  144.  
  145. AROS_LH0(BPTR, expunge, struct consolebase *, ConsoleDevice, 3, Console)
  146. {
  147.     AROS_LIBFUNC_INIT
  148.  
  149.     /* Do not expunge the device. Set the delayed expunge flag and return. */
  150.     ConsoleDevice->device.dd_Library.lib_Flags|=LIBF_DELEXP;
  151.     return 0;
  152.     AROS_LIBFUNC_EXIT
  153. }
  154.  
  155. AROS_LH0I(int, null, struct consolebase *, ConsoleDevice, 4, Console)
  156. {
  157.     AROS_LIBFUNC_INIT
  158.     return 0;
  159.     AROS_LIBFUNC_EXIT
  160. }
  161.  
  162. AROS_LH1(void, beginio,
  163.  AROS_LHA(struct IORequest *, ioreq, A1),
  164.        struct consolebase *, ConsoleDevice, 5, Console)
  165. {
  166.     AROS_LIBFUNC_INIT
  167.     LONG error=0;
  168.  
  169.     /* WaitIO will look into this */
  170.     ioreq->io_Message.mn_Node.ln_Type=NT_MESSAGE;
  171.  
  172.     /*
  173.     Do everything quick no matter what. This is possible
  174.     because I never need to Wait().
  175.     */
  176.     switch (ioreq->io_Command)
  177.     {
  178.     default:
  179.     error=ERROR_NOT_IMPLEMENTED;
  180.     break;
  181.     }
  182.  
  183.     /* If the quick bit is not set send the message to the port */
  184.     if(!(ioreq->io_Flags&IOF_QUICK))
  185.     ReplyMsg (&ioreq->io_Message);
  186.  
  187.     /* Trigger a rescedule every now and then */
  188.     if(SysBase->TaskReady.lh_Head->ln_Pri==SysBase->ThisTask->tc_Node.ln_Pri&&
  189.        SysBase->TDNestCnt<0&&SysBase->IDNestCnt<0)
  190.     {
  191.     SysBase->ThisTask->tc_State=TS_READY;
  192.     Enqueue(&SysBase->TaskReady,&SysBase->ThisTask->tc_Node);
  193.     Switch();
  194.     }
  195.  
  196.     AROS_LIBFUNC_EXIT
  197. }
  198.  
  199. AROS_LH1(LONG, abortio,
  200.  AROS_LHA(struct IORequest *, ioreq, A1),
  201.        struct consolebase *, ConsoleDevice, 6, Console)
  202. {
  203.     AROS_LIBFUNC_INIT
  204.     /* Everything already done. */
  205.     return 0;
  206.     AROS_LIBFUNC_EXIT
  207. }
  208.  
  209. static const char end=0;
  210.