1 | #include "stdio.txt" |
---|
2 | #include "string.txt" |
---|
3 | #include "fileio.txt" |
---|
4 | #include "alloc.txt" |
---|
5 | |
---|
6 | #define CONSTAT *0xff80 |
---|
7 | #define CONDATA *0xff81 |
---|
8 | #define REMSTAT *0xff90 |
---|
9 | #define REMDATA *0xff91 |
---|
10 | |
---|
11 | #define RXRDY 0x01 |
---|
12 | #define TXRDY 0x02 |
---|
13 | |
---|
14 | #define BREAK 0x00 |
---|
15 | #define EOT 0x04 |
---|
16 | #define ESC 0x1b |
---|
17 | |
---|
18 | main() |
---|
19 | { printf("Terminal emulator\n"); |
---|
20 | reminit(); |
---|
21 | while (1) |
---|
22 | { printf("\nT(erm , F(ile , E(xit : "); |
---|
23 | switch ( toupper(getchar()) ) |
---|
24 | { case 'T' : term(); break; |
---|
25 | case 'F' : filer(); break; |
---|
26 | case 'E' : exit(); |
---|
27 | } |
---|
28 | } |
---|
29 | } |
---|
30 | |
---|
31 | term() |
---|
32 | {char c; |
---|
33 | printf("\n>>> enter terminal mode <ctl-@ to exit>\n"); |
---|
34 | #asm |
---|
35 | ORCC #$50 disable interrupt |
---|
36 | #endasm |
---|
37 | while (1) |
---|
38 | { if ( remstat() ) conwrite(remread()); |
---|
39 | if ( constat() ) |
---|
40 | { if ( (c = conread()) == BREAK ) break; |
---|
41 | remwrite(c); |
---|
42 | } |
---|
43 | } |
---|
44 | ; |
---|
45 | #asm |
---|
46 | ANDCC #$AF restore interrupt mask |
---|
47 | #endasm |
---|
48 | } |
---|
49 | |
---|
50 | filer() |
---|
51 | { printf("\n>>> enter file transfer mode\n"); |
---|
52 | while (1) |
---|
53 | { printf("\nDirection F(lex->unix , U(nix->flex , E(xit : "); |
---|
54 | switch ( toupper(getchar()) ) |
---|
55 | { case 'F' : flex_unix(); break; |
---|
56 | case 'U' : unix_flex(); break; |
---|
57 | case 'E' : return; |
---|
58 | } |
---|
59 | } |
---|
60 | } |
---|
61 | |
---|
62 | flex_unix() |
---|
63 | {char fn0[80],fn1[80],c; |
---|
64 | FILE *fp; |
---|
65 | printf("\nFLEX to UNIX file transfer\n"); |
---|
66 | printf("FLEX file name : "); |
---|
67 | gets(fn0,80); |
---|
68 | printf("\n"); |
---|
69 | toupstr(fn0); |
---|
70 | if ( (fp = fopen(fn0,"rc")) < 0 ) |
---|
71 | { printf("Can't open %s\n",fn0); |
---|
72 | return; |
---|
73 | } |
---|
74 | printf("UNIX file name : "); |
---|
75 | gets(fn1,80); |
---|
76 | printf("\n"); |
---|
77 | tx_str("cat /dev/tty >"); |
---|
78 | tx_str(fn1); |
---|
79 | tx_char('\n'); |
---|
80 | while ( (c = getc(fp)) != EOF ) tx_char(c); |
---|
81 | remwrite(EOT); |
---|
82 | fclose(fp); |
---|
83 | } |
---|
84 | |
---|
85 | unix_flex() |
---|
86 | {char fn0[80],fn1[80],c; |
---|
87 | FILE *fp; |
---|
88 | int i; |
---|
89 | char linebuf[256]; |
---|
90 | printf("\nUNIX to FLEX file transfer\n"); |
---|
91 | printf("UNIX file name : "); |
---|
92 | gets(fn0,80); |
---|
93 | printf("\nFLEX file name : "); |
---|
94 | gets(fn1,80); |
---|
95 | printf("\n"); |
---|
96 | toupstr(fn1); |
---|
97 | if ( (fp = fopen(fn1,"wc")) < 0 ) |
---|
98 | { printf("Can't create %s\n",fn1); |
---|
99 | return; |
---|
100 | } |
---|
101 | tx_str("/mnt/sys/tezuka/unix_flex/unix_flex "); |
---|
102 | tx_str(fn0); |
---|
103 | tx_char('\n'); |
---|
104 | while ( 1 ) { |
---|
105 | i = 0; |
---|
106 | while ( (c = remread()) != '\n' ) { |
---|
107 | if ( c == ESC ) { |
---|
108 | fclose(fp); |
---|
109 | return; |
---|
110 | } |
---|
111 | linebuf[i++] = c; |
---|
112 | } |
---|
113 | linebuf[i++] = '\n'; |
---|
114 | linebuf[i] = '\0'; |
---|
115 | for ( i = 0; linebuf[i]; i++ ) putc(linebuf[i],fp); |
---|
116 | remwrite(ESC); |
---|
117 | putchar('.'); |
---|
118 | } |
---|
119 | } |
---|
120 | |
---|
121 | toupstr(s) |
---|
122 | char *s; |
---|
123 | { while ( *s ) |
---|
124 | { *s = toupper(*s); |
---|
125 | ++s; |
---|
126 | } |
---|
127 | } |
---|
128 | |
---|
129 | tx_str(s) |
---|
130 | char *s; |
---|
131 | { while ( *s ) tx_char(*s++); |
---|
132 | } |
---|
133 | |
---|
134 | tx_char(c) |
---|
135 | char c; |
---|
136 | { remwrite(c); |
---|
137 | while ( c != remread() ); |
---|
138 | /* */putchar(c); |
---|
139 | } |
---|
140 | |
---|
141 | constat() |
---|
142 | { return ( CONSTAT & RXRDY ); |
---|
143 | } |
---|
144 | |
---|
145 | conread() |
---|
146 | { while ( !constat() ); |
---|
147 | return ( CONDATA & 0x7f); |
---|
148 | } |
---|
149 | |
---|
150 | conwrite(ch) |
---|
151 | char ch; |
---|
152 | { while ( !(CONSTAT & TXRDY) ); |
---|
153 | CONDATA = ch; |
---|
154 | } |
---|
155 | |
---|
156 | reminit() |
---|
157 | { |
---|
158 | REMSTAT = 0x43; |
---|
159 | REMSTAT = 0x15; |
---|
160 | } |
---|
161 | |
---|
162 | remstat() |
---|
163 | { return ( REMSTAT & RXRDY ); |
---|
164 | } |
---|
165 | |
---|
166 | remread() |
---|
167 | { while ( !remstat() ); |
---|
168 | return ( REMDATA & 0x7f ); |
---|
169 | } |
---|
170 | |
---|
171 | remwrite(ch) |
---|
172 | char ch; |
---|
173 | { while ( !(REMSTAT & TXRDY) ); |
---|
174 | REMDATA = ch; |
---|
175 | } |
---|
176 | |
---|