Subversion Repositories Kolibri OS

Rev

Rev 1703 | Rev 1952 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
431 serge 1
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2
;;                                                              ;;
1508 art_zh 3
;; Copyright (C) KolibriOS team 2004-2010. All rights reserved. ;;
431 serge 4
;; Copyright (C) MenuetOS 2000-2004 Ville Mikael Turjanmaa      ;;
5
;; Distributed under terms of the GNU General Public License    ;;
6
;;                                                              ;;
7
;;  BOOTCODE.INC                                                ;;
8
;;                                                              ;;
9
;;  KolibriOS 16-bit loader,                                    ;;
10
;;                        based on bootcode for MenuetOS        ;;
11
;;                                                              ;;
12
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1 ha 13
 
593 mikedld 14
$Revision: 1941 $
1 ha 15
 
16
 
17
;==========================================================================
18
;
19
;                           16 BIT FUNCTIONS
20
;
21
;==========================================================================
22
 
1941 art_zh 23
if 0
29 halyavin 24
putchar:
25
; in: al=character
1683 art_zh 26
	mov	ah, 0Eh
27
	mov	bh, 0
28
	int	10h
29
	ret
1 ha 30
 
29 halyavin 31
print:
32
; in: si->string
1683 art_zh 33
	mov	al, 186
34
	call	putchar
35
	mov	al, ' '
36
	call	putchar
1 ha 37
 
29 halyavin 38
printplain:
39
; in: si->string
1683 art_zh 40
	pusha
41
	lodsb
29 halyavin 42
@@:
1683 art_zh 43
	call	putchar
44
	lodsb
45
	test	al,al
46
	jnz	@b
47
	popa
48
	ret
1 ha 49
 
50
 
29 halyavin 51
setcursor:
52
; in: dl=column, dh=row
1683 art_zh 53
	mov	ah, 2
54
	mov	bh, 0
55
	int	10h
56
	ret
29 halyavin 57
 
58
macro _setcursor row,column
59
{
1683 art_zh 60
	mov	dx, row*256 + column
61
	call	setcursor
29 halyavin 62
}
63
 
1941 art_zh 64
end if
65
 
134 diamond 66
boot_read_floppy:
1683 art_zh 67
	push	si
68
	xor	si, si
69
	mov	ah, 2	; read
134 diamond 70
@@:
1683 art_zh 71
	push	ax
72
	int	0x13
73
	pop	ax
74
	jnc	@f
75
	inc	si
76
	cmp	si, 10
1703 art_zh 77
	jnb	$
134 diamond 78
@@:
1683 art_zh 79
	pop	si
80
	ret
134 diamond 81
 
1703 art_zh 82
sayerr_plain:
83
	jmp	$
84
 
85
sayerr:
86
	jmp	$
87
 
88
 
795 shurf 89
; convert abs. sector number (AX) to BIOS T:H:S
90
; sector number = (abs.sector%BPB_SecPerTrk)+1
91
; pre.track number = (abs.sector/BPB_SecPerTrk)
92
; head number = pre.track number%BPB_NumHeads
93
; track number = pre.track number/BPB_NumHeads
94
; Return: cl - sector number
95
;         ch - track number
96
;         dl - drive number (0 = a:)
97
;         dh - head number
98
conv_abs_to_THS:
1683 art_zh 99
	push	bx
100
	mov	bx,word [BPB_SecPerTrk]
101
	xor	dx,dx
102
	div	bx
103
	inc	dx
104
	mov	cl, dl				; cl = sector number
105
	mov	bx,word [BPB_NumHeads]
106
	xor	dx,dx
107
	div	bx
108
	; !!!!!!! ax = track number, dx = head number
109
	mov	ch,al				; ch=track number
110
	xchg	dh,dl				; dh=head number
111
	mov	dl,0				; dl=0 (drive 0 (a:))
112
	pop	bx
113
	retn
795 shurf 114
; needed variables
1683 art_zh 115
BPB_SecPerTrk	dw	0			; sectors per track
116
BPB_NumHeads	dw	0			; number of heads
117
BPB_FATSz16	dw	0			; size of FAT
118
BPB_RootEntCnt	dw	0			; count of root dir. entries
119
BPB_BytsPerSec	dw	0			; bytes per sector
120
BPB_RsvdSecCnt	dw	0			; number of reserved sectors
121
BPB_TotSec16	dw	0			; count of the sectors on the volume
122
BPB_SecPerClus	db	0			; number of sectors per cluster
123
BPB_NumFATs	db	0			; number of FAT tables
124
abs_sector_adj	dw	0			; adjustment to make abs. sector number
125
end_of_FAT	dw	0			; end of FAT table
126
FirstDataSector dw	0			; begin of data
795 shurf 127
 
