Subversion Repositories Kolibri OS

Rev

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

Rev Author Line No. Line
431 serge 1
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2
;;                                                              ;;
3
;; Copyright (C) KolibriOS team 2004-2007. All rights reserved. ;;
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: 1103 $
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
45
        cmp     al, 0
46
        jnz     @b
47
        popa
48
        ret
1 ha 49
 
29 halyavin 50
getkey:
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)
514 diamond 54
        mov     ah, 0
55
        int     16h
56
        cmp     al, bl
57
        jb      getkey
58
        cmp     al, bh
59
        ja      getkey
60
        push    ax
61
        call    putchar
62
        pop     ax
63
        and     ax, 0Fh
64
        jnz     @f
65
        mov     al, 10
29 halyavin 66
@@:
514 diamond 67
        ret
1 ha 68
 
29 halyavin 69
setcursor:
70
; in: dl=column, dh=row
514 diamond 71
        mov     ah, 2
72
        mov     bh, 0
73
        int     10h
74
        ret
29 halyavin 75
 
76
macro _setcursor row,column
77
{
514 diamond 78
        mov     dx, row*256 + column
79
        call    setcursor
29 halyavin 80
}
81
 
134 diamond 82
boot_read_floppy:
83
        push    si
84
        xor     si, si
85
        mov     ah, 2   ; read
86
@@:
87
        push    ax
88
        int     0x13
89
        pop     ax
90
        jnc     @f
91
        inc     si
92
        cmp     si, 10
93
        jb      @b
465 serge 94
        mov     si, badsect
134 diamond 95
sayerr_plain:
96
        call    printplain
97
        jmp     $
98
@@:
99
        pop     si
100
        ret
101
 
795 shurf 102
; convert abs. sector number (AX) to BIOS T:H:S
103
; sector number = (abs.sector%BPB_SecPerTrk)+1
104
; pre.track number = (abs.sector/BPB_SecPerTrk)
105
; head number = pre.track number%BPB_NumHeads
106
; track number = pre.track number/BPB_NumHeads
107
; Return: cl - sector number
108
;         ch - track number
109
;         dl - drive number (0 = a:)
110
;         dh - head number
111
conv_abs_to_THS:
112
        push    bx
113
        mov     bx,word [BPB_SecPerTrk]
114
        xor     dx,dx
115
        div     bx
116
        inc     dx
117
        mov     cl, dl                          ; cl = sector number
118
        mov     bx,word [BPB_NumHeads]
119
        xor     dx,dx
120
        div     bx
121
        ; !!!!!!! ax = track number, dx = head number
122
        mov     ch,al                           ; ch=track number
123
        xchg    dh,dl                           ; dh=head number
124
        mov     dl,0                            ; dl=0 (drive 0 (a:))
125
        pop     bx
126
        retn
127
; needed variables
816 Lrz 128
BPB_SecPerTrk   dw      0                       ; sectors per track
129
BPB_NumHeads    dw      0                       ; number of heads
130
BPB_FATSz16     dw      0                       ; size of FAT
131
BPB_RootEntCnt  dw      0                       ; count of root dir. entries
132
BPB_BytsPerSec  dw      0                       ; bytes per sector
133
BPB_RsvdSecCnt  dw      0                       ; number of reserved sectors
134
BPB_TotSec16    dw      0                       ; count of the sectors on the volume
135
BPB_SecPerClus  db      0                       ; number of sectors per cluster
136
BPB_NumFATs     db      0                       ; number of FAT tables
137
abs_sector_adj  dw      0                       ; adjustment to make abs. sector number
138
end_of_FAT      dw      0                       ; end of FAT table
139
FirstDataSector dw      0                       ; begin of data
795 shurf 140
 
1 ha 141
;=========================================================================
142
;
143
;                           16 BIT CODE
144
;
145
;=========================================================================
146
 
713 Lrz 147
include 'bootvesa.inc'                 ;Include source for boot vesa
1 ha 148
 
149
start_of_code:
514 diamond 150
        cld
29 halyavin 151
; \begin{diamond}[02.12.2005]
514 diamond 152
; if bootloader sets ax = 'KL', then ds:si points to loader block
153
        cmp     ax, 'KL'
154
        jnz     @f
155
        mov     word [cs:cfgmanager.loader_block], si
156
        mov     word [cs:cfgmanager.loader_block+2], ds
29 halyavin 157
@@:
158
; \end{diamond}[02.12.2005]
1 ha 159
 
514 diamond 160
; if bootloader sets cx = 'HA' and dx = 'RD', then bx contains identifier of source hard disk
161
; (see comment to bx_from_load)
162
        cmp     cx, 'HA'
163
        jnz     no_hd_load
164
        cmp     dx,'RD'
165
        jnz     no_hd_load
166
        mov     word [cs:bx_from_load], bx              ; {SPraid}[13.03.2007]
488 spraid 167
no_hd_load:
168
 
29 halyavin 169
; set up stack
514 diamond 170
        mov     ax, 3000h
171
        mov     ss, ax
172
        mov     sp, 0EC00h
29 halyavin 173
; set up segment registers
514 diamond 174
        push    cs
175
        pop     ds
176
        push    cs
177
        pop     es
1 ha 178
 
29 halyavin 179
; set videomode
514 diamond 180
        mov     ax, 3
181
        int     0x10
1 ha 182
 
134 diamond 183
if lang eq ru
1 ha 184
 ; Load & set russian VGA font (RU.INC)
514 diamond 185
        mov     bp, RU_FNT1             ; RU_FNT1 - First part
186
        mov     bx, 1000h               ; 768 bytes
187
        mov     cx, 30h                 ; 48 symbols
