home *** CD-ROM | disk | FTP | other *** search
/ RISC DISC 1 / RISC_DISC_1.iso / pd_share / code / desklib / Libraries / Serial / c / NZPWOnRec
Encoding:
Text File  |  1994-05-22  |  2.3 KB  |  64 lines

  1. /*
  2.     ####             #    #     # #
  3.     #   #            #    #       #          The FreeWare C library for
  4.     #   #  ##   ###  #  # #     # ###             RISC OS machines
  5.     #   # #  # #     # #  #     # #  #   ___________________________________
  6.     #   # ####  ###  ##   #     # #  #
  7.     #   # #        # # #  #     # #  #    Please refer to the accompanying
  8.     ####   ### ####  #  # ##### # ###    documentation for conditions of use
  9.     ________________________________________________________________________
  10.  
  11.     File:    Serial.c.NZPWOnRec
  12.     Author:  Copyright © 1993 Jason Howat
  13.     Version: 1.00 (21 Nov 1993)
  14.     Purpose: Provide a handler to modify a pollword on reception of a
  15.              character on the serial port.
  16. */
  17.  
  18. #include "DeskLib:Core.h"
  19. #include "DeskLib:SWI.h"
  20. #include "DeskLib:Error.h"
  21. #include "SerialSWIs.h"                 /* Serial.h.SerialSWIs */
  22. #include <stdlib.h>
  23. #include <string.h>
  24.  
  25.  
  26. static unsigned *serial__RMAblock = NULL;
  27. static void *serial__pollword = NULL;
  28. static const unsigned serial__insvcode[] = {0xe92d4002,
  29.                                             0xe3c11102,
  30.                                             0xe3510001,
  31.                                             0x059f1004,
  32.                                             0x058c1000,
  33.                                             0xe8fd8002};
  34.  
  35. void Serial__NZPWORRemove(void);
  36.  
  37.  
  38. void Serial_NonZeroPollWordOnReceive(int pollword_value,
  39.                                           void *pollword)
  40. {
  41.   Error_CheckFatal(SWI(4,3, SWI_OS_Module + SWI_XOS_Bit, 6, 0, 0, 32,
  42.                                       /* TO */ NULL, NULL, &serial__RMAblock));
  43.  
  44.   if(pollword_value == 0)
  45.     pollword_value = 1;
  46.  
  47.   memcpy(serial__RMAblock, serial__insvcode, 24);
  48.   serial__RMAblock[6] = pollword_value;
  49.  
  50.   Error_CheckFatal(SWI(3,0, SWI_OS_Claim + SWI_XOS_Bit, 0x14, serial__RMAblock,
  51.                                                               pollword));
  52.   serial__pollword = pollword;
  53.  
  54.   atexit(Serial__NZPWORRemove);
  55. }
  56.  
  57. void Serial__NZPWORRemove(void)
  58. {
  59.   Error_CheckFatal(SWI(3,0, SWI_OS_Release + SWI_XOS_Bit,
  60.                                      0x14, serial__RMAblock, serial__pollword));
  61.   Error_CheckFatal(SWI(3,0, SWI_OS_Module + SWI_XOS_Bit, 7, 0,
  62.                                                              serial__RMAblock));
  63. }
  64.