1 ha 128
;=========================================================================
129
;
130
;                           16 BIT CODE
131
;
132
;=========================================================================
133
 
1683 art_zh 134
include 'bootvesa.inc'		       ;Include source for boot vesa
1 ha 135
 
136
start_of_code:
1683 art_zh 137
	cld
29 halyavin 138
; \begin{diamond}[02.12.2005]
514 diamond 139
; if bootloader sets ax = 'KL', then ds:si points to loader block
1683 art_zh 140
	cmp	ax, 'KL'
141
	jnz	@f
142
	mov	word [cs:cfgmanager.loader_block], si
143
	mov	word [cs:cfgmanager.loader_block+2], ds
29 halyavin 144
@@:
145
; \end{diamond}[02.12.2005]
1 ha 146
 
514 diamond 147
; if bootloader sets cx = 'HA' and dx = 'RD', then bx contains identifier of source hard disk
148
; (see comment to bx_from_load)
1683 art_zh 149
	cmp	cx, 'HA'
150
	jnz	no_hd_load
151
	cmp	dx,'RD'
152
	jnz	no_hd_load
153
	mov	word [cs:bx_from_load], bx		; {SPraid}[13.03.2007]
488 spraid 154
no_hd_load:
155
 
29 halyavin 156
; set up stack
1683 art_zh 157
	mov	ax, 3000h
158
	mov	ss, ax
159
	mov	sp, 0EC00h
29 halyavin 160
; set up segment registers
1683 art_zh 161
	push	cs
162
	pop	ds
163
	push	cs
164
	pop	es
1 ha 165
 
29 halyavin 166
; set videomode
1683 art_zh 167
	mov	ax, 3
168
	int	0x10
1 ha 169
 
29 halyavin 170
; draw frames
1683 art_zh 171
	push	0xb800
172
	pop	es
173
	xor	di, di
174
	mov	ah, 1*16+15
465 serge 175
 
1703 art_zh 176
cpugood:
1 ha 177
 
1683 art_zh 178
	push	0
179
	popf
180
	sti
465 serge 181
 
29 halyavin 182
; set up esp
1683 art_zh 183
	movzx	esp, sp
1 ha 184
 
1683 art_zh 185
	push	0
186
	pop	es
187
	and	word [es:0x9031], 0
164 serge 188
; \begin{Mario79}
189
; find HDD IDE DMA PCI device
160 diamond 190
; check for PCI BIOS
1683 art_zh 191
	mov	ax, 0xB101
192
	int	0x1A
193
	jc	.nopci
194
	cmp	edx, 'PCI '
195
	jnz	.nopci
160 diamond 196
; find PCI class code
197
; class 1 = mass storage
198
; subclass 1 = IDE controller
199
; a) class 1, subclass 1, programming interface 0x80
1683 art_zh 200
	mov	ax, 0xB103
201
	mov	ecx, 1*10000h + 1*100h + 0x80
202
	xor	si, si	; device index = 0
203
	int	0x1A
204
	jnc	.found
187 diamond 205
; b) class 1, subclass 1, programming interface 0x8A
1683 art_zh 206
	mov	ax, 0xB103
207
	mov	ecx, 1*10000h + 1*100h + 0x8A
208
	xor	si, si	; device index = 0
209
	int	0x1A
210
	jnc	.found
187 diamond 211
; c) class 1, subclass 1, programming interface 0x85
1683 art_zh 212
	mov	ax, 0xB103
213
	mov	ecx, 1*10000h + 1*100h + 0x85
214
	xor	si, si
215
	int	0x1A
216
	jc	.nopci
160 diamond 217
.found:
218
; get memory base
1683 art_zh 219
	mov	ax, 0xB10A
220
	mov	di, 0x20	; memory base is config register at 0x20
221
	int	0x1A
222
	jc	.nopci
223
	and	cx, 0xFFF0	; clear address decode type
224
	mov	[es:0x9031], cx
160 diamond 225
.nopci:
164 serge 226
; \end{Mario79}
160 diamond 227
 
76 mario79 228
; --------------- APM ---------------------
1683 art_zh 229
	and	word [es:0x9044], 0	; ver = 0.0 (APM not found)
230
	mov	ax, 0x5300
231
	xor	bx, bx