188
        mov     dx, 80h                 ; 128 - position of first symbol
189
        mov     ax, 1100h
190
        int     10h
1 ha 191
 
514 diamond 192
        mov     bp, RU_FNT2             ; RU_FNT2 -Second part
193
        mov     bx, 1000h               ; 512 bytes
194
        mov     cx, 20h                 ; 32 symbols
195
        mov     dx, 0E0h                ; 224 - position of first symbol
196
        mov     ax, 1100h
197
        int     10h
1 ha 198
 ; End set VGA russian font
274 kaitz 199
else if lang eq et
514 diamond 200
        mov     bp, ET_FNT              ; ET_FNT1
201
        mov     bx, 1000h               ;
202
        mov     cx, 255                 ; 256 symbols
203
        xor     dx, dx                  ; 0 - position of first symbol
204
        mov     ax, 1100h
205
        int     10h
134 diamond 206
end if
1 ha 207
 
29 halyavin 208
; draw frames
514 diamond 209
        push    0xb800
210
        pop     es
211
        xor     di, di
212
        mov     ah, 1*16+15
465 serge 213
 
29 halyavin 214
; draw top
514 diamond 215
        mov     si, d80x25_top
216
        mov     cx, d80x25_top_num * 80
29 halyavin 217
@@:
514 diamond 218
        lodsb
219
        stosw
220
        loop    @b
29 halyavin 221
; draw spaces
514 diamond 222
        mov     si, space_msg
223
        mov     dx, 25 - d80x25_top_num - d80x25_bottom_num
29 halyavin 224
dfl1:
514 diamond 225
        push    si
226
        mov     cx, 80
29 halyavin 227
@@:
514 diamond 228
        lodsb
229
        stosw
230
        loop    @b
231
        pop     si
232
        dec     dx
233
        jnz     dfl1
29 halyavin 234
; draw bottom
514 diamond 235
        mov     si, d80x25_bottom
236
        mov     cx, d80x25_bottom_num * 80
29 halyavin 237
@@:
514 diamond 238
        lodsb
239
        stosw
240
        loop    @b
1 ha 241
 
514 diamond 242
        mov     byte [space_msg+80], 0    ; now space_msg is null terminated
1 ha 243
 
514 diamond 244
        _setcursor d80x25_top_num,0
1 ha 245
 
246
 
247
; TEST FOR 386+
248
 
514 diamond 249
        mov     bx, 0x4000
1 ha 250
        pushf
251
        pop     ax
514 diamond 252
        mov     dx, ax
253
        xor     ax, bx
1 ha 254
        push    ax
255
        popf
256
        pushf
257
        pop     ax
514 diamond 258
        and     ax, bx
259
        and     dx, bx
260
        cmp     ax, dx
1 ha 261
        jnz     cpugood
514 diamond 262
        mov     si, not386
40 halyavin 263
sayerr:
1 ha 264
        call    print
265
        jmp     $
266
     cpugood:
267
 
514 diamond 268
        push    0
465 serge 269
        popf
270
        sti
271
 
29 halyavin 272
; set up esp
514 diamond 273
        movzx   esp, sp
1 ha 274
 
160 diamond 275
        push    0
276
        pop     es
277
        and     word [es:0x9031], 0
164 serge 278
; \begin{Mario79}
279
; find HDD IDE DMA PCI device
160 diamond 280
; check for PCI BIOS
281
        mov     ax, 0xB101
282
        int     0x1A
283
        jc      .nopci
284
        cmp     edx, 'PCI '
285
        jnz     .nopci
286
; find PCI class code
287
; class 1 = mass storage
288
; subclass 1 = IDE controller
289
; a) class 1, subclass 1, programming interface 0x80
290
        mov     ax, 0xB103
291
        mov     ecx, 1*10000h + 1*100h + 0x80
514 diamond 292
        xor     si, si  ; device index = 0
160 diamond 293
        int     0x1A
294
        jnc     .found
187 diamond 295
; b) class 1, subclass 1, programming interface 0x8A
160 diamond 296
        mov     ax, 0xB103
187 diamond 297
        mov     ecx, 1*10000h + 1*100h + 0x8A
514 diamond 298
        xor     si, si  ; device index = 0
160 diamond 299
        int     0x1A
300
        jnc     .found
187 diamond 301
; c) class 1, subclass 1, programming interface 0x85
160 diamond 302
        mov     ax, 0xB103
187 diamond 303
        mov     ecx, 1*10000h + 1*100h + 0x85
514 diamond 304
        xor     si, si
160 diamond 305
        int     0x1A
306
        jc      .nopci
307
.found:
308
; get memory base
309
        mov     ax, 0xB10A
310
        mov     di, 0x20        ; memory base is config register at 0x20
311
        int     0x1A
312
        jc      .nopci
313
        and     cx, 0xFFF0      ; clear address decode type
314
        mov     [es:0x9031], cx
315
.nopci:
164 serge 316
; \end{Mario79}
160 diamond 317
 
514 diamond 318
        mov     al, 0xf6        ; Ñáðîñ êëàâèàòóðû, ðàçðåøèòü ñêàíèðîâàíèå
319
        out     0x60, al
320
        xor     cx, cx
1 ha 321
wait_loop:       ; variant 2
322
; reading state of port of 8042 controller
514 diamond 323
        in      al, 64h
324
        and     al, 00000010b  ; ready flag
164 serge 325
; wait until 8042 controller is ready
1 ha 326
        loopnz  wait_loop
327
 
713 Lrz 328
;;;/diamond today   5.02.2008
329
; set keyboard typematic rate & delay
330
        mov     al, 0xf3
