Subversion Repositories Kolibri OS

Rev

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

Rev Author Line No. Line
431 serge 1
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2
;;                                                              ;;
2465 Serge 3
;; Copyright (C) KolibriOS team 2004-2011. 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: 5201 $
1 ha 15
 
16
 
17
;==========================================================================
18
;
19
;                           16 BIT FUNCTIONS
20
;
21
;==========================================================================
22
 
183 diamond 23
 
29 halyavin 24
putchar:
25
; in: al=character
514 diamond 26
        mov     ah, 0Eh
27
        mov     bh, 0
28
        int     10h
29
        ret
1 ha 30
 
29 halyavin 31
print:
32
; in: si->string
514 diamond 33
        mov     al, 186
34
        call    putchar
35
        mov     al, ' '
36
        call    putchar
1 ha 37
 
29 halyavin 38
printplain:
39
; in: si->string
514 diamond 40
        pusha
41
        lodsb
29 halyavin 42
@@:
514 diamond 43
        call    putchar
44
        lodsb
2434 Serge 45
        test    al, al
514 diamond 46
        jnz     @b
47
        popa
48
        ret
1 ha 49
 
3908 Serge 50
getkey:                         ; Use BIOS INT 16h to read a key from the keyboard
29 halyavin 51
; get number in range [bl,bh] (bl,bh in ['0'..'9'])
52
; in: bx=range
53
; out: ax=digit (1..9, 10 for 0)
4265 Serge 54
        mov     ah, 0       ; If 'int 16h' is called with 'ah' equal to zero, the BIOS will not return control to the caller
55
        int     16h         ; until a key is available in the system type ahead buffer. On return, 'al' contains the ASCII
56
        cmp     al, 27      ; code for the key read from the buffer and 'ah' contains the keyboard scan code. (27=>ESC)
