forked from witchcraft2001/disktest
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdisktest.asm
636 lines (627 loc) · 20 KB
/
disktest.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
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
DEVICE ZXSPECTRUM128
org 0x80EA
include "dss_equ.asm"
include "spr_equ.asm"
EXEhead: db "EXE"
db 0 ; +3
dw EntryExec-EXEhead
dw 0x0000 ; +4
dw EXEend-EntryExec ; +8
dw 0, 0 ; +10
dw 0 ; +14
dw EntryExec ; +16
dw EntryExec
dw 0x80FF
EntryExec: di
push ix
ld a,(ix-0x03) ; file handle
ld c,Dss.Close ; close file
rst 0x10
ld hl, CopyrightStr
ld c, Dss.PChars ; print text
rst 0x10
ld c, Dss.Version
rst 0x10
LD A, D
OR A
JR NZ, .next1
pop hl
LD HL, IncorDosStr
LD C, Dss.PChars ; print text
RST 0x10
JP Exit
.next1: ld c,Dss.CurDisk
rst 0x10
jp c,DiskError
pop hl
ld (WorkDriveNumber),a
add a,"A"
ld (DiskInfo.letter),a
call ParseArguments
jp c,Exit
ld hl,DiskInfo
ld c,Dss.PChars
rst 0x10
ld a,(WorkDriveNumber)
ld c,Dss.ChDisk
rst 0x10
jp c,DiskError
ld a,"\\"
ld (DiskInfo.letter+2),a
xor a
ld (DiskInfo.letter+3),a
ld hl,DiskInfo.letter
ld c,Dss.ChDir
rst 0x10
jp c,DiskError
ld hl,FileSizeStr
ld c,Dss.PChars
rst 0x10
ld hl,EnterStr
ld c,Dss.PChars
rst 0x10
call DeleteTestFile
call CreateFile
jp c,SomeErrors
ld hl,TestSize512BStr
ld de,0x0200
call TestConsistentRead
jp c,SomeErrors
ld hl,TestSize2KBStr
ld de,0x0800
call TestConsistentRead
jp c,SomeErrors
ld hl,TestSize4KBStr
ld de,0x1000
call TestConsistentRead
jp c,SomeErrors
ld hl,TestSize8KBStr
ld de,0x2000
call TestConsistentRead
jp c,SomeErrors
ld hl,TestSize16KBStr
ld de,0x4000
call TestConsistentRead
jp c,SomeErrors
jp Exit
;[]-------------------------------------------------------------------------[]
TestConsistentRead:
push de
ld de,ConsistentReadStr.size
ld bc,4
ldir
ld hl,ConsistentReadStr
ld c,Dss.PChars
rst 0x10
pop hl
ld (.buferSize),hl
call CMOSWait
; call PrintCurrentTime
call GetCurrentTime
push hl
push bc
ld hl,0
push hl
pop ix
ld bc,Dss.Move_FP
ld a,(FileHandler)
rst 0x10
jr c,.exit
ld hl,Buffer
ld de,0x0800
.buferSize: equ $-2
.loop:
push de
push hl
ld a,(FileHandler)
ld c,Dss.Read
rst 0x10
push de
ex af,af'
ld c,Dss.ScanKey
rst 0x10
pop bc
pop hl
pop de
; pop bc
jr nz,.break
ex af,af'
jr c,.error
ld a,b
or c
jr nz,.loop
.endfile: ld hl,ElapsedTimeStr
ld c,Dss.PChars
rst 0x10
call GetCurrentTime
pop af
pop de
ld c,a
call TimeMinus
push hl
push bc
call PrintTime
pop bc
pop hl
xor a
or h ;Слишком большое время
jr nz,.tobig
ld c,b
ld b,l
push bc
ld hl,(FileBlocks)
ex hl,de
and a
rr d
rr e
ld hl,0
pop bc
call div32 ;в DE - частное - KB/s
push de
pop hl
ld bc,SpeedNumStr
call PRNUM0
ld hl,SpeedStr
ld c,Dss.PChars
rst 0x10
.tobig: ld hl,EnterStr
ld c,Dss.PChars
rst 0x10
and a
ret
.break: xor a
jr .exit
.error: ld a,1
.exit: pop bc
pop hl
scf
ret
;[]-------------------------------------------------------------------------[]
CreateFile: ld hl,Buffer
ld de,Buffer+1
ld bc,0x1000-1
ld (hl),0
ldir
call CMOSWait
; call PrintCurrentTime
call GetCurrentTime
push hl
push bc
ld hl,CreateFileStr
ld c,Dss.PChars
rst 0x10
ld hl,TestFileName
ld c,Dss.Creat_N
xor a
rst 0x10
jr c,.error1
ld (FileHandler),a
ld hl,(FileBlocks)
and a
rr h
rr l
rr h
rr l
rr h
rr l
ld b,h
ld c,l
ld hl,Buffer
ld de,0x1000
.loop: push hl
push bc
push de
ld a,(FileHandler)
ld c,Dss.Write
rst 0x10
jr c,.error
ld c,Dss.ScanKey
rst 0x10
jr nz,.break
pop de
pop bc
pop hl
dec bc
ld a,b
or c
jr nz,.loop
ld hl,ElapsedTimeStr
ld c,Dss.PChars
rst 0x10
call GetCurrentTime
pop af
pop de
ld c,a
call TimeMinus
push hl
push bc
call PrintTime
pop bc
pop hl
xor a
or h ;Слишком большое время
jr nz,.tobig
ld c,b
ld b,l
push bc
ld hl,(FileBlocks)
ex hl,de
and a
rr d
rr e
ld hl,0
pop bc
call div32 ;в DE - частное - Б/С
push de
pop hl
ld bc,SpeedNumStr
call PRNUM0
ld hl,SpeedStr
ld c,Dss.PChars
rst 0x10
.tobig: ld hl,EnterStr
ld c,Dss.PChars
rst 0x10
and a
ret
.break: xor a
jr .exit
.error: ld a,1
.exit: pop de
pop bc
pop hl
.error1: pop bc
pop hl
scf
ret
DeleteTestFile: ld hl,TestFileName ;delete temp file
ld c,Dss.Delete
xor a
rst 0x10
ret
SomeErrors: ld hl,CancelStr
and a
jr z,PrintError
DiskError: LD HL, DiskErrorStr
PrintError: LD C, Dss.PChars ; print text
RST 0x10
Exit: ld a,(FileHandler)
and a
jr z,.next
ld c,Dss.Close
rst 0x10
.next: call DeleteTestFile
LD BC, 0xFF00 + Dss.Exit
RST 0x10 ; exit
GetCurrentTime:
ld c,Dss.SysTime
rst 0x10
ret
;Print current time
PrintCurrentTime:
ld c,Dss.SysTime
rst 0x10
PrintTime: push bc
ld de,CMOSTime
ld a,h
call GetCMOS
inc de
ld a,l
call GetCMOS
INC DE
pop af
call GetCMOS
ld hl,CMOSTime
ld c,Dss.PChars
rst 0x10
ret
GetCMOS:
ex de,hl
ld bc,#2F0A
inc b
sub c
jr nc,$-2
add a,c
ld (hl),b
inc hl
add a,"0"
ld (hl),a
inc hl
ex de,hl
ret
;Time = Time1 - Time2
;HL,B - Time1 (H - hours, L - minutes, B - seconds)
;DE,C - Time2 (D - hours, E - minutes, C - seconds)
;Result: HL,B
TimeMinus: ld a,b
and a
sub c
ld b,a
jr nc,.next
neg
ld b,a
ld a,60
sub b
ld b,a
inc l
dec l
jr z,.zero
dec l
jr .next
.zero: ld l,59
dec h
.next: ld a,l
and a
sub e
ld l,a
jr nc,.next1
neg
ld l,a
ld a,60
sub l
inc h
dec h
jr nz,.nozero
ld h,24
.nozero: dec h
.next1: ld a,h
and a
sub d
ld h,a
ret nc
ld h,23
ret
;Convert Time (hours, minutes, seconds) to seconds
;HL,B - Time1 (H - hours, L - minutes, B - seconds)
;Result - HL,DE 32bit result
TimeInSeconds: push bc
push hl
ld a,h
ld bc,3600
ld hl,0
and a
ld d,a
ld e,a
jr z,.next
.loop: add hl,bc
jr nc,.loop1
inc d
.loop1: dec a
jr nz,.loop
.next: ex (sp),hl
ld a,l
ld l,e
ld h,e
ld bc,60
and a
jr z,.next2
.loop2: add hl,bc
dec a
jr nz,.loop2
.next2: ex hl,de
pop hl
and a
add hl,de
jr nc,.next3
inc b
.next3: ld e,b
ld d,0
pop bc
ld c,b
ld b,d
and a
add hl,bc
jr nc,.next4
inc de
.next4: ex hl,de
ret
;Ожидание до начала секунды
CMOSWait: di
ld bc,CMOS_AWR ;далее не портится
ld a,0
out (c),a
ld a,0FFh
in a,(0xBD)
ld e,a
.loop0: ld bc,CMOS_AWR ;далее не портится
ld a,0
out (c),A
ld a,0xff
in a,(0xBD) ;отфильтруем тик (на тот случай если попали в его конец)
cp e ;
jr z,.loop0 ;
ld e,a ;4, а вот от сюда и начинается отсчёт тактов
ret
;Parse Arguments in Command line
ParseArguments:
ld a,(hl)
or a
ret z
inc hl
inc hl
ld bc,0x2f20
ld e,"-"
.loop: ld a,(hl)
inc hl
and a
ret z
cp c
jr z,.loop
cp b
jr z,.argument
cp e
jr z,.argument
res 5,a
cp "A"
jr c,.skip
cp "Z" + 1
jr nc,.skip
ld d,a
ld a,(hl)
inc hl
cp ":"
jr nz,.skip
ld a,d
ld (DiskInfo.letter),a
sub "A"
ld (WorkDriveNumber),a
jr .loop
.argument: ld a,(hl)
inc hl
cp "?"
jr z,.help
res 5,a
cp "H"
jr z,.help
cp "S"
jr z,.size
.skip: ld a,(hl)
cp c
jr z,.loop
and a
ret z
inc hl
jr .skip
.help: ld hl,HelpStr
ld c,Dss.PChars
rst 0x10
scf
ret
.size: inc hl
push de
push bc
ex hl,de
push de
ld hl,S512KStr
push hl
call CheckParam
ld hl,0x0400
jr nc,.found
pop de
pop de
push de
ld hl,S1MStr
push hl
call CheckParam
ld hl,0x0800
jr nc,.found
pop de
pop de
push de
ld hl,S2MStr
push hl
call CheckParam
ld hl,0x1000
jr nc,.found
pop de
pop de
push de
ld hl,S4MStr
push hl
call CheckParam
ld hl,0x2000
jr nc,.found
pop de
pop de
push de
ld hl,S8MStr
push hl
call CheckParam
ld hl,0x4000
jr c,.notfound
.found: ld (FileBlocks),hl
pop hl
ld de,FileSizeStr.size
ld bc,4
ldir
pop hl
pop bc
pop de
jp .skip
.notfound pop hl
push de
ld hl,UnknownSizeStr
ld c,Dss.PChars
rst 0x10
pop hl
pop de
pop bc
pop de
jp .skip
CheckParam: ld b,0x20
.loop: ld a,(hl)
or a
ret z
ld a,(de)
cp b
jr z,.end
and a
jr z,.end
cp (hl)
jr z,.next
cp "A"
jr c,.end
res 5,a
cp (hl)
jr nz,.end
.next: inc hl
inc de
jr .loop
.end: scf
ret
HelpStr: db "Disk perfomance testing utility.", 0x0D, 0x0A
db "With no command line parameters, the utility will perform a file-system based", 0x0D, 0x0A
db "performance test with a test file size of 2MB on disk from which utility was", 0x0D, 0x0A
db "started.", 0x0D, 0x0A, 0x0D, 0x0A
db "Usage: X: specify test disk letter", 0x0D, 0x0A
db " /H, /? help page", 0x0D, 0x0A
db " /S specify the test file size (512K, 1M, 2M, 4M, 8M).", 0x0D, 0x0A
db " Default test file size is 2M", 0x0D, 0x0A, 0x0D, 0x0A
db "Example: DISKTEST.EXE C: /S 4M", 0x0D, 0x0A, 0x0D, 0x0A, 0x00
FileSizeStr: db "Test file size: "
.size: db "2M ", 0x00
S512KStr: db "512K", 0x00
S1MStr: db "1M", 0x00,0x00
S2MStr: db "2M", 0x00,0x00
S4MStr: db "4M", 0x00,0x00
S8MStr: db "8M", 0x00,0x00
UnknownSizeStr: db "The value of the size parameter is not correct, please read the help (start app", 0x0D, 0x0A
db "with /? argument).", 0x0D, 0x0A, 0x00
CopyrightStr: db 0x0D, 0x0A
db "DiskTest, ver 0.6 (Alpha)", 0x0D, 0x0A
db "(C) 2021, Mikhaltchenkov Dmitry aka Hard/WCG, Rostov-on-Don.", 0x0D, 0x0A, 0x0D, 0x0A, 0x00
IncorDosStr: db "Incorrect DOS version, need DOS 1.00 or high.", 0x0D, 0x0A, 0x00
CreateFileStr: db "Creating test file ... ", 0x00
DiskInfo: db "Testing disk: "
.letter: db "A:", 0x0D, 0x0A, 0x00
EnterStr: db 0x0D, 0x0A, 0x00
ElapsedTimeStr: db "Elapsed: ", 0x00
CancelStr: db "Canceled", 0x0D, 0x0A, 0x00
SpeedStr: db "Speed: "
SpeedNumStr: db "00000 KiB/s", 0x00
CMOSTime: db "00:00:00 ", 0x00
TestSize512BStr:
db "512B"
TestSize2KBStr:
db " 2KB"
TestSize4KBStr:
db " 4KB"
TestSize8KBStr:
db " 8KB"
TestSize16KBStr:
db "16KB"
ConsistentReadStr:
db "Test: Consistent reading "
.size: db "512B ... ", 0x00
DiskErrorStr: db "PANIC: Disk error!", 0x0D, 0x0A, 0x00
TestFileName: db "DISKTEST.$$$",0
FileBlocks: dw 0x1000 ;file lenght in 512 bytes blocks
FileHandler: db 0 ;file handler
WorkDriveNumber:
db 0xFF
;Division routines
include "muldiv.asm"
include "prnum.asm"
Buffer: equ $
EXEend:
savebin "DISKTEST.EXE",EXEhead,EXEend-EXEhead