331
        out     0x60, al
332
        xor     cx, cx
333
@@:
334
        in      al, 64h
335
        test    al, 2
336
        loopnz  @b
337
        mov     al, 0
338
        out     0x60, al
339
        xor     cx, cx
340
@@:
341
        in      al, 64h
342
        test    al, 2
343
        loopnz  @b
344
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
76 mario79 345
; --------------- APM ---------------------
514 diamond 346
        and     word [es:0x9044], 0     ; ver = 0.0 (APM not found)
347
        mov     ax, 0x5300
348
        xor     bx, bx
349
        int     0x15
350
        jc      apm_end                 ; APM not found
351
        test    cx, 2
352
        jz      apm_end                 ; APM 32-bit protected-mode interface not supported
353
        mov     [es:0x9044], ax         ; Save APM Version
354
        mov     [es:0x9046], cx         ; Save APM flags
164 serge 355
 
514 diamond 356
        ; Write APM ver ----
357
        and     ax, 0xf0f
358
        add     ax, '00'
359
        mov     si, msg_apm
360
        mov     [si + 5], ah
361
        mov     [si + 7], al
362
        _setcursor 0, 3
363
        call    printplain
364
        ; ------------------
164 serge 365
 
514 diamond 366
        mov     ax, 0x5304              ; Disconnect interface
367
        xor     bx, bx
368
        int     0x15
369
        mov     ax, 0x5303              ; Connect 32 bit mode interface
370
        xor     bx, bx
371
        int     0x15
465 serge 372
 
514 diamond 373
        mov     [es:0x9040], ebx
374
        mov     [es:0x9050], ax
375
        mov     [es:0x9052], cx
376
        mov     [es:0x9054], dx
465 serge 377
 
76 mario79 378
apm_end:
437 diamond 379
        _setcursor d80x25_top_num, 0
76 mario79 380
 
713 Lrz 381
;CHECK current of code
382
        cmp     [cfgmanager.loader_block], -1
383
        jz      noloaderblock
384
        les     bx, [cfgmanager.loader_block]
385
        cmp     byte [es:bx], 1
386
        mov     si, loader_block_error
387
        jnz     sayerr
737 diamond 388
        push    0
389
        pop     es
713 Lrz 390
 
391
noloaderblock:
1 ha 392
; DISPLAY VESA INFORMATION
713 Lrz 393
         call    print_vesa_info
394
         call    calc_vmodes_table
395
         call    check_first_parm  ;check and enable cursor_pos
1 ha 396
 
29 halyavin 397
; \begin{diamond}[30.11.2005]
398
cfgmanager:
399
; settings:
400
; a) preboot_graph = graphical mode
401
;    preboot_gprobe = probe this mode?
713 Lrz 402
; b) preboot_dma  = use DMA access?
29 halyavin 403
; c) preboot_vrrm = use VRR?
404
; d) preboot_device = from what boot?
713 Lrz 405
 
29 halyavin 406
; determine default settings
514 diamond 407
        mov     [.bSettingsChanged], 0
713 Lrz 408
 
409
;.preboot_gr_end:
726 diamond 410
        mov     di, preboot_device
411
; if image in memory is present and [preboot_device] is uninitialized,
412
; set it to use this preloaded image
413
        cmp     byte [di], 0
414
        jnz     .preboot_device_inited
415
        cmp     [.loader_block], -1
416
        jz      @f
417
        les     bx, [.loader_block]
418
        test    byte [es:bx+1], 1
419
        jz      @f
420
        mov     byte [di], 3
421
        jmp     .preboot_device_inited
422
@@:
423
; otherwise, set [preboot_device] to 1 (default value - boot from floppy)
424
        mov     byte [di], 1
425
.preboot_device_inited:
1018 diamond 426
; following 4 lines set variables to 1 if its current value is 0
726 diamond 427
        cmp     byte [di+preboot_dma-preboot_device], 1
428
        adc     byte [di+preboot_dma-preboot_device], 0
429
        cmp     byte [di+preboot_biosdisk-preboot_device], 1
430
        adc     byte [di+preboot_biosdisk-preboot_device], 0
1018 diamond 431
; default value for VRR is OFF
432
        cmp     byte [di+preboot_vrrm-preboot_device], 0
433
        jnz	@f
434
        mov	byte [di+preboot_vrrm-preboot_device], 2
435
@@:
29 halyavin 436
; notify user
713 Lrz 437
        _setcursor 5,2
438
 
514 diamond 439
        mov     si, linef
713 Lrz 440
        call    printplain
514 diamond 441
        mov     si, start_msg
442
        call    print
443
        mov     si, time_msg
444
        call    print
29 halyavin 445
; get start time
514 diamond 446
        call    .gettime
447
        mov     [.starttime], eax
448
        mov     word [.timer], .newtimer
449
        mov     word [.timer+2], cs
29 halyavin 450
.printcfg:
946 lrz 451
 
514 diamond 452
        _setcursor 9,0
453
        mov     si, current_cfg_msg
454
        call    print
455
        mov     si, curvideo_msg
456
        call    print
713 Lrz 457
 
458
            call    draw_current_vmode
459
 
709 diamond 460
        mov     si, usebd_msg
461
        cmp     [preboot_biosdisk], 1
462
        call    .say_on_off
514 diamond 463
        mov     si, vrrm_msg
464
        cmp     [preboot_vrrm], 1
465
        call    .say_on_off
466
        mov     si, preboot_device_msg
467
        call    print
468
        mov     al, [preboot_device]
545 spraid 469
        and     eax, 7
514 diamond 470
        mov     si, [preboot_device_msgs+eax*2]
471
        call    printplain