232
	int	0x15
233
	jc	apm_end 		; APM not found
234
	test	cx, 2
235
	jz	apm_end 		; APM 32-bit protected-mode interface not supported
236
	mov	[es:0x9044], ax 	; Save APM Version
237
	mov	[es:0x9046], cx 	; Save APM flags
164 serge 238
 
1683 art_zh 239
	mov	ax, 0x5304		; Disconnect interface
240
	xor	bx, bx
241
	int	0x15
242
	mov	ax, 0x5303		; Connect 32 bit mode interface
243
	xor	bx, bx
244
	int	0x15
465 serge 245
 
1683 art_zh 246
	mov	[es:0x9040], ebx
247
	mov	[es:0x9050], ax
248
	mov	[es:0x9052], cx
249
	mov	[es:0x9054], dx
465 serge 250
 
76 mario79 251
apm_end:
252
 
713 Lrz 253
;CHECK current of code
1683 art_zh 254
	cmp	[cfgmanager.loader_block], -1
255
	jz	noloaderblock
256
	les	bx, [cfgmanager.loader_block]
257
	cmp	byte [es:bx], 1
258
	jnz	sayerr
259
	push	0
260
	pop	es
713 Lrz 261
 
262
noloaderblock:
1 ha 263
; DISPLAY VESA INFORMATION
1683 art_zh 264
	 call	 print_vesa_info
265
	 call	 calc_vmodes_table
266
	 call	 check_first_parm  ;check and enable cursor_pos
1 ha 267
 
29 halyavin 268
; \begin{diamond}[30.11.2005]
269
cfgmanager:
270
; settings:
271
; a) preboot_graph = graphical mode
272
;    preboot_gprobe = probe this mode?
713 Lrz 273
; b) preboot_dma  = use DMA access?
29 halyavin 274
; c) preboot_vrrm = use VRR?
275
; d) preboot_device = from what boot?
713 Lrz 276
 
29 halyavin 277
; determine default settings
1703 art_zh 278
;        mov     [.bSettingsChanged], 0
713 Lrz 279
 
280
;.preboot_gr_end:
1683 art_zh 281
	mov	di, preboot_device
726 diamond 282
; if image in memory is present and [preboot_device] is uninitialized,
283
; set it to use this preloaded image
1683 art_zh 284
	cmp	byte [di], 0
285
	jnz	.preboot_device_inited
286
	cmp	[.loader_block], -1
287
	jz	@f
288
	les	bx, [.loader_block]
289
	test	byte [es:bx+1], 1
290
	jz	@f
291
	mov	byte [di], 3
292
	jmp	.preboot_device_inited
726 diamond 293
@@:
294
; otherwise, set [preboot_device] to 1 (default value - boot from floppy)
1683 art_zh 295
	mov	byte [di], 1
726 diamond 296
.preboot_device_inited:
1018 diamond 297
; following 4 lines set variables to 1 if its current value is 0
1683 art_zh 298
	cmp	byte [di+preboot_dma-preboot_device], 1
299
	adc	byte [di+preboot_dma-preboot_device], 0
300
	cmp	byte [di+preboot_biosdisk-preboot_device], 1
301
	adc	byte [di+preboot_biosdisk-preboot_device], 0
713 Lrz 302
 
1703 art_zh 303
;        pop     ax              ; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< ??
304
	jmp	.continue
143 diamond 305
.loader_block dd -1
29 halyavin 306
.continue:
1683 art_zh 307
	sti
1703 art_zh 308
	jmp	 .load
946 lrz 309
 
29 halyavin 310
.loadc:
1683 art_zh 311
	pop	eax
29 halyavin 312
.cont:
1683 art_zh 313
	push	cs
314
	pop	ds
29 halyavin 315
.load:
1 ha 316
 
317
; ASK GRAPHICS MODE
318
 
1683 art_zh 319
	call	set_vmode
1 ha 320
 
321
; GRAPHICS ACCELERATION
346 diamond 322
; force yes
1683 art_zh 323
	mov	[es:0x901C], byte 1
1 ha 324
 
514 diamond 325
; DMA ACCESS TO HD
1 ha 326
 
1683 art_zh 327
	mov	al, [preboot_dma]
328
	mov	[es:0x901F], al
346 diamond 329
 
1 ha 330
; VRR_M USE
331
 
1683 art_zh 332
	mov	al,[preboot_vrrm]
333
	mov	[es:0x9030], al
334
	mov	[es:0x901E], byte 1
1 ha 335
 
