home *** CD-ROM | disk | FTP | other *** search
/ Crawly Crypt Collection 1 / crawlyvol1.bin / telecomm / fser096b / xsdd_tst.c < prev    next >
C/C++ Source or Header  |  1993-07-29  |  8KB  |  427 lines

  1. #include <portab.h>
  2. #include <screen.h>
  3. #include <string.h>
  4. #include <tos.h>
  5. #include <ext.h>
  6.  
  7. #include <stdlib.h>
  8. #include <stdio.h>
  9.  
  10. #define AUX   (1)
  11. /* AUX (channel 1) undefined (EUNDEV) in FastXSer/XSDD, will be changed later */
  12.  
  13. #define MODEM1 (6)
  14. /* MODEM1 (channel 6) undefined (EUNDEV) in FastXSer/XSDD, will be changed later */
  15.  
  16. #define MODEM2 (7)
  17. #define SERIAL2 (8)
  18. #define SERIAL2 (9)
  19.  
  20. /*
  21.    the assignment of the channels is subject to changes
  22.    at the moment they meet the assignment of MSTE and Falcon030,
  23.    and TT (SERIAL1 left out on TT, channel8 !equals! channel9 )
  24. */
  25.  
  26.  
  27. extern UWORD get_cookie( ULONG, ULONG * );
  28.  
  29. typedef LONG cdecl (*cookie_fun)(UWORD opcode,...);
  30.  
  31. static cookie_fun XSDD = NULL;
  32.  
  33. char init[] = "at&t1\r";
  34. char bye[] = "+++  at&t0\r";
  35. char buffers[8192];
  36. char buffer[8192];
  37.  
  38.  
  39. /*
  40.   Rückgabewert:
  41.   0
  42. */
  43.  
  44. WORD XSDriverInfo( BYTE *info, LONG *product, WORD *version )
  45. {
  46.     LONG old_ssp=0;
  47.     
  48.     if ( !Super( (void *) 1L) ) old_ssp = Super( 0L );
  49.  
  50.     XSDD( -2, info, product, version );
  51.  
  52.     if ( old_ssp ) Super( (void *) old_ssp );
  53.  
  54.     return 0;
  55. }
  56.  
  57.  
  58. /*
  59.   Rückgabewert:
  60.   Version
  61. */
  62.  
  63. WORD XSVersion( void )
  64. {
  65.     WORD ret;
  66.     LONG old_ssp=0;
  67.     
  68.     if ( !Super( (void *) 1L) ) old_ssp = Super( 0L );
  69.  
  70.     ret = (WORD) XSDD( -1 );
  71.  
  72.     if ( old_ssp ) Super( (void *) old_ssp );
  73.  
  74.     return ret;
  75. }
  76.  
  77.  
  78. /*
  79.   Rückgabewert:
  80.   >=0 - Anzahl der verfügbaren Zeichen
  81.   EUNDEV - Ungültiges Device
  82. */
  83.  
  84. LONG XSInStat(WORD device)
  85. {
  86.     LONG ret;
  87.     LONG old_ssp=0;
  88.     
  89.     if ( !Super( (void *) 1L) ) old_ssp = Super( 0L );
  90.  
  91.     ret = XSDD( 0, device );
  92.  
  93.     if ( old_ssp ) Super( (void *) old_ssp );
  94.  
  95.     return ret;
  96. }
  97.  
  98.  
  99. /*
  100. Rückgabewert:
  101.   >=0 - Anzahl der Zeichen, die gelesen wurden wurden
  102.   EUNDEV - Ungültiges Device
  103.   Weitere (negative) TOS-Fehlernummern bei I/O-fehlern
  104. */
  105.  
  106. LONG XSRead(WORD device, LONG count, BYTE *buffer)
  107. {
  108.     LONG ret;
  109.     LONG old_ssp=0;
  110.     
  111.     if ( !Super( (void *) 1L) ) old_ssp = Super( 0L );
  112.  
  113.     ret = XSDD( 1, device, count, buffer );
  114.  
  115.     if ( old_ssp ) Super( (void *) old_ssp );
  116.  
  117.     return ret;
  118. }
  119.  
  120.  
  121. /*
  122.   Rückgabewert:
  123.   >=0 - Anzahl der Zeichen, die ausgegeben werden können
  124.   EUNDEV - Ungültiges Device
  125. */
  126.  
  127. LONG XSOutStat(WORD device)
  128. {
  129.     LONG ret;
  130.     LONG old_ssp=0;
  131.     
  132.     if ( !Super( (void *) 1L) ) old_ssp = Super( 0L );
  133.  
  134.     ret = XSDD( 2, device );
  135.  
  136.     if ( old_ssp ) Super( (void *) old_ssp );
  137.  
  138.     return ret;
  139. }
  140.  
  141.  
  142. /*
  143.   Rückgabewert:
  144.   >=0 - Anzahl der Zeichen, die geschrieben wurden
  145.   EUNDEV - Ungültiges Device
  146.   Weitere (negative) TOS-Fehlernummern bei I/O-Fehlern
  147. */
  148.  
  149. LONG XSWrite(WORD device, LONG count, BYTE *buffer)
  150. {
  151.     LONG ret;
  152.     LONG old_ssp=0;
  153.     
  154.     if ( !Super( (void *) 1L) ) old_ssp = Super( 0L );
  155.  
  156.     ret = XSDD( 3, device, count, buffer );
  157.  
  158.     if ( old_ssp ) Super( (void *) old_ssp );
  159.  
  160.     return ret;
  161. }
  162.  
  163.  
  164. /*
  165.   Rückgabe:
  166.   0 bei Erfolg
  167.   EUNDEV - Ungültiges Device
  168. */
  169.  
  170. WORD XSDevName(WORD device, BYTE *name)
  171. {
  172.     WORD ret;
  173.     LONG old_ssp=0;
  174.     
  175.     if ( !Super( (void *) 1L) ) old_ssp = Super( 0L );
  176.  
  177.     ret = (WORD) XSDD( 4, device, name );
  178.  
  179.     if ( old_ssp ) Super( (void *) old_ssp );
  180.  
  181.     return ret;
  182. }
  183.   
  184.  
  185. #define TIOCM_LE  0x01              /* line enable */
  186. #define TIOCM_DTR 0x02              /* data terminal ready */
  187. #define TIOCM_RTS 0x04              /* ready to send */
  188. #define TIOCM_CTS 0x08              /* clear to send */
  189. #define TIOCM_CAR 0x10              /* carrier detect */
  190. #define TIOCM_RNG 0x20              /* ring */
  191. #define TIOCM_DSR 0x40              /* data set ready */
  192.  
  193. /*
  194.   Rückgabewert:
  195.   >=0 (LONG!) - Verfügbare Kontrolleitungen
  196.   EUNDEV - Ungültiges Device
  197. */
  198.  
  199. LONG XSCtlMap(WORD device)
  200. {
  201.     LONG ret;
  202.     LONG old_ssp=0;
  203.     
  204.     if ( !Super( (void *) 1L) ) old_ssp = Super( 0L );
  205.  
  206.     ret = (WORD) XSDD( 5, device );
  207.  
  208.     if ( old_ssp ) Super( (void *) old_ssp );
  209.  
  210.     return ret;
  211. }
  212.  
  213.  
  214. /*
  215.   Rückgabewert:
  216.   >=0 (LONG!) - Status der Kontrolleitungen
  217.   EUNDEV - Ungültiges Device
  218. */
  219.  
  220. LONG XSGetCtl(WORD device)
  221. {
  222.     LONG ret;
  223.     LONG old_ssp=0;
  224.     
  225.     if ( !Super( (void *) 1L) ) old_ssp = Super( 0L );
  226.  
  227.     ret = (WORD) XSDD( 5, device );
  228.  
  229.     if ( old_ssp ) Super( (void *) old_ssp );
  230.  
  231.     return ret;
  232. }
  233.  
  234.  
  235. /*
  236.   Rückgabewert:
  237.   0 bei Erfolg
  238.   EUNDEV - Ungültiges Device
  239. */
  240.  
  241. WORD XSSetCtl(WORD device, UWORD ctl)
  242. {
  243.     WORD ret;
  244.     LONG old_ssp=0;
  245.     
  246.     if ( !Super( (void *) 1L) ) old_ssp = Super( 0L );
  247.  
  248.     ret = (WORD) XSDD( 6, device, ctl );
  249.  
  250.     if ( old_ssp ) Super( (void *) old_ssp );
  251.  
  252.     return ret;
  253. }
  254.  
  255.  
  256. /*
  257.   Rückgabewert:
  258.   0 bei Erfolg
  259.   EUNDEV - Ungültiges Device
  260. */
  261.  
  262. WORD XSOnCtl(WORD device, UWORD on_mask)
  263. {
  264.     WORD ret;
  265.     LONG old_ssp=0;
  266.     
  267.     if ( !Super( (void *) 1L) ) old_ssp = Super( 0L );
  268.  
  269.     ret = (WORD) XSDD( 7, device, on_mask );
  270.  
  271.     if ( old_ssp ) Super( (void *) old_ssp );
  272.  
  273.     return ret;
  274. }
  275.  
  276.  
  277. /*
  278.   Rückgabewert:
  279.   0 bei Erfolg
  280.   EUNDEV - Ungültiges Device
  281. */
  282.  
  283. WORD XSOffCtl(WORD device, UWORD off_mask)
  284. {
  285.     WORD ret;
  286.     LONG old_ssp=0;
  287.     
  288.     if ( !Super( (void *) 1L) ) old_ssp = Super( 0L );
  289.  
  290.     ret = (WORD) XSDD( 8, device, off_mask );
  291.  
  292.     if ( old_ssp ) Super( (void *) old_ssp );
  293.  
  294.     return ret;
  295. }
  296.  
  297.  
  298. /*
  299.   Rückgabe: 
  300.   0 bei Erfolg
  301.   EUNDEV - Ungültiges Device
  302. */
  303.  
  304. WORD XSBreak(WORD device, WORD on)
  305. {
  306.     WORD ret;
  307.     LONG old_ssp=0;
  308.     
  309.     if ( !Super( (void *) 1L) ) old_ssp = Super( 0L );
  310.  
  311.     ret = (WORD) XSDD( 8, device, on );
  312.  
  313.     if ( old_ssp ) Super( (void *) old_ssp );
  314.  
  315.     return ret;
  316. }
  317.  
  318. /* fehlen noch:    (laut XSDD-spec)
  319. LONG XSIBaud(WORD device, LONG baudrate)
  320. LONG XSOBaud(WORD device, LONG baudrate)
  321. WORD XSReserve(WORD device)
  322. WORD XSRelease(WORD device)
  323. LONG XSCapMap(WORD device)
  324. LONG XSSetFlags(WORD device, UWORD flags)
  325. LONG XSGetFlags(WORD device)
  326. WORD XSFlush(WORD device, WORD mode)
  327.  
  328. und die hab ich mir selbst ausgedacht:
  329. LONG XSIBuffer(WORD device, LONG *buffer, LONG *size)
  330. LONG XSOBuffer(WORD device, LONG *buffer, LONG *size)
  331.  
  332. die setzen den BufferPointer und BufferSize im IOREC, jeweils für
  333. Eingabe und Ausgabe, und liefern die alten Werte zurück.
  334.  
  335. Weitere Vorschläge???
  336.  
  337. Übrigens: Im Moment werden (entgegen der XSDD-Spec) nur die Register
  338.  A2-A7/D3-D7 nicht verändert, das entspricht der PureC-Konvention.
  339.  
  340. */
  341.  
  342.  
  343. int main()
  344. {
  345.     int cnt;
  346.     char *cp;
  347.     
  348.     ULONG cookievalue[1];
  349.  
  350.     char xsddinfo[128], devinfo[32];
  351.     char *p;
  352.     LONG product;
  353.     WORD version1, version2;
  354.     int i;
  355.     
  356.     p=buffers;
  357.     for( i=0; i<0x200; i++)
  358.     {
  359.         strcpy(p,"abcdefghijklmnop");
  360.         p+=0x10;
  361.     }
  362.     cnt = get_cookie( 'xSDD', cookievalue );
  363.     
  364.     if ( cnt )
  365.     {
  366.         XSDD = (cookie_fun) *cookievalue;
  367.     }
  368.     else
  369.     {
  370.         printf( "\n XSDD nicht installiert.\n" );
  371.         exit( 1 );
  372.     }
  373.  
  374.     XSDriverInfo( xsddinfo, &product, &version1 );
  375.     version2 = XSVersion();
  376.     XSDevName( 7, devinfo );
  377.     
  378.     printf( "\n xsddinfo: %s", xsddinfo );
  379.     printf( "\n product:  %.4s", &product );
  380.     printf( "\n Version1: %#06x", version1 );
  381.     printf( "\n Version2: %#06x", version2 );
  382.     printf( "\n devname:  %s", devinfo );
  383.  
  384.     cp = init;
  385.     do
  386.     {
  387.         Bconout( 7, *cp++ );
  388.         delay(200);
  389.     }
  390.     while( *cp );
  391.  
  392.     delay(5000);
  393.  
  394.     while( !kbhit() )
  395.     {
  396.         while( XSOutStat( 7 )<0x7ffL );
  397.         
  398.         while( XSOutStat( 7 )>=0x7ffL )
  399.         {
  400.             XSWrite( 7, 0x10L, buffers );
  401.         }
  402.  
  403.         while( XSInStat( 7 )<0x10L );
  404.  
  405.         while( XSInStat( 7 )>=0x10L )
  406.         {
  407.             buffer[0x10] = 0;
  408.             XSRead( 7, 0x10L, buffer );
  409.     
  410.             printf( "\n%s", buffer );
  411.         }
  412.     }
  413.  
  414.     getch();
  415.  
  416.     cp = bye;
  417.     do
  418.     {
  419.         delay( 500 );
  420.         Bconout( 7, *cp++ );
  421.     }
  422.     while( *cp );
  423.  
  424.     while( Bconstat( 7 ) ) Bconin(7);
  425.  
  426.     return 0;
  427. }