726 diamond 472
.show_remarks:
473
; show remarks in gray color
474
        mov     di, ((21-num_remarks)*80 + 2)*2
475
        push    0xB800
476
        pop     es
477
        mov     cx, num_remarks
478
        mov     si, remarks
479
.write_remarks:
480
        lodsw
481
        push    si
482
        xchg    ax, si
483
        mov     ah, 1*16+7      ; background: blue (1), foreground: gray (7)
484
        push    di
485
.write_remark:
486
        lodsb
487
        test    al, al
488
        jz      @f
489
        stosw
490
        jmp     .write_remark
491
@@:
492
        pop     di
493
        pop     si
494
        add     di, 80*2
495
        loop    .write_remarks
29 halyavin 496
.wait:
514 diamond 497
        _setcursor 25,0         ; out of screen
34 halyavin 498
; set timer interrupt handler
514 diamond 499
        cli
500
        push    0
501
        pop     es
713 Lrz 502
        push    dword [es:8*4]
503
        pop     dword [.oldtimer]
504
        push    dword [.timer]
505
        pop     dword [es:8*4]
506
;        mov     eax, [es:8*4]
507
;        mov     [.oldtimer], eax
508
;        mov     eax, [.timer]
509
;        mov     [es:8*4], eax
514 diamond 510
        sti
29 halyavin 511
; wait for keypressed
713 Lrz 512
        xor     ax,ax
514 diamond 513
        int     16h
514
        push    ax
29 halyavin 515
; restore timer interrupt
713 Lrz 516
;        push    0
517
;        pop     es
514 diamond 518
        mov     eax, [.oldtimer]
519
        mov     [es:8*4], eax
520
        mov     [.timer], eax
946 lrz 521
 
514 diamond 522
        _setcursor 7,0
523
        mov     si, space_msg
524
        call    printplain
726 diamond 525
; clear remarks and restore normal attributes
526
        push    es
527
        mov     di, ((21-num_remarks)*80 + 2)*2
528
        push    0xB800
529
        pop     es
530
        mov     cx, num_remarks
531
        mov     ax, ' ' + (1*16 + 15)*100h
532
@@:
533
        push    cx
534
        mov     cx, 76
535
        rep     stosw
536
        pop     cx
537
        add     di, 4*2
538
        loop    @b
539
        pop     es
514 diamond 540
        pop     ax
29 halyavin 541
; switch on key
514 diamond 542
        cmp     al, 13
543
        jz      .continue
544
        or      al, 20h
545
        cmp     al, 'a'
546
        jz      .change_a
547
        cmp     al, 'b'
548
        jz      .change_b
549
        cmp     al, 'c'
550
        jz      .change_c
551
        cmp     al, 'd'
726 diamond 552
        jnz     .show_remarks
514 diamond 553
        _setcursor 15,0
554
        mov     si, bdev
555
        call    print
545 spraid 556
        mov     bx, '14'
514 diamond 557
        call    getkey
558
        mov     [preboot_device], al
559
        _setcursor 13,0
29 halyavin 560
.d:
514 diamond 561
        mov     [.bSettingsChanged], 1
713 Lrz 562
        call    clear_vmodes_table             ;clear vmodes_table
514 diamond 563
        jmp    .printcfg
29 halyavin 564
.change_a:
713 Lrz 565
.loops:
566
        call    draw_vmodes_table
816 Lrz 567
        _setcursor 25,0         ; out of screen
713 Lrz 568
        xor     ax,ax
569
        int     0x16
570
;        call    clear_table_cursor             ;clear current position of cursor
571
 
572
        mov     si,word [cursor_pos]
573
 
574
        cmp     ah,0x48;x,0x48E0               ; up
575
        jne     .down
576
        cmp     si,modes_table
577
        jbe     .loops
578
        sub     word [cursor_pos],size_of_step
579
        jmp     .loops
580
 
581
.down:  cmp     ah,0x50;x,0x50E0               ; down
730 diamond 582
        jne     .pgup
713 Lrz 583
        cmp     word[es:si+10],-1
584
        je      .loops
585
        add     word [cursor_pos],size_of_step
586
        jmp     .loops
587
 
730 diamond 588
.pgup:  cmp     ah,0x49                 ; page up
589
        jne     .pgdn
731 diamond 590
        sub     si, size_of_step*long_v_table
730 diamond 591
        cmp     si, modes_table
592
        jae     @f
593
        mov     si, modes_table
594
@@:
595
        mov     word [cursor_pos], si
596
        mov     si, word [home_cursor]
731 diamond 597
        sub     si, size_of_step*long_v_table
730 diamond 598
        cmp     si, modes_table
599
        jae     @f
600
        mov     si, modes_table
601
@@:
602
        mov     word [home_cursor], si
603
        jmp     .loops
604
 
605
.pgdn:  cmp     ah,0x51                 ; page down
606
        jne     .enter
607
        mov     ax, [end_cursor]
731 diamond 608
        add     si, size_of_step*long_v_table
730 diamond 609
        cmp     si, ax
610
        jb      @f
611
        mov     si, ax
612
        sub     si, size_of_step
613
@@:
614
        mov     word [cursor_pos], si
615
        mov     si, word [home_cursor]
731 diamond 616
        sub     ax, size_of_step*long_v_table
617
        add     si, size_of_step*long_v_table
730 diamond 618
        cmp     si, ax
619
        jb      @f
620
        mov     si, ax
621
@@:
622
        mov     word [home_cursor], si
623
        jmp     .loops
624
 
713 Lrz 625
.enter: cmp     al,0x0D;x,0x1C0D               ; enter
626
        jne     .loops
627
        push    word [cursor_pos]