57
        jz      @f          ; If ESC is pressed, return (user doesn't want to change any value).
58
        cmp     al, bl      ; Compare 'al' (ASCII code of key pressed) with 'bl' (lowest accepted char from the range).
59
        jb      getkey      ; ASCII code is below lowest accepted value => continue waiting for another key.
60
        cmp     al, bh      ; Compare 'al' (ASCII code of key pressed) with 'bh' (highest accepted char from the range).
61
        ja      getkey      ; ASCII code is above highest accepted value => continue waiting for another key.
3908 Serge 62
        push    ax              ; If the pressed key is in the accepted range, save it on the stack and echo to screen.
514 diamond 63
        call    putchar
64
        pop     ax
4265 Serge 65
        and     ax, 0Fh     ; Convert ASCII code to number: '1'->1, '2'->2, etc. 0Fh=1111b.
66
        jnz     @f          ; ASCII code for '0' is 48 (110000b). (110000b AND 1111b) = 0
67
        mov     al, 10      ; So if key '0' was entered, return 10 in 'ax'
29 halyavin 68
@@:
514 diamond 69
        ret
1 ha 70
 
29 halyavin 71
setcursor:
72
; in: dl=column, dh=row
514 diamond 73
        mov     ah, 2
74
        mov     bh, 0
75
        int     10h
76
        ret
29 halyavin 77
 
78
macro _setcursor row,column
79
{
514 diamond 80
        mov     dx, row*256 + column
81
        call    setcursor
29 halyavin 82
}
83
 
4265 Serge 84
macro _ask_question question,range,variable_to_set
85
{
86
        _setcursor 16,0
87
        mov     si, question    ; Print the question
88
        call    print
89
        mov     bx, range       ; range accepted for answer
90
        call    getkey
91
        cmp     al, 27          ; If ESC was pressed, do not change the value
92
        jz      .esc_pressed
93
        mov     [variable_to_set], al
94
}
95
 
134 diamond 96
boot_read_floppy:
97
        push    si
98
        xor     si, si
99
        mov     ah, 2   ; read
100
@@:
101
        push    ax
102
        int     0x13
103
        pop     ax
104
        jnc     @f
105
        inc     si
106
        cmp     si, 10
107
        jb      @b
2010 serge 108
sayerr_badsect:
465 serge 109
        mov     si, badsect
134 diamond 110
sayerr_plain:
111
        call    printplain
112
        jmp     $
113
@@:
114
        pop     si
115
        ret
116
 
795 shurf 117
; convert abs. sector number (AX) to BIOS T:H:S
118
; sector number = (abs.sector%BPB_SecPerTrk)+1
119
; pre.track number = (abs.sector/BPB_SecPerTrk)
120
; head number = pre.track number%BPB_NumHeads
121
; track number = pre.track number/BPB_NumHeads
122
; Return: cl - sector number
123
;         ch - track number
124
;         dl - drive number (0 = a:)
125
;         dh - head number
126
conv_abs_to_THS:
127
        push    bx
2434 Serge 128
        mov     bx, word [BPB_SecPerTrk]
129
        xor     dx, dx
795 shurf 130
        div     bx
131
        inc     dx
132
        mov     cl, dl                          ; cl = sector number
2434 Serge 133
        mov     bx, word [BPB_NumHeads]
134
        xor     dx, dx
795 shurf 135
        div     bx
136
        ; !!!!!!! ax = track number, dx = head number
2434 Serge 137
        mov     ch, al                          ; ch=track number
138
        xchg    dh, dl                          ; dh=head number
139
        mov     dl, 0                           ; dl=0 (drive 0 (a:))
795 shurf 140
        pop     bx
141
        retn
142
; needed variables
816 Lrz 143
BPB_SecPerTrk   dw      0                       ; sectors per track
144
BPB_NumHeads    dw      0                       ; number of heads
145
BPB_FATSz16     dw      0                       ; size of FAT
146
BPB_RootEntCnt  dw      0                       ; count of root dir. entries
147
BPB_BytsPerSec  dw      0                       ; bytes per sector
148
BPB_RsvdSecCnt  dw      0                       ; number of reserved sectors
149
BPB_TotSec16    dw      0                       ; count of the sectors on the volume
150
BPB_SecPerClus  db      0                       ; number of sectors per cluster
151
BPB_NumFATs     db      0                       ; number of FAT tables
152
abs_sector_adj  dw      0                       ; adjustment to make abs. sector number
153
end_of_FAT      dw      0                       ; end of FAT table
154
FirstDataSector dw      0                       ; begin of data
795 shurf 155
 
1 ha 156
;=========================================================================
157
;
158
;                           16 BIT CODE
159
;
160
;=========================================================================
161
 
3908 Serge 162
include 'bootvesa.inc'                 ;Include source for boot vesa
2010 serge 163
if defined extended_primary_loader
164
include 'parsers.inc'
165
end if
1 ha 166
 
167
start_of_code:
2010 serge 168
 
169
if defined extended_primary_loader
170
; save data from primary loader
171
        mov     word [cs:bootcallback], si
172
        mov     word [cs:bootcallback+2], ds
173
        push    cs
174
        pop     ds
175
        mov     [bootdevice], ax
176
        mov     [bootfs], bx
177
 
178
; set up stack
179
        mov     ax, 3000h
180
        mov     ss, ax
181
        mov     sp, 0EC00h
182
 
183
; try to load configuration file
184
        mov     ax, 1
185
        mov     di, config_file_struct
186
        call    [bootcallback]
514 diamond 187
        cld
2010 serge 188
        push    cs
189
        pop     es
190
; bx=0 - ok, bx=1 - part of file loaded, assume this is ok
191
        cmp     bx, 1
192
        ja      .config_bad
193
; configuration file was loaded, parse
194
; if length is too big, use first 0FFFFh bytes
195
        test    dx, dx
196
        jz      @f
197
        mov     ax, 0FFFFh
198
@@:
199
; ds:si will be pointer to current data, dx = limit
200
        xchg    ax, dx
201
        push    4000h
202
        pop     ds
203
        xor     si, si
204
.parse_loop:
205
; skip spaces
206
        cmp     si, dx
207
        jae     .parse_done
208
        lodsb
209
        cmp     al, ' '
210
        jbe     .parse_loop
211
        dec     si
212
; loop over all possible configuration values
213
        mov     bx, config_file_variables
214
.find_variant:
215
; get length
216
        mov     cx, [es:bx]
217
; zero length = end of list
218
        jecxz   .find_newline
219
; skip over length
220
        inc     bx
221
        inc     bx
222
        mov     di, bx
223
; skip over string
224
        add     bx, cx
225
; test whether we have at least cx symbols left
226
        mov     ax, cx
227
        add     ax, si
228
        jc      .next_variant1
229
        cmp     ax, dx
230
        jae     .next_variant1
231
; save current position
232
        push    si
233
; compare strings
3908 Serge 234
        repz cmpsb
2010 serge 235
        jnz     .next_variant2
236
; strings are equal; look for "=" with possible spaces before and after
237
@@:
238
        cmp     si, dx
239
        jae     .next_variant2
240
        lodsb
241
        cmp     al, ' '
242
        jbe     @b
243
        cmp     al, '='
244
        jnz     .next_variant2
245
; ok, we found the true variant
246
; ignore saved position on the stack
247
        pop     ax
248
; call the parser
249
        call    word [es:bx]
250
; line parsed, find next
251
.find_newline:
252
        cmp     si, dx
253
        jae     .parse_done
254
        lodsb
255
        cmp     al, 13
256
        jz      .parse_loop
257
        cmp     al, 10
258
        jz      .parse_loop
259
        jmp     .find_newline
260
.next_variant2:
261
; continue to the next variant, restoring current position
262
        pop     si
263
.next_variant1:
264
; continue to the next variant
265
; skip over the parser
266
        inc     bx
267
        inc     bx
268
        jmp     .find_variant
269
.parse_done:
270
.config_bad:
271
 
272
; set up segment registers
273
        push    cs
274
        pop     ds
275
else
276
        cld
29 halyavin 277
; \begin{diamond}[02.12.2005]
514 diamond 278
; if bootloader sets ax = 'KL', then ds:si points to loader block
279
        cmp     ax, 'KL'
280
        jnz     @f
281
        mov     word [cs:cfgmanager.loader_block], si
282
        mov     word [cs:cfgmanager.loader_block+2], ds
29 halyavin 283
@@:
284
; \end{diamond}[02.12.2005]
1 ha 285
 
514 diamond 286
; if bootloader sets cx = 'HA' and dx = 'RD', then bx contains identifier of source hard disk
287
; (see comment to bx_from_load)
288
        cmp     cx, 'HA'
289
        jnz     no_hd_load
2434 Serge 290
        cmp     dx, 'RD'
514 diamond 291
        jnz     no_hd_load
292
        mov     word [cs:bx_from_load], bx              ; {SPraid}[13.03.2007]
488 spraid 293
no_hd_load:
294
 
29 halyavin 295
; set up stack
514 diamond 296
        mov     ax, 3000h
297
        mov     ss, ax
298
        mov     sp, 0EC00h
29 halyavin 299
; set up segment registers
514 diamond 300
        push    cs
301
        pop     ds
302
        push    cs
303
        pop     es
2010 serge 304
end if
1 ha 305
 
29 halyavin 306
; set videomode
514 diamond 307
        mov     ax, 3
308
        int     0x10
1 ha 309
 
134 diamond 310
if lang eq ru
1 ha 311
 ; Load & set russian VGA font (RU.INC)
514 diamond 312
        mov     bp, RU_FNT1             ; RU_FNT1 - First part
313
        mov     bx, 1000h               ; 768 bytes
314
        mov     cx, 30h                 ; 48 symbols
315
        mov     dx, 80h                 ; 128 - position of first symbol
316
        mov     ax, 1100h
317
        int     10h
1 ha 318
 
514 diamond 319
        mov     bp, RU_FNT2             ; RU_FNT2 -Second part
320
        mov     bx, 1000h               ; 512 bytes
321
        mov     cx, 20h                 ; 32 symbols
322
        mov     dx, 0E0h                ; 224 - position of first symbol
323
        mov     ax, 1100h
324
        int     10h
1 ha 325
 ; End set VGA russian font
274 kaitz 326
else if lang eq et
514 diamond 327
        mov     bp, ET_FNT              ; ET_FNT1
328
        mov     bx, 1000h               ;
329
        mov     cx, 255                 ; 256 symbols
330
        xor     dx, dx                  ; 0 - position of first symbol
331
        mov     ax, 1100h
332
        int     10h
134 diamond 333
end if
1 ha 334
 
29 halyavin 335
; draw frames
514 diamond 336
        push    0xb800
337
        pop     es
338
        xor     di, di
339
        mov     ah, 1*16+15
465 serge 340
 
29 halyavin 341
; draw top
514 diamond 342
        mov     si, d80x25_top
343
        mov     cx, d80x25_top_num * 80
29 halyavin 344
@@:
514 diamond 345
        lodsb
346
        stosw
347
        loop    @b
29 halyavin 348
; draw spaces
514 diamond 349
        mov     si, space_msg
350
        mov     dx, 25 - d80x25_top_num - d80x25_bottom_num
29 halyavin 351
dfl1:
514 diamond 352
        push    si
353
        mov     cx, 80
29 halyavin 354
@@:
514 diamond 355
        lodsb
356
        stosw
357
        loop    @b
358
        pop     si
359
        dec     dx
360
        jnz     dfl1
29 halyavin 361
; draw bottom
514 diamond 362
        mov     si, d80x25_bottom
363
        mov     cx, d80x25_bottom_num * 80
29 halyavin 364
@@:
514 diamond 365
        lodsb
366
        stosw
367
        loop    @b
1 ha 368
 
514 diamond 369
        mov     byte [space_msg+80], 0    ; now space_msg is null terminated
1 ha 370
 
514 diamond 371
        _setcursor d80x25_top_num,0
1 ha 372
 
373
 
374
; TEST FOR 386+
375
 
514 diamond 376
        mov     bx, 0x4000
1 ha 377
        pushf
378
        pop     ax
514 diamond 379
        mov     dx, ax
380
        xor     ax, bx
1 ha 381
        push    ax
382
        popf
383
        pushf
384
        pop     ax
514 diamond 385
        and     ax, bx
386
        and     dx, bx
387
        cmp     ax, dx
1 ha 388
        jnz     cpugood
514 diamond 389
        mov     si, not386
40 halyavin 390
sayerr:
1 ha 391
        call    print
392
        jmp     $
393
     cpugood:
394
 
514 diamond 395
        push    0
465 serge 396
        popf
397
 
29 halyavin 398
; set up esp
514 diamond 399
        movzx   esp, sp
1 ha 400
 
160 diamond 401
        push    0
402
        pop     es
3908 Serge 403
 
5201 serge 404
        xor     cx, cx
405
@@:
406
        in      al, 64h
407
        test    al, 2
408
        loopnz  @b
3908 Serge 409
 
3555 Serge 410
        mov     al, 0xf6        ; Сброс клавиатуры, разрешить сканирование
514 diamond 411
        out     0x60, al
412
        xor     cx, cx
5201 serge 413
@@:
514 diamond 414
        in      al, 64h
5201 serge 415
        test    al, 1
416
        loopz   @b
417
        in      al, 0x60
1 ha 418
 
713 Lrz 419
;;;/diamond today   5.02.2008
420
; set keyboard typematic rate & delay
421
        mov     al, 0xf3
422
        out     0x60, al
423
        xor     cx, cx
424
@@:
425
        in      al, 64h
5201 serge 426
        test    al, 1
427
        loopz   @b
428
        in      al, 0x60
713 Lrz 429
        mov     al, 0
430
        out     0x60, al
431
        xor     cx, cx
432
@@:
433
        in      al, 64h
5201 serge 434
        test    al, 1
435
        loopz   @b
436
        in      al, 0x60
713 Lrz 437
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
5201 serge 438
        sti
76 mario79 439
; --------------- APM ---------------------
2441 Serge 440
        and     word [es:BOOT_APM_VERSION], 0     ; ver = 0.0 (APM not found)
514 diamond 441
        mov     ax, 0x5300
442
        xor     bx, bx
443
        int     0x15
3908 Serge 444
        jc      apm_end                 ; APM not found
514 diamond 445
        test    cx, 2
3908 Serge 446
        jz      apm_end                 ; APM 32-bit protected-mode interface not supported
2441 Serge 447
        mov     [es:BOOT_APM_VERSION], ax         ; Save APM Version
448
        mov     [es:BOOT_APM_FLAGS], cx           ; Save APM flags
164 serge 449
 
514 diamond 450
        ; Write APM ver ----
451
        and     ax, 0xf0f
452
        add     ax, '00'
453
        mov     si, msg_apm
454
        mov     [si + 5], ah
455
        mov     [si + 7], al
456
        _setcursor 0, 3
457
        call    printplain
458
        ; ------------------
164 serge 459
 
514 diamond 460
        mov     ax, 0x5304              ; Disconnect interface
461
        xor     bx, bx
462
        int     0x15
463
        mov     ax, 0x5303              ; Connect 32 bit mode interface
464
        xor     bx, bx
465
        int     0x15
465 serge 466
 
2441 Serge 467
        mov     [es:BOOT_APM_ENTRY], ebx
468
        mov     [es:BOOT_APM_CODE_32], ax
469
        mov     [es:BOOT_APM_CODE_16], cx
470
        mov     [es:BOOT_APM_DATA_16], dx
465 serge 471
 
76 mario79 472
apm_end:
437 diamond 473
        _setcursor d80x25_top_num, 0
76 mario79 474
 
2010 serge 475
if ~ defined extended_primary_loader
713 Lrz 476
;CHECK current of code
477
        cmp     [cfgmanager.loader_block], -1
478
        jz      noloaderblock
479
        les     bx, [cfgmanager.loader_block]
480
        cmp     byte [es:bx], 1
481
        mov     si, loader_block_error
482
        jnz     sayerr
737 diamond 483
        push    0
484
        pop     es
2010 serge 485
end if
713 Lrz 486
 
487
noloaderblock:
1 ha 488
; DISPLAY VESA INFORMATION
3908 Serge 489
        call    print_vesa_info
490
        call    calc_vmodes_table
491
        call    check_first_parm   ;check and enable cursor_pos
1 ha 492
 
29 halyavin 493
; \begin{diamond}[30.11.2005]
494
cfgmanager:
495
; settings:
496
; a) preboot_graph = graphical mode
497
;    preboot_gprobe = probe this mode?
3908 Serge 498
; b) preboot_biosdisk  = use BIOS disks through V86 emulation? // (earlier was: preboot_dma  = use DMA access?)
499
; c) preboot_debug = duplicates kernel debug output to the screen // (earlier was: preboot_vrrm = use VRR?)
500
;    // VRR is an obsolete functionality, used only with CRT monitors: increase display frequency by reducing screen resolution
501
; d) preboot_launcher = start the first app (right now it's LAUNCHER) after kernel is loaded?
502
; e) preboot_device = from where to boot?
713 Lrz 503
 
