-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsdfat-clustmap.spin
165 lines (145 loc) · 6.57 KB
/
sdfat-clustmap.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
155
156
157
158
159
160
161
162
163
164
{
---------------------------------------------------------------------------------------------------
Filename: sdfat-clustmap.spin
Description: FAT/cluster map tool
Author: Jesse Burt
Started: May 13, 2023
Updated: Mar 11, 2024
Copyright (c) 2024 - See end of file for terms of use.
---------------------------------------------------------------------------------------------------
}
CON
_clkmode = cfg._clkmode
_xinfreq = cfg._xinfreq
OBJ
cfg: "boardcfg.flip"
ser: "com.serial.terminal.ansi" | SER_BAUD=115_200
sd: "memfs.sdfat" | CS=22+3, SCK=22+1, MOSI=22+2, MISO=22+0
time: "time"
PUB main() | sect, fat_nr, tmp, fat_entry, first_ent, last_ent, new_val
setup()
sect := 0 ' relative to FAT1 start sector
sd.read_fat(sect)
repeat
if ( (sect => 0) and (sect < sd.sects_per_fat()) )
fat_nr := 1
elseif ( (sect => sd.sects_per_fat()) and (sect < sd.sects_per_fat() * 2) )
fat_nr := 2
ser.pos_xy(0, 3)
ser.printf2(@"FAT #%d, sector %d", fat_nr, sd.fat1_start()+sect)
ser.clear_line()
ser.newline()
ser.hexdump(sd.getsbp(), 0, 4, 512, 16)
case ser.getchar()
"[": ' read prev FAT sector (limited to fat1_start())
sect := 0 #> (sect - 1)
sd.read_fat(sect)
"]": ' read next FAT sector (limited to sects_per_fat())
sect := (sect + 1) <# (sd.sects_per_fat() * 2)
sd.read_fat(sect)
"s": ' read first FAT sector
sect := 0
sd.read_fat(sect)
"e": ' read last FAT sector
sect := sd.sects_per_fat()-1
sd.read_fat(sect)
"n": ' add a new entry
ser.set_attrs(ser.ECHO)
repeat
ser.str(@"FAT entry to add (decimal, 0..127)? ")
tmp := ser.getdec()
if ( (tmp < 0) or (tmp > 127) )
ser.fgcolor(ser.RED)
ser.strln(@" invalid entry - retry")
ser.fgcolor(ser.GREY)
next
ser.newline()
quit
fat_entry := sd.read_fat_entry(tmp)
repeat
ser.printf1(@"Entry current value: %08.8x\n\r", fat_entry)
ser.str(@"New entry (hex, 0..0fffffff)? ")
new_val := ser.gethex()
if ( (new_val < 0) or (new_val > $0fff_ffff) )
ser.fgcolor(ser.RED)
ser.strln(@" invalid entry - retry")
ser.fgcolor(ser.GREY)
next
ser.newline()
quit
ser.set_attrs(0)
sd.write_fat_entry(tmp, new_val)
"c": ' clear FAT entry (in memory only)
ser.set_attrs(ser.ECHO)
repeat
ser.str(@"FAT entry to clear (decimal, 0..127)? ")
tmp := ser.getdec()
if ( (tmp < 0) or (tmp > 127) )
ser.fgcolor(ser.RED)
ser.strln(@" invalid entry - retry")
ser.fgcolor(ser.GREY)
next
ser.newline()
quit
ser.set_attrs(0)
fat_entry := sd.read_fat_entry(tmp)
ser.printf1(@"Entry current value: %08.8x\n\r", fat_entry)
sd.write_fat_entry(tmp, 0)
"C": ' clear range of FAT entries (in memory only)
ser.set_attrs(ser.ECHO)
repeat
ser.str(@"First FAT entry to clear (decimal, 0..127)? ")
first_ent := ser.getdec()
if ( (first_ent < 0) or (first_ent > 127) )
ser.fgcolor(ser.RED)
ser.strln(@" invalid entry - retry")
ser.fgcolor(ser.GREY)
next
ser.newline()
quit
repeat
ser.printf1(@"Last FAT entry to clear (decimal, %d..127)? ", first_ent)
last_ent := ser.getdec()
if ( (last_ent < first_ent) or (last_ent > 127) )
ser.fgcolor(ser.RED)
ser.strln(@" invalid entry - retry")
ser.fgcolor(ser.GREY)
next
ser.newline()
quit
ser.set_attrs(0)
fat_entry := sd.read_fat_entry(tmp)
ser.printf1(@"Entry current value: %08.8x\n\r", fat_entry)
repeat tmp from first_ent to last_ent
sd.write_fat_entry(tmp, 0)
"w": ' write changes to SD
sd.write_fat(sect)
sd.read_fat(sect)
repeat
PUB setup() | err
ser.start()
time.msleep(30)
ser.clear()
ser.strln(@"serial terminal started")
err := sd.start()
if (err < 0)
ser.printf1(@"Error mounting SD card %x\n\r", err)
repeat
else
ser.printf1(@"Mounted card (%d)\n\r", err)
DAT
{
Copyright 2024 Jesse Burt
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.
}