746 Lrz 628
        pop     bp
629
        push    word [es:bp]
630
        pop     word [x_save]
631
        push    word [es:bp+2]
632
        pop     word [y_save]
816 Lrz 633
        push    word [es:bp+6]
749 Lrz 634
        pop     word [number_vm]
746 Lrz 635
        mov     word [preboot_graph],bp           ;save choose
636
 
514 diamond 637
        jmp    .d
713 Lrz 638
 
29 halyavin 639
.change_b:
514 diamond 640
        _setcursor 15,0
709 diamond 641
;        mov     si, ask_dma
642
;        call    print
643
;        mov     bx, '13'
644
;        call    getkey
645
;        mov     [preboot_dma], al
646
        mov     si, ask_bd
514 diamond 647
        call    print
709 diamond 648
        mov     bx, '12'
514 diamond 649
        call    getkey
709 diamond 650
        mov     [preboot_biosdisk], al
514 diamond 651
        _setcursor 11,0
652
        jmp     .d
29 halyavin 653
.change_c:
514 diamond 654
        _setcursor 15,0
655
        mov     si, vrrmprint
656
        call    print
657
        mov     bx, '12'
658
        call    getkey
659
        mov     [preboot_vrrm], al
660
        _setcursor 12,0
661
        jmp     .d
713 Lrz 662
;;;;;;;;;;;;;;;;;;;;;;;;;;;;
40 halyavin 663
.say_on_off:
514 diamond 664
        pushf
665
        call    print
666
        mov     si, on_msg
667
        popf
668
        jz      @f
669
        mov     si, off_msg
670
@@:     jmp     printplain
40 halyavin 671
; novesa and vervesa strings are not used at the moment of executing this code
672
virtual at novesa
29 halyavin 673
.oldtimer dd ?
674
.starttime dd ?
675
.bSettingsChanged db ?
34 halyavin 676
.timer dd ?
40 halyavin 677
end virtual
143 diamond 678
.loader_block dd -1
29 halyavin 679
.gettime:
514 diamond 680
        mov     ah, 0
681
        int     1Ah
682
        xchg    ax, cx
683
        shl     eax, 10h
684
        xchg    ax, dx
685
        ret
29 halyavin 686
.newtimer:
514 diamond 687
        push    ds
688
        push    cs
689
        pop     ds
690
        pushf
691
        call    [.oldtimer]
692
        pushad
693
        call    .gettime
694
        sub     eax, [.starttime]
695
        sub     ax, 18*5
696
        jae     .timergo
697
        neg     ax
698
        add     ax, 18-1
699
        mov     bx, 18
700
        xor     dx, dx
701
        div     bx
29 halyavin 702
if lang eq ru
703
; ¯®¤®¦¤¨â¥ 5 ᥪ㭤, 4/3/2 ᥪ㭤ë, 1 ᥪ㭤ã
514 diamond 704
        cmp     al, 5
705
        mov     cl, ' '
706
        jae     @f
707
        cmp     al, 1
708
        mov     cl, 'ã'
709
        jz      @f
710
        mov     cl, 'ë'
711
@@:     mov     [time_str+9], cl
274 kaitz 712
else if lang eq et
514 diamond 713
        cmp     al, 1
714
        ja      @f
715
        mov     [time_str+9], ' '
716
        mov     [time_str+10],' '
381 serge 717
@@:
29 halyavin 718
else
719
; wait 5/4/3/2 seconds, 1 second
514 diamond 720
        cmp     al, 1
721
        mov     cl, 's'
722
        ja      @f
723
        mov     cl, ' '
724
@@:     mov     [time_str+9], cl
29 halyavin 725
end if
514 diamond 726
        add     al, '0'
727
        mov     [time_str+1], al
728
        mov     si, time_msg
729
        _setcursor 7,0
730
        call    print
731
        _setcursor 25,0
732
        popad
733
        pop     ds
734
        iret
29 halyavin 735
.timergo:
514 diamond 736
        push    0
737
        pop     es
738
        mov     eax, [.oldtimer]
739
        mov     [es:8*4], eax
740
        mov     sp, 0EC00h
29 halyavin 741
.continue:
514 diamond 742
        sti
743
        _setcursor 6,0
744
        mov     si, space_msg
745
        call    printplain
746
        call    printplain
747
        _setcursor 6,0
748
        mov     si, loading_msg
749
        call    print
750
        _setcursor 15,0
751
        cmp     [.bSettingsChanged], 0
752
        jz      .load
753
        cmp     [.loader_block], -1
754
        jz      .load
755
        les     bx, [.loader_block]
756
        mov     eax, [es:bx+3]
757
        push    ds
758
        pop     es
759
        test    eax, eax
760
        jz      .load
761
        push    eax
762
        mov     si, save_quest
763
        call    print
29 halyavin 764
.waityn:
514 diamond 765
        mov     ah, 0
766
        int     16h
767
        or      al, 20h
768
        cmp     al, 'n'
769
        jz      .loadc
770
        cmp     al, 'y'
771
        jnz     .waityn
772
        call    putchar
773
        mov     byte [space_msg+80], 186
946 lrz 774
 
514 diamond 775
        pop     eax
776
        push    cs
777
        push    .cont
778
        push    eax
946 lrz 779
        retf                          ;call back
29 halyavin 780
.loadc:
514 diamond 781
        pop     eax
29 halyavin 782
.cont:
514 diamond 783
        push    cs
784
        pop     ds
785
        mov     si, space_msg
786
        mov     byte [si+80], 0
787
        _setcursor 15,0
788
        call    printplain
789
        _setcursor 15,0