29 halyavin 504
; determine default settings
2010 serge 505
if ~ defined extended_primary_loader
514 diamond 506
        mov     [.bSettingsChanged], 0
2010 serge 507
end if
713 Lrz 508
 
509
;.preboot_gr_end:
726 diamond 510
        mov     di, preboot_device
511
; if image in memory is present and [preboot_device] is uninitialized,
512
; set it to use this preloaded image
513
        cmp     byte [di], 0
514
        jnz     .preboot_device_inited
2010 serge 515
if defined extended_primary_loader
516
        inc     byte [di]
517
        cmp     byte [bootdevice], 'f' ; floppy?
518
        jz      .preboot_device_inited
519
        inc     byte [di]
520
else
726 diamond 521
        cmp     [.loader_block], -1
522
        jz      @f
523
        les     bx, [.loader_block]
524
        test    byte [es:bx+1], 1
525
        jz      @f
526
        mov     byte [di], 3
527
        jmp     .preboot_device_inited
528
@@:
529
; otherwise, set [preboot_device] to 1 (default value - boot from floppy)
530
        mov     byte [di], 1
2010 serge 531
end if
726 diamond 532
.preboot_device_inited:
1018 diamond 533
; following 4 lines set variables to 1 if its current value is 0
726 diamond 534
        cmp     byte [di+preboot_dma-preboot_device], 1
535
        adc     byte [di+preboot_dma-preboot_device], 0
3908 Serge 536
        cmp     byte [di+preboot_launcher-preboot_device], 1        ; Start LAUNCHER by default
537
        adc     byte [di+preboot_launcher-preboot_device], 0
3725 Serge 538
;        cmp     byte [di+preboot_biosdisk-preboot_device], 1
539
;        adc     byte [di+preboot_biosdisk-preboot_device], 0
2268 Serge 540
;; default value for VRR is OFF
541
;        cmp     byte [di+preboot_vrrm-preboot_device], 0
3908 Serge 542
;        jnz    @f
543
;        mov    byte [di+preboot_vrrm-preboot_device], 2
2268 Serge 544
;@@:
29 halyavin 545
; notify user
713 Lrz 546
        _setcursor 5,2
547
 
514 diamond 548
        mov     si, linef
713 Lrz 549
        call    printplain
514 diamond 550
        mov     si, start_msg
551
        call    print
552
        mov     si, time_msg
553
        call    print
