Вот есть код, кто-нибудь может сказать его есть смылл доделывать или он ни имеет признаков жизни) ?
Assembler | 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
| IDEAL
P386
MODEL FLAT ,PASCAL
SMART
LOCALS
NOJUMPS
MAX_HDD_WAIT_TIME equ 18*2 ; 10 seconds
ENUM DEVICETYPE ATATYPE,ATAPITYPE
DATASEG
IdentyfyCommand dd 0ECh,0A1h
HDDAllBasePorts dw 1F0h,170h,1E8h,168h
HDDWindowText db '[1] Channel: 0 / Device: 0 ',0
DriveTypeATA db 'ATA',0
DriveTypeATAPI db 'ATAPI',0
AddressTypeLBA db 'LBA support. Size: %uMb/n',0
AddressTypeCHS db 'CHS only. Size: %uMb/n',0
UDATASEG
HDDBasePort dd ?
HDDChannel db ?
HDDDrive db ?
HDDError db ?
ATAFeatures db ?
ATASectorCount db ?
ATASectorNumber db ?
ATACylinder dw ? *
ATAHead db ?
ATAAddressMode db ?
HDDTime dd ?
; Ё¬п Ё ен*¤« д*©«*
FileName db 20 dup(?)
Handle dd ?
DevicesID dd 4 dup(?)
STACK 10000h
;±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±
; CODE
;±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±
CODESEG
ALIGN 4
include "debug.inc"
ALIGN 4
pushad
xor ecx,ecx
mov eax,[large 046Ch]
add eax,MAX_HDD_WAIT_TIME
mov [HDDTime],eax
movzx ebx,[__channel]
dec ebx
cmp ebx, 3
ja __errchan
movzx edx,[word ebx*2+HDDAllBasePorts]
mov [HDDBasePort],edx
add edx,206h
mov al,1010b
out dx,al
sub edx,206h-7
__wait_not_bsy:
mov eax,[large 046Ch]
cmp eax,[HDDTime]
ja __timeout
in al,dx
test al,80h
jnz __wait_not_bsy
dec edx
mov al,[__hddnumber]
cmp al,1
ja __numerr
shl al,4
or al,10100000b
mov ah, [ATAAddressMode]
shl ah,6
or al,ah
out dx,al
inc edx
__wait_ready:
mov eax,[large 046Ch]
cmp eax,[HDDTime]
ja __timeout
in al,dx
test al,80h
jnz __wait_ready
test al,40h
jz __wait_ready
sub edx,6
mov al,[ATAFeatures]
out dx,al
inc edx
mov al,[ATASectorCount]
out dx,al
inc edx
mov al,[ATASectorNumber]
out dx,al
inc edx
mov ax,[ATACylinder]
out dx,al
inc edx
mov al,ah
out dx,al
inc edx
mov al,[__hddnumber]
shl al,4
cmp [ATAHead],0fh
ja __errhead
or al,[ATAHead]
or al,10100000b
mov ah,[ATAAddressMode]
shl ah,6
or al,ah
out dx,al
inc edx
mov al,[__command]
out dx,al
__end:
mov [HDDError],cl
popad
ret
__errhead:
inc ecx ; 5
__numerr:
inc ecx ; 4
__errchan:
inc ecx ; 3
__addrmode:
inc ecx ; 2
__timeout:
inc ecx ; 1
jmp __end
endp send_command_to_hdd
align 4
proc get_identify_device near __type, __channel: BYTE, __hddnumber: BYTE, __buffer
pushad
xor eax,eax
mov [ATAAddressMode],al
mov [ATAFeatures],al
mov [ATAHead],al
mov eax,[__type]
and eax,1
mov eax,[IdentyfyCommand+eax*4]
call send_command_to_hdd, eax, [dword __channel],[dword __hddnumber]
xor ebx,ebx
cmp [HDDError],0
jne __end
mov edx,[HDDBasePort]
add edx,7
__wait:
mov eax,[large 046Ch]
cmp eax,[HDDTime]
ja __timeout
in al,dx
test al,80h
jnz __wait
test al,01h
jnz __error
test al,08h
jz __wait
mov edi,[__buffer]
sub edx,7
mov ecx,256
rep insw
__end:
popad
ret
__error:
add ebx,5
__timeout:
inc ebx
mov [HDDError],bl
jmp __end
endp get_identify_device
align 4
proc read_sectors near __sector_address, __numsectors: byte, __buffer
pushad
xor eax,eax
mov [ATAFeatures],al
inc al
mov [ATAAddressMode],al ; ०Ё¬ LBA
mov al,[__numsectors]
mov [ATASectorCount],al
mov eax,[__sector_address]
mov [dword ATASectorNumber],eax
mov al,[HDDDrive]
mov dl,[HDDChannel]
call send_command_to_hdd, 20h, edx, eax
cmp [HDDError],0
jne __end
; ®¦Ё¤*Ґ¬ Ј®в®ў*®бвЁ ¤***ле
mov edx,[HDDBasePort]
add edx,7
__wait:
mov eax,[large 046Ch]
cmp eax,[HDDTime]
ja __timeout
in al,dx
test al,80h
jnz __wait
test al,08h
jz __wait
; ЇаЁ*Ё¬*Ґ¬ ¤***лҐ
mov edi,[__buffer]
sub edx,7
__read:
mov ecx,256
rep insw
dec [__numsectors]
jnz __read
__end:
popad
ret
__timeout:
mov [HDDError],1
jmp __end
endp read_sectors
align 4
proc write_sectors near __sector_address, __numsectors: byte, __buffer
pushad
xor eax,eax
mov [ATAFeatures],al
inc al
mov [ATAAddressMode],al ; ०Ё¬ LBA
mov al,[__numsectors]
mov [ATASectorCount],al
mov eax,[__sector_address]
mov [dword ATASectorNumber],eax
mov al,[HDDDrive]
mov dl,[HDDChannel]
call send_command_to_hdd, 30h, edx, eax
cmp [HDDError],0
jne __end
mov edx,[HDDBasePort]
add edx,7
__wait:
mov eax,[large 046Ch]
cmp eax,[HDDTime]
ja __timeout
in al,dx
test al,80h
jnz __wait
test al,08h
jz __wait
mov esi,[__buffer]
sub edx,7
__read:
mov ecx,256
rep outsw
dec [__numsectors]
jnz __read
__end:
popad
ret
__timeout:
mov [HDDError],1
jmp __end
endp write_sectors
proc _get_mem near __size
push ebx ecx edx esi edi
mov eax,501h
mov ecx,[__size]
add ecx,4+15
and ecx,0FFFFFFFCh
shld ebx,ecx,16
int 31h
jc __get_dos_mem
shl ecx,16
shld ebx,ecx,16
shl edi,16
mov eax,ebx
shld esi,edi,16
mov [ebx],esi
add eax,4
pop edi esi edx ecx ebx
ret
__get_dos_mem:
mov ebx,[__size]
add ebx,4+4+15
shr ebx,4
mov eax,100h
int 31h
jc __error
movzx eax,ax
shl eax,4
or ebx,-1
mov [eax],edx
mov [eax+4],ebx
add eax,8
pop edi esi edx ecx ebx
ret
__error:
xor eax,eax
pop edi esi edx ecx ebx
ret
endp _get_mem
proc _free_mem near __linaddr
mov eax,[__linaddr]
sub eax,4
mov edi,[eax]
mov esi,edi
sub esi,-1
jz __dos
shld esi,edi,16
mov eax,502h
int 31h
ret
__dos:
sub eax,4
mov edx,[eax]
mov eax,101h
int 31h
ret
endp _free_mem
proc fcreate near __filename
push ecx edx
mov eax,3C02h
xor ecx,ecx
mov edx,[__filename]
int 21h
pop edx
pop ecx
ret
endp
proc fclose near __handle
push ebx
mov ah,3Eh
mov ebx,[__handle]
int 21h
pop ebx
ret
endp
proc fwrite near __handle,__buffer,__size
pusha
mov ah,40h
mov ecx,[__size]
mov ebx,[__handle]
mov edx,[__buffer]
int 21h
popa
ret
endp
proc GetStatusID near __x,__y,__num
mov edx,[__num]
mov ecx,edx
mov eax,edx
add eax,'0'
mov [byte HDDWindowText+1],al
and edx,1
add ecx,edx
xor edx,1 ; edx - device
shr ecx,1 ; ecx - channel
mov eax,ecx
add eax,'0'
mov [byte HDDWindowText+9+4],al
mov eax,edx
add eax,'0'
mov [byte HDDWindowText+21+4],al
WINDOW HDDWindowText,[__x],[__y],38,9,<DARKGREY or (WHITE shl 4)>,WHITE,1Fh
call _get_mem, 512
jz __error_mem
xchg esi,eax ; esi - buffer
lea ebx,[HDDError]
call get_identify_device, ATATYPE,ecx,edx,esi
cmp [byte ebx],6
jne __ata
__atapi:
call get_identify_device, ATAPITYPE,ecx,edx,esi
cmp [byte ebx],0
jne __error
jmp __foundatapi
__ata:
cmp [byte ebx],0
jne __error
mov eax,offset DriveTypeATA
test [byte esi+1],80h
jz __found
__foundatapi:
mov eax,offset DriveTypeATAPI
__found:
CPrintf "Found: %s/n",1Bh,eax
test [byte esi+1],80h
jnz __retatapi
lea eax,[esi+27*2]
mov [byte eax+38],0
Printf "Model: %s/n",eax
mov edi,[dword esi+60*2]
movzx eax,[word esi+1*2]
movzx ebx,[word esi+3*2]
movzx ecx,[word esi+6*2]
push eax
or edi,edi
jnz __lba
mul ebx
mul ecx
mov edi,offset AddressTypeCHS
Printf edi,eax
jmp __size
__lba:
mov eax,edi
mov edi,offset AddressTypeLBA
__size:
shr eax,11 ; Mb = /512
Printf edi,eax
pop eax
Printf "Cyl: %u, Head: %u, Sec: %u/n",eax,ebx,ecx
CPrintf "Current:/n",1Bh
mov edi,[dword esi+57*2]
mov eax,edi
shr eax,11
Printf "Sectors: %u. Size: %uMb/n",edi,eax
movzx eax,[word esi+54*2]
movzx ebx,[word esi+55*2]
movzx ecx,[word esi+56*2]
Printf "Cyl: %u, Head: %u, Sec: %u/n",eax,ebx,ecx
__done:
ret
__error:
CPrintf "Device not found./n",1Bh
__retatapi:
xor esi,esi
ret
__error_mem:
CPrintf "ERROR: not enought memory!/n",1Ch
xor esi,esi
ret
endp
ALIGN 4
start:
jmp short _main
db 'WATCOM... What me worry?'
;°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°
; CS - Code Selector Base: 00000000h - Limit: 4G
; DS - Data Selector Base: 00000000h - Limit: 4G
; ES - PSP Selector Base: PSP Seg - Limit: 100h
; FS - ?
; GS - ?
; SS - Data Selector Base: 00000000h - Limit: 4G
; ESP -> STACK segment
; Direction Flag - ?
; Interrupt Flag - ?
;°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°
_main:
; Startup code
sti
cld
push ds
pop es
call GetStatusID, 1, 1, 1
mov [DevicesID+00],esi
call GetStatusID, 40,1, 2
mov [DevicesID+04],esi
call GetStatusID, 1, 11,3
mov [DevicesID+08],esi
call GetStatusID, 40,11,4
mov [DevicesID+12],esi
input:
movzx edx,[large byte 484h]
sub edx,3
WINDOW "Enter number device (1..4) for save MBR. 'Esc' - Exit",10,edx,58,3,<DARKGREY or (WHITE shl 4)>,WHITE,1Fh
inputloop:
readkey
cmp al,27
je Quit
sub al,'1'
js errorinput
cmp al,3
jbe inputname
errorinput:
Printf "enter only number in range 1..4 or 'ESC' for exit"
errorkey:
ReadKey
cmp al,27
je Quit
jmp input
; ўў®¤ Ё¬Ґ*Ё д*©«*
inputname:
xor ebx,ebx
mov bl,al ; save num device
mov ecx,[DevicesID+ebx*4]
or ecx,ecx
jz inputloop
xor ecx,ecx
Printf "file name: "
call GetCursor ; dx - cursor
call GetAddr ; edi - vid mem
mov esi,offset FileName
__readfilename:
readkey
or al,al
jz __readfilename
cmp al,27 ; esc
je input
cmp al,13 ; enter
je __doneread
cmp al,8 ; backspace
jne __symbol
; back space
or ecx,ecx
jz __readfilename
sub edi,2
dec ecx
mov [byte edi],' '
dec dl
call SetCursor
jmp __readfilename
__symbol:
cmp ecx,12
jae __readfilename
cmp al,20h
jbe __readfilename
cmp al,'z'
ja __readfilename
stosb
inc edi
mov [esi+ecx],al
inc ecx
inc dl
call SetCursor
jmp __readfilename
__doneread:
or ecx,ecx
jz input
xor al,al
mov [esi+ecx],al
GotoXY 0,0
call fcreate, esi
xchg edi,eax
jnc getbuffer
Printf "Can't create file: %s",esi
jmp errorkey
getbuffer:
; ўл¤Ґ«пҐ¬ Ї*¬пвм
call _get_mem,2048
jnz saveinfo
Printf "Not enought memory!"
call fclose, edi
jmp errorkey
saveinfo: ; б®еа**塞 MBR
xchg esi,eax ; esi - mem
mov edx,ebx ; ebx - number device
inc edx
mov ecx,edx
and edx,1
add ecx,edx
xor edx,1 ; edx - device
shr ecx,1 ; ecx - channel
mov [HDDChannel],cl
mov [HDDDrive],dl
mov edx,esi
add edx,1024 ; edx - mem
xor eax,eax
call readsector
call blockwrite
jmp Quit
blockwrite:
call fwrite, edi,esi,512
jc __error
ret
__error:
call fclose, edi
Printf "ERROR: write to file!"
pop eax
jmp errorkey
readsector:
call read_sectors, eax,1,esi
cmp [HDDError],0
jne __error
ret
__error:
Printf "ERROR: read sector!"
call fclose, edi
pop eax
jmp errorkey
Quit:
mov ax,4c00h ; AH=4Ch - Exit To DOS
int 21h ; DOS INT 21h
ENDS
END Start |
|
Содержимое файла Debug.inc (в нем функции вывода символов из строки, позиционирование, смена цвета, переводы из числа в строку в т. ч. и для вещественных и еще некоторые процедуры и ф-и)
Assembler | 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
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
| BLACK equ 0
BLUE equ 1
GREEN equ 2
CYAN equ 3
RED equ 4
MAGENTA equ 5
BROWN equ 6
LIGHTGREY equ 7
DARKGREY equ 8
LIGHTBLUE equ 9
LIGHTGREEN equ 10
LIGHTCYAN equ 11
LIGHTRED equ 12
LIGHTMAGENTA equ 13
YELLOW equ 14
WHITE equ 15
; add-in ¤«п ¬Ґpж**Ёп
BLINK EQU 128
macro pushcpp a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z
local cf
ifnb <b>
pushcpp <b>,<c>,<d>,<e>,<f>,<g>,<h>,<i>,<j>,<k>,<l>,<m>,<n>,<o>,<p>,<q>,<r>,<s>,<t>,<u>,<v>,<w>,<x>,<y>,<z>
NUMPARAM = NUMPARAM+4
endif
ID INSTR <a>,<">
IF ID EQ 1
dataseg
cf db a,0
ends
codeseg
push offset cf
ELSE
IF (SYMTYPE(a)) EQ 2Ah
push offset a
ELSE
push a
ENDIF
ENDIF
endm
MACRO Attrib reg, background, symbol
mov reg,(background shl 4) or symbol
ENDM
MACRO ReadKey
xor eax,eax
int 16h
ENDM
MACRO FlushKeyboadr
local x,y
x:
mov ah,1
int 16h
jz y
xor eax,eax
int 16h
jmp x
y:
ENDM
MACRO GotoXY x,y
call _gotoxy, x,y
ENDM
MACRO SetClip x1,y1,x2,y2
mov [WindMinX],x1
mov [WindMaxX],x2
mov [WindMinY],y1
mov [WindMaxY],y2
ENDM
MACRO Window text,left,top,lenX,lenY,CaptAttr,BordCol,TextAttr
local cf
ID INSTR <text>,<">
IF ID EQ 1
dataseg
cf db text,0
ends
codeseg
push offset cf
ELSE
IF (SYMTYPE(text)) EQ 2Ah
push offset text
ELSE
push text
ENDIF
ENDIF
call _window,left,top,lenX,lenY,CaptAttr,BordCol,TextAttr
ENDM
macro printf string:req,a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z
local id
pusha
sub esp,256
mov edx,esp
NUMPARAM = 0
IsString INSTR <string>,<">
IF (IsString) EQ 1
dataseg
id db string,0
ends
codeseg
pushcpp edx,<offset id>,<a>,<b>,<c>,<d>,<e>,<f>,<g>,<h>,<i>,<j>,<k>,<l>,<m>,<n>,<o>,<p>,<q>,<r>,<s>,<t>,<u>,<v>,<w>,<x>,<y>,<z>
ELSE
pushcpp edx,<string>,<a>,<b>,<c>,<d>,<e>,<f>,<g>,<h>,<i>,<j>,<k>,<l>,<m>,<n>,<o>,<p>,<q>,<r>,<s>,<t>,<u>,<v>,<w>,<x>,<y>,<z>
ENDIF
NUMPARAM = NUMPARAM+4
call _scanf
add esp,NUMPARAM
mov edx,esp
call _putstring, edx
add esp,256
popa
endm
macro cprintf string:req,color:req,a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z
local id
pusha
sub esp,256
mov edx,esp
NUMPARAM = 0
IsString INSTR <string>,<">
IF (IsString) EQ 1
dataseg
id db string,0
ends
codeseg
pushcpp edx,<offset id>,<a>,<b>,<c>,<d>,<e>,<f>,<g>,<h>,<i>,<j>,<k>,<l>,<m>,<n>,<o>,<p>,<q>,<r>,<s>,<t>,<u>,<v>,<w>,<x>,<y>,<z>
ELSE
pushcpp edx,<string>,<a>,<b>,<c>,<d>,<e>,<f>,<g>,<h>,<i>,<j>,<k>,<l>,<m>,<n>,<o>,<p>,<q>,<r>,<s>,<t>,<u>,<v>,<w>,<x>,<y>,<z>
ENDIF
NUMPARAM = NUMPARAM+4
call _scanf
add esp,NUMPARAM
mov edx,esp
call _putcstring, edx,color
add esp,256
popa
endm
;±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±
WindMinX db 0
WindMinY db 0
WindMaxX db 79
WindMaxY db 24
PROC GetAddr NEAR
push eax ebx edx
and edx,0ffffh
movzx ebx,dl ; ebx - x
movzx eax,[large word 44Ah]
shr edx,8 ; edx - y
mov edi,0B8000h
mul edx
add eax,ebx
shl eax,1
add edi,eax
movzx ebx,[large word 44Eh]
add edi,ebx
pop edx ebx eax
ret
ENDP
; out: dl - x
; dh - y
PROC GetCursor NEAR
movzx edx,[large byte 462h]
movzx edx,[large word edx*2+450h]
ret
ENDP
; in: dl - x
; dh - y
PROC SetCursor NEAR
pusha
movzx ebx,[large byte 462h]
mov [ebx*2+450h],dx *
call GetAddr
sub edi,0B8000h
mov ebx,edi
shr ebx,1
mov ah,bh
movzx edx,[large word 463h]
mov al,0Eh
out dx,ax
mov ah,bl
inc al
out dx,ax
popa
ret
ENDP
proc _gotoxy near __x,__y
pushad
mov eax,[__x]
mov edx,[__y]
xor ebx,ebx
mov bl,[WindMinX]
xor ecx,ecx
mov cl,[WindMinY]
add eax,ebx
add edx,ecx
cmp eax,ebx
jge __n1
mov eax,ebx
__n1:
cmp edx,ecx
jge __n2
mov edx,ecx
__n2:
xor ebx,ebx
mov bl,[WindMaxX]
xor ecx,ecx
mov cl,[WindMaxY]
cmp eax,ebx
jbe __n3
mov eax,ebx
__n3:
cmp edx,ecx
jbe __n4
mov edx,ecx
__n4:
shl edx,8
or edx,eax
call SetCursor
popad
ret
endp
proc StrLen near ; __lpszStr: dword
push ebx edx ecx
mov eax,[esp+4*4] ; eax = __lpszStr
lea edx,[eax+3]
__loop:
mov ebx,[eax]
add eax,4
lea ecx,[ebx-01010101h]
not ebx
and ecx,ebx ; and these two
and ecx,80808080h
jz __loop
test ecx,00008080h
jnz __done
shr ecx,16
add eax,2
__done:
shl cl,1
sbb eax,edx
pop ecx edx ebx
ret 4
endp StrLen
;Используем /t /r /l /n /b /f
; "%" ["0"] ["-"] [width] ["." prec] type
MAXDIGS EQU 256
ALIGN 4
proc _scanf C
push ebp
mov edi,[esp+8]
mov esi,[esp+12]
lea ebp,[esp+16]
sub esp,MAXDIGS
cld
__next_char:
lodsb
cmp al,'%'
je __format
cmp al,'/'
je __frmstr
__store_char:
stosb
or al,al
jnz __next_char
__done:
add esp,MAXDIGS
pop ebp
ret
__frmstr:
lodsb
or al,al
je __store_char
cmp al,'/'
je __store_char
cmp al,'b'
jne __tab
__backspace:
mov al,08h
jmp __store_char
__tab:
cmp al,'t'
jne __formfeed
mov al,09h
jmp __store_char
__formfeed:
cmp al,'f'
jne __linefeed
mov al,0Ch
jmp __store_char
__linefeed:
cmp al,'l'
je __lf
__return:
cmp al,'r'
jne __newline
mov al,0Dh
jmp __store_char
__newline:
cmp al,'n'
jne __next_char
mov al,0Dh
stosb
__lf:
mov al,0Ah
jmp __store_char
__format:
xor eax,eax
lodsb
cmp al,'%'
jbe __store_char
xor ebx,ebx
mov ecx,' '
cmp al,'0'
jne __leftadj
mov cl,al
lodsb
__leftadj:
xor edx,edx
cmp al,'-'
jne __width
inc ch
mov cl,' '
lodsb
__width:
cmp al,'0'
jb __prec
cmp al,'9'
ja __prec
sub al,'0'
imul ebx,10
add ebx,eax
lodsb
jmp __width
__prec:
cmp al,'.'
jne __conversion
lodsb
__prec_width:
cmp al,'0'
jb __conversion
cmp al,'9'
ja __conversion
sub al,'0'
imul edx,10
add edx,eax
lodsb
jmp __prec_width
__conversion:
; edi - result string
; esi - format string
cmp al,'b'
je __conv_bin
cmp al,'o'
je __conv_oct
cmp al,'h'
je __conv_hex
cmp al,'x'
je __conv_hex
cmp al,'u'
je __conv_dec
cmp al,'i'
je __conv_int
cmp al,'d'
je __conv_int
cmp al,'f'
je __conv_flt
cmp al,'g'
je __conv_dbl
cmp al,'e'
je __conv_exp
__conv_chr:
cmp al,'c'
jne __conv_str
movzx eax,[byte ebp]
add ebp,4
stosb
jmp __next_char
__conv_str:
cmp al,'s'
jne __store_char
push esi
mov esi,[ebp]
add ebp,4
__strloop:
lodsb
or al,al
jz __strdone
stosb
jmp __strloop
__strdone:
pop esi
jmp __next_char
__conv_dec:
mov al,10
jmp __conv_num
__conv_int:
cmp [dword ebp],0
jns short __int_done
or ecx,8000h
neg [dword ebp]
dec ebx
__int_done:
mov al,10
jmp __conv_num
__conv_hex:
mov al,16
jmp __conv_num
__conv_oct:
mov al,8
jmp __conv_num
__conv_bin:
mov al,2
jmp __conv_num
__conv_flt:
fld [dword ebp]
add ebp,4
jmp __conv_ext
__conv_dbl:
fld [qword ebp]
add ebp,8
__conv_ext:
or edx,edx
jnz __conv_float
mov edx,4
jmp __conv_float
__conv_exp:
or ebx,ebx
jnz __exp1
mov ebx,23
__exp1:
fld [dword ebp]
add ebp,4
or edx,-1
jmp __conv_float
__conv_num:
push esi ecx
movzx ecx,al
mov eax,[ebp]
add ebp,4
lea esi,[esp+MAXDIGS+8]
__intloop:
xor edx,edx
div ecx
add dl,'0'
cmp dl,'0'+10
jb __int1
add dl,'A'-'0'-10
__int1:
dec esi
mov [esi],dl
or eax,eax
jnz __intloop
xor edx,edx
lea ecx,[esp+MAXDIGS+8]
sub ecx,esi
pop eax
sub ebx,ecx
jns __n1
xor ebx,ebx
__n1:
__format_num:
test eax,100h
jnz __put_sign
cmp al,' '
jne __put_sign
__put_filled1:
xchg ecx,ebx
rep stosb
xchg ecx,ebx
__put_sign:
test eax,8000h
jz __test_filled2
mov [byte edi],'-'
inc edi
__test_filled2:
test eax,100h
jnz __put_int
xchg ecx,ebx
rep stosb
xchg ecx,ebx
__put_int:
rep movsb
xchg ecx,edx
jecxz __done_frm
mov [byte edi],'.'
inc edi
rep movsb
__done_frm:
xchg ecx,ebx
rep stosb
__done_format:
pop esi
jmp __next_char
__conv_float:
push esi
push edi
mov esi,edx
cmp ebx,MAXDIGS
jbe __next
mov ebx,MAXDIGS
__next:
fld st(0)
fstp [tbyte esp +8]
mov eax,[dword esp+8 +8]
mov edi,eax
and edi,8000h
and eax,7fffh
or ecx,edi
cmp eax,7fffh
je __naninf
fabs
;test esi,esi
or edx,edx
jge __fixed
call _scaleext ; val ** st(0), exp ў eax
__scientific:
push ecx
mov esi,ebx
sub esi,8 ; digcnt = width - 8;
cmp esi,2 ; if digcnt < 2 then digcnt = 2
jge __s1
mov esi,2
jmp __s2
__s1:
cmp esi,18
jle __s2
mov esi,18
__s2:
push eax
lea edx,[esp+16]
mov eax,esi
call _emitdigits
pop ecx
pop edx
mov eax,' '
xchg ecx,ebx
sub ecx,esi
pop edi
sub ecx,8
js __s3
rep stosb
__s3:
test edx,8000h
jz __s4
mov eax,'-'
__s4:
stosb
mov ecx,esi
lea esi,[esp+4]
cmp [byte esi],'0'
je __s5
inc ebx
dec esi
__s5:
inc esi
movsb
mov [byte edi],'.'
inc edi
dec ecx
rep movsb
mov [byte edi],'E'
mov ecx,'+'
test ebx,ebx
jge __s6
mov ecx,'-'
neg ebx
__s6:
mov [edi+1],cl
xchg eax,ebx
; ўлў®¤Ё¬ нЄбЇ®*Ґ*вг
xor edx,edx
mov cx,10
div cx
add dl,'0'
mov [edi+5],dl
xor edx,edx
div cx
add dl,'0'
mov [edi+4],dl
xor edx,edx
div cx
add dl,'0'
mov [edi+3],dl
add al,'0'
mov [edi+2],al
add edi,6
jmp __done_format
; ўлў®¤ ў д®а¬*⥠int.precision
__fixed:
push ecx
cmp esi,MAXDIGS-40 ; if precision > maxdigs-40 then precision := maxdigs-40;
jle __f1
mov esi,MAXDIGS-40
__f1:
fcom [ten] ; digs > 10.0 ?
fstsw ax
sahf
mov eax,0
jb __f2 ; -> ¤*
; val = mant * 10**exp
call _scaleext ; val ** st(0), exp ў eax
cmp eax,35
jg __scientific
__f2:
;st(0) [0.0 <= val < 10.0]
inc eax
lea edx,[esp +12] ; edx - digbuf
push eax
add eax,esi ; eax - digcnt
call _emitdigits ; uses eax ecx edx edi
pop eax
mov edx,esi
lea esi,[esp +12] ; esi ** digbuf
cmp [byte esi],'0'
je __f3
inc eax
dec esi
__f3:
shr edi,15
inc esi
mov ecx,eax
add eax,edi
test edx,edx ; if precision > 0 then
je __f4
inc eax
add eax,edx
sub ebx,eax
jns __f4
xor ebx,ebx
__f4:
pop eax
pop edi
jmp __format_num
__naninf:
; ebx - ¤«Ё**
; edi - §**Є зЁб«*
; [esp+4+8] - value
; [esp] - out buffer
fstp st(0)
cmp [dword esp+4 +8],80000000h
mov esi,offset nanstr
jne __fillblank
dec edi
mov esi,offset plusinfstr
jnz __fillblank
mov esi,offset mininfstr
__fillblank:
pop edi
mov ecx,ebx
sub cl,[esi]
jbe __savenan
mov eax,' '
rep stosb
__savenan:
movzx ecx,[byte esi]
inc esi
rep movsb
jmp __done_format
nanstr db 3,'nan'
plusinfstr db 4,'+inf'
mininfstr db 4,'-inf'
endp
ALIGN 4
ten dq 10.0
tenE17 dq 1.E17
tenE18 dq 1.E18
ALIGN 4
proc _pow10calck
push eax
; ln()
fldln2
fld [ten]
fyl2x
fimul [dword esp]
; exp ()
fldl2e
fmulp st(1), st
fld st(0)
frndint
fxch
fsub st, st(1)
f2xm1
fld1
faddp st(1), st
fscale
fstp st(1)
pop eax
ret
endp
ALIGN 4
proc _emitdigits
push edi
mov edi,edx
mov ecx,eax
sub esp,12
mov [byte edi],'0' ; digbuf[0] := '0';
fmul [tene17]
frndint ; val := round(val*1e17);
fcom [tene18] ; if val >= 1e18 then
fstsw ax
sahf
jb __savebcd
fsub [tene18] ; val := val - 1e18;
mov [byte edi],'1' ; digbuf[0] := '1';
__savebcd:
fbstp [esp]
mov edx,8
inc edi
__unpack:
wait
mov al,[esp+edx]
mov ah,al
shr al,4
and ah,0fh
add ax,'00'
stosw
dec edx
jns __unpack
sub ecx,18
jl __round
mov al,'0'
rep stosb
jmp __done
__round:
; ®Єа㣫塞
add edi,ecx
cmp [byte edi],'5'
jl __done
__rloop:
dec edi
inc [byte edi]
cmp [byte edi],'9'
jle __done
mov [byte edi],'0'
jmp __rloop
__done:
add esp,12
pop edi
ret
endp _emitdigits
ALIGN 4
proc _scaleext
push ebx
sub esp,12
xor ebx,ebx
__normloop:
fld st(0)
fstp [tbyte esp]
xor eax,eax
mov ax,[esp+8]
test ax,ax
je __testzero
__cont:
sub ax,3fffh
mov dx,4d10h ; log10(2) * 2**16
imul dx
movsx eax,dx ; exp10 = exp2 * log10(2)
neg eax
jz __exit
sub ebx,eax
call _pow10calck
jmp __normloop
__exit:
add esp,12
mov eax,ebx
pop ebx
ret
__testzero:
cmp [dword esp+4],0
jne __cont
cmp [dword esp+0],0
jne __cont
jmp __exit
endp _scaleext
proc _window near __Name,__x,__y,__lenX,__lenY,__CaptAttr,__BordCol,__TextAttr
pushad
mov esi,[__Name]
call StrLen,esi
mov ebx,[__lenX]
sub ebx,2
cmp eax,ebx
jb __n1
mov eax,ebx
__n1:
mov ecx,eax ; ecx - len name
; а*бзЁвлў*Ґ¬ Є®®а¤Ё**вл
mov dl,[byte __x]
mov dh,[byte __y]
mov eax,edx
inc al
mov [WindMinX],al
inc ah
mov [WindMinY],ah
call GetAddr ; edi - screen addr
mov edx,eax
call SetCursor
; ўлў®¤Ё¬ §*Ј®«®ў®Є
sub ebx,ecx
mov ah,[byte __CaptAttr]
mov al,' '
stosw
__capt:
lodsb
stosw
loop __capt
mov ecx,ebx
mov al,' '
rep stosw
mov al,' '
stosw
xor ebx,ebx
mov bl,[byte __lenY]
xor ecx,ecx
mov cl,[byte __lenX]
mov al,bl
add al,dh
sub al,3
mov [WindMaxY],al
mov al,cl
add al,dl
sub al,3
mov [WindMaxX],al
mov edx,[__BordCol]
mov eax,[__TextAttr]
and edx,1111b
and eax,11110000b
or edx,eax ; dl - Border Attr
movzx eax,[large word 44Ah]
mov dh,[byte __TextAttr]
sub eax,ecx
shl eax,1 ; eax - screen increment
add edi,eax
mov esi,ecx
sub esi,2
sub ebx,2
mov ebp,eax
__loop:
mov al,0BAh
mov ah,dl
stosw ; і
mov al,20h
mov ah,dh
mov ecx,esi
rep stosw
mov al,0BAh
mov ah,dl
stosw ; і
add edi,ebp
dec ebx
jnz __loop
mov al,0C8h
mov ah,dl
stosw
mov al,0CDh
mov ecx,esi
rep stosw
mov al,0BCh
stosw
__done:
popad
ret
endp
proc _putstring NEAR __bufstr
call GetCursor
call GetAddr
mov esi,[__bufstr]
__loop:
lodsb
or al,al
je __done
cmp al,0Dh
je __cr
cmp al,0Ah
je __lf
cmp al,09
je __tab
cmp dl,[WindMaxX]
ja __loop
stosb
inc dl
inc edi
jmp __loop
__lf:
mov dl,[WindMinX]
call GetAddr
jmp __loop
__cr:
cmp dh,[WindMaxY]
je __done
inc dh
call GetAddr
jmp __loop
__tab:
add dl,8
jmp __loop
__done:
cmp dl,[WindMaxX]
jbe __n1
mov dl,[WindMaxX]
__n1:
cmp dh,[WindMaxY]
jbe __n2
mov dh,[WindMaxY]
__n2:
call SetCursor
ret
endp
proc _putcstring near __bufstr, __color
call GetCursor
call GetAddr
mov esi,[__bufstr]
mov ah,[byte __color]
__loop:
lodsb
or al,al
je __done
cmp al,0Dh
je __cr
cmp al,0Ah
je __lf
cmp dl,[WindMaxX]
ja __loop
stosw
inc dl
jmp __loop
__lf:
mov dl,[WindMinX]
call GetAddr
jmp __loop
__cr:
cmp dh,[WindMaxY]
je __done
inc dh
call GetAddr
jmp __loop
__done:
cmp dl,[WindMaxX]
jbe __n1
mov dl,[WindMaxX]
__n1:
cmp dh,[WindMaxY]
jbe __n2
mov dh,[WindMaxY]
__n2:
call SetCursor
ret
endp |
|
0
|