336
; BOOT DEVICE
337
 
1683 art_zh 338
	mov	al, [preboot_device]
339
	dec	al
340
	mov	[boot_dev], al
1 ha 341
 
1103 diamond 342
; GET MEMORY MAP
343
include 'detect/biosmem.inc'
344
 
1 ha 345
; READ DISKETTE TO MEMORY
346
 
1683 art_zh 347
	cmp	[boot_dev],0
348
	jne	no_sys_on_floppy
349
	xor	ax, ax		  ; reset drive
350
	xor	dx, dx
351
	int	0x13
709 diamond 352
; do we boot from CD-ROM?
1683 art_zh 353
	mov	ah, 41h
354
	mov	bx, 55AAh
355
	xor	dx, dx
356
	int	0x13
357
	jc	.nocd
358
	cmp	bx, 0AA55h
359
	jnz	.nocd
360
	mov	ah, 48h
361
	push	ds
362
	push	es
363
	pop	ds
364
	mov	si, 0xa000
365
	mov	word [si], 30
366
	int	0x13
367
	pop	ds
368
	jc	.nocd
369
	push	ds
370
	lds	si, [es:si+26]
371
	test	byte [ds:si+10], 40h
372
	pop	ds
373
	jz	.nocd
709 diamond 374
; yes - read all floppy by 18 sectors
795 shurf 375
 
376
; TODO: !!!! read only first sector and set variables !!!!!
377
; ...
378
; TODO: !!! then read flippy image track by track
1683 art_zh 379
 
380
	mov	cx, 0x0001	; startcyl,startsector
709 diamond 381
.a1:
1683 art_zh 382
	push	cx dx
383
	mov	al, 18
384
	mov	bx, 0xa000
385
	call	boot_read_floppy
386
	mov	si, movedesc
387
	push	es
388
	push	ds
389
	pop	es
390
	mov	cx, 256*18
391
	mov	ah, 0x87
392
	int	0x15
393
	pop	es
394
	pop	dx cx
395
	test	ah, ah
396
	jnz	sayerr_floppy
397
	add	dword [si+8*3+2], 512*18
398
	inc	dh
399
	cmp	dh, 2
400
	jnz	.a1
401
	mov	dh, 0
402
	inc	ch
403
	cmp	ch, 80
404
	jae	ok_sys_on_floppy
405
	mov	al, ch
406
	shr	ch, 2
407
	jmp	.a1
709 diamond 408
.nocd:
409
; no - read only used sectors from floppy
134 diamond 410
; now load floppy image to memory
411
; at first load boot sector and first FAT table
795 shurf 412
 
413
; read only first sector and fill variables
1683 art_zh 414
	mov	cx, 0x0001	; first logical sector
415
	xor	dx, dx		; head = 0, drive = 0 (a:)
416
	mov	al, 1		; read one sector
417
	mov	bx, 0xB000	; es:bx -> data area
418
	call	boot_read_floppy
795 shurf 419
; fill the necessary parameters to work with a floppy
1683 art_zh 420
	mov	ax, word [es:bx+24]
421
	mov	word [BPB_SecPerTrk], ax
422
	mov	ax, word [es:bx+26]
423
	mov	word [BPB_NumHeads], ax
424
	mov	ax, word [es:bx+17]
425
	mov	word [BPB_RootEntCnt], ax
426
	mov	ax, word [es:bx+14]
427
	mov	word [BPB_RsvdSecCnt], ax
428
	mov	ax, word [es:bx+19]
429
	mov	word [BPB_TotSec16], ax
430
	mov	al, byte [es:bx+13]
431
	mov	byte [BPB_SecPerClus], al
432
	mov	al, byte [es:bx+16]
433
	mov	byte [BPB_NumFATs], al
925 Lrz 434
; 18.11.2008
1683 art_zh 435
	mov	ax, word [es:bx+22]
436
	mov	word [BPB_FATSz16], ax
437
	mov	cx, word [es:bx+11]
438
	mov	word [BPB_BytsPerSec], cx
925 Lrz 439
 
795 shurf 440
; count of clusters in FAT12 ((size_of_FAT*2)/3)
925 Lrz 441
;        mov     ax, word [BPB_FATSz16]
442
;        mov     cx, word [BPB_BytsPerSec]
443
;end  18.11.2008
1683 art_zh 444
	xor	dx, dx
445
	mul	cx
446
	shl	ax, 1
447
	mov	cx, 3
448
	div	cx		; now ax - number of clusters in FAT12