29 halyavin 554
; get start time
514 diamond 555
        call    .gettime
556
        mov     [.starttime], eax
557
        mov     word [.timer], .newtimer
558
        mov     word [.timer+2], cs
29 halyavin 559
.printcfg:
946 lrz 560
 
514 diamond 561
        _setcursor 9,0
562
        mov     si, current_cfg_msg
563
        call    print
564
        mov     si, curvideo_msg
565
        call    print
713 Lrz 566
 
3908 Serge 567
        call    draw_current_vmode
713 Lrz 568
 
709 diamond 569
        mov     si, usebd_msg
570
        cmp     [preboot_biosdisk], 1
571
        call    .say_on_off
2268 Serge 572
;        mov     si, vrrm_msg
573
;        cmp     [preboot_vrrm], 1
574
;        call    .say_on_off
3908 Serge 575
        mov     si, debug_mode_msg
576
        cmp     [preboot_debug], 1
577
        call    .say_on_off
578
        mov     si, launcher_msg
579
        cmp     [preboot_launcher], 1
580
        call    .say_on_off
514 diamond 581
        mov     si, preboot_device_msg
582
        call    print
583
        mov     al, [preboot_device]
2010 serge 584
if defined extended_primary_loader
585
        and     eax, 3
586
else
545 spraid 587
        and     eax, 7
2010 serge 588
end if
514 diamond 589
        mov     si, [preboot_device_msgs+eax*2]
590
        call    printplain
726 diamond 591
.show_remarks:
592
; show remarks in gray color
593
        mov     di, ((21-num_remarks)*80 + 2)*2
594
        push    0xB800
595
        pop     es
596
        mov     cx, num_remarks
597
        mov     si, remarks
598
.write_remarks:
599
        lodsw
600
        push    si
601
        xchg    ax, si
602
        mov     ah, 1*16+7      ; background: blue (1), foreground: gray (7)
603
        push    di
604
.write_remark:
605
        lodsb
606
        test    al, al
607
        jz      @f
608
        stosw
609
        jmp     .write_remark
610
@@:
611
        pop     di
612
        pop     si
613
        add     di, 80*2
614
        loop    .write_remarks
29 halyavin 615
.wait:
514 diamond 616
        _setcursor 25,0         ; out of screen
34 halyavin 617
; set timer interrupt handler
514 diamond 618
        cli
619
        push    0
620
        pop     es
713 Lrz 621
        push    dword [es:8*4]
622
        pop     dword [.oldtimer]
623
        push    dword [.timer]
2441 Serge 624
        pop     dword [es:8*4]
713 Lrz 625
;        mov     eax, [es:8*4]
626
;        mov     [.oldtimer], eax
627
;        mov     eax, [.timer]
628
;        mov     [es:8*4], eax
514 diamond 629
        sti
29 halyavin 630
; wait for keypressed
2434 Serge 631
        xor     ax, ax
514 diamond 632
        int     16h
633
        push    ax
29 halyavin 634
; restore timer interrupt
713 Lrz 635
;        push    0
636
;        pop     es
514 diamond 637
        mov     eax, [.oldtimer]
638
        mov     [es:8*4], eax
639
        mov     [.timer], eax
946 lrz 640
 
514 diamond 641
        _setcursor 7,0
642
        mov     si, space_msg
643
        call    printplain
726 diamond 644
; clear remarks and restore normal attributes
645
        push    es
646
        mov     di, ((21-num_remarks)*80 + 2)*2
647
        push    0xB800
648
        pop     es
649
        mov     cx, num_remarks
650
        mov     ax, ' ' + (1*16 + 15)*100h
651
@@:
652
        push    cx
653
        mov     cx, 76
3908 Serge 654
        rep stosw
726 diamond 655
        pop     cx
656
        add     di, 4*2
657
        loop    @b
658
        pop     es
514 diamond 659
        pop     ax
29 halyavin 660
; switch on key
514 diamond 661
        cmp     al, 13
662
        jz      .continue
663
        or      al, 20h
3908 Serge 664
        cmp     al, 'a'         ; select graphical mode
514 diamond 665
        jz      .change_a
3908 Serge 666
        cmp     al, 'q'         ; Trick to make 'A' key on azerty keyboard work
667
        je      .change_a
668
        cmp     al, 'b'         ; use BIOS disks? // (selecting YES will make BIOS disks visible as /bd)
514 diamond 669
        jz      .change_b
3908 Serge 670
        cmp     al, 'c'         ; load kernel in debug mode?  // (earlier was: use VRR?)
671
        jz      .change_c
672
        cmp     al, 'd'         ; start launcher after kernel is loaded?
673
        jz      .change_d
674
        cmp     al, 'e'         ; select boot origin
726 diamond 675
        jnz     .show_remarks
3908 Serge 676
; e) preboot_device = from where to boot?
2010 serge 677
if defined extended_primary_loader
4265 Serge 678
        _ask_question bdev,'12',preboot_device              ; range accepted for answer: 1-2
2010 serge 679
else
4265 Serge 680
        _ask_question bdev,'14',preboot_device              ; range accepted for answer: 1-4
2010 serge 681
end if
3908 Serge 682
        _setcursor 14,0
4265 Serge 683
 
29 halyavin 684
.d:
2010 serge 685
if ~ defined extended_primary_loader
514 diamond 686
        mov     [.bSettingsChanged], 1
2010 serge 687
end if
4265 Serge 688
.esc_pressed:
713 Lrz 689
        call    clear_vmodes_table             ;clear vmodes_table
3908 Serge 690
        jmp     .printcfg
4265 Serge 691
 
29 halyavin 692
.change_a:
3908 Serge 693
        call    clear_vmodes_table             ;clear vmodes_table
4265 Serge 694
 
695
        mov     si, word [cursor_pos]
696
        mov     word [cursor_pos_old], si
713 Lrz 697
.loops:
698
        call    draw_vmodes_table
816 Lrz 699
        _setcursor 25,0         ; out of screen
2434 Serge 700
        xor     ax, ax
713 Lrz 701
        int     0x16
702
;        call    clear_table_cursor             ;clear current position of cursor
703
 
2434 Serge 704
        mov     si, word [cursor_pos]
713 Lrz 705
 
4265 Serge 706
        cmp     al, 27              ; If ESC was pressed, do not change the value
707
        jnz     @f                   ; Just exit the resolution selection box
708
 
709
        mov     si, word [cursor_pos_old]
710
        mov     word [cursor_pos], si
711
        jmp     .esc_pressed
712
@@:
2434 Serge 713
        cmp     ah, 0x48;x,0x48E0               ; up
713 Lrz 714
        jne     .down
2434 Serge 715
        cmp     si, modes_table
713 Lrz 716
        jbe     .loops
2434 Serge 717
        sub     word [cursor_pos], size_of_step
713 Lrz 718
        jmp     .loops
719
 
2434 Serge 720
.down:
721
        cmp     ah, 0x50;x,0x50E0               ; down
730 diamond 722
        jne     .pgup
2434 Serge 723
        cmp     word[es:si+10], -1
2441 Serge 724
        je      .loops
2434 Serge 725
        add     word [cursor_pos], size_of_step
