-
Notifications
You must be signed in to change notification settings - Fork 1
/
mserase.asm
206 lines (185 loc) · 6.13 KB
/
mserase.asm
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
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
;
; Slowdos Source Code
;
;
; $Id: mserase.asm,v 1.3 2003/06/15 20:26:25 dom Exp $
; $Author: dom $
; $Date: 2003/06/15 20:26:25 $
;
; Erase command
MODULE erase
INCLUDE "slowdos.def"
INCLUDE "syntaxdefs.def"
;; Errors that we use
EXTERN errorn
EXTERN error_notfound
EXTERN error_filetype
;; Other things
EXTERN settapn
EXTERN clfiln
EXTERN clfilen
EXTERN ckchar
EXTERN discan
EXTERN disca0
EXTERN swos
EXTERN swos1
EXTERN rdnxft
EXTERN link_clusters
EXTERN wrfata
EXTERN r_hxfer
EXTERN uftofin
EXTERN ckwild
PUBLIC hook_erase
PUBLIC erase
PUBLIC getdiroffset
fildes: defs 12,32 ; VARIABLE
hook_erase:
call r_hxfer
call uftofin
ld hl,filen
call ckwild
jp en_ers
; Erase command
;
; Syntax:
; ERASE Pdd"f" - erase file f from the disc, f may be wild
; ERASE Pdd"u1" TO "u2" - rename u1 to u2
erase:
call getdrv ; Get the drive
call cksemi ; Get a semi colon, comma or quote
call exptex ; We want some text
call ckenqu ; Check for end of statement (i.e. delete)
jp z,erase6
cp 204 ; If not end, TO must follow
jp nz,error_nonsense ; If not, then nonsense in basic
; Renaming files
call rout32
call cksemi ; We expect a semi colon, comma or filename
call exptex ; Get a strinbg
call ckend ; End of statement
call settapn ; Clear .TAP modes
ld hl,fildes ; Clear fildes
call clfiln ; Exits with hl=fildes
call getstr ; Get the second string
jr z,eras15
eras14: call errorn
defb 43 ;bad filename
eras15: call clfilen ; Clear ufia+2, hl = ufia+2
call getstr ; Get the original filename
jr nz,eras14
call discan ; Search for the original filename a = posn
jp nc,error_notfound ; File not found
erase0: ld de,(dirsol) ; Get directory sector
push de ; Save it
call getdiroffset ; Get offset within sector for dir entry
push hl ; Save that too
ld hl,sector ; Copy the read sector to the write sector
ld de,wrisec
push de
ld bc,512
ldir
pop de ; Get wrisec back
pop ix ; Get the offset into sector back
add ix,de ; Now ix points to the file
erase2: bit 0,(ix+11) ; Check for read only flag
jr z,eras25
call errorn
defb 52 ;read only
eras25: push ix ; Save the sector positoin
ld hl,fildes ; Check the new filename for bad characters
push hl
call ckchar
pop hl
jp c,error_filename
pop de ; Copy the new filename over the old one
push hl ; hl = fildes
ld bc,8
ldir
inc hl ; Now do extension
ld bc,3
ldir
pop hl ; Get fildes back, copy to filen
ld de,filen
ld bc,12
ldir
call discan ; Scan the disc for the new name
jr nc,erase4 ; If found then error
call errorn
defb 32 ;file exists
erase4: pop de ; Not found, so write out the directory sector
jp swos
; Delete a file from disc
erase6: call ckend ; End of statement
call settapn ; Clear .TAP modes
call clfilen ; Clear filen, hl = filen
call getstr ; Get the filename
en_ers: ld hl,flags
res 2,(hl) ; No files found yet
inc hl ; hl=flags2
res 4,(hl) ; Indicate start from beginning of directory
eras64: call disca0 ; Scan the disc
jr c,erase8 ; Filename found
ld hl,flags
bit 1,(hl) ; Check if wild filename was supplied
jr z,erase7 ; No it wasn't
bit 2,(hl) ; Check to see if we already found something
ret nz ; We did, so exit normally
erase7: call errorn
defb 34 ;file not exist
erase8: call getdiroffset ; Offset within directory
push hl ; Save it
ld hl,sector ; Copy this sector to write sector
ld de,wrisec
push de
ld bc,512
ldir
pop de ; de = wrisec
pop ix ; offset within directory
add ix,de
bit 0,(ix+11) ; check for read only file
jr z,eras81
call errorn
defb 52 ;file read only
eras81: bit 4,(ix+11) ; can't delete directories
jp nz,error_filetype
eras82: bit 3,(ix+11) ; can't delete volume names
jp nz,error_filetype
ld (ix+0),229 ; Blank out first character of name
; Chase the FAT trail and zero down clusters occupied by this file
ld e,(ix+26)
ld d,(ix+27)
eras84: push de
call rdnxft ; de = next cluster
pop hl ; hl = current cluster
push af ; Save whether valid next cluster or not
ex de,hl
push hl ; Save next cluster
ld bc,0 ; Zero out that link
call link_clusters
pop de ; Get next cluster back
pop af ; nc means next cluster is good
jr nc,eras84
ld hl,swos1 ; Write out one copy of the FAT, save the other
call wrfata ; so it can be used to restore files
ld de,(dirsol) ; Write out the directory sector
call swos
ld hl,flags
set 2,(hl) ; Indicate that we've deleted a file
bit 1,(hl) ; Check to see if filename was wild
inc hl ; hl=flags2
set 4,(hl) ; Continue scanning directory from last posn
jr nz,eras64 ; loop back around if filename was wild
ret
;Routine to find position in directory sector
;Entry: a=file posn (and 15)
;Exit: hl=offset
getdiroffset:
and 15
add A,A
ADD A,A
ADD A,A
ld l,a
ld h,0
add hl,hl
add hl,hl
ret