449
	mov	word [end_of_FAT], ax
795 shurf 450
 
451
; load first FAT table
1683 art_zh 452
	mov	cx, 0x0002	; startcyl,startsector          ; TODO!!!!!
453
	xor	dx, dx		; starthead,drive
454
	mov	al, byte [BPB_FATSz16]	   ; no of sectors to read
455
	add	bx, word [BPB_BytsPerSec]  ; es:bx -> data area
456
	call	boot_read_floppy
457
	mov	bx, 0xB000
795 shurf 458
 
134 diamond 459
; and copy them to extended memory
1683 art_zh 460
	mov	si, movedesc
461
	mov	[si+8*2+3], bh		; from
462
 
463
	mov	ax, word [BPB_BytsPerSec]
464
	shr	ax, 1			; words per sector
465
	mov	cx, word [BPB_RsvdSecCnt]
466
	add	cx, word [BPB_FATSz16]
467
	mul	cx
468
	push	ax			; save to stack count of words in boot+FAT
469
	xchg	ax, cx
470
 
471
	push	es
472
	push	ds
473
	pop	es
474
	mov	ah, 0x87
475
	int	0x15
476
	pop	es
477
	test	ah, ah
478
	jz	@f
134 diamond 479
sayerr_floppy:
1683 art_zh 480
	mov	dx, 0x3f2
481
	mov	al, 0
482
	out	dx, al
1703 art_zh 483
;        mov     si, memmovefailed
484
	jmp	$
134 diamond 485
@@:
1683 art_zh 486
	pop	ax			; restore from stack count of words in boot+FAT
487
	shl	ax, 1			; make bytes count from count of words
488
	and	eax, 0ffffh
489
	add	dword [si+8*3+2], eax
795 shurf 490
 
491
; copy first FAT to second copy
492
; TODO: BPB_NumFATs !!!!!
1683 art_zh 493
	add	bx, word [BPB_BytsPerSec]	; !!! TODO: may be need multiply by BPB_RsvdSecCnt !!!
494
	mov	byte [si+8*2+3], bh	; bx - begin of FAT
795 shurf 495
 
1683 art_zh 496
	mov	ax, word [BPB_BytsPerSec]
497
	shr	ax, 1			; words per sector
498
	mov	cx, word [BPB_FATSz16]
499
	mul	cx
500
	mov	cx, ax			; cx - count of words in FAT
501
 
502
	push	es
503
	push	ds
504
	pop	es
505
	mov	ah, 0x87
506
	int	0x15
507
	pop	es
508
	test	ah, ah
509
	jnz	sayerr_floppy
510
 
511
	mov	ax, cx
512
	shl	ax, 1
513
	and	eax, 0ffffh		; ax - count of bytes in FAT
514
	add	dword [si+8*3+2], eax
515
 
795 shurf 516
; reading RootDir
517
; TODO: BPB_NumFATs
1683 art_zh 518
	add	bx, ax
519
	add	bx, 100h
520
	and	bx, 0ff00h			; bx - place in buffer to write RootDir
521
	push	bx
795 shurf 522
 
1683 art_zh 523
	mov	bx, word [BPB_BytsPerSec]
524
	shr	bx, 5				; divide bx by 32
525
	mov	ax, word [BPB_RootEntCnt]
526
	xor	dx, dx
527
	div	bx
528
	push	ax				; ax - count of RootDir sectors
795 shurf 529
 
1683 art_zh 530
	mov	ax, word [BPB_FATSz16]
531
	xor	cx, cx
532
	mov	cl, byte [BPB_NumFATs]
533
	mul	cx
534
	add	ax, word [BPB_RsvdSecCnt]	; ax - first sector of RootDir
795 shurf 535
 
1683 art_zh 536
	mov	word [FirstDataSector], ax
537
	pop	bx
538
	push	bx
539
	add	word [FirstDataSector], bx	; Begin of data region of floppy
540
 
795 shurf 541
; read RootDir
1683 art_zh 542
	call	conv_abs_to_THS
543
	pop	ax
544
	pop	bx				; place in buffer to write
545
	push	ax
546
	call	boot_read_floppy		; read RootDir into buffer
795 shurf 547
; copy RootDir
1683 art_zh 548
	mov	byte [si+8*2+3], bh		; from buffer
549
	pop	ax				; ax = count of RootDir sectors
550
	mov	cx, word [BPB_BytsPerSec]
551
	mul	cx
552
	shr	ax, 1
553
	mov	cx, ax				; count of words to copy
