-
Notifications
You must be signed in to change notification settings - Fork 26
/
portio.pla
45 lines (43 loc) · 842 Bytes
/
portio.pla
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
//
// Game port I/O library based on the wiring library
//
include "inc/cmdsys.plh"
const ANN0 = $C058
const ANN1 = $C05A
const ANN2 = $C05C
const ANN3 = $C05E
const OFF = 0
const ON = 1
const STROBE = $C040
const FLAG0 = $C060
const FLAG1 = $C061
const FLAG2 = $C062
const FLAG3 = $C063
const PREAD = $FB1E
const WAIT = $FCA8
export def digitalRead(pin)
return FLAG0[pin&3] > 127
end
export def portRead
return (^FLAG0>>7)&1|(^FLAG1>>6)&2|(^FLAG2>>5)&4|(^FLAG3>>4)&8
end
export def digitalWrite(pin, val)#0
ANN0[((pin&3)<<1)+(val&1)]
end
export def portWrite(val)#0
ANN0[val&1]
ANN1[(val>>1)&1]
ANN2[(val>>2)&1]
ANN3[(val>>3)&1]
end
export def analogRead(pin)
return call(PREAD,0,pin&3,0,0).2
end
export def delay(time)#0
call(WAIT,time,0,0,0)
end
//
// Keep module in memory
//
return modkeep
done