29 halyavin 790
.load:
791
; \end{diamond}[02.12.2005]
1 ha 792
 
793
; ASK GRAPHICS MODE
794
 
713 Lrz 795
        call    set_vmode
1 ha 796
 
797
; GRAPHICS ACCELERATION
346 diamond 798
; force yes
799
        mov     [es:0x901C], byte 1
1 ha 800
 
514 diamond 801
; DMA ACCESS TO HD
1 ha 802
 
514 diamond 803
        mov     al, [preboot_dma]
804
        mov     [es:0x901F], al
346 diamond 805
 
1 ha 806
; VRR_M USE
807
 
465 serge 808
        mov     al,[preboot_vrrm]
514 diamond 809
        mov     [es:0x9030], al
810
        mov     [es:0x901E], byte 1
1 ha 811
 
812
; BOOT DEVICE
813
 
514 diamond 814
        mov     al, [preboot_device]
40 halyavin 815
        dec     al
514 diamond 816
        mov     [boot_dev], al
1 ha 817
 
1103 diamond 818
; GET MEMORY MAP
819
include 'detect/biosmem.inc'
820
 
1 ha 821
; READ DISKETTE TO MEMORY
822
 
1103 diamond 823
        cmp     [boot_dev],0
1 ha 824
        jne     no_sys_on_floppy
465 serge 825
        mov     si,diskload
1 ha 826
        call    print
514 diamond 827
        xor     ax, ax            ; reset drive
828
        xor     dx, dx
1 ha 829
        int     0x13
709 diamond 830
; do we boot from CD-ROM?
831
        mov     ah, 41h
832
        mov     bx, 55AAh
833
        xor     dx, dx
834
        int     0x13
835
        jc      .nocd
836
        cmp     bx, 0AA55h
837
        jnz     .nocd
838
        mov     ah, 48h
839
        push    ds
840
        push    es
841
        pop     ds
842
        mov     si, 0xa000
843
        mov     word [si], 30
844
        int     0x13
845
        pop     ds
846
        jc      .nocd
847
        push    ds
848
        lds     si, [es:si+26]
849
        test    byte [ds:si+10], 40h
850
        pop     ds
851
        jz      .nocd
852
; yes - read all floppy by 18 sectors
795 shurf 853
 
854
; TODO: !!!! read only first sector and set variables !!!!!
855
; ...
856
; TODO: !!! then read flippy image track by track
857
 
816 Lrz 858
        mov     cx, 0x0001      ; startcyl,startsector
709 diamond 859
.a1:
860
        push    cx dx
861
        mov     al, 18
862
        mov     bx, 0xa000
863
        call    boot_read_floppy
864
        mov     si, movedesc
865
        push    es
866
        push    ds
867
        pop     es
868
        mov     cx, 256*18
869
        mov     ah, 0x87
870
        int     0x15
871
        pop     es
872
        pop     dx cx
873
        test    ah, ah
874
        jnz     sayerr_floppy
875
        add     dword [si+8*3+2], 512*18
876
        inc     dh
877
        cmp     dh, 2
878
        jnz     .a1
879
        mov     dh, 0
880
        inc     ch
881
        cmp     ch, 80
882
        jae     ok_sys_on_floppy
883
        pusha
884
        mov     al, ch
885
        shr     ch, 2
886
        add     al, ch
887
        aam
888
        xchg    al, ah
889
        add     ax, '00'
890
        mov     si, pros
891
        mov     [si], ax
892
        call    printplain
893
        popa
894
        jmp     .a1
895
.nocd:
896
; no - read only used sectors from floppy
134 diamond 897
; now load floppy image to memory
898
; at first load boot sector and first FAT table
795 shurf 899
 
900
; read only first sector and fill variables
816 Lrz 901
        mov     cx, 0x0001      ; first logical sector
902
        xor     dx, dx          ; head = 0, drive = 0 (a:)
903
        mov     al, 1           ; read one sector
904
        mov     bx, 0xB000      ; es:bx -> data area
905
        call    boot_read_floppy
795 shurf 906
; fill the necessary parameters to work with a floppy
816 Lrz 907
        mov     ax, word [es:bx+24]
908
        mov     word [BPB_SecPerTrk], ax
909
        mov     ax, word [es:bx+26]
910
        mov     word [BPB_NumHeads], ax
911
        mov     ax, word [es:bx+17]
912
        mov     word [BPB_RootEntCnt], ax
913
        mov     ax, word [es:bx+14]
914
        mov     word [BPB_RsvdSecCnt], ax
915
        mov     ax, word [es:bx+19]
916
        mov     word [BPB_TotSec16], ax
917
        mov     al, byte [es:bx+13]
918
        mov     byte [BPB_SecPerClus], al
919
        mov     al, byte [es:bx+16]
920
        mov     byte [BPB_NumFATs], al
925 Lrz 921
; 18.11.2008
922
        mov     ax, word [es:bx+22]
923
        mov     word [BPB_FATSz16], ax
924
        mov     cx, word [es:bx+11]
925
        mov     word [BPB_BytsPerSec], cx
926
 
795 shurf 927
; count of clusters in FAT12 ((size_of_FAT*2)/3)
925 Lrz 928
;        mov     ax, word [BPB_FATSz16]
929
;        mov     cx, word [BPB_BytsPerSec]
930
;end  18.11.2008
816 Lrz 931
        xor     dx, dx
932
        mul     cx
933
        shl     ax, 1
934
        mov     cx, 3
935
        div     cx              ; now ax - number of clusters in FAT12
936
        mov     word [end_of_FAT], ax
795 shurf 937
 
938
; load first FAT table
816 Lrz 939
        mov     cx, 0x0002      ; startcyl,startsector          ; TODO!!!!!