713 Lrz 726
        jmp     .loops
727
 
2434 Serge 728
.pgup:
729
        cmp     ah, 0x49                ; page up
730 diamond 730
        jne     .pgdn
731 diamond 731
        sub     si, size_of_step*long_v_table
730 diamond 732
        cmp     si, modes_table
733
        jae     @f
734
        mov     si, modes_table
735
@@:
736
        mov     word [cursor_pos], si
737
        mov     si, word [home_cursor]
731 diamond 738
        sub     si, size_of_step*long_v_table
730 diamond 739
        cmp     si, modes_table
740
        jae     @f
741
        mov     si, modes_table
742
@@:
743
        mov     word [home_cursor], si
744
        jmp     .loops
745
 
2434 Serge 746
.pgdn:
747
        cmp     ah, 0x51                ; page down
730 diamond 748
        jne     .enter
749
        mov     ax, [end_cursor]
731 diamond 750
        add     si, size_of_step*long_v_table
730 diamond 751
        cmp     si, ax
752
        jb      @f
753
        mov     si, ax
754
        sub     si, size_of_step
755
@@:
756
        mov     word [cursor_pos], si
757
        mov     si, word [home_cursor]
731 diamond 758
        sub     ax, size_of_step*long_v_table
759
        add     si, size_of_step*long_v_table
730 diamond 760
        cmp     si, ax
761
        jb      @f
762
        mov     si, ax
763
@@:
764
        mov     word [home_cursor], si
765
        jmp     .loops
766
 
2434 Serge 767
.enter:
768
        cmp     al, 0x0D;x,0x1C0D               ; enter
713 Lrz 769
        jne     .loops
770
        push    word [cursor_pos]
746 Lrz 771
        pop     bp
772
        push    word [es:bp]
773
        pop     word [x_save]
774
        push    word [es:bp+2]
775
        pop     word [y_save]
816 Lrz 776
        push    word [es:bp+6]
749 Lrz 777
        pop     word [number_vm]
2434 Serge 778
        mov     word [preboot_graph], bp          ;save choose
3908 Serge 779
 
780
        jmp     .d
2441 Serge 781
 
3908 Serge 782
.change_b:                      ; b) preboot_biosdisk  = use BIOS disks through V86 emulation?
4265 Serge 783
;        _setcursor 16,0
3908 Serge 784
;        mov     si, ask_dma    // (earlier was: preboot_dma  = use DMA access?)
709 diamond 785
;        call    print
3908 Serge 786
;        mov     bx, '13'       ; range accepted for answer: 1-3
709 diamond 787
;        call    getkey
788
;        mov     [preboot_dma], al
4265 Serge 789
        _ask_question ask_bd,'12',preboot_biosdisk              ; range accepted for answer: 1-2
514 diamond 790
        _setcursor 11,0
791
        jmp     .d
3908 Serge 792
;.change_c:                     ; //  VRR is an obsolete functionality, used only with CRT monitors
793
;        _setcursor 16,0
2268 Serge 794
;        mov     si, vrrmprint
795
;        call    print
3908 Serge 796
;        mov     bx, '12'       ; range accepted for answer: 1-2
2268 Serge 797
;        call    getkey
798
;        mov     [preboot_vrrm], al
799
;        _setcursor 12,0
800
;        jmp     .d
3908 Serge 801
.change_c:                      ; c) preboot_debug = duplicates kernel debug output to the screen
4265 Serge 802
        _ask_question ask_debug,'12',preboot_debug              ; range accepted for answer: 1-2
3908 Serge 803
        _setcursor 12,0
804
        jmp     .d