554
	push	es
555
	push	ds
556
	pop	es
557
	mov	ah, 0x87
558
	int	0x15
559
	pop	es
795 shurf 560
 
1683 art_zh 561
	mov	ax, cx
562
	shl	ax, 1
563
	and	eax, 0ffffh		; ax - count of bytes in RootDir
564
	add	dword [si+8*3+2], eax	; add count of bytes copied
795 shurf 565
 
566
; Reading data clusters from floppy
1683 art_zh 567
	mov	byte [si+8*2+3], bh
568
	push	bx
795 shurf 569
 
1683 art_zh 570
	mov	di, 2			; First data cluster
134 diamond 571
.read_loop:
1683 art_zh 572
	mov	bx, di
573
	shr	bx, 1			; bx+di = di*1.5
574
	jnc	.even
575
	test	word [es:bx+di+0xB200], 0xFFF0	; TODO: may not be 0xB200 !!!
576
	jmp	@f
134 diamond 577
.even:
1683 art_zh 578
	test	word [es:bx+di+0xB200], 0xFFF	; TODO: may not be 0xB200 !!!
795 shurf 579
 
134 diamond 580
@@:
1683 art_zh 581
	jz	.skip
795 shurf 582
; read cluster di
583
;.read:
1683 art_zh 584
	;conv cluster di to abs. sector ax
585
	; ax = (N-2) * BPB_SecPerClus + FirstDataSector
586
	mov	ax, di
587
	sub	ax, 2
588
	xor	bx, bx
589
	mov	bl, byte [BPB_SecPerClus]
590
	mul	bx
591
	add	ax, word [FirstDataSector]
592
	call	conv_abs_to_THS
593
	pop	bx
594
	push	bx
595
	mov	al, byte [BPB_SecPerClus]	; number of sectors in cluster
596
	call	boot_read_floppy
597
	push	es
598
	push	ds
599
	pop	es
600
	pusha
795 shurf 601
;
1683 art_zh 602
	mov	ax, word [BPB_BytsPerSec]
603
	xor	cx, cx
604
	mov	cl, byte [BPB_SecPerClus]
605
	mul	cx
606
	shr	ax, 1				; ax = (BPB_BytsPerSec * BPB_SecPerClus)/2
607
	mov	cx, ax				; number of words to copy (count words in cluster)
795 shurf 608
;
1683 art_zh 609
	mov	ah, 0x87
610
	int	0x15				; copy data
611
	test	ah, ah
612
	popa
613
	pop	es
614
	jnz	sayerr_floppy
795 shurf 615
; skip cluster di
134 diamond 616
.skip:
1683 art_zh 617
	mov	ax, word [BPB_BytsPerSec]
618
	xor	cx, cx
619
	mov	cl, byte [BPB_SecPerClus]
620
	mul	cx
621
	and	eax, 0ffffh		; ax - count of bytes in cluster
622
	add	dword [si+8*3+2], eax
795 shurf 623
 
1683 art_zh 624
	mov	ax, word [end_of_FAT]	; max cluster number
625
	pusha
134 diamond 626
; draw percentage
795 shurf 627
; total clusters: ax
628
; read clusters: di
1683 art_zh 629
	xchg	ax, di
630
	mov	cx, 100
631
	mul	cx
632
	div	di
633
	aam
634
	xchg	al, ah
635
	add	ax, '00'
134 diamond 636
@@:
1683 art_zh 637
	popa
638
	inc	di
639
	cmp	di, word [end_of_FAT]	; max number of cluster
640
	jnz	.read_loop
641
	pop	bx			; clear stack
134 diamond 642
 
709 diamond 643
ok_sys_on_floppy:
514 diamond 644
no_sys_on_floppy:
1683 art_zh 645
	xor	ax, ax		; reset drive
646
	xor	dx, dx
647
	int	0x13
648
	mov	dx, 0x3f2	; floppy motor off
649
	mov	al, 0
650
	out	dx, al
1 ha 651
 
652
 
653
; SET GRAPHICS
654
 
1683 art_zh 655
	xor	ax, ax
656
	mov	es, ax
164 serge 657
 
1683 art_zh 658
	mov	bx, [es:0x9008] 	; vga & 320x200
659
	mov	ax, 0x4f02		; Vesa
412 serge 660
setgr:
1683 art_zh 661
	int	0x10
662
	test	ah, ah
1703 art_zh 663
	jnz	$
412 serge 664
gmok2:
1683 art_zh 665
	push	ds
666
	pop	es