134 diamond 940
        xor     dx, dx          ; starthead,drive
795 shurf 941
        mov     al, byte [BPB_FATSz16]     ; no of sectors to read
942
        add     bx, word [BPB_BytsPerSec]  ; es:bx -> data area
134 diamond 943
        call    boot_read_floppy
816 Lrz 944
        mov     bx, 0xB000
795 shurf 945
 
134 diamond 946
; and copy them to extended memory
465 serge 947
        mov     si, movedesc
816 Lrz 948
        mov     [si+8*2+3], bh          ; from
949
 
950
        mov     ax, word [BPB_BytsPerSec]
951
        shr     ax, 1                   ; words per sector
952
        mov     cx, word [BPB_RsvdSecCnt]
953
        add     cx, word [BPB_FATSz16]
954
        mul     cx
955
        push    ax                      ; save to stack count of words in boot+FAT
956
        xchg    ax, cx
957
 
134 diamond 958
        push    es
959
        push    ds
960
        pop     es
961
        mov     ah, 0x87
962
        int     0x15
816 Lrz 963
        pop     es
76 mario79 964
        test    ah, ah
134 diamond 965
        jz      @f
966
sayerr_floppy:
967
        mov     dx, 0x3f2
968
        mov     al, 0
969
        out     dx, al
465 serge 970
        mov     si, memmovefailed
134 diamond 971
        jmp     sayerr_plain
972
@@:
816 Lrz 973
        pop     ax                      ; restore from stack count of words in boot+FAT
974
        shl     ax, 1                   ; make bytes count from count of words
975
        and     eax, 0ffffh
795 shurf 976
        add     dword [si+8*3+2], eax
977
 
978
; copy first FAT to second copy
979
; TODO: BPB_NumFATs !!!!!
816 Lrz 980
        add     bx, word [BPB_BytsPerSec]       ; !!! TODO: may be need multiply by BPB_RsvdSecCnt !!!
981
        mov     byte [si+8*2+3], bh     ; bx - begin of FAT
982
 
983
        mov     ax, word [BPB_BytsPerSec]
984
        shr     ax, 1                   ; words per sector
985
        mov     cx, word [BPB_FATSz16]
986
        mul     cx
987
        mov     cx, ax                  ; cx - count of words in FAT
795 shurf 988
 
989
        push    es
990
        push    ds
991
        pop     es
134 diamond 992
        mov     ah, 0x87
993
        int     0x15
994
        pop     es
995
        test    ah, ah
996
        jnz     sayerr_floppy
816 Lrz 997
 
998
        mov     ax, cx
999
        shl     ax, 1
1000
        and     eax, 0ffffh             ; ax - count of bytes in FAT
795 shurf 1001
        add     dword [si+8*3+2], eax
816 Lrz 1002
 
795 shurf 1003
; reading RootDir
1004
; TODO: BPB_NumFATs
816 Lrz 1005
        add     bx, ax
1006
        add     bx, 100h
1007
        and     bx, 0ff00h                      ; bx - place in buffer to write RootDir
1008
        push    bx
795 shurf 1009
 
816 Lrz 1010
        mov     bx, word [BPB_BytsPerSec]
1011
        shr     bx, 5                           ; divide bx by 32
1012
        mov     ax, word [BPB_RootEntCnt]
1013
        xor     dx, dx
1014
        div     bx
1015
        push    ax                              ; ax - count of RootDir sectors
795 shurf 1016
 
816 Lrz 1017
        mov     ax, word [BPB_FATSz16]
1018
        xor     cx, cx
1019
        mov     cl, byte [BPB_NumFATs]
1020
        mul     cx
1021
        add     ax, word [BPB_RsvdSecCnt]       ; ax - first sector of RootDir
795 shurf 1022
 
816 Lrz 1023
        mov     word [FirstDataSector], ax
1024
        pop     bx
1025
        push    bx
1026
        add     word [FirstDataSector], bx      ; Begin of data region of floppy
1027
 
795 shurf 1028
; read RootDir
816 Lrz 1029
        call    conv_abs_to_THS
1030
        pop     ax
1031
        pop     bx                              ; place in buffer to write
1032
        push    ax
1033
        call    boot_read_floppy                ; read RootDir into buffer
795 shurf 1034
; copy RootDir
816 Lrz 1035
        mov     byte [si+8*2+3], bh             ; from buffer
1036
        pop     ax                              ; ax = count of RootDir sectors
1037
        mov     cx, word [BPB_BytsPerSec]
1038
        mul     cx
1039
        shr     ax, 1
1040
        mov     cx, ax                          ; count of words to copy
1041
        push    es
1042
        push    ds
1043
        pop     es
795 shurf 1044
        mov     ah, 0x87
1045
        int     0x15
816 Lrz 1046
        pop     es
795 shurf 1047
 
816 Lrz 1048
        mov     ax, cx
1049
        shl     ax, 1
1050
        and     eax, 0ffffh             ; ax - count of bytes in RootDir
1051
        add     dword [si+8*3+2], eax   ; add count of bytes copied
795 shurf 1052
 
1053
; Reading data clusters from floppy
816 Lrz 1054
        mov     byte [si+8*2+3], bh
1055
        push    bx
795 shurf 1056
 
816 Lrz 1057
        mov     di, 2                   ; First data cluster
134 diamond 1058
.read_loop:
816 Lrz 1059
        mov     bx, di
1060
        shr     bx, 1                   ; bx+di = di*1.5
1061
        jnc     .even
1062
        test    word [es:bx+di+0xB200], 0xFFF0  ; TODO: may not be 0xB200 !!!
