-
Notifications
You must be signed in to change notification settings - Fork 2
/
dumbdrv.asm
282 lines (262 loc) · 5.73 KB
/
dumbdrv.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
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
;
; DumbDrv - Dummy DOS Device Driver
; Copyright (C) 1994-1997 Marcus Better
;
; This program is free software; you can redistribute it and/or modify
; it under the terms of the GNU General Public License as published by
; the Free Software Foundation; either version 2 of the License, or
; (at your option) any later version.
;
; This program is distributed in the hope that it will be useful,
; but WITHOUT ANY WARRANTY; without even the implied warranty of
; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
; GNU General Public License for more details.
;
; You should have received a copy of the GNU General Public License
; along with this program; if not, write to the Free Software
; Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
;
IDEAL
JUMPS
LOCALS
;========================================================= CONSTANTS
; Status codes
stSuccess EQU 0100h
stError EQU 8100h
stUnknownCmd EQU 8103h
stDrvNotReady EQU 8102h
MediaID EQU 0F0h ; Media ID byte - "other"
;========================================================= Driver segment
SEGMENT DrvSeg
ASSUME cs:DrvSeg,ds:NOTHING,es:NOTHING,ss:NOTHING
; Device header
DW 0FFFFh, 0 ; Link to next driver
DW 0 ; Attributes
DW Strategy, Interrupt
DB 1, 7 DUP (0) ; Number of units
;========================================================= Resident DATA area
; Data area
ReqHdrOfs DW 0 ; Offset ot request header
ReqHdrSeg DW 0 ; Segment of request header
VolumeID DB "DUMBDRV", 0
; BIOS Parameter Block
LABEL BPB
BytesPerSec DW 512
SecPerClust DB 2
ResSectors DW 1
FATs DB 1
RootDirEnts DW 32
Sectors DW 512
Media DB 0F0h
FATsecs DW 4
SecPerTrack DW 9
Heads DW 2
HiddenSecs DD 0
HugeSectors DD 0
pBPB DW 26 DUP(OFFSET BPB) ; Array of BPB pointers
JmpTbl DW Init, MediaChk, BuildBPB, 0
DW NotReady, 0, 0, 0
DW NotReady, NotReady
;========================================================= STRATEGY routine
PROC Strategy FAR
mov [ReqHdrOfs], bx
mov [ReqHdrSeg], es
ret
ENDP Strategy
;========================================================= INTERRUPT routine
PROC Interrupt FAR
push ax bx cx dx si di bp ds es
pushf
push cs
pop ds
ASSUME ds:DrvSeg
les bx, [DWORD ReqHdrOfs]
mov al, [es:bx+2] ; Function number
cmp al, 09h
ja @@errUnknownCommand
xor ah, ah
mov si, ax
shl si, 1
mov cx, [JmpTbl+si]
jcxz @@errUnknownCommand
call cx
jmp @@Exit
@@errUnknownCommand:
mov [WORD es:bx+3], stUnknownCmd
@@Exit: popf
pop es ds bp di si dx cx bx ax
ret
ENDP Interrupt
;========================================================= Functions
; Media check
PROC MediaChk
mov [WORD es:bx+3], stSuccess ; Status
mov [BYTE es:bx+14], 1 ; Media unchanged
mov [WORD es:bx+15], OFFSET VolumeID
mov [es:bx+17], cs
ret
ENDP MediaChk
; Build BPB
PROC BuildBPB
mov [WORD es:bx+3], stSuccess ; Status
mov [WORD es:bx+18], OFFSET BPB
mov [es:bx+20], cs
ret
ENDP BuildBPB
; Return "Drive not ready" error for Read or Write req.
PROC NotReady
mov [WORD es:bx+3], stDrvNotReady
mov [WORD es:bx+18], 0 ; Sectors read/written
mov [WORD es:bx+22], OFFSET VolumeID
mov [WORD es:bx+24], cs
ret
ENDP NotReady
LABEL EndResCode
;========================================================= INIT Code
PROC Init
; Say hello
mov ah, 09h
mov dx, OFFSET HelloMsg
int 21h
; Parse command line
call ParseCmdLine
jc @@CmdLineError
or al, al
jz @@CmdLineError ; Zero drives specified
mov ah, [es:bx+22] ; First drive number
add ah, al
cmp ah, 25 ; Maximum number of drives
jna @@DrivesOk
mov al, 26
sub al, [es:bx+22]
@@DrivesOk:
mov [Drives], al
; Set fields
mov [BYTE es:bx+13], al ; Number of units
mov [WORD es:bx+3], stSuccess ; Status
mov [WORD es:bx+14], OFFSET EndResCode
mov [es:bx+16], cs
mov [WORD es:bx+18], OFFSET pBPB
mov [es:bx+20], cs
mov [WORD es:bx+23], 1 ; Error message flag
; Print message
mov ah, [es:bx+22] ; Drive number
add [DrvLetter], ah
mov ah, 09h
mov dx, OFFSET InstallMsg
int 21h
mov al, [Drives]
cmp al, 1
je @@Msg1
add al, [es:bx+22]
dec al
add [DrvLetter2], al
mov ah, 09h
mov dx, OFFSET InstMsg2
int 21h
ret
@@Msg1:
mov ah, 09h
mov dx, OFFSET MsgEnd
int 21h
ret
; Bad cmd line syntax - fail init
@@CmdLineError:
mov ah, 09h
mov dx, OFFSET Syntax
int 21h
mov [BYTE es:bx+13], 0
mov [WORD es:bx+14], 0
mov [WORD es:bx+13], stError
ret
ENDP Init
;---------------------------------------------------------------------
; Parse command line.
PROC ParseCmdLine
push ds
push bx cx dx si di
cld
lds si, [es:bx+18]
ASSUME ds:NOTHING
; Scan past the filename to the first space
@@EatFilename:
lodsb
cmp al, 0Dh
je @@NoParams
cmp al, 0Ah
je @@NoParams
cmp al, ' '
jne @@EatFilename
; Eat spaces
@@EatSpaces:
lodsb
cmp al, ' '
je @@EatSpaces
cmp al, 0Ah
je @@NoParams
cmp al, 0Dh
je @@NoParams
xor dx, dx
; Parse one- or two-digit number
cmp al, '0'
jb @@Error
cmp al, '9'
ja @@Error
mov dl, al
sub dl, '0'
lodsb
cmp al, 0Ah
je @@Done
cmp al, 0Dh
je @@Done
cmp al, ' '
je @@EndParams
cmp al, '0'
jb @@Error
cmp al, '9'
ja @@Error
sub al, '0'
mov dh, dl
mov cl, 3
shl dh, cl
shl dl, 1
add dl, dh
add dl, al
; Make sure command line ends here
@@EndParams:
lodsb
cmp al, 0Ah
je @@Done
cmp al, 0Dh
je @@Done
cmp al, ' '
je @@EndParams
@@Error:
stc
jmp @@Exit
@@NoParams:
mov ax, 1
clc
jmp @@Exit
@@Done:
mov al, dl
xor ah, ah
clc
jmp @@Exit
@@Exit:
pop di si dx cx bx
pop ds
ret
ENDP ParseCmdLine
;========================================================= INIT data
HelloMsg DB 10,13,"DumbDrv Version 1.10 96-01-03", 10, 13
DB "Copyright (c) 1994-96, Marcus Better.",10,13,10,13,"$"
InstallMsg DB "DumbDrv installed as "
DrvLetter DB "A:","$"
InstMsg2 DB " - "
DrvLetter2 DB "A:"
MsgEnd DB 10,13,"$"
Syntax DB "Invalid arguments.",10,13,"$"
Drives DB 1 ; Number of drives to support
ENDS DrvSeg
END