Subversion Repositories Kolibri OS

Rev

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

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