805
.change_d:                      ; d) preboot_launcher = start the first app (right now it's LAUNCHER) after kernel is loaded?
4265 Serge 806
        _ask_question ask_launcher,'12',preboot_launcher        ; range accepted for answer: 1-2
3908 Serge 807
        _setcursor 13,0
808
        jmp     .d
713 Lrz 809
;;;;;;;;;;;;;;;;;;;;;;;;;;;;
40 halyavin 810
.say_on_off:
514 diamond 811
        pushf
812
        call    print
813
        mov     si, on_msg
814
        popf
815
        jz      @f
816
        mov     si, off_msg
2434 Serge 817
@@:
818
        jmp     printplain
40 halyavin 819
; novesa and vervesa strings are not used at the moment of executing this code
820
virtual at novesa
29 halyavin 821
.oldtimer dd ?
822
.starttime dd ?
2010 serge 823
if ~ defined extended_primary_loader
29 halyavin 824
.bSettingsChanged db ?
2010 serge 825
end if
34 halyavin 826
.timer dd ?
40 halyavin 827
end virtual
2010 serge 828
if ~ defined extended_primary_loader
143 diamond 829
.loader_block dd -1
2010 serge 830
end if
29 halyavin 831
.gettime:
514 diamond 832
        mov     ah, 0
833
        int     1Ah
834
        xchg    ax, cx
835
        shl     eax, 10h
836
        xchg    ax, dx
837
        ret
29 halyavin 838
.newtimer:
514 diamond 839
        push    ds
840
        push    cs
841
        pop     ds
842
        pushf
843
        call    [.oldtimer]
844
        pushad
845
        call    .gettime
846
        sub     eax, [.starttime]
2010 serge 847
if defined extended_primary_loader
848
        sub     ax, [preboot_timeout]
849
else
514 diamond 850
        sub     ax, 18*5
2010 serge 851
end if
514 diamond 852
        jae     .timergo
853
        neg     ax
854
        add     ax, 18-1
855
        mov     bx, 18
856
        xor     dx, dx
857
        div     bx
29 halyavin 858
if lang eq ru
3555 Serge 859
; подождите 5 секунд, 4/3/2 секунды, 1 секунду
514 diamond 860
        cmp     al, 5
861
        mov     cl, ' '
862
        jae     @f
863
        cmp     al, 1
3555 Serge 864
        mov     cl, 0xE3 ; 'у' in cp866
514 diamond 865
        jz      @f
3555 Serge 866
        mov     cl, 0xEB ; 'ы' in cp866
2434 Serge 867
@@:
868
        mov     [time_str+9], cl
274 kaitz 869
else if lang eq et
514 diamond 870
        cmp     al, 1
871
        ja      @f
3555 Serge 872
        mov     byte [time_str+9], ' '
873
        mov     byte [time_str+10], ' '
381 serge 874
@@:
3500 Serge 875
else if lang eq sp
876
; esperar 5/4/3/2 segundos, 1 segundo
877
        cmp     al, 1
878
        mov     cl, 's'
879
        ja      @f
880
        mov     cl, ' '
881
@@:
882
        mov     [time_str+10], cl
29 halyavin 883
else
884
; wait 5/4/3/2 seconds, 1 second
514 diamond 885
        cmp     al, 1
886
        mov     cl, 's'
887
        ja      @f
888
        mov     cl, ' '
2434 Serge 889
@@:
890
        mov     [time_str+9], cl
29 halyavin 891
end if
514 diamond 892
        add     al, '0'
893
        mov     [time_str+1], al
894
        mov     si, time_msg
895
        _setcursor 7,0
896
        call    print
897
        _setcursor 25,0
898
        popad
899
        pop     ds
900
        iret
29 halyavin 901
.timergo:
514 diamond 902
        push    0
903
        pop     es
904
        mov     eax, [.oldtimer]
905
        mov     [es:8*4], eax
906
        mov     sp, 0EC00h
29 halyavin 907
.continue:
514 diamond 908
        sti
909
        _setcursor 6,0
910
        mov     si, space_msg
911
        call    printplain
912
        call    printplain
913
        _setcursor 6,0
914
        mov     si, loading_msg
915
        call    print
3908 Serge 916
        _setcursor 16,0
2010 serge 917
if ~ defined extended_primary_loader
514 diamond 918
        cmp     [.bSettingsChanged], 0
919
        jz      .load
920
        cmp     [.loader_block], -1
921
        jz      .load
922
        les     bx, [.loader_block]
923
        mov     eax, [es:bx+3]
924
        push    ds
925
        pop     es
926
        test    eax, eax
927
        jz      .load
928
        push    eax
929
        mov     si, save_quest
930
        call    print
29 halyavin 931
.waityn:
514 diamond 932
        mov     ah, 0
933
        int     16h
934
        or      al, 20h
935
        cmp     al, 'n'
936
        jz      .loadc
3500 Serge 937
        if lang eq sp
938
        cmp     al, 's'
939
        else
514 diamond 940
        cmp     al, 'y'
3500 Serge 941
        end if
514 diamond 942
        jnz     .waityn
943
        call    putchar
944
        mov     byte [space_msg+80], 186
946 lrz 945
 
514 diamond 946
        pop     eax
947
        push    cs
948
        push    .cont
949
        push    eax
946 lrz 950
        retf                          ;call back
29 halyavin 951
.loadc:
514 diamond 952
        pop     eax
29 halyavin 953
.cont:
514 diamond 954
        push    cs
955
        pop     ds
956
        mov     si, space_msg
957
        mov     byte [si+80], 0
3908 Serge 958
        _setcursor 16,0
514 diamond 959
        call    printplain
3908 Serge 960
        _setcursor 16,0
29 halyavin 961
.load:
2010 serge 962
end if
29 halyavin 963
; \end{diamond}[02.12.2005]
1 ha 964
 
965
; ASK GRAPHICS MODE
966
 
713 Lrz 967
        call    set_vmode
1 ha 968
 
969
; GRAPHICS ACCELERATION
346 diamond 970
; force yes
2441 Serge 971
        mov     [es:BOOT_MTRR], byte 1
1 ha 972
 
514 diamond 973
; DMA ACCESS TO HD
1 ha 974
 
514 diamond 975
        mov     al, [preboot_dma]
2441 Serge 976
        mov     [es:BOOT_DMA], al
346 diamond 977
 
2268 Serge 978
;; VRR_M USE
979
;
980
;        mov     al,[preboot_vrrm]
3908 Serge 981
;        mov     [es:BOOT_VRR], al              ;// 0x9030
1 ha 982
 
3908 Serge 983
; Set kernel DEBUG mode - if nonzero, duplicates debug output to the screen.
984
        mov     al, [preboot_debug]
985
        mov     [es:BOOT_DEBUG_PRINT], al       ;// 0x901E
986
 
987
; Start the first app (right now it's LAUNCHER) after kernel is loaded?
988
        mov     al, [preboot_launcher]
989
        mov     [es:BOOT_LAUNCHER_START], al    ;// 0x901D
990
 
1 ha 991
; BOOT DEVICE
992
 
514 diamond 993
        mov     al, [preboot_device]
40 halyavin 994
        dec     al
514 diamond 995
        mov     [boot_dev], al
1 ha 996
 
1103 diamond 997
; GET MEMORY MAP
2010 serge 998
include '../detect/biosmem.inc'
1103 diamond 999
 
1 ha 1000
; READ DISKETTE TO MEMORY
1001
 
2434 Serge 1002
        cmp     [boot_dev], 0
1 ha 1003
        jne     no_sys_on_floppy
2434 Serge 1004
        mov     si, diskload
1 ha 1005
        call    print
514 diamond 1006
        xor     ax, ax            ; reset drive
1007
        xor     dx, dx
1 ha 1008
        int     0x13
709 diamond 1009
; do we boot from CD-ROM?
1010
        mov     ah, 41h
1011
        mov     bx, 55AAh
1012
        xor     dx, dx
1013
        int     0x13
1014
        jc      .nocd
1015
        cmp     bx, 0AA55h
1016
        jnz     .nocd
1017
        mov     ah, 48h
1018
        push    ds
1019
        push    es
1020
        pop     ds
1021
        mov     si, 0xa000
1022
        mov     word [si], 30
1023
        int     0x13
1024
        pop     ds
1025
        jc      .nocd
1026
        push    ds
1027
        lds     si, [es:si+26]
1028
        test    byte [ds:si+10], 40h
1029
        pop     ds
1030
        jz      .nocd
1031
; yes - read all floppy by 18 sectors
795 shurf 1032
 
1033
; TODO: !!!! read only first sector and set variables !!!!!
1034
; ...
1035
; TODO: !!! then read flippy image track by track
3908 Serge 1036
 
816 Lrz 1037
        mov     cx, 0x0001      ; startcyl,startsector
709 diamond 1038
.a1:
1039
        push    cx dx
1040
        mov     al, 18
1041
        mov     bx, 0xa000
1042
        call    boot_read_floppy
1043
        mov     si, movedesc
1044
        push    es
1045
        push    ds
1046
        pop     es
1047
        mov     cx, 256*18
1048
        mov     ah, 0x87
1049
        int     0x15
1050
        pop     es
1051
        pop     dx cx
1052
        test    ah, ah
1053
        jnz     sayerr_floppy
1054
        add     dword [si+8*3+2], 512*18
1055
        inc     dh
1056
        cmp     dh, 2
1057
        jnz     .a1
1058
        mov     dh, 0
1059
        inc     ch
1060
        cmp     ch, 80
1061
        jae     ok_sys_on_floppy
1062
        pusha
1063
        mov     al, ch
1064
        shr     ch, 2
1065
        add     al, ch
1066
        aam
1067
        xchg    al, ah
1068
        add     ax, '00'
1069
        mov     si, pros
1070
        mov     [si], ax
1071
        call    printplain
1072
        popa
1073
        jmp     .a1
1074
.nocd:
1075
; no - read only used sectors from floppy
134 diamond 1076
; now load floppy image to memory
1077
; at first load boot sector and first FAT table
795 shurf 1078
 
1079
; read only first sector and fill variables
816 Lrz 1080
        mov     cx, 0x0001      ; first logical sector
1081
        xor     dx, dx          ; head = 0, drive = 0 (a:)
1082
        mov     al, 1           ; read one sector
1083
        mov     bx, 0xB000      ; es:bx -> data area
1084
        call    boot_read_floppy
795 shurf 1085
; fill the necessary parameters to work with a floppy
816 Lrz 1086
        mov     ax, word [es:bx+24]
1087
        mov     word [BPB_SecPerTrk], ax
1088
        mov     ax, word [es:bx+26]
1089
        mov     word [BPB_NumHeads], ax
1090
        mov     ax, word [es:bx+17]
1091
        mov     word [BPB_RootEntCnt], ax
1092
        mov     ax, word [es:bx+14]
1093
        mov     word [BPB_RsvdSecCnt], ax
1094
        mov     ax, word [es:bx+19]
1095
        mov     word [BPB_TotSec16], ax
1096
        mov     al, byte [es:bx+13]
1097
        mov     byte [BPB_SecPerClus], al
1098
        mov     al, byte [es:bx+16]
1099
        mov     byte [BPB_NumFATs], al
925 Lrz 1100
; 18.11.2008
1101
        mov     ax, word [es:bx+22]
1102
        mov     word [BPB_FATSz16], ax
1103
        mov     cx, word [es:bx+11]
1104
        mov     word [BPB_BytsPerSec], cx
1105
 
795 shurf 1106
; count of clusters in FAT12 ((size_of_FAT*2)/3)
925 Lrz 1107
;        mov     ax, word [BPB_FATSz16]
1108
;        mov     cx, word [BPB_BytsPerSec]
1109
;end  18.11.2008
816 Lrz 1110
        xor     dx, dx
1111
        mul     cx
1112
        shl     ax, 1
1113
        mov     cx, 3
1114
        div     cx              ; now ax - number of clusters in FAT12
1115
        mov     word [end_of_FAT], ax
795 shurf 1116
 
1117
; load first FAT table
816 Lrz 1118
        mov     cx, 0x0002      ; startcyl,startsector          ; TODO!!!!!
134 diamond 1119
        xor     dx, dx          ; starthead,drive
795 shurf 1120
        mov     al, byte [BPB_FATSz16]     ; no of sectors to read
1121
        add     bx, word [BPB_BytsPerSec]  ; es:bx -> data area
134 diamond 1122
        call    boot_read_floppy
816 Lrz 1123
        mov     bx, 0xB000
795 shurf 1124
 
134 diamond 1125
; and copy them to extended memory
465 serge 1126
        mov     si, movedesc
816 Lrz 1127
        mov     [si+8*2+3], bh          ; from
3908 Serge 1128
 
816 Lrz 1129
        mov     ax, word [BPB_BytsPerSec]
1130
        shr     ax, 1                   ; words per sector
1131
        mov     cx, word [BPB_RsvdSecCnt]
1132
        add     cx, word [BPB_FATSz16]
1133
        mul     cx
1134
        push    ax                      ; save to stack count of words in boot+FAT
1135
        xchg    ax, cx
3908 Serge 1136
 
134 diamond 1137
        push    es
1138
        push    ds
1139
        pop     es
1140
        mov     ah, 0x87
1141
        int     0x15
816 Lrz 1142
        pop     es
76 mario79 1143
        test    ah, ah
134 diamond 1144
        jz      @f
1145
sayerr_floppy:
1146
        mov     dx, 0x3f2
1147
        mov     al, 0
1148
        out     dx, al
2010 serge 1149
sayerr_memmove:
465 serge 1150
        mov     si, memmovefailed
134 diamond 1151
        jmp     sayerr_plain
1152
@@:
816 Lrz 1153
        pop     ax                      ; restore from stack count of words in boot+FAT
1154
        shl     ax, 1                   ; make bytes count from count of words
1155
        and     eax, 0ffffh
795 shurf 1156
        add     dword [si+8*3+2], eax
1157
 
1158
; copy first FAT to second copy
1159
; TODO: BPB_NumFATs !!!!!
816 Lrz 1160
        add     bx, word [BPB_BytsPerSec]       ; !!! TODO: may be need multiply by BPB_RsvdSecCnt !!!
1161
        mov     byte [si+8*2+3], bh     ; bx - begin of FAT
3908 Serge 1162
 
816 Lrz 1163
        mov     ax, word [BPB_BytsPerSec]
1164
        shr     ax, 1                   ; words per sector
1165
        mov     cx, word [BPB_FATSz16]
1166
        mul     cx
1167
        mov     cx, ax                  ; cx - count of words in FAT
795 shurf 1168
 
1169
        push    es
1170
        push    ds
1171
        pop     es
134 diamond 1172
        mov     ah, 0x87
1173
        int     0x15
1174
        pop     es
1175
        test    ah, ah
1176
        jnz     sayerr_floppy
3908 Serge 1177
 
816 Lrz 1178
        mov     ax, cx
1179
        shl     ax, 1
1180
        and     eax, 0ffffh             ; ax - count of bytes in FAT
795 shurf 1181
        add     dword [si+8*3+2], eax
3908 Serge 1182
 
795 shurf 1183
; reading RootDir
1184
; TODO: BPB_NumFATs
816 Lrz 1185
        add     bx, ax
1186
        add     bx, 100h
1187
        and     bx, 0ff00h                      ; bx - place in buffer to write RootDir
1188
        push    bx
795 shurf 1189
 
816 Lrz 1190
        mov     bx, word [BPB_BytsPerSec]
1191
        shr     bx, 5                           ; divide bx by 32
1192
        mov     ax, word [BPB_RootEntCnt]
1193
        xor     dx, dx
1194
        div     bx
1195
        push    ax                              ; ax - count of RootDir sectors
795 shurf 1196
 
816 Lrz 1197
        mov     ax, word [BPB_FATSz16]
1198
        xor     cx, cx
1199
        mov     cl, byte [BPB_NumFATs]
1200
        mul     cx
1201
        add     ax, word [BPB_RsvdSecCnt]       ; ax - first sector of RootDir
795 shurf 1202
 
816 Lrz 1203
        mov     word [FirstDataSector], ax
1204
        pop     bx
1205
        push    bx
1206
        add     word [FirstDataSector], bx      ; Begin of data region of floppy
3908 Serge 1207
 
795 shurf 1208
; read RootDir
816 Lrz 1209
        call    conv_abs_to_THS
1210
        pop     ax
1211
        pop     bx                              ; place in buffer to write
1212
        push    ax
1213
        call    boot_read_floppy                ; read RootDir into buffer
795 shurf 1214
; copy RootDir
816 Lrz 1215
        mov     byte [si+8*2+3], bh             ; from buffer
1216
        pop     ax                              ; ax = count of RootDir sectors
1217
        mov     cx, word [BPB_BytsPerSec]
1218
        mul     cx
1219
        shr     ax, 1
1220
        mov     cx, ax                          ; count of words to copy
1221
        push    es
1222
        push    ds
1223
        pop     es
795 shurf 1224
        mov     ah, 0x87
1225
        int     0x15
816 Lrz 1226
        pop     es
795 shurf 1227
 
816 Lrz 1228
        mov     ax, cx
1229
        shl     ax, 1
1230
        and     eax, 0ffffh             ; ax - count of bytes in RootDir
1231
        add     dword [si+8*3+2], eax   ; add count of bytes copied
795 shurf 1232
 
1233
; Reading data clusters from floppy
816 Lrz 1234
        mov     byte [si+8*2+3], bh
1235
        push    bx
795 shurf 1236
 
816 Lrz 1237
        mov     di, 2                   ; First data cluster
134 diamond 1238
.read_loop:
816 Lrz 1239
        mov     bx, di
1240
        shr     bx, 1                   ; bx+di = di*1.5
1241
        jnc     .even
1242
        test    word [es:bx+di+0xB200], 0xFFF0  ; TODO: may not be 0xB200 !!!
1243
        jmp     @f
134 diamond 1244
.even:
816 Lrz 1245
        test    word [es:bx+di+0xB200], 0xFFF   ; TODO: may not be 0xB200 !!!
795 shurf 1246
 
134 diamond 1247
@@:
816 Lrz 1248
        jz      .skip
795 shurf 1249
; read cluster di
1250
;.read:
816 Lrz 1251
        ;conv cluster di to abs. sector ax
1252
        ; ax = (N-2) * BPB_SecPerClus + FirstDataSector
1253
        mov     ax, di
1254
        sub     ax, 2
1255
        xor     bx, bx
1256
        mov     bl, byte [BPB_SecPerClus]
1257
        mul     bx
1258
        add     ax, word [FirstDataSector]
1259
        call    conv_abs_to_THS
1260
        pop     bx
1261
        push    bx
1262
        mov     al, byte [BPB_SecPerClus]       ; number of sectors in cluster
1263
        call    boot_read_floppy
76 mario79 1264
        push    es
1265
        push    ds
1 ha 1266
        pop     es
134 diamond 1267
        pusha
795 shurf 1268
;
816 Lrz 1269
        mov     ax, word [BPB_BytsPerSec]
1270
        xor     cx, cx
1271
        mov     cl, byte [BPB_SecPerClus]
1272
        mul     cx
1273
        shr     ax, 1                           ; ax = (BPB_BytsPerSec * BPB_SecPerClus)/2
1274
        mov     cx, ax                          ; number of words to copy (count words in cluster)
795 shurf 1275
;
816 Lrz 1276
        mov     ah, 0x87
1277
        int     0x15                            ; copy data
134 diamond 1278
        test    ah, ah
1 ha 1279
        popa
134 diamond 1280
        pop     es
1281
        jnz     sayerr_floppy
795 shurf 1282
; skip cluster di
134 diamond 1283
.skip:
816 Lrz 1284
        mov     ax, word [BPB_BytsPerSec]
1285
        xor     cx, cx
1286
        mov     cl, byte [BPB_SecPerClus]
1287
        mul     cx
1288
        and     eax, 0ffffh             ; ax - count of bytes in cluster
1289
        add     dword [si+8*3+2], eax
795 shurf 1290
 
816 Lrz 1291
        mov     ax, word [end_of_FAT]   ; max cluster number
134 diamond 1292
        pusha
1293
; draw percentage
795 shurf 1294
; total clusters: ax
1295
; read clusters: di
816 Lrz 1296
        xchg    ax, di
134 diamond 1297
        mov     cx, 100
1298
        mul     cx
816 Lrz 1299
        div     di
134 diamond 1300
        aam
1301
        xchg    al, ah
1302
        add     ax, '00'
465 serge 1303
        mov     si, pros
134 diamond 1304
        cmp     [si], ax
1305
        jz      @f
1306
        mov     [si], ax
1 ha 1307
        call    printplain
134 diamond 1308
@@:
1 ha 1309
        popa
134 diamond 1310
        inc     di
816 Lrz 1311
        cmp     di, word [end_of_FAT]   ; max number of cluster
134 diamond 1312
        jnz     .read_loop
816 Lrz 1313
        pop     bx                      ; clear stack
134 diamond 1314
 
709 diamond 1315
ok_sys_on_floppy:
514 diamond 1316
        mov     si, backspace2
1 ha 1317
        call    printplain
514 diamond 1318
        mov     si, okt
1 ha 1319
        call    printplain
514 diamond 1320
no_sys_on_floppy:
1321
        xor     ax, ax          ; reset drive
1322
        xor     dx, dx
1 ha 1323
        int     0x13
514 diamond 1324
        mov     dx, 0x3f2       ; floppy motor off
1325
        mov     al, 0
1326
        out     dx, al
1 ha 1327
 
2010 serge 1328
if defined extended_primary_loader
1329
        cmp     [boot_dev], 1
1330
        jne     no_sys_from_primary
1331
; load kolibri.img using callback from primary loader
1332
        and     word [movedesc + 24 + 2], 0
1333
        mov     byte [movedesc + 24 + 4], 10h
1334
; read in blocks of 64K until file is fully loaded
1335
        mov     ax, 1
1336
.repeat:
1337
        mov     di, image_file_struct
1338
        call    [bootcallback]
1339
        push    cs
1340
        pop     ds
1341
        push    cs
1342
        pop     es
1343
        cmp     bx, 1
1344
        ja      sayerr_badsect
1345
        push    bx
1346
        mov     si, movedesc
1347
        and     word [si + 16 + 2], 0
1348
        mov     byte [si + 16 + 4], 4
1349
        mov     ah, 87h
1350
        mov     cx, 8000h
1351
        int     15h
1352
        pop     bx
1353
        test    ah, ah
1354
        jnz     sayerr_memmove
1355
        inc     byte [si + 24 + 4]
1356
        test    bx, bx
1357
        jz      no_sys_from_primary
1358
        mov     ax, 2
1359
        jmp     .repeat
1360
no_sys_from_primary:
1361
end if
1 ha 1362
 
1363
; SET GRAPHICS
1364
 
514 diamond 1365
        xor     ax, ax
1366
        mov     es, ax
164 serge 1367
 
2441 Serge 1368
        mov     ax, [es:BOOT_VESA_MODE]         ; vga & 320x200
514 diamond 1369
        mov     bx, ax
1370
        cmp     ax, 0x13
1 ha 1371
        je      setgr
514 diamond 1372
        cmp     ax, 0x12
1 ha 1373
        je      setgr
514 diamond 1374
        mov     ax, 0x4f02              ; Vesa
412 serge 1375
setgr:
1 ha 1376
        int     0x10
514 diamond 1377
        test    ah, ah
1378
        mov     si, fatalsel
713 Lrz 1379
        jnz     v_mode_error
1 ha 1380
; set mode 0x12 graphics registers:
514 diamond 1381
        cmp     bx, 0x12
1 ha 1382
        jne     gmok2
1383
 
514 diamond 1384
        mov     al, 0x05
1385
        mov     dx, 0x03ce
40 halyavin 1386
        push    dx
514 diamond 1387
        out     dx, al      ; select GDC mode register
1388
        mov     al, 0x02
1389
        inc     dx
1390
        out     dx, al      ; set write mode 2
1 ha 1391
 
514 diamond 1392
        mov     al, 0x02
1393
        mov     dx, 0x03c4
1394
        out     dx, al      ; select VGA sequencer map mask register
1395
        mov     al, 0x0f
1396
        inc     dx
1397
        out     dx, al      ; set mask for all planes 0-3
1 ha 1398
 
514 diamond 1399
        mov     al, 0x08
1400
        pop     dx
1401
        out     dx, al      ; select GDC bit mask register
1 ha 1402
                           ; for writes to 0x03cf
412 serge 1403
gmok2:
76 mario79 1404
        push    ds
514 diamond 1405
        pop     es