Annotation of uae/src/serial.c, revision 1.1.1.2

1.1       root        1:  /* 
                      2:   * UAE - The Un*x Amiga Emulator
                      3:   * 
                      4:   *  Serial Line Emulation
                      5:   *
1.1.1.2 ! root        6:   * (c) 1996 Stefan Reinauer <[email protected]>
1.1       root        7:   */
                      8: 
                      9: #include "sysconfig.h"
                     10: #include "sysdeps.h"
                     11: 
                     12: #include "config.h"
                     13: #include "options.h"
                     14: #include "memory.h"
                     15: #include "custom.h"
1.1.1.2 ! root       16: #include "readcpu.h"
1.1       root       17: #include "newcpu.h"
                     18: 
1.1.1.2 ! root       19: #ifndef O_NONBLOCK
        !            20: #define O_NONBLOCK O_NDELAY
        !            21: #endif
        !            22: 
1.1       root       23: void serial_init(void);
                     24: void serial_exit(void);
                     25: 
                     26: UWORD SERDATR(void);
                     27: void  SERPER(UWORD w);
                     28: void  SERDAT(UWORD w);
                     29: 
                     30: int sersend;
                     31: int serrecv;
                     32: int sd = -1;
                     33: 
                     34: UWORD serdat;
                     35: 
                     36: void SERPER(UWORD w)
                     37: {
                     38:     if (!use_serial)
                     39:        return;
                     40: 
                     41: #ifndef __DOS__
                     42:     if (w&0x8000) fprintf (stdout, "SERPER: 9 Bit Transmission not implemented\n");
                     43:     fprintf (stdout, "serial port baudrate set to ");
                     44:     switch (w & 0x7fff)
                     45:     {
                     46:      case 0x2e9b: fprintf (stdout, "  300\n"); return;
                     47:      case 0x0ba6: fprintf (stdout, " 1200\n"); return;
                     48:      case 0x02e9: fprintf (stdout, " 4800\n"); return;
                     49:      case 0x0174: fprintf (stdout, " 9600\n"); return;
                     50:      case 0x00b9: fprintf (stdout, "19200\n"); return;
                     51:      case 0x005c: fprintf (stdout, "38400\n"); return;
                     52:      default:
                     53:        fprintf(stdout,"%d (approx.)\n",
                     54:                (unsigned int)(3579546.471/(double)((w&0x7fff)+1)));  return;
                     55:     }
                     56: #else
                     57:     if (w&0x8000) fprintf (stderr, "SERPER: 9 Bit Transmission not implemented\n");
                     58:     fprintf (stderr, "serial port baudrate set to ");
                     59:     switch (w & 0x7fff)
                     60:     {
                     61:      case 0x2e9b: fprintf (stderr, "  300\n"); return;
                     62:      case 0x0ba6: fprintf (stderr, " 1200\n"); return;
                     63:      case 0x02e9: fprintf (stderr, " 4800\n"); return;
                     64:      case 0x0174: fprintf (stderr, " 9600\n"); return;
                     65:      case 0x00b9: fprintf (stderr, "19200\n"); return;
                     66:      case 0x005c: fprintf (stderr, "38400\n"); return;
                     67:      default:
                     68:        fprintf(stderr,"%d (approx.)\n",
                     69:                (unsigned int)(3579546.471/(double)((w&0x7fff)+1)));  return;
                     70:     }
                     71: #endif
                     72: }
                     73: 
                     74: void SERDAT(UWORD w)
                     75: {
                     76:     char z;
                     77: 
                     78:     if (!use_serial)
                     79:        return;
                     80: 
                     81:     fprintf(stderr,"SERDAT: wrote 0x%04x\n",w);
                     82:     z=(char)(w&0xff);
                     83:     if (sd>0) {
                     84:        write (sd,&z,1);
                     85:     }   
                     86:     return;
                     87: }
                     88: 
                     89: UWORD SERDATR(void)
                     90: {
                     91:     char z;
                     92: 
                     93:     if (!use_serial)
1.1.1.2 ! root       94:        return 0;
1.1       root       95: 
                     96:     if ((read (sd, &z,1))==1) {
                     97:        serdat=0x6100;
                     98:        intreq|=0x0800;
                     99:        serdat+=(int)z;
                    100: #ifndef __DOS__
                    101:        fprintf (stdout,"SERDATR: received 0x%02x\n",(int)z);
                    102: #else
                    103:        fprintf (stderr,"SERDATR: received 0x%02x\n",(int)z);
                    104: #endif
                    105:     }
                    106:     return serdat;
                    107: }
                    108: 
                    109: void serial_init(void)
                    110: {
                    111:     if (!use_serial)
                    112:        return;
                    113: 
                    114: #ifndef __DOS__
                    115:     if ((sd=open(sername,O_RDWR|O_NONBLOCK))<0)
                    116:        fprintf (stderr,"Error: Could not open Device %s\n",sername);
                    117: #else
                    118:     if ((sd=open(sername,O_RDWR|O_NONBLOCK|O_BINARY))<0)
                    119:        fprintf (stderr,"Error: Could not open Device %s\n",sername);
                    120: #endif
                    121:     serdat=0x2000;
                    122:     return;
                    123: }
                    124: 
                    125: void serial_exit(void)
                    126: {
                    127:     if (sd >= 0)
                    128:        close(sd);
                    129:     return;
                    130: }

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.