]> cloudbase.mooo.com Git - avrcpm.git/blob - cpm/utils/wipe.mac
* avr/config.inc
[avrcpm.git] / cpm / utils / wipe.mac
1 ; This is a utility program to delete all data on a disk drive.
2 ; The deletion is done by filling all directory sectors with 0E5h.
3 ;
4 ; The program can be used, to init a RAM disk after cold start.
5 ;
6 ; Copyright (C) 2010 Leo C.
7 ;
8 ; This program is free software: you can redistribute it and/or modify
9 ; it under the terms of the GNU General Public License as published by
10 ; the Free Software Foundation, either version 3 of the License, or
11 ; (at your option) any later version.
12 ;
13 ; This program is distributed in the hope that it will be useful,
14 ; but WITHOUT ANY WARRANTY; without even the implied warranty of
15 ; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 ; GNU General Public License for more details.
17 ;
18 ; You should have received a copy of the GNU General Public License
19 ; along with this program. If not, see <http://www.gnu.org/licenses/>.
20 ;
21 ; $Id$
22
23 .Z80
24
25 ; BIOS functions
26
27 biosofs equ -3 ;offset
28
29 wbootf equ biosofs+3*1 ;warm boot function
30 homef equ biosofs+3*8 ;disk home function
31 seldskf equ biosofs+3*9 ;select disk function
32 settrkf equ biosofs+3*10 ;set track function
33 setsecf equ biosofs+3*11 ;set sector function
34 setdmaf equ biosofs+3*12 ;set dma function
35 readf equ biosofs+3*13 ;read disk function
36 writef equ biosofs+3*14 ;write disk function
37 sectranf equ biosofs+3*16 ;sector translate
38
39 ; BDOS functions
40
41 pstring equ 9
42 rstring equ 10
43 seldsk equ 14
44
45 cdisk equ 4
46 bdos equ 5
47 cr equ 13
48 lf equ 10
49 tab equ 9
50
51 buf equ 80h
52
53
54 aseg
55 org 100h
56
57 jp start
58
59 rev: db '$Id$'
60 usage: db 'Usage: WIPE [Options] d:',cr,lf
61 db 'Delete all files on drive d: in all user areas.',cr,lf
62 db cr,lf
63 db 'Options:',cr,lf
64 db ' -Y Don''t ask for confirmation.',cr,lf
65 db '$'
66 mdrvinval:
67 db 'Invalid drive: '
68 minvch: db '?:' ;filled in
69 db cr,lf,'$'
70 mnodrive:
71 db 'Can not select drive '
72 mnodrch:db '?:' ;filled in
73 db cr,lf,'$'
74 mnowipe:db 'Nothing done.'
75 mcrlf: db cr,lf,'$'
76 mconfirm:
77 db 'Delete all files in all user areas on drive '
78 mcfmchar:
79 db '?: (Y/N)?','$'
80
81 drive: db 0
82 optyes:
83 db 0
84 transtbl:
85 ds 2
86 ccpret: ds 2
87 conbuf: db conlen
88 consiz: ds 1
89 conlin: ds 15
90 conlen equ $-consiz
91
92 ; Get next character from commandline
93
94 getchar:
95 ld a,(hl)
96 inc hl
97 or a ;eol?
98 ret
99
100 ; Skip white space
101
102 skipblank:
103 ld a,(hl)
104 inc hl
105 or a ;eol?
106 ret z
107 cp ' '
108 jp z,skipblank
109 cp tab
110 jp z,skipblank
111 ret
112
113 ; Setup command line. (Terminate with 0)
114
115 setupcmdl:
116 ld hl,buf
117 ld e,(hl) ; get number of characters on command line
118 ld d,0
119 inc hl
120 ex de,hl
121 add hl,de
122 ld (hl),0
123 ex de,hl
124 ret
125
126 ; Parse commandline
127
128 parsecmd:
129 call skipblank
130 jp z,pusage ; empty command line
131 cp '-'
132 jp nz,pcmdarg ; no option, parse agrument
133 call getchar
134 cp 'Y'
135 jp nz,pusage
136 ld (optyes),a
137 call skipblank
138 jp z,pusage ; no argument
139 pcmdarg:
140 ld b,'?' ; get argument (disk drive)
141 cp ' ' ; non printable char?
142 jp c,pcmd1
143 ld b,a
144 pcmd1:
145 call getchar
146 cp ':'
147 ret nz
148 ld a,b
149 ld (drive),a
150 call skipblank
151 jp nz,pusage
152 ret
153
154
155 ; Fill buffer with E5
156
157 fillbuf:
158 ld hl,buf
159 ld c,128
160 ld a,0e5h
161 fbl:
162 ld (hl),a
163 inc hl
164 dec c
165 jp nz,fbl
166 ret
167
168 ; Print messages on console
169
170 pusage: ld de,usage ; address of usage text
171 jp pmsgexit
172
173 pdrvinval:
174 ld (minvch),a
175 ld de,mdrvinval ;
176 jp pmsgexit
177
178 pnodrive:
179 ld a,(drive)
180 ld (mnodrch),a
181 ld de,mnodrive ;
182 jp pmsgexit
183
184 ; Ask for confirmation.
185
186 confirm:
187 ld a,(drive)
188 ld (mcfmchar),a
189 ld de,mconfirm ;
190 ld c,pstring ; CP/M command for print
191 call bdos
192 ld de,conbuf
193 ld c,rstring
194 call bdos
195 ld de,mcrlf
196 ld c,pstring ; CP/M command for print
197 call bdos
198 ld a,(conlin) ; first char
199 and 05fh ; toupper()
200 cp 'Y'
201 ret z
202 ld de,mnowipe
203 pmsgexit:
204 ld c,pstring ; CP/M command for print
205 call bdos ; print it
206
207 ; Return to CCP (no warmboot).
208
209 exitccp:
210 ld hl,(ccpret)
211 jp (hl)
212
213 ; Call BIOS functions
214
215 bseldsk:
216 ld hl,(1)
217 ld de,seldskf
218 add hl,de
219 jp (hl)
220 bsetdma:
221 ld hl,(1)
222 ld de,setdmaf
223 add hl,de
224 jp (hl)
225 bsettrk:
226 ld hl,(1)
227 ld de,settrkf
228 add hl,de
229 jp (hl)
230 bsetsec:
231 call bsectran
232 ld c,l
233 ld b,0
234 ld hl,(1)
235 ld de,setsecf
236 add hl,de
237 jp (hl)
238 bwrite:
239 ld c,1 ;write type = dir
240 ld hl,(1)
241 ld de,writef
242 add hl,de
243 jp (hl)
244 bsectran:
245 ld hl,(1)
246 ld de,sectranf
247 add hl,de
248 ex de,hl
249 ld hl,(transtbl)
250 ex de,hl
251 jp (hl)
252
253 ; The main function
254
255 start:
256 pop hl ; Get return address;
257 ld (ccpret),hl ; and save it for later
258 ld sp,stack ; Setup local stack.
259 call setupcmdl
260 call parsecmd
261 ld a,(drive) ; Was a drive specified?
262 or a
263 jp z,pusage ; If not, print message and return.
264 cp 'A' ; valid drive letter?
265 jp c,pdrvinval
266 cp 'P'+1
267 jp nc,pdrvinval
268
269 ld a,(optyes) ; Was 'Y' option given?
270 or a
271 call z,confirm ; If no, ask for confirmation.
272
273 ; Command is ok and confirmed, check drive
274
275 ld a,(drive) ; Select the requested drive.
276 sub 'A' ; Use the BIOS function for this,
277 ld c,a ; as BDOS would initialize the drive
278 call bseldsk ; and try to read the (broken) directory.
279 ld a,l
280 or h
281 jp nz,getdpb
282
283 ld a,(cdisk) ; Reselect current disk drive.
284 and 0fh
285 ld c,a
286 call bseldsk
287 jp pnodrive ; Msg, and return to CCP.
288
289 ; Drive exists. Get disk parameter
290 getdpb:
291 ld a,(hl) ; sector translation table
292 ld (transtbl),a
293 inc hl
294 ld a,(hl)
295 ld (transtbl+1),a
296 dec hl
297 ld de,10 ; dpb ofset
298 add hl,de
299 ld e,(hl)
300 inc hl
301 ld d,(hl) ; de = dpb of selected drive
302
303 ld hl,13 ; ofset to # of reserved tracks
304 add hl,de
305 ld c,(hl) ; Start track
306 inc hl
307 ld b,(hl) ; bc = track
308
309 push bc ; save for later
310
311 ; Compute number of sectors to fill.
312
313 ld hl,7 ; drm ofset
314 add hl,de
315 ld a,(hl) ; get drm (# of dir entries - 1)
316 add a,3+1 ; round up
317 ld c,a
318 inc hl
319 ld a,(hl) ; Each sector holds 4 dir entries
320 adc a,0
321 rra
322 ld b,a
323 ld a,c
324 rra
325 ld c,a
326 ld a,b
327 or a ; clear carry
328 rra
329 ld b,a
330 ld a,c
331 rra
332 ld c,a ; c = # of sectors ((drm+1+3)/4)
333
334 ; Get sectors per track.
335
336 ld a,(de) ; b = sectors per track
337 ld b,a
338 push bc
339
340 ; Init fill loop.
341
342 call fillbuf
343 ld bc,buf
344 call bsetdma
345
346 ld bc,0 ; c = sec
347 pop de ; d = spt, e = nsec
348 pop hl ; hl = track
349 nxtrk:
350 push hl ; track
351 push de ; spt, nsec
352 push bc ; sec
353 ld b,h
354 ld c,l
355 call bsettrk ;
356 pop bc
357 pop de
358 nxtsec:
359 push de ;
360 push bc
361 call bsetsec
362 call bwrite
363 pop bc ;sec
364 pop de ;d = spt, e = nsec
365 dec e
366 jp z,done
367
368 inc c ;next sector
369 ld a,c
370 cp d ;if sector >= spt then change tracks
371 jp c,nxtsec
372
373 ld c,b ;sec = 0
374 pop hl
375 inc hl ;next track
376 jp nxtrk
377
378 ; All directory sectors filled.
379 done:
380 pop hl
381 jp 0 ; Boot (reinits disks)
382
383 progend:ds (($+255) and 0ff00h)-$ ; Fill rest of page with zero
384
385 stack equ progend+40
386
387 end
388
389 ; vim:set ts=8 noet nowrap
390