Subversion Repositories Kolibri OS

Rev

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