1063
        jmp     @f
134 diamond 1064
.even:
816 Lrz 1065
        test    word [es:bx+di+0xB200], 0xFFF   ; TODO: may not be 0xB200 !!!
795 shurf 1066
 
134 diamond 1067
@@:
816 Lrz 1068
        jz      .skip
795 shurf 1069
; read cluster di
1070
;.read:
816 Lrz 1071
        ;conv cluster di to abs. sector ax
1072
        ; ax = (N-2) * BPB_SecPerClus + FirstDataSector
1073
        mov     ax, di
1074
        sub     ax, 2
1075
        xor     bx, bx
1076
        mov     bl, byte [BPB_SecPerClus]
1077
        mul     bx
1078
        add     ax, word [FirstDataSector]
1079
        call    conv_abs_to_THS
1080
        pop     bx
1081
        push    bx
1082
        mov     al, byte [BPB_SecPerClus]       ; number of sectors in cluster
1083
        call    boot_read_floppy
76 mario79 1084
        push    es
1085
        push    ds
1 ha 1086
        pop     es
134 diamond 1087
        pusha
795 shurf 1088
;
816 Lrz 1089
        mov     ax, word [BPB_BytsPerSec]
1090
        xor     cx, cx
1091
        mov     cl, byte [BPB_SecPerClus]
1092
        mul     cx
1093
        shr     ax, 1                           ; ax = (BPB_BytsPerSec * BPB_SecPerClus)/2
1094
        mov     cx, ax                          ; number of words to copy (count words in cluster)
795 shurf 1095
;
816 Lrz 1096
        mov     ah, 0x87
1097
        int     0x15                            ; copy data
134 diamond 1098
        test    ah, ah
1 ha 1099
        popa
134 diamond 1100
        pop     es
1101
        jnz     sayerr_floppy
795 shurf 1102
; skip cluster di
134 diamond 1103
.skip:
816 Lrz 1104
        mov     ax, word [BPB_BytsPerSec]
1105
        xor     cx, cx
1106
        mov     cl, byte [BPB_SecPerClus]
1107
        mul     cx
1108
        and     eax, 0ffffh             ; ax - count of bytes in cluster
1109
        add     dword [si+8*3+2], eax
795 shurf 1110
 
816 Lrz 1111
        mov     ax, word [end_of_FAT]   ; max cluster number
134 diamond 1112
        pusha
1113
; draw percentage
795 shurf 1114
; total clusters: ax
1115
; read clusters: di
816 Lrz 1116
        xchg    ax, di
134 diamond 1117
        mov     cx, 100
1118
        mul     cx
816 Lrz 1119
        div     di
134 diamond 1120
        aam
1121
        xchg    al, ah
1122
        add     ax, '00'
465 serge 1123
        mov     si, pros
134 diamond 1124
        cmp     [si], ax
1125
        jz      @f
1126
        mov     [si], ax
1 ha 1127
        call    printplain
134 diamond 1128
@@:
1 ha 1129
        popa
134 diamond 1130
        inc     di
816 Lrz 1131
        cmp     di, word [end_of_FAT]   ; max number of cluster
134 diamond 1132
        jnz     .read_loop
816 Lrz 1133
        pop     bx                      ; clear stack
134 diamond 1134
 
709 diamond 1135
ok_sys_on_floppy:
514 diamond 1136
        mov     si, backspace2
1 ha 1137
        call    printplain
514 diamond 1138
        mov     si, okt
1 ha 1139
        call    printplain
514 diamond 1140
no_sys_on_floppy:
1141
        xor     ax, ax          ; reset drive
1142
        xor     dx, dx
1 ha 1143
        int     0x13
514 diamond 1144
        mov     dx, 0x3f2       ; floppy motor off
1145
        mov     al, 0
1146
        out     dx, al
1 ha 1147
 
1148
 
1149
; SET GRAPHICS
1150
 
514 diamond 1151
        xor     ax, ax
1152
        mov     es, ax
164 serge 1153
 
514 diamond 1154
        mov     ax, [es:0x9008]         ; vga & 320x200
1155
        mov     bx, ax
1156
        cmp     ax, 0x13
1 ha 1157
        je      setgr
514 diamond 1158
        cmp     ax, 0x12
1 ha 1159
        je      setgr
514 diamond 1160
        mov     ax, 0x4f02              ; Vesa
412 serge 1161
setgr:
1 ha 1162
        int     0x10
514 diamond 1163
        test    ah, ah
1164
        mov     si, fatalsel
713 Lrz 1165
        jnz     v_mode_error
1 ha 1166
; set mode 0x12 graphics registers:
514 diamond 1167
        cmp     bx, 0x12
1 ha 1168
        jne     gmok2
1169
 
514 diamond 1170
        mov     al, 0x05
1171
        mov     dx, 0x03ce
40 halyavin 1172
        push    dx
514 diamond 1173
        out     dx, al      ; select GDC mode register
1174
        mov     al, 0x02
1175
        inc     dx
1176
        out     dx, al      ; set write mode 2
1 ha 1177
 
514 diamond 1178
        mov     al, 0x02
1179
        mov     dx, 0x03c4
1180
        out     dx, al      ; select VGA sequencer map mask register
1181
        mov     al, 0x0f
1182
        inc     dx
1183
        out     dx, al      ; set mask for all planes 0-3
1 ha 1184
 
514 diamond 1185
        mov     al, 0x08
1186
        pop     dx
1187
        out     dx, al      ; select GDC bit mask register
1 ha 1188
                           ; for writes to 0x03cf
412 serge 1189
gmok2:
76 mario79 1190
        push    ds
514 diamond 1191
        pop     es