-
Notifications
You must be signed in to change notification settings - Fork 3
/
Monitor.spin
154 lines (115 loc) · 9.03 KB
/
Monitor.spin
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
''***************************************
''* Hex Monitor v1.0 *
''* Author: Chip Gracey *
''* Copyright (c) 2005 Parallax, Inc. *
''* See end of file for terms of use. *
''***************************************
' connects to a terminal via rx/tx pins
'
' commands: (backspace is supported)
'
' <enter> - dump next 256 bytes
' addr <enter> - dump 256 bytes starting at addr
' addr b1 b2 b3 <enter> - enter bytes starting at addr
CON
maxline = 64
VAR
long rx, tx, baud, linesize, linepos, hex, address, stack[40]
byte line[maxline]
PUB start(rxpin, txpin, baudrate) : okay
'' Start monitor in another cog
rx := rxpin
tx := txpin
baud := clkfreq / baudrate
okay := cognew(monitor, @stack) > 0
PRI monitor
' Actual 'monitor' program that runs in another cog
outa[tx] := dira[tx] := 1
repeat
linesize := getline
linepos := 0
if gethex
address := hex
if gethex
repeat
byte[address++] := hex
while gethex
else
hexpage
else
hexpage
PRI gethex : got | c
hex := 0
repeat while linepos <> linesize
case c := line[linepos++]
" ": if got
quit
other: hex := hex << 4 + lookdownz(c : "0".."9", "A".."F")
got++
PRI getline : size | c
serout(">")
repeat
case c := uppercase(serin)
"0".."9", "A".."F", " ":
if size <> maxline
line[size++] := c
serout(c)
8: if size
size--
serout(8)
serout(" ")
serout(8)
13: serout(c)
quit
PRI uppercase(c) : chr
if lookdown(c: "a".."z")
c -= $20
chr := c
PRI hexpage | c
repeat 16
hexout(address,4)
serout("-")
repeat 16
hexout(byte[address++],2)
serout(" ")
address -= 16
repeat 16
c := byte[address++]
if not lookdown(c : $20..$80)
c := "."
serout(c)
serout(13)
PRI hexout(value, digits)
value <<= (8-digits) << 2
repeat digits
serout(lookupz((value <-= 4) & $F : "0".."9", "A".."F"))
PRI serout(b) | t
b := b.byte << 2 + $400
t := cnt
repeat 10
waitcnt(t += baud)
outa[tx] := (b >>= 1) & 1
PRI serin : b | t
waitpeq(0, |< rx, 0)
t := cnt + baud >> 1
repeat 8
waitcnt(t += baud)
b := ina[rx] << 7 | b >> 1
waitcnt(t + baud)
{{
┌──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┐
│ TERMS OF USE: MIT License │
├──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┤
│Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation │
│files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, │
│modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software│
│is furnished to do so, subject to the following conditions: │
│ │
│The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.│
│ │
│THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE │
│WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR │
│COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, │
│ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. │
└──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┘
}}