TTY.icl 1.55 KB
Newer Older
Mart Lubbers's avatar
Mart Lubbers committed
1
2
implementation module TTY

3
import StdClass
Mart Lubbers's avatar
Mart Lubbers committed
4
5
6
7
8
9
10
11
12
13

import code from "tty."

:: *TTY :== Int

instance zero TTYSettings where
	zero = {TTYSettings |
		baudrate = B9600,
		bytesize = BytesizeEight,
		parity = ParityNone,
Mart Lubbers's avatar
Mart Lubbers committed
14
		stop2bits = False,
Mart Lubbers's avatar
Mart Lubbers committed
15
16
17
		xonxoff = False}

instance toInt BaudRate where
Mart Lubbers's avatar
Mart Lubbers committed
18
19
20
21
22
	toInt b = case b of
		B0 = 0; B50 = 1; B75 = 2; B110 = 3; B134 = 4; B150 = 5; B200 = 6
		B300 = 7; B600 = 8; B1200 = 9; B1800 = 10; B2400 = 11; B4800 = 12
		B9600 = 13; B19200 = 14; B38400 = 15; B57600 = 16; B115200 = 17
		B230400 = 18
Mart Lubbers's avatar
Mart Lubbers committed
23
24

instance toInt ByteSize where
Mart Lubbers's avatar
Mart Lubbers committed
25
26
	toInt b = case b of
		BytesizeFive = 0; BytesizeSix = 1; BytesizeSeven = 2; BytesizeEight = 3
Mart Lubbers's avatar
Mart Lubbers committed
27
28

instance toInt Parity where
Mart Lubbers's avatar
Mart Lubbers committed
29
	toInt p = case p of
30
31
		ParityNone = 0; ParityOdd = 1; ParityEven = 2; ParitySpace = 3;
		ParityMark = 4
Mart Lubbers's avatar
Mart Lubbers committed
32
33
34
35
36
37
38

TTYopen :: !String !TTYSettings !*env -> (!Bool, !*TTY, !*env)
TTYopen fn ts w = TTYopen2
	fn
	(toInt ts.baudrate)
	(toInt ts.bytesize)
	(toInt ts.parity)
Mart Lubbers's avatar
Mart Lubbers committed
39
	ts.stop2bits
Mart Lubbers's avatar
Mart Lubbers committed
40
41
42
	ts.xonxoff
	w
	where
Mart Lubbers's avatar
Mart Lubbers committed
43
		TTYopen2 :: !String !Int !Int !Int !Bool !Bool !*env -> (!Bool, !*TTY, !*env)
Mart Lubbers's avatar
Mart Lubbers committed
44
45
46
47
48
		TTYopen2 _ _ _ _ _ _ _ = code {
				ccall ttyopen "SIIIII:VII:A"
			}

TTYclose :: !*TTY !*env -> (!Bool, !*env)
Mart Lubbers's avatar
Mart Lubbers committed
49
TTYclose _ _ = code {
Mart Lubbers's avatar
Mart Lubbers committed
50
51
52
53
		ccall ttyclose "I:I:A"
	}

TTYreadline :: !*TTY -> (!String, !*TTY)
Mart Lubbers's avatar
Mart Lubbers committed
54
TTYreadline _ = code {
Mart Lubbers's avatar
Mart Lubbers committed
55
		ccall ttyreadline "I:VSI"
56
	}
Mart Lubbers's avatar
Mart Lubbers committed
57

Mart Lubbers's avatar
Mart Lubbers committed
58
TTYwrite :: !*TTY !String -> *TTY
Mart Lubbers's avatar
Mart Lubbers committed
59
TTYwrite _ _ = code {
Mart Lubbers's avatar
Mart Lubbers committed
60
61
62
		ccall ttywrite "IS:I"
	}

Mart Lubbers's avatar
Mart Lubbers committed
63
64
65
66
67
TTYavailable :: !*TTY -> (!Bool, !*TTY)
TTYavailable _ = code {
		ccall ttyavailable "I:VII"
	}

Mart Lubbers's avatar
Mart Lubbers committed
68
TTYerror :: !*env -> (!String, !*env)
Mart Lubbers's avatar
Mart Lubbers committed
69
TTYerror _ = code {
Mart Lubbers's avatar
Mart Lubbers committed
70
71
72
		ccall ttyerror ":S:A"
	}

73
Start =0